[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> |
---|
[266] | 12 | |
---|
[105] | 13 | using namespace hugo; |
---|
[73] | 14 | |
---|
| 15 | // Use a DIMACS max flow file as stdin. |
---|
| 16 | // read_dimacs_demo < dimacs_max_flow_file |
---|
[139] | 17 | |
---|
[174] | 18 | |
---|
| 19 | // struct Ize { |
---|
| 20 | // }; |
---|
[139] | 21 | |
---|
[174] | 22 | // struct Mize { |
---|
| 23 | // Ize bumm; |
---|
| 24 | // }; |
---|
[139] | 25 | |
---|
[174] | 26 | // template <typename B> |
---|
| 27 | // class Huha { |
---|
| 28 | // public: |
---|
| 29 | // int u; |
---|
| 30 | // B brr; |
---|
| 31 | // }; |
---|
| 32 | |
---|
[139] | 33 | |
---|
[73] | 34 | int main(int, char **) { |
---|
| 35 | |
---|
[174] | 36 | typedef ListGraph MutableGraph; |
---|
[139] | 37 | |
---|
[305] | 38 | typedef SmartGraph Graph; |
---|
| 39 | //typedef ListGraph Graph; |
---|
[174] | 40 | typedef Graph::Node Node; |
---|
| 41 | typedef Graph::EdgeIt EdgeIt; |
---|
[139] | 42 | |
---|
| 43 | |
---|
[174] | 44 | // Mize mize[10]; |
---|
| 45 | // Mize bize[0]; |
---|
| 46 | // Mize zize; |
---|
| 47 | // typedef Mize Tize[0]; |
---|
[146] | 48 | |
---|
[174] | 49 | // std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl; |
---|
| 50 | // std::cout << sizeof(bize) << std::endl; |
---|
[146] | 51 | |
---|
| 52 | |
---|
[174] | 53 | // Huha<Tize> k; |
---|
| 54 | // std::cout << sizeof(k) << std::endl; |
---|
[139] | 55 | |
---|
[174] | 56 | |
---|
| 57 | // struct Bumm { |
---|
| 58 | // //int a; |
---|
| 59 | // bool b; |
---|
| 60 | // }; |
---|
| 61 | |
---|
| 62 | // std::cout << sizeof(Bumm) << std::endl; |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | Graph G; |
---|
| 66 | Node s, t; |
---|
| 67 | Graph::EdgeMap<int> cap(G); |
---|
[73] | 68 | readDimacsMaxFlow(std::cin, G, s, t, cap); |
---|
[155] | 69 | |
---|
[174] | 70 | // typedef TrivGraphWrapper<Graph> TGW; |
---|
| 71 | // TGW gw(G); |
---|
| 72 | // TGW::NodeIt sw; |
---|
| 73 | // gw./*getF*/first(sw); |
---|
| 74 | // std::cout << "p1:" << gw.nodeNum() << std::endl; |
---|
| 75 | // gw.erase(sw); |
---|
| 76 | // std::cout << "p2:" << gw.nodeNum() << std::endl; |
---|
| 77 | |
---|
| 78 | // typedef const Graph cLG; |
---|
| 79 | // typedef TrivGraphWrapper<const cLG> CTGW; |
---|
| 80 | // CTGW cgw(G); |
---|
| 81 | // CTGW::NodeIt csw; |
---|
| 82 | // cgw./*getF*/first(csw); |
---|
| 83 | // std::cout << "p1:" << cgw.nodeNum() << std::endl; |
---|
| 84 | // //cgw.erase(csw); |
---|
| 85 | // std::cout << "p2:" << cgw.nodeNum() << std::endl; |
---|
| 86 | |
---|
[311] | 87 | { |
---|
| 88 | std::cout << "preflow ..." << std::endl; |
---|
| 89 | Graph::EdgeMap<int> flow(G); //0 flow |
---|
| 90 | |
---|
| 91 | Timer ts; |
---|
| 92 | ts.reset(); |
---|
| 93 | |
---|
| 94 | Preflow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > |
---|
| 95 | max_flow_test(G, s, t, cap, flow); |
---|
| 96 | max_flow_test.run(); |
---|
| 97 | // int i=0; |
---|
| 98 | // while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { |
---|
| 99 | // for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { |
---|
| 100 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
| 101 | // } |
---|
| 102 | // std::cout<<std::endl; |
---|
| 103 | // ++i; |
---|
| 104 | // } |
---|
| 105 | |
---|
| 106 | // std::cout << "maximum flow: "<< std::endl; |
---|
| 107 | // for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { |
---|
| 108 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
| 109 | // } |
---|
| 110 | // std::cout<<std::endl; |
---|
| 111 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 112 | // std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 113 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 114 | } |
---|
[73] | 115 | |
---|
[133] | 116 | { |
---|
[311] | 117 | std::cout << "physical blocking flow augmentation ..." << std::endl; |
---|
[303] | 118 | Graph::EdgeMap<int> flow(G); //0 flow |
---|
[73] | 119 | |
---|
[174] | 120 | Timer ts; |
---|
| 121 | ts.reset(); |
---|
| 122 | |
---|
[303] | 123 | MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > |
---|
| 124 | max_flow_test(G, s, t, flow, cap); |
---|
[174] | 125 | int i=0; |
---|
| 126 | while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { |
---|
| 127 | // for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { |
---|
[168] | 128 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
| 129 | // } |
---|
| 130 | // std::cout<<std::endl; |
---|
[174] | 131 | ++i; |
---|
| 132 | } |
---|
[168] | 133 | |
---|
[174] | 134 | // std::cout << "maximum flow: "<< std::endl; |
---|
| 135 | // for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { |
---|
| 136 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
| 137 | // } |
---|
| 138 | // std::cout<<std::endl; |
---|
| 139 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 140 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 141 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
[168] | 142 | } |
---|
| 143 | |
---|
[268] | 144 | { |
---|
[311] | 145 | std::cout << "faster physical blocking flow augmentation ..." << std::endl; |
---|
[303] | 146 | Graph::EdgeMap<int> flow(G); //0 flow |
---|
[266] | 147 | |
---|
[268] | 148 | Timer ts; |
---|
| 149 | ts.reset(); |
---|
[266] | 150 | |
---|
[303] | 151 | MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > |
---|
| 152 | max_flow_test(G, s, t, flow, cap); |
---|
[268] | 153 | int i=0; |
---|
| 154 | while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { |
---|
| 155 | // for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { |
---|
| 156 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
[266] | 157 | // } |
---|
[268] | 158 | // std::cout<<std::endl; |
---|
| 159 | ++i; |
---|
| 160 | } |
---|
[266] | 161 | |
---|
[268] | 162 | // std::cout << "maximum flow: "<< std::endl; |
---|
| 163 | // for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { |
---|
| 164 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
[266] | 165 | // } |
---|
[268] | 166 | // std::cout<<std::endl; |
---|
| 167 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 168 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 169 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 170 | } |
---|
[266] | 171 | |
---|
[269] | 172 | { |
---|
[311] | 173 | std::cout << "on-the-fly blocking flow augmentation ..." << std::endl; |
---|
[303] | 174 | Graph::EdgeMap<int> flow(G); //0 flow |
---|
[266] | 175 | |
---|
[269] | 176 | Timer ts; |
---|
| 177 | ts.reset(); |
---|
[266] | 178 | |
---|
[303] | 179 | MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > |
---|
| 180 | max_flow_test(G, s, t, flow, cap); |
---|
[269] | 181 | int i=0; |
---|
| 182 | while (max_flow_test.augmentOnBlockingFlow2()) { |
---|
| 183 | // for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { |
---|
| 184 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
[266] | 185 | // } |
---|
[269] | 186 | // std::cout<<std::endl; |
---|
| 187 | ++i; |
---|
| 188 | } |
---|
[266] | 189 | |
---|
[269] | 190 | // std::cout << "maximum flow: "<< std::endl; |
---|
| 191 | // for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { |
---|
| 192 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
[266] | 193 | // } |
---|
[269] | 194 | // std::cout<<std::endl; |
---|
| 195 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 196 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 197 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 198 | } |
---|
[266] | 199 | |
---|
[168] | 200 | { |
---|
[311] | 201 | std::cout << "on-the-fly shortest path augmentation ..." << std::endl; |
---|
[303] | 202 | Graph::EdgeMap<int> flow(G); //0 flow |
---|
[206] | 203 | |
---|
| 204 | Timer ts; |
---|
| 205 | ts.reset(); |
---|
| 206 | |
---|
[303] | 207 | MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > |
---|
| 208 | max_flow_test(G, s, t, flow, cap); |
---|
[174] | 209 | int i=0; |
---|
| 210 | while (max_flow_test.augmentOnShortestPath()) { |
---|
| 211 | // for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { |
---|
[168] | 212 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
| 213 | // } |
---|
| 214 | // std::cout<<std::endl; |
---|
[174] | 215 | ++i; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | // std::cout << "maximum flow: "<< std::endl; |
---|
| 219 | // for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { |
---|
| 220 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
| 221 | // } |
---|
| 222 | // std::cout<<std::endl; |
---|
| 223 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 224 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 225 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
[168] | 226 | } |
---|
[133] | 227 | |
---|
[73] | 228 | |
---|
| 229 | return 0; |
---|
| 230 | } |
---|