# HG changeset patch # User Peter Kovacs # Date 1246548989 -7200 # Node ID e2bdd1a988f3b91687c940bb8649738ec4de3c8a # Parent cab85bd7859b6b89eee29e8db1619888a513e6a6 Add a parameter to control arc mixing in NS (#298) diff -r cab85bd7859b -r e2bdd1a988f3 lemon/network_simplex.h --- a/lemon/network_simplex.h Wed Jul 01 16:34:01 2009 +0200 +++ b/lemon/network_simplex.h Thu Jul 02 17:36:29 2009 +0200 @@ -625,7 +625,11 @@ /// The constructor of the class. /// /// \param graph The digraph the algorithm runs on. - NetworkSimplex(const GR& graph) : + /// \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) : _graph(graph), _node_id(graph), _arc_id(graph), INF(std::numeric_limits::has_infinity ? std::numeric_limits::infinity() : @@ -663,18 +667,29 @@ _last_succ.resize(all_node_num); _state.resize(max_arc_num); - // Copy the graph (store the arcs in a mixed order) + // Copy the graph int i = 0; for (NodeIt n(_graph); n != INVALID; ++n, ++i) { _node_id[n] = i; } - 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; + 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)]; + } } // Initialize maps