# HG changeset patch
# User Peter Kovacs
# Date 1282514892 -7200
# Node ID f6f2a3139f64df654e708aed8dc63185a3fbf10d
# Parent dca9eed2c375a0121a33e12412ae4be3e6dceed5
Improve arc mixing in NS and enable it by default (#391)
diff --git a/lemon/network_simplex.h b/lemon/network_simplex.h
--- a/lemon/network_simplex.h
+++ b/lemon/network_simplex.h
@@ -636,11 +636,13 @@
/// The constructor of the class.
///
/// \param graph The digraph the algorithm runs on.
- /// \param arc_mixing Indicate if the arcs have to be stored in a
+ /// \param arc_mixing Indicate if the arcs will 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) :
+ /// In general, it leads to similar performance as using the original
+ /// arc order, but it makes the algorithm more robust and for certain
+ /// problem instances, even significantly faster.
+ /// Therefore, it is enabled by default.
+ NetworkSimplex(const GR& graph, bool arc_mixing = true) :
_graph(graph), _node_id(graph), _arc_id(graph),
_arc_mixing(arc_mixing),
MAX(std::numeric_limits::max()),
@@ -930,7 +932,8 @@
}
if (_arc_mixing) {
// Store the arcs in a mixed order
- int k = std::max(int(std::sqrt(double(_arc_num))), 10);
+ int skip = int(std::sqrt(double(_arc_num * _arc_num) / _node_num));
+ int k = std::max(skip, 3);
int i = 0, j = 0;
for (ArcIt a(_graph); a != INVALID; ++a) {
_arc_id[a] = i;