COIN-OR::LEMON - Graph Library

Ticket #298: 298-arcmixing-e2bdd1a988f3.patch

File 298-arcmixing-e2bdd1a988f3.patch, 2.3 KB (added by Peter Kovacs, 15 years ago)

Slightly better version of [0a0cbbf56e23]

  • lemon/network_simplex.h

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1246548989 -7200
    # Node ID e2bdd1a988f3b91687c940bb8649738ec4de3c8a
    # Parent  cab85bd7859b6b89eee29e8db1619888a513e6a6
    Add a parameter to control arc mixing in NS (#298)
    
    diff --git a/lemon/network_simplex.h b/lemon/network_simplex.h
    a b  
    625625    /// The constructor of the class.
    626626    ///
    627627    /// \param graph The digraph the algorithm runs on.
    628     NetworkSimplex(const GR& graph) :
     628    /// \param arc_mixing Indicate if the arcs have to be stored in a
     629    /// mixed order in the internal data structure.
     630    /// In special cases, it could lead to better overall performance,
     631    /// but it is usually slower. Therefore it is disabled by default.
     632    NetworkSimplex(const GR& graph, bool arc_mixing = false) :
    629633      _graph(graph), _node_id(graph), _arc_id(graph),
    630634      INF(std::numeric_limits<Value>::has_infinity ?
    631635          std::numeric_limits<Value>::infinity() :
     
    663667      _last_succ.resize(all_node_num);
    664668      _state.resize(max_arc_num);
    665669
    666       // Copy the graph (store the arcs in a mixed order)
     670      // Copy the graph
    667671      int i = 0;
    668672      for (NodeIt n(_graph); n != INVALID; ++n, ++i) {
    669673        _node_id[n] = i;
    670674      }
    671       int k = std::max(int(std::sqrt(double(_arc_num))), 10);
    672       i = 0;
    673       for (ArcIt a(_graph); a != INVALID; ++a) {
    674         _arc_id[a] = i;
    675         _source[i] = _node_id[_graph.source(a)];
    676         _target[i] = _node_id[_graph.target(a)];
    677         if ((i += k) >= _arc_num) i = (i % k) + 1;
     675      if (arc_mixing) {
     676        // Store the arcs in a mixed order
     677        int k = std::max(int(std::sqrt(double(_arc_num))), 10);
     678        int i = 0, j = 0;
     679        for (ArcIt a(_graph); a != INVALID; ++a) {
     680          _arc_id[a] = i;
     681          _source[i] = _node_id[_graph.source(a)];
     682          _target[i] = _node_id[_graph.target(a)];
     683          if ((i += k) >= _arc_num) i = ++j;
     684        }
     685      } else {
     686        // Store the arcs in the original order
     687        int i = 0;
     688        for (ArcIt a(_graph); a != INVALID; ++a, ++i) {
     689          _arc_id[a] = i;
     690          _source[i] = _node_id[_graph.source(a)];
     691          _target[i] = _node_id[_graph.target(a)];
     692        }
    678693      }
    679694     
    680695      // Initialize maps