setInvalid() functions added.
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, NodeIt 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(NodeIt 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_graph_traits.hh>
28 #include <marciMap.hh>
34 template <typename graph_type>
36 typedef typename graph_traits<graph_type>::NodeIt NodeIt;
37 //typedef typename graph_traits<graph_type>::EdgeIt EdgeIt;
38 typedef typename graph_traits<graph_type>::EachNodeIt EachNodeIt;
39 typedef typename graph_traits<graph_type>::InEdgeIt InEdgeIt;
44 // NodeMap<graph_type, EdgeIt> pred;
45 NodeMap<graph_type, int> distance;
51 The distance of the Nodes is n, except t for which it is 0.
53 reverse_bfs(graph_type& _G, NodeIt _t) : G(_G), t(_t), distance(G, number_of(G.first_Node())) {
59 NodeMap<graph_type, bool> reached(G, false);
62 std::queue<NodeIt> bfs_queue;
65 while (!bfs_queue.empty()) {
67 NodeIt v=bfs_queue.front();
70 for(InEdgeIt e=G.template first<InEdgeIt>(v); e.valid(); ++e) {
72 if (!reached.get(w)) {
74 distance.put(w, distance.get(v)+1);
84 return distance.get(v);
92 #endif //REVERSE_BFS_HH