alpar@404
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*-
|
alpar@404
|
2 |
*
|
alpar@404
|
3 |
* This file is a part of LEMON, a generic C++ optimization library.
|
alpar@404
|
4 |
*
|
alpar@1270
|
5 |
* Copyright (C) 2003-2013
|
alpar@404
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@404
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@404
|
8 |
*
|
alpar@404
|
9 |
* Permission to use, modify and distribute this software is granted
|
alpar@404
|
10 |
* provided that this copyright notice appears in all copies. For
|
alpar@404
|
11 |
* precise terms see the accompanying LICENSE file.
|
alpar@404
|
12 |
*
|
alpar@404
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@404
|
14 |
* express or implied, and with no claim as to its suitability for any
|
alpar@404
|
15 |
* purpose.
|
alpar@404
|
16 |
*
|
alpar@404
|
17 |
*/
|
alpar@404
|
18 |
|
alpar@442
|
19 |
#include <iostream>
|
alpar@404
|
20 |
|
alpar@404
|
21 |
#include "test_tools.h"
|
alpar@404
|
22 |
#include <lemon/smart_graph.h>
|
alpar@404
|
23 |
#include <lemon/preflow.h>
|
kpeter@1228
|
24 |
#include <lemon/edmonds_karp.h>
|
alpar@404
|
25 |
#include <lemon/concepts/digraph.h>
|
alpar@404
|
26 |
#include <lemon/concepts/maps.h>
|
alpar@404
|
27 |
#include <lemon/lgf_reader.h>
|
kpeter@409
|
28 |
#include <lemon/elevator.h>
|
kpeter@1383
|
29 |
#include <lemon/tolerance.h>
|
alpar@404
|
30 |
|
alpar@404
|
31 |
using namespace lemon;
|
alpar@404
|
32 |
|
alpar@442
|
33 |
char test_lgf[] =
|
alpar@442
|
34 |
"@nodes\n"
|
alpar@442
|
35 |
"label\n"
|
alpar@442
|
36 |
"0\n"
|
alpar@442
|
37 |
"1\n"
|
alpar@442
|
38 |
"2\n"
|
alpar@442
|
39 |
"3\n"
|
alpar@442
|
40 |
"4\n"
|
alpar@442
|
41 |
"5\n"
|
alpar@442
|
42 |
"6\n"
|
alpar@442
|
43 |
"7\n"
|
alpar@442
|
44 |
"8\n"
|
alpar@442
|
45 |
"9\n"
|
alpar@442
|
46 |
"@arcs\n"
|
alpar@442
|
47 |
" label capacity\n"
|
alpar@442
|
48 |
"0 1 0 20\n"
|
alpar@442
|
49 |
"0 2 1 0\n"
|
alpar@442
|
50 |
"1 1 2 3\n"
|
alpar@442
|
51 |
"1 2 3 8\n"
|
alpar@442
|
52 |
"1 3 4 8\n"
|
alpar@442
|
53 |
"2 5 5 5\n"
|
alpar@442
|
54 |
"3 2 6 5\n"
|
alpar@442
|
55 |
"3 5 7 5\n"
|
alpar@442
|
56 |
"3 6 8 5\n"
|
alpar@442
|
57 |
"4 3 9 3\n"
|
alpar@442
|
58 |
"5 7 10 3\n"
|
alpar@442
|
59 |
"5 6 11 10\n"
|
alpar@442
|
60 |
"5 8 12 10\n"
|
alpar@442
|
61 |
"6 8 13 8\n"
|
alpar@442
|
62 |
"8 9 14 20\n"
|
alpar@442
|
63 |
"8 1 15 5\n"
|
alpar@442
|
64 |
"9 5 16 5\n"
|
alpar@442
|
65 |
"@attributes\n"
|
alpar@442
|
66 |
"source 1\n"
|
alpar@442
|
67 |
"target 8\n";
|
alpar@442
|
68 |
|
kpeter@1385
|
69 |
char test_lgf_float[] =
|
kpeter@1385
|
70 |
"@nodes\n"
|
kpeter@1385
|
71 |
"label\n"
|
kpeter@1385
|
72 |
"0\n"
|
kpeter@1385
|
73 |
"1\n"
|
kpeter@1385
|
74 |
"2\n"
|
kpeter@1385
|
75 |
"3\n"
|
kpeter@1385
|
76 |
"4\n"
|
kpeter@1385
|
77 |
"5\n"
|
kpeter@1385
|
78 |
"6\n"
|
kpeter@1385
|
79 |
"7\n"
|
kpeter@1385
|
80 |
"8\n"
|
kpeter@1385
|
81 |
"9\n"
|
kpeter@1385
|
82 |
"@arcs\n"
|
kpeter@1385
|
83 |
" capacity\n"
|
kpeter@1385
|
84 |
"0 1 0.1\n"
|
kpeter@1385
|
85 |
"0 2 0.1\n"
|
kpeter@1385
|
86 |
"0 3 0.1\n"
|
kpeter@1385
|
87 |
"1 4 0.1\n"
|
kpeter@1385
|
88 |
"2 4 0.1\n"
|
kpeter@1385
|
89 |
"3 4 0.1\n"
|
kpeter@1385
|
90 |
"4 5 0.3\n"
|
kpeter@1385
|
91 |
"5 6 0.1\n"
|
kpeter@1385
|
92 |
"5 7 0.1\n"
|
kpeter@1385
|
93 |
"5 8 0.1\n"
|
kpeter@1385
|
94 |
"6 9 0.1\n"
|
kpeter@1385
|
95 |
"7 9 0.1\n"
|
kpeter@1385
|
96 |
"8 9 0.1\n"
|
kpeter@1385
|
97 |
"@attributes\n"
|
kpeter@1385
|
98 |
"source 0\n"
|
kpeter@1385
|
99 |
"target 9\n";
|
kpeter@1385
|
100 |
|
kpeter@1228
|
101 |
// Checks the general interface of a max flow algorithm
|
kpeter@1228
|
102 |
template <typename GR, typename CAP>
|
kpeter@1228
|
103 |
struct MaxFlowClassConcept
|
kpeter@1228
|
104 |
{
|
kpeter@1228
|
105 |
|
kpeter@1228
|
106 |
template <typename MF>
|
kpeter@1228
|
107 |
struct Constraints {
|
kpeter@1228
|
108 |
|
kpeter@1228
|
109 |
typedef typename GR::Node Node;
|
kpeter@1228
|
110 |
typedef typename GR::Arc Arc;
|
kpeter@1228
|
111 |
typedef typename CAP::Value Value;
|
kpeter@1228
|
112 |
typedef concepts::ReadWriteMap<Arc, Value> FlowMap;
|
kpeter@1228
|
113 |
typedef concepts::WriteMap<Node, bool> CutMap;
|
kpeter@1228
|
114 |
|
kpeter@1228
|
115 |
GR g;
|
kpeter@1228
|
116 |
Node n;
|
kpeter@1228
|
117 |
Arc e;
|
kpeter@1228
|
118 |
CAP cap;
|
kpeter@1228
|
119 |
FlowMap flow;
|
kpeter@1228
|
120 |
CutMap cut;
|
kpeter@1228
|
121 |
Value v;
|
kpeter@1228
|
122 |
bool b;
|
kpeter@1228
|
123 |
|
kpeter@1228
|
124 |
void constraints() {
|
kpeter@1228
|
125 |
checkConcept<concepts::Digraph, GR>();
|
kpeter@1228
|
126 |
|
kpeter@1228
|
127 |
const Constraints& me = *this;
|
kpeter@1228
|
128 |
|
kpeter@1228
|
129 |
typedef typename MF
|
kpeter@1228
|
130 |
::template SetFlowMap<FlowMap>
|
kpeter@1228
|
131 |
::Create MaxFlowType;
|
kpeter@1228
|
132 |
typedef typename MF::Create MaxFlowType2;
|
kpeter@1228
|
133 |
MaxFlowType max_flow(me.g, me.cap, me.n, me.n);
|
kpeter@1228
|
134 |
const MaxFlowType& const_max_flow = max_flow;
|
kpeter@1228
|
135 |
|
kpeter@1228
|
136 |
max_flow
|
kpeter@1228
|
137 |
.capacityMap(cap)
|
kpeter@1228
|
138 |
.flowMap(flow)
|
kpeter@1228
|
139 |
.source(n)
|
kpeter@1228
|
140 |
.target(n);
|
kpeter@1228
|
141 |
|
kpeter@1228
|
142 |
typename MaxFlowType::Tolerance tol = const_max_flow.tolerance();
|
kpeter@1228
|
143 |
max_flow.tolerance(tol);
|
kpeter@1228
|
144 |
|
kpeter@1228
|
145 |
max_flow.init();
|
kpeter@1228
|
146 |
max_flow.init(cap);
|
kpeter@1228
|
147 |
max_flow.run();
|
kpeter@1228
|
148 |
|
kpeter@1228
|
149 |
v = const_max_flow.flowValue();
|
kpeter@1228
|
150 |
v = const_max_flow.flow(e);
|
kpeter@1228
|
151 |
const FlowMap& fm = const_max_flow.flowMap();
|
kpeter@1228
|
152 |
|
kpeter@1228
|
153 |
b = const_max_flow.minCut(n);
|
kpeter@1228
|
154 |
const_max_flow.minCutMap(cut);
|
kpeter@1228
|
155 |
|
alpar@1262
|
156 |
::lemon::ignore_unused_variable_warning(fm);
|
kpeter@1228
|
157 |
}
|
kpeter@1228
|
158 |
|
kpeter@1228
|
159 |
};
|
kpeter@1228
|
160 |
|
kpeter@1228
|
161 |
};
|
kpeter@1228
|
162 |
|
kpeter@1228
|
163 |
// Checks the specific parts of Preflow's interface
|
kpeter@409
|
164 |
void checkPreflowCompile()
|
alpar@404
|
165 |
{
|
kpeter@1228
|
166 |
typedef int Value;
|
alpar@404
|
167 |
typedef concepts::Digraph Digraph;
|
kpeter@1228
|
168 |
typedef concepts::ReadMap<Digraph::Arc, Value> CapMap;
|
kpeter@409
|
169 |
typedef Elevator<Digraph, Digraph::Node> Elev;
|
kpeter@409
|
170 |
typedef LinkedElevator<Digraph, Digraph::Node> LinkedElev;
|
kpeter@409
|
171 |
|
alpar@404
|
172 |
Digraph g;
|
kpeter@1228
|
173 |
Digraph::Node n;
|
alpar@404
|
174 |
CapMap cap;
|
alpar@404
|
175 |
|
kpeter@632
|
176 |
typedef Preflow<Digraph, CapMap>
|
kpeter@1228
|
177 |
::SetElevator<Elev>
|
kpeter@1228
|
178 |
::SetStandardElevator<LinkedElev>
|
kpeter@1228
|
179 |
::Create PreflowType;
|
kpeter@632
|
180 |
PreflowType preflow_test(g, cap, n, n);
|
kpeter@632
|
181 |
const PreflowType& const_preflow_test = preflow_test;
|
alpar@404
|
182 |
|
kpeter@736
|
183 |
const PreflowType::Elevator& elev = const_preflow_test.elevator();
|
kpeter@736
|
184 |
preflow_test.elevator(const_cast<PreflowType::Elevator&>(elev));
|
kpeter@632
|
185 |
|
kpeter@1228
|
186 |
bool b = preflow_test.init(cap);
|
alpar@404
|
187 |
preflow_test.startFirstPhase();
|
alpar@404
|
188 |
preflow_test.startSecondPhase();
|
alpar@404
|
189 |
preflow_test.runMinCut();
|
alpar@404
|
190 |
|
alpar@1262
|
191 |
::lemon::ignore_unused_variable_warning(b);
|
alpar@404
|
192 |
}
|
alpar@404
|
193 |
|
kpeter@1228
|
194 |
// Checks the specific parts of EdmondsKarp's interface
|
kpeter@1228
|
195 |
void checkEdmondsKarpCompile()
|
kpeter@1228
|
196 |
{
|
kpeter@1228
|
197 |
typedef int Value;
|
kpeter@1228
|
198 |
typedef concepts::Digraph Digraph;
|
kpeter@1228
|
199 |
typedef concepts::ReadMap<Digraph::Arc, Value> CapMap;
|
kpeter@1228
|
200 |
|
kpeter@1228
|
201 |
Digraph g;
|
kpeter@1228
|
202 |
Digraph::Node n;
|
kpeter@1228
|
203 |
CapMap cap;
|
kpeter@1228
|
204 |
|
kpeter@1228
|
205 |
EdmondsKarp<Digraph, CapMap> ek_test(g, cap, n, n);
|
kpeter@1228
|
206 |
|
kpeter@1228
|
207 |
ek_test.init(cap);
|
kpeter@1228
|
208 |
bool b = ek_test.checkedInit(cap);
|
kpeter@1228
|
209 |
b = ek_test.augment();
|
kpeter@1228
|
210 |
ek_test.start();
|
kpeter@1228
|
211 |
|
alpar@1262
|
212 |
::lemon::ignore_unused_variable_warning(b);
|
kpeter@1228
|
213 |
}
|
kpeter@1228
|
214 |
|
kpeter@1228
|
215 |
|
kpeter@1228
|
216 |
template <typename T>
|
kpeter@1382
|
217 |
T cutValue(const SmartDigraph& g,
|
kpeter@1382
|
218 |
const SmartDigraph::NodeMap<bool>& cut,
|
kpeter@1382
|
219 |
const SmartDigraph::ArcMap<T>& cap) {
|
alpar@404
|
220 |
|
kpeter@1382
|
221 |
T c = 0;
|
kpeter@1382
|
222 |
for (SmartDigraph::ArcIt e(g); e != INVALID; ++e) {
|
kpeter@1382
|
223 |
if (cut[g.source(e)] && !cut[g.target(e)]) c += cap[e];
|
alpar@404
|
224 |
}
|
alpar@404
|
225 |
return c;
|
alpar@404
|
226 |
}
|
alpar@404
|
227 |
|
kpeter@1228
|
228 |
template <typename T>
|
alpar@404
|
229 |
bool checkFlow(const SmartDigraph& g,
|
kpeter@1228
|
230 |
const SmartDigraph::ArcMap<T>& flow,
|
kpeter@1228
|
231 |
const SmartDigraph::ArcMap<T>& cap,
|
kpeter@1383
|
232 |
SmartDigraph::Node s, SmartDigraph::Node t,
|
kpeter@1383
|
233 |
const Tolerance<T>& tol) {
|
alpar@404
|
234 |
|
alpar@404
|
235 |
for (SmartDigraph::ArcIt e(g); e != INVALID; ++e) {
|
kpeter@1383
|
236 |
if (tol.negative(flow[e]) || tol.less(cap[e], flow[e])) return false;
|
alpar@404
|
237 |
}
|
alpar@404
|
238 |
|
alpar@404
|
239 |
for (SmartDigraph::NodeIt n(g); n != INVALID; ++n) {
|
alpar@404
|
240 |
if (n == s || n == t) continue;
|
kpeter@1228
|
241 |
T sum = 0;
|
alpar@404
|
242 |
for (SmartDigraph::OutArcIt e(g, n); e != INVALID; ++e) {
|
alpar@404
|
243 |
sum += flow[e];
|
alpar@404
|
244 |
}
|
alpar@404
|
245 |
for (SmartDigraph::InArcIt e(g, n); e != INVALID; ++e) {
|
alpar@404
|
246 |
sum -= flow[e];
|
alpar@404
|
247 |
}
|
kpeter@1383
|
248 |
if (tol.nonZero(sum)) return false;
|
alpar@404
|
249 |
}
|
alpar@404
|
250 |
return true;
|
alpar@404
|
251 |
}
|
alpar@404
|
252 |
|
kpeter@1382
|
253 |
void checkInitPreflow()
|
alpar@1027
|
254 |
{
|
alpar@1027
|
255 |
DIGRAPH_TYPEDEFS(SmartDigraph);
|
alpar@1270
|
256 |
|
alpar@1027
|
257 |
SmartDigraph g;
|
kpeter@1382
|
258 |
SmartDigraph::ArcMap<int> cap(g), iflow(g);
|
kpeter@1382
|
259 |
Node s = g.addNode(); Node t = g.addNode();
|
kpeter@1382
|
260 |
Node n1 = g.addNode(); Node n2 = g.addNode();
|
alpar@1027
|
261 |
Arc a;
|
kpeter@1382
|
262 |
a = g.addArc(s, n1); cap[a] = 20; iflow[a] = 20;
|
kpeter@1382
|
263 |
a = g.addArc(n1, n2); cap[a] = 10; iflow[a] = 0;
|
kpeter@1382
|
264 |
a = g.addArc(n2, t); cap[a] = 20; iflow[a] = 0;
|
alpar@1027
|
265 |
|
kpeter@1382
|
266 |
Preflow<SmartDigraph> pre(g, cap, s, t);
|
alpar@1027
|
267 |
pre.init(iflow);
|
alpar@1027
|
268 |
pre.startFirstPhase();
|
kpeter@1382
|
269 |
|
kpeter@1382
|
270 |
check(pre.flowValue() == 10, "Incorrect max flow value.");
|
alpar@1027
|
271 |
check(pre.minCut(s), "Wrong min cut (Node s).");
|
alpar@1027
|
272 |
check(pre.minCut(n1), "Wrong min cut (Node n1).");
|
alpar@1027
|
273 |
check(!pre.minCut(n2), "Wrong min cut (Node n2).");
|
alpar@1027
|
274 |
check(!pre.minCut(t), "Wrong min cut (Node t).");
|
alpar@1027
|
275 |
}
|
alpar@1027
|
276 |
|
kpeter@1228
|
277 |
template <typename MF, typename SF>
|
kpeter@1384
|
278 |
void checkMaxFlowAlg(const char *input_lgf, typename MF::Value expected) {
|
kpeter@1228
|
279 |
typedef SmartDigraph Digraph;
|
kpeter@1228
|
280 |
DIGRAPH_TYPEDEFS(Digraph);
|
alpar@1027
|
281 |
|
kpeter@1228
|
282 |
typedef typename MF::Value Value;
|
kpeter@1228
|
283 |
typedef Digraph::ArcMap<Value> CapMap;
|
kpeter@1228
|
284 |
typedef CapMap FlowMap;
|
kpeter@1228
|
285 |
typedef BoolNodeMap CutMap;
|
alpar@404
|
286 |
|
kpeter@1383
|
287 |
Tolerance<Value> tol;
|
kpeter@1383
|
288 |
|
alpar@404
|
289 |
Digraph g;
|
alpar@404
|
290 |
Node s, t;
|
alpar@404
|
291 |
CapMap cap(g);
|
kpeter@1384
|
292 |
std::istringstream input(input_lgf);
|
kpeter@1385
|
293 |
DigraphReader<Digraph>(g, input)
|
kpeter@1228
|
294 |
.arcMap("capacity", cap)
|
kpeter@1385
|
295 |
.node("source", s)
|
kpeter@1385
|
296 |
.node("target", t)
|
kpeter@1228
|
297 |
.run();
|
alpar@404
|
298 |
|
kpeter@1228
|
299 |
MF max_flow(g, cap, s, t);
|
kpeter@1228
|
300 |
max_flow.run();
|
alpar@404
|
301 |
|
kpeter@1384
|
302 |
check(!tol.different(expected, max_flow.flowValue()),
|
kpeter@1384
|
303 |
"Incorrect max flow value.");
|
kpeter@1383
|
304 |
check(checkFlow(g, max_flow.flowMap(), cap, s, t, tol),
|
alpar@404
|
305 |
"The flow is not feasible.");
|
alpar@404
|
306 |
|
alpar@404
|
307 |
CutMap min_cut(g);
|
kpeter@1228
|
308 |
max_flow.minCutMap(min_cut);
|
kpeter@1228
|
309 |
Value min_cut_value = cutValue(g, min_cut, cap);
|
alpar@404
|
310 |
|
kpeter@1384
|
311 |
check(!tol.different(expected, min_cut_value),
|
kpeter@1384
|
312 |
"Incorrect min cut value.");
|
alpar@404
|
313 |
|
alpar@404
|
314 |
FlowMap flow(g);
|
kpeter@1385
|
315 |
for (ArcIt e(g); e != INVALID; ++e) flow[e] = 13 * max_flow.flowMap()[e];
|
kpeter@1385
|
316 |
for (ArcIt e(g); e != INVALID; ++e) cap[e] = 17 * cap[e];
|
kpeter@1228
|
317 |
max_flow.init(flow);
|
kpeter@1228
|
318 |
|
kpeter@1228
|
319 |
SF::startFirstPhase(max_flow); // start first phase of the algorithm
|
alpar@404
|
320 |
|
alpar@404
|
321 |
CutMap min_cut1(g);
|
kpeter@1228
|
322 |
max_flow.minCutMap(min_cut1);
|
kpeter@1228
|
323 |
min_cut_value = cutValue(g, min_cut1, cap);
|
alpar@404
|
324 |
|
kpeter@1385
|
325 |
check(!tol.different(17 * expected, max_flow.flowValue()),
|
kpeter@1384
|
326 |
"Incorrect max flow value.");
|
kpeter@1385
|
327 |
check(!tol.different(17 * expected, min_cut_value),
|
kpeter@1384
|
328 |
"Incorrect min cut value.");
|
alpar@404
|
329 |
|
kpeter@1228
|
330 |
SF::startSecondPhase(max_flow); // start second phase of the algorithm
|
alpar@404
|
331 |
|
kpeter@1383
|
332 |
check(checkFlow(g, max_flow.flowMap(), cap, s, t, tol),
|
alpar@404
|
333 |
"The flow is not feasible.");
|
alpar@404
|
334 |
|
alpar@404
|
335 |
CutMap min_cut2(g);
|
kpeter@1228
|
336 |
max_flow.minCutMap(min_cut2);
|
kpeter@1228
|
337 |
min_cut_value = cutValue(g, min_cut2, cap);
|
alpar@404
|
338 |
|
kpeter@1385
|
339 |
check(!tol.different(17 * expected, max_flow.flowValue()),
|
kpeter@1384
|
340 |
"Incorrect max flow value.");
|
kpeter@1385
|
341 |
check(!tol.different(17 * expected, min_cut_value),
|
kpeter@1384
|
342 |
"Incorrect min cut value.");
|
alpar@404
|
343 |
|
kpeter@1228
|
344 |
max_flow.flowMap(flow);
|
alpar@404
|
345 |
|
kpeter@1228
|
346 |
NodeIt tmp1(g, s);
|
alpar@404
|
347 |
++tmp1;
|
kpeter@1228
|
348 |
if (tmp1 != INVALID) s = tmp1;
|
alpar@404
|
349 |
|
kpeter@1228
|
350 |
NodeIt tmp2(g, t);
|
alpar@404
|
351 |
++tmp2;
|
kpeter@1228
|
352 |
if (tmp2 != INVALID) t = tmp2;
|
alpar@404
|
353 |
|
kpeter@1228
|
354 |
max_flow.source(s);
|
kpeter@1228
|
355 |
max_flow.target(t);
|
alpar@404
|
356 |
|
kpeter@1228
|
357 |
max_flow.run();
|
alpar@404
|
358 |
|
alpar@404
|
359 |
CutMap min_cut3(g);
|
kpeter@1228
|
360 |
max_flow.minCutMap(min_cut3);
|
kpeter@1382
|
361 |
min_cut_value = cutValue(g, min_cut3, cap);
|
alpar@404
|
362 |
|
kpeter@1383
|
363 |
check(!tol.different(max_flow.flowValue(), min_cut_value),
|
kpeter@1228
|
364 |
"The max flow value or the min cut value is wrong.");
|
kpeter@1228
|
365 |
}
|
alpar@404
|
366 |
|
kpeter@1228
|
367 |
// Struct for calling start functions of a general max flow algorithm
|
kpeter@1228
|
368 |
template <typename MF>
|
kpeter@1228
|
369 |
struct GeneralStartFunctions {
|
kpeter@1228
|
370 |
|
kpeter@1228
|
371 |
static void startFirstPhase(MF& mf) {
|
kpeter@1228
|
372 |
mf.start();
|
kpeter@1228
|
373 |
}
|
kpeter@1228
|
374 |
|
kpeter@1228
|
375 |
static void startSecondPhase(MF& mf) {
|
alpar@1262
|
376 |
::lemon::ignore_unused_variable_warning(mf);
|
kpeter@1228
|
377 |
}
|
kpeter@1228
|
378 |
|
kpeter@1228
|
379 |
};
|
kpeter@1228
|
380 |
|
kpeter@1228
|
381 |
// Struct for calling start functions of Preflow
|
kpeter@1228
|
382 |
template <typename MF>
|
kpeter@1228
|
383 |
struct PreflowStartFunctions {
|
kpeter@1228
|
384 |
|
kpeter@1228
|
385 |
static void startFirstPhase(MF& mf) {
|
kpeter@1228
|
386 |
mf.startFirstPhase();
|
kpeter@1228
|
387 |
}
|
kpeter@1228
|
388 |
|
kpeter@1228
|
389 |
static void startSecondPhase(MF& mf) {
|
kpeter@1228
|
390 |
mf.startSecondPhase();
|
kpeter@1228
|
391 |
}
|
kpeter@1228
|
392 |
|
kpeter@1228
|
393 |
};
|
kpeter@1228
|
394 |
|
kpeter@1228
|
395 |
int main() {
|
kpeter@1228
|
396 |
|
kpeter@1228
|
397 |
typedef concepts::Digraph GR;
|
kpeter@1228
|
398 |
typedef concepts::ReadMap<GR::Arc, int> CM1;
|
kpeter@1228
|
399 |
typedef concepts::ReadMap<GR::Arc, double> CM2;
|
kpeter@1228
|
400 |
|
kpeter@1228
|
401 |
// Check the interface of Preflow
|
kpeter@1228
|
402 |
checkConcept< MaxFlowClassConcept<GR, CM1>,
|
kpeter@1228
|
403 |
Preflow<GR, CM1> >();
|
kpeter@1228
|
404 |
checkConcept< MaxFlowClassConcept<GR, CM2>,
|
kpeter@1228
|
405 |
Preflow<GR, CM2> >();
|
kpeter@1228
|
406 |
|
kpeter@1228
|
407 |
// Check the interface of EdmondsKarp
|
kpeter@1228
|
408 |
checkConcept< MaxFlowClassConcept<GR, CM1>,
|
kpeter@1228
|
409 |
EdmondsKarp<GR, CM1> >();
|
kpeter@1228
|
410 |
checkConcept< MaxFlowClassConcept<GR, CM2>,
|
kpeter@1228
|
411 |
EdmondsKarp<GR, CM2> >();
|
kpeter@1228
|
412 |
|
kpeter@1228
|
413 |
// Check Preflow
|
kpeter@1228
|
414 |
typedef Preflow<SmartDigraph, SmartDigraph::ArcMap<int> > PType1;
|
kpeter@1228
|
415 |
typedef Preflow<SmartDigraph, SmartDigraph::ArcMap<float> > PType2;
|
kpeter@1384
|
416 |
typedef Preflow<SmartDigraph, SmartDigraph::ArcMap<double> > PType3;
|
kpeter@1385
|
417 |
|
kpeter@1384
|
418 |
checkMaxFlowAlg<PType1, PreflowStartFunctions<PType1> >(test_lgf, 13);
|
kpeter@1384
|
419 |
checkMaxFlowAlg<PType2, PreflowStartFunctions<PType2> >(test_lgf, 13);
|
kpeter@1384
|
420 |
checkMaxFlowAlg<PType3, PreflowStartFunctions<PType3> >(test_lgf, 13);
|
kpeter@1382
|
421 |
|
kpeter@1385
|
422 |
checkMaxFlowAlg<PType2, PreflowStartFunctions<PType2> >(test_lgf_float, 0.3);
|
kpeter@1385
|
423 |
checkMaxFlowAlg<PType3, PreflowStartFunctions<PType3> >(test_lgf_float, 0.3);
|
kpeter@1385
|
424 |
|
kpeter@1382
|
425 |
checkInitPreflow();
|
alpar@1270
|
426 |
|
kpeter@1228
|
427 |
// Check EdmondsKarp
|
kpeter@1228
|
428 |
typedef EdmondsKarp<SmartDigraph, SmartDigraph::ArcMap<int> > EKType1;
|
kpeter@1228
|
429 |
typedef EdmondsKarp<SmartDigraph, SmartDigraph::ArcMap<float> > EKType2;
|
kpeter@1384
|
430 |
typedef EdmondsKarp<SmartDigraph, SmartDigraph::ArcMap<double> > EKType3;
|
kpeter@1385
|
431 |
|
kpeter@1384
|
432 |
checkMaxFlowAlg<EKType1, GeneralStartFunctions<EKType1> >(test_lgf, 13);
|
kpeter@1384
|
433 |
checkMaxFlowAlg<EKType2, GeneralStartFunctions<EKType2> >(test_lgf, 13);
|
kpeter@1384
|
434 |
checkMaxFlowAlg<EKType3, GeneralStartFunctions<EKType3> >(test_lgf, 13);
|
alpar@404
|
435 |
|
kpeter@1385
|
436 |
checkMaxFlowAlg<EKType2, GeneralStartFunctions<EKType2> >(test_lgf_float, 0.3);
|
kpeter@1385
|
437 |
checkMaxFlowAlg<EKType3, GeneralStartFunctions<EKType3> >(test_lgf_float, 0.3);
|
kpeter@1385
|
438 |
|
alpar@404
|
439 |
return 0;
|
alpar@404
|
440 |
}
|