BfsVisit< _Graph, _Visitor, _Traits > Class Template Reference
[Graph Search]


Detailed Description

template<typename _Graph, typename _Visitor, typename _Traits>
class lemon::BfsVisit< _Graph, _Visitor, _Traits >

This class provides an efficient implementation of the BFS algorithm with visitor interface.

The BfsVisit class provides an alternative interface to the Bfs class. It works with callback mechanism, the BfsVisit object calls on every bfs event the Visitor class member functions.

Parameters:
_Graph The graph type the algorithm runs on. The default value is ListGraph. The value of _Graph is not used directly by Bfs, it is only passed to BfsDefaultTraits.
_Visitor The Visitor object for the algorithm. The BfsVisitor<_Graph> is an empty Visitor which does not observe the Bfs events. If you want to observe the bfs events you should implement your own Visitor class.
_Traits Traits class to set various data types used by the algorithm. The default traits class is BfsVisitDefaultTraits<_Graph>. See BfsVisitDefaultTraits for the documentation of a Bfs visit traits class.
Author:
Jacint Szabo, Alpar Juttner and Balazs Dezso
#include <lemon/bfs.h>

List of all members.

Classes

struct  DefReachedMap
class  UninitializedParameter
 Exception for uninitialized parameters. More...

Public Types

typedef Traits::ReachedMap ReachedMap
 The type of the map indicating which nodes are reached.

Public Member Functions

 BfsVisit (const Graph &graph, Visitor &visitor)
 Constructor.
 ~BfsVisit ()
BfsVisitreachedMap (ReachedMap &m)
 Sets the map indicating if a node is reached.
Execution control
The simplest way to execute the algorithm is to use one of the member functions called run(...).
If you need more control on the execution, first you must call init(), then you can adda source node with addSource(). Finally start() will perform the actual path computation.

void init ()
void addSource (Node s)
 Adds a new source node.
Node processNextNode ()
 Processes the next node.
Node processNextNode (Node target, bool &reach)
 Processes the next node.
template<typename NM >
Node processNextNode (const NM &nm, Node &rnode)
 Processes the next node.
Node nextNode ()
 Next node to be processed.
bool emptyQueue ()
 Returns false if there are nodes to be processed in the queue.
int queueSize ()
 Returns the number of the nodes to be processed.
void start ()
 Executes the algorithm.
void start (Node dest)
 Executes the algorithm until dest is reached.
template<typename NM >
Node start (const NM &nm)
 Executes the algorithm until a condition is met.
void run (Node s)
 Runs BFSVisit algorithm from node s.
void run ()
 Runs BFSVisit algorithm to visit all nodes in the graph.
Query Functions
The result of the BFS algorithm can be obtained using these functions.
Before the use of these functions, either run() or start() must be called.

bool reached (Node v)
 Checks if a node is reachable from the root.

Private Member Functions

void create_maps ()

Private Attributes

const Graph * _graph
 Pointer to the underlying graph.
Visitor * _visitor
 Pointer to the visitor object.
ReachedMap_reached
 Pointer to the map of reached status of the nodes.
bool local_reached
 Indicates if _reached is locally allocated (true) or not.


Constructor & Destructor Documentation

BfsVisit ( const Graph &  graph,
Visitor &  visitor 
) [inline]

Constructor.

Parameters:
graph the graph the algorithm will run on.
visitor The visitor of the algorithm.

~BfsVisit (  )  [inline]

Destructor.


Member Function Documentation

void create_maps (  )  [inline, private]

Creates the maps if necessary.

BfsVisit& reachedMap ( ReachedMap m  )  [inline]

Sets the map indicating if a node is reached. If you don't use this function before calling run(), it will allocate one. The destuctor deallocates this automatically allocated map, of course.

Returns:
(*this)

void init (  )  [inline]

Initializes the internal data structures.

void addSource ( Node  s  )  [inline]

Adds a new source node to the set of nodes to be processed.

Node processNextNode (  )  [inline]

Processes the next node.

Returns:
The processed node.
Precondition:
The queue must not be empty!

Node processNextNode ( Node  target,
bool &  reach 
) [inline]

Processes the next node. And checks that the given target node is reached. If the target node is reachable from the processed node then the reached parameter will be set true. The reached parameter should be initially false.

Parameters:
target The target node.
Return values:
reach Indicates that the target node is reached.
Returns:
The processed node.
Warning:
The queue must not be empty!

Node processNextNode ( const NM &  nm,
Node &  rnode 
) [inline]

Processes the next node. And checks that at least one of reached node has true value in the nm node map. If one node with true value is reachable from the processed node then the rnode parameter will be set to the first of such nodes.

Parameters:
nm The node map of possible targets.
Return values:
rnode The reached target node.
Returns:
The processed node.
Warning:
The queue must not be empty!

Node nextNode (  )  [inline]

Next node to be processed.

Returns:
The next node to be processed or INVALID if the stack is empty.

bool emptyQueue (  )  [inline]

Returns false if there are nodes to be processed in the queue

int queueSize (  )  [inline]

Returns the number of the nodes to be processed in the queue.

void start (  )  [inline]

Executes the algorithm.

Precondition:
init() must be called and at least one node should be added with addSource() before using this function.

void start ( Node  dest  )  [inline]

Executes the algorithm until dest is reached.

Precondition:
init() must be called and at least one node should be added with addSource() before using this function.

Node start ( const NM &  nm  )  [inline]

Executes the algorithm until a condition is met.

Precondition:
init() must be called and at least one node should be added with addSource() before using this function.
Parameters:
nm must be a bool (or convertible) node map. The algorithm will stop when it reaches a node v with nm[v] true.
Returns:
The reached node v with nm[v] true or INVALID if no such node was found.

void run ( Node  s  )  [inline]

This method runs the BFS algorithm from a root node s.

Note:
b.run(s) is just a shortcut of the following code.
          b.init();
          b.addSource(s);
          b.start();

void run (  )  [inline]

This method runs the BFS algorithm in order to compute the BFS path to each node. The algorithm computes

  • The BFS tree.
  • The distance of each node from the root in the BFS tree.

Note:
b.run() is just a shortcut of the following code.
         b.init();
         for (NodeIt it(graph); it != INVALID; ++it) {
           if (!b.reached(it)) {
             b.addSource(it);
             b.start();
           }
         }

bool reached ( Node  v  )  [inline]

Returns true if v is reachable from the root(s).

Warning:
The source nodes are inditated as unreachable.
Precondition:
Either run() or start() must be called before using this function.


Generated on Thu Jun 4 04:03:32 2009 for LEMON by  doxygen 1.5.9