[Lemon-commits] Peter Kovacs: Support LEQ and GEQ supply constra...
Lemon HG
hg at lemon.cs.elte.hu
Fri Apr 24 13:15:15 CEST 2009
details: http://lemon.cs.elte.hu/hg/lemon/rev/19b6f20e0ea2
changeset: 646:19b6f20e0ea2
user: Peter Kovacs <kpeter [at] inf.elte.hu>
date: Fri Apr 24 12:23:17 2009 +0200
description:
Support LEQ and GEQ supply constraints in dimacs-solver (#234, #219)
diffstat:
tools/dimacs-solver.cc | 30 ++++++++++++++++++++++++------
1 files changed, 24 insertions(+), 6 deletions(-)
diffs (60 lines):
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<class Value>
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<Value> lower(g), cap(g), cost(g);
Digraph::NodeMap<Value> 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<Digraph, Value> 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<Value>(ap,is,os,desc);
+ solve_min<Value>(ap,is,os,infty,desc);
break;
case DimacsDescriptor::MAX:
solve_max<Value>(ap,is,os,infty,desc);
More information about the Lemon-commits
mailing list