GR is the graph the algorithm runs on. It has \ref lemon::ListGraph "ListGraph" as default type. TR is a Traits class commonly used to easy the parametrization of templates. In most cases you wont need to modify the default type \ref lemon::BfsDefaultTraits "BfsDefaultTraits

If you want the shortest path from a specified node to all other node, just write: \code bfs.run(s); \endcode Now the distances and path information are stored in maps which you can access with member functions like \ref lemon::Bfs::distMap "distMap()" or \ref lemon::Bfs::predMap "predMap()".

Or more directly whit other member functions like \c predNode(). Once the algorithm is finished (or to be precise reached that node) \ref lemon::Bfs::dist "dist()" or \ref lemon::Bfs::predNode "predNode()" can be called. For an example let's say we want to print the shortest path of those nodes which are in a certain distance. \code bfs.run(s); for( ListUGraph::NodeIt n(gr); n != INVALID; ++n ) { if( bfs.reached(n) && bfs.dist(n) <= max_dist ) { std::cout << gr.id(n); Node prev = bfs.prevNode(n); while( prev != INVALID ) { std::cout << "<-" << gr.id(prev); prev = bfs.prevNode(n); } std::cout << std::endl; } } \endcode \subsubsection bfs_adv_control Advanced control In the previous code we only used \c run(). Now we introduce the way you can directly control the execution of the algorithm. First you have to initialize the variables with \ref lemon::Bfs::init "init()". \code bfs.init(); \endcode Then you add one or more source nodes to the queue. They will be processed, as they would be reached by the algorithm before. And yes - you can add more sources during the execution. \code bfs.addSource(node_1); bfs.addSource(node_2); ... \endcode And finally you can start the process with \ref lemon::Bfs::start "start()", or you can write your own loop to process the nodes one-by-one. \todo demo for bfs advanced control \subsection Dfs Since Dfs is very similar to Bfs with a few tiny differences we only see a bit more complex example to demonstrate Dfs's capabilities. We will see a program, which solves the problem of

- We run the dfs algorithm to all nodes.
- Put every node into a list when processed completely.
- Write out the list in reverse order.

Although we implemented this needed helper class ourselves it was not necessary. The \ref lemon::FrontInserterBoolMap "FrontInserterBoolMap" class does exactly what we needed. To be correct it's more general - and it's all in \c LEMON. But we wanted to show you, how easy is to add additional functionality. First we declare the needed data structures: the graph and a map to store the nodes' label. \skip ListGraph \until label Now we build a graph. But keep in mind that it must be DAG because cyclic graphs has no topological ordering. \skip belt \until trousers We label them... \skip label \until trousers Then add directed edges which represent the precedences between those items. \skip trousers, belt \until ); See how easy is to access the internal information of this algorithm trough maps. We only need to set our own map as the class's \ref lemon::Dfs::ProcessedMap "ProcessedMap". \skip Dfs \until run And now comes the third part. Write out the list in reverse order. But the list was composed in reverse way (with \c push_front() instead of \c push_back() so we just iterate it. \skip std \until endl The program is to be found in the \ref demo directory: \ref topological_ordering.cc More algorithms are described in the \ref algorithms2 "second part". */ }