marci@174: // -*- c++ -*- marci@259: #ifndef HUGO_EDMONDS_KARP_H marci@259: #define HUGO_EDMONDS_KARP_H marci@174: marci@174: #include marci@174: #include marci@174: #include marci@174: marci@174: #include marci@174: #include marci@174: marci@174: namespace hugo { marci@174: marci@174: template marci@174: class ResGraph { marci@174: public: marci@174: typedef typename Graph::Node Node; marci@174: typedef typename Graph::NodeIt NodeIt; marci@174: private: marci@174: typedef typename Graph::SymEdgeIt OldSymEdgeIt; marci@174: const Graph& G; marci@174: FlowMap& flow; marci@174: const CapacityMap& capacity; marci@174: public: marci@174: ResGraph(const Graph& _G, FlowMap& _flow, marci@174: const CapacityMap& _capacity) : marci@174: G(_G), flow(_flow), capacity(_capacity) { } marci@174: marci@174: class Edge; marci@174: class OutEdgeIt; marci@174: friend class Edge; marci@174: friend class OutEdgeIt; marci@174: marci@174: class Edge { marci@174: friend class ResGraph; marci@174: protected: marci@174: const ResGraph* resG; marci@174: OldSymEdgeIt sym; marci@174: public: marci@174: Edge() { } marci@174: //Edge(const Edge& e) : resG(e.resG), sym(e.sym) { } marci@174: Number free() const { marci@174: if (resG->G.aNode(sym)==resG->G.tail(sym)) { marci@174: return (resG->capacity.get(sym)-resG->flow.get(sym)); marci@174: } else { marci@174: return (resG->flow.get(sym)); marci@174: } marci@174: } marci@174: bool valid() const { return sym.valid(); } marci@174: void augment(Number a) const { marci@174: if (resG->G.aNode(sym)==resG->G.tail(sym)) { marci@174: resG->flow.set(sym, resG->flow.get(sym)+a); marci@174: //resG->flow[sym]+=a; marci@174: } else { marci@174: resG->flow.set(sym, resG->flow.get(sym)-a); marci@174: //resG->flow[sym]-=a; marci@174: } marci@174: } marci@174: }; marci@174: marci@174: class OutEdgeIt : public Edge { marci@174: friend class ResGraph; marci@174: public: marci@174: OutEdgeIt() { } marci@174: //OutEdgeIt(const OutEdgeIt& e) { resG=e.resG; sym=e.sym; } marci@174: private: marci@174: OutEdgeIt(const ResGraph& _resG, Node v) { marci@174: resG=&_resG; marci@174: sym=resG->G.template first(v); marci@174: while( sym.valid() && !(free()>0) ) { ++sym; } marci@174: } marci@174: public: marci@174: OutEdgeIt& operator++() { marci@174: ++sym; marci@174: while( sym.valid() && !(free()>0) ) { ++sym; } marci@174: return *this; marci@174: } marci@174: }; marci@174: marci@174: void /*getF*/first(OutEdgeIt& e, Node v) const { marci@174: e=OutEdgeIt(*this, v); marci@174: } marci@174: void /*getF*/first(NodeIt& v) const { G./*getF*/first(v); } marci@174: marci@174: template< typename It > marci@174: It first() const { marci@174: It e; marci@174: /*getF*/first(e); marci@174: return e; marci@174: } marci@174: marci@174: template< typename It > marci@174: It first(Node v) const { marci@174: It e; marci@174: /*getF*/first(e, v); marci@174: return e; marci@174: } marci@174: marci@174: Node tail(Edge e) const { return G.aNode(e.sym); } marci@174: Node head(Edge e) const { return G.bNode(e.sym); } marci@174: marci@174: Node aNode(OutEdgeIt e) const { return G.aNode(e.sym); } marci@174: Node bNode(OutEdgeIt e) const { return G.bNode(e.sym); } marci@174: marci@174: int id(Node v) const { return G.id(v); } marci@174: marci@174: template marci@174: class NodeMap { marci@174: typename Graph::NodeMap node_map; marci@174: public: marci@174: NodeMap(const ResGraph& _G) : node_map(_G.G) { } marci@174: NodeMap(const ResGraph& _G, S a) : node_map(_G.G, a) { } marci@174: void set(Node nit, S a) { node_map.set(nit, a); } marci@174: S get(Node nit) const { return node_map.get(nit); } marci@174: S& operator[](Node nit) { return node_map[nit]; } marci@174: const S& operator[](Node nit) const { return node_map[nit]; } marci@174: }; marci@174: marci@174: }; marci@174: marci@174: marci@174: template marci@174: class ResGraph2 { marci@174: public: marci@174: typedef typename Graph::Node Node; marci@174: typedef typename Graph::NodeIt NodeIt; marci@174: private: marci@174: //typedef typename Graph::SymEdgeIt OldSymEdgeIt; marci@174: typedef typename Graph::OutEdgeIt OldOutEdgeIt; marci@174: typedef typename Graph::InEdgeIt OldInEdgeIt; marci@174: marci@174: const Graph& G; marci@174: FlowMap& flow; marci@174: const CapacityMap& capacity; marci@174: public: marci@174: ResGraph2(const Graph& _G, FlowMap& _flow, marci@174: const CapacityMap& _capacity) : marci@174: G(_G), flow(_flow), capacity(_capacity) { } marci@174: marci@174: class Edge; marci@174: class OutEdgeIt; marci@174: friend class Edge; marci@174: friend class OutEdgeIt; marci@174: marci@174: class Edge { marci@174: friend class ResGraph2; marci@174: protected: marci@174: const ResGraph2* resG; marci@174: //OldSymEdgeIt sym; marci@174: OldOutEdgeIt out; marci@174: OldInEdgeIt in; marci@174: bool out_or_in; //true, iff out marci@174: public: marci@174: Edge() : out_or_in(true) { } marci@174: Number free() const { marci@174: if (out_or_in) { marci@174: return (resG->capacity.get(out)-resG->flow.get(out)); marci@174: } else { marci@174: return (resG->flow.get(in)); marci@174: } marci@174: } marci@174: bool valid() const { marci@174: return out_or_in && out.valid() || in.valid(); } marci@174: void augment(Number a) const { marci@174: if (out_or_in) { marci@174: resG->flow.set(out, resG->flow.get(out)+a); marci@174: } else { marci@174: resG->flow.set(in, resG->flow.get(in)-a); marci@174: } marci@174: } marci@174: }; marci@174: marci@174: class OutEdgeIt : public Edge { marci@174: friend class ResGraph2; marci@174: public: marci@174: OutEdgeIt() { } marci@174: private: marci@174: OutEdgeIt(const ResGraph2& _resG, Node v) { marci@174: resG=&_resG; marci@174: out=resG->G.template first(v); marci@174: while( out.valid() && !(free()>0) ) { ++out; } marci@174: if (!out.valid()) { marci@174: out_or_in=0; marci@174: in=resG->G.template first(v); marci@174: while( in.valid() && !(free()>0) ) { ++in; } marci@174: } marci@174: } marci@174: public: marci@174: OutEdgeIt& operator++() { marci@174: if (out_or_in) { marci@174: Node v=resG->G.aNode(out); marci@174: ++out; marci@174: while( out.valid() && !(free()>0) ) { ++out; } marci@174: if (!out.valid()) { marci@174: out_or_in=0; marci@174: in=resG->G.template first(v); marci@174: while( in.valid() && !(free()>0) ) { ++in; } marci@174: } marci@174: } else { marci@174: ++in; marci@174: while( in.valid() && !(free()>0) ) { ++in; } marci@174: } marci@174: return *this; marci@174: } marci@174: }; marci@174: marci@174: void /*getF*/first(OutEdgeIt& e, Node v) const { marci@174: e=OutEdgeIt(*this, v); marci@174: } marci@174: void /*getF*/first(NodeIt& v) const { G./*getF*/first(v); } marci@174: marci@174: template< typename It > marci@174: It first() const { marci@174: It e; marci@174: /*getF*/first(e); marci@174: return e; marci@174: } marci@174: marci@174: template< typename It > marci@174: It first(Node v) const { marci@174: It e; marci@174: /*getF*/first(e, v); marci@174: return e; marci@174: } marci@174: marci@174: Node tail(Edge e) const { marci@174: return ((e.out_or_in) ? G.aNode(e.out) : G.aNode(e.in)); } marci@174: Node head(Edge e) const { marci@174: return ((e.out_or_in) ? G.bNode(e.out) : G.bNode(e.in)); } marci@174: marci@174: Node aNode(OutEdgeIt e) const { marci@174: return ((e.out_or_in) ? G.aNode(e.out) : G.aNode(e.in)); } marci@174: Node bNode(OutEdgeIt e) const { marci@174: return ((e.out_or_in) ? G.bNode(e.out) : G.bNode(e.in)); } marci@174: marci@174: int id(Node v) const { return G.id(v); } marci@174: marci@174: template marci@174: class NodeMap { marci@174: typename Graph::NodeMap node_map; marci@174: public: marci@174: NodeMap(const ResGraph2& _G) : node_map(_G.G) { } marci@174: NodeMap(const ResGraph2& _G, S a) : node_map(_G.G, a) { } marci@174: void set(Node nit, S a) { node_map.set(nit, a); } marci@174: S get(Node nit) const { return node_map.get(nit); } marci@174: }; marci@174: }; marci@174: marci@174: marci@266: template marci@174: class MaxFlow { marci@269: protected: marci@269: typedef GraphWrapper GW; marci@269: typedef typename GW::Node Node; marci@269: typedef typename GW::Edge Edge; marci@269: typedef typename GW::EdgeIt EdgeIt; marci@269: typedef typename GW::OutEdgeIt OutEdgeIt; marci@269: typedef typename GW::InEdgeIt InEdgeIt; marci@266: //const Graph* G; marci@269: GW gw; marci@174: Node s; marci@174: Node t; marci@174: FlowMap* flow; marci@174: const CapacityMap* capacity; marci@269: typedef ResGraphWrapper ResGW; marci@269: typedef typename ResGW::OutEdgeIt ResGWOutEdgeIt; marci@269: typedef typename ResGW::Edge ResGWEdge; marci@269: public: marci@174: marci@269: MaxFlow(const GW& _gw, Node _s, Node _t, FlowMap& _flow, const CapacityMap& _capacity) : marci@266: gw(_gw), s(_s), t(_t), flow(&_flow), capacity(&_capacity) { } marci@269: marci@174: bool augmentOnShortestPath() { marci@269: ResGW res_graph(gw, *flow, *capacity); marci@174: bool _augment=false; marci@174: marci@269: typedef typename ResGW::NodeMap ReachedMap; marci@269: BfsIterator5< ResGW, ReachedMap > bfs(res_graph); marci@269: bfs.pushAndSetReached(s); marci@174: marci@269: typename ResGW::NodeMap pred(res_graph); marci@269: pred.set(s, INVALID); marci@174: marci@269: typename ResGW::NodeMap free(res_graph); marci@174: marci@174: //searching for augmenting path marci@269: while ( !bfs.finished() ) { marci@269: ResGWOutEdgeIt e=bfs; marci@269: if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) { marci@174: Node v=res_graph.tail(e); marci@174: Node w=res_graph.head(e); marci@174: pred.set(w, e); marci@174: if (res_graph.valid(pred.get(v))) { marci@269: free.set(w, std::min(free.get(v), res_graph.resCap(e))); marci@174: } else { marci@269: free.set(w, res_graph.resCap(e)); marci@174: } marci@174: if (res_graph.head(e)==t) { _augment=true; break; } marci@174: } marci@174: marci@269: ++bfs; marci@174: } //end of searching augmenting path marci@174: marci@174: if (_augment) { marci@174: Node n=t; marci@174: Number augment_value=free.get(t); marci@174: while (res_graph.valid(pred.get(n))) { marci@269: ResGWEdge e=pred.get(n); marci@174: res_graph.augment(e, augment_value); marci@174: n=res_graph.tail(e); marci@174: } marci@174: } marci@174: marci@174: return _augment; marci@174: } marci@174: marci@266: template marci@263: class DistanceMap { marci@263: protected: marci@266: MapGraphWrapper gw; marci@266: typename MapGraphWrapper::NodeMap dist; marci@263: public: marci@266: DistanceMap(MapGraphWrapper& _gw) : gw(_gw), dist(_gw, _gw.nodeNum()) { } marci@266: void set(const typename MapGraphWrapper::Node& n, int a) { dist[n]=a; } marci@266: int get(const typename MapGraphWrapper::Node& n) const { return dist[n]; } marci@266: bool get(const typename MapGraphWrapper::Edge& e) const { marci@263: return (dist.get(gw.tail(e)) bool augmentOnBlockingFlow() { marci@269: typedef MutableGraph MG; marci@174: bool _augment=false; marci@174: marci@269: ResGW res_graph(gw, *flow, *capacity); marci@174: marci@269: typedef typename ResGW::NodeMap ReachedMap; marci@269: BfsIterator5< ResGW, ReachedMap > bfs(res_graph); marci@174: marci@174: bfs.pushAndSetReached(s); marci@269: //typename ResGW::NodeMap dist(res_graph); //filled up with 0's marci@269: DistanceMap dist(res_graph); marci@174: while ( !bfs.finished() ) { marci@269: ResGWOutEdgeIt e=bfs; marci@174: if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) { marci@174: dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1); marci@174: } marci@174: ++bfs; marci@174: } //computing distances from s in the residual graph marci@174: marci@269: MG F; marci@269: typedef SubGraphWrapper > FilterResGW; marci@269: FilterResGW filter_res_graph(res_graph, dist); marci@269: typename ResGW::NodeMap res_graph_to_F(res_graph); marci@269: for(typename ResGW::NodeIt n=res_graph.template first(); res_graph.valid(n); res_graph.next(n)) { marci@174: res_graph_to_F.set(n, F.addNode()); marci@174: } marci@174: marci@269: typename MG::Node sF=res_graph_to_F.get(s); marci@269: typename MG::Node tF=res_graph_to_F.get(t); marci@269: typename MG::EdgeMap original_edge(F); marci@269: typename MG::EdgeMap residual_capacity(F); marci@174: marci@174: //Making F to the graph containing the edges of the residual graph marci@174: //which are in some shortest paths marci@269: for(typename FilterResGW::EdgeIt e=filter_res_graph.template first(); filter_res_graph.valid(e); filter_res_graph.next(e)) { marci@266: //if (dist.get(res_graph.head(e))==dist.get(res_graph.tail(e))+1) { marci@269: typename MG::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e))); marci@174: original_edge.update(); marci@174: original_edge.set(f, e); marci@174: residual_capacity.update(); marci@269: residual_capacity.set(f, res_graph.resCap(e)); marci@266: //} marci@174: } marci@174: marci@174: bool __augment=true; marci@174: marci@174: while (__augment) { marci@174: __augment=false; marci@174: //computing blocking flow with dfs marci@269: typedef typename TrivGraphWrapper::NodeMap BlockingReachedMap; marci@269: DfsIterator5< TrivGraphWrapper, BlockingReachedMap > dfs(F); marci@269: typename MG::NodeMap pred(F); marci@269: pred.set(sF, INVALID); marci@174: //invalid iterators for sources marci@174: marci@269: typename MG::NodeMap free(F); marci@174: marci@174: dfs.pushAndSetReached(sF); marci@174: while (!dfs.finished()) { marci@174: ++dfs; marci@269: if (F.valid(/*typename MG::OutEdgeIt*/(dfs))) { marci@174: if (dfs.isBNodeNewlyReached()) { marci@269: typename MG::Node v=F.aNode(dfs); marci@269: typename MG::Node w=F.bNode(dfs); marci@174: pred.set(w, dfs); marci@174: if (F.valid(pred.get(v))) { marci@174: free.set(w, std::min(free.get(v), residual_capacity.get(dfs))); marci@174: } else { marci@174: free.set(w, residual_capacity.get(dfs)); marci@174: } marci@174: if (w==tF) { marci@174: __augment=true; marci@174: _augment=true; marci@174: break; marci@174: } marci@174: marci@174: } else { marci@269: F.erase(/*typename MG::OutEdgeIt*/(dfs)); marci@174: } marci@174: } marci@174: } marci@174: marci@174: if (__augment) { marci@269: typename MG::Node n=tF; marci@174: Number augment_value=free.get(tF); marci@174: while (F.valid(pred.get(n))) { marci@269: typename MG::Edge e=pred.get(n); marci@174: res_graph.augment(original_edge.get(e), augment_value); marci@174: n=F.tail(e); marci@174: if (residual_capacity.get(e)==augment_value) marci@174: F.erase(e); marci@174: else marci@174: residual_capacity.set(e, residual_capacity.get(e)-augment_value); marci@174: } marci@174: } marci@174: marci@174: } marci@174: marci@174: return _augment; marci@174: } marci@263: marci@268: template bool augmentOnBlockingFlow1() { marci@269: typedef MutableGraph MG; marci@268: bool _augment=false; marci@193: marci@269: ResGW res_graph(gw, *flow, *capacity); marci@193: marci@268: //bfs for distances on the residual graph marci@269: typedef typename ResGW::NodeMap ReachedMap; marci@269: BfsIterator5< ResGW, ReachedMap > bfs(res_graph); marci@268: bfs.pushAndSetReached(s); marci@269: typename ResGW::NodeMap dist(res_graph); //filled up with 0's marci@193: marci@268: //F will contain the physical copy of the residual graph marci@269: //with the set of edges which are on shortest paths marci@269: MG F; marci@269: typename ResGW::NodeMap res_graph_to_F(res_graph); marci@269: for(typename ResGW::NodeIt n=res_graph.template first(); res_graph.valid(n); res_graph.next(n)) { marci@268: res_graph_to_F.set(n, F.addNode()); marci@268: } marci@269: marci@269: typename MG::Node sF=res_graph_to_F.get(s); marci@269: typename MG::Node tF=res_graph_to_F.get(t); marci@269: typename MG::EdgeMap original_edge(F); marci@269: typename MG::EdgeMap residual_capacity(F); marci@193: marci@268: while ( !bfs.finished() ) { marci@269: ResGWOutEdgeIt e=bfs; marci@268: if (res_graph.valid(e)) { marci@268: if (bfs.isBNodeNewlyReached()) { marci@268: dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1); marci@269: typename MG::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e))); marci@268: original_edge.update(); marci@268: original_edge.set(f, e); marci@268: residual_capacity.update(); marci@269: residual_capacity.set(f, res_graph.resCap(e)); marci@268: } else { marci@268: if (dist.get(res_graph.head(e))==(dist.get(res_graph.tail(e))+1)) { marci@269: typename MG::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e))); marci@268: original_edge.update(); marci@268: original_edge.set(f, e); marci@268: residual_capacity.update(); marci@269: residual_capacity.set(f, res_graph.resCap(e)); marci@268: } marci@268: } marci@268: } marci@268: ++bfs; marci@268: } //computing distances from s in the residual graph marci@193: marci@268: bool __augment=true; marci@193: marci@268: while (__augment) { marci@268: __augment=false; marci@268: //computing blocking flow with dfs marci@269: typedef typename TrivGraphWrapper::NodeMap BlockingReachedMap; marci@269: DfsIterator5< TrivGraphWrapper, BlockingReachedMap > dfs(F); marci@269: typename MG::NodeMap pred(F); marci@269: pred.set(sF, INVALID); marci@268: //invalid iterators for sources marci@193: marci@269: typename MG::NodeMap free(F); marci@193: marci@268: dfs.pushAndSetReached(sF); marci@268: while (!dfs.finished()) { marci@268: ++dfs; marci@269: if (F.valid(/*typename MG::OutEdgeIt*/(dfs))) { marci@268: if (dfs.isBNodeNewlyReached()) { marci@269: typename MG::Node v=F.aNode(dfs); marci@269: typename MG::Node w=F.bNode(dfs); marci@268: pred.set(w, dfs); marci@268: if (F.valid(pred.get(v))) { marci@268: free.set(w, std::min(free.get(v), residual_capacity.get(dfs))); marci@268: } else { marci@268: free.set(w, residual_capacity.get(dfs)); marci@268: } marci@268: if (w==tF) { marci@268: __augment=true; marci@268: _augment=true; marci@268: break; marci@268: } marci@193: marci@268: } else { marci@269: F.erase(/*typename MG::OutEdgeIt*/(dfs)); marci@268: } marci@268: } marci@268: } marci@193: marci@268: if (__augment) { marci@269: typename MG::Node n=tF; marci@268: Number augment_value=free.get(tF); marci@268: while (F.valid(pred.get(n))) { marci@269: typename MG::Edge e=pred.get(n); marci@268: res_graph.augment(original_edge.get(e), augment_value); marci@268: n=F.tail(e); marci@268: if (residual_capacity.get(e)==augment_value) marci@268: F.erase(e); marci@268: else marci@268: residual_capacity.set(e, residual_capacity.get(e)-augment_value); marci@268: } marci@268: } marci@193: marci@268: } marci@193: marci@268: return _augment; marci@268: } marci@268: marci@269: bool augmentOnBlockingFlow2() { marci@269: bool _augment=false; marci@269: marci@269: ResGW res_graph(gw, *flow, *capacity); marci@269: marci@269: typedef typename ResGW::NodeMap ReachedMap; marci@269: BfsIterator5< ResGW, ReachedMap > bfs(res_graph); marci@269: marci@269: bfs.pushAndSetReached(s); marci@269: DistanceMap dist(res_graph); marci@269: while ( !bfs.finished() ) { marci@269: ResGWOutEdgeIt e=bfs; marci@269: if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) { marci@269: dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1); marci@269: } marci@269: ++bfs; marci@269: } //computing distances from s in the residual graph marci@269: marci@269: //Subgraph containing the edges on some shortest paths marci@269: typedef SubGraphWrapper > FilterResGW; marci@269: FilterResGW filter_res_graph(res_graph, dist); marci@269: marci@269: //Subgraph, which is able to delete edges which are already marci@269: //met by the dfs marci@269: typename FilterResGW::NodeMap marci@269: first_out_edges(filter_res_graph); marci@269: typename FilterResGW::NodeIt v; marci@269: for(filter_res_graph.first(v); filter_res_graph.valid(v); marci@269: filter_res_graph.next(v)) marci@269: { marci@269: typename FilterResGW::OutEdgeIt e; marci@269: filter_res_graph.first(e, v); marci@269: first_out_edges.set(v, e); marci@269: } marci@269: typedef ErasingFirstGraphWrapper > ErasingResGW; marci@269: ErasingResGW erasing_res_graph(filter_res_graph, first_out_edges); marci@269: marci@269: bool __augment=true; marci@269: marci@269: while (__augment) { marci@269: marci@269: __augment=false; marci@269: //computing blocking flow with dfs marci@269: typedef typename ErasingResGW::NodeMap BlockingReachedMap; marci@269: DfsIterator5< ErasingResGW, BlockingReachedMap > marci@269: dfs(erasing_res_graph); marci@269: typename ErasingResGW::NodeMap marci@269: pred(erasing_res_graph); marci@269: pred.set(s, INVALID); marci@269: //invalid iterators for sources marci@269: marci@269: typename ErasingResGW::NodeMap free(erasing_res_graph); marci@269: marci@269: dfs.pushAndSetReached(s); marci@269: while (!dfs.finished()) { marci@269: ++dfs; marci@269: if (erasing_res_graph.valid( marci@269: /*typename ErasingResGW::OutEdgeIt*/(dfs))) marci@269: { marci@269: if (dfs.isBNodeNewlyReached()) { marci@269: marci@269: typename ErasingResGW::Node v=erasing_res_graph.aNode(dfs); marci@269: typename ErasingResGW::Node w=erasing_res_graph.bNode(dfs); marci@269: marci@269: pred.set(w, /*typename ErasingResGW::OutEdgeIt*/(dfs)); marci@269: if (erasing_res_graph.valid(pred.get(v))) { marci@269: free.set(w, std::min(free.get(v), res_graph.resCap(dfs))); marci@269: } else { marci@269: free.set(w, res_graph.resCap(dfs)); marci@269: } marci@269: marci@269: if (w==t) { marci@269: __augment=true; marci@269: _augment=true; marci@269: break; marci@269: } marci@269: } else { marci@269: erasing_res_graph.erase(dfs); marci@269: } marci@269: } marci@269: } marci@269: marci@269: if (__augment) { marci@269: typename ErasingResGW::Node n=t; marci@269: Number augment_value=free.get(n); marci@269: while (erasing_res_graph.valid(pred.get(n))) { marci@269: typename ErasingResGW::OutEdgeIt e=pred.get(n); marci@269: res_graph.augment(e, augment_value); marci@269: n=erasing_res_graph.tail(e); marci@269: if (res_graph.resCap(e)==0) marci@269: erasing_res_graph.erase(e); marci@269: } marci@269: } marci@269: marci@269: } //while (__augment) marci@269: marci@269: return _augment; marci@269: } marci@269: marci@266: // bool augmentOnBlockingFlow2() { marci@266: // bool _augment=false; marci@193: marci@266: // //typedef ErasingResGraphWrapper EAugGraph; marci@266: // typedef FilterGraphWrapper< ErasingResGraphWrapper > EAugGraph; marci@266: // typedef typename EAugGraph::OutEdgeIt EAugOutEdgeIt; marci@266: // typedef typename EAugGraph::Edge EAugEdge; marci@193: marci@266: // EAugGraph res_graph(*G, *flow, *capacity); marci@193: marci@266: // //typedef typename EAugGraph::NodeMap ReachedMap; marci@266: // BfsIterator5< marci@266: // ErasingResGraphWrapper, marci@266: // /*typename ErasingResGraphWrapper::OutEdgeIt,*/ marci@266: // ErasingResGraphWrapper::NodeMap > bfs(res_graph); marci@266: marci@266: // bfs.pushAndSetReached(s); marci@197: marci@266: // typename ErasingResGraphWrapper:: marci@266: // NodeMap& dist=res_graph.dist; marci@197: marci@266: // while ( !bfs.finished() ) { marci@266: // typename ErasingResGraphWrapper::OutEdgeIt e=bfs; marci@266: // if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) { marci@266: // dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1); marci@266: // } marci@266: // ++bfs; marci@266: // } //computing distances from s in the residual graph marci@197: marci@266: // bool __augment=true; marci@266: marci@266: // while (__augment) { marci@266: marci@266: // __augment=false; marci@266: // //computing blocking flow with dfs marci@266: // typedef typename EAugGraph::NodeMap BlockingReachedMap; marci@266: // DfsIterator5< EAugGraph/*, EAugOutEdgeIt*/, BlockingReachedMap > marci@266: // dfs(res_graph); marci@266: // typename EAugGraph::NodeMap pred(res_graph); marci@266: // pred.set(s, EAugEdge(INVALID)); marci@266: // //invalid iterators for sources marci@266: marci@266: // typename EAugGraph::NodeMap free(res_graph); marci@266: marci@266: // dfs.pushAndSetReached(s); marci@266: // while (!dfs.finished()) { marci@266: // ++dfs; marci@266: // if (res_graph.valid(EAugOutEdgeIt(dfs))) { marci@266: // if (dfs.isBNodeNewlyReached()) { marci@266: marci@266: // typename EAugGraph::Node v=res_graph.aNode(dfs); marci@266: // typename EAugGraph::Node w=res_graph.bNode(dfs); marci@266: marci@266: // pred.set(w, EAugOutEdgeIt(dfs)); marci@266: // if (res_graph.valid(pred.get(v))) { marci@266: // free.set(w, std::min(free.get(v), res_graph.free(dfs))); marci@266: // } else { marci@266: // free.set(w, res_graph.free(dfs)); marci@266: // } marci@266: marci@266: // if (w==t) { marci@266: // __augment=true; marci@266: // _augment=true; marci@266: // break; marci@266: // } marci@266: // } else { marci@266: // res_graph.erase(dfs); marci@266: // } marci@266: // } marci@266: marci@266: // } marci@266: marci@266: // if (__augment) { marci@266: // typename EAugGraph::Node n=t; marci@266: // Number augment_value=free.get(t); marci@266: // while (res_graph.valid(pred.get(n))) { marci@266: // EAugEdge e=pred.get(n); marci@266: // res_graph.augment(e, augment_value); marci@266: // n=res_graph.tail(e); marci@266: // if (res_graph.free(e)==0) marci@266: // res_graph.erase(e); marci@266: // } marci@266: // } marci@193: marci@266: // } marci@193: marci@266: // return _augment; marci@266: // } marci@269: marci@269: void run() { marci@269: //int num_of_augmentations=0; marci@269: while (augmentOnShortestPath()) { marci@269: //while (augmentOnBlockingFlow()) { marci@269: //std::cout << ++num_of_augmentations << " "; marci@269: //std::cout< void run() { marci@269: //int num_of_augmentations=0; marci@269: //while (augmentOnShortestPath()) { marci@269: while (augmentOnBlockingFlow()) { marci@269: //std::cout << ++num_of_augmentations << " "; marci@269: //std::cout<get(e); marci@193: } marci@193: return a; marci@193: } marci@269: marci@193: }; marci@193: marci@193: marci@174: // template marci@266: // class MaxMatching { marci@174: // public: marci@174: // typedef typename Graph::Node Node; marci@266: // typedef typename Graph::NodeIt NodeIt; marci@174: // typedef typename Graph::Edge Edge; marci@174: // typedef typename Graph::EdgeIt EdgeIt; marci@174: // typedef typename Graph::OutEdgeIt OutEdgeIt; marci@174: // typedef typename Graph::InEdgeIt InEdgeIt; marci@266: marci@266: // typedef typename Graph::NodeMap SMap; marci@266: // typedef typename Graph::NodeMap TMap; marci@174: // private: marci@266: // const Graph* G; marci@266: // SMap* S; marci@266: // TMap* T; marci@266: // //Node s; marci@266: // //Node t; marci@266: // FlowMap* flow; marci@266: // const CapacityMap* capacity; marci@174: // typedef ResGraphWrapper AugGraph; marci@174: // typedef typename AugGraph::OutEdgeIt AugOutEdgeIt; marci@174: // typedef typename AugGraph::Edge AugEdge; marci@266: // typename Graph::NodeMap used; //0 marci@266: marci@174: // public: marci@266: // MaxMatching(const Graph& _G, SMap& _S, TMap& _T, FlowMap& _flow, const CapacityMap& _capacity) : marci@266: // G(&_G), S(&_S), T(&_T), flow(&_flow), capacity(&_capacity), used(_G) { } marci@266: // bool augmentOnShortestPath() { marci@266: // AugGraph res_graph(*G, *flow, *capacity); marci@174: // bool _augment=false; marci@174: marci@174: // typedef typename AugGraph::NodeMap ReachedMap; marci@269: // BfsIterator5< AugGraph, /*AugOutEdgeIt,*/ ReachedMap > bfs(res_graph); marci@266: // typename AugGraph::NodeMap pred(res_graph); marci@266: // for(NodeIt s=G->template first(); G->valid(s); G->next(s)) { marci@266: // if ((S->get(s)) && (used.get(s)<1) ) { marci@266: // //Number u=0; marci@266: // //for(OutEdgeIt e=G->template first(s); G->valid(e); G->next(e)) marci@266: // //u+=flow->get(e); marci@266: // //if (u<1) { marci@269: // bfs.pushAndSetReached(s); marci@266: // pred.set(s, AugEdge(INVALID)); marci@266: // //} marci@266: // } marci@174: // } marci@174: marci@174: // typename AugGraph::NodeMap free(res_graph); marci@174: marci@266: // Node n; marci@174: // //searching for augmenting path marci@269: // while ( !bfs.finished() ) { marci@269: // AugOutEdgeIt e=bfs; marci@269: // if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) { marci@174: // Node v=res_graph.tail(e); marci@174: // Node w=res_graph.head(e); marci@174: // pred.set(w, e); marci@266: // if (res_graph.valid(pred.get(v))) { marci@266: // free.set(w, std::min(free.get(v), res_graph.free(e))); marci@174: // } else { marci@266: // free.set(w, res_graph.free(e)); marci@174: // } marci@266: // n=res_graph.head(e); marci@266: // if (T->get(n) && (used.get(n)<1) ) { marci@266: // //Number u=0; marci@266: // //for(InEdgeIt f=G->template first(n); G->valid(f); G->next(f)) marci@266: // //u+=flow->get(f); marci@266: // //if (u<1) { marci@266: // _augment=true; marci@266: // break; marci@266: // //} marci@174: // } marci@174: // } marci@174: marci@269: // ++bfs; marci@174: // } //end of searching augmenting path marci@174: marci@174: // if (_augment) { marci@266: // //Node n=t; marci@266: // used.set(n, 1); //mind2 vegen jav marci@266: // Number augment_value=free.get(n); marci@266: // while (res_graph.valid(pred.get(n))) { marci@174: // AugEdge e=pred.get(n); marci@266: // res_graph.augment(e, augment_value); marci@174: // n=res_graph.tail(e); marci@174: // } marci@266: // used.set(n, 1); //mind2 vegen jav marci@174: // } marci@174: marci@174: // return _augment; marci@174: // } marci@266: marci@266: // // template bool augmentOnBlockingFlow() { marci@266: // // bool _augment=false; marci@266: marci@266: // // AugGraph res_graph(*G, *flow, *capacity); marci@266: marci@266: // // typedef typename AugGraph::NodeMap ReachedMap; marci@266: // // BfsIterator4< AugGraph, AugOutEdgeIt, ReachedMap > bfs(res_graph); marci@266: marci@266: marci@266: marci@266: marci@266: marci@266: // // //typename AugGraph::NodeMap pred(res_graph); marci@266: // // for(NodeIt s=G->template first(); G->valid(s); G->next(s)) { marci@266: // // if (S->get(s)) { marci@266: // // Number u=0; marci@266: // // for(OutEdgeIt e=G->template first(s); G->valid(e); G->next(e)) marci@266: // // u+=flow->get(e); marci@266: // // if (u<1) { marci@269: // // bfs.pushAndSetReached(s); marci@266: // // //pred.set(s, AugEdge(INVALID)); marci@266: // // } marci@266: // // } marci@266: // // } marci@266: marci@266: marci@266: marci@266: marci@266: // // //bfs.pushAndSetReached(s); marci@266: // // typename AugGraph::NodeMap dist(res_graph); //filled up with 0's marci@266: // // while ( !bfs.finished() ) { marci@266: // // AugOutEdgeIt e=bfs; marci@266: // // if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) { marci@266: // // dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1); marci@266: // // } marci@266: marci@266: // // ++bfs; marci@266: // // } //computing distances from s in the residual graph marci@266: marci@266: // // MutableGraph F; marci@266: // // typename AugGraph::NodeMap marci@266: // // res_graph_to_F(res_graph); marci@266: // // for(typename AugGraph::NodeIt n=res_graph.template first(); res_graph.valid(n); res_graph.next(n)) { marci@266: // // res_graph_to_F.set(n, F.addNode()); marci@266: // // } marci@266: marci@266: // // typename MutableGraph::Node sF=res_graph_to_F.get(s); marci@266: // // typename MutableGraph::Node tF=res_graph_to_F.get(t); marci@266: marci@266: // // typename MutableGraph::EdgeMap original_edge(F); marci@266: // // typename MutableGraph::EdgeMap residual_capacity(F); marci@266: marci@266: // // //Making F to the graph containing the edges of the residual graph marci@266: // // //which are in some shortest paths marci@266: // // for(typename AugGraph::EdgeIt e=res_graph.template first(); res_graph.valid(e); res_graph.next(e)) { marci@266: // // if (dist.get(res_graph.head(e))==dist.get(res_graph.tail(e))+1) { marci@266: // // typename MutableGraph::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e))); marci@266: // // original_edge.update(); marci@266: // // original_edge.set(f, e); marci@266: // // residual_capacity.update(); marci@266: // // residual_capacity.set(f, res_graph.free(e)); marci@266: // // } marci@266: // // } marci@266: marci@266: // // bool __augment=true; marci@266: marci@266: // // while (__augment) { marci@266: // // __augment=false; marci@266: // // //computing blocking flow with dfs marci@266: // // typedef typename MutableGraph::NodeMap BlockingReachedMap; marci@266: // // DfsIterator4< MutableGraph, typename MutableGraph::OutEdgeIt, BlockingReachedMap > dfs(F); marci@266: // // typename MutableGraph::NodeMap pred(F); marci@266: // // pred.set(sF, typename MutableGraph::Edge(INVALID)); marci@266: // // //invalid iterators for sources marci@266: marci@266: // // typename MutableGraph::NodeMap free(F); marci@266: marci@266: // // dfs.pushAndSetReached(sF); marci@266: // // while (!dfs.finished()) { marci@266: // // ++dfs; marci@266: // // if (F.valid(typename MutableGraph::OutEdgeIt(dfs))) { marci@266: // // if (dfs.isBNodeNewlyReached()) { marci@266: // // typename MutableGraph::Node v=F.aNode(dfs); marci@266: // // typename MutableGraph::Node w=F.bNode(dfs); marci@266: // // pred.set(w, dfs); marci@266: // // if (F.valid(pred.get(v))) { marci@266: // // free.set(w, std::min(free.get(v), residual_capacity.get(dfs))); marci@266: // // } else { marci@266: // // free.set(w, residual_capacity.get(dfs)); marci@266: // // } marci@266: // // if (w==tF) { marci@266: // // __augment=true; marci@266: // // _augment=true; marci@266: // // break; marci@266: // // } marci@266: marci@266: // // } else { marci@266: // // F.erase(typename MutableGraph::OutEdgeIt(dfs)); marci@266: // // } marci@266: // // } marci@266: // // } marci@266: marci@266: // // if (__augment) { marci@266: // // typename MutableGraph::Node n=tF; marci@266: // // Number augment_value=free.get(tF); marci@266: // // while (F.valid(pred.get(n))) { marci@266: // // typename MutableGraph::Edge e=pred.get(n); marci@266: // // res_graph.augment(original_edge.get(e), augment_value); marci@266: // // n=F.tail(e); marci@266: // // if (residual_capacity.get(e)==augment_value) marci@266: // // F.erase(e); marci@266: // // else marci@266: // // residual_capacity.set(e, residual_capacity.get(e)-augment_value); marci@266: // // } marci@266: // // } marci@266: marci@266: // // } marci@266: marci@266: // // return _augment; marci@266: // // } marci@266: // bool augmentOnBlockingFlow2() { marci@266: // bool _augment=false; marci@266: marci@266: // //typedef ErasingResGraphWrapper EAugGraph; marci@266: // typedef FilterGraphWrapper< ErasingResGraphWrapper > EAugGraph; marci@266: // typedef typename EAugGraph::OutEdgeIt EAugOutEdgeIt; marci@266: // typedef typename EAugGraph::Edge EAugEdge; marci@266: marci@266: // EAugGraph res_graph(*G, *flow, *capacity); marci@266: marci@266: // //typedef typename EAugGraph::NodeMap ReachedMap; marci@266: // BfsIterator5< marci@266: // ErasingResGraphWrapper, marci@266: // /*typename ErasingResGraphWrapper::OutEdgeIt,*/ marci@266: // ErasingResGraphWrapper::NodeMap > bfs(res_graph); marci@266: marci@266: marci@266: // //typename AugGraph::NodeMap pred(res_graph); marci@266: // for(NodeIt s=G->template first(); G->valid(s); G->next(s)) { marci@266: // if (S->get(s)) { marci@266: // Number u=0; marci@266: // for(OutEdgeIt e=G->template first(s); G->valid(e); G->next(e)) marci@266: // u+=flow->get(e); marci@266: // if (u<1) { marci@266: // bfs.pushAndSetReached(s); marci@266: // //pred.set(s, AugEdge(INVALID)); marci@266: // } marci@266: // } marci@266: // } marci@266: marci@266: marci@266: // //bfs.pushAndSetReached(s); marci@266: marci@266: // typename ErasingResGraphWrapper:: marci@266: // NodeMap& dist=res_graph.dist; marci@266: marci@266: // while ( !bfs.finished() ) { marci@266: // typename ErasingResGraphWrapper::OutEdgeIt e=bfs; marci@266: // if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) { marci@266: // dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1); marci@266: // } marci@266: // ++bfs; marci@266: // } //computing distances from s in the residual graph marci@266: marci@266: // bool __augment=true; marci@266: marci@266: // while (__augment) { marci@266: marci@266: // __augment=false; marci@266: // //computing blocking flow with dfs marci@266: // typedef typename EAugGraph::NodeMap BlockingReachedMap; marci@266: // DfsIterator5< EAugGraph/*, EAugOutEdgeIt*/, BlockingReachedMap > marci@266: // dfs(res_graph); marci@266: // typename EAugGraph::NodeMap pred(res_graph, INVALID); marci@266: // //pred.set(s, EAugEdge(INVALID)); marci@266: // //invalid iterators for sources marci@266: marci@266: // typename EAugGraph::NodeMap free(res_graph); marci@266: marci@266: marci@266: // //typename AugGraph::NodeMap pred(res_graph); marci@266: // for(NodeIt s=G->template first(); G->valid(s); G->next(s)) { marci@266: // if (S->get(s)) { marci@266: // Number u=0; marci@266: // for(OutEdgeIt e=G->template first(s); G->valid(e); G->next(e)) marci@266: // u+=flow->get(e); marci@266: // if (u<1) { marci@266: // dfs.pushAndSetReached(s); marci@266: // //pred.set(s, AugEdge(INVALID)); marci@266: // } marci@266: // } marci@266: // } marci@266: marci@266: marci@266: marci@266: // //dfs.pushAndSetReached(s); marci@266: // typename EAugGraph::Node n; marci@266: // while (!dfs.finished()) { marci@266: // ++dfs; marci@266: // if (res_graph.valid(EAugOutEdgeIt(dfs))) { marci@266: // if (dfs.isBNodeNewlyReached()) { marci@266: marci@266: // typename EAugGraph::Node v=res_graph.aNode(dfs); marci@266: // typename EAugGraph::Node w=res_graph.bNode(dfs); marci@266: marci@266: // pred.set(w, EAugOutEdgeIt(dfs)); marci@266: // if (res_graph.valid(pred.get(v))) { marci@266: // free.set(w, std::min(free.get(v), res_graph.free(dfs))); marci@266: // } else { marci@266: // free.set(w, res_graph.free(dfs)); marci@266: // } marci@266: marci@266: // n=w; marci@266: // if (T->get(w)) { marci@266: // Number u=0; marci@266: // for(InEdgeIt f=G->template first(n); G->valid(f); G->next(f)) marci@266: // u+=flow->get(f); marci@266: // if (u<1) { marci@266: // __augment=true; marci@266: // _augment=true; marci@266: // break; marci@266: // } marci@266: // } marci@266: // } else { marci@266: // res_graph.erase(dfs); marci@266: // } marci@266: // } marci@266: marci@266: // } marci@266: marci@266: // if (__augment) { marci@266: // // typename EAugGraph::Node n=t; marci@266: // Number augment_value=free.get(n); marci@266: // while (res_graph.valid(pred.get(n))) { marci@266: // EAugEdge e=pred.get(n); marci@266: // res_graph.augment(e, augment_value); marci@266: // n=res_graph.tail(e); marci@266: // if (res_graph.free(e)==0) marci@266: // res_graph.erase(e); marci@266: // } marci@266: // } marci@266: marci@266: // } marci@266: marci@266: // return _augment; marci@266: // } marci@174: // void run() { marci@266: // //int num_of_augmentations=0; marci@266: // while (augmentOnShortestPath()) { marci@266: // //while (augmentOnBlockingFlow()) { marci@266: // //std::cout << ++num_of_augmentations << " "; marci@266: // //std::cout< void run() { marci@266: // // //int num_of_augmentations=0; marci@266: // // //while (augmentOnShortestPath()) { marci@266: // // while (augmentOnBlockingFlow()) { marci@266: // // //std::cout << ++num_of_augmentations << " "; marci@266: // // //std::cout</*getF*/first(e); G->valid(e); G->next(e)) { marci@266: // a+=flow->get(e); marci@174: // } marci@174: // return a; marci@174: // } marci@174: // }; marci@174: marci@174: marci@174: marci@266: marci@266: marci@266: marci@266: // // template marci@266: // // class MaxFlow2 { marci@266: // // public: marci@266: // // typedef typename Graph::Node Node; marci@266: // // typedef typename Graph::Edge Edge; marci@266: // // typedef typename Graph::EdgeIt EdgeIt; marci@266: // // typedef typename Graph::OutEdgeIt OutEdgeIt; marci@266: // // typedef typename Graph::InEdgeIt InEdgeIt; marci@266: // // private: marci@266: // // const Graph& G; marci@266: // // std::list& S; marci@266: // // std::list& T; marci@266: // // FlowMap& flow; marci@266: // // const CapacityMap& capacity; marci@266: // // typedef ResGraphWrapper AugGraph; marci@266: // // typedef typename AugGraph::OutEdgeIt AugOutEdgeIt; marci@266: // // typedef typename AugGraph::Edge AugEdge; marci@266: // // typename Graph::NodeMap SMap; marci@266: // // typename Graph::NodeMap TMap; marci@266: // // public: marci@266: // // MaxFlow2(const Graph& _G, std::list& _S, std::list& _T, FlowMap& _flow, const CapacityMap& _capacity) : G(_G), S(_S), T(_T), flow(_flow), capacity(_capacity), SMap(_G), TMap(_G) { marci@266: // // for(typename std::list::const_iterator i=S.begin(); marci@266: // // i!=S.end(); ++i) { marci@266: // // SMap.set(*i, true); marci@266: // // } marci@266: // // for (typename std::list::const_iterator i=T.begin(); marci@266: // // i!=T.end(); ++i) { marci@266: // // TMap.set(*i, true); marci@266: // // } marci@266: // // } marci@266: // // bool augment() { marci@266: // // AugGraph res_graph(G, flow, capacity); marci@266: // // bool _augment=false; marci@266: // // Node reached_t_node; marci@266: marci@266: // // typedef typename AugGraph::NodeMap ReachedMap; marci@269: // // BfsIterator4< AugGraph, AugOutEdgeIt, ReachedMap > bfs(res_graph); marci@266: // // for(typename std::list::const_iterator i=S.begin(); marci@266: // // i!=S.end(); ++i) { marci@269: // // bfs.pushAndSetReached(*i); marci@266: // // } marci@269: // // //bfs.pushAndSetReached(s); marci@266: marci@266: // // typename AugGraph::NodeMap pred(res_graph); marci@266: // // //filled up with invalid iterators marci@266: marci@266: // // typename AugGraph::NodeMap free(res_graph); marci@266: marci@266: // // //searching for augmenting path marci@269: // // while ( !bfs.finished() ) { marci@269: // // AugOutEdgeIt e=/*AugOutEdgeIt*/(bfs); marci@269: // // if (e.valid() && bfs.isBNodeNewlyReached()) { marci@266: // // Node v=res_graph.tail(e); marci@266: // // Node w=res_graph.head(e); marci@266: // // pred.set(w, e); marci@266: // // if (pred.get(v).valid()) { marci@266: // // free.set(w, std::min(free.get(v), e.free())); marci@266: // // } else { marci@266: // // free.set(w, e.free()); marci@266: // // } marci@266: // // if (TMap.get(res_graph.head(e))) { marci@266: // // _augment=true; marci@266: // // reached_t_node=res_graph.head(e); marci@266: // // break; marci@266: // // } marci@266: // // } marci@266: marci@269: // // ++bfs; marci@266: // // } //end of searching augmenting path marci@266: marci@266: // // if (_augment) { marci@266: // // Node n=reached_t_node; marci@266: // // Number augment_value=free.get(reached_t_node); marci@266: // // while (pred.get(n).valid()) { marci@266: // // AugEdge e=pred.get(n); marci@266: // // e.augment(augment_value); marci@266: // // n=res_graph.tail(e); marci@266: // // } marci@266: // // } marci@266: marci@266: // // return _augment; marci@266: // // } marci@266: // // void run() { marci@266: // // while (augment()) { } marci@266: // // } marci@266: // // Number flowValue() { marci@266: // // Number a=0; marci@266: // // for(typename std::list::const_iterator i=S.begin(); marci@266: // // i!=S.end(); ++i) { marci@266: // // for(OutEdgeIt e=G.template first(*i); e.valid(); ++e) { marci@266: // // a+=flow.get(e); marci@266: // // } marci@266: // // for(InEdgeIt e=G.template first(*i); e.valid(); ++e) { marci@266: // // a-=flow.get(e); marci@266: // // } marci@266: // // } marci@266: // // return a; marci@266: // // } marci@266: // // }; marci@266: marci@266: marci@174: } // namespace hugo marci@174: marci@259: #endif //HUGO_EDMONDS_KARP_H