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