5 #include <list_graph.h>
6 //#include <smart_graph.h>
8 #include <edmonds_karp_1.h>
9 #include <time_measure.h>
10 #include <graph_wrapper_1.h>
14 template<typename T> int get(T) const {return 1;}
17 using namespace lemon;
19 // Use a DIMACS max flow file as stdin.
20 // read_dimacs_demo < dimacs_max_flow_file
30 // template <typename B>
38 int main(int, char **) {
40 typedef ListGraph MutableGraph;
42 //typedef SmartGraph Graph;
43 typedef ListGraph Graph;
44 typedef Graph::Node Node;
45 typedef Graph::EdgeIt EdgeIt;
51 // typedef Mize Tize[0];
53 // std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl;
54 // std::cout << sizeof(bize) << std::endl;
58 // std::cout << sizeof(k) << std::endl;
66 // std::cout << sizeof(Bumm) << std::endl;
71 Graph::EdgeMap<int> cap(G);
72 readDimacsMaxFlow(std::cin, G, s, t, cap);
74 // typedef TrivGraphWrapper<Graph> TGW;
77 // gw./*getF*/first(sw);
78 // std::cout << "p1:" << gw.nodeNum() << std::endl;
80 // std::cout << "p2:" << gw.nodeNum() << std::endl;
82 // typedef const Graph cLG;
83 // typedef TrivGraphWrapper<const cLG> CTGW;
86 // cgw./*getF*/first(csw);
87 // std::cout << "p1:" << cgw.nodeNum() << std::endl;
89 // std::cout << "p2:" << cgw.nodeNum() << std::endl;
93 typedef TrivGraphWrapper<const Graph> GW;
95 std::cout << "edmonds karp demo (physical blocking flow augmentation)..." << std::endl;
96 GW::EdgeMap<int> flow(gw); //0 flow
101 typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
103 MaxFlow<GW, int, GW::EdgeMap<int>, EMW > max_flow_test(gw, s, t, flow, cw);
105 while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) {
106 // for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
107 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
109 // std::cout<<std::endl;
113 // std::cout << "maximum flow: "<< std::endl;
114 // for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) {
115 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
117 // std::cout<<std::endl;
118 std::cout << "elapsed time: " << ts << std::endl;
119 std::cout << "number of augmentation phases: " << i << std::endl;
120 std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
124 typedef TrivGraphWrapper<const Graph> GW;
126 std::cout << "edmonds karp demo (physical blocking flow 1 augmentation)..." << std::endl;
127 GW::EdgeMap<int> flow(gw); //0 flow
132 typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
134 MaxFlow<GW, int, GW::EdgeMap<int>, EMW > max_flow_test(gw, s, t, flow, cw);
136 while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
137 // for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
138 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
140 // std::cout<<std::endl;
144 // std::cout << "maximum flow: "<< std::endl;
145 // for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) {
146 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
148 // std::cout<<std::endl;
149 std::cout << "elapsed time: " << ts << std::endl;
150 std::cout << "number of augmentation phases: " << i << std::endl;
151 std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
155 typedef TrivGraphWrapper<const Graph> GW;
157 std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl;
158 GW::EdgeMap<int> flow(gw); //0 flow
163 typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
165 MaxFlow<GW, int, GW::EdgeMap<int>, EMW > max_flow_test(gw, s, t, flow, cw);
167 while (max_flow_test.augmentOnBlockingFlow2()) {
168 // for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
169 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
171 // std::cout<<std::endl;
175 // std::cout << "maximum flow: "<< std::endl;
176 // for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) {
177 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
179 // std::cout<<std::endl;
180 std::cout << "elapsed time: " << ts << std::endl;
181 std::cout << "number of augmentation phases: " << i << std::endl;
182 std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
186 typedef TrivGraphWrapper<const Graph> GW;
188 std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl;
189 GW::EdgeMap<int> flow(gw); //0 flow
194 typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
196 MaxFlow<GW, int, GW::EdgeMap<int>, EMW> max_flow_test(gw, s, t, flow, cw);
198 while (max_flow_test.augmentOnShortestPath()) {
199 // for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
200 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
202 // std::cout<<std::endl;
206 // std::cout << "maximum flow: "<< std::endl;
207 // for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) {
208 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
210 // std::cout<<std::endl;
211 std::cout << "elapsed time: " << ts << std::endl;
212 std::cout << "number of augmentation phases: " << i << std::endl;
213 std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;