src/hugo/graph_wrapper.h
changeset 652 4dfa1f79bf3e
parent 626 0015642b0990
child 653 c3ad7c661a49
equal deleted inserted replaced
16:80d2f67e4b41 17:bf5717581e8a
     9 ///This file contains several useful graph wrapper functions.
     9 ///This file contains several useful graph wrapper functions.
    10 ///
    10 ///
    11 ///\author Marton Makai
    11 ///\author Marton Makai
    12 
    12 
    13 #include <hugo/invalid.h>
    13 #include <hugo/invalid.h>
       
    14 #include <hugo/maps.h>
    14 //#include <iter_map.h>
    15 //#include <iter_map.h>
    15 
    16 
    16 namespace hugo {
    17 namespace hugo {
    17 
    18 
    18   // Graph wrappers
    19   // Graph wrappers
   101     class Node : public Graph::Node {
   102     class Node : public Graph::Node {
   102       friend class GraphWrapper<Graph>;
   103       friend class GraphWrapper<Graph>;
   103     public:
   104     public:
   104       Node() { }
   105       Node() { }
   105       Node(const typename Graph::Node& _n) : Graph::Node(_n) { }
   106       Node(const typename Graph::Node& _n) : Graph::Node(_n) { }
       
   107       // /// \bug construction throughrthr multiple levels should be 
       
   108       // /// handled better
       
   109       // Node(const typename ParentGraph::ParentGraph::Node& _n) : 
       
   110       // Graph::Node(_n) { }
   106       Node(const Invalid& i) : Graph::Node(i) { }
   111       Node(const Invalid& i) : Graph::Node(i) { }
   107     };
   112     };
   108     class NodeIt { 
   113     class NodeIt { 
   109       friend class GraphWrapper<Graph>;
   114       friend class GraphWrapper<Graph>;
   110       typename Graph::NodeIt n;
   115       typename Graph::NodeIt n;
   200     void erase(const Node& i) const { graph->erase(i); }
   205     void erase(const Node& i) const { graph->erase(i); }
   201     void erase(const Edge& i) const { graph->erase(i); }
   206     void erase(const Edge& i) const { graph->erase(i); }
   202   
   207   
   203     void clear() const { graph->clear(); }
   208     void clear() const { graph->clear(); }
   204     
   209     
       
   210     bool forward(const Edge& e) const { graph->forward(e); }
       
   211     bool backward(const Edge& e) const { graph->backward(e); }
       
   212     
       
   213     Edge opposite(const Edge& e) const { Edge(graph->opposite(e)); }
       
   214 
   205     template<typename T> class NodeMap : public Graph::template NodeMap<T> { 
   215     template<typename T> class NodeMap : public Graph::template NodeMap<T> { 
   206       typedef typename Graph::template NodeMap<T> Parent;
   216       typedef typename Graph::template NodeMap<T> Parent;
   207     public:
   217     public:
   208       NodeMap(const GraphWrapper<Graph>& _G) :  Parent(*(_G.graph)) { }
   218       NodeMap(const GraphWrapper<Graph>& _G) :  Parent(*(_G.graph)) { }
   209       NodeMap(const GraphWrapper<Graph>& _G, T a) : Parent(*(_G.graph), a) { }
   219       NodeMap(const GraphWrapper<Graph>& _G, T a) : Parent(*(_G.graph), a) { }
   225   /// Thus \c Graph have to be a directed graph type.
   235   /// Thus \c Graph have to be a directed graph type.
   226   ///
   236   ///
   227   ///\author Marton Makai
   237   ///\author Marton Makai
   228   template<typename Graph>
   238   template<typename Graph>
   229   class RevGraphWrapper : public GraphWrapper<Graph> {
   239   class RevGraphWrapper : public GraphWrapper<Graph> {
       
   240   public:
       
   241     typedef GraphWrapper<Graph> Parent; 
   230   protected:
   242   protected:
   231     RevGraphWrapper() : GraphWrapper<Graph>() { }
   243     RevGraphWrapper() : GraphWrapper<Graph>() { }
   232   public:
   244   public:
   233     RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }  
   245     RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }  
   234 
   246 
   305   ///
   317   ///
   306   ///\author Marton Makai
   318   ///\author Marton Makai
   307   template<typename Graph, typename NodeFilterMap, 
   319   template<typename Graph, typename NodeFilterMap, 
   308 	   typename EdgeFilterMap>
   320 	   typename EdgeFilterMap>
   309   class SubGraphWrapper : public GraphWrapper<Graph> {
   321   class SubGraphWrapper : public GraphWrapper<Graph> {
       
   322   public:
       
   323     typedef GraphWrapper<Graph> Parent;
   310   protected:
   324   protected:
   311     NodeFilterMap* node_filter_map;
   325     NodeFilterMap* node_filter_map;
   312     EdgeFilterMap* edge_filter_map;
   326     EdgeFilterMap* edge_filter_map;
   313 
   327 
   314     SubGraphWrapper() : GraphWrapper<Graph>(), 
   328     SubGraphWrapper() : GraphWrapper<Graph>(), 
   319     void setEdgeFilterMap(EdgeFilterMap& _edge_filter_map) {
   333     void setEdgeFilterMap(EdgeFilterMap& _edge_filter_map) {
   320       edge_filter_map=&_edge_filter_map;
   334       edge_filter_map=&_edge_filter_map;
   321     }
   335     }
   322     
   336     
   323   public:
   337   public:
   324 
       
   325     SubGraphWrapper(Graph& _graph, NodeFilterMap& _node_filter_map, 
   338     SubGraphWrapper(Graph& _graph, NodeFilterMap& _node_filter_map, 
   326 		    EdgeFilterMap& _edge_filter_map) : 
   339 		    EdgeFilterMap& _edge_filter_map) : 
   327       GraphWrapper<Graph>(_graph), node_filter_map(&_node_filter_map), 
   340       GraphWrapper<Graph>(_graph), node_filter_map(&_node_filter_map), 
   328       edge_filter_map(&_edge_filter_map) { }  
   341       edge_filter_map(&_edge_filter_map) { }  
   329 
   342 
   494   /// the orientation of a directed one.
   507   /// the orientation of a directed one.
   495   ///
   508   ///
   496   /// \author Marton Makai
   509   /// \author Marton Makai
   497   template<typename Graph>
   510   template<typename Graph>
   498   class UndirGraphWrapper : public GraphWrapper<Graph> {
   511   class UndirGraphWrapper : public GraphWrapper<Graph> {
       
   512   public:
       
   513     typedef GraphWrapper<Graph> Parent; 
   499   protected:
   514   protected:
   500     UndirGraphWrapper() : GraphWrapper<Graph>() { }
   515     UndirGraphWrapper() : GraphWrapper<Graph>() { }
   501     
   516     
   502   public:
   517   public:
   503     typedef typename GraphWrapper<Graph>::Node Node;
   518     typedef typename GraphWrapper<Graph>::Node Node;
   589       Parent::setGraph(gr); 
   604       Parent::setGraph(gr); 
   590     }
   605     }
   591   };
   606   };
   592 
   607 
   593 
   608 
   594   ///\brief A wrapper for composing bidirected graph from a directed one. 
   609 
       
   610   ///\brief A wrapper for composing a subgraph of a 
       
   611   /// bidirected graph composed from a directed one. 
   595   /// experimental, for fezso's sake.
   612   /// experimental, for fezso's sake.
   596   ///
   613   ///
   597   /// A wrapper for composing bidirected graph from a directed one. 
   614   /// A wrapper for composing a subgraps of a 
       
   615   /// bidirected graph composed from a directed one. 
   598   /// experimental, for fezso's sake.
   616   /// experimental, for fezso's sake.
   599   /// A bidirected graph is composed over the directed one without physical 
   617   /// A bidirected graph is composed over the directed one without physical 
   600   /// storage. As the oppositely directed edges are logically different ones 
   618   /// storage. As the oppositely directed edges are logically different ones 
   601   /// the maps are able to attach different values for them.
   619   /// the maps are able to attach different values for them.
   602   template<typename Graph>
   620   template<typename Graph, 
   603   class BidirGraphWrapper : public GraphWrapper<Graph> {
   621 	   typename ForwardFilterMap, typename BackwardFilterMap>
       
   622   class SubBidirGraphWrapper : public GraphWrapper<Graph> {
       
   623   public:
       
   624     typedef GraphWrapper<Graph> Parent; 
   604   protected:
   625   protected:
   605     //const CapacityMap* capacity;
   626     //const CapacityMap* capacity;
   606     //FlowMap* flow;
   627     //FlowMap* flow;
   607 
   628 
   608     BidirGraphWrapper() : GraphWrapper<Graph>()/*, 
   629     ForwardFilterMap* forward_filter;
       
   630     BackwardFilterMap* backward_filter;
       
   631 
       
   632     SubBidirGraphWrapper() : GraphWrapper<Graph>()/*, 
   609 						 capacity(0), flow(0)*/ { }
   633 						 capacity(0), flow(0)*/ { }
   610 //     void setCapacityMap(const CapacityMap& _capacity) {
   634     void setForwardFilterMap(ForwardFilterMap& _forward_filter) {
   611 //       capacity=&_capacity;
   635       forward_filter=&_forward_filter;
   612 //     }
   636     }
   613 //     void setFlowMap(FlowMap& _flow) {
   637     void setBackwardFilterMap(BackwardFilterMap& _backward_filter) {
   614 //       flow=&_flow;
   638       backward_filter=&_backward_filter;
   615 //     }
   639     }
   616 
   640 
   617   public:
   641   public:
   618 
   642 
   619     BidirGraphWrapper(Graph& _graph/*, const CapacityMap& _capacity, 
   643     SubBidirGraphWrapper(Graph& _graph, ForwardFilterMap& _forward_filter, 
   620 				     FlowMap& _flow*/) : 
   644 			 BackwardFilterMap& _backward_filter) : 
   621       GraphWrapper<Graph>(_graph)/*, capacity(&_capacity), flow(&_flow)*/ { }
   645       GraphWrapper<Graph>(_graph), 
       
   646       forward_filter(&_forward_filter), backward_filter(&_backward_filter) { }
   622 
   647 
   623     class Edge; 
   648     class Edge; 
   624     class OutEdgeIt; 
   649     class OutEdgeIt; 
   625     friend class Edge; 
   650     friend class Edge; 
   626     friend class OutEdgeIt; 
   651     friend class OutEdgeIt; 
   630 
   655 
   631     typedef typename GraphWrapper<Graph>::Node Node;
   656     typedef typename GraphWrapper<Graph>::Node Node;
   632     typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
   657     typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
   633 
   658 
   634     class Edge : public Graph::Edge {
   659     class Edge : public Graph::Edge {
   635       friend class BidirGraphWrapper<Graph>;
   660       friend class SubBidirGraphWrapper<Graph, 
       
   661 					ForwardFilterMap, BackwardFilterMap>;
   636       ///\bug ez nem is kell
   662       ///\bug ez nem is kell
   637       //template<typename T> friend class NodeMap;
   663       //template<typename T> friend class NodeMap;
   638       template<typename T> friend class EdgeMap;
   664       template<typename T> friend class EdgeMap;
   639     protected:
   665     protected:
   640       bool backward; //true, iff backward
   666       bool backward; //true, iff backward
   657 		static_cast<typename Graph::Edge>(v));
   683 		static_cast<typename Graph::Edge>(v));
   658       } 
   684       } 
   659     };
   685     };
   660 
   686 
   661     class OutEdgeIt {
   687     class OutEdgeIt {
   662       friend class BidirGraphWrapper<Graph>;
   688       friend class SubBidirGraphWrapper<Graph, 
       
   689 					ForwardFilterMap, BackwardFilterMap>;
   663     protected:
   690     protected:
   664       typename Graph::OutEdgeIt out;
   691       typename Graph::OutEdgeIt out;
   665       typename Graph::InEdgeIt in;
   692       typename Graph::InEdgeIt in;
   666       bool backward;
   693       bool backward;
   667     public:
   694     public:
   668       OutEdgeIt() { }
   695       OutEdgeIt() { }
   669       //FIXME
   696       //FIXME
   670 //      OutEdgeIt(const Edge& e) : Edge(e) { }
   697 //      OutEdgeIt(const Edge& e) : Edge(e) { }
   671       OutEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { }
   698       OutEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { }
   672 //the unique invalid iterator
   699 //the unique invalid iterator
   673       OutEdgeIt(const BidirGraphWrapper<Graph>& _G, Node v) { 
   700       OutEdgeIt(const SubBidirGraphWrapper<Graph, 
       
   701 		ForwardFilterMap, BackwardFilterMap>& _G, Node v) { 
   674 	backward=false;
   702 	backward=false;
   675 	_G.graph->first(out, v);
   703 	_G.graph->first(out, v);
   676 	while(_G.graph->valid(out) && !_G.enabled(*this)) { _G.graph->next(out); }
   704 	while(_G.graph->valid(out) && !(*_G.forward_filter)[*this]) { _G.graph->next(out); }
   677 	if (!_G.graph->valid(out)) {
   705 	if (!_G.graph->valid(out)) {
   678 	  backward=true;
   706 	  backward=true;
   679 	  _G.graph->first(in, v);
   707 	  _G.graph->first(in, v);
   680 	  while(_G.graph->valid(in) && !_G.enabled(*this)) { _G.graph->next(in); }
   708 	  while(_G.graph->valid(in) && !(*_G.backward_filter)[*this]) { _G.graph->next(in); }
   681 	}
   709 	}
   682       }
   710       }
   683       operator Edge() const { 
   711       operator Edge() const { 
   684 //	Edge e;
   712 //	Edge e;
   685 //	e.forward=this->forward;
   713 //	e.forward=this->forward;
   691 	  return Edge(out, this->backward);
   719 	  return Edge(out, this->backward);
   692       }
   720       }
   693     };
   721     };
   694 
   722 
   695     class InEdgeIt {
   723     class InEdgeIt {
   696       friend class BidirGraphWrapper<Graph>;
   724       friend class SubBidirGraphWrapper<Graph, 
       
   725 					ForwardFilterMap, BackwardFilterMap>;
   697     protected:
   726     protected:
   698       typename Graph::OutEdgeIt out;
   727       typename Graph::OutEdgeIt out;
   699       typename Graph::InEdgeIt in;
   728       typename Graph::InEdgeIt in;
   700       bool backward;
   729       bool backward;
   701     public:
   730     public:
   702       InEdgeIt() { }
   731       InEdgeIt() { }
   703       //FIXME
   732       //FIXME
   704 //      OutEdgeIt(const Edge& e) : Edge(e) { }
   733 //      OutEdgeIt(const Edge& e) : Edge(e) { }
   705       InEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { }
   734       InEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { }
   706 //the unique invalid iterator
   735 //the unique invalid iterator
   707       InEdgeIt(const BidirGraphWrapper<Graph>& _G, Node v) { 
   736       InEdgeIt(const SubBidirGraphWrapper<Graph, 
       
   737 	       ForwardFilterMap, BackwardFilterMap>& _G, Node v) { 
   708 	backward=false;
   738 	backward=false;
   709 	_G.graph->first(in, v);
   739 	_G.graph->first(in, v);
   710 	while(_G.graph->valid(in) && !_G.enabled(*this)) { _G.graph->next(in); }
   740 	while(_G.graph->valid(in) && !(*_G.forward_filter)[*this]) { _G.graph->next(in); }
   711 	if (!_G.graph->valid(in)) {
   741 	if (!_G.graph->valid(in)) {
   712 	  backward=true;
   742 	  backward=true;
   713 	  _G.graph->first(out, v);
   743 	  _G.graph->first(out, v);
   714 	  while(_G.graph->valid(out) && !_G.enabled(*this)) { _G.graph->next(out); }
   744 	  while(_G.graph->valid(out) && !(*_G.backward_filter)[*this]) { _G.graph->next(out); }
   715 	}
   745 	}
   716       }
   746       }
   717       operator Edge() const { 
   747       operator Edge() const { 
   718 //	Edge e;
   748 //	Edge e;
   719 //	e.forward=this->forward;
   749 //	e.forward=this->forward;
   725 	  return Edge(in, this->backward);
   755 	  return Edge(in, this->backward);
   726       }
   756       }
   727     };
   757     };
   728 
   758 
   729     class EdgeIt {
   759     class EdgeIt {
   730       friend class BidirGraphWrapper<Graph>;
   760       friend class SubBidirGraphWrapper<Graph, 
       
   761 					ForwardFilterMap, BackwardFilterMap>;
   731     protected:
   762     protected:
   732       typename Graph::EdgeIt e;
   763       typename Graph::EdgeIt e;
   733       bool backward;
   764       bool backward;
   734     public:
   765     public:
   735       EdgeIt() { }
   766       EdgeIt() { }
   736       EdgeIt(const Invalid& i) : e(i), backward(true) { }
   767       EdgeIt(const Invalid& i) : e(i), backward(true) { }
   737       EdgeIt(const BidirGraphWrapper<Graph>& _G) { 
   768       EdgeIt(const SubBidirGraphWrapper<Graph, 
       
   769 	     ForwardFilterMap, BackwardFilterMap>& _G) { 
   738 	backward=false;
   770 	backward=false;
   739 	_G.graph->first(e);
   771 	_G.graph->first(e);
   740 	while (_G.graph->valid(e) && !_G.enabled(*this)) _G.graph->next(e);
   772 	while (_G.graph->valid(e) && !(*_G.forward_filter)[*this]) _G.graph->next(e);
   741 	if (!_G.graph->valid(e)) {
   773 	if (!_G.graph->valid(e)) {
   742 	  backward=true;
   774 	  backward=true;
   743 	  _G.graph->first(e);
   775 	  _G.graph->first(e);
   744 	  while (_G.graph->valid(e) && !_G.enabled(*this)) _G.graph->next(e);
   776 	  while (_G.graph->valid(e) && !(*_G.backward_filter)[*this]) _G.graph->next(e);
   745 	}
   777 	}
   746       }
   778       }
   747       operator Edge() const { 
   779       operator Edge() const { 
   748 	return Edge(e, this->backward);
   780 	return Edge(e, this->backward);
   749       }
   781       }
   768 //    NodeIt& next(NodeIt& n) const { GraphWrapper<Graph>::next(n); return n; }
   800 //    NodeIt& next(NodeIt& n) const { GraphWrapper<Graph>::next(n); return n; }
   769     OutEdgeIt& next(OutEdgeIt& e) const { 
   801     OutEdgeIt& next(OutEdgeIt& e) const { 
   770       if (!e.backward) {
   802       if (!e.backward) {
   771 	Node v=this->graph->aNode(e.out);
   803 	Node v=this->graph->aNode(e.out);
   772 	this->graph->next(e.out);
   804 	this->graph->next(e.out);
   773 	while(this->graph->valid(e.out) && !enabled(e)) { 
   805 	while(this->graph->valid(e.out) && !(*forward_filter)[e]) { 
   774 	  this->graph->next(e.out); }
   806 	  this->graph->next(e.out); }
   775 	if (!this->graph->valid(e.out)) {
   807 	if (!this->graph->valid(e.out)) {
   776 	  e.backward=true;
   808 	  e.backward=true;
   777 	  this->graph->first(e.in, v); 
   809 	  this->graph->first(e.in, v); 
   778 	  while(this->graph->valid(e.in) && !enabled(e)) { 
   810 	  while(this->graph->valid(e.in) && !(*backward_filter)[e]) { 
   779 	    this->graph->next(e.in); }
   811 	    this->graph->next(e.in); }
   780 	}
   812 	}
   781       } else {
   813       } else {
   782 	this->graph->next(e.in);
   814 	this->graph->next(e.in);
   783 	while(this->graph->valid(e.in) && !enabled(e)) { 
   815 	while(this->graph->valid(e.in) && !(*backward_filter)[e]) { 
   784 	  this->graph->next(e.in); } 
   816 	  this->graph->next(e.in); } 
   785       }
   817       }
   786       return e;
   818       return e;
   787     }
   819     }
   788 //     FIXME Not tested
   820 //     FIXME Not tested
   789     InEdgeIt& next(InEdgeIt& e) const { 
   821     InEdgeIt& next(InEdgeIt& e) const { 
   790       if (!e.backward) {
   822       if (!e.backward) {
   791 	Node v=this->graph->aNode(e.in);
   823 	Node v=this->graph->aNode(e.in);
   792 	this->graph->next(e.in);
   824 	this->graph->next(e.in);
   793 	while(this->graph->valid(e.in) && !enabled(e)) { 
   825 	while(this->graph->valid(e.in) && !(*forward_filter)[e]) { 
   794 	  this->graph->next(e.in); }
   826 	  this->graph->next(e.in); }
   795 	if (!this->graph->valid(e.in)) {
   827 	if (!this->graph->valid(e.in)) {
   796 	  e.backward=true;
   828 	  e.backward=true;
   797 	  this->graph->first(e.out, v); 
   829 	  this->graph->first(e.out, v); 
   798 	  while(this->graph->valid(e.out) && !enabled(e)) { 
   830 	  while(this->graph->valid(e.out) && !(*backward_filter)[e]) { 
   799 	    this->graph->next(e.out); }
   831 	    this->graph->next(e.out); }
   800 	}
   832 	}
   801       } else {
   833       } else {
   802 	this->graph->next(e.out);
   834 	this->graph->next(e.out);
   803 	while(this->graph->valid(e.out) && !enabled(e)) { 
   835 	while(this->graph->valid(e.out) && !(*backward_filter)[e]) { 
   804 	  this->graph->next(e.out); } 
   836 	  this->graph->next(e.out); } 
   805       }
   837       }
   806       return e;
   838       return e;
   807     }
   839     }
   808     EdgeIt& next(EdgeIt& e) const {
   840     EdgeIt& next(EdgeIt& e) const {
   809       if (!e.backward) {
   841       if (!e.backward) {
   810 	this->graph->next(e.e);
   842 	this->graph->next(e.e);
   811 	while(this->graph->valid(e.e) && !enabled(e)) { 
   843 	while(this->graph->valid(e.e) && !(*forward_filter)[e]) { 
   812 	  this->graph->next(e.e); }
   844 	  this->graph->next(e.e); }
   813 	if (!this->graph->valid(e.e)) {
   845 	if (!this->graph->valid(e.e)) {
   814 	  e.backward=true;
   846 	  e.backward=true;
   815 	  this->graph->first(e.e); 
   847 	  this->graph->first(e.e); 
   816 	  while(this->graph->valid(e.e) && !enabled(e)) { 
   848 	  while(this->graph->valid(e.e) && !(*backward_filter)[e]) { 
   817 	    this->graph->next(e.e); }
   849 	    this->graph->next(e.e); }
   818 	}
   850 	}
   819       } else {
   851       } else {
   820 	this->graph->next(e.e);
   852 	this->graph->next(e.e);
   821 	while(this->graph->valid(e.e) && !enabled(e)) { 
   853 	while(this->graph->valid(e.e) && !(*backward_filter)[e]) { 
   822 	  this->graph->next(e.e); } 
   854 	  this->graph->next(e.e); } 
   823       }
   855       }
   824       return e;
   856       return e;
   825     }
   857     }
   826 
   858 
   874 //       else  
   906 //       else  
   875 // // 	flow->set(e.in, flow->get(e.in)-a);
   907 // // 	flow->set(e.in, flow->get(e.in)-a);
   876 // 	flow->set(e, (*flow)[e]-a);
   908 // 	flow->set(e, (*flow)[e]-a);
   877 //     }
   909 //     }
   878 
   910 
   879     bool enabled(const Edge& e) const { 
   911 //     bool enabled(const Edge& e) const { 
   880       if (!e.backward) 
   912 //       if (!e.backward) 
   881 //	return (capacity->get(e.out)-flow->get(e.out)); 
   913 // //	return (capacity->get(e.out)-flow->get(e.out)); 
   882 	//return ((*capacity)[e]-(*flow)[e]);
   914 // 	//return ((*capacity)[e]-(*flow)[e]);
   883 	return true;
   915 // 	return true;
   884       else 
   916 //       else 
   885 //	return (flow->get(e.in)); 
   917 // //	return (flow->get(e.in)); 
   886 	//return ((*flow)[e]); 
   918 // 	//return ((*flow)[e]); 
   887 	return true;
   919 // 	return true;
   888     }
   920 //     }
   889 
   921 
   890 //     Number enabled(typename Graph::OutEdgeIt out) const { 
   922 //     Number enabled(typename Graph::OutEdgeIt out) const { 
   891 // //      return (capacity->get(out)-flow->get(out)); 
   923 // //      return (capacity->get(out)-flow->get(out)); 
   892 //       return ((*capacity)[out]-(*flow)[out]); 
   924 //       return ((*capacity)[out]-(*flow)[out]); 
   893 //     }
   925 //     }
   901     class EdgeMap {
   933     class EdgeMap {
   902       typename Graph::template EdgeMap<T> forward_map, backward_map; 
   934       typename Graph::template EdgeMap<T> forward_map, backward_map; 
   903     public:
   935     public:
   904       typedef T ValueType;
   936       typedef T ValueType;
   905       typedef Edge KeyType;
   937       typedef Edge KeyType;
   906       EdgeMap(const BidirGraphWrapper<Graph>& _G) : forward_map(*(_G.graph)), backward_map(*(_G.graph)) { }
   938       EdgeMap(const SubBidirGraphWrapper<Graph, 
   907       EdgeMap(const BidirGraphWrapper<Graph>& _G, T a) : forward_map(*(_G.graph), a), backward_map(*(_G.graph), a) { }
   939 	      ForwardFilterMap, BackwardFilterMap>& _G) : 
       
   940 	forward_map(*(_G.graph)), backward_map(*(_G.graph)) { }
       
   941       EdgeMap(const SubBidirGraphWrapper<Graph, 
       
   942 	      ForwardFilterMap, BackwardFilterMap>& _G, T a) : 
       
   943 	forward_map(*(_G.graph), a), backward_map(*(_G.graph), a) { }
   908       void set(Edge e, T a) { 
   944       void set(Edge e, T a) { 
   909 	if (!e.backward) 
   945 	if (!e.backward) 
   910 	  forward_map.set(e/*.out*/, a); 
   946 	  forward_map.set(e/*.out*/, a); 
   911 	else 
   947 	else 
   912 	  backward_map.set(e/*.in*/, a); 
   948 	  backward_map.set(e/*.in*/, a); 
   927 // 	else 
   963 // 	else 
   928 // 	  return backward_map.get(e.in); 
   964 // 	  return backward_map.get(e.in); 
   929 //       }
   965 //       }
   930     };
   966     };
   931   };
   967   };
       
   968 
       
   969 
       
   970 
       
   971   ///\brief A wrapper for composing bidirected graph from a directed one. 
       
   972   /// experimental, for fezso's sake.
       
   973   ///
       
   974   /// A wrapper for composing bidirected graph from a directed one. 
       
   975   /// experimental, for fezso's sake.
       
   976   /// A bidirected graph is composed over the directed one without physical 
       
   977   /// storage. As the oppositely directed edges are logically different ones 
       
   978   /// the maps are able to attach different values for them.
       
   979   template<typename Graph>
       
   980   class BidirGraphWrapper : 
       
   981     public SubBidirGraphWrapper<
       
   982     Graph, 
       
   983     ConstMap<typename Graph::Edge, bool>, 
       
   984     ConstMap<typename Graph::Edge, bool> > {
       
   985   public:
       
   986     typedef  SubBidirGraphWrapper<
       
   987       Graph, 
       
   988       ConstMap<typename Graph::Edge, bool>, 
       
   989       ConstMap<typename Graph::Edge, bool> > Parent; 
       
   990   protected:
       
   991     ConstMap<typename Graph::Edge, bool> cm;
       
   992     //const CapacityMap* capacity;
       
   993     //FlowMap* flow;
       
   994 
       
   995     BidirGraphWrapper() : Parent(), cm(true) { }
       
   996 //     void setCapacityMap(const CapacityMap& _capacity) {
       
   997 //       capacity=&_capacity;
       
   998 //     }
       
   999 //     void setFlowMap(FlowMap& _flow) {
       
  1000 //       flow=&_flow;
       
  1001 //     }
       
  1002 
       
  1003   public:
       
  1004 
       
  1005     BidirGraphWrapper(Graph& _graph) : Parent() { 
       
  1006       Parent::setGraph(_graph);
       
  1007       Parent::setForwardFilterMap(cm);
       
  1008       Parent::setBackwardFilterMap(cm);
       
  1009     }
       
  1010   };
       
  1011 
       
  1012 
       
  1013 
       
  1014 
       
  1015 //   ///\brief A wrapper for composing bidirected graph from a directed one. 
       
  1016 //   /// experimental, for fezso's sake.
       
  1017 //   ///
       
  1018 //   /// A wrapper for composing bidirected graph from a directed one. 
       
  1019 //   /// experimental, for fezso's sake.
       
  1020 //   /// A bidirected graph is composed over the directed one without physical 
       
  1021 //   /// storage. As the oppositely directed edges are logically different ones 
       
  1022 //   /// the maps are able to attach different values for them.
       
  1023 //   template<typename Graph>
       
  1024 //   class BidirGraphWrapper : public GraphWrapper<Graph> {
       
  1025 //   public:
       
  1026 //     typedef GraphWrapper<Graph> Parent; 
       
  1027 //   protected:
       
  1028 //     //const CapacityMap* capacity;
       
  1029 //     //FlowMap* flow;
       
  1030 
       
  1031 //     BidirGraphWrapper() : GraphWrapper<Graph>()/*, 
       
  1032 // 						 capacity(0), flow(0)*/ { }
       
  1033 // //     void setCapacityMap(const CapacityMap& _capacity) {
       
  1034 // //       capacity=&_capacity;
       
  1035 // //     }
       
  1036 // //     void setFlowMap(FlowMap& _flow) {
       
  1037 // //       flow=&_flow;
       
  1038 // //     }
       
  1039 
       
  1040 //   public:
       
  1041 
       
  1042 //     BidirGraphWrapper(Graph& _graph/*, const CapacityMap& _capacity, 
       
  1043 // 				     FlowMap& _flow*/) : 
       
  1044 //       GraphWrapper<Graph>(_graph)/*, capacity(&_capacity), flow(&_flow)*/ { }
       
  1045 
       
  1046 //     class Edge; 
       
  1047 //     class OutEdgeIt; 
       
  1048 //     friend class Edge; 
       
  1049 //     friend class OutEdgeIt; 
       
  1050 
       
  1051 //     //template<typename T> class NodeMap;    
       
  1052 //     template<typename T> class EdgeMap;
       
  1053 
       
  1054 //     typedef typename GraphWrapper<Graph>::Node Node;
       
  1055 //     typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
       
  1056 
       
  1057 //     class Edge : public Graph::Edge {
       
  1058 //       friend class BidirGraphWrapper<Graph>;
       
  1059 //       ///\bug ez nem is kell
       
  1060 //       //template<typename T> friend class NodeMap;
       
  1061 //       template<typename T> friend class EdgeMap;
       
  1062 //     protected:
       
  1063 //       bool backward; //true, iff backward
       
  1064 // //      typename Graph::Edge e;
       
  1065 //     public:
       
  1066 //       Edge() { }
       
  1067 //       ///\bug =false kell-e? zsoltnak kell az addEdge miatt
       
  1068 //       Edge(const typename Graph::Edge& _e, bool _backward=false) : 
       
  1069 // 	Graph::Edge(_e), backward(_backward) { }
       
  1070 //       Edge(const Invalid& i) : Graph::Edge(i), backward(true) { }
       
  1071 // //the unique invalid iterator
       
  1072 //       friend bool operator==(const Edge& u, const Edge& v) { 
       
  1073 // 	return (v.backward==u.backward && 
       
  1074 // 		static_cast<typename Graph::Edge>(u)==
       
  1075 // 		static_cast<typename Graph::Edge>(v));
       
  1076 //       } 
       
  1077 //       friend bool operator!=(const Edge& u, const Edge& v) { 
       
  1078 // 	return (v.backward!=u.backward || 
       
  1079 // 		static_cast<typename Graph::Edge>(u)!=
       
  1080 // 		static_cast<typename Graph::Edge>(v));
       
  1081 //       } 
       
  1082 //     };
       
  1083 
       
  1084 //     class OutEdgeIt {
       
  1085 //       friend class BidirGraphWrapper<Graph>;
       
  1086 //     protected:
       
  1087 //       typename Graph::OutEdgeIt out;
       
  1088 //       typename Graph::InEdgeIt in;
       
  1089 //       bool backward;
       
  1090 //     public:
       
  1091 //       OutEdgeIt() { }
       
  1092 //       //FIXME
       
  1093 // //      OutEdgeIt(const Edge& e) : Edge(e) { }
       
  1094 //       OutEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { }
       
  1095 // //the unique invalid iterator
       
  1096 //       OutEdgeIt(const BidirGraphWrapper<Graph>& _G, Node v) { 
       
  1097 // 	backward=false;
       
  1098 // 	_G.graph->first(out, v);
       
  1099 // 	while(_G.graph->valid(out) && !_G.enabled(*this)) { _G.graph->next(out); }
       
  1100 // 	if (!_G.graph->valid(out)) {
       
  1101 // 	  backward=true;
       
  1102 // 	  _G.graph->first(in, v);
       
  1103 // 	  while(_G.graph->valid(in) && !_G.enabled(*this)) { _G.graph->next(in); }
       
  1104 // 	}
       
  1105 //       }
       
  1106 //       operator Edge() const { 
       
  1107 // //	Edge e;
       
  1108 // //	e.forward=this->forward;
       
  1109 // //	if (this->forward) e=out; else e=in;
       
  1110 // //	return e;
       
  1111 // 	if (this->backward) 
       
  1112 // 	  return Edge(in, this->backward); 
       
  1113 // 	else 
       
  1114 // 	  return Edge(out, this->backward);
       
  1115 //       }
       
  1116 //     };
       
  1117 
       
  1118 //     class InEdgeIt {
       
  1119 //       friend class BidirGraphWrapper<Graph>;
       
  1120 //     protected:
       
  1121 //       typename Graph::OutEdgeIt out;
       
  1122 //       typename Graph::InEdgeIt in;
       
  1123 //       bool backward;
       
  1124 //     public:
       
  1125 //       InEdgeIt() { }
       
  1126 //       //FIXME
       
  1127 // //      OutEdgeIt(const Edge& e) : Edge(e) { }
       
  1128 //       InEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { }
       
  1129 // //the unique invalid iterator
       
  1130 //       InEdgeIt(const BidirGraphWrapper<Graph>& _G, Node v) { 
       
  1131 // 	backward=false;
       
  1132 // 	_G.graph->first(in, v);
       
  1133 // 	while(_G.graph->valid(in) && !_G.enabled(*this)) { _G.graph->next(in); }
       
  1134 // 	if (!_G.graph->valid(in)) {
       
  1135 // 	  backward=true;
       
  1136 // 	  _G.graph->first(out, v);
       
  1137 // 	  while(_G.graph->valid(out) && !_G.enabled(*this)) { _G.graph->next(out); }
       
  1138 // 	}
       
  1139 //       }
       
  1140 //       operator Edge() const { 
       
  1141 // //	Edge e;
       
  1142 // //	e.forward=this->forward;
       
  1143 // //	if (this->forward) e=out; else e=in;
       
  1144 // //	return e;
       
  1145 // 	if (this->backward) 
       
  1146 // 	  return Edge(out, this->backward); 
       
  1147 // 	else 
       
  1148 // 	  return Edge(in, this->backward);
       
  1149 //       }
       
  1150 //     };
       
  1151 
       
  1152 //     class EdgeIt {
       
  1153 //       friend class BidirGraphWrapper<Graph>;
       
  1154 //     protected:
       
  1155 //       typename Graph::EdgeIt e;
       
  1156 //       bool backward;
       
  1157 //     public:
       
  1158 //       EdgeIt() { }
       
  1159 //       EdgeIt(const Invalid& i) : e(i), backward(true) { }
       
  1160 //       EdgeIt(const BidirGraphWrapper<Graph>& _G) { 
       
  1161 // 	backward=false;
       
  1162 // 	_G.graph->first(e);
       
  1163 // 	while (_G.graph->valid(e) && !_G.enabled(*this)) _G.graph->next(e);
       
  1164 // 	if (!_G.graph->valid(e)) {
       
  1165 // 	  backward=true;
       
  1166 // 	  _G.graph->first(e);
       
  1167 // 	  while (_G.graph->valid(e) && !_G.enabled(*this)) _G.graph->next(e);
       
  1168 // 	}
       
  1169 //       }
       
  1170 //       operator Edge() const { 
       
  1171 // 	return Edge(e, this->backward);
       
  1172 //       }
       
  1173 //     };
       
  1174 
       
  1175 //     using GraphWrapper<Graph>::first;
       
  1176 // //     NodeIt& first(NodeIt& i) const { 
       
  1177 // //       i=NodeIt(*this); return i;
       
  1178 // //     }
       
  1179 //     OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
       
  1180 //       i=OutEdgeIt(*this, p); return i;
       
  1181 //     }
       
  1182 // //    FIXME not tested
       
  1183 //     InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
       
  1184 //       i=InEdgeIt(*this, p); return i;
       
  1185 //     }
       
  1186 //     EdgeIt& first(EdgeIt& i) const { 
       
  1187 //       i=EdgeIt(*this); return i;
       
  1188 //     }
       
  1189   
       
  1190 //     using GraphWrapper<Graph>::next;
       
  1191 // //    NodeIt& next(NodeIt& n) const { GraphWrapper<Graph>::next(n); return n; }
       
  1192 //     OutEdgeIt& next(OutEdgeIt& e) const { 
       
  1193 //       if (!e.backward) {
       
  1194 // 	Node v=this->graph->aNode(e.out);
       
  1195 // 	this->graph->next(e.out);
       
  1196 // 	while(this->graph->valid(e.out) && !enabled(e)) { 
       
  1197 // 	  this->graph->next(e.out); }
       
  1198 // 	if (!this->graph->valid(e.out)) {
       
  1199 // 	  e.backward=true;
       
  1200 // 	  this->graph->first(e.in, v); 
       
  1201 // 	  while(this->graph->valid(e.in) && !enabled(e)) { 
       
  1202 // 	    this->graph->next(e.in); }
       
  1203 // 	}
       
  1204 //       } else {
       
  1205 // 	this->graph->next(e.in);
       
  1206 // 	while(this->graph->valid(e.in) && !enabled(e)) { 
       
  1207 // 	  this->graph->next(e.in); } 
       
  1208 //       }
       
  1209 //       return e;
       
  1210 //     }
       
  1211 // //     FIXME Not tested
       
  1212 //     InEdgeIt& next(InEdgeIt& e) const { 
       
  1213 //       if (!e.backward) {
       
  1214 // 	Node v=this->graph->aNode(e.in);
       
  1215 // 	this->graph->next(e.in);
       
  1216 // 	while(this->graph->valid(e.in) && !enabled(e)) { 
       
  1217 // 	  this->graph->next(e.in); }
       
  1218 // 	if (!this->graph->valid(e.in)) {
       
  1219 // 	  e.backward=true;
       
  1220 // 	  this->graph->first(e.out, v); 
       
  1221 // 	  while(this->graph->valid(e.out) && !enabled(e)) { 
       
  1222 // 	    this->graph->next(e.out); }
       
  1223 // 	}
       
  1224 //       } else {
       
  1225 // 	this->graph->next(e.out);
       
  1226 // 	while(this->graph->valid(e.out) && !enabled(e)) { 
       
  1227 // 	  this->graph->next(e.out); } 
       
  1228 //       }
       
  1229 //       return e;
       
  1230 //     }
       
  1231 //     EdgeIt& next(EdgeIt& e) const {
       
  1232 //       if (!e.backward) {
       
  1233 // 	this->graph->next(e.e);
       
  1234 // 	while(this->graph->valid(e.e) && !enabled(e)) { 
       
  1235 // 	  this->graph->next(e.e); }
       
  1236 // 	if (!this->graph->valid(e.e)) {
       
  1237 // 	  e.backward=true;
       
  1238 // 	  this->graph->first(e.e); 
       
  1239 // 	  while(this->graph->valid(e.e) && !enabled(e)) { 
       
  1240 // 	    this->graph->next(e.e); }
       
  1241 // 	}
       
  1242 //       } else {
       
  1243 // 	this->graph->next(e.e);
       
  1244 // 	while(this->graph->valid(e.e) && !enabled(e)) { 
       
  1245 // 	  this->graph->next(e.e); } 
       
  1246 //       }
       
  1247 //       return e;
       
  1248 //     }
       
  1249 
       
  1250 //     Node tail(Edge e) const { 
       
  1251 //       return ((!e.backward) ? this->graph->tail(e) : this->graph->head(e)); }
       
  1252 //     Node head(Edge e) const { 
       
  1253 //       return ((!e.backward) ? this->graph->head(e) : this->graph->tail(e)); }
       
  1254 
       
  1255 //     Node aNode(OutEdgeIt e) const { 
       
  1256 //       return ((!e.backward) ? this->graph->aNode(e.out) : 
       
  1257 // 	      this->graph->aNode(e.in)); }
       
  1258 //     Node bNode(OutEdgeIt e) const { 
       
  1259 //       return ((!e.backward) ? this->graph->bNode(e.out) : 
       
  1260 // 	      this->graph->bNode(e.in)); }
       
  1261 
       
  1262 //     Node aNode(InEdgeIt e) const { 
       
  1263 //       return ((!e.backward) ? this->graph->aNode(e.in) : 
       
  1264 // 	      this->graph->aNode(e.out)); }
       
  1265 //     Node bNode(InEdgeIt e) const { 
       
  1266 //       return ((!e.backward) ? this->graph->bNode(e.in) : 
       
  1267 // 	      this->graph->bNode(e.out)); }
       
  1268 
       
  1269 //     /// Gives back the opposite edge.
       
  1270 //     Edge opposite(const Edge& e) const { 
       
  1271 //       Edge f=e;
       
  1272 //       f.backward=!f.backward;
       
  1273 //       return f;
       
  1274 //     }
       
  1275 
       
  1276 // //    int nodeNum() const { return graph->nodeNum(); }
       
  1277 //     //FIXME
       
  1278 //     void edgeNum() const { }
       
  1279 //     //int edgeNum() const { return graph->edgeNum(); }
       
  1280 
       
  1281 
       
  1282 // //    int id(Node v) const { return graph->id(v); }
       
  1283 
       
  1284 //     bool valid(Node n) const { return GraphWrapper<Graph>::valid(n); }
       
  1285 //     bool valid(Edge e) const { 
       
  1286 //       return this->graph->valid(e);
       
  1287 // 	//return e.forward ? graph->valid(e.out) : graph->valid(e.in); 
       
  1288 //     }
       
  1289 
       
  1290 //     bool forward(const Edge& e) const { return !e.backward; }
       
  1291 //     bool backward(const Edge& e) const { return e.backward; }
       
  1292 
       
  1293 // //     void augment(const Edge& e, Number a) const {
       
  1294 // //       if (!e.backward)  
       
  1295 // // // 	flow->set(e.out, flow->get(e.out)+a);
       
  1296 // // 	flow->set(e, (*flow)[e]+a);
       
  1297 // //       else  
       
  1298 // // // 	flow->set(e.in, flow->get(e.in)-a);
       
  1299 // // 	flow->set(e, (*flow)[e]-a);
       
  1300 // //     }
       
  1301 
       
  1302 //     bool enabled(const Edge& e) const { 
       
  1303 //       if (!e.backward) 
       
  1304 // //	return (capacity->get(e.out)-flow->get(e.out)); 
       
  1305 // 	//return ((*capacity)[e]-(*flow)[e]);
       
  1306 // 	return true;
       
  1307 //       else 
       
  1308 // //	return (flow->get(e.in)); 
       
  1309 // 	//return ((*flow)[e]); 
       
  1310 // 	return true;
       
  1311 //     }
       
  1312 
       
  1313 // //     Number enabled(typename Graph::OutEdgeIt out) const { 
       
  1314 // // //      return (capacity->get(out)-flow->get(out)); 
       
  1315 // //       return ((*capacity)[out]-(*flow)[out]); 
       
  1316 // //     }
       
  1317     
       
  1318 // //     Number enabled(typename Graph::InEdgeIt in) const { 
       
  1319 // // //      return (flow->get(in)); 
       
  1320 // //       return ((*flow)[in]); 
       
  1321 // //     }
       
  1322 
       
  1323 //     template <typename T>
       
  1324 //     class EdgeMap {
       
  1325 //       typename Graph::template EdgeMap<T> forward_map, backward_map; 
       
  1326 //     public:
       
  1327 //       typedef T ValueType;
       
  1328 //       typedef Edge KeyType;
       
  1329 //       EdgeMap(const BidirGraphWrapper<Graph>& _G) : forward_map(*(_G.graph)), backward_map(*(_G.graph)) { }
       
  1330 //       EdgeMap(const BidirGraphWrapper<Graph>& _G, T a) : forward_map(*(_G.graph), a), backward_map(*(_G.graph), a) { }
       
  1331 //       void set(Edge e, T a) { 
       
  1332 // 	if (!e.backward) 
       
  1333 // 	  forward_map.set(e/*.out*/, a); 
       
  1334 // 	else 
       
  1335 // 	  backward_map.set(e/*.in*/, a); 
       
  1336 //       }
       
  1337 //       T operator[](Edge e) const { 
       
  1338 // 	if (!e.backward) 
       
  1339 // 	  return forward_map[e/*.out*/]; 
       
  1340 // 	else 
       
  1341 // 	  return backward_map[e/*.in*/]; 
       
  1342 //       }
       
  1343 //       void update() { 
       
  1344 // 	forward_map.update(); 
       
  1345 // 	backward_map.update();
       
  1346 //       }
       
  1347 // //       T get(Edge e) const { 
       
  1348 // // 	if (e.out_or_in) 
       
  1349 // // 	  return forward_map.get(e.out); 
       
  1350 // // 	else 
       
  1351 // // 	  return backward_map.get(e.in); 
       
  1352 // //       }
       
  1353 //     };
       
  1354 //   };
   932 
  1355 
   933   /// \brief A bidirected graph template.
  1356   /// \brief A bidirected graph template.
   934   ///
  1357   ///
   935   /// A bidirected graph template.
  1358   /// A bidirected graph template.
   936   /// Such a bidirected graph stores each pair of oppositely directed edges 
  1359   /// Such a bidirected graph stores each pair of oppositely directed edges 
   939   /// As the oppositely directed edges are logically different ones 
  1362   /// As the oppositely directed edges are logically different ones 
   940   /// the maps are able to attach different values for them.
  1363   /// the maps are able to attach different values for them.
   941   /// \ingroup graphs
  1364   /// \ingroup graphs
   942   template<typename Graph>
  1365   template<typename Graph>
   943   class BidirGraph : public BidirGraphWrapper<Graph> {
  1366   class BidirGraph : public BidirGraphWrapper<Graph> {
       
  1367   public:
   944     typedef UndirGraphWrapper<Graph> Parent;
  1368     typedef UndirGraphWrapper<Graph> Parent;
   945   protected:
  1369   protected:
   946     Graph gr;
  1370     Graph gr;
   947   public:
  1371   public:
   948     BidirGraph() : BidirGraphWrapper<Graph>() { 
  1372     BidirGraph() : BidirGraphWrapper<Graph>() { 
   949       Parent::setGraph(gr); 
  1373       Parent::setGraph(gr); 
   950     }
  1374     }
   951   };
  1375   };
       
  1376 
       
  1377 
       
  1378 
       
  1379   /// An experiment for ResGraphWrapper.
       
  1380   template<typename Graph, typename Number,
       
  1381 	   typename CapacityMap, typename FlowMap>
       
  1382   class ForwardFilter {
       
  1383     const Graph* graph;
       
  1384     const CapacityMap* capacity;
       
  1385     const FlowMap* flow;
       
  1386   public:
       
  1387     ForwardFilter(const Graph& _graph, 
       
  1388 		  const CapacityMap& _capacity, const FlowMap& _flow) :
       
  1389       graph(&_graph), capacity(&_capacity), flow(&_flow) { }
       
  1390     bool operator[](const typename Graph::Edge& e) const {
       
  1391       return ((*flow)[e] < (*capacity)[e]);
       
  1392     }
       
  1393   };
       
  1394 
       
  1395   /// An experiment for ResGraphWrapper.
       
  1396   template<typename Graph, typename Number,
       
  1397 	   typename CapacityMap, typename FlowMap>
       
  1398   class BackwardFilter {
       
  1399     const Graph* graph;
       
  1400     const CapacityMap* capacity;
       
  1401     const FlowMap* flow;
       
  1402   public:
       
  1403     BackwardFilter(const Graph& _graph, 
       
  1404 		   const CapacityMap& _capacity, const FlowMap& _flow) :
       
  1405       graph(&_graph), capacity(&_capacity), flow(&_flow) { }
       
  1406     bool operator[](const typename Graph::Edge& e) const {
       
  1407       return (0 < (*flow)[e]);
       
  1408     }
       
  1409   };
       
  1410 
       
  1411 
       
  1412   /// An experiment for ResGraphWrapper.
       
  1413   template<typename Graph, typename Number, 
       
  1414 	   typename CapacityMap, typename FlowMap>
       
  1415   class ExpResGraphWrapper : 
       
  1416     public SubBidirGraphWrapper< 
       
  1417     Graph, 
       
  1418     ForwardFilter<Graph, Number, CapacityMap, FlowMap>,  
       
  1419     BackwardFilter<Graph, Number, CapacityMap, FlowMap> > {
       
  1420   public:
       
  1421     typedef SubBidirGraphWrapper< 
       
  1422       Graph, 
       
  1423       ForwardFilter<Graph, Number, CapacityMap, FlowMap>,  
       
  1424       BackwardFilter<Graph, Number, CapacityMap, FlowMap> > Parent;
       
  1425   protected:
       
  1426     const CapacityMap* capacity;
       
  1427     FlowMap* flow;
       
  1428     ForwardFilter<Graph, Number, CapacityMap, FlowMap> forward_filter;
       
  1429     BackwardFilter<Graph, Number, CapacityMap, FlowMap> backward_filter;
       
  1430   public:
       
  1431     ExpResGraphWrapper(Graph& _graph, const CapacityMap& _capacity, 
       
  1432 		       FlowMap& _flow) : 
       
  1433       Parent(), capacity(&_capacity), flow(&_flow), 
       
  1434       forward_filter(_graph, _capacity, _flow), 
       
  1435       backward_filter(_graph, _capacity, _flow) {
       
  1436       Parent::setGraph(_graph);
       
  1437       Parent::setForwardFilterMap(forward_filter);
       
  1438       Parent::setBackwardFilterMap(backward_filter);
       
  1439     }
       
  1440 
       
  1441     //    bool forward(const Parent::Edge& e) const { return Parent::forward(e); }
       
  1442     //bool backward(const Edge& e) const { return e.backward; }
       
  1443 
       
  1444     void augment(const typename Parent::Edge& e, Number a) const {
       
  1445       if (Parent::forward(e))  
       
  1446 // 	flow->set(e.out, flow->get(e.out)+a);
       
  1447 	flow->set(e, (*flow)[e]+a);
       
  1448       else  
       
  1449 	//flow->set(e.in, flow->get(e.in)-a);
       
  1450 	flow->set(e, (*flow)[e]-a);
       
  1451     }
       
  1452 
       
  1453     Number resCap(const typename Parent::Edge& e) const { 
       
  1454       if (Parent::forward(e)) 
       
  1455 //	return (capacity->get(e.out)-flow->get(e.out)); 
       
  1456 	return ((*capacity)[e]-(*flow)[e]); 
       
  1457       else 
       
  1458 //	return (flow->get(e.in)); 
       
  1459 	return ((*flow)[e]); 
       
  1460     }
       
  1461 
       
  1462   };
       
  1463 
       
  1464 
       
  1465 
       
  1466 
       
  1467 //   /// An experiment for ResGraphWrapper.
       
  1468 //   template<typename Graph, typename Number, 
       
  1469 // 	   typename CapacityMap, typename FlowMap>
       
  1470 //   class ExpResGraphWrapper : 
       
  1471 //     public SubGraphWrapper< BidirGraphWrapper<Graph>, 
       
  1472 // 			    ConstMap<typename BidirGraphWrapper<Graph>::Node, 
       
  1473 // 				     bool>, 
       
  1474 // 			    EdgeFilter< BidirGraphWrapper<Graph>, 
       
  1475 // 					CapacityMap, FlowMap> > {
       
  1476 //   public:
       
  1477 //     typedef SubGraphWrapper< BidirGraphWrapper<Graph>, 
       
  1478 // 			     ConstMap<typename BidirGraphWrapper<Graph>::Node, 
       
  1479 // 				      bool>, 
       
  1480 // 			     EdgeFilter< BidirGraphWrapper<Graph>, 
       
  1481 // 					 CapacityMap, FlowMap> > Parent; 
       
  1482 //   protected:
       
  1483 //     const CapacityMap* capacity;
       
  1484 //     FlowMap* flow;
       
  1485 //     BidirGraphWrapper<Graph> bidir_graph;
       
  1486 //     ConstMap<typename BidirGraphWrapper<Graph>::Node, bool> node_filter;
       
  1487 //     EdgeFilter< BidirGraphWrapper<Graph>, CapacityMap, FlowMap> edge_filter;
       
  1488 //   public:
       
  1489 //     ExpResGraphWrapper(Graph& _graph, const CapacityMap& _capacity, 
       
  1490 // 		       FlowMap& _flow) : 
       
  1491 //       Parent(), capacity(&_capacity), flow(&_flow), 
       
  1492 //       bidir_graph(_graph), 
       
  1493 //       node_filter(true),
       
  1494 //       edge_filter(bidir_graph, *capacity, *flow) { 
       
  1495 //       Parent::setGraph(bidir_graph);
       
  1496 //       Parent::setNodeFilterMap(node_filter);
       
  1497 //       Parent::setEdgeFilterMap(edge_filter);
       
  1498 //     }
       
  1499 
       
  1500 //     //    bool forward(const Parent::Edge& e) const { return Parent::forward(e); }
       
  1501 //     //bool backward(const Edge& e) const { return e.backward; }
       
  1502 
       
  1503 //     void augment(const typename Parent::Edge& e, Number a) const {
       
  1504 //       if (Parent::forward(e))  
       
  1505 // // 	flow->set(e.out, flow->get(e.out)+a);
       
  1506 // 	flow->set(e, (*flow)[e]+a);
       
  1507 //       else  
       
  1508 // // 	flow->set(e.in, flow->get(e.in)-a);
       
  1509 // 	flow->set(e, (*flow)[e]-a);
       
  1510 //     }
       
  1511 
       
  1512 //     Number resCap(const typename Parent::Edge& e) const { 
       
  1513 //       if (Parent::forward(e)) 
       
  1514 // //	return (capacity->get(e.out)-flow->get(e.out)); 
       
  1515 // 	return ((*capacity)[e]-(*flow)[e]); 
       
  1516 //       else 
       
  1517 // //	return (flow->get(e.in)); 
       
  1518 // 	return ((*flow)[e]); 
       
  1519 //     }
       
  1520 
       
  1521 //   };
       
  1522 
   952 
  1523 
   953 
  1524 
   954   /// A wrapper for composing the residual graph for directed flow and circulation problems.
  1525   /// A wrapper for composing the residual graph for directed flow and circulation problems.
   955 
  1526 
   956   /// A wrapper for composing the residual graph for directed flow and circulation problems.
  1527   /// A wrapper for composing the residual graph for directed flow and circulation problems.
   957   template<typename Graph, typename Number, 
  1528   template<typename Graph, typename Number, 
   958 	   typename CapacityMap, typename FlowMap>
  1529 	   typename CapacityMap, typename FlowMap>
   959   class ResGraphWrapper : public GraphWrapper<Graph> {
  1530   class ResGraphWrapper : public GraphWrapper<Graph> {
       
  1531   public:
       
  1532     typedef GraphWrapper<Graph> Parent; 
   960   protected:
  1533   protected:
   961     const CapacityMap* capacity;
  1534     const CapacityMap* capacity;
   962     FlowMap* flow;
  1535     FlowMap* flow;
   963 
  1536 
   964     ResGraphWrapper() : GraphWrapper<Graph>(0), 
  1537     ResGraphWrapper() : GraphWrapper<Graph>(0), 
  1281   /// is called. 
  1854   /// is called. 
  1282   ///
  1855   ///
  1283   ///\author Marton Makai
  1856   ///\author Marton Makai
  1284   template<typename Graph, typename FirstOutEdgesMap>
  1857   template<typename Graph, typename FirstOutEdgesMap>
  1285   class ErasingFirstGraphWrapper : public GraphWrapper<Graph> {
  1858   class ErasingFirstGraphWrapper : public GraphWrapper<Graph> {
       
  1859   public:
       
  1860     typedef GraphWrapper<Graph> Parent; 
  1286   protected:
  1861   protected:
  1287     FirstOutEdgesMap* first_out_edges;
  1862     FirstOutEdgesMap* first_out_edges;
  1288   public:
  1863   public:
  1289     ErasingFirstGraphWrapper(Graph& _graph, 
  1864     ErasingFirstGraphWrapper(Graph& _graph, 
  1290 			     FirstOutEdgesMap& _first_out_edges) : 
  1865 			     FirstOutEdgesMap& _first_out_edges) :