lemongraph 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +8 -0
  3. data/LICENSE +674 -0
  4. data/README.md +6 -0
  5. data/ext/lemon-1.3.1/AUTHORS +26 -0
  6. data/ext/lemon-1.3.1/CMakeLists.txt +371 -0
  7. data/ext/lemon-1.3.1/INSTALL +167 -0
  8. data/ext/lemon-1.3.1/LICENSE +32 -0
  9. data/ext/lemon-1.3.1/NEWS +337 -0
  10. data/ext/lemon-1.3.1/README +50 -0
  11. data/ext/lemon-1.3.1/cmake/FindCOIN.cmake +110 -0
  12. data/ext/lemon-1.3.1/cmake/FindGLPK.cmake +55 -0
  13. data/ext/lemon-1.3.1/cmake/FindGhostscript.cmake +10 -0
  14. data/ext/lemon-1.3.1/cmake/FindILOG.cmake +102 -0
  15. data/ext/lemon-1.3.1/cmake/FindSOPLEX.cmake +23 -0
  16. data/ext/lemon-1.3.1/cmake/LEMONConfig.cmake.in +13 -0
  17. data/ext/lemon-1.3.1/cmake/nsis/lemon.ico +0 -0
  18. data/ext/lemon-1.3.1/cmake/nsis/uninstall.ico +0 -0
  19. data/ext/lemon-1.3.1/cmake/version.cmake +1 -0
  20. data/ext/lemon-1.3.1/cmake/version.cmake.in +1 -0
  21. data/ext/lemon-1.3.1/contrib/CMakeLists.txt +19 -0
  22. data/ext/lemon-1.3.1/lemon/CMakeLists.txt +91 -0
  23. data/ext/lemon-1.3.1/lemon/adaptors.h +3638 -0
  24. data/ext/lemon-1.3.1/lemon/arg_parser.cc +474 -0
  25. data/ext/lemon-1.3.1/lemon/arg_parser.h +440 -0
  26. data/ext/lemon-1.3.1/lemon/assert.h +214 -0
  27. data/ext/lemon-1.3.1/lemon/base.cc +37 -0
  28. data/ext/lemon-1.3.1/lemon/bellman_ford.h +1116 -0
  29. data/ext/lemon-1.3.1/lemon/bfs.h +1754 -0
  30. data/ext/lemon-1.3.1/lemon/bin_heap.h +347 -0
  31. data/ext/lemon-1.3.1/lemon/binomial_heap.h +445 -0
  32. data/ext/lemon-1.3.1/lemon/bits/alteration_notifier.h +472 -0
  33. data/ext/lemon-1.3.1/lemon/bits/array_map.h +351 -0
  34. data/ext/lemon-1.3.1/lemon/bits/bezier.h +174 -0
  35. data/ext/lemon-1.3.1/lemon/bits/default_map.h +182 -0
  36. data/ext/lemon-1.3.1/lemon/bits/edge_set_extender.h +627 -0
  37. data/ext/lemon-1.3.1/lemon/bits/enable_if.h +131 -0
  38. data/ext/lemon-1.3.1/lemon/bits/graph_adaptor_extender.h +401 -0
  39. data/ext/lemon-1.3.1/lemon/bits/graph_extender.h +1332 -0
  40. data/ext/lemon-1.3.1/lemon/bits/lock.h +65 -0
  41. data/ext/lemon-1.3.1/lemon/bits/map_extender.h +332 -0
  42. data/ext/lemon-1.3.1/lemon/bits/path_dump.h +177 -0
  43. data/ext/lemon-1.3.1/lemon/bits/solver_bits.h +194 -0
  44. data/ext/lemon-1.3.1/lemon/bits/traits.h +388 -0
  45. data/ext/lemon-1.3.1/lemon/bits/variant.h +494 -0
  46. data/ext/lemon-1.3.1/lemon/bits/vector_map.h +244 -0
  47. data/ext/lemon-1.3.1/lemon/bits/windows.cc +166 -0
  48. data/ext/lemon-1.3.1/lemon/bits/windows.h +44 -0
  49. data/ext/lemon-1.3.1/lemon/bucket_heap.h +594 -0
  50. data/ext/lemon-1.3.1/lemon/capacity_scaling.h +1014 -0
  51. data/ext/lemon-1.3.1/lemon/cbc.cc +460 -0
  52. data/ext/lemon-1.3.1/lemon/cbc.h +129 -0
  53. data/ext/lemon-1.3.1/lemon/christofides_tsp.h +254 -0
  54. data/ext/lemon-1.3.1/lemon/circulation.h +807 -0
  55. data/ext/lemon-1.3.1/lemon/clp.cc +464 -0
  56. data/ext/lemon-1.3.1/lemon/clp.h +164 -0
  57. data/ext/lemon-1.3.1/lemon/color.cc +44 -0
  58. data/ext/lemon-1.3.1/lemon/color.h +204 -0
  59. data/ext/lemon-1.3.1/lemon/concept_check.h +77 -0
  60. data/ext/lemon-1.3.1/lemon/concepts/bpgraph.h +1029 -0
  61. data/ext/lemon-1.3.1/lemon/concepts/digraph.h +491 -0
  62. data/ext/lemon-1.3.1/lemon/concepts/graph.h +788 -0
  63. data/ext/lemon-1.3.1/lemon/concepts/graph_components.h +2134 -0
  64. data/ext/lemon-1.3.1/lemon/concepts/heap.h +324 -0
  65. data/ext/lemon-1.3.1/lemon/concepts/maps.h +223 -0
  66. data/ext/lemon-1.3.1/lemon/concepts/path.h +312 -0
  67. data/ext/lemon-1.3.1/lemon/config.h.in +22 -0
  68. data/ext/lemon-1.3.1/lemon/connectivity.h +1688 -0
  69. data/ext/lemon-1.3.1/lemon/core.h +2506 -0
  70. data/ext/lemon-1.3.1/lemon/cost_scaling.h +1607 -0
  71. data/ext/lemon-1.3.1/lemon/counter.h +249 -0
  72. data/ext/lemon-1.3.1/lemon/cplex.cc +994 -0
  73. data/ext/lemon-1.3.1/lemon/cplex.h +292 -0
  74. data/ext/lemon-1.3.1/lemon/cycle_canceling.h +1230 -0
  75. data/ext/lemon-1.3.1/lemon/dfs.h +1637 -0
  76. data/ext/lemon-1.3.1/lemon/dheap.h +352 -0
  77. data/ext/lemon-1.3.1/lemon/dijkstra.h +1303 -0
  78. data/ext/lemon-1.3.1/lemon/dim2.h +726 -0
  79. data/ext/lemon-1.3.1/lemon/dimacs.h +448 -0
  80. data/ext/lemon-1.3.1/lemon/edge_set.h +1420 -0
  81. data/ext/lemon-1.3.1/lemon/edmonds_karp.h +556 -0
  82. data/ext/lemon-1.3.1/lemon/elevator.h +982 -0
  83. data/ext/lemon-1.3.1/lemon/error.h +276 -0
  84. data/ext/lemon-1.3.1/lemon/euler.h +287 -0
  85. data/ext/lemon-1.3.1/lemon/fib_heap.h +475 -0
  86. data/ext/lemon-1.3.1/lemon/fractional_matching.h +2139 -0
  87. data/ext/lemon-1.3.1/lemon/full_graph.h +1082 -0
  88. data/ext/lemon-1.3.1/lemon/glpk.cc +1012 -0
  89. data/ext/lemon-1.3.1/lemon/glpk.h +263 -0
  90. data/ext/lemon-1.3.1/lemon/gomory_hu.h +568 -0
  91. data/ext/lemon-1.3.1/lemon/graph_to_eps.h +1186 -0
  92. data/ext/lemon-1.3.1/lemon/greedy_tsp.h +251 -0
  93. data/ext/lemon-1.3.1/lemon/grid_graph.h +699 -0
  94. data/ext/lemon-1.3.1/lemon/grosso_locatelli_pullan_mc.h +840 -0
  95. data/ext/lemon-1.3.1/lemon/hao_orlin.h +1015 -0
  96. data/ext/lemon-1.3.1/lemon/hartmann_orlin_mmc.h +654 -0
  97. data/ext/lemon-1.3.1/lemon/howard_mmc.h +651 -0
  98. data/ext/lemon-1.3.1/lemon/hypercube_graph.h +459 -0
  99. data/ext/lemon-1.3.1/lemon/insertion_tsp.h +533 -0
  100. data/ext/lemon-1.3.1/lemon/karp_mmc.h +590 -0
  101. data/ext/lemon-1.3.1/lemon/kruskal.h +324 -0
  102. data/ext/lemon-1.3.1/lemon/lemon.pc.in +10 -0
  103. data/ext/lemon-1.3.1/lemon/lgf_reader.h +3854 -0
  104. data/ext/lemon-1.3.1/lemon/lgf_writer.h +2687 -0
  105. data/ext/lemon-1.3.1/lemon/list_graph.h +2510 -0
  106. data/ext/lemon-1.3.1/lemon/lp.h +95 -0
  107. data/ext/lemon-1.3.1/lemon/lp_base.cc +30 -0
  108. data/ext/lemon-1.3.1/lemon/lp_base.h +2147 -0
  109. data/ext/lemon-1.3.1/lemon/lp_skeleton.cc +143 -0
  110. data/ext/lemon-1.3.1/lemon/lp_skeleton.h +234 -0
  111. data/ext/lemon-1.3.1/lemon/maps.h +4057 -0
  112. data/ext/lemon-1.3.1/lemon/matching.h +3505 -0
  113. data/ext/lemon-1.3.1/lemon/math.h +77 -0
  114. data/ext/lemon-1.3.1/lemon/max_cardinality_search.h +794 -0
  115. data/ext/lemon-1.3.1/lemon/min_cost_arborescence.h +808 -0
  116. data/ext/lemon-1.3.1/lemon/nagamochi_ibaraki.h +702 -0
  117. data/ext/lemon-1.3.1/lemon/nauty_reader.h +113 -0
  118. data/ext/lemon-1.3.1/lemon/nearest_neighbor_tsp.h +238 -0
  119. data/ext/lemon-1.3.1/lemon/network_simplex.h +1659 -0
  120. data/ext/lemon-1.3.1/lemon/opt2_tsp.h +367 -0
  121. data/ext/lemon-1.3.1/lemon/pairing_heap.h +474 -0
  122. data/ext/lemon-1.3.1/lemon/path.h +1164 -0
  123. data/ext/lemon-1.3.1/lemon/planarity.h +2754 -0
  124. data/ext/lemon-1.3.1/lemon/preflow.h +985 -0
  125. data/ext/lemon-1.3.1/lemon/quad_heap.h +343 -0
  126. data/ext/lemon-1.3.1/lemon/radix_heap.h +438 -0
  127. data/ext/lemon-1.3.1/lemon/radix_sort.h +487 -0
  128. data/ext/lemon-1.3.1/lemon/random.cc +29 -0
  129. data/ext/lemon-1.3.1/lemon/random.h +1005 -0
  130. data/ext/lemon-1.3.1/lemon/smart_graph.h +1344 -0
  131. data/ext/lemon-1.3.1/lemon/soplex.cc +465 -0
  132. data/ext/lemon-1.3.1/lemon/soplex.h +158 -0
  133. data/ext/lemon-1.3.1/lemon/static_graph.h +476 -0
  134. data/ext/lemon-1.3.1/lemon/suurballe.h +776 -0
  135. data/ext/lemon-1.3.1/lemon/time_measure.h +610 -0
  136. data/ext/lemon-1.3.1/lemon/tolerance.h +242 -0
  137. data/ext/lemon-1.3.1/lemon/unionfind.h +1824 -0
  138. data/ext/lemon-1.3.1/scripts/unify-sources.sh +390 -0
  139. data/ext/lemon-1.3.1/scripts/valgrind-wrapper.sh +22 -0
  140. data/ext/lemongraph/arc_map.cc +1007 -0
  141. data/ext/lemongraph/digraph.cc +282 -0
  142. data/ext/lemongraph/digraph_arc.cc +153 -0
  143. data/ext/lemongraph/digraph_node.cc +277 -0
  144. data/ext/lemongraph/edge_map.cc +770 -0
  145. data/ext/lemongraph/extconf.rb +53 -0
  146. data/ext/lemongraph/graph.cc +351 -0
  147. data/ext/lemongraph/graph_arc.cc +95 -0
  148. data/ext/lemongraph/graph_edge.cc +153 -0
  149. data/ext/lemongraph/graph_item.cc +76 -0
  150. data/ext/lemongraph/graph_node.cc +321 -0
  151. data/ext/lemongraph/lemongraph.cc +260 -0
  152. data/ext/lemongraph/lemongraph.hh +295 -0
  153. data/ext/lemongraph/lemongraph.map +6 -0
  154. data/ext/lemongraph/lemongraph_export.hh +31 -0
  155. data/ext/lemongraph/node_map.cc +1011 -0
  156. data/lemongraph.gemspec +176 -0
  157. data/lib/lemongraph/graphviz.rb +240 -0
  158. data/lib/lemongraph/version.rb +4 -0
  159. data/lib/lemongraph.rb +21 -0
  160. data/samples/lemondeps.rb +38 -0
  161. metadata +202 -0
