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