COIN-OR::LEMON - Graph Library

Changeset 775:e46a1f0623a0 in lemon-0.x for src/hugo/graph_wrapper.h


Ignore:
Timestamp:
08/31/04 13:26:59 (20 years ago)
Author:
marci
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1068
Message:

ResGraphWrapper?<Graph> is done, so does dimacs.h.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/hugo/graph_wrapper.h

    r774 r775  
    348348  };
    349349
     350
     351
    350352  /// A graph wrapper for hiding nodes and edges from a graph.
    351353 
     
    381383
    382384    typedef typename GraphWrapper<Graph>::Node Node;
    383     class NodeIt {
    384       friend class GraphWrapper<Graph>;
     385//     class NodeIt {
     386//       friend class GraphWrapper<Graph>;
     387//       friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
     388//       typename Graph::NodeIt n;
     389//      public:
     390//       NodeIt() { }
     391//       NodeIt(const typename Graph::NodeIt& _n) : n(_n) { }
     392//       NodeIt(const Invalid& i) : n(i) { }
     393//       NodeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _G) :
     394//      n(*(_G.graph)) {
     395//      while (_G.graph->valid(n) && !(*(_G.node_filter_map))[n])
     396//        _G.graph->next(n);
     397//       }
     398//       operator Node() const { return Node(typename Graph::Node(n)); }
     399//     };
     400    class NodeIt : public Node {
     401      const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
    385402      friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
    386       typename Graph::NodeIt n;
    387      public:
     403    public:
    388404      NodeIt() { }
    389       NodeIt(const typename Graph::NodeIt& _n) : n(_n) { }
    390       NodeIt(const Invalid& i) : n(i) { }
    391       NodeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _G) :
    392         n(*(_G.graph)) {
    393         while (_G.graph->valid(n) && !(*(_G.node_filter_map))[n])
    394           _G.graph->next(n);
    395       }
    396       operator Node() const { return Node(typename Graph::Node(n)); }
     405      //      NodeIt(const NodeIt& n) : Node(n), gw(n.gw) { }
     406      NodeIt(Invalid i) : Node(i) { }
     407      NodeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw) :
     408        Node(typename Graph::NodeIt(*(_gw.graph))), gw(&_gw) { }
     409      NodeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw,
     410             const Node& n) :
     411        Node(n), gw(&_gw) { }
     412      NodeIt& operator++() {
     413        *(static_cast<Node*>(this))=
     414          ++(typename Graph::NodeIt(*(gw->graph), *this));
     415        while (*static_cast<Node*>(this)!=INVALID &&
     416               !(*(gw->node_filter_map))[*this])
     417          *(static_cast<Node*>(this))=
     418            ++(typename Graph::NodeIt(*(gw->graph), *this));
     419        return *this;
     420      }
    397421    };
    398422    typedef typename GraphWrapper<Graph>::Edge Edge;
    399     class OutEdgeIt {
    400       friend class GraphWrapper<Graph>;
     423    class OutEdgeIt : public Edge {
     424      const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
    401425      friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
    402       typename Graph::OutEdgeIt e;
    403426    public:
    404427      OutEdgeIt() { }
    405       OutEdgeIt(const typename Graph::OutEdgeIt& _e) : e(_e) { }
    406       OutEdgeIt(const Invalid& i) : e(i) { }
    407       OutEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _G,
    408                 const Node& _n) :
    409         e(*(_G.graph), typename Graph::Node(_n)) {
    410         while (_G.graph->valid(e) && !(*(_G.edge_filter_map))[e])
    411           _G.graph->next(e);
    412       }
    413       operator Edge() const { return Edge(typename Graph::Edge(e)); }
    414     };
    415     class InEdgeIt {
    416       friend class GraphWrapper<Graph>;
     428      //      OutEdgeIt(const OutEdgeIt& e) : Edge(e), gw(e.gw) { }
     429      OutEdgeIt(Invalid i) : Edge(i) { }
     430      OutEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, const Node& n) :
     431        Edge(typename Graph::OutEdgeIt(*(_gw.graph)), n), gw(&_gw) { }
     432      OutEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw,
     433             const Edge& e) :
     434        Edge(e), gw(&_gw) { }
     435      OutEdgeIt& operator++() {
     436        *(static_cast<Edge*>(this))=
     437          ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
     438        while (*static_cast<Edge*>(this)!=INVALID &&
     439               !(*(gw->edge_filter_map))[*this])
     440          *(static_cast<Edge*>(this))=
     441            ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
     442        return *this;
     443      }
     444    };
     445    class InEdgeIt : public Edge {
     446      const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
    417447      friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
    418       typename Graph::InEdgeIt e;
    419448    public:
    420449      InEdgeIt() { }
    421       InEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { }
    422       InEdgeIt(const Invalid& i) : e(i) { }
    423       InEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _G,
    424                const Node& _n) :
    425         e(*(_G.graph), typename Graph::Node(_n)) {
    426         while (_G.graph->valid(e) && !(*(_G.edge_filter_map))[e])
    427           _G.graph->next(e);
    428       }
    429       operator Edge() const { return Edge(typename Graph::Edge(e)); }
    430     };
    431     //typedef typename Graph::SymEdgeIt SymEdgeIt;
    432     class EdgeIt {
    433       friend class GraphWrapper<Graph>;
     450      //      InEdgeIt(const InEdgeIt& e) : Edge(e), gw(e.gw) { }
     451      InEdgeIt(Invalid i) : Edge(i) { }
     452      InEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, const Node& n) :
     453        Edge(typename Graph::InEdgeIt(*(_gw.graph)), n), gw(&_gw) { }
     454      InEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw,
     455             const Edge& e) :
     456        Edge(e), gw(&_gw) { }
     457      InEdgeIt& operator++() {
     458        *(static_cast<Edge*>(this))=
     459          ++(typename Graph::InEdgeIt(*(gw->graph), *this));
     460        while (*static_cast<Edge*>(this)!=INVALID &&
     461               !(*(gw->edge_filter_map))[*this])
     462          *(static_cast<Edge*>(this))=
     463            ++(typename Graph::InEdgeIt(*(gw->graph), *this));
     464        return *this;
     465      }
     466    };
     467    class EdgeIt : public Edge {
     468      const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
    434469      friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
    435       typename Graph::EdgeIt e;
    436470    public:
    437471      EdgeIt() { }
    438       EdgeIt(const typename Graph::EdgeIt& _e) : e(_e) { }
    439       EdgeIt(const Invalid& i) : e(i) { }
    440       EdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _G) :
    441         e(*(_G.graph)) {
    442         while (_G.graph->valid(e) && !(*(_G.edge_filter_map))[e])
    443           _G.graph->next(e);
    444       }
    445       operator Edge() const { return Edge(typename Graph::Edge(e)); }
     472      //      EdgeIt(const EdgeIt& e) : Edge(e), gw(e.gw) { }
     473      EdgeIt(Invalid i) : Edge(i) { }
     474      EdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw) :
     475        Edge(typename Graph::EdgeIt(*(_gw.graph))), gw(&_gw) { }
     476      EdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw,
     477             const Edge& e) :
     478        Edge(e), gw(&_gw) { }
     479      EdgeIt& operator++() {
     480        *(static_cast<Edge*>(this))=
     481          ++(typename Graph::EdgeIt(*(gw->graph), *this));
     482        while (*static_cast<Edge*>(this)!=INVALID &&
     483               !(*(gw->edge_filter_map))[*this])
     484          *(static_cast<Edge*>(this))=
     485            ++(typename Graph::EdgeIt(*(gw->graph), *this));
     486        return *this;
     487      }
    446488    };
    447489
     
    459501    }
    460502   
    461     NodeIt& next(NodeIt& i) const {
    462       this->graph->next(i.n);
    463       while (this->graph->valid(i) && !(*node_filter_map)[i.n]) {
    464         this->graph->next(i.n); }
    465       return i;
    466     }
    467     OutEdgeIt& next(OutEdgeIt& i) const {
    468       this->graph->next(i.e);
    469       while (this->graph->valid(i) && !(*edge_filter_map)[i.e]) {
    470         this->graph->next(i.e); }
    471       return i;
    472     }
    473     InEdgeIt& next(InEdgeIt& i) const {
    474       this->graph->next(i.e);
    475       while (this->graph->valid(i) && !(*edge_filter_map)[i.e]) {
    476         this->graph->next(i.e); }
    477       return i;
    478     }
    479     EdgeIt& next(EdgeIt& i) const {
    480       this->graph->next(i.e);
    481       while (this->graph->valid(i) && !(*edge_filter_map)[i.e]) {
    482         this->graph->next(i.e); }
    483       return i;
    484     }
    485 
    486     Node aNode(const OutEdgeIt& e) const {
    487       return Node(this->graph->aNode(e.e)); }
    488     Node aNode(const InEdgeIt& e) const {
    489       return Node(this->graph->aNode(e.e)); }
    490     Node bNode(const OutEdgeIt& e) const {
    491       return Node(this->graph->bNode(e.e)); }
    492     Node bNode(const InEdgeIt& e) const {
    493       return Node(this->graph->bNode(e.e)); }
     503//     NodeIt& next(NodeIt& i) const {
     504//       this->graph->next(i.n);
     505//       while (this->graph->valid(i) && !(*node_filter_map)[i.n]) {
     506//      this->graph->next(i.n); }
     507//       return i;
     508//     }
     509//     OutEdgeIt& next(OutEdgeIt& i) const {
     510//       this->graph->next(i.e);
     511//       while (this->graph->valid(i) && !(*edge_filter_map)[i.e]) {
     512//      this->graph->next(i.e); }
     513//       return i;
     514//     }
     515//     InEdgeIt& next(InEdgeIt& i) const {
     516//       this->graph->next(i.e);
     517//       while (this->graph->valid(i) && !(*edge_filter_map)[i.e]) {
     518//      this->graph->next(i.e); }
     519//       return i;
     520//     }
     521//     EdgeIt& next(EdgeIt& i) const {
     522//       this->graph->next(i.e);
     523//       while (this->graph->valid(i) && !(*edge_filter_map)[i.e]) {
     524//      this->graph->next(i.e); }
     525//       return i;
     526//     }
     527
     528//     Node aNode(const OutEdgeIt& e) const {
     529//       return Node(this->graph->aNode(e.e)); }
     530//     Node aNode(const InEdgeIt& e) const {
     531//       return Node(this->graph->aNode(e.e)); }
     532//     Node bNode(const OutEdgeIt& e) const {
     533//       return Node(this->graph->bNode(e.e)); }
     534//     Node bNode(const InEdgeIt& e) const {
     535//       return Node(this->graph->bNode(e.e)); }
    494536
    495537    /// This function hides \c n in the graph, i.e. the iteration
     
    754796          *(static_cast<GraphEdge*>(this))=
    755797            ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
    756         if (*static_cast<GraphEdge*>(this)==INVALID)
     798        if (*static_cast<GraphEdge*>(this)==INVALID) {
    757799          *static_cast<Edge*>(this)=
    758800            Edge(typename Graph::InEdgeIt(*(_gw.graph), n), true);
    759         while (*static_cast<GraphEdge*>(this)!=INVALID &&
    760                !(*(gw->backward_filter))[*this])
    761           *(static_cast<GraphEdge*>(this))=
    762             ++(typename Graph::InEdgeIt(*(gw->graph), *this));
     801          while (*static_cast<GraphEdge*>(this)!=INVALID &&
     802                 !(*(gw->backward_filter))[*this])
     803            *(static_cast<GraphEdge*>(this))=
     804              ++(typename Graph::InEdgeIt(*(gw->graph), *this));
     805        }
    763806      }
    764807      OutEdgeIt(const SubBidirGraphWrapper<Graph,
     
    774817            *(static_cast<GraphEdge*>(this))=
    775818              ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
    776           if (*static_cast<GraphEdge*>(this)==INVALID)
     819          if (*static_cast<GraphEdge*>(this)==INVALID) {
    777820            *static_cast<Edge*>(this)=
    778821              Edge(typename Graph::InEdgeIt(*(gw->graph), n), true);
    779           while (*static_cast<GraphEdge*>(this)!=INVALID &&
    780                  !(*(gw->backward_filter))[*this])
    781             *(static_cast<GraphEdge*>(this))=
    782               ++(typename Graph::InEdgeIt(*(gw->graph), *this));
     822            while (*static_cast<GraphEdge*>(this)!=INVALID &&
     823                   !(*(gw->backward_filter))[*this])
     824              *(static_cast<GraphEdge*>(this))=
     825                ++(typename Graph::InEdgeIt(*(gw->graph), *this));
     826          }
    783827        } else {
    784828          *(static_cast<GraphEdge*>(this))=
     
    810854          *(static_cast<GraphEdge*>(this))=
    811855            ++(typename Graph::InEdgeIt(*(gw->graph), *this));
    812         if (*static_cast<GraphEdge*>(this)==INVALID)
     856        if (*static_cast<GraphEdge*>(this)==INVALID) {
    813857          *static_cast<Edge*>(this)=
    814858            Edge(typename Graph::OutEdgeIt(*(_gw.graph), n), true);
    815         while (*static_cast<GraphEdge*>(this)!=INVALID &&
    816                !(*(gw->backward_filter))[*this])
    817           *(static_cast<GraphEdge*>(this))=
    818             ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
     859          while (*static_cast<GraphEdge*>(this)!=INVALID &&
     860                 !(*(gw->backward_filter))[*this])
     861            *(static_cast<GraphEdge*>(this))=
     862              ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
     863        }
    819864      }
    820865      InEdgeIt(const SubBidirGraphWrapper<Graph,
     
    823868      InEdgeIt& operator++() {
    824869        if (!this->backward) {
    825           Node n=gw->head(*this);
     870          Node n=gw->tail(*this);
    826871          *(static_cast<GraphEdge*>(this))=
    827872            ++(typename Graph::InEdgeIt(*(gw->graph), *this));
     
    830875            *(static_cast<GraphEdge*>(this))=
    831876              ++(typename Graph::InEdgeIt(*(gw->graph), *this));
    832           if (*static_cast<GraphEdge*>(this)==INVALID)
     877          if (*static_cast<GraphEdge*>(this)==INVALID) {
    833878            *static_cast<Edge*>(this)=
    834879              Edge(typename Graph::OutEdgeIt(*(gw->graph), n), true);
    835           while (*static_cast<GraphEdge*>(this)!=INVALID &&
    836                  !(*(gw->backward_filter))[*this])
    837             *(static_cast<GraphEdge*>(this))=
    838               ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
     880            while (*static_cast<GraphEdge*>(this)!=INVALID &&
     881                   !(*(gw->backward_filter))[*this])
     882              *(static_cast<GraphEdge*>(this))=
     883                ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
     884          }
    839885        } else {
    840886          *(static_cast<GraphEdge*>(this))=
     
    860906//the unique invalid iterator
    861907      EdgeIt(const SubBidirGraphWrapper<Graph,
    862                 ForwardFilterMap, BackwardFilterMap>& _gw) :
    863         Edge(typename Graph::EdgeIt(*(_gw.graph)), false), gw(&_gw) {
     908             ForwardFilterMap, BackwardFilterMap>& _gw) :
     909        Edge(typename Graph::OutEdgeIt(*(_gw.graph)), false), gw(&_gw) {
    864910        while (*static_cast<GraphEdge*>(this)!=INVALID &&
    865911               !(*(gw->forward_filter))[*this])
    866912          *(static_cast<GraphEdge*>(this))=
    867913            ++(typename Graph::EdgeIt(*(gw->graph), *this));
    868         if (*static_cast<GraphEdge*>(this)==INVALID)
     914        if (*static_cast<GraphEdge*>(this)==INVALID) {
    869915          *static_cast<Edge*>(this)=
    870916            Edge(typename Graph::EdgeIt(*(_gw.graph)), true);
    871         while (*static_cast<GraphEdge*>(this)!=INVALID &&
    872                !(*(gw->backward_filter))[*this])
    873           *(static_cast<GraphEdge*>(this))=
    874             ++(typename Graph::EdgeIt(*(gw->graph), *this));
     917          while (*static_cast<GraphEdge*>(this)!=INVALID &&
     918                 !(*(gw->backward_filter))[*this])
     919            *(static_cast<GraphEdge*>(this))=
     920              ++(typename Graph::EdgeIt(*(gw->graph), *this));
     921        }
    875922      }
    876923      EdgeIt(const SubBidirGraphWrapper<Graph,
     
    885932            *(static_cast<GraphEdge*>(this))=
    886933              ++(typename Graph::EdgeIt(*(gw->graph), *this));
    887           if (*static_cast<GraphEdge*>(this)==INVALID)
     934          if (*static_cast<GraphEdge*>(this)==INVALID) {
    888935            *static_cast<Edge*>(this)=
    889936              Edge(typename Graph::EdgeIt(*(gw->graph)), true);
    890           while (*static_cast<GraphEdge*>(this)!=INVALID &&
    891                  !(*(gw->backward_filter))[*this])
    892             *(static_cast<GraphEdge*>(this))=
    893               ++(typename Graph::EdgeIt(*(gw->graph), *this));
     937            while (*static_cast<GraphEdge*>(this)!=INVALID &&
     938                   !(*(gw->backward_filter))[*this])
     939              *(static_cast<GraphEdge*>(this))=
     940                ++(typename Graph::EdgeIt(*(gw->graph), *this));
     941          }
    894942        } else {
    895943          *(static_cast<GraphEdge*>(this))=
Note: See TracChangeset for help on using the changeset viewer.