kpeter@593
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*-
|
kpeter@593
|
2 |
*
|
kpeter@593
|
3 |
* This file is a part of LEMON, a generic C++ optimization library.
|
kpeter@593
|
4 |
*
|
kpeter@593
|
5 |
* Copyright (C) 2003-2009
|
kpeter@593
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
kpeter@593
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
kpeter@593
|
8 |
*
|
kpeter@593
|
9 |
* Permission to use, modify and distribute this software is granted
|
kpeter@593
|
10 |
* provided that this copyright notice appears in all copies. For
|
kpeter@593
|
11 |
* precise terms see the accompanying LICENSE file.
|
kpeter@593
|
12 |
*
|
kpeter@593
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
kpeter@593
|
14 |
* express or implied, and with no claim as to its suitability for any
|
kpeter@593
|
15 |
* purpose.
|
kpeter@593
|
16 |
*
|
kpeter@593
|
17 |
*/
|
kpeter@593
|
18 |
|
kpeter@593
|
19 |
#include <iostream>
|
kpeter@593
|
20 |
#include <fstream>
|
kpeter@636
|
21 |
#include <limits>
|
kpeter@593
|
22 |
|
kpeter@593
|
23 |
#include <lemon/list_graph.h>
|
kpeter@593
|
24 |
#include <lemon/lgf_reader.h>
|
kpeter@593
|
25 |
|
kpeter@593
|
26 |
#include <lemon/network_simplex.h>
|
kpeter@593
|
27 |
|
kpeter@593
|
28 |
#include <lemon/concepts/digraph.h>
|
kpeter@593
|
29 |
#include <lemon/concept_check.h>
|
kpeter@593
|
30 |
|
kpeter@593
|
31 |
#include "test_tools.h"
|
kpeter@593
|
32 |
|
kpeter@593
|
33 |
using namespace lemon;
|
kpeter@593
|
34 |
|
kpeter@593
|
35 |
char test_lgf[] =
|
kpeter@593
|
36 |
"@nodes\n"
|
kpeter@636
|
37 |
"label sup1 sup2 sup3 sup4 sup5 sup6\n"
|
kpeter@636
|
38 |
" 1 20 27 0 30 20 30\n"
|
kpeter@636
|
39 |
" 2 -4 0 0 0 -8 -3\n"
|
kpeter@636
|
40 |
" 3 0 0 0 0 0 0\n"
|
kpeter@636
|
41 |
" 4 0 0 0 0 0 0\n"
|
kpeter@636
|
42 |
" 5 9 0 0 0 6 11\n"
|
kpeter@636
|
43 |
" 6 -6 0 0 0 -5 -6\n"
|
kpeter@636
|
44 |
" 7 0 0 0 0 0 0\n"
|
kpeter@636
|
45 |
" 8 0 0 0 0 0 3\n"
|
kpeter@636
|
46 |
" 9 3 0 0 0 0 0\n"
|
kpeter@636
|
47 |
" 10 -2 0 0 0 -7 -2\n"
|
kpeter@636
|
48 |
" 11 0 0 0 0 -10 0\n"
|
kpeter@636
|
49 |
" 12 -20 -27 0 -30 -30 -20\n"
|
kpeter@636
|
50 |
"\n"
|
kpeter@593
|
51 |
"@arcs\n"
|
kpeter@636
|
52 |
" cost cap low1 low2 low3\n"
|
kpeter@636
|
53 |
" 1 2 70 11 0 8 8\n"
|
kpeter@636
|
54 |
" 1 3 150 3 0 1 0\n"
|
kpeter@636
|
55 |
" 1 4 80 15 0 2 2\n"
|
kpeter@636
|
56 |
" 2 8 80 12 0 0 0\n"
|
kpeter@636
|
57 |
" 3 5 140 5 0 3 1\n"
|
kpeter@636
|
58 |
" 4 6 60 10 0 1 0\n"
|
kpeter@636
|
59 |
" 4 7 80 2 0 0 0\n"
|
kpeter@636
|
60 |
" 4 8 110 3 0 0 0\n"
|
kpeter@636
|
61 |
" 5 7 60 14 0 0 0\n"
|
kpeter@636
|
62 |
" 5 11 120 12 0 0 0\n"
|
kpeter@636
|
63 |
" 6 3 0 3 0 0 0\n"
|
kpeter@636
|
64 |
" 6 9 140 4 0 0 0\n"
|
kpeter@636
|
65 |
" 6 10 90 8 0 0 0\n"
|
kpeter@636
|
66 |
" 7 1 30 5 0 0 -5\n"
|
kpeter@636
|
67 |
" 8 12 60 16 0 4 3\n"
|
kpeter@636
|
68 |
" 9 12 50 6 0 0 0\n"
|
kpeter@636
|
69 |
"10 12 70 13 0 5 2\n"
|
kpeter@636
|
70 |
"10 2 100 7 0 0 0\n"
|
kpeter@636
|
71 |
"10 7 60 10 0 0 -3\n"
|
kpeter@636
|
72 |
"11 10 20 14 0 6 -20\n"
|
kpeter@636
|
73 |
"12 11 30 10 0 0 -10\n"
|
kpeter@593
|
74 |
"\n"
|
kpeter@593
|
75 |
"@attributes\n"
|
kpeter@593
|
76 |
"source 1\n"
|
kpeter@593
|
77 |
"target 12\n";
|
kpeter@593
|
78 |
|
kpeter@593
|
79 |
|
kpeter@636
|
80 |
enum SupplyType {
|
kpeter@601
|
81 |
EQ,
|
kpeter@601
|
82 |
GEQ,
|
kpeter@601
|
83 |
LEQ
|
kpeter@601
|
84 |
};
|
kpeter@601
|
85 |
|
kpeter@593
|
86 |
// Check the interface of an MCF algorithm
|
kpeter@638
|
87 |
template <typename GR, typename Value, typename Cost>
|
kpeter@593
|
88 |
class McfClassConcept
|
kpeter@593
|
89 |
{
|
kpeter@593
|
90 |
public:
|
kpeter@593
|
91 |
|
kpeter@593
|
92 |
template <typename MCF>
|
kpeter@593
|
93 |
struct Constraints {
|
kpeter@593
|
94 |
void constraints() {
|
kpeter@593
|
95 |
checkConcept<concepts::Digraph, GR>();
|
kpeter@593
|
96 |
|
kpeter@597
|
97 |
MCF mcf(g);
|
kpeter@638
|
98 |
const MCF& const_mcf = mcf;
|
kpeter@593
|
99 |
|
kpeter@598
|
100 |
b = mcf.reset()
|
kpeter@598
|
101 |
.lowerMap(lower)
|
kpeter@597
|
102 |
.upperMap(upper)
|
kpeter@597
|
103 |
.costMap(cost)
|
kpeter@597
|
104 |
.supplyMap(sup)
|
kpeter@597
|
105 |
.stSupply(n, n, k)
|
kpeter@597
|
106 |
.run();
|
kpeter@597
|
107 |
|
kpeter@636
|
108 |
c = const_mcf.totalCost();
|
kpeter@638
|
109 |
x = const_mcf.template totalCost<double>();
|
kpeter@601
|
110 |
v = const_mcf.flow(a);
|
kpeter@636
|
111 |
c = const_mcf.potential(n);
|
kpeter@638
|
112 |
const_mcf.flowMap(fm);
|
kpeter@638
|
113 |
const_mcf.potentialMap(pm);
|
kpeter@593
|
114 |
}
|
kpeter@593
|
115 |
|
kpeter@593
|
116 |
typedef typename GR::Node Node;
|
kpeter@593
|
117 |
typedef typename GR::Arc Arc;
|
kpeter@638
|
118 |
typedef concepts::ReadMap<Node, Value> NM;
|
kpeter@638
|
119 |
typedef concepts::ReadMap<Arc, Value> VAM;
|
kpeter@599
|
120 |
typedef concepts::ReadMap<Arc, Cost> CAM;
|
kpeter@638
|
121 |
typedef concepts::WriteMap<Arc, Value> FlowMap;
|
kpeter@638
|
122 |
typedef concepts::WriteMap<Node, Cost> PotMap;
|
kpeter@593
|
123 |
|
kpeter@593
|
124 |
const GR &g;
|
kpeter@638
|
125 |
const VAM &lower;
|
kpeter@638
|
126 |
const VAM &upper;
|
kpeter@599
|
127 |
const CAM &cost;
|
kpeter@593
|
128 |
const NM ⊃
|
kpeter@593
|
129 |
const Node &n;
|
kpeter@593
|
130 |
const Arc &a;
|
kpeter@638
|
131 |
const Value &k;
|
kpeter@638
|
132 |
FlowMap fm;
|
kpeter@638
|
133 |
PotMap pm;
|
kpeter@597
|
134 |
bool b;
|
kpeter@638
|
135 |
double x;
|
kpeter@638
|
136 |
typename MCF::Value v;
|
kpeter@638
|
137 |
typename MCF::Cost c;
|
kpeter@593
|
138 |
};
|
kpeter@593
|
139 |
|
kpeter@593
|
140 |
};
|
kpeter@593
|
141 |
|
kpeter@593
|
142 |
|
kpeter@593
|
143 |
// Check the feasibility of the given flow (primal soluiton)
|
kpeter@593
|
144 |
template < typename GR, typename LM, typename UM,
|
kpeter@593
|
145 |
typename SM, typename FM >
|
kpeter@593
|
146 |
bool checkFlow( const GR& gr, const LM& lower, const UM& upper,
|
kpeter@601
|
147 |
const SM& supply, const FM& flow,
|
kpeter@636
|
148 |
SupplyType type = EQ )
|
kpeter@593
|
149 |
{
|
kpeter@593
|
150 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR);
|
kpeter@593
|
151 |
|
kpeter@593
|
152 |
for (ArcIt e(gr); e != INVALID; ++e) {
|
kpeter@593
|
153 |
if (flow[e] < lower[e] || flow[e] > upper[e]) return false;
|
kpeter@593
|
154 |
}
|
kpeter@593
|
155 |
|
kpeter@593
|
156 |
for (NodeIt n(gr); n != INVALID; ++n) {
|
kpeter@593
|
157 |
typename SM::Value sum = 0;
|
kpeter@593
|
158 |
for (OutArcIt e(gr, n); e != INVALID; ++e)
|
kpeter@593
|
159 |
sum += flow[e];
|
kpeter@593
|
160 |
for (InArcIt e(gr, n); e != INVALID; ++e)
|
kpeter@593
|
161 |
sum -= flow[e];
|
kpeter@601
|
162 |
bool b = (type == EQ && sum == supply[n]) ||
|
kpeter@601
|
163 |
(type == GEQ && sum >= supply[n]) ||
|
kpeter@601
|
164 |
(type == LEQ && sum <= supply[n]);
|
kpeter@601
|
165 |
if (!b) return false;
|
kpeter@593
|
166 |
}
|
kpeter@593
|
167 |
|
kpeter@593
|
168 |
return true;
|
kpeter@593
|
169 |
}
|
kpeter@593
|
170 |
|
kpeter@593
|
171 |
// Check the feasibility of the given potentials (dual soluiton)
|
kpeter@597
|
172 |
// using the "Complementary Slackness" optimality condition
|
kpeter@593
|
173 |
template < typename GR, typename LM, typename UM,
|
kpeter@601
|
174 |
typename CM, typename SM, typename FM, typename PM >
|
kpeter@593
|
175 |
bool checkPotential( const GR& gr, const LM& lower, const UM& upper,
|
kpeter@601
|
176 |
const CM& cost, const SM& supply, const FM& flow,
|
kpeter@601
|
177 |
const PM& pi )
|
kpeter@593
|
178 |
{
|
kpeter@593
|
179 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR);
|
kpeter@593
|
180 |
|
kpeter@593
|
181 |
bool opt = true;
|
kpeter@593
|
182 |
for (ArcIt e(gr); opt && e != INVALID; ++e) {
|
kpeter@593
|
183 |
typename CM::Value red_cost =
|
kpeter@593
|
184 |
cost[e] + pi[gr.source(e)] - pi[gr.target(e)];
|
kpeter@593
|
185 |
opt = red_cost == 0 ||
|
kpeter@593
|
186 |
(red_cost > 0 && flow[e] == lower[e]) ||
|
kpeter@593
|
187 |
(red_cost < 0 && flow[e] == upper[e]);
|
kpeter@593
|
188 |
}
|
kpeter@601
|
189 |
|
kpeter@601
|
190 |
for (NodeIt n(gr); opt && n != INVALID; ++n) {
|
kpeter@601
|
191 |
typename SM::Value sum = 0;
|
kpeter@601
|
192 |
for (OutArcIt e(gr, n); e != INVALID; ++e)
|
kpeter@601
|
193 |
sum += flow[e];
|
kpeter@601
|
194 |
for (InArcIt e(gr, n); e != INVALID; ++e)
|
kpeter@601
|
195 |
sum -= flow[e];
|
kpeter@601
|
196 |
opt = (sum == supply[n]) || (pi[n] == 0);
|
kpeter@601
|
197 |
}
|
kpeter@601
|
198 |
|
kpeter@593
|
199 |
return opt;
|
kpeter@593
|
200 |
}
|
kpeter@593
|
201 |
|
kpeter@593
|
202 |
// Run a minimum cost flow algorithm and check the results
|
kpeter@593
|
203 |
template < typename MCF, typename GR,
|
kpeter@593
|
204 |
typename LM, typename UM,
|
kpeter@636
|
205 |
typename CM, typename SM,
|
kpeter@636
|
206 |
typename PT >
|
kpeter@636
|
207 |
void checkMcf( const MCF& mcf, PT mcf_result,
|
kpeter@593
|
208 |
const GR& gr, const LM& lower, const UM& upper,
|
kpeter@593
|
209 |
const CM& cost, const SM& supply,
|
kpeter@636
|
210 |
PT result, bool optimal, typename CM::Value total,
|
kpeter@601
|
211 |
const std::string &test_id = "",
|
kpeter@636
|
212 |
SupplyType type = EQ )
|
kpeter@593
|
213 |
{
|
kpeter@593
|
214 |
check(mcf_result == result, "Wrong result " + test_id);
|
kpeter@636
|
215 |
if (optimal) {
|
kpeter@638
|
216 |
typename GR::template ArcMap<typename SM::Value> flow(gr);
|
kpeter@638
|
217 |
typename GR::template NodeMap<typename CM::Value> pi(gr);
|
kpeter@638
|
218 |
mcf.flowMap(flow);
|
kpeter@638
|
219 |
mcf.potentialMap(pi);
|
kpeter@638
|
220 |
check(checkFlow(gr, lower, upper, supply, flow, type),
|
kpeter@593
|
221 |
"The flow is not feasible " + test_id);
|
kpeter@593
|
222 |
check(mcf.totalCost() == total, "The flow is not optimal " + test_id);
|
kpeter@638
|
223 |
check(checkPotential(gr, lower, upper, cost, supply, flow, pi),
|
kpeter@593
|
224 |
"Wrong potentials " + test_id);
|
kpeter@593
|
225 |
}
|
kpeter@593
|
226 |
}
|
kpeter@593
|
227 |
|
kpeter@593
|
228 |
int main()
|
kpeter@593
|
229 |
{
|
kpeter@593
|
230 |
// Check the interfaces
|
kpeter@593
|
231 |
{
|
kpeter@607
|
232 |
typedef concepts::Digraph GR;
|
kpeter@638
|
233 |
checkConcept< McfClassConcept<GR, int, int>,
|
kpeter@638
|
234 |
NetworkSimplex<GR> >();
|
kpeter@638
|
235 |
checkConcept< McfClassConcept<GR, double, double>,
|
kpeter@638
|
236 |
NetworkSimplex<GR, double> >();
|
kpeter@638
|
237 |
checkConcept< McfClassConcept<GR, int, double>,
|
kpeter@638
|
238 |
NetworkSimplex<GR, int, double> >();
|
kpeter@593
|
239 |
}
|
kpeter@593
|
240 |
|
kpeter@593
|
241 |
// Run various MCF tests
|
kpeter@593
|
242 |
typedef ListDigraph Digraph;
|
kpeter@593
|
243 |
DIGRAPH_TYPEDEFS(ListDigraph);
|
kpeter@593
|
244 |
|
kpeter@593
|
245 |
// Read the test digraph
|
kpeter@593
|
246 |
Digraph gr;
|
kpeter@636
|
247 |
Digraph::ArcMap<int> c(gr), l1(gr), l2(gr), l3(gr), u(gr);
|
kpeter@636
|
248 |
Digraph::NodeMap<int> s1(gr), s2(gr), s3(gr), s4(gr), s5(gr), s6(gr);
|
kpeter@597
|
249 |
ConstMap<Arc, int> cc(1), cu(std::numeric_limits<int>::max());
|
kpeter@593
|
250 |
Node v, w;
|
kpeter@593
|
251 |
|
kpeter@593
|
252 |
std::istringstream input(test_lgf);
|
kpeter@593
|
253 |
DigraphReader<Digraph>(gr, input)
|
kpeter@593
|
254 |
.arcMap("cost", c)
|
kpeter@593
|
255 |
.arcMap("cap", u)
|
kpeter@593
|
256 |
.arcMap("low1", l1)
|
kpeter@593
|
257 |
.arcMap("low2", l2)
|
kpeter@636
|
258 |
.arcMap("low3", l3)
|
kpeter@593
|
259 |
.nodeMap("sup1", s1)
|
kpeter@593
|
260 |
.nodeMap("sup2", s2)
|
kpeter@593
|
261 |
.nodeMap("sup3", s3)
|
kpeter@601
|
262 |
.nodeMap("sup4", s4)
|
kpeter@601
|
263 |
.nodeMap("sup5", s5)
|
kpeter@636
|
264 |
.nodeMap("sup6", s6)
|
kpeter@593
|
265 |
.node("source", v)
|
kpeter@593
|
266 |
.node("target", w)
|
kpeter@593
|
267 |
.run();
|
kpeter@636
|
268 |
|
kpeter@636
|
269 |
// Build a test digraph for testing negative costs
|
kpeter@636
|
270 |
Digraph ngr;
|
kpeter@636
|
271 |
Node n1 = ngr.addNode();
|
kpeter@636
|
272 |
Node n2 = ngr.addNode();
|
kpeter@636
|
273 |
Node n3 = ngr.addNode();
|
kpeter@636
|
274 |
Node n4 = ngr.addNode();
|
kpeter@636
|
275 |
Node n5 = ngr.addNode();
|
kpeter@636
|
276 |
Node n6 = ngr.addNode();
|
kpeter@636
|
277 |
Node n7 = ngr.addNode();
|
kpeter@636
|
278 |
|
kpeter@636
|
279 |
Arc a1 = ngr.addArc(n1, n2);
|
kpeter@636
|
280 |
Arc a2 = ngr.addArc(n1, n3);
|
kpeter@636
|
281 |
Arc a3 = ngr.addArc(n2, n4);
|
kpeter@636
|
282 |
Arc a4 = ngr.addArc(n3, n4);
|
kpeter@636
|
283 |
Arc a5 = ngr.addArc(n3, n2);
|
kpeter@636
|
284 |
Arc a6 = ngr.addArc(n5, n3);
|
kpeter@636
|
285 |
Arc a7 = ngr.addArc(n5, n6);
|
kpeter@636
|
286 |
Arc a8 = ngr.addArc(n6, n7);
|
kpeter@636
|
287 |
Arc a9 = ngr.addArc(n7, n5);
|
kpeter@636
|
288 |
|
kpeter@636
|
289 |
Digraph::ArcMap<int> nc(ngr), nl1(ngr, 0), nl2(ngr, 0);
|
kpeter@636
|
290 |
ConstMap<Arc, int> nu1(std::numeric_limits<int>::max()), nu2(5000);
|
kpeter@636
|
291 |
Digraph::NodeMap<int> ns(ngr, 0);
|
kpeter@636
|
292 |
|
kpeter@636
|
293 |
nl2[a7] = 1000;
|
kpeter@636
|
294 |
nl2[a8] = -1000;
|
kpeter@636
|
295 |
|
kpeter@636
|
296 |
ns[n1] = 100;
|
kpeter@636
|
297 |
ns[n4] = -100;
|
kpeter@636
|
298 |
|
kpeter@636
|
299 |
nc[a1] = 100;
|
kpeter@636
|
300 |
nc[a2] = 30;
|
kpeter@636
|
301 |
nc[a3] = 20;
|
kpeter@636
|
302 |
nc[a4] = 80;
|
kpeter@636
|
303 |
nc[a5] = 50;
|
kpeter@636
|
304 |
nc[a6] = 10;
|
kpeter@636
|
305 |
nc[a7] = 80;
|
kpeter@636
|
306 |
nc[a8] = 30;
|
kpeter@636
|
307 |
nc[a9] = -120;
|
kpeter@593
|
308 |
|
kpeter@597
|
309 |
// A. Test NetworkSimplex with the default pivot rule
|
kpeter@593
|
310 |
{
|
kpeter@598
|
311 |
NetworkSimplex<Digraph> mcf(gr);
|
kpeter@593
|
312 |
|
kpeter@601
|
313 |
// Check the equality form
|
kpeter@598
|
314 |
mcf.upperMap(u).costMap(c);
|
kpeter@598
|
315 |
checkMcf(mcf, mcf.supplyMap(s1).run(),
|
kpeter@636
|
316 |
gr, l1, u, c, s1, mcf.OPTIMAL, true, 5240, "#A1");
|
kpeter@598
|
317 |
checkMcf(mcf, mcf.stSupply(v, w, 27).run(),
|
kpeter@636
|
318 |
gr, l1, u, c, s2, mcf.OPTIMAL, true, 7620, "#A2");
|
kpeter@598
|
319 |
mcf.lowerMap(l2);
|
kpeter@598
|
320 |
checkMcf(mcf, mcf.supplyMap(s1).run(),
|
kpeter@636
|
321 |
gr, l2, u, c, s1, mcf.OPTIMAL, true, 5970, "#A3");
|
kpeter@598
|
322 |
checkMcf(mcf, mcf.stSupply(v, w, 27).run(),
|
kpeter@636
|
323 |
gr, l2, u, c, s2, mcf.OPTIMAL, true, 8010, "#A4");
|
kpeter@598
|
324 |
mcf.reset();
|
kpeter@598
|
325 |
checkMcf(mcf, mcf.supplyMap(s1).run(),
|
kpeter@636
|
326 |
gr, l1, cu, cc, s1, mcf.OPTIMAL, true, 74, "#A5");
|
kpeter@598
|
327 |
checkMcf(mcf, mcf.lowerMap(l2).stSupply(v, w, 27).run(),
|
kpeter@636
|
328 |
gr, l2, cu, cc, s2, mcf.OPTIMAL, true, 94, "#A6");
|
kpeter@598
|
329 |
mcf.reset();
|
kpeter@598
|
330 |
checkMcf(mcf, mcf.run(),
|
kpeter@636
|
331 |
gr, l1, cu, cc, s3, mcf.OPTIMAL, true, 0, "#A7");
|
kpeter@636
|
332 |
checkMcf(mcf, mcf.lowerMap(l2).upperMap(u).run(),
|
kpeter@636
|
333 |
gr, l2, u, cc, s3, mcf.INFEASIBLE, false, 0, "#A8");
|
kpeter@636
|
334 |
mcf.reset().lowerMap(l3).upperMap(u).costMap(c).supplyMap(s4);
|
kpeter@636
|
335 |
checkMcf(mcf, mcf.run(),
|
kpeter@636
|
336 |
gr, l3, u, c, s4, mcf.OPTIMAL, true, 6360, "#A9");
|
kpeter@601
|
337 |
|
kpeter@601
|
338 |
// Check the GEQ form
|
kpeter@636
|
339 |
mcf.reset().upperMap(u).costMap(c).supplyMap(s5);
|
kpeter@601
|
340 |
checkMcf(mcf, mcf.run(),
|
kpeter@636
|
341 |
gr, l1, u, c, s5, mcf.OPTIMAL, true, 3530, "#A10", GEQ);
|
kpeter@636
|
342 |
mcf.supplyType(mcf.GEQ);
|
kpeter@601
|
343 |
checkMcf(mcf, mcf.lowerMap(l2).run(),
|
kpeter@636
|
344 |
gr, l2, u, c, s5, mcf.OPTIMAL, true, 4540, "#A11", GEQ);
|
kpeter@636
|
345 |
mcf.supplyType(mcf.CARRY_SUPPLIES).supplyMap(s6);
|
kpeter@601
|
346 |
checkMcf(mcf, mcf.run(),
|
kpeter@636
|
347 |
gr, l2, u, c, s6, mcf.INFEASIBLE, false, 0, "#A12", GEQ);
|
kpeter@601
|
348 |
|
kpeter@601
|
349 |
// Check the LEQ form
|
kpeter@636
|
350 |
mcf.reset().supplyType(mcf.LEQ);
|
kpeter@636
|
351 |
mcf.upperMap(u).costMap(c).supplyMap(s6);
|
kpeter@601
|
352 |
checkMcf(mcf, mcf.run(),
|
kpeter@636
|
353 |
gr, l1, u, c, s6, mcf.OPTIMAL, true, 5080, "#A13", LEQ);
|
kpeter@601
|
354 |
checkMcf(mcf, mcf.lowerMap(l2).run(),
|
kpeter@636
|
355 |
gr, l2, u, c, s6, mcf.OPTIMAL, true, 5930, "#A14", LEQ);
|
kpeter@636
|
356 |
mcf.supplyType(mcf.SATISFY_DEMANDS).supplyMap(s5);
|
kpeter@601
|
357 |
checkMcf(mcf, mcf.run(),
|
kpeter@636
|
358 |
gr, l2, u, c, s5, mcf.INFEASIBLE, false, 0, "#A15", LEQ);
|
kpeter@636
|
359 |
|
kpeter@636
|
360 |
// Check negative costs
|
kpeter@636
|
361 |
NetworkSimplex<Digraph> nmcf(ngr);
|
kpeter@636
|
362 |
nmcf.lowerMap(nl1).costMap(nc).supplyMap(ns);
|
kpeter@636
|
363 |
checkMcf(nmcf, nmcf.run(),
|
kpeter@636
|
364 |
ngr, nl1, nu1, nc, ns, nmcf.UNBOUNDED, false, 0, "#A16");
|
kpeter@636
|
365 |
checkMcf(nmcf, nmcf.upperMap(nu2).run(),
|
kpeter@636
|
366 |
ngr, nl1, nu2, nc, ns, nmcf.OPTIMAL, true, -40000, "#A17");
|
kpeter@636
|
367 |
nmcf.reset().lowerMap(nl2).costMap(nc).supplyMap(ns);
|
kpeter@636
|
368 |
checkMcf(nmcf, nmcf.run(),
|
kpeter@636
|
369 |
ngr, nl2, nu1, nc, ns, nmcf.UNBOUNDED, false, 0, "#A18");
|
kpeter@593
|
370 |
}
|
kpeter@593
|
371 |
|
kpeter@597
|
372 |
// B. Test NetworkSimplex with each pivot rule
|
kpeter@593
|
373 |
{
|
kpeter@598
|
374 |
NetworkSimplex<Digraph> mcf(gr);
|
kpeter@636
|
375 |
mcf.supplyMap(s1).costMap(c).upperMap(u).lowerMap(l2);
|
kpeter@593
|
376 |
|
kpeter@598
|
377 |
checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::FIRST_ELIGIBLE),
|
kpeter@636
|
378 |
gr, l2, u, c, s1, mcf.OPTIMAL, true, 5970, "#B1");
|
kpeter@598
|
379 |
checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::BEST_ELIGIBLE),
|
kpeter@636
|
380 |
gr, l2, u, c, s1, mcf.OPTIMAL, true, 5970, "#B2");
|
kpeter@598
|
381 |
checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::BLOCK_SEARCH),
|
kpeter@636
|
382 |
gr, l2, u, c, s1, mcf.OPTIMAL, true, 5970, "#B3");
|
kpeter@598
|
383 |
checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::CANDIDATE_LIST),
|
kpeter@636
|
384 |
gr, l2, u, c, s1, mcf.OPTIMAL, true, 5970, "#B4");
|
kpeter@598
|
385 |
checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::ALTERING_LIST),
|
kpeter@636
|
386 |
gr, l2, u, c, s1, mcf.OPTIMAL, true, 5970, "#B5");
|
kpeter@593
|
387 |
}
|
kpeter@593
|
388 |
|
kpeter@593
|
389 |
return 0;
|
kpeter@593
|
390 |
}
|