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.
_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. |
#include <lemon/bfs.h>
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 () | |
BfsVisit & | reachedMap (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 | |
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. |
BfsVisit | ( | const Graph & | graph, | |
Visitor & | visitor | |||
) | [inline] |
Constructor.
graph | the graph the algorithm will run on. | |
visitor | The visitor of the algorithm. |
~BfsVisit | ( | ) | [inline] |
Destructor.
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.
(*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.
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.
target | The target node. |
reach | Indicates that the target node is reached. |
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.
nm | The node map of possible targets. |
rnode | The reached target node. |
Node nextNode | ( | ) | [inline] |
Next node to be processed.
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.
void start | ( | Node | dest | ) | [inline] |
Executes the algorithm until dest
is reached.
Node start | ( | const NM & | nm | ) | [inline] |
Executes the algorithm until a condition is met.
nm | must be a bool (or convertible) node map. The algorithm will stop when it reaches a node v with nm[v] true. |
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
.
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
b.init(); for (NodeIt it(graph); it != INVALID; ++it) { if (!b.reached(it)) { b.addSource(it); b.start(); } }
bool reached | ( | Node | v | ) | [inline] |