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