Index: test/CMakeLists.txt
===================================================================
--- test/CMakeLists.txt	(revision 674)
+++ test/CMakeLists.txt	(revision 668)
@@ -37,20 +37,20 @@
   unionfind_test)
 
-IF(LEMON_HAVE_LP)
+IF(HAVE_LP)
   ADD_EXECUTABLE(lp_test lp_test.cc)
   SET(LP_TEST_LIBS lemon)
-  IF(LEMON_HAVE_GLPK)
+  IF(HAVE_GLPK)
     SET(LP_TEST_LIBS ${LP_TEST_LIBS} ${GLPK_LIBRARIES})
-  ENDIF(LEMON_HAVE_GLPK)
-  IF(LEMON_HAVE_CPLEX)
+  ENDIF(HAVE_GLPK)
+  IF(HAVE_CPLEX)
     SET(LP_TEST_LIBS ${LP_TEST_LIBS} ${CPLEX_LIBRARIES})
-  ENDIF(LEMON_HAVE_CPLEX)
-  IF(LEMON_HAVE_CLP)
+  ENDIF(HAVE_CPLEX)
+  IF(HAVE_CLP)
     SET(LP_TEST_LIBS ${LP_TEST_LIBS} ${COIN_CLP_LIBRARIES})
-  ENDIF(LEMON_HAVE_CLP)
+  ENDIF(HAVE_CLP)
   TARGET_LINK_LIBRARIES(lp_test ${LP_TEST_LIBS})
   ADD_TEST(lp_test lp_test)
 
-  IF(WIN32 AND LEMON_HAVE_GLPK)
+  IF(WIN32 AND HAVE_GLPK)
     GET_TARGET_PROPERTY(TARGET_LOC lp_test LOCATION)
     GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH)
@@ -60,6 +60,6 @@
       COMMAND cmake -E copy ${GLPK_BIN_DIR}/zlib1.dll ${TARGET_PATH}
     )
-  ENDIF(WIN32 AND LEMON_HAVE_GLPK)
-  IF(WIN32 AND LEMON_HAVE_CPLEX)
+  ENDIF(WIN32 AND HAVE_GLPK)
+  IF(WIN32 AND HAVE_CPLEX)
     GET_TARGET_PROPERTY(TARGET_LOC lp_test LOCATION)
     GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH)
@@ -67,23 +67,23 @@
       COMMAND cmake -E copy ${CPLEX_BIN_DIR}/cplex91.dll ${TARGET_PATH}
     )
-  ENDIF(WIN32 AND LEMON_HAVE_CPLEX)
-ENDIF(LEMON_HAVE_LP)
+  ENDIF(WIN32 AND HAVE_CPLEX)
+ENDIF(HAVE_LP)
 
-IF(LEMON_HAVE_MIP)
+IF(HAVE_MIP)
   ADD_EXECUTABLE(mip_test mip_test.cc)
   SET(MIP_TEST_LIBS lemon)
-  IF(LEMON_HAVE_GLPK)
+  IF(HAVE_GLPK)
     SET(MIP_TEST_LIBS ${MIP_TEST_LIBS} ${GLPK_LIBRARIES})
-  ENDIF(LEMON_HAVE_GLPK)
-  IF(LEMON_HAVE_CPLEX)
+  ENDIF(HAVE_GLPK)
+  IF(HAVE_CPLEX)
     SET(MIP_TEST_LIBS ${MIP_TEST_LIBS} ${CPLEX_LIBRARIES})
-  ENDIF(LEMON_HAVE_CPLEX)
-  IF(LEMON_HAVE_CBC)
+  ENDIF(HAVE_CPLEX)
+  IF(HAVE_CBC)
     SET(MIP_TEST_LIBS ${MIP_TEST_LIBS} ${COIN_CBC_LIBRARIES})
-  ENDIF(LEMON_HAVE_CBC)
+  ENDIF(HAVE_CBC)
   TARGET_LINK_LIBRARIES(mip_test ${MIP_TEST_LIBS})
   ADD_TEST(mip_test mip_test)
 
