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