# HG changeset patch # User marci # Date 1077125233 0 # Node ID f1de2ab64e1cf6ca7fa3fc23a891d513dd34d2a3 # Parent f26897fb91fdd285e8b6c6585911b09cb4a42365 . diff -r f26897fb91fd -r f1de2ab64e1c src/work/edmonds_karp.hh --- a/src/work/edmonds_karp.hh Wed Feb 18 15:58:28 2004 +0000 +++ b/src/work/edmonds_karp.hh Wed Feb 18 17:27:13 2004 +0000 @@ -6,6 +6,7 @@ #include #include +#include namespace marci { @@ -443,8 +444,51 @@ return _augment; } + bool augmentWithBlockingFlow() { + BfsIterator4< Graph, OutEdgeIt, typename Graph::NodeMap > bfs(G); + bfs.pushAndSetReached(s); + typename Graph::NodeMap dist(G); //filled up with 0's + while ( !bfs.finished() ) { + OutEdgeIt e=OutEdgeIt(bfs); + if (e.valid() && bfs.isBNodeNewlyReached()) { + dist.set(G.head(e), dist.get(G.tail(e))+1); + //NodeIt v=res_graph.tail(e); + //NodeIt 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 (res_graph.head(e)==t) { _augment=true; break; } + } + + ++bfs; + } //end of searching augmenting path + + double pre_time_copy=currTime(); + typedef Graph MutableGraph; + MutableGraph F; + typename Graph::NodeMap G_to_F(G); + for(typename Graph::EachNodeIt n=G.template first(); n.valid(); ++n) { + G_to_F.set(n, F.addNode()); + } + for(typename Graph::EachEdgeIt e=G.template first(); e.valid(); ++e) { + if (dist.get(G.head(e))==dist.get(G.tail(e))+1) { + F.addEdge(G_to_F.get(G.tail(e)), G_to_F.get(G.head(e))); + } + } + double post_time_copy=currTime(); + std::cout << "copy time: " << post_time_copy-pre_time_copy << " sec"<< std::endl; + + return 0; + } void run() { - while (augment()) { } + //int num_of_augmentations=0; + while (augment()) { + //std::cout << ++num_of_augmentations << " "; + //std::cout< cap(G); readDimacsMaxFlow(std::cin, G, s, t, cap); +/* + double pre_time_copy=currTime(); + ListGraph F; + ListGraph::NodeMap G_to_F(G); + typedef ListGraph::EachNodeIt EachNodeIt; + for(EachNodeIt n=G.first(); n.valid(); ++n) { + G_to_F.set(n, F.addNode()); + } + for(EachEdgeIt e=G.first(); e.valid(); ++e) { + F.addEdge(G_to_F.get(G.tail(e)), G_to_F.get(G.head(e))); + } + double post_time_copy=currTime(); + std::cout << "copy time: " << post_time_copy-pre_time_copy << " sec"<< std::endl; +*/ + std::cout << "edmonds karp demo..." << std::endl; ListGraph::EdgeMap flow(G); //0 flow double pre_time=currTime(); MaxFlow, ListGraph::EdgeMap > max_flow_test(G, s, t, flow, cap); + max_flow_test.augmentWithBlockingFlow(); max_flow_test.run(); double post_time=currTime(); //std::cout << "maximum flow: "<< std::endl; diff -r f26897fb91fd -r f1de2ab64e1c src/work/marci/preflow_demo_jacint.cc --- a/src/work/marci/preflow_demo_jacint.cc Wed Feb 18 15:58:28 2004 +0000 +++ b/src/work/marci/preflow_demo_jacint.cc Wed Feb 18 17:27:13 2004 +0000 @@ -27,7 +27,8 @@ double pre_time=currTime(); preflow_push_max_flow max_flow_test(G, s, t, cap); max_flow_test.run(); - ListGraph::NodeMap cut=max_flow_test.mincut(); + ListGraph::NodeMap cut(G); + max_flow_test.mincut(cut); int cut_value=0; for(EachEdgeIt e=G.first(); e.valid(); ++e) { if (cut.get(G.tail(e)) && !cut.get(G.head(e))) cut_value+=cap.get(e); @@ -50,7 +51,8 @@ double pre_time=currTime(); preflow_push_hl max_flow_test(G, s, t, cap); max_flow_test.run(); - ListGraph::NodeMap cut=max_flow_test.mincut(); + ListGraph::NodeMap cut(G); + max_flow_test.mincut(cut); int cut_value=0; for(EachEdgeIt e=G.first(); e.valid(); ++e) { if (cut.get(G.tail(e)) && !cut.get(G.head(e))) cut_value+=cap.get(e);