COIN-OR::LEMON - Graph Library

Ticket #180: 180-cas6-2ee24622f87b.patch

File 180-cas6-2ee24622f87b.patch, 5.4 KB (added by Peter Kovacs, 15 years ago)
  • lemon/capacity_scaling.h

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1253038155 -7200
    # Node ID 2ee24622f87bf4841af1f46c650a34c8417a1882
    # Parent  50d28aa826bb5e2196c8522ed54269c3c92cab06
    Traits class + named parameter for CapacityScaling (#180)
    to specify the heap used in internal Dijkstra computations.
    
    diff --git a/lemon/capacity_scaling.h b/lemon/capacity_scaling.h
    a b  
    3131
    3232namespace lemon {
    3333
     34  /// \brief Default traits class of CapacityScaling algorithm.
     35  ///
     36  /// Default traits class of CapacityScaling algorithm.
     37  /// \tparam GR Digraph type.
     38  /// \tparam V The value type used for flow amounts, capacity bounds
     39  /// and supply values. By default it is \c int.
     40  /// \tparam C The value type used for costs and potentials.
     41  /// By default it is the same as \c V.
     42  template <typename GR, typename V = int, typename C = V>
     43  struct CapacityScalingDefaultTraits
     44  {
     45    /// The type of the digraph
     46    typedef GR Digraph;
     47    /// The type of the flow amounts, capacity bounds and supply values
     48    typedef V Value;
     49    /// The type of the arc costs
     50    typedef C Cost;
     51
     52    /// \brief The type of the heap used for internal Dijkstra computations.
     53    ///
     54    /// The type of the heap used for internal Dijkstra computations.
     55    /// It must conform to the \ref lemon::concepts::Heap "Heap" concept,
     56    /// its priority type must be \c Cost and its cross reference type
     57    /// must be \ref RangeMap "RangeMap<int>".
     58    typedef BinHeap<Cost, RangeMap<int> > Heap;
     59  };
     60
    3461  /// \addtogroup min_cost_flow_algs
    3562  /// @{
    3663
     
    5784  /// be integer.
    5885  /// \warning This algorithm does not support negative costs for such
    5986  /// arcs that have infinite upper bound.
    60   template <typename GR, typename V = int, typename C = V>
     87#ifdef DOXYGEN
     88  template <typename GR, typename V, typename C, typename TR>
     89#else
     90  template < typename GR, typename V = int, typename C = V,
     91             typename TR = CapacityScalingDefaultTraits<GR, V, C> >
     92#endif
    6193  class CapacityScaling
    6294  {
    6395  public:
    6496
     97    /// The type of the digraph
     98    typedef typename TR::Digraph Digraph;
    6599    /// The type of the flow amounts, capacity bounds and supply values
    66     typedef V Value;
     100    typedef typename TR::Value Value;
    67101    /// The type of the arc costs
    68     typedef C Cost;
     102    typedef typename TR::Cost Cost;
     103
     104    /// The type of the heap used for internal Dijkstra computations
     105    typedef typename TR::Heap Heap;
     106
     107    /// The \ref CapacityScalingDefaultTraits "traits class" of the algorithm
     108    typedef TR Traits;
    69109
    70110  public:
    71111
     
    92132
    93133    TEMPLATE_DIGRAPH_TYPEDEFS(GR);
    94134
    95     typedef std::vector<Arc> ArcVector;
    96     typedef std::vector<Node> NodeVector;
    97135    typedef std::vector<int> IntVector;
    98136    typedef std::vector<bool> BoolVector;
    99137    typedef std::vector<Value> ValueVector;
     
    155193    // potentials according to the found distance labels.
    156194    class ResidualDijkstra
    157195    {
    158       typedef RangeMap<int> HeapCrossRef;
    159       typedef BinHeap<Cost, HeapCrossRef> Heap;
    160 
    161196    private:
    162197
    163198      int _node_num;
     
    182217      {}
    183218
    184219      int run(int s, Value delta = 1) {
    185         HeapCrossRef heap_cross_ref(_node_num, Heap::PRE_HEAP);
     220        RangeMap<int> heap_cross_ref(_node_num, Heap::PRE_HEAP);
    186221        Heap heap(heap_cross_ref);
    187222        heap.push(s, 0);
    188223        _pred[s] = -1;
     
    233268
    234269  public:
    235270
     271    /// \name Named Template Parameters
     272    /// @{
     273
     274    template <typename T>
     275    struct SetHeapTraits : public Traits {
     276      typedef T Heap;
     277    };
     278
     279    /// \brief \ref named-templ-param "Named parameter" for setting
     280    /// \c Heap type.
     281    ///
     282    /// \ref named-templ-param "Named parameter" for setting \c Heap
     283    /// type, which is used for internal Dijkstra computations.
     284    /// It must conform to the \ref lemon::concepts::Heap "Heap" concept,
     285    /// its priority type must be \c Cost and its cross reference type
     286    /// must be \ref RangeMap "RangeMap<int>".
     287    template <typename T>
     288    struct SetHeap
     289      : public CapacityScaling<GR, V, C, SetHeapTraits<T> > {
     290      typedef  CapacityScaling<GR, V, C, SetHeapTraits<T> > Create;
     291    };
     292
     293    /// @}
     294
     295  public:
     296
    236297    /// \brief Constructor.
    237298    ///
    238299    /// The constructor of the class.
     
    431492    /// @}
    432493
    433494    /// \name Execution control
     495    /// The algorithm can be executed using \ref run().
    434496
    435497    /// @{
    436498
     
    747809
    748810    // Execute the capacity scaling algorithm
    749811    ProblemType startWithScaling() {
    750       // Process capacity scaling phases
     812      // Perform capacity scaling phases
    751813      int s, t;
    752814      int phase_cnt = 0;
    753815      int factor = 4;
  • test/min_cost_flow_test.cc

    diff --git a/test/min_cost_flow_test.cc b/test/min_cost_flow_test.cc
    a b  
    2727#include <lemon/capacity_scaling.h>
    2828
    2929#include <lemon/concepts/digraph.h>
     30#include <lemon/concepts/heap.h>
    3031#include <lemon/concept_check.h>
    3132
    3233#include "test_tools.h"
     
    287288                  CapacityScaling<GR, double> >();
    288289    checkConcept< McfClassConcept<GR, int, double>,
    289290                  CapacityScaling<GR, int, double> >();
     291    typedef CapacityScaling<GR>::
     292      SetHeap<concepts::Heap<int, RangeMap<int> > >::Create CAS;
     293    checkConcept< McfClassConcept<GR, int, int>, CAS >();
    290294  }
    291295
    292296  // Run various MCF tests