[174] | 1 | // -*- c++ -*- |
---|
[73] | 2 | #include <iostream> |
---|
| 3 | #include <fstream> |
---|
| 4 | |
---|
[174] | 5 | #include <list_graph.h> |
---|
[305] | 6 | #include <smart_graph.h> |
---|
[174] | 7 | #include <dimacs.h> |
---|
| 8 | #include <edmonds_karp.h> |
---|
[73] | 9 | #include <time_measure.h> |
---|
[303] | 10 | //#include <graph_wrapper.h> |
---|
[311] | 11 | #include <preflow.h> |
---|
[333] | 12 | #include <for_each_macros.h> |
---|
[266] | 13 | |
---|
[105] | 14 | using namespace hugo; |
---|
[73] | 15 | |
---|
| 16 | // Use a DIMACS max flow file as stdin. |
---|
| 17 | // read_dimacs_demo < dimacs_max_flow_file |
---|
[139] | 18 | |
---|
[174] | 19 | |
---|
| 20 | // struct Ize { |
---|
| 21 | // }; |
---|
[139] | 22 | |
---|
[174] | 23 | // struct Mize { |
---|
| 24 | // Ize bumm; |
---|
| 25 | // }; |
---|
[139] | 26 | |
---|
[174] | 27 | // template <typename B> |
---|
| 28 | // class Huha { |
---|
| 29 | // public: |
---|
| 30 | // int u; |
---|
| 31 | // B brr; |
---|
| 32 | // }; |
---|
| 33 | |
---|
[139] | 34 | |
---|
[73] | 35 | int main(int, char **) { |
---|
| 36 | |
---|
[174] | 37 | typedef ListGraph MutableGraph; |
---|
[139] | 38 | |
---|
[317] | 39 | // typedef SmartGraph Graph; |
---|
| 40 | typedef ListGraph Graph; |
---|
[174] | 41 | typedef Graph::Node Node; |
---|
| 42 | typedef Graph::EdgeIt EdgeIt; |
---|
[139] | 43 | |
---|
| 44 | |
---|
[174] | 45 | // Mize mize[10]; |
---|
| 46 | // Mize bize[0]; |
---|
| 47 | // Mize zize; |
---|
| 48 | // typedef Mize Tize[0]; |
---|
[146] | 49 | |
---|
[174] | 50 | // std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl; |
---|
| 51 | // std::cout << sizeof(bize) << std::endl; |
---|
[146] | 52 | |
---|
| 53 | |
---|
[174] | 54 | // Huha<Tize> k; |
---|
| 55 | // std::cout << sizeof(k) << std::endl; |
---|
[139] | 56 | |
---|
[174] | 57 | |
---|
| 58 | // struct Bumm { |
---|
| 59 | // //int a; |
---|
| 60 | // bool b; |
---|
| 61 | // }; |
---|
| 62 | |
---|
| 63 | // std::cout << sizeof(Bumm) << std::endl; |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | Graph G; |
---|
| 67 | Node s, t; |
---|
| 68 | Graph::EdgeMap<int> cap(G); |
---|
[73] | 69 | readDimacsMaxFlow(std::cin, G, s, t, cap); |
---|
[333] | 70 | Timer ts; |
---|
| 71 | Graph::EdgeMap<int> flow(G); //0 flow |
---|
| 72 | Preflow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > |
---|
| 73 | pre_flow_test(G, s, t, cap, flow); |
---|
| 74 | MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > |
---|
| 75 | max_flow_test(G, s, t, cap, flow); |
---|
[155] | 76 | |
---|
[311] | 77 | { |
---|
| 78 | std::cout << "preflow ..." << std::endl; |
---|
| 79 | ts.reset(); |
---|
[333] | 80 | pre_flow_test.run(); |
---|
[311] | 81 | std::cout << "elapsed time: " << ts << std::endl; |
---|
[333] | 82 | std::cout << "flow value: "<< pre_flow_test.flowValue() << std::endl; |
---|
[311] | 83 | } |
---|
[73] | 84 | |
---|
[133] | 85 | { |
---|
[311] | 86 | std::cout << "physical blocking flow augmentation ..." << std::endl; |
---|
[333] | 87 | FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0); |
---|
[174] | 88 | ts.reset(); |
---|
| 89 | int i=0; |
---|
[333] | 90 | while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; } |
---|
[174] | 91 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 92 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 93 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
[168] | 94 | } |
---|
| 95 | |
---|
[268] | 96 | { |
---|
[311] | 97 | std::cout << "faster physical blocking flow augmentation ..." << std::endl; |
---|
[333] | 98 | FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0); |
---|
[268] | 99 | ts.reset(); |
---|
| 100 | int i=0; |
---|
[333] | 101 | while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; } |
---|
[268] | 102 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 103 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 104 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 105 | } |
---|
[266] | 106 | |
---|
[269] | 107 | { |
---|
[311] | 108 | std::cout << "on-the-fly blocking flow augmentation ..." << std::endl; |
---|
[333] | 109 | FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0); |
---|
[269] | 110 | ts.reset(); |
---|
| 111 | int i=0; |
---|
[333] | 112 | while (max_flow_test.augmentOnBlockingFlow2()) { ++i; } |
---|
[269] | 113 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 114 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 115 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 116 | } |
---|
[266] | 117 | |
---|
[168] | 118 | { |
---|
[311] | 119 | std::cout << "on-the-fly shortest path augmentation ..." << std::endl; |
---|
[333] | 120 | FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0); |
---|
[206] | 121 | ts.reset(); |
---|
[174] | 122 | int i=0; |
---|
[333] | 123 | while (max_flow_test.augmentOnShortestPath()) { ++i; } |
---|
[174] | 124 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 125 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 126 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
[168] | 127 | } |
---|
[133] | 128 | |
---|
[73] | 129 | |
---|
| 130 | return 0; |
---|
| 131 | } |
---|