Index: lemon/network_simplex.h
===================================================================
--- lemon/network_simplex.h	(revision 777)
+++ lemon/network_simplex.h	(revision 710)
@@ -162,4 +162,6 @@
     TEMPLATE_DIGRAPH_TYPEDEFS(GR);
 
+    typedef std::vector<Arc> ArcVector;
+    typedef std::vector<Node> NodeVector;
     typedef std::vector<int> IntVector;
     typedef std::vector<bool> BoolVector;
@@ -363,30 +365,31 @@
         Cost c, min = 0;
         int cnt = _block_size;
-        int 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;
@@ -426,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;
@@ -443,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
@@ -454,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;
+          }
         }
 
@@ -472,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;
@@ -543,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;
@@ -572,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)
@@ -608,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 );
@@ -624,9 +634,5 @@
     ///
     /// \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),
       INF(std::numeric_limits<Value>::has_infinity ?
@@ -666,31 +672,29 @@
       _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)];
-        }
+      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;
       }
       
-      // Reset parameters
-      reset();
+      // 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;
     }
 
@@ -765,4 +769,5 @@
     /// 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.
@@ -785,4 +790,5 @@
     /// 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()
