0
67
10
597
582
17
13
1
133
61
15
9
66
77
12
13
172
171
344
324
62
75
64
64
2
9
19
15
71
55
35
39
272
217
20
6
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_HARTMANN_ORLIN_H |
|
20 |
#define LEMON_HARTMANN_ORLIN_H |
|
21 |
|
|
22 |
/// \ingroup min_mean_cycle |
|
23 |
/// |
|
24 |
/// \file |
|
25 |
/// \brief Hartmann-Orlin's algorithm for finding a minimum mean cycle. |
|
26 |
|
|
27 |
#include <vector> |
|
28 |
#include <limits> |
|
29 |
#include <lemon/core.h> |
|
30 |
#include <lemon/path.h> |
|
31 |
#include <lemon/tolerance.h> |
|
32 |
#include <lemon/connectivity.h> |
|
33 |
|
|
34 |
namespace lemon { |
|
35 |
|
|
36 |
/// \brief Default traits class of HartmannOrlin algorithm. |
|
37 |
/// |
|
38 |
/// Default traits class of HartmannOrlin algorithm. |
|
39 |
/// \tparam GR The type of the digraph. |
|
40 |
/// \tparam LEN The type of the length map. |
|
41 |
/// It must conform to the \ref concepts::Rea_data "Rea_data" concept. |
|
42 |
#ifdef DOXYGEN |
|
43 |
template <typename GR, typename LEN> |
|
44 |
#else |
|
45 |
template <typename GR, typename LEN, |
|
46 |
bool integer = std::numeric_limits<typename LEN::Value>::is_integer> |
|
47 |
#endif |
|
48 |
struct HartmannOrlinDefaultTraits |
|
49 |
{ |
|
50 |
/// The type of the digraph |
|
51 |
typedef GR Digraph; |
|
52 |
/// The type of the length map |
|
53 |
typedef LEN LengthMap; |
|
54 |
/// The type of the arc lengths |
|
55 |
typedef typename LengthMap::Value Value; |
|
56 |
|
|
57 |
/// \brief The large value type used for internal computations |
|
58 |
/// |
|
59 |
/// The large value type used for internal computations. |
|
60 |
/// It is \c long \c long if the \c Value type is integer, |
|
61 |
/// otherwise it is \c double. |
|
62 |
/// \c Value must be convertible to \c LargeValue. |
|
63 |
typedef double LargeValue; |
|
64 |
|
|
65 |
/// The tolerance type used for internal computations |
|
66 |
typedef lemon::Tolerance<LargeValue> Tolerance; |
|
67 |
|
|
68 |
/// \brief The path type of the found cycles |
|
69 |
/// |
|
70 |
/// The path type of the found cycles. |
|
71 |
/// It must conform to the \ref lemon::concepts::Path "Path" concept |
|
72 |
/// and it must have an \c addFront() function. |
|
73 |
typedef lemon::Path<Digraph> Path; |
|
74 |
}; |
|
75 |
|
|
76 |
// Default traits class for integer value types |
|
77 |
template <typename GR, typename LEN> |
|
78 |
struct HartmannOrlinDefaultTraits<GR, LEN, true> |
|
79 |
{ |
|
80 |
typedef GR Digraph; |
|
81 |
typedef LEN LengthMap; |
|
82 |
typedef typename LengthMap::Value Value; |
|
83 |
#ifdef LEMON_HAVE_LONG_LONG |
|
84 |
typedef long long LargeValue; |
|
85 |
#else |
|
86 |
typedef long LargeValue; |
|
87 |
#endif |
|
88 |
typedef lemon::Tolerance<LargeValue> Tolerance; |
|
89 |
typedef lemon::Path<Digraph> Path; |
|
90 |
}; |
|
91 |
|
|
92 |
|
|
93 |
/// \addtogroup min_mean_cycle |
|
94 |
/// @{ |
|
95 |
|
|
96 |
/// \brief Implementation of the Hartmann-Orlin algorithm for finding |
|
97 |
/// a minimum mean cycle. |
|
98 |
/// |
|
99 |
/// This class implements the Hartmann-Orlin algorithm for finding |
|
100 |
/// a directed cycle of minimum mean length (cost) in a digraph |
|
101 |
/// \ref amo93networkflows, \ref dasdan98minmeancycle. |
|
102 |
/// It is an improved version of \ref Karp "Karp"'s original algorithm, |
|
103 |
/// it applies an efficient early termination scheme. |
|
104 |
/// It runs in time O(ne) and uses space O(n<sup>2</sup>+e). |
|
105 |
/// |
|
106 |
/// \tparam GR The type of the digraph the algorithm runs on. |
|
107 |
/// \tparam LEN The type of the length map. The default |
|
108 |
/// map type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". |
|
109 |
#ifdef DOXYGEN |
|
110 |
template <typename GR, typename LEN, typename TR> |
|
111 |
#else |
|
112 |
template < typename GR, |
|
113 |
typename LEN = typename GR::template ArcMap<int>, |
|
114 |
typename TR = HartmannOrlinDefaultTraits<GR, LEN> > |
|
115 |
#endif |
|
116 |
class HartmannOrlin |
|
117 |
{ |
|
118 |
public: |
|
119 |
|
|
120 |
/// The type of the digraph |
|
121 |
typedef typename TR::Digraph Digraph; |
|
122 |
/// The type of the length map |
|
123 |
typedef typename TR::LengthMap LengthMap; |
|
124 |
/// The type of the arc lengths |
|
125 |
typedef typename TR::Value Value; |
|
126 |
|
|
127 |
/// \brief The large value type |
|
128 |
/// |
|
129 |
/// The large value type used for internal computations. |
|
130 |
/// Using the \ref HartmannOrlinDefaultTraits "default traits class", |
|
131 |
/// it is \c long \c long if the \c Value type is integer, |
|
132 |
/// otherwise it is \c double. |
|
133 |
typedef typename TR::LargeValue LargeValue; |
|
134 |
|
|
135 |
/// The tolerance type |
|
136 |
typedef typename TR::Tolerance Tolerance; |
|
137 |
|
|
138 |
/// \brief The path type of the found cycles |
|
139 |
/// |
|
140 |
/// The path type of the found cycles. |
|
141 |
/// Using the \ref HartmannOrlinDefaultTraits "default traits class", |
|
142 |
/// it is \ref lemon::Path "Path<Digraph>". |
|
143 |
typedef typename TR::Path Path; |
|
144 |
|
|
145 |
/// The \ref HartmannOrlinDefaultTraits "traits class" of the algorithm |
|
146 |
typedef TR Traits; |
|
147 |
|
|
148 |
private: |
|
149 |
|
|
150 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
|
151 |
|
|
152 |
// Data sturcture for path data |
|
153 |
struct PathData |
|
154 |
{ |
|
155 |
LargeValue dist; |
|
156 |
Arc pred; |
|
157 |
PathData(LargeValue d, Arc p = INVALID) : |
|
158 |
dist(d), pred(p) {} |
|
159 |
}; |
|
160 |
|
|
161 |
typedef typename Digraph::template NodeMap<std::vector<PathData> > |
|
162 |
PathDataNodeMap; |
|
163 |
|
|
164 |
private: |
|
165 |
|
|
166 |
// The digraph the algorithm runs on |
|
167 |
const Digraph &_gr; |
|
168 |
// The length of the arcs |
|
169 |
const LengthMap &_length; |
|
170 |
|
|
171 |
// Data for storing the strongly connected components |
|
172 |
int _comp_num; |
|
173 |
typename Digraph::template NodeMap<int> _comp; |
|
174 |
std::vector<std::vector<Node> > _comp_nodes; |
|
175 |
std::vector<Node>* _nodes; |
|
176 |
typename Digraph::template NodeMap<std::vector<Arc> > _out_arcs; |
|
177 |
|
|
178 |
// Data for the found cycles |
|
179 |
bool _curr_found, _best_found; |
|
180 |
LargeValue _curr_length, _best_length; |
|
181 |
int _curr_size, _best_size; |
|
182 |
Node _curr_node, _best_node; |
|
183 |
int _curr_level, _best_level; |
|
184 |
|
|
185 |
Path *_cycle_path; |
|
186 |
bool _local_path; |
|
187 |
|
|
188 |
// Node map for storing path data |
|
189 |
PathDataNodeMap _data; |
|
190 |
// The processed nodes in the last round |
|
191 |
std::vector<Node> _process; |
|
192 |
|
|
193 |
Tolerance _tolerance; |
|
194 |
|
|
195 |
// Infinite constant |
|
196 |
const LargeValue INF; |
|
197 |
|
|
198 |
public: |
|
199 |
|
|
200 |
/// \name Named Template Parameters |
|
201 |
/// @{ |
|
202 |
|
|
203 |
template <typename T> |
|
204 |
struct SetLargeValueTraits : public Traits { |
|
205 |
typedef T LargeValue; |
|
206 |
typedef lemon::Tolerance<T> Tolerance; |
|
207 |
}; |
|
208 |
|
|
209 |
/// \brief \ref named-templ-param "Named parameter" for setting |
|
210 |
/// \c LargeValue type. |
|
211 |
/// |
|
212 |
/// \ref named-templ-param "Named parameter" for setting \c LargeValue |
|
213 |
/// type. It is used for internal computations in the algorithm. |
|
214 |
template <typename T> |
|
215 |
struct SetLargeValue |
|
216 |
: public HartmannOrlin<GR, LEN, SetLargeValueTraits<T> > { |
|
217 |
typedef HartmannOrlin<GR, LEN, SetLargeValueTraits<T> > Create; |
|
218 |
}; |
|
219 |
|
|
220 |
template <typename T> |
|
221 |
struct SetPathTraits : public Traits { |
|
222 |
typedef T Path; |
|
223 |
}; |
|
224 |
|
|
225 |
/// \brief \ref named-templ-param "Named parameter" for setting |
|
226 |
/// \c %Path type. |
|
227 |
/// |
|
228 |
/// \ref named-templ-param "Named parameter" for setting the \c %Path |
|
229 |
/// type of the found cycles. |
|
230 |
/// It must conform to the \ref lemon::concepts::Path "Path" concept |
|
231 |
/// and it must have an \c addFront() function. |
|
232 |
template <typename T> |
|
233 |
struct SetPath |
|
234 |
: public HartmannOrlin<GR, LEN, SetPathTraits<T> > { |
|
235 |
typedef HartmannOrlin<GR, LEN, SetPathTraits<T> > Create; |
|
236 |
}; |
|
237 |
|
|
238 |
/// @} |
|
239 |
|
|
240 |
public: |
|
241 |
|
|
242 |
/// \brief Constructor. |
|
243 |
/// |
|
244 |
/// The constructor of the class. |
|
245 |
/// |
|
246 |
/// \param digraph The digraph the algorithm runs on. |
|
247 |
/// \param length The lengths (costs) of the arcs. |
|
248 |
HartmannOrlin( const Digraph &digraph, |
|
249 |
const LengthMap &length ) : |
|
250 |
_gr(digraph), _length(length), _comp(digraph), _out_arcs(digraph), |
|
251 |
_best_found(false), _best_length(0), _best_size(1), |
|
252 |
_cycle_path(NULL), _local_path(false), _data(digraph), |
|
253 |
INF(std::numeric_limits<LargeValue>::has_infinity ? |
|
254 |
std::numeric_limits<LargeValue>::infinity() : |
|
255 |
std::numeric_limits<LargeValue>::max()) |
|
256 |
{} |
|
257 |
|
|
258 |
/// Destructor. |
|
259 |
~HartmannOrlin() { |
|
260 |
if (_local_path) delete _cycle_path; |
|
261 |
} |
|
262 |
|
|
263 |
/// \brief Set the path structure for storing the found cycle. |
|
264 |
/// |
|
265 |
/// This function sets an external path structure for storing the |
|
266 |
/// found cycle. |
|
267 |
/// |
|
268 |
/// If you don't call this function before calling \ref run() or |
|
269 |
/// \ref findMinMean(), it will allocate a local \ref Path "path" |
|
270 |
/// structure. The destuctor deallocates this automatically |
|
271 |
/// allocated object, of course. |
|
272 |
/// |
|
273 |
/// \note The algorithm calls only the \ref lemon::Path::addFront() |
|
274 |
/// "addFront()" function of the given path structure. |
|
275 |
/// |
|
276 |
/// \return <tt>(*this)</tt> |
|
277 |
HartmannOrlin& cycle(Path &path) { |
|
278 |
if (_local_path) { |
|
279 |
delete _cycle_path; |
|
280 |
_local_path = false; |
|
281 |
} |
|
282 |
_cycle_path = &path; |
|
283 |
return *this; |
|
284 |
} |
|
285 |
|
|
286 |
/// \brief Set the tolerance used by the algorithm. |
|
287 |
/// |
|
288 |
/// This function sets the tolerance object used by the algorithm. |
|
289 |
/// |
|
290 |
/// \return <tt>(*this)</tt> |
|
291 |
HartmannOrlin& tolerance(const Tolerance& tolerance) { |
|
292 |
_tolerance = tolerance; |
|
293 |
return *this; |
|
294 |
} |
|
295 |
|
|
296 |
/// \brief Return a const reference to the tolerance. |
|
297 |
/// |
|
298 |
/// This function returns a const reference to the tolerance object |
|
299 |
/// used by the algorithm. |
|
300 |
const Tolerance& tolerance() const { |
|
301 |
return _tolerance; |
|
302 |
} |
|
303 |
|
|
304 |
/// \name Execution control |
|
305 |
/// The simplest way to execute the algorithm is to call the \ref run() |
|
306 |
/// function.\n |
|
307 |
/// If you only need the minimum mean length, you may call |
|
308 |
/// \ref findMinMean(). |
|
309 |
|
|
310 |
/// @{ |
|
311 |
|
|
312 |
/// \brief Run the algorithm. |
|
313 |
/// |
|
314 |
/// This function runs the algorithm. |
|
315 |
/// It can be called more than once (e.g. if the underlying digraph |
|
316 |
/// and/or the arc lengths have been modified). |
|
317 |
/// |
|
318 |
/// \return \c true if a directed cycle exists in the digraph. |
|
319 |
/// |
|
320 |
/// \note <tt>mmc.run()</tt> is just a shortcut of the following code. |
|
321 |
/// \code |
|
322 |
/// return mmc.findMinMean() && mmc.findCycle(); |
|
323 |
/// \endcode |
|
324 |
bool run() { |
|
325 |
return findMinMean() && findCycle(); |
|
326 |
} |
|
327 |
|
|
328 |
/// \brief Find the minimum cycle mean. |
|
329 |
/// |
|
330 |
/// This function finds the minimum mean length of the directed |
|
331 |
/// cycles in the digraph. |
|
332 |
/// |
|
333 |
/// \return \c true if a directed cycle exists in the digraph. |
|
334 |
bool findMinMean() { |
|
335 |
// Initialization and find strongly connected components |
|
336 |
init(); |
|
337 |
findComponents(); |
|
338 |
|
|
339 |
// Find the minimum cycle mean in the components |
|
340 |
for (int comp = 0; comp < _comp_num; ++comp) { |
|
341 |
if (!initComponent(comp)) continue; |
|
342 |
processRounds(); |
|
343 |
|
|
344 |
// Update the best cycle (global minimum mean cycle) |
|
345 |
if ( _curr_found && (!_best_found || |
|
346 |
_curr_length * _best_size < _best_length * _curr_size) ) { |
|
347 |
_best_found = true; |
|
348 |
_best_length = _curr_length; |
|
349 |
_best_size = _curr_size; |
|
350 |
_best_node = _curr_node; |
|
351 |
_best_level = _curr_level; |
|
352 |
} |
|
353 |
} |
|
354 |
return _best_found; |
|
355 |
} |
|
356 |
|
|
357 |
/// \brief Find a minimum mean directed cycle. |
|
358 |
/// |
|
359 |
/// This function finds a directed cycle of minimum mean length |
|
360 |
/// in the digraph using the data computed by findMinMean(). |
|
361 |
/// |
|
362 |
/// \return \c true if a directed cycle exists in the digraph. |
|
363 |
/// |
|
364 |
/// \pre \ref findMinMean() must be called before using this function. |
|
365 |
bool findCycle() { |
|
366 |
if (!_best_found) return false; |
|
367 |
IntNodeMap reached(_gr, -1); |
|
368 |
int r = _best_level + 1; |
|
369 |
Node u = _best_node; |
|
370 |
while (reached[u] < 0) { |
|
371 |
reached[u] = --r; |
|
372 |
u = _gr.source(_data[u][r].pred); |
|
373 |
} |
|
374 |
r = reached[u]; |
|
375 |
Arc e = _data[u][r].pred; |
|
376 |
_cycle_path->addFront(e); |
|
377 |
_best_length = _length[e]; |
|
378 |
_best_size = 1; |
|
379 |
Node v; |
|
380 |
while ((v = _gr.source(e)) != u) { |
|
381 |
e = _data[v][--r].pred; |
|
382 |
_cycle_path->addFront(e); |
|
383 |
_best_length += _length[e]; |
|
384 |
++_best_size; |
|
385 |
} |
|
386 |
return true; |
|
387 |
} |
|
388 |
|
|
389 |
/// @} |
|
390 |
|
|
391 |
/// \name Query Functions |
|
392 |
/// The results of the algorithm can be obtained using these |
|
393 |
/// functions.\n |
|
394 |
/// The algorithm should be executed before using them. |
|
395 |
|
|
396 |
/// @{ |
|
397 |
|
|
398 |
/// \brief Return the total length of the found cycle. |
|
399 |
/// |
|
400 |
/// This function returns the total length of the found cycle. |
|
401 |
/// |
|
402 |
/// \pre \ref run() or \ref findMinMean() must be called before |
|
403 |
/// using this function. |
|
404 |
LargeValue cycleLength() const { |
|
405 |
return _best_length; |
|
406 |
} |
|
407 |
|
|
408 |
/// \brief Return the number of arcs on the found cycle. |
|
409 |
/// |
|
410 |
/// This function returns the number of arcs on the found cycle. |
|
411 |
/// |
|
412 |
/// \pre \ref run() or \ref findMinMean() must be called before |
|
413 |
/// using this function. |
|
414 |
int cycleArcNum() const { |
|
415 |
return _best_size; |
|
416 |
} |
|
417 |
|
|
418 |
/// \brief Return the mean length of the found cycle. |
|
419 |
/// |
|
420 |
/// This function returns the mean length of the found cycle. |
|
421 |
/// |
|
422 |
/// \note <tt>alg.cycleMean()</tt> is just a shortcut of the |
|
423 |
/// following code. |
|
424 |
/// \code |
|
425 |
/// return static_cast<double>(alg.cycleLength()) / alg.cycleArcNum(); |
|
426 |
/// \endcode |
|
427 |
/// |
|
428 |
/// \pre \ref run() or \ref findMinMean() must be called before |
|
429 |
/// using this function. |
|
430 |
double cycleMean() const { |
|
431 |
return static_cast<double>(_best_length) / _best_size; |
|
432 |
} |
|
433 |
|
|
434 |
/// \brief Return the found cycle. |
|
435 |
/// |
|
436 |
/// This function returns a const reference to the path structure |
|
437 |
/// storing the found cycle. |
|
438 |
/// |
|
439 |
/// \pre \ref run() or \ref findCycle() must be called before using |
|
440 |
/// this function. |
|
441 |
const Path& cycle() const { |
|
442 |
return *_cycle_path; |
|
443 |
} |
|
444 |
|
|
445 |
///@} |
|
446 |
|
|
447 |
private: |
|
448 |
|
|
449 |
// Initialization |
|
450 |
void init() { |
|
451 |
if (!_cycle_path) { |
|
452 |
_local_path = true; |
|
453 |
_cycle_path = new Path; |
|
454 |
} |
|
455 |
_cycle_path->clear(); |
|
456 |
_best_found = false; |
|
457 |
_best_length = 0; |
|
458 |
_best_size = 1; |
|
459 |
_cycle_path->clear(); |
|
460 |
for (NodeIt u(_gr); u != INVALID; ++u) |
|
461 |
_data[u].clear(); |
|
462 |
} |
|
463 |
|
|
464 |
// Find strongly connected components and initialize _comp_nodes |
|
465 |
// and _out_arcs |
|
466 |
void findComponents() { |
|
467 |
_comp_num = stronglyConnectedComponents(_gr, _comp); |
|
468 |
_comp_nodes.resize(_comp_num); |
|
469 |
if (_comp_num == 1) { |
|
470 |
_comp_nodes[0].clear(); |
|
471 |
for (NodeIt n(_gr); n != INVALID; ++n) { |
|
472 |
_comp_nodes[0].push_back(n); |
|
473 |
_out_arcs[n].clear(); |
|
474 |
for (OutArcIt a(_gr, n); a != INVALID; ++a) { |
|
475 |
_out_arcs[n].push_back(a); |
|
476 |
} |
|
477 |
} |
|
478 |
} else { |
|
479 |
for (int i = 0; i < _comp_num; ++i) |
|
480 |
_comp_nodes[i].clear(); |
|
481 |
for (NodeIt n(_gr); n != INVALID; ++n) { |
|
482 |
int k = _comp[n]; |
|
483 |
_comp_nodes[k].push_back(n); |
|
484 |
_out_arcs[n].clear(); |
|
485 |
for (OutArcIt a(_gr, n); a != INVALID; ++a) { |
|
486 |
if (_comp[_gr.target(a)] == k) _out_arcs[n].push_back(a); |
|
487 |
} |
|
488 |
} |
|
489 |
} |
|
490 |
} |
|
491 |
|
|
492 |
// Initialize path data for the current component |
|
493 |
bool initComponent(int comp) { |
|
494 |
_nodes = &(_comp_nodes[comp]); |
|
495 |
int n = _nodes->size(); |
|
496 |
if (n < 1 || (n == 1 && _out_arcs[(*_nodes)[0]].size() == 0)) { |
|
497 |
return false; |
|
498 |
} |
|
499 |
for (int i = 0; i < n; ++i) { |
|
500 |
_data[(*_nodes)[i]].resize(n + 1, PathData(INF)); |
|
501 |
} |
|
502 |
return true; |
|
503 |
} |
|
504 |
|
|
505 |
// Process all rounds of computing path data for the current component. |
|
506 |
// _data[v][k] is the length of a shortest directed walk from the root |
|
507 |
// node to node v containing exactly k arcs. |
|
508 |
void processRounds() { |
|
509 |
Node start = (*_nodes)[0]; |
|
510 |
_data[start][0] = PathData(0); |
|
511 |
_process.clear(); |
|
512 |
_process.push_back(start); |
|
513 |
|
|
514 |
int k, n = _nodes->size(); |
|
515 |
int next_check = 4; |
|
516 |
bool terminate = false; |
|
517 |
for (k = 1; k <= n && int(_process.size()) < n && !terminate; ++k) { |
|
518 |
processNextBuildRound(k); |
|
519 |
if (k == next_check || k == n) { |
|
520 |
terminate = checkTermination(k); |
|
521 |
next_check = next_check * 3 / 2; |
|
522 |
} |
|
523 |
} |
|
524 |
for ( ; k <= n && !terminate; ++k) { |
|
525 |
processNextFullRound(k); |
|
526 |
if (k == next_check || k == n) { |
|
527 |
terminate = checkTermination(k); |
|
528 |
next_check = next_check * 3 / 2; |
|
529 |
} |
|
530 |
} |
|
531 |
} |
|
532 |
|
|
533 |
// Process one round and rebuild _process |
|
534 |
void processNextBuildRound(int k) { |
|
535 |
std::vector<Node> next; |
|
536 |
Node u, v; |
|
537 |
Arc e; |
|
538 |
LargeValue d; |
|
539 |
for (int i = 0; i < int(_process.size()); ++i) { |
|
540 |
u = _process[i]; |
|
541 |
for (int j = 0; j < int(_out_arcs[u].size()); ++j) { |
|
542 |
e = _out_arcs[u][j]; |
|
543 |
v = _gr.target(e); |
|
544 |
d = _data[u][k-1].dist + _length[e]; |
|
545 |
if (_tolerance.less(d, _data[v][k].dist)) { |
|
546 |
if (_data[v][k].dist == INF) next.push_back(v); |
|
547 |
_data[v][k] = PathData(d, e); |
|
548 |
} |
|
549 |
} |
|
550 |
} |
|
551 |
_process.swap(next); |
|
552 |
} |
|
553 |
|
|
554 |
// Process one round using _nodes instead of _process |
|
555 |
void processNextFullRound(int k) { |
|
556 |
Node u, v; |
|
557 |
Arc e; |
|
558 |
LargeValue d; |
|
559 |
for (int i = 0; i < int(_nodes->size()); ++i) { |
|
560 |
u = (*_nodes)[i]; |
|
561 |
for (int j = 0; j < int(_out_arcs[u].size()); ++j) { |
|
562 |
e = _out_arcs[u][j]; |
|
563 |
v = _gr.target(e); |
|
564 |
d = _data[u][k-1].dist + _length[e]; |
|
565 |
if (_tolerance.less(d, _data[v][k].dist)) { |
|
566 |
_data[v][k] = PathData(d, e); |
|
567 |
} |
|
568 |
} |
|
569 |
} |
|
570 |
} |
|
571 |
|
|
572 |
// Check early termination |
|
573 |
bool checkTermination(int k) { |
|
574 |
typedef std::pair<int, int> Pair; |
|
575 |
typename GR::template NodeMap<Pair> level(_gr, Pair(-1, 0)); |
|
576 |
typename GR::template NodeMap<LargeValue> pi(_gr); |
|
577 |
int n = _nodes->size(); |
|
578 |
LargeValue length; |
|
579 |
int size; |
|
580 |
Node u; |
|
581 |
|
|
582 |
// Search for cycles that are already found |
|
583 |
_curr_found = false; |
|
584 |
for (int i = 0; i < n; ++i) { |
|
585 |
u = (*_nodes)[i]; |
|
586 |
if (_data[u][k].dist == INF) continue; |
|
587 |
for (int j = k; j >= 0; --j) { |
|
588 |
if (level[u].first == i && level[u].second > 0) { |
|
589 |
// A cycle is found |
|
590 |
length = _data[u][level[u].second].dist - _data[u][j].dist; |
|
591 |
size = level[u].second - j; |
|
592 |
if (!_curr_found || length * _curr_size < _curr_length * size) { |
|
593 |
_curr_length = length; |
|
594 |
_curr_size = size; |
|
595 |
_curr_node = u; |
|
596 |
_curr_level = level[u].second; |
|
597 |
_curr_found = true; |
|
598 |
} |
|
599 |
} |
|
600 |
level[u] = Pair(i, j); |
|
601 |
if (j != 0) { |
|
602 |
u = _gr.source(_data[u][j].pred); |
|
603 |
} |
|
604 |
} |
|
605 |
} |
|
606 |
|
|
607 |
// If at least one cycle is found, check the optimality condition |
|
608 |
LargeValue d; |
|
609 |
if (_curr_found && k < n) { |
|
610 |
// Find node potentials |
|
611 |
for (int i = 0; i < n; ++i) { |
|
612 |
u = (*_nodes)[i]; |
|
613 |
pi[u] = INF; |
|
614 |
for (int j = 0; j <= k; ++j) { |
|
615 |
if (_data[u][j].dist < INF) { |
|
616 |
d = _data[u][j].dist * _curr_size - j * _curr_length; |
|
617 |
if (_tolerance.less(d, pi[u])) pi[u] = d; |
|
618 |
} |
|
619 |
} |
|
620 |
} |
|
621 |
|
|
622 |
// Check the optimality condition for all arcs |
|
623 |
bool done = true; |
|
624 |
for (ArcIt a(_gr); a != INVALID; ++a) { |
|
625 |
if (_tolerance.less(_length[a] * _curr_size - _curr_length, |
|
626 |
pi[_gr.target(a)] - pi[_gr.source(a)]) ) { |
|
627 |
done = false; |
|
628 |
break; |
|
629 |
} |
|
630 |
} |
|
631 |
return done; |
|
632 |
} |
|
633 |
return (k == n); |
|
634 |
} |
|
635 |
|
|
636 |
}; //class HartmannOrlin |
|
637 |
|
|
638 |
///@} |
|
639 |
|
|
640 |
} //namespace lemon |
|
641 |
|
|
642 |
#endif //LEMON_HARTMANN_ORLIN_H |
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_HOWARD_H |
|
20 |
#define LEMON_HOWARD_H |
|
21 |
|
|
22 |
/// \ingroup min_mean_cycle |
|
23 |
/// |
|
24 |
/// \file |
|
25 |
/// \brief Howard's algorithm for finding a minimum mean cycle. |
|
26 |
|
|
27 |
#include <vector> |
|
28 |
#include <limits> |
|
29 |
#include <lemon/core.h> |
|
30 |
#include <lemon/path.h> |
|
31 |
#include <lemon/tolerance.h> |
|
32 |
#include <lemon/connectivity.h> |
|
33 |
|
|
34 |
namespace lemon { |
|
35 |
|
|
36 |
/// \brief Default traits class of Howard class. |
|
37 |
/// |
|
38 |
/// Default traits class of Howard class. |
|
39 |
/// \tparam GR The type of the digraph. |
|
40 |
/// \tparam LEN The type of the length map. |
|
41 |
/// It must conform to the \ref concepts::ReadMap "ReadMap" concept. |
|
42 |
#ifdef DOXYGEN |
|
43 |
template <typename GR, typename LEN> |
|
44 |
#else |
|
45 |
template <typename GR, typename LEN, |
|
46 |
bool integer = std::numeric_limits<typename LEN::Value>::is_integer> |
|
47 |
#endif |
|
48 |
struct HowardDefaultTraits |
|
49 |
{ |
|
50 |
/// The type of the digraph |
|
51 |
typedef GR Digraph; |
|
52 |
/// The type of the length map |
|
53 |
typedef LEN LengthMap; |
|
54 |
/// The type of the arc lengths |
|
55 |
typedef typename LengthMap::Value Value; |
|
56 |
|
|
57 |
/// \brief The large value type used for internal computations |
|
58 |
/// |
|
59 |
/// The large value type used for internal computations. |
|
60 |
/// It is \c long \c long if the \c Value type is integer, |
|
61 |
/// otherwise it is \c double. |
|
62 |
/// \c Value must be convertible to \c LargeValue. |
|
63 |
typedef double LargeValue; |
|
64 |
|
|
65 |
/// The tolerance type used for internal computations |
|
66 |
typedef lemon::Tolerance<LargeValue> Tolerance; |
|
67 |
|
|
68 |
/// \brief The path type of the found cycles |
|
69 |
/// |
|
70 |
/// The path type of the found cycles. |
|
71 |
/// It must conform to the \ref lemon::concepts::Path "Path" concept |
|
72 |
/// and it must have an \c addBack() function. |
|
73 |
typedef lemon::Path<Digraph> Path; |
|
74 |
}; |
|
75 |
|
|
76 |
// Default traits class for integer value types |
|
77 |
template <typename GR, typename LEN> |
|
78 |
struct HowardDefaultTraits<GR, LEN, true> |
|
79 |
{ |
|
80 |
typedef GR Digraph; |
|
81 |
typedef LEN LengthMap; |
|
82 |
typedef typename LengthMap::Value Value; |
|
83 |
#ifdef LEMON_HAVE_LONG_LONG |
|
84 |
typedef long long LargeValue; |
|
85 |
#else |
|
86 |
typedef long LargeValue; |
|
87 |
#endif |
|
88 |
typedef lemon::Tolerance<LargeValue> Tolerance; |
|
89 |
typedef lemon::Path<Digraph> Path; |
|
90 |
}; |
|
91 |
|
|
92 |
|
|
93 |
/// \addtogroup min_mean_cycle |
|
94 |
/// @{ |
|
95 |
|
|
96 |
/// \brief Implementation of Howard's algorithm for finding a minimum |
|
97 |
/// mean cycle. |
|
98 |
/// |
|
99 |
/// This class implements Howard's policy iteration algorithm for finding |
|
100 |
/// a directed cycle of minimum mean length (cost) in a digraph |
|
101 |
/// \ref amo93networkflows, \ref dasdan98minmeancycle. |
|
102 |
/// This class provides the most efficient algorithm for the |
|
103 |
/// minimum mean cycle problem, though the best known theoretical |
|
104 |
/// bound on its running time is exponential. |
|
105 |
/// |
|
106 |
/// \tparam GR The type of the digraph the algorithm runs on. |
|
107 |
/// \tparam LEN The type of the length map. The default |
|
108 |
/// map type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". |
|
109 |
#ifdef DOXYGEN |
|
110 |
template <typename GR, typename LEN, typename TR> |
|
111 |
#else |
|
112 |
template < typename GR, |
|
113 |
typename LEN = typename GR::template ArcMap<int>, |
|
114 |
typename TR = HowardDefaultTraits<GR, LEN> > |
|
115 |
#endif |
|
116 |
class Howard |
|
117 |
{ |
|
118 |
public: |
|
119 |
|
|
120 |
/// The type of the digraph |
|
121 |
typedef typename TR::Digraph Digraph; |
|
122 |
/// The type of the length map |
|
123 |
typedef typename TR::LengthMap LengthMap; |
|
124 |
/// The type of the arc lengths |
|
125 |
typedef typename TR::Value Value; |
|
126 |
|
|
127 |
/// \brief The large value type |
|
128 |
/// |
|
129 |
/// The large value type used for internal computations. |
|
130 |
/// Using the \ref HowardDefaultTraits "default traits class", |
|
131 |
/// it is \c long \c long if the \c Value type is integer, |
|
132 |
/// otherwise it is \c double. |
|
133 |
typedef typename TR::LargeValue LargeValue; |
|
134 |
|
|
135 |
/// The tolerance type |
|
136 |
typedef typename TR::Tolerance Tolerance; |
|
137 |
|
|
138 |
/// \brief The path type of the found cycles |
|
139 |
/// |
|
140 |
/// The path type of the found cycles. |
|
141 |
/// Using the \ref HowardDefaultTraits "default traits class", |
|
142 |
/// it is \ref lemon::Path "Path<Digraph>". |
|
143 |
typedef typename TR::Path Path; |
|
144 |
|
|
145 |
/// The \ref HowardDefaultTraits "traits class" of the algorithm |
|
146 |
typedef TR Traits; |
|
147 |
|
|
148 |
private: |
|
149 |
|
|
150 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
|
151 |
|
|
152 |
// The digraph the algorithm runs on |
|
153 |
const Digraph &_gr; |
|
154 |
// The length of the arcs |
|
155 |
const LengthMap &_length; |
|
156 |
|
|
157 |
// Data for the found cycles |
|
158 |
bool _curr_found, _best_found; |
|
159 |
LargeValue _curr_length, _best_length; |
|
160 |
int _curr_size, _best_size; |
|
161 |
Node _curr_node, _best_node; |
|
162 |
|
|
163 |
Path *_cycle_path; |
|
164 |
bool _local_path; |
|
165 |
|
|
166 |
// Internal data used by the algorithm |
|
167 |
typename Digraph::template NodeMap<Arc> _policy; |
|
168 |
typename Digraph::template NodeMap<bool> _reached; |
|
169 |
typename Digraph::template NodeMap<int> _level; |
|
170 |
typename Digraph::template NodeMap<LargeValue> _dist; |
|
171 |
|
|
172 |
// Data for storing the strongly connected components |
|
173 |
int _comp_num; |
|
174 |
typename Digraph::template NodeMap<int> _comp; |
|
175 |
std::vector<std::vector<Node> > _comp_nodes; |
|
176 |
std::vector<Node>* _nodes; |
|
177 |
typename Digraph::template NodeMap<std::vector<Arc> > _in_arcs; |
|
178 |
|
|
179 |
// Queue used for BFS search |
|
180 |
std::vector<Node> _queue; |
|
181 |
int _qfront, _qback; |
|
182 |
|
|
183 |
Tolerance _tolerance; |
|
184 |
|
|
185 |
// Infinite constant |
|
186 |
const LargeValue INF; |
|
187 |
|
|
188 |
public: |
|
189 |
|
|
190 |
/// \name Named Template Parameters |
|
191 |
/// @{ |
|
192 |
|
|
193 |
template <typename T> |
|
194 |
struct SetLargeValueTraits : public Traits { |
|
195 |
typedef T LargeValue; |
|
196 |
typedef lemon::Tolerance<T> Tolerance; |
|
197 |
}; |
|
198 |
|
|
199 |
/// \brief \ref named-templ-param "Named parameter" for setting |
|
200 |
/// \c LargeValue type. |
|
201 |
/// |
|
202 |
/// \ref named-templ-param "Named parameter" for setting \c LargeValue |
|
203 |
/// type. It is used for internal computations in the algorithm. |
|
204 |
template <typename T> |
|
205 |
struct SetLargeValue |
|
206 |
: public Howard<GR, LEN, SetLargeValueTraits<T> > { |
|
207 |
typedef Howard<GR, LEN, SetLargeValueTraits<T> > Create; |
|
208 |
}; |
|
209 |
|
|
210 |
template <typename T> |
|
211 |
struct SetPathTraits : public Traits { |
|
212 |
typedef T Path; |
|
213 |
}; |
|
214 |
|
|
215 |
/// \brief \ref named-templ-param "Named parameter" for setting |
|
216 |
/// \c %Path type. |
|
217 |
/// |
|
218 |
/// \ref named-templ-param "Named parameter" for setting the \c %Path |
|
219 |
/// type of the found cycles. |
|
220 |
/// It must conform to the \ref lemon::concepts::Path "Path" concept |
|
221 |
/// and it must have an \c addBack() function. |
|
222 |
template <typename T> |
|
223 |
struct SetPath |
|
224 |
: public Howard<GR, LEN, SetPathTraits<T> > { |
|
225 |
typedef Howard<GR, LEN, SetPathTraits<T> > Create; |
|
226 |
}; |
|
227 |
|
|
228 |
/// @} |
|
229 |
|
|
230 |
public: |
|
231 |
|
|
232 |
/// \brief Constructor. |
|
233 |
/// |
|
234 |
/// The constructor of the class. |
|
235 |
/// |
|
236 |
/// \param digraph The digraph the algorithm runs on. |
|
237 |
/// \param length The lengths (costs) of the arcs. |
|
238 |
Howard( const Digraph &digraph, |
|
239 |
const LengthMap &length ) : |
|
240 |
_gr(digraph), _length(length), _best_found(false), |
|
241 |
_best_length(0), _best_size(1), _cycle_path(NULL), _local_path(false), |
|
242 |
_policy(digraph), _reached(digraph), _level(digraph), _dist(digraph), |
|
243 |
_comp(digraph), _in_arcs(digraph), |
|
244 |
INF(std::numeric_limits<LargeValue>::has_infinity ? |
|
245 |
std::numeric_limits<LargeValue>::infinity() : |
|
246 |
std::numeric_limits<LargeValue>::max()) |
|
247 |
{} |
|
248 |
|
|
249 |
/// Destructor. |
|
250 |
~Howard() { |
|
251 |
if (_local_path) delete _cycle_path; |
|
252 |
} |
|
253 |
|
|
254 |
/// \brief Set the path structure for storing the found cycle. |
|
255 |
/// |
|
256 |
/// This function sets an external path structure for storing the |
|
257 |
/// found cycle. |
|
258 |
/// |
|
259 |
/// If you don't call this function before calling \ref run() or |
|
260 |
/// \ref findMinMean(), it will allocate a local \ref Path "path" |
|
261 |
/// structure. The destuctor deallocates this automatically |
|
262 |
/// allocated object, of course. |
|
263 |
/// |
|
264 |
/// \note The algorithm calls only the \ref lemon::Path::addBack() |
|
265 |
/// "addBack()" function of the given path structure. |
|
266 |
/// |
|
267 |
/// \return <tt>(*this)</tt> |
|
268 |
Howard& cycle(Path &path) { |
|
269 |
if (_local_path) { |
|
270 |
delete _cycle_path; |
|
271 |
_local_path = false; |
|
272 |
} |
|
273 |
_cycle_path = &path; |
|
274 |
return *this; |
|
275 |
} |
|
276 |
|
|
277 |
/// \brief Set the tolerance used by the algorithm. |
|
278 |
/// |
|
279 |
/// This function sets the tolerance object used by the algorithm. |
|
280 |
/// |
|
281 |
/// \return <tt>(*this)</tt> |
|
282 |
Howard& tolerance(const Tolerance& tolerance) { |
|
283 |
_tolerance = tolerance; |
|
284 |
return *this; |
|
285 |
} |
|
286 |
|
|
287 |
/// \brief Return a const reference to the tolerance. |
|
288 |
/// |
|
289 |
/// This function returns a const reference to the tolerance object |
|
290 |
/// used by the algorithm. |
|
291 |
const Tolerance& tolerance() const { |
|
292 |
return _tolerance; |
|
293 |
} |
|
294 |
|
|
295 |
/// \name Execution control |
|
296 |
/// The simplest way to execute the algorithm is to call the \ref run() |
|
297 |
/// function.\n |
|
298 |
/// If you only need the minimum mean length, you may call |
|
299 |
/// \ref findMinMean(). |
|
300 |
|
|
301 |
/// @{ |
|
302 |
|
|
303 |
/// \brief Run the algorithm. |
|
304 |
/// |
|
305 |
/// This function runs the algorithm. |
|
306 |
/// It can be called more than once (e.g. if the underlying digraph |
|
307 |
/// and/or the arc lengths have been modified). |
|
308 |
/// |
|
309 |
/// \return \c true if a directed cycle exists in the digraph. |
|
310 |
/// |
|
311 |
/// \note <tt>mmc.run()</tt> is just a shortcut of the following code. |
|
312 |
/// \code |
|
313 |
/// return mmc.findMinMean() && mmc.findCycle(); |
|
314 |
/// \endcode |
|
315 |
bool run() { |
|
316 |
return findMinMean() && findCycle(); |
|
317 |
} |
|
318 |
|
|
319 |
/// \brief Find the minimum cycle mean. |
|
320 |
/// |
|
321 |
/// This function finds the minimum mean length of the directed |
|
322 |
/// cycles in the digraph. |
|
323 |
/// |
|
324 |
/// \return \c true if a directed cycle exists in the digraph. |
|
325 |
bool findMinMean() { |
|
326 |
// Initialize and find strongly connected components |
|
327 |
init(); |
|
328 |
findComponents(); |
|
329 |
|
|
330 |
// Find the minimum cycle mean in the components |
|
331 |
for (int comp = 0; comp < _comp_num; ++comp) { |
|
332 |
// Find the minimum mean cycle in the current component |
|
333 |
if (!buildPolicyGraph(comp)) continue; |
|
334 |
while (true) { |
|
335 |
findPolicyCycle(); |
|
336 |
if (!computeNodeDistances()) break; |
|
337 |
} |
|
338 |
// Update the best cycle (global minimum mean cycle) |
|
339 |
if ( _curr_found && (!_best_found || |
|
340 |
_curr_length * _best_size < _best_length * _curr_size) ) { |
|
341 |
_best_found = true; |
|
342 |
_best_length = _curr_length; |
|
343 |
_best_size = _curr_size; |
|
344 |
_best_node = _curr_node; |
|
345 |
} |
|
346 |
} |
|
347 |
return _best_found; |
|
348 |
} |
|
349 |
|
|
350 |
/// \brief Find a minimum mean directed cycle. |
|
351 |
/// |
|
352 |
/// This function finds a directed cycle of minimum mean length |
|
353 |
/// in the digraph using the data computed by findMinMean(). |
|
354 |
/// |
|
355 |
/// \return \c true if a directed cycle exists in the digraph. |
|
356 |
/// |
|
357 |
/// \pre \ref findMinMean() must be called before using this function. |
|
358 |
bool findCycle() { |
|
359 |
if (!_best_found) return false; |
|
360 |
_cycle_path->addBack(_policy[_best_node]); |
|
361 |
for ( Node v = _best_node; |
|
362 |
(v = _gr.target(_policy[v])) != _best_node; ) { |
|
363 |
_cycle_path->addBack(_policy[v]); |
|
364 |
} |
|
365 |
return true; |
|
366 |
} |
|
367 |
|
|
368 |
/// @} |
|
369 |
|
|
370 |
/// \name Query Functions |
|
371 |
/// The results of the algorithm can be obtained using these |
|
372 |
/// functions.\n |
|
373 |
/// The algorithm should be executed before using them. |
|
374 |
|
|
375 |
/// @{ |
|
376 |
|
|
377 |
/// \brief Return the total length of the found cycle. |
|
378 |
/// |
|
379 |
/// This function returns the total length of the found cycle. |
|
380 |
/// |
|
381 |
/// \pre \ref run() or \ref findMinMean() must be called before |
|
382 |
/// using this function. |
|
383 |
LargeValue cycleLength() const { |
|
384 |
return _best_length; |
|
385 |
} |
|
386 |
|
|
387 |
/// \brief Return the number of arcs on the found cycle. |
|
388 |
/// |
|
389 |
/// This function returns the number of arcs on the found cycle. |
|
390 |
/// |
|
391 |
/// \pre \ref run() or \ref findMinMean() must be called before |
|
392 |
/// using this function. |
|
393 |
int cycleArcNum() const { |
|
394 |
return _best_size; |
|
395 |
} |
|
396 |
|
|
397 |
/// \brief Return the mean length of the found cycle. |
|
398 |
/// |
|
399 |
/// This function returns the mean length of the found cycle. |
|
400 |
/// |
|
401 |
/// \note <tt>alg.cycleMean()</tt> is just a shortcut of the |
|
402 |
/// following code. |
|
403 |
/// \code |
|
404 |
/// return static_cast<double>(alg.cycleLength()) / alg.cycleArcNum(); |
|
405 |
/// \endcode |
|
406 |
/// |
|
407 |
/// \pre \ref run() or \ref findMinMean() must be called before |
|
408 |
/// using this function. |
|
409 |
double cycleMean() const { |
|
410 |
return static_cast<double>(_best_length) / _best_size; |
|
411 |
} |
|
412 |
|
|
413 |
/// \brief Return the found cycle. |
|
414 |
/// |
|
415 |
/// This function returns a const reference to the path structure |
|
416 |
/// storing the found cycle. |
|
417 |
/// |
|
418 |
/// \pre \ref run() or \ref findCycle() must be called before using |
|
419 |
/// this function. |
|
420 |
const Path& cycle() const { |
|
421 |
return *_cycle_path; |
|
422 |
} |
|
423 |
|
|
424 |
///@} |
|
425 |
|
|
426 |
private: |
|
427 |
|
|
428 |
// Initialize |
|
429 |
void init() { |
|
430 |
if (!_cycle_path) { |
|
431 |
_local_path = true; |
|
432 |
_cycle_path = new Path; |
|
433 |
} |
|
434 |
_queue.resize(countNodes(_gr)); |
|
435 |
_best_found = false; |
|
436 |
_best_length = 0; |
|
437 |
_best_size = 1; |
|
438 |
_cycle_path->clear(); |
|
439 |
} |
|
440 |
|
|
441 |
// Find strongly connected components and initialize _comp_nodes |
|
442 |
// and _in_arcs |
|
443 |
void findComponents() { |
|
444 |
_comp_num = stronglyConnectedComponents(_gr, _comp); |
|
445 |
_comp_nodes.resize(_comp_num); |
|
446 |
if (_comp_num == 1) { |
|
447 |
_comp_nodes[0].clear(); |
|
448 |
for (NodeIt n(_gr); n != INVALID; ++n) { |
|
449 |
_comp_nodes[0].push_back(n); |
|
450 |
_in_arcs[n].clear(); |
|
451 |
for (InArcIt a(_gr, n); a != INVALID; ++a) { |
|
452 |
_in_arcs[n].push_back(a); |
|
453 |
} |
|
454 |
} |
|
455 |
} else { |
|
456 |
for (int i = 0; i < _comp_num; ++i) |
|
457 |
_comp_nodes[i].clear(); |
|
458 |
for (NodeIt n(_gr); n != INVALID; ++n) { |
|
459 |
int k = _comp[n]; |
|
460 |
_comp_nodes[k].push_back(n); |
|
461 |
_in_arcs[n].clear(); |
|
462 |
for (InArcIt a(_gr, n); a != INVALID; ++a) { |
|
463 |
if (_comp[_gr.source(a)] == k) _in_arcs[n].push_back(a); |
|
464 |
} |
|
465 |
} |
|
466 |
} |
|
467 |
} |
|
468 |
|
|
469 |
// Build the policy graph in the given strongly connected component |
|
470 |
// (the out-degree of every node is 1) |
|
471 |
bool buildPolicyGraph(int comp) { |
|
472 |
_nodes = &(_comp_nodes[comp]); |
|
473 |
if (_nodes->size() < 1 || |
|
474 |
(_nodes->size() == 1 && _in_arcs[(*_nodes)[0]].size() == 0)) { |
|
475 |
return false; |
|
476 |
} |
|
477 |
for (int i = 0; i < int(_nodes->size()); ++i) { |
|
478 |
_dist[(*_nodes)[i]] = INF; |
|
479 |
} |
|
480 |
Node u, v; |
|
481 |
Arc e; |
|
482 |
for (int i = 0; i < int(_nodes->size()); ++i) { |
|
483 |
v = (*_nodes)[i]; |
|
484 |
for (int j = 0; j < int(_in_arcs[v].size()); ++j) { |
|
485 |
e = _in_arcs[v][j]; |
|
486 |
u = _gr.source(e); |
|
487 |
if (_length[e] < _dist[u]) { |
|
488 |
_dist[u] = _length[e]; |
|
489 |
_policy[u] = e; |
|
490 |
} |
|
491 |
} |
|
492 |
} |
|
493 |
return true; |
|
494 |
} |
|
495 |
|
|
496 |
// Find the minimum mean cycle in the policy graph |
|
497 |
void findPolicyCycle() { |
|
498 |
for (int i = 0; i < int(_nodes->size()); ++i) { |
|
499 |
_level[(*_nodes)[i]] = -1; |
|
500 |
} |
|
501 |
LargeValue clength; |
|
502 |
int csize; |
|
503 |
Node u, v; |
|
504 |
_curr_found = false; |
|
505 |
for (int i = 0; i < int(_nodes->size()); ++i) { |
|
506 |
u = (*_nodes)[i]; |
|
507 |
if (_level[u] >= 0) continue; |
|
508 |
for (; _level[u] < 0; u = _gr.target(_policy[u])) { |
|
509 |
_level[u] = i; |
|
510 |
} |
|
511 |
if (_level[u] == i) { |
|
512 |
// A cycle is found |
|
513 |
clength = _length[_policy[u]]; |
|
514 |
csize = 1; |
|
515 |
for (v = u; (v = _gr.target(_policy[v])) != u; ) { |
|
516 |
clength += _length[_policy[v]]; |
|
517 |
++csize; |
|
518 |
} |
|
519 |
if ( !_curr_found || |
|
520 |
(clength * _curr_size < _curr_length * csize) ) { |
|
521 |
_curr_found = true; |
|
522 |
_curr_length = clength; |
|
523 |
_curr_size = csize; |
|
524 |
_curr_node = u; |
|
525 |
} |
|
526 |
} |
|
527 |
} |
|
528 |
} |
|
529 |
|
|
530 |
// Contract the policy graph and compute node distances |
|
531 |
bool computeNodeDistances() { |
|
532 |
// Find the component of the main cycle and compute node distances |
|
533 |
// using reverse BFS |
|
534 |
for (int i = 0; i < int(_nodes->size()); ++i) { |
|
535 |
_reached[(*_nodes)[i]] = false; |
|
536 |
} |
|
537 |
_qfront = _qback = 0; |
|
538 |
_queue[0] = _curr_node; |
|
539 |
_reached[_curr_node] = true; |
|
540 |
_dist[_curr_node] = 0; |
|
541 |
Node u, v; |
|
542 |
Arc e; |
|
543 |
while (_qfront <= _qback) { |
|
544 |
v = _queue[_qfront++]; |
|
545 |
for (int j = 0; j < int(_in_arcs[v].size()); ++j) { |
|
546 |
e = _in_arcs[v][j]; |
|
547 |
u = _gr.source(e); |
|
548 |
if (_policy[u] == e && !_reached[u]) { |
|
549 |
_reached[u] = true; |
|
550 |
_dist[u] = _dist[v] + _length[e] * _curr_size - _curr_length; |
|
551 |
_queue[++_qback] = u; |
|
552 |
} |
|
553 |
} |
|
554 |
} |
|
555 |
|
|
556 |
// Connect all other nodes to this component and compute node |
|
557 |
// distances using reverse BFS |
|
558 |
_qfront = 0; |
|
559 |
while (_qback < int(_nodes->size())-1) { |
|
560 |
v = _queue[_qfront++]; |
|
561 |
for (int j = 0; j < int(_in_arcs[v].size()); ++j) { |
|
562 |
e = _in_arcs[v][j]; |
|
563 |
u = _gr.source(e); |
|
564 |
if (!_reached[u]) { |
|
565 |
_reached[u] = true; |
|
566 |
_policy[u] = e; |
|
567 |
_dist[u] = _dist[v] + _length[e] * _curr_size - _curr_length; |
|
568 |
_queue[++_qback] = u; |
|
569 |
} |
|
570 |
} |
|
571 |
} |
|
572 |
|
|
573 |
// Improve node distances |
|
574 |
bool improved = false; |
|
575 |
for (int i = 0; i < int(_nodes->size()); ++i) { |
|
576 |
v = (*_nodes)[i]; |
|
577 |
for (int j = 0; j < int(_in_arcs[v].size()); ++j) { |
|
578 |
e = _in_arcs[v][j]; |
|
579 |
u = _gr.source(e); |
|
580 |
LargeValue delta = _dist[v] + _length[e] * _curr_size - _curr_length; |
|
581 |
if (_tolerance.less(delta, _dist[u])) { |
|
582 |
_dist[u] = delta; |
|
583 |
_policy[u] = e; |
|
584 |
improved = true; |
|
585 |
} |
|
586 |
} |
|
587 |
} |
|
588 |
return improved; |
|
589 |
} |
|
590 |
|
|
591 |
}; //class Howard |
|
592 |
|
|
593 |
///@} |
|
594 |
|
|
595 |
} //namespace lemon |
|
596 |
|
|
597 |
#endif //LEMON_HOWARD_H |
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_KARP_H |
|
20 |
#define LEMON_KARP_H |
|
21 |
|
|
22 |
/// \ingroup min_mean_cycle |
|
23 |
/// |
|
24 |
/// \file |
|
25 |
/// \brief Karp's algorithm for finding a minimum mean cycle. |
|
26 |
|
|
27 |
#include <vector> |
|
28 |
#include <limits> |
|
29 |
#include <lemon/core.h> |
|
30 |
#include <lemon/path.h> |
|
31 |
#include <lemon/tolerance.h> |
|
32 |
#include <lemon/connectivity.h> |
|
33 |
|
|
34 |
namespace lemon { |
|
35 |
|
|
36 |
/// \brief Default traits class of Karp algorithm. |
|
37 |
/// |
|
38 |
/// Default traits class of Karp algorithm. |
|
39 |
/// \tparam GR The type of the digraph. |
|
40 |
/// \tparam LEN The type of the length map. |
|
41 |
/// It must conform to the \ref concepts::ReadMap "ReadMap" concept. |
|
42 |
#ifdef DOXYGEN |
|
43 |
template <typename GR, typename LEN> |
|
44 |
#else |
|
45 |
template <typename GR, typename LEN, |
|
46 |
bool integer = std::numeric_limits<typename LEN::Value>::is_integer> |
|
47 |
#endif |
|
48 |
struct KarpDefaultTraits |
|
49 |
{ |
|
50 |
/// The type of the digraph |
|
51 |
typedef GR Digraph; |
|
52 |
/// The type of the length map |
|
53 |
typedef LEN LengthMap; |
|
54 |
/// The type of the arc lengths |
|
55 |
typedef typename LengthMap::Value Value; |
|
56 |
|
|
57 |
/// \brief The large value type used for internal computations |
|
58 |
/// |
|
59 |
/// The large value type used for internal computations. |
|
60 |
/// It is \c long \c long if the \c Value type is integer, |
|
61 |
/// otherwise it is \c double. |
|
62 |
/// \c Value must be convertible to \c LargeValue. |
|
63 |
typedef double LargeValue; |
|
64 |
|
|
65 |
/// The tolerance type used for internal computations |
|
66 |
typedef lemon::Tolerance<LargeValue> Tolerance; |
|
67 |
|
|
68 |
/// \brief The path type of the found cycles |
|
69 |
/// |
|
70 |
/// The path type of the found cycles. |
|
71 |
/// It must conform to the \ref lemon::concepts::Path "Path" concept |
|
72 |
/// and it must have an \c addFront() function. |
|
73 |
typedef lemon::Path<Digraph> Path; |
|
74 |
}; |
|
75 |
|
|
76 |
// Default traits class for integer value types |
|
77 |
template <typename GR, typename LEN> |
|
78 |
struct KarpDefaultTraits<GR, LEN, true> |
|
79 |
{ |
|
80 |
typedef GR Digraph; |
|
81 |
typedef LEN LengthMap; |
|
82 |
typedef typename LengthMap::Value Value; |
|
83 |
#ifdef LEMON_HAVE_LONG_LONG |
|
84 |
typedef long long LargeValue; |
|
85 |
#else |
|
86 |
typedef long LargeValue; |
|
87 |
#endif |
|
88 |
typedef lemon::Tolerance<LargeValue> Tolerance; |
|
89 |
typedef lemon::Path<Digraph> Path; |
|
90 |
}; |
|
91 |
|
|
92 |
|
|
93 |
/// \addtogroup min_mean_cycle |
|
94 |
/// @{ |
|
95 |
|
|
96 |
/// \brief Implementation of Karp's algorithm for finding a minimum |
|
97 |
/// mean cycle. |
|
98 |
/// |
|
99 |
/// This class implements Karp's algorithm for finding a directed |
|
100 |
/// cycle of minimum mean length (cost) in a digraph |
|
101 |
/// \ref amo93networkflows, \ref dasdan98minmeancycle. |
|
102 |
/// It runs in time O(ne) and uses space O(n<sup>2</sup>+e). |
|
103 |
/// |
|
104 |
/// \tparam GR The type of the digraph the algorithm runs on. |
|
105 |
/// \tparam LEN The type of the length map. The default |
|
106 |
/// map type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". |
|
107 |
#ifdef DOXYGEN |
|
108 |
template <typename GR, typename LEN, typename TR> |
|
109 |
#else |
|
110 |
template < typename GR, |
|
111 |
typename LEN = typename GR::template ArcMap<int>, |
|
112 |
typename TR = KarpDefaultTraits<GR, LEN> > |
|
113 |
#endif |
|
114 |
class Karp |
|
115 |
{ |
|
116 |
public: |
|
117 |
|
|
118 |
/// The type of the digraph |
|
119 |
typedef typename TR::Digraph Digraph; |
|
120 |
/// The type of the length map |
|
121 |
typedef typename TR::LengthMap LengthMap; |
|
122 |
/// The type of the arc lengths |
|
123 |
typedef typename TR::Value Value; |
|
124 |
|
|
125 |
/// \brief The large value type |
|
126 |
/// |
|
127 |
/// The large value type used for internal computations. |
|
128 |
/// Using the \ref KarpDefaultTraits "default traits class", |
|
129 |
/// it is \c long \c long if the \c Value type is integer, |
|
130 |
/// otherwise it is \c double. |
|
131 |
typedef typename TR::LargeValue LargeValue; |
|
132 |
|
|
133 |
/// The tolerance type |
|
134 |
typedef typename TR::Tolerance Tolerance; |
|
135 |
|
|
136 |
/// \brief The path type of the found cycles |
|
137 |
/// |
|
138 |
/// The path type of the found cycles. |
|
139 |
/// Using the \ref KarpDefaultTraits "default traits class", |
|
140 |
/// it is \ref lemon::Path "Path<Digraph>". |
|
141 |
typedef typename TR::Path Path; |
|
142 |
|
|
143 |
/// The \ref KarpDefaultTraits "traits class" of the algorithm |
|
144 |
typedef TR Traits; |
|
145 |
|
|
146 |
private: |
|
147 |
|
|
148 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
|
149 |
|
|
150 |
// Data sturcture for path data |
|
151 |
struct PathData |
|
152 |
{ |
|
153 |
LargeValue dist; |
|
154 |
Arc pred; |
|
155 |
PathData(LargeValue d, Arc p = INVALID) : |
|
156 |
dist(d), pred(p) {} |
|
157 |
}; |
|
158 |
|
|
159 |
typedef typename Digraph::template NodeMap<std::vector<PathData> > |
|
160 |
PathDataNodeMap; |
|
161 |
|
|
162 |
private: |
|
163 |
|
|
164 |
// The digraph the algorithm runs on |
|
165 |
const Digraph &_gr; |
|
166 |
// The length of the arcs |
|
167 |
const LengthMap &_length; |
|
168 |
|
|
169 |
// Data for storing the strongly connected components |
|
170 |
int _comp_num; |
|
171 |
typename Digraph::template NodeMap<int> _comp; |
|
172 |
std::vector<std::vector<Node> > _comp_nodes; |
|
173 |
std::vector<Node>* _nodes; |
|
174 |
typename Digraph::template NodeMap<std::vector<Arc> > _out_arcs; |
|
175 |
|
|
176 |
// Data for the found cycle |
|
177 |
LargeValue _cycle_length; |
|
178 |
int _cycle_size; |
|
179 |
Node _cycle_node; |
|
180 |
|
|
181 |
Path *_cycle_path; |
|
182 |
bool _local_path; |
|
183 |
|
|
184 |
// Node map for storing path data |
|
185 |
PathDataNodeMap _data; |
|
186 |
// The processed nodes in the last round |
|
187 |
std::vector<Node> _process; |
|
188 |
|
|
189 |
Tolerance _tolerance; |
|
190 |
|
|
191 |
// Infinite constant |
|
192 |
const LargeValue INF; |
|
193 |
|
|
194 |
public: |
|
195 |
|
|
196 |
/// \name Named Template Parameters |
|
197 |
/// @{ |
|
198 |
|
|
199 |
template <typename T> |
|
200 |
struct SetLargeValueTraits : public Traits { |
|
201 |
typedef T LargeValue; |
|
202 |
typedef lemon::Tolerance<T> Tolerance; |
|
203 |
}; |
|
204 |
|
|
205 |
/// \brief \ref named-templ-param "Named parameter" for setting |
|
206 |
/// \c LargeValue type. |
|
207 |
/// |
|
208 |
/// \ref named-templ-param "Named parameter" for setting \c LargeValue |
|
209 |
/// type. It is used for internal computations in the algorithm. |
|
210 |
template <typename T> |
|
211 |
struct SetLargeValue |
|
212 |
: public Karp<GR, LEN, SetLargeValueTraits<T> > { |
|
213 |
typedef Karp<GR, LEN, SetLargeValueTraits<T> > Create; |
|
214 |
}; |
|
215 |
|
|
216 |
template <typename T> |
|
217 |
struct SetPathTraits : public Traits { |
|
218 |
typedef T Path; |
|
219 |
}; |
|
220 |
|
|
221 |
/// \brief \ref named-templ-param "Named parameter" for setting |
|
222 |
/// \c %Path type. |
|
223 |
/// |
|
224 |
/// \ref named-templ-param "Named parameter" for setting the \c %Path |
|
225 |
/// type of the found cycles. |
|
226 |
/// It must conform to the \ref lemon::concepts::Path "Path" concept |
|
227 |
/// and it must have an \c addFront() function. |
|
228 |
template <typename T> |
|
229 |
struct SetPath |
|
230 |
: public Karp<GR, LEN, SetPathTraits<T> > { |
|
231 |
typedef Karp<GR, LEN, SetPathTraits<T> > Create; |
|
232 |
}; |
|
233 |
|
|
234 |
/// @} |
|
235 |
|
|
236 |
public: |
|
237 |
|
|
238 |
/// \brief Constructor. |
|
239 |
/// |
|
240 |
/// The constructor of the class. |
|
241 |
/// |
|
242 |
/// \param digraph The digraph the algorithm runs on. |
|
243 |
/// \param length The lengths (costs) of the arcs. |
|
244 |
Karp( const Digraph &digraph, |
|
245 |
const LengthMap &length ) : |
|
246 |
_gr(digraph), _length(length), _comp(digraph), _out_arcs(digraph), |
|
247 |
_cycle_length(0), _cycle_size(1), _cycle_node(INVALID), |
|
248 |
_cycle_path(NULL), _local_path(false), _data(digraph), |
|
249 |
INF(std::numeric_limits<LargeValue>::has_infinity ? |
|
250 |
std::numeric_limits<LargeValue>::infinity() : |
|
251 |
std::numeric_limits<LargeValue>::max()) |
|
252 |
{} |
|
253 |
|
|
254 |
/// Destructor. |
|
255 |
~Karp() { |
|
256 |
if (_local_path) delete _cycle_path; |
|
257 |
} |
|
258 |
|
|
259 |
/// \brief Set the path structure for storing the found cycle. |
|
260 |
/// |
|
261 |
/// This function sets an external path structure for storing the |
|
262 |
/// found cycle. |
|
263 |
/// |
|
264 |
/// If you don't call this function before calling \ref run() or |
|
265 |
/// \ref findMinMean(), it will allocate a local \ref Path "path" |
|
266 |
/// structure. The destuctor deallocates this automatically |
|
267 |
/// allocated object, of course. |
|
268 |
/// |
|
269 |
/// \note The algorithm calls only the \ref lemon::Path::addFront() |
|
270 |
/// "addFront()" function of the given path structure. |
|
271 |
/// |
|
272 |
/// \return <tt>(*this)</tt> |
|
273 |
Karp& cycle(Path &path) { |
|
274 |
if (_local_path) { |
|
275 |
delete _cycle_path; |
|
276 |
_local_path = false; |
|
277 |
} |
|
278 |
_cycle_path = &path; |
|
279 |
return *this; |
|
280 |
} |
|
281 |
|
|
282 |
/// \brief Set the tolerance used by the algorithm. |
|
283 |
/// |
|
284 |
/// This function sets the tolerance object used by the algorithm. |
|
285 |
/// |
|
286 |
/// \return <tt>(*this)</tt> |
|
287 |
Karp& tolerance(const Tolerance& tolerance) { |
|
288 |
_tolerance = tolerance; |
|
289 |
return *this; |
|
290 |
} |
|
291 |
|
|
292 |
/// \brief Return a const reference to the tolerance. |
|
293 |
/// |
|
294 |
/// This function returns a const reference to the tolerance object |
|
295 |
/// used by the algorithm. |
|
296 |
const Tolerance& tolerance() const { |
|
297 |
return _tolerance; |
|
298 |
} |
|
299 |
|
|
300 |
/// \name Execution control |
|
301 |
/// The simplest way to execute the algorithm is to call the \ref run() |
|
302 |
/// function.\n |
|
303 |
/// If you only need the minimum mean length, you may call |
|
304 |
/// \ref findMinMean(). |
|
305 |
|
|
306 |
/// @{ |
|
307 |
|
|
308 |
/// \brief Run the algorithm. |
|
309 |
/// |
|
310 |
/// This function runs the algorithm. |
|
311 |
/// It can be called more than once (e.g. if the underlying digraph |
|
312 |
/// and/or the arc lengths have been modified). |
|
313 |
/// |
|
314 |
/// \return \c true if a directed cycle exists in the digraph. |
|
315 |
/// |
|
316 |
/// \note <tt>mmc.run()</tt> is just a shortcut of the following code. |
|
317 |
/// \code |
|
318 |
/// return mmc.findMinMean() && mmc.findCycle(); |
|
319 |
/// \endcode |
|
320 |
bool run() { |
|
321 |
return findMinMean() && findCycle(); |
|
322 |
} |
|
323 |
|
|
324 |
/// \brief Find the minimum cycle mean. |
|
325 |
/// |
|
326 |
/// This function finds the minimum mean length of the directed |
|
327 |
/// cycles in the digraph. |
|
328 |
/// |
|
329 |
/// \return \c true if a directed cycle exists in the digraph. |
|
330 |
bool findMinMean() { |
|
331 |
// Initialization and find strongly connected components |
|
332 |
init(); |
|
333 |
findComponents(); |
|
334 |
|
|
335 |
// Find the minimum cycle mean in the components |
|
336 |
for (int comp = 0; comp < _comp_num; ++comp) { |
|
337 |
if (!initComponent(comp)) continue; |
|
338 |
processRounds(); |
|
339 |
updateMinMean(); |
|
340 |
} |
|
341 |
return (_cycle_node != INVALID); |
|
342 |
} |
|
343 |
|
|
344 |
/// \brief Find a minimum mean directed cycle. |
|
345 |
/// |
|
346 |
/// This function finds a directed cycle of minimum mean length |
|
347 |
/// in the digraph using the data computed by findMinMean(). |
|
348 |
/// |
|
349 |
/// \return \c true if a directed cycle exists in the digraph. |
|
350 |
/// |
|
351 |
/// \pre \ref findMinMean() must be called before using this function. |
|
352 |
bool findCycle() { |
|
353 |
if (_cycle_node == INVALID) return false; |
|
354 |
IntNodeMap reached(_gr, -1); |
|
355 |
int r = _data[_cycle_node].size(); |
|
356 |
Node u = _cycle_node; |
|
357 |
while (reached[u] < 0) { |
|
358 |
reached[u] = --r; |
|
359 |
u = _gr.source(_data[u][r].pred); |
|
360 |
} |
|
361 |
r = reached[u]; |
|
362 |
Arc e = _data[u][r].pred; |
|
363 |
_cycle_path->addFront(e); |
|
364 |
_cycle_length = _length[e]; |
|
365 |
_cycle_size = 1; |
|
366 |
Node v; |
|
367 |
while ((v = _gr.source(e)) != u) { |
|
368 |
e = _data[v][--r].pred; |
|
369 |
_cycle_path->addFront(e); |
|
370 |
_cycle_length += _length[e]; |
|
371 |
++_cycle_size; |
|
372 |
} |
|
373 |
return true; |
|
374 |
} |
|
375 |
|
|
376 |
/// @} |
|
377 |
|
|
378 |
/// \name Query Functions |
|
379 |
/// The results of the algorithm can be obtained using these |
|
380 |
/// functions.\n |
|
381 |
/// The algorithm should be executed before using them. |
|
382 |
|
|
383 |
/// @{ |
|
384 |
|
|
385 |
/// \brief Return the total length of the found cycle. |
|
386 |
/// |
|
387 |
/// This function returns the total length of the found cycle. |
|
388 |
/// |
|
389 |
/// \pre \ref run() or \ref findMinMean() must be called before |
|
390 |
/// using this function. |
|
391 |
LargeValue cycleLength() const { |
|
392 |
return _cycle_length; |
|
393 |
} |
|
394 |
|
|
395 |
/// \brief Return the number of arcs on the found cycle. |
|
396 |
/// |
|
397 |
/// This function returns the number of arcs on the found cycle. |
|
398 |
/// |
|
399 |
/// \pre \ref run() or \ref findMinMean() must be called before |
|
400 |
/// using this function. |
|
401 |
int cycleArcNum() const { |
|
402 |
return _cycle_size; |
|
403 |
} |
|
404 |
|
|
405 |
/// \brief Return the mean length of the found cycle. |
|
406 |
/// |
|
407 |
/// This function returns the mean length of the found cycle. |
|
408 |
/// |
|
409 |
/// \note <tt>alg.cycleMean()</tt> is just a shortcut of the |
|
410 |
/// following code. |
|
411 |
/// \code |
|
412 |
/// return static_cast<double>(alg.cycleLength()) / alg.cycleArcNum(); |
|
413 |
/// \endcode |
|
414 |
/// |
|
415 |
/// \pre \ref run() or \ref findMinMean() must be called before |
|
416 |
/// using this function. |
|
417 |
double cycleMean() const { |
|
418 |
return static_cast<double>(_cycle_length) / _cycle_size; |
|
419 |
} |
|
420 |
|
|
421 |
/// \brief Return the found cycle. |
|
422 |
/// |
|
423 |
/// This function returns a const reference to the path structure |
|
424 |
/// storing the found cycle. |
|
425 |
/// |
|
426 |
/// \pre \ref run() or \ref findCycle() must be called before using |
|
427 |
/// this function. |
|
428 |
const Path& cycle() const { |
|
429 |
return *_cycle_path; |
|
430 |
} |
|
431 |
|
|
432 |
///@} |
|
433 |
|
|
434 |
private: |
|
435 |
|
|
436 |
// Initialization |
|
437 |
void init() { |
|
438 |
if (!_cycle_path) { |
|
439 |
_local_path = true; |
|
440 |
_cycle_path = new Path; |
|
441 |
} |
|
442 |
_cycle_path->clear(); |
|
443 |
_cycle_length = 0; |
|
444 |
_cycle_size = 1; |
|
445 |
_cycle_node = INVALID; |
|
446 |
for (NodeIt u(_gr); u != INVALID; ++u) |
|
447 |
_data[u].clear(); |
|
448 |
} |
|
449 |
|
|
450 |
// Find strongly connected components and initialize _comp_nodes |
|
451 |
// and _out_arcs |
|
452 |
void findComponents() { |
|
453 |
_comp_num = stronglyConnectedComponents(_gr, _comp); |
|
454 |
_comp_nodes.resize(_comp_num); |
|
455 |
if (_comp_num == 1) { |
|
456 |
_comp_nodes[0].clear(); |
|
457 |
for (NodeIt n(_gr); n != INVALID; ++n) { |
|
458 |
_comp_nodes[0].push_back(n); |
|
459 |
_out_arcs[n].clear(); |
|
460 |
for (OutArcIt a(_gr, n); a != INVALID; ++a) { |
|
461 |
_out_arcs[n].push_back(a); |
|
462 |
} |
|
463 |
} |
|
464 |
} else { |
|
465 |
for (int i = 0; i < _comp_num; ++i) |
|
466 |
_comp_nodes[i].clear(); |
|
467 |
for (NodeIt n(_gr); n != INVALID; ++n) { |
|
468 |
int k = _comp[n]; |
|
469 |
_comp_nodes[k].push_back(n); |
|
470 |
_out_arcs[n].clear(); |
|
471 |
for (OutArcIt a(_gr, n); a != INVALID; ++a) { |
|
472 |
if (_comp[_gr.target(a)] == k) _out_arcs[n].push_back(a); |
|
473 |
} |
|
474 |
} |
|
475 |
} |
|
476 |
} |
|
477 |
|
|
478 |
// Initialize path data for the current component |
|
479 |
bool initComponent(int comp) { |
|
480 |
_nodes = &(_comp_nodes[comp]); |
|
481 |
int n = _nodes->size(); |
|
482 |
if (n < 1 || (n == 1 && _out_arcs[(*_nodes)[0]].size() == 0)) { |
|
483 |
return false; |
|
484 |
} |
|
485 |
for (int i = 0; i < n; ++i) { |
|
486 |
_data[(*_nodes)[i]].resize(n + 1, PathData(INF)); |
|
487 |
} |
|
488 |
return true; |
|
489 |
} |
|
490 |
|
|
491 |
// Process all rounds of computing path data for the current component. |
|
492 |
// _data[v][k] is the length of a shortest directed walk from the root |
|
493 |
// node to node v containing exactly k arcs. |
|
494 |
void processRounds() { |
|
495 |
Node start = (*_nodes)[0]; |
|
496 |
_data[start][0] = PathData(0); |
|
497 |
_process.clear(); |
|
498 |
_process.push_back(start); |
|
499 |
|
|
500 |
int k, n = _nodes->size(); |
|
501 |
for (k = 1; k <= n && int(_process.size()) < n; ++k) { |
|
502 |
processNextBuildRound(k); |
|
503 |
} |
|
504 |
for ( ; k <= n; ++k) { |
|
505 |
processNextFullRound(k); |
|
506 |
} |
|
507 |
} |
|
508 |
|
|
509 |
// Process one round and rebuild _process |
|
510 |
void processNextBuildRound(int k) { |
|
511 |
std::vector<Node> next; |
|
512 |
Node u, v; |
|
513 |
Arc e; |
|
514 |
LargeValue d; |
|
515 |
for (int i = 0; i < int(_process.size()); ++i) { |
|
516 |
u = _process[i]; |
|
517 |
for (int j = 0; j < int(_out_arcs[u].size()); ++j) { |
|
518 |
e = _out_arcs[u][j]; |
|
519 |
v = _gr.target(e); |
|
520 |
d = _data[u][k-1].dist + _length[e]; |
|
521 |
if (_tolerance.less(d, _data[v][k].dist)) { |
|
522 |
if (_data[v][k].dist == INF) next.push_back(v); |
|
523 |
_data[v][k] = PathData(d, e); |
|
524 |
} |
|
525 |
} |
|
526 |
} |
|
527 |
_process.swap(next); |
|
528 |
} |
|
529 |
|
|
530 |
// Process one round using _nodes instead of _process |
|
531 |
void processNextFullRound(int k) { |
|
532 |
Node u, v; |
|
533 |
Arc e; |
|
534 |
LargeValue d; |
|
535 |
for (int i = 0; i < int(_nodes->size()); ++i) { |
|
536 |
u = (*_nodes)[i]; |
|
537 |
for (int j = 0; j < int(_out_arcs[u].size()); ++j) { |
|
538 |
e = _out_arcs[u][j]; |
|
539 |
v = _gr.target(e); |
|
540 |
d = _data[u][k-1].dist + _length[e]; |
|
541 |
if (_tolerance.less(d, _data[v][k].dist)) { |
|
542 |
_data[v][k] = PathData(d, e); |
|
543 |
} |
|
544 |
} |
|
545 |
} |
|
546 |
} |
|
547 |
|
|
548 |
// Update the minimum cycle mean |
|
549 |
void updateMinMean() { |
|
550 |
int n = _nodes->size(); |
|
551 |
for (int i = 0; i < n; ++i) { |
|
552 |
Node u = (*_nodes)[i]; |
|
553 |
if (_data[u][n].dist == INF) continue; |
|
554 |
LargeValue length, max_length = 0; |
|
555 |
int size, max_size = 1; |
|
556 |
bool found_curr = false; |
|
557 |
for (int k = 0; k < n; ++k) { |
|
558 |
if (_data[u][k].dist == INF) continue; |
|
559 |
length = _data[u][n].dist - _data[u][k].dist; |
|
560 |
size = n - k; |
|
561 |
if (!found_curr || length * max_size > max_length * size) { |
|
562 |
found_curr = true; |
|
563 |
max_length = length; |
|
564 |
max_size = size; |
|
565 |
} |
|
566 |
} |
|
567 |
if ( found_curr && (_cycle_node == INVALID || |
|
568 |
max_length * _cycle_size < _cycle_length * max_size) ) { |
|
569 |
_cycle_length = max_length; |
|
570 |
_cycle_size = max_size; |
|
571 |
_cycle_node = u; |
|
572 |
} |
|
573 |
} |
|
574 |
} |
|
575 |
|
|
576 |
}; //class Karp |
|
577 |
|
|
578 |
///@} |
|
579 |
|
|
580 |
} //namespace lemon |
|
581 |
|
|
582 |
#endif //LEMON_KARP_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 \ |
... | ... |
@@ -282,2 +282,24 @@ |
282 | 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 |
/** |
|
283 | 305 |
@defgroup algs Algorithms |
... | ... |
@@ -296,3 +318,4 @@ |
296 | 318 |
This group contains the common graph search algorithms, namely |
297 |
\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. |
|
298 | 321 |
*/ |
... | ... |
@@ -304,3 +327,4 @@ |
304 | 327 |
|
305 |
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. |
|
306 | 330 |
|
... | ... |
@@ -321,2 +345,11 @@ |
321 | 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 |
/** |
|
322 | 355 |
@defgroup max_flow Maximum Flow Algorithms |
... | ... |
@@ -326,3 +359,3 @@ |
326 | 359 |
This group contains the algorithms for finding maximum flows and |
327 |
feasible circulations. |
|
360 |
feasible circulations \ref clrs01algorithms, \ref amo93networkflows. |
|
328 | 361 |
|
... | ... |
@@ -341,8 +374,12 @@ |
341 | 374 |
LEMON contains several algorithms for solving maximum flow problems: |
342 |
- \ref EdmondsKarp Edmonds-Karp algorithm. |
|
343 |
- \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm. |
|
344 |
- \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees. |
|
345 |
- \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. |
|
346 | 383 |
|
347 |
In most cases the \ref Preflow |
|
384 |
In most cases the \ref Preflow algorithm provides the |
|
348 | 385 |
fastest method for computing a maximum flow. All implementations |
... | ... |
@@ -364,4 +401,5 @@ |
364 | 401 |
This group contains the algorithms for finding minimum cost flows and |
365 |
circulations. For more information about this problem and its dual |
|
366 |
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". |
|
367 | 405 |
|
... | ... |
@@ -369,9 +407,12 @@ |
369 | 407 |
- \ref NetworkSimplex Primal Network Simplex algorithm with various |
370 |
pivot strategies. |
|
408 |
pivot strategies \ref dantzig63linearprog, \ref kellyoneill91netsimplex. |
|
371 | 409 |
- \ref CostScaling Push-Relabel and Augment-Relabel algorithms based on |
372 |
cost scaling |
|
410 |
cost scaling \ref goldberg90approximation, \ref goldberg97efficient, |
|
411 |
\ref bunnagel98efficient. |
|
373 | 412 |
- \ref CapacityScaling Successive Shortest %Path algorithm with optional |
374 |
capacity scaling. |
|
375 |
- \ref CancelAndTighten The Cancel and Tighten algorithm. |
|
376 |
|
|
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. |
|
377 | 418 |
|
... | ... |
@@ -398,3 +439,3 @@ |
398 | 439 |
\f[ \min_{X \subset V, X\not\in \{\emptyset, V\}} |
399 |
\sum_{uv\in A |
|
440 |
\sum_{uv\in A: u\in X, v\not\in X}cap(uv) \f] |
|
400 | 441 |
|
... | ... |
@@ -414,23 +455,36 @@ |
414 | 455 |
/** |
415 |
@defgroup |
|
456 |
@defgroup min_mean_cycle Minimum Mean Cycle Algorithms |
|
416 | 457 |
@ingroup algs |
417 |
\brief Algorithms for |
|
458 |
\brief Algorithms for finding minimum mean cycles. |
|
418 | 459 |
|
419 |
This group contains the algorithms for discovering the graph properties |
|
420 |
like connectivity, bipartiteness, euler property, simplicity etc. |
|
460 |
This group contains the algorithms for finding minimum mean cycles |
|
461 |
\ref clrs01algorithms, \ref amo93networkflows. |
|
421 | 462 |
|
422 |
\image html edge_biconnected_components.png |
|
423 |
\image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth |
|
424 |
|
|
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. |
|
425 | 467 |
|
426 |
/** |
|
427 |
@defgroup planar Planarity Embedding and Drawing |
|
428 |
@ingroup algs |
|
429 |
\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. |
|
430 | 475 |
|
431 |
This group contains the algorithms for planarity checking, |
|
432 |
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. |
|
433 | 483 |
|
434 |
\image html planar.png |
|
435 |
\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. |
|
436 | 490 |
*/ |
... | ... |
@@ -478,8 +532,32 @@ |
478 | 532 |
/** |
479 |
@defgroup |
|
533 |
@defgroup graph_properties Connectivity and Other Graph Properties |
|
480 | 534 |
@ingroup algs |
481 |
\brief Algorithms for |
|
535 |
\brief Algorithms for discovering the graph properties |
|
482 | 536 |
|
483 |
This group contains the algorithms for finding minimum cost spanning |
|
484 |
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. |
|
485 | 563 |
*/ |
... | ... |
@@ -496,11 +574,2 @@ |
496 | 574 |
/** |
497 |
@defgroup approx Approximation Algorithms |
|
498 |
@ingroup algs |
|
499 |
\brief Approximation algorithms. |
|
500 |
|
|
501 |
This group contains the approximation and heuristic algorithms |
|
502 |
implemented in LEMON. |
|
503 |
*/ |
|
504 |
|
|
505 |
/** |
|
506 | 575 |
@defgroup gen_opt_group General Optimization Tools |
... | ... |
@@ -514,9 +583,12 @@ |
514 | 583 |
/** |
515 |
@defgroup lp_group |
|
584 |
@defgroup lp_group LP and MIP Solvers |
|
516 | 585 |
@ingroup gen_opt_group |
517 |
\brief |
|
586 |
\brief LP and MIP solver interfaces for LEMON. |
|
518 | 587 |
|
519 |
This group contains Lp and Mip solver interfaces for LEMON. The |
|
520 |
various LP solvers could be used in the same manner with this |
|
521 |
|
|
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. |
|
522 | 594 |
*/ |
... | ... |
@@ -610,3 +682,3 @@ |
610 | 682 |
/** |
611 |
@defgroup dimacs_group DIMACS |
|
683 |
@defgroup dimacs_group DIMACS Format |
|
612 | 684 |
@ingroup io_group |
... | ... |
@@ -659,4 +731,4 @@ |
659 | 731 |
|
660 |
This group contains the skeletons and concept checking classes of LEMON's |
|
661 |
graph structures and helper classes used to implement these. |
|
732 |
This group contains the skeletons and concept checking classes of |
|
733 |
graph structures. |
|
662 | 734 |
*/ |
... | ... |
@@ -672,2 +744,11 @@ |
672 | 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 |
/** |
|
673 | 754 |
\anchor demoprograms |
... | ... |
@@ -683,11 +764,2 @@ |
683 | 764 |
|
684 |
/** |
|
685 |
@defgroup tools Standalone Utility Applications |
|
686 |
|
|
687 |
Some utility applications are listed here. |
|
688 |
|
|
689 |
The standard compilation procedure (<tt>./configure;make</tt>) will compile |
|
690 |
them, as well. |
|
691 |
*/ |
|
692 |
|
|
693 | 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$, |
... | ... |
@@ -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. |
... | ... |
@@ -25,2 +25,3 @@ |
25 | 25 |
|
26 |
#include <lemon/list_graph.h> |
|
26 | 27 |
#include <lemon/bits/path_dump.h> |
... | ... |
@@ -301,3 +302,3 @@ |
301 | 302 |
/// \c OperationTraits type. |
302 |
/// For more information see \ref BellmanFordDefaultOperationTraits. |
|
303 |
/// For more information, see \ref BellmanFordDefaultOperationTraits. |
|
303 | 304 |
template <class T> |
... | ... |
@@ -719,3 +720,3 @@ |
719 | 720 |
/// The shortest path tree used here is equal to the shortest path |
720 |
/// tree used in \ref predNode() and \predMap(). |
|
721 |
/// tree used in \ref predNode() and \ref predMap(). |
|
721 | 722 |
/// |
... | ... |
@@ -734,3 +735,3 @@ |
734 | 735 |
/// The shortest path tree used here is equal to the shortest path |
735 |
/// tree used in \ref predArc() and \predMap(). |
|
736 |
/// tree used in \ref predArc() and \ref predMap(). |
|
736 | 737 |
/// |
... | ... |
@@ -777,3 +778,3 @@ |
777 | 778 |
/// Otherwise it gives back an empty path. |
778 |
lemon::Path<Digraph> negativeCycle() { |
|
779 |
lemon::Path<Digraph> negativeCycle() const { |
|
779 | 780 |
typename Digraph::template NodeMap<int> state(*_gr, -1); |
... | ... |
@@ -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 |
/// |
... | ... |
@@ -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); |
... | ... |
@@ -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 |
... | ... |
@@ -471,4 +478,4 @@ |
471 | 478 |
/// The simplest way to execute the algorithm is to call \ref run().\n |
472 |
/// If you need more control on the initial solution or the execution, |
|
473 |
/// 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 |
|
474 | 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 |
... | ... |
@@ -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> |
... | ... |
@@ -26,3 +26,3 @@ |
26 | 26 |
///\file |
27 |
///\brief |
|
27 |
///\brief FullDigraph and FullGraph classes. |
|
28 | 28 |
|
... | ... |
@@ -53,3 +53,3 @@ |
53 | 53 |
Node operator()(int ix) const { return Node(ix); } |
54 |
int index(const Node& node) |
|
54 |
static int index(const Node& node) { return node._id; } |
|
55 | 55 |
|
... | ... |
@@ -150,20 +150,24 @@ |
150 | 150 |
/// |
151 |
/// \brief A full |
|
151 |
/// \brief A directed full graph class. |
|
152 | 152 |
/// |
153 |
/// This is a simple and fast directed full graph implementation. |
|
154 |
/// From each node go arcs to each node (including the source node), |
|
155 |
/// therefore the number of the arcs in the digraph is the square of |
|
156 |
/// the node number. This digraph type is completely static, so you |
|
157 |
/// can neither add nor delete either arcs or nodes, and it needs |
|
158 |
/// constant space in memory. |
|
153 |
/// FullDigraph is a simple and fast implmenetation of directed full |
|
154 |
/// (complete) graphs. It contains an arc from each node to each node |
|
155 |
/// (including a loop for each node), therefore the number of arcs |
|
156 |
/// is the square of the number of nodes. |
|
157 |
/// This class is completely static and it needs constant memory space. |
|
158 |
/// Thus you can neither add nor delete nodes or arcs, however |
|
159 |
/// the structure can be resized using resize(). |
|
159 | 160 |
/// |
160 |
/// This class fully conforms to the \ref concepts::Digraph |
|
161 |
/// "Digraph concept". |
|
161 |
/// This type fully conforms to the \ref concepts::Digraph "Digraph concept". |
|
162 |
/// Most of its member functions and nested classes are documented |
|
163 |
/// only in the concept class. |
|
162 | 164 |
/// |
163 |
/// |
|
165 |
/// This class provides constant time counting for nodes and arcs. |
|
166 |
/// |
|
167 |
/// \note FullDigraph and FullGraph classes are very similar, |
|
164 | 168 |
/// but there are two differences. While this class conforms only |
165 |
/// to the \ref concepts::Digraph "Digraph" concept, the \c FullGraph |
|
166 |
/// class conforms to the \ref concepts::Graph "Graph" concept, |
|
167 |
/// moreover \c FullGraph does not contain a loop arc for each |
|
168 |
/// node as \c FullDigraph does. |
|
169 |
/// to the \ref concepts::Digraph "Digraph" concept, FullGraph |
|
170 |
/// conforms to the \ref concepts::Graph "Graph" concept, |
|
171 |
/// moreover FullGraph does not contain a loop for each |
|
172 |
/// node as this class does. |
|
169 | 173 |
/// |
... | ... |
@@ -175,3 +179,5 @@ |
175 | 179 |
|
176 |
/// \brief |
|
180 |
/// \brief Default constructor. |
|
181 |
/// |
|
182 |
/// Default constructor. The number of nodes and arcs will be zero. |
|
177 | 183 |
FullDigraph() { construct(0); } |
... | ... |
@@ -186,4 +192,4 @@ |
186 | 192 |
/// |
187 |
/// Resizes the digraph. The function will fully destroy and |
|
188 |
/// rebuild the digraph. This cause that the maps of the digraph will |
|
193 |
/// This function resizes the digraph. It fully destroys and |
|
194 |
/// rebuilds the structure, therefore the maps of the digraph will be |
|
189 | 195 |
/// reallocated automatically and the previous values will be lost. |
... | ... |
@@ -199,5 +205,6 @@ |
199 | 205 |
/// |
200 |
/// Returns the node with the given index. Since it is a static |
|
201 |
/// digraph its nodes can be indexed with integers from the range |
|
202 |
/// |
|
206 |
/// Returns the node with the given index. Since this structure is |
|
207 |
/// completely static, the nodes can be indexed with integers from |
|
208 |
/// the range <tt>[0..nodeNum()-1]</tt>. |
|
209 |
/// The index of a node is the same as its ID. |
|
203 | 210 |
/// \sa index() |
... | ... |
@@ -207,7 +214,8 @@ |
207 | 214 |
/// |
208 |
/// Returns the index of the given node. Since it is a static |
|
209 |
/// digraph its nodes can be indexed with integers from the range |
|
210 |
/// <tt>[0..nodeNum()-1]</tt>. |
|
211 |
/// \sa operator() |
|
212 |
|
|
215 |
/// Returns the index of the given node. Since this structure is |
|
216 |
/// completely static, the nodes can be indexed with integers from |
|
217 |
/// the range <tt>[0..nodeNum()-1]</tt>. |
|
218 |
/// The index of a node is the same as its ID. |
|
219 |
/// \sa operator()() |
|
220 |
static int index(const Node& node) { return Parent::index(node); } |
|
213 | 221 |
|
... | ... |
@@ -216,3 +224,3 @@ |
216 | 224 |
/// Returns the arc connecting the given nodes. |
217 |
Arc arc( |
|
225 |
Arc arc(Node u, Node v) const { |
|
218 | 226 |
return Parent::arc(u, v); |
... | ... |
@@ -285,3 +293,3 @@ |
285 | 293 |
Node operator()(int ix) const { return Node(ix); } |
286 |
int index(const Node& node) |
|
294 |
static int index(const Node& node) { return node._id; } |
|
287 | 295 |
|
... | ... |
@@ -522,17 +530,21 @@ |
522 | 530 |
/// |
523 |
/// This is a simple and fast undirected full graph |
|
524 |
/// implementation. From each node go edge to each other node, |
|
525 |
/// therefore the number of edges in the graph is \f$n(n-1)/2\f$. |
|
526 |
/// This graph type is completely static, so you can neither |
|
527 |
/// add nor delete either edges or nodes, and it needs constant |
|
528 |
/// space in memory. |
|
531 |
/// FullGraph is a simple and fast implmenetation of undirected full |
|
532 |
/// (complete) graphs. It contains an edge between every distinct pair |
|
533 |
/// of nodes, therefore the number of edges is <tt>n(n-1)/2</tt>. |
|
534 |
/// This class is completely static and it needs constant memory space. |
|
535 |
/// Thus you can neither add nor delete nodes or edges, however |
|
536 |
/// the structure can be resized using resize(). |
|
529 | 537 |
/// |
530 |
/// This |
|
538 |
/// This type fully conforms to the \ref concepts::Graph "Graph concept". |
|
539 |
/// Most of its member functions and nested classes are documented |
|
540 |
/// only in the concept class. |
|
531 | 541 |
/// |
532 |
/// The \c FullGraph and \c FullDigraph classes are very similar, |
|
533 |
/// but there are two differences. While the \c FullDigraph class |
|
542 |
/// This class provides constant time counting for nodes, edges and arcs. |
|
543 |
/// |
|
544 |
/// \note FullDigraph and FullGraph classes are very similar, |
|
545 |
/// but there are two differences. While FullDigraph |
|
534 | 546 |
/// conforms only to the \ref concepts::Digraph "Digraph" concept, |
535 | 547 |
/// this class conforms to the \ref concepts::Graph "Graph" concept, |
536 |
/// moreover \c FullGraph does not contain a loop arc for each |
|
537 |
/// node as \c FullDigraph does. |
|
548 |
/// moreover this class does not contain a loop for each |
|
549 |
/// node as FullDigraph does. |
|
538 | 550 |
/// |
... | ... |
@@ -544,3 +556,5 @@ |
544 | 556 |
|
545 |
/// \brief |
|
557 |
/// \brief Default constructor. |
|
558 |
/// |
|
559 |
/// Default constructor. The number of nodes and edges will be zero. |
|
546 | 560 |
FullGraph() { construct(0); } |
... | ... |
@@ -555,4 +569,4 @@ |
555 | 569 |
/// |
556 |
/// Resizes the graph. The function will fully destroy and |
|
557 |
/// rebuild the graph. This cause that the maps of the graph will |
|
570 |
/// This function resizes the graph. It fully destroys and |
|
571 |
/// rebuilds the structure, therefore the maps of the graph will be |
|
558 | 572 |
/// reallocated automatically and the previous values will be lost. |
... | ... |
@@ -570,5 +584,6 @@ |
570 | 584 |
/// |
571 |
/// Returns the node with the given index. Since it is a static |
|
572 |
/// graph its nodes can be indexed with integers from the range |
|
573 |
/// |
|
585 |
/// Returns the node with the given index. Since this structure is |
|
586 |
/// completely static, the nodes can be indexed with integers from |
|
587 |
/// the range <tt>[0..nodeNum()-1]</tt>. |
|
588 |
/// The index of a node is the same as its ID. |
|
574 | 589 |
/// \sa index() |
... | ... |
@@ -578,7 +593,8 @@ |
578 | 593 |
/// |
579 |
/// Returns the index of the given node. Since it is a static |
|
580 |
/// graph its nodes can be indexed with integers from the range |
|
581 |
/// <tt>[0..nodeNum()-1]</tt>. |
|
582 |
/// \sa operator() |
|
583 |
|
|
594 |
/// Returns the index of the given node. Since this structure is |
|
595 |
/// completely static, the nodes can be indexed with integers from |
|
596 |
/// the range <tt>[0..nodeNum()-1]</tt>. |
|
597 |
/// The index of a node is the same as its ID. |
|
598 |
/// \sa operator()() |
|
599 |
static int index(const Node& node) { return Parent::index(node); } |
|
584 | 600 |
|
... | ... |
@@ -587,3 +603,3 @@ |
587 | 603 |
/// Returns the arc connecting the given nodes. |
588 |
Arc arc( |
|
604 |
Arc arc(Node s, Node t) const { |
|
589 | 605 |
return Parent::arc(s, t); |
... | ... |
@@ -591,6 +607,6 @@ |
591 | 607 |
|
592 |
/// \brief Returns the edge |
|
608 |
/// \brief Returns the edge connecting the given nodes. |
|
593 | 609 |
/// |
594 |
/// Returns the edge connects the given nodes. |
|
595 |
Edge edge(const Node& u, const Node& v) const { |
|
610 |
/// Returns the edge connecting the given nodes. |
|
611 |
Edge edge(Node u, Node v) const { |
|
596 | 612 |
return Parent::edge(u, v); |
... | ... |
@@ -61,2 +61,38 @@ |
61 | 61 |
|
62 |
int GlpkBase::_addRow(Value lo, ExprIterator b, |
|
63 |
ExprIterator e, Value up) { |
|
64 |
int i = glp_add_rows(lp, 1); |
|
65 |
|
|
66 |
if (lo == -INF) { |
|
67 |
if (up == INF) { |
|
68 |
glp_set_row_bnds(lp, i, GLP_FR, lo, up); |
|
69 |
} else { |
|
70 |
glp_set_row_bnds(lp, i, GLP_UP, lo, up); |
|
71 |
} |
|
72 |
} else { |
|
73 |
if (up == INF) { |
|
74 |
glp_set_row_bnds(lp, i, GLP_LO, lo, up); |
|
75 |
} else if (lo != up) { |
|
76 |
glp_set_row_bnds(lp, i, GLP_DB, lo, up); |
|
77 |
} else { |
|
78 |
glp_set_row_bnds(lp, i, GLP_FX, lo, up); |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
std::vector<int> indexes; |
|
83 |
std::vector<Value> values; |
|
84 |
|
|
85 |
indexes.push_back(0); |
|
86 |
values.push_back(0); |
|
87 |
|
|
88 |
for(ExprIterator it = b; it != e; ++it) { |
|
89 |
indexes.push_back(it->first); |
|
90 |
values.push_back(it->second); |
|
91 |
} |
|
92 |
|
|
93 |
glp_set_mat_row(lp, i, values.size() - 1, |
|
94 |
&indexes.front(), &values.front()); |
|
95 |
return i; |
|
96 |
} |
|
97 |
|
|
62 | 98 |
void GlpkBase::_eraseCol(int i) { |
... | ... |
@@ -296,7 +296,5 @@ |
296 | 296 |
template <typename CutMap> |
297 |
Value minCutMap(const Node& s, |
|
297 |
Value minCutMap(const Node& s, |
|
298 | 298 |
const Node& t, |
299 |
///< |
|
300 | 299 |
CutMap& cutMap |
301 |
///< |
|
302 | 300 |
) const { |
... | ... |
@@ -361,6 +359,6 @@ |
361 | 359 |
/// \code |
362 |
/// |
|
360 |
/// GomoryHu<Graph> gom(g, capacities); |
|
363 | 361 |
/// gom.run(); |
364 | 362 |
/// int cnt=0; |
365 |
/// for( |
|
363 |
/// for(GomoryHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt; |
|
366 | 364 |
/// \endcode |
... | ... |
@@ -396,3 +394,3 @@ |
396 | 394 |
/// does not necessarily give the same set of nodes. |
397 |
/// However it is ensured that |
|
395 |
/// However, it is ensured that |
|
398 | 396 |
/// \code |
... | ... |
@@ -458,6 +456,6 @@ |
458 | 456 |
/// \code |
459 |
/// |
|
457 |
/// GomoryHu<Graph> gom(g, capacities); |
|
460 | 458 |
/// gom.run(); |
461 | 459 |
/// int value=0; |
462 |
/// for( |
|
460 |
/// for(GomoryHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e) |
|
463 | 461 |
/// value+=capacities[e]; |
... | ... |
@@ -144,3 +144,3 @@ |
144 | 144 |
///\param ost Reference to the output stream. |
145 |
///By default it is <tt>std::cout</tt>. |
|
145 |
///By default, it is <tt>std::cout</tt>. |
|
146 | 146 |
///\param pros If it is \c true, then the \c ostream referenced by \c os |
... | ... |
@@ -514,3 +514,3 @@ |
514 | 514 |
|
515 |
///By default graphToEps() rescales the whole image in order to avoid |
|
515 |
///By default, graphToEps() rescales the whole image in order to avoid |
|
516 | 516 |
///very big or very small bounding boxes. |
... | ... |
@@ -1116,3 +1116,3 @@ |
1116 | 1116 |
///\param os Reference to the output stream. |
1117 |
///By default it is <tt>std::cout</tt>. |
|
1117 |
///By default, it is <tt>std::cout</tt>. |
|
1118 | 1118 |
/// |
... | ... |
@@ -1128,3 +1128,3 @@ |
1128 | 1128 |
/// |
1129 |
///For more detailed examples see the \ref graph_to_eps_demo.cc demo file. |
|
1129 |
///For more detailed examples, see the \ref graph_to_eps_demo.cc demo file. |
|
1130 | 1130 |
/// |
... | ... |
@@ -472,10 +472,10 @@ |
472 | 472 |
/// |
473 |
/// This class implements a special graph type. The nodes of the |
|
474 |
/// graph can be indexed by two integer \c (i,j) value where \c i is |
|
475 |
/// in the \c [0..width()-1] range and j is in the \c |
|
476 |
/// [0..height()-1] range. Two nodes are connected in the graph if |
|
477 |
/// the indexes differ exactly on one position and exactly one is |
|
478 |
/// the difference. The nodes of the graph can be indexed by position |
|
479 |
/// with the \c operator()() function. The positions of the nodes can be |
|
480 |
/// get with \c pos(), \c col() and \c row() members. The outgoing |
|
473 |
/// GridGraph implements a special graph type. The nodes of the |
|
474 |
/// graph can be indexed by two integer values \c (i,j) where \c i is |
|
475 |
/// in the range <tt>[0..width()-1]</tt> and j is in the range |
|
476 |
/// <tt>[0..height()-1]</tt>. Two nodes are connected in the graph if |
|
477 |
/// the indices differ exactly on one position and the difference is |
|
478 |
/// also exactly one. The nodes of the graph can be obtained by position |
|
479 |
/// using the \c operator()() function and the indices of the nodes can |
|
480 |
/// be obtained using \c pos(), \c col() and \c row() members. The outgoing |
|
481 | 481 |
/// arcs can be retrieved with the \c right(), \c up(), \c left() |
... | ... |
@@ -484,2 +484,6 @@ |
484 | 484 |
/// |
485 |
/// This class is completely static and it needs constant memory space. |
|
486 |
/// Thus you can neither add nor delete nodes or edges, however |
|
487 |
/// the structure can be resized using resize(). |
|
488 |
/// |
|
485 | 489 |
/// \image html grid_graph.png |
... | ... |
@@ -498,4 +502,7 @@ |
498 | 502 |
/// |
499 |
/// This graph type fully conforms to the \ref concepts::Graph |
|
500 |
/// "Graph concept". |
|
503 |
/// This type fully conforms to the \ref concepts::Graph "Graph concept". |
|
504 |
/// Most of its member functions and nested classes are documented |
|
505 |
/// only in the concept class. |
|
506 |
/// |
|
507 |
/// This class provides constant time counting for nodes, edges and arcs. |
|
501 | 508 |
class GridGraph : public ExtendedGridGraphBase { |
... | ... |
@@ -505,5 +512,7 @@ |
505 | 512 |
|
506 |
/// \brief Map to get the indices of the nodes as dim2::Point |
|
513 |
/// \brief Map to get the indices of the nodes as \ref dim2::Point |
|
514 |
/// "dim2::Point<int>". |
|
507 | 515 |
/// |
508 |
/// Map to get the indices of the nodes as dim2::Point |
|
516 |
/// Map to get the indices of the nodes as \ref dim2::Point |
|
517 |
/// "dim2::Point<int>". |
|
509 | 518 |
class IndexMap { |
... | ... |
@@ -516,4 +525,2 @@ |
516 | 525 |
/// \brief Constructor |
517 |
/// |
|
518 |
/// Constructor |
|
519 | 526 |
IndexMap(const GridGraph& graph) : _graph(graph) {} |
... | ... |
@@ -521,4 +528,2 @@ |
521 | 528 |
/// \brief The subscript operator |
522 |
/// |
|
523 |
/// The subscript operator. |
|
524 | 529 |
Value operator[](Key key) const { |
... | ... |
@@ -542,4 +547,2 @@ |
542 | 547 |
/// \brief Constructor |
543 |
/// |
|
544 |
/// Constructor |
|
545 | 548 |
ColMap(const GridGraph& graph) : _graph(graph) {} |
... | ... |
@@ -547,4 +550,2 @@ |
547 | 550 |
/// \brief The subscript operator |
548 |
/// |
|
549 |
/// The subscript operator. |
|
550 | 551 |
Value operator[](Key key) const { |
... | ... |
@@ -568,4 +569,2 @@ |
568 | 569 |
/// \brief Constructor |
569 |
/// |
|
570 |
/// Constructor |
|
571 | 570 |
RowMap(const GridGraph& graph) : _graph(graph) {} |
... | ... |
@@ -573,4 +572,2 @@ |
573 | 572 |
/// \brief The subscript operator |
574 |
/// |
|
575 |
/// The subscript operator. |
|
576 | 573 |
Value operator[](Key key) const { |
... | ... |
@@ -585,11 +582,10 @@ |
585 | 582 |
/// |
586 |
/// Construct a grid graph with given size. |
|
583 |
/// Construct a grid graph with the given size. |
|
587 | 584 |
GridGraph(int width, int height) { construct(width, height); } |
588 | 585 |
|
589 |
/// \brief |
|
586 |
/// \brief Resizes the graph |
|
590 | 587 |
/// |
591 |
/// Resize the graph. The function will fully destroy and rebuild |
|
592 |
/// the graph. This cause that the maps of the graph will |
|
593 |
/// reallocated automatically and the previous values will be |
|
594 |
/// lost. |
|
588 |
/// This function resizes the graph. It fully destroys and |
|
589 |
/// rebuilds the structure, therefore the maps of the graph will be |
|
590 |
/// reallocated automatically and the previous values will be lost. |
|
595 | 591 |
void resize(int width, int height) { |
... | ... |
@@ -611,3 +607,3 @@ |
611 | 607 |
|
612 |
/// \brief |
|
608 |
/// \brief The column index of the node. |
|
613 | 609 |
/// |
... | ... |
@@ -618,3 +614,3 @@ |
618 | 614 |
|
619 |
/// \brief |
|
615 |
/// \brief The row index of the node. |
|
620 | 616 |
/// |
... | ... |
@@ -625,3 +621,3 @@ |
625 | 621 |
|
626 |
/// \brief |
|
622 |
/// \brief The position of the node. |
|
627 | 623 |
/// |
... | ... |
@@ -632,3 +628,3 @@ |
632 | 628 |
|
633 |
/// \brief |
|
629 |
/// \brief The number of the columns. |
|
634 | 630 |
/// |
... | ... |
@@ -639,3 +635,3 @@ |
639 | 635 |
|
640 |
/// \brief |
|
636 |
/// \brief The number of the rows. |
|
641 | 637 |
/// |
... | ... |
@@ -646,3 +642,3 @@ |
646 | 642 |
|
647 |
/// \brief |
|
643 |
/// \brief The arc goes right from the node. |
|
648 | 644 |
/// |
... | ... |
@@ -654,3 +650,3 @@ |
654 | 650 |
|
655 |
/// \brief |
|
651 |
/// \brief The arc goes left from the node. |
|
656 | 652 |
/// |
... | ... |
@@ -662,3 +658,3 @@ |
662 | 658 |
|
663 |
/// \brief |
|
659 |
/// \brief The arc goes up from the node. |
|
664 | 660 |
/// |
... | ... |
@@ -670,3 +666,3 @@ |
670 | 666 |
|
671 |
/// \brief |
|
667 |
/// \brief The arc goes down from the node. |
|
672 | 668 |
/// |
... | ... |
@@ -264,3 +264,3 @@ |
264 | 264 |
|
265 |
int index(Node node) |
|
265 |
static int index(Node node) { |
|
266 | 266 |
return node._id; |
... | ... |
@@ -284,6 +284,15 @@ |
284 | 284 |
/// |
285 |
/// This class implements a special graph type. The nodes of the graph |
|
286 |
/// are indiced with integers with at most \c dim binary digits. |
|
285 |
/// HypercubeGraph implements a special graph type. The nodes of the |
|
286 |
/// graph are indexed with integers having at most \c dim binary digits. |
|
287 | 287 |
/// Two nodes are connected in the graph if and only if their indices |
288 | 288 |
/// differ only on one position in the binary form. |
289 |
/// This class is completely static and it needs constant memory space. |
|
290 |
/// Thus you can neither add nor delete nodes or edges, however, |
|
291 |
/// the structure can be resized using resize(). |
|
292 |
/// |
|
293 |
/// This type fully conforms to the \ref concepts::Graph "Graph concept". |
|
294 |
/// Most of its member functions and nested classes are documented |
|
295 |
/// only in the concept class. |
|
296 |
/// |
|
297 |
/// This class provides constant time counting for nodes, edges and arcs. |
|
289 | 298 |
/// |
... | ... |
@@ -292,5 +301,2 @@ |
292 | 301 |
/// (assuming that the size of \c int is 32 bit). |
293 |
/// |
|
294 |
/// This graph type fully conforms to the \ref concepts::Graph |
|
295 |
/// "Graph concept". |
|
296 | 302 |
class HypercubeGraph : public ExtendedHypercubeGraphBase { |
... | ... |
@@ -305,2 +311,17 @@ |
305 | 311 |
|
312 |
/// \brief Resizes the graph |
|
313 |
/// |
|
314 |
/// This function resizes the graph. It fully destroys and |
|
315 |
/// rebuilds the structure, therefore the maps of the graph will be |
|
316 |
/// reallocated automatically and the previous values will be lost. |
|
317 |
void resize(int dim) { |
|
318 |
Parent::notifier(Arc()).clear(); |
|
319 |
Parent::notifier(Edge()).clear(); |
|
320 |
Parent::notifier(Node()).clear(); |
|
321 |
construct(dim); |
|
322 |
Parent::notifier(Node()).build(); |
|
323 |
Parent::notifier(Edge()).build(); |
|
324 |
Parent::notifier(Arc()).build(); |
|
325 |
} |
|
326 |
|
|
306 | 327 |
/// \brief The number of dimensions. |
... | ... |
@@ -322,3 +343,3 @@ |
322 | 343 |
/// Gives back the dimension id of the given edge. |
323 |
/// It is in the [0..dim-1] |
|
344 |
/// It is in the range <tt>[0..dim-1]</tt>. |
|
324 | 345 |
int dimension(Edge edge) const { |
... | ... |
@@ -330,3 +351,3 @@ |
330 | 351 |
/// Gives back the dimension id of the given arc. |
331 |
/// It is in the [0..dim-1] |
|
352 |
/// It is in the range <tt>[0..dim-1]</tt>. |
|
332 | 353 |
int dimension(Arc arc) const { |
... | ... |
@@ -339,3 +360,3 @@ |
339 | 360 |
/// The lower bits of the integer describes the node. |
340 |
int index(Node node) |
|
361 |
static int index(Node node) { |
|
341 | 362 |
return Parent::index(node); |
... | ... |
@@ -429,3 +429,3 @@ |
429 | 429 |
/// |
430 |
/// By default the reader uses the first section in the file of the |
|
430 |
/// By default, the reader uses the first section in the file of the |
|
431 | 431 |
/// proper type. If a section has an optional name, then it can be |
... | ... |
@@ -2223,3 +2223,3 @@ |
2223 | 2223 |
/// |
2224 |
/// For example let's see a section, which contain several |
|
2224 |
/// For example, let's see a section, which contain several |
|
2225 | 2225 |
/// integers, which should be inserted into a vector. |
... | ... |
@@ -23,3 +23,3 @@ |
23 | 23 |
///\file |
24 |
///\brief ListDigraph |
|
24 |
///\brief ListDigraph and ListGraph classes. |
|
25 | 25 |
|
... | ... |
@@ -34,2 +34,4 @@ |
34 | 34 |
|
35 |
class ListDigraph; |
|
36 |
|
|
35 | 37 |
class ListDigraphBase { |
... | ... |
@@ -64,2 +66,3 @@ |
64 | 66 |
friend class ListDigraphBase; |
67 |
friend class ListDigraph; |
|
65 | 68 |
protected: |
... | ... |
@@ -79,2 +82,3 @@ |
79 | 82 |
friend class ListDigraphBase; |
83 |
friend class ListDigraph; |
|
80 | 84 |
protected: |
... | ... |
@@ -118,5 +122,5 @@ |
118 | 122 |
for(n = first_node; |
119 |
n!=-1 && nodes[n]. |
|
123 |
n != -1 && nodes[n].first_out == -1; |
|
120 | 124 |
n = nodes[n].next) {} |
121 |
arc.id = (n == -1) ? -1 : nodes[n]. |
|
125 |
arc.id = (n == -1) ? -1 : nodes[n].first_out; |
|
122 | 126 |
} |
... | ... |
@@ -124,10 +128,10 @@ |
124 | 128 |
void next(Arc& arc) const { |
125 |
if (arcs[arc.id].next_in != -1) { |
|
126 |
arc.id = arcs[arc.id].next_in; |
|
129 |
if (arcs[arc.id].next_out != -1) { |
|
130 |
arc.id = arcs[arc.id].next_out; |
|
127 | 131 |
} else { |
128 | 132 |
int n; |
129 |
for(n = nodes[arcs[arc.id].target].next; |
|
130 |
n!=-1 && nodes[n].first_in == -1; |
|
133 |
for(n = nodes[arcs[arc.id].source].next; |
|
134 |
n != -1 && nodes[n].first_out == -1; |
|
131 | 135 |
n = nodes[n].next) {} |
132 |
arc.id = (n == -1) ? -1 : nodes[n]. |
|
136 |
arc.id = (n == -1) ? -1 : nodes[n].first_out; |
|
133 | 137 |
} |
... | ... |
@@ -313,13 +317,15 @@ |
313 | 317 |
|
314 |
///\ref ListDigraph is a simple and fast <em>directed graph</em> |
|
315 |
///implementation based on static linked lists that are stored in |
|
318 |
///\ref ListDigraph is a versatile and fast directed graph |
|
319 |
///implementation based on linked lists that are stored in |
|
316 | 320 |
///\c std::vector structures. |
317 | 321 |
/// |
318 |
///It conforms to the \ref concepts::Digraph "Digraph concept" and it |
|
319 |
///also provides several useful additional functionalities. |
|
320 |
/// |
|
322 |
///This type fully conforms to the \ref concepts::Digraph "Digraph concept" |
|
323 |
///and it also provides several useful additional functionalities. |
|
324 |
///Most of its member functions and nested classes are documented |
|
321 | 325 |
///only in the concept class. |
322 | 326 |
/// |
327 |
///This class provides only linear time counting for nodes and arcs. |
|
328 |
/// |
|
323 | 329 |
///\sa concepts::Digraph |
324 |
|
|
330 |
///\sa ListGraph |
|
325 | 331 |
class ListDigraph : public ExtendedListDigraphBase { |
... | ... |
@@ -328,12 +334,6 @@ |
328 | 334 |
private: |
329 |
///ListDigraph is \e not copy constructible. Use copyDigraph() instead. |
|
330 |
|
|
331 |
///ListDigraph is \e not copy constructible. Use copyDigraph() instead. |
|
332 |
/// |
|
335 |
/// Digraphs are \e not copy constructible. Use DigraphCopy instead. |
|
333 | 336 |
ListDigraph(const ListDigraph &) :ExtendedListDigraphBase() {}; |
334 |
///\brief Assignment of ListDigraph to another one is \e not allowed. |
|
335 |
///Use copyDigraph() instead. |
|
336 |
|
|
337 |
///Assignment of ListDigraph to another one is \e not allowed. |
|
338 |
/// |
|
337 |
/// \brief Assignment of a digraph to another one is \e not allowed. |
|
338 |
/// Use DigraphCopy instead. |
|
339 | 339 |
void operator=(const ListDigraph &) {} |
... | ... |
@@ -349,3 +349,3 @@ |
349 | 349 |
|
350 |
/// |
|
350 |
///This function adds a new node to the digraph. |
|
351 | 351 |
///\return The new node. |
... | ... |
@@ -355,6 +355,6 @@ |
355 | 355 |
|
356 |
/// |
|
356 |
///This function adds a new arc to the digraph with source node \c s |
|
357 | 357 |
///and target node \c t. |
358 | 358 |
///\return The new arc. |
359 |
Arc addArc( |
|
359 |
Arc addArc(Node s, Node t) { |
|
360 | 360 |
return Parent::addArc(s, t); |
... | ... |
@@ -364,5 +364,8 @@ |
364 | 364 |
/// |
365 |
/// |
|
365 |
///This function erases the given node along with its outgoing and |
|
366 |
///incoming arcs from the digraph. |
|
366 | 367 |
/// |
367 |
|
|
368 |
///\note All iterators referencing the removed node or the connected |
|
369 |
///arcs are invalidated, of course. |
|
370 |
void erase(Node n) { Parent::erase(n); } |
|
368 | 371 |
|
... | ... |
@@ -370,5 +373,7 @@ |
370 | 373 |
/// |
371 |
/// |
|
374 |
///This function erases the given arc from the digraph. |
|
372 | 375 |
/// |
373 |
|
|
376 |
///\note All iterators referencing the removed arc are invalidated, |
|
377 |
///of course. |
|
378 |
void erase(Arc a) { Parent::erase(a); } |
|
374 | 379 |
|
... | ... |
@@ -376,8 +381,7 @@ |
376 | 381 |
|
377 |
/// This function gives back true if the given node is valid, |
|
378 |
/// ie. it is a real node of the graph. |
|
382 |
/// This function gives back \c true if the given node is valid, |
|
383 |
/// i.e. it is a real node of the digraph. |
|
379 | 384 |
/// |
380 |
/// \warning A Node pointing to a removed item |
|
381 |
/// could become valid again later if new nodes are |
|
382 |
/// |
|
385 |
/// \warning A removed node could become valid again if new nodes are |
|
386 |
/// added to the digraph. |
|
383 | 387 |
bool valid(Node n) const { return Parent::valid(n); } |
... | ... |
@@ -386,17 +390,15 @@ |
386 | 390 |
|
387 |
/// This function gives back true if the given arc is valid, |
|
388 |
/// ie. it is a real arc of the graph. |
|
391 |
/// This function gives back \c true if the given arc is valid, |
|
392 |
/// i.e. it is a real arc of the digraph. |
|
389 | 393 |
/// |
390 |
/// \warning An Arc pointing to a removed item |
|
391 |
/// could become valid again later if new nodes are |
|
392 |
/// |
|
394 |
/// \warning A removed arc could become valid again if new arcs are |
|
395 |
/// added to the digraph. |
|
393 | 396 |
bool valid(Arc a) const { return Parent::valid(a); } |
394 | 397 |
|
395 |
/// Change the target of |
|
398 |
/// Change the target node of an arc |
|
396 | 399 |
|
397 |
/// |
|
400 |
/// This function changes the target node of the given arc \c a to \c n. |
|
398 | 401 |
/// |
399 |
///\note The <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s referencing |
|
400 |
///the changed arc remain valid. However <tt>InArcIt</tt>s are |
|
401 |
/// |
|
402 |
///\note \c ArcIt and \c OutArcIt iterators referencing the changed |
|
403 |
///arc remain valid, but \c InArcIt iterators are invalidated. |
|
402 | 404 |
/// |
... | ... |
@@ -407,9 +409,8 @@ |
407 | 409 |
} |
408 |
/// Change the source of |
|
410 |
/// Change the source node of an arc |
|
409 | 411 |
|
410 |
/// |
|
412 |
/// This function changes the source node of the given arc \c a to \c n. |
|
411 | 413 |
/// |
412 |
///\note The <tt>InArcIt</tt>s referencing the changed arc remain |
|
413 |
///valid. However the <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s are |
|
414 |
/// |
|
414 |
///\note \c InArcIt iterators referencing the changed arc remain |
|
415 |
///valid, but \c ArcIt and \c OutArcIt iterators are invalidated. |
|
415 | 416 |
/// |
... | ... |
@@ -421,7 +422,7 @@ |
421 | 422 |
|
422 |
/// |
|
423 |
/// Reverse the direction of an arc. |
|
423 | 424 |
|
424 |
///\note The <tt>ArcIt</tt>s referencing the changed arc remain |
|
425 |
///valid. However <tt>OutArcIt</tt>s and <tt>InArcIt</tt>s are |
|
426 |
/// |
|
425 |
/// This function reverses the direction of the given arc. |
|
426 |
///\note \c ArcIt, \c OutArcIt and \c InArcIt iterators referencing |
|
427 |
///the changed arc are invalidated. |
|
427 | 428 |
/// |
... | ... |
@@ -429,39 +430,22 @@ |
429 | 430 |
///feature. |
430 |
void reverseArc(Arc e) { |
|
431 |
Node t=target(e); |
|
432 |
changeTarget(e,source(e)); |
|
433 |
changeSource(e,t); |
|
431 |
void reverseArc(Arc a) { |
|
432 |
Node t=target(a); |
|
433 |
changeTarget(a,source(a)); |
|
434 |
changeSource(a,t); |
|
434 | 435 |
} |
435 | 436 |
|
436 |
/// Reserve memory for nodes. |
|
437 |
|
|
438 |
/// Using this function it is possible to avoid the superfluous memory |
|
439 |
/// allocation: if you know that the digraph you want to build will |
|
440 |
/// be very large (e.g. it will contain millions of nodes and/or arcs) |
|
441 |
/// then it is worth reserving space for this amount before starting |
|
442 |
/// to build the digraph. |
|
443 |
/// \sa reserveArc |
|
444 |
void reserveNode(int n) { nodes.reserve(n); }; |
|
445 |
|
|
446 |
/// Reserve memory for arcs. |
|
447 |
|
|
448 |
/// Using this function it is possible to avoid the superfluous memory |
|
449 |
/// allocation: if you know that the digraph you want to build will |
|
450 |
/// be very large (e.g. it will contain millions of nodes and/or arcs) |
|
451 |
/// then it is worth reserving space for this amount before starting |
|
452 |
/// to build the digraph. |
|
453 |
/// \sa reserveNode |
|
454 |
void reserveArc(int m) { arcs.reserve(m); }; |
|
455 |
|
|
456 | 437 |
///Contract two nodes. |
457 | 438 |
|
458 |
///This function contracts two nodes. |
|
459 |
///Node \p b will be removed but instead of deleting |
|
460 |
///incident arcs, they will be joined to \p a. |
|
461 |
///The last parameter \p r controls whether to remove loops. \c true |
|
462 |
/// |
|
439 |
///This function contracts the given two nodes. |
|
440 |
///Node \c v is removed, but instead of deleting its |
|
441 |
///incident arcs, they are joined to node \c u. |
|
442 |
///If the last parameter \c r is \c true (this is the default value), |
|
443 |
///then the newly created loops are removed. |
|
463 | 444 |
/// |
464 |
///\note The <tt>ArcIt</tt>s referencing a moved arc remain |
|
465 |
///valid. However <tt>InArcIt</tt>s and <tt>OutArcIt</tt>s |
|
466 |
/// |
|
445 |
///\note The moved arcs are joined to node \c u using changeSource() |
|
446 |
///or changeTarget(), thus \c ArcIt and \c OutArcIt iterators are |
|
447 |
///invalidated for the outgoing arcs of node \c v and \c InArcIt |
|
448 |
///iterators are invalidated for the incomming arcs of \c v. |
|
449 |
///Moreover all iterators referencing node \c v or the removed |
|
450 |
///loops are also invalidated. Other iterators remain valid. |
|
467 | 451 |
/// |
... | ... |
@@ -469,19 +453,19 @@ |
469 | 453 |
///feature. |
470 |
void contract(Node |
|
454 |
void contract(Node u, Node v, bool r = true) |
|
471 | 455 |
{ |
472 |
for(OutArcIt e(*this, |
|
456 |
for(OutArcIt e(*this,v);e!=INVALID;) { |
|
473 | 457 |
OutArcIt f=e; |
474 | 458 |
++f; |
475 |
if(r && target(e)==a) erase(e); |
|
476 |
else changeSource(e,a); |
|
459 |
if(r && target(e)==u) erase(e); |
|
460 |
else changeSource(e,u); |
|
477 | 461 |
e=f; |
478 | 462 |
} |
479 |
for(InArcIt e(*this, |
|
463 |
for(InArcIt e(*this,v);e!=INVALID;) { |
|
480 | 464 |
InArcIt f=e; |
481 | 465 |
++f; |
482 |
if(r && source(e)==a) erase(e); |
|
483 |
else changeTarget(e,a); |
|
466 |
if(r && source(e)==u) erase(e); |
|
467 |
else changeTarget(e,u); |
|
484 | 468 |
e=f; |
485 | 469 |
} |
486 |
erase( |
|
470 |
erase(v); |
|
487 | 471 |
} |
... | ... |
@@ -490,13 +474,13 @@ |
490 | 474 |
|
491 |
///This function splits a node. First a new node is added to the digraph, |
|
492 |
///then the source of each outgoing arc of \c n is moved to this new node. |
|
493 |
///If \c connect is \c true (this is the default value), then a new arc |
|
494 |
///from \c n to the newly created node is also added. |
|
475 |
///This function splits the given node. First, a new node is added |
|
476 |
///to the digraph, then the source of each outgoing arc of node \c n |
|
477 |
///is moved to this new node. |
|
478 |
///If the second parameter \c connect is \c true (this is the default |
|
479 |
///value), then a new arc from node \c n to the newly created node |
|
480 |
///is also added. |
|
495 | 481 |
///\return The newly created node. |
496 | 482 |
/// |
497 |
///\note The <tt>ArcIt</tt>s referencing a moved arc remain |
|
498 |
///valid. However <tt>InArcIt</tt>s and <tt>OutArcIt</tt>s may |
|
499 |
/// |
|
483 |
///\note All iterators remain valid. |
|
500 | 484 |
/// |
501 |
///\warning This functionality cannot be used |
|
485 |
///\warning This functionality cannot be used together with the |
|
502 | 486 |
///Snapshot feature. |
... | ... |
@@ -504,7 +488,6 @@ |
504 | 488 |
Node b = addNode(); |
505 |
for(OutArcIt e(*this,n);e!=INVALID;) { |
|
506 |
OutArcIt f=e; |
|
507 |
++f; |
|
508 |
changeSource(e,b); |
|
509 |
|
|
489 |
nodes[b.id].first_out=nodes[n.id].first_out; |
|
490 |
nodes[n.id].first_out=-1; |
|
491 |
for(int i=nodes[b.id].first_out; i!=-1; i=arcs[i].next_out) { |
|
492 |
arcs[i].source=b.id; |
|
510 | 493 |
} |
... | ... |
@@ -516,7 +499,10 @@ |
516 | 499 |
|
517 |
///This function splits an arc. First a new node \c b is added to |
|
518 |
///the digraph, then the original arc is re-targeted to \c |
|
519 |
/// |
|
500 |
///This function splits the given arc. First, a new node \c v is |
|
501 |
///added to the digraph, then the target node of the original arc |
|
502 |
///is set to \c v. Finally, an arc from \c v to the original target |
|
503 |
///is added. |
|
504 |
///\return The newly created node. |
|
520 | 505 |
/// |
521 |
///\ |
|
506 |
///\note \c InArcIt iterators referencing the original arc are |
|
507 |
///invalidated. Other iterators remain valid. |
|
522 | 508 |
/// |
... | ... |
@@ -524,9 +510,38 @@ |
524 | 510 |
///Snapshot feature. |
525 |
Node split(Arc e) { |
|
526 |
Node b = addNode(); |
|
527 |
addArc(b,target(e)); |
|
528 |
changeTarget(e,b); |
|
529 |
|
|
511 |
Node split(Arc a) { |
|
512 |
Node v = addNode(); |
|
513 |
addArc(v,target(a)); |
|
514 |
changeTarget(a,v); |
|
515 |
return v; |
|
530 | 516 |
} |
531 | 517 |
|
518 |
///Clear the digraph. |
|
519 |
|
|
520 |
///This function erases all nodes and arcs from the digraph. |
|
521 |
/// |
|
522 |
///\note All iterators of the digraph are invalidated, of course. |
|
523 |
void clear() { |
|
524 |
Parent::clear(); |
|
525 |
} |
|
526 |
|
|
527 |
/// Reserve memory for nodes. |
|
528 |
|
|
529 |
/// Using this function, it is possible to avoid superfluous memory |
|
530 |
/// allocation: if you know that the digraph you want to build will |
|
531 |
/// be large (e.g. it will contain millions of nodes and/or arcs), |
|
532 |
/// then it is worth reserving space for this amount before starting |
|
533 |
/// to build the digraph. |
|
534 |
/// \sa reserveArc() |
|
535 |
void reserveNode(int n) { nodes.reserve(n); }; |
|
536 |
|
|
537 |
/// Reserve memory for arcs. |
|
538 |
|
|
539 |
/// Using this function, it is possible to avoid superfluous memory |
|
540 |
/// allocation: if you know that the digraph you want to build will |
|
541 |
/// be large (e.g. it will contain millions of nodes and/or arcs), |
|
542 |
/// then it is worth reserving space for this amount before starting |
|
543 |
/// to build the digraph. |
|
544 |
/// \sa reserveNode() |
|
545 |
void reserveArc(int m) { arcs.reserve(m); }; |
|
546 |
|
|
532 | 547 |
/// \brief Class to make a snapshot of the digraph and restore |
... | ... |
@@ -539,5 +554,11 @@ |
539 | 554 |
/// |
540 |
/// \warning Arc and node deletions and other modifications (e.g. |
|
541 |
/// contracting, splitting, reversing arcs or nodes) cannot be |
|
555 |
/// \note After a state is restored, you cannot restore a later state, |
|
556 |
/// i.e. you cannot add the removed nodes and arcs again using |
|
557 |
/// another Snapshot instance. |
|
558 |
/// |
|
559 |
/// \warning Node and arc deletions and other modifications (e.g. |
|
560 |
/// reversing, contracting, splitting arcs or nodes) cannot be |
|
542 | 561 |
/// restored. These events invalidate the snapshot. |
562 |
/// However, the arcs and nodes that were added to the digraph after |
|
563 |
/// making the current snapshot can be removed without invalidating it. |
|
543 | 564 |
class Snapshot { |
... | ... |
@@ -711,3 +732,3 @@ |
711 | 732 |
/// Default constructor. |
712 |
/// |
|
733 |
/// You have to call save() to actually make a snapshot. |
|
713 | 734 |
Snapshot() |
... | ... |
@@ -718,8 +739,7 @@ |
718 | 739 |
/// |
719 |
/// This constructor immediately makes a snapshot of the digraph. |
|
720 |
/// \param _digraph The digraph we make a snapshot of. |
|
721 |
|
|
740 |
/// This constructor immediately makes a snapshot of the given digraph. |
|
741 |
Snapshot(ListDigraph &gr) |
|
722 | 742 |
: node_observer_proxy(*this), |
723 | 743 |
arc_observer_proxy(*this) { |
724 |
attach( |
|
744 |
attach(gr); |
|
725 | 745 |
} |
... | ... |
@@ -728,8 +748,6 @@ |
728 | 748 |
/// |
729 |
/// Make a snapshot of the digraph. |
|
730 |
/// |
|
731 |
/// This function |
|
749 |
/// This function makes a snapshot of the given digraph. |
|
750 |
/// It can be called more than once. In case of a repeated |
|
732 | 751 |
/// call, the previous snapshot gets lost. |
733 |
/// \param _digraph The digraph we make the snapshot of. |
|
734 |
void save(ListDigraph &_digraph) { |
|
752 |
void save(ListDigraph &gr) { |
|
735 | 753 |
if (attached()) { |
... | ... |
@@ -738,3 +756,3 @@ |
738 | 756 |
} |
739 |
attach( |
|
757 |
attach(gr); |
|
740 | 758 |
} |
... | ... |
@@ -742,4 +760,8 @@ |
742 | 760 |
/// \brief Undo the changes until the last snapshot. |
743 |
// |
|
744 |
/// Undo the changes until the last snapshot created by save(). |
|
761 |
/// |
|
762 |
/// This function undos the changes until the last snapshot |
|
763 |
/// created by save() or Snapshot(ListDigraph&). |
|
764 |
/// |
|
765 |
/// \warning This method invalidates the snapshot, i.e. repeated |
|
766 |
/// restoring is not supported unless you call save() again. |
|
745 | 767 |
void restore() { |
... | ... |
@@ -757,5 +779,5 @@ |
757 | 779 |
|
758 |
/// \brief |
|
780 |
/// \brief Returns \c true if the snapshot is valid. |
|
759 | 781 |
/// |
760 |
/// |
|
782 |
/// This function returns \c true if the snapshot is valid. |
|
761 | 783 |
bool valid() const { |
... | ... |
@@ -797,6 +819,2 @@ |
797 | 819 |
|
798 |
class Node; |
|
799 |
class Arc; |
|
800 |
class Edge; |
|
801 |
|
|
802 | 820 |
class Node { |
... | ... |
@@ -850,4 +868,2 @@ |
850 | 868 |
|
851 |
|
|
852 |
|
|
853 | 869 |
ListGraphBase() |
... | ... |
@@ -1166,13 +1182,15 @@ |
1166 | 1182 |
|
1167 |
///\ref ListGraph is a simple and fast <em>undirected graph</em> |
|
1168 |
///implementation based on static linked lists that are stored in |
|
1183 |
///\ref ListGraph is a versatile and fast undirected graph |
|
1184 |
///implementation based on linked lists that are stored in |
|
1169 | 1185 |
///\c std::vector structures. |
1170 | 1186 |
/// |
1171 |
///It conforms to the \ref concepts::Graph "Graph concept" and it |
|
1172 |
///also provides several useful additional functionalities. |
|
1173 |
/// |
|
1187 |
///This type fully conforms to the \ref concepts::Graph "Graph concept" |
|
1188 |
///and it also provides several useful additional functionalities. |
|
1189 |
///Most of its member functions and nested classes are documented |
|
1174 | 1190 |
///only in the concept class. |
1175 | 1191 |
/// |
1192 |
///This class provides only linear time counting for nodes, edges and arcs. |
|
1193 |
/// |
|
1176 | 1194 |
///\sa concepts::Graph |
1177 |
|
|
1195 |
///\sa ListDigraph |
|
1178 | 1196 |
class ListGraph : public ExtendedListGraphBase { |
... | ... |
@@ -1181,12 +1199,6 @@ |
1181 | 1199 |
private: |
1182 |
///ListGraph is \e not copy constructible. Use copyGraph() instead. |
|
1183 |
|
|
1184 |
///ListGraph is \e not copy constructible. Use copyGraph() instead. |
|
1185 |
/// |
|
1200 |
/// Graphs are \e not copy constructible. Use GraphCopy instead. |
|
1186 | 1201 |
ListGraph(const ListGraph &) :ExtendedListGraphBase() {}; |
1187 |
///\brief Assignment of ListGraph to another one is \e not allowed. |
|
1188 |
///Use copyGraph() instead. |
|
1189 |
|
|
1190 |
///Assignment of ListGraph to another one is \e not allowed. |
|
1191 |
/// |
|
1202 |
/// \brief Assignment of a graph to another one is \e not allowed. |
|
1203 |
/// Use GraphCopy instead. |
|
1192 | 1204 |
void operator=(const ListGraph &) {} |
... | ... |
@@ -1203,3 +1215,3 @@ |
1203 | 1215 |
/// |
1204 |
/// |
|
1216 |
/// This function adds a new node to the graph. |
|
1205 | 1217 |
/// \return The new node. |
... | ... |
@@ -1209,55 +1221,58 @@ |
1209 | 1221 |
/// |
1210 |
/// Add a new edge to the graph with source node \c s |
|
1211 |
/// and target node \c t. |
|
1222 |
/// This function adds a new edge to the graph between nodes |
|
1223 |
/// \c u and \c v with inherent orientation from node \c u to |
|
1224 |
/// node \c v. |
|
1212 | 1225 |
/// \return The new edge. |
1213 |
Edge addEdge(const Node& s, const Node& t) { |
|
1214 |
return Parent::addEdge(s, t); |
|
1226 |
Edge addEdge(Node u, Node v) { |
|
1227 |
return Parent::addEdge(u, v); |
|
1215 | 1228 |
} |
1216 | 1229 |
|
1217 |
/// |
|
1230 |
///\brief Erase a node from the graph. |
|
1218 | 1231 |
/// |
1219 |
/// |
|
1232 |
/// This function erases the given node along with its incident arcs |
|
1233 |
/// from the graph. |
|
1220 | 1234 |
/// |
1221 |
|
|
1235 |
/// \note All iterators referencing the removed node or the incident |
|
1236 |
/// edges are invalidated, of course. |
|
1237 |
void erase(Node n) { Parent::erase(n); } |
|
1222 | 1238 |
|
1223 |
/// |
|
1239 |
///\brief Erase an edge from the graph. |
|
1224 | 1240 |
/// |
1225 |
/// |
|
1241 |
/// This function erases the given edge from the graph. |
|
1226 | 1242 |
/// |
1227 |
|
|
1243 |
/// \note All iterators referencing the removed edge are invalidated, |
|
1244 |
/// of course. |
|
1245 |
void erase(Edge e) { Parent::erase(e); } |
|
1228 | 1246 |
/// Node validity check |
1229 | 1247 |
|
1230 |
/// This function gives back true if the given node is valid, |
|
1231 |
/// ie. it is a real node of the graph. |
|
1248 |
/// This function gives back \c true if the given node is valid, |
|
1249 |
/// i.e. it is a real node of the graph. |
|
1232 | 1250 |
/// |
1233 |
/// \warning A Node pointing to a removed item |
|
1234 |
/// could become valid again later if new nodes are |
|
1251 |
/// \warning A removed node could become valid again if new nodes are |
|
1235 | 1252 |
/// added to the graph. |
1236 | 1253 |
bool valid(Node n) const { return Parent::valid(n); } |
1254 |
/// Edge validity check |
|
1255 |
|
|
1256 |
/// This function gives back \c true if the given edge is valid, |
|
1257 |
/// i.e. it is a real edge of the graph. |
|
1258 |
/// |
|
1259 |
/// \warning A removed edge could become valid again if new edges are |
|
1260 |
/// added to the graph. |
|
1261 |
bool valid(Edge e) const { return Parent::valid(e); } |
|
1237 | 1262 |
/// Arc validity check |
1238 | 1263 |
|
1239 |
/// This function gives back true if the given arc is valid, |
|
1240 |
/// ie. it is a real arc of the graph. |
|
1264 |
/// This function gives back \c true if the given arc is valid, |
|
1265 |
/// i.e. it is a real arc of the graph. |
|
1241 | 1266 |
/// |
1242 |
/// \warning An Arc pointing to a removed item |
|
1243 |
/// could become valid again later if new edges are |
|
1267 |
/// \warning A removed arc could become valid again if new edges are |
|
1244 | 1268 |
/// added to the graph. |
1245 | 1269 |
bool valid(Arc a) const { return Parent::valid(a); } |
1246 |
/// Edge validity check |
|
1247 | 1270 |
|
1248 |
/// This function gives back true if the given edge is valid, |
|
1249 |
/// ie. it is a real arc of the graph. |
|
1271 |
/// \brief Change the first node of an edge. |
|
1250 | 1272 |
/// |
1251 |
/// \warning A Edge pointing to a removed item |
|
1252 |
/// could become valid again later if new edges are |
|
1253 |
/// added to the graph. |
|
1254 |
bool valid(Edge e) const { return Parent::valid(e); } |
|
1255 |
/// |
|
1273 |
/// This function changes the first node of the given edge \c e to \c n. |
|
1256 | 1274 |
/// |
1257 |
/// This function changes the end \c u of \c e to node \c n. |
|
1258 |
/// |
|
1259 |
///\note The <tt>EdgeIt</tt>s and <tt>ArcIt</tt>s referencing the |
|
1260 |
///changed edge are invalidated and if the changed node is the |
|
1261 |
///base node of an iterator then this iterator is also |
|
1262 |
///invalidated. |
|
1275 |
///\note \c EdgeIt and \c ArcIt iterators referencing the |
|
1276 |
///changed edge are invalidated and all other iterators whose |
|
1277 |
///base node is the changed node are also invalidated. |
|
1263 | 1278 |
/// |
... | ... |
@@ -1268,9 +1283,10 @@ |
1268 | 1283 |
} |
1269 |
/// \brief Change the |
|
1284 |
/// \brief Change the second node of an edge. |
|
1270 | 1285 |
/// |
1271 |
/// This function changes the |
|
1286 |
/// This function changes the second node of the given edge \c e to \c n. |
|
1272 | 1287 |
/// |
1273 |
///\note The <tt>EdgeIt</tt>s referencing the changed edge remain |
|
1274 |
///valid, however <tt>ArcIt</tt>s and if the changed node is the |
|
1275 |
/// |
|
1288 |
///\note \c EdgeIt iterators referencing the changed edge remain |
|
1289 |
///valid, but \c ArcIt iterators referencing the changed edge and |
|
1290 |
///all other iterators whose base node is the changed node are also |
|
1291 |
///invalidated. |
|
1276 | 1292 |
/// |
... | ... |
@@ -1281,12 +1297,16 @@ |
1281 | 1297 |
} |
1298 |
|
|
1282 | 1299 |
/// \brief Contract two nodes. |
1283 | 1300 |
/// |
1284 |
/// This function contracts two nodes. |
|
1285 |
/// Node \p b will be removed but instead of deleting |
|
1286 |
/// its neighboring arcs, they will be joined to \p a. |
|
1287 |
/// The last parameter \p r controls whether to remove loops. \c true |
|
1288 |
/// |
|
1301 |
/// This function contracts the given two nodes. |
|
1302 |
/// Node \c b is removed, but instead of deleting |
|
1303 |
/// its incident edges, they are joined to node \c a. |
|
1304 |
/// If the last parameter \c r is \c true (this is the default value), |
|
1305 |
/// then the newly created loops are removed. |
|
1289 | 1306 |
/// |
1290 |
/// \note The <tt>ArcIt</tt>s referencing a moved arc remain |
|
1291 |
/// valid. |
|
1307 |
/// \note The moved edges are joined to node \c a using changeU() |
|
1308 |
/// or changeV(), thus all edge and arc iterators whose base node is |
|
1309 |
/// \c b are invalidated. |
|
1310 |
/// Moreover all iterators referencing node \c b or the removed |
|
1311 |
/// loops are also invalidated. Other iterators remain valid. |
|
1292 | 1312 |
/// |
... | ... |
@@ -1309,2 +1329,30 @@ |
1309 | 1329 |
|
1330 |
///Clear the graph. |
|
1331 |
|
|
1332 |
///This function erases all nodes and arcs from the graph. |
|
1333 |
/// |
|
1334 |
///\note All iterators of the graph are invalidated, of course. |
|
1335 |
void clear() { |
|
1336 |
Parent::clear(); |
|
1337 |
} |
|
1338 |
|
|
1339 |
/// Reserve memory for nodes. |
|
1340 |
|
|
1341 |
/// Using this function, it is possible to avoid superfluous memory |
|
1342 |
/// allocation: if you know that the graph you want to build will |
|
1343 |
/// be large (e.g. it will contain millions of nodes and/or edges), |
|
1344 |
/// then it is worth reserving space for this amount before starting |
|
1345 |
/// to build the graph. |
|
1346 |
/// \sa reserveEdge() |
|
1347 |
void reserveNode(int n) { nodes.reserve(n); }; |
|
1348 |
|
|
1349 |
/// Reserve memory for edges. |
|
1350 |
|
|
1351 |
/// Using this function, it is possible to avoid superfluous memory |
|
1352 |
/// allocation: if you know that the graph you want to build will |
|
1353 |
/// be large (e.g. it will contain millions of nodes and/or edges), |
|
1354 |
/// then it is worth reserving space for this amount before starting |
|
1355 |
/// to build the graph. |
|
1356 |
/// \sa reserveNode() |
|
1357 |
void reserveEdge(int m) { arcs.reserve(2 * m); }; |
|
1310 | 1358 |
|
... | ... |
@@ -1318,5 +1366,11 @@ |
1318 | 1366 |
/// |
1319 |
/// \warning Edge and node deletions and other modifications |
|
1320 |
/// (e.g. changing nodes of edges, contracting nodes) cannot be |
|
1321 |
/// restored |
|
1367 |
/// \note After a state is restored, you cannot restore a later state, |
|
1368 |
/// i.e. you cannot add the removed nodes and edges again using |
|
1369 |
/// another Snapshot instance. |
|
1370 |
/// |
|
1371 |
/// \warning Node and edge deletions and other modifications |
|
1372 |
/// (e.g. changing the end-nodes of edges or contracting nodes) |
|
1373 |
/// cannot be restored. These events invalidate the snapshot. |
|
1374 |
/// However, the edges and nodes that were added to the graph after |
|
1375 |
/// making the current snapshot can be removed without invalidating it. |
|
1322 | 1376 |
class Snapshot { |
... | ... |
@@ -1490,3 +1544,3 @@ |
1490 | 1544 |
/// Default constructor. |
1491 |
/// |
|
1545 |
/// You have to call save() to actually make a snapshot. |
|
1492 | 1546 |
Snapshot() |
... | ... |
@@ -1497,8 +1551,7 @@ |
1497 | 1551 |
/// |
1498 |
/// This constructor immediately makes a snapshot of the graph. |
|
1499 |
/// \param _graph The graph we make a snapshot of. |
|
1500 |
|
|
1552 |
/// This constructor immediately makes a snapshot of the given graph. |
|
1553 |
Snapshot(ListGraph &gr) |
|
1501 | 1554 |
: node_observer_proxy(*this), |
1502 | 1555 |
edge_observer_proxy(*this) { |
1503 |
attach( |
|
1556 |
attach(gr); |
|
1504 | 1557 |
} |
... | ... |
@@ -1507,8 +1560,6 @@ |
1507 | 1560 |
/// |
1508 |
/// Make a snapshot of the graph. |
|
1509 |
/// |
|
1510 |
/// This function |
|
1561 |
/// This function makes a snapshot of the given graph. |
|
1562 |
/// It can be called more than once. In case of a repeated |
|
1511 | 1563 |
/// call, the previous snapshot gets lost. |
1512 |
/// \param _graph The graph we make the snapshot of. |
|
1513 |
void save(ListGraph &_graph) { |
|
1564 |
void save(ListGraph &gr) { |
|
1514 | 1565 |
if (attached()) { |
... | ... |
@@ -1517,3 +1568,3 @@ |
1517 | 1568 |
} |
1518 |
attach( |
|
1569 |
attach(gr); |
|
1519 | 1570 |
} |
... | ... |
@@ -1521,4 +1572,8 @@ |
1521 | 1572 |
/// \brief Undo the changes until the last snapshot. |
1522 |
// |
|
1523 |
/// Undo the changes until the last snapshot created by save(). |
|
1573 |
/// |
|
1574 |
/// This function undos the changes until the last snapshot |
|
1575 |
/// created by save() or Snapshot(ListGraph&). |
|
1576 |
/// |
|
1577 |
/// \warning This method invalidates the snapshot, i.e. repeated |
|
1578 |
/// restoring is not supported unless you call save() again. |
|
1524 | 1579 |
void restore() { |
... | ... |
@@ -1536,5 +1591,5 @@ |
1536 | 1591 |
|
1537 |
/// \brief |
|
1592 |
/// \brief Returns \c true if the snapshot is valid. |
|
1538 | 1593 |
/// |
1539 |
/// |
|
1594 |
/// This function returns \c true if the snapshot is valid. |
|
1540 | 1595 |
bool valid() const { |
... | ... |
@@ -148,3 +148,3 @@ |
148 | 148 |
|
149 |
/// Its usage is quite simple, for example you can count the number |
|
149 |
/// Its usage is quite simple, for example, you can count the number |
|
150 | 150 |
/// of columns in an LP \c lp: |
... | ... |
@@ -243,3 +243,3 @@ |
243 | 243 |
|
244 |
/// Its usage is quite simple, for example you can count the number |
|
244 |
/// Its usage is quite simple, for example, you can count the number |
|
245 | 245 |
/// of rows in an LP \c lp: |
... | ... |
@@ -945,2 +945,10 @@ |
945 | 945 |
|
946 |
virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u) { |
|
947 |
int row = _addRow(); |
|
948 |
_setRowCoeffs(row, b, e); |
|
949 |
_setRowLowerBound(row, l); |
|
950 |
_setRowUpperBound(row, u); |
|
951 |
return row; |
|
952 |
} |
|
953 |
|
|
946 | 954 |
virtual void _eraseCol(int col) = 0; |
... | ... |
@@ -1209,4 +1217,6 @@ |
1209 | 1217 |
Row addRow(Value l,const Expr &e, Value u) { |
1210 |
Row r=addRow(); |
|
1211 |
row(r,l,e,u); |
|
1218 |
Row r; |
|
1219 |
e.simplify(); |
|
1220 |
r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), cols), |
|
1221 |
ExprIterator(e.comps.end(), cols), u - *e)); |
|
1212 | 1222 |
return r; |
... | ... |
@@ -1219,4 +1229,8 @@ |
1219 | 1229 |
Row addRow(const Constr &c) { |
1220 |
Row r=addRow(); |
|
1221 |
row(r,c); |
|
1230 |
Row r; |
|
1231 |
c.expr().simplify(); |
|
1232 |
r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound():-INF, |
|
1233 |
ExprIterator(c.expr().comps.begin(), cols), |
|
1234 |
ExprIterator(c.expr().comps.end(), cols), |
|
1235 |
c.upperBounded()?c.upperBound():INF)); |
|
1222 | 1236 |
return r; |
Changeset was too big and was cut off... Show full diff
0 comments (0 inline)