COIN-OR::LEMON - Graph Library

Ignore:
Timestamp:
04/29/09 16:54:27 (10 years ago)
Author:
Peter Kovacs <kpeter@…>
Branch:
default
Phase:
public
Message:

Less map copying in NetworkSimplex? (#234)

  • The graph is copied in the constructor instead of the init() function. It must not be modified after the class is constructed.
  • The maps are copied once (instead of twice).
  • Remove FlowMap?, PotentialMap? typedefs and flowMap(), pontentialMap() setter functions.
  • flowMap() and potentialMap() query functions copy the values into the given map (reference) instead of returning a const reference to a previously constructed map.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/min_cost_flow_test.cc

    r687 r689  
    8585
    8686// Check the interface of an MCF algorithm
    87 template <typename GR, typename Flow, typename Cost>
     87template <typename GR, typename Value, typename Cost>
    8888class McfClassConcept
    8989{
     
    9696
    9797      MCF mcf(g);
     98      const MCF& const_mcf = mcf;
    9899
    99100      b = mcf.reset()
     
    103104             .supplyMap(sup)
    104105             .stSupply(n, n, k)
    105              .flowMap(flow)
    106              .potentialMap(pot)
    107106             .run();
    108      
    109       const MCF& const_mcf = mcf;
    110 
    111       const typename MCF::FlowMap &fm = const_mcf.flowMap();
    112       const typename MCF::PotentialMap &pm = const_mcf.potentialMap();
    113107
    114108      c = const_mcf.totalCost();
    115       double x = const_mcf.template totalCost<double>();
     109      x = const_mcf.template totalCost<double>();
    116110      v = const_mcf.flow(a);
    117111      c = const_mcf.potential(n);
    118      
    119       v = const_mcf.INF;
    120 
    121       ignore_unused_variable_warning(fm);
    122       ignore_unused_variable_warning(pm);
    123       ignore_unused_variable_warning(x);
     112      const_mcf.flowMap(fm);
     113      const_mcf.potentialMap(pm);
    124114    }
    125115
    126116    typedef typename GR::Node Node;
    127117    typedef typename GR::Arc Arc;
    128     typedef concepts::ReadMap<Node, Flow> NM;
    129     typedef concepts::ReadMap<Arc, Flow> FAM;
     118    typedef concepts::ReadMap<Node, Value> NM;
     119    typedef concepts::ReadMap<Arc, Value> VAM;
    130120    typedef concepts::ReadMap<Arc, Cost> CAM;
     121    typedef concepts::WriteMap<Arc, Value> FlowMap;
     122    typedef concepts::WriteMap<Node, Cost> PotMap;
    131123
    132124    const GR &g;
    133     const FAM &lower;
    134     const FAM &upper;
     125    const VAM &lower;
     126    const VAM &upper;
    135127    const CAM &cost;
    136128    const NM &sup;
    137129    const Node &n;
    138130    const Arc &a;
    139     const Flow &k;
    140     Flow v;
    141     Cost c;
     131    const Value &k;
     132    FlowMap fm;
     133    PotMap pm;
    142134    bool b;
    143 
    144     typename MCF::FlowMap &flow;
    145     typename MCF::PotentialMap &pot;
     135    double x;
     136    typename MCF::Value v;
     137    typename MCF::Cost c;
    146138  };
    147139
     
    222214  check(mcf_result == result, "Wrong result " + test_id);
    223215  if (optimal) {
    224     check(checkFlow(gr, lower, upper, supply, mcf.flowMap(), type),
     216    typename GR::template ArcMap<typename SM::Value> flow(gr);
     217    typename GR::template NodeMap<typename CM::Value> pi(gr);
     218    mcf.flowMap(flow);
     219    mcf.potentialMap(pi);
     220    check(checkFlow(gr, lower, upper, supply, flow, type),
    225221          "The flow is not feasible " + test_id);
    226222    check(mcf.totalCost() == total, "The flow is not optimal " + test_id);
    227     check(checkPotential(gr, lower, upper, cost, supply, mcf.flowMap(),
    228                          mcf.potentialMap()),
     223    check(checkPotential(gr, lower, upper, cost, supply, flow, pi),
    229224          "Wrong potentials " + test_id);
    230225  }
     
    235230  // Check the interfaces
    236231  {
    237     typedef int Flow;
    238     typedef int Cost;
    239232    typedef concepts::Digraph GR;
    240     checkConcept< McfClassConcept<GR, Flow, Cost>,
    241                   NetworkSimplex<GR, Flow, Cost> >();
     233    checkConcept< McfClassConcept<GR, int, int>,
     234                  NetworkSimplex<GR> >();
     235    checkConcept< McfClassConcept<GR, double, double>,
     236                  NetworkSimplex<GR, double> >();
     237    checkConcept< McfClassConcept<GR, int, double>,
     238                  NetworkSimplex<GR, int, double> >();
    242239  }
    243240
Note: See TracChangeset for help on using the changeset viewer.