# HG changeset patch # User marci # Date 1080751118 0 # Node ID e4811faaaa75ca784d32803a24436d196fd25673 # Parent 07af3069c0b84935c339bc25b28f5504867a3069 Ment-e a dereferalasok sporolasaval elobbre a vilag? diff -r 07af3069c0b8 -r e4811faaaa75 src/work/marci/gw_vs_not.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/marci/gw_vs_not.cc Wed Mar 31 16:38:38 2004 +0000 @@ -0,0 +1,179 @@ +// -*- c++ -*- +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace hugo; + +// Use a DIMACS max flow file as stdin. +// read_dimacs_demo < dimacs_max_flow_file + +int main(int, char **) { + + typedef ListGraph MutableGraph; + //typedef SmartGraph Graph; + typedef ListGraph Graph; + typedef Graph::Node Node; + typedef Graph::EdgeIt EdgeIt; + + Graph G; + Node s, t; + Graph::EdgeMap cap(G); + readDimacsMaxFlow(std::cin, G, s, t, cap); + + { + typedef TrivGraphWrapper GW; + GW gw(G); + typedef GW::EdgeMapWrapper< Graph::EdgeMap, int > EMW; + EMW cw(cap); + Timer ts; + GW::EdgeMap flow(gw); + MaxFlow, EMW > max_flow_test(gw, s, t, flow, cw); + int i; + + { + std::cout << "edmonds karp demo (physical blocking flow augmentation)..." << std::endl; + for (GW::EdgeIt e(gw); gw.valid(e); gw.next(e)) flow.set(e, 0); + ts.reset(); + + i=0; + while (max_flow_test.augmentOnBlockingFlow()) { ++i; } + + std::cout << "elapsed time: " << ts << std::endl; + std::cout << "number of augmentation phases: " << i << std::endl; + std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; + } + + { + std::cout << "edmonds karp demo (physical blocking flow 1 augmentation)..." << std::endl; + for (GW::EdgeIt e(gw); gw.valid(e); gw.next(e)) flow.set(e, 0); + ts.reset(); + + i=0; + while (max_flow_test.augmentOnBlockingFlow1()) { ++i; } + + std::cout << "elapsed time: " << ts << std::endl; + std::cout << "number of augmentation phases: " << i << std::endl; + std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; + } + + { + std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl; + for (GW::EdgeIt e(gw); gw.valid(e); gw.next(e)) flow.set(e, 0); + ts.reset(); + + i=0; + while (max_flow_test.augmentOnBlockingFlow2()) { ++i; } + + std::cout << "elapsed time: " << ts << std::endl; + std::cout << "number of augmentation phases: " << i << std::endl; + std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; + } + + { + std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl; + for (GW::EdgeIt e(gw); gw.valid(e); gw.next(e)) flow.set(e, 0); + ts.reset(); + + i=0; + while (max_flow_test.augmentOnShortestPath()) { ++i; } + + std::cout << "elapsed time: " << ts << std::endl; + std::cout << "number of augmentation phases: " << i << std::endl; + std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; + } + } + + + + + { + typedef TrivGraphWrapper GW1; + GW1 gw1(G); + typedef TrivGraphWrapper GW2; + GW2 gw2(gw1); + typedef TrivGraphWrapper GW3; + GW3 gw3(gw2); + typedef TrivGraphWrapper GW4; + GW4 gw4(gw3); + typedef TrivGraphWrapper GW5; + GW5 gw5(gw4); + typedef TrivGraphWrapper GW6; + GW6 gw6(gw5); + typedef TrivGraphWrapper GW7; + GW7 gw7(gw6); + typedef TrivGraphWrapper GW8; + GW8 gw8(gw7); + typedef TrivGraphWrapper GW9; + GW9 gw9(gw8); + typedef TrivGraphWrapper GW; + GW gw(gw9); + typedef GW::EdgeMapWrapper< Graph::EdgeMap, int > EMW; + EMW cw(cap); + Timer ts; + GW::EdgeMap flow(gw); + MaxFlow, EMW > max_flow_test(gw, s, t, flow, cw); + int i; + + { + std::cout << "edmonds karp demo (physical blocking flow augmentation)..." << std::endl; + for (GW::EdgeIt e(gw); gw.valid(e); gw.next(e)) flow.set(e, 0); + ts.reset(); + + i=0; + while (max_flow_test.augmentOnBlockingFlow()) { ++i; } + + std::cout << "elapsed time: " << ts << std::endl; + std::cout << "number of augmentation phases: " << i << std::endl; + std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; + } + + { + std::cout << "edmonds karp demo (physical blocking flow 1 augmentation)..." << std::endl; + for (GW::EdgeIt e(gw); gw.valid(e); gw.next(e)) flow.set(e, 0); + ts.reset(); + + i=0; + while (max_flow_test.augmentOnBlockingFlow1()) { ++i; } + + std::cout << "elapsed time: " << ts << std::endl; + std::cout << "number of augmentation phases: " << i << std::endl; + std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; + } + + { + std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl; + for (GW::EdgeIt e(gw); gw.valid(e); gw.next(e)) flow.set(e, 0); + ts.reset(); + + i=0; + while (max_flow_test.augmentOnBlockingFlow2()) { ++i; } + + std::cout << "elapsed time: " << ts << std::endl; + std::cout << "number of augmentation phases: " << i << std::endl; + std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; + } + + { + std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl; + for (GW::EdgeIt e(gw); gw.valid(e); gw.next(e)) flow.set(e, 0); + ts.reset(); + + i=0; + while (max_flow_test.augmentOnShortestPath()) { ++i; } + + std::cout << "elapsed time: " << ts << std::endl; + std::cout << "number of augmentation phases: " << i << std::endl; + std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; + } + } + + + return 0; +}