Matrix interface running time test...
3 #include <lemon/smart_graph.h>
4 #include <lemon/maps.h>
10 struct _BFS_DEFAULT_VIS {};
11 struct _BFS_CUSTOM_VIS {};
16 typedef ListGraph Graph;
23 typedef typename T::Graph Graph;
24 typedef typename T::Reached Reached;
25 typedef typename T::PredNode PredNode;
26 typedef typename T::PredEdge PredEdge;
27 typedef typename T::Priority Priority;
29 typedef typename T::DefaultReachedTag DefaultReachedTag;
31 typedef typename Graph::Node Node;
32 typedef typename Graph::OutEdgeIt OutEdgeIt;
48 Priority &pr) :_graph(g), _source(s),
50 _predNode(pn), _predEdge(pe), _priority(pr) { }
53 int run(const _Bfs_CUSTOM_VIS &)
57 int N=_graph.nodeNum();
62 for(typename Graph::NodeIt n(_graph);n!=INVALID;++n)
63 _visited->set(n,false);
66 _visited->set(_source,true);
70 for(OutEdgeIt e(_graph,n);e!=INVALID;++e)
71 if(!(*_visited)[m=_graph.target(e)]) {
73 _visited->set(m,true);
79 return 1; //Why return 1?
81 int run(const _BFS_DEFAULT_VIS &)
83 _visited= new Reached(_graph);
84 int r = run(_BFS_CUSTOM_VIS());
88 int run() { return run(DefaultReachedTag());}
90 template<class T> _Bfs<Graph,T,_BFS_CUSTOM_VIS,PredNode,PredEdge,Priority>
93 return _Bfs<Graph,T,_BFS_CUSTOM_VIS,PredNode,PredEdge,Priority>
94 (_graph,_source,&t,_predNode,_predEdge,_priority);
98 _Bfs<Graph,Reached,DefaultReachedTag,T,PredEdge,Priority>
101 return _BFS<Graph,Reached,DefaultReachedTag,T,PredEdge,Priority>
104 t,_predEdge,_priority);
108 _BFS<Graph,Reached,DefaultReachedTag,PredNode,T,Priority>
111 return _BFS<Graph,Reached,DefaultReachedTag,PredNode,T,Priority>
114 _predNode,t,_priority);
117 _Bfs<Graph,Reached,DefaultReachedTag,PredNode,PredEdge,Priority>
120 return _Bfs<Graph,Reached,DefaultReachedTag,PredNode,PredEdge,Priority>
123 _predNode,_predEdge,_priority);
130 typename G::template NodeMap<bool>,
132 NullMap<typename G::Node,typename G::Node>,
133 NullMap<typename G::Node,typename G::Edge>,
134 NullMap<typename G::Node,int> >
135 bfs(const G &g,typename G::Node s)
137 // typename G::template NodeMap<bool> v(g);
140 typename G::template NodeMap<bool>,
142 NullMap<typename G::Node,typename G::Node>,
143 NullMap<typename G::Node,typename G::Edge>,
144 NullMap<typename G::Node,int> >
146 (typename G::template NodeMap<bool>*)(NULL),
147 *((NullMap<typename G::Node,typename G::Node>*)(NULL)),
148 *((NullMap<typename G::Node,typename G::Edge> *)(NULL)),
149 *((NullMap<typename G::Node,int> *)(NULL))
154 class MyReachedMap : public SmartGraph::NodeMap<bool>
156 const SmartGraph &_G;
158 MyReachedMap(const SmartGraph &G) : SmartGraph::NodeMap<bool>(G), _G(G) {}
159 void set(SmartGraph::Node n,bool b)
161 SmartGraph::NodeMap<bool>::set(n,b);
162 if(b) std::cout << _G.id(n) << std::endl;
170 SmartGraph::Node s=G.addNode();
171 SmartGraph::Node n1=G.addNode();
172 SmartGraph::Node n2=G.addNode();
173 SmartGraph::Node n3=G.addNode();
174 SmartGraph::Node n4=G.addNode();
175 SmartGraph::Node n5=G.addNode();
176 SmartGraph::Node n6=G.addNode();
177 SmartGraph::Node n7=G.addNode();
179 G.addEdge(s,n1);G.addEdge(s,n3);G.addEdge(n1,n2);G.addEdge(n1,n3);
180 G.addEdge(s,n4);G.addEdge(n4,n7);G.addEdge(n7,n6);G.addEdge(n4,n5);
181 G.addEdge(n7,n2);G.addEdge(n6,n3);G.addEdge(n4,s);G.addEdge(n1,s);
185 SmartGraph::NodeMap<SmartGraph::Node> m(G);
186 SmartGraph::NodeMap<SmartGraph::Edge> em(G);
191 //Runs BFS on graph 'G' from node 's'.
192 //(It practically does nothing, for it throws away its result.)
195 //Runs BFS on graph 'G' from node 's'. Puts the predessor nodes to 'm'.
196 bfs(G,s).setPredNodeMap(m).run();
198 //Runs BFS on graph 'G' from node 's'.
199 //Puts the predessor nodes to 'm' and the edges of the bfs tree to 'em'.
200 bfs(G,s).setPredNodeMap(m).setPredEdgeMap(em).run();
202 //Runs BFS on graph 'G' from node 's'.
203 //It uses a scpecial 'visited map' that prints out the reached nodes.
204 bfs(G,s).setVisitMap(vm).run();