COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/marci/graph_wrapper.h @ 300:60b578e3d507

Last change on this file since 300:60b578e3d507 was 279:be43902fadb7, checked in by marci, 20 years ago

minor changes

File size: 58.2 KB
RevLine 
[174]1// -*- c++ -*-
[259]2#ifndef HUGO_GRAPH_WRAPPER_H
3#define HUGO_GRAPH_WRAPPER_H
[76]4
[174]5#include <invalid.h>
6
[105]7namespace hugo {
[76]8
9  template<typename Graph>
10  class TrivGraphWrapper {
[199]11  protected:
[76]12    Graph* graph;
13 
14  public:
15    typedef Graph BaseGraph;
16
[174]17    typedef typename Graph::Node Node;
[265]18    class NodeIt : public Graph::NodeIt {
19    public:
20      NodeIt() { }
21      NodeIt(const typename Graph::NodeIt& n) : Graph::NodeIt(n) { }
22      NodeIt(const Invalid& i) : Graph::NodeIt(i) { }
23      NodeIt(const TrivGraphWrapper<Graph>& _G) :
24        Graph::NodeIt(*(_G.graph)) { }
25    };
[174]26    typedef typename Graph::Edge Edge;
[265]27    //typedef typename Graph::OutEdgeIt OutEdgeIt;
28    class OutEdgeIt : public Graph::OutEdgeIt {
29    public:
30      OutEdgeIt() { }
31      OutEdgeIt(const typename Graph::OutEdgeIt& e) : Graph::OutEdgeIt(e) { }
32      OutEdgeIt(const Invalid& i) : Graph::OutEdgeIt(i) { }
33      OutEdgeIt(const TrivGraphWrapper<Graph>& _G, const Node& n) :
34        Graph::OutEdgeIt(*(_G.graph), n) { }
35    };
36    //typedef typename Graph::InEdgeIt InEdgeIt;
37    class InEdgeIt : public Graph::InEdgeIt {
38    public:
39      InEdgeIt() { }
40      InEdgeIt(const typename Graph::InEdgeIt& e) : Graph::InEdgeIt(e) { }
41      InEdgeIt(const Invalid& i) : Graph::InEdgeIt(i) { }
42      InEdgeIt(const TrivGraphWrapper<Graph>& _G, const Node& n) :
43        Graph::InEdgeIt(*(_G.graph), n) { }
44    };
[155]45    //typedef typename Graph::SymEdgeIt SymEdgeIt;
[265]46    //typedef typename Graph::EdgeIt EdgeIt;
47    class EdgeIt : public Graph::EdgeIt {
48    public:
49      EdgeIt() { }
50      EdgeIt(const typename Graph::EdgeIt& e) : Graph::EdgeIt(e) { }
51      EdgeIt(const Invalid& i) : Graph::EdgeIt(i) { }
52      EdgeIt(const TrivGraphWrapper<Graph>& _G) :
53        Graph::EdgeIt(*(_G.graph)) { }
54    };
[168]55
56    //TrivGraphWrapper() : graph(0) { }
57    TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
58
[265]59//    void setGraph(Graph& _graph) { graph = &_graph; }
60//    Graph& getGraph() const { return (*graph); }
61
62    NodeIt& first(NodeIt& i) const {
63      i=NodeIt(*this);
64      return i;
65    }
66    EdgeIt& first(EdgeIt& i) const {
67      i=EdgeIt(*this);
68      return i;
69    }
70//     template<typename I> I& first(I& i) const {
71//       //return graph->first(i);
72//       i=I(*this);
73//       return i;
74//     }
75    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {
76      i=OutEdgeIt(*this, p);
77      return i;
78    }
79    InEdgeIt& first(InEdgeIt& i, const Node& p) const {
80      i=InEdgeIt(*this, p);
81      return i;
82    }
83//     template<typename I, typename P> I& first(I& i, const P& p) const {
84//       //return graph->first(i, p);
85//       i=I(*this, p);
86//       return i;
87//     }
[76]88   
[265]89//    template<typename I> I getNext(const I& i) const {
90//      return graph->getNext(i); }
91    template<typename I> I& next(I &i) const { graph->next(i); return i; }   
[76]92
93    template< typename It > It first() const {
[212]94      It e; first(e); return e; }
[76]95
[174]96    template< typename It > It first(const Node& v) const {
[212]97      It e; first(e, v); return e; }
[76]98
[174]99    Node head(const Edge& e) const { return graph->head(e); }
100    Node tail(const Edge& e) const { return graph->tail(e); }
[155]101
102    template<typename I> bool valid(const I& i) const
103      { return graph->valid(i); }
104 
105    //template<typename I> void setInvalid(const I &i);
106    //{ return graph->setInvalid(i); }
107
108    int nodeNum() const { return graph->nodeNum(); }
109    int edgeNum() const { return graph->edgeNum(); }
[76]110 
[174]111    template<typename I> Node aNode(const I& e) const {
[76]112      return graph->aNode(e); }
[174]113    template<typename I> Node bNode(const I& e) const {
[76]114      return graph->bNode(e); }
115 
[174]116    Node addNode() const { return graph->addNode(); }
117    Edge addEdge(const Node& tail, const Node& head) const {
[76]118      return graph->addEdge(tail, head); }
119 
120    template<typename I> void erase(const I& i) const { graph->erase(i); }
121 
122    void clear() const { graph->clear(); }
[155]123   
[76]124    template<typename T> class NodeMap : public Graph::NodeMap<T> {
125    public:
[266]126      NodeMap(const TrivGraphWrapper<Graph>& _G) : 
[265]127        Graph::NodeMap<T>(*(_G.graph)) { }
[155]128      NodeMap(const TrivGraphWrapper<Graph>& _G, T a) :
[265]129        Graph::NodeMap<T>(*(_G.graph), a) { }
[76]130    };
[168]131
[155]132    template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
133    public:
[266]134      EdgeMap(const TrivGraphWrapper<Graph>& _G) : 
[265]135        Graph::EdgeMap<T>(*(_G.graph)) { }
[155]136      EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) :
[265]137        Graph::EdgeMap<T>(*(_G.graph), a) { }
[155]138    };
[266]139
140    template<typename Map, typename T> class NodeMapWrapper {
141    protected:
142      Map* map;
143    public:
144      NodeMapWrapper(Map& _map) : map(&_map) { }
145      //template<typename T>
146      void set(Node n, T a) { map->set(n, a); }
147      //template<typename T>
148      T get(Node n) const { return map->get(n); }
149    };
150
151    template<typename Map, typename T> class EdgeMapWrapper {
152    protected:
153      Map* map;
154    public:
155      EdgeMapWrapper(Map& _map) : map(&_map) { }
156      //template<typename T>
157      void set(Edge n, T a) { map->set(n, a); }
158      //template<typename T>
159      T get(Edge n) const { return map->get(n); }
160    };
[76]161  };
162
[212]163  template<typename GraphWrapper>
164  class GraphWrapperSkeleton {
165  protected:
166    GraphWrapper gw;
167 
168  public:
[263]169    //typedef typename GraphWrapper::BaseGraph BaseGraph;
[212]170
[265]171//     typedef typename GraphWrapper::Node Node;
172//     typedef typename GraphWrapper::NodeIt NodeIt;
173
174//     typedef typename GraphWrapper::Edge Edge;
175//     typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
176//     typedef typename GraphWrapper::InEdgeIt InEdgeIt;
177//     //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
178//     typedef typename GraphWrapper::EdgeIt EdgeIt;
179
[212]180    typedef typename GraphWrapper::Node Node;
[265]181    class NodeIt : public GraphWrapper::NodeIt {
182    public:
183      NodeIt() { }
184      NodeIt(const typename GraphWrapper::NodeIt& n) :
185        GraphWrapper::NodeIt(n) { }
186      NodeIt(const Invalid& i) : GraphWrapper::NodeIt(i) { }
187      NodeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) :
188        GraphWrapper::NodeIt(_G.gw) { }
189    };
190    typedef typename GraphWrapper::Edge Edge;
191    //typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
192    class OutEdgeIt : public GraphWrapper::OutEdgeIt {
193    public:
194      OutEdgeIt() { }
195      OutEdgeIt(const typename GraphWrapper::OutEdgeIt& e) :
196        GraphWrapper::OutEdgeIt(e) { }
197      OutEdgeIt(const Invalid& i) : GraphWrapper::OutEdgeIt(i) { }
198      OutEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) :
199        GraphWrapper::OutEdgeIt(_G.gw, n) { }
200    };
201    //typedef typename GraphWrapper::InEdgeIt InEdgeIt;
202    class InEdgeIt : public GraphWrapper::InEdgeIt {
203    public:
204      InEdgeIt() { }
205      InEdgeIt(const typename GraphWrapper::InEdgeIt& e) :
206        GraphWrapper::InEdgeIt(e) { }
207      InEdgeIt(const Invalid& i) : GraphWrapper::InEdgeIt(i) { }
208      InEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) :
209        GraphWrapper::InEdgeIt(_G.gw, n) { }
210    };
211    //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
212    //typedef typename GraphWrapper::EdgeIt EdgeIt;
213    class EdgeIt : public GraphWrapper::EdgeIt {
214    public:
215      EdgeIt() { }
216      EdgeIt(const typename GraphWrapper::EdgeIt& e) :
217        GraphWrapper::EdgeIt(e) { }
218      EdgeIt(const Invalid& i) : GraphWrapper::EdgeIt(i) { }
219      EdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) :
220        GraphWrapper::EdgeIt(_G.gw) { }
221    };
[212]222
223
224    //GraphWrapperSkeleton() : gw() { }
[230]225    GraphWrapperSkeleton(GraphWrapper _gw) : gw(_gw) { }
[212]226
[263]227    //void setGraph(BaseGraph& _graph) { gw.setGraph(_graph); }
228    //BaseGraph& getGraph() const { return gw.getGraph(); }
[212]229   
[265]230    template<typename I> I& first(I& i) const {       
231      i=I(*this);
232      return i;
233    }
[212]234    template<typename I, typename P> I& first(I& i, const P& p) const {
[265]235      i=I(*this, p);
236      return i;
237    }
[212]238   
[265]239//    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
240    template<typename I> I& next(I &i) const { gw.next(i); return i; }   
[212]241
242    template< typename It > It first() const {
243      It e; this->first(e); return e; }
244
245    template< typename It > It first(const Node& v) const {
246      It e; this->first(e, v); return e; }
247
248    Node head(const Edge& e) const { return gw.head(e); }
249    Node tail(const Edge& e) const { return gw.tail(e); }
250
251    template<typename I> bool valid(const I& i) const { return gw.valid(i); }
252 
253    //template<typename I> void setInvalid(const I &i);
254    //{ return graph->setInvalid(i); }
255
256    int nodeNum() const { return gw.nodeNum(); }
257    int edgeNum() const { return gw.edgeNum(); }
258 
259    template<typename I> Node aNode(const I& e) const { return gw.aNode(e); }
260    template<typename I> Node bNode(const I& e) const { return gw.bNode(e); }
261 
262    Node addNode() const { return gw.addNode(); }
263    Edge addEdge(const Node& tail, const Node& head) const {
264      return gw.addEdge(tail, head); }
265 
266    template<typename I> void erase(const I& i) const { gw.erase(i); }
267 
268    void clear() const { gw.clear(); }
269   
270    template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
271    public:
[266]272      NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) : 
[212]273        GraphWrapper::NodeMap<T>(_G.gw) { }
274      NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) :
275        GraphWrapper::NodeMap<T>(_G.gw, a) { }
276    };
277
278    template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> {
279    public:
[266]280      EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) : 
[212]281        GraphWrapper::EdgeMap<T>(_G.gw) { }
282      EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) :
283        GraphWrapper::EdgeMap<T>(_G.gw, a) { }
284    };
285  };
286
[230]287//   template<typename Graph>
288//   class RevGraphWrapper
289//   {
290//   protected:
291//     Graph* graph;
292 
293//   public:
294//     typedef Graph BaseGraph;
295
296//     typedef typename Graph::Node Node;   
297//     typedef typename Graph::NodeIt NodeIt;
298 
299//     typedef typename Graph::Edge Edge;
300//     typedef typename Graph::OutEdgeIt InEdgeIt;
301//     typedef typename Graph::InEdgeIt OutEdgeIt;
302//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
303//     typedef typename Graph::EdgeIt EdgeIt;
304
305//     //RevGraphWrapper() : graph(0) { }
306//     RevGraphWrapper(Graph& _graph) : graph(&_graph) { }
307
308//     void setGraph(Graph& _graph) { graph = &_graph; }
309//     Graph& getGraph() const { return (*graph); }
310   
311//     template<typename I> I& first(I& i) const { return graph->first(i); }
312//     template<typename I, typename P> I& first(I& i, const P& p) const {
313//       return graph->first(i, p); }
314
315//     template<typename I> I getNext(const I& i) const {
316//       return graph->getNext(i); }
317//     template<typename I> I& next(I &i) const { return graph->next(i); }   
318
319//     template< typename It > It first() const {
320//       It e; first(e); return e; }
321
322//     template< typename It > It first(const Node& v) const {
323//       It e; first(e, v); return e; }
324
325//     Node head(const Edge& e) const { return graph->tail(e); }
326//     Node tail(const Edge& e) const { return graph->head(e); }
327 
328//     template<typename I> bool valid(const I& i) const
329//       { return graph->valid(i); }
330 
331//     //template<typename I> void setInvalid(const I &i);
332//     //{ return graph->setInvalid(i); }
333 
334//     template<typename I> Node aNode(const I& e) const {
335//       return graph->aNode(e); }
336//     template<typename I> Node bNode(const I& e) const {
337//       return graph->bNode(e); }
338
339//     Node addNode() const { return graph->addNode(); }
340//     Edge addEdge(const Node& tail, const Node& head) const {
341//       return graph->addEdge(tail, head); }
342 
343//     int nodeNum() const { return graph->nodeNum(); }
344//     int edgeNum() const { return graph->edgeNum(); }
345 
346//     template<typename I> void erase(const I& i) const { graph->erase(i); }
347 
348//     void clear() const { graph->clear(); }
349
350//     template<typename T> class NodeMap : public Graph::NodeMap<T> {
351//     public:
352//       NodeMap(const RevGraphWrapper<Graph>& _G) :
353//      Graph::NodeMap<T>(_G.getGraph()) { }
354//       NodeMap(const RevGraphWrapper<Graph>& _G, T a) :
355//      Graph::NodeMap<T>(_G.getGraph(), a) { }
356//     };
357
358//     template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
359//     public:
360//       EdgeMap(const RevGraphWrapper<Graph>& _G) :
361//      Graph::EdgeMap<T>(_G.getGraph()) { }
362//       EdgeMap(const RevGraphWrapper<Graph>& _G, T a) :
363//      Graph::EdgeMap<T>(_G.getGraph(), a) { }
364//     };
365//   };
366
[235]367//   template<typename /*Graph*/GraphWrapper
368//   /*=typename GraphWrapperSkeleton< TrivGraphWrapper<Graph>*/ >
369//   class RevGraphWrapper :
370//     public GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/ {
371//   protected:
372//     //Graph* graph;
[230]373   
[235]374//   public:
375//     //typedef Graph BaseGraph;
376
377//     //typedef typename Graph::Node Node;   
378//     //typedef typename Graph::NodeIt NodeIt;
379 
380//     //typedef typename Graph::Edge Edge;
381//     typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::OutEdgeIt InEdgeIt;
382//     typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::InEdgeIt OutEdgeIt;
383//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
384//     //typedef typename Graph::EdgeIt EdgeIt;
385
386//     //RevGraphWrapper() : graph(0) { }
387//     RevGraphWrapper(GraphWrapper _gw/*BaseGraph& _graph*/) : GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/(_gw/*TrivGraphWrapper<Graph>(_graph)*/) { }
388   
389//     //void setGraph(Graph& _graph) { graph = &_graph; }
390//     //Graph& getGraph() const { return (*graph); }
391   
392//     //template<typename I> I& first(I& i) const { return graph->first(i); }
393//     //template<typename I, typename P> I& first(I& i, const P& p) const {
394//     //  return graph->first(i, p); }
395
396//     //template<typename I> I getNext(const I& i) const {
397//     //  return graph->getNext(i); }
398//     //template<typename I> I& next(I &i) const { return graph->next(i); }   
399
400//     //template< typename It > It first() const {
401//     //  It e; first(e); return e; }
402
403//     //template< typename It > It first(const Node& v) const {
404//     //  It e; first(e, v); return e; }
405
406//     //Node head(const Edge& e) const { return graph->tail(e); }
407//     //Node tail(const Edge& e) const { return graph->head(e); }
408 
409//     //template<typename I> bool valid(const I& i) const
410//     //  { return graph->valid(i); }
411 
412//     //template<typename I> void setInvalid(const I &i);
413//     //{ return graph->setInvalid(i); }
414 
415//     //template<typename I> Node aNode(const I& e) const {
416//     //  return graph->aNode(e); }
417//     //template<typename I> Node bNode(const I& e) const {
418//     //  return graph->bNode(e); }
419
420//     //Node addNode() const { return graph->addNode(); }
421//     //Edge addEdge(const Node& tail, const Node& head) const {
422//     //  return graph->addEdge(tail, head); }
423 
424//     //int nodeNum() const { return graph->nodeNum(); }
425//     //int edgeNum() const { return graph->edgeNum(); }
426 
427//     //template<typename I> void erase(const I& i) const { graph->erase(i); }
428 
429//     //void clear() const { graph->clear(); }
430
431//     template<typename T> class NodeMap :
432//       public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>
433//     {
434//     public:
435//       NodeMap(const RevGraphWrapper<GraphWrapper>& _gw) :
436//      GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw) { }
437//       NodeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) :
438//      GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw, a) { }
439//     };
440   
441//     template<typename T> class EdgeMap :
442//       public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T> {
443//     public:
444//       EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw) :
445//      GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw) { }
446//       EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) :
447//      GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw, a) { }
448//     };
449//   };
450
451  template<typename GraphWrapper>
452  class RevGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
[230]453  public:
[237]454    typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
455    typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge;
[279]456    //FIXME
457    //If GraphWrapper::OutEdgeIt is not defined
458    //and we do not want to use RevGraphWrapper::InEdgeIt,
459    //this won't work, because of typedef
460    //OR
461    //graphs have to define their non-existing iterators to void
462    //Unfortunately all the typedefs are instantiated in templates,
463    //unlike other stuff
[235]464    typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt InEdgeIt;
465    typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt OutEdgeIt;
[237]466
[238]467    RevGraphWrapper(GraphWrapper _gw) :
468      GraphWrapperSkeleton<GraphWrapper>(_gw) { } 
469
[237]470    Node head(const Edge& e) const
471      { return GraphWrapperSkeleton<GraphWrapper>::tail(e); }
472    Node tail(const Edge& e) const
473      { return GraphWrapperSkeleton<GraphWrapper>::head(e); }
[76]474  };
475
[263]476  //Subgraph on the same node-set and partial edge-set
477  template<typename GraphWrapper, typename EdgeFilterMap>
478  class SubGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
479  protected:
480    EdgeFilterMap* filter_map;
481  public:
482    typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
483    typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
484    typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge;
485    typedef typename GraphWrapperSkeleton<GraphWrapper>::EdgeIt EdgeIt;
486    typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt InEdgeIt;
487    typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt OutEdgeIt;
488
489    SubGraphWrapper(GraphWrapper _gw, EdgeFilterMap& _filter_map) :
490      GraphWrapperSkeleton<GraphWrapper>(_gw), filter_map(&_filter_map) { } 
491
492    template<typename I> I& first(I& i) const {
493      gw.first(i);
494      while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
495      return i;
496    }
497    template<typename I, typename P> I& first(I& i, const P& p) const {
498      gw.first(i, p);
499      while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
500      return i;
501    }
502   
503    //template<typename I> I getNext(const I& i) const {
504    //  return gw.getNext(i);
505    //}
506    template<typename I> I& next(I &i) const {
507      gw.next(i);
508      while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
509      return i;
510    }
511   
512    template< typename It > It first() const {
513      It e; this->first(e); return e; }
514   
515    template< typename It > It first(const Node& v) const {
516      It e; this->first(e, v); return e; }
517  };
[155]518
[238]519//   template<typename GraphWrapper>
[236]520//   class UndirGraphWrapper {
521//   protected:
[238]522//     //Graph* graph;
523//     GraphWrapper gw;
524
[236]525//   public:
[238]526//     typedef GraphWrapper BaseGraph;
[236]527
[238]528//     typedef typename GraphWrapper::Node Node;
529//     typedef typename GraphWrapper::NodeIt NodeIt;
[236]530
531//     //typedef typename Graph::Edge Edge;
532//     //typedef typename Graph::OutEdgeIt OutEdgeIt;
533//     //typedef typename Graph::InEdgeIt InEdgeIt;
534//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
535//     //typedef typename Graph::EdgeIt EdgeIt;
536
537//     //private:
[238]538//     typedef typename GraphWrapper::Edge GraphEdge;
539//     typedef typename GraphWrapper::OutEdgeIt GraphOutEdgeIt;
540//     typedef typename GraphWrapper::InEdgeIt GraphInEdgeIt;
[236]541//     //public:
542
543//     //UndirGraphWrapper() : graph(0) { }
[238]544//     UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
[236]545
[238]546//     //void setGraph(Graph& _graph) { graph = &_graph; }
547//     //Graph& getGraph() const { return (*graph); }
[236]548 
549//     class Edge {
[238]550//       friend class UndirGraphWrapper<GraphWrapper>;
[236]551//       bool out_or_in; //true iff out
552//       GraphOutEdgeIt out;
553//       GraphInEdgeIt in;
554//     public:
555//       Edge() : out_or_in(), out(), in() { }
556//       Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
557//       operator GraphEdge() const {
558//      if (out_or_in) return(out); else return(in);
559//       }
560//       friend bool operator==(const Edge& u, const Edge& v) {
561//      if (v.out_or_in)
562//        return (u.out_or_in && u.out==v.out);
563//      else
564//        return (!u.out_or_in && u.in==v.in);
565//       }
566//       friend bool operator!=(const Edge& u, const Edge& v) {
567//      if (v.out_or_in)
568//        return (!u.out_or_in || u.out!=v.out);
569//      else
570//        return (u.out_or_in || u.in!=v.in);
571//       }
572//     };
573
574//     class OutEdgeIt : public Edge {
[238]575//       friend class UndirGraphWrapper<GraphWrapper>;
[236]576//     public:
577//       OutEdgeIt() : Edge() { }
578//       OutEdgeIt(const Invalid& i) : Edge(i) { }
[238]579//       OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n)
580//      : Edge() {
[236]581//      out_or_in=true;
[238]582//      _G.gw.first(out, n);
583//      if (!(_G.gw.valid(out))) {
[236]584//        out_or_in=false;
[238]585//        _G.gw.first(in, n);
[236]586//      }
587//       }
588//     };
589
590//     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
591//       e.out_or_in=true;
[238]592//       gw.first(e.out, n);
593//       if (!(gw.valid(e.out))) {
[236]594//      e.out_or_in=false;
[238]595//      gw.first(e.in, n);
[236]596//       }
597//       return e;
598//     }
599
600//     OutEdgeIt& next(OutEdgeIt& e) const {
601//       if (e.out_or_in) {
[238]602//      Node n=gw.tail(e.out);
603//      gw.next(e.out);
604//      if (!gw.valid(e.out)) {
[236]605//        e.out_or_in=false;
[238]606//        gw.first(e.in, n);
[236]607//      }
608//       } else {
[238]609//      gw.next(e.in);
[236]610//       }
611//       return e;
612//     }
613
614//     Node aNode(const OutEdgeIt& e) const {
[238]615//       if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
[236]616//     Node bNode(const OutEdgeIt& e) const {
[238]617//       if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
[236]618
619//     typedef OutEdgeIt InEdgeIt;
620
[238]621//     template<typename I> I& first(I& i) const { return gw.first(i); }
[236]622// //     template<typename I, typename P> I& first(I& i, const P& p) const {
623// //       return graph->first(i, p); }
624   
625//     template<typename I> I getNext(const I& i) const {
[238]626//       return gw.getNext(i); }
627//     template<typename I> I& next(I &i) const { return gw.next(i); }   
[236]628
629//     template< typename It > It first() const {
630//       It e; first(e); return e; }
631
632//     template< typename It > It first(const Node& v) const {
633//       It e; first(e, v); return e; }
634
[238]635//     Node head(const Edge& e) const { return gw.head(e); }
636//     Node tail(const Edge& e) const { return gw.tail(e); }
[236]637
638//     template<typename I> bool valid(const I& i) const
[238]639//       { return gw.valid(i); }
[236]640 
641//     //template<typename I> void setInvalid(const I &i);
642//     //{ return graph->setInvalid(i); }
643
[238]644//     int nodeNum() const { return gw.nodeNum(); }
645//     int edgeNum() const { return gw.edgeNum(); }
[236]646 
647// //     template<typename I> Node aNode(const I& e) const {
648// //       return graph->aNode(e); }
649// //     template<typename I> Node bNode(const I& e) const {
650// //       return graph->bNode(e); }
651 
[238]652//     Node addNode() const { return gw.addNode(); }
[236]653// // FIXME: ez igy nem jo, mert nem
654// //    Edge addEdge(const Node& tail, const Node& head) const {
655// //      return graph->addEdge(tail, head); }
656 
[238]657//     template<typename I> void erase(const I& i) const { gw.erase(i); }
[236]658 
[238]659//     void clear() const { gw.clear(); }
[236]660   
[238]661//     template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
[236]662//     public:
[238]663//       NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
664//      GraphWrapper::NodeMap<T>(_G.gw) { }
665//       NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
666//      GraphWrapper::NodeMap<T>(_G.gw, a) { }
[236]667//     };
668
[238]669//     template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> {
[236]670//     public:
[238]671//       EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
672//      GraphWrapper::EdgeMap<T>(_G.gw) { }
673//       EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
674//      GraphWrapper::EdgeMap<T>(_G.gw, a) { }
[236]675//     };
676//   };
677
678
679  template<typename GraphWrapper>
[238]680  class UndirGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
[199]681  protected:
[238]682//    GraphWrapper gw;
[236]683
[158]684  public:
[238]685    //typedef GraphWrapper BaseGraph;
[158]686
[238]687    typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
688    typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
[158]689
690    //private:
[275]691    //FIXME ezeknek valojaban a GraphWrapper megfelelo dolgai kellene hogy
692    //legyenek, at kell irni
693    typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/
694    GraphWrapper::Edge GraphEdge;
695    typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/
696    GraphWrapper::OutEdgeIt GraphOutEdgeIt;
697    typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/
698    GraphWrapper::InEdgeIt GraphInEdgeIt;
[158]699    //public:
700
[168]701    //UndirGraphWrapper() : graph(0) { }
[238]702    UndirGraphWrapper(GraphWrapper _gw) :
703      GraphWrapperSkeleton<GraphWrapper>(_gw) { } 
704
705    //UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
[168]706
[236]707    //void setGraph(Graph& _graph) { graph = &_graph; }
708    //Graph& getGraph() const { return (*graph); }
[168]709 
[174]710    class Edge {
[236]711      friend class UndirGraphWrapper<GraphWrapper>;
[279]712    protected:
[158]713      bool out_or_in; //true iff out
714      GraphOutEdgeIt out;
715      GraphInEdgeIt in;
716    public:
[174]717      Edge() : out_or_in(), out(), in() { }
718      Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
719      operator GraphEdge() const {
[158]720        if (out_or_in) return(out); else return(in);
721      }
[239]722//FIXME
723//2 edges are equal if they "refer" to the same physical edge
724//is it good?
[174]725      friend bool operator==(const Edge& u, const Edge& v) {
726        if (v.out_or_in)
[239]727          if (u.out_or_in) return (u.out==v.out); else return (u.out==v.in);
728        //return (u.out_or_in && u.out==v.out);
[174]729        else
[239]730          if (u.out_or_in) return (u.out==v.in); else return (u.in==v.in);
731        //return (!u.out_or_in && u.in==v.in);
[174]732      }
733      friend bool operator!=(const Edge& u, const Edge& v) {
734        if (v.out_or_in)
[239]735          if (u.out_or_in) return (u.out!=v.out); else return (u.out!=v.in);
736        //return (!u.out_or_in || u.out!=v.out);
[174]737        else
[239]738          if (u.out_or_in) return (u.out!=v.in); else return (u.in!=v.in);
739        //return (u.out_or_in || u.in!=v.in);
[174]740      }
[158]741    };
742
[174]743    class OutEdgeIt : public Edge {
[236]744      friend class UndirGraphWrapper<GraphWrapper>;
[158]745    public:
[174]746      OutEdgeIt() : Edge() { }
747      OutEdgeIt(const Invalid& i) : Edge(i) { }
[236]748      OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n)
749        : Edge() {
[239]750        out_or_in=true; _G.gw.first(out, n);
751        if (!(_G.gw.valid(out))) { out_or_in=false; _G.gw.first(in, n); }
[158]752      }
753    };
754
[238]755    typedef OutEdgeIt InEdgeIt;
756
757    class EdgeIt : public Edge {
758      friend class UndirGraphWrapper<GraphWrapper>;
759    protected:
760      NodeIt v;
761    public:
762      EdgeIt() : Edge() { }
763      EdgeIt(const Invalid& i) : Edge(i) { }
764      EdgeIt(const UndirGraphWrapper<GraphWrapper>& _G)
765        : Edge() {
766        out_or_in=true;
767        //Node v;
768        _G.first(v);
769        if (_G.valid(v)) _G.gw.first(out); else out=INVALID;
770        while (_G.valid(v) && !_G.gw.valid(out)) {
771          _G.gw.next(v);
772          if (_G.valid(v)) _G.gw.first(out);
773        }
774      }
775    };
776
[212]777    OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
[239]778      e.out_or_in=true; gw.first(e.out, n);
779      if (!(gw.valid(e.out))) { e.out_or_in=false; gw.first(e.in, n); }
[158]780      return e;
781    }
782
[238]783    EdgeIt& first(EdgeIt& e) const {
784      e.out_or_in=true;
785      //NodeIt v;
786      first(e.v);
787      if (valid(e.v)) gw.first(e.out, e.v); else e.out=INVALID;
788      while (valid(e.v) && !gw.valid(e.out)) {
789        gw.next(e.v);
790        if (valid(e.v)) gw.first(e.out, e.v);
791      }
792      return e;
793    }
794
[265]795    template<typename I> I& first(I& i) const { gw.first(i); return i; }
[238]796    template<typename I, typename P> I& first(I& i, const P& p) const {
[266]797      gw.first(i, p); return i; }
[238]798
[158]799    OutEdgeIt& next(OutEdgeIt& e) const {
800      if (e.out_or_in) {
[236]801        Node n=gw.tail(e.out);
802        gw.next(e.out);
[239]803        if (!gw.valid(e.out)) { e.out_or_in=false; gw.first(e.in, n); }
[158]804      } else {
[236]805        gw.next(e.in);
[158]806      }
807      return e;
808    }
809
[238]810    EdgeIt& next(EdgeIt& e) const {
811      //NodeIt v=tail(e);
812      gw.next(e.out);
813      while (valid(e.v) && !gw.valid(e.out)) {
814        next(e.v);
815        if (valid(e.v)) gw.first(e.out, e.v);
816      }
817      return e;
818    }
[158]819
[238]820    template<typename I> I& next(I &i) const { return gw.next(i); }   
[265]821//    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
[158]822
823    template< typename It > It first() const {
[212]824      It e; first(e); return e; }
[158]825
[174]826    template< typename It > It first(const Node& v) const {
[212]827      It e; first(e, v); return e; }
[158]828
[238]829//    Node head(const Edge& e) const { return gw.head(e); }
830//    Node tail(const Edge& e) const { return gw.tail(e); }
[158]831
[238]832//    template<typename I> bool valid(const I& i) const
833//      { return gw.valid(i); }
[158]834 
[238]835//    int nodeNum() const { return gw.nodeNum(); }
836//    int edgeNum() const { return gw.edgeNum(); }
[158]837 
[174]838//     template<typename I> Node aNode(const I& e) const {
[158]839//       return graph->aNode(e); }
[174]840//     template<typename I> Node bNode(const I& e) const {
[158]841//       return graph->bNode(e); }
[238]842
843    Node aNode(const OutEdgeIt& e) const {
844      if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
845    Node bNode(const OutEdgeIt& e) const {
846      if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
[158]847 
[238]848//    Node addNode() const { return gw.addNode(); }
849
[231]850// FIXME: ez igy nem jo, mert nem
851//    Edge addEdge(const Node& tail, const Node& head) const {
852//      return graph->addEdge(tail, head); }
[158]853 
[238]854//    template<typename I> void erase(const I& i) const { gw.erase(i); }
[158]855 
[238]856//    void clear() const { gw.clear(); }
[158]857   
[238]858//     template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
859//     public:
860//       NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
861//      GraphWrapper::NodeMap<T>(_G.gw) { }
862//       NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
863//      GraphWrapper::NodeMap<T>(_G.gw, a) { }
864//     };
[168]865
[238]866//     template<typename T> class EdgeMap :
867//       public GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T> {
868//     public:
869//       EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
870//      GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T>(_G.gw) { }
871//       EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
872//      GraphWrapper::EdgeMap<T>(_G.gw, a) { }
873//     };
874   };
[158]875
876
877
[236]878
879
[155]880//   template<typename Graph>
881//   class SymGraphWrapper
882//   {
883//     Graph* graph;
[76]884 
[155]885//   public:
886//     typedef Graph BaseGraph;
887
[174]888//     typedef typename Graph::Node Node;
889//     typedef typename Graph::Edge Edge;
890 
[155]891//     typedef typename Graph::NodeIt NodeIt;
892   
893//     //FIXME tag-ekkel megcsinalni, hogy abbol csinaljon
894//     //iranyitatlant, ami van
895//     //mert csak 1 dolgot lehet be typedef-elni
896//     typedef typename Graph::OutEdgeIt SymEdgeIt;
897//     //typedef typename Graph::InEdgeIt SymEdgeIt;
898//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
[174]899//     typedef typename Graph::EdgeIt EdgeIt;
[155]900
901//     int nodeNum() const { return graph->nodeNum(); }
902//     int edgeNum() const { return graph->edgeNum(); }
903   
[212]904//     template<typename I> I& first(I& i) const { return graph->first(i); }
905//     template<typename I, typename P> I& first(I& i, const P& p) const {
906//       return graph->first(i, p); }
[155]907//     //template<typename I> I next(const I i); { return graph->goNext(i); }
908//     //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
909
910//     template< typename It > It first() const {
[212]911//       It e; first(e); return e; }
[155]912
[174]913//     template< typename It > It first(Node v) const {
[212]914//       It e; first(e, v); return e; }
[155]915
[174]916//     Node head(const Edge& e) const { return graph->head(e); }
917//     Node tail(const Edge& e) const { return graph->tail(e); }
[155]918 
[174]919//     template<typename I> Node aNode(const I& e) const {
[155]920//       return graph->aNode(e); }
[174]921//     template<typename I> Node bNode(const I& e) const {
[155]922//       return graph->bNode(e); }
923 
924//     //template<typename I> bool valid(const I i);
925//     //{ return graph->valid(i); }
926 
927//     //template<typename I> void setInvalid(const I &i);
928//     //{ return graph->setInvalid(i); }
929 
[174]930//     Node addNode() { return graph->addNode(); }
931//     Edge addEdge(const Node& tail, const Node& head) {
[155]932//       return graph->addEdge(tail, head); }
933 
934//     template<typename I> void erase(const I& i) { graph->erase(i); }
935 
936//     void clear() { graph->clear(); }
937 
938//     template<typename T> class NodeMap : public Graph::NodeMap<T> { };
939//     template<typename T> class EdgeMap : public Graph::EdgeMap<T> { };
940 
941//     void setGraph(Graph& _graph) { graph = &_graph; }
942//     Graph& getGraph() { return (*graph); }
943
944//     //SymGraphWrapper() : graph(0) { }
945//     SymGraphWrapper(Graph& _graph) : graph(&_graph) { }
946//   };
947
948
[266]949  template<typename GraphWrapper, typename Number, typename FlowMap, typename CapacityMap>
950  class ResGraphWrapper : public GraphWrapperSkeleton<GraphWrapper>{
[76]951  public:
[259]952    //typedef Graph BaseGraph;
[266]953    //typedef TrivGraphWrapper<const Graph> GraphWrapper;
954    typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
955    typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
[155]956  private:
[275]957    typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/
958    GraphWrapper::OutEdgeIt OldOutEdgeIt;
959    typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/
960    GraphWrapper::InEdgeIt OldInEdgeIt;
[199]961  protected:
[259]962    //const Graph* graph;
[266]963    //GraphWrapper gw;
[155]964    FlowMap* flow;
965    const CapacityMap* capacity;
966  public:
[168]967
[266]968    ResGraphWrapper(const GraphWrapper& _gw, FlowMap& _flow,
969                    const CapacityMap& _capacity) :
970      GraphWrapperSkeleton<GraphWrapper>(_gw),
971      flow(&_flow), capacity(&_capacity) { }
[168]972
[259]973    //void setGraph(const Graph& _graph) { graph = &_graph; }
974    //const Graph& getGraph() const { return (*graph); }
[168]975
[174]976    class Edge;
[155]977    class OutEdgeIt;
[174]978    friend class Edge;
[155]979    friend class OutEdgeIt;
[76]980
[174]981    class Edge {
[266]982      friend class ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>;
[155]983    protected:
[168]984      bool out_or_in; //true, iff out
[155]985      OldOutEdgeIt out;
986      OldInEdgeIt in;
987    public:
[174]988      Edge() : out_or_in(true) { }
989      Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
[168]990//       bool valid() const {
991//      return out_or_in && out.valid() || in.valid(); }
[174]992      friend bool operator==(const Edge& u, const Edge& v) {
993        if (v.out_or_in)
994          return (u.out_or_in && u.out==v.out);
995        else
996          return (!u.out_or_in && u.in==v.in);
997      }
998      friend bool operator!=(const Edge& u, const Edge& v) {
999        if (v.out_or_in)
1000          return (!u.out_or_in || u.out!=v.out);
1001        else
1002          return (u.out_or_in || u.in!=v.in);
1003      }
[155]1004    };
1005
1006
[174]1007    class OutEdgeIt : public Edge {
[266]1008      friend class ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>;
[155]1009    public:
1010      OutEdgeIt() { }
[168]1011      //FIXME
[174]1012      OutEdgeIt(const Edge& e) : Edge(e) { }
1013      OutEdgeIt(const Invalid& i) : Edge(i) { }
[265]1014    protected:
[266]1015      OutEdgeIt(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() {
[259]1016        resG.gw.first(out, v);
[269]1017        while( resG.gw.valid(out) && !(resG.resCap(out)>0) ) { resG.gw.next(out); }
[259]1018        if (!resG.gw.valid(out)) {
[155]1019          out_or_in=0;
[259]1020          resG.gw.first(in, v);
[269]1021          while( resG.gw.valid(in) && !(resG.resCap(in)>0) ) { resG.gw.next(in); }
[155]1022        }
1023      }
[168]1024//     public:
1025//       OutEdgeIt& operator++() {
1026//      if (out_or_in) {
[174]1027//        Node v=/*resG->*/G->aNode(out);
[168]1028//        ++out;
[269]1029//        while( out.valid() && !(Edge::resCap()>0) ) { ++out; }
[168]1030//        if (!out.valid()) {
1031//          out_or_in=0;
[212]1032//          G->first(in, v);
[269]1033//          while( in.valid() && !(Edge::resCap()>0) ) { ++in; }
[168]1034//        }
1035//      } else {
1036//        ++in;
[269]1037//        while( in.valid() && !(Edge::resCap()>0) ) { ++in; }
[168]1038//      }
1039//      return *this;
1040//       }
[155]1041    };
1042
[263]1043    //FIXME This is just for having InEdgeIt
1044    typedef void InEdgeIt;
1045
[174]1046    class EdgeIt : public Edge {
[266]1047      friend class ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>;
[265]1048      NodeIt v;
[155]1049    public:
[174]1050      EdgeIt() { }
1051      //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { }
1052      EdgeIt(const Invalid& i) : Edge(i) { }
[266]1053      EdgeIt(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& resG) : Edge() {
[259]1054        resG.gw.first(v);
[269]1055        if (resG.gw.valid(v)) resG.gw.first(out, v); else out=INVALID;
1056        while (resG.gw.valid(out) && !(resG.resCap(out)>0) ) { resG.gw.next(out); }
[259]1057        while (resG.gw.valid(v) && !resG.gw.valid(out)) {
1058          resG.gw.next(v);
1059          if (resG.gw.valid(v)) resG.gw.first(out, v);
[269]1060          while (resG.gw.valid(out) && !(resG.resCap(out)>0) ) { resG.gw.next(out); }
[155]1061        }
[259]1062        if (!resG.gw.valid(out)) {
[155]1063          out_or_in=0;
[259]1064          resG.gw.first(v);
[269]1065          if (resG.gw.valid(v)) resG.gw.first(in, v); else in=INVALID;
1066          while (resG.gw.valid(in) && !(resG.resCap(in)>0) ) { resG.gw.next(in); }
[259]1067          while (resG.gw.valid(v) && !resG.gw.valid(in)) {
1068            resG.gw.next(v);
1069            if (resG.gw.valid(v)) resG.gw.first(in, v);
[269]1070            while (resG.gw.valid(in) && !(resG.resCap(in)>0) ) { resG.gw.next(in); }
[155]1071          }
1072        }
1073      }
[174]1074//       EdgeIt& operator++() {
[168]1075//      if (out_or_in) {
1076//        ++out;
[269]1077//        while (out.valid() && !(Edge::resCap()>0) ) { ++out; }
[168]1078//        while (v.valid() && !out.valid()) {
1079//          ++v;
[212]1080//          if (v.valid()) G->first(out, v);
[269]1081//          while (out.valid() && !(Edge::resCap()>0) ) { ++out; }
[168]1082//        }
1083//        if (!out.valid()) {
1084//          out_or_in=0;
[212]1085//          G->first(v);
1086//          if (v.valid()) G->first(in, v); else in=OldInEdgeIt();
[269]1087//          while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
[168]1088//          while (v.valid() && !in.valid()) {
1089//            ++v;
[212]1090//            if (v.valid()) G->first(in, v);
[269]1091//            while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
[168]1092//          } 
1093//        }
1094//      } else {
1095//        ++in;
[269]1096//        while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
[168]1097//        while (v.valid() && !in.valid()) {
1098//          ++v;
[212]1099//          if (v.valid()) G->first(in, v);
[269]1100//          while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
[168]1101//        }
1102//      }
1103//      return *this;
1104//       }
[155]1105    };
1106
[266]1107    NodeIt& first(NodeIt& v) const { gw.first(v); return v; }
[212]1108    OutEdgeIt& first(OutEdgeIt& e, Node v) const {
[168]1109      e=OutEdgeIt(*this, v);
[174]1110      return e;
[155]1111    }
[212]1112    EdgeIt& first(EdgeIt& e) const {
[174]1113      e=EdgeIt(*this);
1114      return e;
[155]1115    }
1116   
[259]1117    NodeIt& next(NodeIt& n) const { return gw.next(n); }
[155]1118
1119    OutEdgeIt& next(OutEdgeIt& e) const {
1120      if (e.out_or_in) {
[259]1121        Node v=gw.aNode(e.out);
1122        gw.next(e.out);
[269]1123        while( gw.valid(e.out) && !(resCap(e.out)>0) ) { gw.next(e.out); }
[259]1124        if (!gw.valid(e.out)) {
[155]1125          e.out_or_in=0;
[259]1126          gw.first(e.in, v);
[269]1127          while( gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
[155]1128        }
1129      } else {
[259]1130        gw.next(e.in);
[269]1131        while( gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
[155]1132      }
1133      return e;
1134    }
1135
[174]1136    EdgeIt& next(EdgeIt& e) const {
[155]1137      if (e.out_or_in) {
[259]1138        gw.next(e.out);
[269]1139        while (gw.valid(e.out) && !(resCap(e.out)>0) ) { gw.next(e.out); }
[259]1140          while (gw.valid(e.v) && !gw.valid(e.out)) {
1141            gw.next(e.v);
1142            if (gw.valid(e.v)) gw.first(e.out, e.v);
[269]1143            while (gw.valid(e.out) && !(resCap(e.out)>0) ) { gw.next(e.out); }
[155]1144          }
[259]1145          if (!gw.valid(e.out)) {
[155]1146            e.out_or_in=0;
[259]1147            gw.first(e.v);
[269]1148            if (gw.valid(e.v)) gw.first(e.in, e.v); else e.in=INVALID;
1149            while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
[259]1150            while (gw.valid(e.v) && !gw.valid(e.in)) {
1151              gw.next(e.v);
1152              if (gw.valid(e.v)) gw.first(e.in, e.v);
[269]1153              while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
[155]1154            } 
1155          }
1156        } else {
[259]1157          gw.next(e.in);
[269]1158          while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
[259]1159          while (gw.valid(e.v) && !gw.valid(e.in)) {
1160            gw.next(e.v);
1161            if (gw.valid(e.v)) gw.first(e.in, e.v);
[269]1162            while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
[155]1163          }
1164        }
1165        return e;
1166      }
[76]1167   
1168
[155]1169    template< typename It >
1170    It first() const {
1171      It e;
[212]1172      first(e);
[155]1173      return e;
1174    }
[76]1175
[155]1176    template< typename It >
[174]1177    It first(Node v) const {
[155]1178      It e;
[212]1179      first(e, v);
[155]1180      return e;
1181    }
[76]1182
[174]1183    Node tail(Edge e) const {
[259]1184      return ((e.out_or_in) ? gw.aNode(e.out) : gw.aNode(e.in)); }
[174]1185    Node head(Edge e) const {
[259]1186      return ((e.out_or_in) ? gw.bNode(e.out) : gw.bNode(e.in)); }
[76]1187
[174]1188    Node aNode(OutEdgeIt e) const {
[259]1189      return ((e.out_or_in) ? gw.aNode(e.out) : gw.aNode(e.in)); }
[174]1190    Node bNode(OutEdgeIt e) const {
[259]1191      return ((e.out_or_in) ? gw.bNode(e.out) : gw.bNode(e.in)); }
[76]1192
[263]1193    int nodeNum() const { return gw.nodeNum(); }
1194    //FIXME
1195    //int edgeNum() const { return gw.edgeNum(); }
1196
1197
[259]1198    int id(Node v) const { return gw.id(v); }
[155]1199
[259]1200    bool valid(Node n) const { return gw.valid(n); }
[174]1201    bool valid(Edge e) const {
[259]1202      return e.out_or_in ? gw.valid(e.out) : gw.valid(e.in); }
[155]1203
[174]1204    void augment(const Edge& e, Number a) const {
[168]1205      if (e.out_or_in) 
1206        flow->set(e.out, flow->get(e.out)+a);
1207      else 
1208        flow->set(e.in, flow->get(e.in)-a);
1209    }
1210
[269]1211    Number resCap(const Edge& e) const {
[168]1212      if (e.out_or_in)
1213        return (capacity->get(e.out)-flow->get(e.out));
1214      else
1215        return (flow->get(e.in));
1216    }
1217
[269]1218    Number resCap(OldOutEdgeIt out) const {
[168]1219      return (capacity->get(out)-flow->get(out));
1220    }
1221   
[269]1222    Number resCap(OldInEdgeIt in) const {
[168]1223      return (flow->get(in));
1224    }
1225
[266]1226//     template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
1227//     public:
1228//       NodeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G)
1229//      : GraphWrapper::NodeMap<T>(_G.gw) { }
1230//       NodeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G,
1231//            T a) : GraphWrapper::NodeMap<T>(_G.gw, a) { }
1232//     };
[155]1233
1234//     template <typename T>
1235//     class NodeMap {
1236//       typename Graph::NodeMap<T> node_map;
1237//     public:
[174]1238//       NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(*(_G.graph)) { }
1239//       NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : node_map(*(_G.graph), a) { }
1240//       void set(Node nit, T a) { node_map.set(nit, a); }
1241//       T get(Node nit) const { return node_map.get(nit); }
[155]1242//     };
1243
1244    template <typename T>
1245    class EdgeMap {
[259]1246      typename GraphWrapper::EdgeMap<T> forward_map, backward_map;
[155]1247    public:
[266]1248      EdgeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G) : forward_map(_G.gw), backward_map(_G.gw) { }
1249      EdgeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(_G.gw, a), backward_map(_G.gw, a) { }
[174]1250      void set(Edge e, T a) {
[155]1251        if (e.out_or_in)
1252          forward_map.set(e.out, a);
1253        else
1254          backward_map.set(e.in, a);
1255      }
[174]1256      T get(Edge e) {
[155]1257        if (e.out_or_in)
1258          return forward_map.get(e.out);
1259        else
1260          return backward_map.get(e.in);
1261      }
1262    };
[168]1263  };
1264
[269]1265  //Subgraph on the same node-set and partial edge-set
1266  template<typename GraphWrapper, typename FirstOutEdgesMap>
1267  class ErasingFirstGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
1268  protected:
1269    FirstOutEdgesMap* first_out_edges;
1270  public:
1271    typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
1272    typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
1273    typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge;
1274    typedef typename GraphWrapperSkeleton<GraphWrapper>::EdgeIt EdgeIt;
1275    typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt InEdgeIt;
1276    typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt OutEdgeIt;
1277
1278    ErasingFirstGraphWrapper(GraphWrapper _gw, FirstOutEdgesMap& _first_out_edges) :
1279      GraphWrapperSkeleton<GraphWrapper>(_gw), first_out_edges(&_first_out_edges) { } 
1280
1281    template<typename I> I& first(I& i) const {
1282      gw.first(i);
1283      //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
1284      return i;
1285    }
1286    OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
1287      e=first_out_edges->get(n);
1288      return e;
1289    }
1290    template<typename I, typename P> I& first(I& i, const P& p) const {
1291      gw.first(i, p);
1292      //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
1293      return i;
1294    }
1295   
1296    //template<typename I> I getNext(const I& i) const {
1297    //  return gw.getNext(i);
1298    //}
1299    template<typename I> I& next(I &i) const {
1300      gw.next(i);
1301      //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
1302      return i;
1303    }
1304   
1305    template< typename It > It first() const {
1306      It e; this->first(e); return e; }
1307   
1308    template< typename It > It first(const Node& v) const {
1309      It e; this->first(e, v); return e; }
1310
1311    void erase(const OutEdgeIt& e) const {
1312      OutEdgeIt f=e;
1313      this->next(f);
1314      first_out_edges->set(this->tail(e), f);
1315    }
1316  };
1317
[266]1318//   template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
1319//   class ErasingResGraphWrapper : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
1320//   protected:
1321//     ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
1322//     //ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
1323//   public:
1324//     ErasingResGraphWrapper(const Graph& _G, FlowMap& _flow,
1325//                         const CapacityMap& _capacity) :
1326//       ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity),
1327//       first_out_edges(*this) /*, dist(*this)*/ {
1328//       for(NodeIt n=this->template first<NodeIt>(); this->valid(n); this->next(n)) {
1329//      OutEdgeIt e;
1330//      ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
1331//      first_out_edges.set(n, e);
1332//       }
1333//     }
[168]1334
[266]1335//     //void setGraph(Graph& _graph) { graph = &_graph; }
1336//     //Graph& getGraph() const { return (*graph); }
[168]1337 
[266]1338//     //TrivGraphWrapper() : graph(0) { }
1339//     //ErasingResGraphWrapper(Graph& _graph) : graph(&_graph) { }
[168]1340
[266]1341//     //typedef Graph BaseGraph;
[168]1342
[266]1343//     //typedef typename Graph::Node Node;
1344//     //typedef typename Graph::NodeIt NodeIt;
[168]1345
[266]1346//     //typedef typename Graph::Edge Edge;
1347//     //typedef typename Graph::OutEdgeIt OutEdgeIt;
1348//     //typedef typename Graph::InEdgeIt InEdgeIt;
1349//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
1350//     //typedef typename Graph::EdgeIt EdgeIt;
[168]1351
[266]1352//     typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
1353//     typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
[168]1354
[266]1355//     typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
1356//     typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
1357//     //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
1358//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
1359//     //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
[168]1360
[266]1361//     NodeIt& first(NodeIt& n) const {
1362//       return ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
1363//     }
[168]1364
[266]1365//     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
1366//       e=first_out_edges.get(n);
1367//       return e;
1368//     }
[168]1369   
[266]1370//     //ROSSZ template<typename I> I& first(I& i) const { return first(i); }
1371//     //ROSSZ template<typename I, typename P> I& first(I& i, const P& p) const {
1372//     //  return first(i, p); }
[168]1373   
[266]1374//     //template<typename I> I getNext(const I& i) const {
1375//     //  return gw.getNext(i); }
1376//     //template<typename I> I& next(I &i) const { return gw.next(i); }   
[168]1377
[266]1378//     template< typename It > It first() const {
1379//       It e; first(e); return e; }
[168]1380
[266]1381//     template< typename It > It first(const Node& v) const {
1382//       It e; first(e, v); return e; }
[168]1383
[266]1384//     //Node head(const Edge& e) const { return gw.head(e); }
1385//     //Node tail(const Edge& e) const { return gw.tail(e); }
[168]1386
[266]1387//     //template<typename I> bool valid(const I& i) const
1388//     //  { return gw.valid(i); }
[168]1389 
[266]1390//     //int nodeNum() const { return gw.nodeNum(); }
1391//     //int edgeNum() const { return gw.edgeNum(); }
[168]1392 
[266]1393//     //template<typename I> Node aNode(const I& e) const {
1394//     //  return gw.aNode(e); }
1395//     //template<typename I> Node bNode(const I& e) const {
1396//     //  return gw.bNode(e); }
[168]1397 
[266]1398//     //Node addNode() const { return gw.addNode(); }
1399//     //Edge addEdge(const Node& tail, const Node& head) const {
1400//     //  return gw.addEdge(tail, head); }
[168]1401 
[266]1402//     //void erase(const OutEdgeIt& e) {
1403//     //  first_out_edge(this->tail(e))=e;
1404//     //}
1405//     void erase(const Edge& e) {
1406//       OutEdgeIt f(e);
1407//       next(f);
1408//       first_out_edges.set(this->tail(e), f);
1409//     }
1410//     //template<typename I> void erase(const I& i) const { gw.erase(i); }
[168]1411 
[266]1412//     //void clear() const { gw.clear(); }
[168]1413   
[266]1414//     template<typename T> class NodeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> {
1415//     public:
1416//       NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) :
1417//      ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
1418//       NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) :
1419//      ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
1420//     };
[168]1421
[266]1422//     template<typename T> class EdgeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> {
1423//     public:
1424//       EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) :
1425//      ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
1426//       EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) :
1427//      ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
1428//     };
1429//   };
[168]1430
[266]1431//   template<typename GraphWrapper>
1432//   class FilterGraphWrapper {
1433//   };
[168]1434
[266]1435//   template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
1436//   class FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
[168]1437
[266]1438//     //Graph* graph;
[168]1439 
[266]1440//   public:
1441//     //typedef Graph BaseGraph;
[168]1442
[266]1443//     typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
1444//     typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
[168]1445
[266]1446//     typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
1447//     typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
1448//     //typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
1449//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
1450//     typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
[168]1451
[266]1452//     //FilterGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
[168]1453   
[266]1454//   public:
1455//     FilterGraphWrapper(const Graph& _G, FlowMap& _flow,
1456//                         const CapacityMap& _capacity) :
1457//       ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), dist(*this, gw.nodeNum()) {
1458//     }
[168]1459
[266]1460//     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
1461//       ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
1462//       while (valid(e) && (dist.get(tail(e))/*+1!=*/>=dist.get(head(e))))
1463//      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1464//       return e;
1465//     }
[168]1466
[266]1467//     NodeIt& next(NodeIt& e) const {
1468//       return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1469//     }
[168]1470
[266]1471//     OutEdgeIt& next(OutEdgeIt& e) const {
1472//       ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1473//       while (valid(e) && (dist.get(tail(e))/*+1!*/>=dist.get(head(e))))
1474//      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1475//       return e;
1476//     }
[168]1477
[266]1478//     NodeIt& first(NodeIt& n) const {
1479//       return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
1480//     }
[168]1481
[266]1482//     void erase(const Edge& e) {
1483//       OutEdgeIt f(e);
1484//       ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
1485//       while (valid(f) && (dist.get(tail(f))/*+1!=*/>=dist.get(head(f))))
1486//      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
1487//       first_out_edges.set(this->tail(e), f);
1488//     }
[168]1489
[266]1490//     //TrivGraphWrapper() : graph(0) { }
1491//     //TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
[168]1492
[266]1493//     //void setGraph(Graph& _graph) { graph = &_graph; }
1494//     //Graph& getGraph() const { return (*graph); }
[168]1495   
[266]1496//     //template<typename I> I& first(I& i) const { return gw.first(i); }
1497//     //template<typename I, typename P> I& first(I& i, const P& p) const {
1498//     //  return gw.first(i, p); }
[168]1499   
[266]1500//     //template<typename I> I getNext(const I& i) const {
1501//     //  return gw.getNext(i); }
1502//     //template<typename I> I& next(I &i) const { return gw.next(i); }   
[168]1503
[266]1504//     template< typename It > It first() const {
1505//       It e; first(e); return e; }
[168]1506
[266]1507//     template< typename It > It first(const Node& v) const {
1508//       It e; first(e, v); return e; }
[168]1509
[266]1510//     //Node head(const Edge& e) const { return gw.head(e); }
1511//     //Node tail(const Edge& e) const { return gw.tail(e); }
[168]1512
[266]1513//     //template<typename I> bool valid(const I& i) const
1514//     //  { return gw.valid(i); }
[168]1515 
[266]1516//     //template<typename I> void setInvalid(const I &i);
1517//     //{ return gw.setInvalid(i); }
[168]1518
[266]1519//     //int nodeNum() const { return gw.nodeNum(); }
1520//     //int edgeNum() const { return gw.edgeNum(); }
[168]1521 
[266]1522//     //template<typename I> Node aNode(const I& e) const {
1523//     //  return gw.aNode(e); }
1524//     //template<typename I> Node bNode(const I& e) const {
1525//     //  return gw.bNode(e); }
[168]1526 
[266]1527//     //Node addNode() const { return gw.addNode(); }
1528//     //Edge addEdge(const Node& tail, const Node& head) const {
1529//     //  return gw.addEdge(tail, head); }
[168]1530 
[266]1531//     //template<typename I> void erase(const I& i) const { gw.erase(i); }
[168]1532 
[266]1533//     //void clear() const { gw.clear(); }
[168]1534   
[266]1535//     template<typename T> class NodeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> {
1536//     public:
1537//       NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) :
1538//      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
1539//       NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) :
1540//      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
1541//     };
[168]1542
[266]1543//     template<typename T> class EdgeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> {
1544//     public:
1545//       EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) :
1546//      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
1547//       EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) :
1548//      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
1549//     };
[168]1550
[266]1551//   public:
1552//     ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
[155]1553
[266]1554//   };
[76]1555
1556
[148]1557
1558// // FIXME: comparison should be made better!!!
1559//   template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap>
1560//   class ResGraphWrapper
1561//   {
1562//     Graph* graph;
[76]1563 
[148]1564//   public:
1565//     typedef Graph BaseGraph;
[76]1566
[174]1567//     typedef typename Graph::Node Node;
1568//     typedef typename Graph::Edge Edge;
1569 
[148]1570//     typedef typename Graph::NodeIt NodeIt;
[76]1571   
[148]1572//     class OutEdgeIt {
1573//     public:
[174]1574//       //Graph::Node n;
[148]1575//       bool out_or_in;
1576//       typename Graph::OutEdgeIt o;
1577//       typename Graph::InEdgeIt i;   
1578//     };
1579//     class InEdgeIt {
1580//     public:
[174]1581//       //Graph::Node n;
[148]1582//       bool out_or_in;
1583//       typename Graph::OutEdgeIt o;
1584//       typename Graph::InEdgeIt i;   
1585//     };
1586//     typedef typename Graph::SymEdgeIt SymEdgeIt;
[174]1587//     typedef typename Graph::EdgeIt EdgeIt;
[76]1588
[259]1589//     int nodeNum() const { return gw.nodeNum(); }
1590//     int edgeNum() const { return gw.edgeNum(); }
[76]1591
[259]1592//     Node& first(Node& n) const { return gw.first(n); }
[76]1593
[174]1594//     // Edge and SymEdge  is missing!!!!
1595//     // Edge <-> In/OutEdgeIt conversion is missing!!!!
[76]1596
[148]1597//     //FIXME
[212]1598//     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const
[148]1599//       {
1600//      e.n=n;
[259]1601//      gw.first(e.o,n);
1602//      while(gw.valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
1603//        gw.goNext(e.o);
1604//      if(!gw.valid(e.o)) {
1605//        gw.first(e.i,n);
1606//        while(gw.valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
1607//          gw.goNext(e.i);
[148]1608//      }
1609//      return e;
1610//       }
1611// /*
1612//   OutEdgeIt &goNext(OutEdgeIt &e)
1613//   {
[259]1614//   if(gw.valid(e.o)) {
1615//   while(gw.valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
1616//   gw.goNext(e.o);
1617//   if(gw.valid(e.o)) return e;
1618//   else gw.first(e.i,e.n);
[148]1619//   }
1620//   else {
[259]1621//   while(gw.valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
1622//   gw.goNext(e.i);
[148]1623//   return e;
1624//   }
1625//   }
1626//   OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
1627// */
[259]1628//     //bool valid(const OutEdgeIt e) { return gw.valid(e.o)||gw.valid(e.i);}
[76]1629
[148]1630//     //FIXME
[212]1631//     InEdgeIt& first(InEdgeIt& e, const Node& n) const
[148]1632//       {
1633//      e.n=n;
[259]1634//      gw.first(e.i,n);
1635//      while(gw.valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
1636//        gw.goNext(e.i);
1637//      if(!gw.valid(e.i)) {
1638//        gw.first(e.o,n);
1639//        while(gw.valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
1640//          gw.goNext(e.o);
[148]1641//      }
1642//      return e;
1643//       }
1644// /*
1645//   InEdgeIt &goNext(InEdgeIt &e)
1646//   {
[259]1647//   if(gw.valid(e.i)) {
1648//   while(gw.valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
1649//   gw.goNext(e.i);
1650//   if(gw.valid(e.i)) return e;
1651//   else gw.first(e.o,e.n);
[148]1652//   }
1653//   else {
[259]1654//   while(gw.valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
1655//   gw.goNext(e.o);
[148]1656//   return e;
1657//   }
1658//   }
1659//   InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
1660// */
[259]1661//     //bool valid(const InEdgeIt e) { return gw.valid(e.i)||gw.valid(e.o);}
[76]1662
[259]1663//     //template<typename I> I &goNext(I &i); { return gw.goNext(i); }
1664//     //template<typename I> I next(const I i); { return gw.goNext(i); }
[76]1665
[148]1666//     template< typename It > It first() const {
[212]1667//       It e; first(e); return e; }
[76]1668
[174]1669//     template< typename It > It first(Node v) const {
[212]1670//       It e; first(e, v); return e; }
[76]1671
[259]1672//     Node head(const Edge& e) const { return gw.head(e); }
1673//     Node tail(const Edge& e) const { return gw.tail(e); }
[76]1674 
[174]1675//     template<typename I> Node aNode(const I& e) const {
[259]1676//       return gw.aNode(e); }
[174]1677//     template<typename I> Node bNode(const I& e) const {
[259]1678//       return gw.bNode(e); }
[76]1679 
[148]1680//     //template<typename I> bool valid(const I i);
[259]1681//     //{ return gw.valid(i); }
[76]1682 
[148]1683//     //template<typename I> void setInvalid(const I &i);
[259]1684//     //{ return gw.setInvalid(i); }
[76]1685 
[259]1686//     Node addNode() { return gw.addNode(); }
[174]1687//     Edge addEdge(const Node& tail, const Node& head) {
[259]1688//       return gw.addEdge(tail, head); }
[76]1689 
[259]1690//     template<typename I> void erase(const I& i) { gw.erase(i); }
[76]1691 
[259]1692//     void clear() { gw.clear(); }
[76]1693 
[148]1694//     template<typename S> class NodeMap : public Graph::NodeMap<S> { };
1695//     template<typename S> class EdgeMap : public Graph::EdgeMap<S> { };
[76]1696 
[148]1697//     void setGraph(Graph& _graph) { graph = &_graph; }
1698//     Graph& getGraph() { return (*graph); }
[76]1699
[148]1700//     //ResGraphWrapper() : graph(0) { }
1701//     ResGraphWrapper(Graph& _graph) : graph(&_graph) { }
1702//   };
[76]1703
[105]1704} //namespace hugo
[76]1705
[259]1706#endif //HUGO_GRAPH_WRAPPER_H
[76]1707
Note: See TracBrowser for help on using the repository browser.