Index: lemon/network_simplex.h
===================================================================
--- lemon/network_simplex.h	(revision 877)
+++ lemon/network_simplex.h	(revision 891)
@@ -3,5 +3,5 @@
  * This file is a part of LEMON, a generic C++ optimization library.
  *
- * Copyright (C) 2003-2010
+ * Copyright (C) 2003-2009
  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
  * (Egervary Research Group on Combinatorial Optimization, EGRES).
@@ -41,15 +41,13 @@
   ///
   /// \ref NetworkSimplex implements the primal Network Simplex algorithm
-  /// for finding a \ref min_cost_flow "minimum cost flow"
-  /// \ref amo93networkflows, \ref dantzig63linearprog,
-  /// \ref kellyoneill91netsimplex.
-  /// This algorithm is a highly efficient specialized version of the
-  /// linear programming simplex method directly for the minimum cost
-  /// flow problem.
+  /// for finding a \ref min_cost_flow "minimum cost flow".
+  /// This algorithm is a specialized version of the linear programming
+  /// simplex method directly for the minimum cost flow problem.
+  /// It is one of the most efficient solution methods.
   ///
-  /// In general, %NetworkSimplex is the fastest implementation available
-  /// in LEMON for this problem.
-  /// Moreover, it supports both directions of the supply/demand inequality
-  /// constraints. For more information, see \ref SupplyType.
+  /// In general this class is the fastest implementation available
+  /// in LEMON for the minimum cost flow problem.
+  /// Moreover it supports both directions of the supply/demand inequality
+  /// constraints. For more information see \ref SupplyType.
   ///
   /// Most of the parameters of the problem (except for the digraph)
@@ -59,15 +57,15 @@
   ///
   /// \tparam GR The digraph type the algorithm runs on.
-  /// \tparam V The number type used for flow amounts, capacity bounds
-  /// and supply values in the algorithm. By default, it is \c int.
-  /// \tparam C The number type used for costs and potentials in the
-  /// algorithm. By default, it is the same as \c V.
+  /// \tparam V The value type used for flow amounts, capacity bounds
+  /// and supply values in the algorithm. By default it is \c int.
+  /// \tparam C The value type used for costs and potentials in the
+  /// algorithm. By default it is the same as \c V.
   ///
-  /// \warning Both number types must be signed and all input data must
+  /// \warning Both value types must be signed and all input data must
   /// be integer.
   ///
   /// \note %NetworkSimplex provides five different pivot rule
   /// implementations, from which the most efficient one is used
-  /// by default. For more information, see \ref PivotRule.
+  /// by default. For more information see \ref PivotRule.
   template <typename GR, typename V = int, typename C = V>
   class NetworkSimplex
@@ -98,5 +96,5 @@
       UNBOUNDED
     };
-
+    
     /// \brief Constants for selecting the type of the supply constraints.
     ///
@@ -116,5 +114,5 @@
       LEQ
     };
-
+    
     /// \brief Constants for selecting the pivot rule.
     ///
@@ -125,21 +123,21 @@
     /// implementations that significantly affect the running time
     /// of the algorithm.
-    /// By default, \ref BLOCK_SEARCH "Block Search" is used, which
+    /// By default \ref BLOCK_SEARCH "Block Search" is used, which
     /// proved to be the most efficient and the most robust on various
-    /// test inputs.
-    /// However, another pivot rule can be selected using the \ref run()
+    /// test inputs according to our benchmark tests.
+    /// However another pivot rule can be selected using the \ref run()
     /// function with the proper parameter.
     enum PivotRule {
 
-      /// The \e First \e Eligible pivot rule.
+      /// The First Eligible pivot rule.
       /// The next eligible arc is selected in a wraparound fashion
       /// in every iteration.
       FIRST_ELIGIBLE,
 
-      /// The \e Best \e Eligible pivot rule.
+      /// The Best Eligible pivot rule.
       /// The best eligible arc is selected in every iteration.
       BEST_ELIGIBLE,
 
-      /// The \e Block \e Search pivot rule.
+      /// The Block Search pivot rule.
       /// A specified number of arcs are examined in every iteration
       /// in a wraparound fashion and the best eligible arc is selected
@@ -147,5 +145,5 @@
       BLOCK_SEARCH,
 
-      /// The \e Candidate \e List pivot rule.
+      /// The Candidate List pivot rule.
       /// In a major iteration a candidate list is built from eligible arcs
       /// in a wraparound fashion and in the following minor iterations
@@ -153,5 +151,5 @@
       CANDIDATE_LIST,
 
-      /// The \e Altering \e Candidate \e List pivot rule.
+      /// The Altering Candidate List pivot rule.
       /// It is a modified version of the Candidate List method.
       /// It keeps only the several best eligible arcs from the former
@@ -159,25 +157,22 @@
       ALTERING_LIST
     };
-
+    
   private:
 
     TEMPLATE_DIGRAPH_TYPEDEFS(GR);
 
+    typedef std::vector<Arc> ArcVector;
+    typedef std::vector<Node> NodeVector;
     typedef std::vector<int> IntVector;
+    typedef std::vector<bool> BoolVector;
     typedef std::vector<Value> ValueVector;
     typedef std::vector<Cost> CostVector;