-  IF(WIN32 AND LEMON_HAVE_GLPK)
+  IF(WIN32 AND HAVE_GLPK)
     GET_TARGET_PROPERTY(TARGET_LOC mip_test LOCATION)
     GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH)
@@ -93,6 +93,6 @@
       COMMAND cmake -E copy ${GLPK_BIN_DIR}/zlib1.dll ${TARGET_PATH}
     )
-  ENDIF(WIN32 AND LEMON_HAVE_GLPK)
-  IF(WIN32 AND LEMON_HAVE_CPLEX)
+  ENDIF(WIN32 AND HAVE_GLPK)
+  IF(WIN32 AND HAVE_CPLEX)
     GET_TARGET_PROPERTY(TARGET_LOC mip_test LOCATION)
     GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH)
@@ -100,6 +100,6 @@
       COMMAND cmake -E copy ${CPLEX_BIN_DIR}/cplex91.dll ${TARGET_PATH}
     )
-  ENDIF(WIN32 AND LEMON_HAVE_CPLEX)
-ENDIF(LEMON_HAVE_MIP)
+  ENDIF(WIN32 AND HAVE_CPLEX)
+ENDIF(HAVE_MIP)
 
 FOREACH(TEST_NAME ${TESTS})
Index: test/lp_test.cc
===================================================================
--- test/lp_test.cc	(revision 678)
+++ test/lp_test.cc	(revision 622)
@@ -22,19 +22,21 @@
 #include <lemon/tolerance.h>
 
+#ifdef HAVE_CONFIG_H
 #include <lemon/config.h>
-
-#ifdef LEMON_HAVE_GLPK
+#endif
+
+#ifdef HAVE_GLPK
 #include <lemon/glpk.h>
 #endif
 
-#ifdef LEMON_HAVE_CPLEX
+#ifdef HAVE_CPLEX
 #include <lemon/cplex.h>
 #endif
 
-#ifdef LEMON_HAVE_SOPLEX
+#ifdef HAVE_SOPLEX
 #include <lemon/soplex.h>
 #endif
 
-#ifdef LEMON_HAVE_CLP
+#ifdef HAVE_CLP
 #include <lemon/clp.h>
 #endif
@@ -378,5 +380,5 @@
   lpTest(lp_skel);
 
