src/work/marci/iterator_bfs_demo.cc
changeset 338 e8725f30dd98
parent 312 54e07057eb47
child 360 91fba31268d6
equal deleted inserted replaced
2:f0a76c519d2b 3:3fdd1b517611
   166     
   166     
   167     EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
   167     EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
   168     
   168     
   169     cout << "bfs and dfs iterator demo on the reversed directed graph" << endl;
   169     cout << "bfs and dfs iterator demo on the reversed directed graph" << endl;
   170     for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 
   170     for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 
   171       cout << node_name[n] << ": ";
   171       cout << node_name[GW::Node(n)] << ": ";
   172       cout << "out edges: ";
   172       cout << "out edges: ";
   173       for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
   173       for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
   174 	cout << edge_name[e] << " ";
   174 	cout << edge_name[e] << " ";
   175       cout << "in edges: ";
   175       cout << "in edges: ";
   176       for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
   176       for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
   181     cout << "bfs from t ..." << endl;
   181     cout << "bfs from t ..." << endl;
   182     BfsIterator5< GW, GW::NodeMap<bool> > bfs(gw);
   182     BfsIterator5< GW, GW::NodeMap<bool> > bfs(gw);
   183     bfs.pushAndSetReached(t);
   183     bfs.pushAndSetReached(t);
   184     while (!bfs.finished()) {
   184     while (!bfs.finished()) {
   185       //cout << "edge: ";
   185       //cout << "edge: ";
   186       if (gw.valid(bfs)) {
   186       if (gw.valid(GW::OutEdgeIt(bfs))) {
   187 	cout << edge_name[bfs] << /*endl*/", " << 
   187 	cout << edge_name[GW::OutEdgeIt(bfs)] << /*endl*/", " << 
   188 	  node_name[gw.aNode(bfs)] << 
   188 	  node_name[gw.aNode(bfs)] << 
   189 	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
   189 	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
   190 	  node_name[gw.bNode(bfs)] << 
   190 	  node_name[gw.bNode(bfs)] << 
   191 	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
   191 	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
   192 	   ": is not newly reached.");
   192 	   ": is not newly reached.");
   215     DfsIterator5< GW, GW::NodeMap<bool> > dfs(gw);
   215     DfsIterator5< GW, GW::NodeMap<bool> > dfs(gw);
   216     dfs.pushAndSetReached(t);
   216     dfs.pushAndSetReached(t);
   217     while (!dfs.finished()) {
   217     while (!dfs.finished()) {
   218       ++dfs;
   218       ++dfs;
   219       //cout << "edge: ";
   219       //cout << "edge: ";
   220       if (gw.valid(dfs)) {
   220       if (gw.valid(GW::OutEdgeIt(dfs))) {
   221 	cout << edge_name[dfs] << /*endl*/", " << 
   221 	cout << edge_name[GW::OutEdgeIt(dfs)] << /*endl*/", " << 
   222 	  node_name[gw.aNode(dfs)] << 
   222 	  node_name[gw.aNode(dfs)] << 
   223 	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
   223 	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
   224 	  node_name[gw.bNode(dfs)] << 
   224 	  node_name[gw.bNode(dfs)] << 
   225 	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
   225 	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
   226 	   ": is not newly reached.");
   226 	   ": is not newly reached.");
   234       cout << endl;
   234       cout << endl;
   235     }
   235     }
   236   }
   236   }
   237 
   237 
   238   {
   238   {
   239     //typedef UndirGraphWrapper<const Graph> GW;
       
   240     typedef UndirGraphWrapper<const Graph> GW;
   239     typedef UndirGraphWrapper<const Graph> GW;
   241     GW gw(G);
   240     GW gw(G);
   242     
   241     
   243     EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
   242     EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
   244     
   243     
   245     cout << "bfs and dfs iterator demo on the undirected graph" << endl;
   244     cout << "bfs and dfs iterator demo on the undirected graph" << endl;
   246     for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 
   245     for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 
   247       cout << node_name[n] << ": ";
   246       cout << node_name[GW::Node(n)] << ": ";
   248       cout << "out edges: ";
   247       cout << "out edges: ";
   249       for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
   248       for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
   250 	cout << edge_name[e] << " ";
   249 	cout << edge_name[e] << " ";
   251       cout << "in edges: ";
   250       cout << "in edges: ";
   252       for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
   251       for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e))