tools/dimacs-solver.cc
changeset 611 85cb3aa71cce
parent 594 d657c71db7db
parent 605 5232721b3f14
child 614 19b6f20e0ea2
     1.1 --- a/tools/dimacs-solver.cc	Tue Apr 21 13:08:19 2009 +0100
     1.2 +++ b/tools/dimacs-solver.cc	Tue Apr 21 15:18:54 2009 +0100
     1.3 @@ -43,6 +43,7 @@
     1.4  #include <lemon/dijkstra.h>
     1.5  #include <lemon/preflow.h>
     1.6  #include <lemon/matching.h>
     1.7 +#include <lemon/network_simplex.h>
     1.8  
     1.9  using namespace lemon;
    1.10  typedef SmartDigraph Digraph;
    1.11 @@ -90,6 +91,28 @@
    1.12    if(report) std::cerr << "\nMax flow value: " << pre.flowValue() << '\n';  
    1.13  }
    1.14  
    1.15 +template<class Value>
    1.16 +void solve_min(ArgParser &ap, std::istream &is, std::ostream &,
    1.17 +               DimacsDescriptor &desc)
    1.18 +{
    1.19 +  bool report = !ap.given("q");
    1.20 +  Digraph g;
    1.21 +  Digraph::ArcMap<Value> lower(g), cap(g), cost(g);
    1.22 +  Digraph::NodeMap<Value> sup(g);
    1.23 +  Timer ti;
    1.24 +  ti.restart();
    1.25 +  readDimacsMin(is, g, lower, cap, cost, sup, 0, desc);
    1.26 +  if (report) std::cerr << "Read the file: " << ti << '\n';
    1.27 +  ti.restart();
    1.28 +  NetworkSimplex<Digraph, Value> ns(g);
    1.29 +  ns.lowerMap(lower).capacityMap(cap).costMap(cost).supplyMap(sup);
    1.30 +  if (report) std::cerr << "Setup NetworkSimplex class: " << ti << '\n';
    1.31 +  ti.restart();
    1.32 +  ns.run();
    1.33 +  if (report) std::cerr << "Run NetworkSimplex: " << ti << '\n';
    1.34 +  if (report) std::cerr << "\nMin flow cost: " << ns.totalCost() << '\n';
    1.35 +}
    1.36 +
    1.37  void solve_mat(ArgParser &ap, std::istream &is, std::ostream &,
    1.38                DimacsDescriptor &desc)
    1.39  {
    1.40 @@ -128,8 +151,7 @@
    1.41    switch(desc.type)
    1.42      {
    1.43      case DimacsDescriptor::MIN:
    1.44 -      std::cerr <<
    1.45 -        "\n\n Sorry, the min. cost flow solver is not yet available.\n";
    1.46 +      solve_min<Value>(ap,is,os,desc);
    1.47        break;
    1.48      case DimacsDescriptor::MAX:
    1.49        solve_max<Value>(ap,is,os,infty,desc);