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