RevGraphWrapper
authormarci
Mon, 22 Mar 2004 16:37:10 +0000
changeset 234348f8fd374ee
parent 233 57ef4fd493d5
child 235 aa50acc936dc
RevGraphWrapper
src/work/iterator_bfs_demo.cc
src/work/marci/graph_wrapper.h
     1.1 --- a/src/work/iterator_bfs_demo.cc	Mon Mar 22 16:07:42 2004 +0000
     1.2 +++ b/src/work/iterator_bfs_demo.cc	Mon Mar 22 16:37:10 2004 +0000
     1.3 @@ -78,55 +78,55 @@
     1.4    cout << "    \\-->    ------------->         "<< endl;
     1.5    
     1.6  //   typedef TrivGraphWrapper<const Graph> CGW;
     1.7 -//   CGW wG(G);
     1.8 +//   CGW gw(G);
     1.9  
    1.10  //   cout << "bfs and dfs demo on the directed graph" << endl;
    1.11 -//   for(CGW::NodeIt n=wG.first<CGW::NodeIt>(); n.valid(); ++n) { 
    1.12 +//   for(CGW::NodeIt n=gw.first<CGW::NodeIt>(); n.valid(); ++n) { 
    1.13  //     cout << n << ": ";
    1.14  //     cout << "out edges: ";
    1.15 -//     for(CGW::OutEdgeIt e=wG.first<CGW::OutEdgeIt>(n); e.valid(); ++e) 
    1.16 +//     for(CGW::OutEdgeIt e=gw.first<CGW::OutEdgeIt>(n); e.valid(); ++e) 
    1.17  //       cout << e << " ";
    1.18  //     cout << "in edges: ";
    1.19 -//     for(CGW::InEdgeIt e=wG.first<CGW::InEdgeIt>(n); e.valid(); ++e) 
    1.20 +//     for(CGW::InEdgeIt e=gw.first<CGW::InEdgeIt>(n); e.valid(); ++e) 
    1.21  //       cout << e << " ";
    1.22  //     cout << endl;
    1.23  //   }
    1.24  
    1.25    {
    1.26      typedef TrivGraphWrapper<const Graph> GW;
    1.27 -    GW wG(G);
    1.28 +    GW gw(G);
    1.29  
    1.30 -    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(wG, node_name);
    1.31 +    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
    1.32      
    1.33      cout << "bfs and dfs iterator demo on the directed graph" << endl;
    1.34 -    for(GW::NodeIt n=wG.first<GW::NodeIt>(); wG.valid(n); wG.next(n)) { 
    1.35 +    for(GW::NodeIt n=gw.first<GW::NodeIt>(); gw.valid(n); gw.next(n)) { 
    1.36        cout << node_name.get(n) << ": ";
    1.37        cout << "out edges: ";
    1.38 -      for(GW::OutEdgeIt e=wG.first<GW::OutEdgeIt>(n); wG.valid(e); wG.next(e)) 
    1.39 +      for(GW::OutEdgeIt e=gw.first<GW::OutEdgeIt>(n); gw.valid(e); gw.next(e)) 
    1.40  	cout << edge_name.get(e) << " ";
    1.41        cout << "in edges: ";
    1.42 -      for(GW::InEdgeIt e=wG.first<GW::InEdgeIt>(n); wG.valid(e); wG.next(e)) 
    1.43 +      for(GW::InEdgeIt e=gw.first<GW::InEdgeIt>(n); gw.valid(e); gw.next(e)) 
    1.44  	cout << edge_name.get(e) << " ";
    1.45        cout << endl;
    1.46      }
    1.47  
    1.48      cout << "bfs from s ..." << endl;
    1.49 -    BfsIterator5< GW, GW::NodeMap<bool> > bfs(wG);
    1.50 +    BfsIterator5< GW, GW::NodeMap<bool> > bfs(gw);
    1.51      bfs.pushAndSetReached(s);
    1.52      while (!bfs.finished()) {
    1.53        //cout << "edge: ";
    1.54 -      if (wG.valid(bfs)) {
    1.55 +      if (gw.valid(bfs)) {
    1.56  	cout << edge_name.get(bfs) << /*endl*/", " << 
    1.57 -	  /*" aNode: " <<*/ node_name.get(wG.aNode(bfs)) << 
    1.58 +	  node_name.get(gw.aNode(bfs)) << 
    1.59  	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
    1.60 -	  /*" bNode: " <<*/ node_name.get(wG.bNode(bfs)) << 
    1.61 +	  node_name.get(gw.bNode(bfs)) << 
    1.62  	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
    1.63  	   ": is not newly reached.");
    1.64        } else { 
    1.65  	cout << "invalid" << /*endl*/", " << 
    1.66 -	  /*" aNode: " <<*/ node_name.get(bfs.aNode()) << 
    1.67 +	  node_name.get(bfs.aNode()) << 
    1.68  	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
    1.69 -	  /*" bNode: " <<*/ 
    1.70 +	  
    1.71  	  "invalid.";
    1.72        }
    1.73        cout << endl;
    1.74 @@ -144,23 +144,23 @@
    1.75      cout << "    \\-->    ------------->         "<< endl;
    1.76  
    1.77      cout << "dfs from s ..." << endl;
    1.78 -    DfsIterator5< GW, GW::NodeMap<bool> > dfs(wG);
    1.79 +    DfsIterator5< GW, GW::NodeMap<bool> > dfs(gw);
    1.80      dfs.pushAndSetReached(s);
    1.81      while (!dfs.finished()) {
    1.82        ++dfs;
    1.83        //cout << "edge: ";
    1.84 -      if (wG.valid(dfs)) {
    1.85 +      if (gw.valid(dfs)) {
    1.86  	cout << edge_name.get(dfs) << /*endl*/", " << 
    1.87 -	  /*" aNode: " <<*/ node_name.get(wG.aNode(dfs)) << 
    1.88 +	  node_name.get(gw.aNode(dfs)) << 
    1.89  	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
    1.90 -	  /*" bNode: " <<*/ node_name.get(wG.bNode(dfs)) << 
    1.91 +	  node_name.get(gw.bNode(dfs)) << 
    1.92  	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
    1.93  	   ": is not newly reached.");
    1.94        } else { 
    1.95  	cout << "invalid" << /*endl*/", " << 
    1.96 -	  /*" aNode: " <<*/ node_name.get(dfs.aNode()) << 
    1.97 +	  node_name.get(dfs.aNode()) << 
    1.98  	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
    1.99 -	  /*" bNode: " <<*/ 
   1.100 +	  
   1.101  	  "invalid.";
   1.102        }
   1.103        cout << endl;
   1.104 @@ -169,40 +169,40 @@
   1.105  
   1.106  
   1.107    {
   1.108 -    typedef RevGraphWrapper<const Graph> GW;
   1.109 -    GW wG(G);
   1.110 +    typedef RevGraphWrapper<const TrivGraphWrapper<const Graph> > GW;
   1.111 +    GW gw(G);
   1.112      
   1.113 -    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(wG, node_name);
   1.114 +    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
   1.115      
   1.116      cout << "bfs and dfs iterator demo on the reversed directed graph" << endl;
   1.117 -    for(GW::NodeIt n=wG.first<GW::NodeIt>(); wG.valid(n); wG.next(n)) { 
   1.118 +    for(GW::NodeIt n=gw.first<GW::NodeIt>(); gw.valid(n); gw.next(n)) { 
   1.119        cout << node_name.get(n) << ": ";
   1.120        cout << "out edges: ";
   1.121 -      for(GW::OutEdgeIt e=wG.first<GW::OutEdgeIt>(n); wG.valid(e); wG.next(e)) 
   1.122 +      for(GW::OutEdgeIt e=gw.first<GW::OutEdgeIt>(n); gw.valid(e); gw.next(e)) 
   1.123  	cout << edge_name.get(e) << " ";
   1.124        cout << "in edges: ";
   1.125 -      for(GW::InEdgeIt e=wG.first<GW::InEdgeIt>(n); wG.valid(e); wG.next(e)) 
   1.126 +      for(GW::InEdgeIt e=gw.first<GW::InEdgeIt>(n); gw.valid(e); gw.next(e)) 
   1.127  	cout << edge_name.get(e) << " ";
   1.128        cout << endl;
   1.129      }
   1.130  
   1.131      cout << "bfs from t ..." << endl;
   1.132 -    BfsIterator5< GW, GW::NodeMap<bool> > bfs(wG);
   1.133 +    BfsIterator5< GW, GW::NodeMap<bool> > bfs(gw);
   1.134      bfs.pushAndSetReached(t);
   1.135      while (!bfs.finished()) {
   1.136        //cout << "edge: ";
   1.137 -      if (wG.valid(bfs)) {
   1.138 +      if (gw.valid(bfs)) {
   1.139  	cout << edge_name.get(bfs) << /*endl*/", " << 
   1.140 -	  /*" aNode: " <<*/ node_name.get(wG.aNode(bfs)) << 
   1.141 +	  node_name.get(gw.aNode(bfs)) << 
   1.142  	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
   1.143 -	  /*" bNode: " <<*/ node_name.get(wG.bNode(bfs)) << 
   1.144 +	  node_name.get(gw.bNode(bfs)) << 
   1.145  	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
   1.146  	   ": is not newly reached.");
   1.147        } else { 
   1.148  	cout << "invalid" << /*endl*/", " << 
   1.149 -	  /*" aNode: " <<*/ node_name.get(bfs.aNode()) << 
   1.150 +	  node_name.get(bfs.aNode()) << 
   1.151  	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
   1.152 -	  /*" bNode: " <<*/ 
   1.153 +	  
   1.154  	  "invalid.";
   1.155        }
   1.156        cout << endl;
   1.157 @@ -220,23 +220,23 @@
   1.158      cout << "    \\-->    ------------->         "<< endl;
   1.159      
   1.160      cout << "dfs from t ..." << endl;
   1.161 -    DfsIterator5< GW, GW::NodeMap<bool> > dfs(wG);
   1.162 +    DfsIterator5< GW, GW::NodeMap<bool> > dfs(gw);
   1.163      dfs.pushAndSetReached(t);
   1.164      while (!dfs.finished()) {
   1.165        ++dfs;
   1.166        //cout << "edge: ";
   1.167 -      if (wG.valid(dfs)) {
   1.168 +      if (gw.valid(dfs)) {
   1.169  	cout << edge_name.get(dfs) << /*endl*/", " << 
   1.170 -	  /*" aNode: " <<*/ node_name.get(wG.aNode(dfs)) << 
   1.171 +	  node_name.get(gw.aNode(dfs)) << 
   1.172  	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
   1.173 -	  /*" bNode: " <<*/ node_name.get(wG.bNode(dfs)) << 
   1.174 +	  node_name.get(gw.bNode(dfs)) << 
   1.175  	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
   1.176  	   ": is not newly reached.");
   1.177        } else { 
   1.178  	cout << "invalid" << /*endl*/", " << 
   1.179 -	  /*" aNode: " <<*/ node_name.get(dfs.aNode()) << 
   1.180 +	  node_name.get(dfs.aNode()) << 
   1.181  	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
   1.182 -	  /*" bNode: " <<*/ 
   1.183 +	  
   1.184  	  "invalid.";
   1.185        }
   1.186        cout << endl;
   1.187 @@ -245,39 +245,39 @@
   1.188  
   1.189    {
   1.190      typedef UndirGraphWrapper<const Graph> GW;
   1.191 -    GW wG(G);
   1.192 +    GW gw(G);
   1.193      
   1.194 -    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(wG, node_name);
   1.195 +    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
   1.196      
   1.197      cout << "bfs and dfs iterator demo on the undirected graph" << endl;
   1.198 -    for(GW::NodeIt n=wG.first<GW::NodeIt>(); wG.valid(n); wG.next(n)) { 
   1.199 +    for(GW::NodeIt n=gw.first<GW::NodeIt>(); gw.valid(n); gw.next(n)) { 
   1.200        cout << node_name.get(n) << ": ";
   1.201        cout << "out edges: ";
   1.202 -      for(GW::OutEdgeIt e=wG.first<GW::OutEdgeIt>(n); wG.valid(e); wG.next(e)) 
   1.203 +      for(GW::OutEdgeIt e=gw.first<GW::OutEdgeIt>(n); gw.valid(e); gw.next(e)) 
   1.204  	cout << edge_name.get(e) << " ";
   1.205        cout << "in edges: ";
   1.206 -      for(GW::InEdgeIt e=wG.first<GW::InEdgeIt>(n); wG.valid(e); wG.next(e)) 
   1.207 +      for(GW::InEdgeIt e=gw.first<GW::InEdgeIt>(n); gw.valid(e); gw.next(e)) 
   1.208  	cout << edge_name.get(e) << " ";
   1.209        cout << endl;
   1.210      }
   1.211  
   1.212      cout << "bfs from t ..." << endl;
   1.213 -    BfsIterator5< GW, GW::NodeMap<bool> > bfs(wG);
   1.214 +    BfsIterator5< GW, GW::NodeMap<bool> > bfs(gw);
   1.215      bfs.pushAndSetReached(t);
   1.216      while (!bfs.finished()) {
   1.217        //cout << "edge: ";
   1.218 -      if (wG.valid(GW::OutEdgeIt(bfs))) {
   1.219 +      if (gw.valid(GW::OutEdgeIt(bfs))) {
   1.220  	cout << edge_name.get(GW::OutEdgeIt(bfs)) << /*endl*/", " << 
   1.221 -	  /*" aNode: " <<*/ node_name.get(wG.aNode(bfs)) << 
   1.222 +	  node_name.get(gw.aNode(bfs)) << 
   1.223  	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
   1.224 -	  /*" bNode: " <<*/ node_name.get(wG.bNode(bfs)) << 
   1.225 +	  node_name.get(gw.bNode(bfs)) << 
   1.226  	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
   1.227  	   ": is not newly reached.");
   1.228        } else { 
   1.229  	cout << "invalid" << /*endl*/", " << 
   1.230 -	  /*" aNode: " <<*/ node_name.get(bfs.aNode()) << 
   1.231 +	  node_name.get(bfs.aNode()) << 
   1.232  	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
   1.233 -	  /*" bNode: " <<*/ 
   1.234 +	  
   1.235  	  "invalid.";
   1.236        }
   1.237        cout << endl;
   1.238 @@ -295,23 +295,23 @@
   1.239      cout << "    \\-->    ------------->         "<< endl;
   1.240      
   1.241      cout << "dfs from t ..." << endl;
   1.242 -    DfsIterator5< GW, GW::NodeMap<bool> > dfs(wG);
   1.243 +    DfsIterator5< GW, GW::NodeMap<bool> > dfs(gw);
   1.244      dfs.pushAndSetReached(t);
   1.245      while (!dfs.finished()) {
   1.246        ++dfs;
   1.247        //cout << "edge: ";
   1.248 -      if (wG.valid(GW::OutEdgeIt(dfs))) {
   1.249 +      if (gw.valid(GW::OutEdgeIt(dfs))) {
   1.250  	cout << edge_name.get(GW::OutEdgeIt(dfs)) << /*endl*/", " << 
   1.251 -	  /*" aNode: " <<*/ node_name.get(wG.aNode(dfs)) << 
   1.252 +	  node_name.get(gw.aNode(dfs)) << 
   1.253  	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
   1.254 -	  /*" bNode: " <<*/ node_name.get(wG.bNode(dfs)) << 
   1.255 +	  node_name.get(gw.bNode(dfs)) << 
   1.256  	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
   1.257  	   ": is not newly reached.");
   1.258        } else { 
   1.259  	cout << "invalid" << /*endl*/", " << 
   1.260 -	  /*" aNode: " <<*/ node_name.get(dfs.aNode()) << 
   1.261 +	  node_name.get(dfs.aNode()) << 
   1.262  	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
   1.263 -	  /*" bNode: " <<*/ 
   1.264 +	  
   1.265  	  "invalid.";
   1.266        }
   1.267        cout << endl;
     2.1 --- a/src/work/marci/graph_wrapper.h	Mon Mar 22 16:07:42 2004 +0000
     2.2 +++ b/src/work/marci/graph_wrapper.h	Mon Mar 22 16:37:10 2004 +0000
     2.3 @@ -240,9 +240,10 @@
     2.4  //     };
     2.5  //   };
     2.6  
     2.7 -  template<typename Graph>
     2.8 +  template<typename /*Graph*/GraphWrapper
     2.9 +  /*=typename GraphWrapperSkeleton< TrivGraphWrapper<Graph>*/ >
    2.10    class RevGraphWrapper : 
    2.11 -    public GraphWrapperSkeleton< TrivGraphWrapper<Graph> > {
    2.12 +    public GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/ {
    2.13    protected:
    2.14      //Graph* graph;
    2.15      
    2.16 @@ -253,13 +254,13 @@
    2.17      //typedef typename Graph::NodeIt NodeIt;
    2.18    
    2.19      //typedef typename Graph::Edge Edge;
    2.20 -    typedef typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::OutEdgeIt InEdgeIt;
    2.21 -    typedef typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::InEdgeIt OutEdgeIt;
    2.22 +    typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::OutEdgeIt InEdgeIt;
    2.23 +    typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::InEdgeIt OutEdgeIt;
    2.24      //typedef typename Graph::SymEdgeIt SymEdgeIt;
    2.25      //typedef typename Graph::EdgeIt EdgeIt;
    2.26  
    2.27      //RevGraphWrapper() : graph(0) { }
    2.28 -    RevGraphWrapper(Graph& _graph) : GraphWrapperSkeleton< TrivGraphWrapper<Graph> >(TrivGraphWrapper<Graph>(_graph)) { }
    2.29 +    RevGraphWrapper(GraphWrapper _gw/*BaseGraph& _graph*/) : GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/(_gw/*TrivGraphWrapper<Graph>(_graph)*/) { }
    2.30      
    2.31      //void setGraph(Graph& _graph) { graph = &_graph; }
    2.32      //Graph& getGraph() const { return (*graph); }
    2.33 @@ -304,22 +305,22 @@
    2.34      //void clear() const { graph->clear(); }
    2.35  
    2.36      template<typename T> class NodeMap : 
    2.37 -      public GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::NodeMap<T> 
    2.38 +      public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T> 
    2.39      { 
    2.40      public:
    2.41 -      NodeMap(const RevGraphWrapper<Graph>& _G) : 
    2.42 -	GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::NodeMap<T>(_G) { }
    2.43 -      NodeMap(const RevGraphWrapper<Graph>& _G, T a) : 
    2.44 -	GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::NodeMap<T>(_G, a) { }
    2.45 +      NodeMap(const RevGraphWrapper<GraphWrapper>& _gw) : 
    2.46 +	GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw) { }
    2.47 +      NodeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) : 
    2.48 +	GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw, a) { }
    2.49      };
    2.50      
    2.51      template<typename T> class EdgeMap : 
    2.52 -      public GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::EdgeMap<T> { 
    2.53 +      public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T> { 
    2.54      public:
    2.55 -      EdgeMap(const RevGraphWrapper<Graph>& _G) : 
    2.56 -	GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::EdgeMap<T>(_G) { }
    2.57 -      EdgeMap(const RevGraphWrapper<Graph>& _G, T a) : 
    2.58 -	GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::EdgeMap<T>(_G, a) { }
    2.59 +      EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw) : 
    2.60 +	GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw) { }
    2.61 +      EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) : 
    2.62 +	GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw, a) { }
    2.63      };
    2.64    };
    2.65