diff --git a/tools/dimacs-solver.cc b/tools/dimacs-solver.cc --- a/tools/dimacs-solver.cc +++ b/tools/dimacs-solver.cc @@ -43,6 +43,7 @@ #include #include #include +#include using namespace lemon; typedef SmartDigraph Digraph; @@ -90,6 +91,28 @@ if(report) std::cerr << "\nMax flow value: " << pre.flowValue() << '\n'; } +template +void solve_min(ArgParser &ap, std::istream &is, std::ostream &, + DimacsDescriptor &desc) +{ + bool report = !ap.given("q"); + Digraph g; + Digraph::ArcMap lower(g), cap(g), cost(g); + Digraph::NodeMap sup(g); + Timer ti; + ti.restart(); + readDimacsMin(is, g, lower, cap, cost, sup, 0, desc); + if (report) std::cerr << "Read the file: " << ti << '\n'; + ti.restart(); + NetworkSimplex ns(g); + ns.lowerMap(lower).capacityMap(cap).costMap(cost).supplyMap(sup); + if (report) std::cerr << "Setup NetworkSimplex class: " << ti << '\n'; + ti.restart(); + ns.run(); + if (report) std::cerr << "Run NetworkSimplex: " << ti << '\n'; + if (report) std::cerr << "\nMin flow cost: " << ns.totalCost() << '\n'; +} + void solve_mat(ArgParser &ap, std::istream &is, std::ostream &, DimacsDescriptor &desc) { @@ -128,8 +151,7 @@ switch(desc.type) { case DimacsDescriptor::MIN: - std::cerr << - "\n\n Sorry, the min. cost flow solver is not yet available.\n"; + solve_min(ap,is,os,desc); break; case DimacsDescriptor::MAX: solve_max(ap,is,os,infty,desc);