test/min_cost_flow_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Wed, 25 Aug 2010 21:34:58 +0200
changeset 742 16d466589b54
parent 662 cc61d09f053b
child 761 f1398882a928
permissions -rw-r--r--
Backport the CMAKE related changesets from the main branch

[e20fecd1945f] Add check target for CMake (#388)
[e74b5db4f2c6] Put the output of chg-len.py in the version string (#389)
[7d166b8b8018] Safer call of ./scripts/chg-len.py on Windows (#389)
[659ba4805a48] Make CMAKE config more consistent with configure.ac (#390)
[63e4468c680e] Add 'Maintainer' CMAKE build type (#388, #390)
[a725503acfe9] Allow CPACK configuration on all platforms
[10242c611190] Create and install lemon.pc (#393)
[48e29534cf03] The deafult target doesn't build lp_test and mip_test (#388)
[0fbbdd578c06] Full path for DoxygenLayout.xml in Doxyfile.in (#395)
[481496e6d71f] SOURCE_BROWSER Doxygen switch is configurable from CMAKE (#395)
[09282720100b] update-external-tags CMAKE target (#395)
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@668
    96
      
kpeter@668
    97
      const Constraints& me = *this;
kpeter@593
    98
kpeter@668
    99
      MCF mcf(me.g);
kpeter@638
   100
      const MCF& const_mcf = mcf;
kpeter@593
   101
kpeter@598
   102
      b = mcf.reset()
kpeter@668
   103
             .lowerMap(me.lower)
kpeter@668
   104
             .upperMap(me.upper)
kpeter@668
   105
             .costMap(me.cost)
kpeter@668
   106
             .supplyMap(me.sup)
kpeter@668
   107
             .stSupply(me.n, me.n, me.k)
kpeter@597
   108
             .run();
kpeter@597
   109
kpeter@636
   110
      c = const_mcf.totalCost();
kpeter@638
   111
      x = const_mcf.template totalCost<double>();
kpeter@668
   112
      v = const_mcf.flow(me.a);
kpeter@668
   113
      c = const_mcf.potential(me.n);
kpeter@638
   114
      const_mcf.flowMap(fm);
kpeter@638
   115
      const_mcf.potentialMap(pm);
kpeter@593
   116
    }
kpeter@593
   117
kpeter@593
   118
    typedef typename GR::Node Node;
kpeter@593
   119
    typedef typename GR::Arc Arc;
kpeter@638
   120
    typedef concepts::ReadMap<Node, Value> NM;
kpeter@638
   121
    typedef concepts::ReadMap<Arc, Value> VAM;
kpeter@599
   122
    typedef concepts::ReadMap<Arc, Cost> CAM;
kpeter@638
   123
    typedef concepts::WriteMap<Arc, Value> FlowMap;
kpeter@638
   124
    typedef concepts::WriteMap<Node, Cost> PotMap;
kpeter@668
   125
  
kpeter@668
   126
    GR g;
kpeter@668
   127
    VAM lower;
kpeter@668
   128
    VAM upper;
kpeter@668
   129
    CAM cost;
kpeter@668
   130
    NM sup;
kpeter@668
   131
    Node n;
kpeter@668
   132
    Arc a;
kpeter@668
   133
    Value k;
kpeter@593
   134
kpeter@638
   135
    FlowMap fm;
kpeter@638
   136
    PotMap pm;
kpeter@597
   137
    bool b;
kpeter@638
   138
    double x;
kpeter@638
   139
    typename MCF::Value v;
kpeter@638
   140
    typename MCF::Cost c;
kpeter@593
   141
  };
kpeter@593
   142
kpeter@593
   143
};
kpeter@593
   144
kpeter@593
   145
kpeter@593
   146
// Check the feasibility of the given flow (primal soluiton)
kpeter@593
   147
template < typename GR, typename LM, typename UM,
kpeter@593
   148
           typename SM, typename FM >
kpeter@593
   149
bool checkFlow( const GR& gr, const LM& lower, const UM& upper,
kpeter@601
   150
                const SM& supply, const FM& flow,
kpeter@636
   151
                SupplyType type = EQ )
kpeter@593
   152
{
kpeter@593
   153
  TEMPLATE_DIGRAPH_TYPEDEFS(GR);
kpeter@593
   154
kpeter@593
   155
  for (ArcIt e(gr); e != INVALID; ++e) {
kpeter@593
   156
    if (flow[e] < lower[e] || flow[e] > upper[e]) return false;
kpeter@593
   157
  }
kpeter@593
   158
kpeter@593
   159
  for (NodeIt n(gr); n != INVALID; ++n) {
kpeter@593
   160
    typename SM::Value sum = 0;
kpeter@593
   161
    for (OutArcIt e(gr, n); e != INVALID; ++e)
kpeter@593
   162
      sum += flow[e];
kpeter@593
   163
    for (InArcIt e(gr, n); e != INVALID; ++e)
kpeter@593
   164
      sum -= flow[e];
kpeter@601
   165
    bool b = (type ==  EQ && sum == supply[n]) ||
kpeter@601
   166
             (type == GEQ && sum >= supply[n]) ||
kpeter@601
   167
             (type == LEQ && sum <= supply[n]);
kpeter@601
   168
    if (!b) return false;
kpeter@593
   169
  }
kpeter@593
   170
kpeter@593
   171
  return true;
kpeter@593
   172
}
kpeter@593
   173
kpeter@593
   174
// Check the feasibility of the given potentials (dual soluiton)
kpeter@597
   175
// using the "Complementary Slackness" optimality condition
kpeter@593
   176
template < typename GR, typename LM, typename UM,
kpeter@601
   177
           typename CM, typename SM, typename FM, typename PM >
kpeter@593
   178
bool checkPotential( const GR& gr, const LM& lower, const UM& upper,
kpeter@601
   179
                     const CM& cost, const SM& supply, const FM& flow, 
kpeter@662
   180
                     const PM& pi, SupplyType type )
kpeter@593
   181
{
kpeter@593
   182
  TEMPLATE_DIGRAPH_TYPEDEFS(GR);
kpeter@593
   183
kpeter@593
   184
  bool opt = true;
kpeter@593
   185
  for (ArcIt e(gr); opt && e != INVALID; ++e) {
kpeter@593
   186
    typename CM::Value red_cost =
kpeter@593
   187
      cost[e] + pi[gr.source(e)] - pi[gr.target(e)];
kpeter@593
   188
    opt = red_cost == 0 ||
kpeter@593
   189
          (red_cost > 0 && flow[e] == lower[e]) ||
kpeter@593
   190
          (red_cost < 0 && flow[e] == upper[e]);
kpeter@593
   191
  }
kpeter@601
   192
  
kpeter@601
   193
  for (NodeIt n(gr); opt && n != INVALID; ++n) {
kpeter@601
   194
    typename SM::Value sum = 0;
kpeter@601
   195
    for (OutArcIt e(gr, n); e != INVALID; ++e)
kpeter@601
   196
      sum += flow[e];
kpeter@601
   197
    for (InArcIt e(gr, n); e != INVALID; ++e)
kpeter@601
   198
      sum -= flow[e];
kpeter@662
   199
    if (type != LEQ) {
kpeter@662
   200
      opt = (pi[n] <= 0) && (sum == supply[n] || pi[n] == 0);
kpeter@662
   201
    } else {
kpeter@662
   202
      opt = (pi[n] >= 0) && (sum == supply[n] || pi[n] == 0);
kpeter@662
   203
    }
kpeter@601
   204
  }
kpeter@601
   205
  
kpeter@593
   206
  return opt;
kpeter@593
   207
}
kpeter@593
   208
kpeter@662
   209
// Check whether the dual cost is equal to the primal cost
kpeter@662
   210
template < typename GR, typename LM, typename UM,
kpeter@662
   211
           typename CM, typename SM, typename PM >
kpeter@662
   212
bool checkDualCost( const GR& gr, const LM& lower, const UM& upper,
kpeter@662
   213
                    const CM& cost, const SM& supply, const PM& pi,
kpeter@662
   214
                    typename CM::Value total )
kpeter@662
   215
{
kpeter@662
   216
  TEMPLATE_DIGRAPH_TYPEDEFS(GR);
kpeter@662
   217
kpeter@662
   218
  typename CM::Value dual_cost = 0;
kpeter@662
   219
  SM red_supply(gr);
kpeter@662
   220
  for (NodeIt n(gr); n != INVALID; ++n) {
kpeter@662
   221
    red_supply[n] = supply[n];
kpeter@662
   222
  }
kpeter@662
   223
  for (ArcIt a(gr); a != INVALID; ++a) {
kpeter@662
   224
    if (lower[a] != 0) {
kpeter@662
   225
      dual_cost += lower[a] * cost[a];
kpeter@662
   226
      red_supply[gr.source(a)] -= lower[a];
kpeter@662
   227
      red_supply[gr.target(a)] += lower[a];
kpeter@662
   228
    }
kpeter@662
   229
  }
kpeter@662
   230
  
kpeter@662
   231
  for (NodeIt n(gr); n != INVALID; ++n) {
kpeter@662
   232
    dual_cost -= red_supply[n] * pi[n];
kpeter@662
   233
  }
kpeter@662
   234
  for (ArcIt a(gr); a != INVALID; ++a) {
kpeter@662
   235
    typename CM::Value red_cost =
kpeter@662
   236
      cost[a] + pi[gr.source(a)] - pi[gr.target(a)];
kpeter@662
   237
    dual_cost -= (upper[a] - lower[a]) * std::max(-red_cost, 0);
kpeter@662
   238
  }
kpeter@662
   239
  
kpeter@662
   240
  return dual_cost == total;
kpeter@662
   241
}
kpeter@662
   242
kpeter@593
   243
// Run a minimum cost flow algorithm and check the results
kpeter@593
   244
template < typename MCF, typename GR,
kpeter@593
   245
           typename LM, typename UM,
kpeter@636
   246
           typename CM, typename SM,
kpeter@636
   247
           typename PT >
kpeter@636
   248
void checkMcf( const MCF& mcf, PT mcf_result,
kpeter@593
   249
               const GR& gr, const LM& lower, const UM& upper,
kpeter@593
   250
               const CM& cost, const SM& supply,
kpeter@636
   251
               PT result, bool optimal, typename CM::Value total,
kpeter@601
   252
               const std::string &test_id = "",
kpeter@636
   253
               SupplyType type = EQ )
kpeter@593
   254
{
kpeter@593
   255
  check(mcf_result == result, "Wrong result " + test_id);
kpeter@636
   256
  if (optimal) {
kpeter@638
   257
    typename GR::template ArcMap<typename SM::Value> flow(gr);
kpeter@638
   258
    typename GR::template NodeMap<typename CM::Value> pi(gr);
kpeter@638
   259
    mcf.flowMap(flow);
kpeter@638
   260
    mcf.potentialMap(pi);
kpeter@638
   261
    check(checkFlow(gr, lower, upper, supply, flow, type),
kpeter@593
   262
          "The flow is not feasible " + test_id);
kpeter@593
   263
    check(mcf.totalCost() == total, "The flow is not optimal " + test_id);
kpeter@662
   264
    check(checkPotential(gr, lower, upper, cost, supply, flow, pi, type),
kpeter@593
   265
          "Wrong potentials " + test_id);
kpeter@662
   266
    check(checkDualCost(gr, lower, upper, cost, supply, pi, total),
kpeter@662
   267
          "Wrong dual cost " + test_id);
kpeter@593
   268
  }
kpeter@593
   269
}
kpeter@593
   270
kpeter@593
   271
int main()
kpeter@593
   272
{
kpeter@593
   273
  // Check the interfaces
kpeter@593
   274
  {
kpeter@607
   275
    typedef concepts::Digraph GR;
kpeter@638
   276
    checkConcept< McfClassConcept<GR, int, int>,
kpeter@638
   277
                  NetworkSimplex<GR> >();
kpeter@638
   278
    checkConcept< McfClassConcept<GR, double, double>,
kpeter@638
   279
                  NetworkSimplex<GR, double> >();
kpeter@638
   280
    checkConcept< McfClassConcept<GR, int, double>,
kpeter@638
   281
                  NetworkSimplex<GR, int, double> >();
kpeter@593
   282
  }
kpeter@593
   283
kpeter@593
   284
  // Run various MCF tests
kpeter@593
   285
  typedef ListDigraph Digraph;
kpeter@593
   286
  DIGRAPH_TYPEDEFS(ListDigraph);
kpeter@593
   287
kpeter@593
   288
  // Read the test digraph
kpeter@593
   289
  Digraph gr;
kpeter@636
   290
  Digraph::ArcMap<int> c(gr), l1(gr), l2(gr), l3(gr), u(gr);
kpeter@636
   291
  Digraph::NodeMap<int> s1(gr), s2(gr), s3(gr), s4(gr), s5(gr), s6(gr);
kpeter@597
   292
  ConstMap<Arc, int> cc(1), cu(std::numeric_limits<int>::max());
kpeter@593
   293
  Node v, w;
kpeter@593
   294
kpeter@593
   295
  std::istringstream input(test_lgf);
kpeter@593
   296
  DigraphReader<Digraph>(gr, input)
kpeter@593
   297
    .arcMap("cost", c)
kpeter@593
   298
    .arcMap("cap", u)
kpeter@593
   299
    .arcMap("low1", l1)
kpeter@593
   300
    .arcMap("low2", l2)
kpeter@636
   301
    .arcMap("low3", l3)
kpeter@593
   302
    .nodeMap("sup1", s1)
kpeter@593
   303
    .nodeMap("sup2", s2)
kpeter@593
   304
    .nodeMap("sup3", s3)
kpeter@601
   305
    .nodeMap("sup4", s4)
kpeter@601
   306
    .nodeMap("sup5", s5)
kpeter@636
   307
    .nodeMap("sup6", s6)
kpeter@593
   308
    .node("source", v)
kpeter@593
   309
    .node("target", w)
kpeter@593
   310
    .run();
kpeter@636
   311
  
kpeter@662
   312
  // Build test digraphs with negative costs
kpeter@662
   313
  Digraph neg_gr;
kpeter@662
   314
  Node n1 = neg_gr.addNode();
kpeter@662
   315
  Node n2 = neg_gr.addNode();
kpeter@662
   316
  Node n3 = neg_gr.addNode();
kpeter@662
   317
  Node n4 = neg_gr.addNode();
kpeter@662
   318
  Node n5 = neg_gr.addNode();
kpeter@662
   319
  Node n6 = neg_gr.addNode();
kpeter@662
   320
  Node n7 = neg_gr.addNode();
kpeter@636
   321
  
kpeter@662
   322
  Arc a1 = neg_gr.addArc(n1, n2);
kpeter@662
   323
  Arc a2 = neg_gr.addArc(n1, n3);
kpeter@662
   324
  Arc a3 = neg_gr.addArc(n2, n4);
kpeter@662
   325
  Arc a4 = neg_gr.addArc(n3, n4);
kpeter@662
   326
  Arc a5 = neg_gr.addArc(n3, n2);
kpeter@662
   327
  Arc a6 = neg_gr.addArc(n5, n3);
kpeter@662
   328
  Arc a7 = neg_gr.addArc(n5, n6);
kpeter@662
   329
  Arc a8 = neg_gr.addArc(n6, n7);
kpeter@662
   330
  Arc a9 = neg_gr.addArc(n7, n5);
kpeter@636
   331
  
kpeter@662
   332
  Digraph::ArcMap<int> neg_c(neg_gr), neg_l1(neg_gr, 0), neg_l2(neg_gr, 0);
kpeter@662
   333
  ConstMap<Arc, int> neg_u1(std::numeric_limits<int>::max()), neg_u2(5000);
kpeter@662
   334
  Digraph::NodeMap<int> neg_s(neg_gr, 0);
kpeter@636
   335
  
kpeter@662
   336
  neg_l2[a7] =  1000;
kpeter@662
   337
  neg_l2[a8] = -1000;
kpeter@636
   338
  
kpeter@662
   339
  neg_s[n1] =  100;
kpeter@662
   340
  neg_s[n4] = -100;
kpeter@636
   341
  
kpeter@662
   342
  neg_c[a1] =  100;
kpeter@662
   343
  neg_c[a2] =   30;
kpeter@662
   344
  neg_c[a3] =   20;
kpeter@662
   345
  neg_c[a4] =   80;
kpeter@662
   346
  neg_c[a5] =   50;
kpeter@662
   347
  neg_c[a6] =   10;
kpeter@662
   348
  neg_c[a7] =   80;
kpeter@662
   349
  neg_c[a8] =   30;
kpeter@662
   350
  neg_c[a9] = -120;
kpeter@662
   351
kpeter@662
   352
  Digraph negs_gr;
kpeter@662
   353
  Digraph::NodeMap<int> negs_s(negs_gr);
kpeter@662
   354
  Digraph::ArcMap<int> negs_c(negs_gr);
kpeter@662
   355
  ConstMap<Arc, int> negs_l(0), negs_u(1000);
kpeter@662
   356
  n1 = negs_gr.addNode();
kpeter@662
   357
  n2 = negs_gr.addNode();
kpeter@662
   358
  negs_s[n1] = 100;
kpeter@662
   359
  negs_s[n2] = -300;
kpeter@662
   360
  negs_c[negs_gr.addArc(n1, n2)] = -1;
kpeter@662
   361
kpeter@593
   362
kpeter@597
   363
  // A. Test NetworkSimplex with the default pivot rule
kpeter@593
   364
  {
kpeter@598
   365
    NetworkSimplex<Digraph> mcf(gr);
kpeter@593
   366
kpeter@601
   367
    // Check the equality form
kpeter@598
   368
    mcf.upperMap(u).costMap(c);
kpeter@598
   369
    checkMcf(mcf, mcf.supplyMap(s1).run(),
kpeter@636
   370
             gr, l1, u, c, s1, mcf.OPTIMAL, true,   5240, "#A1");
kpeter@598
   371
    checkMcf(mcf, mcf.stSupply(v, w, 27).run(),
kpeter@636
   372
             gr, l1, u, c, s2, mcf.OPTIMAL, true,   7620, "#A2");
kpeter@598
   373
    mcf.lowerMap(l2);
kpeter@598
   374
    checkMcf(mcf, mcf.supplyMap(s1).run(),
kpeter@636
   375
             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#A3");
kpeter@598
   376
    checkMcf(mcf, mcf.stSupply(v, w, 27).run(),
kpeter@636
   377
             gr, l2, u, c, s2, mcf.OPTIMAL, true,   8010, "#A4");
kpeter@598
   378
    mcf.reset();
kpeter@598
   379
    checkMcf(mcf, mcf.supplyMap(s1).run(),
kpeter@636
   380
             gr, l1, cu, cc, s1, mcf.OPTIMAL, true,   74, "#A5");
kpeter@598
   381
    checkMcf(mcf, mcf.lowerMap(l2).stSupply(v, w, 27).run(),
kpeter@636
   382
             gr, l2, cu, cc, s2, mcf.OPTIMAL, true,   94, "#A6");
kpeter@598
   383
    mcf.reset();
kpeter@598
   384
    checkMcf(mcf, mcf.run(),
kpeter@636
   385
             gr, l1, cu, cc, s3, mcf.OPTIMAL, true,    0, "#A7");
kpeter@636
   386
    checkMcf(mcf, mcf.lowerMap(l2).upperMap(u).run(),
kpeter@636
   387
             gr, l2, u, cc, s3, mcf.INFEASIBLE, false, 0, "#A8");
kpeter@636
   388
    mcf.reset().lowerMap(l3).upperMap(u).costMap(c).supplyMap(s4);
kpeter@636
   389
    checkMcf(mcf, mcf.run(),
kpeter@636
   390
             gr, l3, u, c, s4, mcf.OPTIMAL, true,   6360, "#A9");
kpeter@601
   391
kpeter@601
   392
    // Check the GEQ form
kpeter@636
   393
    mcf.reset().upperMap(u).costMap(c).supplyMap(s5);
kpeter@601
   394
    checkMcf(mcf, mcf.run(),
kpeter@636
   395
             gr, l1, u, c, s5, mcf.OPTIMAL, true,   3530, "#A10", GEQ);
kpeter@636
   396
    mcf.supplyType(mcf.GEQ);
kpeter@601
   397
    checkMcf(mcf, mcf.lowerMap(l2).run(),
kpeter@636
   398
             gr, l2, u, c, s5, mcf.OPTIMAL, true,   4540, "#A11", GEQ);
kpeter@662
   399
    mcf.supplyMap(s6);
kpeter@601
   400
    checkMcf(mcf, mcf.run(),
kpeter@636
   401
             gr, l2, u, c, s6, mcf.INFEASIBLE, false,  0, "#A12", GEQ);
kpeter@601
   402
kpeter@601
   403
    // Check the LEQ form
kpeter@636
   404
    mcf.reset().supplyType(mcf.LEQ);
kpeter@636
   405
    mcf.upperMap(u).costMap(c).supplyMap(s6);
kpeter@601
   406
    checkMcf(mcf, mcf.run(),
kpeter@636
   407
             gr, l1, u, c, s6, mcf.OPTIMAL, true,   5080, "#A13", LEQ);
kpeter@601
   408
    checkMcf(mcf, mcf.lowerMap(l2).run(),
kpeter@636
   409
             gr, l2, u, c, s6, mcf.OPTIMAL, true,   5930, "#A14", LEQ);
kpeter@662
   410
    mcf.supplyMap(s5);
kpeter@601
   411
    checkMcf(mcf, mcf.run(),
kpeter@636
   412
             gr, l2, u, c, s5, mcf.INFEASIBLE, false,  0, "#A15", LEQ);
kpeter@636
   413
kpeter@636
   414
    // Check negative costs
kpeter@662
   415
    NetworkSimplex<Digraph> neg_mcf(neg_gr);
kpeter@662
   416
    neg_mcf.lowerMap(neg_l1).costMap(neg_c).supplyMap(neg_s);
kpeter@662
   417
    checkMcf(neg_mcf, neg_mcf.run(), neg_gr, neg_l1, neg_u1,
kpeter@662
   418
      neg_c, neg_s, neg_mcf.UNBOUNDED, false,    0, "#A16");
kpeter@662
   419
    neg_mcf.upperMap(neg_u2);
kpeter@662
   420
    checkMcf(neg_mcf, neg_mcf.run(), neg_gr, neg_l1, neg_u2,
kpeter@662
   421
      neg_c, neg_s, neg_mcf.OPTIMAL, true,  -40000, "#A17");
kpeter@662
   422
    neg_mcf.reset().lowerMap(neg_l2).costMap(neg_c).supplyMap(neg_s);
kpeter@662
   423
    checkMcf(neg_mcf, neg_mcf.run(), neg_gr, neg_l2, neg_u1,
kpeter@662
   424
      neg_c, neg_s, neg_mcf.UNBOUNDED, false,    0, "#A18");
kpeter@662
   425
      
kpeter@662
   426
    NetworkSimplex<Digraph> negs_mcf(negs_gr);
kpeter@662
   427
    negs_mcf.costMap(negs_c).supplyMap(negs_s);
kpeter@662
   428
    checkMcf(negs_mcf, negs_mcf.run(), negs_gr, negs_l, negs_u,
kpeter@662
   429
      negs_c, negs_s, negs_mcf.OPTIMAL, true, -300, "#A19", GEQ);
kpeter@593
   430
  }
kpeter@593
   431
kpeter@597
   432
  // B. Test NetworkSimplex with each pivot rule
kpeter@593
   433
  {
kpeter@598
   434
    NetworkSimplex<Digraph> mcf(gr);
kpeter@636
   435
    mcf.supplyMap(s1).costMap(c).upperMap(u).lowerMap(l2);
kpeter@593
   436
kpeter@598
   437
    checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::FIRST_ELIGIBLE),
kpeter@636
   438
             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B1");
kpeter@598
   439
    checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::BEST_ELIGIBLE),
kpeter@636
   440
             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B2");
kpeter@598
   441
    checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::BLOCK_SEARCH),
kpeter@636
   442
             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B3");
kpeter@598
   443
    checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::CANDIDATE_LIST),
kpeter@636
   444
             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B4");
kpeter@598
   445
    checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::ALTERING_LIST),
kpeter@636
   446
             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B5");
kpeter@593
   447
  }
kpeter@593
   448
kpeter@593
   449
  return 0;
kpeter@593
   450
}