0
73
18
1101
17
13
1
163
70
15
9
66
77
110
110
166
139
12
19
10
13
172
171
344
324
62
75
64
64
2
9
19
15
125
118
Changeset was too big and was cut off... Show full diff
1 |
%%%%% Defining LEMON %%%%% |
|
2 |
|
|
3 |
@misc{lemon, |
|
4 |
key = {LEMON}, |
|
5 |
title = {{LEMON} -- {L}ibrary for {E}fficient {M}odeling and |
|
6 |
{O}ptimization in {N}etworks}, |
|
7 |
howpublished = {\url{http://lemon.cs.elte.hu/}}, |
|
8 |
year = 2009 |
|
9 |
} |
|
10 |
|
|
11 |
@misc{egres, |
|
12 |
key = {EGRES}, |
|
13 |
title = {{EGRES} -- {E}gerv{\'a}ry {R}esearch {G}roup on |
|
14 |
{C}ombinatorial {O}ptimization}, |
|
15 |
url = {http://www.cs.elte.hu/egres/} |
|
16 |
} |
|
17 |
|
|
18 |
@misc{coinor, |
|
19 |
key = {COIN-OR}, |
|
20 |
title = {{COIN-OR} -- {C}omputational {I}nfrastructure for |
|
21 |
{O}perations {R}esearch}, |
|
22 |
url = {http://www.coin-or.org/} |
|
23 |
} |
|
24 |
|
|
25 |
|
|
26 |
%%%%% Other libraries %%%%%% |
|
27 |
|
|
28 |
@misc{boost, |
|
29 |
key = {Boost}, |
|
30 |
title = {{B}oost {C++} {L}ibraries}, |
|
31 |
url = {http://www.boost.org/} |
|
32 |
} |
|
33 |
|
|
34 |
@book{bglbook, |
|
35 |
author = {Jeremy G. Siek and Lee-Quan Lee and Andrew |
|
36 |
Lumsdaine}, |
|
37 |
title = {The Boost Graph Library: User Guide and Reference |
|
38 |
Manual}, |
|
39 |
publisher = {Addison-Wesley}, |
|
40 |
year = 2002 |
|
41 |
} |
|
42 |
|
|
43 |
@misc{leda, |
|
44 |
key = {LEDA}, |
|
45 |
title = {{LEDA} -- {L}ibrary of {E}fficient {D}ata {T}ypes and |
|
46 |
{A}lgorithms}, |
|
47 |
url = {http://www.algorithmic-solutions.com/} |
|
48 |
} |
|
49 |
|
|
50 |
@book{ledabook, |
|
51 |
author = {Kurt Mehlhorn and Stefan N{\"a}her}, |
|
52 |
title = {{LEDA}: {A} platform for combinatorial and geometric |
|
53 |
computing}, |
|
54 |
isbn = {0-521-56329-1}, |
|
55 |
publisher = {Cambridge University Press}, |
|
56 |
address = {New York, NY, USA}, |
|
57 |
year = 1999 |
|
58 |
} |
|
59 |
|
|
60 |
|
|
61 |
%%%%% Tools that LEMON depends on %%%%% |
|
62 |
|
|
63 |
@misc{cmake, |
|
64 |
key = {CMake}, |
|
65 |
title = {{CMake} -- {C}ross {P}latform {M}ake}, |
|
66 |
url = {http://www.cmake.org/} |
|
67 |
} |
|
68 |
|
|
69 |
@misc{doxygen, |
|
70 |
key = {Doxygen}, |
|
71 |
title = {{Doxygen} -- {S}ource code documentation generator |
|
72 |
tool}, |
|
73 |
url = {http://www.doxygen.org/} |
|
74 |
} |
|
75 |
|
|
76 |
|
|
77 |
%%%%% LP/MIP libraries %%%%% |
|
78 |
|
|
79 |
@misc{glpk, |
|
80 |
key = {GLPK}, |
|
81 |
title = {{GLPK} -- {GNU} {L}inear {P}rogramming {K}it}, |
|
82 |
url = {http://www.gnu.org/software/glpk/} |
|
83 |
} |
|
84 |
|
|
85 |
@misc{clp, |
|
86 |
key = {Clp}, |
|
87 |
title = {{Clp} -- {Coin-Or} {L}inear {P}rogramming}, |
|
88 |
url = {http://projects.coin-or.org/Clp/} |
|
89 |
} |
|
90 |
|
|
91 |
@misc{cbc, |
|
92 |
key = {Cbc}, |
|
93 |
title = {{Cbc} -- {Coin-Or} {B}ranch and {C}ut}, |
|
94 |
url = {http://projects.coin-or.org/Cbc/} |
|
95 |
} |
|
96 |
|
|
97 |
@misc{cplex, |
|
98 |
key = {CPLEX}, |
|
99 |
title = {{ILOG} {CPLEX}}, |
|
100 |
url = {http://www.ilog.com/} |
|
101 |
} |
|
102 |
|
|
103 |
@misc{soplex, |
|
104 |
key = {SoPlex}, |
|
105 |
title = {{SoPlex} -- {T}he {S}equential {O}bject-{O}riented |
|
106 |
{S}implex}, |
|
107 |
url = {http://soplex.zib.de/} |
|
108 |
} |
|
109 |
|
|
110 |
|
|
111 |
%%%%% General books %%%%% |
|
112 |
|
|
113 |
@book{amo93networkflows, |
|
114 |
author = {Ravindra K. Ahuja and Thomas L. Magnanti and James |
|
115 |
B. Orlin}, |
|
116 |
title = {Network Flows: Theory, Algorithms, and Applications}, |
|
117 |
publisher = {Prentice-Hall, Inc.}, |
|
118 |
year = 1993, |
|
119 |
month = feb, |
|
120 |
isbn = {978-0136175490} |
|
121 |
} |
|
122 |
|
|
123 |
@book{schrijver03combinatorial, |
|
124 |
author = {Alexander Schrijver}, |
|
125 |
title = {Combinatorial Optimization: Polyhedra and Efficiency}, |
|
126 |
publisher = {Springer-Verlag}, |
|
127 |
year = 2003, |
|
128 |
isbn = {978-3540443896} |
|
129 |
} |
|
130 |
|
|
131 |
@book{clrs01algorithms, |
|
132 |
author = {Thomas H. Cormen and Charles E. Leiserson and Ronald |
|
133 |
L. Rivest and Clifford Stein}, |
|
134 |
title = {Introduction to Algorithms}, |
|
135 |
publisher = {The MIT Press}, |
|
136 |
year = 2001, |
|
137 |
edition = {2nd} |
|
138 |
} |
|
139 |
|
|
140 |
@book{stroustrup00cpp, |
|
141 |
author = {Bjarne Stroustrup}, |
|
142 |
title = {The C++ Programming Language}, |
|
143 |
edition = {3rd}, |
|
144 |
publisher = {Addison-Wesley Professional}, |
|
145 |
isbn = 0201700735, |
|
146 |
month = {February}, |
|
147 |
year = 2000 |
|
148 |
} |
|
149 |
|
|
150 |
|
|
151 |
%%%%% Maximum flow algorithms %%%%% |
|
152 |
|
|
153 |
@article{edmondskarp72theoretical, |
|
154 |
author = {Jack Edmonds and Richard M. Karp}, |
|
155 |
title = {Theoretical improvements in algorithmic efficiency |
|
156 |
for network flow problems}, |
|
157 |
journal = {Journal of the ACM}, |
|
158 |
year = 1972, |
|
159 |
volume = 19, |
|
160 |
number = 2, |
|
161 |
pages = {248-264} |
|
162 |
} |
|
163 |
|
|
164 |
@article{goldberg88newapproach, |
|
165 |
author = {Andrew V. Goldberg and Robert E. Tarjan}, |
|
166 |
title = {A new approach to the maximum flow problem}, |
|
167 |
journal = {Journal of the ACM}, |
|
168 |
year = 1988, |
|
169 |
volume = 35, |
|
170 |
number = 4, |
|
171 |
pages = {921-940} |
|
172 |
} |
|
173 |
|
|
174 |
@article{dinic70algorithm, |
|
175 |
author = {E. A. Dinic}, |
|
176 |
title = {Algorithm for solution of a problem of maximum flow |
|
177 |
in a network with power estimation}, |
|
178 |
journal = {Soviet Math. Doklady}, |
|
179 |
year = 1970, |
|
180 |
volume = 11, |
|
181 |
pages = {1277-1280} |
|
182 |
} |
|
183 |
|
|
184 |
@article{goldberg08partial, |
|
185 |
author = {Andrew V. Goldberg}, |
|
186 |
title = {The Partial Augment-Relabel Algorithm for the |
|
187 |
Maximum Flow Problem}, |
|
188 |
journal = {16th Annual European Symposium on Algorithms}, |
|
189 |
year = 2008, |
|
190 |
pages = {466-477} |
|
191 |
} |
|
192 |
|
|
193 |
@article{sleator83dynamic, |
|
194 |
author = {Daniel D. Sleator and Robert E. Tarjan}, |
|
195 |
title = {A data structure for dynamic trees}, |
|
196 |
journal = {Journal of Computer and System Sciences}, |
|
197 |
year = 1983, |
|
198 |
volume = 26, |
|
199 |
number = 3, |
|
200 |
pages = {362-391} |
|
201 |
} |
|
202 |
|
|
203 |
|
|
204 |
%%%%% Minimum mean cycle algorithms %%%%% |
|
205 |
|
|
206 |
@article{karp78characterization, |
|
207 |
author = {Richard M. Karp}, |
|
208 |
title = {A characterization of the minimum cycle mean in a |
|
209 |
digraph}, |
|
210 |
journal = {Discrete Math.}, |
|
211 |
year = 1978, |
|
212 |
volume = 23, |
|
213 |
pages = {309-311} |
|
214 |
} |
|
215 |
|
|
216 |
@article{dasdan98minmeancycle, |
|
217 |
author = {Ali Dasdan and Rajesh K. Gupta}, |
|
218 |
title = {Faster Maximum and Minimum Mean Cycle Alogrithms for |
|
219 |
System Performance Analysis}, |
|
220 |
journal = {IEEE Transactions on Computer-Aided Design of |
|
221 |
Integrated Circuits and Systems}, |
|
222 |
year = 1998, |
|
223 |
volume = 17, |
|
224 |
number = 10, |
|
225 |
pages = {889-899} |
|
226 |
} |
|
227 |
|
|
228 |
|
|
229 |
%%%%% Minimum cost flow algorithms %%%%% |
|
230 |
|
|
231 |
@article{klein67primal, |
|
232 |
author = {Morton Klein}, |
|
233 |
title = {A primal method for minimal cost flows with |
|
234 |
applications to the assignment and transportation |
|
235 |
problems}, |
|
236 |
journal = {Management Science}, |
|
237 |
year = 1967, |
|
238 |
volume = 14, |
|
239 |
pages = {205-220} |
|
240 |
} |
|
241 |
|
|
242 |
@article{goldberg89cyclecanceling, |
|
243 |
author = {Andrew V. Goldberg and Robert E. Tarjan}, |
|
244 |
title = {Finding minimum-cost circulations by canceling |
|
245 |
negative cycles}, |
|
246 |
journal = {Journal of the ACM}, |
|
247 |
year = 1989, |
|
248 |
volume = 36, |
|
249 |
number = 4, |
|
250 |
pages = {873-886} |
|
251 |
} |
|
252 |
|
|
253 |
@article{goldberg90approximation, |
|
254 |
author = {Andrew V. Goldberg and Robert E. Tarjan}, |
|
255 |
title = {Finding Minimum-Cost Circulations by Successive |
|
256 |
Approximation}, |
|
257 |
journal = {Mathematics of Operations Research}, |
|
258 |
year = 1990, |
|
259 |
volume = 15, |
|
260 |
number = 3, |
|
261 |
pages = {430-466} |
|
262 |
} |
|
263 |
|
|
264 |
@article{goldberg97efficient, |
|
265 |
author = {Andrew V. Goldberg}, |
|
266 |
title = {An Efficient Implementation of a Scaling |
|
267 |
Minimum-Cost Flow Algorithm}, |
|
268 |
journal = {Journal of Algorithms}, |
|
269 |
year = 1997, |
|
270 |
volume = 22, |
|
271 |
number = 1, |
|
272 |
pages = {1-29} |
|
273 |
} |
|
274 |
|
|
275 |
@article{bunnagel98efficient, |
|
276 |
author = {Ursula B{\"u}nnagel and Bernhard Korte and Jens |
|
277 |
Vygen}, |
|
278 |
title = {Efficient implementation of the {G}oldberg-{T}arjan |
|
279 |
minimum-cost flow algorithm}, |
|
280 |
journal = {Optimization Methods and Software}, |
|
281 |
year = 1998, |
|
282 |
volume = 10, |
|
283 |
pages = {157-174} |
|
284 |
} |
|
285 |
|
|
286 |
@book{dantzig63linearprog, |
|
287 |
author = {George B. Dantzig}, |
|
288 |
title = {Linear Programming and Extensions}, |
|
289 |
publisher = {Princeton University Press}, |
|
290 |
year = 1963 |
|
291 |
} |
|
292 |
|
|
293 |
@mastersthesis{kellyoneill91netsimplex, |
|
294 |
author = {Damian J. Kelly and Garrett M. O'Neill}, |
|
295 |
title = {The Minimum Cost Flow Problem and The Network |
|
296 |
Simplex Method}, |
|
297 |
school = {University College}, |
|
298 |
address = {Dublin, Ireland}, |
|
299 |
year = 1991, |
|
300 |
month = sep, |
|
301 |
} |
1 |
/* -*- C++ -*- |
|
2 |
* |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
4 |
* |
|
5 |
* Copyright (C) 2003-2008 |
|
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_BELLMAN_FORD_H |
|
20 |
#define LEMON_BELLMAN_FORD_H |
|
21 |
|
|
22 |
/// \ingroup shortest_path |
|
23 |
/// \file |
|
24 |
/// \brief Bellman-Ford algorithm. |
|
25 |
|
|
26 |
#include <lemon/list_graph.h> |
|
27 |
#include <lemon/bits/path_dump.h> |
|
28 |
#include <lemon/core.h> |
|
29 |
#include <lemon/error.h> |
|
30 |
#include <lemon/maps.h> |
|
31 |
#include <lemon/path.h> |
|
32 |
|
|
33 |
#include <limits> |
|
34 |
|
|
35 |
namespace lemon { |
|
36 |
|
|
37 |
/// \brief Default OperationTraits for the BellmanFord algorithm class. |
|
38 |
/// |
|
39 |
/// This operation traits class defines all computational operations |
|
40 |
/// and constants that are used in the Bellman-Ford algorithm. |
|
41 |
/// The default implementation is based on the \c numeric_limits class. |
|
42 |
/// If the numeric type does not have infinity value, then the maximum |
|
43 |
/// value is used as extremal infinity value. |
|
44 |
template < |
|
45 |
typename V, |
|
46 |
bool has_inf = std::numeric_limits<V>::has_infinity> |
|
47 |
struct BellmanFordDefaultOperationTraits { |
|
48 |
/// \e |
|
49 |
typedef V Value; |
|
50 |
/// \brief Gives back the zero value of the type. |
|
51 |
static Value zero() { |
|
52 |
return static_cast<Value>(0); |
|
53 |
} |
|
54 |
/// \brief Gives back the positive infinity value of the type. |
|
55 |
static Value infinity() { |
|
56 |
return std::numeric_limits<Value>::infinity(); |
|
57 |
} |
|
58 |
/// \brief Gives back the sum of the given two elements. |
|
59 |
static Value plus(const Value& left, const Value& right) { |
|
60 |
return left + right; |
|
61 |
} |
|
62 |
/// \brief Gives back \c true only if the first value is less than |
|
63 |
/// the second. |
|
64 |
static bool less(const Value& left, const Value& right) { |
|
65 |
return left < right; |
|
66 |
} |
|
67 |
}; |
|
68 |
|
|
69 |
template <typename V> |
|
70 |
struct BellmanFordDefaultOperationTraits<V, false> { |
|
71 |
typedef V Value; |
|
72 |
static Value zero() { |
|
73 |
return static_cast<Value>(0); |
|
74 |
} |
|
75 |
static Value infinity() { |
|
76 |
return std::numeric_limits<Value>::max(); |
|
77 |
} |
|
78 |
static Value plus(const Value& left, const Value& right) { |
|
79 |
if (left == infinity() || right == infinity()) return infinity(); |
|
80 |
return left + right; |
|
81 |
} |
|
82 |
static bool less(const Value& left, const Value& right) { |
|
83 |
return left < right; |
|
84 |
} |
|
85 |
}; |
|
86 |
|
|
87 |
/// \brief Default traits class of BellmanFord class. |
|
88 |
/// |
|
89 |
/// Default traits class of BellmanFord class. |
|
90 |
/// \param GR The type of the digraph. |
|
91 |
/// \param LEN The type of the length map. |
|
92 |
template<typename GR, typename LEN> |
|
93 |
struct BellmanFordDefaultTraits { |
|
94 |
/// The type of the digraph the algorithm runs on. |
|
95 |
typedef GR Digraph; |
|
96 |
|
|
97 |
/// \brief The type of the map that stores the arc lengths. |
|
98 |
/// |
|
99 |
/// The type of the map that stores the arc lengths. |
|
100 |
/// It must conform to the \ref concepts::ReadMap "ReadMap" concept. |
|
101 |
typedef LEN LengthMap; |
|
102 |
|
|
103 |
/// The type of the arc lengths. |
|
104 |
typedef typename LEN::Value Value; |
|
105 |
|
|
106 |
/// \brief Operation traits for Bellman-Ford algorithm. |
|
107 |
/// |
|
108 |
/// It defines the used operations and the infinity value for the |
|
109 |
/// given \c Value type. |
|
110 |
/// \see BellmanFordDefaultOperationTraits |
|
111 |
typedef BellmanFordDefaultOperationTraits<Value> OperationTraits; |
|
112 |
|
|
113 |
/// \brief The type of the map that stores the last arcs of the |
|
114 |
/// shortest paths. |
|
115 |
/// |
|
116 |
/// The type of the map that stores the last |
|
117 |
/// arcs of the shortest paths. |
|
118 |
/// It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
119 |
typedef typename GR::template NodeMap<typename GR::Arc> PredMap; |
|
120 |
|
|
121 |
/// \brief Instantiates a \c PredMap. |
|
122 |
/// |
|
123 |
/// This function instantiates a \ref PredMap. |
|
124 |
/// \param g is the digraph to which we would like to define the |
|
125 |
/// \ref PredMap. |
|
126 |
static PredMap *createPredMap(const GR& g) { |
|
127 |
return new PredMap(g); |
|
128 |
} |
|
129 |
|
|
130 |
/// \brief The type of the map that stores the distances of the nodes. |
|
131 |
/// |
|
132 |
/// The type of the map that stores the distances of the nodes. |
|
133 |
/// It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
134 |
typedef typename GR::template NodeMap<typename LEN::Value> DistMap; |
|
135 |
|
|
136 |
/// \brief Instantiates a \c DistMap. |
|
137 |
/// |
|
138 |
/// This function instantiates a \ref DistMap. |
|
139 |
/// \param g is the digraph to which we would like to define the |
|
140 |
/// \ref DistMap. |
|
141 |
static DistMap *createDistMap(const GR& g) { |
|
142 |
return new DistMap(g); |
|
143 |
} |
|
144 |
|
|
145 |
}; |
|
146 |
|
|
147 |
/// \brief %BellmanFord algorithm class. |
|
148 |
/// |
|
149 |
/// \ingroup shortest_path |
|
150 |
/// This class provides an efficient implementation of the Bellman-Ford |
|
151 |
/// algorithm. The maximum time complexity of the algorithm is |
|
152 |
/// <tt>O(ne)</tt>. |
|
153 |
/// |
|
154 |
/// The Bellman-Ford algorithm solves the single-source shortest path |
|
155 |
/// problem when the arcs can have negative lengths, but the digraph |
|
156 |
/// should not contain directed cycles with negative total length. |
|
157 |
/// If all arc costs are non-negative, consider to use the Dijkstra |
|
158 |
/// algorithm instead, since it is more efficient. |
|
159 |
/// |
|
160 |
/// The arc lengths are passed to the algorithm using a |
|
161 |
/// \ref concepts::ReadMap "ReadMap", so it is easy to change it to any |
|
162 |
/// kind of length. The type of the length values is determined by the |
|
163 |
/// \ref concepts::ReadMap::Value "Value" type of the length map. |
|
164 |
/// |
|
165 |
/// There is also a \ref bellmanFord() "function-type interface" for the |
|
166 |
/// Bellman-Ford algorithm, which is convenient in the simplier cases and |
|
167 |
/// it can be used easier. |
|
168 |
/// |
|
169 |
/// \tparam GR The type of the digraph the algorithm runs on. |
|
170 |
/// The default type is \ref ListDigraph. |
|
171 |
/// \tparam LEN A \ref concepts::ReadMap "readable" arc map that specifies |
|
172 |
/// the lengths of the arcs. The default map type is |
|
173 |
/// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". |
|
174 |
#ifdef DOXYGEN |
|
175 |
template <typename GR, typename LEN, typename TR> |
|
176 |
#else |
|
177 |
template <typename GR=ListDigraph, |
|
178 |
typename LEN=typename GR::template ArcMap<int>, |
|
179 |
typename TR=BellmanFordDefaultTraits<GR,LEN> > |
|
180 |
#endif |
|
181 |
class BellmanFord { |
|
182 |
public: |
|
183 |
|
|
184 |
///The type of the underlying digraph. |
|
185 |
typedef typename TR::Digraph Digraph; |
|
186 |
|
|
187 |
/// \brief The type of the arc lengths. |
|
188 |
typedef typename TR::LengthMap::Value Value; |
|
189 |
/// \brief The type of the map that stores the arc lengths. |
|
190 |
typedef typename TR::LengthMap LengthMap; |
|
191 |
/// \brief The type of the map that stores the last |
|
192 |
/// arcs of the shortest paths. |
|
193 |
typedef typename TR::PredMap PredMap; |
|
194 |
/// \brief The type of the map that stores the distances of the nodes. |
|
195 |
typedef typename TR::DistMap DistMap; |
|
196 |
/// The type of the paths. |
|
197 |
typedef PredMapPath<Digraph, PredMap> Path; |
|
198 |
///\brief The \ref BellmanFordDefaultOperationTraits |
|
199 |
/// "operation traits class" of the algorithm. |
|
200 |
typedef typename TR::OperationTraits OperationTraits; |
|
201 |
|
|
202 |
///The \ref BellmanFordDefaultTraits "traits class" of the algorithm. |
|
203 |
typedef TR Traits; |
|
204 |
|
|
205 |
private: |
|
206 |
|
|
207 |
typedef typename Digraph::Node Node; |
|
208 |
typedef typename Digraph::NodeIt NodeIt; |
|
209 |
typedef typename Digraph::Arc Arc; |
|
210 |
typedef typename Digraph::OutArcIt OutArcIt; |
|
211 |
|
|
212 |
// Pointer to the underlying digraph. |
|
213 |
const Digraph *_gr; |
|
214 |
// Pointer to the length map |
|
215 |
const LengthMap *_length; |
|
216 |
// Pointer to the map of predecessors arcs. |
|
217 |
PredMap *_pred; |
|
218 |
// Indicates if _pred is locally allocated (true) or not. |
|
219 |
bool _local_pred; |
|
220 |
// Pointer to the map of distances. |
|
221 |
DistMap *_dist; |
|
222 |
// Indicates if _dist is locally allocated (true) or not. |
|
223 |
bool _local_dist; |
|
224 |
|
|
225 |
typedef typename Digraph::template NodeMap<bool> MaskMap; |
|
226 |
MaskMap *_mask; |
|
227 |
|
|
228 |
std::vector<Node> _process; |
|
229 |
|
|
230 |
// Creates the maps if necessary. |
|
231 |
void create_maps() { |
|
232 |
if(!_pred) { |
|
233 |
_local_pred = true; |
|
234 |
_pred = Traits::createPredMap(*_gr); |
|
235 |
} |
|
236 |
if(!_dist) { |
|
237 |
_local_dist = true; |
|
238 |
_dist = Traits::createDistMap(*_gr); |
|
239 |
} |
|
240 |
_mask = new MaskMap(*_gr, false); |
|
241 |
} |
|
242 |
|
|
243 |
public : |
|
244 |
|
|
245 |
typedef BellmanFord Create; |
|
246 |
|
|
247 |
/// \name Named Template Parameters |
|
248 |
|
|
249 |
///@{ |
|
250 |
|
|
251 |
template <class T> |
|
252 |
struct SetPredMapTraits : public Traits { |
|
253 |
typedef T PredMap; |
|
254 |
static PredMap *createPredMap(const Digraph&) { |
|
255 |
LEMON_ASSERT(false, "PredMap is not initialized"); |
|
256 |
return 0; // ignore warnings |
|
257 |
} |
|
258 |
}; |
|
259 |
|
|
260 |
/// \brief \ref named-templ-param "Named parameter" for setting |
|
261 |
/// \c PredMap type. |
|
262 |
/// |
|
263 |
/// \ref named-templ-param "Named parameter" for setting |
|
264 |
/// \c PredMap type. |
|
265 |
/// It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
266 |
template <class T> |
|
267 |
struct SetPredMap |
|
268 |
: public BellmanFord< Digraph, LengthMap, SetPredMapTraits<T> > { |
|
269 |
typedef BellmanFord< Digraph, LengthMap, SetPredMapTraits<T> > Create; |
|
270 |
}; |
|
271 |
|
|
272 |
template <class T> |
|
273 |
struct SetDistMapTraits : public Traits { |
|
274 |
typedef T DistMap; |
|
275 |
static DistMap *createDistMap(const Digraph&) { |
|
276 |
LEMON_ASSERT(false, "DistMap is not initialized"); |
|
277 |
return 0; // ignore warnings |
|
278 |
} |
|
279 |
}; |
|
280 |
|
|
281 |
/// \brief \ref named-templ-param "Named parameter" for setting |
|
282 |
/// \c DistMap type. |
|
283 |
/// |
|
284 |
/// \ref named-templ-param "Named parameter" for setting |
|
285 |
/// \c DistMap type. |
|
286 |
/// It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
287 |
template <class T> |
|
288 |
struct SetDistMap |
|
289 |
: public BellmanFord< Digraph, LengthMap, SetDistMapTraits<T> > { |
|
290 |
typedef BellmanFord< Digraph, LengthMap, SetDistMapTraits<T> > Create; |
|
291 |
}; |
|
292 |
|
|
293 |
template <class T> |
|
294 |
struct SetOperationTraitsTraits : public Traits { |
|
295 |
typedef T OperationTraits; |
|
296 |
}; |
|
297 |
|
|
298 |
/// \brief \ref named-templ-param "Named parameter" for setting |
|
299 |
/// \c OperationTraits type. |
|
300 |
/// |
|
301 |
/// \ref named-templ-param "Named parameter" for setting |
|
302 |
/// \c OperationTraits type. |
|
303 |
/// For more information, see \ref BellmanFordDefaultOperationTraits. |
|
304 |
template <class T> |
|
305 |
struct SetOperationTraits |
|
306 |
: public BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> > { |
|
307 |
typedef BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> > |
|
308 |
Create; |
|
309 |
}; |
|
310 |
|
|
311 |
///@} |
|
312 |
|
|
313 |
protected: |
|
314 |
|
|
315 |
BellmanFord() {} |
|
316 |
|
|
317 |
public: |
|
318 |
|
|
319 |
/// \brief Constructor. |
|
320 |
/// |
|
321 |
/// Constructor. |
|
322 |
/// \param g The digraph the algorithm runs on. |
|
323 |
/// \param length The length map used by the algorithm. |
|
324 |
BellmanFord(const Digraph& g, const LengthMap& length) : |
|
325 |
_gr(&g), _length(&length), |
|
326 |
_pred(0), _local_pred(false), |
|
327 |
_dist(0), _local_dist(false), _mask(0) {} |
|
328 |
|
|
329 |
///Destructor. |
|
330 |
~BellmanFord() { |
|
331 |
if(_local_pred) delete _pred; |
|
332 |
if(_local_dist) delete _dist; |
|
333 |
if(_mask) delete _mask; |
|
334 |
} |
|
335 |
|
|
336 |
/// \brief Sets the length map. |
|
337 |
/// |
|
338 |
/// Sets the length map. |
|
339 |
/// \return <tt>(*this)</tt> |
|
340 |
BellmanFord &lengthMap(const LengthMap &map) { |
|
341 |
_length = ↦ |
|
342 |
return *this; |
|
343 |
} |
|
344 |
|
|
345 |
/// \brief Sets the map that stores the predecessor arcs. |
|
346 |
/// |
|
347 |
/// Sets the map that stores the predecessor arcs. |
|
348 |
/// If you don't use this function before calling \ref run() |
|
349 |
/// or \ref init(), an instance will be allocated automatically. |
|
350 |
/// The destructor deallocates this automatically allocated map, |
|
351 |
/// of course. |
|
352 |
/// \return <tt>(*this)</tt> |
|
353 |
BellmanFord &predMap(PredMap &map) { |
|
354 |
if(_local_pred) { |
|
355 |
delete _pred; |
|
356 |
_local_pred=false; |
|
357 |
} |
|
358 |
_pred = ↦ |
|
359 |
return *this; |
|
360 |
} |
|
361 |
|
|
362 |
/// \brief Sets the map that stores the distances of the nodes. |
|
363 |
/// |
|
364 |
/// Sets the map that stores the distances of the nodes calculated |
|
365 |
/// by the algorithm. |
|
366 |
/// If you don't use this function before calling \ref run() |
|
367 |
/// or \ref init(), an instance will be allocated automatically. |
|
368 |
/// The destructor deallocates this automatically allocated map, |
|
369 |
/// of course. |
|
370 |
/// \return <tt>(*this)</tt> |
|
371 |
BellmanFord &distMap(DistMap &map) { |
|
372 |
if(_local_dist) { |
|
373 |
delete _dist; |
|
374 |
_local_dist=false; |
|
375 |
} |
|
376 |
_dist = ↦ |
|
377 |
return *this; |
|
378 |
} |
|
379 |
|
|
380 |
/// \name Execution Control |
|
381 |
/// The simplest way to execute the Bellman-Ford algorithm is to use |
|
382 |
/// one of the member functions called \ref run().\n |
|
383 |
/// If you need better control on the execution, you have to call |
|
384 |
/// \ref init() first, then you can add several source nodes |
|
385 |
/// with \ref addSource(). Finally the actual path computation can be |
|
386 |
/// performed with \ref start(), \ref checkedStart() or |
|
387 |
/// \ref limitedStart(). |
|
388 |
|
|
389 |
///@{ |
|
390 |
|
|
391 |
/// \brief Initializes the internal data structures. |
|
392 |
/// |
|
393 |
/// Initializes the internal data structures. The optional parameter |
|
394 |
/// is the initial distance of each node. |
|
395 |
void init(const Value value = OperationTraits::infinity()) { |
|
396 |
create_maps(); |
|
397 |
for (NodeIt it(*_gr); it != INVALID; ++it) { |
|
398 |
_pred->set(it, INVALID); |
|
399 |
_dist->set(it, value); |
|
400 |
} |
|
401 |
_process.clear(); |
|
402 |
if (OperationTraits::less(value, OperationTraits::infinity())) { |
|
403 |
for (NodeIt it(*_gr); it != INVALID; ++it) { |
|
404 |
_process.push_back(it); |
|
405 |
_mask->set(it, true); |
|
406 |
} |
|
407 |
} |
|
408 |
} |
|
409 |
|
|
410 |
/// \brief Adds a new source node. |
|
411 |
/// |
|
412 |
/// This function adds a new source node. The optional second parameter |
|
413 |
/// is the initial distance of the node. |
|
414 |
void addSource(Node source, Value dst = OperationTraits::zero()) { |
|
415 |
_dist->set(source, dst); |
|
416 |
if (!(*_mask)[source]) { |
|
417 |
_process.push_back(source); |
|
418 |
_mask->set(source, true); |
|
419 |
} |
|
420 |
} |
|
421 |
|
|
422 |
/// \brief Executes one round from the Bellman-Ford algorithm. |
|
423 |
/// |
|
424 |
/// If the algoritm calculated the distances in the previous round |
|
425 |
/// exactly for the paths of at most \c k arcs, then this function |
|
426 |
/// will calculate the distances exactly for the paths of at most |
|
427 |
/// <tt>k+1</tt> arcs. Performing \c k iterations using this function |
|
428 |
/// calculates the shortest path distances exactly for the paths |
|
429 |
/// consisting of at most \c k arcs. |
|
430 |
/// |
|
431 |
/// \warning The paths with limited arc number cannot be retrieved |
|
432 |
/// easily with \ref path() or \ref predArc() functions. If you also |
|
433 |
/// need the shortest paths and not only the distances, you should |
|
434 |
/// store the \ref predMap() "predecessor map" after each iteration |
|
435 |
/// and build the path manually. |
|
436 |
/// |
|
437 |
/// \return \c true when the algorithm have not found more shorter |
|
438 |
/// paths. |
|
439 |
/// |
|
440 |
/// \see ActiveIt |
|
441 |
bool processNextRound() { |
|
442 |
for (int i = 0; i < int(_process.size()); ++i) { |
|
443 |
_mask->set(_process[i], false); |
|
444 |
} |
|
445 |
std::vector<Node> nextProcess; |
|
446 |
std::vector<Value> values(_process.size()); |
|
447 |
for (int i = 0; i < int(_process.size()); ++i) { |
|
448 |
values[i] = (*_dist)[_process[i]]; |
|
449 |
} |
|
450 |
for (int i = 0; i < int(_process.size()); ++i) { |
|
451 |
for (OutArcIt it(*_gr, _process[i]); it != INVALID; ++it) { |
|
452 |
Node target = _gr->target(it); |
|
453 |
Value relaxed = OperationTraits::plus(values[i], (*_length)[it]); |
|
454 |
if (OperationTraits::less(relaxed, (*_dist)[target])) { |
|
455 |
_pred->set(target, it); |
|
456 |
_dist->set(target, relaxed); |
|
457 |
if (!(*_mask)[target]) { |
|
458 |
_mask->set(target, true); |
|
459 |
nextProcess.push_back(target); |
|
460 |
} |
|
461 |
} |
|
462 |
} |
|
463 |
} |
|
464 |
_process.swap(nextProcess); |
|
465 |
return _process.empty(); |
|
466 |
} |
|
467 |
|
|
468 |
/// \brief Executes one weak round from the Bellman-Ford algorithm. |
|
469 |
/// |
|
470 |
/// If the algorithm calculated the distances in the previous round |
|
471 |
/// at least for the paths of at most \c k arcs, then this function |
|
472 |
/// will calculate the distances at least for the paths of at most |
|
473 |
/// <tt>k+1</tt> arcs. |
|
474 |
/// This function does not make it possible to calculate the shortest |
|
475 |
/// path distances exactly for paths consisting of at most \c k arcs, |
|
476 |
/// this is why it is called weak round. |
|
477 |
/// |
|
478 |
/// \return \c true when the algorithm have not found more shorter |
|
479 |
/// paths. |
|
480 |
/// |
|
481 |
/// \see ActiveIt |
|
482 |
bool processNextWeakRound() { |
|
483 |
for (int i = 0; i < int(_process.size()); ++i) { |
|
484 |
_mask->set(_process[i], false); |
|
485 |
} |
|
486 |
std::vector<Node> nextProcess; |
|
487 |
for (int i = 0; i < int(_process.size()); ++i) { |
|
488 |
for (OutArcIt it(*_gr, _process[i]); it != INVALID; ++it) { |
|
489 |
Node target = _gr->target(it); |
|
490 |
Value relaxed = |
|
491 |
OperationTraits::plus((*_dist)[_process[i]], (*_length)[it]); |
|
492 |
if (OperationTraits::less(relaxed, (*_dist)[target])) { |
|
493 |
_pred->set(target, it); |
|
494 |
_dist->set(target, relaxed); |
|
495 |
if (!(*_mask)[target]) { |
|
496 |
_mask->set(target, true); |
|
497 |
nextProcess.push_back(target); |
|
498 |
} |
|
499 |
} |
|
500 |
} |
|
501 |
} |
|
502 |
_process.swap(nextProcess); |
|
503 |
return _process.empty(); |
|
504 |
} |
|
505 |
|
|
506 |
/// \brief Executes the algorithm. |
|
507 |
/// |
|
508 |
/// Executes the algorithm. |
|
509 |
/// |
|
510 |
/// This method runs the Bellman-Ford algorithm from the root node(s) |
|
511 |
/// in order to compute the shortest path to each node. |
|
512 |
/// |
|
513 |
/// The algorithm computes |
|
514 |
/// - the shortest path tree (forest), |
|
515 |
/// - the distance of each node from the root(s). |
|
516 |
/// |
|
517 |
/// \pre init() must be called and at least one root node should be |
|
518 |
/// added with addSource() before using this function. |
|
519 |
void start() { |
|
520 |
int num = countNodes(*_gr) - 1; |
|
521 |
for (int i = 0; i < num; ++i) { |
|
522 |
if (processNextWeakRound()) break; |
|
523 |
} |
|
524 |
} |
|
525 |
|
|
526 |
/// \brief Executes the algorithm and checks the negative cycles. |
|
527 |
/// |
|
528 |
/// Executes the algorithm and checks the negative cycles. |
|
529 |
/// |
|
530 |
/// This method runs the Bellman-Ford algorithm from the root node(s) |
|
531 |
/// in order to compute the shortest path to each node and also checks |
|
532 |
/// if the digraph contains cycles with negative total length. |
|
533 |
/// |
|
534 |
/// The algorithm computes |
|
535 |
/// - the shortest path tree (forest), |
|
536 |
/// - the distance of each node from the root(s). |
|
537 |
/// |
|
538 |
/// \return \c false if there is a negative cycle in the digraph. |
|
539 |
/// |
|
540 |
/// \pre init() must be called and at least one root node should be |
|
541 |
/// added with addSource() before using this function. |
|
542 |
bool checkedStart() { |
|
543 |
int num = countNodes(*_gr); |
|
544 |
for (int i = 0; i < num; ++i) { |
|
545 |
if (processNextWeakRound()) return true; |
|
546 |
} |
|
547 |
return _process.empty(); |
|
548 |
} |
|
549 |
|
|
550 |
/// \brief Executes the algorithm with arc number limit. |
|
551 |
/// |
|
552 |
/// Executes the algorithm with arc number limit. |
|
553 |
/// |
|
554 |
/// This method runs the Bellman-Ford algorithm from the root node(s) |
|
555 |
/// in order to compute the shortest path distance for each node |
|
556 |
/// using only the paths consisting of at most \c num arcs. |
|
557 |
/// |
|
558 |
/// The algorithm computes |
|
559 |
/// - the limited distance of each node from the root(s), |
|
560 |
/// - the predecessor arc for each node. |
|
561 |
/// |
|
562 |
/// \warning The paths with limited arc number cannot be retrieved |
|
563 |
/// easily with \ref path() or \ref predArc() functions. If you also |
|
564 |
/// need the shortest paths and not only the distances, you should |
|
565 |
/// store the \ref predMap() "predecessor map" after each iteration |
|
566 |
/// and build the path manually. |
|
567 |
/// |
|
568 |
/// \pre init() must be called and at least one root node should be |
|
569 |
/// added with addSource() before using this function. |
|
570 |
void limitedStart(int num) { |
|
571 |
for (int i = 0; i < num; ++i) { |
|
572 |
if (processNextRound()) break; |
|
573 |
} |
|
574 |
} |
|
575 |
|
|
576 |
/// \brief Runs the algorithm from the given root node. |
|
577 |
/// |
|
578 |
/// This method runs the Bellman-Ford algorithm from the given root |
|
579 |
/// node \c s in order to compute the shortest path to each node. |
|
580 |
/// |
|
581 |
/// The algorithm computes |
|
582 |
/// - the shortest path tree (forest), |
|
583 |
/// - the distance of each node from the root(s). |
|
584 |
/// |
|
585 |
/// \note bf.run(s) is just a shortcut of the following code. |
|
586 |
/// \code |
|
587 |
/// bf.init(); |
|
588 |
/// bf.addSource(s); |
|
589 |
/// bf.start(); |
|
590 |
/// \endcode |
|
591 |
void run(Node s) { |
|
592 |
init(); |
|
593 |
addSource(s); |
|
594 |
start(); |
|
595 |
} |
|
596 |
|
|
597 |
/// \brief Runs the algorithm from the given root node with arc |
|
598 |
/// number limit. |
|
599 |
/// |
|
600 |
/// This method runs the Bellman-Ford algorithm from the given root |
|
601 |
/// node \c s in order to compute the shortest path distance for each |
|
602 |
/// node using only the paths consisting of at most \c num arcs. |
|
603 |
/// |
|
604 |
/// The algorithm computes |
|
605 |
/// - the limited distance of each node from the root(s), |
|
606 |
/// - the predecessor arc for each node. |
|
607 |
/// |
|
608 |
/// \warning The paths with limited arc number cannot be retrieved |
|
609 |
/// easily with \ref path() or \ref predArc() functions. If you also |
|
610 |
/// need the shortest paths and not only the distances, you should |
|
611 |
/// store the \ref predMap() "predecessor map" after each iteration |
|
612 |
/// and build the path manually. |
|
613 |
/// |
|
614 |
/// \note bf.run(s, num) is just a shortcut of the following code. |
|
615 |
/// \code |
|
616 |
/// bf.init(); |
|
617 |
/// bf.addSource(s); |
|
618 |
/// bf.limitedStart(num); |
|
619 |
/// \endcode |
|
620 |
void run(Node s, int num) { |
|
621 |
init(); |
|
622 |
addSource(s); |
|
623 |
limitedStart(num); |
|
624 |
} |
|
625 |
|
|
626 |
///@} |
|
627 |
|
|
628 |
/// \brief LEMON iterator for getting the active nodes. |
|
629 |
/// |
|
630 |
/// This class provides a common style LEMON iterator that traverses |
|
631 |
/// the active nodes of the Bellman-Ford algorithm after the last |
|
632 |
/// phase. These nodes should be checked in the next phase to |
|
633 |
/// find augmenting arcs outgoing from them. |
|
634 |
class ActiveIt { |
|
635 |
public: |
|
636 |
|
|
637 |
/// \brief Constructor. |
|
638 |
/// |
|
639 |
/// Constructor for getting the active nodes of the given BellmanFord |
|
640 |
/// instance. |
|
641 |
ActiveIt(const BellmanFord& algorithm) : _algorithm(&algorithm) |
|
642 |
{ |
|
643 |
_index = _algorithm->_process.size() - 1; |
|
644 |
} |
|
645 |
|
|
646 |
/// \brief Invalid constructor. |
|
647 |
/// |
|
648 |
/// Invalid constructor. |
|
649 |
ActiveIt(Invalid) : _algorithm(0), _index(-1) {} |
|
650 |
|
|
651 |
/// \brief Conversion to \c Node. |
|
652 |
/// |
|
653 |
/// Conversion to \c Node. |
|
654 |
operator Node() const { |
|
655 |
return _index >= 0 ? _algorithm->_process[_index] : INVALID; |
|
656 |
} |
|
657 |
|
|
658 |
/// \brief Increment operator. |
|
659 |
/// |
|
660 |
/// Increment operator. |
|
661 |
ActiveIt& operator++() { |
|
662 |
--_index; |
|
663 |
return *this; |
|
664 |
} |
|
665 |
|
|
666 |
bool operator==(const ActiveIt& it) const { |
|
667 |
return static_cast<Node>(*this) == static_cast<Node>(it); |
|
668 |
} |
|
669 |
bool operator!=(const ActiveIt& it) const { |
|
670 |
return static_cast<Node>(*this) != static_cast<Node>(it); |
|
671 |
} |
|
672 |
bool operator<(const ActiveIt& it) const { |
|
673 |
return static_cast<Node>(*this) < static_cast<Node>(it); |
|
674 |
} |
|
675 |
|
|
676 |
private: |
|
677 |
const BellmanFord* _algorithm; |
|
678 |
int _index; |
|
679 |
}; |
|
680 |
|
|
681 |
/// \name Query Functions |
|
682 |
/// The result of the Bellman-Ford algorithm can be obtained using these |
|
683 |
/// functions.\n |
|
684 |
/// Either \ref run() or \ref init() should be called before using them. |
|
685 |
|
|
686 |
///@{ |
|
687 |
|
|
688 |
/// \brief The shortest path to the given node. |
|
689 |
/// |
|
690 |
/// Gives back the shortest path to the given node from the root(s). |
|
691 |
/// |
|
692 |
/// \warning \c t should be reached from the root(s). |
|
693 |
/// |
|
694 |
/// \pre Either \ref run() or \ref init() must be called before |
|
695 |
/// using this function. |
|
696 |
Path path(Node t) const |
|
697 |
{ |
|
698 |
return Path(*_gr, *_pred, t); |
|
699 |
} |
|
700 |
|
|
701 |
/// \brief The distance of the given node from the root(s). |
|
702 |
/// |
|
703 |
/// Returns the distance of the given node from the root(s). |
|
704 |
/// |
|
705 |
/// \warning If node \c v is not reached from the root(s), then |
|
706 |
/// the return value of this function is undefined. |
|
707 |
/// |
|
708 |
/// \pre Either \ref run() or \ref init() must be called before |
|
709 |
/// using this function. |
|
710 |
Value dist(Node v) const { return (*_dist)[v]; } |
|
711 |
|
|
712 |
/// \brief Returns the 'previous arc' of the shortest path tree for |
|
713 |
/// the given node. |
|
714 |
/// |
|
715 |
/// This function returns the 'previous arc' of the shortest path |
|
716 |
/// tree for node \c v, i.e. it returns the last arc of a |
|
717 |
/// shortest path from a root to \c v. It is \c INVALID if \c v |
|
718 |
/// is not reached from the root(s) or if \c v is a root. |
|
719 |
/// |
|
720 |
/// The shortest path tree used here is equal to the shortest path |
|
721 |
/// tree used in \ref predNode() and \ref predMap(). |
|
722 |
/// |
|
723 |
/// \pre Either \ref run() or \ref init() must be called before |
|
724 |
/// using this function. |
|
725 |
Arc predArc(Node v) const { return (*_pred)[v]; } |
|
726 |
|
|
727 |
/// \brief Returns the 'previous node' of the shortest path tree for |
|
728 |
/// the given node. |
|
729 |
/// |
|
730 |
/// This function returns the 'previous node' of the shortest path |
|
731 |
/// tree for node \c v, i.e. it returns the last but one node of |
|
732 |
/// a shortest path from a root to \c v. It is \c INVALID if \c v |
|
733 |
/// is not reached from the root(s) or if \c v is a root. |
|
734 |
/// |
|
735 |
/// The shortest path tree used here is equal to the shortest path |
|
736 |
/// tree used in \ref predArc() and \ref predMap(). |
|
737 |
/// |
|
738 |
/// \pre Either \ref run() or \ref init() must be called before |
|
739 |
/// using this function. |
|
740 |
Node predNode(Node v) const { |
|
741 |
return (*_pred)[v] == INVALID ? INVALID : _gr->source((*_pred)[v]); |
|
742 |
} |
|
743 |
|
|
744 |
/// \brief Returns a const reference to the node map that stores the |
|
745 |
/// distances of the nodes. |
|
746 |
/// |
|
747 |
/// Returns a const reference to the node map that stores the distances |
|
748 |
/// of the nodes calculated by the algorithm. |
|
749 |
/// |
|
750 |
/// \pre Either \ref run() or \ref init() must be called before |
|
751 |
/// using this function. |
|
752 |
const DistMap &distMap() const { return *_dist;} |
|
753 |
|
|
754 |
/// \brief Returns a const reference to the node map that stores the |
|
755 |
/// predecessor arcs. |
|
756 |
/// |
|
757 |
/// Returns a const reference to the node map that stores the predecessor |
|
758 |
/// arcs, which form the shortest path tree (forest). |
|
759 |
/// |
|
760 |
/// \pre Either \ref run() or \ref init() must be called before |
|
761 |
/// using this function. |
|
762 |
const PredMap &predMap() const { return *_pred; } |
|
763 |
|
|
764 |
/// \brief Checks if a node is reached from the root(s). |
|
765 |
/// |
|
766 |
/// Returns \c true if \c v is reached from the root(s). |
|
767 |
/// |
|
768 |
/// \pre Either \ref run() or \ref init() must be called before |
|
769 |
/// using this function. |
|
770 |
bool reached(Node v) const { |
|
771 |
return (*_dist)[v] != OperationTraits::infinity(); |
|
772 |
} |
|
773 |
|
|
774 |
/// \brief Gives back a negative cycle. |
|
775 |
/// |
|
776 |
/// This function gives back a directed cycle with negative total |
|
777 |
/// length if the algorithm has already found one. |
|
778 |
/// Otherwise it gives back an empty path. |
|
779 |
lemon::Path<Digraph> negativeCycle() const { |
|
780 |
typename Digraph::template NodeMap<int> state(*_gr, -1); |
|
781 |
lemon::Path<Digraph> cycle; |
|
782 |
for (int i = 0; i < int(_process.size()); ++i) { |
|
783 |
if (state[_process[i]] != -1) continue; |
|
784 |
for (Node v = _process[i]; (*_pred)[v] != INVALID; |
|
785 |
v = _gr->source((*_pred)[v])) { |
|
786 |
if (state[v] == i) { |
|
787 |
cycle.addFront((*_pred)[v]); |
|
788 |
for (Node u = _gr->source((*_pred)[v]); u != v; |
|
789 |
u = _gr->source((*_pred)[u])) { |
|
790 |
cycle.addFront((*_pred)[u]); |
|
791 |
} |
|
792 |
return cycle; |
|
793 |
} |
|
794 |
else if (state[v] >= 0) { |
|
795 |
break; |
|
796 |
} |
|
797 |
state[v] = i; |
|
798 |
} |
|
799 |
} |
|
800 |
return cycle; |
|
801 |
} |
|
802 |
|
|
803 |
///@} |
|
804 |
}; |
|
805 |
|
|
806 |
/// \brief Default traits class of bellmanFord() function. |
|
807 |
/// |
|
808 |
/// Default traits class of bellmanFord() function. |
|
809 |
/// \tparam GR The type of the digraph. |
|
810 |
/// \tparam LEN The type of the length map. |
|
811 |
template <typename GR, typename LEN> |
|
812 |
struct BellmanFordWizardDefaultTraits { |
|
813 |
/// The type of the digraph the algorithm runs on. |
|
814 |
typedef GR Digraph; |
|
815 |
|
|
816 |
/// \brief The type of the map that stores the arc lengths. |
|
817 |
/// |
|
818 |
/// The type of the map that stores the arc lengths. |
|
819 |
/// It must meet the \ref concepts::ReadMap "ReadMap" concept. |
|
820 |
typedef LEN LengthMap; |
|
821 |
|
|
822 |
/// The type of the arc lengths. |
|
823 |
typedef typename LEN::Value Value; |
|
824 |
|
|
825 |
/// \brief Operation traits for Bellman-Ford algorithm. |
|
826 |
/// |
|
827 |
/// It defines the used operations and the infinity value for the |
|
828 |
/// given \c Value type. |
|
829 |
/// \see BellmanFordDefaultOperationTraits |
|
830 |
typedef BellmanFordDefaultOperationTraits<Value> OperationTraits; |
|
831 |
|
|
832 |
/// \brief The type of the map that stores the last |
|
833 |
/// arcs of the shortest paths. |
|
834 |
/// |
|
835 |
/// The type of the map that stores the last arcs of the shortest paths. |
|
836 |
/// It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
837 |
typedef typename GR::template NodeMap<typename GR::Arc> PredMap; |
|
838 |
|
|
839 |
/// \brief Instantiates a \c PredMap. |
|
840 |
/// |
|
841 |
/// This function instantiates a \ref PredMap. |
|
842 |
/// \param g is the digraph to which we would like to define the |
|
843 |
/// \ref PredMap. |
|
844 |
static PredMap *createPredMap(const GR &g) { |
|
845 |
return new PredMap(g); |
|
846 |
} |
|
847 |
|
|
848 |
/// \brief The type of the map that stores the distances of the nodes. |
|
849 |
/// |
|
850 |
/// The type of the map that stores the distances of the nodes. |
|
851 |
/// It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
852 |
typedef typename GR::template NodeMap<Value> DistMap; |
|
853 |
|
|
854 |
/// \brief Instantiates a \c DistMap. |
|
855 |
/// |
|
856 |
/// This function instantiates a \ref DistMap. |
|
857 |
/// \param g is the digraph to which we would like to define the |
|
858 |
/// \ref DistMap. |
|
859 |
static DistMap *createDistMap(const GR &g) { |
|
860 |
return new DistMap(g); |
|
861 |
} |
|
862 |
|
|
863 |
///The type of the shortest paths. |
|
864 |
|
|
865 |
///The type of the shortest paths. |
|
866 |
///It must meet the \ref concepts::Path "Path" concept. |
|
867 |
typedef lemon::Path<Digraph> Path; |
|
868 |
}; |
|
869 |
|
|
870 |
/// \brief Default traits class used by BellmanFordWizard. |
|
871 |
/// |
|
872 |
/// Default traits class used by BellmanFordWizard. |
|
873 |
/// \tparam GR The type of the digraph. |
|
874 |
/// \tparam LEN The type of the length map. |
|
875 |
template <typename GR, typename LEN> |
|
876 |
class BellmanFordWizardBase |
|
877 |
: public BellmanFordWizardDefaultTraits<GR, LEN> { |
|
878 |
|
|
879 |
typedef BellmanFordWizardDefaultTraits<GR, LEN> Base; |
|
880 |
protected: |
|
881 |
// Type of the nodes in the digraph. |
|
882 |
typedef typename Base::Digraph::Node Node; |
|
883 |
|
|
884 |
// Pointer to the underlying digraph. |
|
885 |
void *_graph; |
|
886 |
// Pointer to the length map |
|
887 |
void *_length; |
|
888 |
// Pointer to the map of predecessors arcs. |
|
889 |
void *_pred; |
|
890 |
// Pointer to the map of distances. |
|
891 |
void *_dist; |
|
892 |
//Pointer to the shortest path to the target node. |
|
893 |
void *_path; |
|
894 |
//Pointer to the distance of the target node. |
|
895 |
void *_di; |
|
896 |
|
|
897 |
public: |
|
898 |
/// Constructor. |
|
899 |
|
|
900 |
/// This constructor does not require parameters, it initiates |
|
901 |
/// all of the attributes to default values \c 0. |
|
902 |
BellmanFordWizardBase() : |
|
903 |
_graph(0), _length(0), _pred(0), _dist(0), _path(0), _di(0) {} |
|
904 |
|
|
905 |
/// Constructor. |
|
906 |
|
|
907 |
/// This constructor requires two parameters, |
|
908 |
/// others are initiated to \c 0. |
|
909 |
/// \param gr The digraph the algorithm runs on. |
|
910 |
/// \param len The length map. |
|
911 |
BellmanFordWizardBase(const GR& gr, |
|
912 |
const LEN& len) : |
|
913 |
_graph(reinterpret_cast<void*>(const_cast<GR*>(&gr))), |
|
914 |
_length(reinterpret_cast<void*>(const_cast<LEN*>(&len))), |
|
915 |
_pred(0), _dist(0), _path(0), _di(0) {} |
|
916 |
|
|
917 |
}; |
|
918 |
|
|
919 |
/// \brief Auxiliary class for the function-type interface of the |
|
920 |
/// \ref BellmanFord "Bellman-Ford" algorithm. |
|
921 |
/// |
|
922 |
/// This auxiliary class is created to implement the |
|
923 |
/// \ref bellmanFord() "function-type interface" of the |
|
924 |
/// \ref BellmanFord "Bellman-Ford" algorithm. |
|
925 |
/// It does not have own \ref run() method, it uses the |
|
926 |
/// functions and features of the plain \ref BellmanFord. |
|
927 |
/// |
|
928 |
/// This class should only be used through the \ref bellmanFord() |
|
929 |
/// function, which makes it easier to use the algorithm. |
|
930 |
template<class TR> |
|
931 |
class BellmanFordWizard : public TR { |
|
932 |
typedef TR Base; |
|
933 |
|
|
934 |
typedef typename TR::Digraph Digraph; |
|
935 |
|
|
936 |
typedef typename Digraph::Node Node; |
|
937 |
typedef typename Digraph::NodeIt NodeIt; |
|
938 |
typedef typename Digraph::Arc Arc; |
|
939 |
typedef typename Digraph::OutArcIt ArcIt; |
|
940 |
|
|
941 |
typedef typename TR::LengthMap LengthMap; |
|
942 |
typedef typename LengthMap::Value Value; |
|
943 |
typedef typename TR::PredMap PredMap; |
|
944 |
typedef typename TR::DistMap DistMap; |
|
945 |
typedef typename TR::Path Path; |
|
946 |
|
|
947 |
public: |
|
948 |
/// Constructor. |
|
949 |
BellmanFordWizard() : TR() {} |
|
950 |
|
|
951 |
/// \brief Constructor that requires parameters. |
|
952 |
/// |
|
953 |
/// Constructor that requires parameters. |
|
954 |
/// These parameters will be the default values for the traits class. |
|
955 |
/// \param gr The digraph the algorithm runs on. |
|
956 |
/// \param len The length map. |
|
957 |
BellmanFordWizard(const Digraph& gr, const LengthMap& len) |
|
958 |
: TR(gr, len) {} |
|
959 |
|
|
960 |
/// \brief Copy constructor |
|
961 |
BellmanFordWizard(const TR &b) : TR(b) {} |
|
962 |
|
|
963 |
~BellmanFordWizard() {} |
|
964 |
|
|
965 |
/// \brief Runs the Bellman-Ford algorithm from the given source node. |
|
966 |
/// |
|
967 |
/// This method runs the Bellman-Ford algorithm from the given source |
|
968 |
/// node in order to compute the shortest path to each node. |
|
969 |
void run(Node s) { |
|
970 |
BellmanFord<Digraph,LengthMap,TR> |
|
971 |
bf(*reinterpret_cast<const Digraph*>(Base::_graph), |
|
972 |
*reinterpret_cast<const LengthMap*>(Base::_length)); |
|
973 |
if (Base::_pred) bf.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); |
|
974 |
if (Base::_dist) bf.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); |
|
975 |
bf.run(s); |
|
976 |
} |
|
977 |
|
|
978 |
/// \brief Runs the Bellman-Ford algorithm to find the shortest path |
|
979 |
/// between \c s and \c t. |
|
980 |
/// |
|
981 |
/// This method runs the Bellman-Ford algorithm from node \c s |
|
982 |
/// in order to compute the shortest path to node \c t. |
|
983 |
/// Actually, it computes the shortest path to each node, but using |
|
984 |
/// this function you can retrieve the distance and the shortest path |
|
985 |
/// for a single target node easier. |
|
986 |
/// |
|
987 |
/// \return \c true if \c t is reachable form \c s. |
|
988 |
bool run(Node s, Node t) { |
|
989 |
BellmanFord<Digraph,LengthMap,TR> |
|
990 |
bf(*reinterpret_cast<const Digraph*>(Base::_graph), |
|
991 |
*reinterpret_cast<const LengthMap*>(Base::_length)); |
|
992 |
if (Base::_pred) bf.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); |
|
993 |
if (Base::_dist) bf.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); |
|
994 |
bf.run(s); |
|
995 |
if (Base::_path) *reinterpret_cast<Path*>(Base::_path) = bf.path(t); |
|
996 |
if (Base::_di) *reinterpret_cast<Value*>(Base::_di) = bf.dist(t); |
|
997 |
return bf.reached(t); |
|
998 |
} |
|
999 |
|
|
1000 |
template<class T> |
|
1001 |
struct SetPredMapBase : public Base { |
|
1002 |
typedef T PredMap; |
|
1003 |
static PredMap *createPredMap(const Digraph &) { return 0; }; |
|
1004 |
SetPredMapBase(const TR &b) : TR(b) {} |
|
1005 |
}; |
|
1006 |
|
|
1007 |
/// \brief \ref named-templ-param "Named parameter" for setting |
|
1008 |
/// the predecessor map. |
|
1009 |
/// |
|
1010 |
/// \ref named-templ-param "Named parameter" for setting |
|
1011 |
/// the map that stores the predecessor arcs of the nodes. |
|
1012 |
template<class T> |
|
1013 |
BellmanFordWizard<SetPredMapBase<T> > predMap(const T &t) { |
|
1014 |
Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t)); |
|
1015 |
return BellmanFordWizard<SetPredMapBase<T> >(*this); |
|
1016 |
} |
|
1017 |
|
|
1018 |
template<class T> |
|
1019 |
struct SetDistMapBase : public Base { |
|
1020 |
typedef T DistMap; |
|
1021 |
static DistMap *createDistMap(const Digraph &) { return 0; }; |
|
1022 |
SetDistMapBase(const TR &b) : TR(b) {} |
|
1023 |
}; |
|
1024 |
|
|
1025 |
/// \brief \ref named-templ-param "Named parameter" for setting |
|
1026 |
/// the distance map. |
|
1027 |
/// |
|
1028 |
/// \ref named-templ-param "Named parameter" for setting |
|
1029 |
/// the map that stores the distances of the nodes calculated |
|
1030 |
/// by the algorithm. |
|
1031 |
template<class T> |
|
1032 |
BellmanFordWizard<SetDistMapBase<T> > distMap(const T &t) { |
|
1033 |
Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t)); |
|
1034 |
return BellmanFordWizard<SetDistMapBase<T> >(*this); |
|
1035 |
} |
|
1036 |
|
|
1037 |
template<class T> |
|
1038 |
struct SetPathBase : public Base { |
|
1039 |
typedef T Path; |
|
1040 |
SetPathBase(const TR &b) : TR(b) {} |
|
1041 |
}; |
|
1042 |
|
|
1043 |
/// \brief \ref named-func-param "Named parameter" for getting |
|
1044 |
/// the shortest path to the target node. |
|
1045 |
/// |
|
1046 |
/// \ref named-func-param "Named parameter" for getting |
|
1047 |
/// the shortest path to the target node. |
|
1048 |
template<class T> |
|
1049 |
BellmanFordWizard<SetPathBase<T> > path(const T &t) |
|
1050 |
{ |
|
1051 |
Base::_path=reinterpret_cast<void*>(const_cast<T*>(&t)); |
|
1052 |
return BellmanFordWizard<SetPathBase<T> >(*this); |
|
1053 |
} |
|
1054 |
|
|
1055 |
/// \brief \ref named-func-param "Named parameter" for getting |
|
1056 |
/// the distance of the target node. |
|
1057 |
/// |
|
1058 |
/// \ref named-func-param "Named parameter" for getting |
|
1059 |
/// the distance of the target node. |
|
1060 |
BellmanFordWizard dist(const Value &d) |
|
1061 |
{ |
|
1062 |
Base::_di=reinterpret_cast<void*>(const_cast<Value*>(&d)); |
|
1063 |
return *this; |
|
1064 |
} |
|
1065 |
|
|
1066 |
}; |
|
1067 |
|
|
1068 |
/// \brief Function type interface for the \ref BellmanFord "Bellman-Ford" |
|
1069 |
/// algorithm. |
|
1070 |
/// |
|
1071 |
/// \ingroup shortest_path |
|
1072 |
/// Function type interface for the \ref BellmanFord "Bellman-Ford" |
|
1073 |
/// algorithm. |
|
1074 |
/// |
|
1075 |
/// This function also has several \ref named-templ-func-param |
|
1076 |
/// "named parameters", they are declared as the members of class |
|
1077 |
/// \ref BellmanFordWizard. |
|
1078 |
/// The following examples show how to use these parameters. |
|
1079 |
/// \code |
|
1080 |
/// // Compute shortest path from node s to each node |
|
1081 |
/// bellmanFord(g,length).predMap(preds).distMap(dists).run(s); |
|
1082 |
/// |
|
1083 |
/// // Compute shortest path from s to t |
|
1084 |
/// bool reached = bellmanFord(g,length).path(p).dist(d).run(s,t); |
|
1085 |
/// \endcode |
|
1086 |
/// \warning Don't forget to put the \ref BellmanFordWizard::run() "run()" |
|
1087 |
/// to the end of the parameter list. |
|
1088 |
/// \sa BellmanFordWizard |
|
1089 |
/// \sa BellmanFord |
|
1090 |
template<typename GR, typename LEN> |
|
1091 |
BellmanFordWizard<BellmanFordWizardBase<GR,LEN> > |
|
1092 |
bellmanFord(const GR& digraph, |
|
1093 |
const LEN& length) |
|
1094 |
{ |
|
1095 |
return BellmanFordWizard<BellmanFordWizardBase<GR,LEN> >(digraph, length); |
|
1096 |
} |
|
1097 |
|
|
1098 |
} //END OF NAMESPACE LEMON |
|
1099 |
|
|
1100 |
#endif |
|
1101 |
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_BINOM_HEAP_H |
|
20 |
#define LEMON_BINOM_HEAP_H |
|
21 |
|
|
22 |
///\file |
|
23 |
///\ingroup heaps |
|
24 |
///\brief Binomial Heap implementation. |
|
25 |
|
|
26 |
#include <vector> |
|
27 |
#include <utility> |
|
28 |
#include <functional> |
|
29 |
#include <lemon/math.h> |
|
30 |
#include <lemon/counter.h> |
|
31 |
|
|
32 |
namespace lemon { |
|
33 |
|
|
34 |
/// \ingroup heaps |
|
35 |
/// |
|
36 |
///\brief Binomial heap data structure. |
|
37 |
/// |
|
38 |
/// This class implements the \e binomial \e heap data structure. |
|
39 |
/// It fully conforms to the \ref concepts::Heap "heap concept". |
|
40 |
/// |
|
41 |
/// The methods \ref increase() and \ref erase() are not efficient |
|
42 |
/// in a binomial heap. In case of many calls of these operations, |
|
43 |
/// it is better to use other heap structure, e.g. \ref BinHeap |
|
44 |
/// "binary heap". |
|
45 |
/// |
|
46 |
/// \tparam PR Type of the priorities of the items. |
|
47 |
/// \tparam IM A read-writable item map with \c int values, used |
|
48 |
/// internally to handle the cross references. |
|
49 |
/// \tparam CMP A functor class for comparing the priorities. |
|
50 |
/// The default is \c std::less<PR>. |
|
51 |
#ifdef DOXYGEN |
|
52 |
template <typename PR, typename IM, typename CMP> |
|
53 |
#else |
|
54 |
template <typename PR, typename IM, typename CMP = std::less<PR> > |
|
55 |
#endif |
|
56 |
class BinomHeap { |
|
57 |
public: |
|
58 |
/// Type of the item-int map. |
|
59 |
typedef IM ItemIntMap; |
|
60 |
/// Type of the priorities. |
|
61 |
typedef PR Prio; |
|
62 |
/// Type of the items stored in the heap. |
|
63 |
typedef typename ItemIntMap::Key Item; |
|
64 |
/// Functor type for comparing the priorities. |
|
65 |
typedef CMP Compare; |
|
66 |
|
|
67 |
/// \brief Type to represent the states of the items. |
|
68 |
/// |
|
69 |
/// Each item has a state associated to it. It can be "in heap", |
|
70 |
/// "pre-heap" or "post-heap". The latter two are indifferent from the |
|
71 |
/// heap's point of view, but may be useful to the user. |
|
72 |
/// |
|
73 |
/// The item-int map must be initialized in such way that it assigns |
|
74 |
/// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap. |
|
75 |
enum State { |
|
76 |
IN_HEAP = 0, ///< = 0. |
|
77 |
PRE_HEAP = -1, ///< = -1. |
|
78 |
POST_HEAP = -2 ///< = -2. |
|
79 |
}; |
|
80 |
|
|
81 |
private: |
|
82 |
class Store; |
|
83 |
|
|
84 |
std::vector<Store> _data; |
|
85 |
int _min, _head; |
|
86 |
ItemIntMap &_iim; |
|
87 |
Compare _comp; |
|
88 |
int _num_items; |
|
89 |
|
|
90 |
public: |
|
91 |
/// \brief Constructor. |
|
92 |
/// |
|
93 |
/// Constructor. |
|
94 |
/// \param map A map that assigns \c int values to the items. |
|
95 |
/// It is used internally to handle the cross references. |
|
96 |
/// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item. |
|
97 |
explicit BinomHeap(ItemIntMap &map) |
|
98 |
: _min(0), _head(-1), _iim(map), _num_items(0) {} |
|
99 |
|
|
100 |
/// \brief Constructor. |
|
101 |
/// |
|
102 |
/// Constructor. |
|
103 |
/// \param map A map that assigns \c int values to the items. |
|
104 |
/// It is used internally to handle the cross references. |
|
105 |
/// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item. |
|
106 |
/// \param comp The function object used for comparing the priorities. |
|
107 |
BinomHeap(ItemIntMap &map, const Compare &comp) |
|
108 |
: _min(0), _head(-1), _iim(map), _comp(comp), _num_items(0) {} |
|
109 |
|
|
110 |
/// \brief The number of items stored in the heap. |
|
111 |
/// |
|
112 |
/// This function returns the number of items stored in the heap. |
|
113 |
int size() const { return _num_items; } |
|
114 |
|
|
115 |
/// \brief Check if the heap is empty. |
|
116 |
/// |
|
117 |
/// This function returns \c true if the heap is empty. |
|
118 |
bool empty() const { return _num_items==0; } |
|
119 |
|
|
120 |
/// \brief Make the heap empty. |
|
121 |
/// |
|
122 |
/// This functon makes the heap empty. |
|
123 |
/// It does not change the cross reference map. If you want to reuse |
|
124 |
/// a heap that is not surely empty, you should first clear it and |
|
125 |
/// then you should set the cross reference map to \c PRE_HEAP |
|
126 |
/// for each item. |
|
127 |
void clear() { |
|
128 |
_data.clear(); _min=0; _num_items=0; _head=-1; |
|
129 |
} |
|
130 |
|
|
131 |
/// \brief Set the priority of an item or insert it, if it is |
|
132 |
/// not stored in the heap. |
|
133 |
/// |
|
134 |
/// This method sets the priority of the given item if it is |
|
135 |
/// already stored in the heap. Otherwise it inserts the given |
|
136 |
/// item into the heap with the given priority. |
|
137 |
/// \param item The item. |
|
138 |
/// \param value The priority. |
|
139 |
void set (const Item& item, const Prio& value) { |
|
140 |
int i=_iim[item]; |
|
141 |
if ( i >= 0 && _data[i].in ) { |
|
142 |
if ( _comp(value, _data[i].prio) ) decrease(item, value); |
|
143 |
if ( _comp(_data[i].prio, value) ) increase(item, value); |
|
144 |
} else push(item, value); |
|
145 |
} |
|
146 |
|
|
147 |
/// \brief Insert an item into the heap with the given priority. |
|
148 |
/// |
|
149 |
/// This function inserts the given item into the heap with the |
|
150 |
/// given priority. |
|
151 |
/// \param item The item to insert. |
|
152 |
/// \param value The priority of the item. |
|
153 |
/// \pre \e item must not be stored in the heap. |
|
154 |
void push (const Item& item, const Prio& value) { |
|
155 |
int i=_iim[item]; |
|
156 |
if ( i<0 ) { |
|
157 |
int s=_data.size(); |
|
158 |
_iim.set( item,s ); |
|
159 |
Store st; |
|
160 |
st.name=item; |
|
161 |
st.prio=value; |
|
162 |
_data.push_back(st); |
|
163 |
i=s; |
|
164 |
} |
|
165 |
else { |
|
166 |
_data[i].parent=_data[i].right_neighbor=_data[i].child=-1; |
|
167 |
_data[i].degree=0; |
|
168 |
_data[i].in=true; |
|
169 |
_data[i].prio=value; |
|
170 |
} |
|
171 |
|
|
172 |
if( 0==_num_items ) { |
|
173 |
_head=i; |
|
174 |
_min=i; |
|
175 |
} else { |
|
176 |
merge(i); |
|
177 |
if( _comp(_data[i].prio, _data[_min].prio) ) _min=i; |
|
178 |
} |
|
179 |
++_num_items; |
|
180 |
} |
|
181 |
|
|
182 |
/// \brief Return the item having minimum priority. |
|
183 |
/// |
|
184 |
/// This function returns the item having minimum priority. |
|
185 |
/// \pre The heap must be non-empty. |
|
186 |
Item top() const { return _data[_min].name; } |
|
187 |
|
|
188 |
/// \brief The minimum priority. |
|
189 |
/// |
|
190 |
/// This function returns the minimum priority. |
|
191 |
/// \pre The heap must be non-empty. |
|
192 |
Prio prio() const { return _data[_min].prio; } |
|
193 |
|
|
194 |
/// \brief The priority of the given item. |
|
195 |
/// |
|
196 |
/// This function returns the priority of the given item. |
|
197 |
/// \param item The item. |
|
198 |
/// \pre \e item must be in the heap. |
|
199 |
const Prio& operator[](const Item& item) const { |
|
200 |
return _data[_iim[item]].prio; |
|
201 |
} |
|
202 |
|
|
203 |
/// \brief Remove the item having minimum priority. |
|
204 |
/// |
|
205 |
/// This function removes the item having minimum priority. |
|
206 |
/// \pre The heap must be non-empty. |
|
207 |
void pop() { |
|
208 |
_data[_min].in=false; |
|
209 |
|
|
210 |
int head_child=-1; |
|
211 |
if ( _data[_min].child!=-1 ) { |
|
212 |
int child=_data[_min].child; |
|
213 |
int neighb; |
|
214 |
while( child!=-1 ) { |
|
215 |
neighb=_data[child].right_neighbor; |
|
216 |
_data[child].parent=-1; |
|
217 |
_data[child].right_neighbor=head_child; |
|
218 |
head_child=child; |
|
219 |
child=neighb; |
|
220 |
} |
|
221 |
} |
|
222 |
|
|
223 |
if ( _data[_head].right_neighbor==-1 ) { |
|
224 |
// there was only one root |
|
225 |
_head=head_child; |
|
226 |
} |
|
227 |
else { |
|
228 |
// there were more roots |
|
229 |
if( _head!=_min ) { unlace(_min); } |
|
230 |
else { _head=_data[_head].right_neighbor; } |
|
231 |
merge(head_child); |
|
232 |
} |
|
233 |
_min=findMin(); |
|
234 |
--_num_items; |
|
235 |
} |
|
236 |
|
|
237 |
/// \brief Remove the given item from the heap. |
|
238 |
/// |
|
239 |
/// This function removes the given item from the heap if it is |
|
240 |
/// already stored. |
|
241 |
/// \param item The item to delete. |
|
242 |
/// \pre \e item must be in the heap. |
|
243 |
void erase (const Item& item) { |
|
244 |
int i=_iim[item]; |
|
245 |
if ( i >= 0 && _data[i].in ) { |
|
246 |
decrease( item, _data[_min].prio-1 ); |
|
247 |
pop(); |
|
248 |
} |
|
249 |
} |
|
250 |
|
|
251 |
/// \brief Decrease the priority of an item to the given value. |
|
252 |
/// |
|
253 |
/// This function decreases the priority of an item to the given value. |
|
254 |
/// \param item The item. |
|
255 |
/// \param value The priority. |
|
256 |
/// \pre \e item must be stored in the heap with priority at least \e value. |
|
257 |
void decrease (Item item, const Prio& value) { |
|
258 |
int i=_iim[item]; |
|
259 |
int p=_data[i].parent; |
|
260 |
_data[i].prio=value; |
|
261 |
|
|
262 |
while( p!=-1 && _comp(value, _data[p].prio) ) { |
|
263 |
_data[i].name=_data[p].name; |
|
264 |
_data[i].prio=_data[p].prio; |
|
265 |
_data[p].name=item; |
|
266 |
_data[p].prio=value; |
|
267 |
_iim[_data[i].name]=i; |
|
268 |
i=p; |
|
269 |
p=_data[p].parent; |
|
270 |
} |
|
271 |
_iim[item]=i; |
|
272 |
if ( _comp(value, _data[_min].prio) ) _min=i; |
|
273 |
} |
|
274 |
|
|
275 |
/// \brief Increase the priority of an item to the given value. |
|
276 |
/// |
|
277 |
/// This function increases the priority of an item to the given value. |
|
278 |
/// \param item The item. |
|
279 |
/// \param value The priority. |
|
280 |
/// \pre \e item must be stored in the heap with priority at most \e value. |
|
281 |
void increase (Item item, const Prio& value) { |
|
282 |
erase(item); |
|
283 |
push(item, value); |
|
284 |
} |
|
285 |
|
|
286 |
/// \brief Return the state of an item. |
|
287 |
/// |
|
288 |
/// This method returns \c PRE_HEAP if the given item has never |
|
289 |
/// been in the heap, \c IN_HEAP if it is in the heap at the moment, |
|
290 |
/// and \c POST_HEAP otherwise. |
|
291 |
/// In the latter case it is possible that the item will get back |
|
292 |
/// to the heap again. |
|
293 |
/// \param item The item. |
|
294 |
State state(const Item &item) const { |
|
295 |
int i=_iim[item]; |
|
296 |
if( i>=0 ) { |
|
297 |
if ( _data[i].in ) i=0; |
|
298 |
else i=-2; |
|
299 |
} |
|
300 |
return State(i); |
|
301 |
} |
|
302 |
|
|
303 |
/// \brief Set the state of an item in the heap. |
|
304 |
/// |
|
305 |
/// This function sets the state of the given item in the heap. |
|
306 |
/// It can be used to manually clear the heap when it is important |
|
307 |
/// to achive better time complexity. |
|
308 |
/// \param i The item. |
|
309 |
/// \param st The state. It should not be \c IN_HEAP. |
|
310 |
void state(const Item& i, State st) { |
|
311 |
switch (st) { |
|
312 |
case POST_HEAP: |
|
313 |
case PRE_HEAP: |
|
314 |
if (state(i) == IN_HEAP) { |
|
315 |
erase(i); |
|
316 |
} |
|
317 |
_iim[i] = st; |
|
318 |
break; |
|
319 |
case IN_HEAP: |
|
320 |
break; |
|
321 |
} |
|
322 |
} |
|
323 |
|
|
324 |
private: |
|
325 |
|
|
326 |
// Find the minimum of the roots |
|
327 |
int findMin() { |
|
328 |
if( _head!=-1 ) { |
|
329 |
int min_loc=_head, min_val=_data[_head].prio; |
|
330 |
for( int x=_data[_head].right_neighbor; x!=-1; |
|
331 |
x=_data[x].right_neighbor ) { |
|
332 |
if( _comp( _data[x].prio,min_val ) ) { |
|
333 |
min_val=_data[x].prio; |
|
334 |
min_loc=x; |
|
335 |
} |
|
336 |
} |
|
337 |
return min_loc; |
|
338 |
} |
|
339 |
else return -1; |
|
340 |
} |
|
341 |
|
|
342 |
// Merge the heap with another heap starting at the given position |
|
343 |
void merge(int a) { |
|
344 |
if( _head==-1 || a==-1 ) return; |
|
345 |
if( _data[a].right_neighbor==-1 && |
|
346 |
_data[a].degree<=_data[_head].degree ) { |
|
347 |
_data[a].right_neighbor=_head; |
|
348 |
_head=a; |
|
349 |
} else { |
|
350 |
interleave(a); |
|
351 |
} |
|
352 |
if( _data[_head].right_neighbor==-1 ) return; |
|
353 |
|
|
354 |
int x=_head; |
|
355 |
int x_prev=-1, x_next=_data[x].right_neighbor; |
|
356 |
while( x_next!=-1 ) { |
|
357 |
if( _data[x].degree!=_data[x_next].degree || |
|
358 |
( _data[x_next].right_neighbor!=-1 && |
|
359 |
_data[_data[x_next].right_neighbor].degree==_data[x].degree ) ) { |
|
360 |
x_prev=x; |
|
361 |
x=x_next; |
|
362 |
} |
|
363 |
else { |
|
364 |
if( _comp(_data[x_next].prio,_data[x].prio) ) { |
|
365 |
if( x_prev==-1 ) { |
|
366 |
_head=x_next; |
|
367 |
} else { |
|
368 |
_data[x_prev].right_neighbor=x_next; |
|
369 |
} |
|
370 |
fuse(x,x_next); |
|
371 |
x=x_next; |
|
372 |
} |
|
373 |
else { |
|
374 |
_data[x].right_neighbor=_data[x_next].right_neighbor; |
|
375 |
fuse(x_next,x); |
|
376 |
} |
|
377 |
} |
|
378 |
x_next=_data[x].right_neighbor; |
|
379 |
} |
|
380 |
} |
|
381 |
|
|
382 |
// Interleave the elements of the given list into the list of the roots |
|
383 |
void interleave(int a) { |
|
384 |
int p=_head, q=a; |
|
385 |
int curr=_data.size(); |
|
386 |
_data.push_back(Store()); |
|
387 |
|
|
388 |
while( p!=-1 || q!=-1 ) { |
|
389 |
if( q==-1 || ( p!=-1 && _data[p].degree<_data[q].degree ) ) { |
|
390 |
_data[curr].right_neighbor=p; |
|
391 |
curr=p; |
|
392 |
p=_data[p].right_neighbor; |
|
393 |
} |
|
394 |
else { |
|
395 |
_data[curr].right_neighbor=q; |
|
396 |
curr=q; |
|
397 |
q=_data[q].right_neighbor; |
|
398 |
} |
|
399 |
} |
|
400 |
|
|
401 |
_head=_data.back().right_neighbor; |
|
402 |
_data.pop_back(); |
|
403 |
} |
|
404 |
|
|
405 |
// Lace node a under node b |
|
406 |
void fuse(int a, int b) { |
|
407 |
_data[a].parent=b; |
|
408 |
_data[a].right_neighbor=_data[b].child; |
|
409 |
_data[b].child=a; |
|
410 |
|
|
411 |
++_data[b].degree; |
|
412 |
} |
|
413 |
|
|
414 |
// Unlace node a (if it has siblings) |
|
415 |
void unlace(int a) { |
|
416 |
int neighb=_data[a].right_neighbor; |
|
417 |
int other=_head; |
|
418 |
|
|
419 |
while( _data[other].right_neighbor!=a ) |
|
420 |
other=_data[other].right_neighbor; |
|
421 |
_data[other].right_neighbor=neighb; |
|
422 |
} |
|
423 |
|
|
424 |
private: |
|
425 |
|
|
426 |
class Store { |
|
427 |
friend class BinomHeap; |
|
428 |
|
|
429 |
Item name; |
|
430 |
int parent; |
|
431 |
int right_neighbor; |
|
432 |
int child; |
|
433 |
int degree; |
|
434 |
bool in; |
|
435 |
Prio prio; |
|
436 |
|
|
437 |
Store() : parent(-1), right_neighbor(-1), child(-1), degree(0), |
|
438 |
in(true) {} |
|
439 |
}; |
|
440 |
}; |
|
441 |
|
|
442 |
} //namespace lemon |
|
443 |
|
|
444 |
#endif //LEMON_BINOM_HEAP_H |
|
445 |
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_FOURARY_HEAP_H |
|
20 |
#define LEMON_FOURARY_HEAP_H |
|
21 |
|
|
22 |
///\ingroup heaps |
|
23 |
///\file |
|
24 |
///\brief Fourary heap implementation. |
|
25 |
|
|
26 |
#include <vector> |
|
27 |
#include <utility> |
|
28 |
#include <functional> |
|
29 |
|
|
30 |
namespace lemon { |
|
31 |
|
|
32 |
/// \ingroup heaps |
|
33 |
/// |
|
34 |
///\brief Fourary heap data structure. |
|
35 |
/// |
|
36 |
/// This class implements the \e fourary \e heap data structure. |
|
37 |
/// It fully conforms to the \ref concepts::Heap "heap concept". |
|
38 |
/// |
|
39 |
/// The fourary heap is a specialization of the \ref KaryHeap "K-ary heap" |
|
40 |
/// for <tt>K=4</tt>. It is similar to the \ref BinHeap "binary heap", |
|
41 |
/// but its nodes have at most four children, instead of two. |
|
42 |
/// |
|
43 |
/// \tparam PR Type of the priorities of the items. |
|
44 |
/// \tparam IM A read-writable item map with \c int values, used |
|
45 |
/// internally to handle the cross references. |
|
46 |
/// \tparam CMP A functor class for comparing the priorities. |
|
47 |
/// The default is \c std::less<PR>. |
|
48 |
/// |
|
49 |
///\sa BinHeap |
|
50 |
///\sa KaryHeap |
|
51 |
#ifdef DOXYGEN |
|
52 |
template <typename PR, typename IM, typename CMP> |
|
53 |
#else |
|
54 |
template <typename PR, typename IM, typename CMP = std::less<PR> > |
|
55 |
#endif |
|
56 |
class FouraryHeap { |
|
57 |
public: |
|
58 |
/// Type of the item-int map. |
|
59 |
typedef IM ItemIntMap; |
|
60 |
/// Type of the priorities. |
|
61 |
typedef PR Prio; |
|
62 |
/// Type of the items stored in the heap. |
|
63 |
typedef typename ItemIntMap::Key Item; |
|
64 |
/// Type of the item-priority pairs. |
|
65 |
typedef std::pair<Item,Prio> Pair; |
|
66 |
/// Functor type for comparing the priorities. |
|
67 |
typedef CMP Compare; |
|
68 |
|
|
69 |
/// \brief Type to represent the states of the items. |
|
70 |
/// |
|
71 |
/// Each item has a state associated to it. It can be "in heap", |
|
72 |
/// "pre-heap" or "post-heap". The latter two are indifferent from the |
|
73 |
/// heap's point of view, but may be useful to the user. |
|
74 |
/// |
|
75 |
/// The item-int map must be initialized in such way that it assigns |
|
76 |
/// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap. |
|
77 |
enum State { |
|
78 |
IN_HEAP = 0, ///< = 0. |
|
79 |
PRE_HEAP = -1, ///< = -1. |
|
80 |
POST_HEAP = -2 ///< = -2. |
|
81 |
}; |
|
82 |
|
|
83 |
private: |
|
84 |
std::vector<Pair> _data; |
|
85 |
Compare _comp; |
|
86 |
ItemIntMap &_iim; |
|
87 |
|
|
88 |
public: |
|
89 |
/// \brief Constructor. |
|
90 |
/// |
|
91 |
/// Constructor. |
|
92 |
/// \param map A map that assigns \c int values to the items. |
|
93 |
/// It is used internally to handle the cross references. |
|
94 |
/// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item. |
|
95 |
explicit FouraryHeap(ItemIntMap &map) : _iim(map) {} |
|
96 |
|
|
97 |
/// \brief Constructor. |
|
98 |
/// |
|
99 |
/// Constructor. |
|
100 |
/// \param map A map that assigns \c int values to the items. |
|
101 |
/// It is used internally to handle the cross references. |
|
102 |
/// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item. |
|
103 |
/// \param comp The function object used for comparing the priorities. |
|
104 |
FouraryHeap(ItemIntMap &map, const Compare &comp) |
|
105 |
: _iim(map), _comp(comp) {} |
|
106 |
|
|
107 |
/// \brief The number of items stored in the heap. |
|
108 |
/// |
|
109 |
/// This function returns the number of items stored in the heap. |
|
110 |
int size() const { return _data.size(); } |
|
111 |
|
|
112 |
/// \brief Check if the heap is empty. |
|
113 |
/// |
|
114 |
/// This function returns \c true if the heap is empty. |
|
115 |
bool empty() const { return _data.empty(); } |
|
116 |
|
|
117 |
/// \brief Make the heap empty. |
|
118 |
/// |
|
119 |
/// This functon makes the heap empty. |
|
120 |
/// It does not change the cross reference map. If you want to reuse |
|
121 |
/// a heap that is not surely empty, you should first clear it and |
|
122 |
/// then you should set the cross reference map to \c PRE_HEAP |
|
123 |
/// for each item. |
|
124 |
void clear() { _data.clear(); } |
|
125 |
|
|
126 |
private: |
|
127 |
static int parent(int i) { return (i-1)/4; } |
|
128 |
static int firstChild(int i) { return 4*i+1; } |
|
129 |
|
|
130 |
bool less(const Pair &p1, const Pair &p2) const { |
|
131 |
return _comp(p1.second, p2.second); |
|
132 |
} |
|
133 |
|
|
134 |
void bubbleUp(int hole, Pair p) { |
|
135 |
int par = parent(hole); |
|
136 |
while( hole>0 && less(p,_data[par]) ) { |
|
137 |
move(_data[par],hole); |
|
138 |
hole = par; |
|
139 |
par = parent(hole); |
|
140 |
} |
|
141 |
move(p, hole); |
|
142 |
} |
|
143 |
|
|
144 |
void bubbleDown(int hole, Pair p, int length) { |
|
145 |
if( length>1 ) { |
|
146 |
int child = firstChild(hole); |
|
147 |
while( child+3<length ) { |
|
148 |
int min=child; |
|
149 |
if( less(_data[++child], _data[min]) ) min=child; |
|
150 |
if( less(_data[++child], _data[min]) ) min=child; |
|
151 |
if( less(_data[++child], _data[min]) ) min=child; |
|
152 |
if( !less(_data[min], p) ) |
|
153 |
goto ok; |
|
154 |
move(_data[min], hole); |
|
155 |
hole = min; |
|
156 |
child = firstChild(hole); |
|
157 |
} |
|
158 |
if ( child<length ) { |
|
159 |
int min = child; |
|
160 |
if( ++child<length && less(_data[child], _data[min]) ) min=child; |
|
161 |
if( ++child<length && less(_data[child], _data[min]) ) min=child; |
|
162 |
if( less(_data[min], p) ) { |
|
163 |
move(_data[min], hole); |
|
164 |
hole = min; |
|
165 |
} |
|
166 |
} |
|
167 |
} |
|
168 |
ok: |
|
169 |
move(p, hole); |
|
170 |
} |
|
171 |
|
|
172 |
void move(const Pair &p, int i) { |
|
173 |
_data[i] = p; |
|
174 |
_iim.set(p.first, i); |
|
175 |
} |
|
176 |
|
|
177 |
public: |
|
178 |
/// \brief Insert a pair of item and priority into the heap. |
|
179 |
/// |
|
180 |
/// This function inserts \c p.first to the heap with priority |
|
181 |
/// \c p.second. |
|
182 |
/// \param p The pair to insert. |
|
183 |
/// \pre \c p.first must not be stored in the heap. |
|
184 |
void push(const Pair &p) { |
|
185 |
int n = _data.size(); |
|
186 |
_data.resize(n+1); |
|
187 |
bubbleUp(n, p); |
|
188 |
} |
|
189 |
|
|
190 |
/// \brief Insert an item into the heap with the given priority. |
|
191 |
/// |
|
192 |
/// This function inserts the given item into the heap with the |
|
193 |
/// given priority. |
|
194 |
/// \param i The item to insert. |
|
195 |
/// \param p The priority of the item. |
|
196 |
/// \pre \e i must not be stored in the heap. |
|
197 |
void push(const Item &i, const Prio &p) { push(Pair(i,p)); } |
|
198 |
|
|
199 |
/// \brief Return the item having minimum priority. |
|
200 |
/// |
|
201 |
/// This function returns the item having minimum priority. |
|
202 |
/// \pre The heap must be non-empty. |
|
203 |
Item top() const { return _data[0].first; } |
|
204 |
|
|
205 |
/// \brief The minimum priority. |
|
206 |
/// |
|
207 |
/// This function returns the minimum priority. |
|
208 |
/// \pre The heap must be non-empty. |
|
209 |
Prio prio() const { return _data[0].second; } |
|
210 |
|
|
211 |
/// \brief Remove the item having minimum priority. |
|
212 |
/// |
|
213 |
/// This function removes the item having minimum priority. |
|
214 |
/// \pre The heap must be non-empty. |
|
215 |
void pop() { |
|
216 |
int n = _data.size()-1; |
|
217 |
_iim.set(_data[0].first, POST_HEAP); |
|
218 |
if (n>0) bubbleDown(0, _data[n], n); |
|
219 |
_data.pop_back(); |
|
220 |
} |
|
221 |
|
|
222 |
/// \brief Remove the given item from the heap. |
|
223 |
/// |
|
224 |
/// This function removes the given item from the heap if it is |
|
225 |
/// already stored. |
|
226 |
/// \param i The item to delete. |
|
227 |
/// \pre \e i must be in the heap. |
|
228 |
void erase(const Item &i) { |
|
229 |
int h = _iim[i]; |
|
230 |
int n = _data.size()-1; |
|
231 |
_iim.set(_data[h].first, POST_HEAP); |
|
232 |
if( h<n ) { |
|
233 |
if( less(_data[parent(h)], _data[n]) ) |
|
234 |
bubbleDown(h, _data[n], n); |
|
235 |
else |
|
236 |
bubbleUp(h, _data[n]); |
|
237 |
} |
|
238 |
_data.pop_back(); |
|
239 |
} |
|
240 |
|
|
241 |
/// \brief The priority of the given item. |
|
242 |
/// |
|
243 |
/// This function returns the priority of the given item. |
|
244 |
/// \param i The item. |
|
245 |
/// \pre \e i must be in the heap. |
|
246 |
Prio operator[](const Item &i) const { |
|
247 |
int idx = _iim[i]; |
|
248 |
return _data[idx].second; |
|
249 |
} |
|
250 |
|
|
251 |
/// \brief Set the priority of an item or insert it, if it is |
|
252 |
/// not stored in the heap. |
|
253 |
/// |
|
254 |
/// This method sets the priority of the given item if it is |
|
255 |
/// already stored in the heap. Otherwise it inserts the given |
|
256 |
/// item into the heap with the given priority. |
|
257 |
/// \param i The item. |
|
258 |
/// \param p The priority. |
|
259 |
void set(const Item &i, const Prio &p) { |
|
260 |
int idx = _iim[i]; |
|
261 |
if( idx < 0 ) |
|
262 |
push(i,p); |
|
263 |
else if( _comp(p, _data[idx].second) ) |
|
264 |
bubbleUp(idx, Pair(i,p)); |
|
265 |
else |
|
266 |
bubbleDown(idx, Pair(i,p), _data.size()); |
|
267 |
} |
|
268 |
|
|
269 |
/// \brief Decrease the priority of an item to the given value. |
|
270 |
/// |
|
271 |
/// This function decreases the priority of an item to the given value. |
|
272 |
/// \param i The item. |
|
273 |
/// \param p The priority. |
|
274 |
/// \pre \e i must be stored in the heap with priority at least \e p. |
|
275 |
void decrease(const Item &i, const Prio &p) { |
|
276 |
int idx = _iim[i]; |
|
277 |
bubbleUp(idx, Pair(i,p)); |
|
278 |
} |
|
279 |
|
|
280 |
/// \brief Increase the priority of an item to the given value. |
|
281 |
/// |
|
282 |
/// This function increases the priority of an item to the given value. |
|
283 |
/// \param i The item. |
|
284 |
/// \param p The priority. |
|
285 |
/// \pre \e i must be stored in the heap with priority at most \e p. |
|
286 |
void increase(const Item &i, const Prio &p) { |
|
287 |
int idx = _iim[i]; |
|
288 |
bubbleDown(idx, Pair(i,p), _data.size()); |
|
289 |
} |
|
290 |
|
|
291 |
/// \brief Return the state of an item. |
|
292 |
/// |
|
293 |
/// This method returns \c PRE_HEAP if the given item has never |
|
294 |
/// been in the heap, \c IN_HEAP if it is in the heap at the moment, |
|
295 |
/// and \c POST_HEAP otherwise. |
|
296 |
/// In the latter case it is possible that the item will get back |
|
297 |
/// to the heap again. |
|
298 |
/// \param i The item. |
|
299 |
State state(const Item &i) const { |
|
300 |
int s = _iim[i]; |
|
301 |
if (s>=0) s=0; |
|
302 |
return State(s); |
|
303 |
} |
|
304 |
|
|
305 |
/// \brief Set the state of an item in the heap. |
|
306 |
/// |
|
307 |
/// This function sets the state of the given item in the heap. |
|
308 |
/// It can be used to manually clear the heap when it is important |
|
309 |
/// to achive better time complexity. |
|
310 |
/// \param i The item. |
|
311 |
/// \param st The state. It should not be \c IN_HEAP. |
|
312 |
void state(const Item& i, State st) { |
|
313 |
switch (st) { |
|
314 |
case POST_HEAP: |
|
315 |
case PRE_HEAP: |
|
316 |
if (state(i) == IN_HEAP) erase(i); |
|
317 |
_iim[i] = st; |
|
318 |
break; |
|
319 |
case IN_HEAP: |
|
320 |
break; |
|
321 |
} |
|
322 |
} |
|
323 |
|
|
324 |
/// \brief Replace an item in the heap. |
|
325 |
/// |
|
326 |
/// This function replaces item \c i with item \c j. |
|
327 |
/// Item \c i must be in the heap, while \c j must be out of the heap. |
|
328 |
/// After calling this method, item \c i will be out of the |
|
329 |
/// heap and \c j will be in the heap with the same prioriority |
|
330 |
/// as item \c i had before. |
|
331 |
void replace(const Item& i, const Item& j) { |
|
332 |
int idx = _iim[i]; |
|
333 |
_iim.set(i, _iim[j]); |
|
334 |
_iim.set(j, idx); |
|
335 |
_data[idx].first = j; |
|
336 |
} |
|
337 |
|
|
338 |
}; // class FouraryHeap |
|
339 |
|
|
340 |
} // namespace lemon |
|
341 |
|
|
342 |
#endif // LEMON_FOURARY_HEAP_H |
... | ... |
@@ -43,2 +43,3 @@ |
43 | 43 |
AC_CHECK_PROG([doxygen_found],[doxygen],[yes],[no]) |
44 |
AC_CHECK_PROG([python_found],[python],[yes],[no]) |
|
44 | 45 |
AC_CHECK_PROG([gs_found],[gs],[yes],[no]) |
... | ... |
@@ -84,2 +85,17 @@ |
84 | 85 |
|
86 |
dnl Support for running test cases using valgrind. |
|
87 |
use_valgrind=no |
|
88 |
AC_ARG_ENABLE([valgrind], |
|
89 |
AS_HELP_STRING([--enable-valgrind], [use valgrind when running tests]), |
|
90 |
[use_valgrind=yes]) |
|
91 |
|
|
92 |
if [[ "$use_valgrind" = "yes" ]]; then |
|
93 |
AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no) |
|
94 |
|
|
95 |
if [[ "$HAVE_VALGRIND" = "no" ]]; then |
|
96 |
AC_MSG_ERROR([Valgrind not found in PATH.]) |
|
97 |
fi |
|
98 |
fi |
|
99 |
AM_CONDITIONAL(USE_VALGRIND, [test "$use_valgrind" = "yes"]) |
|
100 |
|
|
85 | 101 |
dnl Checks for header files. |
... | ... |
@@ -129,2 +145,3 @@ |
129 | 145 |
echo Build additional tools........ : $enable_tools |
146 |
echo Use valgrind for tests........ : $use_valgrind |
|
130 | 147 |
echo |
... | ... |
@@ -11,3 +11,3 @@ |
11 | 11 |
|
12 |
IF(DOXYGEN_EXECUTABLE AND GHOSTSCRIPT_EXECUTABLE) |
|
12 |
IF(DOXYGEN_EXECUTABLE AND PYTHONINTERP_FOUND AND GHOSTSCRIPT_EXECUTABLE) |
|
13 | 13 |
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/) |
... | ... |
@@ -30,2 +30,3 @@ |
30 | 30 |
COMMAND ${CMAKE_COMMAND} -E remove_directory html |
31 |
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/bib2dox.py ${CMAKE_CURRENT_SOURCE_DIR}/references.bib >references.dox |
|
31 | 32 |
COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile |
1 |
# Doxyfile 1.5. |
|
1 |
# Doxyfile 1.5.9 |
|
2 | 2 |
|
... | ... |
@@ -23,3 +23,2 @@ |
23 | 23 |
MULTILINE_CPP_IS_BRIEF = NO |
24 |
DETAILS_AT_TOP = YES |
|
25 | 24 |
INHERIT_DOCS = NO |
... | ... |
@@ -93,3 +92,4 @@ |
93 | 92 |
"@abs_top_srcdir@/tools" \ |
94 |
"@abs_top_srcdir@/test/test_tools.h" |
|
93 |
"@abs_top_srcdir@/test/test_tools.h" \ |
|
94 |
"@abs_top_builddir@/doc/references.dox" |
|
95 | 95 |
INPUT_ENCODING = UTF-8 |
... | ... |
@@ -225,3 +225,3 @@ |
225 | 225 |
#--------------------------------------------------------------------------- |
226 |
# |
|
226 |
# Options related to the search engine |
|
227 | 227 |
#--------------------------------------------------------------------------- |
... | ... |
@@ -68,3 +68,15 @@ |
68 | 68 |
|
69 |
|
|
69 |
references.dox: doc/references.bib |
|
70 |
if test ${python_found} = yes; then \ |
|
71 |
cd doc; \ |
|
72 |
python @abs_top_srcdir@/scripts/bib2dox.py @abs_top_builddir@/$< >$@; \ |
|
73 |
cd ..; \ |
|
74 |
else \ |
|
75 |
echo; \ |
|
76 |
echo "Python not found."; \ |
|
77 |
echo; \ |
|
78 |
exit 1; \ |
|
79 |
fi |
|
80 |
|
|
81 |
html-local: $(DOC_PNG_IMAGES) references.dox |
|
70 | 82 |
if test ${doxygen_found} = yes; then \ |
... | ... |
@@ -228,10 +228,2 @@ |
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 |
... | ... |
@@ -248,3 +240,32 @@ |
248 | 240 |
|
249 |
\sa |
|
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 |
*/ |
... | ... |
@@ -261,2 +282,24 @@ |
261 | 282 |
/** |
283 |
@defgroup geomdat Geometric Data Structures |
|
284 |
@ingroup auxdat |
|
285 |
\brief Geometric data structures implemented in LEMON. |
|
286 |
|
|
287 |
This group contains geometric data structures implemented in LEMON. |
|
288 |
|
|
289 |
- \ref lemon::dim2::Point "dim2::Point" implements a two dimensional |
|
290 |
vector with the usual operations. |
|
291 |
- \ref lemon::dim2::Box "dim2::Box" can be used to determine the |
|
292 |
rectangular bounding box of a set of \ref lemon::dim2::Point |
|
293 |
"dim2::Point"'s. |
|
294 |
*/ |
|
295 |
|
|
296 |
/** |
|
297 |
@defgroup matrices Matrices |
|
298 |
@ingroup auxdat |
|
299 |
\brief Two dimensional data storages implemented in LEMON. |
|
300 |
|
|
301 |
This group contains two dimensional data storages implemented in LEMON. |
|
302 |
*/ |
|
303 |
|
|
304 |
/** |
|
262 | 305 |
@defgroup algs Algorithms |
... | ... |
@@ -275,3 +318,4 @@ |
275 | 318 |
This group contains the common graph search algorithms, namely |
276 |
\e breadth-first \e search (BFS) and \e depth-first \e search (DFS) |
|
319 |
\e breadth-first \e search (BFS) and \e depth-first \e search (DFS) |
|
320 |
\ref clrs01algorithms. |
|
277 | 321 |
*/ |
... | ... |
@@ -283,3 +327,4 @@ |
283 | 327 |
|
284 |
This group contains the algorithms for finding shortest paths in digraphs |
|
328 |
This group contains the algorithms for finding shortest paths in digraphs |
|
329 |
\ref clrs01algorithms. |
|
285 | 330 |
|
... | ... |
@@ -300,2 +345,11 @@ |
300 | 345 |
/** |
346 |
@defgroup spantree Minimum Spanning Tree Algorithms |
|
347 |
@ingroup algs |
|
348 |
\brief Algorithms for finding minimum cost spanning trees and arborescences. |
|
349 |
|
|
350 |
This group contains the algorithms for finding minimum cost spanning |
|
351 |
trees and arborescences \ref clrs01algorithms. |
|
352 |
*/ |
|
353 |
|
|
354 |
/** |
|
301 | 355 |
@defgroup max_flow Maximum Flow Algorithms |
... | ... |
@@ -305,3 +359,3 @@ |
305 | 359 |
This group contains the algorithms for finding maximum flows and |
306 |
feasible circulations. |
|
360 |
feasible circulations \ref clrs01algorithms, \ref amo93networkflows. |
|
307 | 361 |
|
... | ... |
@@ -320,8 +374,12 @@ |
320 | 374 |
LEMON contains several algorithms for solving maximum flow problems: |
321 |
- \ref EdmondsKarp Edmonds-Karp algorithm. |
|
322 |
- \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm. |
|
323 |
- \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees. |
|
324 |
- \ref GoldbergTarjan Preflow push-relabel algorithm with dynamic trees. |
|
375 |
- \ref EdmondsKarp Edmonds-Karp algorithm |
|
376 |
\ref edmondskarp72theoretical. |
|
377 |
- \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm |
|
378 |
\ref goldberg88newapproach. |
|
379 |
- \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees |
|
380 |
\ref dinic70algorithm, \ref sleator83dynamic. |
|
381 |
- \ref GoldbergTarjan !Preflow push-relabel algorithm with dynamic trees |
|
382 |
\ref goldberg88newapproach, \ref sleator83dynamic. |
|
325 | 383 |
|
326 |
In most cases the \ref Preflow |
|
384 |
In most cases the \ref Preflow algorithm provides the |
|
327 | 385 |
fastest method for computing a maximum flow. All implementations |
... | ... |
@@ -343,4 +401,5 @@ |
343 | 401 |
This group contains the algorithms for finding minimum cost flows and |
344 |
circulations. For more information about this problem and its dual |
|
345 |
solution see \ref min_cost_flow "Minimum Cost Flow Problem". |
|
402 |
circulations \ref amo93networkflows. For more information about this |
|
403 |
problem and its dual solution, see \ref min_cost_flow |
|
404 |
"Minimum Cost Flow Problem". |
|
346 | 405 |
|
... | ... |
@@ -348,9 +407,12 @@ |
348 | 407 |
- \ref NetworkSimplex Primal Network Simplex algorithm with various |
349 |
pivot strategies. |
|
408 |
pivot strategies \ref dantzig63linearprog, \ref kellyoneill91netsimplex. |
|
350 | 409 |
- \ref CostScaling Push-Relabel and Augment-Relabel algorithms based on |
351 |
cost scaling |
|
410 |
cost scaling \ref goldberg90approximation, \ref goldberg97efficient, |
|
411 |
\ref bunnagel98efficient. |
|
352 | 412 |
- \ref CapacityScaling Successive Shortest %Path algorithm with optional |
353 |
capacity scaling. |
|
354 |
- \ref CancelAndTighten The Cancel and Tighten algorithm. |
|
355 |
|
|
413 |
capacity scaling \ref edmondskarp72theoretical. |
|
414 |
- \ref CancelAndTighten The Cancel and Tighten algorithm |
|
415 |
\ref goldberg89cyclecanceling. |
|
416 |
- \ref CycleCanceling Cycle-Canceling algorithms |
|
417 |
\ref klein67primal, \ref goldberg89cyclecanceling. |
|
356 | 418 |
|
... | ... |
@@ -377,3 +439,3 @@ |
377 | 439 |
\f[ \min_{X \subset V, X\not\in \{\emptyset, V\}} |
378 |
\sum_{uv\in A |
|
440 |
\sum_{uv\in A: u\in X, v\not\in X}cap(uv) \f] |
|
379 | 441 |
|
... | ... |
@@ -393,23 +455,36 @@ |
393 | 455 |
/** |
394 |
@defgroup |
|
456 |
@defgroup min_mean_cycle Minimum Mean Cycle Algorithms |
|
395 | 457 |
@ingroup algs |
396 |
\brief Algorithms for |
|
458 |
\brief Algorithms for finding minimum mean cycles. |
|
397 | 459 |
|
398 |
This group contains the algorithms for discovering the graph properties |
|
399 |
like connectivity, bipartiteness, euler property, simplicity etc. |
|
460 |
This group contains the algorithms for finding minimum mean cycles |
|
461 |
\ref clrs01algorithms, \ref amo93networkflows. |
|
400 | 462 |
|
401 |
\image html edge_biconnected_components.png |
|
402 |
\image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth |
|
403 |
|
|
463 |
The \e minimum \e mean \e cycle \e problem is to find a directed cycle |
|
464 |
of minimum mean length (cost) in a digraph. |
|
465 |
The mean length of a cycle is the average length of its arcs, i.e. the |
|
466 |
ratio between the total length of the cycle and the number of arcs on it. |
|
404 | 467 |
|
405 |
/** |
|
406 |
@defgroup planar Planarity Embedding and Drawing |
|
407 |
@ingroup algs |
|
408 |
\brief Algorithms for planarity checking, embedding and drawing |
|
468 |
This problem has an important connection to \e conservative \e length |
|
469 |
\e functions, too. A length function on the arcs of a digraph is called |
|
470 |
conservative if and only if there is no directed cycle of negative total |
|
471 |
length. For an arbitrary length function, the negative of the minimum |
|
472 |
cycle mean is the smallest \f$\epsilon\f$ value so that increasing the |
|
473 |
arc lengths uniformly by \f$\epsilon\f$ results in a conservative length |
|
474 |
function. |
|
409 | 475 |
|
410 |
This group contains the algorithms for planarity checking, |
|
411 |
embedding and drawing. |
|
476 |
LEMON contains three algorithms for solving the minimum mean cycle problem: |
|
477 |
- \ref Karp "Karp"'s original algorithm \ref amo93networkflows, |
|
478 |
\ref dasdan98minmeancycle. |
|
479 |
- \ref HartmannOrlin "Hartmann-Orlin"'s algorithm, which is an improved |
|
480 |
version of Karp's algorithm \ref dasdan98minmeancycle. |
|
481 |
- \ref Howard "Howard"'s policy iteration algorithm |
|
482 |
\ref dasdan98minmeancycle. |
|
412 | 483 |
|
413 |
\image html planar.png |
|
414 |
\image latex planar.eps "Plane graph" width=\textwidth |
|
484 |
In practice, the Howard algorithm proved to be by far the most efficient |
|
485 |
one, though the best known theoretical bound on its running time is |
|
486 |
exponential. |
|
487 |
Both Karp and HartmannOrlin algorithms run in time O(ne) and use space |
|
488 |
O(n<sup>2</sup>+e), but the latter one is typically faster due to the |
|
489 |
applied early termination scheme. |
|
415 | 490 |
*/ |
... | ... |
@@ -457,8 +532,32 @@ |
457 | 532 |
/** |
458 |
@defgroup |
|
533 |
@defgroup graph_properties Connectivity and Other Graph Properties |
|
459 | 534 |
@ingroup algs |
460 |
\brief Algorithms for |
|
535 |
\brief Algorithms for discovering the graph properties |
|
461 | 536 |
|
462 |
This group contains the algorithms for finding minimum cost spanning |
|
463 |
trees and arborescences. |
|
537 |
This group contains the algorithms for discovering the graph properties |
|
538 |
like connectivity, bipartiteness, euler property, simplicity etc. |
|
539 |
|
|
540 |
\image html connected_components.png |
|
541 |
\image latex connected_components.eps "Connected components" width=\textwidth |
|
542 |
*/ |
|
543 |
|
|
544 |
/** |
|
545 |
@defgroup planar Planarity Embedding and Drawing |
|
546 |
@ingroup algs |
|
547 |
\brief Algorithms for planarity checking, embedding and drawing |
|
548 |
|
|
549 |
This group contains the algorithms for planarity checking, |
|
550 |
embedding and drawing. |
|
551 |
|
|
552 |
\image html planar.png |
|
553 |
\image latex planar.eps "Plane graph" width=\textwidth |
|
554 |
*/ |
|
555 |
|
|
556 |
/** |
|
557 |
@defgroup approx Approximation Algorithms |
|
558 |
@ingroup algs |
|
559 |
\brief Approximation algorithms. |
|
560 |
|
|
561 |
This group contains the approximation and heuristic algorithms |
|
562 |
implemented in LEMON. |
|
464 | 563 |
*/ |
... | ... |
@@ -475,11 +574,2 @@ |
475 | 574 |
/** |
476 |
@defgroup approx Approximation Algorithms |
|
477 |
@ingroup algs |
|
478 |
\brief Approximation algorithms. |
|
479 |
|
|
480 |
This group contains the approximation and heuristic algorithms |
|
481 |
implemented in LEMON. |
|
482 |
*/ |
|
483 |
|
|
484 |
/** |
|
485 | 575 |
@defgroup gen_opt_group General Optimization Tools |
... | ... |
@@ -493,9 +583,12 @@ |
493 | 583 |
/** |
494 |
@defgroup lp_group |
|
584 |
@defgroup lp_group LP and MIP Solvers |
|
495 | 585 |
@ingroup gen_opt_group |
496 |
\brief |
|
586 |
\brief LP and MIP solver interfaces for LEMON. |
|
497 | 587 |
|
498 |
This group contains Lp and Mip solver interfaces for LEMON. The |
|
499 |
various LP solvers could be used in the same manner with this |
|
500 |
|
|
588 |
This group contains LP and MIP solver interfaces for LEMON. |
|
589 |
Various LP solvers could be used in the same manner with this |
|
590 |
high-level interface. |
|
591 |
|
|
592 |
The currently supported solvers are \ref glpk, \ref clp, \ref cbc, |
|
593 |
\ref cplex, \ref soplex. |
|
501 | 594 |
*/ |
... | ... |
@@ -589,3 +682,3 @@ |
589 | 682 |
/** |
590 |
@defgroup dimacs_group DIMACS |
|
683 |
@defgroup dimacs_group DIMACS Format |
|
591 | 684 |
@ingroup io_group |
... | ... |
@@ -638,4 +731,4 @@ |
638 | 731 |
|
639 |
This group contains the skeletons and concept checking classes of LEMON's |
|
640 |
graph structures and helper classes used to implement these. |
|
732 |
This group contains the skeletons and concept checking classes of |
|
733 |
graph structures. |
|
641 | 734 |
*/ |
... | ... |
@@ -651,2 +744,11 @@ |
651 | 744 |
/** |
745 |
@defgroup tools Standalone Utility Applications |
|
746 |
|
|
747 |
Some utility applications are listed here. |
|
748 |
|
|
749 |
The standard compilation procedure (<tt>./configure;make</tt>) will compile |
|
750 |
them, as well. |
|
751 |
*/ |
|
752 |
|
|
753 |
/** |
|
652 | 754 |
\anchor demoprograms |
... | ... |
@@ -662,11 +764,2 @@ |
662 | 764 |
|
663 |
/** |
|
664 |
@defgroup tools Standalone Utility Applications |
|
665 |
|
|
666 |
Some utility applications are listed here. |
|
667 |
|
|
668 |
The standard compilation procedure (<tt>./configure;make</tt>) will compile |
|
669 |
them, as well. |
|
670 |
*/ |
|
671 |
|
|
672 | 765 |
} |
... | ... |
@@ -23,10 +23,7 @@ |
23 | 23 |
|
24 |
\subsection whatis What is LEMON |
|
25 |
|
|
26 |
LEMON stands for <b>L</b>ibrary for <b>E</b>fficient <b>M</b>odeling |
|
27 |
and <b>O</b>ptimization in <b>N</b>etworks. |
|
28 |
It is a C++ template |
|
29 |
library aimed at combinatorial optimization tasks which |
|
30 |
often involve in working |
|
31 |
with graphs. |
|
24 |
<b>LEMON</b> stands for <i><b>L</b>ibrary for <b>E</b>fficient <b>M</b>odeling |
|
25 |
and <b>O</b>ptimization in <b>N</b>etworks</i>. |
|
26 |
It is a C++ template library providing efficient implementation of common |
|
27 |
data structures and algorithms with focus on combinatorial optimization |
|
28 |
problems in graphs and networks. |
|
32 | 29 |
|
... | ... |
@@ -40,3 +37,12 @@ |
40 | 37 |
|
41 |
|
|
38 |
The project is maintained by the |
|
39 |
<a href="http://www.cs.elte.hu/egres/">Egerváry Research Group on |
|
40 |
Combinatorial Optimization</a> \ref egres |
|
41 |
at the Operations Research Department of the |
|
42 |
<a href="http://www.elte.hu/">Eötvös Loránd University, |
|
43 |
Budapest</a>, Hungary. |
|
44 |
LEMON is also a member of the <a href="http://www.coin-or.org/">COIN-OR</a> |
|
45 |
initiative \ref coinor. |
|
46 |
|
|
47 |
\section howtoread How to Read the Documentation |
|
42 | 48 |
... | ... |
@@ -28,3 +28,3 @@ |
28 | 28 |
in a network with capacity constraints (lower and upper bounds) |
29 |
and arc costs. |
|
29 |
and arc costs \ref amo93networkflows. |
|
30 | 30 |
|
... | ... |
@@ -80,3 +80,3 @@ |
80 | 80 |
- For all \f$u\in V\f$ nodes: |
81 |
- \f$\pi(u) |
|
81 |
- \f$\pi(u)\leq 0\f$; |
|
82 | 82 |
- if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$, |
... | ... |
@@ -147,3 +147,3 @@ |
147 | 147 |
- For all \f$u\in V\f$ nodes: |
148 |
- \f$\pi(u) |
|
148 |
- \f$\pi(u)\geq 0\f$; |
|
149 | 149 |
- if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$, |
... | ... |
@@ -59,4 +59,6 @@ |
59 | 59 |
lemon/assert.h \ |
60 |
lemon/bellman_ford.h \ |
|
60 | 61 |
lemon/bfs.h \ |
61 | 62 |
lemon/bin_heap.h \ |
63 |
lemon/binom_heap.h \ |
|
62 | 64 |
lemon/bucket_heap.h \ |
... | ... |
@@ -80,2 +82,3 @@ |
80 | 82 |
lemon/fib_heap.h \ |
83 |
lemon/fourary_heap.h \ |
|
81 | 84 |
lemon/full_graph.h \ |
... | ... |
@@ -85,3 +88,7 @@ |
85 | 88 |
lemon/grid_graph.h \ |
89 |
lemon/hartmann_orlin.h \ |
|
90 |
lemon/howard.h \ |
|
86 | 91 |
lemon/hypercube_graph.h \ |
92 |
lemon/karp.h \ |
|
93 |
lemon/kary_heap.h \ |
|
87 | 94 |
lemon/kruskal.h \ |
... | ... |
@@ -94,3 +101,2 @@ |
94 | 101 |
lemon/lp_skeleton.h \ |
95 |
lemon/list_graph.h \ |
|
96 | 102 |
lemon/maps.h \ |
... | ... |
@@ -101,3 +107,5 @@ |
101 | 107 |
lemon/network_simplex.h \ |
108 |
lemon/pairing_heap.h \ |
|
102 | 109 |
lemon/path.h \ |
110 |
lemon/planarity.h \ |
|
103 | 111 |
lemon/preflow.h \ |
... | ... |
@@ -108,2 +116,3 @@ |
108 | 116 |
lemon/soplex.h \ |
117 |
lemon/static_graph.h \ |
|
109 | 118 |
lemon/suurballe.h \ |
... | ... |
@@ -362,2 +362,5 @@ |
362 | 362 |
/// |
363 |
/// This class provides item counting in the same time as the adapted |
|
364 |
/// digraph structure. |
|
365 |
/// |
|
363 | 366 |
/// \tparam DGR The type of the adapted digraph. |
... | ... |
@@ -721,2 +724,4 @@ |
721 | 724 |
/// |
725 |
/// This class provides only linear time counting for nodes and arcs. |
|
726 |
/// |
|
722 | 727 |
/// \tparam DGR The type of the adapted digraph. |
... | ... |
@@ -1316,2 +1321,4 @@ |
1316 | 1321 |
/// |
1322 |
/// This class provides only linear time counting for nodes, edges and arcs. |
|
1323 |
/// |
|
1317 | 1324 |
/// \tparam GR The type of the adapted graph. |
... | ... |
@@ -1473,2 +1480,4 @@ |
1473 | 1480 |
/// |
1481 |
/// This class provides only linear time item counting. |
|
1482 |
/// |
|
1474 | 1483 |
/// \tparam GR The type of the adapted digraph or graph. |
... | ... |
@@ -1621,2 +1630,4 @@ |
1621 | 1630 |
/// |
1631 |
/// This class provides only linear time counting for nodes and arcs. |
|
1632 |
/// |
|
1622 | 1633 |
/// \tparam DGR The type of the adapted digraph. |
... | ... |
@@ -1731,2 +1742,4 @@ |
1731 | 1742 |
/// |
1743 |
/// This class provides only linear time counting for nodes, edges and arcs. |
|
1744 |
/// |
|
1732 | 1745 |
/// \tparam GR The type of the adapted graph. |
... | ... |
@@ -2234,2 +2247,5 @@ |
2234 | 2247 |
/// |
2248 |
/// This class provides item counting in the same time as the adapted |
|
2249 |
/// digraph structure. |
|
2250 |
/// |
|
2235 | 2251 |
/// \tparam DGR The type of the adapted digraph. |
... | ... |
@@ -2537,2 +2553,5 @@ |
2537 | 2553 |
/// |
2554 |
/// This class provides item counting in the same time as the adapted |
|
2555 |
/// graph structure. |
|
2556 |
/// |
|
2538 | 2557 |
/// \tparam GR The type of the adapted graph. |
... | ... |
@@ -2680,2 +2699,4 @@ |
2680 | 2699 |
/// |
2700 |
/// This class provides only linear time counting for nodes and arcs. |
|
2701 |
/// |
|
2681 | 2702 |
/// \tparam DGR The type of the adapted digraph. |
... | ... |
@@ -3327,2 +3348,5 @@ |
3327 | 3348 |
/// |
3349 |
/// This class provides item counting in the same time as the adapted |
|
3350 |
/// digraph structure. |
|
3351 |
/// |
|
3328 | 3352 |
/// \tparam DGR The type of the adapted digraph. |
... | ... |
@@ -49,3 +49,3 @@ |
49 | 49 |
///arcs of the shortest paths. |
50 |
///It must |
|
50 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
51 | 51 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
... | ... |
@@ -64,3 +64,4 @@ |
64 | 64 |
///The type of the map that indicates which nodes are processed. |
65 |
///It must |
|
65 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
66 |
///By default, it is a NullMap. |
|
66 | 67 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
... | ... |
@@ -83,3 +84,3 @@ |
83 | 84 |
///The type of the map that indicates which nodes are reached. |
84 |
///It must |
|
85 |
///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
85 | 86 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
... | ... |
@@ -98,3 +99,3 @@ |
98 | 99 |
///The type of the map that stores the distances of the nodes. |
99 |
///It must |
|
100 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
100 | 101 |
typedef typename Digraph::template NodeMap<int> DistMap; |
... | ... |
@@ -227,3 +228,3 @@ |
227 | 228 |
///\c PredMap type. |
228 |
///It must |
|
229 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
229 | 230 |
template <class T> |
... | ... |
@@ -247,3 +248,3 @@ |
247 | 248 |
///\c DistMap type. |
248 |
///It must |
|
249 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
249 | 250 |
template <class T> |
... | ... |
@@ -267,3 +268,3 @@ |
267 | 268 |
///\c ReachedMap type. |
268 |
///It must |
|
269 |
///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
269 | 270 |
template <class T> |
... | ... |
@@ -287,3 +288,3 @@ |
287 | 288 |
///\c ProcessedMap type. |
288 |
///It must |
|
289 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
289 | 290 |
template <class T> |
... | ... |
@@ -415,4 +416,4 @@ |
415 | 416 |
///member functions called \ref run(Node) "run()".\n |
416 |
///If you need more control on the execution, first you have to call |
|
417 |
///\ref init(), then you can add several source nodes with |
|
417 |
///If you need better control on the execution, you have to call |
|
418 |
///\ref init() first, then you can add several source nodes with |
|
418 | 419 |
///\ref addSource(). Finally the actual path computation can be |
... | ... |
@@ -702,8 +703,4 @@ |
702 | 703 |
|
703 |
///This method runs the %BFS algorithm in order to |
|
704 |
///compute the shortest path to each node. |
|
705 |
/// |
|
706 |
///The algorithm computes |
|
707 |
///- the shortest path tree (forest), |
|
708 |
///- the distance of each node from the root(s). |
|
704 |
///This method runs the %BFS algorithm in order to visit all nodes |
|
705 |
///in the digraph. |
|
709 | 706 |
/// |
... | ... |
@@ -739,5 +736,5 @@ |
739 | 736 |
|
740 |
///The shortest path to |
|
737 |
///The shortest path to the given node. |
|
741 | 738 |
|
742 |
///Returns the shortest path to |
|
739 |
///Returns the shortest path to the given node from the root(s). |
|
743 | 740 |
/// |
... | ... |
@@ -749,5 +746,5 @@ |
749 | 746 |
|
750 |
///The distance of |
|
747 |
///The distance of the given node from the root(s). |
|
751 | 748 |
|
752 |
///Returns the distance of |
|
749 |
///Returns the distance of the given node from the root(s). |
|
753 | 750 |
/// |
... | ... |
@@ -760,4 +757,5 @@ |
760 | 757 |
|
761 |
///Returns the 'previous arc' of the shortest path tree for a node. |
|
762 |
|
|
758 |
///\brief Returns the 'previous arc' of the shortest path tree for |
|
759 |
///the given node. |
|
760 |
/// |
|
763 | 761 |
///This function returns the 'previous arc' of the shortest path |
... | ... |
@@ -768,3 +766,3 @@ |
768 | 766 |
///The shortest path tree used here is equal to the shortest path |
769 |
///tree used in \ref predNode(). |
|
767 |
///tree used in \ref predNode() and \ref predMap(). |
|
770 | 768 |
/// |
... | ... |
@@ -774,7 +772,8 @@ |
774 | 772 |
|
775 |
///Returns the 'previous node' of the shortest path tree for a node. |
|
776 |
|
|
773 |
///\brief Returns the 'previous node' of the shortest path tree for |
|
774 |
///the given node. |
|
775 |
/// |
|
777 | 776 |
///This function returns the 'previous node' of the shortest path |
778 | 777 |
///tree for the node \c v, i.e. it returns the last but one node |
779 |
/// |
|
778 |
///of a shortest path from a root to \c v. It is \c INVALID |
|
780 | 779 |
///if \c v is not reached from the root(s) or if \c v is a root. |
... | ... |
@@ -782,3 +781,3 @@ |
782 | 781 |
///The shortest path tree used here is equal to the shortest path |
783 |
///tree used in \ref predArc(). |
|
782 |
///tree used in \ref predArc() and \ref predMap(). |
|
784 | 783 |
/// |
... | ... |
@@ -803,3 +802,3 @@ |
803 | 802 |
///Returns a const reference to the node map that stores the predecessor |
804 |
///arcs, which form the shortest path tree. |
|
803 |
///arcs, which form the shortest path tree (forest). |
|
805 | 804 |
/// |
... | ... |
@@ -809,3 +808,3 @@ |
809 | 808 |
|
810 |
///Checks if |
|
809 |
///Checks if the given node is reached from the root(s). |
|
811 | 810 |
|
... | ... |
@@ -835,3 +834,3 @@ |
835 | 834 |
///arcs of the shortest paths. |
836 |
///It must |
|
835 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
837 | 836 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
... | ... |
@@ -850,4 +849,4 @@ |
850 | 849 |
///The type of the map that indicates which nodes are processed. |
851 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
|
852 |
///By default it is a NullMap. |
|
850 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
851 |
///By default, it is a NullMap. |
|
853 | 852 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
... | ... |
@@ -870,3 +869,3 @@ |
870 | 869 |
///The type of the map that indicates which nodes are reached. |
871 |
///It must |
|
870 |
///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
872 | 871 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
... | ... |
@@ -885,3 +884,3 @@ |
885 | 884 |
///The type of the map that stores the distances of the nodes. |
886 |
///It must |
|
885 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
887 | 886 |
typedef typename Digraph::template NodeMap<int> DistMap; |
... | ... |
@@ -900,3 +899,3 @@ |
900 | 899 |
///The type of the shortest paths. |
901 |
///It must |
|
900 |
///It must conform to the \ref concepts::Path "Path" concept. |
|
902 | 901 |
typedef lemon::Path<Digraph> Path; |
... | ... |
@@ -906,8 +905,4 @@ |
906 | 905 |
|
907 |
/// To make it easier to use Bfs algorithm |
|
908 |
/// we have created a wizard class. |
|
909 |
/// This \ref BfsWizard class needs default traits, |
|
910 |
/// as well as the \ref Bfs class. |
|
911 |
/// The \ref BfsWizardBase is a class to be the default traits of the |
|
912 |
/// \ref BfsWizard class. |
|
906 |
/// Default traits class used by BfsWizard. |
|
907 |
/// \tparam GR The type of the digraph. |
|
913 | 908 |
template<class GR> |
... | ... |
@@ -939,3 +934,3 @@ |
939 | 934 |
|
940 |
/// This constructor does not require parameters, |
|
935 |
/// This constructor does not require parameters, it initiates |
|
941 | 936 |
/// all of the attributes to \c 0. |
... | ... |
@@ -969,3 +964,2 @@ |
969 | 964 |
|
970 |
///The type of the digraph the algorithm runs on. |
|
971 | 965 |
typedef typename TR::Digraph Digraph; |
... | ... |
@@ -977,12 +971,6 @@ |
977 | 971 |
|
978 |
///\brief The type of the map that stores the predecessor |
|
979 |
///arcs of the shortest paths. |
|
980 | 972 |
typedef typename TR::PredMap PredMap; |
981 |
///\brief The type of the map that stores the distances of the nodes. |
|
982 | 973 |
typedef typename TR::DistMap DistMap; |
983 |
///\brief The type of the map that indicates which nodes are reached. |
|
984 | 974 |
typedef typename TR::ReachedMap ReachedMap; |
985 |
///\brief The type of the map that indicates which nodes are processed. |
|
986 | 975 |
typedef typename TR::ProcessedMap ProcessedMap; |
987 |
///The type of the shortest paths |
|
988 | 976 |
typedef typename TR::Path Path; |
... | ... |
@@ -1056,4 +1044,4 @@ |
1056 | 1044 |
|
1057 |
///This method runs BFS algorithm in order to compute |
|
1058 |
///the shortest path to each node. |
|
1045 |
///This method runs BFS algorithm in order to visit all nodes |
|
1046 |
///in the digraph. |
|
1059 | 1047 |
void run() |
... | ... |
@@ -1069,7 +1057,8 @@ |
1069 | 1057 |
}; |
1070 |
///\brief \ref named-func-param "Named parameter" |
|
1071 |
///for setting PredMap object. |
|
1058 |
|
|
1059 |
///\brief \ref named-templ-param "Named parameter" for setting |
|
1060 |
///the predecessor map. |
|
1072 | 1061 |
/// |
1073 |
///\ref named-func-param "Named parameter" |
|
1074 |
///for setting PredMap object. |
|
1062 |
///\ref named-templ-param "Named parameter" function for setting |
|
1063 |
///the map that stores the predecessor arcs of the nodes. |
|
1075 | 1064 |
template<class T> |
... | ... |
@@ -1087,7 +1076,8 @@ |
1087 | 1076 |
}; |
1088 |
///\brief \ref named-func-param "Named parameter" |
|
1089 |
///for setting ReachedMap object. |
|
1077 |
|
|
1078 |
///\brief \ref named-templ-param "Named parameter" for setting |
|
1079 |
///the reached map. |
|
1090 | 1080 |
/// |
1091 |
/// \ref named-func-param "Named parameter" |
|
1092 |
///for setting ReachedMap object. |
|
1081 |
///\ref named-templ-param "Named parameter" function for setting |
|
1082 |
///the map that indicates which nodes are reached. |
|
1093 | 1083 |
template<class T> |
... | ... |
@@ -1105,7 +1095,9 @@ |
1105 | 1095 |
}; |
1106 |
///\brief \ref named-func-param "Named parameter" |
|
1107 |
///for setting DistMap object. |
|
1096 |
|
|
1097 |
///\brief \ref named-templ-param "Named parameter" for setting |
|
1098 |
///the distance map. |
|
1108 | 1099 |
/// |
1109 |
/// \ref named-func-param "Named parameter" |
|
1110 |
///for setting DistMap object. |
|
1100 |
///\ref named-templ-param "Named parameter" function for setting |
|
1101 |
///the map that stores the distances of the nodes calculated |
|
1102 |
///by the algorithm. |
|
1111 | 1103 |
template<class T> |
... | ... |
@@ -1123,7 +1115,8 @@ |
1123 | 1115 |
}; |
1124 |
///\brief \ref named-func-param "Named parameter" |
|
1125 |
///for setting ProcessedMap object. |
|
1116 |
|
|
1117 |
///\brief \ref named-func-param "Named parameter" for setting |
|
1118 |
///the processed map. |
|
1126 | 1119 |
/// |
1127 |
/// \ref named-func-param "Named parameter" |
|
1128 |
///for setting ProcessedMap object. |
|
1120 |
///\ref named-templ-param "Named parameter" function for setting |
|
1121 |
///the map that indicates which nodes are processed. |
|
1129 | 1122 |
template<class T> |
... | ... |
@@ -1266,3 +1259,3 @@ |
1266 | 1259 |
/// The type of the map that indicates which nodes are reached. |
1267 |
/// It must |
|
1260 |
/// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
1268 | 1261 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
... | ... |
@@ -1427,4 +1420,4 @@ |
1427 | 1420 |
/// member functions called \ref run(Node) "run()".\n |
1428 |
/// If you need more control on the execution, first you have to call |
|
1429 |
/// \ref init(), then you can add several source nodes with |
|
1421 |
/// If you need better control on the execution, you have to call |
|
1422 |
/// \ref init() first, then you can add several source nodes with |
|
1430 | 1423 |
/// \ref addSource(). Finally the actual path computation can be |
... | ... |
@@ -1700,8 +1693,4 @@ |
1700 | 1693 |
/// |
1701 |
/// This method runs the %BFS algorithm in order to |
|
1702 |
/// compute the shortest path to each node. |
|
1703 |
/// |
|
1704 |
/// The algorithm computes |
|
1705 |
/// - the shortest path tree (forest), |
|
1706 |
/// - the distance of each node from the root(s). |
|
1694 |
/// This method runs the %BFS algorithm in order to visit all nodes |
|
1695 |
/// in the digraph. |
|
1707 | 1696 |
/// |
... | ... |
@@ -1737,3 +1726,3 @@ |
1737 | 1726 |
|
1738 |
/// \brief Checks if |
|
1727 |
/// \brief Checks if the given node is reached from the root(s). |
|
1739 | 1728 |
/// |
... | ... |
@@ -21,5 +21,5 @@ |
21 | 21 |
|
22 |
///\ingroup |
|
22 |
///\ingroup heaps |
|
23 | 23 |
///\file |
24 |
///\brief Binary |
|
24 |
///\brief Binary heap implementation. |
|
25 | 25 |
|
... | ... |
@@ -31,41 +31,37 @@ |
31 | 31 |
|
32 |
///\ingroup |
|
32 |
/// \ingroup heaps |
|
33 | 33 |
/// |
34 |
///\brief |
|
34 |
/// \brief Binary heap data structure. |
|
35 | 35 |
/// |
36 |
///This class implements the \e binary \e heap data structure. |
|
36 |
/// This class implements the \e binary \e heap data structure. |
|
37 |
/// It fully conforms to the \ref concepts::Heap "heap concept". |
|
37 | 38 |
/// |
38 |
///A \e heap is a data structure for storing items with specified values |
|
39 |
///called \e priorities in such a way that finding the item with minimum |
|
40 |
///priority is efficient. \c CMP specifies the ordering of the priorities. |
|
41 |
///In a heap one can change the priority of an item, add or erase an |
|
42 |
///item, etc. |
|
43 |
/// |
|
44 |
///\tparam PR Type of the priority of the items. |
|
45 |
///\tparam IM A read and writable item map with int values, used internally |
|
46 |
///to handle the cross references. |
|
47 |
///\tparam CMP A functor class for the ordering of the priorities. |
|
48 |
///The default is \c std::less<PR>. |
|
49 |
/// |
|
50 |
///\sa FibHeap |
|
51 |
///\sa Dijkstra |
|
39 |
/// \tparam PR Type of the priorities of the items. |
|
40 |
/// \tparam IM A read-writable item map with \c int values, used |
|
41 |
/// internally to handle the cross references. |
|
42 |
/// \tparam CMP A functor class for comparing the priorities. |
|
43 |
/// The default is \c std::less<PR>. |
|
44 |
#ifdef DOXYGEN |
|
45 |
template <typename PR, typename IM, typename CMP> |
|
46 |
#else |
|
52 | 47 |
template <typename PR, typename IM, typename CMP = std::less<PR> > |
48 |
#endif |
|
53 | 49 |
class BinHeap { |
50 |
public: |
|
54 | 51 |
|
55 |
public: |
|
56 |
///\e |
|
52 |
/// Type of the item-int map. |
|
57 | 53 |
typedef IM ItemIntMap; |
58 |
/// |
|
54 |
/// Type of the priorities. |
|
59 | 55 |
typedef PR Prio; |
60 |
/// |
|
56 |
/// Type of the items stored in the heap. |
|
61 | 57 |
typedef typename ItemIntMap::Key Item; |
62 |
/// |
|
58 |
/// Type of the item-priority pairs. |
|
63 | 59 |
typedef std::pair<Item,Prio> Pair; |
64 |
/// |
|
60 |
/// Functor type for comparing the priorities. |
|
65 | 61 |
typedef CMP Compare; |
66 | 62 |
|
67 |
/// \brief Type to represent the |
|
63 |
/// \brief Type to represent the states of the items. |
|
68 | 64 |
/// |
69 |
/// Each Item element have a state associated to it. It may be "in heap", |
|
70 |
/// "pre heap" or "post heap". The latter two are indifferent from the |
|
65 |
/// Each item has a state associated to it. It can be "in heap", |
|
66 |
/// "pre-heap" or "post-heap". The latter two are indifferent from the |
|
71 | 67 |
/// heap's point of view, but may be useful to the user. |
... | ... |
@@ -86,18 +82,18 @@ |
86 | 82 |
public: |
87 |
|
|
83 |
|
|
84 |
/// \brief Constructor. |
|
88 | 85 |
/// |
89 |
/// The constructor. |
|
90 |
/// \param map should be given to the constructor, since it is used |
|
91 |
/// internally to handle the cross references. The value of the map |
|
92 |
/// must be \c PRE_HEAP (<tt>-1</tt>) for every item. |
|
86 |
/// Constructor. |
|
87 |
/// \param map A map that assigns \c int values to the items. |
|
88 |
/// It is used internally to handle the cross references. |
|
89 |
/// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item. |
|
93 | 90 |
explicit BinHeap(ItemIntMap &map) : _iim(map) {} |
94 | 91 |
|
95 |
/// \brief |
|
92 |
/// \brief Constructor. |
|
96 | 93 |
/// |
97 |
/// The constructor. |
|
98 |
/// \param map should be given to the constructor, since it is used |
|
99 |
/// internally to handle the cross references. The value of the map |
|
100 |
/// should be PRE_HEAP (-1) for each element. |
|
101 |
/// |
|
102 |
/// \param comp The comparator function object. |
|
94 |
/// Constructor. |
|
95 |
/// \param map A map that assigns \c int values to the items. |
|
96 |
/// It is used internally to handle the cross references. |
|
97 |
/// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item. |
|
98 |
/// \param comp The function object used for comparing the priorities. |
|
103 | 99 |
BinHeap(ItemIntMap &map, const Compare &comp) |
... | ... |
@@ -106,18 +102,19 @@ |
106 | 102 |
|
107 |
/// The number of items stored in the heap. |
|
103 |
/// \brief The number of items stored in the heap. |
|
108 | 104 |
/// |
109 |
/// |
|
105 |
/// This function returns the number of items stored in the heap. |
|
110 | 106 |
int size() const { return _data.size(); } |
111 | 107 |
|
112 |
/// \brief |
|
108 |
/// \brief Check if the heap is empty. |
|
113 | 109 |
/// |
114 |
/// |
|
110 |
/// This function returns \c true if the heap is empty. |
|
115 | 111 |
bool empty() const { return _data.empty(); } |
116 | 112 |
|
117 |
/// \brief Make |
|
113 |
/// \brief Make the heap empty. |
|
118 | 114 |
/// |
119 |
/// Make empty this heap. It does not change the cross reference map. |
|
120 |
/// If you want to reuse what is not surely empty you should first clear |
|
121 |
/// the heap and after that you should set the cross reference map for |
|
122 |
/// each item to \c PRE_HEAP. |
|
115 |
/// This functon makes the heap empty. |
|
116 |
/// It does not change the cross reference map. If you want to reuse |
|
117 |
/// a heap that is not surely empty, you should first clear it and |
|
118 |
/// then you should set the cross reference map to \c PRE_HEAP |
|
119 |
/// for each item. |
|
123 | 120 |
void clear() { |
... | ... |
@@ -129,3 +126,3 @@ |
129 | 126 |
|
130 |
static int |
|
127 |
static int secondChild(int i) { return 2*i+2; } |
|
131 | 128 |
bool less(const Pair &p1, const Pair &p2) const { |
... | ... |
@@ -134,3 +131,3 @@ |
134 | 131 |
|
135 |
int |
|
132 |
int bubbleUp(int hole, Pair p) { |
|
136 | 133 |
int par = parent(hole); |
... | ... |
@@ -145,4 +142,4 @@ |
145 | 142 |
|
146 |
int bubble_down(int hole, Pair p, int length) { |
|
147 |
int child = second_child(hole); |
|
143 |
int bubbleDown(int hole, Pair p, int length) { |
|
144 |
int child = secondChild(hole); |
|
148 | 145 |
while(child < length) { |
... | ... |
@@ -155,3 +152,3 @@ |
155 | 152 |
hole = child; |
156 |
child = |
|
153 |
child = secondChild(hole); |
|
157 | 154 |
} |
... | ... |
@@ -173,6 +170,9 @@ |
173 | 170 |
public: |
171 |
|
|
174 | 172 |
/// \brief Insert a pair of item and priority into the heap. |
175 | 173 |
/// |
176 |
/// |
|
174 |
/// This function inserts \c p.first to the heap with priority |
|
175 |
/// \c p.second. |
|
177 | 176 |
/// \param p The pair to insert. |
177 |
/// \pre \c p.first must not be stored in the heap. |
|
178 | 178 |
void push(const Pair &p) { |
... | ... |
@@ -180,17 +180,18 @@ |
180 | 180 |
_data.resize(n+1); |
181 |
|
|
181 |
bubbleUp(n, p); |
|
182 | 182 |
} |
183 | 183 |
|
184 |
/// \brief Insert an item into the heap with the given |
|
184 |
/// \brief Insert an item into the heap with the given priority. |
|
185 | 185 |
/// |
186 |
/// |
|
186 |
/// This function inserts the given item into the heap with the |
|
187 |
/// given priority. |
|
187 | 188 |
/// \param i The item to insert. |
188 | 189 |
/// \param p The priority of the item. |
190 |
/// \pre \e i must not be stored in the heap. |
|
189 | 191 |
void push(const Item &i, const Prio &p) { push(Pair(i,p)); } |
190 | 192 |
|
191 |
/// \brief |
|
193 |
/// \brief Return the item having minimum priority. |
|
192 | 194 |
/// |
193 |
/// This method returns the item with minimum priority relative to \c |
|
194 |
/// Compare. |
|
195 |
/// |
|
195 |
/// This function returns the item having minimum priority. |
|
196 |
/// \pre The heap must be non-empty. |
|
196 | 197 |
Item top() const { |
... | ... |
@@ -199,6 +200,6 @@ |
199 | 200 |
|
200 |
/// \brief |
|
201 |
/// \brief The minimum priority. |
|
201 | 202 |
/// |
202 |
/// It returns the minimum priority relative to \c Compare. |
|
203 |
/// \pre The heap must be nonempty. |
|
203 |
/// This function returns the minimum priority. |
|
204 |
/// \pre The heap must be non-empty. |
|
204 | 205 |
Prio prio() const { |
... | ... |
@@ -207,6 +208,5 @@ |
207 | 208 |
|
208 |
/// \brief |
|
209 |
/// \brief Remove the item having minimum priority. |
|
209 | 210 |
/// |
210 |
/// This method deletes the item with minimum priority relative to \c |
|
211 |
/// Compare from the heap. |
|
211 |
/// This function removes the item having minimum priority. |
|
212 | 212 |
/// \pre The heap must be non-empty. |
... | ... |
@@ -216,3 +216,3 @@ |
216 | 216 |
if (n > 0) { |
217 |
|
|
217 |
bubbleDown(0, _data[n], n); |
|
218 | 218 |
} |
... | ... |
@@ -221,7 +221,8 @@ |
221 | 221 |
|
222 |
/// \brief |
|
222 |
/// \brief Remove the given item from the heap. |
|
223 | 223 |
/// |
224 |
/// This method deletes item \c i from the heap. |
|
225 |
/// \param i The item to erase. |
|
226 |
/// |
|
224 |
/// This function removes the given item from the heap if it is |
|
225 |
/// already stored. |
|
226 |
/// \param i The item to delete. |
|
227 |
/// \pre \e i must be in the heap. |
|
227 | 228 |
void erase(const Item &i) { |
... | ... |
@@ -231,4 +232,4 @@ |
231 | 232 |
if( h < n ) { |
232 |
if ( bubble_up(h, _data[n]) == h) { |
|
233 |
bubble_down(h, _data[n], n); |
|
233 |
if ( bubbleUp(h, _data[n]) == h) { |
|
234 |
bubbleDown(h, _data[n], n); |
|
234 | 235 |
} |
... | ... |
@@ -238,8 +239,7 @@ |
238 | 239 |
|
239 |
|
|
240 |
/// \brief Returns the priority of \c i. |
|
240 |
/// \brief The priority of the given item. |
|
241 | 241 |
/// |
242 |
/// This function returns the priority of |
|
242 |
/// This function returns the priority of the given item. |
|
243 | 243 |
/// \param i The item. |
244 |
/// \pre \ |
|
244 |
/// \pre \e i must be in the heap. |
|
245 | 245 |
Prio operator[](const Item &i) const { |
... | ... |
@@ -249,7 +249,8 @@ |
249 | 249 |
|
250 |
/// \brief \c i gets to the heap with priority \c p independently |
|
251 |
/// if \c i was already there. |
|
250 |
/// \brief Set the priority of an item or insert it, if it is |
|
251 |
/// not stored in the heap. |
|
252 | 252 |
/// |
253 |
/// This method calls \ref push(\c i, \c p) if \c i is not stored |
|
254 |
/// in the heap and sets the priority of \c i to \c p otherwise. |
|
253 |
/// This method sets the priority of the given item if it is |
|
254 |
/// already stored in the heap. Otherwise it inserts the given |
|
255 |
/// item into the heap with the given priority. |
|
255 | 256 |
/// \param i The item. |
... | ... |
@@ -262,6 +263,6 @@ |
262 | 263 |
else if( _comp(p, _data[idx].second) ) { |
263 |
|
|
264 |
bubbleUp(idx, Pair(i,p)); |
|
264 | 265 |
} |
265 | 266 |
else { |
266 |
|
|
267 |
bubbleDown(idx, Pair(i,p), _data.size()); |
|
267 | 268 |
} |
... | ... |
@@ -269,33 +270,31 @@ |
269 | 270 |
|
270 |
/// \brief |
|
271 |
/// \brief Decrease the priority of an item to the given value. |
|
271 | 272 |
/// |
272 |
/// This |
|
273 |
/// This function decreases the priority of an item to the given value. |
|
273 | 274 |
/// \param i The item. |
274 | 275 |
/// \param p The priority. |
275 |
/// \pre \c i must be stored in the heap with priority at least \c |
|
276 |
/// p relative to \c Compare. |
|
276 |
/// \pre \e i must be stored in the heap with priority at least \e p. |
|
277 | 277 |
void decrease(const Item &i, const Prio &p) { |
278 | 278 |
int idx = _iim[i]; |
279 |
|
|
279 |
bubbleUp(idx, Pair(i,p)); |
|
280 | 280 |
} |
281 | 281 |
|
282 |
/// \brief |
|
282 |
/// \brief Increase the priority of an item to the given value. |
|
283 | 283 |
/// |
284 |
/// This |
|
284 |
/// This function increases the priority of an item to the given value. |
|
285 | 285 |
/// \param i The item. |
286 | 286 |
/// \param p The priority. |
287 |
/// \pre \c i must be stored in the heap with priority at most \c |
|
288 |
/// p relative to \c Compare. |
|
287 |
/// \pre \e i must be stored in the heap with priority at most \e p. |
|
289 | 288 |
void increase(const Item &i, const Prio &p) { |
290 | 289 |
int idx = _iim[i]; |
291 |
|
|
290 |
bubbleDown(idx, Pair(i,p), _data.size()); |
|
292 | 291 |
} |
293 | 292 |
|
294 |
/// \brief Returns if \c item is in, has already been in, or has |
|
295 |
/// never been in the heap. |
|
293 |
/// \brief Return the state of an item. |
|
296 | 294 |
/// |
297 |
/// This method returns PRE_HEAP if \c item has never been in the |
|
298 |
/// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP |
|
299 |
/// otherwise. In the latter case it is possible that \c item will |
|
300 |
/// get back to the heap again. |
|
295 |
/// This method returns \c PRE_HEAP if the given item has never |
|
296 |
/// been in the heap, \c IN_HEAP if it is in the heap at the moment, |
|
297 |
/// and \c POST_HEAP otherwise. |
|
298 |
/// In the latter case it is possible that the item will get back |
|
299 |
/// to the heap again. |
|
301 | 300 |
/// \param i The item. |
... | ... |
@@ -308,7 +307,7 @@ |
308 | 307 |
|
309 |
/// \brief |
|
308 |
/// \brief Set the state of an item in the heap. |
|
310 | 309 |
/// |
311 |
/// Sets the state of the \c item in the heap. It can be used to |
|
312 |
/// manually clear the heap when it is important to achive the |
|
313 |
/// |
|
310 |
/// This function sets the state of the given item in the heap. |
|
311 |
/// It can be used to manually clear the heap when it is important |
|
312 |
/// to achive better time complexity. |
|
314 | 313 |
/// \param i The item. |
... | ... |
@@ -329,8 +328,9 @@ |
329 | 328 |
|
330 |
/// \brief |
|
329 |
/// \brief Replace an item in the heap. |
|
331 | 330 |
/// |
332 |
/// The \c i item is replaced with \c j item. The \c i item should |
|
333 |
/// be in the heap, while the \c j should be out of the heap. The |
|
334 |
/// \c i item will out of the heap and \c j will be in the heap |
|
335 |
/// with the same prioriority as prevoiusly the \c i item. |
|
331 |
/// This function replaces item \c i with item \c j. |
|
332 |
/// Item \c i must be in the heap, while \c j must be out of the heap. |
|
333 |
/// After calling this method, item \c i will be out of the |
|
334 |
/// heap and \c j will be in the heap with the same prioriority |
|
335 |
/// as item \c i had before. |
|
336 | 336 |
void replace(const Item& i, const Item& j) { |
... | ... |
@@ -58,3 +58,3 @@ |
58 | 58 |
|
59 |
Node fromId(int id, Node) |
|
59 |
static Node fromId(int id, Node) { |
|
60 | 60 |
return Parent::nodeFromId(id); |
... | ... |
@@ -62,3 +62,3 @@ |
62 | 62 |
|
63 |
Arc fromId(int id, Arc) |
|
63 |
static Arc fromId(int id, Arc) { |
|
64 | 64 |
return Parent::arcFromId(id); |
... | ... |
@@ -357,3 +357,3 @@ |
357 | 357 |
|
358 |
Node fromId(int id, Node) |
|
358 |
static Node fromId(int id, Node) { |
|
359 | 359 |
return Parent::nodeFromId(id); |
... | ... |
@@ -361,3 +361,3 @@ |
361 | 361 |
|
362 |
Arc fromId(int id, Arc) |
|
362 |
static Arc fromId(int id, Arc) { |
|
363 | 363 |
return Parent::arcFromId(id); |
... | ... |
@@ -365,3 +365,3 @@ |
365 | 365 |
|
366 |
Edge fromId(int id, Edge) |
|
366 |
static Edge fromId(int id, Edge) { |
|
367 | 367 |
return Parent::edgeFromId(id); |
... | ... |
@@ -606,3 +606,3 @@ |
606 | 606 |
public: |
607 |
NodeMap(const Graph& graph) |
|
607 |
explicit NodeMap(const Graph& graph) |
|
608 | 608 |
: Parent(graph) {} |
... | ... |
@@ -630,3 +630,3 @@ |
630 | 630 |
public: |
631 |
ArcMap(const Graph& graph) |
|
631 |
explicit ArcMap(const Graph& graph) |
|
632 | 632 |
: Parent(graph) {} |
... | ... |
@@ -654,3 +654,3 @@ |
654 | 654 |
public: |
655 |
EdgeMap(const Graph& graph) |
|
655 |
explicit EdgeMap(const Graph& graph) |
|
656 | 656 |
: Parent(graph) {} |
... | ... |
@@ -21,5 +21,5 @@ |
21 | 21 |
|
22 |
///\ingroup |
|
22 |
///\ingroup heaps |
|
23 | 23 |
///\file |
24 |
///\brief Bucket |
|
24 |
///\brief Bucket heap implementation. |
|
25 | 25 |
|
... | ... |
@@ -55,19 +55,24 @@ |
55 | 55 |
|
56 |
/// \ingroup |
|
56 |
/// \ingroup heaps |
|
57 | 57 |
/// |
58 |
/// \brief |
|
58 |
/// \brief Bucket heap data structure. |
|
59 | 59 |
/// |
60 |
/// This class implements the \e bucket \e heap data structure. A \e heap |
|
61 |
/// is a data structure for storing items with specified values called \e |
|
62 |
/// priorities in such a way that finding the item with minimum priority is |
|
63 |
/// efficient. The bucket heap is very simple implementation, it can store |
|
64 |
/// only integer priorities and it stores for each priority in the |
|
65 |
/// \f$ [0..C) \f$ range a list of items. So it should be used only when |
|
66 |
/// the |
|
60 |
/// This class implements the \e bucket \e heap data structure. |
|
61 |
/// It practically conforms to the \ref concepts::Heap "heap concept", |
|
62 |
/// but it has some limitations. |
|
67 | 63 |
/// |
68 |
/// \param IM A read and write Item int map, used internally |
|
69 |
/// to handle the cross references. |
|
70 |
/// \param MIN If the given parameter is false then instead of the |
|
71 |
/// minimum value the maximum can be retrivied with the top() and |
|
72 |
/// |
|
64 |
/// The bucket heap is a very simple structure. It can store only |
|
65 |
/// \c int priorities and it maintains a list of items for each priority |
|
66 |
/// in the range <tt>[0..C)</tt>. So it should only be used when the |
|
67 |
/// priorities are small. It is not intended to use as a Dijkstra heap. |
|
68 |
/// |
|
69 |
/// \tparam IM A read-writable item map with \c int values, used |
|
70 |
/// internally to handle the cross references. |
|
71 |
/// \tparam MIN Indicate if the heap is a \e min-heap or a \e max-heap. |
|
72 |
/// The default is \e min-heap. If this parameter is set to \c false, |
|
73 |
/// then the comparison is reversed, so the top(), prio() and pop() |
|
74 |
/// functions deal with the item having maximum priority instead of the |
|
75 |
/// minimum. |
|
76 |
/// |
|
77 |
/// \sa SimpleBucketHeap |
|
73 | 78 |
template <typename IM, bool MIN = true> |
... | ... |
@@ -76,10 +81,11 @@ |
76 | 81 |
public: |
77 |
/// \e |
|
78 |
typedef typename IM::Key Item; |
|
79 |
|
|
82 |
|
|
83 |
/// Type of the item-int map. |
|
84 |
typedef IM ItemIntMap; |
|
85 |
/// Type of the priorities. |
|
80 | 86 |
typedef int Prio; |
81 |
/// \e |
|
82 |
typedef std::pair<Item, Prio> Pair; |
|
83 |
/// \e |
|
84 |
typedef IM ItemIntMap; |
|
87 |
/// Type of the items stored in the heap. |
|
88 |
typedef typename ItemIntMap::Key Item; |
|
89 |
/// Type of the item-priority pairs. |
|
90 |
typedef std::pair<Item,Prio> Pair; |
|
85 | 91 |
|
... | ... |
@@ -91,6 +97,6 @@ |
91 | 97 |
|
92 |
/// \brief Type to represent the |
|
98 |
/// \brief Type to represent the states of the items. |
|
93 | 99 |
/// |
94 |
/// Each Item element have a state associated to it. It may be "in heap", |
|
95 |
/// "pre heap" or "post heap". The latter two are indifferent from the |
|
100 |
/// Each item has a state associated to it. It can be "in heap", |
|
101 |
/// "pre-heap" or "post-heap". The latter two are indifferent from the |
|
96 | 102 |
/// heap's point of view, but may be useful to the user. |
... | ... |
@@ -106,26 +112,28 @@ |
106 | 112 |
public: |
107 |
|
|
113 |
|
|
114 |
/// \brief Constructor. |
|
108 | 115 |
/// |
109 |
/// The constructor. |
|
110 |
/// \param map should be given to the constructor, since it is used |
|
111 |
/// internally to handle the cross references. The value of the map |
|
112 |
/// should be PRE_HEAP (-1) for each element. |
|
116 |
/// Constructor. |
|
117 |
/// \param map A map that assigns \c int values to the items. |
|
118 |
/// It is used internally to handle the cross references. |
|
119 |
/// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item. |
|
113 | 120 |
explicit BucketHeap(ItemIntMap &map) : _iim(map), _minimum(0) {} |
114 | 121 |
|
115 |
/// The number of items stored in the heap. |
|
122 |
/// \brief The number of items stored in the heap. |
|
116 | 123 |
/// |
117 |
/// |
|
124 |
/// This function returns the number of items stored in the heap. |
|
118 | 125 |
int size() const { return _data.size(); } |
119 | 126 |
|
120 |
/// \brief |
|
127 |
/// \brief Check if the heap is empty. |
|
121 | 128 |
/// |
122 |
/// |
|
129 |
/// This function returns \c true if the heap is empty. |
|
123 | 130 |
bool empty() const { return _data.empty(); } |
124 | 131 |
|
125 |
/// \brief Make |
|
132 |
/// \brief Make the heap empty. |
|
126 | 133 |
/// |
127 |
/// Make empty this heap. It does not change the cross reference |
|
128 |
/// map. If you want to reuse a heap what is not surely empty you |
|
129 |
/// should first clear the heap and after that you should set the |
|
130 |
/// cross reference map for each item to \c PRE_HEAP. |
|
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. |
|
131 | 139 |
void clear() { |
... | ... |
@@ -136,3 +144,3 @@ |
136 | 144 |
|
137 |
void |
|
145 |
void relocateLast(int idx) { |
|
138 | 146 |
if (idx + 1 < int(_data.size())) { |
... | ... |
@@ -176,6 +184,9 @@ |
176 | 184 |
public: |
185 |
|
|
177 | 186 |
/// \brief Insert a pair of item and priority into the heap. |
178 | 187 |
/// |
179 |
/// |
|
188 |
/// This function inserts \c p.first to the heap with priority |
|
189 |
/// \c p.second. |
|
180 | 190 |
/// \param p The pair to insert. |
191 |
/// \pre \c p.first must not be stored in the heap. |
|
181 | 192 |
void push(const Pair& p) { |
... | ... |
@@ -186,5 +197,7 @@ |
186 | 197 |
/// |
187 |
/// |
|
198 |
/// This function inserts the given item into the heap with the |
|
199 |
/// given priority. |
|
188 | 200 |
/// \param i The item to insert. |
189 | 201 |
/// \param p The priority of the item. |
202 |
/// \pre \e i must not be stored in the heap. |
|
190 | 203 |
void push(const Item &i, const Prio &p) { |
... | ... |
@@ -199,6 +212,6 @@ |
199 | 212 |
|
200 |
/// \brief |
|
213 |
/// \brief Return the item having minimum priority. |
|
201 | 214 |
/// |
202 |
/// This method returns the item with minimum priority. |
|
203 |
/// \pre The heap must be nonempty. |
|
215 |
/// This function returns the item having minimum priority. |
|
216 |
/// \pre The heap must be non-empty. |
|
204 | 217 |
Item top() const { |
... | ... |
@@ -210,6 +223,6 @@ |
210 | 223 |
|
211 |
/// \brief |
|
224 |
/// \brief The minimum priority. |
|
212 | 225 |
/// |
213 |
/// It returns the minimum priority. |
|
214 |
/// \pre The heap must be nonempty. |
|
226 |
/// This function returns the minimum priority. |
|
227 |
/// \pre The heap must be non-empty. |
|
215 | 228 |
Prio prio() const { |
... | ... |
@@ -221,5 +234,5 @@ |
221 | 234 |
|
222 |
/// \brief |
|
235 |
/// \brief Remove the item having minimum priority. |
|
223 | 236 |
/// |
224 |
/// This |
|
237 |
/// This function removes the item having minimum priority. |
|
225 | 238 |
/// \pre The heap must be non-empty. |
... | ... |
@@ -232,10 +245,11 @@ |
232 | 245 |
unlace(idx); |
233 |
|
|
246 |
relocateLast(idx); |
|
234 | 247 |
} |
235 | 248 |
|
236 |
/// \brief |
|
249 |
/// \brief Remove the given item from the heap. |
|
237 | 250 |
/// |
238 |
/// This method deletes item \c i from the heap, if \c i was |
|
239 |
/// already stored in the heap. |
|
240 |
/// |
|
251 |
/// This function removes the given item from the heap if it is |
|
252 |
/// already stored. |
|
253 |
/// \param i The item to delete. |
|
254 |
/// \pre \e i must be in the heap. |
|
241 | 255 |
void erase(const Item &i) { |
... | ... |
@@ -244,11 +258,10 @@ |
244 | 258 |
unlace(idx); |
245 |
|
|
259 |
relocateLast(idx); |
|
246 | 260 |
} |
247 | 261 |
|
248 |
|
|
249 |
/// \brief Returns the priority of \c i. |
|
262 |
/// \brief The priority of the given item. |
|
250 | 263 |
/// |
251 |
/// This function returns the priority of item \c i. |
|
252 |
/// \pre \c i must be in the heap. |
|
264 |
/// This function returns the priority of the given item. |
|
253 | 265 |
/// \param i The item. |
266 |
/// \pre \e i must be in the heap. |
|
254 | 267 |
Prio operator[](const Item &i) const { |
... | ... |
@@ -258,7 +271,8 @@ |
258 | 271 |
|
259 |
/// \brief \c i gets to the heap with priority \c p independently |
|
260 |
/// if \c i was already there. |
|
272 |
/// \brief Set the priority of an item or insert it, if it is |
|
273 |
/// not stored in the heap. |
|
261 | 274 |
/// |
262 |
/// This method calls \ref push(\c i, \c p) if \c i is not stored |
|
263 |
/// in the heap and sets the priority of \c i to \c p otherwise. |
|
275 |
/// This method sets the priority of the given item if it is |
|
276 |
/// already stored in the heap. Otherwise it inserts the given |
|
277 |
/// item into the heap with the given priority. |
|
264 | 278 |
/// \param i The item. |
... | ... |
@@ -276,9 +290,8 @@ |
276 | 290 |
|
277 |
/// \brief |
|
291 |
/// \brief Decrease the priority of an item to the given value. |
|
278 | 292 |
/// |
279 |
/// This method decreases the priority of item \c i to \c p. |
|
280 |
/// \pre \c i must be stored in the heap with priority at least \c |
|
281 |
/// |
|
293 |
/// This function decreases the priority of an item to the given value. |
|
282 | 294 |
/// \param i The item. |
283 | 295 |
/// \param p The priority. |
296 |
/// \pre \e i must be stored in the heap with priority at least \e p. |
|
284 | 297 |
void decrease(const Item &i, const Prio &p) { |
... | ... |
@@ -293,9 +306,8 @@ |
293 | 306 |
|
294 |
/// \brief |
|
307 |
/// \brief Increase the priority of an item to the given value. |
|
295 | 308 |
/// |
296 |
/// This method sets the priority of item \c i to \c p. |
|
297 |
/// \pre \c i must be stored in the heap with priority at most \c |
|
298 |
/// |
|
309 |
/// This function increases the priority of an item to the given value. |
|
299 | 310 |
/// \param i The item. |
300 | 311 |
/// \param p The priority. |
312 |
/// \pre \e i must be stored in the heap with priority at most \e p. |
|
301 | 313 |
void increase(const Item &i, const Prio &p) { |
... | ... |
@@ -307,9 +319,9 @@ |
307 | 319 |
|
308 |
/// \brief Returns if \c item is in, has already been in, or has |
|
309 |
/// never been in the heap. |
|
320 |
/// \brief Return the state of an item. |
|
310 | 321 |
/// |
311 |
/// This method returns PRE_HEAP if \c item has never been in the |
|
312 |
/// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP |
|
313 |
/// otherwise. In the latter case it is possible that \c item will |
|
314 |
/// get back to the heap again. |
|
322 |
/// This method returns \c PRE_HEAP if the given item has never |
|
323 |
/// been in the heap, \c IN_HEAP if it is in the heap at the moment, |
|
324 |
/// and \c POST_HEAP otherwise. |
|
325 |
/// In the latter case it is possible that the item will get back |
|
326 |
/// to the heap again. |
|
315 | 327 |
/// \param i The item. |
... | ... |
@@ -321,7 +333,7 @@ |
321 | 333 |
|
322 |
/// \brief |
|
334 |
/// \brief Set the state of an item in the heap. |
|
323 | 335 |
/// |
324 |
/// Sets the state of the \c item in the heap. It can be used to |
|
325 |
/// manually clear the heap when it is important to achive the |
|
326 |
/// |
|
336 |
/// This function sets the state of the given item in the heap. |
|
337 |
/// It can be used to manually clear the heap when it is important |
|
338 |
/// to achive better time complexity. |
|
327 | 339 |
/// \param i The item. |
... | ... |
@@ -361,19 +373,25 @@ |
361 | 373 |
|
362 |
/// \ingroup |
|
374 |
/// \ingroup heaps |
|
363 | 375 |
/// |
364 |
/// \brief |
|
376 |
/// \brief Simplified bucket heap data structure. |
|
365 | 377 |
/// |
366 | 378 |
/// This class implements a simplified \e bucket \e heap data |
367 |
/// structure. It does not provide some functionality but it faster |
|
368 |
/// and simplier data structure than the BucketHeap. The main |
|
369 |
/// difference is that the BucketHeap stores for every key a double |
|
370 |
/// linked list while this class stores just simple lists. In the |
|
371 |
/// other way it does not support erasing each elements just the |
|
372 |
/// minimal and it does not supports key increasing, decreasing. |
|
379 |
/// structure. It does not provide some functionality, but it is |
|
380 |
/// faster and simpler than BucketHeap. The main difference is |
|
381 |
/// that BucketHeap stores a doubly-linked list for each key while |
|
382 |
/// this class stores only simply-linked lists. It supports erasing |
|
383 |
/// only for the item having minimum priority and it does not support |
|
384 |
/// key increasing and decreasing. |
|
373 | 385 |
/// |
374 |
/// \param IM A read and write Item int map, used internally |
|
375 |
/// to handle the cross references. |
|
376 |
/// \param MIN If the given parameter is false then instead of the |
|
377 |
/// minimum value the maximum can be retrivied with the top() and |
|
378 |
/// |
|
386 |
/// Note that this implementation does not conform to the |
|
387 |
/// \ref concepts::Heap "heap concept" due to the lack of some |
|
388 |
/// functionality. |
|
389 |
/// |
|
390 |
/// \tparam IM A read-writable item map with \c int values, used |
|
391 |
/// internally to handle the cross references. |
|
392 |
/// \tparam MIN Indicate if the heap is a \e min-heap or a \e max-heap. |
|
393 |
/// The default is \e min-heap. If this parameter is set to \c false, |
|
394 |
/// then the comparison is reversed, so the top(), prio() and pop() |
|
395 |
/// functions deal with the item having maximum priority instead of the |
|
396 |
/// minimum. |
|
379 | 397 |
/// |
... | ... |
@@ -384,6 +402,11 @@ |
384 | 402 |
public: |
385 |
|
|
403 |
|
|
404 |
/// Type of the item-int map. |
|
405 |
typedef IM ItemIntMap; |
|
406 |
/// Type of the priorities. |
|
386 | 407 |
typedef int Prio; |
387 |
typedef std::pair<Item, Prio> Pair; |
|
388 |
typedef IM ItemIntMap; |
|
408 |
/// Type of the items stored in the heap. |
|
409 |
typedef typename ItemIntMap::Key Item; |
|
410 |
/// Type of the item-priority pairs. |
|
411 |
typedef std::pair<Item,Prio> Pair; |
|
389 | 412 |
|
... | ... |
@@ -395,6 +418,6 @@ |
395 | 418 |
|
396 |
/// \brief Type to represent the |
|
419 |
/// \brief Type to represent the states of the items. |
|
397 | 420 |
/// |
398 |
/// Each Item element have a state associated to it. It may be "in heap", |
|
399 |
/// "pre heap" or "post heap". The latter two are indifferent from the |
|
421 |
/// Each item has a state associated to it. It can be "in heap", |
|
422 |
/// "pre-heap" or "post-heap". The latter two are indifferent from the |
|
400 | 423 |
/// heap's point of view, but may be useful to the user. |
... | ... |
@@ -411,8 +434,8 @@ |
411 | 434 |
|
412 |
/// \brief |
|
435 |
/// \brief Constructor. |
|
413 | 436 |
/// |
414 |
/// The constructor. |
|
415 |
/// \param map should be given to the constructor, since it is used |
|
416 |
/// internally to handle the cross references. The value of the map |
|
417 |
/// should be PRE_HEAP (-1) for each element. |
|
437 |
/// Constructor. |
|
438 |
/// \param map A map that assigns \c int values to the items. |
|
439 |
/// It is used internally to handle the cross references. |
|
440 |
/// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item. |
|
418 | 441 |
explicit SimpleBucketHeap(ItemIntMap &map) |
... | ... |
@@ -420,18 +443,19 @@ |
420 | 443 |
|
421 |
/// \brief |
|
444 |
/// \brief The number of items stored in the heap. |
|
422 | 445 |
/// |
423 |
/// |
|
446 |
/// This function returns the number of items stored in the heap. |
|
424 | 447 |
int size() const { return _num; } |
425 | 448 |
|
426 |
/// \brief |
|
449 |
/// \brief Check if the heap is empty. |
|
427 | 450 |
/// |
428 |
/// |
|
451 |
/// This function returns \c true if the heap is empty. |
|
429 | 452 |
bool empty() const { return _num == 0; } |
430 | 453 |
|
431 |
/// \brief Make |
|
454 |
/// \brief Make the heap empty. |
|
432 | 455 |
/// |
433 |
/// Make empty this heap. It does not change the cross reference |
|
434 |
/// map. If you want to reuse a heap what is not surely empty you |
|
435 |
/// should first clear the heap and after that you should set the |
|
436 |
/// cross reference map for each item to \c PRE_HEAP. |
|
456 |
/// This functon makes the heap empty. |
|
457 |
/// It does not change the cross reference map. If you want to reuse |
|
458 |
/// a heap that is not surely empty, you should first clear it and |
|
459 |
/// then you should set the cross reference map to \c PRE_HEAP |
|
460 |
/// for each item. |
|
437 | 461 |
void clear() { |
... | ... |
@@ -442,4 +466,6 @@ |
442 | 466 |
/// |
443 |
/// |
|
467 |
/// This function inserts \c p.first to the heap with priority |
|
468 |
/// \c p.second. |
|
444 | 469 |
/// \param p The pair to insert. |
470 |
/// \pre \c p.first must not be stored in the heap. |
|
445 | 471 |
void push(const Pair& p) { |
... | ... |
@@ -450,5 +476,7 @@ |
450 | 476 |
/// |
451 |
/// |
|
477 |
/// This function inserts the given item into the heap with the |
|
478 |
/// given priority. |
|
452 | 479 |
/// \param i The item to insert. |
453 | 480 |
/// \param p The priority of the item. |
481 |
/// \pre \e i must not be stored in the heap. |
|
454 | 482 |
void push(const Item &i, const Prio &p) { |
... | ... |
@@ -473,6 +501,6 @@ |
473 | 501 |
|
474 |
/// \brief |
|
502 |
/// \brief Return the item having minimum priority. |
|
475 | 503 |
/// |
476 |
/// This method returns the item with minimum priority. |
|
477 |
/// \pre The heap must be nonempty. |
|
504 |
/// This function returns the item having minimum priority. |
|
505 |
/// \pre The heap must be non-empty. |
|
478 | 506 |
Item top() const { |
... | ... |
@@ -484,6 +512,6 @@ |
484 | 512 |
|
485 |
/// \brief |
|
513 |
/// \brief The minimum priority. |
|
486 | 514 |
/// |
487 |
/// It returns the minimum priority. |
|
488 |
/// \pre The heap must be nonempty. |
|
515 |
/// This function returns the minimum priority. |
|
516 |
/// \pre The heap must be non-empty. |
|
489 | 517 |
Prio prio() const { |
... | ... |
@@ -495,5 +523,5 @@ |
495 | 523 |
|
496 |
/// \brief |
|
524 |
/// \brief Remove the item having minimum priority. |
|
497 | 525 |
/// |
498 |
/// This |
|
526 |
/// This function removes the item having minimum priority. |
|
499 | 527 |
/// \pre The heap must be non-empty. |
... | ... |
@@ -511,12 +539,11 @@ |
511 | 539 |
|
512 |
/// \brief |
|
540 |
/// \brief The priority of the given item. |
|
513 | 541 |
/// |
514 |
/// This function returns the priority of item \c i. |
|
515 |
/// \warning This operator is not a constant time function |
|
516 |
/// because it scans the whole data structure to find the proper |
|
517 |
/// value. |
|
518 |
/// |
|
542 |
/// This function returns the priority of the given item. |
|
519 | 543 |
/// \param i The item. |
544 |
/// \pre \e i must be in the heap. |
|
545 |
/// \warning This operator is not a constant time function because |
|
546 |
/// it scans the whole data structure to find the proper value. |
|
520 | 547 |
Prio operator[](const Item &i) const { |
521 |
for (int k = 0; k < _first.size(); ++k) { |
|
548 |
for (int k = 0; k < int(_first.size()); ++k) { |
|
522 | 549 |
int idx = _first[k]; |
... | ... |
@@ -532,9 +559,9 @@ |
532 | 559 |
|
533 |
/// \brief Returns if \c item is in, has already been in, or has |
|
534 |
/// never been in the heap. |
|
560 |
/// \brief Return the state of an item. |
|
535 | 561 |
/// |
536 |
/// This method returns PRE_HEAP if \c item has never been in the |
|
537 |
/// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP |
|
538 |
/// otherwise. In the latter case it is possible that \c item will |
|
539 |
/// get back to the heap again. |
|
562 |
/// This method returns \c PRE_HEAP if the given item has never |
|
563 |
/// been in the heap, \c IN_HEAP if it is in the heap at the moment, |
|
564 |
/// and \c POST_HEAP otherwise. |
|
565 |
/// In the latter case it is possible that the item will get back |
|
566 |
/// to the heap again. |
|
540 | 567 |
/// \param i The item. |
... | ... |
@@ -96,2 +96,14 @@ |
96 | 96 |
|
97 |
int CbcMip::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) { |
|
98 |
std::vector<int> indexes; |
|
99 |
std::vector<Value> values; |
|
100 |
|
|
101 |
for(ExprIterator it = b; it != e; ++it) { |
|
102 |
indexes.push_back(it->first); |
|
103 |
values.push_back(it->second); |
|
104 |
} |
|
105 |
|
|
106 |
_prob->addRow(values.size(), &indexes.front(), &values.front(), l, u); |
|
107 |
return _prob->numberRows() - 1; |
|
108 |
} |
|
97 | 109 |
... | ... |
@@ -74,3 +74,7 @@ |
74 | 74 |
/// concept. |
75 |
#ifdef DOXYGEN |
|
76 |
typedef GR::ArcMap<Value> FlowMap; |
|
77 |
#else |
|
75 | 78 |
typedef typename Digraph::template ArcMap<Value> FlowMap; |
79 |
#endif |
|
76 | 80 |
|
... | ... |
@@ -89,5 +93,8 @@ |
89 | 93 |
/// |
90 |
/// \sa Elevator |
|
91 |
/// \sa LinkedElevator |
|
94 |
/// \sa Elevator, LinkedElevator |
|
95 |
#ifdef DOXYGEN |
|
96 |
typedef lemon::Elevator<GR, GR::Node> Elevator; |
|
97 |
#else |
|
92 | 98 |
typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator; |
99 |
#endif |
|
93 | 100 |
|
... | ... |
@@ -301,3 +308,3 @@ |
301 | 308 |
/// digraph and the maximum level should be passed to it). |
302 |
/// However an external elevator object could also be passed to the |
|
309 |
/// However, an external elevator object could also be passed to the |
|
303 | 310 |
/// algorithm with the \ref elevator(Elevator&) "elevator()" function |
... | ... |
@@ -452,6 +459,7 @@ |
452 | 459 |
|
453 |
/// \brief Sets the tolerance used by algorithm. |
|
460 |
/// \brief Sets the tolerance used by the algorithm. |
|
454 | 461 |
/// |
455 |
/// Sets the tolerance used by algorithm. |
|
456 |
Circulation& tolerance(const Tolerance& tolerance) const { |
|
462 |
/// Sets the tolerance object used by the algorithm. |
|
463 |
/// \return <tt>(*this)</tt> |
|
464 |
Circulation& tolerance(const Tolerance& tolerance) { |
|
457 | 465 |
_tol = tolerance; |
... | ... |
@@ -462,5 +470,6 @@ |
462 | 470 |
/// |
463 |
/// Returns a const reference to the tolerance |
|
471 |
/// Returns a const reference to the tolerance object used by |
|
472 |
/// the algorithm. |
|
464 | 473 |
const Tolerance& tolerance() const { |
465 |
return |
|
474 |
return _tol; |
|
466 | 475 |
} |
... | ... |
@@ -469,4 +478,4 @@ |
469 | 478 |
/// The simplest way to execute the algorithm is to call \ref run().\n |
470 |
/// If you need more control on the initial solution or the execution, |
|
471 |
/// first you have to call one of the \ref init() functions, then |
|
479 |
/// If you need better control on the initial solution or the execution, |
|
480 |
/// you have to call one of the \ref init() functions first, then |
|
472 | 481 |
/// the \ref start() function. |
... | ... |
@@ -80,2 +80,15 @@ |
80 | 80 |
|
81 |
int ClpLp::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) { |
|
82 |
std::vector<int> indexes; |
|
83 |
std::vector<Value> values; |
|
84 |
|
|
85 |
for(ExprIterator it = b; it != e; ++it) { |
|
86 |
indexes.push_back(it->first); |
|
87 |
values.push_back(it->second); |
|
88 |
} |
|
89 |
|
|
90 |
_prob->addRow(values.size(), &indexes.front(), &values.front(), l, u); |
|
91 |
return _prob->numberRows() - 1; |
|
92 |
} |
|
93 |
|
|
81 | 94 |
... | ... |
@@ -37,32 +37,26 @@ |
37 | 37 |
/// |
38 |
/// This class describes the \ref concept "concept" of the |
|
39 |
/// immutable directed digraphs. |
|
38 |
/// This class describes the common interface of all directed |
|
39 |
/// graphs (digraphs). |
|
40 | 40 |
/// |
41 |
/// Note that actual digraph implementation like @ref ListDigraph or |
|
42 |
/// @ref SmartDigraph may have several additional functionality. |
|
41 |
/// Like all concept classes, it only provides an interface |
|
42 |
/// without any sensible implementation. So any general algorithm for |
|
43 |
/// directed graphs should compile with this class, but it will not |
|
44 |
/// run properly, of course. |
|
45 |
/// An actual digraph implementation like \ref ListDigraph or |
|
46 |
/// \ref SmartDigraph may have additional functionality. |
|
43 | 47 |
/// |
44 |
/// \sa |
|
48 |
/// \sa Graph |
|
45 | 49 |
class Digraph { |
46 | 50 |
private: |
47 |
/// |
|
51 |
/// Diraphs are \e not copy constructible. Use DigraphCopy instead. |
|
52 |
Digraph(const Digraph &) {} |
|
53 |
/// \brief Assignment of a digraph to another one is \e not allowed. |
|
54 |
/// Use DigraphCopy instead. |
|
55 |
void operator=(const Digraph &) {} |
|
48 | 56 |
|
49 |
///Digraphs are \e not copy constructible. Use DigraphCopy() instead. |
|
50 |
/// |
|
51 |
Digraph(const Digraph &) {}; |
|
52 |
///\brief Assignment of \ref Digraph "Digraph"s to another ones are |
|
53 |
|
|
57 |
public: |
|
58 |
/// Default constructor. |
|
59 |
Digraph() { } |
|
54 | 60 |
|
55 |
///Assignment of \ref Digraph "Digraph"s to another ones are |
|
56 |
///\e not allowed. Use DigraphCopy() instead. |
|
57 |
|
|
58 |
void operator=(const Digraph &) {} |
|
59 |
public: |
|
60 |
///\e |
|
61 |
|
|
62 |
/// Defalult constructor. |
|
63 |
|
|
64 |
/// Defalult constructor. |
|
65 |
/// |
|
66 |
Digraph() { } |
|
67 |
/// |
|
61 |
/// The node type of the digraph |
|
68 | 62 |
|
... | ... |
@@ -70,3 +64,3 @@ |
70 | 64 |
/// as a base class of the node iterators, |
71 |
/// thus they |
|
65 |
/// thus they convert to this type. |
|
72 | 66 |
class Node { |
... | ... |
@@ -75,4 +69,4 @@ |
75 | 69 |
|
76 |
/// @warning The default constructor sets the iterator |
|
77 |
/// to an undefined value. |
|
70 |
/// Default constructor. |
|
71 |
/// \warning It sets the object to an undefined value. |
|
78 | 72 |
Node() { } |
... | ... |
@@ -84,5 +78,5 @@ |
84 | 78 |
|
85 |
/// Invalid constructor \& conversion. |
|
79 |
/// %Invalid constructor \& conversion. |
|
86 | 80 |
|
87 |
/// |
|
81 |
/// Initializes the object to be invalid. |
|
88 | 82 |
/// \sa Invalid for more details. |
... | ... |
@@ -91,4 +85,6 @@ |
91 | 85 |
|
86 |
/// Equality operator. |
|
87 |
/// |
|
92 | 88 |
/// Two iterators are equal if and only if they point to the |
93 |
/// same object or both are |
|
89 |
/// same object or both are \c INVALID. |
|
94 | 90 |
bool operator==(Node) const { return true; } |
... | ... |
@@ -97,4 +93,3 @@ |
97 | 93 |
|
98 |
/// \sa operator==(Node n) |
|
99 |
/// |
|
94 |
/// Inequality operator. |
|
100 | 95 |
bool operator!=(Node) const { return true; } |
... | ... |
@@ -103,17 +98,15 @@ |
103 | 98 |
|
104 |
/// To allow the use of digraph descriptors as key type in std::map or |
|
105 |
/// similar associative container we require this. |
|
99 |
/// Artificial ordering operator. |
|
106 | 100 |
/// |
107 |
/// \note This operator only have to define some strict ordering of |
|
108 |
/// the items; this order has nothing to do with the iteration |
|
109 |
/// ordering of |
|
101 |
/// \note This operator only has to define some strict ordering of |
|
102 |
/// the nodes; this order has nothing to do with the iteration |
|
103 |
/// ordering of the nodes. |
|
110 | 104 |
bool operator<(Node) const { return false; } |
111 |
|
|
112 | 105 |
}; |
113 | 106 |
|
114 |
/// |
|
107 |
/// Iterator class for the nodes. |
|
115 | 108 |
|
116 |
/// This iterator goes through each node. |
|
117 |
/// Its usage is quite simple, for example you can count the number |
|
118 |
/// |
|
109 |
/// This iterator goes through each node of the digraph. |
|
110 |
/// Its usage is quite simple, for example, you can count the number |
|
111 |
/// of nodes in a digraph \c g of type \c %Digraph like this: |
|
119 | 112 |
///\code |
... | ... |
@@ -126,4 +119,4 @@ |
126 | 119 |
|
127 |
/// @warning The default constructor sets the iterator |
|
128 |
/// to an undefined value. |
|
120 |
/// Default constructor. |
|
121 |
/// \warning It sets the iterator to an undefined value. |
|
129 | 122 |
NodeIt() { } |
... | ... |
@@ -134,5 +127,5 @@ |
134 | 127 |
NodeIt(const NodeIt& n) : Node(n) { } |
135 |
/// Invalid constructor \& conversion. |
|
128 |
/// %Invalid constructor \& conversion. |
|
136 | 129 |
|
137 |
/// |
|
130 |
/// Initializes the iterator to be invalid. |
|
138 | 131 |
/// \sa Invalid for more details. |
... | ... |
@@ -141,11 +134,9 @@ |
141 | 134 |
|
142 |
/// Sets the iterator to the first node of |
|
135 |
/// Sets the iterator to the first node of the given digraph. |
|
143 | 136 |
/// |
144 |
NodeIt(const Digraph&) { } |
|
145 |
/// Node -> NodeIt conversion. |
|
137 |
explicit NodeIt(const Digraph&) { } |
|
138 |
/// Sets the iterator to the given node. |
|
146 | 139 |
|
147 |
/// Sets the iterator to the node of \c the digraph pointed by |
|
148 |
/// the trivial iterator. |
|
149 |
/// This feature necessitates that each time we |
|
150 |
/// iterate the arc-set, the iteration order is the same. |
|
140 |
/// Sets the iterator to the given node of the given digraph. |
|
141 |
/// |
|
151 | 142 |
NodeIt(const Digraph&, const Node&) { } |
... | ... |
@@ -159,3 +150,3 @@ |
159 | 150 |
|
160 |
/// |
|
151 |
/// The arc type of the digraph |
|
161 | 152 |
|
... | ... |
@@ -168,4 +159,4 @@ |
168 | 159 |
|
169 |
/// @warning The default constructor sets the iterator |
|
170 |
/// to an undefined value. |
|
160 |
/// Default constructor. |
|
161 |
/// \warning It sets the object to an undefined value. |
|
171 | 162 |
Arc() { } |
... | ... |
@@ -176,6 +167,6 @@ |
176 | 167 |
Arc(const Arc&) { } |
177 |
/// |
|
168 |
/// %Invalid constructor \& conversion. |
|
178 | 169 |
|
179 |
/// Initialize the iterator to be invalid. |
|
180 |
/// |
|
170 |
/// Initializes the object to be invalid. |
|
171 |
/// \sa Invalid for more details. |
|
181 | 172 |
Arc(Invalid) { } |
... | ... |
@@ -183,4 +174,6 @@ |
183 | 174 |
|
175 |
/// Equality operator. |
|
176 |
/// |
|
184 | 177 |
/// Two iterators are equal if and only if they point to the |
185 |
/// same object or both are |
|
178 |
/// same object or both are \c INVALID. |
|
186 | 179 |
bool operator==(Arc) const { return true; } |
... | ... |
@@ -188,4 +181,3 @@ |
188 | 181 |
|
189 |
/// \sa operator==(Arc n) |
|
190 |
/// |
|
182 |
/// Inequality operator. |
|
191 | 183 |
bool operator!=(Arc) const { return true; } |
... | ... |
@@ -194,8 +186,7 @@ |
194 | 186 |
|
195 |
/// To allow the use of digraph descriptors as key type in std::map or |
|
196 |
/// similar associative container we require this. |
|
187 |
/// Artificial ordering operator. |
|
197 | 188 |
/// |
198 |
/// \note This operator only have to define some strict ordering of |
|
199 |
/// the items; this order has nothing to do with the iteration |
|
200 |
/// ordering of |
|
189 |
/// \note This operator only has to define some strict ordering of |
|
190 |
/// the arcs; this order has nothing to do with the iteration |
|
191 |
/// ordering of the arcs. |
|
201 | 192 |
bool operator<(Arc) const { return false; } |
... | ... |
@@ -203,3 +194,3 @@ |
203 | 194 |
|
204 |
/// |
|
195 |
/// Iterator class for the outgoing arcs of a node. |
|
205 | 196 |
|
... | ... |
@@ -207,10 +198,9 @@ |
207 | 198 |
/// of a digraph. |
208 |
/// Its usage is quite simple, for example you can count the number |
|
199 |
/// Its usage is quite simple, for example, you can count the number |
|
209 | 200 |
/// of outgoing arcs of a node \c n |
210 |
/// in digraph \c g of type \c Digraph as follows. |
|
201 |
/// in a digraph \c g of type \c %Digraph as follows. |
|
211 | 202 |
///\code |
212 | 203 |
/// int count=0; |
213 |
/// for (Digraph::OutArcIt |
|
204 |
/// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count; |
|
214 | 205 |
///\endcode |
215 |
|
|
216 | 206 |
class OutArcIt : public Arc { |
... | ... |
@@ -219,4 +209,4 @@ |
219 | 209 |
|
220 |
/// @warning The default constructor sets the iterator |
|
221 |
/// to an undefined value. |
|
210 |
/// Default constructor. |
|
211 |
/// \warning It sets the iterator to an undefined value. |
|
222 | 212 |
OutArcIt() { } |
... | ... |
@@ -227,19 +217,18 @@ |
227 | 217 |
OutArcIt(const OutArcIt& e) : Arc(e) { } |
228 |
/// |
|
218 |
/// %Invalid constructor \& conversion. |
|
229 | 219 |
|
230 |
/// |
|
220 |
/// Initializes the iterator to be invalid. |
|
221 |
/// \sa Invalid for more details. |
|
222 |
OutArcIt(Invalid) { } |
|
223 |
/// Sets the iterator to the first outgoing arc. |
|
224 |
|
|
225 |
/// Sets the iterator to the first outgoing arc of the given node. |
|
231 | 226 |
/// |
232 |
OutArcIt(Invalid) { } |
|
233 |
/// This constructor sets the iterator to the first outgoing arc. |
|
227 |
OutArcIt(const Digraph&, const Node&) { } |
|
228 |
/// Sets the iterator to the given arc. |
|
234 | 229 |
|
235 |
/// This constructor sets the iterator to the first outgoing arc of |
|
236 |
/// the node. |
|
237 |
OutArcIt(const Digraph&, const Node&) { } |
|
238 |
/// Arc -> OutArcIt conversion |
|
239 |
|
|
240 |
/// Sets the iterator to the value of the trivial iterator. |
|
241 |
/// This feature necessitates that each time we |
|
242 |
/// iterate the arc-set, the iteration order is the same. |
|
230 |
/// Sets the iterator to the given arc of the given digraph. |
|
231 |
/// |
|
243 | 232 |
OutArcIt(const Digraph&, const Arc&) { } |
244 |
///Next outgoing arc |
|
233 |
/// Next outgoing arc |
|
245 | 234 |
|
... | ... |
@@ -250,3 +239,3 @@ |
250 | 239 |
|
251 |
/// |
|
240 |
/// Iterator class for the incoming arcs of a node. |
|
252 | 241 |
|
... | ... |
@@ -254,10 +243,9 @@ |
254 | 243 |
/// of a digraph. |
255 |
/// Its usage is quite simple, for example you can count the number |
|
256 |
/// of outgoing arcs of a node \c n |
|
257 |
/// |
|
244 |
/// Its usage is quite simple, for example, you can count the number |
|
245 |
/// of incoming arcs of a node \c n |
|
246 |
/// in a digraph \c g of type \c %Digraph as follows. |
|
258 | 247 |
///\code |
259 | 248 |
/// int count=0; |
260 |
/// for(Digraph::InArcIt |
|
249 |
/// for(Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count; |
|
261 | 250 |
///\endcode |
262 |
|
|
263 | 251 |
class InArcIt : public Arc { |
... | ... |
@@ -266,4 +254,4 @@ |
266 | 254 |
|
267 |
/// @warning The default constructor sets the iterator |
|
268 |
/// to an undefined value. |
|
255 |
/// Default constructor. |
|
256 |
/// \warning It sets the iterator to an undefined value. |
|
269 | 257 |
InArcIt() { } |
... | ... |
@@ -274,17 +262,16 @@ |
274 | 262 |
InArcIt(const InArcIt& e) : Arc(e) { } |
275 |
/// |
|
263 |
/// %Invalid constructor \& conversion. |
|
276 | 264 |
|
277 |
/// |
|
265 |
/// Initializes the iterator to be invalid. |
|
266 |
/// \sa Invalid for more details. |
|
267 |
InArcIt(Invalid) { } |
|
268 |
/// Sets the iterator to the first incoming arc. |
|
269 |
|
|
270 |
/// Sets the iterator to the first incoming arc of the given node. |
|
278 | 271 |
/// |
279 |
InArcIt(Invalid) { } |
|
280 |
/// This constructor sets the iterator to first incoming arc. |
|
272 |
InArcIt(const Digraph&, const Node&) { } |
|
273 |
/// Sets the iterator to the given arc. |
|
281 | 274 |
|
282 |
/// This constructor set the iterator to the first incoming arc of |
|
283 |
/// the node. |
|
284 |
InArcIt(const Digraph&, const Node&) { } |
|
285 |
/// Arc -> InArcIt conversion |
|
286 |
|
|
287 |
/// Sets the iterator to the value of the trivial iterator \c e. |
|
288 |
/// This feature necessitates that each time we |
|
289 |
/// iterate the arc-set, the iteration order is the same. |
|
275 |
/// Sets the iterator to the given arc of the given digraph. |
|
276 |
/// |
|
290 | 277 |
InArcIt(const Digraph&, const Arc&) { } |
... | ... |
@@ -292,14 +279,15 @@ |
292 | 279 |
|
293 |
/// Assign the iterator to the next inarc of the corresponding node. |
|
294 |
/// |
|
280 |
/// Assign the iterator to the next |
|
281 |
/// incoming arc of the corresponding node. |
|
295 | 282 |
InArcIt& operator++() { return *this; } |
296 | 283 |
}; |
297 |
/// This iterator goes through each arc. |
|
298 | 284 |
|
299 |
/// This iterator goes through each arc of a digraph. |
|
300 |
/// Its usage is quite simple, for example you can count the number |
|
301 |
/// |
|
285 |
/// Iterator class for the arcs. |
|
286 |
|
|
287 |
/// This iterator goes through each arc of the digraph. |
|
288 |
/// Its usage is quite simple, for example, you can count the number |
|
289 |
/// of arcs in a digraph \c g of type \c %Digraph as follows: |
|
302 | 290 |
///\code |
303 | 291 |
/// int count=0; |
304 |
/// for(Digraph::ArcIt |
|
292 |
/// for(Digraph::ArcIt a(g); a!=INVALID; ++a) ++count; |
|
305 | 293 |
///\endcode |
... | ... |
@@ -309,4 +297,4 @@ |
309 | 297 |
|
310 |
/// @warning The default constructor sets the iterator |
|
311 |
/// to an undefined value. |
|
298 |
/// Default constructor. |
|
299 |
/// \warning It sets the iterator to an undefined value. |
|
312 | 300 |
ArcIt() { } |
... | ... |
@@ -317,54 +305,64 @@ |
317 | 305 |
ArcIt(const ArcIt& e) : Arc(e) { } |
318 |
/// |
|
306 |
/// %Invalid constructor \& conversion. |
|
319 | 307 |
|
320 |
/// |
|
308 |
/// Initializes the iterator to be invalid. |
|
309 |
/// \sa Invalid for more details. |
|
310 |
ArcIt(Invalid) { } |
|
311 |
/// Sets the iterator to the first arc. |
|
312 |
|
|
313 |
/// Sets the iterator to the first arc of the given digraph. |
|
321 | 314 |
/// |
322 |
ArcIt(Invalid) { } |
|
323 |
/// This constructor sets the iterator to the first arc. |
|
315 |
explicit ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); } |
|
316 |
/// Sets the iterator to the given arc. |
|
324 | 317 |
|
325 |
/// This constructor sets the iterator to the first arc of \c g. |
|
326 |
///@param g the digraph |
|
327 |
ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); } |
|
328 |
/// Arc -> ArcIt conversion |
|
329 |
|
|
330 |
/// Sets the iterator to the value of the trivial iterator \c e. |
|
331 |
/// This feature necessitates that each time we |
|
332 |
/// iterate the arc-set, the iteration order is the same. |
|
318 |
/// Sets the iterator to the given arc of the given digraph. |
|
319 |
/// |
|
333 | 320 |
ArcIt(const Digraph&, const Arc&) { } |
334 |
///Next arc |
|
321 |
/// Next arc |
|
335 | 322 |
|
336 | 323 |
/// Assign the iterator to the next arc. |
324 |
/// |
|
337 | 325 |
ArcIt& operator++() { return *this; } |
338 | 326 |
}; |
339 |
///Gives back the target node of an arc. |
|
340 | 327 |
|
341 |
/// |
|
328 |
/// \brief The source node of the arc. |
|
342 | 329 |
/// |
343 |
Node target(Arc) const { return INVALID; } |
|
344 |
///Gives back the source node of an arc. |
|
345 |
|
|
346 |
///Gives back the source node of an arc. |
|
347 |
/// |
|
330 |
/// Returns the source node of the given arc. |
|
348 | 331 |
Node source(Arc) const { return INVALID; } |
349 | 332 |
|
350 |
/// \brief |
|
333 |
/// \brief The target node of the arc. |
|
334 |
/// |
|
335 |
/// Returns the target node of the given arc. |
|
336 |
Node target(Arc) const { return INVALID; } |
|
337 |
|
|
338 |
/// \brief The ID of the node. |
|
339 |
/// |
|
340 |
/// Returns the ID of the given node. |
|
351 | 341 |
int id(Node) const { return -1; } |
352 | 342 |
|
353 |
/// \brief |
|
343 |
/// \brief The ID of the arc. |
|
344 |
/// |
|
345 |
/// Returns the ID of the given arc. |
|
354 | 346 |
int id(Arc) const { return -1; } |
355 | 347 |
|
356 |
/// \brief |
|
348 |
/// \brief The node with the given ID. |
|
357 | 349 |
/// |
358 |
/// |
|
350 |
/// Returns the node with the given ID. |
|
351 |
/// \pre The argument should be a valid node ID in the digraph. |
|
359 | 352 |
Node nodeFromId(int) const { return INVALID; } |
360 | 353 |
|
361 |
/// \brief |
|
354 |
/// \brief The arc with the given ID. |
|
362 | 355 |
/// |
363 |
/// |
|
356 |
/// Returns the arc with the given ID. |
|
357 |
/// \pre The argument should be a valid arc ID in the digraph. |
|
364 | 358 |
Arc arcFromId(int) const { return INVALID; } |
365 | 359 |
|
366 |
/// \brief |
|
360 |
/// \brief An upper bound on the node IDs. |
|
361 |
/// |
|
362 |
/// Returns an upper bound on the node IDs. |
|
367 | 363 |
int maxNodeId() const { return -1; } |
368 | 364 |
|
369 |
/// \brief |
|
365 |
/// \brief An upper bound on the arc IDs. |
|
366 |
/// |
|
367 |
/// Returns an upper bound on the arc IDs. |
|
370 | 368 |
int maxArcId() const { return -1; } |
... | ... |
@@ -394,7 +392,12 @@ |
394 | 392 |
|
393 |
/// \brief The opposite node on the arc. |
|
394 |
/// |
|
395 |
/// Returns the opposite node on the given arc. |
|
396 |
Node oppositeNode(Node, Arc) const { return INVALID; } |
|
397 |
|
|
395 | 398 |
/// \brief The base node of the iterator. |
396 | 399 |
/// |
397 |
/// Gives back the base node of the iterator. |
|
398 |
/// It is always the target of the pointed arc. |
|
399 |
|
|
400 |
/// Returns the base node of the given outgoing arc iterator |
|
401 |
/// (i.e. the source node of the corresponding arc). |
|
402 |
Node baseNode(OutArcIt) const { return INVALID; } |
|
400 | 403 |
|
... | ... |
@@ -402,5 +405,5 @@ |
402 | 405 |
/// |
403 |
/// Gives back the running node of the iterator. |
|
404 |
/// It is always the source of the pointed arc. |
|
405 |
|
|
406 |
/// Returns the running node of the given outgoing arc iterator |
|
407 |
/// (i.e. the target node of the corresponding arc). |
|
408 |
Node runningNode(OutArcIt) const { return INVALID; } |
|
406 | 409 |
|
... | ... |
@@ -408,5 +411,5 @@ |
408 | 411 |
/// |
409 |
/// Gives back the base node of the iterator. |
|
410 |
/// It is always the source of the pointed arc. |
|
411 |
|
|
412 |
/// Returns the base node of the given incomming arc iterator |
|
413 |
/// (i.e. the target node of the corresponding arc). |
|
414 |
Node baseNode(InArcIt) const { return INVALID; } |
|
412 | 415 |
|
... | ... |
@@ -414,14 +417,10 @@ |
414 | 417 |
/// |
415 |
/// Gives back the running node of the iterator. |
|
416 |
/// It is always the target of the pointed arc. |
|
417 |
|
|
418 |
/// Returns the running node of the given incomming arc iterator |
|
419 |
/// (i.e. the source node of the corresponding arc). |
|
420 |
Node runningNode(InArcIt) const { return INVALID; } |
|
418 | 421 |
|
419 |
/// \brief |
|
422 |
/// \brief Standard graph map type for the nodes. |
|
420 | 423 |
/// |
421 |
/// Gives back the opposite node on the given arc. |
|
422 |
Node oppositeNode(const Node&, const Arc&) const { return INVALID; } |
|
423 |
|
|
424 |
/// \brief Reference map of the nodes to type \c T. |
|
425 |
/// |
|
426 |
/// Reference map of the nodes to type \c T. |
|
424 |
/// Standard graph map type for the nodes. |
|
425 |
/// It conforms to the ReferenceMap concept. |
|
427 | 426 |
template<class T> |
... | ... |
@@ -430,5 +429,5 @@ |
430 | 429 |
|
431 |
///\e |
|
432 |
NodeMap(const Digraph&) { } |
|
433 |
/// |
|
430 |
/// Constructor |
|
431 |
explicit NodeMap(const Digraph&) { } |
|
432 |
/// Constructor with given initial value |
|
434 | 433 |
NodeMap(const Digraph&, T) { } |
... | ... |
@@ -447,5 +446,6 @@ |
447 | 446 |
|
448 |
/// \brief |
|
447 |
/// \brief Standard graph map type for the arcs. |
|
449 | 448 |
/// |
450 |
/// |
|
449 |
/// Standard graph map type for the arcs. |
|
450 |
/// It conforms to the ReferenceMap concept. |
|
451 | 451 |
template<class T> |
... | ... |
@@ -454,6 +454,7 @@ |
454 | 454 |
|
455 |
///\e |
|
456 |
ArcMap(const Digraph&) { } |
|
457 |
/// |
|
455 |
/// Constructor |
|
456 |
explicit ArcMap(const Digraph&) { } |
|
457 |
/// Constructor with given initial value |
|
458 | 458 |
ArcMap(const Digraph&, T) { } |
459 |
|
|
459 | 460 |
private: |
... | ... |
@@ -20,3 +20,3 @@ |
20 | 20 |
///\file |
21 |
///\brief The concept of |
|
21 |
///\brief The concept of undirected graphs. |
|
22 | 22 |
|
... | ... |
@@ -26,2 +26,4 @@ |
26 | 26 |
#include <lemon/concepts/graph_components.h> |
27 |
#include <lemon/concepts/maps.h> |
|
28 |
#include <lemon/concept_check.h> |
|
27 | 29 |
#include <lemon/core.h> |
... | ... |
@@ -33,43 +35,56 @@ |
33 | 35 |
/// |
34 |
/// \brief Class describing the concept of |
|
36 |
/// \brief Class describing the concept of undirected graphs. |
|
35 | 37 |
/// |
36 |
/// This class describes the common interface of all Undirected |
|
37 |
/// Graphs. |
|
38 |
/// This class describes the common interface of all undirected |
|
39 |
/// graphs. |
|
38 | 40 |
/// |
39 |
/// As all concept describing classes it provides only interface |
|
40 |
/// without any sensible implementation. So any algorithm for |
|
41 |
/// |
|
41 |
/// Like all concept classes, it only provides an interface |
|
42 |
/// without any sensible implementation. So any general algorithm for |
|
43 |
/// undirected graphs should compile with this class, but it will not |
|
42 | 44 |
/// run properly, of course. |
45 |
/// An actual graph implementation like \ref ListGraph or |
|
46 |
/// \ref SmartGraph may have additional functionality. |
|
43 | 47 |
/// |
44 |
/// The LEMON undirected graphs also fulfill the concept of |
|
45 |
/// directed graphs (\ref lemon::concepts::Digraph "Digraph |
|
46 |
/// Concept"). Each edges can be seen as two opposite |
|
47 |
/// directed arc and consequently the undirected graph can be |
|
48 |
/// seen as the direceted graph of these directed arcs. The |
|
49 |
/// Graph has the Edge inner class for the edges and |
|
50 |
/// the Arc type for the directed arcs. The Arc type is |
|
51 |
/// convertible to Edge or inherited from it so from a directed |
|
52 |
/// |
|
48 |
/// The undirected graphs also fulfill the concept of \ref Digraph |
|
49 |
/// "directed graphs", since each edge can also be regarded as two |
|
50 |
/// oppositely directed arcs. |
|
51 |
/// Undirected graphs provide an Edge type for the undirected edges and |
|
52 |
/// an Arc type for the directed arcs. The Arc type is convertible to |
|
53 |
/// Edge or inherited from it, i.e. the corresponding edge can be |
|
54 |
/// obtained from an arc. |
|
55 |
/// EdgeIt and EdgeMap classes can be used for the edges, while ArcIt |
|
56 |
/// and ArcMap classes can be used for the arcs (just like in digraphs). |
|
57 |
/// Both InArcIt and OutArcIt iterates on the same edges but with |
|
58 |
/// opposite direction. IncEdgeIt also iterates on the same edges |
|
59 |
/// as OutArcIt and InArcIt, but it is not convertible to Arc, |
|
60 |
/// only to Edge. |
|
53 | 61 |
/// |
54 |
/// In the sense of the LEMON each edge has a default |
|
55 |
/// direction (it should be in every computer implementation, |
|
56 |
/// because the order of edge's nodes defines an |
|
57 |
/// orientation). With the default orientation we can define that |
|
58 |
/// the directed arc is forward or backward directed. With the \c |
|
59 |
/// direction() and \c direct() function we can get the direction |
|
60 |
/// |
|
62 |
/// In LEMON, each undirected edge has an inherent orientation. |
|
63 |
/// Thus it can defined if an arc is forward or backward oriented in |
|
64 |
/// an undirected graph with respect to this default oriantation of |
|
65 |
/// the represented edge. |
|
66 |
/// With the direction() and direct() functions the direction |
|
67 |
/// of an arc can be obtained and set, respectively. |
|
61 | 68 |
/// |
62 |
/// The EdgeIt is an iterator for the edges. We can use |
|
63 |
/// the EdgeMap to map values for the edges. The InArcIt and |
|
64 |
/// OutArcIt iterates on the same edges but with opposite |
|
65 |
/// direction. The IncEdgeIt iterates also on the same edges |
|
66 |
/// as the OutArcIt and InArcIt but it is not convertible to Arc just |
|
67 |
/// to Edge. |
|
69 |
/// Only nodes and edges can be added to or removed from an undirected |
|
70 |
/// graph and the corresponding arcs are added or removed automatically. |
|
71 |
/// |
|
72 |
/// \sa Digraph |
|
68 | 73 |
class Graph { |
74 |
private: |
|
75 |
/// Graphs are \e not copy constructible. Use DigraphCopy instead. |
|
76 |
Graph(const Graph&) {} |
|
77 |
/// \brief Assignment of a graph to another one is \e not allowed. |
|
78 |
/// Use DigraphCopy instead. |
|
79 |
void operator=(const Graph&) {} |
|
80 |
|
|
69 | 81 |
public: |
70 |
/// \brief The undirected graph should be tagged by the |
|
71 |
/// UndirectedTag. |
|
82 |
/// Default constructor. |
|
83 |
Graph() {} |
|
84 |
|
|
85 |
/// \brief Undirected graphs should be tagged with \c UndirectedTag. |
|
72 | 86 |
/// |
73 |
/// The undirected graph should be tagged by the UndirectedTag. This |
|
74 |
/// tag helps the enable_if technics to make compile time |
|
87 |
/// Undirected graphs should be tagged with \c UndirectedTag. |
|
88 |
/// |
|
89 |
/// This tag helps the \c enable_if technics to make compile time |
|
75 | 90 |
/// specializations for undirected graphs. |
... | ... |
@@ -77,9 +92,7 @@ |
77 | 92 |
|
78 |
/// \brief The base type of node iterators, |
|
79 |
/// or in other words, the trivial node iterator. |
|
80 |
/// |
|
81 |
/// This is the base type of each node iterator, |
|
82 |
/// thus each kind of node iterator converts to this. |
|
83 |
/// More precisely each kind of node iterator should be inherited |
|
84 |
/// |
|
93 |
/// The node type of the graph |
|
94 |
|
|
95 |
/// This class identifies a node of the graph. It also serves |
|
96 |
/// as a base class of the node iterators, |
|
97 |
/// thus they convert to this type. |
|
85 | 98 |
class Node { |
... | ... |
@@ -88,4 +101,4 @@ |
88 | 101 |
|
89 |
/// @warning The default constructor sets the iterator |
|
90 |
/// to an undefined value. |
|
102 |
/// Default constructor. |
|
103 |
/// \warning It sets the object to an undefined value. |
|
91 | 104 |
Node() { } |
... | ... |
@@ -97,5 +110,5 @@ |
97 | 110 |
|
98 |
/// Invalid constructor \& conversion. |
|
111 |
/// %Invalid constructor \& conversion. |
|
99 | 112 |
|
100 |
/// |
|
113 |
/// Initializes the object to be invalid. |
|
101 | 114 |
/// \sa Invalid for more details. |
... | ... |
@@ -104,4 +117,6 @@ |
104 | 117 |
|
118 |
/// Equality operator. |
|
119 |
/// |
|
105 | 120 |
/// Two iterators are equal if and only if they point to the |
106 |
/// same object or both are |
|
121 |
/// same object or both are \c INVALID. |
|
107 | 122 |
bool operator==(Node) const { return true; } |
... | ... |
@@ -110,4 +125,3 @@ |
110 | 125 |
|
111 |
/// \sa operator==(Node n) |
|
112 |
/// |
|
126 |
/// Inequality operator. |
|
113 | 127 |
bool operator!=(Node) const { return true; } |
... | ... |
@@ -116,6 +130,5 @@ |
116 | 130 |
|
117 |
/// To allow the use of graph descriptors as key type in std::map or |
|
118 |
/// similar associative container we require this. |
|
131 |
/// Artificial ordering operator. |
|
119 | 132 |
/// |
120 |
/// \note This operator only |
|
133 |
/// \note This operator only has to define some strict ordering of |
|
121 | 134 |
/// the items; this order has nothing to do with the iteration |
... | ... |
@@ -126,7 +139,7 @@ |
126 | 139 |
|
127 |
/// |
|
140 |
/// Iterator class for the nodes. |
|
128 | 141 |
|
129 |
/// This iterator goes through each node. |
|
130 |
/// Its usage is quite simple, for example you can count the number |
|
131 |
/// |
|
142 |
/// This iterator goes through each node of the graph. |
|
143 |
/// Its usage is quite simple, for example, you can count the number |
|
144 |
/// of nodes in a graph \c g of type \c %Graph like this: |
|
132 | 145 |
///\code |
... | ... |
@@ -139,4 +152,4 @@ |
139 | 152 |
|
140 |
/// @warning The default constructor sets the iterator |
|
141 |
/// to an undefined value. |
|
153 |
/// Default constructor. |
|
154 |
/// \warning It sets the iterator to an undefined value. |
|
142 | 155 |
NodeIt() { } |
... | ... |
@@ -147,5 +160,5 @@ |
147 | 160 |
NodeIt(const NodeIt& n) : Node(n) { } |
148 |
/// Invalid constructor \& conversion. |
|
161 |
/// %Invalid constructor \& conversion. |
|
149 | 162 |
|
150 |
/// |
|
163 |
/// Initializes the iterator to be invalid. |
|
151 | 164 |
/// \sa Invalid for more details. |
... | ... |
@@ -154,11 +167,9 @@ |
154 | 167 |
|
155 |
/// Sets the iterator to the first node of |
|
168 |
/// Sets the iterator to the first node of the given digraph. |
|
156 | 169 |
/// |
157 |
NodeIt(const Graph&) { } |
|
158 |
/// Node -> NodeIt conversion. |
|
170 |
explicit NodeIt(const Graph&) { } |
|
171 |
/// Sets the iterator to the given node. |
|
159 | 172 |
|
160 |
/// Sets the iterator to the node of \c the graph pointed by |
|
161 |
/// the trivial iterator. |
|
162 |
/// This feature necessitates that each time we |
|
163 |
/// iterate the arc-set, the iteration order is the same. |
|
173 |
/// Sets the iterator to the given node of the given digraph. |
|
174 |
/// |
|
164 | 175 |
NodeIt(const Graph&, const Node&) { } |
... | ... |
@@ -172,6 +183,7 @@ |
172 | 183 |
|
173 |
/// The |
|
184 |
/// The edge type of the graph |
|
174 | 185 |
|
175 |
/// The base type of the edge iterators. |
|
176 |
/// |
|
186 |
/// This class identifies an edge of the graph. It also serves |
|
187 |
/// as a base class of the edge iterators, |
|
188 |
/// thus they will convert to this type. |
|
177 | 189 |
class Edge { |
... | ... |
@@ -180,4 +192,4 @@ |
180 | 192 |
|
181 |
/// @warning The default constructor sets the iterator |
|
182 |
/// to an undefined value. |
|
193 |
/// Default constructor. |
|
194 |
/// \warning It sets the object to an undefined value. |
|
183 | 195 |
Edge() { } |
... | ... |
@@ -188,6 +200,6 @@ |
188 | 200 |
Edge(const Edge&) { } |
189 |
/// |
|
201 |
/// %Invalid constructor \& conversion. |
|
190 | 202 |
|
191 |
/// Initialize the iterator to be invalid. |
|
192 |
/// |
|
203 |
/// Initializes the object to be invalid. |
|
204 |
/// \sa Invalid for more details. |
|
193 | 205 |
Edge(Invalid) { } |
... | ... |
@@ -195,4 +207,6 @@ |
195 | 207 |
|
208 |
/// Equality operator. |
|
209 |
/// |
|
196 | 210 |
/// Two iterators are equal if and only if they point to the |
197 |
/// same object or both are |
|
211 |
/// same object or both are \c INVALID. |
|
198 | 212 |
bool operator==(Edge) const { return true; } |
... | ... |
@@ -200,4 +214,3 @@ |
200 | 214 |
|
201 |
/// \sa operator==(Edge n) |
|
202 |
/// |
|
215 |
/// Inequality operator. |
|
203 | 216 |
bool operator!=(Edge) const { return true; } |
... | ... |
@@ -206,8 +219,7 @@ |
206 | 219 |
|
207 |
/// To allow the use of graph descriptors as key type in std::map or |
|
208 |
/// similar associative container we require this. |
|
220 |
/// Artificial ordering operator. |
|
209 | 221 |
/// |
210 |
/// \note This operator only have to define some strict ordering of |
|
211 |
/// the items; this order has nothing to do with the iteration |
|
212 |
/// ordering of |
|
222 |
/// \note This operator only has to define some strict ordering of |
|
223 |
/// the edges; this order has nothing to do with the iteration |
|
224 |
/// ordering of the edges. |
|
213 | 225 |
bool operator<(Edge) const { return false; } |
... | ... |
@@ -215,7 +227,7 @@ |
215 | 227 |
|
216 |
/// |
|
228 |
/// Iterator class for the edges. |
|
217 | 229 |
|
218 |
/// This iterator goes through each edge of a graph. |
|
219 |
/// Its usage is quite simple, for example you can count the number |
|
220 |
/// |
|
230 |
/// This iterator goes through each edge of the graph. |
|
231 |
/// Its usage is quite simple, for example, you can count the number |
|
232 |
/// of edges in a graph \c g of type \c %Graph as follows: |
|
221 | 233 |
///\code |
... | ... |
@@ -228,4 +240,4 @@ |
228 | 240 |
|
229 |
/// @warning The default constructor sets the iterator |
|
230 |
/// to an undefined value. |
|
241 |
/// Default constructor. |
|
242 |
/// \warning It sets the iterator to an undefined value. |
|
231 | 243 |
EdgeIt() { } |
... | ... |
@@ -236,17 +248,16 @@ |
236 | 248 |
EdgeIt(const EdgeIt& e) : Edge(e) { } |
237 |
/// |
|
249 |
/// %Invalid constructor \& conversion. |
|
238 | 250 |
|
239 |
/// |
|
251 |
/// Initializes the iterator to be invalid. |
|
252 |
/// \sa Invalid for more details. |
|
253 |
EdgeIt(Invalid) { } |
|
254 |
/// Sets the iterator to the first edge. |
|
255 |
|
|
256 |
/// Sets the iterator to the first edge of the given graph. |
|
240 | 257 |
/// |
241 |
EdgeIt(Invalid) { } |
|
242 |
/// This constructor sets the iterator to the first edge. |
|
258 |
explicit EdgeIt(const Graph&) { } |
|
259 |
/// Sets the iterator to the given edge. |
|
243 | 260 |
|
244 |
/// This constructor sets the iterator to the first edge. |
|
245 |
EdgeIt(const Graph&) { } |
|
246 |
/// Edge -> EdgeIt conversion |
|
247 |
|
|
248 |
/// Sets the iterator to the value of the trivial iterator. |
|
249 |
/// This feature necessitates that each time we |
|
250 |
/// iterate the edge-set, the iteration order is the |
|
251 |
/// same. |
|
261 |
/// Sets the iterator to the given edge of the given graph. |
|
262 |
/// |
|
252 | 263 |
EdgeIt(const Graph&, const Edge&) { } |
... | ... |
@@ -255,2 +266,3 @@ |
255 | 266 |
/// Assign the iterator to the next edge. |
267 |
/// |
|
256 | 268 |
EdgeIt& operator++() { return *this; } |
... | ... |
@@ -258,12 +270,9 @@ |
258 | 270 |
|
259 |
/// \brief This iterator goes trough the incident undirected |
|
260 |
/// arcs of a node. |
|
261 |
/// |
|
262 |
/// This iterator goes trough the incident edges |
|
263 |
/// of a certain node of a graph. You should assume that the |
|
264 |
/// loop arcs will be iterated twice. |
|
265 |
/// |
|
266 |
/// Its usage is quite simple, for example you can compute the |
|
267 |
/// degree (i.e. count the number of incident arcs of a node \c n |
|
268 |
/// in graph \c g of type \c Graph as follows. |
|
271 |
/// Iterator class for the incident edges of a node. |
|
272 |
|
|
273 |
/// This iterator goes trough the incident undirected edges |
|
274 |
/// of a certain node of a graph. |
|
275 |
/// Its usage is quite simple, for example, you can compute the |
|
276 |
/// degree (i.e. the number of incident edges) of a node \c n |
|
277 |
/// in a graph \c g of type \c %Graph as follows. |
|
269 | 278 |
/// |
... | ... |
@@ -273,2 +282,4 @@ |
273 | 282 |
///\endcode |
283 |
/// |
|
284 |
/// \warning Loop edges will be iterated twice. |
|
274 | 285 |
class IncEdgeIt : public Edge { |
... | ... |
@@ -277,4 +288,4 @@ |
277 | 288 |
|
278 |
/// @warning The default constructor sets the iterator |
|
279 |
/// to an undefined value. |
|
289 |
/// Default constructor. |
|
290 |
/// \warning It sets the iterator to an undefined value. |
|
280 | 291 |
IncEdgeIt() { } |
... | ... |
@@ -285,21 +296,20 @@ |
285 | 296 |
IncEdgeIt(const IncEdgeIt& e) : Edge(e) { } |
286 |
/// |
|
297 |
/// %Invalid constructor \& conversion. |
|
287 | 298 |
|
288 |
/// |
|
299 |
/// Initializes the iterator to be invalid. |
|
300 |
/// \sa Invalid for more details. |
|
301 |
IncEdgeIt(Invalid) { } |
|
302 |
/// Sets the iterator to the first incident edge. |
|
303 |
|
|
304 |
/// Sets the iterator to the first incident edge of the given node. |
|
289 | 305 |
/// |
290 |
IncEdgeIt(Invalid) { } |
|
291 |
/// This constructor sets the iterator to first incident arc. |
|
306 |
IncEdgeIt(const Graph&, const Node&) { } |
|
307 |
/// Sets the iterator to the given edge. |
|
292 | 308 |
|
293 |
/// This constructor set the iterator to the first incident arc of |
|
294 |
/// the node. |
|
295 |
IncEdgeIt(const Graph&, const Node&) { } |
|
296 |
/// Edge -> IncEdgeIt conversion |
|
309 |
/// Sets the iterator to the given edge of the given graph. |
|
310 |
/// |
|
311 |
IncEdgeIt(const Graph&, const Edge&) { } |
|
312 |
/// Next incident edge |
|
297 | 313 |
|
298 |
/// Sets the iterator to the value of the trivial iterator \c e. |
|
299 |
/// This feature necessitates that each time we |
|
300 |
/// iterate the arc-set, the iteration order is the same. |
|
301 |
IncEdgeIt(const Graph&, const Edge&) { } |
|
302 |
/// Next incident arc |
|
303 |
|
|
304 |
/// Assign the iterator to the next incident |
|
314 |
/// Assign the iterator to the next incident edge |
|
305 | 315 |
/// of the corresponding node. |
... | ... |
@@ -308,7 +318,7 @@ |
308 | 318 |
|
309 |
/// The |
|
319 |
/// The arc type of the graph |
|
310 | 320 |
|
311 |
/// The directed arc type. It can be converted to the |
|
312 |
/// edge or it should be inherited from the undirected |
|
313 |
/// |
|
321 |
/// This class identifies a directed arc of the graph. It also serves |
|
322 |
/// as a base class of the arc iterators, |
|
323 |
/// thus they will convert to this type. |
|
314 | 324 |
class Arc { |
... | ... |
@@ -317,4 +327,4 @@ |
317 | 327 |
|
318 |
/// @warning The default constructor sets the iterator |
|
319 |
/// to an undefined value. |
|
328 |
/// Default constructor. |
|
329 |
/// \warning It sets the object to an undefined value. |
|
320 | 330 |
Arc() { } |
... | ... |
@@ -325,6 +335,6 @@ |
325 | 335 |
Arc(const Arc&) { } |
326 |
/// |
|
336 |
/// %Invalid constructor \& conversion. |
|
327 | 337 |
|
328 |
/// Initialize the iterator to be invalid. |
|
329 |
/// |
|
338 |
/// Initializes the object to be invalid. |
|
339 |
/// \sa Invalid for more details. |
|
330 | 340 |
Arc(Invalid) { } |
... | ... |
@@ -332,4 +342,6 @@ |
332 | 342 |
|
343 |
/// Equality operator. |
|
344 |
/// |
|
333 | 345 |
/// Two iterators are equal if and only if they point to the |
334 |
/// same object or both are |
|
346 |
/// same object or both are \c INVALID. |
|
335 | 347 |
bool operator==(Arc) const { return true; } |
... | ... |
@@ -337,4 +349,3 @@ |
337 | 349 |
|
338 |
/// \sa operator==(Arc n) |
|
339 |
/// |
|
350 |
/// Inequality operator. |
|
340 | 351 |
bool operator!=(Arc) const { return true; } |
... | ... |
@@ -343,21 +354,24 @@ |
343 | 354 |
|
344 |
/// To allow the use of graph descriptors as key type in std::map or |
|
345 |
/// similar associative container we require this. |
|
355 |
/// Artificial ordering operator. |
|
346 | 356 |
/// |
347 |
/// \note This operator only have to define some strict ordering of |
|
348 |
/// the items; this order has nothing to do with the iteration |
|
349 |
/// ordering of |
|
357 |
/// \note This operator only has to define some strict ordering of |
|
358 |
/// the arcs; this order has nothing to do with the iteration |
|
359 |
/// ordering of the arcs. |
|
350 | 360 |
bool operator<(Arc) const { return false; } |
351 | 361 |
|
352 |
/// Converison to Edge |
|
362 |
/// Converison to \c Edge |
|
363 |
|
|
364 |
/// Converison to \c Edge. |
|
365 |
/// |
|
353 | 366 |
operator Edge() const { return Edge(); } |
354 | 367 |
}; |
355 |
/// This iterator goes through each directed arc. |
|
356 | 368 |
|
357 |
/// This iterator goes through each arc of a graph. |
|
358 |
/// Its usage is quite simple, for example you can count the number |
|
359 |
/// |
|
369 |
/// Iterator class for the arcs. |
|
370 |
|
|
371 |
/// This iterator goes through each directed arc of the graph. |
|
372 |
/// Its usage is quite simple, for example, you can count the number |
|
373 |
/// of arcs in a graph \c g of type \c %Graph as follows: |
|
360 | 374 |
///\code |
361 | 375 |
/// int count=0; |
362 |
/// for(Graph::ArcIt |
|
376 |
/// for(Graph::ArcIt a(g); a!=INVALID; ++a) ++count; |
|
363 | 377 |
///\endcode |
... | ... |
@@ -367,4 +381,4 @@ |
367 | 381 |
|
368 |
/// @warning The default constructor sets the iterator |
|
369 |
/// to an undefined value. |
|
382 |
/// Default constructor. |
|
383 |
/// \warning It sets the iterator to an undefined value. |
|
370 | 384 |
ArcIt() { } |
... | ... |
@@ -375,21 +389,21 @@ |
375 | 389 |
ArcIt(const ArcIt& e) : Arc(e) { } |
376 |
/// |
|
390 |
/// %Invalid constructor \& conversion. |
|
377 | 391 |
|
378 |
/// |
|
392 |
/// Initializes the iterator to be invalid. |
|
393 |
/// \sa Invalid for more details. |
|
394 |
ArcIt(Invalid) { } |
|
395 |
/// Sets the iterator to the first arc. |
|
396 |
|
|
397 |
/// Sets the iterator to the first arc of the given graph. |
|
379 | 398 |
/// |
380 |
ArcIt(Invalid) { } |
|
381 |
/// This constructor sets the iterator to the first arc. |
|
399 |
explicit ArcIt(const Graph &g) { ignore_unused_variable_warning(g); } |
|
400 |
/// Sets the iterator to the given arc. |
|
382 | 401 |
|
383 |
/// This constructor sets the iterator to the first arc of \c g. |
|
384 |
///@param g the graph |
|
385 |
ArcIt(const Graph &g) { ignore_unused_variable_warning(g); } |
|
386 |
/// Arc -> ArcIt conversion |
|
387 |
|
|
388 |
/// Sets the iterator to the value of the trivial iterator \c e. |
|
389 |
/// This feature necessitates that each time we |
|
390 |
/// iterate the arc-set, the iteration order is the same. |
|
402 |
/// Sets the iterator to the given arc of the given graph. |
|
403 |
/// |
|
391 | 404 |
ArcIt(const Graph&, const Arc&) { } |
392 |
///Next arc |
|
405 |
/// Next arc |
|
393 | 406 |
|
394 | 407 |
/// Assign the iterator to the next arc. |
408 |
/// |
|
395 | 409 |
ArcIt& operator++() { return *this; } |
... | ... |
@@ -397,14 +411,13 @@ |
397 | 411 |
|
398 |
/// |
|
412 |
/// Iterator class for the outgoing arcs of a node. |
|
399 | 413 |
|
400 |
/// This iterator goes trough the \e outgoing arcs of a certain node |
|
401 |
/// of a graph. |
|
402 |
/// |
|
414 |
/// This iterator goes trough the \e outgoing directed arcs of a |
|
415 |
/// certain node of a graph. |
|
416 |
/// Its usage is quite simple, for example, you can count the number |
|
403 | 417 |
/// of outgoing arcs of a node \c n |
404 |
/// in graph \c g of type \c Graph as follows. |
|
418 |
/// in a graph \c g of type \c %Graph as follows. |
|
405 | 419 |
///\code |
406 | 420 |
/// int count=0; |
407 |
/// for ( |
|
421 |
/// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count; |
|
408 | 422 |
///\endcode |
409 |
|
|
410 | 423 |
class OutArcIt : public Arc { |
... | ... |
@@ -413,4 +426,4 @@ |
413 | 426 |
|
414 |
/// @warning The default constructor sets the iterator |
|
415 |
/// to an undefined value. |
|
427 |
/// Default constructor. |
|
428 |
/// \warning It sets the iterator to an undefined value. |
|
416 | 429 |
OutArcIt() { } |
... | ... |
@@ -421,13 +434,11 @@ |
421 | 434 |
OutArcIt(const OutArcIt& e) : Arc(e) { } |
422 |
/// |
|
435 |
/// %Invalid constructor \& conversion. |
|
423 | 436 |
|
424 |
/// |
|
437 |
/// Initializes the iterator to be invalid. |
|
438 |
/// \sa Invalid for more details. |
|
439 |
OutArcIt(Invalid) { } |
|
440 |
/// Sets the iterator to the first outgoing arc. |
|
441 |
|
|
442 |
/// Sets the iterator to the first outgoing arc of the given node. |
|
425 | 443 |
/// |
426 |
OutArcIt(Invalid) { } |
|
427 |
/// This constructor sets the iterator to the first outgoing arc. |
|
428 |
|
|
429 |
/// This constructor sets the iterator to the first outgoing arc of |
|
430 |
/// the node. |
|
431 |
///@param n the node |
|
432 |
///@param g the graph |
|
433 | 444 |
OutArcIt(const Graph& n, const Node& g) { |
... | ... |
@@ -436,9 +447,8 @@ |
436 | 447 |
} |
437 |
/// |
|
448 |
/// Sets the iterator to the given arc. |
|
438 | 449 |
|
439 |
/// Sets the iterator to the value of the trivial iterator. |
|
440 |
/// This feature necessitates that each time we |
|
441 |
/// |
|
450 |
/// Sets the iterator to the given arc of the given graph. |
|
451 |
/// |
|
442 | 452 |
OutArcIt(const Graph&, const Arc&) { } |
443 |
///Next outgoing arc |
|
453 |
/// Next outgoing arc |
|
444 | 454 |
|
... | ... |
@@ -449,14 +459,13 @@ |
449 | 459 |
|
450 |
/// |
|
460 |
/// Iterator class for the incoming arcs of a node. |
|
451 | 461 |
|
452 |
/// This iterator goes trough the \e incoming arcs of a certain node |
|
453 |
/// of a graph. |
|
454 |
/// Its usage is quite simple, for example you can count the number |
|
455 |
/// of outgoing arcs of a node \c n |
|
456 |
/// |
|
462 |
/// This iterator goes trough the \e incoming directed arcs of a |
|
463 |
/// certain node of a graph. |
|
464 |
/// Its usage is quite simple, for example, you can count the number |
|
465 |
/// of incoming arcs of a node \c n |
|
466 |
/// in a graph \c g of type \c %Graph as follows. |
|
457 | 467 |
///\code |
458 | 468 |
/// int count=0; |
459 |
/// for( |
|
469 |
/// for (Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count; |
|
460 | 470 |
///\endcode |
461 |
|
|
462 | 471 |
class InArcIt : public Arc { |
... | ... |
@@ -465,4 +474,4 @@ |
465 | 474 |
|
466 |
/// @warning The default constructor sets the iterator |
|
467 |
/// to an undefined value. |
|
475 |
/// Default constructor. |
|
476 |
/// \warning It sets the iterator to an undefined value. |
|
468 | 477 |
InArcIt() { } |
... | ... |
@@ -473,13 +482,11 @@ |
473 | 482 |
InArcIt(const InArcIt& e) : Arc(e) { } |
474 |
/// |
|
483 |
/// %Invalid constructor \& conversion. |
|
475 | 484 |
|
476 |
/// |
|
485 |
/// Initializes the iterator to be invalid. |
|
486 |
/// \sa Invalid for more details. |
|
487 |
InArcIt(Invalid) { } |
|
488 |
/// Sets the iterator to the first incoming arc. |
|
489 |
|
|
490 |
/// Sets the iterator to the first incoming arc of the given node. |
|
477 | 491 |
/// |
478 |
InArcIt(Invalid) { } |
|
479 |
/// This constructor sets the iterator to first incoming arc. |
|
480 |
|
|
481 |
/// This constructor set the iterator to the first incoming arc of |
|
482 |
/// the node. |
|
483 |
///@param n the node |
|
484 |
///@param g the graph |
|
485 | 492 |
InArcIt(const Graph& g, const Node& n) { |
... | ... |
@@ -488,7 +495,6 @@ |
488 | 495 |
} |
489 |
/// |
|
496 |
/// Sets the iterator to the given arc. |
|
490 | 497 |
|
491 |
/// Sets the iterator to the value of the trivial iterator \c e. |
|
492 |
/// This feature necessitates that each time we |
|
493 |
/// |
|
498 |
/// Sets the iterator to the given arc of the given graph. |
|
499 |
/// |
|
494 | 500 |
InArcIt(const Graph&, const Arc&) { } |
... | ... |
@@ -496,4 +502,4 @@ |
496 | 502 |
|
497 |
/// Assign the iterator to the next inarc of the corresponding node. |
|
498 |
/// |
|
503 |
/// Assign the iterator to the next |
|
504 |
/// incoming arc of the corresponding node. |
|
499 | 505 |
InArcIt& operator++() { return *this; } |
... | ... |
@@ -501,5 +507,6 @@ |
501 | 507 |
|
502 |
/// \brief |
|
508 |
/// \brief Standard graph map type for the nodes. |
|
503 | 509 |
/// |
504 |
/// |
|
510 |
/// Standard graph map type for the nodes. |
|
511 |
/// It conforms to the ReferenceMap concept. |
|
505 | 512 |
template<class T> |
... | ... |
@@ -509,5 +516,5 @@ |
509 | 516 |
|
510 |
///\e |
|
511 |
NodeMap(const Graph&) { } |
|
512 |
/// |
|
517 |
/// Constructor |
|
518 |
explicit NodeMap(const Graph&) { } |
|
519 |
/// Constructor with given initial value |
|
513 | 520 |
NodeMap(const Graph&, T) { } |
... | ... |
@@ -526,5 +533,6 @@ |
526 | 533 |
|
527 |
/// \brief |
|
534 |
/// \brief Standard graph map type for the arcs. |
|
528 | 535 |
/// |
529 |
/// |
|
536 |
/// Standard graph map type for the arcs. |
|
537 |
/// It conforms to the ReferenceMap concept. |
|
530 | 538 |
template<class T> |
... | ... |
@@ -534,6 +542,7 @@ |
534 | 542 |
|
535 |
///\e |
|
536 |
ArcMap(const Graph&) { } |
|
537 |
/// |
|
543 |
/// Constructor |
|
544 |
explicit ArcMap(const Graph&) { } |
|
545 |
/// Constructor with given initial value |
|
538 | 546 |
ArcMap(const Graph&, T) { } |
547 |
|
|
539 | 548 |
private: |
... | ... |
@@ -550,5 +559,6 @@ |
550 | 559 |
|
551 |
/// Reference map of the edges to type \c T. |
|
552 |
|
|
553 |
/// |
|
560 |
/// \brief Standard graph map type for the edges. |
|
561 |
/// |
|
562 |
/// Standard graph map type for the edges. |
|
563 |
/// It conforms to the ReferenceMap concept. |
|
554 | 564 |
template<class T> |
... | ... |
@@ -558,6 +568,7 @@ |
558 | 568 |
|
559 |
///\e |
|
560 |
EdgeMap(const Graph&) { } |
|
561 |
/// |
|
569 |
/// Constructor |
|
570 |
explicit EdgeMap(const Graph&) { } |
|
571 |
/// Constructor with given initial value |
|
562 | 572 |
EdgeMap(const Graph&, T) { } |
573 |
|
|
563 | 574 |
private: |
... | ... |
@@ -574,46 +585,11 @@ |
574 | 585 |
|
575 |
/// \brief |
|
586 |
/// \brief The first node of the edge. |
|
576 | 587 |
/// |
577 |
/// Direct the given edge. The returned arc source |
|
578 |
/// will be the given node. |
|
579 |
Arc direct(const Edge&, const Node&) const { |
|
580 |
return INVALID; |
|
581 |
} |
|
582 |
|
|
583 |
/// |
|
588 |
/// Returns the first node of the given edge. |
|
584 | 589 |
/// |
585 |
/// Direct the given edge. The returned arc |
|
586 |
/// represents the given edge and the direction comes |
|
587 |
/// from the bool parameter. The source of the edge and |
|
588 |
/// the directed arc is the same when the given bool is true. |
|
589 |
Arc direct(const Edge&, bool) const { |
|
590 |
return INVALID; |
|
591 |
} |
|
592 |
|
|
593 |
/// \brief Returns true if the arc has default orientation. |
|
594 |
/// |
|
595 |
/// Returns whether the given directed arc is same orientation as |
|
596 |
/// the corresponding edge's default orientation. |
|
597 |
bool direction(Arc) const { return true; } |
|
598 |
|
|
599 |
/// \brief Returns the opposite directed arc. |
|
600 |
/// |
|
601 |
/// Returns the opposite directed arc. |
|
602 |
Arc oppositeArc(Arc) const { return INVALID; } |
|
603 |
|
|
604 |
/// \brief Opposite node on an arc |
|
605 |
/// |
|
606 |
/// \return The opposite of the given node on the given edge. |
|
607 |
Node oppositeNode(Node, Edge) const { return INVALID; } |
|
608 |
|
|
609 |
/// \brief First node of the edge. |
|
610 |
/// |
|
611 |
/// \return The first node of the given edge. |
|
612 |
/// |
|
613 |
/// Naturally edges don't have direction and thus |
|
614 |
/// don't have source and target node. However we use \c u() and \c v() |
|
615 |
/// methods to query the two nodes of the arc. The direction of the |
|
616 |
/// arc which arises this way is called the inherent direction of the |
|
617 |
/// edge, and is used to define the "default" direction |
|
618 |
/// of the directed versions of the arcs. |
|
590 |
/// Edges don't have source and target nodes, however, methods |
|
591 |
/// u() and v() are used to query the two end-nodes of an edge. |
|
592 |
/// The orientation of an edge that arises this way is called |
|
593 |
/// the inherent direction, it is used to define the default |
|
594 |
/// direction for the corresponding arcs. |
|
619 | 595 |
/// \sa v() |
... | ... |
@@ -622,12 +598,11 @@ |
622 | 598 |
|
623 |
/// \brief |
|
599 |
/// \brief The second node of the edge. |
|
624 | 600 |
/// |
625 |
/// |
|
601 |
/// Returns the second node of the given edge. |
|
626 | 602 |
/// |
627 |
/// Naturally edges don't have direction and thus |
|
628 |
/// don't have source and target node. However we use \c u() and \c v() |
|
629 |
/// methods to query the two nodes of the arc. The direction of the |
|
630 |
/// arc which arises this way is called the inherent direction of the |
|
631 |
/// edge, and is used to define the "default" direction |
|
632 |
/// of the directed versions of the arcs. |
|
603 |
/// Edges don't have source and target nodes, however, methods |
|
604 |
/// u() and v() are used to query the two end-nodes of an edge. |
|
605 |
/// The orientation of an edge that arises this way is called |
|
606 |
/// the inherent direction, it is used to define the default |
|
607 |
/// direction for the corresponding arcs. |
|
633 | 608 |
/// \sa u() |
... | ... |
@@ -636,41 +611,94 @@ |
636 | 611 |
|
637 |
/// \brief |
|
612 |
/// \brief The source node of the arc. |
|
613 |
/// |
|
614 |
/// Returns the source node of the given arc. |
|
638 | 615 |
Node source(Arc) const { return INVALID; } |
639 | 616 |
|
640 |
/// \brief |
|
617 |
/// \brief The target node of the arc. |
|
618 |
/// |
|
619 |
/// Returns the target node of the given arc. |
|
641 | 620 |
Node target(Arc) const { return INVALID; } |
642 | 621 |
|
643 |
/// \brief |
|
622 |
/// \brief The ID of the node. |
|
623 |
/// |
|
624 |
/// Returns the ID of the given node. |
|
644 | 625 |
int id(Node) const { return -1; } |
645 | 626 |
|
646 |
/// \brief |
|
627 |
/// \brief The ID of the edge. |
|
628 |
/// |
|
629 |
/// Returns the ID of the given edge. |
|
647 | 630 |
int id(Edge) const { return -1; } |
648 | 631 |
|
649 |
/// \brief |
|
632 |
/// \brief The ID of the arc. |
|
633 |
/// |
|
634 |
/// Returns the ID of the given arc. |
|
650 | 635 |
int id(Arc) const { return -1; } |
651 | 636 |
|
652 |
/// \brief |
|
637 |
/// \brief The node with the given ID. |
|
653 | 638 |
/// |
654 |
/// |
|
639 |
/// Returns the node with the given ID. |
|
640 |
/// \pre The argument should be a valid node ID in the graph. |
|
655 | 641 |
Node nodeFromId(int) const { return INVALID; } |
656 | 642 |
|
657 |
/// \brief |
|
643 |
/// \brief The edge with the given ID. |
|
658 | 644 |
/// |
659 |
/// |
|
645 |
/// Returns the edge with the given ID. |
|
646 |
/// \pre The argument should be a valid edge ID in the graph. |
|
660 | 647 |
Edge edgeFromId(int) const { return INVALID; } |
661 | 648 |
|
662 |
/// \brief |
|
649 |
/// \brief The arc with the given ID. |
|
663 | 650 |
/// |
664 |
/// |
|
651 |
/// Returns the arc with the given ID. |
|
652 |
/// \pre The argument should be a valid arc ID in the graph. |
|
665 | 653 |
Arc arcFromId(int) const { return INVALID; } |
666 | 654 |
|
667 |
/// \brief |
|
655 |
/// \brief An upper bound on the node IDs. |
|
656 |
/// |
|
657 |
/// Returns an upper bound on the node IDs. |
|
668 | 658 |
int maxNodeId() const { return -1; } |
669 | 659 |
|
670 |
/// \brief |
|
660 |
/// \brief An upper bound on the edge IDs. |
|
661 |
/// |
|
662 |
/// Returns an upper bound on the edge IDs. |
|
671 | 663 |
int maxEdgeId() const { return -1; } |
672 | 664 |
|
673 |
/// \brief |
|
665 |
/// \brief An upper bound on the arc IDs. |
|
666 |
/// |
|
667 |
/// Returns an upper bound on the arc IDs. |
|
674 | 668 |
int maxArcId() const { return -1; } |
675 | 669 |
|
670 |
/// \brief The direction of the arc. |
|
671 |
/// |
|
672 |
/// Returns \c true if the direction of the given arc is the same as |
|
673 |
/// the inherent orientation of the represented edge. |
|
674 |
bool direction(Arc) const { return true; } |
|
675 |
|
|
676 |
/// \brief Direct the edge. |
|
677 |
/// |
|
678 |
/// Direct the given edge. The returned arc |
|
679 |
/// represents the given edge and its direction comes |
|
680 |
/// from the bool parameter. If it is \c true, then the direction |
|
681 |
/// of the arc is the same as the inherent orientation of the edge. |
|
682 |
Arc direct(Edge, bool) const { |
|
683 |
return INVALID; |
|
684 |
} |
|
685 |
|
|
686 |
/// \brief Direct the edge. |
|
687 |
/// |
|
688 |
/// Direct the given edge. The returned arc represents the given |
|
689 |
/// edge and its source node is the given node. |
|
690 |
Arc direct(Edge, Node) const { |
|
691 |
return INVALID; |
|
692 |
} |
|
693 |
|
|
694 |
/// \brief The oppositely directed arc. |
|
695 |
/// |
|
696 |
/// Returns the oppositely directed arc representing the same edge. |
|
697 |
Arc oppositeArc(Arc) const { return INVALID; } |
|
698 |
|
|
699 |
/// \brief The opposite node on the edge. |
|
700 |
/// |
|
701 |
/// Returns the opposite node on the given edge. |
|
702 |
Node oppositeNode(Node, Edge) const { return INVALID; } |
|
703 |
|
|
676 | 704 |
void first(Node&) const {} |
... | ... |
@@ -707,43 +735,35 @@ |
707 | 735 |
|
708 |
/// \brief |
|
736 |
/// \brief The base node of the iterator. |
|
709 | 737 |
/// |
710 |
/// Returns the base node (the source in this case) of the iterator |
|
711 |
Node baseNode(OutArcIt e) const { |
|
712 |
return source(e); |
|
713 |
} |
|
714 |
/// |
|
738 |
/// Returns the base node of the given incident edge iterator. |
|
739 |
Node baseNode(IncEdgeIt) const { return INVALID; } |
|
740 |
|
|
741 |
/// \brief The running node of the iterator. |
|
715 | 742 |
/// |
716 |
/// Returns the running node (the target in this case) of the |
|
717 |
/// iterator |
|
718 |
Node runningNode(OutArcIt e) const { |
|
719 |
return target(e); |
|
720 |
|
|
743 |
/// Returns the running node of the given incident edge iterator. |
|
744 |
Node runningNode(IncEdgeIt) const { return INVALID; } |
|
721 | 745 |
|
722 |
/// \brief |
|
746 |
/// \brief The base node of the iterator. |
|
723 | 747 |
/// |
724 |
/// Returns the base node (the target in this case) of the iterator |
|
725 |
Node baseNode(InArcIt e) const { |
|
726 |
return target(e); |
|
727 |
} |
|
728 |
/// |
|
748 |
/// Returns the base node of the given outgoing arc iterator |
|
749 |
/// (i.e. the source node of the corresponding arc). |
|
750 |
Node baseNode(OutArcIt) const { return INVALID; } |
|
751 |
|
|
752 |
/// \brief The running node of the iterator. |
|
729 | 753 |
/// |
730 |
/// Returns the running node (the source in this case) of the |
|
731 |
/// iterator |
|
732 |
Node runningNode(InArcIt e) const { |
|
733 |
return source(e); |
|
734 |
|
|
754 |
/// Returns the running node of the given outgoing arc iterator |
|
755 |
/// (i.e. the target node of the corresponding arc). |
|
756 |
Node runningNode(OutArcIt) const { return INVALID; } |
|
735 | 757 |
|
736 |
/// \brief |
|
758 |
/// \brief The base node of the iterator. |
|
737 | 759 |
/// |
738 |
/// Returns the base node of the iterator |
|
739 |
Node baseNode(IncEdgeIt) const { |
|
740 |
return INVALID; |
|
741 |
} |
|
760 |
/// Returns the base node of the given incomming arc iterator |
|
761 |
/// (i.e. the target node of the corresponding arc). |
|
762 |
Node baseNode(InArcIt) const { return INVALID; } |
|
742 | 763 |
|
743 |
/// \brief |
|
764 |
/// \brief The running node of the iterator. |
|
744 | 765 |
/// |
745 |
/// Returns the running node of the iterator |
|
746 |
Node runningNode(IncEdgeIt) const { |
|
747 |
return INVALID; |
|
748 |
} |
|
766 |
/// Returns the running node of the given incomming arc iterator |
|
767 |
/// (i.e. the source node of the corresponding arc). |
|
768 |
Node runningNode(InArcIt) const { return INVALID; } |
|
749 | 769 |
... | ... |
@@ -20,3 +20,3 @@ |
20 | 20 |
///\file |
21 |
///\brief The |
|
21 |
///\brief The concepts of graph components. |
|
22 | 22 |
|
... | ... |
@@ -94,3 +94,3 @@ |
94 | 94 |
/// |
95 |
/// \note This operator only |
|
95 |
/// \note This operator only has to define some strict ordering of |
|
96 | 96 |
/// the items; this order has nothing to do with the iteration |
... | ... |
@@ -18,2 +18,5 @@ |
18 | 18 |
|
19 |
#ifndef LEMON_CONCEPTS_HEAP_H |
|
20 |
#define LEMON_CONCEPTS_HEAP_H |
|
21 |
|
|
19 | 22 |
///\ingroup concept |
... | ... |
@@ -22,5 +25,2 @@ |
22 | 25 |
|
23 |
#ifndef LEMON_CONCEPTS_HEAP_H |
|
24 |
#define LEMON_CONCEPTS_HEAP_H |
|
25 |
|
|
26 | 26 |
#include <lemon/core.h> |
... | ... |
@@ -37,17 +37,23 @@ |
37 | 37 |
/// |
38 |
/// Concept class describing the main interface of heaps. A \e heap |
|
39 |
/// is a data structure for storing items with specified values called |
|
40 |
/// \e priorities in such a way that finding the item with minimum |
|
41 |
/// priority is efficient. In a heap one can change the priority of an |
|
42 |
/// |
|
38 |
/// This concept class describes the main interface of heaps. |
|
39 |
/// The various \ref heaps "heap structures" are efficient |
|
40 |
/// implementations of the abstract data type \e priority \e queue. |
|
41 |
/// They store items with specified values called \e priorities |
|
42 |
/// in such a way that finding and removing the item with minimum |
|
43 |
/// priority are efficient. The basic operations are adding and |
|
44 |
/// erasing items, changing the priority of an item, etc. |
|
43 | 45 |
/// |
44 |
/// \tparam PR Type of the priority of the items. |
|
45 |
/// \tparam IM A read and writable item map with int values, used |
|
46 |
/// Heaps are crucial in several algorithms, such as Dijkstra and Prim. |
|
47 |
/// Any class that conforms to this concept can be used easily in such |
|
48 |
/// algorithms. |
|
49 |
/// |
|
50 |
/// \tparam PR Type of the priorities of the items. |
|
51 |
/// \tparam IM A read-writable item map with \c int values, used |
|
46 | 52 |
/// internally to handle the cross references. |
47 |
/// \tparam |
|
53 |
/// \tparam CMP A functor class for comparing the priorities. |
|
48 | 54 |
/// The default is \c std::less<PR>. |
49 | 55 |
#ifdef DOXYGEN |
50 |
template <typename PR, typename IM, typename |
|
56 |
template <typename PR, typename IM, typename CMP> |
|
51 | 57 |
#else |
52 |
template <typename PR, typename IM> |
|
58 |
template <typename PR, typename IM, typename CMP = std::less<PR> > |
|
53 | 59 |
#endif |
... | ... |
@@ -66,5 +72,4 @@ |
66 | 72 |
/// Each item has a state associated to it. It can be "in heap", |
67 |
/// "pre heap" or "post heap". The later two are indifferent |
|
68 |
/// from the point of view of the heap, but may be useful for |
|
69 |
/// |
|
73 |
/// "pre-heap" or "post-heap". The latter two are indifferent from the |
|
74 |
/// heap's point of view, but may be useful to the user. |
|
70 | 75 |
/// |
... | ... |
@@ -74,9 +79,9 @@ |
74 | 79 |
IN_HEAP = 0, ///< = 0. The "in heap" state constant. |
75 |
PRE_HEAP = -1, ///< = -1. The "pre heap" state constant. |
|
76 |
POST_HEAP = -2 ///< = -2. The "post heap" state constant. |
|
80 |
PRE_HEAP = -1, ///< = -1. The "pre-heap" state constant. |
|
81 |
POST_HEAP = -2 ///< = -2. The "post-heap" state constant. |
|
77 | 82 |
}; |
78 | 83 |
|
79 |
/// \brief |
|
84 |
/// \brief Constructor. |
|
80 | 85 |
/// |
81 |
/// |
|
86 |
/// Constructor. |
|
82 | 87 |
/// \param map A map that assigns \c int values to keys of type |
... | ... |
@@ -84,30 +89,46 @@ |
84 | 89 |
/// handle the cross references. The assigned value must be |
85 |
/// \c PRE_HEAP (<tt>-1</tt>) for |
|
90 |
/// \c PRE_HEAP (<tt>-1</tt>) for each item. |
|
86 | 91 |
explicit Heap(ItemIntMap &map) {} |
87 | 92 |
|
93 |
/// \brief Constructor. |
|
94 |
/// |
|
95 |
/// Constructor. |
|
96 |
/// \param map A map that assigns \c int values to keys of type |
|
97 |
/// \c Item. It is used internally by the heap implementations to |
|
98 |
/// handle the cross references. The assigned value must be |
|
99 |
/// \c PRE_HEAP (<tt>-1</tt>) for each item. |
|
100 |
/// \param comp The function object used for comparing the priorities. |
|
101 |
explicit Heap(ItemIntMap &map, const CMP &comp) {} |
|
102 |
|
|
88 | 103 |
/// \brief The number of items stored in the heap. |
89 | 104 |
/// |
90 |
/// |
|
105 |
/// This function returns the number of items stored in the heap. |
|
91 | 106 |
int size() const { return 0; } |
92 | 107 |
|
93 |
/// \brief |
|
108 |
/// \brief Check if the heap is empty. |
|
94 | 109 |
/// |
95 |
/// |
|
110 |
/// This function returns \c true if the heap is empty. |
|
96 | 111 |
bool empty() const { return false; } |
97 | 112 |
|
98 |
/// \brief |
|
113 |
/// \brief Make the heap empty. |
|
99 | 114 |
/// |
100 |
/// Makes the heap empty. |
|
101 |
void clear(); |
|
115 |
/// This functon makes the heap empty. |
|
116 |
/// It does not change the cross reference map. If you want to reuse |
|
117 |
/// a heap that is not surely empty, you should first clear it and |
|
118 |
/// then you should set the cross reference map to \c PRE_HEAP |
|
119 |
/// for each item. |
|
120 |
void clear() {} |
|
102 | 121 |
|
103 |
/// \brief |
|
122 |
/// \brief Insert an item into the heap with the given priority. |
|
104 | 123 |
/// |
105 |
/// |
|
124 |
/// This function inserts the given item into the heap with the |
|
125 |
/// given priority. |
|
106 | 126 |
/// \param i The item to insert. |
107 | 127 |
/// \param p The priority of the item. |
128 |
/// \pre \e i must not be stored in the heap. |
|
108 | 129 |
void push(const Item &i, const Prio &p) {} |
109 | 130 |
|
110 |
/// \brief |
|
131 |
/// \brief Return the item having minimum priority. |
|
111 | 132 |
/// |
112 |
/// |
|
133 |
/// This function returns the item having minimum priority. |
|
113 | 134 |
/// \pre The heap must be non-empty. |
... | ... |
@@ -117,3 +138,3 @@ |
117 | 138 |
/// |
118 |
/// |
|
139 |
/// This function returns the minimum priority. |
|
119 | 140 |
/// \pre The heap must be non-empty. |
... | ... |
@@ -121,5 +142,5 @@ |
121 | 142 |
|
122 |
/// \brief |
|
143 |
/// \brief Remove the item having minimum priority. |
|
123 | 144 |
/// |
124 |
/// |
|
145 |
/// This function removes the item having minimum priority. |
|
125 | 146 |
/// \pre The heap must be non-empty. |
... | ... |
@@ -127,16 +148,18 @@ |
127 | 148 |
|
128 |
/// \brief |
|
149 |
/// \brief Remove the given item from the heap. |
|
129 | 150 |
/// |
130 |
/// |
|
151 |
/// This function removes the given item from the heap if it is |
|
152 |
/// already stored. |
|
131 | 153 |
/// \param i The item to delete. |
154 |
/// \pre \e i must be in the heap. |
|
132 | 155 |
void erase(const Item &i) {} |
133 | 156 |
|
134 |
/// \brief The priority of |
|
157 |
/// \brief The priority of the given item. |
|
135 | 158 |
/// |
136 |
/// |
|
159 |
/// This function returns the priority of the given item. |
|
137 | 160 |
/// \param i The item. |
138 |
/// \pre \ |
|
161 |
/// \pre \e i must be in the heap. |
|
139 | 162 |
Prio operator[](const Item &i) const {} |
140 | 163 |
|
141 |
/// \brief |
|
164 |
/// \brief Set the priority of an item or insert it, if it is |
|
142 | 165 |
/// not stored in the heap. |
... | ... |
@@ -144,4 +167,4 @@ |
144 | 167 |
/// This method sets the priority of the given item if it is |
145 |
/// already stored in the heap. |
|
146 |
/// Otherwise it inserts the given item with the given priority. |
|
168 |
/// already stored in the heap. Otherwise it inserts the given |
|
169 |
/// item into the heap with the given priority. |
|
147 | 170 |
/// |
... | ... |
@@ -151,20 +174,19 @@ |
151 | 174 |
|
152 |
/// \brief |
|
175 |
/// \brief Decrease the priority of an item to the given value. |
|
153 | 176 |
/// |
154 |
/// |
|
177 |
/// This function decreases the priority of an item to the given value. |
|
155 | 178 |
/// \param i The item. |
156 | 179 |
/// \param p The priority. |
157 |
/// \pre \ |
|
180 |
/// \pre \e i must be stored in the heap with priority at least \e p. |
|
158 | 181 |
void decrease(const Item &i, const Prio &p) {} |
159 | 182 |
|
160 |
/// \brief |
|
183 |
/// \brief Increase the priority of an item to the given value. |
|
161 | 184 |
/// |
162 |
/// |
|
185 |
/// This function increases the priority of an item to the given value. |
|
163 | 186 |
/// \param i The item. |
164 | 187 |
/// \param p The priority. |
165 |
/// \pre \ |
|
188 |
/// \pre \e i must be stored in the heap with priority at most \e p. |
|
166 | 189 |
void increase(const Item &i, const Prio &p) {} |
167 | 190 |
|
168 |
/// \brief Returns if an item is in, has already been in, or has |
|
169 |
/// never been in the heap. |
|
191 |
/// \brief Return the state of an item. |
|
170 | 192 |
/// |
... | ... |
@@ -178,7 +200,7 @@ |
178 | 200 |
|
179 |
/// \brief |
|
201 |
/// \brief Set the state of an item in the heap. |
|
180 | 202 |
/// |
181 |
/// Sets the state of the given item in the heap. It can be used |
|
182 |
/// to manually clear the heap when it is important to achive the |
|
183 |
/// |
|
203 |
/// This function sets the state of the given item in the heap. |
|
204 |
/// It can be used to manually clear the heap when it is important |
|
205 |
/// to achive better time complexity. |
|
184 | 206 |
/// \param i The item. |
... | ... |
@@ -20,3 +20,3 @@ |
20 | 20 |
///\file |
21 |
///\brief |
|
21 |
///\brief The concept of paths |
|
22 | 22 |
/// |
... | ... |
@@ -40,9 +40,18 @@ |
40 | 40 |
/// digraph. |
41 |
/// In a sense, a path can be treated as a list of arcs. |
|
42 |
/// LEMON path types just store this list. As a consequence, they cannot |
|
43 |
/// enumerate the nodes on the path directly and a zero length path |
|
44 |
/// cannot store its source node. |
|
45 |
/// |
|
46 |
/// The arcs of a path should be stored in the order of their directions, |
|
47 |
/// i.e. the target node of each arc should be the same as the source |
|
48 |
/// node of the next arc. This consistency could be checked using |
|
49 |
/// \ref checkPath(). |
|
50 |
/// The source and target nodes of a (consistent) path can be obtained |
|
51 |
/// using \ref pathSource() and \ref pathTarget(). |
|
52 |
/// |
|
53 |
/// A path can be constructed from another path of any type using the |
|
54 |
/// copy constructor or the assignment operator. |
|
55 |
/// |
|
41 | 56 |
/// \tparam GR The digraph type in which the path is. |
42 |
/// |
|
43 |
/// In a sense, the path can be treated as a list of arcs. The |
|
44 |
/// lemon path type stores just this list. As a consequence it |
|
45 |
/// cannot enumerate the nodes in the path and the zero length |
|
46 |
/// paths cannot store the source. |
|
47 |
/// |
|
48 | 57 |
template <typename GR> |
... | ... |
@@ -61,3 +70,3 @@ |
61 | 70 |
|
62 |
/// \brief Template constructor |
|
71 |
/// \brief Template copy constructor |
|
63 | 72 |
template <typename CPath> |
... | ... |
@@ -65,3 +74,3 @@ |
65 | 74 |
|
66 |
/// \brief Template assigment |
|
75 |
/// \brief Template assigment operator |
|
67 | 76 |
template <typename CPath> |
... | ... |
@@ -72,3 +81,3 @@ |
72 | 81 |
|
73 |
/// Length of the path |
|
82 |
/// Length of the path, i.e. the number of arcs on the path. |
|
74 | 83 |
int length() const { return 0;} |
... | ... |
@@ -81,5 +90,5 @@ |
81 | 90 |
|
82 |
/// \brief LEMON style iterator for |
|
91 |
/// \brief LEMON style iterator for enumerating the arcs of a path. |
|
83 | 92 |
/// |
84 |
/// |
|
93 |
/// LEMON style iterator class for enumerating the arcs of a path. |
|
85 | 94 |
class ArcIt { |
... | ... |
@@ -90,6 +99,6 @@ |
90 | 99 |
ArcIt(Invalid) {} |
91 |
/// |
|
100 |
/// Sets the iterator to the first arc of the given path |
|
92 | 101 |
ArcIt(const Path &) {} |
93 | 102 |
|
94 |
/// Conversion to Arc |
|
103 |
/// Conversion to \c Arc |
|
95 | 104 |
operator Arc() const { return INVALID; } |
... | ... |
@@ -194,14 +203,11 @@ |
194 | 203 |
/// A skeleton structure for path dumpers. The path dumpers are |
195 |
/// the generalization of the paths. The path dumpers can |
|
196 |
/// enumerate the arcs of the path wheter in forward or in |
|
197 |
/// backward order. In most time these classes are not used |
|
198 |
/// directly rather it used to assign a dumped class to a real |
|
199 |
/// |
|
204 |
/// the generalization of the paths, they can enumerate the arcs |
|
205 |
/// of the path either in forward or in backward order. |
|
206 |
/// These classes are typically not used directly, they are rather |
|
207 |
/// used to be assigned to a real path type. |
|
200 | 208 |
/// |
201 | 209 |
/// The main purpose of this concept is that the shortest path |
202 |
/// algorithms can enumerate easily the arcs in reverse order. |
|
203 |
/// If we would like to give back a real path from these |
|
204 |
/// algorithms then we should create a temporarly path object. In |
|
205 |
/// LEMON such algorithms gives back a path dumper what can |
|
206 |
/// |
|
210 |
/// algorithms can enumerate the arcs easily in reverse order. |
|
211 |
/// In LEMON, such algorithms give back a (reverse) path dumper that |
|
212 |
/// can be assigned to a real path. The dumpers can be implemented as |
|
207 | 213 |
/// an adaptor class to the predecessor map. |
... | ... |
@@ -209,5 +215,2 @@ |
209 | 215 |
/// \tparam GR The digraph type in which the path is. |
210 |
/// |
|
211 |
/// The paths can be constructed from any path type by a |
|
212 |
/// template constructor or a template assignment operator. |
|
213 | 216 |
template <typename GR> |
... | ... |
@@ -221,3 +224,3 @@ |
221 | 224 |
|
222 |
/// Length of the path |
|
225 |
/// Length of the path, i.e. the number of arcs on the path. |
|
223 | 226 |
int length() const { return 0;} |
... | ... |
@@ -229,11 +232,10 @@ |
229 | 232 |
/// |
230 |
/// If the RevPathTag is defined and true then reverse dumping |
|
231 |
/// is provided in the path dumper. In this case instead of the |
|
232 |
/// ArcIt the RevArcIt iterator should be implemented in the |
|
233 |
/// dumper. |
|
233 |
/// If this tag is defined to be \c True, then reverse dumping |
|
234 |
/// is provided in the path dumper. In this case, \c RevArcIt |
|
235 |
/// iterator should be implemented instead of \c ArcIt iterator. |
|
234 | 236 |
typedef False RevPathTag; |
235 | 237 |
|
236 |
/// \brief LEMON style iterator for |
|
238 |
/// \brief LEMON style iterator for enumerating the arcs of a path. |
|
237 | 239 |
/// |
238 |
/// |
|
240 |
/// LEMON style iterator class for enumerating the arcs of a path. |
|
239 | 241 |
class ArcIt { |
... | ... |
@@ -244,6 +246,6 @@ |
244 | 246 |
ArcIt(Invalid) {} |
245 |
/// |
|
247 |
/// Sets the iterator to the first arc of the given path |
|
246 | 248 |
ArcIt(const PathDumper&) {} |
247 | 249 |
|
248 |
/// Conversion to Arc |
|
250 |
/// Conversion to \c Arc |
|
249 | 251 |
operator Arc() const { return INVALID; } |
... | ... |
@@ -262,6 +264,7 @@ |
262 | 264 |
|
263 |
/// \brief LEMON style iterator for |
|
265 |
/// \brief LEMON style iterator for enumerating the arcs of a path |
|
266 |
/// in reverse direction. |
|
264 | 267 |
/// |
265 |
/// This class is used to iterate on the arcs of the paths in |
|
266 |
/// reverse direction. |
|
268 |
/// LEMON style iterator class for enumerating the arcs of a path |
|
269 |
/// in reverse direction. |
|
267 | 270 |
class RevArcIt { |
... | ... |
@@ -272,6 +275,6 @@ |
272 | 275 |
RevArcIt(Invalid) {} |
273 |
/// |
|
276 |
/// Sets the iterator to the last arc of the given path |
|
274 | 277 |
RevArcIt(const PathDumper &) {} |
275 | 278 |
|
276 |
/// Conversion to Arc |
|
279 |
/// Conversion to \c Arc |
|
277 | 280 |
operator Arc() const { return INVALID; } |
... | ... |
@@ -113,2 +113,35 @@ |
113 | 113 |
|
114 |
int CplexBase::_addRow(Value lb, ExprIterator b, |
|
115 |
ExprIterator e, Value ub) { |
|
116 |
int i = CPXgetnumrows(cplexEnv(), _prob); |
|
117 |
if (lb == -INF) { |
|
118 |
const char s = 'L'; |
|
119 |
CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0); |
|
120 |
} else if (ub == INF) { |
|
121 |
const char s = 'G'; |
|
122 |
CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0); |
|
123 |
} else if (lb == ub){ |
|
124 |
const char s = 'E'; |
|
125 |
CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0); |
|
126 |
} else { |
|
127 |
const char s = 'R'; |
|
128 |
double len = ub - lb; |
|
129 |
CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, &len, 0); |
|
130 |
} |
|
131 |
|
|
132 |
std::vector<int> indices; |
|
133 |
std::vector<int> rowlist; |
|
134 |
std::vector<Value> values; |
|
135 |
|
|
136 |
for(ExprIterator it=b; it!=e; ++it) { |
|
137 |
indices.push_back(it->first); |
|
138 |
values.push_back(it->second); |
|
139 |
rowlist.push_back(i); |
|
140 |
} |
|
141 |
|
|
142 |
CPXchgcoeflist(cplexEnv(), _prob, values.size(), |
|
143 |
&rowlist.front(), &indices.front(), &values.front()); |
|
144 |
|
|
145 |
return i; |
|
146 |
} |
|
114 | 147 |
... | ... |
@@ -49,3 +49,3 @@ |
49 | 49 |
///arcs of the %DFS paths. |
50 |
///It must |
|
50 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
51 | 51 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
... | ... |
@@ -64,3 +64,4 @@ |
64 | 64 |
///The type of the map that indicates which nodes are processed. |
65 |
///It must |
|
65 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
66 |
///By default, it is a NullMap. |
|
66 | 67 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
... | ... |
@@ -83,3 +84,3 @@ |
83 | 84 |
///The type of the map that indicates which nodes are reached. |
84 |
///It must |
|
85 |
///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
85 | 86 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
... | ... |
@@ -98,3 +99,3 @@ |
98 | 99 |
///The type of the map that stores the distances of the nodes. |
99 |
///It must |
|
100 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
100 | 101 |
typedef typename Digraph::template NodeMap<int> DistMap; |
... | ... |
@@ -226,3 +227,3 @@ |
226 | 227 |
///\c PredMap type. |
227 |
///It must |
|
228 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
228 | 229 |
template <class T> |
... | ... |
@@ -246,3 +247,3 @@ |
246 | 247 |
///\c DistMap type. |
247 |
///It must |
|
248 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
248 | 249 |
template <class T> |
... | ... |
@@ -266,3 +267,3 @@ |
266 | 267 |
///\c ReachedMap type. |
267 |
///It must |
|
268 |
///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
268 | 269 |
template <class T> |
... | ... |
@@ -286,3 +287,3 @@ |
286 | 287 |
///\c ProcessedMap type. |
287 |
///It must |
|
288 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
288 | 289 |
template <class T> |
... | ... |
@@ -413,4 +414,4 @@ |
413 | 414 |
///member functions called \ref run(Node) "run()".\n |
414 |
///If you need more control on the execution, first you have to call |
|
415 |
///\ref init(), then you can add a source node with \ref addSource() |
|
415 |
///If you need better control on the execution, you have to call |
|
416 |
///\ref init() first, then you can add a source node with \ref addSource() |
|
416 | 417 |
///and perform the actual computation with \ref start(). |
... | ... |
@@ -634,8 +635,4 @@ |
634 | 635 |
|
635 |
///This method runs the %DFS algorithm in order to compute the |
|
636 |
///%DFS path to each node. |
|
637 |
/// |
|
638 |
///The algorithm computes |
|
639 |
///- the %DFS tree (forest), |
|
640 |
///- the distance of each node from the root(s) in the %DFS tree. |
|
636 |
///This method runs the %DFS algorithm in order to visit all nodes |
|
637 |
///in the digraph. |
|
641 | 638 |
/// |
... | ... |
@@ -671,5 +668,5 @@ |
671 | 668 |
|
672 |
///The DFS path to |
|
669 |
///The DFS path to the given node. |
|
673 | 670 |
|
674 |
///Returns the DFS path to |
|
671 |
///Returns the DFS path to the given node from the root(s). |
|
675 | 672 |
/// |
... | ... |
@@ -681,5 +678,5 @@ |
681 | 678 |
|
682 |
///The distance of |
|
679 |
///The distance of the given node from the root(s). |
|
683 | 680 |
|
684 |
///Returns the distance of |
|
681 |
///Returns the distance of the given node from the root(s). |
|
685 | 682 |
/// |
... | ... |
@@ -692,3 +689,3 @@ |
692 | 689 |
|
693 |
///Returns the 'previous arc' of the %DFS tree for |
|
690 |
///Returns the 'previous arc' of the %DFS tree for the given node. |
|
694 | 691 |
|
... | ... |
@@ -700,3 +697,3 @@ |
700 | 697 |
///The %DFS tree used here is equal to the %DFS tree used in |
701 |
///\ref predNode(). |
|
698 |
///\ref predNode() and \ref predMap(). |
|
702 | 699 |
/// |
... | ... |
@@ -706,3 +703,3 @@ |
706 | 703 |
|
707 |
///Returns the 'previous node' of the %DFS tree. |
|
704 |
///Returns the 'previous node' of the %DFS tree for the given node. |
|
708 | 705 |
|
... | ... |
@@ -710,3 +707,3 @@ |
710 | 707 |
///tree for the node \c v, i.e. it returns the last but one node |
711 |
/// |
|
708 |
///of a %DFS path from a root to \c v. It is \c INVALID |
|
712 | 709 |
///if \c v is not reached from the root(s) or if \c v is a root. |
... | ... |
@@ -714,3 +711,3 @@ |
714 | 711 |
///The %DFS tree used here is equal to the %DFS tree used in |
715 |
///\ref predArc(). |
|
712 |
///\ref predArc() and \ref predMap(). |
|
716 | 713 |
/// |
... | ... |
@@ -735,3 +732,3 @@ |
735 | 732 |
///Returns a const reference to the node map that stores the predecessor |
736 |
///arcs, which form the DFS tree. |
|
733 |
///arcs, which form the DFS tree (forest). |
|
737 | 734 |
/// |
... | ... |
@@ -741,3 +738,3 @@ |
741 | 738 |
|
742 |
///Checks if |
|
739 |
///Checks if the given node. node is reached from the root(s). |
|
743 | 740 |
|
... | ... |
@@ -767,3 +764,3 @@ |
767 | 764 |
///arcs of the %DFS paths. |
768 |
///It must |
|
765 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
769 | 766 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
... | ... |
@@ -782,4 +779,4 @@ |
782 | 779 |
///The type of the map that indicates which nodes are processed. |
783 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
|
784 |
///By default it is a NullMap. |
|
780 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
781 |
///By default, it is a NullMap. |
|
785 | 782 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
... | ... |
@@ -802,3 +799,3 @@ |
802 | 799 |
///The type of the map that indicates which nodes are reached. |
803 |
///It must |
|
800 |
///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
804 | 801 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
... | ... |
@@ -817,3 +814,3 @@ |
817 | 814 |
///The type of the map that stores the distances of the nodes. |
818 |
///It must |
|
815 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
819 | 816 |
typedef typename Digraph::template NodeMap<int> DistMap; |
... | ... |
@@ -832,3 +829,3 @@ |
832 | 829 |
///The type of the DFS paths. |
833 |
///It must |
|
830 |
///It must conform to the \ref concepts::Path "Path" concept. |
|
834 | 831 |
typedef lemon::Path<Digraph> Path; |
... | ... |
@@ -838,8 +835,4 @@ |
838 | 835 |
|
839 |
/// To make it easier to use Dfs algorithm |
|
840 |
/// we have created a wizard class. |
|
841 |
/// This \ref DfsWizard class needs default traits, |
|
842 |
/// as well as the \ref Dfs class. |
|
843 |
/// The \ref DfsWizardBase is a class to be the default traits of the |
|
844 |
/// \ref DfsWizard class. |
|
836 |
/// Default traits class used by DfsWizard. |
|
837 |
/// \tparam GR The type of the digraph. |
|
845 | 838 |
template<class GR> |
... | ... |
@@ -871,3 +864,3 @@ |
871 | 864 |
|
872 |
/// This constructor does not require parameters, |
|
865 |
/// This constructor does not require parameters, it initiates |
|
873 | 866 |
/// all of the attributes to \c 0. |
... | ... |
@@ -901,3 +894,2 @@ |
901 | 894 |
|
902 |
///The type of the digraph the algorithm runs on. |
|
903 | 895 |
typedef typename TR::Digraph Digraph; |
... | ... |
@@ -909,12 +901,6 @@ |
909 | 901 |
|
910 |
///\brief The type of the map that stores the predecessor |
|
911 |
///arcs of the DFS paths. |
|
912 | 902 |
typedef typename TR::PredMap PredMap; |
913 |
///\brief The type of the map that stores the distances of the nodes. |
|
914 | 903 |
typedef typename TR::DistMap DistMap; |
915 |
///\brief The type of the map that indicates which nodes are reached. |
|
916 | 904 |
typedef typename TR::ReachedMap ReachedMap; |
917 |
///\brief The type of the map that indicates which nodes are processed. |
|
918 | 905 |
typedef typename TR::ProcessedMap ProcessedMap; |
919 |
///The type of the DFS paths |
|
920 | 906 |
typedef typename TR::Path Path; |
... | ... |
@@ -988,4 +974,4 @@ |
988 | 974 |
|
989 |
///This method runs DFS algorithm in order to compute |
|
990 |
///the DFS path to each node. |
|
975 |
///This method runs DFS algorithm in order to visit all nodes |
|
976 |
///in the digraph. |
|
991 | 977 |
void run() |
... | ... |
@@ -1001,7 +987,8 @@ |
1001 | 987 |
}; |
1002 |
///\brief \ref named-func-param "Named parameter" |
|
1003 |
///for setting PredMap object. |
|
988 |
|
|
989 |
///\brief \ref named-templ-param "Named parameter" for setting |
|
990 |
///the predecessor map. |
|
1004 | 991 |
/// |
1005 |
///\ref named-func-param "Named parameter" |
|
1006 |
///for setting PredMap object. |
|
992 |
///\ref named-templ-param "Named parameter" function for setting |
|
993 |
///the map that stores the predecessor arcs of the nodes. |
|
1007 | 994 |
template<class T> |
... | ... |
@@ -1019,7 +1006,8 @@ |
1019 | 1006 |
}; |
1020 |
///\brief \ref named-func-param "Named parameter" |
|
1021 |
///for setting ReachedMap object. |
|
1007 |
|
|
1008 |
///\brief \ref named-templ-param "Named parameter" for setting |
|
1009 |
///the reached map. |
|
1022 | 1010 |
/// |
1023 |
/// \ref named-func-param "Named parameter" |
|
1024 |
///for setting ReachedMap object. |
|
1011 |
///\ref named-templ-param "Named parameter" function for setting |
|
1012 |
///the map that indicates which nodes are reached. |
|
1025 | 1013 |
template<class T> |
... | ... |
@@ -1037,7 +1025,9 @@ |
1037 | 1025 |
}; |
1038 |
///\brief \ref named-func-param "Named parameter" |
|
1039 |
///for setting DistMap object. |
|
1026 |
|
|
1027 |
///\brief \ref named-templ-param "Named parameter" for setting |
|
1028 |
///the distance map. |
|
1040 | 1029 |
/// |
1041 |
/// \ref named-func-param "Named parameter" |
|
1042 |
///for setting DistMap object. |
|
1030 |
///\ref named-templ-param "Named parameter" function for setting |
|
1031 |
///the map that stores the distances of the nodes calculated |
|
1032 |
///by the algorithm. |
|
1043 | 1033 |
template<class T> |
... | ... |
@@ -1055,7 +1045,8 @@ |
1055 | 1045 |
}; |
1056 |
///\brief \ref named-func-param "Named parameter" |
|
1057 |
///for setting ProcessedMap object. |
|
1046 |
|
|
1047 |
///\brief \ref named-func-param "Named parameter" for setting |
|
1048 |
///the processed map. |
|
1058 | 1049 |
/// |
1059 |
/// \ref named-func-param "Named parameter" |
|
1060 |
///for setting ProcessedMap object. |
|
1050 |
///\ref named-templ-param "Named parameter" function for setting |
|
1051 |
///the map that indicates which nodes are processed. |
|
1061 | 1052 |
template<class T> |
... | ... |
@@ -1210,3 +1201,3 @@ |
1210 | 1201 |
/// The type of the map that indicates which nodes are reached. |
1211 |
/// It must |
|
1202 |
/// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
1212 | 1203 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
... | ... |
@@ -1371,4 +1362,4 @@ |
1371 | 1362 |
/// member functions called \ref run(Node) "run()".\n |
1372 |
/// If you need more control on the execution, first you have to call |
|
1373 |
/// \ref init(), then you can add a source node with \ref addSource() |
|
1363 |
/// If you need better control on the execution, you have to call |
|
1364 |
/// \ref init() first, then you can add a source node with \ref addSource() |
|
1374 | 1365 |
/// and perform the actual computation with \ref start(). |
... | ... |
@@ -1585,8 +1576,4 @@ |
1585 | 1576 |
|
1586 |
/// This method runs the %DFS algorithm in order to |
|
1587 |
/// compute the %DFS path to each node. |
|
1588 |
/// |
|
1589 |
/// The algorithm computes |
|
1590 |
/// - the %DFS tree (forest), |
|
1591 |
/// - the distance of each node from the root(s) in the %DFS tree. |
|
1577 |
/// This method runs the %DFS algorithm in order to visit all nodes |
|
1578 |
/// in the digraph. |
|
1592 | 1579 |
/// |
... | ... |
@@ -1622,3 +1609,3 @@ |
1622 | 1609 |
|
1623 |
/// \brief Checks if |
|
1610 |
/// \brief Checks if the given node is reached from the root(s). |
|
1624 | 1611 |
/// |
... | ... |
@@ -72,5 +72,5 @@ |
72 | 72 |
///The type of the map that stores the arc lengths. |
73 |
///It must |
|
73 |
///It must conform to the \ref concepts::ReadMap "ReadMap" concept. |
|
74 | 74 |
typedef LEN LengthMap; |
75 |
///The type of the |
|
75 |
///The type of the arc lengths. |
|
76 | 76 |
typedef typename LEN::Value Value; |
... | ... |
@@ -118,3 +118,3 @@ |
118 | 118 |
///arcs of the shortest paths. |
119 |
///It must |
|
119 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
120 | 120 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
... | ... |
@@ -133,4 +133,4 @@ |
133 | 133 |
///The type of the map that indicates which nodes are processed. |
134 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
|
135 |
///By default it is a NullMap. |
|
134 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
135 |
///By default, it is a NullMap. |
|
136 | 136 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
... | ... |
@@ -153,3 +153,3 @@ |
153 | 153 |
///The type of the map that stores the distances of the nodes. |
154 |
///It must |
|
154 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
155 | 155 |
typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap; |
... | ... |
@@ -171,2 +171,6 @@ |
171 | 171 |
/// |
172 |
///The %Dijkstra algorithm solves the single-source shortest path problem |
|
173 |
///when all arc lengths are non-negative. If there are negative lengths, |
|
174 |
///the BellmanFord algorithm should be used instead. |
|
175 |
/// |
|
172 | 176 |
///The arc lengths are passed to the algorithm using a |
... | ... |
@@ -203,4 +207,4 @@ |
203 | 207 |
|
204 |
///The type of the length of the arcs. |
|
205 |
typedef typename TR::LengthMap::Value Value; |
|
208 |
///The type of the arc lengths. |
|
209 |
typedef typename TR::Value Value; |
|
206 | 210 |
///The type of the map that stores the arc lengths. |
... | ... |
@@ -306,3 +310,3 @@ |
306 | 310 |
///\c PredMap type. |
307 |
///It must |
|
311 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
308 | 312 |
template <class T> |
... | ... |
@@ -327,3 +331,3 @@ |
327 | 331 |
///\c DistMap type. |
328 |
///It must |
|
332 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
329 | 333 |
template <class T> |
... | ... |
@@ -348,3 +352,3 @@ |
348 | 352 |
///\c ProcessedMap type. |
349 |
///It must |
|
353 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
350 | 354 |
template <class T> |
... | ... |
@@ -424,3 +428,3 @@ |
424 | 428 |
///reference should be passed to the constructor of the heap). |
425 |
///However external heap and cross reference objects could also be |
|
429 |
///However, external heap and cross reference objects could also be |
|
426 | 430 |
///passed to the algorithm using the \ref heap() function before |
... | ... |
@@ -445,2 +449,3 @@ |
445 | 449 |
///\c OperationTraits type. |
450 |
/// For more information, see \ref DijkstraDefaultOperationTraits. |
|
446 | 451 |
template <class T> |
... | ... |
@@ -586,4 +591,4 @@ |
586 | 591 |
///one of the member functions called \ref run(Node) "run()".\n |
587 |
///If you need more control on the execution, first you have to call |
|
588 |
///\ref init(), then you can add several source nodes with |
|
592 |
///If you need better control on the execution, you have to call |
|
593 |
///\ref init() first, then you can add several source nodes with |
|
589 | 594 |
///\ref addSource(). Finally the actual path computation can be |
... | ... |
@@ -803,3 +808,3 @@ |
803 | 808 |
///functions.\n |
804 |
///Either \ref run(Node) "run()" or \ref |
|
809 |
///Either \ref run(Node) "run()" or \ref init() should be called |
|
805 | 810 |
///before using them. |
... | ... |
@@ -808,5 +813,5 @@ |
808 | 813 |
|
809 |
///The shortest path to |
|
814 |
///The shortest path to the given node. |
|
810 | 815 |
|
811 |
///Returns the shortest path to |
|
816 |
///Returns the shortest path to the given node from the root(s). |
|
812 | 817 |
/// |
... | ... |
@@ -818,5 +823,5 @@ |
818 | 823 |
|
819 |
///The distance of |
|
824 |
///The distance of the given node from the root(s). |
|
820 | 825 |
|
821 |
///Returns the distance of |
|
826 |
///Returns the distance of the given node from the root(s). |
|
822 | 827 |
/// |
... | ... |
@@ -829,4 +834,5 @@ |
829 | 834 |
|
830 |
///Returns the 'previous arc' of the shortest path tree for a node. |
|
831 |
|
|
835 |
///\brief Returns the 'previous arc' of the shortest path tree for |
|
836 |
///the given node. |
|
837 |
/// |
|
832 | 838 |
///This function returns the 'previous arc' of the shortest path |
... | ... |
@@ -837,3 +843,3 @@ |
837 | 843 |
///The shortest path tree used here is equal to the shortest path |
838 |
///tree used in \ref predNode(). |
|
844 |
///tree used in \ref predNode() and \ref predMap(). |
|
839 | 845 |
/// |
... | ... |
@@ -843,7 +849,8 @@ |
843 | 849 |
|
844 |
///Returns the 'previous node' of the shortest path tree for a node. |
|
845 |
|
|
850 |
///\brief Returns the 'previous node' of the shortest path tree for |
|
851 |
///the given node. |
|
852 |
/// |
|
846 | 853 |
///This function returns the 'previous node' of the shortest path |
847 | 854 |
///tree for the node \c v, i.e. it returns the last but one node |
848 |
/// |
|
855 |
///of a shortest path from a root to \c v. It is \c INVALID |
|
849 | 856 |
///if \c v is not reached from the root(s) or if \c v is a root. |
... | ... |
@@ -851,3 +858,3 @@ |
851 | 858 |
///The shortest path tree used here is equal to the shortest path |
852 |
///tree used in \ref predArc(). |
|
859 |
///tree used in \ref predArc() and \ref predMap(). |
|
853 | 860 |
/// |
... | ... |
@@ -872,3 +879,3 @@ |
872 | 879 |
///Returns a const reference to the node map that stores the predecessor |
873 |
///arcs, which form the shortest path tree. |
|
880 |
///arcs, which form the shortest path tree (forest). |
|
874 | 881 |
/// |
... | ... |
@@ -878,3 +885,3 @@ |
878 | 885 |
|
879 |
///Checks if |
|
886 |
///Checks if the given node is reached from the root(s). |
|
880 | 887 |
|
... | ... |
@@ -897,5 +904,5 @@ |
897 | 904 |
|
898 |
///The current distance of |
|
905 |
///The current distance of the given node from the root(s). |
|
899 | 906 |
|
900 |
///Returns the current distance of |
|
907 |
///Returns the current distance of the given node from the root(s). |
|
901 | 908 |
///It may be decreased in the following processes. |
... | ... |
@@ -926,5 +933,5 @@ |
926 | 933 |
///The type of the map that stores the arc lengths. |
927 |
///It must |
|
934 |
///It must conform to the \ref concepts::ReadMap "ReadMap" concept. |
|
928 | 935 |
typedef LEN LengthMap; |
929 |
///The type of the |
|
936 |
///The type of the arc lengths. |
|
930 | 937 |
typedef typename LEN::Value Value; |
... | ... |
@@ -975,3 +982,3 @@ |
975 | 982 |
///arcs of the shortest paths. |
976 |
///It must |
|
983 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
977 | 984 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
... | ... |
@@ -990,4 +997,4 @@ |
990 | 997 |
///The type of the map that indicates which nodes are processed. |
991 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
|
992 |
///By default it is a NullMap. |
|
998 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
999 |
///By default, it is a NullMap. |
|
993 | 1000 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
... | ... |
@@ -1010,3 +1017,3 @@ |
1010 | 1017 |
///The type of the map that stores the distances of the nodes. |
1011 |
///It must |
|
1018 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
1012 | 1019 |
typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap; |
... | ... |
@@ -1025,3 +1032,3 @@ |
1025 | 1032 |
///The type of the shortest paths. |
1026 |
///It must |
|
1033 |
///It must conform to the \ref concepts::Path "Path" concept. |
|
1027 | 1034 |
typedef lemon::Path<Digraph> Path; |
... | ... |
@@ -1031,8 +1038,5 @@ |
1031 | 1038 |
|
1032 |
/// To make it easier to use Dijkstra algorithm |
|
1033 |
/// we have created a wizard class. |
|
1034 |
/// This \ref DijkstraWizard class needs default traits, |
|
1035 |
/// as well as the \ref Dijkstra class. |
|
1036 |
/// The \ref DijkstraWizardBase is a class to be the default traits of the |
|
1037 |
/// \ref DijkstraWizard class. |
|
1039 |
/// Default traits class used by DijkstraWizard. |
|
1040 |
/// \tparam GR The type of the digraph. |
|
1041 |
/// \tparam LEN The type of the length map. |
|
1038 | 1042 |
template<typename GR, typename LEN> |
... | ... |
@@ -1095,3 +1099,2 @@ |
1095 | 1099 |
|
1096 |
///The type of the digraph the algorithm runs on. |
|
1097 | 1100 |
typedef typename TR::Digraph Digraph; |
... | ... |
@@ -1103,16 +1106,8 @@ |
1103 | 1106 |
|
1104 |
///The type of the map that stores the arc lengths. |
|
1105 | 1107 |
typedef typename TR::LengthMap LengthMap; |
1106 |
///The type of the length of the arcs. |
|
1107 | 1108 |
typedef typename LengthMap::Value Value; |
1108 |
///\brief The type of the map that stores the predecessor |
|
1109 |
///arcs of the shortest paths. |
|
1110 | 1109 |
typedef typename TR::PredMap PredMap; |
1111 |
///The type of the map that stores the distances of the nodes. |
|
1112 | 1110 |
typedef typename TR::DistMap DistMap; |
1113 |
///The type of the map that indicates which nodes are processed. |
|
1114 | 1111 |
typedef typename TR::ProcessedMap ProcessedMap; |
1115 |
///The type of the shortest paths |
|
1116 | 1112 |
typedef typename TR::Path Path; |
1117 |
///The heap type used by the dijkstra algorithm. |
|
1118 | 1113 |
typedef typename TR::Heap Heap; |
... | ... |
@@ -1188,7 +1183,8 @@ |
1188 | 1183 |
}; |
1189 |
///\brief \ref named-func-param "Named parameter" |
|
1190 |
///for setting PredMap object. |
|
1184 |
|
|
1185 |
///\brief \ref named-templ-param "Named parameter" for setting |
|
1186 |
///the predecessor map. |
|
1191 | 1187 |
/// |
1192 |
///\ref named-func-param "Named parameter" |
|
1193 |
///for setting PredMap object. |
|
1188 |
///\ref named-templ-param "Named parameter" function for setting |
|
1189 |
///the map that stores the predecessor arcs of the nodes. |
|
1194 | 1190 |
template<class T> |
... | ... |
@@ -1206,7 +1202,9 @@ |
1206 | 1202 |
}; |
1207 |
///\brief \ref named-func-param "Named parameter" |
|
1208 |
///for setting DistMap object. |
|
1203 |
|
|
1204 |
///\brief \ref named-templ-param "Named parameter" for setting |
|
1205 |
///the distance map. |
|
1209 | 1206 |
/// |
1210 |
///\ref named-func-param "Named parameter" |
|
1211 |
///for setting DistMap object. |
|
1207 |
///\ref named-templ-param "Named parameter" function for setting |
|
1208 |
///the map that stores the distances of the nodes calculated |
|
1209 |
///by the algorithm. |
|
1212 | 1210 |
template<class T> |
... | ... |
@@ -1224,7 +1222,8 @@ |
1224 | 1222 |
}; |
1225 |
///\brief \ref named-func-param "Named parameter" |
|
1226 |
///for setting ProcessedMap object. |
|
1223 |
|
|
1224 |
///\brief \ref named-func-param "Named parameter" for setting |
|
1225 |
///the processed map. |
|
1227 | 1226 |
/// |
1228 |
/// \ref named-func-param "Named parameter" |
|
1229 |
///for setting ProcessedMap object. |
|
1227 |
///\ref named-templ-param "Named parameter" function for setting |
|
1228 |
///the map that indicates which nodes are processed. |
|
1230 | 1229 |
template<class T> |
... | ... |
@@ -1241,2 +1240,3 @@ |
1241 | 1240 |
}; |
1241 |
|
|
1242 | 1242 |
///\brief \ref named-func-param "Named parameter" |
... | ... |
@@ -23,12 +23,5 @@ |
23 | 23 |
|
24 |
///\ingroup |
|
24 |
///\ingroup geomdat |
|
25 | 25 |
///\file |
26 | 26 |
///\brief A simple two dimensional vector and a bounding box implementation |
27 |
/// |
|
28 |
/// The class \ref lemon::dim2::Point "dim2::Point" implements |
|
29 |
/// a two dimensional vector with the usual operations. |
|
30 |
/// |
|
31 |
/// The class \ref lemon::dim2::Box "dim2::Box" can be used to determine |
|
32 |
/// the rectangular bounding box of a set of |
|
33 |
/// \ref lemon::dim2::Point "dim2::Point"'s. |
|
34 | 27 |
|
... | ... |
@@ -42,3 +35,3 @@ |
42 | 35 |
|
43 |
/// \addtogroup |
|
36 |
/// \addtogroup geomdat |
|
44 | 37 |
/// @{ |
... | ... |
@@ -257,2 +257,6 @@ |
257 | 257 |
/// |
258 |
/// This class fully conforms to the \ref concepts::Digraph |
|
259 |
/// "Digraph" concept. |
|
260 |
/// It provides only linear time counting for nodes and arcs. |
|
261 |
/// |
|
258 | 262 |
/// \param GR The type of the graph which shares its node set with |
... | ... |
@@ -261,5 +265,2 @@ |
261 | 265 |
/// concept. |
262 |
/// |
|
263 |
/// This class fully conforms to the \ref concepts::Digraph |
|
264 |
/// "Digraph" concept. |
|
265 | 266 |
template <typename GR> |
... | ... |
@@ -687,2 +688,6 @@ |
687 | 688 |
/// |
689 |
/// This class fully conforms to the \ref concepts::Graph "Graph" |
|
690 |
/// concept. |
|
691 |
/// It provides only linear time counting for nodes, edges and arcs. |
|
692 |
/// |
|
688 | 693 |
/// \param GR The type of the graph which shares its node set |
... | ... |
@@ -691,5 +696,2 @@ |
691 | 696 |
/// concept. |
692 |
/// |
|
693 |
/// This class fully conforms to the \ref concepts::Graph "Graph" |
|
694 |
/// concept. |
|
695 | 697 |
template <typename GR> |
... | ... |
@@ -869,3 +871,3 @@ |
869 | 871 |
|
870 |
void next(Arc& arc) |
|
872 |
static void next(Arc& arc) { |
|
871 | 873 |
--arc.id; |
... | ... |
@@ -956,2 +958,6 @@ |
956 | 958 |
/// |
959 |
/// This class fully conforms to the \ref concepts::Digraph "Digraph" |
|
960 |
/// concept. |
|
961 |
/// It provides only linear time counting for nodes and arcs. |
|
962 |
/// |
|
957 | 963 |
/// \warning If a node is erased from the underlying graph and this |
... | ... |
@@ -960,5 +966,2 @@ |
960 | 966 |
/// validity can be checked with the \c valid() member function. |
961 |
/// |
|
962 |
/// This class fully conforms to the \ref concepts::Digraph |
|
963 |
/// "Digraph" concept. |
|
964 | 967 |
template <typename GR> |
... | ... |
@@ -1175,3 +1178,3 @@ |
1175 | 1178 |
|
1176 |
void next(Arc& arc) |
|
1179 |
static void next(Arc& arc) { |
|
1177 | 1180 |
--arc.id; |
... | ... |
@@ -1183,3 +1186,3 @@ |
1183 | 1186 |
|
1184 |
void next(Edge& arc) |
|
1187 |
static void next(Edge& arc) { |
|
1185 | 1188 |
--arc.id; |
... | ... |
@@ -1306,2 +1309,6 @@ |
1306 | 1309 |
/// |
1310 |
/// This class fully conforms to the \ref concepts::Graph "Graph" |
|
1311 |
/// concept. |
|
1312 |
/// It provides only linear time counting for nodes, edges and arcs. |
|
1313 |
/// |
|
1307 | 1314 |
/// \warning If a node is erased from the underlying graph and this |
... | ... |
@@ -1310,5 +1317,2 @@ |
1310 | 1317 |
/// be checked with the \c valid() member function. |
1311 |
/// |
|
1312 |
/// This class fully conforms to the \ref concepts::Graph |
|
1313 |
/// "Graph" concept. |
|
1314 | 1318 |
template <typename GR> |
... | ... |
@@ -22,6 +22,7 @@ |
22 | 22 |
///\file |
23 |
///\ingroup auxdat |
|
24 |
///\brief Fibonacci Heap implementation. |
|
23 |
///\ingroup heaps |
|
24 |
///\brief Fibonacci heap implementation. |
|
25 | 25 |
|
26 | 26 |
#include <vector> |
27 |
#include <utility> |
|
27 | 28 |
#include <functional> |
... | ... |
@@ -31,28 +32,22 @@ |
31 | 32 |
|
32 |
/// \ingroup |
|
33 |
/// \ingroup heaps |
|
33 | 34 |
/// |
34 |
///\brief Fibonacci |
|
35 |
/// \brief Fibonacci heap data structure. |
|
35 | 36 |
/// |
36 |
///This class implements the \e Fibonacci \e heap data structure. A \e heap |
|
37 |
///is a data structure for storing items with specified values called \e |
|
38 |
///priorities in such a way that finding the item with minimum priority is |
|
39 |
///efficient. \c CMP specifies the ordering of the priorities. In a heap |
|
40 |
/// |
|
37 |
/// This class implements the \e Fibonacci \e heap data structure. |
|
38 |
/// It fully conforms to the \ref concepts::Heap "heap concept". |
|
41 | 39 |
/// |
42 |
///The methods \ref increase and \ref erase are not efficient in a Fibonacci |
|
43 |
///heap. In case of many calls to these operations, it is better to use a |
|
44 |
///\ref |
|
40 |
/// The methods \ref increase() and \ref erase() are not efficient in a |
|
41 |
/// Fibonacci heap. In case of many calls of these operations, it is |
|
42 |
/// better to use other heap structure, e.g. \ref BinHeap "binary heap". |
|
45 | 43 |
/// |
46 |
///\param PRIO Type of the priority of the items. |
|
47 |
///\param IM A read and writable Item int map, used internally |
|
48 |
///to handle the cross references. |
|
49 |
///\param CMP A class for the ordering of the priorities. The |
|
50 |
///default is \c std::less<PRIO>. |
|
51 |
/// |
|
52 |
///\sa BinHeap |
|
53 |
///\sa Dijkstra |
|
44 |
/// \tparam PR Type of the priorities of the items. |
|
45 |
/// \tparam IM A read-writable item map with \c int values, used |
|
46 |
/// internally to handle the cross references. |
|
47 |
/// \tparam CMP A functor class for comparing the priorities. |
|
48 |
/// The default is \c std::less<PR>. |
|
54 | 49 |
#ifdef DOXYGEN |
55 |
template <typename |
|
50 |
template <typename PR, typename IM, typename CMP> |
|
56 | 51 |
#else |
57 |
template <typename |
|
52 |
template <typename PR, typename IM, typename CMP = std::less<PR> > |
|
58 | 53 |
#endif |
... | ... |
@@ -60,11 +55,12 @@ |
60 | 55 |
public: |
61 |
|
|
56 |
|
|
57 |
/// Type of the item-int map. |
|
62 | 58 |
typedef IM ItemIntMap; |
63 |
///\e |
|
64 |
typedef PRIO Prio; |
|
65 |
/// |
|
59 |
/// Type of the priorities. |
|
60 |
typedef PR Prio; |
|
61 |
/// Type of the items stored in the heap. |
|
66 | 62 |
typedef typename ItemIntMap::Key Item; |
67 |
/// |
|
63 |
/// Type of the item-priority pairs. |
|
68 | 64 |
typedef std::pair<Item,Prio> Pair; |
69 |
/// |
|
65 |
/// Functor type for comparing the priorities. |
|
70 | 66 |
typedef CMP Compare; |
... | ... |
@@ -82,6 +78,6 @@ |
82 | 78 |
|
83 |
/// \brief Type to represent the |
|
79 |
/// \brief Type to represent the states of the items. |
|
84 | 80 |
/// |
85 |
/// Each Item element have a state associated to it. It may be "in heap", |
|
86 |
/// "pre heap" or "post heap". The latter two are indifferent from the |
|
81 |
/// Each item has a state associated to it. It can be "in heap", |
|
82 |
/// "pre-heap" or "post-heap". The latter two are indifferent from the |
|
87 | 83 |
/// heap's point of view, but may be useful to the user. |
... | ... |
@@ -96,6 +92,8 @@ |
96 | 92 |
|
97 |
/// \brief |
|
93 |
/// \brief Constructor. |
|
98 | 94 |
/// |
99 |
/// \c map should be given to the constructor, since it is |
|
100 |
/// used internally to handle the cross references. |
|
95 |
/// Constructor. |
|
96 |
/// \param map A map that assigns \c int values to the items. |
|
97 |
/// It is used internally to handle the cross references. |
|
98 |
/// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item. |
|
101 | 99 |
explicit FibHeap(ItemIntMap &map) |
... | ... |
@@ -103,7 +101,9 @@ |
103 | 101 |
|
104 |
/// \brief |
|
102 |
/// \brief Constructor. |
|
105 | 103 |
/// |
106 |
/// \c map should be given to the constructor, since it is used |
|
107 |
/// internally to handle the cross references. \c comp is an |
|
108 |
/// |
|
104 |
/// Constructor. |
|
105 |
/// \param map A map that assigns \c int values to the items. |
|
106 |
/// It is used internally to handle the cross references. |
|
107 |
/// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item. |
|
108 |
/// \param comp The function object used for comparing the priorities. |
|
109 | 109 |
FibHeap(ItemIntMap &map, const Compare &comp) |
... | ... |
@@ -113,16 +113,17 @@ |
113 | 113 |
/// |
114 |
/// |
|
114 |
/// This function returns the number of items stored in the heap. |
|
115 | 115 |
int size() const { return _num; } |
116 | 116 |
|
117 |
/// \brief |
|
117 |
/// \brief Check if the heap is empty. |
|
118 | 118 |
/// |
119 |
/// |
|
119 |
/// This function returns \c true if the heap is empty. |
|
120 | 120 |
bool empty() const { return _num==0; } |
121 | 121 |
|
122 |
/// \brief Make |
|
122 |
/// \brief Make the heap empty. |
|
123 | 123 |
/// |
124 |
/// Make empty this heap. It does not change the cross reference |
|
125 |
/// map. If you want to reuse a heap what is not surely empty you |
|
126 |
/// should first clear the heap and after that you should set the |
|
127 |
/// cross reference map for each item to \c PRE_HEAP. |
|
124 |
/// This functon makes the heap empty. |
|
125 |
/// It does not change the cross reference map. If you want to reuse |
|
126 |
/// a heap that is not surely empty, you should first clear it and |
|
127 |
/// then you should set the cross reference map to \c PRE_HEAP |
|
128 |
/// for each item. |
|
128 | 129 |
void clear() { |
... | ... |
@@ -131,21 +132,10 @@ |
131 | 132 |
|
132 |
/// \brief \c item gets to the heap with priority \c value independently |
|
133 |
/// if \c item was already there. |
|
133 |
/// \brief Insert an item into the heap with the given priority. |
|
134 | 134 |
/// |
135 |
/// This method calls \ref push(\c item, \c value) if \c item is not |
|
136 |
/// stored in the heap and it calls \ref decrease(\c item, \c value) or |
|
137 |
/// \ref increase(\c item, \c value) otherwise. |
|
138 |
void set (const Item& item, const Prio& value) { |
|
139 |
int i=_iim[item]; |
|
140 |
if ( i >= 0 && _data[i].in ) { |
|
141 |
if ( _comp(value, _data[i].prio) ) decrease(item, value); |
|
142 |
if ( _comp(_data[i].prio, value) ) increase(item, value); |
|
143 |
} else push(item, value); |
|
144 |
} |
|
145 |
|
|
146 |
/// \brief Adds \c item to the heap with priority \c value. |
|
147 |
/// |
|
148 |
/// Adds \c item to the heap with priority \c value. |
|
149 |
/// \pre \c item must not be stored in the heap. |
|
150 |
void push (const Item& item, const Prio& value) { |
|
135 |
/// This function inserts the given item into the heap with the |
|
136 |
/// given priority. |
|
137 |
/// \param item The item to insert. |
|
138 |
/// \param prio The priority of the item. |
|
139 |
/// \pre \e item must not be stored in the heap. |
|
140 |
void push (const Item& item, const Prio& prio) { |
|
151 | 141 |
int i=_iim[item]; |
... | ... |
@@ -170,3 +160,3 @@ |
170 | 160 |
_data[i].left_neighbor=_minimum; |
171 |
if ( _comp( |
|
161 |
if ( _comp( prio, _data[_minimum].prio) ) _minimum=i; |
|
172 | 162 |
} else { |
... | ... |
@@ -175,3 +165,3 @@ |
175 | 165 |
} |
176 |
_data[i].prio= |
|
166 |
_data[i].prio=prio; |
|
177 | 167 |
++_num; |
... | ... |
@@ -179,27 +169,17 @@ |
179 | 169 |
|
180 |
/// \brief |
|
170 |
/// \brief Return the item having minimum priority. |
|
181 | 171 |
/// |
182 |
/// This method returns the item with minimum priority relative to \c |
|
183 |
/// Compare. |
|
184 |
/// |
|
172 |
/// This function returns the item having minimum priority. |
|
173 |
/// \pre The heap must be non-empty. |
|
185 | 174 |
Item top() const { return _data[_minimum].name; } |
186 | 175 |
|
187 |
/// \brief |
|
176 |
/// \brief The minimum priority. |
|
188 | 177 |
/// |
189 |
/// It returns the minimum priority relative to \c Compare. |
|
190 |
/// \pre The heap must be nonempty. |
|
191 |
|
|
178 |
/// This function returns the minimum priority. |
|
179 |
/// \pre The heap must be non-empty. |
|
180 |
Prio prio() const { return _data[_minimum].prio; } |
|
192 | 181 |
|
193 |
/// \brief |
|
182 |
/// \brief Remove the item having minimum priority. |
|
194 | 183 |
/// |
195 |
/// It returns the priority of \c item. |
|
196 |
/// \pre \c item must be in the heap. |
|
197 |
const Prio& operator[](const Item& item) const { |
|
198 |
return _data[_iim[item]].prio; |
|
199 |
} |
|
200 |
|
|
201 |
/// \brief Deletes the item with minimum priority relative to \c Compare. |
|
202 |
/// |
|
203 |
/// This method deletes the item with minimum priority relative to \c |
|
204 |
/// Compare from the heap. |
|
184 |
/// This function removes the item having minimum priority. |
|
205 | 185 |
/// \pre The heap must be non-empty. |
... | ... |
@@ -210,3 +190,3 @@ |
210 | 190 |
if ( _data[_minimum].degree!=0 ) { |
211 |
|
|
191 |
makeRoot(_data[_minimum].child); |
|
212 | 192 |
_minimum=_data[_minimum].child; |
... | ... |
@@ -223,3 +203,3 @@ |
223 | 203 |
|
224 |
|
|
204 |
makeRoot(child); |
|
225 | 205 |
|
... | ... |
@@ -236,6 +216,8 @@ |
236 | 216 |
|
237 |
/// \brief |
|
217 |
/// \brief Remove the given item from the heap. |
|
238 | 218 |
/// |
239 |
/// This method deletes \c item from the heap, if \c item was already |
|
240 |
/// stored in the heap. It is quite inefficient in Fibonacci heaps. |
|
219 |
/// This function removes the given item from the heap if it is |
|
220 |
/// already stored. |
|
221 |
/// \param item The item to delete. |
|
222 |
/// \pre \e item must be in the heap. |
|
241 | 223 |
void erase (const Item& item) { |
... | ... |
@@ -254,13 +236,39 @@ |
254 | 236 |
|
255 |
/// \brief |
|
237 |
/// \brief The priority of the given item. |
|
256 | 238 |
/// |
257 |
/// This method decreases the priority of \c item to \c value. |
|
258 |
/// \pre \c item must be stored in the heap with priority at least \c |
|
259 |
/// value relative to \c Compare. |
|
260 |
void decrease (Item item, const Prio& value) { |
|
239 |
/// This function returns the priority of the given item. |
|
240 |
/// \param item The item. |
|
241 |
/// \pre \e item must be in the heap. |
|
242 |
Prio operator[](const Item& item) const { |
|
243 |
return _data[_iim[item]].prio; |
|
244 |
} |
|
245 |
|
|
246 |
/// \brief Set the priority of an item or insert it, if it is |
|
247 |
/// not stored in the heap. |
|
248 |
/// |
|
249 |
/// This method sets the priority of the given item if it is |
|
250 |
/// already stored in the heap. Otherwise it inserts the given |
|
251 |
/// item into the heap with the given priority. |
|
252 |
/// \param item The item. |
|
253 |
/// \param prio The priority. |
|
254 |
void set (const Item& item, const Prio& prio) { |
|
261 | 255 |
int i=_iim[item]; |
262 |
_data[i]. |
|
256 |
if ( i >= 0 && _data[i].in ) { |
|
257 |
if ( _comp(prio, _data[i].prio) ) decrease(item, prio); |
|
258 |
if ( _comp(_data[i].prio, prio) ) increase(item, prio); |
|
259 |
} else push(item, prio); |
|
260 |
} |
|
261 |
|
|
262 |
/// \brief Decrease the priority of an item to the given value. |
|
263 |
/// |
|
264 |
/// This function decreases the priority of an item to the given value. |
|
265 |
/// \param item The item. |
|
266 |
/// \param prio The priority. |
|
267 |
/// \pre \e item must be stored in the heap with priority at least \e prio. |
|
268 |
void decrease (const Item& item, const Prio& prio) { |
|
269 |
int i=_iim[item]; |
|
270 |
_data[i].prio=prio; |
|
263 | 271 |
int p=_data[i].parent; |
264 | 272 |
|
265 |
if ( p!=-1 && _comp( |
|
273 |
if ( p!=-1 && _comp(prio, _data[p].prio) ) { |
|
266 | 274 |
cut(i,p); |
... | ... |
@@ -268,25 +276,24 @@ |
268 | 276 |
} |
269 |
if ( _comp( |
|
277 |
if ( _comp(prio, _data[_minimum].prio) ) _minimum=i; |
|
270 | 278 |
} |
271 | 279 |
|
272 |
/// \brief |
|
280 |
/// \brief Increase the priority of an item to the given value. |
|
273 | 281 |
/// |
274 |
/// This method sets the priority of \c item to \c value. Though |
|
275 |
/// there is no precondition on the priority of \c item, this |
|
276 |
/// method should be used only if it is indeed necessary to increase |
|
277 |
/// (relative to \c Compare) the priority of \c item, because this |
|
278 |
/// method is inefficient. |
|
279 |
void increase (Item item, const Prio& value) { |
|
282 |
/// This function increases the priority of an item to the given value. |
|
283 |
/// \param item The item. |
|
284 |
/// \param prio The priority. |
|
285 |
/// \pre \e item must be stored in the heap with priority at most \e prio. |
|
286 |
void increase (const Item& item, const Prio& prio) { |
|
280 | 287 |
erase(item); |
281 |
push(item, |
|
288 |
push(item, prio); |
|
282 | 289 |
} |
283 | 290 |
|
284 |
|
|
285 |
/// \brief Returns if \c item is in, has already been in, or has never |
|
286 |
/// |
|
291 |
/// \brief Return the state of an item. |
|
287 | 292 |
/// |
288 |
/// This method returns PRE_HEAP if \c item has never been in the |
|
289 |
/// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP |
|
290 |
/// otherwise. In the latter case it is possible that \c item will |
|
291 |
/// get back to the heap again. |
|
293 |
/// This method returns \c PRE_HEAP if the given item has never |
|
294 |
/// been in the heap, \c IN_HEAP if it is in the heap at the moment, |
|
295 |
/// and \c POST_HEAP otherwise. |
|
296 |
/// In the latter case it is possible that the item will get back |
|
297 |
/// to the heap again. |
|
298 |
/// \param item The item. |
|
292 | 299 |
State state(const Item &item) const { |
... | ... |
@@ -300,7 +307,7 @@ |
300 | 307 |
|
301 |
/// \brief |
|
308 |
/// \brief Set the state of an item in the heap. |
|
302 | 309 |
/// |
303 |
/// Sets the state of the \c item in the heap. It can be used to |
|
304 |
/// manually clear the heap when it is important to achive the |
|
305 |
/// |
|
310 |
/// This function sets the state of the given item in the heap. |
|
311 |
/// It can be used to manually clear the heap when it is important |
|
312 |
/// to achive better time complexity. |
|
306 | 313 |
/// \param i The item. |
... | ... |
@@ -367,3 +374,3 @@ |
367 | 374 |
|
368 |
void |
|
375 |
void makeRoot(int c) { |
|
369 | 376 |
int s=c; |
Changeset was too big and was cut off... Show full diff
0 comments (0 inline)