Index: src/work/edmonds_karp.h
===================================================================
--- src/work/edmonds_karp.h	(revision 265)
+++ src/work/edmonds_karp.h	(revision 266)
@@ -248,28 +248,30 @@
 
 
-  template <typename Graph, typename Number, typename FlowMap, typename CapacityMap>
+  template <typename GraphWrapper, typename Number, typename FlowMap, typename CapacityMap>
   class MaxFlow {
   public:
-    typedef typename Graph::Node Node;
-    typedef typename Graph::Edge Edge;
-    typedef typename Graph::EdgeIt EdgeIt;
-    typedef typename Graph::OutEdgeIt OutEdgeIt;
-    typedef typename Graph::InEdgeIt InEdgeIt;
+    typedef typename GraphWrapper::Node Node;
+    typedef typename GraphWrapper::Edge Edge;
+    typedef typename GraphWrapper::EdgeIt EdgeIt;
+    typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
+    typedef typename GraphWrapper::InEdgeIt InEdgeIt;
 
   private:
-    const Graph* G;
+    //const Graph* G;
+    GraphWrapper gw;
     Node s;
     Node t;
     FlowMap* flow;
     const CapacityMap* capacity;
-    typedef ResGraphWrapper<Graph, Number, FlowMap, CapacityMap > AugGraph;
+    typedef ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap > 
+    AugGraph;
     typedef typename AugGraph::OutEdgeIt AugOutEdgeIt;
     typedef typename AugGraph::Edge AugEdge;
 
   public:
-    MaxFlow(const Graph& _G, Node _s, Node _t, FlowMap& _flow, const CapacityMap& _capacity) : 
-      G(&_G), s(_s), t(_t), flow(&_flow), capacity(&_capacity) { }
+    MaxFlow(const GraphWrapper& _gw, Node _s, Node _t, FlowMap& _flow, const CapacityMap& _capacity) : 
+      gw(_gw), s(_s), t(_t), flow(&_flow), capacity(&_capacity) { }
     bool augmentOnShortestPath() {
-      AugGraph res_graph(*G, *flow, *capacity);
+      AugGraph res_graph(gw, *flow, *capacity);
       bool _augment=false;
       
@@ -314,123 +316,16 @@
     }
 
-//     template<typename MutableGraph> bool augmentOnBlockingFlow() {      
-//       bool _augment=false;
-
-//       AugGraph res_graph(*G, *flow, *capacity);
-
-//       typedef typename AugGraph::NodeMap<bool> ReachedMap;
-//       BfsIterator5< AugGraph /*, AugOutEdgeIt*/, ReachedMap > bfs(res_graph);
-
-//       bfs.pushAndSetReached(s);
-//       typename AugGraph::NodeMap<int> dist(res_graph); //filled up with 0's
-//       while ( !bfs.finished() ) { 
-// 	AugOutEdgeIt e=bfs;
-// 	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
-// 	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
-// 	}
-	
-// 	++bfs;
-//       } //computing distances from s in the residual graph
-
-//       MutableGraph F;
-//       typename AugGraph::NodeMap<typename MutableGraph::Node> 
-// 	res_graph_to_F(res_graph);
-//       for(typename AugGraph::NodeIt n=res_graph.template first<typename AugGraph::NodeIt>(); res_graph.valid(n); res_graph.next(n)) {
-// 	res_graph_to_F.set(n, F.addNode());
-//       }
-      
-//       typename MutableGraph::Node sF=res_graph_to_F.get(s);
-//       typename MutableGraph::Node tF=res_graph_to_F.get(t);
-
-//       typename MutableGraph::EdgeMap<AugEdge> original_edge(F);
-//       typename MutableGraph::EdgeMap<Number> residual_capacity(F);
-
-//       //Making F to the graph containing the edges of the residual graph 
-//       //which are in some shortest paths
-//       for(typename AugGraph::EdgeIt e=res_graph.template first<typename AugGraph::EdgeIt>(); res_graph.valid(e); res_graph.next(e)) {
-// 	if (dist.get(res_graph.head(e))==dist.get(res_graph.tail(e))+1) {
-// 	  typename MutableGraph::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
-// 	  original_edge.update();
-// 	  original_edge.set(f, e);
-// 	  residual_capacity.update();
-// 	  residual_capacity.set(f, res_graph.free(e));
-// 	} 
-//       }
-
-//       bool __augment=true;
-
-//       while (__augment) {
-// 	__augment=false;
-// 	//computing blocking flow with dfs
-// 	typedef typename TrivGraphWrapper<MutableGraph>::NodeMap<bool> BlockingReachedMap;
-// 	DfsIterator5< TrivGraphWrapper<MutableGraph>/*, typename MutableGraph::OutEdgeIt*/, BlockingReachedMap > dfs(F);
-// 	typename MutableGraph::NodeMap<typename MutableGraph::Edge> pred(F);
-// 	pred.set(sF, typename MutableGraph::Edge(INVALID));
-// 	//invalid iterators for sources
-
-// 	typename MutableGraph::NodeMap<Number> free(F);
-
-// 	dfs.pushAndSetReached(sF);      
-// 	while (!dfs.finished()) {
-// 	  ++dfs;
-// 	  if (F.valid(typename MutableGraph::OutEdgeIt(dfs))) {
-// 	    if (dfs.isBNodeNewlyReached()) {
-// 	      typename MutableGraph::Node v=F.aNode(dfs);
-// 	      typename MutableGraph::Node w=F.bNode(dfs);
-// 	      pred.set(w, dfs);
-// 	      if (F.valid(pred.get(v))) {
-// 		free.set(w, std::min(free.get(v), residual_capacity.get(dfs)));
-// 	      } else {
-// 		free.set(w, residual_capacity.get(dfs)); 
-// 	      }
-// 	      if (w==tF) { 
-// 		__augment=true; 
-// 		_augment=true;
-// 		break; 
-// 	      }
-	      
-// 	    } else {
-// 	      F.erase(typename MutableGraph::OutEdgeIt(dfs));
-// 	    }
-// 	  } 
-// 	}
-
-// 	if (__augment) {
-// 	  typename MutableGraph::Node n=tF;
-// 	  Number augment_value=free.get(tF);
-// 	  while (F.valid(pred.get(n))) { 
-// 	    typename MutableGraph::Edge e=pred.get(n);
-// 	    res_graph.augment(original_edge.get(e), augment_value); 
-// 	    n=F.tail(e);
-// 	    if (residual_capacity.get(e)==augment_value) 
-// 	      F.erase(e); 
-// 	    else 
-// 	      residual_capacity.set(e, residual_capacity.get(e)-augment_value);
-// 	  }
-// 	}
-	
-//       }
-            
-//       return _augment;
-//     }
-
-    template<typename GraphWrapper> 
+    template<typename MapGraphWrapper> 
     class DistanceMap {
     protected:
-      GraphWrapper gw;
-      typename GraphWrapper::NodeMap<int> dist; 
+      MapGraphWrapper gw;
+      typename MapGraphWrapper::NodeMap<int> dist; 
     public:
-      DistanceMap(GraphWrapper& _gw) : gw(_gw), dist(_gw, _gw.nodeNum()) { }
-      //NodeMap(const ListGraph& _G, T a) : 
-      //G(_G), container(G.node_id, a) { }
-      void set(const typename GraphWrapper::Node& n, int a) { dist[n]=a; }
-      int get(const typename GraphWrapper::Node& n) const { return dist[n]; }
-      bool get(const typename GraphWrapper::Edge& e) const { 
+      DistanceMap(MapGraphWrapper& _gw) : gw(_gw), dist(_gw, _gw.nodeNum()) { }
+      void set(const typename MapGraphWrapper::Node& n, int a) { dist[n]=a; }
+      int get(const typename MapGraphWrapper::Node& n) const { return dist[n]; }
+      bool get(const typename MapGraphWrapper::Edge& e) const { 
 	return (dist.get(gw.tail(e))<dist.get(gw.head(e))); 
       }
-      //typename std::vector<T>::reference operator[](Node n) { 
-      //return container[/*G.id(n)*/n.node->id]; }
-      //typename std::vector<T>::const_reference operator[](Node n) const { 
-      //return container[/*G.id(n)*/n.node->id]; 
     };
 
@@ -438,5 +333,5 @@
       bool _augment=false;
 
-      AugGraph res_graph(*G, *flow, *capacity);
+      AugGraph res_graph(gw, *flow, *capacity);
 
       typedef typename AugGraph::NodeMap<bool> ReachedMap;
@@ -454,32 +349,7 @@
       } //computing distances from s in the residual graph
 
-//       MutableGraph F;
-//       typename AugGraph::NodeMap<typename MutableGraph::Node> 
-// 	res_graph_to_F(res_graph);
-//       for(typename AugGraph::NodeIt n=res_graph.template first<typename AugGraph::NodeIt>(); res_graph.valid(n); res_graph.next(n)) {
-// 	res_graph_to_F.set(n, F.addNode());
-//       }
-      
-//       typename MutableGraph::Node sF=res_graph_to_F.get(s);
-//       typename MutableGraph::Node tF=res_graph_to_F.get(t);
-
-//       typename MutableGraph::EdgeMap<AugEdge> original_edge(F);
-//       typename MutableGraph::EdgeMap<Number> residual_capacity(F);
-
-//       //Making F to the graph containing the edges of the residual graph 
-//       //which are in some shortest paths
-//       for(typename AugGraph::EdgeIt e=res_graph.template first<typename AugGraph::EdgeIt>(); res_graph.valid(e); res_graph.next(e)) {
-// 	if (dist.get(res_graph.head(e))==dist.get(res_graph.tail(e))+1) {
-// 	  typename MutableGraph::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
-// 	  original_edge.update();
-// 	  original_edge.set(f, e);
-// 	  residual_capacity.update();
-// 	  residual_capacity.set(f, res_graph.free(e));
-// 	} 
-//       }
-
       MutableGraph F;
-      //typedef SubGraphWrapper<AugGraph, DistanceMap<AugGraph> > FilterResGraph;
-      //FilterResGraph filter_res_graph(res_graph, dist);
+      typedef SubGraphWrapper<AugGraph, DistanceMap<AugGraph> > FilterResGraph;
+      FilterResGraph filter_res_graph(res_graph, dist);
       typename AugGraph::NodeMap<typename MutableGraph::Node> 
 	res_graph_to_F(res_graph);
@@ -496,8 +366,6 @@
       //Making F to the graph containing the edges of the residual graph 
       //which are in some shortest paths
-      for(typename AugGraph::EdgeIt e=res_graph.template first<typename AugGraph::EdgeIt>(); 
-	  res_graph.valid(e); 
-	  res_graph.next(e)) {
-	if (dist.get(res_graph.head(e))==dist.get(res_graph.tail(e))+1) {
+      for(typename FilterResGraph::EdgeIt e=filter_res_graph.template first<typename FilterResGraph::EdgeIt>(); filter_res_graph.valid(e); filter_res_graph.next(e)) {
+	//if (dist.get(res_graph.head(e))==dist.get(res_graph.tail(e))+1) {
 	  typename MutableGraph::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
 	  original_edge.update();
@@ -505,5 +373,5 @@
 	  residual_capacity.update();
 	  residual_capacity.set(f, res_graph.free(e));
-	} 
+	  //} 
       }
 
@@ -565,353 +433,17 @@
     }
 
-    template<typename MutableGraph> bool augmentOnBlockingFlow1() {      
-      bool _augment=false;
-
-      AugGraph res_graph(*G, *flow, *capacity);
-
-      //bfs for distances on the residual graph
-      typedef typename AugGraph::NodeMap<bool> ReachedMap;
-      BfsIterator5< AugGraph, ReachedMap > bfs(res_graph);
-      bfs.pushAndSetReached(s);
-      typename AugGraph::NodeMap<int> dist(res_graph); //filled up with 0's
-
-      //F will contain the physical copy of the residual graph
-      //with the set of edges which areon shortest paths
-      MutableGraph F;
-      typename AugGraph::NodeMap<typename MutableGraph::Node> 
-	res_graph_to_F(res_graph);
-      for(typename AugGraph::NodeIt n=res_graph.template first<typename AugGraph::NodeIt>(); res_graph.valid(n); res_graph.next(n)) {
-	res_graph_to_F.set(n, F.addNode());
-      }
-      typename MutableGraph::Node sF=res_graph_to_F.get(s);
-      typename MutableGraph::Node tF=res_graph_to_F.get(t);
-      typename MutableGraph::EdgeMap<AugEdge> original_edge(F);
-      typename MutableGraph::EdgeMap<Number> residual_capacity(F);
-
-      while ( !bfs.finished() ) { 
-	AugOutEdgeIt e=bfs;
-	if (res_graph.valid(e)) {
-	  if (bfs.isBNodeNewlyReached()) {
-	    dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
-	    typename MutableGraph::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
-	    original_edge.update();
-	    original_edge.set(f, e);
-	    residual_capacity.update();
-	    residual_capacity.set(f, res_graph.free(e));
-	  } else {
-	    if (dist.get(res_graph.head(e))==(dist.get(res_graph.tail(e))+1)) {
-	      typename MutableGraph::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
-	      original_edge.update();
-	      original_edge.set(f, e);
-	      residual_capacity.update();
-	      residual_capacity.set(f, res_graph.free(e));
-	    }
-	  }
-	}
-	++bfs;
-      } //computing distances from s in the residual graph
-
-      bool __augment=true;
-
-      while (__augment) {
-	__augment=false;
-	//computing blocking flow with dfs
-	typedef typename TrivGraphWrapper<MutableGraph>::NodeMap<bool> BlockingReachedMap;
-	DfsIterator5< TrivGraphWrapper<MutableGraph>/*, typename MutableGraph::OutEdgeIt*/, BlockingReachedMap > dfs(F);
-	typename MutableGraph::NodeMap<typename MutableGraph::Edge> pred(F);
-	pred.set(sF, typename MutableGraph::Edge(INVALID));
-	//invalid iterators for sources
-
-	typename MutableGraph::NodeMap<Number> free(F);
-
-	dfs.pushAndSetReached(sF);      
-	while (!dfs.finished()) {
-	  ++dfs;
-	  if (F.valid(typename MutableGraph::OutEdgeIt(dfs))) {
-	    if (dfs.isBNodeNewlyReached()) {
-	      typename MutableGraph::Node v=F.aNode(dfs);
-	      typename MutableGraph::Node w=F.bNode(dfs);
-	      pred.set(w, dfs);
-	      if (F.valid(pred.get(v))) {
-		free.set(w, std::min(free.get(v), residual_capacity.get(dfs)));
-	      } else {
-		free.set(w, residual_capacity.get(dfs)); 
-	      }
-	      if (w==tF) { 
-		__augment=true; 
-		_augment=true;
-		break; 
-	      }
-	      
-	    } else {
-	      F.erase(typename MutableGraph::OutEdgeIt(dfs));
-	    }
-	  } 
-	}
-
-	if (__augment) {
-	  typename MutableGraph::Node n=tF;
-	  Number augment_value=free.get(tF);
-	  while (F.valid(pred.get(n))) { 
-	    typename MutableGraph::Edge e=pred.get(n);
-	    res_graph.augment(original_edge.get(e), augment_value); 
-	    n=F.tail(e);
-	    if (residual_capacity.get(e)==augment_value) 
-	      F.erase(e); 
-	    else 
-	      residual_capacity.set(e, residual_capacity.get(e)-augment_value);
-	  }
-	}
-	
-      }
-            
-      return _augment;
-    }
-    bool augmentOnBlockingFlow2() {
-      bool _augment=false;
-
-      //typedef ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> EAugGraph;
-      typedef FilterGraphWrapper< ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > EAugGraph;
-      typedef typename EAugGraph::OutEdgeIt EAugOutEdgeIt;
-      typedef typename EAugGraph::Edge EAugEdge;
-
-      EAugGraph res_graph(*G, *flow, *capacity);
-
-      //typedef typename EAugGraph::NodeMap<bool> ReachedMap;
-      BfsIterator5< 
-	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>, 
-	/*typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt,*/ 
-	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<bool> > bfs(res_graph);
-      
-      bfs.pushAndSetReached(s);
-
-      typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::
-	NodeMap<int>& dist=res_graph.dist;
-
-      while ( !bfs.finished() ) {
-	typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt e=bfs;
-	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
-	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
-	}
-	++bfs;	
-      } //computing distances from s in the residual graph
-
-      bool __augment=true;
-
-      while (__augment) {
-
-	__augment=false;
-	//computing blocking flow with dfs
-	typedef typename EAugGraph::NodeMap<bool> BlockingReachedMap;
-	DfsIterator5< EAugGraph/*, EAugOutEdgeIt*/, BlockingReachedMap > 
-	  dfs(res_graph);
-	typename EAugGraph::NodeMap<EAugEdge> pred(res_graph); 
-	pred.set(s, EAugEdge(INVALID));
-	//invalid iterators for sources
-
-	typename EAugGraph::NodeMap<Number> free(res_graph);
-
-	dfs.pushAndSetReached(s);
-	while (!dfs.finished()) {
-	  ++dfs;
-	  if (res_graph.valid(EAugOutEdgeIt(dfs))) { 
-	    if (dfs.isBNodeNewlyReached()) {
-	  
-	      typename EAugGraph::Node v=res_graph.aNode(dfs);
-	      typename EAugGraph::Node w=res_graph.bNode(dfs);
-
-	      pred.set(w, EAugOutEdgeIt(dfs));
-	      if (res_graph.valid(pred.get(v))) {
-		free.set(w, std::min(free.get(v), res_graph.free(dfs)));
-	      } else {
-		free.set(w, res_graph.free(dfs)); 
-	      }
-	      
-	      if (w==t) { 
-		__augment=true; 
-		_augment=true;
-		break; 
-	      }
-	    } else {
-	      res_graph.erase(dfs);
-	    }
-	  } 
-
-	}
-
-	if (__augment) {
-	  typename EAugGraph::Node n=t;
-	  Number augment_value=free.get(t);
-	  while (res_graph.valid(pred.get(n))) { 
-	    EAugEdge e=pred.get(n);
-	    res_graph.augment(e, augment_value);
-	    n=res_graph.tail(e);
-	    if (res_graph.free(e)==0)
-	      res_graph.erase(e);
-	  }
-	}
-      
-      }
-            
-      return _augment;
-    }
-    void run() {
-      //int num_of_augmentations=0;
-      while (augmentOnShortestPath()) { 
-	//while (augmentOnBlockingFlow<MutableGraph>()) { 
-	//std::cout << ++num_of_augmentations << " ";
-	//std::cout<<std::endl;
-      } 
-    }
-    template<typename MutableGraph> void run() {
-      //int num_of_augmentations=0;
-      //while (augmentOnShortestPath()) { 
-	while (augmentOnBlockingFlow<MutableGraph>()) { 
-	//std::cout << ++num_of_augmentations << " ";
-	//std::cout<<std::endl;
-      } 
-    }
-    Number flowValue() { 
-      Number a=0;
-      OutEdgeIt e;
-      for(G->/*getF*/first(e, s); G->valid(e); G->next(e)) {
-	a+=flow->get(e);
-      }
-      return a;
-    }
-  };
-
-
-  template <typename Graph, typename Number, typename FlowMap, typename CapacityMap>
-  class MaxMatching {
-  public:
-    typedef typename Graph::Node Node;
-    typedef typename Graph::NodeIt NodeIt;
-    typedef typename Graph::Edge Edge;
-    typedef typename Graph::EdgeIt EdgeIt;
-    typedef typename Graph::OutEdgeIt OutEdgeIt;
-    typedef typename Graph::InEdgeIt InEdgeIt;
-
-    typedef typename Graph::NodeMap<bool> SMap;
-    typedef typename Graph::NodeMap<bool> TMap;
-  private:
-    const Graph* G;
-    SMap* S;
-    TMap* T;
-    //Node s;
-    //Node t;
-    FlowMap* flow;
-    const CapacityMap* capacity;
-    typedef ResGraphWrapper<Graph, Number, FlowMap, CapacityMap > AugGraph;
-    typedef typename AugGraph::OutEdgeIt AugOutEdgeIt;
-    typedef typename AugGraph::Edge AugEdge;
-    typename Graph::NodeMap<int> used; //0
-
-  public:
-    MaxMatching(const Graph& _G, SMap& _S, TMap& _T, FlowMap& _flow, const CapacityMap& _capacity) : 
-      G(&_G), S(&_S), T(&_T), flow(&_flow), capacity(&_capacity), used(_G) { }
-    bool augmentOnShortestPath() {
-      AugGraph res_graph(*G, *flow, *capacity);
-      bool _augment=false;
-      
-      typedef typename AugGraph::NodeMap<bool> ReachedMap;
-      BfsIterator5< AugGraph, /*AugOutEdgeIt,*/ ReachedMap > res_bfs(res_graph);
-      typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
-      for(NodeIt s=G->template first<NodeIt>(); G->valid(s); G->next(s)) {
-	if ((S->get(s)) && (used.get(s)<1) ) {
-	  //Number u=0;
-	  //for(OutEdgeIt e=G->template first<OutEdgeIt>(s); G->valid(e); G->next(e))
-	  //u+=flow->get(e);
-	  //if (u<1) {
-	    res_bfs.pushAndSetReached(s);
-	    pred.set(s, AugEdge(INVALID));
-	    //}
-	}
-      }
-      
-      typename AugGraph::NodeMap<Number> free(res_graph);
-	
-      Node n;
-      //searching for augmenting path
-      while ( !res_bfs.finished() ) { 
-	AugOutEdgeIt e=res_bfs;
-	if (res_graph.valid(e) && res_bfs.isBNodeNewlyReached()) {
-	  Node v=res_graph.tail(e);
-	  Node w=res_graph.head(e);
-	  pred.set(w, e);
-	  if (res_graph.valid(pred.get(v))) {
-	    free.set(w, std::min(free.get(v), res_graph.free(e)));
-	  } else {
-	    free.set(w, res_graph.free(e)); 
-	  }
-	  n=res_graph.head(e);
-	  if (T->get(n) && (used.get(n)<1) ) { 
-	    //Number u=0;
-	    //for(InEdgeIt f=G->template first<InEdgeIt>(n); G->valid(f); G->next(f))
-	    //u+=flow->get(f);
-	    //if (u<1) {
-	      _augment=true; 
-	      break; 
-	      //}
-	  }
-	}
-	
-	++res_bfs;
-      } //end of searching augmenting path
-
-      if (_augment) {
-	//Node n=t;
-	used.set(n, 1); //mind2 vegen jav
-	Number augment_value=free.get(n);
-	while (res_graph.valid(pred.get(n))) { 
-	  AugEdge e=pred.get(n);
-	  res_graph.augment(e, augment_value); 
-	  n=res_graph.tail(e);
-	}
-	used.set(n, 1); //mind2 vegen jav
-      }
-
-      return _augment;
-    }
-
-//     template<typename MutableGraph> bool augmentOnBlockingFlow() {      
+//     template<typename MutableGraph> bool augmentOnBlockingFlow1() {      
 //       bool _augment=false;
 
 //       AugGraph res_graph(*G, *flow, *capacity);
 
+//       //bfs for distances on the residual graph
 //       typedef typename AugGraph::NodeMap<bool> ReachedMap;
-//       BfsIterator4< AugGraph, AugOutEdgeIt, ReachedMap > bfs(res_graph);
-
-
-
-
-
-//       //typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
-//       for(NodeIt s=G->template first<NodeIt>(); G->valid(s); G->next(s)) {
-// 	if (S->get(s)) {
-// 	  Number u=0;
-// 	  for(OutEdgeIt e=G->template first<OutEdgeIt>(s); G->valid(e); G->next(e))
-// 	    u+=flow->get(e);
-// 	  if (u<1) {
-// 	    res_bfs.pushAndSetReached(s);
-// 	    //pred.set(s, AugEdge(INVALID));
-// 	  }
-// 	}
-//       }
-
-
-
-
-//       //bfs.pushAndSetReached(s);
+//       BfsIterator5< AugGraph, ReachedMap > bfs(res_graph);
+//       bfs.pushAndSetReached(s);
 //       typename AugGraph::NodeMap<int> dist(res_graph); //filled up with 0's
-//       while ( !bfs.finished() ) { 
-// 	AugOutEdgeIt e=bfs;
-// 	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
-// 	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
-// 	}
-	
-// 	++bfs;
-//       } //computing distances from s in the residual graph
-
+
+//       //F will contain the physical copy of the residual graph
+//       //with the set of edges which areon shortest paths
 //       MutableGraph F;
 //       typename AugGraph::NodeMap<typename MutableGraph::Node> 
@@ -920,22 +452,31 @@
 // 	res_graph_to_F.set(n, F.addNode());
 //       }
-      
 //       typename MutableGraph::Node sF=res_graph_to_F.get(s);
 //       typename MutableGraph::Node tF=res_graph_to_F.get(t);
-
 //       typename MutableGraph::EdgeMap<AugEdge> original_edge(F);
 //       typename MutableGraph::EdgeMap<Number> residual_capacity(F);
 
-//       //Making F to the graph containing the edges of the residual graph 
-//       //which are in some shortest paths
-//       for(typename AugGraph::EdgeIt e=res_graph.template first<typename AugGraph::EdgeIt>(); res_graph.valid(e); res_graph.next(e)) {
-// 	if (dist.get(res_graph.head(e))==dist.get(res_graph.tail(e))+1) {
-// 	  typename MutableGraph::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
-// 	  original_edge.update();
-// 	  original_edge.set(f, e);
-// 	  residual_capacity.update();
-// 	  residual_capacity.set(f, res_graph.free(e));
-// 	} 
-//       }
+//       while ( !bfs.finished() ) { 
+// 	AugOutEdgeIt e=bfs;
+// 	if (res_graph.valid(e)) {
+// 	  if (bfs.isBNodeNewlyReached()) {
+// 	    dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
+// 	    typename MutableGraph::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
+// 	    original_edge.update();
+// 	    original_edge.set(f, e);
+// 	    residual_capacity.update();
+// 	    residual_capacity.set(f, res_graph.free(e));
+// 	  } else {
+// 	    if (dist.get(res_graph.head(e))==(dist.get(res_graph.tail(e))+1)) {
+// 	      typename MutableGraph::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
+// 	      original_edge.update();
+// 	      original_edge.set(f, e);
+// 	      residual_capacity.update();
+// 	      residual_capacity.set(f, res_graph.free(e));
+// 	    }
+// 	  }
+// 	}
+// 	++bfs;
+//       } //computing distances from s in the residual graph
 
 //       bool __augment=true;
@@ -944,6 +485,6 @@
 // 	__augment=false;
 // 	//computing blocking flow with dfs
-// 	typedef typename MutableGraph::NodeMap<bool> BlockingReachedMap;
-// 	DfsIterator4< MutableGraph, typename MutableGraph::OutEdgeIt, BlockingReachedMap > dfs(F);
+// 	typedef typename TrivGraphWrapper<MutableGraph>::NodeMap<bool> BlockingReachedMap;
+// 	DfsIterator5< TrivGraphWrapper<MutableGraph>/*, typename MutableGraph::OutEdgeIt*/, BlockingReachedMap > dfs(F);
 // 	typename MutableGraph::NodeMap<typename MutableGraph::Edge> pred(F);
 // 	pred.set(sF, typename MutableGraph::Edge(INVALID));
@@ -995,138 +536,100 @@
 //       return _augment;
 //     }
-    bool augmentOnBlockingFlow2() {
-      bool _augment=false;
-
-      //typedef ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> EAugGraph;
-      typedef FilterGraphWrapper< ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > EAugGraph;
-      typedef typename EAugGraph::OutEdgeIt EAugOutEdgeIt;
-      typedef typename EAugGraph::Edge EAugEdge;
-
-      EAugGraph res_graph(*G, *flow, *capacity);
-
-      //typedef typename EAugGraph::NodeMap<bool> ReachedMap;
-      BfsIterator5< 
-	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>, 
-	/*typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt,*/ 
-	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<bool> > bfs(res_graph);
-
-
-      //typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
-      for(NodeIt s=G->template first<NodeIt>(); G->valid(s); G->next(s)) {
-	if (S->get(s)) {
-	  Number u=0;
-	  for(OutEdgeIt e=G->template first<OutEdgeIt>(s); G->valid(e); G->next(e))
-	    u+=flow->get(e);
-	  if (u<1) {
-	    bfs.pushAndSetReached(s);
-	    //pred.set(s, AugEdge(INVALID));
-	  }
-	}
-      }
-
+//     bool augmentOnBlockingFlow2() {
+//       bool _augment=false;
+
+//       //typedef ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> EAugGraph;
+//       typedef FilterGraphWrapper< ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > EAugGraph;
+//       typedef typename EAugGraph::OutEdgeIt EAugOutEdgeIt;
+//       typedef typename EAugGraph::Edge EAugEdge;
+
+//       EAugGraph res_graph(*G, *flow, *capacity);
+
+//       //typedef typename EAugGraph::NodeMap<bool> ReachedMap;
+//       BfsIterator5< 
+// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>, 
+// 	/*typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt,*/ 
+// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<bool> > bfs(res_graph);
       
-      //bfs.pushAndSetReached(s);
-
-      typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::
-	NodeMap<int>& dist=res_graph.dist;
-
-      while ( !bfs.finished() ) {
-	typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt e=bfs;
-	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
-	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
-	}
-	++bfs;	
-      } //computing distances from s in the residual graph
-
-      bool __augment=true;
-
-      while (__augment) {
-
-	__augment=false;
-	//computing blocking flow with dfs
-	typedef typename EAugGraph::NodeMap<bool> BlockingReachedMap;
-	DfsIterator5< EAugGraph/*, EAugOutEdgeIt*/, BlockingReachedMap > 
-	  dfs(res_graph);
-	typename EAugGraph::NodeMap<EAugEdge> pred(res_graph, INVALID); 
-	//pred.set(s, EAugEdge(INVALID));
-	//invalid iterators for sources
-
-	typename EAugGraph::NodeMap<Number> free(res_graph);
-
-
-	//typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
-      for(NodeIt s=G->template first<NodeIt>(); G->valid(s); G->next(s)) {
-	if (S->get(s)) {
-	  Number u=0;
-	  for(OutEdgeIt e=G->template first<OutEdgeIt>(s); G->valid(e); G->next(e))
-	    u+=flow->get(e);
-	  if (u<1) {
-	    dfs.pushAndSetReached(s);
-	    //pred.set(s, AugEdge(INVALID));
-	  }
-	}
-      }
-
-
-
-      //dfs.pushAndSetReached(s);
-      typename EAugGraph::Node n;
-	while (!dfs.finished()) {
-	  ++dfs;
-	  if (res_graph.valid(EAugOutEdgeIt(dfs))) { 
-	    if (dfs.isBNodeNewlyReached()) {
+//       bfs.pushAndSetReached(s);
+
+//       typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::
+// 	NodeMap<int>& dist=res_graph.dist;
+
+//       while ( !bfs.finished() ) {
+// 	typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt e=bfs;
+// 	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
+// 	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
+// 	}
+// 	++bfs;	
+//       } //computing distances from s in the residual graph
+
+//       bool __augment=true;
+
+//       while (__augment) {
+
+// 	__augment=false;
+// 	//computing blocking flow with dfs
+// 	typedef typename EAugGraph::NodeMap<bool> BlockingReachedMap;
+// 	DfsIterator5< EAugGraph/*, EAugOutEdgeIt*/, BlockingReachedMap > 
+// 	  dfs(res_graph);
+// 	typename EAugGraph::NodeMap<EAugEdge> pred(res_graph); 
+// 	pred.set(s, EAugEdge(INVALID));
+// 	//invalid iterators for sources
+
+// 	typename EAugGraph::NodeMap<Number> free(res_graph);
+
+// 	dfs.pushAndSetReached(s);
+// 	while (!dfs.finished()) {
+// 	  ++dfs;
+// 	  if (res_graph.valid(EAugOutEdgeIt(dfs))) { 
+// 	    if (dfs.isBNodeNewlyReached()) {
 	  
-	      typename EAugGraph::Node v=res_graph.aNode(dfs);
-	      typename EAugGraph::Node w=res_graph.bNode(dfs);
-
-	      pred.set(w, EAugOutEdgeIt(dfs));
-	      if (res_graph.valid(pred.get(v))) {
-		free.set(w, std::min(free.get(v), res_graph.free(dfs)));
-	      } else {
-		free.set(w, res_graph.free(dfs)); 
-	      }
-	     
-	      n=w;
-	      if (T->get(w)) {
-		Number u=0;
-		for(InEdgeIt f=G->template first<InEdgeIt>(n); G->valid(f); G->next(f))
-		  u+=flow->get(f);
-		if (u<1) {
-		  __augment=true; 
-		  _augment=true;
-		  break; 
-		}
-	      }
-	    } else {
-	      res_graph.erase(dfs);
-	    }
-	  } 
-
-	}
-
-	if (__augment) {
-	  // typename EAugGraph::Node n=t;
-	  Number augment_value=free.get(n);
-	  while (res_graph.valid(pred.get(n))) { 
-	    EAugEdge e=pred.get(n);
-	    res_graph.augment(e, augment_value);
-	    n=res_graph.tail(e);
-	    if (res_graph.free(e)==0)
-	      res_graph.erase(e);
-	  }
-	}
+// 	      typename EAugGraph::Node v=res_graph.aNode(dfs);
+// 	      typename EAugGraph::Node w=res_graph.bNode(dfs);
+
+// 	      pred.set(w, EAugOutEdgeIt(dfs));
+// 	      if (res_graph.valid(pred.get(v))) {
+// 		free.set(w, std::min(free.get(v), res_graph.free(dfs)));
+// 	      } else {
+// 		free.set(w, res_graph.free(dfs)); 
+// 	      }
+	      
+// 	      if (w==t) { 
+// 		__augment=true; 
+// 		_augment=true;
+// 		break; 
+// 	      }
+// 	    } else {
+// 	      res_graph.erase(dfs);
+// 	    }
+// 	  } 
+
+// 	}
+
+// 	if (__augment) {
+// 	  typename EAugGraph::Node n=t;
+// 	  Number augment_value=free.get(t);
+// 	  while (res_graph.valid(pred.get(n))) { 
+// 	    EAugEdge e=pred.get(n);
+// 	    res_graph.augment(e, augment_value);
+// 	    n=res_graph.tail(e);
+// 	    if (res_graph.free(e)==0)
+// 	      res_graph.erase(e);
+// 	  }
+// 	}
       
-      }
+//       }
             
-      return _augment;
-    }
-    void run() {
-      //int num_of_augmentations=0;
-      while (augmentOnShortestPath()) { 
-	//while (augmentOnBlockingFlow<MutableGraph>()) { 
-	//std::cout << ++num_of_augmentations << " ";
-	//std::cout<<std::endl;
-      } 
-    }
+//       return _augment;
+//     }
+//     void run() {
+//       //int num_of_augmentations=0;
+//       while (augmentOnShortestPath()) { 
+// 	//while (augmentOnBlockingFlow<MutableGraph>()) { 
+// 	//std::cout << ++num_of_augmentations << " ";
+// 	//std::cout<<std::endl;
+//       } 
+//     }
 //     template<typename MutableGraph> void run() {
 //       //int num_of_augmentations=0;
