COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/marci/graph_wrapper.h @ 235:aa50acc936dc

Last change on this file since 235:aa50acc936dc was 235:aa50acc936dc, checked in by marci, 20 years ago

.

File size: 43.0 KB
RevLine 
[174]1// -*- c++ -*-
[76]2#ifndef GRAPH_WRAPPER_H
3#define GRAPH_WRAPPER_H
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;
[76]18    typedef typename Graph::NodeIt NodeIt;
19
[174]20    typedef typename Graph::Edge Edge;
[76]21    typedef typename Graph::OutEdgeIt OutEdgeIt;
22    typedef typename Graph::InEdgeIt InEdgeIt;
[155]23    //typedef typename Graph::SymEdgeIt SymEdgeIt;
[174]24    typedef typename Graph::EdgeIt EdgeIt;
[168]25
26    //TrivGraphWrapper() : graph(0) { }
27    TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
28
29    void setGraph(Graph& _graph) { graph = &_graph; }
30    Graph& getGraph() const { return (*graph); }
[76]31   
[212]32    template<typename I> I& first(I& i) const { return graph->first(i); }
33    template<typename I, typename P> I& first(I& i, const P& p) const {
34      return graph->first(i, p); }
[155]35   
36    template<typename I> I getNext(const I& i) const {
37      return graph->getNext(i); }
38    template<typename I> I& next(I &i) const { return graph->next(i); }   
[76]39
40    template< typename It > It first() const {
[212]41      It e; first(e); return e; }
[76]42
[174]43    template< typename It > It first(const Node& v) const {
[212]44      It e; first(e, v); return e; }
[76]45
[174]46    Node head(const Edge& e) const { return graph->head(e); }
47    Node tail(const Edge& e) const { return graph->tail(e); }
[155]48
49    template<typename I> bool valid(const I& i) const
50      { return graph->valid(i); }
51 
52    //template<typename I> void setInvalid(const I &i);
53    //{ return graph->setInvalid(i); }
54
55    int nodeNum() const { return graph->nodeNum(); }
56    int edgeNum() const { return graph->edgeNum(); }
[76]57 
[174]58    template<typename I> Node aNode(const I& e) const {
[76]59      return graph->aNode(e); }
[174]60    template<typename I> Node bNode(const I& e) const {
[76]61      return graph->bNode(e); }
62 
[174]63    Node addNode() const { return graph->addNode(); }
64    Edge addEdge(const Node& tail, const Node& head) const {
[76]65      return graph->addEdge(tail, head); }
66 
67    template<typename I> void erase(const I& i) const { graph->erase(i); }
68 
69    void clear() const { graph->clear(); }
[155]70   
[76]71    template<typename T> class NodeMap : public Graph::NodeMap<T> {
72    public:
[155]73      NodeMap(const TrivGraphWrapper<Graph>& _G) :
[158]74        Graph::NodeMap<T>(_G.getGraph()) { }
[155]75      NodeMap(const TrivGraphWrapper<Graph>& _G, T a) :
[158]76        Graph::NodeMap<T>(_G.getGraph(), a) { }
[76]77    };
[168]78
[155]79    template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
80    public:
81      EdgeMap(const TrivGraphWrapper<Graph>& _G) :
[158]82        Graph::EdgeMap<T>(_G.getGraph()) { }
[155]83      EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) :
[158]84        Graph::EdgeMap<T>(_G.getGraph(), a) { }
[155]85    };
[76]86  };
87
[212]88  template<typename GraphWrapper>
89  class GraphWrapperSkeleton {
90  protected:
91    GraphWrapper gw;
92 
93  public:
94    typedef typename GraphWrapper::BaseGraph BaseGraph;
95
96    typedef typename GraphWrapper::Node Node;
97    typedef typename GraphWrapper::NodeIt NodeIt;
98
99    typedef typename GraphWrapper::Edge Edge;
100    typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
101    typedef typename GraphWrapper::InEdgeIt InEdgeIt;
102    //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
103    typedef typename GraphWrapper::EdgeIt EdgeIt;
104
105    //GraphWrapperSkeleton() : gw() { }
[230]106    GraphWrapperSkeleton(GraphWrapper _gw) : gw(_gw) { }
[212]107
108    void setGraph(BaseGraph& _graph) { gw.setGraph(_graph); }
109    BaseGraph& getGraph() const { return gw.getGraph(); }
110   
111    template<typename I> I& first(I& i) const { return gw.first(i); }
112    template<typename I, typename P> I& first(I& i, const P& p) const {
113      return gw.first(i, p); }
114   
115    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
116    template<typename I> I& next(I &i) const { return gw.next(i); }   
117
118    template< typename It > It first() const {
119      It e; this->first(e); return e; }
120
121    template< typename It > It first(const Node& v) const {
122      It e; this->first(e, v); return e; }
123
124    Node head(const Edge& e) const { return gw.head(e); }
125    Node tail(const Edge& e) const { return gw.tail(e); }
126
127    template<typename I> bool valid(const I& i) const { return gw.valid(i); }
128 
129    //template<typename I> void setInvalid(const I &i);
130    //{ return graph->setInvalid(i); }
131
132    int nodeNum() const { return gw.nodeNum(); }
133    int edgeNum() const { return gw.edgeNum(); }
134 
135    template<typename I> Node aNode(const I& e) const { return gw.aNode(e); }
136    template<typename I> Node bNode(const I& e) const { return gw.bNode(e); }
137 
138    Node addNode() const { return gw.addNode(); }
139    Edge addEdge(const Node& tail, const Node& head) const {
140      return gw.addEdge(tail, head); }
141 
142    template<typename I> void erase(const I& i) const { gw.erase(i); }
143 
144    void clear() const { gw.clear(); }
145   
146    template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
147    public:
148      NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) :
149        GraphWrapper::NodeMap<T>(_G.gw) { }
150      NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) :
151        GraphWrapper::NodeMap<T>(_G.gw, a) { }
152    };
153
154    template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> {
155    public:
156      EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) :
157        GraphWrapper::EdgeMap<T>(_G.gw) { }
158      EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) :
159        GraphWrapper::EdgeMap<T>(_G.gw, a) { }
160    };
161  };
162
[230]163//   template<typename Graph>
164//   class RevGraphWrapper
165//   {
166//   protected:
167//     Graph* graph;
168 
169//   public:
170//     typedef Graph BaseGraph;
171
172//     typedef typename Graph::Node Node;   
173//     typedef typename Graph::NodeIt NodeIt;
174 
175//     typedef typename Graph::Edge Edge;
176//     typedef typename Graph::OutEdgeIt InEdgeIt;
177//     typedef typename Graph::InEdgeIt OutEdgeIt;
178//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
179//     typedef typename Graph::EdgeIt EdgeIt;
180
181//     //RevGraphWrapper() : graph(0) { }
182//     RevGraphWrapper(Graph& _graph) : graph(&_graph) { }
183
184//     void setGraph(Graph& _graph) { graph = &_graph; }
185//     Graph& getGraph() const { return (*graph); }
186   
187//     template<typename I> I& first(I& i) const { return graph->first(i); }
188//     template<typename I, typename P> I& first(I& i, const P& p) const {
189//       return graph->first(i, p); }
190
191//     template<typename I> I getNext(const I& i) const {
192//       return graph->getNext(i); }
193//     template<typename I> I& next(I &i) const { return graph->next(i); }   
194
195//     template< typename It > It first() const {
196//       It e; first(e); return e; }
197
198//     template< typename It > It first(const Node& v) const {
199//       It e; first(e, v); return e; }
200
201//     Node head(const Edge& e) const { return graph->tail(e); }
202//     Node tail(const Edge& e) const { return graph->head(e); }
203 
204//     template<typename I> bool valid(const I& i) const
205//       { return graph->valid(i); }
206 
207//     //template<typename I> void setInvalid(const I &i);
208//     //{ return graph->setInvalid(i); }
209 
210//     template<typename I> Node aNode(const I& e) const {
211//       return graph->aNode(e); }
212//     template<typename I> Node bNode(const I& e) const {
213//       return graph->bNode(e); }
214
215//     Node addNode() const { return graph->addNode(); }
216//     Edge addEdge(const Node& tail, const Node& head) const {
217//       return graph->addEdge(tail, head); }
218 
219//     int nodeNum() const { return graph->nodeNum(); }
220//     int edgeNum() const { return graph->edgeNum(); }
221 
222//     template<typename I> void erase(const I& i) const { graph->erase(i); }
223 
224//     void clear() const { graph->clear(); }
225
226//     template<typename T> class NodeMap : public Graph::NodeMap<T> {
227//     public:
228//       NodeMap(const RevGraphWrapper<Graph>& _G) :
229//      Graph::NodeMap<T>(_G.getGraph()) { }
230//       NodeMap(const RevGraphWrapper<Graph>& _G, T a) :
231//      Graph::NodeMap<T>(_G.getGraph(), a) { }
232//     };
233
234//     template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
235//     public:
236//       EdgeMap(const RevGraphWrapper<Graph>& _G) :
237//      Graph::EdgeMap<T>(_G.getGraph()) { }
238//       EdgeMap(const RevGraphWrapper<Graph>& _G, T a) :
239//      Graph::EdgeMap<T>(_G.getGraph(), a) { }
240//     };
241//   };
242
[235]243//   template<typename /*Graph*/GraphWrapper
244//   /*=typename GraphWrapperSkeleton< TrivGraphWrapper<Graph>*/ >
245//   class RevGraphWrapper :
246//     public GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/ {
247//   protected:
248//     //Graph* graph;
[230]249   
[235]250//   public:
251//     //typedef Graph BaseGraph;
252
253//     //typedef typename Graph::Node Node;   
254//     //typedef typename Graph::NodeIt NodeIt;
255 
256//     //typedef typename Graph::Edge Edge;
257//     typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::OutEdgeIt InEdgeIt;
258//     typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::InEdgeIt OutEdgeIt;
259//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
260//     //typedef typename Graph::EdgeIt EdgeIt;
261
262//     //RevGraphWrapper() : graph(0) { }
263//     RevGraphWrapper(GraphWrapper _gw/*BaseGraph& _graph*/) : GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/(_gw/*TrivGraphWrapper<Graph>(_graph)*/) { }
264   
265//     //void setGraph(Graph& _graph) { graph = &_graph; }
266//     //Graph& getGraph() const { return (*graph); }
267   
268//     //template<typename I> I& first(I& i) const { return graph->first(i); }
269//     //template<typename I, typename P> I& first(I& i, const P& p) const {
270//     //  return graph->first(i, p); }
271
272//     //template<typename I> I getNext(const I& i) const {
273//     //  return graph->getNext(i); }
274//     //template<typename I> I& next(I &i) const { return graph->next(i); }   
275
276//     //template< typename It > It first() const {
277//     //  It e; first(e); return e; }
278
279//     //template< typename It > It first(const Node& v) const {
280//     //  It e; first(e, v); return e; }
281
282//     //Node head(const Edge& e) const { return graph->tail(e); }
283//     //Node tail(const Edge& e) const { return graph->head(e); }
284 
285//     //template<typename I> bool valid(const I& i) const
286//     //  { return graph->valid(i); }
287 
288//     //template<typename I> void setInvalid(const I &i);
289//     //{ return graph->setInvalid(i); }
290 
291//     //template<typename I> Node aNode(const I& e) const {
292//     //  return graph->aNode(e); }
293//     //template<typename I> Node bNode(const I& e) const {
294//     //  return graph->bNode(e); }
295
296//     //Node addNode() const { return graph->addNode(); }
297//     //Edge addEdge(const Node& tail, const Node& head) const {
298//     //  return graph->addEdge(tail, head); }
299 
300//     //int nodeNum() const { return graph->nodeNum(); }
301//     //int edgeNum() const { return graph->edgeNum(); }
302 
303//     //template<typename I> void erase(const I& i) const { graph->erase(i); }
304 
305//     //void clear() const { graph->clear(); }
306
307//     template<typename T> class NodeMap :
308//       public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>
309//     {
310//     public:
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) { }
315//     };
316   
317//     template<typename T> class EdgeMap :
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) { }
324//     };
325//   };
326
327
328  template<typename GraphWrapper>
329  class RevGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
[230]330  public:
[235]331    typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt InEdgeIt;
332    typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt OutEdgeIt;
[230]333   
[235]334    RevGraphWrapper(GraphWrapper _gw) :
335      GraphWrapperSkeleton<GraphWrapper>(_gw) { } 
[76]336  };
337
[155]338
[158]339  template<typename Graph>
340  class UndirGraphWrapper {
[199]341  protected:
[158]342    Graph* graph;
343 
344  public:
345    typedef Graph BaseGraph;
346
[174]347    typedef typename Graph::Node Node;
[158]348    typedef typename Graph::NodeIt NodeIt;
349
[174]350    //typedef typename Graph::Edge Edge;
[158]351    //typedef typename Graph::OutEdgeIt OutEdgeIt;
352    //typedef typename Graph::InEdgeIt InEdgeIt;
353    //typedef typename Graph::SymEdgeIt SymEdgeIt;
[174]354    //typedef typename Graph::EdgeIt EdgeIt;
[158]355
356    //private:
[174]357    typedef typename Graph::Edge GraphEdge;
[158]358    typedef typename Graph::OutEdgeIt GraphOutEdgeIt;
359    typedef typename Graph::InEdgeIt GraphInEdgeIt;
360    //public:
361
[168]362    //UndirGraphWrapper() : graph(0) { }
363    UndirGraphWrapper(Graph& _graph) : graph(&_graph) { }
364
365    void setGraph(Graph& _graph) { graph = &_graph; }
366    Graph& getGraph() const { return (*graph); }
367 
[174]368    class Edge {
[158]369      friend class UndirGraphWrapper<Graph>;
370      bool out_or_in; //true iff out
371      GraphOutEdgeIt out;
372      GraphInEdgeIt in;
373    public:
[174]374      Edge() : out_or_in(), out(), in() { }
375      Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
376      operator GraphEdge() const {
[158]377        if (out_or_in) return(out); else return(in);
378      }
[174]379      friend bool operator==(const Edge& u, const Edge& v) {
380        if (v.out_or_in)
381          return (u.out_or_in && u.out==v.out);
382        else
383          return (!u.out_or_in && u.in==v.in);
384      }
385      friend bool operator!=(const Edge& u, const Edge& v) {
386        if (v.out_or_in)
387          return (!u.out_or_in || u.out!=v.out);
388        else
389          return (u.out_or_in || u.in!=v.in);
390      }
[158]391    };
392
[174]393    class OutEdgeIt : public Edge {
[158]394      friend class UndirGraphWrapper<Graph>;
395    public:
[174]396      OutEdgeIt() : Edge() { }
397      OutEdgeIt(const Invalid& i) : Edge(i) { }
398      OutEdgeIt(const UndirGraphWrapper& _G, const Node& n) : Edge() {
399        out_or_in=true;
[212]400        _G.graph->first(out, n);
[158]401        if (!(_G.graph->valid(out))) {
402          out_or_in=false;
[212]403          _G.graph->first(in, n);
[158]404        }
405      }
406    };
407
[212]408    OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
[158]409      e.out_or_in=true;
[212]410      graph->first(e.out, n);
[158]411      if (!(graph->valid(e.out))) {
412        e.out_or_in=false;
[212]413        graph->first(e.in, n);
[158]414      }
415      return e;
416    }
417
418    OutEdgeIt& next(OutEdgeIt& e) const {
419      if (e.out_or_in) {
[174]420        Node n=graph->tail(e.out);
[158]421        graph->next(e.out);
422        if (!graph->valid(e.out)) {
423          e.out_or_in=false;
[212]424          graph->first(e.in, n);
[158]425        }
426      } else {
427        graph->next(e.in);
428      }
429      return e;
430    }
431
[174]432    Node aNode(const OutEdgeIt& e) const {
[158]433      if (e.out_or_in) return graph->tail(e); else return graph->head(e); }
[174]434    Node bNode(const OutEdgeIt& e) const {
[158]435      if (e.out_or_in) return graph->head(e); else return graph->tail(e); }
436
437    typedef OutEdgeIt InEdgeIt;
438
[212]439    template<typename I> I& first(I& i) const { return graph->first(i); }
440//     template<typename I, typename P> I& first(I& i, const P& p) const {
441//       return graph->first(i, p); }
[158]442   
443    template<typename I> I getNext(const I& i) const {
444      return graph->getNext(i); }
445    template<typename I> I& next(I &i) const { return graph->next(i); }   
446
447    template< typename It > It first() const {
[212]448      It e; first(e); return e; }
[158]449
[174]450    template< typename It > It first(const Node& v) const {
[212]451      It e; first(e, v); return e; }
[158]452
[174]453    Node head(const Edge& e) const { return graph->head(e); }
454    Node tail(const Edge& e) const { return graph->tail(e); }
[158]455
456    template<typename I> bool valid(const I& i) const
457      { return graph->valid(i); }
458 
459    //template<typename I> void setInvalid(const I &i);
460    //{ return graph->setInvalid(i); }
461
462    int nodeNum() const { return graph->nodeNum(); }
463    int edgeNum() const { return graph->edgeNum(); }
464 
[174]465//     template<typename I> Node aNode(const I& e) const {
[158]466//       return graph->aNode(e); }
[174]467//     template<typename I> Node bNode(const I& e) const {
[158]468//       return graph->bNode(e); }
469 
[174]470    Node addNode() const { return graph->addNode(); }
[231]471// FIXME: ez igy nem jo, mert nem
472//    Edge addEdge(const Node& tail, const Node& head) const {
473//      return graph->addEdge(tail, head); }
[158]474 
475    template<typename I> void erase(const I& i) const { graph->erase(i); }
476 
477    void clear() const { graph->clear(); }
478   
479    template<typename T> class NodeMap : public Graph::NodeMap<T> {
480    public:
481      NodeMap(const UndirGraphWrapper<Graph>& _G) :
482        Graph::NodeMap<T>(_G.getGraph()) { }
483      NodeMap(const UndirGraphWrapper<Graph>& _G, T a) :
484        Graph::NodeMap<T>(_G.getGraph(), a) { }
485    };
[168]486
[158]487    template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
488    public:
489      EdgeMap(const UndirGraphWrapper<Graph>& _G) :
490        Graph::EdgeMap<T>(_G.getGraph()) { }
491      EdgeMap(const UndirGraphWrapper<Graph>& _G, T a) :
492        Graph::EdgeMap<T>(_G.getGraph(), a) { }
493    };
494  };
495
496
497
[155]498//   template<typename Graph>
499//   class SymGraphWrapper
500//   {
501//     Graph* graph;
[76]502 
[155]503//   public:
504//     typedef Graph BaseGraph;
505
[174]506//     typedef typename Graph::Node Node;
507//     typedef typename Graph::Edge Edge;
508 
[155]509//     typedef typename Graph::NodeIt NodeIt;
510   
511//     //FIXME tag-ekkel megcsinalni, hogy abbol csinaljon
512//     //iranyitatlant, ami van
513//     //mert csak 1 dolgot lehet be typedef-elni
514//     typedef typename Graph::OutEdgeIt SymEdgeIt;
515//     //typedef typename Graph::InEdgeIt SymEdgeIt;
516//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
[174]517//     typedef typename Graph::EdgeIt EdgeIt;
[155]518
519//     int nodeNum() const { return graph->nodeNum(); }
520//     int edgeNum() const { return graph->edgeNum(); }
521   
[212]522//     template<typename I> I& first(I& i) const { return graph->first(i); }
523//     template<typename I, typename P> I& first(I& i, const P& p) const {
524//       return graph->first(i, p); }
[155]525//     //template<typename I> I next(const I i); { return graph->goNext(i); }
526//     //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
527
528//     template< typename It > It first() const {
[212]529//       It e; first(e); return e; }
[155]530
[174]531//     template< typename It > It first(Node v) const {
[212]532//       It e; first(e, v); return e; }
[155]533
[174]534//     Node head(const Edge& e) const { return graph->head(e); }
535//     Node tail(const Edge& e) const { return graph->tail(e); }
[155]536 
[174]537//     template<typename I> Node aNode(const I& e) const {
[155]538//       return graph->aNode(e); }
[174]539//     template<typename I> Node bNode(const I& e) const {
[155]540//       return graph->bNode(e); }
541 
542//     //template<typename I> bool valid(const I i);
543//     //{ return graph->valid(i); }
544 
545//     //template<typename I> void setInvalid(const I &i);
546//     //{ return graph->setInvalid(i); }
547 
[174]548//     Node addNode() { return graph->addNode(); }
549//     Edge addEdge(const Node& tail, const Node& head) {
[155]550//       return graph->addEdge(tail, head); }
551 
552//     template<typename I> void erase(const I& i) { graph->erase(i); }
553 
554//     void clear() { graph->clear(); }
555 
556//     template<typename T> class NodeMap : public Graph::NodeMap<T> { };
557//     template<typename T> class EdgeMap : public Graph::EdgeMap<T> { };
558 
559//     void setGraph(Graph& _graph) { graph = &_graph; }
560//     Graph& getGraph() { return (*graph); }
561
562//     //SymGraphWrapper() : graph(0) { }
563//     SymGraphWrapper(Graph& _graph) : graph(&_graph) { }
564//   };
565
566
567  template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
568  class ResGraphWrapper {
[76]569  public:
570    typedef Graph BaseGraph;
[174]571    typedef typename Graph::Node Node;
[155]572    typedef typename Graph::NodeIt NodeIt;
573  private:
574    typedef typename Graph::OutEdgeIt OldOutEdgeIt;
575    typedef typename Graph::InEdgeIt OldInEdgeIt;
[199]576  protected:
[174]577    const Graph* graph;
[155]578    FlowMap* flow;
579    const CapacityMap* capacity;
580  public:
[168]581
[155]582    ResGraphWrapper(const Graph& _G, FlowMap& _flow,
583             const CapacityMap& _capacity) :
[174]584      graph(&_G), flow(&_flow), capacity(&_capacity) { }
[168]585
586    void setGraph(const Graph& _graph) { graph = &_graph; }
[174]587    const Graph& getGraph() const { return (*graph); }
[168]588
[174]589    class Edge;
[155]590    class OutEdgeIt;
[174]591    friend class Edge;
[155]592    friend class OutEdgeIt;
[76]593
[174]594    class Edge {
[155]595      friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
596    protected:
[168]597      bool out_or_in; //true, iff out
[155]598      OldOutEdgeIt out;
599      OldInEdgeIt in;
600    public:
[174]601      Edge() : out_or_in(true) { }
602      Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
[168]603//       bool valid() const {
604//      return out_or_in && out.valid() || in.valid(); }
[174]605      friend bool operator==(const Edge& u, const Edge& v) {
606        if (v.out_or_in)
607          return (u.out_or_in && u.out==v.out);
608        else
609          return (!u.out_or_in && u.in==v.in);
610      }
611      friend bool operator!=(const Edge& u, const Edge& v) {
612        if (v.out_or_in)
613          return (!u.out_or_in || u.out!=v.out);
614        else
615          return (u.out_or_in || u.in!=v.in);
616      }
[155]617    };
618
619
[174]620    class OutEdgeIt : public Edge {
[155]621      friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
622    public:
623      OutEdgeIt() { }
[168]624      //FIXME
[174]625      OutEdgeIt(const Edge& e) : Edge(e) { }
626      OutEdgeIt(const Invalid& i) : Edge(i) { }
[155]627    private:
[174]628      OutEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() {
[212]629        resG.graph->first(out, v);
[174]630        while( resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); }
631        if (!resG.graph->valid(out)) {
[155]632          out_or_in=0;
[212]633          resG.graph->first(in, v);
[174]634          while( resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); }
[155]635        }
636      }
[168]637//     public:
638//       OutEdgeIt& operator++() {
639//      if (out_or_in) {
[174]640//        Node v=/*resG->*/G->aNode(out);
[168]641//        ++out;
[174]642//        while( out.valid() && !(Edge::free()>0) ) { ++out; }
[168]643//        if (!out.valid()) {
644//          out_or_in=0;
[212]645//          G->first(in, v);
[174]646//          while( in.valid() && !(Edge::free()>0) ) { ++in; }
[168]647//        }
648//      } else {
649//        ++in;
[174]650//        while( in.valid() && !(Edge::free()>0) ) { ++in; }
[168]651//      }
652//      return *this;
653//       }
[155]654    };
655
[174]656    class EdgeIt : public Edge {
[155]657      friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
[174]658      typename Graph::NodeIt v;
[155]659    public:
[174]660      EdgeIt() { }
661      //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { }
662      EdgeIt(const Invalid& i) : Edge(i) { }
663      EdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG) : Edge() {
[212]664        resG.graph->first(v);
665        if (resG.graph->valid(v)) resG.graph->first(out, v); else out=OldOutEdgeIt(INVALID);
[174]666        while (resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); }
667        while (resG.graph->valid(v) && !resG.graph->valid(out)) {
668          resG.graph->next(v);
[212]669          if (resG.graph->valid(v)) resG.graph->first(out, v);
[174]670          while (resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); }
[155]671        }
[174]672        if (!resG.graph->valid(out)) {
[155]673          out_or_in=0;
[212]674          resG.graph->first(v);
675          if (resG.graph->valid(v)) resG.graph->first(in, v); else in=OldInEdgeIt(INVALID);
[174]676          while (resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); }
677          while (resG.graph->valid(v) && !resG.graph->valid(in)) {
678            resG.graph->next(v);
[212]679            if (resG.graph->valid(v)) resG.graph->first(in, v);
[174]680            while (resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); }
[155]681          }
682        }
683      }
[174]684//       EdgeIt& operator++() {
[168]685//      if (out_or_in) {
686//        ++out;
[174]687//        while (out.valid() && !(Edge::free()>0) ) { ++out; }
[168]688//        while (v.valid() && !out.valid()) {
689//          ++v;
[212]690//          if (v.valid()) G->first(out, v);
[174]691//          while (out.valid() && !(Edge::free()>0) ) { ++out; }
[168]692//        }
693//        if (!out.valid()) {
694//          out_or_in=0;
[212]695//          G->first(v);
696//          if (v.valid()) G->first(in, v); else in=OldInEdgeIt();
[174]697//          while (in.valid() && !(Edge::free()>0) ) { ++in; }
[168]698//          while (v.valid() && !in.valid()) {
699//            ++v;
[212]700//            if (v.valid()) G->first(in, v);
[174]701//            while (in.valid() && !(Edge::free()>0) ) { ++in; }
[168]702//          } 
703//        }
704//      } else {
705//        ++in;
[174]706//        while (in.valid() && !(Edge::free()>0) ) { ++in; }
[168]707//        while (v.valid() && !in.valid()) {
708//          ++v;
[212]709//          if (v.valid()) G->first(in, v);
[174]710//          while (in.valid() && !(Edge::free()>0) ) { ++in; }
[168]711//        }
712//      }
713//      return *this;
714//       }
[155]715    };
716
[212]717    NodeIt& first(NodeIt& v) const { return graph->first(v); }
718    OutEdgeIt& first(OutEdgeIt& e, Node v) const {
[168]719      e=OutEdgeIt(*this, v);
[174]720      return e;
[155]721    }
[212]722    EdgeIt& first(EdgeIt& e) const {
[174]723      e=EdgeIt(*this);
724      return e;
[155]725    }
726   
[174]727    NodeIt& next(NodeIt& n) const { return graph->next(n); }
[155]728
729    OutEdgeIt& next(OutEdgeIt& e) const {
730      if (e.out_or_in) {
[174]731        Node v=graph->aNode(e.out);
732        graph->next(e.out);
733        while( graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); }
734        if (!graph->valid(e.out)) {
[155]735          e.out_or_in=0;
[212]736          graph->first(e.in, v);
[174]737          while( graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
[155]738        }
739      } else {
[174]740        graph->next(e.in);
741        while( graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
[155]742      }
743      return e;
744    }
745
[174]746    EdgeIt& next(EdgeIt& e) const {
[155]747      if (e.out_or_in) {
[174]748        graph->next(e.out);
749        while (graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); }
750          while (graph->valid(e.v) && !graph->valid(e.out)) {
751            graph->next(e.v);
[212]752            if (graph->valid(e.v)) graph->first(e.out, e.v);
[174]753            while (graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); }
[155]754          }
[174]755          if (!graph->valid(e.out)) {
[155]756            e.out_or_in=0;
[212]757            graph->first(e.v);
758            if (graph->valid(e.v)) graph->first(e.in, e.v); else e.in=OldInEdgeIt(INVALID);
[174]759            while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
760            while (graph->valid(e.v) && !graph->valid(e.in)) {
761              graph->next(e.v);
[212]762              if (graph->valid(e.v)) graph->first(e.in, e.v);
[174]763              while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
[155]764            } 
765          }
766        } else {
[174]767          graph->next(e.in);
768          while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
769          while (graph->valid(e.v) && !graph->valid(e.in)) {
770            graph->next(e.v);
[212]771            if (graph->valid(e.v)) graph->first(e.in, e.v);
[174]772            while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
[155]773          }
774        }
775        return e;
776      }
[76]777   
778
[155]779    template< typename It >
780    It first() const {
781      It e;
[212]782      first(e);
[155]783      return e;
784    }
[76]785
[155]786    template< typename It >
[174]787    It first(Node v) const {
[155]788      It e;
[212]789      first(e, v);
[155]790      return e;
791    }
[76]792
[174]793    Node tail(Edge e) const {
794      return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); }
795    Node head(Edge e) const {
796      return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); }
[76]797
[174]798    Node aNode(OutEdgeIt e) const {
799      return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); }
800    Node bNode(OutEdgeIt e) const {
801      return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); }
[76]802
[174]803    int id(Node v) const { return graph->id(v); }
[155]804
[174]805    bool valid(Node n) const { return graph->valid(n); }
806    bool valid(Edge e) const {
807      return e.out_or_in ? graph->valid(e.out) : graph->valid(e.in); }
[155]808
[174]809    void augment(const Edge& e, Number a) const {
[168]810      if (e.out_or_in) 
811        flow->set(e.out, flow->get(e.out)+a);
812      else 
813        flow->set(e.in, flow->get(e.in)-a);
814    }
815
[174]816    Number free(const Edge& e) const {
[168]817      if (e.out_or_in)
818        return (capacity->get(e.out)-flow->get(e.out));
819      else
820        return (flow->get(e.in));
821    }
822
823    Number free(OldOutEdgeIt out) const {
824      return (capacity->get(out)-flow->get(out));
825    }
826   
827    Number free(OldInEdgeIt in) const {
828      return (flow->get(in));
829    }
830
[155]831    template<typename T> class NodeMap : public Graph::NodeMap<T> {
832    public:
833      NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G)
[158]834        : Graph::NodeMap<T>(_G.getGraph()) { }
[155]835      NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G,
[158]836              T a) : Graph::NodeMap<T>(_G.getGraph(), a) { }
[155]837    };
838
839//     template <typename T>
840//     class NodeMap {
841//       typename Graph::NodeMap<T> node_map;
842//     public:
[174]843//       NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(*(_G.graph)) { }
844//       NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : node_map(*(_G.graph), a) { }
845//       void set(Node nit, T a) { node_map.set(nit, a); }
846//       T get(Node nit) const { return node_map.get(nit); }
[155]847//     };
848
849    template <typename T>
850    class EdgeMap {
851      typename Graph::EdgeMap<T> forward_map, backward_map;
852    public:
[158]853      EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : forward_map(_G.getGraph()), backward_map(_G.getGraph()) { }
854      EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(_G.getGraph(), a), backward_map(_G.getGraph(), a) { }
[174]855      void set(Edge e, T a) {
[155]856        if (e.out_or_in)
857          forward_map.set(e.out, a);
858        else
859          backward_map.set(e.in, a);
860      }
[174]861      T get(Edge e) {
[155]862        if (e.out_or_in)
863          return forward_map.get(e.out);
864        else
865          return backward_map.get(e.in);
866      }
867    };
[168]868  };
869
870  template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
871  class ErasingResGraphWrapper : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
872  protected:
873    ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
874    //ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
875  public:
876    ErasingResGraphWrapper(const Graph& _G, FlowMap& _flow,
877                           const CapacityMap& _capacity) :
878      ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity),
879      first_out_edges(*this) /*, dist(*this)*/ {
[174]880      for(NodeIt n=this->template first<NodeIt>(); this->valid(n); this->next(n)) {
[168]881        OutEdgeIt e;
[212]882        ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
[168]883        first_out_edges.set(n, e);
884      }
885    }
886
887    //void setGraph(Graph& _graph) { graph = &_graph; }
888    //Graph& getGraph() const { return (*graph); }
889 
890    //TrivGraphWrapper() : graph(0) { }
891    //ErasingResGraphWrapper(Graph& _graph) : graph(&_graph) { }
892
893    //typedef Graph BaseGraph;
894
[174]895    //typedef typename Graph::Node Node;
[168]896    //typedef typename Graph::NodeIt NodeIt;
897
[174]898    //typedef typename Graph::Edge Edge;
[168]899    //typedef typename Graph::OutEdgeIt OutEdgeIt;
900    //typedef typename Graph::InEdgeIt InEdgeIt;
901    //typedef typename Graph::SymEdgeIt SymEdgeIt;
[174]902    //typedef typename Graph::EdgeIt EdgeIt;
[168]903
[174]904    typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
[168]905    typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
906
[174]907    typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
[168]908    typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
909    //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
910    //typedef typename Graph::SymEdgeIt SymEdgeIt;
[174]911    //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
[168]912
[212]913    NodeIt& first(NodeIt& n) const {
914      return ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
[168]915    }
916
[212]917    OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
[168]918      e=first_out_edges.get(n);
919      return e;
920    }
921   
[212]922    //ROSSZ template<typename I> I& first(I& i) const { return first(i); }
923    //ROSSZ template<typename I, typename P> I& first(I& i, const P& p) const {
924    //  return first(i, p); }
[168]925   
926    //template<typename I> I getNext(const I& i) const {
927    //  return graph->getNext(i); }
928    //template<typename I> I& next(I &i) const { return graph->next(i); }   
929
930    template< typename It > It first() const {
[212]931      It e; first(e); return e; }
[168]932
[174]933    template< typename It > It first(const Node& v) const {
[212]934      It e; first(e, v); return e; }
[168]935
[174]936    //Node head(const Edge& e) const { return graph->head(e); }
937    //Node tail(const Edge& e) const { return graph->tail(e); }
[168]938
939    //template<typename I> bool valid(const I& i) const
940    //  { return graph->valid(i); }
941 
942    //int nodeNum() const { return graph->nodeNum(); }
943    //int edgeNum() const { return graph->edgeNum(); }
944 
[174]945    //template<typename I> Node aNode(const I& e) const {
[168]946    //  return graph->aNode(e); }
[174]947    //template<typename I> Node bNode(const I& e) const {
[168]948    //  return graph->bNode(e); }
949 
[174]950    //Node addNode() const { return graph->addNode(); }
951    //Edge addEdge(const Node& tail, const Node& head) const {
[168]952    //  return graph->addEdge(tail, head); }
953 
954    //void erase(const OutEdgeIt& e) {
955    //  first_out_edge(this->tail(e))=e;
956    //}
[174]957    void erase(const Edge& e) {
[168]958      OutEdgeIt f(e);
959      next(f);
960      first_out_edges.set(this->tail(e), f);
961    }
962    //template<typename I> void erase(const I& i) const { graph->erase(i); }
963 
964    //void clear() const { graph->clear(); }
965   
966    template<typename T> class NodeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> {
967    public:
968      NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) :
969        ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
970      NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) :
971        ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
972    };
973
974    template<typename T> class EdgeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> {
975    public:
976      EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) :
977        ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
978      EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) :
979        ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
980    };
981  };
982
983  template<typename GraphWrapper>
984  class FilterGraphWrapper {
985  };
986
987  template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
988  class FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
989
990    //Graph* graph;
991 
992  public:
993    //typedef Graph BaseGraph;
994
[174]995    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
[168]996    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
997
[174]998    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
[168]999    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
1000    //typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
1001    //typedef typename Graph::SymEdgeIt SymEdgeIt;
[174]1002    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
[168]1003
1004    //FilterGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
1005   
1006  public:
1007    FilterGraphWrapper(const Graph& _G, FlowMap& _flow,
1008                           const CapacityMap& _capacity) :
[199]1009      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), dist(*this, graph->nodeNum()) {
[168]1010    }
1011
[212]1012    OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
1013      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
[199]1014      while (valid(e) && (dist.get(tail(e))/*+1!=*/>=dist.get(head(e))))
[168]1015        ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1016      return e;
1017    }
1018
[174]1019    NodeIt& next(NodeIt& e) const {
[168]1020      return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1021    }
1022
1023    OutEdgeIt& next(OutEdgeIt& e) const {
1024      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
[199]1025      while (valid(e) && (dist.get(tail(e))/*+1!*/>=dist.get(head(e))))
[168]1026        ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1027      return e;
1028    }
1029
[212]1030    NodeIt& first(NodeIt& n) const {
1031      return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
[168]1032    }
1033
[174]1034    void erase(const Edge& e) {
[168]1035      OutEdgeIt f(e);
1036      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
[199]1037      while (valid(f) && (dist.get(tail(f))/*+1!=*/>=dist.get(head(f))))
[168]1038        ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
1039      first_out_edges.set(this->tail(e), f);
1040    }
1041
1042    //TrivGraphWrapper() : graph(0) { }
1043    //TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
1044
1045    //void setGraph(Graph& _graph) { graph = &_graph; }
1046    //Graph& getGraph() const { return (*graph); }
1047   
[212]1048    //template<typename I> I& first(I& i) const { return graph->first(i); }
1049    //template<typename I, typename P> I& first(I& i, const P& p) const {
1050    //  return graph->first(i, p); }
[168]1051   
1052    //template<typename I> I getNext(const I& i) const {
1053    //  return graph->getNext(i); }
1054    //template<typename I> I& next(I &i) const { return graph->next(i); }   
1055
1056    template< typename It > It first() const {
[212]1057      It e; first(e); return e; }
[168]1058
[174]1059    template< typename It > It first(const Node& v) const {
[212]1060      It e; first(e, v); return e; }
[168]1061
[174]1062    //Node head(const Edge& e) const { return graph->head(e); }
1063    //Node tail(const Edge& e) const { return graph->tail(e); }
[168]1064
1065    //template<typename I> bool valid(const I& i) const
1066    //  { return graph->valid(i); }
1067 
1068    //template<typename I> void setInvalid(const I &i);
1069    //{ return graph->setInvalid(i); }
1070
1071    //int nodeNum() const { return graph->nodeNum(); }
1072    //int edgeNum() const { return graph->edgeNum(); }
1073 
[174]1074    //template<typename I> Node aNode(const I& e) const {
[168]1075    //  return graph->aNode(e); }
[174]1076    //template<typename I> Node bNode(const I& e) const {
[168]1077    //  return graph->bNode(e); }
1078 
[174]1079    //Node addNode() const { return graph->addNode(); }
1080    //Edge addEdge(const Node& tail, const Node& head) const {
[168]1081    //  return graph->addEdge(tail, head); }
1082 
1083    //template<typename I> void erase(const I& i) const { graph->erase(i); }
1084 
1085    //void clear() const { graph->clear(); }
1086   
1087    template<typename T> class NodeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> {
1088    public:
1089      NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) :
1090        ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
1091      NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) :
1092        ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
1093    };
1094
1095    template<typename T> class EdgeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> {
1096    public:
1097      EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) :
1098        ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
1099      EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) :
1100        ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
1101    };
1102
1103  public:
1104    ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
[155]1105
[76]1106  };
1107
1108
[148]1109
1110// // FIXME: comparison should be made better!!!
1111//   template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap>
1112//   class ResGraphWrapper
1113//   {
1114//     Graph* graph;
[76]1115 
[148]1116//   public:
1117//     typedef Graph BaseGraph;
[76]1118
[174]1119//     typedef typename Graph::Node Node;
1120//     typedef typename Graph::Edge Edge;
1121 
[148]1122//     typedef typename Graph::NodeIt NodeIt;
[76]1123   
[148]1124//     class OutEdgeIt {
1125//     public:
[174]1126//       //Graph::Node n;
[148]1127//       bool out_or_in;
1128//       typename Graph::OutEdgeIt o;
1129//       typename Graph::InEdgeIt i;   
1130//     };
1131//     class InEdgeIt {
1132//     public:
[174]1133//       //Graph::Node n;
[148]1134//       bool out_or_in;
1135//       typename Graph::OutEdgeIt o;
1136//       typename Graph::InEdgeIt i;   
1137//     };
1138//     typedef typename Graph::SymEdgeIt SymEdgeIt;
[174]1139//     typedef typename Graph::EdgeIt EdgeIt;
[76]1140
[148]1141//     int nodeNum() const { return graph->nodeNum(); }
1142//     int edgeNum() const { return graph->edgeNum(); }
[76]1143
[212]1144//     Node& first(Node& n) const { return graph->first(n); }
[76]1145
[174]1146//     // Edge and SymEdge  is missing!!!!
1147//     // Edge <-> In/OutEdgeIt conversion is missing!!!!
[76]1148
[148]1149//     //FIXME
[212]1150//     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const
[148]1151//       {
1152//      e.n=n;
[212]1153//      graph->first(e.o,n);
[148]1154//      while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
1155//        graph->goNext(e.o);
1156//      if(!graph->valid(e.o)) {
[212]1157//        graph->first(e.i,n);
[148]1158//        while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
1159//          graph->goNext(e.i);
1160//      }
1161//      return e;
1162//       }
1163// /*
1164//   OutEdgeIt &goNext(OutEdgeIt &e)
1165//   {
1166//   if(graph->valid(e.o)) {
1167//   while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
1168//   graph->goNext(e.o);
1169//   if(graph->valid(e.o)) return e;
[212]1170//   else graph->first(e.i,e.n);
[148]1171//   }
1172//   else {
1173//   while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
1174//   graph->goNext(e.i);
1175//   return e;
1176//   }
1177//   }
1178//   OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
1179// */
1180//     //bool valid(const OutEdgeIt e) { return graph->valid(e.o)||graph->valid(e.i);}
[76]1181
[148]1182//     //FIXME
[212]1183//     InEdgeIt& first(InEdgeIt& e, const Node& n) const
[148]1184//       {
1185//      e.n=n;
[212]1186//      graph->first(e.i,n);
[148]1187//      while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
1188//        graph->goNext(e.i);
1189//      if(!graph->valid(e.i)) {
[212]1190//        graph->first(e.o,n);
[148]1191//        while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
1192//          graph->goNext(e.o);
1193//      }
1194//      return e;
1195//       }
1196// /*
1197//   InEdgeIt &goNext(InEdgeIt &e)
1198//   {
1199//   if(graph->valid(e.i)) {
1200//   while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
1201//   graph->goNext(e.i);
1202//   if(graph->valid(e.i)) return e;
[212]1203//   else graph->first(e.o,e.n);
[148]1204//   }
1205//   else {
1206//   while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
1207//   graph->goNext(e.o);
1208//   return e;
1209//   }
1210//   }
1211//   InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
1212// */
1213//     //bool valid(const InEdgeIt e) { return graph->valid(e.i)||graph->valid(e.o);}
[76]1214
[148]1215//     //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
1216//     //template<typename I> I next(const I i); { return graph->goNext(i); }
[76]1217
[148]1218//     template< typename It > It first() const {
[212]1219//       It e; first(e); return e; }
[76]1220
[174]1221//     template< typename It > It first(Node v) const {
[212]1222//       It e; first(e, v); return e; }
[76]1223
[174]1224//     Node head(const Edge& e) const { return graph->head(e); }
1225//     Node tail(const Edge& e) const { return graph->tail(e); }
[76]1226 
[174]1227//     template<typename I> Node aNode(const I& e) const {
[148]1228//       return graph->aNode(e); }
[174]1229//     template<typename I> Node bNode(const I& e) const {
[148]1230//       return graph->bNode(e); }
[76]1231 
[148]1232//     //template<typename I> bool valid(const I i);
1233//     //{ return graph->valid(i); }
[76]1234 
[148]1235//     //template<typename I> void setInvalid(const I &i);
1236//     //{ return graph->setInvalid(i); }
[76]1237 
[174]1238//     Node addNode() { return graph->addNode(); }
1239//     Edge addEdge(const Node& tail, const Node& head) {
[148]1240//       return graph->addEdge(tail, head); }
[76]1241 
[148]1242//     template<typename I> void erase(const I& i) { graph->erase(i); }
[76]1243 
[148]1244//     void clear() { graph->clear(); }
[76]1245 
[148]1246//     template<typename S> class NodeMap : public Graph::NodeMap<S> { };
1247//     template<typename S> class EdgeMap : public Graph::EdgeMap<S> { };
[76]1248 
[148]1249//     void setGraph(Graph& _graph) { graph = &_graph; }
1250//     Graph& getGraph() { return (*graph); }
[76]1251
[148]1252//     //ResGraphWrapper() : graph(0) { }
1253//     ResGraphWrapper(Graph& _graph) : graph(&_graph) { }
1254//   };
[76]1255
[105]1256} //namespace hugo
[76]1257
1258#endif //GRAPH_WRAPPER_H
1259
Note: See TracBrowser for help on using the repository browser.