Index: lemon/grid_graph.h
===================================================================
--- lemon/grid_graph.h	(revision 1623)
+++ lemon/grid_graph.h	(revision 1680)
@@ -48,9 +48,58 @@
     ///
     /// Creates a grid graph with the given size.
-    void construct(int height, int width) {
+    void construct(int width, int height) {
       _height = height; _width = width;
       _nodeNum = height * width; _edgeNum = 2 * _nodeNum - width - height;
       _edgeLimit = _nodeNum - width;
     }
+
+    /// \brief Gives back the edge goes down from the node.
+    ///
+    /// Gives back the edge goes down from the node. If there is not
+    /// outgoing edge then it gives back INVALID.
+    Edge _down(Node n) const {
+      if (n.id < _nodeNum - _width) {
+	return Edge(n.id);
+      } else {
+	return INVALID;
+      }
+    }
+
+    /// \brief Gives back the edge comes from up into the node.
+    ///
+    /// Gives back the edge comes from up into the node. If there is not
+    /// incoming edge then it gives back INVALID.
+    Edge _up(Node n) const {
+      if (n.id >= _width) {
+	return Edge(n.id - _width);
+      } else {
+	return INVALID;
+      }
+    }
+
+    /// \brief Gives back the edge goes right from the node.
+    ///
+    /// Gives back the edge goes right from the node. If there is not
+    /// outgoing edge then it gives back INVALID.
+    Edge _right(Node n) const {
+      if (n.id % _width < _width - 1) {
+	return _edgeLimit + n.id % _width + (n.id / _width) * (_width - 1);
+      } else {
+	return INVALID;
+      }
+    }
+
+    /// \brief Gives back the edge comes from left into the node.
+    ///
+    /// Gives back the edge comes left up into the node. If there is not
+    /// incoming edge then it gives back INVALID.
+    Edge _left(Node n) const {
+      if (n.id % _width > 0) {
+	return _edgeLimit + n.id % _width + (n.id / _width) * (_width - 1) - 1;
+      } else {
+	return INVALID;
+      }
+    }
+
 
   public:
@@ -60,5 +109,5 @@
     /// Gives back the node on the given position.
     Node operator()(int i, int j) const {
-      return Node(i * _width + j);
+      return Node(i + j * _width);
     }
 
@@ -73,5 +122,5 @@
     ///
     /// Gives back the coloumn index of the node.
-    int col(Node node) const {
+    int col(Node n) const {
       return n.id % _width;    
     }
@@ -278,12 +327,8 @@
 
 
-  typedef UndirGraphExtender<GridGraphBase>
-  UndirGridGraphBase;
-  typedef AlterableUndirGraphExtender<UndirGridGraphBase> 
-  AlterableGridGraphBase;
-  typedef IterableUndirGraphExtender<AlterableGridGraphBase> 
-  IterableGridGraphBase;
-  typedef MappableUndirGraphExtender<IterableGridGraphBase> 
-  MappableGridGraphBase;
+  typedef MappableUndirGraphExtender<
+    IterableUndirGraphExtender<
+    AlterableUndirGraphExtender<
+    UndirGraphExtender<GridGraphBase> > > > ExtendedGridGraphBase;
 
   /// \ingroup graphs
@@ -312,8 +357,45 @@
   ///
   /// \author Balazs Dezso
-  class GridGraph : public MappableGridGraphBase {
+  class GridGraph : public ExtendedGridGraphBase {
   public:
     
-    GridGraph(int m, int n) { construct(m, n); }
+    GridGraph(int n, int m) { construct(n, m); }
+    
+    /// \brief Gives back the edge goes down from the node.
+    ///
+    /// Gives back the edge goes down from the node. If there is not
+    /// outgoing edge then it gives back INVALID.
+    Edge down(Node n) const {
+      UndirEdge ue = _down(n);
+      return ue != INVALID ? direct(ue, true) : INVALID;
+    }
+    
+    /// \brief Gives back the edge goes up from the node.
+    ///
+    /// Gives back the edge goes up from the node. If there is not
+    /// outgoing edge then it gives back INVALID.
+    Edge up(Node n) const {
+      UndirEdge ue = _up(n);
+      return ue != INVALID ? direct(ue, false) : INVALID;
+    }
+
+    /// \brief Gives back the edge goes right from the node.
+    ///
+    /// Gives back the edge goes right from the node. If there is not
+    /// outgoing edge then it gives back INVALID.
+    Edge right(Node n) const {
+      UndirEdge ue = _right(n);
+      return ue != INVALID ? direct(ue, true) : INVALID;
+    }
+
+    /// \brief Gives back the edge goes left from the node.
+    ///
+    /// Gives back the edge goes left from the node. If there is not
+    /// outgoing edge then it gives back INVALID.
+    Edge left(Node n) const {
+      UndirEdge ue = _left(n);
+      return ue != INVALID ? direct(ue, false) : INVALID;
+    }
+    
   };
 }
