Classes | Public Member Functions

GridGraph Class Reference


Detailed Description

This class implements a special graph type. The nodes of the graph can be indexed by two integer (i,j) value where i is in the [0..width()-1] range and j is in the [0..height()-1] range. Two nodes are connected in the graph if the indexes differ exactly on one position and exactly one is the difference. The nodes of the graph can be indexed by position with the operator()() function. The positions of the nodes can be get with pos(), col() and row() members. The outgoing arcs can be retrieved with the right(), up(), left() and down() functions, where the bottom-left corner is the origin.

grid_graph.png

A short example about the basic usage:

      GridGraph graph(rows, cols);
      GridGraph::NodeMap<int> val(graph);
      for (int i = 0; i < graph.width(); ++i) {
        for (int j = 0; j < graph.height(); ++j) {
          val[graph(i, j)] = i + j;
        }
      }

This graph type fully conforms to the Graph concept.

#include <lemon/grid_graph.h>

Inherits lemon::GraphExtender< GridGraphBase >.

List of all members.

Classes

class  ColMap
class  IndexMap
class  RowMap

Public Member Functions

 GridGraph (int width, int height)
 Constructor.
void resize (int width, int height)
 Resize the graph.
Node operator() (int i, int j) const
 The node on the given position.
int col (Node n) const
int row (Node n) const
dim2::Point< int > pos (Node n) const
 Gives back the position of the node.
int width () const
int height () const
Arc right (Node n) const
 Gives back the arc goes right from the node.
Arc left (Node n) const
 Gives back the arc goes left from the node.
Arc up (Node n) const
 Gives back the arc goes up from the node.
Arc down (Node n) const
 Gives back the arc goes down from the node.
IndexMap indexMap () const
 Index map of the grid graph.
RowMap rowMap () const
 Row map of the grid graph.
ColMap colMap () const
 Column map of the grid graph.

Constructor & Destructor Documentation

GridGraph ( int  width,
int  height 
) [inline]

Construct a grid graph with given size.


Member Function Documentation

void resize ( int  width,
int  height 
) [inline]

Resize the graph. The function will fully destroy and rebuild the graph. This cause that the maps of the graph will reallocated automatically and the previous values will be lost.

Node operator() ( int  i,
int  j 
) const [inline]

Gives back the node on the given position.

int col ( Node  n) const [inline]

Gives back the column index of the node.

int row ( Node  n) const [inline]

Gives back the row index of the node.

dim2::Point<int> pos ( Node  n) const [inline]

Gives back the position of the node, ie. the (col,row) pair.

int width ( ) const [inline]

Gives back the number of the columns.

int height ( ) const [inline]

Gives back the number of the rows.

Arc right ( Node  n) const [inline]

Gives back the arc goes right from the node. If there is not outgoing arc then it gives back INVALID.

Arc left ( Node  n) const [inline]

Gives back the arc goes left from the node. If there is not outgoing arc then it gives back INVALID.

Arc up ( Node  n) const [inline]

Gives back the arc goes up from the node. If there is not outgoing arc then it gives back INVALID.

Arc down ( Node  n) const [inline]

Gives back the arc goes down from the node. If there is not outgoing arc then it gives back INVALID.

IndexMap indexMap ( ) const [inline]

Just returns an IndexMap for the grid graph.

RowMap rowMap ( ) const [inline]

Just returns a RowMap for the grid graph.

ColMap colMap ( ) const [inline]

Just returns a ColMap for the grid graph.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines