# HG changeset patch # User Peter Kovacs # Date 2009-04-24 12:23:17 # Node ID 19b6f20e0ea23619587c72c77c5442ee5602f23c # Parent b1811c363299b056b9ac0f2ddc3ce9e4c5e50520 Support LEQ and GEQ supply constraints in dimacs-solver (#234, #219) diff --git a/tools/dimacs-solver.cc b/tools/dimacs-solver.cc --- a/tools/dimacs-solver.cc +++ b/tools/dimacs-solver.cc @@ -93,24 +93,42 @@ template void solve_min(ArgParser &ap, std::istream &is, std::ostream &, - DimacsDescriptor &desc) + Value infty, 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); + readDimacsMin(is, g, lower, cap, cost, sup, infty, desc); + ti.stop(); + Value sum_sup = 0; + for (Digraph::NodeIt n(g); n != INVALID; ++n) { + sum_sup += sup[n]; + } + if (report) { + std::cerr << "Sum of supply values: " << sum_sup << "\n"; + if (sum_sup <= 0) + std::cerr << "GEQ supply contraints are used for NetworkSimplex\n\n"; + else + std::cerr << "LEQ supply contraints are used for NetworkSimplex\n\n"; + } if (report) std::cerr << "Read the file: " << ti << '\n'; + ti.restart(); NetworkSimplex ns(g); ns.lowerMap(lower).capacityMap(cap).costMap(cost).supplyMap(sup); + if (sum_sup > 0) ns.problemType(ns.LEQ); 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'; + bool res = ns.run(); + if (report) { + std::cerr << "Run NetworkSimplex: " << ti << "\n\n"; + std::cerr << "Feasible flow: " << (res ? "found" : "not found") << '\n'; + if (res) std::cerr << "Min flow cost: " << ns.totalCost() << '\n'; + } } void solve_mat(ArgParser &ap, std::istream &is, std::ostream &, @@ -151,7 +169,7 @@ switch(desc.type) { case DimacsDescriptor::MIN: - solve_min(ap,is,os,desc); + solve_min(ap,is,os,infty,desc); break; case DimacsDescriptor::MAX: solve_max(ap,is,os,infty,desc);