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