-#ifdef LEMON_HAVE_GLPK
+#ifdef HAVE_GLPK
   {
     GlpkLp lp_glpk1,lp_glpk2;
@@ -387,5 +389,5 @@
 #endif
 
-#ifdef LEMON_HAVE_CPLEX
+#ifdef HAVE_CPLEX
   try {
     CplexLp lp_cplex1,lp_cplex2;
@@ -398,5 +400,5 @@
 #endif
 
-#ifdef LEMON_HAVE_SOPLEX
+#ifdef HAVE_SOPLEX
   {
     SoplexLp lp_soplex1,lp_soplex2;
@@ -407,5 +409,5 @@
 #endif
 
-#ifdef LEMON_HAVE_CLP
+#ifdef HAVE_CLP
   {
     ClpLp lp_clp1,lp_clp2;
Index: test/min_cost_flow_test.cc
===================================================================
--- test/min_cost_flow_test.cc	(revision 662)
+++ test/min_cost_flow_test.cc	(revision 687)
@@ -19,4 +19,5 @@
 #include <iostream>
 #include <fstream>
+#include <limits>
 
 #include <lemon/list_graph.h>
@@ -34,41 +35,41 @@
 char test_lgf[] =
   "@nodes\n"
-  "label  sup1 sup2 sup3 sup4 sup5\n"
-  "    1    20   27    0   20   30\n"
-  "    2    -4    0    0   -8   -3\n"
-  "    3     0    0    0    0    0\n"
-  "    4     0    0    0    0    0\n"
-  "    5     9    0    0    6   11\n"
-  "    6    -6    0    0   -5   -6\n"
-  "    7     0    0    0    0    0\n"
-  "    8     0    0    0    0    3\n"
-  "    9     3    0    0    0    0\n"
-  "   10    -2    0    0   -7   -2\n"
-  "   11     0    0    0  -10    0\n"
-  "   12   -20  -27    0  -30  -20\n"
-  "\n"
+  "label  sup1 sup2 sup3 sup4 sup5 sup6\n"
+  "    1    20   27    0   30   20   30\n"
+  "    2    -4    0    0    0   -8   -3\n"
+  "    3     0    0    0    0    0    0\n"
+  "    4     0    0    0    0    0    0\n"
+  "    5     9    0    0    0    6   11\n"
+  "    6    -6    0    0    0   -5   -6\n"
+  "    7     0    0    0    0    0    0\n"
+  "    8     0    0    0    0    0    3\n"
+  "    9     3    0    0    0    0    0\n"
+  "   10    -2    0    0    0   -7   -2\n"
+  "   11     0    0    0    0  -10    0\n"
+  "   12   -20  -27    0  -30  -30  -20\n"
+  "\n"                
   "@arcs\n"
-  "       cost  cap low1 low2\n"
-  " 1  2    70   11    0    8\n"
-  " 1  3   150    3    0    1\n"
-  " 1  4    80   15    0    2\n"
-  " 2  8    80   12    0    0\n"
-  " 3  5   140    5    0    3\n"
-  " 4  6    60   10    0    1\n"
-  " 4  7    80    2    0    0\n"
-  " 4  8   110    3    0    0\n"
-  " 5  7    60   14    0    0\n"
-  " 5 11   120   12    0    0\n"
-  " 6  3     0    3    0    0\n"
-  " 6  9   140    4    0    0\n"
-  " 6 10    90    8    0    0\n"
-  " 7  1    30    5    0    0\n"
-  " 8 12    60   16    0    4\n"
-  " 9 12    50    6    0    0\n"
-  "10 12    70   13    0    5\n"
-  "10  2   100    7    0    0\n"
-  "10  7    60   10    0    0\n"
-  "11 10    20   14    0    6\n"
-  "12 11    30   10    0    0\n"
+  "       cost  cap low1 low2 low3\n"
+  " 1  2    70   11    0    8    8\n"
+  " 1  3   150    3    0    1    0\n"
+  " 1  4    80   15    0    2    2\n"
+  " 2  8    80   12    0    0    0\n"
+  " 3  5   140    5    0    3    1\n"
+  " 4  6    60   10    0    1    0\n"
+  " 4  7    80    2    0    0    0\n"
+  " 4  8   110    3    0    0    0\n"
+  " 5  7    60   14    0    0    0\n"
+  " 5 11   120   12    0    0    0\n"
+  " 6  3     0    3    0    0    0\n"
+  " 6  9   140    4    0    0    0\n"
+  " 6 10    90    8    0    0    0\n"
+  " 7  1    30    5    0    0   -5\n"
+  " 8 12    60   16    0    4    3\n"
+  " 9 12    50    6    0    0    0\n"
+  "10 12    70   13    0    5    2\n"
+  "10  2   100    7    0    0    0\n"
+  "10  7    60   10    0    0   -3\n"
+  "11 10    20   14    0    6  -20\n"
+  "12 11    30   10    0    0  -10\n"
   "\n"
   "@attributes\n"
@@ -77,5 +78,5 @@
 
 
-enum ProblemType {
+enum SupplyType {
   EQ,
   GEQ,
@@ -99,6 +100,4 @@
              .lowerMap(lower)
              .upperMap(upper)
-             .capacityMap(upper)
-             .boundMaps(lower, upper)
              .costMap(cost)
              .supplyMap(sup)
@@ -113,8 +112,10 @@
       const typename MCF::PotentialMap &pm = const_mcf.potentialMap();
 
-      v = const_mcf.totalCost();
+      c = const_mcf.totalCost();
       double x = const_mcf.template totalCost<double>();
       v = const_mcf.flow(a);
-      v = const_mcf.potential(n);
+      c = const_mcf.potential(n);
+      
+      v = const_mcf.INF;
 
       ignore_unused_variable_warning(fm);
@@ -138,4 +139,5 @@
     const Flow &k;
     Flow v;
+    Cost c;
     bool b;
 
@@ -152,5 +154,5 @@
 bool checkFlow( const GR& gr, const LM& lower, const UM& upper,
                 const SM& supply, const FM& flow,
-                ProblemType type = EQ )
+                SupplyType type = EQ )
 {
   TEMPLATE_DIGRAPH_TYPEDEFS(GR);
@@ -209,14 +211,15 @@
 template < typename MCF, typename GR,
            typename LM, typename UM,
-           typename CM, typename SM >
-void checkMcf( const MCF& mcf, bool mcf_result,
+           typename CM, typename SM,
+           typename PT >
+void checkMcf( const MCF& mcf, PT mcf_result,
                const GR& gr, const LM& lower, const UM& upper,
                const CM& cost, const SM& supply,
-               bool result, typename CM::Value total,
+               PT result, bool optimal, typename CM::Value total,
                const std::string &test_id = "",
-               ProblemType type = EQ )
+               SupplyType type = EQ )
 {
   check(mcf_result == result, "Wrong result " + test_id);
-  if (result) {
+  if (optimal) {
     check(checkFlow(gr, lower, upper, supply, mcf.flowMap(), type),
           "The flow is not feasible " + test_id);
@@ -245,6 +248,6 @@
   // Read the test digraph
   Digraph gr;
-  Digraph::ArcMap<int> c(gr), l1(gr), l2(gr), u(gr);
-  Digraph::NodeMap<int> s1(gr), s2(gr), s3(gr), s4(gr), s5(gr);
+  Digraph::ArcMap<int> c(gr), l1(gr), l2(gr), l3(gr), u(gr);
+  Digraph::NodeMap<int> s1(gr), s2(gr), s3(gr), s4(gr), s5(gr), s6(gr);
   ConstMap<Arc, int> cc(1), cu(std::numeric_limits<int>::max());
   Node v, w;
@@ -256,4 +259,5 @@
     .arcMap("low1", l1)
     .arcMap("low2", l2)
+    .arcMap("low3", l3)
     .nodeMap("sup1", s1)
     .nodeMap("sup2", s2)
@@ -261,7 +265,48 @@
     .nodeMap("sup4", s4)
     .nodeMap("sup5", s5)
+    .nodeMap("sup6", s6)
     .node("source", v)
     .node("target", w)
     .run();
+  
+  // Build a test digraph for testing negative costs
+  Digraph ngr;
+  Node n1 = ngr.addNode();
+  Node n2 = ngr.addNode();
+  Node n3 = ngr.addNode();
+  Node n4 = ngr.addNode();
+  Node n5 = ngr.addNode();
+  Node n6 = ngr.addNode();
+  Node n7 = ngr.addNode();
+  
+  Arc a1 = ngr.addArc(n1, n2);
+  Arc a2 = ngr.addArc(n1, n3);
+  Arc a3 = ngr.addArc(n2, n4);
+  Arc a4 = ngr.addArc(n3, n4);
+  Arc a5 = ngr.addArc(n3, n2);
+  Arc a6 = ngr.addArc(n5, n3);
+  Arc a7 = ngr.addArc(n5, n6);
+  Arc a8 = ngr.addArc(n6, n7);
+  Arc a9 = ngr.addArc(n7, n5);
+  
+  Digraph::ArcMap<int> nc(ngr), nl1(ngr, 0), nl2(ngr, 0);
+  ConstMap<Arc, int> nu1(std::numeric_limits<int>::max()), nu2(5000);
+  Digraph::NodeMap<int> ns(ngr, 0);
+  
+  nl2[a7] =  1000;
+  nl2[a8] = -1000;
+  
+  ns[n1] =  100;
+  ns[n4] = -100;
+  
+  nc[a1] =  100;
+  nc[a2] =   30;
+  nc[a3] =   20;
+  nc[a4] =   80;
+  nc[a5] =   50;
+  nc[a6] =   10;
+  nc[a7] =   80;
+  nc[a8] =   30;
+  nc[a9] = -120;
 
   // A. Test NetworkSimplex with the default pivot rule
@@ -272,44 +317,58 @@
     mcf.upperMap(u).costMap(c);
     checkMcf(mcf, mcf.supplyMap(s1).run(),
-             gr, l1, u, c, s1, true,  5240, "#A1");
+             gr, l1, u, c, s1, mcf.OPTIMAL, true,   5240, "#A1");
     checkMcf(mcf, mcf.stSupply(v, w, 27).run(),
-             gr, l1, u, c, s2, true,  7620, "#A2");
+             gr, l1, u, c, s2, mcf.OPTIMAL, true,   7620, "#A2");
     mcf.lowerMap(l2);
     checkMcf(mcf, mcf.supplyMap(s1).run(),
-             gr, l2, u, c, s1, true,  5970, "#A3");
+             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#A3");
     checkMcf(mcf, mcf.stSupply(v, w, 27).run(),
-             gr, l2, u, c, s2, true,  8010, "#A4");
+             gr, l2, u, c, s2, mcf.OPTIMAL, true,   8010, "#A4");
     mcf.reset();
     checkMcf(mcf, mcf.supplyMap(s1).run(),
-             gr, l1, cu, cc, s1, true,  74, "#A5");
+             gr, l1, cu, cc, s1, mcf.OPTIMAL, true,   74, "#A5");
     checkMcf(mcf, mcf.lowerMap(l2).stSupply(v, w, 27).run(),
-             gr, l2, cu, cc, s2, true,  94, "#A6");
+             gr, l2, cu, cc, s2, mcf.OPTIMAL, true,   94, "#A6");
     mcf.reset();
     checkMcf(mcf, mcf.run(),
-             gr, l1, cu, cc, s3, true,   0, "#A7");
-    checkMcf(mcf, mcf.boundMaps(l2, u).run(),
-             gr, l2, u, cc, s3, false,   0, "#A8");
+             gr, l1, cu, cc, s3, mcf.OPTIMAL, true,    0, "#A7");
+    checkMcf(mcf, mcf.lowerMap(l2).upperMap(u).run(),
+             gr, l2, u, cc, s3, mcf.INFEASIBLE, false, 0, "#A8");
+    mcf.reset().lowerMap(l3).upperMap(u).costMap(c).supplyMap(s4);
+    checkMcf(mcf, mcf.run(),
+             gr, l3, u, c, s4, mcf.OPTIMAL, true,   6360, "#A9");
 
     // Check the GEQ form
-    mcf.reset().upperMap(u).costMap(c).supplyMap(s4);
-    checkMcf(mcf, mcf.run(),
-             gr, l1, u, c, s4, true,  3530, "#A9", GEQ);
-    mcf.problemType(mcf.GEQ);
+    mcf.reset().upperMap(u).costMap(c).supplyMap(s5);
+    checkMcf(mcf, mcf.run(),
+             gr, l1, u, c, s5, mcf.OPTIMAL, true,   3530, "#A10", GEQ);
+    mcf.supplyType(mcf.GEQ);
     checkMcf(mcf, mcf.lowerMap(l2).run(),
-             gr, l2, u, c, s4, true,  4540, "#A10", GEQ);
-    mcf.problemType(mcf.CARRY_SUPPLIES).supplyMap(s5);
-    checkMcf(mcf, mcf.run(),
-             gr, l2, u, c, s5, false,    0, "#A11", GEQ);
+             gr, l2, u, c, s5, mcf.OPTIMAL, true,   4540, "#A11", GEQ);
+    mcf.supplyType(mcf.CARRY_SUPPLIES).supplyMap(s6);
+    checkMcf(mcf, mcf.run(),
+             gr, l2, u, c, s6, mcf.INFEASIBLE, false,  0, "#A12", GEQ);
 
     // Check the LEQ form
-    mcf.reset().problemType(mcf.LEQ);
-    mcf.upperMap(u).costMap(c).supplyMap(s5);
-    checkMcf(mcf, mcf.run(),
-             gr, l1, u, c, s5, true,  5080, "#A12", LEQ);
+    mcf.reset().supplyType(mcf.LEQ);
+    mcf.upperMap(u).costMap(c).supplyMap(s6);
+    checkMcf(mcf, mcf.run(),
+             gr, l1, u, c, s6, mcf.OPTIMAL, true,   5080, "#A13", LEQ);
     checkMcf(mcf, mcf.lowerMap(l2).run(),
-             gr, l2, u, c, s5, true,  5930, "#A13", LEQ);
-    mcf.problemType(mcf.SATISFY_DEMANDS).supplyMap(s4);
-    checkMcf(mcf, mcf.run(),
-             gr, l2, u, c, s4, false,    0, "#A14", LEQ);
+             gr, l2, u, c, s6, mcf.OPTIMAL, true,   5930, "#A14", LEQ);
+    mcf.supplyType(mcf.SATISFY_DEMANDS).supplyMap(s5);
+    checkMcf(mcf, mcf.run(),
+             gr, l2, u, c, s5, mcf.INFEASIBLE, false,  0, "#A15", LEQ);
+
+    // Check negative costs
+    NetworkSimplex<Digraph> nmcf(ngr);
+    nmcf.lowerMap(nl1).costMap(nc).supplyMap(ns);
+    checkMcf(nmcf, nmcf.run(),
+      ngr, nl1, nu1, nc, ns, nmcf.UNBOUNDED, false,    0, "#A16");
+    checkMcf(nmcf, nmcf.upperMap(nu2).run(),
+      ngr, nl1, nu2, nc, ns, nmcf.OPTIMAL, true,  -40000, "#A17");
+    nmcf.reset().lowerMap(nl2).costMap(nc).supplyMap(ns);
+    checkMcf(nmcf, nmcf.run(),
+      ngr, nl2, nu1, nc, ns, nmcf.UNBOUNDED, false,    0, "#A18");
   }
 
