COIN-OR::LEMON - Graph Library

Changeset 234:348f8fd374ee in lemon-0.x for src/work


Ignore:
Timestamp:
03/22/04 17:37:10 (21 years ago)
Author:
marci
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@331
Message:

RevGraphWrapper?

Location:
src/work
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/work/iterator_bfs_demo.cc

    r174 r234  
    7979 
    8080//   typedef TrivGraphWrapper<const Graph> CGW;
    81 //   CGW wG(G);
     81//   CGW gw(G);
    8282
    8383//   cout << "bfs and dfs demo on the directed graph" << endl;
    84 //   for(CGW::NodeIt n=wG.first<CGW::NodeIt>(); n.valid(); ++n) {
     84//   for(CGW::NodeIt n=gw.first<CGW::NodeIt>(); n.valid(); ++n) {
    8585//     cout << n << ": ";
    8686//     cout << "out edges: ";
    87 //     for(CGW::OutEdgeIt e=wG.first<CGW::OutEdgeIt>(n); e.valid(); ++e)
     87//     for(CGW::OutEdgeIt e=gw.first<CGW::OutEdgeIt>(n); e.valid(); ++e)
    8888//       cout << e << " ";
    8989//     cout << "in edges: ";
    90 //     for(CGW::InEdgeIt e=wG.first<CGW::InEdgeIt>(n); e.valid(); ++e)
     90//     for(CGW::InEdgeIt e=gw.first<CGW::InEdgeIt>(n); e.valid(); ++e)
    9191//       cout << e << " ";
    9292//     cout << endl;
     
    9595  {
    9696    typedef TrivGraphWrapper<const Graph> GW;
    97     GW wG(G);
    98 
    99     EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(wG, node_name);
     97    GW gw(G);
     98
     99    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
    100100   
    101101    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)) {
     102    for(GW::NodeIt n=gw.first<GW::NodeIt>(); gw.valid(n); gw.next(n)) {
    103103      cout << node_name.get(n) << ": ";
    104104      cout << "out edges: ";
    105       for(GW::OutEdgeIt e=wG.first<GW::OutEdgeIt>(n); wG.valid(e); wG.next(e))
     105      for(GW::OutEdgeIt e=gw.first<GW::OutEdgeIt>(n); gw.valid(e); gw.next(e))
    106106        cout << edge_name.get(e) << " ";
    107107      cout << "in edges: ";
    108       for(GW::InEdgeIt e=wG.first<GW::InEdgeIt>(n); wG.valid(e); wG.next(e))
     108      for(GW::InEdgeIt e=gw.first<GW::InEdgeIt>(n); gw.valid(e); gw.next(e))
    109109        cout << edge_name.get(e) << " ";
    110110      cout << endl;
     
    112112
    113113    cout << "bfs from s ..." << endl;
    114     BfsIterator5< GW, GW::NodeMap<bool> > bfs(wG);
     114    BfsIterator5< GW, GW::NodeMap<bool> > bfs(gw);
    115115    bfs.pushAndSetReached(s);
    116116    while (!bfs.finished()) {
    117117      //cout << "edge: ";
    118       if (wG.valid(bfs)) {
     118      if (gw.valid(bfs)) {
    119119        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)) <<
     120          node_name.get(gw.aNode(bfs)) <<
     121          (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
     122          node_name.get(gw.bNode(bfs)) <<
    123123          (bfs.isBNodeNewlyReached() ? ": is newly reached." :
    124124           ": is not newly reached.");
    125125      } else {
    126126        cout << "invalid" << /*endl*/", " <<
    127           /*" aNode: " <<*/ node_name.get(bfs.aNode()) <<
    128           (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
    129           /*" bNode: " <<*/
     127          node_name.get(bfs.aNode()) <<
     128          (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
     129         
    130130          "invalid.";
    131131      }
     
    145145
    146146    cout << "dfs from s ..." << endl;
    147     DfsIterator5< GW, GW::NodeMap<bool> > dfs(wG);
     147    DfsIterator5< GW, GW::NodeMap<bool> > dfs(gw);
    148148    dfs.pushAndSetReached(s);
    149149    while (!dfs.finished()) {
    150150      ++dfs;
    151151      //cout << "edge: ";
    152       if (wG.valid(dfs)) {
     152      if (gw.valid(dfs)) {
    153153        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)) <<
     154          node_name.get(gw.aNode(dfs)) <<
     155          (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
     156          node_name.get(gw.bNode(dfs)) <<
    157157          (dfs.isBNodeNewlyReached() ? ": is newly reached." :
    158158           ": is not newly reached.");
    159159      } else {
    160160        cout << "invalid" << /*endl*/", " <<
    161           /*" aNode: " <<*/ node_name.get(dfs.aNode()) <<
    162           (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
    163           /*" bNode: " <<*/
     161          node_name.get(dfs.aNode()) <<
     162          (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
     163         
    164164          "invalid.";
    165165      }
     
    170170
    171171  {
    172     typedef RevGraphWrapper<const Graph> GW;
    173     GW wG(G);
    174    
    175     EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(wG, node_name);
     172    typedef RevGraphWrapper<const TrivGraphWrapper<const Graph> > GW;
     173    GW gw(G);
     174   
     175    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
    176176   
    177177    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)) {
     178    for(GW::NodeIt n=gw.first<GW::NodeIt>(); gw.valid(n); gw.next(n)) {
    179179      cout << node_name.get(n) << ": ";
    180180      cout << "out edges: ";
    181       for(GW::OutEdgeIt e=wG.first<GW::OutEdgeIt>(n); wG.valid(e); wG.next(e))
     181      for(GW::OutEdgeIt e=gw.first<GW::OutEdgeIt>(n); gw.valid(e); gw.next(e))
    182182        cout << edge_name.get(e) << " ";
    183183      cout << "in edges: ";
    184       for(GW::InEdgeIt e=wG.first<GW::InEdgeIt>(n); wG.valid(e); wG.next(e))
     184      for(GW::InEdgeIt e=gw.first<GW::InEdgeIt>(n); gw.valid(e); gw.next(e))
    185185        cout << edge_name.get(e) << " ";
    186186      cout << endl;
     
    188188
    189189    cout << "bfs from t ..." << endl;
    190     BfsIterator5< GW, GW::NodeMap<bool> > bfs(wG);
     190    BfsIterator5< GW, GW::NodeMap<bool> > bfs(gw);
    191191    bfs.pushAndSetReached(t);
    192192    while (!bfs.finished()) {
    193193      //cout << "edge: ";
    194       if (wG.valid(bfs)) {
     194      if (gw.valid(bfs)) {
    195195        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)) <<
     196          node_name.get(gw.aNode(bfs)) <<
     197          (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
     198          node_name.get(gw.bNode(bfs)) <<
    199199          (bfs.isBNodeNewlyReached() ? ": is newly reached." :
    200200           ": is not newly reached.");
    201201      } else {
    202202        cout << "invalid" << /*endl*/", " <<
    203           /*" aNode: " <<*/ node_name.get(bfs.aNode()) <<
    204           (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
    205           /*" bNode: " <<*/
     203          node_name.get(bfs.aNode()) <<
     204          (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
     205         
    206206          "invalid.";
    207207      }
     
    221221   
    222222    cout << "dfs from t ..." << endl;
    223     DfsIterator5< GW, GW::NodeMap<bool> > dfs(wG);
     223    DfsIterator5< GW, GW::NodeMap<bool> > dfs(gw);
    224224    dfs.pushAndSetReached(t);
    225225    while (!dfs.finished()) {
    226226      ++dfs;
    227227      //cout << "edge: ";
    228       if (wG.valid(dfs)) {
     228      if (gw.valid(dfs)) {
    229229        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)) <<
     230          node_name.get(gw.aNode(dfs)) <<
     231          (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
     232          node_name.get(gw.bNode(dfs)) <<
    233233          (dfs.isBNodeNewlyReached() ? ": is newly reached." :
    234234           ": is not newly reached.");
    235235      } else {
    236236        cout << "invalid" << /*endl*/", " <<
    237           /*" aNode: " <<*/ node_name.get(dfs.aNode()) <<
    238           (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
    239           /*" bNode: " <<*/
     237          node_name.get(dfs.aNode()) <<
     238          (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
     239         
    240240          "invalid.";
    241241      }
     
    246246  {
    247247    typedef UndirGraphWrapper<const Graph> GW;
    248     GW wG(G);
    249    
    250     EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(wG, node_name);
     248    GW gw(G);
     249   
     250    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
    251251   
    252252    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)) {
     253    for(GW::NodeIt n=gw.first<GW::NodeIt>(); gw.valid(n); gw.next(n)) {
    254254      cout << node_name.get(n) << ": ";
    255255      cout << "out edges: ";
    256       for(GW::OutEdgeIt e=wG.first<GW::OutEdgeIt>(n); wG.valid(e); wG.next(e))
     256      for(GW::OutEdgeIt e=gw.first<GW::OutEdgeIt>(n); gw.valid(e); gw.next(e))
    257257        cout << edge_name.get(e) << " ";
    258258      cout << "in edges: ";
    259       for(GW::InEdgeIt e=wG.first<GW::InEdgeIt>(n); wG.valid(e); wG.next(e))
     259      for(GW::InEdgeIt e=gw.first<GW::InEdgeIt>(n); gw.valid(e); gw.next(e))
    260260        cout << edge_name.get(e) << " ";
    261261      cout << endl;
     
    263263
    264264    cout << "bfs from t ..." << endl;
    265     BfsIterator5< GW, GW::NodeMap<bool> > bfs(wG);
     265    BfsIterator5< GW, GW::NodeMap<bool> > bfs(gw);
    266266    bfs.pushAndSetReached(t);
    267267    while (!bfs.finished()) {
    268268      //cout << "edge: ";
    269       if (wG.valid(GW::OutEdgeIt(bfs))) {
     269      if (gw.valid(GW::OutEdgeIt(bfs))) {
    270270        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)) <<
     271          node_name.get(gw.aNode(bfs)) <<
     272          (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
     273          node_name.get(gw.bNode(bfs)) <<
    274274          (bfs.isBNodeNewlyReached() ? ": is newly reached." :
    275275           ": is not newly reached.");
    276276      } else {
    277277        cout << "invalid" << /*endl*/", " <<
    278           /*" aNode: " <<*/ node_name.get(bfs.aNode()) <<
    279           (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
    280           /*" bNode: " <<*/
     278          node_name.get(bfs.aNode()) <<
     279          (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
     280         
    281281          "invalid.";
    282282      }
     
    296296   
    297297    cout << "dfs from t ..." << endl;
    298     DfsIterator5< GW, GW::NodeMap<bool> > dfs(wG);
     298    DfsIterator5< GW, GW::NodeMap<bool> > dfs(gw);
    299299    dfs.pushAndSetReached(t);
    300300    while (!dfs.finished()) {
    301301      ++dfs;
    302302      //cout << "edge: ";
    303       if (wG.valid(GW::OutEdgeIt(dfs))) {
     303      if (gw.valid(GW::OutEdgeIt(dfs))) {
    304304        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)) <<
     305          node_name.get(gw.aNode(dfs)) <<
     306          (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
     307          node_name.get(gw.bNode(dfs)) <<
    308308          (dfs.isBNodeNewlyReached() ? ": is newly reached." :
    309309           ": is not newly reached.");
    310310      } else {
    311311        cout << "invalid" << /*endl*/", " <<
    312           /*" aNode: " <<*/ node_name.get(dfs.aNode()) <<
    313           (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
    314           /*" bNode: " <<*/
     312          node_name.get(dfs.aNode()) <<
     313          (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") <<
     314         
    315315          "invalid.";
    316316      }
  • src/work/marci/graph_wrapper.h

    r231 r234  
    241241//   };
    242242
    243   template<typename Graph>
     243  template<typename /*Graph*/GraphWrapper
     244  /*=typename GraphWrapperSkeleton< TrivGraphWrapper<Graph>*/ >
    244245  class RevGraphWrapper :
    245     public GraphWrapperSkeleton< TrivGraphWrapper<Graph> > {
     246    public GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/ {
    246247  protected:
    247248    //Graph* graph;
     
    254255 
    255256    //typedef typename Graph::Edge Edge;
    256     typedef typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::OutEdgeIt InEdgeIt;
    257     typedef typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::InEdgeIt OutEdgeIt;
     257    typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::OutEdgeIt InEdgeIt;
     258    typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::InEdgeIt OutEdgeIt;
    258259    //typedef typename Graph::SymEdgeIt SymEdgeIt;
    259260    //typedef typename Graph::EdgeIt EdgeIt;
    260261
    261262    //RevGraphWrapper() : graph(0) { }
    262     RevGraphWrapper(Graph& _graph) : GraphWrapperSkeleton< TrivGraphWrapper<Graph> >(TrivGraphWrapper<Graph>(_graph)) { }
     263    RevGraphWrapper(GraphWrapper _gw/*BaseGraph& _graph*/) : GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/(_gw/*TrivGraphWrapper<Graph>(_graph)*/) { }
    263264   
    264265    //void setGraph(Graph& _graph) { graph = &_graph; }
     
    305306
    306307    template<typename T> class NodeMap :
    307       public GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::NodeMap<T>
     308      public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>
    308309    {
    309310    public:
    310       NodeMap(const RevGraphWrapper<Graph>& _G) :
    311         GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::NodeMap<T>(_G) { }
    312       NodeMap(const RevGraphWrapper<Graph>& _G, T a) :
    313         GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::NodeMap<T>(_G, a) { }
     311      NodeMap(const RevGraphWrapper<GraphWrapper>& _gw) :
     312        GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw) { }
     313      NodeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) :
     314        GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw, a) { }
    314315    };
    315316   
    316317    template<typename T> class EdgeMap :
    317       public GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::EdgeMap<T> {
    318     public:
    319       EdgeMap(const RevGraphWrapper<Graph>& _G) :
    320         GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::EdgeMap<T>(_G) { }
    321       EdgeMap(const RevGraphWrapper<Graph>& _G, T a) :
    322         GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::EdgeMap<T>(_G, a) { }
     318      public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T> {
     319    public:
     320      EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw) :
     321        GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw) { }
     322      EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) :
     323        GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw, a) { }
    323324    };
    324325  };
Note: See TracChangeset for help on using the changeset viewer.