@@ -1136,9 +639,9 @@
 // 	//std::cout<<std::endl;
 //       } 
-//     } 
+//     }
     Number flowValue() { 
       Number a=0;
-      EdgeIt e;
-      for(G->/*getF*/first(e); G->valid(e); G->next(e)) {
+      OutEdgeIt e;
+      for(gw.first(e, s); gw.valid(e); gw.next(e)) {
 	a+=flow->get(e);
       }
@@ -1148,72 +651,75 @@
 
 
-
-
-
-  
 //   template <typename Graph, typename Number, typename FlowMap, typename CapacityMap>
-//   class MaxFlow2 {
+//   class MaxMatching {
 //   public:
 //     typedef typename Graph::Node Node;
+//     typedef typename Graph::NodeIt NodeIt;
 //     typedef typename Graph::Edge Edge;
 //     typedef typename Graph::EdgeIt EdgeIt;
 //     typedef typename Graph::OutEdgeIt OutEdgeIt;
 //     typedef typename Graph::InEdgeIt InEdgeIt;
+
+//     typedef typename Graph::NodeMap<bool> SMap;
+//     typedef typename Graph::NodeMap<bool> TMap;
 //   private:
-//     const Graph& G;
-//     std::list<Node>& S;
-//     std::list<Node>& T;
-//     FlowMap& flow;
-//     const CapacityMap& capacity;
+//     const Graph* G;
+//     SMap* S;
+//     TMap* T;
+//     //Node s;
+//     //Node t;
+//     FlowMap* flow;
+//     const CapacityMap* capacity;
 //     typedef ResGraphWrapper<Graph, Number, FlowMap, CapacityMap > AugGraph;
 //     typedef typename AugGraph::OutEdgeIt AugOutEdgeIt;
 //     typedef typename AugGraph::Edge AugEdge;
-//     typename Graph::NodeMap<bool> SMap;
-//     typename Graph::NodeMap<bool> TMap;
+//     typename Graph::NodeMap<int> used; //0
+
 //   public:
-//     MaxFlow2(const Graph& _G, std::list<Node>& _S, std::list<Node>& _T, FlowMap& _flow, const CapacityMap& _capacity) : G(_G), S(_S), T(_T), flow(_flow), capacity(_capacity), SMap(_G), TMap(_G) { 
-//       for(typename std::list<Node>::const_iterator i=S.begin(); 
-// 	  i!=S.end(); ++i) { 
-// 	SMap.set(*i, true); 
-//       }
-//       for (typename std::list<Node>::const_iterator i=T.begin(); 
-// 	   i!=T.end(); ++i) { 
-// 	TMap.set(*i, true); 
-//       }
-//     }
-//     bool augment() {
-//       AugGraph res_graph(G, flow, capacity);
+//     MaxMatching(const Graph& _G, SMap& _S, TMap& _T, FlowMap& _flow, const CapacityMap& _capacity) : 
+//       G(&_G), S(&_S), T(&_T), flow(&_flow), capacity(&_capacity), used(_G) { }
+//     bool augmentOnShortestPath() {
+//       AugGraph res_graph(*G, *flow, *capacity);
 //       bool _augment=false;
-//       Node reached_t_node;
       
 //       typedef typename AugGraph::NodeMap<bool> ReachedMap;
-//       BfsIterator4< AugGraph, AugOutEdgeIt, ReachedMap > res_bfs(res_graph);
-//       for(typename std::list<Node>::const_iterator i=S.begin(); 
-// 	  i!=S.end(); ++i) {
-// 	res_bfs.pushAndSetReached(*i);
+//       BfsIterator5< AugGraph, /*AugOutEdgeIt,*/ ReachedMap > res_bfs(res_graph);
+//       typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
+//       for(NodeIt s=G->template first<NodeIt>(); G->valid(s); G->next(s)) {
+// 	if ((S->get(s)) && (used.get(s)<1) ) {
+// 	  //Number u=0;
+// 	  //for(OutEdgeIt e=G->template first<OutEdgeIt>(s); G->valid(e); G->next(e))
+// 	  //u+=flow->get(e);
+// 	  //if (u<1) {
+// 	    res_bfs.pushAndSetReached(s);
+// 	    pred.set(s, AugEdge(INVALID));
+// 	    //}
+// 	}
 //       }
-//       //res_bfs.pushAndSetReached(s);
-	
-//       typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
-//       //filled up with invalid iterators
       
 //       typename AugGraph::NodeMap<Number> free(res_graph);
 	
+//       Node n;
 //       //searching for augmenting path
 //       while ( !res_bfs.finished() ) { 
-// 	AugOutEdgeIt e=/*AugOutEdgeIt*/(res_bfs);
-// 	if (e.valid() && res_bfs.isBNodeNewlyReached()) {
+// 	AugOutEdgeIt e=res_bfs;
+// 	if (res_graph.valid(e) && res_bfs.isBNodeNewlyReached()) {
 // 	  Node v=res_graph.tail(e);
 // 	  Node w=res_graph.head(e);
 // 	  pred.set(w, e);
-// 	  if (pred.get(v).valid()) {
-// 	    free.set(w, std::min(free.get(v), e.free()));
+// 	  if (res_graph.valid(pred.get(v))) {
+// 	    free.set(w, std::min(free.get(v), res_graph.free(e)));
 // 	  } else {
-// 	    free.set(w, e.free()); 
+// 	    free.set(w, res_graph.free(e)); 
 // 	  }
-// 	  if (TMap.get(res_graph.head(e))) { 
-// 	    _augment=true; 
-// 	    reached_t_node=res_graph.head(e);
-// 	    break; 
+// 	  n=res_graph.head(e);
+// 	  if (T->get(n) && (used.get(n)<1) ) { 
+// 	    //Number u=0;
+// 	    //for(InEdgeIt f=G->template first<InEdgeIt>(n); G->valid(f); G->next(f))
+// 	    //u+=flow->get(f);
+// 	    //if (u<1) {
+// 	      _augment=true; 
+// 	      break; 
+// 	      //}
 // 	  }
 // 	}
@@ -1223,28 +729,285 @@
 
 //       if (_augment) {
-// 	Node n=reached_t_node;
-// 	Number augment_value=free.get(reached_t_node);
-// 	while (pred.get(n).valid()) { 
+// 	//Node n=t;
+// 	used.set(n, 1); //mind2 vegen jav
+// 	Number augment_value=free.get(n);
+// 	while (res_graph.valid(pred.get(n))) { 
 // 	  AugEdge e=pred.get(n);
-// 	  e.augment(augment_value); 
+// 	  res_graph.augment(e, augment_value); 
 // 	  n=res_graph.tail(e);
 // 	}
+// 	used.set(n, 1); //mind2 vegen jav
 //       }
 
+//       return _augment;
+//     }
+
+// //     template<typename MutableGraph> bool augmentOnBlockingFlow() {      
+// //       bool _augment=false;
+
+// //       AugGraph res_graph(*G, *flow, *capacity);
+
+// //       typedef typename AugGraph::NodeMap<bool> ReachedMap;
+// //       BfsIterator4< AugGraph, AugOutEdgeIt, ReachedMap > bfs(res_graph);
+
+
+
+
+
+// //       //typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
+// //       for(NodeIt s=G->template first<NodeIt>(); G->valid(s); G->next(s)) {
+// // 	if (S->get(s)) {
+// // 	  Number u=0;
+// // 	  for(OutEdgeIt e=G->template first<OutEdgeIt>(s); G->valid(e); G->next(e))
+// // 	    u+=flow->get(e);
+// // 	  if (u<1) {
+// // 	    res_bfs.pushAndSetReached(s);
+// // 	    //pred.set(s, AugEdge(INVALID));
+// // 	  }
+// // 	}
+// //       }
+
+
+
+
+// //       //bfs.pushAndSetReached(s);
+// //       typename AugGraph::NodeMap<int> dist(res_graph); //filled up with 0's
+// //       while ( !bfs.finished() ) { 
+// // 	AugOutEdgeIt e=bfs;
+// // 	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
+// // 	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
+// // 	}
+	
+// // 	++bfs;
+// //       } //computing distances from s in the residual graph
+
+// //       MutableGraph F;
+// //       typename AugGraph::NodeMap<typename MutableGraph::Node> 
+// // 	res_graph_to_F(res_graph);
+// //       for(typename AugGraph::NodeIt n=res_graph.template first<typename AugGraph::NodeIt>(); res_graph.valid(n); res_graph.next(n)) {
+// // 	res_graph_to_F.set(n, F.addNode());
+// //       }
+      
+// //       typename MutableGraph::Node sF=res_graph_to_F.get(s);
+// //       typename MutableGraph::Node tF=res_graph_to_F.get(t);
+
+// //       typename MutableGraph::EdgeMap<AugEdge> original_edge(F);
+// //       typename MutableGraph::EdgeMap<Number> residual_capacity(F);
+
+// //       //Making F to the graph containing the edges of the residual graph 
+// //       //which are in some shortest paths
+// //       for(typename AugGraph::EdgeIt e=res_graph.template first<typename AugGraph::EdgeIt>(); res_graph.valid(e); res_graph.next(e)) {
+// // 	if (dist.get(res_graph.head(e))==dist.get(res_graph.tail(e))+1) {
+// // 	  typename MutableGraph::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
+// // 	  original_edge.update();
+// // 	  original_edge.set(f, e);
+// // 	  residual_capacity.update();
+// // 	  residual_capacity.set(f, res_graph.free(e));
+// // 	} 
+// //       }
+
+// //       bool __augment=true;
+
+// //       while (__augment) {
+// // 	__augment=false;
+// // 	//computing blocking flow with dfs
+// // 	typedef typename MutableGraph::NodeMap<bool> BlockingReachedMap;
+// // 	DfsIterator4< MutableGraph, typename MutableGraph::OutEdgeIt, BlockingReachedMap > dfs(F);
+// // 	typename MutableGraph::NodeMap<typename MutableGraph::Edge> pred(F);
+// // 	pred.set(sF, typename MutableGraph::Edge(INVALID));
+// // 	//invalid iterators for sources
+
+// // 	typename MutableGraph::NodeMap<Number> free(F);
+
+// // 	dfs.pushAndSetReached(sF);      
+// // 	while (!dfs.finished()) {
+// // 	  ++dfs;
+// // 	  if (F.valid(typename MutableGraph::OutEdgeIt(dfs))) {
+// // 	    if (dfs.isBNodeNewlyReached()) {
+// // 	      typename MutableGraph::Node v=F.aNode(dfs);
+// // 	      typename MutableGraph::Node w=F.bNode(dfs);
+// // 	      pred.set(w, dfs);
+// // 	      if (F.valid(pred.get(v))) {
+// // 		free.set(w, std::min(free.get(v), residual_capacity.get(dfs)));
+// // 	      } else {
+// // 		free.set(w, residual_capacity.get(dfs)); 
+// // 	      }
+// // 	      if (w==tF) { 
+// // 		__augment=true; 
+// // 		_augment=true;
+// // 		break; 
+// // 	      }
+	      
+// // 	    } else {
+// // 	      F.erase(typename MutableGraph::OutEdgeIt(dfs));
+// // 	    }
+// // 	  } 
+// // 	}
+
+// // 	if (__augment) {
+// // 	  typename MutableGraph::Node n=tF;
+// // 	  Number augment_value=free.get(tF);
+// // 	  while (F.valid(pred.get(n))) { 
+// // 	    typename MutableGraph::Edge e=pred.get(n);
+// // 	    res_graph.augment(original_edge.get(e), augment_value); 
+// // 	    n=F.tail(e);
+// // 	    if (residual_capacity.get(e)==augment_value) 
+// // 	      F.erase(e); 
+// // 	    else 
+// // 	      residual_capacity.set(e, residual_capacity.get(e)-augment_value);
+// // 	  }
+// // 	}
+	
+// //       }
+            
+// //       return _augment;
+// //     }
+//     bool augmentOnBlockingFlow2() {
+//       bool _augment=false;
+
+//       //typedef ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> EAugGraph;
+//       typedef FilterGraphWrapper< ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > EAugGraph;
+//       typedef typename EAugGraph::OutEdgeIt EAugOutEdgeIt;
+//       typedef typename EAugGraph::Edge EAugEdge;
+
+//       EAugGraph res_graph(*G, *flow, *capacity);
+
+//       //typedef typename EAugGraph::NodeMap<bool> ReachedMap;
+//       BfsIterator5< 
+// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>, 
+// 	/*typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt,*/ 
+// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<bool> > bfs(res_graph);
+
+
+//       //typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
+//       for(NodeIt s=G->template first<NodeIt>(); G->valid(s); G->next(s)) {
+// 	if (S->get(s)) {
+// 	  Number u=0;
+// 	  for(OutEdgeIt e=G->template first<OutEdgeIt>(s); G->valid(e); G->next(e))
+// 	    u+=flow->get(e);
+// 	  if (u<1) {
+// 	    bfs.pushAndSetReached(s);
+// 	    //pred.set(s, AugEdge(INVALID));
+// 	  }
+// 	}
+//       }
+
+      
+//       //bfs.pushAndSetReached(s);
+
+//       typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::
+// 	NodeMap<int>& dist=res_graph.dist;
+
+//       while ( !bfs.finished() ) {
+// 	typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt e=bfs;
+// 	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
+// 	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
+// 	}
+// 	++bfs;	
+//       } //computing distances from s in the residual graph
+
+//       bool __augment=true;
+
+//       while (__augment) {
+
+// 	__augment=false;
+// 	//computing blocking flow with dfs
+// 	typedef typename EAugGraph::NodeMap<bool> BlockingReachedMap;
+// 	DfsIterator5< EAugGraph/*, EAugOutEdgeIt*/, BlockingReachedMap > 
+// 	  dfs(res_graph);
+// 	typename EAugGraph::NodeMap<EAugEdge> pred(res_graph, INVALID); 
+// 	//pred.set(s, EAugEdge(INVALID));
+// 	//invalid iterators for sources
+
+// 	typename EAugGraph::NodeMap<Number> free(res_graph);
+
+
+// 	//typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
+//       for(NodeIt s=G->template first<NodeIt>(); G->valid(s); G->next(s)) {
+// 	if (S->get(s)) {
+// 	  Number u=0;
+// 	  for(OutEdgeIt e=G->template first<OutEdgeIt>(s); G->valid(e); G->next(e))
+// 	    u+=flow->get(e);
+// 	  if (u<1) {
+// 	    dfs.pushAndSetReached(s);
+// 	    //pred.set(s, AugEdge(INVALID));
+// 	  }
+// 	}
+//       }
+
+
+
+//       //dfs.pushAndSetReached(s);
+//       typename EAugGraph::Node n;
+// 	while (!dfs.finished()) {
+// 	  ++dfs;
+// 	  if (res_graph.valid(EAugOutEdgeIt(dfs))) { 
+// 	    if (dfs.isBNodeNewlyReached()) {
+	  
+// 	      typename EAugGraph::Node v=res_graph.aNode(dfs);
+// 	      typename EAugGraph::Node w=res_graph.bNode(dfs);
+
+// 	      pred.set(w, EAugOutEdgeIt(dfs));
+// 	      if (res_graph.valid(pred.get(v))) {
+// 		free.set(w, std::min(free.get(v), res_graph.free(dfs)));
+// 	      } else {
+// 		free.set(w, res_graph.free(dfs)); 
+// 	      }
+	     
+// 	      n=w;
+// 	      if (T->get(w)) {
+// 		Number u=0;
+// 		for(InEdgeIt f=G->template first<InEdgeIt>(n); G->valid(f); G->next(f))
+// 		  u+=flow->get(f);
+// 		if (u<1) {
+// 		  __augment=true; 
+// 		  _augment=true;
+// 		  break; 
+// 		}
+// 	      }
+// 	    } else {
+// 	      res_graph.erase(dfs);
+// 	    }
+// 	  } 
+
+// 	}
+
+// 	if (__augment) {
+// 	  // typename EAugGraph::Node n=t;
+// 	  Number augment_value=free.get(n);
+// 	  while (res_graph.valid(pred.get(n))) { 
+// 	    EAugEdge e=pred.get(n);
+// 	    res_graph.augment(e, augment_value);
+// 	    n=res_graph.tail(e);
+// 	    if (res_graph.free(e)==0)
+// 	      res_graph.erase(e);
+// 	  }
+// 	}
+      
+//       }
+            
 //       return _augment;
 //     }
 //     void run() {
-//       while (augment()) { } 
+//       //int num_of_augmentations=0;
+//       while (augmentOnShortestPath()) { 
+// 	//while (augmentOnBlockingFlow<MutableGraph>()) { 
+// 	//std::cout << ++num_of_augmentations << " ";
+// 	//std::cout<<std::endl;
+//       } 
 //     }
+// //     template<typename MutableGraph> void run() {
+// //       //int num_of_augmentations=0;
+// //       //while (augmentOnShortestPath()) { 
+// // 	while (augmentOnBlockingFlow<MutableGraph>()) { 
+// // 	//std::cout << ++num_of_augmentations << " ";
+// // 	//std::cout<<std::endl;
+// //       } 
+// //     } 
 //     Number flowValue() { 
 //       Number a=0;
-//       for(typename std::list<Node>::const_iterator i=S.begin(); 
-// 	  i!=S.end(); ++i) { 
-// 	for(OutEdgeIt e=G.template first<OutEdgeIt>(*i); e.valid(); ++e) {
-// 	  a+=flow.get(e);
-// 	}
-// 	for(InEdgeIt e=G.template first<InEdgeIt>(*i); e.valid(); ++e) {
-// 	  a-=flow.get(e);
-// 	}
+//       EdgeIt e;
+//       for(G->/*getF*/first(e); G->valid(e); G->next(e)) {
+// 	a+=flow->get(e);
 //       }
 //       return a;
@@ -1254,4 +1017,108 @@
 
 
+
+
+  
+// //   template <typename Graph, typename Number, typename FlowMap, typename CapacityMap>
+// //   class MaxFlow2 {
+// //   public:
+// //     typedef typename Graph::Node Node;
+// //     typedef typename Graph::Edge Edge;
+// //     typedef typename Graph::EdgeIt EdgeIt;
+// //     typedef typename Graph::OutEdgeIt OutEdgeIt;
+// //     typedef typename Graph::InEdgeIt InEdgeIt;
+// //   private:
+// //     const Graph& G;
+// //     std::list<Node>& S;
+// //     std::list<Node>& T;
+// //     FlowMap& flow;
+// //     const CapacityMap& capacity;
+// //     typedef ResGraphWrapper<Graph, Number, FlowMap, CapacityMap > AugGraph;
+// //     typedef typename AugGraph::OutEdgeIt AugOutEdgeIt;
+// //     typedef typename AugGraph::Edge AugEdge;
+// //     typename Graph::NodeMap<bool> SMap;
+// //     typename Graph::NodeMap<bool> TMap;
+// //   public:
+// //     MaxFlow2(const Graph& _G, std::list<Node>& _S, std::list<Node>& _T, FlowMap& _flow, const CapacityMap& _capacity) : G(_G), S(_S), T(_T), flow(_flow), capacity(_capacity), SMap(_G), TMap(_G) { 
+// //       for(typename std::list<Node>::const_iterator i=S.begin(); 
+// // 	  i!=S.end(); ++i) { 
+// // 	SMap.set(*i, true); 
+// //       }
+// //       for (typename std::list<Node>::const_iterator i=T.begin(); 
+// // 	   i!=T.end(); ++i) { 
+// // 	TMap.set(*i, true); 
+// //       }
+// //     }
+// //     bool augment() {
+// //       AugGraph res_graph(G, flow, capacity);
+// //       bool _augment=false;
+// //       Node reached_t_node;
+      
+// //       typedef typename AugGraph::NodeMap<bool> ReachedMap;
+// //       BfsIterator4< AugGraph, AugOutEdgeIt, ReachedMap > res_bfs(res_graph);
+// //       for(typename std::list<Node>::const_iterator i=S.begin(); 
+// // 	  i!=S.end(); ++i) {
+// // 	res_bfs.pushAndSetReached(*i);
+// //       }
+// //       //res_bfs.pushAndSetReached(s);
+	
+// //       typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
+// //       //filled up with invalid iterators
+      
+// //       typename AugGraph::NodeMap<Number> free(res_graph);
+	
+// //       //searching for augmenting path
+// //       while ( !res_bfs.finished() ) { 
+// // 	AugOutEdgeIt e=/*AugOutEdgeIt*/(res_bfs);
+// // 	if (e.valid() && res_bfs.isBNodeNewlyReached()) {
+// // 	  Node v=res_graph.tail(e);
+// // 	  Node w=res_graph.head(e);
+// // 	  pred.set(w, e);
+// // 	  if (pred.get(v).valid()) {
+// // 	    free.set(w, std::min(free.get(v), e.free()));
+// // 	  } else {
+// // 	    free.set(w, e.free()); 
+// // 	  }
+// // 	  if (TMap.get(res_graph.head(e))) { 
+// // 	    _augment=true; 
+// // 	    reached_t_node=res_graph.head(e);
+// // 	    break; 
+// // 	  }
+// // 	}
+	
+// // 	++res_bfs;
+// //       } //end of searching augmenting path
+
+// //       if (_augment) {
+// // 	Node n=reached_t_node;
+// // 	Number augment_value=free.get(reached_t_node);
+// // 	while (pred.get(n).valid()) { 
+// // 	  AugEdge e=pred.get(n);
+// // 	  e.augment(augment_value); 
+// // 	  n=res_graph.tail(e);
+// // 	}
+// //       }
+
+// //       return _augment;
+// //     }
+// //     void run() {
+// //       while (augment()) { } 
+// //     }
+// //     Number flowValue() { 
+// //       Number a=0;
+// //       for(typename std::list<Node>::const_iterator i=S.begin(); 
+// // 	  i!=S.end(); ++i) { 
+// // 	for(OutEdgeIt e=G.template first<OutEdgeIt>(*i); e.valid(); ++e) {
+// // 	  a+=flow.get(e);
+// // 	}
+// // 	for(InEdgeIt e=G.template first<InEdgeIt>(*i); e.valid(); ++e) {
+// // 	  a-=flow.get(e);
+// // 	}
+// //       }
+// //       return a;
+// //     }
+// //   };
+
+
 } // namespace hugo
 
