marci@174
|
1 |
// -*- c++ -*-
|
marci@174
|
2 |
#include <iostream>
|
marci@174
|
3 |
#include <fstream>
|
marci@174
|
4 |
#include <string>
|
marci@174
|
5 |
|
marci@174
|
6 |
#include <list_graph.h>
|
marci@174
|
7 |
#include <smart_graph.h>
|
marci@174
|
8 |
#include <dimacs.h>
|
marci@480
|
9 |
#include <max_flow.h>
|
marci@174
|
10 |
#include <time_measure.h>
|
marci@334
|
11 |
#include <for_each_macros.h>
|
marci@174
|
12 |
|
marci@174
|
13 |
using namespace hugo;
|
marci@174
|
14 |
|
marci@174
|
15 |
// Use a DIMACS max flow file as stdin.
|
marci@174
|
16 |
// read_dimacs_demo dimacs_max_flow_file
|
marci@174
|
17 |
|
marci@174
|
18 |
int main(int, char** argv) {
|
marci@174
|
19 |
|
marci@174
|
20 |
std::string in=argv[1];
|
marci@174
|
21 |
typedef ListGraph MutableGraph;
|
marci@174
|
22 |
|
marci@174
|
23 |
{
|
marci@174
|
24 |
typedef ListGraph Graph;
|
marci@174
|
25 |
typedef Graph::Node Node;
|
marci@174
|
26 |
typedef Graph::EdgeIt EdgeIt;
|
marci@174
|
27 |
|
marci@174
|
28 |
Graph G;
|
marci@174
|
29 |
Node s, t;
|
marci@174
|
30 |
Graph::EdgeMap<int> cap(G);
|
marci@174
|
31 |
std::ifstream ins(in.c_str());
|
marci@174
|
32 |
readDimacsMaxFlow(ins, G, s, t, cap);
|
marci@174
|
33 |
|
marci@334
|
34 |
Timer ts;
|
marci@334
|
35 |
Graph::EdgeMap<int> flow(G); //0 flow
|
marci@334
|
36 |
MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
|
marci@476
|
37 |
max_flow_test(G, s, t, cap, flow/*, true*/);
|
marci@334
|
38 |
|
marci@334
|
39 |
std::cout << "ListGraph ..." << std::endl;
|
marci@334
|
40 |
|
marci@174
|
41 |
{
|
marci@334
|
42 |
std::cout << "preflow ..." << std::endl;
|
marci@334
|
43 |
ts.reset();
|
marci@476
|
44 |
max_flow_test.run();
|
marci@334
|
45 |
std::cout << "elapsed time: " << ts << std::endl;
|
marci@476
|
46 |
std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
|
marci@334
|
47 |
}
|
marci@174
|
48 |
|
marci@334
|
49 |
{
|
marci@334
|
50 |
std::cout << "physical blocking flow augmentation ..." << std::endl;
|
marci@334
|
51 |
FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
|
marci@174
|
52 |
ts.reset();
|
marci@174
|
53 |
int i=0;
|
marci@174
|
54 |
while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
|
marci@174
|
55 |
std::cout << "elapsed time: " << ts << std::endl;
|
marci@174
|
56 |
std::cout << "number of augmentation phases: " << i << std::endl;
|
marci@174
|
57 |
std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
|
marci@174
|
58 |
}
|
marci@174
|
59 |
|
marci@476
|
60 |
// {
|
marci@476
|
61 |
// std::cout << "faster physical blocking flow augmentation ..." << std::endl;
|
marci@476
|
62 |
// FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
|
marci@476
|
63 |
// ts.reset();
|
marci@476
|
64 |
// int i=0;
|
marci@476
|
65 |
// while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; }
|
marci@476
|
66 |
// std::cout << "elapsed time: " << ts << std::endl;
|
marci@476
|
67 |
// std::cout << "number of augmentation phases: " << i << std::endl;
|
marci@476
|
68 |
// std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
|
marci@476
|
69 |
// }
|
marci@174
|
70 |
|
marci@174
|
71 |
{
|
marci@334
|
72 |
std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
|
marci@334
|
73 |
FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
|
marci@334
|
74 |
ts.reset();
|
marci@334
|
75 |
int i=0;
|
marci@334
|
76 |
while (max_flow_test.augmentOnBlockingFlow2()) { ++i; }
|
marci@334
|
77 |
std::cout << "elapsed time: " << ts << std::endl;
|
marci@334
|
78 |
std::cout << "number of augmentation phases: " << i << std::endl;
|
marci@334
|
79 |
std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
|
marci@334
|
80 |
}
|
marci@174
|
81 |
|
marci@334
|
82 |
{
|
marci@334
|
83 |
std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
|
marci@334
|
84 |
FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
|
marci@174
|
85 |
ts.reset();
|
marci@174
|
86 |
int i=0;
|
marci@174
|
87 |
while (max_flow_test.augmentOnShortestPath()) { ++i; }
|
marci@174
|
88 |
std::cout << "elapsed time: " << ts << std::endl;
|
marci@174
|
89 |
std::cout << "number of augmentation phases: " << i << std::endl;
|
marci@174
|
90 |
std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
|
marci@174
|
91 |
}
|
marci@174
|
92 |
}
|
marci@174
|
93 |
|
marci@174
|
94 |
|
marci@174
|
95 |
{
|
marci@174
|
96 |
typedef SmartGraph Graph;
|
marci@174
|
97 |
typedef Graph::Node Node;
|
marci@174
|
98 |
typedef Graph::EdgeIt EdgeIt;
|
marci@174
|
99 |
|
marci@174
|
100 |
Graph G;
|
marci@174
|
101 |
Node s, t;
|
marci@174
|
102 |
Graph::EdgeMap<int> cap(G);
|
marci@174
|
103 |
std::ifstream ins(in.c_str());
|
marci@174
|
104 |
readDimacsMaxFlow(ins, G, s, t, cap);
|
marci@174
|
105 |
|
marci@334
|
106 |
Timer ts;
|
marci@334
|
107 |
Graph::EdgeMap<int> flow(G); //0 flow
|
marci@334
|
108 |
MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
|
marci@476
|
109 |
max_flow_test(G, s, t, cap, flow/*, true*/);
|
marci@476
|
110 |
// MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
|
marci@476
|
111 |
// max_flow_test(G, s, t, cap, flow);
|
marci@334
|
112 |
|
marci@334
|
113 |
std::cout << "SmatrGraph ..." << std::endl;
|
marci@334
|
114 |
|
marci@174
|
115 |
{
|
marci@334
|
116 |
std::cout << "preflow ..." << std::endl;
|
marci@334
|
117 |
FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
|
marci@334
|
118 |
ts.reset();
|
marci@476
|
119 |
max_flow_test.run();
|
marci@334
|
120 |
std::cout << "elapsed time: " << ts << std::endl;
|
marci@476
|
121 |
std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
|
marci@334
|
122 |
}
|
marci@174
|
123 |
|
marci@334
|
124 |
{
|
marci@334
|
125 |
std::cout << "physical blocking flow augmentation ..." << std::endl;
|
marci@334
|
126 |
FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
|
marci@174
|
127 |
ts.reset();
|
marci@174
|
128 |
int i=0;
|
marci@174
|
129 |
while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
|
marci@174
|
130 |
std::cout << "elapsed time: " << ts << std::endl;
|
marci@174
|
131 |
std::cout << "number of augmentation phases: " << i << std::endl;
|
marci@174
|
132 |
std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
|
marci@174
|
133 |
}
|
marci@174
|
134 |
|
marci@476
|
135 |
// {
|
marci@476
|
136 |
// std::cout << "faster physical blocking flow augmentation ..." << std::endl;
|
marci@476
|
137 |
// FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
|
marci@476
|
138 |
// ts.reset();
|
marci@476
|
139 |
// int i=0;
|
marci@476
|
140 |
// while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; }
|
marci@476
|
141 |
// std::cout << "elapsed time: " << ts << std::endl;
|
marci@476
|
142 |
// std::cout << "number of augmentation phases: " << i << std::endl;
|
marci@476
|
143 |
// std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
|
marci@476
|
144 |
// }
|
marci@174
|
145 |
|
marci@174
|
146 |
{
|
marci@334
|
147 |
std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
|
marci@334
|
148 |
FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
|
marci@334
|
149 |
ts.reset();
|
marci@334
|
150 |
int i=0;
|
marci@334
|
151 |
while (max_flow_test.augmentOnBlockingFlow2()) { ++i; }
|
marci@334
|
152 |
std::cout << "elapsed time: " << ts << std::endl;
|
marci@334
|
153 |
std::cout << "number of augmentation phases: " << i << std::endl;
|
marci@334
|
154 |
std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
|
marci@334
|
155 |
}
|
marci@174
|
156 |
|
marci@334
|
157 |
{
|
marci@334
|
158 |
std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
|
marci@334
|
159 |
FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
|
marci@174
|
160 |
ts.reset();
|
marci@174
|
161 |
int i=0;
|
marci@174
|
162 |
while (max_flow_test.augmentOnShortestPath()) { ++i; }
|
marci@174
|
163 |
std::cout << "elapsed time: " << ts << std::endl;
|
marci@174
|
164 |
std::cout << "number of augmentation phases: " << i << std::endl;
|
marci@174
|
165 |
std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
|
marci@174
|
166 |
}
|
marci@174
|
167 |
}
|
marci@174
|
168 |
|
marci@334
|
169 |
|
marci@334
|
170 |
|
marci@334
|
171 |
|
marci@174
|
172 |
return 0;
|
marci@174
|
173 |
}
|