[Lemon-commits] Alpar Juttner: Merge

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/b95898314e09
changeset: 650:b95898314e09
user:      Alpar Juttner <alpar [at] cs.elte.hu>
date:      Fri Apr 24 12:12:14 2009 +0100
description:
	Merge

diffstat:

 lemon/network_simplex.h    |  13 +++++++------
 test/min_cost_flow_test.cc |   7 +------
 tools/dimacs-solver.cc     |  30 ++++++++++++++++++++++++------
 3 files changed, 32 insertions(+), 18 deletions(-)

diffs (130 lines):

diff --git a/lemon/network_simplex.h b/lemon/network_simplex.h
--- a/lemon/network_simplex.h
+++ b/lemon/network_simplex.h
@@ -1147,6 +1147,7 @@
 
       // Run Circulation to check if a feasible solution exists
       typedef ConstMap<Arc, Flow> ConstArcMap;
+      ConstArcMap zero_arc_map(0), inf_arc_map(inf_cap);
       FlowNodeMap *csup = NULL;
       bool local_csup = false;
       if (_psupply) {
@@ -1167,17 +1168,17 @@
             circ_result = circ.run();
           } else {
             Circulation<GR, FlowArcMap, ConstArcMap, FlowNodeMap>
-              circ(_graph, *_plower, ConstArcMap(inf_cap), *csup);
+              circ(_graph, *_plower, inf_arc_map, *csup);
             circ_result = circ.run();
           }
         } else {
           if (_pupper) {
             Circulation<GR, ConstArcMap, FlowArcMap, FlowNodeMap>
-              circ(_graph, ConstArcMap(0), *_pupper, *csup);
+              circ(_graph, zero_arc_map, *_pupper, *csup);
             circ_result = circ.run();
           } else {
             Circulation<GR, ConstArcMap, ConstArcMap, FlowNodeMap>
-              circ(_graph, ConstArcMap(0), ConstArcMap(inf_cap), *csup);
+              circ(_graph, zero_arc_map, inf_arc_map, *csup);
             circ_result = circ.run();
           }
         }
@@ -1194,17 +1195,17 @@
             circ_result = circ.run();
           } else {
             Circulation<RevGraph, FlowArcMap, ConstArcMap, NegNodeMap>
-              circ(rgraph, *_plower, ConstArcMap(inf_cap), neg_csup);
+              circ(rgraph, *_plower, inf_arc_map, neg_csup);
             circ_result = circ.run();
           }
         } else {
           if (_pupper) {
             Circulation<RevGraph, ConstArcMap, FlowArcMap, NegNodeMap>
-              circ(rgraph, ConstArcMap(0), *_pupper, neg_csup);
+              circ(rgraph, zero_arc_map, *_pupper, neg_csup);
             circ_result = circ.run();
           } else {
             Circulation<RevGraph, ConstArcMap, ConstArcMap, NegNodeMap>
-              circ(rgraph, ConstArcMap(0), ConstArcMap(inf_cap), neg_csup);
+              circ(rgraph, zero_arc_map, inf_arc_map, neg_csup);
             circ_result = circ.run();
           }
         }
diff --git a/test/min_cost_flow_test.cc b/test/min_cost_flow_test.cc
--- a/test/min_cost_flow_test.cc
+++ b/test/min_cost_flow_test.cc
@@ -233,12 +233,7 @@
   {
     typedef int Flow;
     typedef int Cost;
-    // TODO: This typedef should be enabled if the standard maps are
-    // reference maps in the graph concepts (See #190).
-/**/
-    //typedef concepts::Digraph GR;
-    typedef ListDigraph GR;
-/**/
+    typedef concepts::Digraph GR;
     checkConcept< McfClassConcept<GR, Flow, Cost>,
                   NetworkSimplex<GR, Flow, Cost> >();
   }
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