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
Line 
1// -*- c++ -*-
2#ifndef GRAPH_WRAPPER_H
3#define GRAPH_WRAPPER_H
4
5#include <invalid.h>
6
7namespace hugo {
8
9  template<typename Graph>
10  class TrivGraphWrapper {
11  protected:
12    Graph* graph;
13 
14  public:
15    typedef Graph BaseGraph;
16
17    typedef typename Graph::Node Node;
18    typedef typename Graph::NodeIt NodeIt;
19
20    typedef typename Graph::Edge Edge;
21    typedef typename Graph::OutEdgeIt OutEdgeIt;
22    typedef typename Graph::InEdgeIt InEdgeIt;
23    //typedef typename Graph::SymEdgeIt SymEdgeIt;
24    typedef typename Graph::EdgeIt EdgeIt;
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); }
31   
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); }
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); }   
39
40    template< typename It > It first() const {
41      It e; first(e); return e; }
42
43    template< typename It > It first(const Node& v) const {
44      It e; first(e, v); return e; }
45
46    Node head(const Edge& e) const { return graph->head(e); }
47    Node tail(const Edge& e) const { return graph->tail(e); }
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(); }
57 
58    template<typename I> Node aNode(const I& e) const {
59      return graph->aNode(e); }
60    template<typename I> Node bNode(const I& e) const {
61      return graph->bNode(e); }
62 
63    Node addNode() const { return graph->addNode(); }
64    Edge addEdge(const Node& tail, const Node& head) const {
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(); }
70   
71    template<typename T> class NodeMap : public Graph::NodeMap<T> {
72    public:
73      NodeMap(const TrivGraphWrapper<Graph>& _G) :
74        Graph::NodeMap<T>(_G.getGraph()) { }
75      NodeMap(const TrivGraphWrapper<Graph>& _G, T a) :
76        Graph::NodeMap<T>(_G.getGraph(), a) { }
77    };
78
79    template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
80    public:
81      EdgeMap(const TrivGraphWrapper<Graph>& _G) :
82        Graph::EdgeMap<T>(_G.getGraph()) { }
83      EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) :
84        Graph::EdgeMap<T>(_G.getGraph(), a) { }
85    };
86  };
87
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() { }
106    GraphWrapperSkeleton(GraphWrapper _gw) : gw(_gw) { }
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
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
243//   template<typename /*Graph*/GraphWrapper
244//   /*=typename GraphWrapperSkeleton< TrivGraphWrapper<Graph>*/ >
245//   class RevGraphWrapper :
246//     public GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/ {
247//   protected:
248//     //Graph* graph;
249   
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> {
330  public:
331    typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt InEdgeIt;
332    typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt OutEdgeIt;
333   
334    RevGraphWrapper(GraphWrapper _gw) :
335      GraphWrapperSkeleton<GraphWrapper>(_gw) { } 
336  };
337
338
339  template<typename Graph>
340  class UndirGraphWrapper {
341  protected:
342    Graph* graph;
343 
344  public:
345    typedef Graph BaseGraph;
346
347    typedef typename Graph::Node Node;
348    typedef typename Graph::NodeIt NodeIt;
349
350    //typedef typename Graph::Edge Edge;
351    //typedef typename Graph::OutEdgeIt OutEdgeIt;
352    //typedef typename Graph::InEdgeIt InEdgeIt;
353    //typedef typename Graph::SymEdgeIt SymEdgeIt;
354    //typedef typename Graph::EdgeIt EdgeIt;
355
356    //private:
357    typedef typename Graph::Edge GraphEdge;
358    typedef typename Graph::OutEdgeIt GraphOutEdgeIt;
359    typedef typename Graph::InEdgeIt GraphInEdgeIt;
360    //public:
361
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 
368    class Edge {
369      friend class UndirGraphWrapper<Graph>;
370      bool out_or_in; //true iff out
371      GraphOutEdgeIt out;
372      GraphInEdgeIt in;
373    public:
374      Edge() : out_or_in(), out(), in() { }
375      Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
376      operator GraphEdge() const {
377        if (out_or_in) return(out); else return(in);
378      }
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      }
391    };
392
393    class OutEdgeIt : public Edge {
394      friend class UndirGraphWrapper<Graph>;
395    public:
396      OutEdgeIt() : Edge() { }
397      OutEdgeIt(const Invalid& i) : Edge(i) { }
398      OutEdgeIt(const UndirGraphWrapper& _G, const Node& n) : Edge() {
399        out_or_in=true;
400        _G.graph->first(out, n);
401        if (!(_G.graph->valid(out))) {
402          out_or_in=false;
403          _G.graph->first(in, n);
404        }
405      }
406    };
407
408    OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
409      e.out_or_in=true;
410      graph->first(e.out, n);
411      if (!(graph->valid(e.out))) {
412        e.out_or_in=false;
413        graph->first(e.in, n);
414      }
415      return e;
416    }
417
418    OutEdgeIt& next(OutEdgeIt& e) const {
419      if (e.out_or_in) {
420        Node n=graph->tail(e.out);
421        graph->next(e.out);
422        if (!graph->valid(e.out)) {
423          e.out_or_in=false;
424          graph->first(e.in, n);
425        }
426      } else {
427        graph->next(e.in);
428      }
429      return e;
430    }
431
432    Node aNode(const OutEdgeIt& e) const {
433      if (e.out_or_in) return graph->tail(e); else return graph->head(e); }
434    Node bNode(const OutEdgeIt& e) const {
435      if (e.out_or_in) return graph->head(e); else return graph->tail(e); }
436
437    typedef OutEdgeIt InEdgeIt;
438
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); }
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 {
448      It e; first(e); return e; }
449
450    template< typename It > It first(const Node& v) const {
451      It e; first(e, v); return e; }
452
453    Node head(const Edge& e) const { return graph->head(e); }
454    Node tail(const Edge& e) const { return graph->tail(e); }
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 
465//     template<typename I> Node aNode(const I& e) const {
466//       return graph->aNode(e); }
467//     template<typename I> Node bNode(const I& e) const {
468//       return graph->bNode(e); }
469 
470    Node addNode() const { return graph->addNode(); }
471// FIXME: ez igy nem jo, mert nem
472//    Edge addEdge(const Node& tail, const Node& head) const {
473//      return graph->addEdge(tail, head); }
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    };
486
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
498//   template<typename Graph>
499//   class SymGraphWrapper
500//   {
501//     Graph* graph;
502 
503//   public:
504//     typedef Graph BaseGraph;
505
506//     typedef typename Graph::Node Node;
507//     typedef typename Graph::Edge Edge;
508 
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;
517//     typedef typename Graph::EdgeIt EdgeIt;
518
519//     int nodeNum() const { return graph->nodeNum(); }
520//     int edgeNum() const { return graph->edgeNum(); }
521   
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); }
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 {
529//       It e; first(e); return e; }
530
531//     template< typename It > It first(Node v) const {
532//       It e; first(e, v); return e; }
533
534//     Node head(const Edge& e) const { return graph->head(e); }
535//     Node tail(const Edge& e) const { return graph->tail(e); }
536 
537//     template<typename I> Node aNode(const I& e) const {
538//       return graph->aNode(e); }
539//     template<typename I> Node bNode(const I& e) const {
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 
548//     Node addNode() { return graph->addNode(); }
549//     Edge addEdge(const Node& tail, const Node& head) {
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 {
569  public:
570    typedef Graph BaseGraph;
571    typedef typename Graph::Node Node;
572    typedef typename Graph::NodeIt NodeIt;
573  private:
574    typedef typename Graph::OutEdgeIt OldOutEdgeIt;
575    typedef typename Graph::InEdgeIt OldInEdgeIt;
576  protected:
577    const Graph* graph;
578    FlowMap* flow;
579    const CapacityMap* capacity;
580  public:
581
582    ResGraphWrapper(const Graph& _G, FlowMap& _flow,
583             const CapacityMap& _capacity) :
584      graph(&_G), flow(&_flow), capacity(&_capacity) { }
585
586    void setGraph(const Graph& _graph) { graph = &_graph; }
587    const Graph& getGraph() const { return (*graph); }
588
589    class Edge;
590    class OutEdgeIt;
591    friend class Edge;
592    friend class OutEdgeIt;
593
594    class Edge {
595      friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
596    protected:
597      bool out_or_in; //true, iff out
598      OldOutEdgeIt out;
599      OldInEdgeIt in;
600    public:
601      Edge() : out_or_in(true) { }
602      Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
603//       bool valid() const {
604//      return out_or_in && out.valid() || in.valid(); }
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      }
617    };
618
619
620    class OutEdgeIt : public Edge {
621      friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
622    public:
623      OutEdgeIt() { }
624      //FIXME
625      OutEdgeIt(const Edge& e) : Edge(e) { }
626      OutEdgeIt(const Invalid& i) : Edge(i) { }
627    private:
628      OutEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() {
629        resG.graph->first(out, v);
630        while( resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); }
631        if (!resG.graph->valid(out)) {
632          out_or_in=0;
633          resG.graph->first(in, v);
634          while( resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); }
635        }
636      }
637//     public:
638//       OutEdgeIt& operator++() {
639//      if (out_or_in) {
640//        Node v=/*resG->*/G->aNode(out);
641//        ++out;
642//        while( out.valid() && !(Edge::free()>0) ) { ++out; }
643//        if (!out.valid()) {
644//          out_or_in=0;
645//          G->first(in, v);
646//          while( in.valid() && !(Edge::free()>0) ) { ++in; }
647//        }
648//      } else {
649//        ++in;
650//        while( in.valid() && !(Edge::free()>0) ) { ++in; }
651//      }
652//      return *this;
653//       }
654    };
655
656    class EdgeIt : public Edge {
657      friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
658      typename Graph::NodeIt v;
659    public:
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() {
664        resG.graph->first(v);
665        if (resG.graph->valid(v)) resG.graph->first(out, v); else out=OldOutEdgeIt(INVALID);
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);
669          if (resG.graph->valid(v)) resG.graph->first(out, v);
670          while (resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); }
671        }
672        if (!resG.graph->valid(out)) {
673          out_or_in=0;
674          resG.graph->first(v);
675          if (resG.graph->valid(v)) resG.graph->first(in, v); else in=OldInEdgeIt(INVALID);
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);
679            if (resG.graph->valid(v)) resG.graph->first(in, v);
680            while (resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); }
681          }
682        }
683      }
684//       EdgeIt& operator++() {
685//      if (out_or_in) {
686//        ++out;
687//        while (out.valid() && !(Edge::free()>0) ) { ++out; }
688//        while (v.valid() && !out.valid()) {
689//          ++v;
690//          if (v.valid()) G->first(out, v);
691//          while (out.valid() && !(Edge::free()>0) ) { ++out; }
692//        }
693//        if (!out.valid()) {
694//          out_or_in=0;
695//          G->first(v);
696//          if (v.valid()) G->first(in, v); else in=OldInEdgeIt();
697//          while (in.valid() && !(Edge::free()>0) ) { ++in; }
698//          while (v.valid() && !in.valid()) {
699//            ++v;
700//            if (v.valid()) G->first(in, v);
701//            while (in.valid() && !(Edge::free()>0) ) { ++in; }
702//          } 
703//        }
704//      } else {
705//        ++in;
706//        while (in.valid() && !(Edge::free()>0) ) { ++in; }
707//        while (v.valid() && !in.valid()) {
708//          ++v;
709//          if (v.valid()) G->first(in, v);
710//          while (in.valid() && !(Edge::free()>0) ) { ++in; }
711//        }
712//      }
713//      return *this;
714//       }
715    };
716
717    NodeIt& first(NodeIt& v) const { return graph->first(v); }
718    OutEdgeIt& first(OutEdgeIt& e, Node v) const {
719      e=OutEdgeIt(*this, v);
720      return e;
721    }
722    EdgeIt& first(EdgeIt& e) const {
723      e=EdgeIt(*this);
724      return e;
725    }
726   
727    NodeIt& next(NodeIt& n) const { return graph->next(n); }
728
729    OutEdgeIt& next(OutEdgeIt& e) const {
730      if (e.out_or_in) {
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)) {
735          e.out_or_in=0;
736          graph->first(e.in, v);
737          while( graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
738        }
739      } else {
740        graph->next(e.in);
741        while( graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
742      }
743      return e;
744    }
745
746    EdgeIt& next(EdgeIt& e) const {
747      if (e.out_or_in) {
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);
752            if (graph->valid(e.v)) graph->first(e.out, e.v);
753            while (graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); }
754          }
755          if (!graph->valid(e.out)) {
756            e.out_or_in=0;
757            graph->first(e.v);
758            if (graph->valid(e.v)) graph->first(e.in, e.v); else e.in=OldInEdgeIt(INVALID);
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);
762              if (graph->valid(e.v)) graph->first(e.in, e.v);
763              while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
764            } 
765          }
766        } else {
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);
771            if (graph->valid(e.v)) graph->first(e.in, e.v);
772            while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
773          }
774        }
775        return e;
776      }
777   
778
779    template< typename It >
780    It first() const {
781      It e;
782      first(e);
783      return e;
784    }
785
786    template< typename It >
787    It first(Node v) const {
788      It e;
789      first(e, v);
790      return e;
791    }
792
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)); }
797
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)); }
802
803    int id(Node v) const { return graph->id(v); }
804
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); }
808
809    void augment(const Edge& e, Number a) const {
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
816    Number free(const Edge& e) const {
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
831    template<typename T> class NodeMap : public Graph::NodeMap<T> {
832    public:
833      NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G)
834        : Graph::NodeMap<T>(_G.getGraph()) { }
835      NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G,
836              T a) : Graph::NodeMap<T>(_G.getGraph(), a) { }
837    };
838
839//     template <typename T>
840//     class NodeMap {
841//       typename Graph::NodeMap<T> node_map;
842//     public:
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); }
847//     };
848
849    template <typename T>
850    class EdgeMap {
851      typename Graph::EdgeMap<T> forward_map, backward_map;
852    public:
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) { }
855      void set(Edge e, T a) {
856        if (e.out_or_in)
857          forward_map.set(e.out, a);
858        else
859          backward_map.set(e.in, a);
860      }
861      T get(Edge e) {
862        if (e.out_or_in)
863          return forward_map.get(e.out);
864        else
865          return backward_map.get(e.in);
866      }
867    };
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)*/ {
880      for(NodeIt n=this->template first<NodeIt>(); this->valid(n); this->next(n)) {
881        OutEdgeIt e;
882        ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
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
895    //typedef typename Graph::Node Node;
896    //typedef typename Graph::NodeIt NodeIt;
897
898    //typedef typename Graph::Edge Edge;
899    //typedef typename Graph::OutEdgeIt OutEdgeIt;
900    //typedef typename Graph::InEdgeIt InEdgeIt;
901    //typedef typename Graph::SymEdgeIt SymEdgeIt;
902    //typedef typename Graph::EdgeIt EdgeIt;
903
904    typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
905    typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
906
907    typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
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;
911    //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
912
913    NodeIt& first(NodeIt& n) const {
914      return ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
915    }
916
917    OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
918      e=first_out_edges.get(n);
919      return e;
920    }
921   
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); }
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 {
931      It e; first(e); return e; }
932
933    template< typename It > It first(const Node& v) const {
934      It e; first(e, v); return e; }
935
936    //Node head(const Edge& e) const { return graph->head(e); }
937    //Node tail(const Edge& e) const { return graph->tail(e); }
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 
945    //template<typename I> Node aNode(const I& e) const {
946    //  return graph->aNode(e); }
947    //template<typename I> Node bNode(const I& e) const {
948    //  return graph->bNode(e); }
949 
950    //Node addNode() const { return graph->addNode(); }
951    //Edge addEdge(const Node& tail, const Node& head) const {
952    //  return graph->addEdge(tail, head); }
953 
954    //void erase(const OutEdgeIt& e) {
955    //  first_out_edge(this->tail(e))=e;
956    //}
957    void erase(const Edge& e) {
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
995    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
996    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
997
998    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
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;
1002    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
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) :
1009      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), dist(*this, graph->nodeNum()) {
1010    }
1011
1012    OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
1013      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
1014      while (valid(e) && (dist.get(tail(e))/*+1!=*/>=dist.get(head(e))))
1015        ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1016      return e;
1017    }
1018
1019    NodeIt& next(NodeIt& e) const {
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);
1025      while (valid(e) && (dist.get(tail(e))/*+1!*/>=dist.get(head(e))))
1026        ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1027      return e;
1028    }
1029
1030    NodeIt& first(NodeIt& n) const {
1031      return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
1032    }
1033
1034    void erase(const Edge& e) {
1035      OutEdgeIt f(e);
1036      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
1037      while (valid(f) && (dist.get(tail(f))/*+1!=*/>=dist.get(head(f))))
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   
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); }
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 {
1057      It e; first(e); return e; }
1058
1059    template< typename It > It first(const Node& v) const {
1060      It e; first(e, v); return e; }
1061
1062    //Node head(const Edge& e) const { return graph->head(e); }
1063    //Node tail(const Edge& e) const { return graph->tail(e); }
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 
1074    //template<typename I> Node aNode(const I& e) const {
1075    //  return graph->aNode(e); }
1076    //template<typename I> Node bNode(const I& e) const {
1077    //  return graph->bNode(e); }
1078 
1079    //Node addNode() const { return graph->addNode(); }
1080    //Edge addEdge(const Node& tail, const Node& head) const {
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;
1105
1106  };
1107
1108
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;
1115 
1116//   public:
1117//     typedef Graph BaseGraph;
1118
1119//     typedef typename Graph::Node Node;
1120//     typedef typename Graph::Edge Edge;
1121 
1122//     typedef typename Graph::NodeIt NodeIt;
1123   
1124//     class OutEdgeIt {
1125//     public:
1126//       //Graph::Node n;
1127//       bool out_or_in;
1128//       typename Graph::OutEdgeIt o;
1129//       typename Graph::InEdgeIt i;   
1130//     };
1131//     class InEdgeIt {
1132//     public:
1133//       //Graph::Node n;
1134//       bool out_or_in;
1135//       typename Graph::OutEdgeIt o;
1136//       typename Graph::InEdgeIt i;   
1137//     };
1138//     typedef typename Graph::SymEdgeIt SymEdgeIt;
1139//     typedef typename Graph::EdgeIt EdgeIt;
1140
1141//     int nodeNum() const { return graph->nodeNum(); }
1142//     int edgeNum() const { return graph->edgeNum(); }
1143
1144//     Node& first(Node& n) const { return graph->first(n); }
1145
1146//     // Edge and SymEdge  is missing!!!!
1147//     // Edge <-> In/OutEdgeIt conversion is missing!!!!
1148
1149//     //FIXME
1150//     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const
1151//       {
1152//      e.n=n;
1153//      graph->first(e.o,n);
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)) {
1157//        graph->first(e.i,n);
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;
1170//   else graph->first(e.i,e.n);
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);}
1181
1182//     //FIXME
1183//     InEdgeIt& first(InEdgeIt& e, const Node& n) const
1184//       {
1185//      e.n=n;
1186//      graph->first(e.i,n);
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)) {
1190//        graph->first(e.o,n);
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;
1203//   else graph->first(e.o,e.n);
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);}
1214
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); }
1217
1218//     template< typename It > It first() const {
1219//       It e; first(e); return e; }
1220
1221//     template< typename It > It first(Node v) const {
1222//       It e; first(e, v); return e; }
1223
1224//     Node head(const Edge& e) const { return graph->head(e); }
1225//     Node tail(const Edge& e) const { return graph->tail(e); }
1226 
1227//     template<typename I> Node aNode(const I& e) const {
1228//       return graph->aNode(e); }
1229//     template<typename I> Node bNode(const I& e) const {
1230//       return graph->bNode(e); }
1231 
1232//     //template<typename I> bool valid(const I i);
1233//     //{ return graph->valid(i); }
1234 
1235//     //template<typename I> void setInvalid(const I &i);
1236//     //{ return graph->setInvalid(i); }
1237 
1238//     Node addNode() { return graph->addNode(); }
1239//     Edge addEdge(const Node& tail, const Node& head) {
1240//       return graph->addEdge(tail, head); }
1241 
1242//     template<typename I> void erase(const I& i) { graph->erase(i); }
1243 
1244//     void clear() { graph->clear(); }
1245 
1246//     template<typename S> class NodeMap : public Graph::NodeMap<S> { };
1247//     template<typename S> class EdgeMap : public Graph::EdgeMap<S> { };
1248 
1249//     void setGraph(Graph& _graph) { graph = &_graph; }
1250//     Graph& getGraph() { return (*graph); }
1251
1252//     //ResGraphWrapper() : graph(0) { }
1253//     ResGraphWrapper(Graph& _graph) : graph(&_graph) { }
1254//   };
1255
1256} //namespace hugo
1257
1258#endif //GRAPH_WRAPPER_H
1259
Note: See TracBrowser for help on using the repository browser.