[Lemon-commits] deba: r3282 - lemon/trunk/lemon

Lemon SVN svn at lemon.cs.elte.hu
Fri May 11 18:03:20 CEST 2007


Author: deba
Date: Fri May 11 18:03:20 2007
New Revision: 3282

Modified:
   lemon/trunk/lemon/network_simplex.h

Log:
Patch in network simplex

Patch from Peter Kovacs



Modified: lemon/trunk/lemon/network_simplex.h
==============================================================================
--- lemon/trunk/lemon/network_simplex.h	(original)
+++ lemon/trunk/lemon/network_simplex.h	Fri May 11 18:03:20 2007
@@ -30,12 +30,15 @@
 #include <lemon/graph_utils.h>
 
 /// \brief The pivot rule used in the algorithm.
-#define EDGE_BLOCK_PIVOT
 //#define FIRST_ELIGIBLE_PIVOT
 //#define BEST_ELIGIBLE_PIVOT
+#define EDGE_BLOCK_PIVOT
 //#define CANDIDATE_LIST_PIVOT
 //#define SORTED_LIST_PIVOT
 
+//#define _DEBUG_ITER_
+
+
 /// \brief State constant for edges at their lower bounds.
 #define LOWER	1
 /// \brief State constant for edges in the spanning tree.
@@ -45,20 +48,19 @@
 
 #ifdef EDGE_BLOCK_PIVOT
   /// \brief Number of blocks for the "Edge Block" pivot rule.
-  #define BLOCK_NUM	  100
-  /// \brief Lower bound for the number of edges to use "Edge Block"
-  // pivot rule instead of "First Eligible" pivot rule.
-  #define MIN_BOUND	  1000
+  #define BLOCK_NUM		100
+  /// \brief Lower bound for the size of blocks.
+  #define MIN_BLOCK_SIZE	10
 #endif
 
 #ifdef CANDIDATE_LIST_PIVOT
   #include <list>
   /// \brief The maximum length of the edge list for the
   /// "Candidate List" pivot rule.
-  #define LIST_LENGTH	  100
+  #define LIST_LENGTH		100
   /// \brief The maximum number of minor iterations between two major
   /// itarations.
-  #define MINOR_LIMIT	  50
+  #define MINOR_LIMIT		10
 #endif
 
 #ifdef SORTED_LIST_PIVOT
@@ -66,12 +68,10 @@
   #include <algorithm>
   /// \brief The maximum length of the edge list for the
   /// "Sorted List" pivot rule.
-  #define LIST_LENGTH	  500
-  #define LOWER_DIV	  4
+  #define LIST_LENGTH		500
+  #define LOWER_DIV		3
 #endif
 
-//#define _DEBUG_ITER_
-
 namespace lemon {
 
   /// \addtogroup min_cost_flow
@@ -513,7 +513,8 @@
 #ifdef EDGE_BLOCK_PIVOT
       // Initializing block_size for the edge block pivot rule
       int edge_num = countEdges(graph);
-      block_size = edge_num > MIN_BOUND ? edge_num / BLOCK_NUM + 1 : 1;
+      block_size = edge_num >= BLOCK_NUM * MIN_BLOCK_SIZE ? 
+		   edge_num / BLOCK_NUM : MIN_BLOCK_SIZE;
 #endif
 #ifdef CANDIDATE_LIST_PIVOT
       minor_count = 0;
@@ -563,29 +564,22 @@
     /// \brief Finds entering edge according to the "Edge Block"
     /// pivot rule.
     bool findEnteringEdge(EdgeIt &next_edge) {
-      if (block_size == 1) {
-	// Performing first eligible selection
-	for (EdgeIt e = next_edge; e != INVALID; ++e) {
-	  if (state[e] * red_cost[e] < 0) {
-	    in_edge = e;
-	    next_edge = ++e;
-	    return true;
-	  }
+      // Performing edge block selection
+      Cost curr, min = 0;
+      EdgeIt min_edge(graph);
+      int cnt = 0;
+      for (EdgeIt e = next_edge; e != INVALID; ++e) {
+	if ((curr = state[e] * red_cost[e]) < min) {
+	  min = curr;
+	  min_edge = e;
 	}
-	for (EdgeIt e(graph); e != next_edge; ++e) {
-	  if (state[e] * red_cost[e] < 0) {
-	    in_edge = e;
-	    next_edge = ++e;
-	    return true;
-	  }
+	if (++cnt == block_size) {
+	  if (min < 0) break;
+	  cnt = 0;
 	}
-	return false;
-      } else {
-	// Performing edge block selection
-	Cost curr, min = 0;
-	EdgeIt min_edge(graph);
-	int cnt = 0;
-	for (EdgeIt e = next_edge; e != INVALID; ++e) {
+      }
+      if (!(min < 0)) {
+	for (EdgeIt e(graph); e != next_edge; ++e) {
 	  if ((curr = state[e] * red_cost[e]) < min) {
 	    min = curr;
 	    min_edge = e;
@@ -595,23 +589,11 @@
 	    cnt = 0;
 	  }
 	}
-	if (!(min < 0)) {
-	  for (EdgeIt e(graph); e != next_edge; ++e) {
-	    if ((curr = state[e] * red_cost[e]) < min) {
-	      min = curr;
-	      min_edge = e;
-	    }
-	    if (++cnt == block_size) {
-	      if (min < 0) break;
-	      cnt = 0;
-	    }
-	  }
-	}
-	in_edge = min_edge;
-	if ((next_edge = ++min_edge) == INVALID)
-	  next_edge = EdgeIt(graph);
-	return min < 0;
       }
+      in_edge = min_edge;
+      if ((next_edge = ++min_edge) == INVALID)
+	next_edge = EdgeIt(graph);
+      return min < 0;
     }
 #endif
 
@@ -696,11 +678,13 @@
 	if ((curr = state[e] * red_cost[e]) < min / LOWER_DIV) {
 	  candidates.push_back(e);
 	  if (curr < min) min = curr;
-	  if (candidates.size() >= LIST_LENGTH) break;
+	  if (candidates.size() == LIST_LENGTH) break;
 	}
       }
       if (candidates.size() == 0) return false;
       sort(candidates.begin(), candidates.end(), sort_func);
+      in_edge = candidates.front();
+      candidates.pop_front();
       return true;
     }
 #endif
@@ -909,9 +893,8 @@
       }
 
 #ifdef _DEBUG_ITER_
-      t_iter.stop();
       std::cout << "Network Simplex algorithm finished. " << iter_num
-		<< " pivot iterations performed.";
+		<< " pivot iterations performed." << std::endl;
 #endif
 
       // Checking if the flow amount equals zero on all the



More information about the Lemon-commits mailing list