[Lemon-commits] [lemon_svn] deba: r2131 - hugo/trunk/lemon

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:50:23 CET 2006


Author: deba
Date: Thu Aug 11 15:20:52 2005
New Revision: 2131

Added:
   hugo/trunk/lemon/grid_graph.h
      - copied, changed from r2128, /hugo/trunk/lemon/matrix_graph.h

Log:
Matrix graph renamed to grid graph
Some usefull function and documentation



Copied: hugo/trunk/lemon/grid_graph.h (from r2128, /hugo/trunk/lemon/matrix_graph.h)
==============================================================================
--- /hugo/trunk/lemon/matrix_graph.h	(original)
+++ hugo/trunk/lemon/grid_graph.h	Thu Aug 11 15:20:52 2005
@@ -1,5 +1,5 @@
 /* -*- C++ -*-
- * lemon/matrix_graph.h - Part of LEMON, a generic C++ optimization library
+ * lemon/grid_graph.h - Part of LEMON, a generic C++ optimization library
  *
  * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
  * (Egervary Research Group on Combinatorial Optimization, EGRES).
@@ -14,8 +14,8 @@
  *
  */
 
-#ifndef MATRIX_GRAPH_H
-#define MATRIX_GRAPH_H
+#ifndef GRID_GRAPH_H
+#define GRID_GRAPH_H
 
 #include <iostream>
 #include <lemon/invalid.h>
@@ -29,34 +29,63 @@
 
 namespace lemon {
 
-  class MatrixGraphBase {
+  class GridGraphBase {
 
   public:
 
-    typedef MatrixGraphBase Graph;
+    typedef GridGraphBase Graph;
 
     class Node;
     class Edge;
 
   public:
 
-    MatrixGraphBase() {}
+    GridGraphBase() {}
 
-    ///Creates a full graph with \c n nodes.
+  protected:
+
+    /// \brief Creates a grid graph with the given size.
+    ///
+    /// Creates a grid graph with the given size.
     void construct(int height, int width) {
       _height = height; _width = width;
       _nodeNum = height * width; _edgeNum = 2 * _nodeNum - width - height;
       _edgeLimit = _nodeNum - width;
     }
+
+  public:
     
+    /// \brief The node on the given position.
+    /// 
+    /// Gives back the node on the given position.
     Node operator()(int i, int j) const {
       return Node(i * _width + j);
     }
 
+    /// \brief Gives back the row index of the node.
+    ///
+    /// Gives back the row index of the node.
+    int row(Node n) const {
+      return n.id / _width;
+    }
+    
+    /// \brief Gives back the coloumn index of the node.
+    ///
+    /// Gives back the coloumn index of the node.
+    int col(Node node) const {
+      return n.id % _width;    
+    }
+
+    /// \brief Gives back the width of the graph.
+    ///
+    /// Gives back the width of the graph.
     int width() const {
       return _width;
     }
 
+    /// \brief Gives back the height of the graph.
+    ///
+    /// Gives back the height of the graph.
     int height() const {
       return _height;
     }
@@ -80,6 +109,9 @@
     ///\sa id(Edge)
     int maxId(Edge = INVALID) const { return edgeNum() - 1; }
 
+    /// \brief Gives back the source node of an edge.
+    ///    
+    /// Gives back the source node of an edge.
     Node source(Edge e) const {
       if (e.id < _edgeLimit) {
 	return e.id;
@@ -89,6 +121,9 @@
       }
     }
 
+    /// \brief Gives back the target node of an edge.
+    ///    
+    /// Gives back the target node of an edge.
     Node target(Edge e) const {
       if (e.id < _edgeLimit) {
 	return e.id + _width;
@@ -144,7 +179,7 @@
     
       
     class Node {
-      friend class MatrixGraphBase;
+      friend class GridGraphBase;
 
     protected:
       int id;
@@ -160,7 +195,7 @@
 
 
     class Edge {
-      friend class MatrixGraphBase;
+      friend class GridGraphBase;
       
     protected:
       int id; 
@@ -242,18 +277,18 @@
   };
 
 
-  typedef UndirGraphExtender<MatrixGraphBase>
-  UndirMatrixGraphBase;
-  typedef AlterableUndirGraphExtender<UndirMatrixGraphBase> 
-  AlterableMatrixGraphBase;
-  typedef IterableUndirGraphExtender<AlterableMatrixGraphBase> 
-  IterableMatrixGraphBase;
-  typedef MappableUndirGraphExtender<IterableMatrixGraphBase> 
-  MappableMatrixGraphBase;
+  typedef UndirGraphExtender<GridGraphBase>
+  UndirGridGraphBase;
+  typedef AlterableUndirGraphExtender<UndirGridGraphBase> 
+  AlterableGridGraphBase;
+  typedef IterableUndirGraphExtender<AlterableGridGraphBase> 
+  IterableGridGraphBase;
+  typedef MappableUndirGraphExtender<IterableGridGraphBase> 
+  MappableGridGraphBase;
 
   /// \ingroup graphs
   ///
-  /// \brief Matrix graph class
+  /// \brief Grid graph class
   ///
   /// This class implements a special graph type. The nodes of the
   /// graph can be indiced by two integer \c (i,j) value where \c i
@@ -263,8 +298,8 @@
   ///
   /// The graph can be indiced in the following way:
   /// \code
-  /// MatrixGraph graph(h, w);
-  /// MatrixGraph::NodeMap<int> val(graph); 
+  /// GridGraph graph(h, w);
+  /// GridGraph::NodeMap<int> val(graph); 
   /// for (int i = 0; i < graph.height(); ++i) {
   ///   for (int j = 0; j < graph.width(); ++j) {
   ///     val[graph(i, j)] = i + j;
@@ -276,10 +311,10 @@
   /// "Undirected Graph" concept.
   ///
   /// \author Balazs Dezso
-  class MatrixGraph : public MappableMatrixGraphBase {
+  class GridGraph : public MappableGridGraphBase {
   public:
     
-    MatrixGraph(int m, int n) { construct(m, n); }
+    GridGraph(int m, int n) { construct(m, n); }
   };
 }
 #endif



More information about the Lemon-commits mailing list