Index: lemon/network_simplex.h
===================================================================
--- lemon/network_simplex.h	(revision 1298)
+++ lemon/network_simplex.h	(revision 1317)
@@ -3,5 +3,5 @@
  * This file is a part of LEMON, a generic C++ optimization library.
  *
- * Copyright (C) 2003-2013
+ * Copyright (C) 2003-2010
  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
  * (Egervary Research Group on Combinatorial Optimization, EGRES).
@@ -42,15 +42,14 @@
   /// \ref NetworkSimplex implements the primal Network Simplex algorithm
   /// for finding a \ref min_cost_flow "minimum cost flow"
-  /// \cite amo93networkflows, \cite dantzig63linearprog,
-  /// \cite kellyoneill91netsimplex.
+  /// \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.
   ///
-  /// In general, \ref NetworkSimplex and \ref CostScaling are the fastest
-  /// implementations available in LEMON for solving this problem.
-  /// (For more information, see \ref min_cost_flow_algs "the module page".)
-  /// Furthermore, this class supports both directions of the supply/demand
-  /// inequality constraints. For more information, see \ref SupplyType.
+  /// 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.
   ///
   /// Most of the parameters of the problem (except for the digraph)
@@ -65,6 +64,5 @@
   /// algorithm. By default, it is the same as \c V.
   ///
-  /// \warning Both \c V and \c C must be signed number types.
-  /// \warning All input data (capacities, supply values, and costs) must
+  /// \warning Both number types must be signed and all input data must
   /// be integer.
   ///
@@ -124,15 +122,12 @@
     /// the \ref run() function.
     ///
-    /// \ref NetworkSimplex provides five different implementations for
-    /// the pivot strategy that significantly affects the running time
+    /// \ref NetworkSimplex provides five different pivot rule
+    /// implementations that significantly affect the running time
     /// of the algorithm.
-    /// According to experimental tests conducted on various problem
-    /// instances, \ref BLOCK_SEARCH "Block Search" and
-    /// \ref ALTERING_LIST "Altering Candidate List" rules turned out
-    /// to be the most efficient.
-    /// Since \ref BLOCK_SEARCH "Block Search" is a simpler strategy that
-    /// seemed to be slightly more robust, it is used by default.
-    /// However, another pivot rule can easily be selected using the
-    /// \ref run() function with the proper parameter.
+    /// 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()
+    /// function with the proper parameter.
     enum PivotRule {
 
@@ -160,5 +155,5 @@
       /// The \e Altering \e Candidate \e List pivot rule.
       /// It is a modified version of the Candidate List method.
-      /// It keeps only a few of the best eligible arcs from the former
+      /// It keeps only the several best eligible arcs from the former
       /// candidate list and extends this list in every iteration.
       ALTERING_LIST
@@ -173,5 +168,5 @@
     typedef std::vector<Cost> CostVector;
     typedef std::vector<signed char> CharVector;
-    // Note: vector<signed char> is used instead of vector<ArcState> and
+    // Note: vector<signed char> is used instead of vector<ArcState> and 
     // vector<ArcDirection> for efficiency reasons
 
@@ -199,5 +194,5 @@
 
     // Parameters of the problem
-    bool _has_lower;
+    bool _have_lower;
     SupplyType _stype;
     Value _sum_supply;
@@ -543,5 +538,5 @@
         SortFunc(const CostVector &map) : _map(map) {}
         bool operator()(int left, int right) {
-          return _map[left] < _map[right];
+          return _map[left] > _map[right];
         }
       };
@@ -561,5 +556,5 @@
         const double BLOCK_SIZE_FACTOR = 1.0;
         const int MIN_BLOCK_SIZE = 10;
-        const double HEAD_LENGTH_FACTOR = 0.01;
+        const double HEAD_LENGTH_FACTOR = 0.1;
         const int MIN_HEAD_LENGTH = 3;
 
