[174] | 1 | // -*- c++ -*- |
---|
| 2 | #include <iostream> |
---|
| 3 | #include <fstream> |
---|
| 4 | #include <string> |
---|
| 5 | |
---|
[642] | 6 | #include <sage_graph.h> |
---|
| 7 | #include <hugo/list_graph.h> |
---|
[555] | 8 | #include <hugo/smart_graph.h> |
---|
| 9 | #include <hugo/dimacs.h> |
---|
[480] | 10 | #include <max_flow.h> |
---|
[555] | 11 | #include <hugo/time_measure.h> |
---|
[640] | 12 | #include <hugo/for_each_macros.h> |
---|
[174] | 13 | |
---|
| 14 | using namespace hugo; |
---|
| 15 | |
---|
| 16 | // Use a DIMACS max flow file as stdin. |
---|
| 17 | // read_dimacs_demo dimacs_max_flow_file |
---|
| 18 | |
---|
| 19 | int main(int, char** argv) { |
---|
| 20 | |
---|
| 21 | std::string in=argv[1]; |
---|
[642] | 22 | typedef SageGraph MutableGraph; |
---|
[174] | 23 | |
---|
| 24 | { |
---|
[642] | 25 | typedef SageGraph Graph; |
---|
[174] | 26 | typedef Graph::Node Node; |
---|
| 27 | typedef Graph::EdgeIt EdgeIt; |
---|
| 28 | |
---|
[577] | 29 | Graph g; |
---|
[174] | 30 | Node s, t; |
---|
[577] | 31 | Graph::EdgeMap<int> cap(g); |
---|
[174] | 32 | std::ifstream ins(in.c_str()); |
---|
[577] | 33 | //readDimacsMaxFlow(ins, g, s, t, cap); |
---|
| 34 | readDimacs(ins, g, cap, s, t); |
---|
[174] | 35 | |
---|
[334] | 36 | Timer ts; |
---|
[577] | 37 | Graph::EdgeMap<int> flow(g); //0 flow |
---|
[334] | 38 | MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > |
---|
[577] | 39 | max_flow_test(g, s, t, cap, flow/*, true*/); |
---|
[334] | 40 | |
---|
[642] | 41 | std::cout << "SageGraph ..." << std::endl; |
---|
[334] | 42 | |
---|
[174] | 43 | { |
---|
[334] | 44 | std::cout << "preflow ..." << std::endl; |
---|
| 45 | ts.reset(); |
---|
[476] | 46 | max_flow_test.run(); |
---|
[334] | 47 | std::cout << "elapsed time: " << ts << std::endl; |
---|
[476] | 48 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
[334] | 49 | } |
---|
[174] | 50 | |
---|
[334] | 51 | { |
---|
| 52 | std::cout << "physical blocking flow augmentation ..." << std::endl; |
---|
[577] | 53 | FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); |
---|
[174] | 54 | ts.reset(); |
---|
| 55 | int i=0; |
---|
| 56 | while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; } |
---|
| 57 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 58 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 59 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 60 | } |
---|
| 61 | |
---|
[476] | 62 | // { |
---|
| 63 | // std::cout << "faster physical blocking flow augmentation ..." << std::endl; |
---|
[577] | 64 | // FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); |
---|
[476] | 65 | // ts.reset(); |
---|
| 66 | // int i=0; |
---|
| 67 | // while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; } |
---|
| 68 | // std::cout << "elapsed time: " << ts << std::endl; |
---|
| 69 | // std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 70 | // std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 71 | // } |
---|
[174] | 72 | |
---|
| 73 | { |
---|
[334] | 74 | std::cout << "on-the-fly blocking flow augmentation ..." << std::endl; |
---|
[577] | 75 | FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); |
---|
[334] | 76 | ts.reset(); |
---|
| 77 | int i=0; |
---|
| 78 | while (max_flow_test.augmentOnBlockingFlow2()) { ++i; } |
---|
| 79 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 80 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 81 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 82 | } |
---|
[174] | 83 | |
---|
[334] | 84 | { |
---|
| 85 | std::cout << "on-the-fly shortest path augmentation ..." << std::endl; |
---|
[577] | 86 | FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); |
---|
[174] | 87 | ts.reset(); |
---|
| 88 | int i=0; |
---|
| 89 | while (max_flow_test.augmentOnShortestPath()) { ++i; } |
---|
| 90 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 91 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 92 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | { |
---|
| 97 | typedef SmartGraph Graph; |
---|
| 98 | typedef Graph::Node Node; |
---|
| 99 | typedef Graph::EdgeIt EdgeIt; |
---|
| 100 | |
---|
[577] | 101 | Graph g; |
---|
[174] | 102 | Node s, t; |
---|
[577] | 103 | Graph::EdgeMap<int> cap(g); |
---|
[174] | 104 | std::ifstream ins(in.c_str()); |
---|
[577] | 105 | //readDimacsMaxFlow(ins, g, s, t, cap); |
---|
| 106 | readDimacs(ins, g, cap, s, t); |
---|
[174] | 107 | |
---|
[334] | 108 | Timer ts; |
---|
[577] | 109 | Graph::EdgeMap<int> flow(g); //0 flow |
---|
[334] | 110 | MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > |
---|
[577] | 111 | max_flow_test(g, s, t, cap, flow/*, true*/); |
---|
[476] | 112 | // MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > |
---|
[577] | 113 | // max_flow_test(g, s, t, cap, flow); |
---|
[334] | 114 | |
---|
[642] | 115 | std::cout << "SmartGraph ..." << std::endl; |
---|
[334] | 116 | |
---|
[174] | 117 | { |
---|
[334] | 118 | std::cout << "preflow ..." << std::endl; |
---|
[577] | 119 | FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); |
---|
[334] | 120 | ts.reset(); |
---|
[476] | 121 | max_flow_test.run(); |
---|
[334] | 122 | std::cout << "elapsed time: " << ts << std::endl; |
---|
[476] | 123 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
[334] | 124 | } |
---|
[174] | 125 | |
---|
[334] | 126 | { |
---|
| 127 | std::cout << "physical blocking flow augmentation ..." << std::endl; |
---|
[577] | 128 | FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); |
---|
[174] | 129 | ts.reset(); |
---|
| 130 | int i=0; |
---|
| 131 | while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; } |
---|
| 132 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 133 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 134 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 135 | } |
---|
| 136 | |
---|
[476] | 137 | // { |
---|
| 138 | // std::cout << "faster physical blocking flow augmentation ..." << std::endl; |
---|
[577] | 139 | // FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); |
---|
[476] | 140 | // ts.reset(); |
---|
| 141 | // int i=0; |
---|
| 142 | // while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; } |
---|
| 143 | // std::cout << "elapsed time: " << ts << std::endl; |
---|
| 144 | // std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 145 | // std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 146 | // } |
---|
[174] | 147 | |
---|
| 148 | { |
---|
[334] | 149 | std::cout << "on-the-fly blocking flow augmentation ..." << std::endl; |
---|
[577] | 150 | FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); |
---|
[334] | 151 | ts.reset(); |
---|
| 152 | int i=0; |
---|
| 153 | while (max_flow_test.augmentOnBlockingFlow2()) { ++i; } |
---|
| 154 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 155 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 156 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 157 | } |
---|
[174] | 158 | |
---|
[334] | 159 | { |
---|
| 160 | std::cout << "on-the-fly shortest path augmentation ..." << std::endl; |
---|
[577] | 161 | FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); |
---|
[174] | 162 | ts.reset(); |
---|
| 163 | int i=0; |
---|
| 164 | while (max_flow_test.augmentOnShortestPath()) { ++i; } |
---|
| 165 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 166 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 167 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | |
---|
[642] | 171 | { |
---|
| 172 | typedef ListGraph Graph; |
---|
| 173 | typedef Graph::Node Node; |
---|
| 174 | typedef Graph::EdgeIt EdgeIt; |
---|
| 175 | |
---|
| 176 | Graph g; |
---|
| 177 | Node s, t; |
---|
| 178 | Graph::EdgeMap<int> cap(g); |
---|
| 179 | std::ifstream ins(in.c_str()); |
---|
| 180 | //readDimacsMaxFlow(ins, g, s, t, cap); |
---|
| 181 | readDimacs(ins, g, cap, s, t); |
---|
| 182 | |
---|
| 183 | Timer ts; |
---|
| 184 | Graph::EdgeMap<int> flow(g); //0 flow |
---|
| 185 | MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > |
---|
| 186 | max_flow_test(g, s, t, cap, flow/*, true*/); |
---|
| 187 | // MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > |
---|
| 188 | // max_flow_test(g, s, t, cap, flow); |
---|
| 189 | |
---|
| 190 | std::cout << "ListGraph ..." << std::endl; |
---|
| 191 | |
---|
| 192 | { |
---|
| 193 | std::cout << "preflow ..." << std::endl; |
---|
| 194 | FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); |
---|
| 195 | ts.reset(); |
---|
| 196 | max_flow_test.run(); |
---|
| 197 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 198 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | { |
---|
| 202 | std::cout << "physical blocking flow augmentation ..." << std::endl; |
---|
| 203 | FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); |
---|
| 204 | ts.reset(); |
---|
| 205 | int i=0; |
---|
| 206 | while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; } |
---|
| 207 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 208 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 209 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | // { |
---|
| 213 | // std::cout << "faster physical blocking flow augmentation ..." << std::endl; |
---|
| 214 | // FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); |
---|
| 215 | // ts.reset(); |
---|
| 216 | // int i=0; |
---|
| 217 | // while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; } |
---|
| 218 | // std::cout << "elapsed time: " << ts << std::endl; |
---|
| 219 | // std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 220 | // std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 221 | // } |
---|
| 222 | |
---|
| 223 | { |
---|
| 224 | std::cout << "on-the-fly blocking flow augmentation ..." << std::endl; |
---|
| 225 | FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); |
---|
| 226 | ts.reset(); |
---|
| 227 | int i=0; |
---|
| 228 | while (max_flow_test.augmentOnBlockingFlow2()) { ++i; } |
---|
| 229 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 230 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 231 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | { |
---|
| 235 | std::cout << "on-the-fly shortest path augmentation ..." << std::endl; |
---|
| 236 | FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); |
---|
| 237 | ts.reset(); |
---|
| 238 | int i=0; |
---|
| 239 | while (max_flow_test.augmentOnShortestPath()) { ++i; } |
---|
| 240 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 241 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 242 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | |
---|
[334] | 246 | |
---|
| 247 | |
---|
| 248 | |
---|
[174] | 249 | return 0; |
---|
| 250 | } |
---|