gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Traits class + a named parameter for CapacityScaling (#180) to specify the heap used in internal Dijkstra computations.
0 1 0
default
1 file changed with 72 insertions and 10 deletions:
↑ Collapse diff ↑
Show white space 2 line context
... ...
@@ -33,2 +33,29 @@
33 33

	
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

	
34 61
  /// \addtogroup min_cost_flow_algs
... ...
@@ -59,3 +86,8 @@
59 86
  /// 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
61 93
  class CapacityScaling
... ...
@@ -64,6 +96,14 @@
64 96

	
97
    /// The type of the digraph
98
    typedef typename TR::Digraph Digraph;
65 99
    /// The type of the flow amounts, capacity bounds and supply values
66
    typedef V Value;
100
    typedef typename TR::Value Value;
67 101
    /// 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;
69 109

	
... ...
@@ -94,4 +134,2 @@
94 134

	
95
    typedef std::vector<Arc> ArcVector;
96
    typedef std::vector<Node> NodeVector;
97 135
    typedef std::vector<int> IntVector;
... ...
@@ -157,5 +195,2 @@
157 195
    {
158
      typedef RangeMap<int> HeapCrossRef;
159
      typedef BinHeap<Cost, HeapCrossRef> Heap;
160

	
161 196
    private:
... ...
@@ -184,3 +219,3 @@
184 219
      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);
186 221
        Heap heap(heap_cross_ref);
... ...
@@ -235,2 +270,28 @@
235 270

	
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

	
236 297
    /// \brief Constructor.
... ...
@@ -433,2 +494,3 @@
433 494
    /// \name Execution control
495
    /// The algorithm can be executed using \ref run().
434 496

	
... ...
@@ -749,3 +811,3 @@
749 811
    ProblemType startWithScaling() {
750
      // Process capacity scaling phases
812
      // Perform capacity scaling phases
751 813
      int s, t;
0 comments (0 inline)