# HG changeset patch # User Peter Kovacs # Date 2009-02-24 09:52:26 # Node ID a79ef774fae12569fdba4acc7c79af425a15f814 # Parent e8349c6f12ca30c0a54b36825969cdaca81f933c Support min cost flow in dimacs-solver (#234) diff --git a/tools/dimacs-solver.cc b/tools/dimacs-solver.cc --- a/tools/dimacs-solver.cc +++ b/tools/dimacs-solver.cc @@ -44,6 +44,7 @@ #include #include #include +#include using namespace lemon; typedef SmartDigraph Digraph; @@ -91,6 +92,29 @@ 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, desc); + if (report) std::cerr << "Read the file: " << ti << '\n'; + ti.restart(); + NetworkSimplex< Digraph, Digraph::ArcMap, Digraph::ArcMap, + Digraph::ArcMap, Digraph::NodeMap > + ns(g, lower, cap, cost, 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) { @@ -118,8 +142,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,desc);