5 #include <list_graph.h>
6 #include <smart_graph.h>
8 #include <edmonds_karp.h>
9 #include <time_measure.h>
10 //#include <graph_wrapper.h>
15 // Use a DIMACS max flow file as stdin.
16 // read_dimacs_demo < dimacs_max_flow_file
26 // template <typename B>
34 int main(int, char **) {
36 typedef ListGraph MutableGraph;
38 typedef SmartGraph Graph;
39 //typedef ListGraph Graph;
40 typedef Graph::Node Node;
41 typedef Graph::EdgeIt EdgeIt;
47 // typedef Mize Tize[0];
49 // std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl;
50 // std::cout << sizeof(bize) << std::endl;
54 // std::cout << sizeof(k) << std::endl;
62 // std::cout << sizeof(Bumm) << std::endl;
67 Graph::EdgeMap<int> cap(G);
68 readDimacsMaxFlow(std::cin, G, s, t, cap);
70 // typedef TrivGraphWrapper<Graph> TGW;
73 // gw./*getF*/first(sw);
74 // std::cout << "p1:" << gw.nodeNum() << std::endl;
76 // std::cout << "p2:" << gw.nodeNum() << std::endl;
78 // typedef const Graph cLG;
79 // typedef TrivGraphWrapper<const cLG> CTGW;
82 // cgw./*getF*/first(csw);
83 // std::cout << "p1:" << cgw.nodeNum() << std::endl;
85 // std::cout << "p2:" << cgw.nodeNum() << std::endl;
88 std::cout << "preflow ..." << std::endl;
89 Graph::EdgeMap<int> flow(G); //0 flow
94 Preflow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
95 max_flow_test(G, s, t, cap, flow);
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)<<") ";
102 // std::cout<<std::endl;
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)<<") ";
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;
117 std::cout << "physical blocking flow augmentation ..." << std::endl;
118 Graph::EdgeMap<int> flow(G); //0 flow
123 MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
124 max_flow_test(G, s, t, flow, cap);
126 while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) {
127 // for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
128 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
130 // std::cout<<std::endl;
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)<<") ";
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;
145 std::cout << "faster physical blocking flow augmentation ..." << std::endl;
146 Graph::EdgeMap<int> flow(G); //0 flow
151 MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
152 max_flow_test(G, s, t, flow, cap);
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)<<") ";
158 // std::cout<<std::endl;
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)<<") ";
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;
173 std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
174 Graph::EdgeMap<int> flow(G); //0 flow
179 MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
180 max_flow_test(G, s, t, flow, cap);
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)<<") ";
186 // std::cout<<std::endl;
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)<<") ";
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;
201 std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
202 Graph::EdgeMap<int> flow(G); //0 flow
207 MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
208 max_flow_test(G, s, t, flow, cap);
210 while (max_flow_test.augmentOnShortestPath()) {
211 // for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
212 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
214 // std::cout<<std::endl;
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)<<") ";
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;