-    typedef std::vector<char> BoolVector;
-    // Note: vector<char> is used instead of vector<bool> for efficiency reasons
 
     // State constants for arcs
-    enum ArcState {
+    enum ArcStateEnum {
       STATE_UPPER = -1,
       STATE_TREE  =  0,
       STATE_LOWER =  1
     };
-
-    typedef std::vector<signed char> StateVector;
-    // Note: vector<signed char> is used instead of vector<ArcState> for
-    // efficiency reasons
 
   private:
@@ -200,5 +195,4 @@
     IntVector _source;
     IntVector _target;
-    bool _arc_mixing;
 
     // Node and arc data
@@ -220,5 +214,5 @@
     IntVector _dirty_revs;
     BoolVector _forward;
-    StateVector _state;
+    IntVector _state;
     int _root;
 
@@ -229,8 +223,6 @@
     Value delta;
 
-    const Value MAX;
-
   public:
-
+  
     /// \brief Constant for infinite upper bounds (capacities).
     ///
@@ -251,5 +243,5 @@
       const IntVector  &_target;
       const CostVector &_cost;
-      const StateVector &_state;
+      const IntVector  &_state;
       const CostVector &_pi;
       int &_in_arc;
@@ -272,5 +264,5 @@
       bool findEnteringArc() {
         Cost c;
-        for (int e = _next_arc; e != _search_arc_num; ++e) {
+        for (int e = _next_arc; e < _search_arc_num; ++e) {
           c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
           if (c < 0) {
@@ -280,5 +272,5 @@
           }
         }
-        for (int e = 0; e != _next_arc; ++e) {
+        for (int e = 0; e < _next_arc; ++e) {
           c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
           if (c < 0) {
@@ -303,5 +295,5 @@
       const IntVector  &_target;
       const CostVector &_cost;
-      const StateVector &_state;
+      const IntVector  &_state;
       const CostVector &_pi;
       int &_in_arc;
@@ -320,5 +312,5 @@
       bool findEnteringArc() {
         Cost c, min = 0;
-        for (int e = 0; e != _search_arc_num; ++e) {
+        for (int e = 0; e < _search_arc_num; ++e) {
           c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
           if (c < min) {
@@ -342,5 +334,5 @@
       const IntVector  &_target;
       const CostVector &_cost;
-      const StateVector &_state;
+      const IntVector  &_state;
       const CostVector &_pi;
       int &_in_arc;
@@ -361,5 +353,5 @@
       {
         // The main parameters of the pivot rule
-        const double BLOCK_SIZE_FACTOR = 1.0;
+        const double BLOCK_SIZE_FACTOR = 0.5;
         const int MIN_BLOCK_SIZE = 10;
 
@@ -373,30 +365,31 @@
         Cost c, min = 0;
         int cnt = _block_size;
-        int e;
-        for (e = _next_arc; e != _search_arc_num; ++e) {
+        int e, min_arc = _next_arc;
+        for (e = _next_arc; e < _search_arc_num; ++e) {
           c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
           if (c < min) {
             min = c;
-            _in_arc = e;
+            min_arc = e;
           }
           if (--cnt == 0) {
-            if (min < 0) goto search_end;
+            if (min < 0) break;
             cnt = _block_size;
           }
         }
-        for (e = 0; e != _next_arc; ++e) {
-          c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
-          if (c < min) {
-            min = c;
-            _in_arc = e;
-          }
-          if (--cnt == 0) {
-            if (min < 0) goto search_end;
-            cnt = _block_size;
+        if (min == 0 || cnt > 0) {
+          for (e = 0; e < _next_arc; ++e) {
+            c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
+            if (c < min) {
+              min = c;
+              min_arc = e;
+            }
+            if (--cnt == 0) {
+              if (min < 0) break;
+              cnt = _block_size;
+            }
           }
         }
         if (min >= 0) return false;
-
-      search_end:
+        _in_arc = min_arc;
         _next_arc = e;
         return true;
@@ -415,5 +408,5 @@
       const IntVector  &_target;
       const CostVector &_cost;
-      const StateVector &_state;
+      const IntVector  &_state;
       const CostVector &_pi;
       int &_in_arc;
@@ -436,5 +429,5 @@
       {
         // The main parameters of the pivot rule
-        const double LIST_LENGTH_FACTOR = 0.25;
+        const double LIST_LENGTH_FACTOR = 1.0;
         const int MIN_LIST_LENGTH = 10;
         const double MINOR_LIMIT_FACTOR = 0.1;
@@ -453,5 +446,5 @@
       bool findEnteringArc() {
         Cost min, c;
-        int e;
+        int e, min_arc = _next_arc;
         if (_curr_length > 0 && _minor_count < _minor_limit) {
           // Minor iteration: select the best eligible arc from the
@@ -464,11 +457,14 @@
             if (c < min) {
               min = c;
-              _in_arc = e;
+              min_arc = e;
             }
-            else if (c >= 0) {
+            if (c >= 0) {
               _candidates[i--] = _candidates[--_curr_length];
             }
           }
-          if (min < 0) return true;
+          if (min < 0) {
+            _in_arc = min_arc;
+            return true;
+          }
         }
 
@@ -476,5 +472,5 @@
         min = 0;
         _curr_length = 0;
-        for (e = _next_arc; e != _search_arc_num; ++e) {
+        for (e = _next_arc; e < _search_arc_num; ++e) {
           c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
           if (c < 0) {
@@ -482,24 +478,25 @@
             if (c < min) {
               min = c;
-              _in_arc = e;
+              min_arc = e;
             }
-            if (_curr_length == _list_length) goto search_end;
-          }
-        }
-        for (e = 0; e != _next_arc; ++e) {
-          c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
-          if (c < 0) {
-            _candidates[_curr_length++] = e;
-            if (c < min) {
-              min = c;
-              _in_arc = e;
+            if (_curr_length == _list_length) break;
+          }
+        }
+        if (_curr_length < _list_length) {
+          for (e = 0; e < _next_arc; ++e) {
+            c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
+            if (c < 0) {
+              _candidates[_curr_length++] = e;
+              if (c < min) {
+                min = c;
+                min_arc = e;
+              }
+              if (_curr_length == _list_length) break;
             }
-            if (_curr_length == _list_length) goto search_end;
           }
         }
         if (_curr_length == 0) return false;
-
-      search_end:
         _minor_count = 1;
+        _in_arc = min_arc;
         _next_arc = e;
         return true;
@@ -518,5 +515,5 @@
       const IntVector  &_target;
       const CostVector &_cost;
-      const StateVector &_state;
+      const IntVector  &_state;
       const CostVector &_pi;
       int &_in_arc;
@@ -553,5 +550,5 @@
       {
         // The main parameters of the pivot rule
-        const double BLOCK_SIZE_FACTOR = 1.0;
+        const double BLOCK_SIZE_FACTOR = 1.5;
         const int MIN_BLOCK_SIZE = 10;
         const double HEAD_LENGTH_FACTOR = 0.1;
@@ -571,5 +568,5 @@
         // Check the current candidate list
         int e;
-        for (int i = 0; i != _curr_length; ++i) {
+        for (int i = 0; i < _curr_length; ++i) {
           e = _candidates[i];
           _cand_cost[e] = _state[e] *
@@ -582,33 +579,37 @@
         // Extend the list
         int cnt = _block_size;
+        int last_arc = 0;
         int limit = _head_length;
 
-        for (e = _next_arc; e != _search_arc_num; ++e) {
+        for (int e = _next_arc; e < _search_arc_num; ++e) {
           _cand_cost[e] = _state[e] *
             (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
           if (_cand_cost[e] < 0) {
             _candidates[_curr_length++] = e;
+            last_arc = e;
           }
           if (--cnt == 0) {
-            if (_curr_length > limit) goto search_end;
+            if (_curr_length > limit) break;
             limit = 0;
             cnt = _block_size;
           }
         }
-        for (e = 0; e != _next_arc; ++e) {
-          _cand_cost[e] = _state[e] *
-            (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
-          if (_cand_cost[e] < 0) {
-            _candidates[_curr_length++] = e;
-          }
-          if (--cnt == 0) {
-            if (_curr_length > limit) goto search_end;
-            limit = 0;
-            cnt = _block_size;
+        if (_curr_length <= limit) {
+          for (int e = 0; e < _next_arc; ++e) {
+            _cand_cost[e] = _state[e] *
+              (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
+            if (_cand_cost[e] < 0) {
+              _candidates[_curr_length++] = e;
+              last_arc = e;
+            }
+            if (--cnt == 0) {
+              if (_curr_length > limit) break;
+              limit = 0;
+              cnt = _block_size;
+            }
           }
         }
         if (_curr_length == 0) return false;
-
-      search_end:
+        _next_arc = last_arc + 1;
 
         // Make heap of the candidate list (approximating a partial sort)
@@ -618,5 +619,4 @@
         // Pop the first element of the heap
         _in_arc = _candidates[0];
-        _next_arc = e;
         pop_heap( _candidates.begin(), _candidates.begin() + _curr_length,
                   _sort_func );
@@ -634,265 +634,16 @@
     ///
     /// \param graph The digraph the algorithm runs on.
-    /// \param arc_mixing Indicate if the arcs have to be stored in a
-    /// mixed order in the internal data structure.
-    /// In special cases, it could lead to better overall performance,
-    /// but it is usually slower. Therefore it is disabled by default.
-    NetworkSimplex(const GR& graph, bool arc_mixing = false) :
+    NetworkSimplex(const GR& graph) :
       _graph(graph), _node_id(graph), _arc_id(graph),
-      _arc_mixing(arc_mixing),
-      MAX(std::numeric_limits<Value>::max()),
       INF(std::numeric_limits<Value>::has_infinity ?
-          std::numeric_limits<Value>::infinity() : MAX)
+          std::numeric_limits<Value>::infinity() :
+          std::numeric_limits<Value>::max())
     {
-      // Check the number types
+      // Check the value types
       LEMON_ASSERT(std::numeric_limits<Value>::is_signed,
         "The flow type of NetworkSimplex must be signed");
       LEMON_ASSERT(std::numeric_limits<Cost>::is_signed,
         "The cost type of NetworkSimplex must be signed");
-
-      // Reset data structures
-      reset();
-    }
-
-    /// \name Parameters
-    /// The parameters of the algorithm can be specified using these
-    /// functions.
-
-    /// @{
-
-    /// \brief Set the lower bounds on the arcs.
-    ///
-    /// This function sets the lower bounds on the arcs.
-    /// If it is not used before calling \ref run(), the lower bounds
-    /// will be set to zero on all arcs.
-    ///
-    /// \param map An arc map storing the lower bounds.
-    /// Its \c Value type must be convertible to the \c Value type
-    /// of the algorithm.
-    ///
-    /// \return <tt>(*this)</tt>
-    template <typename LowerMap>
-    NetworkSimplex& lowerMap(const LowerMap& map) {
-      _have_lower = true;
-      for (ArcIt a(_graph); a != INVALID; ++a) {
-        _lower[_arc_id[a]] = map[a];
-      }
-      return *this;
-    }
-
-    /// \brief Set the upper bounds (capacities) on the arcs.
-    ///
-    /// This function sets the upper bounds (capacities) on the arcs.
-    /// If it is not used before calling \ref run(), the upper bounds
-    /// will be set to \ref INF on all arcs (i.e. the flow value will be
-    /// unbounded from above).
-    ///
-    /// \param map An arc map storing the upper bounds.
-    /// Its \c Value type must be convertible to the \c Value type
-    /// of the algorithm.
-    ///
-    /// \return <tt>(*this)</tt>
-    template<typename UpperMap>
-    NetworkSimplex& upperMap(const UpperMap& map) {
-      for (ArcIt a(_graph); a != INVALID; ++a) {
-        _upper[_arc_id[a]] = map[a];
-      }
-      return *this;
-    }
-
-    /// \brief Set the costs of the arcs.
-    ///
-    /// This function sets the costs of the arcs.
-    /// If it is not used before calling \ref run(), the costs
-    /// will be set to \c 1 on all arcs.
-    ///
-    /// \param map An arc map storing the costs.
-    /// Its \c Value type must be convertible to the \c Cost type
-    /// of the algorithm.
-    ///
-    /// \return <tt>(*this)</tt>
-    template<typename CostMap>
-    NetworkSimplex& costMap(const CostMap& map) {
-      for (ArcIt a(_graph); a != INVALID; ++a) {
-        _cost[_arc_id[a]] = map[a];
-      }
-      return *this;
-    }
-
-    /// \brief Set the supply values of the nodes.
-    ///
-    /// This function sets the supply values of the nodes.
-    /// If neither this function nor \ref stSupply() is used before
-    /// calling \ref run(), the supply of each node will be set to zero.
-    ///
-    /// \param map A node map storing the supply values.
-    /// Its \c Value type must be convertible to the \c Value type
-    /// of the algorithm.
-    ///
-    /// \return <tt>(*this)</tt>
-    template<typename SupplyMap>
-    NetworkSimplex& supplyMap(const SupplyMap& map) {
-      for (NodeIt n(_graph); n != INVALID; ++n) {
-        _supply[_node_id[n]] = map[n];
-      }
-      return *this;
-    }
-
-    /// \brief Set single source and target nodes and a supply value.
-    ///
-    /// This function sets a single source node and a single target node
-    /// and the required flow value.
-    /// If neither this function nor \ref supplyMap() is used before
-    /// calling \ref run(), the supply of each node will be set to zero.
-    ///
-    /// Using this function has the same effect as using \ref supplyMap()
-    /// with such a map in which \c k is assigned to \c s, \c -k is
-    /// assigned to \c t and all other nodes have zero supply value.
-    ///
-    /// \param s The source node.
-    /// \param t The target node.
-    /// \param k The required amount of flow from node \c s to node \c t
-    /// (i.e. the supply of \c s and the demand of \c t).
-    ///
-    /// \return <tt>(*this)</tt>
-    NetworkSimplex& stSupply(const Node& s, const Node& t, Value k) {
-      for (int i = 0; i != _node_num; ++i) {
-        _supply[i] = 0;
-      }
-      _supply[_node_id[s]] =  k;
-      _supply[_node_id[t]] = -k;
-      return *this;
-    }
-
-    /// \brief Set the type of the supply constraints.
-    ///
-    /// This function sets the type of the supply/demand constraints.
-    /// If it is not used before calling \ref run(), the \ref GEQ supply
-    /// type will be used.
-    ///
-    /// For more information, see \ref SupplyType.
-    ///
-    /// \return <tt>(*this)</tt>
-    NetworkSimplex& supplyType(SupplyType supply_type) {
-      _stype = supply_type;
-      return *this;
-    }
-
-    /// @}
-
-    /// \name Execution Control
-    /// The algorithm can be executed using \ref run().
-
-    /// @{
-
-    /// \brief Run the algorithm.
-    ///
-    /// This function runs the algorithm.
-    /// The paramters can be specified using functions \ref lowerMap(),
-    /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(),
-    /// \ref supplyType().
-    /// For example,
-    /// \code
-    ///   NetworkSimplex<ListDigraph> ns(graph);
-    ///   ns.lowerMap(lower).upperMap(upper).costMap(cost)
-    ///     .supplyMap(sup).run();
-    /// \endcode
-    ///
-    /// This function can be called more than once. All the given parameters
-    /// are kept for the next call, unless \ref resetParams() or \ref reset()
-    /// is used, thus only the modified parameters have to be set again.
-    /// If the underlying digraph was also modified after the construction
-    /// of the class (or the last \ref reset() call), then the \ref reset()
-    /// function must be called.
-    ///
-    /// \param pivot_rule The pivot rule that will be used during the
-    /// algorithm. For more information, see \ref PivotRule.
-    ///
-    /// \return \c INFEASIBLE if no feasible flow exists,
-    /// \n \c OPTIMAL if the problem has optimal solution
-    /// (i.e. it is feasible and bounded), and the algorithm has found
-    /// optimal flow and node potentials (primal and dual solutions),
-    /// \n \c UNBOUNDED if the objective function of the problem is
-    /// unbounded, i.e. there is a directed cycle having negative total
-    /// cost and infinite upper bound.
-    ///
-    /// \see ProblemType, PivotRule
-    /// \see resetParams(), reset()
-    ProblemType run(PivotRule pivot_rule = BLOCK_SEARCH) {
-      if (!init()) return INFEASIBLE;
-      return start(pivot_rule);
-    }
-
-    /// \brief Reset all the parameters that have been given before.
-    ///
-    /// This function resets all the paramaters that have been given
-    /// before using functions \ref lowerMap(), \ref upperMap(),
-    /// \ref costMap(), \ref supplyMap(), \ref stSupply(), \ref supplyType().
-    ///
-    /// It is useful for multiple \ref run() calls. Basically, all the given
-    /// parameters are kept for the next \ref run() call, unless
-    /// \ref resetParams() or \ref reset() is used.
-    /// If the underlying digraph was also modified after the construction
-    /// of the class or the last \ref reset() call, then the \ref reset()
-    /// function must be used, otherwise \ref resetParams() is sufficient.
-    ///
-    /// For example,
-    /// \code
-    ///   NetworkSimplex<ListDigraph> ns(graph);
-    ///
-    ///   // First run
-    ///   ns.lowerMap(lower).upperMap(upper).costMap(cost)
-    ///     .supplyMap(sup).run();
-    ///
-    ///   // Run again with modified cost map (resetParams() is not called,
-    ///   // so only the cost map have to be set again)
-    ///   cost[e] += 100;
-    ///   ns.costMap(cost).run();
-    ///
-    ///   // Run again from scratch using resetParams()
-    ///   // (the lower bounds will be set to zero on all arcs)
-    ///   ns.resetParams();
-    ///   ns.upperMap(capacity).costMap(cost)
-    ///     .supplyMap(sup).run();
-    /// \endcode
-    ///
-    /// \return <tt>(*this)</tt>
-    ///
-    /// \see reset(), run()
-    NetworkSimplex& resetParams() {
-      for (int i = 0; i != _node_num; ++i) {
-        _supply[i] = 0;
-      }
-      for (int i = 0; i != _arc_num; ++i) {
-        _lower[i] = 0;
-        _upper[i] = INF;
-        _cost[i] = 1;
-      }
-      _have_lower = false;
-      _stype = GEQ;
-      return *this;
-    }
-
-    /// \brief Reset the internal data structures and all the parameters
-    /// that have been given before.
-    ///
-    /// This function resets the internal data structures and all the
-    /// paramaters that have been given before using functions \ref lowerMap(),
-    /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(),
-    /// \ref supplyType().
-    ///
-    /// It is useful for multiple \ref run() calls. Basically, all the given
-    /// parameters are kept for the next \ref run() call, unless
-    /// \ref resetParams() or \ref reset() is used.
-    /// If the underlying digraph was also modified after the construction
-    /// of the class or the last \ref reset() call, then the \ref reset()
-    /// function must be used, otherwise \ref resetParams() is sufficient.
-    ///
-    /// See \ref resetParams() for examples.
-    ///
-    /// \return <tt>(*this)</tt>
-    ///
-    /// \see resetParams(), run()
-    NetworkSimplex& reset() {
+        
       // Resize vectors
       _node_num = countNodes(_graph);
@@ -921,31 +672,245 @@
       _state.resize(max_arc_num);
 
-      // Copy the graph
+      // Copy the graph (store the arcs in a mixed order)
       int i = 0;
       for (NodeIt n(_graph); n != INVALID; ++n, ++i) {
         _node_id[n] = i;
       }
-      if (_arc_mixing) {
-        // Store the arcs in a mixed order
-        int k = std::max(int(std::sqrt(double(_arc_num))), 10);
-        int i = 0, j = 0;
-        for (ArcIt a(_graph); a != INVALID; ++a) {
-          _arc_id[a] = i;
-          _source[i] = _node_id[_graph.source(a)];
-          _target[i] = _node_id[_graph.target(a)];
-          if ((i += k) >= _arc_num) i = ++j;
-        }
-      } else {
-        // Store the arcs in the original order
-        int i = 0;
-        for (ArcIt a(_graph); a != INVALID; ++a, ++i) {
-          _arc_id[a] = i;
-          _source[i] = _node_id[_graph.source(a)];
-          _target[i] = _node_id[_graph.target(a)];
-        }
-      }
-
-      // Reset parameters
-      resetParams();
+      int k = std::max(int(std::sqrt(double(_arc_num))), 10);
+      i = 0;
+      for (ArcIt a(_graph); a != INVALID; ++a) {
+        _arc_id[a] = i;
+        _source[i] = _node_id[_graph.source(a)];
+        _target[i] = _node_id[_graph.target(a)];
+        if ((i += k) >= _arc_num) i = (i % k) + 1;
+      }
+      
+      // Initialize maps
+      for (int i = 0; i != _node_num; ++i) {
+        _supply[i] = 0;
+      }
+      for (int i = 0; i != _arc_num; ++i) {
+        _lower[i] = 0;
+        _upper[i] = INF;
+        _cost[i] = 1;
+      }
+      _have_lower = false;
+      _stype = GEQ;
+    }
+
+    /// \name Parameters
+    /// The parameters of the algorithm can be specified using these
+    /// functions.
+
+    /// @{
+
+    /// \brief Set the lower bounds on the arcs.
+    ///
+    /// This function sets the lower bounds on the arcs.
+    /// If it is not used before calling \ref run(), the lower bounds
+    /// will be set to zero on all arcs.
+    ///
+    /// \param map An arc map storing the lower bounds.
+    /// Its \c Value type must be convertible to the \c Value type
+    /// of the algorithm.
+    ///
+    /// \return <tt>(*this)</tt>
+    template <typename LowerMap>
+    NetworkSimplex& lowerMap(const LowerMap& map) {
+      _have_lower = true;
+      for (ArcIt a(_graph); a != INVALID; ++a) {
+        _lower[_arc_id[a]] = map[a];
+      }
+      return *this;
+    }
+
+    /// \brief Set the upper bounds (capacities) on the arcs.
+    ///
+    /// This function sets the upper bounds (capacities) on the arcs.
+    /// If it is not used before calling \ref run(), the upper bounds
+    /// will be set to \ref INF on all arcs (i.e. the flow value will be
+    /// unbounded from above on each arc).
+    ///
+    /// \param map An arc map storing the upper bounds.
+    /// Its \c Value type must be convertible to the \c Value type
+    /// of the algorithm.
+    ///
+    /// \return <tt>(*this)</tt>
+    template<typename UpperMap>
+    NetworkSimplex& upperMap(const UpperMap& map) {
+      for (ArcIt a(_graph); a != INVALID; ++a) {
+        _upper[_arc_id[a]] = map[a];
+      }
+      return *this;
+    }
+
+    /// \brief Set the costs of the arcs.
+    ///
+    /// This function sets the costs of the arcs.
+    /// If it is not used before calling \ref run(), the costs
+    /// will be set to \c 1 on all arcs.
+    ///
+    /// \param map An arc map storing the costs.
+    /// Its \c Value type must be convertible to the \c Cost type
+    /// of the algorithm.
+    ///
+    /// \return <tt>(*this)</tt>
+    template<typename CostMap>
+    NetworkSimplex& costMap(const CostMap& map) {
+      for (ArcIt a(_graph); a != INVALID; ++a) {
+        _cost[_arc_id[a]] = map[a];
+      }
+      return *this;
+    }
+
+    /// \brief Set the supply values of the nodes.
+    ///
+    /// This function sets the supply values of the nodes.
+    /// If neither this function nor \ref stSupply() is used before
+    /// calling \ref run(), the supply of each node will be set to zero.
+    /// (It makes sense only if non-zero lower bounds are given.)
+    ///
+    /// \param map A node map storing the supply values.
+    /// Its \c Value type must be convertible to the \c Value type
+    /// of the algorithm.
+    ///
+    /// \return <tt>(*this)</tt>
+    template<typename SupplyMap>
+    NetworkSimplex& supplyMap(const SupplyMap& map) {
+      for (NodeIt n(_graph); n != INVALID; ++n) {
+        _supply[_node_id[n]] = map[n];
+      }
+      return *this;
+    }
+
+    /// \brief Set single source and target nodes and a supply value.
+    ///
+    /// This function sets a single source node and a single target node
+    /// and the required flow value.
+    /// If neither this function nor \ref supplyMap() is used before
+    /// calling \ref run(), the supply of each node will be set to zero.
+    /// (It makes sense only if non-zero lower bounds are given.)
+    ///
+    /// Using this function has the same effect as using \ref supplyMap()
+    /// with such a map in which \c k is assigned to \c s, \c -k is
+    /// assigned to \c t and all other nodes have zero supply value.
+    ///
+    /// \param s The source node.
+    /// \param t The target node.
+    /// \param k The required amount of flow from node \c s to node \c t
+    /// (i.e. the supply of \c s and the demand of \c t).
+    ///
+    /// \return <tt>(*this)</tt>
+    NetworkSimplex& stSupply(const Node& s, const Node& t, Value k) {
+      for (int i = 0; i != _node_num; ++i) {
+        _supply[i] = 0;
+      }
+      _supply[_node_id[s]] =  k;
+      _supply[_node_id[t]] = -k;
+      return *this;
+    }
+    
+    /// \brief Set the type of the supply constraints.
+    ///
+    /// This function sets the type of the supply/demand constraints.
+    /// If it is not used before calling \ref run(), the \ref GEQ supply
+    /// type will be used.
+    ///
+    /// For more information see \ref SupplyType.
+    ///
+    /// \return <tt>(*this)</tt>
+    NetworkSimplex& supplyType(SupplyType supply_type) {
+      _stype = supply_type;
+      return *this;
+    }
+
+    /// @}
+
+    /// \name Execution Control
+    /// The algorithm can be executed using \ref run().
+
+    /// @{
+
+    /// \brief Run the algorithm.
+    ///
+    /// This function runs the algorithm.
+    /// The paramters can be specified using functions \ref lowerMap(),
+    /// \ref upperMap(), \ref costMap(), \ref supplyMap(), \ref stSupply(), 
+    /// \ref supplyType().
+    /// For example,
+    /// \code
+    ///   NetworkSimplex<ListDigraph> ns(graph);
+    ///   ns.lowerMap(lower).upperMap(upper).costMap(cost)
+    ///     .supplyMap(sup).run();
+    /// \endcode
+    ///
+    /// This function can be called more than once. All the parameters
+    /// that have been given are kept for the next call, unless
+    /// \ref reset() is called, thus only the modified parameters
+    /// have to be set again. See \ref reset() for examples.
+    /// However the underlying digraph must not be modified after this
+    /// class have been constructed, since it copies and extends the graph.
+    ///
+    /// \param pivot_rule The pivot rule that will be used during the
+    /// algorithm. For more information see \ref PivotRule.
+    ///
+    /// \return \c INFEASIBLE if no feasible flow exists,
+    /// \n \c OPTIMAL if the problem has optimal solution
+    /// (i.e. it is feasible and bounded), and the algorithm has found
+    /// optimal flow and node potentials (primal and dual solutions),
+    /// \n \c UNBOUNDED if the objective function of the problem is
+    /// unbounded, i.e. there is a directed cycle having negative total
+    /// cost and infinite upper bound.
+    ///
+    /// \see ProblemType, PivotRule
+    ProblemType run(PivotRule pivot_rule = BLOCK_SEARCH) {
+      if (!init()) return INFEASIBLE;
+      return start(pivot_rule);
+    }
+
+    /// \brief Reset all the parameters that have been given before.
+    ///
+    /// This function resets all the paramaters that have been given
+    /// before using functions \ref lowerMap(), \ref upperMap(),
+    /// \ref costMap(), \ref supplyMap(), \ref stSupply(), \ref supplyType().
+    ///
+    /// It is useful for multiple run() calls. If this function is not
+    /// used, all the parameters given before are kept for the next
+    /// \ref run() call.
+    /// However the underlying digraph must not be modified after this
+    /// class have been constructed, since it copies and extends the graph.
+    ///
+    /// For example,
+    /// \code
+    ///   NetworkSimplex<ListDigraph> ns(graph);
+    ///
+    ///   // First run
+    ///   ns.lowerMap(lower).upperMap(upper).costMap(cost)
+    ///     .supplyMap(sup).run();
+    ///
+    ///   // Run again with modified cost map (reset() is not called,
+    ///   // so only the cost map have to be set again)
+    ///   cost[e] += 100;
+    ///   ns.costMap(cost).run();
+    ///
+    ///   // Run again from scratch using reset()
+    ///   // (the lower bounds will be set to zero on all arcs)
+    ///   ns.reset();
+    ///   ns.upperMap(capacity).costMap(cost)
+    ///     .supplyMap(sup).run();
+    /// \endcode
+    ///
+    /// \return <tt>(*this)</tt>
+    NetworkSimplex& reset() {
+      for (int i = 0; i != _node_num; ++i) {
+        _supply[i] = 0;
+      }
+      for (int i = 0; i != _arc_num; ++i) {
+        _lower[i] = 0;
+        _upper[i] = INF;
+        _cost[i] = 1;
+      }
+      _have_lower = false;
+      _stype = GEQ;
       return *this;
     }
@@ -1060,7 +1025,7 @@
           Value c = _lower[i];
           if (c >= 0) {
-            _cap[i] = _upper[i] < MAX ? _upper[i] - c : INF;
+            _cap[i] = _upper[i] < INF ? _upper[i] - c : INF;
           } else {
-            _cap[i] = _upper[i] < MAX + c ? _upper[i] - c : INF;
+            _cap[i] = _upper[i] < INF + c ? _upper[i] - c : INF;
           }
           _supply[_source[i]] -= c;
@@ -1078,5 +1043,5 @@
         ART_COST = std::numeric_limits<Cost>::max() / 2 + 1;
       } else {
-        ART_COST = std::numeric_limits<Cost>::min();
+        ART_COST = 0;
         for (int i = 0; i != _arc_num; ++i) {
           if (_cost[i] > ART_COST) ART_COST = _cost[i];
@@ -1090,5 +1055,5 @@
         _state[i] = STATE_LOWER;
       }
-
+      
       // Set data for the artificial root node
       _root = _node_num;
@@ -1254,5 +1219,5 @@
         e = _pred[u];
         d = _forward[u] ?
-          _flow[e] : (_cap[e] >= MAX ? INF : _cap[e] - _flow[e]);
+          _flow[e] : (_cap[e] == INF ? INF : _cap[e] - _flow[e]);
         if (d < delta) {
           delta = d;
@@ -1264,6 +1229,6 @@
       for (int u = second; u != join; u = _parent[u]) {
         e = _pred[u];
-        d = _forward[u] ?
-          (_cap[e] >= MAX ? INF : _cap[e] - _flow[e]) : _flow[e];
+        d = _forward[u] ? 
+          (_cap[e] == INF ? INF : _cap[e] - _flow[e]) : _flow[e];
         if (d <= delta) {
           delta = d;
@@ -1366,5 +1331,5 @@
 
       // Update _rev_thread using the new _thread values
-      for (int i = 0; i != int(_dirty_revs.size()); ++i) {
+      for (int i = 0; i < int(_dirty_revs.size()); ++i) {
         u = _dirty_revs[i];
         _rev_thread[_thread[u]] = u;
@@ -1436,98 +1401,4 @@
         _pi[u] += sigma;
       }
-    }
-
-    // Heuristic initial pivots
-    bool initialPivots() {
-      Value curr, total = 0;
-      std::vector<Node> supply_nodes, demand_nodes;
-      for (NodeIt u(_graph); u != INVALID; ++u) {
-        curr = _supply[_node_id[u]];
-        if (curr > 0) {
-          total += curr;
-          supply_nodes.push_back(u);
-        }
-        else if (curr < 0) {
-          demand_nodes.push_back(u);
-        }
-      }
-      if (_sum_supply > 0) total -= _sum_supply;
-      if (total <= 0) return true;
-
-      IntVector arc_vector;
-      if (_sum_supply >= 0) {
-        if (supply_nodes.size() == 1 && demand_nodes.size() == 1) {
-          // Perform a reverse graph search from the sink to the source
-          typename GR::template NodeMap<bool> reached(_graph, false);
-          Node s = supply_nodes[0], t = demand_nodes[0];
-          std::vector<Node> stack;
-          reached[t] = true;
-          stack.push_back(t);
-          while (!stack.empty()) {
-            Node u, v = stack.back();
-            stack.pop_back();
-            if (v == s) break;
-            for (InArcIt a(_graph, v); a != INVALID; ++a) {
-              if (reached[u = _graph.source(a)]) continue;
-              int j = _arc_id[a];
-              if (_cap[j] >= total) {
-                arc_vector.push_back(j);
-                reached[u] = true;
-                stack.push_back(u);
-              }
-            }
-          }
-        } else {
-          // Find the min. cost incomming arc for each demand node
-          for (int i = 0; i != int(demand_nodes.size()); ++i) {
-            Node v = demand_nodes[i];
-            Cost c, min_cost = std::numeric_limits<Cost>::max();
-            Arc min_arc = INVALID;
-            for (InArcIt a(_graph, v); a != INVALID; ++a) {
-              c = _cost[_arc_id[a]];
-              if (c < min_cost) {
-                min_cost = c;
-                min_arc = a;
-              }
-            }
-            if (min_arc != INVALID) {
-              arc_vector.push_back(_arc_id[min_arc]);
-            }
-          }
-        }
-      } else {
-        // Find the min. cost outgoing arc for each supply node
-        for (int i = 0; i != int(supply_nodes.size()); ++i) {
-          Node u = supply_nodes[i];
-          Cost c, min_cost = std::numeric_limits<Cost>::max();
-          Arc min_arc = INVALID;
-          for (OutArcIt a(_graph, u); a != INVALID; ++a) {
-            c = _cost[_arc_id[a]];
-            if (c < min_cost) {
-              min_cost = c;
-              min_arc = a;
-            }
-          }
-          if (min_arc != INVALID) {
-            arc_vector.push_back(_arc_id[min_arc]);
-          }
-        }
-      }
-
-      // Perform heuristic initial pivots
-      for (int i = 0; i != int(arc_vector.size()); ++i) {
-        in_arc = arc_vector[i];
-        if (_state[in_arc] * (_cost[in_arc] + _pi[_source[in_arc]] -
-            _pi[_target[in_arc]]) >= 0) continue;
-        findJoinNode();
-        bool change = findLeavingArc();
-        if (delta >= MAX) return false;
-        changeFlow(change);
-        if (change) {
-          updateTreeStructure();
-          updatePotential();
-        }
-      }
-      return true;
     }
 
@@ -1554,12 +1425,9 @@
       PivotRuleImpl pivot(*this);
 
-      // Perform heuristic initial pivots
-      if (!initialPivots()) return UNBOUNDED;
-
       // Execute the Network Simplex algorithm
       while (pivot.findEnteringArc()) {
         findJoinNode();
         bool change = findLeavingArc();
-        if (delta >= MAX) return UNBOUNDED;
+        if (delta >= INF) return UNBOUNDED;
         changeFlow(change);
         if (change) {
@@ -1568,5 +1436,5 @@
         }
       }
-
+      
       // Check feasibility
       for (int e = _search_arc_num; e != _all_arc_num; ++e) {
@@ -1585,10 +1453,10 @@
         }
       }
-
+      
       // Shift potentials to meet the requirements of the GEQ/LEQ type
       // optimality conditions
       if (_sum_supply == 0) {
         if (_stype == GEQ) {
-          Cost max_pot = std::numeric_limits<Cost>::min();
+          Cost max_pot = -std::numeric_limits<Cost>::max();
           for (int i = 0; i != _node_num; ++i) {
             if (_pi[i] > max_pot) max_pot = _pi[i];
