dai::GraphAL Class Reference

Represents the neighborhood structure of nodes in an undirected graph. More...

#include <dai/graph.h>

List of all members.

Public Types

typedef std::vector< NeighborNeighbors
 Describes the neighbors of some node.
typedef std::pair< size_t, size_t > Edge
 Represents an edge: an Edge(n1,n2) corresponds to the edge between node n1 and node n2.

Public Member Functions

Constructors and destructors
 GraphAL ()
 Default constructor (creates an empty graph).
 GraphAL (size_t nr)
 Constructs GraphAL with nr nodes and no edges.
template<typename EdgeInputIterator>
 GraphAL (size_t nr, EdgeInputIterator begin, EdgeInputIterator end)
 Constructs GraphAL from a range of edges.
Accessors and mutators
const Neighbornb (size_t n1, size_t _n2) const
 Returns constant reference to the _n2 'th neighbor of node n1.
Neighbornb (size_t n1, size_t _n2)
 Returns reference to the _n2 'th neighbor of node n1.
const Neighborsnb (size_t n) const
 Returns constant reference to all neighbors of node n.
Neighborsnb (size_t n)
 Returns reference to all neighbors of node n.
Adding nodes and edges
template<typename EdgeInputIterator>
void construct (size_t nr, EdgeInputIterator begin, EdgeInputIterator end)
 (Re)constructs GraphAL from a range of edges.
size_t addNode ()
 Adds a node without neighbors and returns the index of the added node.
template<typename NodeInputIterator>
size_t addNode (NodeInputIterator begin, NodeInputIterator end, size_t sizeHint=0)
 Adds a node, with neighbors specified by a range of nodes.
void addEdge (size_t n1, size_t n2, bool check=true)
 Adds an edge between node n1 and node n2.
Erasing nodes and edges
void eraseNode (size_t n)
 Removes node n and all incident edges; indices of other nodes are changed accordingly.
void eraseEdge (size_t n1, size_t n2)
 Removes edge between node n1 and node n2.
Queries
size_t nrNodes () const
 Returns number of nodes.
size_t nrEdges () const
 Calculates the number of edges, time complexity: O(nrNodes()).
bool isConnected () const
 Returns true if the graph is connected.
bool isTree () const
 Returns true if the graph is a tree, i.e., if it is singly connected and connected.
void checkConsistency () const
 Checks internal consistency.
Input and output
void printDot (std::ostream &os) const
 Writes this GraphAL to an output stream in GraphALViz .dot syntax.

Private Types

typedef std::vector< size_t > levelType
 Used internally by isTree().

Private Attributes

std::vector< Neighbors_nb
 Contains for each node a vector of its neighbors.

Classes

struct  Neighbor
 Describes the neighbor relationship of two nodes in a GraphAL. More...


Detailed Description

Represents the neighborhood structure of nodes in an undirected graph.

A graph has nodes connected by edges. Nodes are indexed by an unsigned integer. If there are nrNodes() nodes, they are numbered 0,1,2,...,nrNodes()-1. An edge between node n1 and node n2 is represented by a GraphAL::Edge(n1,n2).

GraphAL is implemented as a sparse adjacency list, i.e., it stores for each node a list of its neighboring nodes. The list of neighboring nodes is implemented as a vector of Neighbor structures (accessible by the nb() method). Thus, each node has an associated variable of type GraphAL::Neighbors, which is a vector of Neighbor structures, describing its neighboring nodes.


Member Typedef Documentation

typedef std::vector<Neighbor> dai::GraphAL::Neighbors

Describes the neighbors of some node.

typedef std::pair<size_t,size_t> dai::GraphAL::Edge

Represents an edge: an Edge(n1,n2) corresponds to the edge between node n1 and node n2.

typedef std::vector<size_t> dai::GraphAL::levelType [private]

Used internally by isTree().


Constructor & Destructor Documentation

dai::GraphAL::GraphAL (  )  [inline]

Default constructor (creates an empty graph).

dai::GraphAL::GraphAL ( size_t  nr  )  [inline]

Constructs GraphAL with nr nodes and no edges.

template<typename EdgeInputIterator>
dai::GraphAL::GraphAL ( size_t  nr,
EdgeInputIterator  begin,
EdgeInputIterator  end 
) [inline]

Constructs GraphAL from a range of edges.

Template Parameters:
EdgeInputIterator Iterator that iterates over instances of GraphAL::Edge.
Parameters:
nr The number of nodes.
begin Points to the first edge.
end Points just beyond the last edge.


Member Function Documentation

const Neighbor& dai::GraphAL::nb ( size_t  n1,
size_t  _n2 
) const [inline]

Returns constant reference to the _n2 'th neighbor of node n1.

Neighbor& dai::GraphAL::nb ( size_t  n1,
size_t  _n2 
) [inline]

Returns reference to the _n2 'th neighbor of node n1.

const Neighbors& dai::GraphAL::nb ( size_t  n  )  const [inline]

Returns constant reference to all neighbors of node n.

Neighbors& dai::GraphAL::nb ( size_t  n  )  [inline]

Returns reference to all neighbors of node n.

template<typename EdgeInputIterator>
void dai::GraphAL::construct ( size_t  nr,
EdgeInputIterator  begin,
EdgeInputIterator  end 
) [inline]

(Re)constructs GraphAL from a range of edges.

Template Parameters:
EdgeInputIterator Iterator that iterates over instances of GraphAL::Edge.
Parameters:
nr The number of nodes.
begin Points to the first edge.
end Points just beyond the last edge.

size_t dai::GraphAL::addNode (  )  [inline]

Adds a node without neighbors and returns the index of the added node.

template<typename NodeInputIterator>
size_t dai::GraphAL::addNode ( NodeInputIterator  begin,
NodeInputIterator  end,
size_t  sizeHint = 0 
) [inline]

Adds a node, with neighbors specified by a range of nodes.

Template Parameters:
NodeInputIterator Iterator that iterates over instances of size_t.
Parameters:
begin Points to the first index of the nodes that should become neighbors of the added node.
end Points just beyond the last index of the nodes that should become neighbors of the added node.
sizeHint For improved efficiency, the size of the range may be specified by sizeHint.
Returns:
Index of the added node.

void dai::GraphAL::addEdge ( size_t  n1,
size_t  n2,
bool  check = true 
)

Adds an edge between node n1 and node n2.

If check == true, only adds the edge if it does not exist already.

void dai::GraphAL::eraseNode ( size_t  n  ) 

Removes node n and all incident edges; indices of other nodes are changed accordingly.

void dai::GraphAL::eraseEdge ( size_t  n1,
size_t  n2 
)

Removes edge between node n1 and node n2.

size_t dai::GraphAL::nrNodes (  )  const [inline]

Returns number of nodes.

size_t dai::GraphAL::nrEdges (  )  const [inline]

Calculates the number of edges, time complexity: O(nrNodes()).

bool dai::GraphAL::isConnected (  )  const

Returns true if the graph is connected.

bool dai::GraphAL::isTree (  )  const

Returns true if the graph is a tree, i.e., if it is singly connected and connected.

void dai::GraphAL::checkConsistency (  )  const

Checks internal consistency.

void dai::GraphAL::printDot ( std::ostream &  os  )  const

Writes this GraphAL to an output stream in GraphALViz .dot syntax.


Member Data Documentation

std::vector<Neighbors> dai::GraphAL::_nb [private]

Contains for each node a vector of its neighbors.


The documentation for this class was generated from the following files:

Generated on Thu Feb 11 12:26:05 2010 for libDAI by  doxygen 1.5.5