Index: lemon/network_simplex.h
===================================================================
--- lemon/network_simplex.h	(revision 2635)
+++ lemon/network_simplex.h	(revision 2638)
@@ -242,8 +242,8 @@
         _edge(ns._edge), _source(ns._source), _target(ns._target),
         _cost(ns._cost), _state(ns._state), _pi(ns._pi),
-        _in_edge(ns._in_edge), _edge_num(ns._edge_num + ns._node_num), _next_edge(0)
+        _in_edge(ns._in_edge), _edge_num(ns._edge_num), _next_edge(0)
       {
         // The main parameters of the pivot rule
-        const double BLOCK_SIZE_FACTOR = 2.0;
+        const double BLOCK_SIZE_FACTOR = 0.5;
         const int MIN_BLOCK_SIZE = 10;
 
@@ -256,31 +256,30 @@
         Cost c, min = 0;
         int cnt = _block_size;
-        int e, min_edge = _next_edge;
+        int e;
         for (e = _next_edge; e < _edge_num; ++e) {
           c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
           if (c < min) {
             min = c;
-            min_edge = e;
+            _in_edge = e;
           }
           if (--cnt == 0) {
-            if (min < 0) break;
+            if (min < 0) goto search_end;
             cnt = _block_size;
           }
         }
-        if (min == 0 || cnt > 0) {
-          for (e = 0; e < _next_edge; ++e) {
-            c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
-            if (c < min) {
-              min = c;
-              min_edge = e;
-            }
-            if (--cnt == 0) {
-              if (min < 0) break;
-              cnt = _block_size;
-            }
+        for (e = 0; e < _next_edge; ++e) {
+          c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
+          if (c < min) {
+            min = c;
+            _in_edge = e;
+          }
+          if (--cnt == 0) {
+            if (min < 0) goto search_end;
+            cnt = _block_size;
           }
         }
         if (min >= 0) return false;
-        _in_edge = min_edge;
+
+      search_end:
         _next_edge = e;
         return true;
@@ -326,5 +325,5 @@
       {
         // The main parameters of the pivot rule
-        const double LIST_LENGTH_FACTOR = 1.0;
+        const double LIST_LENGTH_FACTOR = 0.25;
         const int MIN_LIST_LENGTH = 10;
         const double MINOR_LIMIT_FACTOR = 0.1;
@@ -342,5 +341,5 @@
       bool findEnteringEdge() {
         Cost min, c;
-        int e, min_edge = _next_edge;
+        int e;
         if (_curr_length > 0 && _minor_count < _minor_limit) {
           // Minor iteration: select the best eligible edge from the
@@ -353,14 +352,11 @@
             if (c < min) {
               min = c;
-              min_edge = e;
+              _in_edge = e;
             }
-            if (c >= 0) {
+            else if (c >= 0) {
               _candidates[i--] = _candidates[--_curr_length];
             }
           }
-          if (min < 0) {
-            _in_edge = min_edge;
-            return true;
-          }
+          if (min < 0) return true;
         }
 
@@ -374,25 +370,24 @@
             if (c < min) {
               min = c;
-              min_edge = e;
+              _in_edge = e;
             }
-            if (_curr_length == _list_length) break;
-          }
-        }
-        if (_curr_length < _list_length) {
-          for (e = 0; e < _next_edge; ++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_edge = e;
-              }
-              if (_curr_length == _list_length) break;
+            if (_curr_length == _list_length) goto search_end;
+          }
+        }
+        for (e = 0; e < _next_edge; ++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_edge = e;
             }
+            if (_curr_length == _list_length) goto search_end;
           }
         }
         if (_curr_length == 0) return false;
+      
+      search_end:        
         _minor_count = 1;
-        _in_edge = min_edge;
         _next_edge = e;
         return true;
@@ -452,5 +447,5 @@
       {
         // The main parameters of the pivot rule
-        const double BLOCK_SIZE_FACTOR = 1.5;
+        const double BLOCK_SIZE_FACTOR = 1.0;
         const int MIN_BLOCK_SIZE = 10;
         const double HEAD_LENGTH_FACTOR = 0.1;
@@ -480,37 +475,33 @@
         // Extend the list
         int cnt = _block_size;
-        int last_edge = 0;
         int limit = _head_length;
         
-        for (int e = _next_edge; e < _edge_num; ++e) {
+        for (e = _next_edge; e < _edge_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_edge = e;
           }
           if (--cnt == 0) {
-            if (_curr_length > limit) break;
+            if (_curr_length > limit) goto search_end;
             limit = 0;
             cnt = _block_size;
           }
         }
-        if (_curr_length <= limit) {
-          for (int e = 0; e < _next_edge; ++e) {
-            _cand_cost[e] = _state[e] *
-              (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
-            if (_cand_cost[e] < 0) {
-              _candidates[_curr_length++] = e;
-              last_edge = e;
-            }
-            if (--cnt == 0) {
-              if (_curr_length > limit) break;
-              limit = 0;
-              cnt = _block_size;
-            }
+        for (e = 0; e < _next_edge; ++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 == 0) return false;
-        _next_edge = last_edge + 1;
+        
+      search_end:
 
         // Make heap of the candidate list (approximating a partial sort)
@@ -520,4 +511,5 @@
         // Pop the first element of the heap
         _in_edge = _candidates[0];
+        _next_edge = e;
         pop_heap( _candidates.begin(), _candidates.begin() + _curr_length,
                   _sort_func );
@@ -932,10 +924,8 @@
       _pi[_root] = 0;
       
-      // Store the edges in a mixed order
-      int k = std::max(int(sqrt(_edge_num)), 10);
+      // Store the edges
       int i = 0;
       for (EdgeIt e(_orig_graph); e != INVALID; ++e) {
-        _edge[i] = e;
-        if ((i += k) >= _edge_num) i = (i % k) + 1;
+        _edge[i++] = e;
       }
 
@@ -962,5 +952,5 @@
 
       // Add artificial edges and initialize the spanning tree data structure
-      Cost max_cost = std::numeric_limits<Cost>::max() / 4;
+      Cost max_cost = std::numeric_limits<Cost>::max() / 2 + 1;
       Capacity max_cap = std::numeric_limits<Capacity>::max();
       for (int u = 0, e = _edge_num; u != _node_num; ++u, ++e) {