@@ -317,16 +376,16 @@
   {
     NetworkSimplex<Digraph> mcf(gr);
-    mcf.supplyMap(s1).costMap(c).capacityMap(u).lowerMap(l2);
+    mcf.supplyMap(s1).costMap(c).upperMap(u).lowerMap(l2);
 
     checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::FIRST_ELIGIBLE),
-             gr, l2, u, c, s1, true,  5970, "#B1");
+             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B1");
     checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::BEST_ELIGIBLE),
-             gr, l2, u, c, s1, true,  5970, "#B2");
+             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B2");
     checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::BLOCK_SEARCH),
-             gr, l2, u, c, s1, true,  5970, "#B3");
+             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B3");
     checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::CANDIDATE_LIST),
-             gr, l2, u, c, s1, true,  5970, "#B4");
+             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B4");
     checkMcf(mcf, mcf.run(NetworkSimplex<Digraph>::ALTERING_LIST),
-             gr, l2, u, c, s1, true,  5970, "#B5");
+             gr, l2, u, c, s1, mcf.OPTIMAL, true,   5970, "#B5");
   }
 
Index: test/mip_test.cc
===================================================================
--- test/mip_test.cc	(revision 678)
+++ test/mip_test.cc	(revision 622)
@@ -19,15 +19,17 @@
 #include "test_tools.h"
 
+#ifdef HAVE_CONFIG_H
 #include <lemon/config.h>
+#endif
 
-#ifdef LEMON_HAVE_CPLEX
+#ifdef HAVE_CPLEX
 #include <lemon/cplex.h>
 #endif
 
-#ifdef LEMON_HAVE_GLPK
+#ifdef HAVE_GLPK
 #include <lemon/glpk.h>
 #endif
 
-#ifdef LEMON_HAVE_CBC
+#ifdef HAVE_CBC
 #include <lemon/cbc.h>
 #endif
@@ -128,5 +130,5 @@
 {
 
-#ifdef LEMON_HAVE_GLPK
+#ifdef HAVE_GLPK
   {
     GlpkMip mip1;
@@ -136,5 +138,5 @@
 #endif
 
-#ifdef LEMON_HAVE_CPLEX
+#ifdef HAVE_CPLEX
   try {
     CplexMip mip2;
@@ -146,5 +148,5 @@
 #endif
 
-#ifdef LEMON_HAVE_CBC
+#ifdef HAVE_CBC
   {
     CbcMip mip1;