@@ -0,0 +1,438 @@
1
+ /* -*- mode: C++; indent-tabs-mode: nil; -*-
2
+ *
3
+ * This file is a part of LEMON, a generic C++ optimization library.
4
+ *
5
+ * Copyright (C) 2003-2009
6
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
8
+ *
9
+ * Permission to use, modify and distribute this software is granted
10
+ * provided that this copyright notice appears in all copies. For
11
+ * precise terms see the accompanying LICENSE file.
12
+ *
13
+ * This software is provided "AS IS" with no warranty of any kind,
14
+ * express or implied, and with no claim as to its suitability for any
15
+ * purpose.
16
+ *
17
+ */
18
+
19
+ #ifndef LEMON_RADIX_HEAP_H
20
+ #define LEMON_RADIX_HEAP_H
21
+
22
+ ///\ingroup heaps
23
+ ///\file
24
+ ///\brief Radix heap implementation.
25
+
26
+ #include <vector>
27
+ #include <lemon/error.h>
28
+
29
+ namespace lemon {
30
+
31
+
32
+ /// \ingroup heaps
33
+ ///
34
+ /// \brief Radix heap data structure.
35
+ ///
36
+ /// This class implements the \e radix \e heap data structure.
37
+ /// It practically conforms to the \ref concepts::Heap "heap concept",
38
+ /// but it has some limitations due its special implementation.
39
+ /// The type of the priorities must be \c int and the priority of an
40
+ /// item cannot be decreased under the priority of the last removed item.
41
+ ///
42
+ /// \tparam IM A read-writable item map with \c int values, used
43
+ /// internally to handle the cross references.
44
+ template <typename IM>
45
+ class RadixHeap {
46
+
47
+ public:
48
+
49
+ /// Type of the item-int map.
50
+ typedef IM ItemIntMap;
51
+ /// Type of the priorities.
52
+ typedef int Prio;
53
+ /// Type of the items stored in the heap.
54
+ typedef typename ItemIntMap::Key Item;
55
+
56
+ /// \brief Exception thrown by RadixHeap.
57
+ ///
58
+ /// This exception is thrown when an item is inserted into a
59
+ /// RadixHeap with a priority smaller than the last erased one.
60
+ /// \see RadixHeap
61
+ class PriorityUnderflowError : public Exception {
62
+ public:
63
+ virtual const char* what() const throw() {
64
+ return "lemon::RadixHeap::PriorityUnderflowError";
65
+ }
66
+ };
67
+
68
+ /// \brief Type to represent the states of the items.
69
+ ///
70
+ /// Each item has a state associated to it. It can be "in heap",
71
+ /// "pre-heap" or "post-heap". The latter two are indifferent from the
72
+ /// heap's point of view, but may be useful to the user.
73
+ ///
74
+ /// The item-int map must be initialized in such way that it assigns
75
+ /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
76
+ enum State {
77
+ IN_HEAP = 0, ///< = 0.
78
+ PRE_HEAP = -1, ///< = -1.
79
+ POST_HEAP = -2 ///< = -2.
80
+ };
81
+
82
+ private:
83
+
84
+ struct RadixItem {
85
+ int prev, next, box;
86
+ Item item;
87
+ int prio;
88
+ RadixItem(Item _item, int _prio) : item(_item), prio(_prio) {}
89
+ };
90
+
91
+ struct RadixBox {
92
+ int first;
93
+ int min, size;
94
+ RadixBox(int _min, int _size) : first(-1), min(_min), size(_size) {}
95
+ };
96
+
97
+ std::vector<RadixItem> _data;
98
+ std::vector<RadixBox> _boxes;
99
+
100
+ ItemIntMap &_iim;
101
+
102
+ public:
103
+
104
+ /// \brief Constructor.
105
+ ///
106
+ /// Constructor.
107
+ /// \param map A map that assigns \c int values to the items.
108
+ /// It is used internally to handle the cross references.
109
+ /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
110
+ /// \param minimum The initial minimum value of the heap.
111
+ /// \param capacity The initial capacity of the heap.
112
+ RadixHeap(ItemIntMap &map, int minimum = 0, int capacity = 0)
113
+ : _iim(map)
114
+ {
115
+ _boxes.push_back(RadixBox(minimum, 1));
116
+ _boxes.push_back(RadixBox(minimum + 1, 1));
117
+ while (lower(_boxes.size() - 1, capacity + minimum - 1)) {
118
+ extend();
119
+ }
120
+ }
121
+
122
+ /// \brief The number of items stored in the heap.
123
+ ///
124
+ /// This function returns the number of items stored in the heap.
125
+ int size() const { return _data.size(); }
126
+
127
+ /// \brief Check if the heap is empty.
128
+ ///
129
+ /// This function returns \c true if the heap is empty.
130
+ bool empty() const { return _data.empty(); }
131
+
132
+ /// \brief Make the heap empty.
133
+ ///
134
+ /// This functon makes the heap empty.
135
+ /// It does not change the cross reference map. If you want to reuse
136
+ /// a heap that is not surely empty, you should first clear it and
137
+ /// then you should set the cross reference map to \c PRE_HEAP
138
+ /// for each item.
139
+ /// \param minimum The minimum value of the heap.
140
+ /// \param capacity The capacity of the heap.
141
+ void clear(int minimum = 0, int capacity = 0) {
142
+ _data.clear(); _boxes.clear();
143
+ _boxes.push_back(RadixBox(minimum, 1));
144
+ _boxes.push_back(RadixBox(minimum + 1, 1));
145
+ while (lower(_boxes.size() - 1, capacity + minimum - 1)) {
146
+ extend();
147
+ }
148
+ }
149
+
150
+ private:
151
+
152
+ bool upper(int box, Prio pr) {
153
+ return pr < _boxes[box].min;
154
+ }
155
+
156
+ bool lower(int box, Prio pr) {
157
+ return pr >= _boxes[box].min + _boxes[box].size;
158
+ }
159
+
160
+ // Remove item from the box list
161
+ void remove(int index) {
162
+ if (_data[index].prev >= 0) {
163
+ _data[_data[index].prev].next = _data[index].next;
164
+ } else {
165
+ _boxes[_data[index].box].first = _data[index].next;
166
+ }
167
+ if (_data[index].next >= 0) {
168
+ _data[_data[index].next].prev = _data[index].prev;
169
+ }
170
+ }
171
+
172
+ // Insert item into the box list
173
+ void insert(int box, int index) {
174
+ if (_boxes[box].first == -1) {
175
+ _boxes[box].first = index;
176
+ _data[index].next = _data[index].prev = -1;
177
+ } else {
178
+ _data[index].next = _boxes[box].first;
179
+ _data[_boxes[box].first].prev = index;
180
+ _data[index].prev = -1;
181
+ _boxes[box].first = index;
182
+ }
183
+ _data[index].box = box;
184
+ }
185
+
186
+ // Add a new box to the box list
187
+ void extend() {
188
+ int min = _boxes.back().min + _boxes.back().size;
189
+ int bs = 2 * _boxes.back().size;
190
+ _boxes.push_back(RadixBox(min, bs));
191
+ }
192
+
193
+ // Move an item up into the proper box.
194
+ void bubbleUp(int index) {
195
+ if (!lower(_data[index].box, _data[index].prio)) return;
196
+ remove(index);
197
+ int box = findUp(_data[index].box, _data[index].prio);
198
+ insert(box, index);
199
+ }
200
+
201
+ // Find up the proper box for the item with the given priority
202
+ int findUp(int start, int pr) {
203
+ while (lower(start, pr)) {
204
+ if (++start == int(_boxes.size())) {
205
+ extend();
206
+ }
207
+ }
208
+ return start;
209
+ }
210
+
211
+ // Move an item down into the proper box
212
+ void bubbleDown(int index) {
213
+ if (!upper(_data[index].box, _data[index].prio)) return;
214
+ remove(index);
215
+ int box = findDown(_data[index].box, _data[index].prio);
216
+ insert(box, index);
217
+ }
218
+
219
+ // Find down the proper box for the item with the given priority
220
+ int findDown(int start, int pr) {
221
+ while (upper(start, pr)) {
222
+ if (--start < 0) throw PriorityUnderflowError();
223
+ }
224
+ return start;
225
+ }
226
+
227
+ // Find the first non-empty box
228
+ int findFirst() {
229
+ int first = 0;
230
+ while (_boxes[first].first == -1) ++first;
231
+ return first;
232
+ }
233
+
234
+ // Gives back the minimum priority of the given box
235
+ int minValue(int box) {
236
+ int min = _data[_boxes[box].first].prio;
237
+ for (int k = _boxes[box].first; k != -1; k = _data[k].next) {
238
+ if (_data[k].prio < min) min = _data[k].prio;
239
+ }
240
+ return min;
241
+ }
242
+
243
+ // Rearrange the items of the heap and make the first box non-empty
244
+ void moveDown() {
245
+ int box = findFirst();
246
+ if (box == 0) return;
247
+ int min = minValue(box);
248
+ for (int i = 0; i <= box; ++i) {
249
+ _boxes[i].min = min;
250
+ min += _boxes[i].size;
251
+ }
252
+ int curr = _boxes[box].first, next;
253
+ while (curr != -1) {
254
+ next = _data[curr].next;
255
+ bubbleDown(curr);
256
+ curr = next;
257
+ }
258
+ }
259
+
260
+ void relocateLast(int index) {
261
+ if (index != int(_data.size()) - 1) {
262
+ _data[index] = _data.back();
263
+ if (_data[index].prev != -1) {
264
+ _data[_data[index].prev].next = index;
265
+ } else {
266
+ _boxes[_data[index].box].first = index;
267
+ }
268
+ if (_data[index].next != -1) {
269
+ _data[_data[index].next].prev = index;
270
+ }
271
+ _iim[_data[index].item] = index;
272
+ }
273
+ _data.pop_back();
274
+ }
275
+
276
+ public:
277
+
278
+ /// \brief Insert an item into the heap with the given priority.
279
+ ///
280
+ /// This function inserts the given item into the heap with the
281
+ /// given priority.
282
+ /// \param i The item to insert.
283
+ /// \param p The priority of the item.
284
+ /// \pre \e i must not be stored in the heap.
285
+ /// \warning This method may throw an \c UnderFlowPriorityException.
286
+ void push(const Item &i, const Prio &p) {
287
+ int n = _data.size();
288
+ _iim.set(i, n);
289
+ _data.push_back(RadixItem(i, p));
290
+ while (lower(_boxes.size() - 1, p)) {
291
+ extend();
292
+ }
293
+ int box = findDown(_boxes.size() - 1, p);
294
+ insert(box, n);
295
+ }
296
+
297
+ /// \brief Return the item having minimum priority.
298
+ ///
299
+ /// This function returns the item having minimum priority.
300
+ /// \pre The heap must be non-empty.
301
+ Item top() const {
302
+ const_cast<RadixHeap<ItemIntMap>&>(*this).moveDown();
303
+ return _data[_boxes[0].first].item;
304
+ }
305
+
306
+ /// \brief The minimum priority.
307
+ ///
308
+ /// This function returns the minimum priority.
309
+ /// \pre The heap must be non-empty.
310
+ Prio prio() const {
311
+ const_cast<RadixHeap<ItemIntMap>&>(*this).moveDown();
312
+ return _data[_boxes[0].first].prio;
313
+ }
314
+
315
+ /// \brief Remove the item having minimum priority.
316
+ ///
317
+ /// This function removes the item having minimum priority.
318
+ /// \pre The heap must be non-empty.
319
+ void pop() {
320
+ moveDown();
321
+ int index = _boxes[0].first;
322
+ _iim[_data[index].item] = POST_HEAP;
323
+ remove(index);
324
+ relocateLast(index);
325
+ }
326
+
327
+ /// \brief Remove the given item from the heap.
328
+ ///
329
+ /// This function removes the given item from the heap if it is
330
+ /// already stored.
331
+ /// \param i The item to delete.
332
+ /// \pre \e i must be in the heap.
333
+ void erase(const Item &i) {
334
+ int index = _iim[i];
335
+ _iim[i] = POST_HEAP;
336
+ remove(index);
337
+ relocateLast(index);
338
+ }
339
+
340
+ /// \brief The priority of the given item.
341
+ ///
342
+ /// This function returns the priority of the given item.
343
+ /// \param i The item.
344
+ /// \pre \e i must be in the heap.
345
+ Prio operator[](const Item &i) const {
346
+ int idx = _iim[i];
347
+ return _data[idx].prio;
348
+ }
349
+
350
+ /// \brief Set the priority of an item or insert it, if it is
351
+ /// not stored in the heap.
352
+ ///
353
+ /// This method sets the priority of the given item if it is
354
+ /// already stored in the heap. Otherwise it inserts the given
355
+ /// item into the heap with the given priority.
356
+ /// \param i The item.
357
+ /// \param p The priority.
358
+ /// \pre \e i must be in the heap.
359
+ /// \warning This method may throw an \c UnderFlowPriorityException.
360
+ void set(const Item &i, const Prio &p) {
361
+ int idx = _iim[i];
362
+ if( idx < 0 ) {
363
+ push(i, p);
364
+ }
365
+ else if( p >= _data[idx].prio ) {
366
+ _data[idx].prio = p;
367
+ bubbleUp(idx);
368
+ } else {
369
+ _data[idx].prio = p;
370
+ bubbleDown(idx);
371
+ }
372
+ }
373
+
374
+ /// \brief Decrease the priority of an item to the given value.
375
+ ///
376
+ /// This function decreases the priority of an item to the given value.
377
+ /// \param i The item.
378
+ /// \param p The priority.
379
+ /// \pre \e i must be stored in the heap with priority at least \e p.
380
+ /// \warning This method may throw an \c UnderFlowPriorityException.
381
+ void decrease(const Item &i, const Prio &p) {
382
+ int idx = _iim[i];
383
+ _data[idx].prio = p;
384
+ bubbleDown(idx);
385
+ }
386
+
387
+ /// \brief Increase the priority of an item to the given value.
388
+ ///
389
+ /// This function increases the priority of an item to the given value.
390
+ /// \param i The item.
391
+ /// \param p The priority.
392
+ /// \pre \e i must be stored in the heap with priority at most \e p.
393
+ void increase(const Item &i, const Prio &p) {
394
+ int idx = _iim[i];
395
+ _data[idx].prio = p;
396
+ bubbleUp(idx);
397
+ }
398
+
399
+ /// \brief Return the state of an item.
400
+ ///
401
+ /// This method returns \c PRE_HEAP if the given item has never
402
+ /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
403
+ /// and \c POST_HEAP otherwise.
404
+ /// In the latter case it is possible that the item will get back
405
+ /// to the heap again.
406
+ /// \param i The item.
407
+ State state(const Item &i) const {
408
+ int s = _iim[i];
409
+ if( s >= 0 ) s = 0;
410
+ return State(s);
411
+ }
412
+
413
+ /// \brief Set the state of an item in the heap.
414
+ ///
415
+ /// This function sets the state of the given item in the heap.
416
+ /// It can be used to manually clear the heap when it is important
417
+ /// to achive better time complexity.
418
+ /// \param i The item.
419
+ /// \param st The state. It should not be \c IN_HEAP.
420
+ void state(const Item& i, State st) {
421
+ switch (st) {
422
+ case POST_HEAP:
423
+ case PRE_HEAP:
424
+ if (state(i) == IN_HEAP) {
425
+ erase(i);
426
+ }
427
+ _iim[i] = st;
428
+ break;
429
+ case IN_HEAP:
430
+ break;
431
+ }
432
+ }
433
+
434
+ }; // class RadixHeap
435
+
436
+ } // namespace lemon
437
+
438
+ #endif // LEMON_RADIX_HEAP_H