@@ -605,7 +600,7 @@
         }
         for (e = 0; e != _next_arc; ++e) {
-          c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
-          if (c < 0) {
-            _cand_cost[e] = c;
+          _cand_cost[e] = _state[e] *
+            (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
+          if (_cand_cost[e] < 0) {
             _candidates[_curr_length++] = e;
           }
@@ -620,14 +615,14 @@
       search_end:
 
-        // Perform partial sort operation on the candidate list
-        int new_length = std::min(_head_length + 1, _curr_length);
-        std::partial_sort(_candidates.begin(), _candidates.begin() + new_length,
-                          _candidates.begin() + _curr_length, _sort_func);
-
-        // Select the entering arc and remove it from the list
+        // Make heap of the candidate list (approximating a partial sort)
+        make_heap( _candidates.begin(), _candidates.begin() + _curr_length,
+                   _sort_func );
+
+        // Pop the first element of the heap
         _in_arc = _candidates[0];
         _next_arc = e;
-        _candidates[0] = _candidates[new_length - 1];
-        _curr_length = new_length - 1;
+        pop_heap( _candidates.begin(), _candidates.begin() + _curr_length,
+                  _sort_func );
+        _curr_length = std::min(_head_length, _curr_length - 1);
         return true;
       }
@@ -683,5 +678,5 @@
     template <typename LowerMap>
     NetworkSimplex& lowerMap(const LowerMap& map) {
-      _has_lower = true;
+      _have_lower = true;
       for (ArcIt a(_graph); a != INVALID; ++a) {
         _lower[_arc_id[a]] = map[a];
@@ -740,6 +735,4 @@
     ///
     /// \return <tt>(*this)</tt>
-    ///
-    /// \sa supplyType()
     template<typename SupplyMap>
     NetworkSimplex& supplyMap(const SupplyMap& map) {
@@ -758,5 +751,5 @@
     ///
     /// Using this function has the same effect as using \ref supplyMap()
-    /// with a map in which \c k is assigned to \c s, \c -k is
+    /// 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.
     ///
@@ -880,5 +873,5 @@
         _cost[i] = 1;
       }
-      _has_lower = false;
+      _have_lower = false;
       _stype = GEQ;
       return *this;
@@ -937,5 +930,5 @@
         _node_id[n] = i;
       }
-      if (_arc_mixing) {
+      if (_arc_mixing && _node_num > 1) {
         // Store the arcs in a mixed order
         const int skip = std::max(_arc_num / _node_num, 3);
@@ -974,5 +967,5 @@
     ///
     /// This function returns the total cost of the found flow.
-    /// Its complexity is O(m).
+    /// Its complexity is O(e).
     ///
     /// \note The return type of the function can be specified as a
@@ -1011,6 +1004,5 @@
     }
 
-    /// \brief Copy the flow values (the primal solution) into the
-    /// given map.
+    /// \brief Return the flow map (the primal solution).
     ///
     /// This function copies the flow value on each arc into the given
@@ -1036,6 +1028,5 @@
     }
 
-    /// \brief Copy the potential values (the dual solution) into the
-    /// given map.
+    /// \brief Return the potential map (the dual solution).
     ///
     /// This function copies the potential (dual value) of each node
@@ -1068,10 +1059,6 @@
              (_stype == LEQ && _sum_supply >= 0)) ) return false;
 
-      // Check lower and upper bounds
-      LEMON_DEBUG(checkBoundMaps(),
-          "Upper bounds must be greater or equal to the lower bounds");
-
       // Remove non-zero lower bounds
-      if (_has_lower) {
+      if (_have_lower) {
         for (int i = 0; i != _arc_num; ++i) {
           Value c = _lower[i];
@@ -1236,13 +1223,4 @@
     }
 
-    // Check if the upper bound is greater than or equal to the lower bound
-    // on each arc.
-    bool checkBoundMaps() {
-      for (int j = 0; j != _arc_num; ++j) {
-        if (_upper[j] < _lower[j]) return false;
-      }
-      return true;
-    }
-
     // Find the join node
     void findJoinNode() {
@@ -1517,5 +1495,5 @@
           }
         } else {
-          // Find the min. cost incoming arc for each demand node
+          // 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];
@@ -1613,5 +1591,5 @@
 
       // Transform the solution and the supply map to the original form
-      if (_has_lower) {
+      if (_have_lower) {
         for (int i = 0; i != _arc_num; ++i) {
           Value c = _lower[i];
