One more step toward the standars interface.
4 Performs a bfs on the out edges. It does not count predecessors,
5 only the distances, but one can easily modify it to know the pred as well.
9 reverse_bfs(graph_type& G, node_iterator t)
15 void run(): runs a reverse bfs from t
17 The following function should be used after run() was already run.
19 int dist(node_iterator v) : returns the distance from v to t. It is the number of nodes if t is not reachable from v.
22 #ifndef REVERSE_BFS_HH
23 #define REVERSE_BFS_HH
27 //#include <marci_list_graph.hh>
28 //#include <marci_property_vector.hh>
34 template <typename graph_type>
37 typedef typename graph_type::NodeIt NodeIt;
38 typedef typename graph_type::EdgeIt EdgeIt;
39 typedef typename graph_type::EachNodeIt EachNodeIt;
40 typedef typename graph_type::EachEdgeIt EachEdgeIt;
41 typedef typename graph_type::OutEdgeIt OutEdgeIt;
42 typedef typename graph_type::InEdgeIt InEdgeIt;
43 typedef typename graph_type::SymEdgeIt SymEdgeIt;
49 // node_property_vector<graph_type, edge_iterator> pred;
50 //node_property_vector<graph_type, int>
51 typename graph_type::NodeMap<int> distance;
57 The distance of the nodes is n, except t for which it is 0.
59 reverse_bfs(graph_type& _G, NodeIt _t) :
61 distance(G, G.nodeNum()) {
67 //node_property_vector<graph_type, bool>
68 typename graph_type::NodeMap<bool> reached(G, false);
71 std::queue<NodeIt> bfs_queue;
74 while (!bfs_queue.empty()) {
76 NodeIt v=bfs_queue.front();
79 for(InEdgeIt e=G.template first<InEdgeIt>(v); e.valid(); ++e) {
81 if (!reached.get(w)) {
83 distance.set(w, distance.get(v)+1);
93 return distance.get(v);
101 #endif //REVERSE_BFS_HH