gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Move the heaps to a separate group (#299)
0 6 0
default
6 files changed with 40 insertions and 19 deletions:
↑ Collapse diff ↑
Ignore white space 48 line context
... ...
@@ -205,69 +205,90 @@
205 205
The usage with class type algorithms is little bit harder. In this
206 206
case the function type map adaptors can not be used, because the
207 207
function map adaptors give back temporary objects.
208 208
\code
209 209
  Digraph graph;
210 210

	
211 211
  typedef Digraph::ArcMap<double> DoubleArcMap;
212 212
  DoubleArcMap length(graph);
213 213
  DoubleArcMap speed(graph);
214 214

	
215 215
  typedef DivMap<DoubleArcMap, DoubleArcMap> TimeMap;
216 216
  TimeMap time(length, speed);
217 217

	
218 218
  Dijkstra<Digraph, TimeMap> dijkstra(graph, time);
219 219
  dijkstra.run(source, target);
220 220
\endcode
221 221
We have a length map and a maximum speed map on the arcs of a digraph.
222 222
The minimum time to pass the arc can be calculated as the division of
223 223
the two maps which can be done implicitly with the \c DivMap template
224 224
class. We use the implicit minimum time map as the length map of the
225 225
\c Dijkstra algorithm.
226 226
*/
227 227

	
228 228
/**
229
@defgroup matrices Matrices
230
@ingroup datas
231
\brief Two dimensional data storages implemented in LEMON.
232

	
233
This group contains two dimensional data storages implemented in LEMON.
234
*/
235

	
236
/**
237 229
@defgroup paths Path Structures
238 230
@ingroup datas
239 231
\brief %Path structures implemented in LEMON.
240 232

	
241 233
This group contains the path structures implemented in LEMON.
242 234

	
243 235
LEMON provides flexible data structures to work with paths.
244 236
All of them have similar interfaces and they can be copied easily with
245 237
assignment operators and copy constructors. This makes it easy and
246 238
efficient to have e.g. the Dijkstra algorithm to store its result in
247 239
any kind of path structure.
248 240

	
249
\sa lemon::concepts::Path
241
\sa \ref concepts::Path "Path concept"
242
*/
243

	
244
/**
245
@defgroup heaps Heap Structures
246
@ingroup datas
247
\brief %Heap structures implemented in LEMON.
248

	
249
This group contains the heap structures implemented in LEMON.
250

	
251
LEMON provides several heap classes. They are efficient implementations
252
of the abstract data type \e priority \e queue. They store items with
253
specified values called \e priorities in such a way that finding and
254
removing the item with minimum priority are efficient.
255
The basic operations are adding and erasing items, changing the priority
256
of an item, etc.
257

	
258
Heaps are crucial in several algorithms, such as Dijkstra and Prim.
259
The heap implementations have the same interface, thus any of them can be
260
used easily in such algorithms.
261

	
262
\sa \ref concepts::Heap "Heap concept"
263
*/
264

	
265
/**
266
@defgroup matrices Matrices
267
@ingroup datas
268
\brief Two dimensional data storages implemented in LEMON.
269

	
270
This group contains two dimensional data storages implemented in LEMON.
250 271
*/
251 272

	
252 273
/**
253 274
@defgroup auxdat Auxiliary Data Structures
254 275
@ingroup datas
255 276
\brief Auxiliary data structures implemented in LEMON.
256 277

	
257 278
This group contains some data structures implemented in LEMON in
258 279
order to make it easier to implement combinatorial algorithms.
259 280
*/
260 281

	
261 282
/**
262 283
@defgroup algs Algorithms
263 284
\brief This group contains the several algorithms
264 285
implemented in LEMON.
265 286

	
266 287
This group contains the several algorithms
267 288
implemented in LEMON.
268 289
*/
269 290

	
270 291
/**
271 292
@defgroup search Graph Search
272 293
@ingroup algs
273 294
\brief Common graph search algorithms.
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5 5
 * Copyright (C) 2003-2009
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_BIN_HEAP_H
20 20
#define LEMON_BIN_HEAP_H
21 21

	
22
///\ingroup auxdat
22
///\ingroup heaps
23 23
///\file
24 24
///\brief Binary heap implementation.
25 25

	
26 26
#include <vector>
27 27
#include <utility>
28 28
#include <functional>
29 29

	
30 30
namespace lemon {
31 31

	
32
  /// \ingroup auxdat
32
  /// \ingroup heaps
33 33
  ///
34 34
  /// \brief Binary heap data structure.
35 35
  ///
36 36
  /// This class implements the \e binary \e heap data structure.
37 37
  /// It fully conforms to the \ref concepts::Heap "heap concept".
38 38
  ///
39 39
  /// \tparam PR Type of the priorities of the items.
40 40
  /// \tparam IM A read-writable item map with \c int values, used
41 41
  /// internally to handle the cross references.
42 42
  /// \tparam CMP A functor class for comparing the priorities.
43 43
  /// The default is \c std::less<PR>.
44 44
#ifdef DOXYGEN
45 45
  template <typename PR, typename IM, typename CMP>
46 46
#else
47 47
  template <typename PR, typename IM, typename CMP = std::less<PR> >
48 48
#endif
49 49
  class BinHeap {
50 50
  public:
51 51

	
52 52
    /// Type of the item-int map.
53 53
    typedef IM ItemIntMap;
54 54
    /// Type of the priorities.
55 55
    typedef PR Prio;
56 56
    /// Type of the items stored in the heap.
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5 5
 * Copyright (C) 2003-2009
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_BUCKET_HEAP_H
20 20
#define LEMON_BUCKET_HEAP_H
21 21

	
22
///\ingroup auxdat
22
///\ingroup heaps
23 23
///\file
24 24
///\brief Bucket heap implementation.
25 25

	
26 26
#include <vector>
27 27
#include <utility>
28 28
#include <functional>
29 29

	
30 30
namespace lemon {
31 31

	
32 32
  namespace _bucket_heap_bits {
33 33

	
34 34
    template <bool MIN>
35 35
    struct DirectionTraits {
36 36
      static bool less(int left, int right) {
37 37
        return left < right;
38 38
      }
39 39
      static void increase(int& value) {
40 40
        ++value;
41 41
      }
42 42
    };
43 43

	
44 44
    template <>
45 45
    struct DirectionTraits<false> {
46 46
      static bool less(int left, int right) {
47 47
        return left > right;
48 48
      }
49 49
      static void increase(int& value) {
50 50
        --value;
51 51
      }
52 52
    };
53 53

	
54 54
  }
55 55

	
56
  /// \ingroup auxdat
56
  /// \ingroup heaps
57 57
  ///
58 58
  /// \brief Bucket heap data structure.
59 59
  ///
60 60
  /// This class implements the \e bucket \e heap data structure.
61 61
  /// It practically conforms to the \ref concepts::Heap "heap concept",
62 62
  /// but it has some limitations.
63 63
  ///
64 64
  /// The bucket heap is a very simple structure. It can store only
65 65
  /// \c int priorities and it maintains a list of items for each priority
66 66
  /// in the range <tt>[0..C)</tt>. So it should only be used when the
67 67
  /// priorities are small. It is not intended to use as a Dijkstra heap.
68 68
  ///
69 69
  /// \tparam IM A read-writable item map with \c int values, used
70 70
  /// internally to handle the cross references.
71 71
  /// \tparam MIN Indicate if the heap is a \e min-heap or a \e max-heap.
72 72
  /// The default is \e min-heap. If this parameter is set to \c false,
73 73
  /// then the comparison is reversed, so the top(), prio() and pop()
74 74
  /// functions deal with the item having maximum priority instead of the
75 75
  /// minimum.
76 76
  ///
77 77
  /// \sa SimpleBucketHeap
78 78
  template <typename IM, bool MIN = true>
79 79
  class BucketHeap {
80 80

	
... ...
@@ -350,49 +350,49 @@
350 350
      case IN_HEAP:
351 351
        break;
352 352
      }
353 353
    }
354 354

	
355 355
  private:
356 356

	
357 357
    struct BucketItem {
358 358
      BucketItem(const Item& _item, int _value)
359 359
        : item(_item), value(_value) {}
360 360

	
361 361
      Item item;
362 362
      int value;
363 363

	
364 364
      int prev, next;
365 365
    };
366 366

	
367 367
    ItemIntMap& _iim;
368 368
    std::vector<int> _first;
369 369
    std::vector<BucketItem> _data;
370 370
    mutable int _minimum;
371 371

	
372 372
  }; // class BucketHeap
373 373

	
374
  /// \ingroup auxdat
374
  /// \ingroup heaps
375 375
  ///
376 376
  /// \brief Simplified bucket heap data structure.
377 377
  ///
378 378
  /// This class implements a simplified \e bucket \e heap data
379 379
  /// structure. It does not provide some functionality, but it is
380 380
  /// faster and simpler than BucketHeap. The main difference is
381 381
  /// that BucketHeap stores a doubly-linked list for each key while
382 382
  /// this class stores only simply-linked lists. It supports erasing
383 383
  /// only for the item having minimum priority and it does not support
384 384
  /// key increasing and decreasing.
385 385
  ///
386 386
  /// Note that this implementation does not conform to the
387 387
  /// \ref concepts::Heap "heap concept" due to the lack of some 
388 388
  /// functionality.
389 389
  ///
390 390
  /// \tparam IM A read-writable item map with \c int values, used
391 391
  /// internally to handle the cross references.
392 392
  /// \tparam MIN Indicate if the heap is a \e min-heap or a \e max-heap.
393 393
  /// The default is \e min-heap. If this parameter is set to \c false,
394 394
  /// then the comparison is reversed, so the top(), prio() and pop()
395 395
  /// functions deal with the item having maximum priority instead of the
396 396
  /// minimum.
397 397
  ///
398 398
  /// \sa BucketHeap
Ignore white space 6 line context
... ...
@@ -15,49 +15,49 @@
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_CONCEPTS_HEAP_H
20 20
#define LEMON_CONCEPTS_HEAP_H
21 21

	
22 22
///\ingroup concept
23 23
///\file
24 24
///\brief The concept of heaps.
25 25

	
26 26
#include <lemon/core.h>
27 27
#include <lemon/concept_check.h>
28 28

	
29 29
namespace lemon {
30 30

	
31 31
  namespace concepts {
32 32

	
33 33
    /// \addtogroup concept
34 34
    /// @{
35 35

	
36 36
    /// \brief The heap concept.
37 37
    ///
38 38
    /// This concept class describes the main interface of heaps.
39
    /// The various heap structures are efficient
39
    /// The various \ref heaps "heap structures" are efficient
40 40
    /// implementations of the abstract data type \e priority \e queue.
41 41
    /// They store items with specified values called \e priorities
42 42
    /// in such a way that finding and removing the item with minimum
43 43
    /// priority are efficient. The basic operations are adding and
44 44
    /// erasing items, changing the priority of an item, etc.
45 45
    ///
46 46
    /// Heaps are crucial in several algorithms, such as Dijkstra and Prim.
47 47
    /// Any class that conforms to this concept can be used easily in such
48 48
    /// algorithms.
49 49
    ///
50 50
    /// \tparam PR Type of the priorities of the items.
51 51
    /// \tparam IM A read-writable item map with \c int values, used
52 52
    /// internally to handle the cross references.
53 53
    /// \tparam CMP A functor class for comparing the priorities.
54 54
    /// The default is \c std::less<PR>.
55 55
#ifdef DOXYGEN
56 56
    template <typename PR, typename IM, typename CMP>
57 57
#else
58 58
    template <typename PR, typename IM, typename CMP = std::less<PR> >
59 59
#endif
60 60
    class Heap {
61 61
    public:
62 62

	
63 63
      /// Type of the item-int map.
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5 5
 * Copyright (C) 2003-2009
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_FIB_HEAP_H
20 20
#define LEMON_FIB_HEAP_H
21 21

	
22 22
///\file
23
///\ingroup auxdat
23
///\ingroup heaps
24 24
///\brief Fibonacci heap implementation.
25 25

	
26 26
#include <vector>
27 27
#include <utility>
28 28
#include <functional>
29 29
#include <lemon/math.h>
30 30

	
31 31
namespace lemon {
32 32

	
33
  /// \ingroup auxdat
33
  /// \ingroup heaps
34 34
  ///
35 35
  /// \brief Fibonacci heap data structure.
36 36
  ///
37 37
  /// This class implements the \e Fibonacci \e heap data structure.
38 38
  /// It fully conforms to the \ref concepts::Heap "heap concept".
39 39
  ///
40 40
  /// The methods \ref increase() and \ref erase() are not efficient in a
41 41
  /// Fibonacci heap. In case of many calls of these operations, it is
42 42
  /// better to use other heap structure, e.g. \ref BinHeap "binary heap".
43 43
  ///
44 44
  /// \tparam PR Type of the priorities of the items.
45 45
  /// \tparam IM A read-writable item map with \c int values, used
46 46
  /// internally to handle the cross references.
47 47
  /// \tparam CMP A functor class for comparing the priorities.
48 48
  /// The default is \c std::less<PR>.
49 49
#ifdef DOXYGEN
50 50
  template <typename PR, typename IM, typename CMP>
51 51
#else
52 52
  template <typename PR, typename IM, typename CMP = std::less<PR> >
53 53
#endif
54 54
  class FibHeap {
55 55
  public:
56 56

	
57 57
    /// Type of the item-int map.
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5 5
 * Copyright (C) 2003-2009
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_RADIX_HEAP_H
20 20
#define LEMON_RADIX_HEAP_H
21 21

	
22
///\ingroup auxdat
22
///\ingroup heaps
23 23
///\file
24 24
///\brief Radix heap implementation.
25 25

	
26 26
#include <vector>
27 27
#include <lemon/error.h>
28 28

	
29 29
namespace lemon {
30 30

	
31 31

	
32
  /// \ingroup auxdat
32
  /// \ingroup heaps
33 33
  ///
34 34
  /// \brief Radix heap data structure.
35 35
  ///
36 36
  /// This class implements the \e radix \e heap data structure.
37 37
  /// It practically conforms to the \ref concepts::Heap "heap concept",
38 38
  /// but it has some limitations due its special implementation.
39 39
  /// The type of the priorities must be \c int and the priority of an
40 40
  /// item cannot be decreased under the priority of the last removed item.
41 41
  ///
42 42
  /// \tparam IM A read-writable item map with \c int values, used
43 43
  /// internally to handle the cross references.
44 44
  template <typename IM>
45 45
  class RadixHeap {
46 46

	
47 47
  public:
48 48

	
49 49
    /// Type of the item-int map.
50 50
    typedef IM ItemIntMap;
51 51
    /// Type of the priorities.
52 52
    typedef int Prio;
53 53
    /// Type of the items stored in the heap.
54 54
    typedef typename ItemIntMap::Key Item;
55 55

	
56 56
    /// \brief Exception thrown by RadixHeap.
0 comments (0 inline)