src/work/marci/graph_wrapper.h
author alpar
Sun, 07 Mar 2004 19:33:34 +0000
changeset 157 ee17030e5f47
parent 155 8c6292ec54c6
child 158 4f54d89fa9d2
permissions -rw-r--r--
One more step toward the standars interface.
     1 // -*-mode: c++; -*-
     2 #ifndef GRAPH_WRAPPER_H
     3 #define GRAPH_WRAPPER_H
     4 
     5 namespace hugo {
     6 
     7   template<typename Graph>
     8   class TrivGraphWrapper {
     9     Graph* graph;
    10   
    11   public:
    12     typedef Graph BaseGraph;
    13 
    14     typedef typename Graph::NodeIt NodeIt;
    15     typedef typename Graph::EachNodeIt EachNodeIt;
    16 
    17     typedef typename Graph::EdgeIt EdgeIt;
    18     typedef typename Graph::OutEdgeIt OutEdgeIt;
    19     typedef typename Graph::InEdgeIt InEdgeIt;
    20     //typedef typename Graph::SymEdgeIt SymEdgeIt;
    21     typedef typename Graph::EachEdgeIt EachEdgeIt;
    22     
    23     template<typename I> I& getFirst(I& i) const { return graph->getFirst(i); }
    24     template<typename I, typename P> I& getFirst(I& i, const P& p) const { 
    25       return graph->getFirst(i, p); }
    26     
    27     template<typename I> I getNext(const I& i) const { 
    28       return graph->getNext(i); }
    29     template<typename I> I& next(I &i) const { return graph->next(i); }    
    30 
    31     template< typename It > It first() const { 
    32       It e; getFirst(e); return e; }
    33 
    34     template< typename It > It first(const NodeIt& v) const { 
    35       It e; getFirst(e, v); return e; }
    36 
    37     NodeIt head(const EdgeIt& e) const { return graph->head(e); }
    38     NodeIt tail(const EdgeIt& e) const { return graph->tail(e); }
    39 
    40     template<typename I> bool valid(const I& i) const 
    41       { return graph->valid(i); }
    42   
    43     //template<typename I> void setInvalid(const I &i);
    44     //{ return graph->setInvalid(i); }
    45 
    46     int nodeNum() const { return graph->nodeNum(); }
    47     int edgeNum() const { return graph->edgeNum(); }
    48   
    49     template<typename I> NodeIt aNode(const I& e) const { 
    50       return graph->aNode(e); }
    51     template<typename I> NodeIt bNode(const I& e) const { 
    52       return graph->bNode(e); }
    53   
    54     NodeIt addNode() const { return graph->addNode(); }
    55     EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) const { 
    56       return graph->addEdge(tail, head); }
    57   
    58     template<typename I> void erase(const I& i) const { graph->erase(i); }
    59   
    60     void clear() const { graph->clear(); }
    61     
    62     template<typename T> class NodeMap : public Graph::NodeMap<T> { 
    63     public:
    64       NodeMap(const TrivGraphWrapper<Graph>& _G) : 
    65 	Graph::NodeMap<T>(*(_G.G)) { }
    66       NodeMap(const TrivGraphWrapper<Graph>& _G, T a) : 
    67 	Graph::NodeMap<T>(*(_G.G), a) { }
    68     };
    69     template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 
    70     public:
    71       EdgeMap(const TrivGraphWrapper<Graph>& _G) : 
    72 	Graph::EdgeMap<T>(*(_G.G)) { }
    73       EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) : 
    74 	Graph::EdgeMap<T>(*(_G.G), a) { }
    75     };
    76     
    77     void setGraph(Graph& _graph) { graph = &_graph; }
    78     Graph& getGraph() const { return (*graph); }
    79   
    80     //TrivGraphWrapper() : graph(0) { }
    81     TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
    82   };
    83 
    84   template<typename Graph>
    85   class RevGraphWrapper
    86   {
    87     Graph* graph;
    88   
    89   public:
    90     typedef Graph BaseGraph;
    91 
    92     typedef typename Graph::NodeIt NodeIt;    
    93     typedef typename Graph::EachNodeIt EachNodeIt;
    94   
    95     typedef typename Graph::EdgeIt EdgeIt;
    96     typedef typename Graph::OutEdgeIt InEdgeIt;
    97     typedef typename Graph::InEdgeIt OutEdgeIt;
    98     //typedef typename Graph::SymEdgeIt SymEdgeIt;
    99     typedef typename Graph::EachEdgeIt EachEdgeIt;
   100     
   101     template<typename I> I& getFirst(I& i) const { return graph->getFirst(i); }
   102     template<typename I, typename P> I& getFirst(I& i, const P& p) const { 
   103       return graph->getFirst(i, p); }
   104 
   105     template<typename I> I getNext(const I& i) const { 
   106       return graph->getNext(i); }
   107     template<typename I> I& next(I &i) const { return graph->next(i); }    
   108 
   109     template< typename It > It first() const { 
   110       It e; getFirst(e); return e; }
   111 
   112     template< typename It > It first(const NodeIt& v) const { 
   113       It e; getFirst(e, v); return e; }
   114 
   115     NodeIt head(const EdgeIt& e) const { return graph->tail(e); }
   116     NodeIt tail(const EdgeIt& e) const { return graph->head(e); }
   117   
   118     template<typename I> bool valid(const I& i) const 
   119       { return graph->valid(i); }
   120   
   121     //template<typename I> void setInvalid(const I &i);
   122     //{ return graph->setInvalid(i); }
   123   
   124     template<typename I> NodeIt aNode(const I& e) const { 
   125       return graph->aNode(e); }
   126     template<typename I> NodeIt bNode(const I& e) const { 
   127       return graph->bNode(e); }
   128 
   129     NodeIt addNode() const { return graph->addNode(); }
   130     EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) const { 
   131       return graph->addEdge(tail, head); }
   132   
   133     int nodeNum() const { return graph->nodeNum(); }
   134     int edgeNum() const { return graph->edgeNum(); }
   135   
   136     template<typename I> void erase(const I& i) const { graph->erase(i); }
   137   
   138     void clear() const { graph->clear(); }
   139 
   140     template<typename T> class NodeMap : public Graph::NodeMap<T> { 
   141     public:
   142       NodeMap(const RevGraphWrapper<Graph>& _G) : 
   143 	Graph::NodeMap<T>(*(_G.G)) { }
   144       NodeMap(const RevGraphWrapper<Graph>& _G, T a) : 
   145 	Graph::NodeMap<T>(*(_G.G), a) { }
   146     };
   147     template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 
   148     public:
   149       EdgeMap(const RevGraphWrapper<Graph>& _G) : 
   150 	Graph::EdgeMap<T>(*(_G.G)) { }
   151       EdgeMap(const RevGraphWrapper<Graph>& _G, T a) : 
   152 	Graph::EdgeMap<T>(*(_G.G), a) { }
   153     };
   154 
   155     void setGraph(Graph& _graph) { graph = &_graph; }
   156     Graph& getGraph() const { return (*graph); }
   157 
   158     //RevGraphWrapper() : graph(0) { }
   159     RevGraphWrapper(Graph& _graph) : graph(&_graph) { }
   160   };
   161 
   162 
   163 //   template<typename Graph>
   164 //   class SymGraphWrapper
   165 //   {
   166 //     Graph* graph;
   167   
   168 //   public:
   169 //     typedef Graph BaseGraph;
   170 
   171 //     typedef typename Graph::NodeIt NodeIt;
   172 //     typedef typename Graph::EdgeIt EdgeIt;
   173   
   174 //     typedef typename Graph::EachNodeIt EachNodeIt;
   175     
   176 //     //FIXME tag-ekkel megcsinalni, hogy abbol csinaljon
   177 //     //iranyitatlant, ami van
   178 //     //mert csak 1 dolgot lehet be typedef-elni
   179 //     typedef typename Graph::OutEdgeIt SymEdgeIt;
   180 //     //typedef typename Graph::InEdgeIt SymEdgeIt;
   181 //     //typedef typename Graph::SymEdgeIt SymEdgeIt;
   182 //     typedef typename Graph::EachEdgeIt EachEdgeIt;
   183 
   184 //     int nodeNum() const { return graph->nodeNum(); }
   185 //     int edgeNum() const { return graph->edgeNum(); }
   186     
   187 //     template<typename I> I& getFirst(I& i) const { return graph->getFirst(i); }
   188 //     template<typename I, typename P> I& getFirst(I& i, const P& p) const { 
   189 //       return graph->getFirst(i, p); }
   190 //     //template<typename I> I next(const I i); { return graph->goNext(i); }
   191 //     //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
   192 
   193 //     template< typename It > It first() const { 
   194 //       It e; getFirst(e); return e; }
   195 
   196 //     template< typename It > It first(NodeIt v) const { 
   197 //       It e; getFirst(e, v); return e; }
   198 
   199 //     NodeIt head(const EdgeIt& e) const { return graph->head(e); }
   200 //     NodeIt tail(const EdgeIt& e) const { return graph->tail(e); }
   201   
   202 //     template<typename I> NodeIt aNode(const I& e) const { 
   203 //       return graph->aNode(e); }
   204 //     template<typename I> NodeIt bNode(const I& e) const { 
   205 //       return graph->bNode(e); }
   206   
   207 //     //template<typename I> bool valid(const I i);
   208 //     //{ return graph->valid(i); }
   209   
   210 //     //template<typename I> void setInvalid(const I &i);
   211 //     //{ return graph->setInvalid(i); }
   212   
   213 //     NodeIt addNode() { return graph->addNode(); }
   214 //     EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) { 
   215 //       return graph->addEdge(tail, head); }
   216   
   217 //     template<typename I> void erase(const I& i) { graph->erase(i); }
   218   
   219 //     void clear() { graph->clear(); }
   220   
   221 //     template<typename T> class NodeMap : public Graph::NodeMap<T> { };
   222 //     template<typename T> class EdgeMap : public Graph::EdgeMap<T> { };
   223   
   224 //     void setGraph(Graph& _graph) { graph = &_graph; }
   225 //     Graph& getGraph() { return (*graph); }
   226 
   227 //     //SymGraphWrapper() : graph(0) { }
   228 //     SymGraphWrapper(Graph& _graph) : graph(&_graph) { }
   229 //   };
   230 
   231 
   232   template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
   233   class ResGraphWrapper {
   234   public:
   235     typedef Graph BaseGraph;
   236     typedef typename Graph::NodeIt NodeIt;
   237     typedef typename Graph::EachNodeIt EachNodeIt;
   238   private:
   239     typedef typename Graph::OutEdgeIt OldOutEdgeIt;
   240     typedef typename Graph::InEdgeIt OldInEdgeIt;
   241     const Graph* G;
   242     FlowMap* flow;
   243     const CapacityMap* capacity;
   244   public:
   245     ResGraphWrapper(const Graph& _G, FlowMap& _flow, 
   246 	     const CapacityMap& _capacity) : 
   247       G(&_G), flow(&_flow), capacity(&_capacity) { }
   248 //     ResGraphWrapper(const ResGraphWrapper& res_graph_wrapper) : 
   249 //       G(res_graph_wrapper.G), flow(res_graph_wrapper.flow), capacity(res_graph_wrapper.capacity) { }
   250     class EdgeIt; 
   251     class OutEdgeIt; 
   252     friend class EdgeIt; 
   253     friend class OutEdgeIt; 
   254 
   255     class EdgeIt {
   256       friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
   257     protected:
   258       //const ResGraph3<Graph, Number, FlowMap, CapacityMap>* resG;
   259       const Graph* G;
   260       FlowMap* flow;
   261       const CapacityMap* capacity;
   262       //OldSymEdgeIt sym;
   263       OldOutEdgeIt out;
   264       OldInEdgeIt in;
   265       bool out_or_in; //true, iff out
   266     public:
   267       EdgeIt() : out_or_in(true) { } 
   268       EdgeIt(const Graph& _G, FlowMap& _flow, const CapacityMap& _capacity) : 
   269 	G(&_G), flow(&_flow), capacity(&_capacity), out_or_in(true) { }
   270       //EdgeIt(const EdgeIt& e) : G(e.G), flow(e.flow), capacity(e.capacity), out(e.out), in(e.in), out_or_in(e.out_or_in) { }
   271       Number free() const { 
   272 	if (out_or_in) { 
   273 	  return (/*resG->*/capacity->get(out)-/*resG->*/flow->get(out)); 
   274 	} else { 
   275 	  return (/*resG->*/flow->get(in)); 
   276 	}
   277       }
   278       bool valid() const { 
   279 	return out_or_in && out.valid() || in.valid(); }
   280       void augment(Number a) const {
   281 	if (out_or_in) { 
   282 	  /*resG->*/flow->set(out, /*resG->*/flow->get(out)+a);
   283 	} else { 
   284 	  /*resG->*/flow->set(in, /*resG->*/flow->get(in)-a);
   285 	}
   286       }
   287       void print() { 
   288 	if (out_or_in) {
   289 	  std::cout << "out "; 
   290 	  if (out.valid()) 
   291 	    std::cout << G->id(G->tail(out)) << "--"<< G->id(out) <<"->"<< G->id(G->head(out)); 
   292 	  else 
   293 	    std::cout << "invalid"; 
   294 	}
   295 	else {
   296 	  std::cout << "in "; 
   297 	  if (in.valid()) 
   298 	    std::cout << G->id(G->head(in)) << "<-"<< G->id(in) <<"--"<< G->id(G->tail(in)); 
   299 	  else 
   300 	    std::cout << "invalid"; 
   301 	}
   302 	std::cout << std::endl;
   303       }
   304     };
   305 
   306     Number free(OldOutEdgeIt out) const { 
   307       return (/*resG->*/capacity->get(out)-/*resG->*/flow->get(out)); 
   308     }
   309     Number free(OldInEdgeIt in) const { 
   310       return (/*resG->*/flow->get(in)); 
   311     }
   312 
   313     class OutEdgeIt : public EdgeIt {
   314       friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
   315     public:
   316       OutEdgeIt() { }
   317     private:
   318       OutEdgeIt(const Graph& _G, NodeIt v, FlowMap& _flow, const CapacityMap& _capacity) : EdgeIt(_G, _flow, _capacity) { 
   319 	//out=/*resG->*/G->template first<OldOutEdgeIt>(v);
   320 	G->getFirst(out, v);
   321 	while( out.valid() && !(EdgeIt::free()>0) ) { ++out; }
   322 	if (!out.valid()) {
   323 	  out_or_in=0;
   324 	  //in=/*resG->*/G->template first<OldInEdgeIt>(v);
   325 	  G->getFirst(in, v);
   326 	  while( in.valid() && !(EdgeIt::free()>0) ) { ++in; }
   327 	}
   328       }
   329     public:
   330       OutEdgeIt& operator++() { 
   331 	if (out_or_in) {
   332 	  NodeIt v=/*resG->*/G->aNode(out);
   333 	  ++out;
   334 	  while( out.valid() && !(EdgeIt::free()>0) ) { ++out; }
   335 	  if (!out.valid()) {
   336 	    out_or_in=0;
   337 	    G->getFirst(in, v); //=/*resG->*/G->template first<OldInEdgeIt>(v);
   338 	    while( in.valid() && !(EdgeIt::free()>0) ) { ++in; }
   339 	  }
   340 	} else {
   341 	  ++in;
   342 	  while( in.valid() && !(EdgeIt::free()>0) ) { ++in; } 
   343 	}
   344 	return *this; 
   345       }
   346     };
   347 
   348     class EachEdgeIt : public EdgeIt {
   349       friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
   350       typename Graph::EachNodeIt v;
   351     public:
   352       EachEdgeIt() { }
   353       //EachEdgeIt(const EachEdgeIt& e) : EdgeIt(e), v(e.v) { }
   354       EachEdgeIt(const Graph& _G, FlowMap& _flow, const CapacityMap& _capacity) : EdgeIt(_G, _flow, _capacity) { 
   355 	out_or_in=true;
   356 	G->getFirst(v);
   357 	if (v.valid()) G->getFirst(out, v); else out=OldOutEdgeIt();
   358 	while (out.valid() && !(EdgeIt::free()>0) ) { ++out; }
   359 	while (v.valid() && !out.valid()) { 
   360 	  ++v; 
   361 	  if (v.valid()) G->getFirst(out, v); 
   362 	  while (out.valid() && !(EdgeIt::free()>0) ) { ++out; }
   363 	}
   364 	if (!out.valid()) {
   365 	  out_or_in=0;
   366 	  G->getFirst(v);
   367 	  if (v.valid()) G->getFirst(in, v); else in=OldInEdgeIt();
   368 	  while (in.valid() && !(EdgeIt::free()>0) ) { ++in; }
   369 	  while (v.valid() && !in.valid()) { 
   370 	    ++v; 
   371 	    if (v.valid()) G->getFirst(in, v); 
   372 	    while (in.valid() && !(EdgeIt::free()>0) ) { ++in; }
   373 	  }
   374 	}
   375       }
   376       EachEdgeIt& operator++() { 
   377 	if (out_or_in) {
   378 	  ++out;
   379 	  while (out.valid() && !(EdgeIt::free()>0) ) { ++out; }
   380 	  while (v.valid() && !out.valid()) { 
   381 	    ++v; 
   382 	    if (v.valid()) G->getFirst(out, v); 
   383 	    while (out.valid() && !(EdgeIt::free()>0) ) { ++out; }
   384 	  }
   385 	  if (!out.valid()) {
   386 	    out_or_in=0;
   387 	    G->getFirst(v);
   388 	    if (v.valid()) G->getFirst(in, v); else in=OldInEdgeIt();
   389 	    while (in.valid() && !(EdgeIt::free()>0) ) { ++in; }
   390 	    while (v.valid() && !in.valid()) { 
   391 	      ++v; 
   392 	      if (v.valid()) G->getFirst(in, v); 
   393 	      while (in.valid() && !(EdgeIt::free()>0) ) { ++in; }
   394 	    }  
   395 	  }
   396 	} else {
   397 	  ++in;
   398 	  while (in.valid() && !(EdgeIt::free()>0) ) { ++in; }
   399 	  while (v.valid() && !in.valid()) { 
   400 	    ++v; 
   401 	    if (v.valid()) G->getFirst(in, v); 
   402 	    while (in.valid() && !(EdgeIt::free()>0) ) { ++in; }
   403 	  }
   404 	}
   405 	return *this;
   406       }
   407     };
   408 
   409     void getFirst(EachNodeIt& v) const { G->getFirst(v); }
   410     void getFirst(OutEdgeIt& e, NodeIt v) const { 
   411       e=OutEdgeIt(*G, v, *flow, *capacity); 
   412     }
   413     void getFirst(EachEdgeIt& e) const { 
   414       e=EachEdgeIt(*G, *flow, *capacity); 
   415     }
   416    
   417     EachNodeIt& next(EachNodeIt& n) const { return G->next(n); }
   418 
   419     OutEdgeIt& next(OutEdgeIt& e) const { 
   420       if (e.out_or_in) {
   421 	NodeIt v=G->aNode(e.out);
   422 	++(e.out);
   423 	while( G->valid(e.out) && !(e.free()>0) ) { ++(e.out); }
   424 	if (!G->valid(e.out)) {
   425 	  e.out_or_in=0;
   426 	  G->getFirst(e.in, v); //=/*resG->*/G->template first<OldInEdgeIt>(v);
   427 	  while( G->valid(e.in) && !(e.free()>0) ) { ++(e.in); }
   428 	}
   429       } else {
   430 	++(e.in);
   431 	while( G->valid(e.in) && !(e.free()>0) ) { ++(e.in); } 
   432       }
   433       return e;
   434     }
   435 
   436     EachEdgeIt& next(EachEdgeIt& e) const { 
   437       if (e.out_or_in) {
   438 	++(e.out);
   439 	while (G->valid(e.out) && !(e.free()>0) ) { ++(e.out); }
   440 	  while (G->valid(e.v) && !G->valid(e.out)) { 
   441 	    ++(e.v); 
   442 	    if (G->valid(e.v)) G->getFirst(e.out, e.v); 
   443 	    while (G->valid(e.out) && !(e.free()>0) ) { ++(e.out); }
   444 	  }
   445 	  if (!G->valid(e.out)) {
   446 	    e.out_or_in=0;
   447 	    G->getFirst(e.v);
   448 	    if (G->valid(e.v)) G->getFirst(e.in, e.v); else e.in=OldInEdgeIt();
   449 	    while (G->valid(e.in) && !(e.free()>0) ) { ++(e.in); }
   450 	    while (G->valid(e.v) && !G->valid(e.in)) { 
   451 	      ++(e.v); 
   452 	      if (G->valid(e.v)) G->getFirst(e.in, e.v); 
   453 	      while (G->valid(e.in) && !(e.free()>0) ) { ++(e.in); }
   454 	    }  
   455 	  }
   456 	} else {
   457 	  ++(e.in);
   458 	  while (G->valid(e.in) && !(e.free()>0) ) { ++(e.in); }
   459 	  while (G->valid(e.v) && !G->valid(e.in)) { 
   460 	    ++(e.v); 
   461 	    if (G->valid(e.v)) G->getFirst(e.in, e.v); 
   462 	    while (G->valid(e.in) && !(e.free()>0) ) { ++(e.in); }
   463 	  }
   464 	}
   465 	return e;
   466       }
   467     
   468 
   469     template< typename It >
   470     It first() const { 
   471       It e;
   472       getFirst(e);
   473       return e; 
   474     }
   475 
   476     template< typename It >
   477     It first(NodeIt v) const { 
   478       It e;
   479       getFirst(e, v);
   480       return e; 
   481     }
   482 
   483     NodeIt tail(EdgeIt e) const { 
   484       return ((e.out_or_in) ? G->aNode(e.out) : G->aNode(e.in)); }
   485     NodeIt head(EdgeIt e) const { 
   486       return ((e.out_or_in) ? G->bNode(e.out) : G->bNode(e.in)); }
   487 
   488     NodeIt aNode(OutEdgeIt e) const { 
   489       return ((e.out_or_in) ? G->aNode(e.out) : G->aNode(e.in)); }
   490     NodeIt bNode(OutEdgeIt e) const { 
   491       return ((e.out_or_in) ? G->bNode(e.out) : G->bNode(e.in)); }
   492 
   493     int id(NodeIt v) const { return G->id(v); }
   494 
   495     bool valid(NodeIt n) const { return G->valid(n); }
   496     bool valid(EdgeIt e) const { 
   497       return e.out_or_in ? G->valid(e.out) : G->valid(e.in); }
   498 
   499     template<typename T> class NodeMap : public Graph::NodeMap<T> { 
   500     public:
   501       NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) 
   502 	: Graph::NodeMap<T>(*(_G.G)) { }
   503       NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, 
   504 	      T a) : Graph::NodeMap<T>(*(_G.G), a) { }
   505     };
   506 
   507 //     template <typename T>
   508 //     class NodeMap {
   509 //       typename Graph::NodeMap<T> node_map; 
   510 //     public:
   511 //       NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(*(_G.G)) { }
   512 //       NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : node_map(*(_G.G), a) { }
   513 //       void set(NodeIt nit, T a) { node_map.set(nit, a); }
   514 //       T get(NodeIt nit) const { return node_map.get(nit); }
   515 //     };
   516 
   517     template <typename T>
   518     class EdgeMap {
   519       typename Graph::EdgeMap<T> forward_map, backward_map; 
   520     public:
   521       EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : forward_map(*(_G.G)), backward_map(*(_G.G)) { }
   522       EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(*(_G.G), a), backward_map(*(_G.G), a) { }
   523       void set(EdgeIt e, T a) { 
   524 	if (e.out_or_in) 
   525 	  forward_map.set(e.out, a); 
   526 	else 
   527 	  backward_map.set(e.in, a); 
   528       }
   529       T get(EdgeIt e) { 
   530 	if (e.out_or_in) 
   531 	  return forward_map.get(e.out); 
   532 	else 
   533 	  return backward_map.get(e.in); 
   534       }
   535     };
   536 
   537   };
   538 
   539 
   540 
   541 // // FIXME: comparison should be made better!!!
   542 //   template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap>
   543 //   class ResGraphWrapper
   544 //   {
   545 //     Graph* graph;
   546   
   547 //   public:
   548 //     typedef Graph BaseGraph;
   549 
   550 //     typedef typename Graph::NodeIt NodeIt;
   551 //     typedef typename Graph::EdgeIt EdgeIt;
   552   
   553 //     typedef typename Graph::EachNodeIt EachNodeIt;
   554    
   555 //     class OutEdgeIt {
   556 //     public:
   557 //       //Graph::NodeIt n;
   558 //       bool out_or_in;
   559 //       typename Graph::OutEdgeIt o;
   560 //       typename Graph::InEdgeIt i;   
   561 //     };
   562 //     class InEdgeIt {
   563 //     public:
   564 //       //Graph::NodeIt n;
   565 //       bool out_or_in;
   566 //       typename Graph::OutEdgeIt o;
   567 //       typename Graph::InEdgeIt i;   
   568 //     };
   569 //     typedef typename Graph::SymEdgeIt SymEdgeIt;
   570 //     typedef typename Graph::EachEdgeIt EachEdgeIt;
   571 
   572 //     int nodeNum() const { return graph->nodeNum(); }
   573 //     int edgeNum() const { return graph->edgeNum(); }
   574 
   575 //     NodeIt& getFirst(NodeIt& n) const { return graph->getFirst(n); }
   576 
   577 //     // EachEdge and SymEdge  is missing!!!!
   578 //     // EdgeIt <-> In/OutEdgeIt conversion is missing!!!!
   579 
   580 //     //FIXME
   581 //     OutEdgeIt& getFirst(OutEdgeIt& e, const NodeIt& n) const 
   582 //       {
   583 // 	e.n=n;
   584 // 	graph->getFirst(e.o,n);
   585 // 	while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
   586 // 	  graph->goNext(e.o);
   587 // 	if(!graph->valid(e.o)) {
   588 // 	  graph->getFirst(e.i,n);
   589 // 	  while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
   590 // 	    graph->goNext(e.i);
   591 // 	}
   592 // 	return e;
   593 //       }
   594 // /*
   595 //   OutEdgeIt &goNext(OutEdgeIt &e)
   596 //   {
   597 //   if(graph->valid(e.o)) {
   598 //   while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
   599 //   graph->goNext(e.o);
   600 //   if(graph->valid(e.o)) return e;
   601 //   else graph->getFirst(e.i,e.n);
   602 //   }
   603 //   else {
   604 //   while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
   605 //   graph->goNext(e.i);
   606 //   return e;
   607 //   }
   608 //   }
   609 //   OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
   610 // */
   611 //     //bool valid(const OutEdgeIt e) { return graph->valid(e.o)||graph->valid(e.i);}
   612 
   613 //     //FIXME
   614 //     InEdgeIt& getFirst(InEdgeIt& e, const NodeIt& n) const 
   615 //       {
   616 // 	e.n=n;
   617 // 	graph->getFirst(e.i,n);
   618 // 	while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
   619 // 	  graph->goNext(e.i);
   620 // 	if(!graph->valid(e.i)) {
   621 // 	  graph->getFirst(e.o,n);
   622 // 	  while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
   623 // 	    graph->goNext(e.o);
   624 // 	}
   625 // 	return e;
   626 //       }
   627 // /*
   628 //   InEdgeIt &goNext(InEdgeIt &e)
   629 //   {
   630 //   if(graph->valid(e.i)) {
   631 //   while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
   632 //   graph->goNext(e.i);
   633 //   if(graph->valid(e.i)) return e;
   634 //   else graph->getFirst(e.o,e.n);
   635 //   }
   636 //   else {
   637 //   while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
   638 //   graph->goNext(e.o);
   639 //   return e;
   640 //   }
   641 //   }
   642 //   InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
   643 // */
   644 //     //bool valid(const InEdgeIt e) { return graph->valid(e.i)||graph->valid(e.o);}
   645 
   646 //     //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
   647 //     //template<typename I> I next(const I i); { return graph->goNext(i); }
   648 
   649 //     template< typename It > It first() const { 
   650 //       It e; getFirst(e); return e; }
   651 
   652 //     template< typename It > It first(NodeIt v) const { 
   653 //       It e; getFirst(e, v); return e; }
   654 
   655 //     NodeIt head(const EdgeIt& e) const { return graph->head(e); }
   656 //     NodeIt tail(const EdgeIt& e) const { return graph->tail(e); }
   657   
   658 //     template<typename I> NodeIt aNode(const I& e) const { 
   659 //       return graph->aNode(e); }
   660 //     template<typename I> NodeIt bNode(const I& e) const { 
   661 //       return graph->bNode(e); }
   662   
   663 //     //template<typename I> bool valid(const I i);
   664 //     //{ return graph->valid(i); }
   665   
   666 //     //template<typename I> void setInvalid(const I &i);
   667 //     //{ return graph->setInvalid(i); }
   668   
   669 //     NodeIt addNode() { return graph->addNode(); }
   670 //     EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) { 
   671 //       return graph->addEdge(tail, head); }
   672   
   673 //     template<typename I> void erase(const I& i) { graph->erase(i); }
   674   
   675 //     void clear() { graph->clear(); }
   676   
   677 //     template<typename S> class NodeMap : public Graph::NodeMap<S> { };
   678 //     template<typename S> class EdgeMap : public Graph::EdgeMap<S> { };
   679   
   680 //     void setGraph(Graph& _graph) { graph = &_graph; }
   681 //     Graph& getGraph() { return (*graph); }
   682 
   683 //     //ResGraphWrapper() : graph(0) { }
   684 //     ResGraphWrapper(Graph& _graph) : graph(&_graph) { }
   685 //   };
   686 
   687 } //namespace hugo
   688 
   689 #endif //GRAPH_WRAPPER_H
   690