marci@270: // -*- c++ -*- marci@270: #include marci@270: #include marci@270: marci@270: #include marci@270: #include marci@270: #include marci@270: #include marci@270: #include marci@270: #include marci@270: marci@270: using namespace hugo; marci@270: marci@270: // Use a DIMACS max flow file as stdin. marci@270: // read_dimacs_demo < dimacs_max_flow_file marci@270: marci@270: int main(int, char **) { marci@270: marci@270: typedef ListGraph MutableGraph; marci@270: //typedef SmartGraph Graph; marci@270: typedef ListGraph Graph; marci@270: typedef Graph::Node Node; marci@270: typedef Graph::EdgeIt EdgeIt; marci@270: marci@270: Graph G; marci@270: Node s, t; marci@270: Graph::EdgeMap cap(G); marci@270: readDimacsMaxFlow(std::cin, G, s, t, cap); marci@270: marci@270: { marci@270: typedef TrivGraphWrapper GW; marci@270: GW gw(G); marci@270: typedef GW::EdgeMapWrapper< Graph::EdgeMap, int > EMW; marci@270: EMW cw(cap); marci@270: Timer ts; marci@270: GW::EdgeMap flow(gw); marci@270: MaxFlow, EMW > max_flow_test(gw, s, t, flow, cw); marci@270: int i; marci@270: marci@270: { marci@270: std::cout << "edmonds karp demo (physical blocking flow augmentation)..." << std::endl; marci@270: for (GW::EdgeIt e(gw); gw.valid(e); gw.next(e)) flow.set(e, 0); marci@270: ts.reset(); marci@270: marci@270: i=0; marci@270: while (max_flow_test.augmentOnBlockingFlow()) { ++i; } marci@270: marci@270: std::cout << "elapsed time: " << ts << std::endl; marci@270: std::cout << "number of augmentation phases: " << i << std::endl; marci@270: std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; marci@270: } marci@270: marci@270: { marci@270: std::cout << "edmonds karp demo (physical blocking flow 1 augmentation)..." << std::endl; marci@270: for (GW::EdgeIt e(gw); gw.valid(e); gw.next(e)) flow.set(e, 0); marci@270: ts.reset(); marci@270: marci@270: i=0; marci@270: while (max_flow_test.augmentOnBlockingFlow1()) { ++i; } marci@270: marci@270: std::cout << "elapsed time: " << ts << std::endl; marci@270: std::cout << "number of augmentation phases: " << i << std::endl; marci@270: std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; marci@270: } marci@270: marci@270: { marci@270: std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl; marci@270: for (GW::EdgeIt e(gw); gw.valid(e); gw.next(e)) flow.set(e, 0); marci@270: ts.reset(); marci@270: marci@270: i=0; marci@270: while (max_flow_test.augmentOnBlockingFlow2()) { ++i; } marci@270: marci@270: std::cout << "elapsed time: " << ts << std::endl; marci@270: std::cout << "number of augmentation phases: " << i << std::endl; marci@270: std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; marci@270: } marci@270: marci@270: { marci@270: std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl; marci@270: for (GW::EdgeIt e(gw); gw.valid(e); gw.next(e)) flow.set(e, 0); marci@270: ts.reset(); marci@270: marci@270: i=0; marci@270: while (max_flow_test.augmentOnShortestPath()) { ++i; } marci@270: marci@270: std::cout << "elapsed time: " << ts << std::endl; marci@270: std::cout << "number of augmentation phases: " << i << std::endl; marci@270: std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; marci@270: } marci@270: } marci@270: marci@270: marci@270: marci@270: marci@270: { marci@270: typedef TrivGraphWrapper GW1; marci@270: GW1 gw1(G); marci@270: typedef TrivGraphWrapper GW2; marci@270: GW2 gw2(gw1); marci@270: typedef TrivGraphWrapper GW3; marci@270: GW3 gw3(gw2); marci@270: typedef TrivGraphWrapper GW4; marci@270: GW4 gw4(gw3); marci@270: typedef TrivGraphWrapper GW5; marci@270: GW5 gw5(gw4); marci@270: typedef TrivGraphWrapper GW6; marci@270: GW6 gw6(gw5); marci@270: typedef TrivGraphWrapper GW7; marci@270: GW7 gw7(gw6); marci@270: typedef TrivGraphWrapper GW8; marci@270: GW8 gw8(gw7); marci@270: typedef TrivGraphWrapper GW9; marci@270: GW9 gw9(gw8); marci@270: typedef TrivGraphWrapper GW; marci@270: GW gw(gw9); marci@270: typedef GW::EdgeMapWrapper< Graph::EdgeMap, int > EMW; marci@270: EMW cw(cap); marci@270: Timer ts; marci@270: GW::EdgeMap flow(gw); marci@270: MaxFlow, EMW > max_flow_test(gw, s, t, flow, cw); marci@270: int i; marci@270: marci@270: { marci@270: std::cout << "edmonds karp demo (physical blocking flow augmentation)..." << std::endl; marci@270: for (GW::EdgeIt e(gw); gw.valid(e); gw.next(e)) flow.set(e, 0); marci@270: ts.reset(); marci@270: marci@270: i=0; marci@270: while (max_flow_test.augmentOnBlockingFlow()) { ++i; } marci@270: marci@270: std::cout << "elapsed time: " << ts << std::endl; marci@270: std::cout << "number of augmentation phases: " << i << std::endl; marci@270: std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; marci@270: } marci@270: marci@270: { marci@270: std::cout << "edmonds karp demo (physical blocking flow 1 augmentation)..." << std::endl; marci@270: for (GW::EdgeIt e(gw); gw.valid(e); gw.next(e)) flow.set(e, 0); marci@270: ts.reset(); marci@270: marci@270: i=0; marci@270: while (max_flow_test.augmentOnBlockingFlow1()) { ++i; } marci@270: marci@270: std::cout << "elapsed time: " << ts << std::endl; marci@270: std::cout << "number of augmentation phases: " << i << std::endl; marci@270: std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; marci@270: } marci@270: marci@270: { marci@270: std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl; marci@270: for (GW::EdgeIt e(gw); gw.valid(e); gw.next(e)) flow.set(e, 0); marci@270: ts.reset(); marci@270: marci@270: i=0; marci@270: while (max_flow_test.augmentOnBlockingFlow2()) { ++i; } marci@270: marci@270: std::cout << "elapsed time: " << ts << std::endl; marci@270: std::cout << "number of augmentation phases: " << i << std::endl; marci@270: std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; marci@270: } marci@270: marci@270: { marci@270: std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl; marci@270: for (GW::EdgeIt e(gw); gw.valid(e); gw.next(e)) flow.set(e, 0); marci@270: ts.reset(); marci@270: marci@270: i=0; marci@270: while (max_flow_test.augmentOnShortestPath()) { ++i; } marci@270: marci@270: std::cout << "elapsed time: " << ts << std::endl; marci@270: std::cout << "number of augmentation phases: " << i << std::endl; marci@270: std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; marci@270: } marci@270: } marci@270: marci@270: marci@270: return 0; marci@270: }