Bugfix + working example
authoralpar
Tue, 27 Jul 2004 18:56:10 +0000
changeset 743efab34f23b30
parent 742 235fd36336b7
child 744 7ac96d31280f
Bugfix + working example
src/work/alpar/bfs-named-param.cc
     1.1 --- a/src/work/alpar/bfs-named-param.cc	Tue Jul 27 16:09:42 2004 +0000
     1.2 +++ b/src/work/alpar/bfs-named-param.cc	Tue Jul 27 18:56:10 2004 +0000
     1.3 @@ -3,6 +3,7 @@
     1.4  #include <hugo/smart_graph.h>
     1.5  #include <hugo/maps.h>
     1.6  #include <vector>
     1.7 +#include <iostream>
     1.8  
     1.9  using namespace hugo;
    1.10  
    1.11 @@ -89,29 +90,29 @@
    1.12    }
    1.13  
    1.14    template<class T>
    1.15 -  _BFS<Graph,Visited,_BFS_CUSTOM_VIS,T,PredEdge,Priority>
    1.16 +  _BFS<Graph,Visited,DefaultVisitedTag,T,PredEdge,Priority>
    1.17    setPredNodeMap(T &t)
    1.18    {
    1.19 -    return _BFS<Graph,Visited,_BFS_CUSTOM_VIS,T,PredEdge,Priority>
    1.20 +    return _BFS<Graph,Visited,DefaultVisitedTag,T,PredEdge,Priority>
    1.21        (_graph,_source,
    1.22         _visited,
    1.23         t,_predEdge,_priority);
    1.24    }
    1.25  
    1.26    template<class T>
    1.27 -  _BFS<Graph,Visited,_BFS_CUSTOM_VIS,PredNode,T,Priority>
    1.28 +  _BFS<Graph,Visited,DefaultVisitedTag,PredNode,T,Priority>
    1.29    setPredEdgeMap(T &t)
    1.30    {
    1.31 -    return _BFS<Graph,Visited,_BFS_CUSTOM_VIS,PredNode,T,Priority>
    1.32 +    return _BFS<Graph,Visited,DefaultVisitedTag,PredNode,T,Priority>
    1.33        (_graph,_source,
    1.34         _visited,
    1.35        _predNode,t,_priority);
    1.36    }
    1.37  
    1.38 -  _BFS<Graph,Visited,_BFS_CUSTOM_VIS,PredNode,PredEdge,Priority>
    1.39 +  _BFS<Graph,Visited,DefaultVisitedTag,PredNode,PredEdge,Priority>
    1.40    setNothing()
    1.41    {
    1.42 -    return _BFS<Graph,Visited,_BFS_CUSTOM_VIS,PredNode,PredEdge,Priority>
    1.43 +    return _BFS<Graph,Visited,DefaultVisitedTag,PredNode,PredEdge,Priority>
    1.44        (_graph,_source,
    1.45         _visited,
    1.46         _predNode,_predEdge,_priority);
    1.47 @@ -145,15 +146,49 @@
    1.48  }
    1.49  
    1.50  
    1.51 +class MyVisitedMap : public SmartGraph::NodeMap<bool>
    1.52 +{
    1.53 +  const SmartGraph &_G;
    1.54 +public:
    1.55 +  MyVisitedMap(const SmartGraph &G) : SmartGraph::NodeMap<bool>(G), _G(G) {}
    1.56 +  void set(SmartGraph::Node n,bool b)
    1.57 +  {
    1.58 +    SmartGraph::NodeMap<bool>::set(n,b);
    1.59 +    if(b) std::cout << _G.id(n) << std::endl;
    1.60 +  }
    1.61 +};
    1.62 +
    1.63 +
    1.64  int main()
    1.65  {
    1.66    SmartGraph G;
    1.67 -  SmartGraph::NodeIt n(G);
    1.68 +  SmartGraph::Node s=G.addNode();
    1.69 +  SmartGraph::Node n1=G.addNode();
    1.70 +  SmartGraph::Node n2=G.addNode();
    1.71 +  SmartGraph::Node n3=G.addNode();
    1.72 +  SmartGraph::Node n4=G.addNode();
    1.73 +  SmartGraph::Node n5=G.addNode();
    1.74 +  SmartGraph::Node n6=G.addNode();
    1.75 +  SmartGraph::Node n7=G.addNode();
    1.76 +
    1.77 +  G.addEdge(s,n1);G.addEdge(s,n3);G.addEdge(n1,n2);G.addEdge(n1,n3);
    1.78 +  G.addEdge(s,n4);G.addEdge(n4,n7);G.addEdge(n7,n6);G.addEdge(n4,n5);
    1.79 +  G.addEdge(n7,n2);G.addEdge(n6,n3);G.addEdge(n4,s);G.addEdge(n1,s);
    1.80 +
    1.81 +  
    1.82 +  
    1.83    SmartGraph::NodeMap<SmartGraph::Node> m(G);
    1.84    SmartGraph::NodeMap<SmartGraph::Edge> em(G);
    1.85 -  
    1.86 -  bfs(G,n).run();
    1.87 -  bfs(G,n).setPredNodeMap(m).run();
    1.88 -  bfs(G,n).setPredNodeMap(m).setPredEdgeMap(em).run();
    1.89 +
    1.90 +  MyVisitedMap vm(G);
    1.91 +
    1.92 +
    1.93 +  //bfs(G,n).run(); 
    1.94 +
    1.95 +  bfs(G,s).setPredNodeMap(m).run();
    1.96 +
    1.97 +  bfs(G,s).setPredNodeMap(m).setPredEdgeMap(em).run();
    1.98 +
    1.99 +  bfs(G,s).setVisitMap(vm).run();
   1.100  
   1.101  }