# HG changeset patch
# User Alpar Juttner <alpar@cs.elte.hu>
# Date 1240571534 -3600
# Node ID b95898314e095d3b9f994b1a1068518f25016745
# Parent  4137ef9aacc6570e5ec02d979059eb94b695938d# Parent  e3d9bff447ed1600879aaf90eaeeaf7c44bb0ee2
Merge

diff -r 4137ef9aacc6 -r b95898314e09 lemon/network_simplex.h
--- a/lemon/network_simplex.h	Fri Apr 24 11:54:48 2009 +0200
+++ b/lemon/network_simplex.h	Fri Apr 24 12:12:14 2009 +0100
@@ -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 -r 4137ef9aacc6 -r b95898314e09 test/min_cost_flow_test.cc
--- a/test/min_cost_flow_test.cc	Fri Apr 24 11:54:48 2009 +0200
+++ b/test/min_cost_flow_test.cc	Fri Apr 24 12:12:14 2009 +0100
@@ -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 -r 4137ef9aacc6 -r b95898314e09 tools/dimacs-solver.cc
--- a/tools/dimacs-solver.cc	Fri Apr 24 11:54:48 2009 +0200
+++ b/tools/dimacs-solver.cc	Fri Apr 24 12:12:14 2009 +0100
@@ -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);