[Lemon-commits] [lemon_svn] marci: r129 - in hugo/trunk/src/work: . marci
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:37:29 CET 2006
Author: marci
Date: Wed Feb 18 18:27:13 2004
New Revision: 129
Modified:
hugo/trunk/src/work/edmonds_karp.hh
hugo/trunk/src/work/marci/edmonds_karp_demo.cc
hugo/trunk/src/work/marci/preflow_demo_jacint.cc
Log:
.
Modified: hugo/trunk/src/work/edmonds_karp.hh
==============================================================================
--- hugo/trunk/src/work/edmonds_karp.hh (original)
+++ hugo/trunk/src/work/edmonds_karp.hh Wed Feb 18 18:27:13 2004
@@ -6,6 +6,7 @@
#include <iterator>
#include <bfs_iterator.hh>
+#include <time_measure.h>
namespace marci {
@@ -443,8 +444,51 @@
return _augment;
}
+ bool augmentWithBlockingFlow() {
+ BfsIterator4< Graph, OutEdgeIt, typename Graph::NodeMap<bool> > bfs(G);
+ bfs.pushAndSetReached(s);
+ typename Graph::NodeMap<int> 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<NodeIt> G_to_F(G);
+ for(typename Graph::EachNodeIt n=G.template first<typename Graph::EachNodeIt>(); n.valid(); ++n) {
+ G_to_F.set(n, F.addNode());
+ }
+ for(typename Graph::EachEdgeIt e=G.template first<typename Graph::EachEdgeIt>(); 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<<std::endl;
+ }
}
Number flowValue() {
Number a=0;
Modified: hugo/trunk/src/work/marci/edmonds_karp_demo.cc
==============================================================================
--- hugo/trunk/src/work/marci/edmonds_karp_demo.cc (original)
+++ hugo/trunk/src/work/marci/edmonds_karp_demo.cc Wed Feb 18 18:27:13 2004
@@ -19,11 +19,27 @@
ListGraph::EdgeMap<int> cap(G);
readDimacsMaxFlow(std::cin, G, s, t, cap);
+/*
+ double pre_time_copy=currTime();
+ ListGraph F;
+ ListGraph::NodeMap<NodeIt> G_to_F(G);
+ typedef ListGraph::EachNodeIt EachNodeIt;
+ for(EachNodeIt n=G.first<EachNodeIt>(); n.valid(); ++n) {
+ G_to_F.set(n, F.addNode());
+ }
+ for(EachEdgeIt e=G.first<EachEdgeIt>(); 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<int> flow(G); //0 flow
double pre_time=currTime();
MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > 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;
Modified: hugo/trunk/src/work/marci/preflow_demo_jacint.cc
==============================================================================
--- hugo/trunk/src/work/marci/preflow_demo_jacint.cc (original)
+++ hugo/trunk/src/work/marci/preflow_demo_jacint.cc Wed Feb 18 18:27:13 2004
@@ -27,7 +27,8 @@
double pre_time=currTime();
preflow_push_max_flow<ListGraph, int> max_flow_test(G, s, t, cap);
max_flow_test.run();
- ListGraph::NodeMap<bool> cut=max_flow_test.mincut();
+ ListGraph::NodeMap<bool> cut(G);
+ max_flow_test.mincut(cut);
int cut_value=0;
for(EachEdgeIt e=G.first<EachEdgeIt>(); 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<ListGraph, int> max_flow_test(G, s, t, cap);
max_flow_test.run();
- ListGraph::NodeMap<bool> cut=max_flow_test.mincut();
+ ListGraph::NodeMap<bool> cut(G);
+ max_flow_test.mincut(cut);
int cut_value=0;
for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
if (cut.get(G.tail(e)) && !cut.get(G.head(e))) cut_value+=cap.get(e);
More information about the Lemon-commits
mailing list