M?g ?rtam bele 2 dolgot, meg a tesztelot is kibovitettem.
6 #include <list_graph.h>
7 #include <smart_graph.h>
8 #include <bfs_iterator.h>
9 #include <graph_wrapper.h>
16 template <typename Graph, typename NodeNameMap>
19 NodeNameMap& node_name_map;
21 EdgeNameMap(Graph& _graph, NodeNameMap& _node_name_map) :
22 graph(_graph), node_name_map(_node_name_map) { }
23 string get(typename Graph::Edge e) const {
25 (node_name_map.get(graph.tail(e))+"->"+node_name_map.get(graph.head(e)));
29 int main (int, char*[])
31 //typedef SmartGraph Graph;
32 typedef ListGraph Graph;
34 typedef Graph::Node Node;
35 typedef Graph::Edge Edge;
36 //typedef Graph::NodeIt NodeIt;
37 //typedef Graph::EdgeIt EdgeIt;
38 //typedef Graph::OutEdgeIt OutEdgeIt;
39 //typedef Graph::InEdgeIt InEdgeIt;
40 //typedef Graph::SymEdgeIt SymEdgeIt;
51 Graph::NodeMap<string> node_name(G);
52 node_name.set(s, "s");
53 node_name.set(v1, "v1");
54 node_name.set(v2, "v2");
55 node_name.set(v3, "v3");
56 node_name.set(v4, "v4");
57 node_name.set(t, "t");
70 cout << " /--> -------------> "<< endl;
71 cout << " / /-- v1 <-\\ /---- v3-\\ "<< endl;
72 cout << " / | | / /-> \\ "<< endl;
73 cout << " / | | / | ^ \\ "<< endl;
74 cout << "s | | / | | \\-> t "<< endl;
75 cout << " \\ | | / | | /-> "<< endl;
76 cout << " \\ | --/ / | | / "<< endl;
77 cout << " \\ \\-> v2 <--/ \\-- v4 -/ "<< endl;
78 cout << " \\--> -------------> "<< endl;
80 // typedef TrivGraphWrapper<const Graph> CGW;
83 // cout << "bfs and dfs demo on the directed graph" << endl;
84 // for(CGW::NodeIt n=wG.first<CGW::NodeIt>(); n.valid(); ++n) {
86 // cout << "out edges: ";
87 // for(CGW::OutEdgeIt e=wG.first<CGW::OutEdgeIt>(n); e.valid(); ++e)
89 // cout << "in edges: ";
90 // for(CGW::InEdgeIt e=wG.first<CGW::InEdgeIt>(n); e.valid(); ++e)
96 typedef TrivGraphWrapper<const Graph> GW;
99 EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(wG, node_name);
101 cout << "bfs and dfs iterator demo on the directed graph" << endl;
102 for(GW::NodeIt n=wG.first<GW::NodeIt>(); wG.valid(n); wG.next(n)) {
103 cout << node_name.get(n) << ": ";
104 cout << "out edges: ";
105 for(GW::OutEdgeIt e=wG.first<GW::OutEdgeIt>(n); wG.valid(e); wG.next(e))
106 cout << edge_name.get(e) << " ";
107 cout << "in edges: ";
108 for(GW::InEdgeIt e=wG.first<GW::InEdgeIt>(n); wG.valid(e); wG.next(e))
109 cout << edge_name.get(e) << " ";
113 cout << "bfs from s ..." << endl;
114 BfsIterator5< GW, GW::NodeMap<bool> > bfs(wG);
115 bfs.pushAndSetReached(s);
116 while (!bfs.finished()) {
119 cout << edge_name.get(bfs) << /*endl*/", " <<
120 /*" aNode: " <<*/ node_name.get(wG.aNode(bfs)) <<
121 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
122 /*" bNode: " <<*/ node_name.get(wG.bNode(bfs)) <<
123 (bfs.isBNodeNewlyReached() ? ": is newly reached." :
124 ": is not newly reached.");
126 cout << "invalid" << /*endl*/", " <<
127 /*" aNode: " <<*/ node_name.get(bfs.aNode()) <<
128 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
136 cout << " /--> -------------> "<< endl;
137 cout << " / /-- v1 <-\\ /---- v3-\\ "<< endl;
138 cout << " / | | / /-> \\ "<< endl;
139 cout << " / | | / | ^ \\ "<< endl;
140 cout << "s | | / | | \\-> t "<< endl;
141 cout << " \\ | | / | | /-> "<< endl;
142 cout << " \\ | --/ / | | / "<< endl;
143 cout << " \\ \\-> v2 <--/ \\-- v4 -/ "<< endl;
144 cout << " \\--> -------------> "<< endl;
146 cout << "dfs from s ..." << endl;
147 DfsIterator5< GW, GW::NodeMap<bool> > dfs(wG);
148 dfs.pushAndSetReached(s);
149 while (!dfs.finished()) {
153 cout << edge_name.get(dfs) << /*endl*/", " <<
154 /*" aNode: " <<*/ node_name.get(wG.aNode(dfs)) <<
155 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
156 /*" bNode: " <<*/ node_name.get(wG.bNode(dfs)) <<
157 (dfs.isBNodeNewlyReached() ? ": is newly reached." :
158 ": is not newly reached.");
160 cout << "invalid" << /*endl*/", " <<
161 /*" aNode: " <<*/ node_name.get(dfs.aNode()) <<
162 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
172 typedef RevGraphWrapper<const Graph> GW;
175 EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(wG, node_name);
177 cout << "bfs and dfs iterator demo on the reversed directed graph" << endl;
178 for(GW::NodeIt n=wG.first<GW::NodeIt>(); wG.valid(n); wG.next(n)) {
179 cout << node_name.get(n) << ": ";
180 cout << "out edges: ";
181 for(GW::OutEdgeIt e=wG.first<GW::OutEdgeIt>(n); wG.valid(e); wG.next(e))
182 cout << edge_name.get(e) << " ";
183 cout << "in edges: ";
184 for(GW::InEdgeIt e=wG.first<GW::InEdgeIt>(n); wG.valid(e); wG.next(e))
185 cout << edge_name.get(e) << " ";
189 cout << "bfs from t ..." << endl;
190 BfsIterator5< GW, GW::NodeMap<bool> > bfs(wG);
191 bfs.pushAndSetReached(t);
192 while (!bfs.finished()) {
195 cout << edge_name.get(bfs) << /*endl*/", " <<
196 /*" aNode: " <<*/ node_name.get(wG.aNode(bfs)) <<
197 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
198 /*" bNode: " <<*/ node_name.get(wG.bNode(bfs)) <<
199 (bfs.isBNodeNewlyReached() ? ": is newly reached." :
200 ": is not newly reached.");
202 cout << "invalid" << /*endl*/", " <<
203 /*" aNode: " <<*/ node_name.get(bfs.aNode()) <<
204 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
212 cout << " /--> -------------> "<< endl;
213 cout << " / /-- v1 <-\\ /---- v3-\\ "<< endl;
214 cout << " / | | / /-> \\ "<< endl;
215 cout << " / | | / | ^ \\ "<< endl;
216 cout << "s | | / | | \\-> t "<< endl;
217 cout << " \\ | | / | | /-> "<< endl;
218 cout << " \\ | --/ / | | / "<< endl;
219 cout << " \\ \\-> v2 <--/ \\-- v4 -/ "<< endl;
220 cout << " \\--> -------------> "<< endl;
222 cout << "dfs from t ..." << endl;
223 DfsIterator5< GW, GW::NodeMap<bool> > dfs(wG);
224 dfs.pushAndSetReached(t);
225 while (!dfs.finished()) {
229 cout << edge_name.get(dfs) << /*endl*/", " <<
230 /*" aNode: " <<*/ node_name.get(wG.aNode(dfs)) <<
231 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
232 /*" bNode: " <<*/ node_name.get(wG.bNode(dfs)) <<
233 (dfs.isBNodeNewlyReached() ? ": is newly reached." :
234 ": is not newly reached.");
236 cout << "invalid" << /*endl*/", " <<
237 /*" aNode: " <<*/ node_name.get(dfs.aNode()) <<
238 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
247 typedef UndirGraphWrapper<const Graph> GW;
250 EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(wG, node_name);
252 cout << "bfs and dfs iterator demo on the undirected graph" << endl;
253 for(GW::NodeIt n=wG.first<GW::NodeIt>(); wG.valid(n); wG.next(n)) {
254 cout << node_name.get(n) << ": ";
255 cout << "out edges: ";
256 for(GW::OutEdgeIt e=wG.first<GW::OutEdgeIt>(n); wG.valid(e); wG.next(e))
257 cout << edge_name.get(e) << " ";
258 cout << "in edges: ";
259 for(GW::InEdgeIt e=wG.first<GW::InEdgeIt>(n); wG.valid(e); wG.next(e))
260 cout << edge_name.get(e) << " ";
264 cout << "bfs from t ..." << endl;
265 BfsIterator5< GW, GW::NodeMap<bool> > bfs(wG);
266 bfs.pushAndSetReached(t);
267 while (!bfs.finished()) {
269 if (wG.valid(GW::OutEdgeIt(bfs))) {
270 cout << edge_name.get(GW::OutEdgeIt(bfs)) << /*endl*/", " <<
271 /*" aNode: " <<*/ node_name.get(wG.aNode(bfs)) <<
272 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
273 /*" bNode: " <<*/ node_name.get(wG.bNode(bfs)) <<
274 (bfs.isBNodeNewlyReached() ? ": is newly reached." :
275 ": is not newly reached.");
277 cout << "invalid" << /*endl*/", " <<
278 /*" aNode: " <<*/ node_name.get(bfs.aNode()) <<
279 (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
287 cout << " /--> -------------> "<< endl;
288 cout << " / /-- v1 <-\\ /---- v3-\\ "<< endl;
289 cout << " / | | / /-> \\ "<< endl;
290 cout << " / | | / | ^ \\ "<< endl;
291 cout << "s | | / | | \\-> t "<< endl;
292 cout << " \\ | | / | | /-> "<< endl;
293 cout << " \\ | --/ / | | / "<< endl;
294 cout << " \\ \\-> v2 <--/ \\-- v4 -/ "<< endl;
295 cout << " \\--> -------------> "<< endl;
297 cout << "dfs from t ..." << endl;
298 DfsIterator5< GW, GW::NodeMap<bool> > dfs(wG);
299 dfs.pushAndSetReached(t);
300 while (!dfs.finished()) {
303 if (wG.valid(GW::OutEdgeIt(dfs))) {
304 cout << edge_name.get(GW::OutEdgeIt(dfs)) << /*endl*/", " <<
305 /*" aNode: " <<*/ node_name.get(wG.aNode(dfs)) <<
306 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
307 /*" bNode: " <<*/ node_name.get(wG.bNode(dfs)) <<
308 (dfs.isBNodeNewlyReached() ? ": is newly reached." :
309 ": is not newly reached.");
311 cout << "invalid" << /*endl*/", " <<
312 /*" aNode: " <<*/ node_name.get(dfs.aNode()) <<
313 (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<