marci@270: // -*- c++ -*-
marci@270: #include <iostream>
marci@270: #include <fstream>
marci@270: 
marci@270: #include <list_graph.h>
marci@270: #include <smart_graph.h>
marci@270: #include <dimacs.h>
marci@270: #include <edmonds_karp.h>
marci@270: #include <time_measure.h>
marci@270: #include <graph_wrapper.h>
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<int> cap(G);
marci@270:   readDimacsMaxFlow(std::cin, G, s, t, cap);
marci@270: 
marci@270:   {
marci@270:     typedef TrivGraphWrapper<const Graph> GW;
marci@270:     GW gw(G);
marci@270:     typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
marci@270:     EMW cw(cap);
marci@270:     Timer ts;
marci@270:     GW::EdgeMap<int> flow(gw); 
marci@270:     MaxFlow<GW, int, GW::EdgeMap<int>, 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<MutableGraph>()) { ++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<MutableGraph>()) { ++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<const Graph> GW1;
marci@270:     GW1 gw1(G);
marci@270:     typedef TrivGraphWrapper<const GW1> GW2;
marci@270:     GW2 gw2(gw1);
marci@270:     typedef TrivGraphWrapper<const GW2> GW3;
marci@270:     GW3 gw3(gw2);
marci@270:     typedef TrivGraphWrapper<const GW3> GW4;
marci@270:     GW4 gw4(gw3);
marci@270:     typedef TrivGraphWrapper<const GW4> GW5;
marci@270:     GW5 gw5(gw4);
marci@270:     typedef TrivGraphWrapper<const GW5> GW6;
marci@270:     GW6 gw6(gw5);
marci@270:     typedef TrivGraphWrapper<const GW6> GW7;
marci@270:     GW7 gw7(gw6);
marci@270:     typedef TrivGraphWrapper<const GW7> GW8;
marci@270:     GW8 gw8(gw7);
marci@270:     typedef TrivGraphWrapper<const GW8> GW9;
marci@270:     GW9 gw9(gw8);
marci@270:     typedef TrivGraphWrapper<const GW9> GW;
marci@270:     GW gw(gw9);
marci@270:     typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
marci@270:     EMW cw(cap);
marci@270:     Timer ts;
marci@270:     GW::EdgeMap<int> flow(gw); 
marci@270:     MaxFlow<GW, int, GW::EdgeMap<int>, 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<MutableGraph>()) { ++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<MutableGraph>()) { ++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: }