// -*- c++ -*- #include #include #include #include #include #include #include #include using namespace lemon; // 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; }