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
439
84
57
47
15
7
175
169
428
4
| 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 |
| 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_STATIC_GRAPH_H |
|
| 20 |
#define LEMON_STATIC_GRAPH_H |
|
| 21 |
|
|
| 22 |
///\ingroup graphs |
|
| 23 |
///\file |
|
| 24 |
///\brief StaticDigraph class. |
|
| 25 |
|
|
| 26 |
#include <lemon/core.h> |
|
| 27 |
#include <lemon/bits/graph_extender.h> |
|
| 28 |
|
|
| 29 |
namespace lemon {
|
|
| 30 |
|
|
| 31 |
class StaticDigraphBase {
|
|
| 32 |
public: |
|
| 33 |
|
|
| 34 |
StaticDigraphBase() |
|
| 35 |
: built(false), node_num(0), arc_num(0), |
|
| 36 |
node_first_out(NULL), node_first_in(NULL), |
|
| 37 |
arc_source(NULL), arc_target(NULL), |
|
| 38 |
arc_next_in(NULL), arc_next_out(NULL) {}
|
|
| 39 |
|
|
| 40 |
~StaticDigraphBase() {
|
|
| 41 |
if (built) {
|
|
| 42 |
delete[] node_first_out; |
|
| 43 |
delete[] node_first_in; |
|
| 44 |
delete[] arc_source; |
|
| 45 |
delete[] arc_target; |
|
| 46 |
delete[] arc_next_out; |
|
| 47 |
delete[] arc_next_in; |
|
| 48 |
} |
|
| 49 |
} |
|
| 50 |
|
|
| 51 |
class Node {
|
|
| 52 |
friend class StaticDigraphBase; |
|
| 53 |
protected: |
|
| 54 |
int id; |
|
| 55 |
Node(int _id) : id(_id) {}
|
|
| 56 |
public: |
|
| 57 |
Node() {}
|
|
| 58 |
Node (Invalid) : id(-1) {}
|
|
| 59 |
bool operator==(const Node& node) const { return id == node.id; }
|
|
| 60 |
bool operator!=(const Node& node) const { return id != node.id; }
|
|
| 61 |
bool operator<(const Node& node) const { return id < node.id; }
|
|
| 62 |
}; |
|
| 63 |
|
|
| 64 |
class Arc {
|
|
| 65 |
friend class StaticDigraphBase; |
|
| 66 |
protected: |
|
| 67 |
int id; |
|
| 68 |
Arc(int _id) : id(_id) {}
|
|
| 69 |
public: |
|
| 70 |
Arc() { }
|
|
| 71 |
Arc (Invalid) : id(-1) {}
|
|
| 72 |
bool operator==(const Arc& arc) const { return id == arc.id; }
|
|
| 73 |
bool operator!=(const Arc& arc) const { return id != arc.id; }
|
|
| 74 |
bool operator<(const Arc& arc) const { return id < arc.id; }
|
|
| 75 |
}; |
|
| 76 |
|
|
| 77 |
Node source(const Arc& e) const { return Node(arc_source[e.id]); }
|
|
| 78 |
Node target(const Arc& e) const { return Node(arc_target[e.id]); }
|
|
| 79 |
|
|
| 80 |
void first(Node& n) const { n.id = node_num - 1; }
|
|
| 81 |
static void next(Node& n) { --n.id; }
|
|
| 82 |
|
|
| 83 |
void first(Arc& e) const { e.id = arc_num - 1; }
|
|
| 84 |
static void next(Arc& e) { --e.id; }
|
|
| 85 |
|
|
| 86 |
void firstOut(Arc& e, const Node& n) const {
|
|
| 87 |
e.id = node_first_out[n.id] != node_first_out[n.id + 1] ? |
|
| 88 |
node_first_out[n.id] : -1; |
|
| 89 |
} |
|
| 90 |
void nextOut(Arc& e) const { e.id = arc_next_out[e.id]; }
|
|
| 91 |
|
|
| 92 |
void firstIn(Arc& e, const Node& n) const { e.id = node_first_in[n.id]; }
|
|
| 93 |
void nextIn(Arc& e) const { e.id = arc_next_in[e.id]; }
|
|
| 94 |
|
|
| 95 |
static int id(const Node& n) { return n.id; }
|
|
| 96 |
static Node nodeFromId(int id) { return Node(id); }
|
|
| 97 |
int maxNodeId() const { return node_num - 1; }
|
|
| 98 |
|
|
| 99 |
static int id(const Arc& e) { return e.id; }
|
|
| 100 |
static Arc arcFromId(int id) { return Arc(id); }
|
|
| 101 |
int maxArcId() const { return arc_num - 1; }
|
|
| 102 |
|
|
| 103 |
typedef True NodeNumTag; |
|
| 104 |
typedef True ArcNumTag; |
|
| 105 |
|
|
| 106 |
int nodeNum() const { return node_num; }
|
|
| 107 |
int arcNum() const { return arc_num; }
|
|
| 108 |
|
|
| 109 |
private: |
|
| 110 |
|
|
| 111 |
template <typename Digraph, typename NodeRefMap> |
|
| 112 |
class ArcLess {
|
|
| 113 |
public: |
|
| 114 |
typedef typename Digraph::Arc Arc; |
|
| 115 |
|
|
| 116 |
ArcLess(const Digraph &_graph, const NodeRefMap& _nodeRef) |
|
| 117 |
: digraph(_graph), nodeRef(_nodeRef) {}
|
|
| 118 |
|
|
| 119 |
bool operator()(const Arc& left, const Arc& right) const {
|
|
| 120 |
return nodeRef[digraph.target(left)] < nodeRef[digraph.target(right)]; |
|
| 121 |
} |
|
| 122 |
private: |
|
| 123 |
const Digraph& digraph; |
|
| 124 |
const NodeRefMap& nodeRef; |
|
| 125 |
}; |
|
| 126 |
|
|
| 127 |
public: |
|
| 128 |
|
|
| 129 |
typedef True BuildTag; |
|
| 130 |
|
|
| 131 |
void clear() {
|
|
| 132 |
if (built) {
|
|
| 133 |
delete[] node_first_out; |
|
| 134 |
delete[] node_first_in; |
|
| 135 |
delete[] arc_source; |
|
| 136 |
delete[] arc_target; |
|
| 137 |
delete[] arc_next_out; |
|
| 138 |
delete[] arc_next_in; |
|
| 139 |
} |
|
| 140 |
built = false; |
|
| 141 |
node_num = 0; |
|
| 142 |
arc_num = 0; |
|
| 143 |
} |
|
| 144 |
|
|
| 145 |
template <typename Digraph, typename NodeRefMap, typename ArcRefMap> |
|
| 146 |
void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) {
|
|
| 147 |
typedef typename Digraph::Node GNode; |
|
| 148 |
typedef typename Digraph::Arc GArc; |
|
| 149 |
|
|
| 150 |
built = true; |
|
| 151 |
|
|
| 152 |
node_num = countNodes(digraph); |
|
| 153 |
arc_num = countArcs(digraph); |
|
| 154 |
|
|
| 155 |
node_first_out = new int[node_num + 1]; |
|
| 156 |
node_first_in = new int[node_num]; |
|
| 157 |
|
|
| 158 |
arc_source = new int[arc_num]; |
|
| 159 |
arc_target = new int[arc_num]; |
|
| 160 |
arc_next_out = new int[arc_num]; |
|
| 161 |
arc_next_in = new int[arc_num]; |
|
| 162 |
|
|
| 163 |
int node_index = 0; |
|
| 164 |
for (typename Digraph::NodeIt n(digraph); n != INVALID; ++n) {
|
|
| 165 |
nodeRef[n] = Node(node_index); |
|
| 166 |
node_first_in[node_index] = -1; |
|
| 167 |
++node_index; |
|
| 168 |
} |
|
| 169 |
|
|
| 170 |
ArcLess<Digraph, NodeRefMap> arcLess(digraph, nodeRef); |
|
| 171 |
|
|
| 172 |
int arc_index = 0; |
|
| 173 |
for (typename Digraph::NodeIt n(digraph); n != INVALID; ++n) {
|
|
| 174 |
int source = nodeRef[n].id; |
|
| 175 |
std::vector<GArc> arcs; |
|
| 176 |
for (typename Digraph::OutArcIt e(digraph, n); e != INVALID; ++e) {
|
|
| 177 |
arcs.push_back(e); |
|
| 178 |
} |
|
| 179 |
if (!arcs.empty()) {
|
|
| 180 |
node_first_out[source] = arc_index; |
|
| 181 |
std::sort(arcs.begin(), arcs.end(), arcLess); |
|
| 182 |
for (typename std::vector<GArc>::iterator it = arcs.begin(); |
|
| 183 |
it != arcs.end(); ++it) {
|
|
| 184 |
int target = nodeRef[digraph.target(*it)].id; |
|
| 185 |
arcRef[*it] = Arc(arc_index); |
|
| 186 |
arc_source[arc_index] = source; |
|
| 187 |
arc_target[arc_index] = target; |
|
| 188 |
arc_next_in[arc_index] = node_first_in[target]; |
|
| 189 |
node_first_in[target] = arc_index; |
|
| 190 |
arc_next_out[arc_index] = arc_index + 1; |
|
| 191 |
++arc_index; |
|
| 192 |
} |
|
| 193 |
arc_next_out[arc_index - 1] = -1; |
|
| 194 |
} else {
|
|
| 195 |
node_first_out[source] = arc_index; |
|
| 196 |
} |
|
| 197 |
} |
|
| 198 |
node_first_out[node_num] = arc_num; |
|
| 199 |
} |
|
| 200 |
|
|
| 201 |
template <typename ArcListIterator> |
|
| 202 |
void build(int n, ArcListIterator first, ArcListIterator last) {
|
|
| 203 |
built = true; |
|
| 204 |
|
|
| 205 |
node_num = n; |
|
| 206 |
arc_num = std::distance(first, last); |
|
| 207 |
|
|
| 208 |
node_first_out = new int[node_num + 1]; |
|
| 209 |
node_first_in = new int[node_num]; |
|
| 210 |
|
|
| 211 |
arc_source = new int[arc_num]; |
|
| 212 |
arc_target = new int[arc_num]; |
|
| 213 |
arc_next_out = new int[arc_num]; |
|
| 214 |
arc_next_in = new int[arc_num]; |
|
| 215 |
|
|
| 216 |
for (int i = 0; i != node_num; ++i) {
|
|
| 217 |
node_first_in[i] = -1; |
|
| 218 |
} |
|
| 219 |
|
|
| 220 |
int arc_index = 0; |
|
| 221 |
for (int i = 0; i != node_num; ++i) {
|
|
| 222 |
node_first_out[i] = arc_index; |
|
| 223 |
for ( ; first != last && (*first).first == i; ++first) {
|
|
| 224 |
int j = (*first).second; |
|
| 225 |
LEMON_ASSERT(j >= 0 && j < node_num, |
|
| 226 |
"Wrong arc list for StaticDigraph::build()"); |
|
| 227 |
arc_source[arc_index] = i; |
|
| 228 |
arc_target[arc_index] = j; |
|
| 229 |
arc_next_in[arc_index] = node_first_in[j]; |
|
| 230 |
node_first_in[j] = arc_index; |
|
| 231 |
arc_next_out[arc_index] = arc_index + 1; |
|
| 232 |
++arc_index; |
|
| 233 |
} |
|
| 234 |
if (arc_index > node_first_out[i]) |
|
| 235 |
arc_next_out[arc_index - 1] = -1; |
|
| 236 |
} |
|
| 237 |
LEMON_ASSERT(first == last, |
|
| 238 |
"Wrong arc list for StaticDigraph::build()"); |
|
| 239 |
node_first_out[node_num] = arc_num; |
|
| 240 |
} |
|
| 241 |
|
|
| 242 |
protected: |
|
| 243 |
|
|
| 244 |
void fastFirstOut(Arc& e, const Node& n) const {
|
|
| 245 |
e.id = node_first_out[n.id]; |
|
| 246 |
} |
|
| 247 |
|
|
| 248 |
static void fastNextOut(Arc& e) {
|
|
| 249 |
++e.id; |
|
| 250 |
} |
|
| 251 |
void fastLastOut(Arc& e, const Node& n) const {
|
|
| 252 |
e.id = node_first_out[n.id + 1]; |
|
| 253 |
} |
|
| 254 |
|
|
| 255 |
protected: |
|
| 256 |
bool built; |
|
| 257 |
int node_num; |
|
| 258 |
int arc_num; |
|
| 259 |
int *node_first_out; |
|
| 260 |
int *node_first_in; |
|
| 261 |
int *arc_source; |
|
| 262 |
int *arc_target; |
|
| 263 |
int *arc_next_in; |
|
| 264 |
int *arc_next_out; |
|
| 265 |
}; |
|
| 266 |
|
|
| 267 |
typedef DigraphExtender<StaticDigraphBase> ExtendedStaticDigraphBase; |
|
| 268 |
|
|
| 269 |
|
|
| 270 |
/// \ingroup graphs |
|
| 271 |
/// |
|
| 272 |
/// \brief A static directed graph class. |
|
| 273 |
/// |
|
| 274 |
/// \ref StaticDigraph is a highly efficient digraph implementation, |
|
| 275 |
/// but it is fully static. |
|
| 276 |
/// It stores only two \c int values for each node and only four \c int |
|
| 277 |
/// values for each arc. Moreover it provides faster item iteration than |
|
| 278 |
/// \ref ListDigraph and \ref SmartDigraph, especially using \c OutArcIt |
|
| 279 |
/// iterators, since its arcs are stored in an appropriate order. |
|
| 280 |
/// However it only provides build() and clear() functions and does not |
|
| 281 |
/// support any other modification of the digraph. |
|
| 282 |
/// |
|
| 283 |
/// Since this digraph structure is completely static, its nodes and arcs |
|
| 284 |
/// can be indexed with integers from the ranges <tt>[0..nodeNum()-1]</tt> |
|
| 285 |
/// and <tt>[0..arcNum()-1]</tt>, respectively. |
|
| 286 |
/// The index of an item is the same as its ID, it can be obtained |
|
| 287 |
/// using the corresponding \ref index() or \ref concepts::Digraph::id() |
|
| 288 |
/// "id()" function. A node or arc with a certain index can be obtained |
|
| 289 |
/// using node() or arc(). |
|
| 290 |
/// |
|
| 291 |
/// This type fully conforms to the \ref concepts::Digraph "Digraph concept". |
|
| 292 |
/// Most of its member functions and nested classes are documented |
|
| 293 |
/// only in the concept class. |
|
| 294 |
/// |
|
| 295 |
/// This class provides constant time counting for nodes and arcs. |
|
| 296 |
/// |
|
| 297 |
/// \sa concepts::Digraph |
|
| 298 |
class StaticDigraph : public ExtendedStaticDigraphBase {
|
|
| 299 |
public: |
|
| 300 |
|
|
| 301 |
typedef ExtendedStaticDigraphBase Parent; |
|
| 302 |
|
|
| 303 |
public: |
|
| 304 |
|
|
| 305 |
/// \brief Constructor |
|
| 306 |
/// |
|
| 307 |
/// Default constructor. |
|
| 308 |
StaticDigraph() : Parent() {}
|
|
| 309 |
|
|
| 310 |
/// \brief The node with the given index. |
|
| 311 |
/// |
|
| 312 |
/// This function returns the node with the given index. |
|
| 313 |
/// \sa index() |
|
| 314 |
static Node node(int ix) { return Parent::nodeFromId(ix); }
|
|
| 315 |
|
|
| 316 |
/// \brief The arc with the given index. |
|
| 317 |
/// |
|
| 318 |
/// This function returns the arc with the given index. |
|
| 319 |
/// \sa index() |
|
| 320 |
static Arc arc(int ix) { return Parent::arcFromId(ix); }
|
|
| 321 |
|
|
| 322 |
/// \brief The index of the given node. |
|
| 323 |
/// |
|
| 324 |
/// This function returns the index of the the given node. |
|
| 325 |
/// \sa node() |
|
| 326 |
static int index(Node node) { return Parent::id(node); }
|
|
| 327 |
|
|
| 328 |
/// \brief The index of the given arc. |
|
| 329 |
/// |
|
| 330 |
/// This function returns the index of the the given arc. |
|
| 331 |
/// \sa arc() |
|
| 332 |
static int index(Arc arc) { return Parent::id(arc); }
|
|
| 333 |
|
|
| 334 |
/// \brief Number of nodes. |
|
| 335 |
/// |
|
| 336 |
/// This function returns the number of nodes. |
|
| 337 |
int nodeNum() const { return node_num; }
|
|
| 338 |
|
|
| 339 |
/// \brief Number of arcs. |
|
| 340 |
/// |
|
| 341 |
/// This function returns the number of arcs. |
|
| 342 |
int arcNum() const { return arc_num; }
|
|
| 343 |
|
|
| 344 |
/// \brief Build the digraph copying another digraph. |
|
| 345 |
/// |
|
| 346 |
/// This function builds the digraph copying another digraph of any |
|
| 347 |
/// kind. It can be called more than once, but in such case, the whole |
|
| 348 |
/// structure and all maps will be cleared and rebuilt. |
|
| 349 |
/// |
|
| 350 |
/// This method also makes possible to copy a digraph to a StaticDigraph |
|
| 351 |
/// structure using \ref DigraphCopy. |
|
| 352 |
/// |
|
| 353 |
/// \param digraph An existing digraph to be copied. |
|
| 354 |
/// \param nodeRef The node references will be copied into this map. |
|
| 355 |
/// Its key type must be \c Digraph::Node and its value type must be |
|
| 356 |
/// \c StaticDigraph::Node. |
|
| 357 |
/// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" |
|
| 358 |
/// concept. |
|
| 359 |
/// \param arcRef The arc references will be copied into this map. |
|
| 360 |
/// Its key type must be \c Digraph::Arc and its value type must be |
|
| 361 |
/// \c StaticDigraph::Arc. |
|
| 362 |
/// It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
| 363 |
/// |
|
| 364 |
/// \note If you do not need the arc references, then you could use |
|
| 365 |
/// \ref NullMap for the last parameter. However the node references |
|
| 366 |
/// are required by the function itself, thus they must be readable |
|
| 367 |
/// from the map. |
|
| 368 |
template <typename Digraph, typename NodeRefMap, typename ArcRefMap> |
|
| 369 |
void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) {
|
|
| 370 |
if (built) Parent::clear(); |
|
| 371 |
Parent::build(digraph, nodeRef, arcRef); |
|
| 372 |
} |
|
| 373 |
|
|
| 374 |
/// \brief Build the digraph from an arc list. |
|
| 375 |
/// |
|
| 376 |
/// This function builds the digraph from the given arc list. |
|
| 377 |
/// It can be called more than once, but in such case, the whole |
|
| 378 |
/// structure and all maps will be cleared and rebuilt. |
|
| 379 |
/// |
|
| 380 |
/// The list of the arcs must be given in the range <tt>[begin, end)</tt> |
|
| 381 |
/// specified by STL compatible itartors whose \c value_type must be |
|
| 382 |
/// <tt>std::pair<int,int></tt>. |
|
| 383 |
/// Each arc must be specified by a pair of integer indices |
|
| 384 |
/// from the range <tt>[0..n-1]</tt>. <i>The pairs must be in a |
|
| 385 |
/// non-decreasing order with respect to their first values.</i> |
|
| 386 |
/// If the k-th pair in the list is <tt>(i,j)</tt>, then |
|
| 387 |
/// <tt>arc(k-1)</tt> will connect <tt>node(i)</tt> to <tt>node(j)</tt>. |
|
| 388 |
/// |
|
| 389 |
/// \param n The number of nodes. |
|
| 390 |
/// \param begin An iterator pointing to the beginning of the arc list. |
|
| 391 |
/// \param end An iterator pointing to the end of the arc list. |
|
| 392 |
/// |
|
| 393 |
/// For example, a simple digraph can be constructed like this. |
|
| 394 |
/// \code |
|
| 395 |
/// std::vector<std::pair<int,int> > arcs; |
|
| 396 |
/// arcs.push_back(std::make_pair(0,1)); |
|
| 397 |
/// arcs.push_back(std::make_pair(0,2)); |
|
| 398 |
/// arcs.push_back(std::make_pair(1,3)); |
|
| 399 |
/// arcs.push_back(std::make_pair(1,2)); |
|
| 400 |
/// arcs.push_back(std::make_pair(3,0)); |
|
| 401 |
/// StaticDigraph gr; |
|
| 402 |
/// gr.build(4, arcs.begin(), arcs.end()); |
|
| 403 |
/// \endcode |
|
| 404 |
template <typename ArcListIterator> |
|
| 405 |
void build(int n, ArcListIterator begin, ArcListIterator end) {
|
|
| 406 |
if (built) Parent::clear(); |
|
| 407 |
StaticDigraphBase::build(n, begin, end); |
|
| 408 |
notifier(Node()).build(); |
|
| 409 |
notifier(Arc()).build(); |
|
| 410 |
} |
|
| 411 |
|
|
| 412 |
/// \brief Clear the digraph. |
|
| 413 |
/// |
|
| 414 |
/// This function erases all nodes and arcs from the digraph. |
|
| 415 |
void clear() {
|
|
| 416 |
Parent::clear(); |
|
| 417 |
} |
|
| 418 |
|
|
| 419 |
protected: |
|
| 420 |
|
|
| 421 |
using Parent::fastFirstOut; |
|
| 422 |
using Parent::fastNextOut; |
|
| 423 |
using Parent::fastLastOut; |
|
| 424 |
|
|
| 425 |
public: |
|
| 426 |
|
|
| 427 |
class OutArcIt : public Arc {
|
|
| 428 |
public: |
|
| 429 |
|
|
| 430 |
OutArcIt() { }
|
|
| 431 |
|
|
| 432 |
OutArcIt(Invalid i) : Arc(i) { }
|
|
| 433 |
|
|
| 434 |
OutArcIt(const StaticDigraph& digraph, const Node& node) {
|
|
| 435 |
digraph.fastFirstOut(*this, node); |
|
| 436 |
digraph.fastLastOut(last, node); |
|
| 437 |
if (last == *this) *this = INVALID; |
|
| 438 |
} |
|
| 439 |
|
|
| 440 |
OutArcIt(const StaticDigraph& digraph, const Arc& arc) : Arc(arc) {
|
|
| 441 |
if (arc != INVALID) {
|
|
| 442 |
digraph.fastLastOut(last, digraph.source(arc)); |
|
| 443 |
} |
|
| 444 |
} |
|
| 445 |
|
|
| 446 |
OutArcIt& operator++() {
|
|
| 447 |
StaticDigraph::fastNextOut(*this); |
|
| 448 |
if (last == *this) *this = INVALID; |
|
| 449 |
return *this; |
|
| 450 |
} |
|
| 451 |
|
|
| 452 |
private: |
|
| 453 |
Arc last; |
|
| 454 |
}; |
|
| 455 |
|
|
| 456 |
Node baseNode(const OutArcIt &arc) const {
|
|
| 457 |
return Parent::source(static_cast<const Arc&>(arc)); |
|
| 458 |
} |
|
| 459 |
|
|
| 460 |
Node runningNode(const OutArcIt &arc) const {
|
|
| 461 |
return Parent::target(static_cast<const Arc&>(arc)); |
|
| 462 |
} |
|
| 463 |
|
|
| 464 |
Node baseNode(const InArcIt &arc) const {
|
|
| 465 |
return Parent::target(static_cast<const Arc&>(arc)); |
|
| 466 |
} |
|
| 467 |
|
|
| 468 |
Node runningNode(const InArcIt &arc) const {
|
|
| 469 |
return Parent::source(static_cast<const Arc&>(arc)); |
|
| 470 |
} |
|
| 471 |
|
|
| 472 |
}; |
|
| 473 |
|
|
| 474 |
} |
|
| 475 |
|
|
| 476 |
#endif |
| 1 |
#!/usr/bin/env /usr/local/Python/bin/python2.1 |
|
| 2 |
""" |
|
| 3 |
BibTeX to Doxygen converter |
|
| 4 |
Usage: python bib2dox.py bibfile.bib > bibfile.dox |
|
| 5 |
|
|
| 6 |
This code is the modification of the BibTeX to XML converter |
|
| 7 |
by Vidar Bronken Gundersen et al. See the original copyright notices below. |
|
| 8 |
|
|
| 9 |
********************************************************************** |
|
| 10 |
|
|
| 11 |
Decoder for bibliographic data, BibTeX |
|
| 12 |
Usage: python bibtex2xml.py bibfile.bib > bibfile.xml |
|
| 13 |
|
|
| 14 |
v.8 |
|
| 15 |
(c)2002-06-23 Vidar Bronken Gundersen |
|
| 16 |
http://bibtexml.sf.net/ |
|
| 17 |
Reuse approved as long as this notification is kept. |
|
| 18 |
Licence: GPL. |
|
| 19 |
|
|
| 20 |
Contributions/thanks to: |
|
| 21 |
Egon Willighagen, http://sf.net/projects/jreferences/ |
|
| 22 |
Richard Mahoney (for providing a test case) |
|
| 23 |
|
|
| 24 |
Editted by Sara Sprenkle to be more robust and handle more bibtex features. |
|
| 25 |
(c) 2003-01-15 |
|
| 26 |
|
|
| 27 |
1. Changed bibtex: tags to bibxml: tags. |
|
| 28 |
2. Use xmlns:bibxml="http://bibtexml.sf.net/" |
|
| 29 |
3. Allow spaces between @type and first {
|
|
| 30 |
4. "author" fields with multiple authors split by " and " |
|
| 31 |
are put in separate xml "bibxml:author" tags. |
|
| 32 |
5. Option for Titles: words are capitalized |
|
| 33 |
only if first letter in title or capitalized inside braces |
|
| 34 |
6. Removes braces from within field values |
|
| 35 |
7. Ignores comments in bibtex file (including @comment{ or % )
|
|
| 36 |
8. Replaces some special latex tags, e.g., replaces ~ with ' ' |
|
| 37 |
9. Handles bibtex @string abbreviations |
|
| 38 |
--> includes bibtex's default abbreviations for months |
|
| 39 |
--> does concatenation of abbr # " more " and " more " # abbr |
|
| 40 |
10. Handles @type( ... ) or @type{ ... }
|
|
| 41 |
11. The keywords field is split on , or ; and put into separate xml |
|
| 42 |
"bibxml:keywords" tags |
|
| 43 |
12. Ignores @preamble |
|
| 44 |
|
|
| 45 |
Known Limitations |
|
| 46 |
1. Does not transform Latex encoding like math mode and special |
|
| 47 |
latex symbols. |
|
| 48 |
2. Does not parse author fields into first and last names. |
|
| 49 |
E.g., It does not do anything special to an author whose name is |
|
| 50 |
in the form LAST_NAME, FIRST_NAME |
|
| 51 |
In "author" tag, will show up as |
|
| 52 |
<bibxml:author>LAST_NAME, FIRST_NAME</bibxml:author> |
|
| 53 |
3. Does not handle "crossref" fields other than to print |
|
| 54 |
<bibxml:crossref>...</bibxml:crossref> |
|
| 55 |
4. Does not inform user of the input's format errors. You just won't |
|
| 56 |
be able to transform the file later with XSL |
|
| 57 |
|
|
| 58 |
You will have to manually edit the XML output if you need to handle |
|
| 59 |
these (and unknown) limitations. |
|
| 60 |
|
|
| 61 |
""" |
|
| 62 |
|
|
| 63 |
import string, re |
|
| 64 |
|
|
| 65 |
# set of valid name characters |
|
| 66 |
valid_name_chars = '[\w\-:]' |
|
| 67 |
|
|
| 68 |
# |
|
| 69 |
# define global regular expression variables |
|
| 70 |
# |
|
| 71 |
author_rex = re.compile('\s+and\s+')
|
|
| 72 |
rembraces_rex = re.compile('[{}]')
|
|
| 73 |
capitalize_rex = re.compile('({[^}]*})')
|
|
| 74 |
|
|
| 75 |
# used by bibtexkeywords(data) |
|
| 76 |
keywords_rex = re.compile('[,;]')
|
|
| 77 |
|
|
| 78 |
# used by concat_line(line) |
|
| 79 |
concatsplit_rex = re.compile('\s*#\s*')
|
|
| 80 |
|
|
| 81 |
# split on {, }, or " in verify_out_of_braces
|
|
| 82 |
delimiter_rex = re.compile('([{}"])',re.I)
|
|
| 83 |
|
|
| 84 |
field_rex = re.compile('\s*(\w*)\s*=\s*(.*)')
|
|
| 85 |
data_rex = re.compile('\s*(\w*)\s*=\s*([^,]*),?')
|
|
| 86 |
|
|
| 87 |
url_rex = re.compile('\\\url\{([^}]*)\}')
|
|
| 88 |
|
|
| 89 |
# |
|
| 90 |
# styles for html formatting |
|
| 91 |
# |
|
| 92 |
divstyle = 'margin-top: -4ex; margin-left: 8em;' |
|
| 93 |
|
|
| 94 |
# |
|
| 95 |
# return the string parameter without braces |
|
| 96 |
# |
|
| 97 |
def transformurls(str): |
|
| 98 |
return url_rex.sub(r'<a href="\1">\1</a>', str) |
|
| 99 |
|
|
| 100 |
# |
|
| 101 |
# return the string parameter without braces |
|
| 102 |
# |
|
| 103 |
def removebraces(str): |
|
| 104 |
return rembraces_rex.sub('', str)
|
|
| 105 |
|
|
| 106 |
# |
|
| 107 |
# latex-specific replacements |
|
| 108 |
# (do this after braces were removed) |
|
| 109 |
# |
|
| 110 |
def latexreplacements(line): |
|
| 111 |
line = string.replace(line, '~', ' ') |
|
| 112 |
line = string.replace(line, '\\\'a', 'á') |
|
| 113 |
line = string.replace(line, '\\"a', 'ä') |
|
| 114 |
line = string.replace(line, '\\\'e', 'é') |
|
| 115 |
line = string.replace(line, '\\"e', 'ë') |
|
| 116 |
line = string.replace(line, '\\\'i', 'í') |
|
| 117 |
line = string.replace(line, '\\"i', 'ï') |
|
| 118 |
line = string.replace(line, '\\\'o', 'ó') |
|
| 119 |
line = string.replace(line, '\\"o', 'ö') |
|
| 120 |
line = string.replace(line, '\\\'u', 'ú') |
|
| 121 |
line = string.replace(line, '\\"u', 'ü') |
|
| 122 |
line = string.replace(line, '\\H o', 'õ') |
|
| 123 |
line = string.replace(line, '\\H u', 'ü') # ũ does not exist |
|
| 124 |
line = string.replace(line, '\\\'A', 'Á') |
|
| 125 |
line = string.replace(line, '\\"A', 'Ä') |
|
| 126 |
line = string.replace(line, '\\\'E', 'É') |
|
| 127 |
line = string.replace(line, '\\"E', 'Ë') |
|
| 128 |
line = string.replace(line, '\\\'I', 'Í') |
|
| 129 |
line = string.replace(line, '\\"I', 'Ï') |
|
| 130 |
line = string.replace(line, '\\\'O', 'Ó') |
|
| 131 |
line = string.replace(line, '\\"O', 'Ö') |
|
| 132 |
line = string.replace(line, '\\\'U', 'Ú') |
|
| 133 |
line = string.replace(line, '\\"U', 'Ü') |
|
| 134 |
line = string.replace(line, '\\H O', 'Õ') |
|
| 135 |
line = string.replace(line, '\\H U', 'Ü') # Ũ does not exist |
|
| 136 |
|
|
| 137 |
return line |
|
| 138 |
|
|
| 139 |
# |
|
| 140 |
# copy characters form a string decoding html expressions (&xyz;) |
|
| 141 |
# |
|
| 142 |
def copychars(str, ifrom, count): |
|
| 143 |
result = '' |
|
| 144 |
i = ifrom |
|
| 145 |
c = 0 |
|
| 146 |
html_spec = False |
|
| 147 |
while (i < len(str)) and (c < count): |
|
| 148 |
if str[i] == '&': |
|
| 149 |
html_spec = True; |
|
| 150 |
if i+1 < len(str): |
|
| 151 |
result += str[i+1] |
|
| 152 |
c += 1 |
|
| 153 |
i += 2 |
|
| 154 |
else: |
|
| 155 |
if not html_spec: |
|
| 156 |
if ((str[i] >= 'A') and (str[i] <= 'Z')) or \ |
|
| 157 |
((str[i] >= 'a') and (str[i] <= 'z')): |
|
| 158 |
result += str[i] |
|
| 159 |
c += 1 |
|
| 160 |
elif str[i] == ';': |
|
| 161 |
html_spec = False; |
|
| 162 |
i += 1 |
|
| 163 |
|
|
| 164 |
return result |
|
| 165 |
|
|
| 166 |
|
|
| 167 |
# |
|
| 168 |
# Handle a list of authors (separated by 'and'). |
|
| 169 |
# It gives back an array of the follwing values: |
|
| 170 |
# - num: the number of authors, |
|
| 171 |
# - list: the list of the author names, |
|
| 172 |
# - text: the bibtex text (separated by commas and/or 'and') |
|
| 173 |
# - abbrev: abbreviation that can be used for indicate the |
|
| 174 |
# bibliography entries |
|
| 175 |
# |
|
| 176 |
def bibtexauthor(data): |
|
| 177 |
result = {}
|
|
| 178 |
bibtex = '' |
|
| 179 |
result['list'] = author_rex.split(data) |
|
| 180 |
result['num'] = len(result['list']) |
|
| 181 |
for i, author in enumerate(result['list']): |
|
| 182 |
# general transformations |
|
| 183 |
author = latexreplacements(removebraces(author.strip())) |
|
| 184 |
# transform "Xyz, A. B." to "A. B. Xyz" |
|
| 185 |
pos = author.find(',')
|
|
| 186 |
if pos != -1: |
|
| 187 |
author = author[pos+1:].strip() + ' ' + author[:pos].strip() |
|
| 188 |
result['list'][i] = author |
|
| 189 |
bibtex += author + '#' |
|
| 190 |
bibtex = bibtex[:-1] |
|
| 191 |
if result['num'] > 1: |
|
| 192 |
ix = bibtex.rfind('#')
|
|
| 193 |
if result['num'] == 2: |
|
| 194 |
bibtex = bibtex[:ix] + ' and ' + bibtex[ix+1:] |
|
| 195 |
else: |
|
| 196 |
bibtex = bibtex[:ix] + ', and ' + bibtex[ix+1:] |
|
| 197 |
bibtex = bibtex.replace('#', ', ')
|
|
| 198 |
result['text'] = bibtex |
|
| 199 |
|
|
| 200 |
result['abbrev'] = '' |
|
| 201 |
for author in result['list']: |
|
| 202 |
pos = author.rfind(' ') + 1
|
|
| 203 |
count = 1 |
|
| 204 |
if result['num'] == 1: |
|
| 205 |
count = 3 |
|
| 206 |
result['abbrev'] += copychars(author, pos, count) |
|
| 207 |
|
|
| 208 |
return result |
|
| 209 |
|
|
| 210 |
|
|
| 211 |
# |
|
| 212 |
# data = title string |
|
| 213 |
# @return the capitalized title (first letter is capitalized), rest are capitalized |
|
| 214 |
# only if capitalized inside braces |
|
| 215 |
# |
|
| 216 |
def capitalizetitle(data): |
|
| 217 |
title_list = capitalize_rex.split(data) |
|
| 218 |
title = '' |
|
| 219 |
count = 0 |
|
| 220 |
for phrase in title_list: |
|
| 221 |
check = string.lstrip(phrase) |
|
| 222 |
|
|
| 223 |
# keep phrase's capitalization the same |
|
| 224 |
if check.find('{') == 0:
|
|
| 225 |
title += removebraces(phrase) |
|
| 226 |
else: |
|
| 227 |
# first word --> capitalize first letter (after spaces) |
|
| 228 |
if count == 0: |
|
| 229 |
title += check.capitalize() |
|
| 230 |
else: |
|
| 231 |
title += phrase.lower() |
|
| 232 |
count = count + 1 |
|
| 233 |
|
|
| 234 |
return title |
|
| 235 |
|
|
| 236 |
|
|
| 237 |
# |
|
| 238 |
# @return the bibtex for the title |
|
| 239 |
# @param data --> title string |
|
| 240 |
# braces are removed from title |
|
| 241 |
# |
|
| 242 |
def bibtextitle(data, entrytype): |
|
| 243 |
if entrytype in ('book', 'inbook'):
|
|
| 244 |
title = removebraces(data.strip()) |
|
| 245 |
else: |
|
| 246 |
title = removebraces(capitalizetitle(data.strip())) |
|
| 247 |
bibtex = title |
|
| 248 |
return bibtex |
|
| 249 |
|
|
| 250 |
|
|
| 251 |
# |
|
| 252 |
# function to compare entry lists |
|
| 253 |
# |
|
| 254 |
def entry_cmp(x, y): |
|
| 255 |
return cmp(x[0], y[0]) |
|
| 256 |
|
|
| 257 |
|
|
| 258 |
# |
|
| 259 |
# print the XML for the transformed "filecont_source" |
|
| 260 |
# |
|
| 261 |
def bibtexdecoder(filecont_source): |
|
| 262 |
filecont = [] |
|
| 263 |
file = [] |
|
| 264 |
|
|
| 265 |
# want @<alphanumeric chars><spaces>{<spaces><any chars>,
|
|
| 266 |
pubtype_rex = re.compile('@(\w*)\s*{\s*(.*),')
|
|
| 267 |
endtype_rex = re.compile('}\s*$')
|
|
| 268 |
endtag_rex = re.compile('^\s*}\s*$')
|
|
| 269 |
|
|
| 270 |
bracefield_rex = re.compile('\s*(\w*)\s*=\s*(.*)')
|
|
| 271 |
bracedata_rex = re.compile('\s*(\w*)\s*=\s*{(.*)},?')
|
|
| 272 |
|
|
| 273 |
quotefield_rex = re.compile('\s*(\w*)\s*=\s*(.*)')
|
|
| 274 |
quotedata_rex = re.compile('\s*(\w*)\s*=\s*"(.*)",?')
|
|
| 275 |
|
|
| 276 |
for line in filecont_source: |
|
| 277 |
line = line[:-1] |
|
| 278 |
|
|
| 279 |
# encode character entities |
|
| 280 |
line = string.replace(line, '&', '&') |
|
| 281 |
line = string.replace(line, '<', '<') |
|
| 282 |
line = string.replace(line, '>', '>') |
|
| 283 |
|
|
| 284 |
# start entry: publication type (store for later use) |
|
| 285 |
if pubtype_rex.match(line): |
|
| 286 |
# want @<alphanumeric chars><spaces>{<spaces><any chars>,
|
|
| 287 |
entrycont = {}
|
|
| 288 |
entry = [] |
|
| 289 |
entrytype = pubtype_rex.sub('\g<1>',line)
|
|
| 290 |
entrytype = string.lower(entrytype) |
|
| 291 |
entryid = pubtype_rex.sub('\g<2>', line)
|
|
| 292 |
|
|
| 293 |
# end entry if just a } |
|
| 294 |
elif endtype_rex.match(line): |
|
| 295 |
# generate doxygen code for the entry |
|
| 296 |
|
|
| 297 |
# enty type related formattings |
|
| 298 |
if entrytype in ('book', 'inbook'):
|
|
| 299 |
entrycont['title'] = '<em>' + entrycont['title'] + '</em>' |
|
| 300 |
if not entrycont.has_key('author'):
|
|
| 301 |
entrycont['author'] = entrycont['editor'] |
|
| 302 |
entrycont['author']['text'] += ', editors' |
|
| 303 |
elif entrytype == 'article': |
|
| 304 |
entrycont['journal'] = '<em>' + entrycont['journal'] + '</em>' |
|
| 305 |
elif entrytype in ('inproceedings', 'incollection', 'conference'):
|
|
| 306 |
entrycont['booktitle'] = '<em>' + entrycont['booktitle'] + '</em>' |
|
| 307 |
elif entrytype == 'techreport': |
|
| 308 |
if not entrycont.has_key('type'):
|
|
| 309 |
entrycont['type'] = 'Technical report' |
|
| 310 |
elif entrytype == 'mastersthesis': |
|
| 311 |
entrycont['type'] = 'Master\'s thesis' |
|
| 312 |
elif entrytype == 'phdthesis': |
|
| 313 |
entrycont['type'] = 'PhD thesis' |
|
| 314 |
|
|
| 315 |
for eline in entrycont: |
|
| 316 |
if eline != '': |
|
| 317 |
eline = latexreplacements(eline) |
|
| 318 |
|
|
| 319 |
if entrycont.has_key('pages') and (entrycont['pages'] != ''):
|
|
| 320 |
entrycont['pages'] = string.replace(entrycont['pages'], '--', '-') |
|
| 321 |
|
|
| 322 |
if entrycont.has_key('author') and (entrycont['author'] != ''):
|
|
| 323 |
entry.append(entrycont['author']['text'] + '.') |
|
| 324 |
if entrycont.has_key('title') and (entrycont['title'] != ''):
|
|
| 325 |
entry.append(entrycont['title'] + '.') |
|
| 326 |
if entrycont.has_key('journal') and (entrycont['journal'] != ''):
|
|
| 327 |
entry.append(entrycont['journal'] + ',') |
|
| 328 |
if entrycont.has_key('booktitle') and (entrycont['booktitle'] != ''):
|
|
| 329 |
entry.append('In ' + entrycont['booktitle'] + ',')
|
|
| 330 |
if entrycont.has_key('type') and (entrycont['type'] != ''):
|
|
| 331 |
eline = entrycont['type'] |
|
| 332 |
if entrycont.has_key('number') and (entrycont['number'] != ''):
|
|
| 333 |
eline += ' ' + entrycont['number'] |
|
| 334 |
eline += ',' |
|
| 335 |
entry.append(eline) |
|
| 336 |
if entrycont.has_key('institution') and (entrycont['institution'] != ''):
|
|
| 337 |
entry.append(entrycont['institution'] + ',') |
|
| 338 |
if entrycont.has_key('publisher') and (entrycont['publisher'] != ''):
|
|
| 339 |
entry.append(entrycont['publisher'] + ',') |
|
| 340 |
if entrycont.has_key('school') and (entrycont['school'] != ''):
|
|
| 341 |
entry.append(entrycont['school'] + ',') |
|
| 342 |
if entrycont.has_key('address') and (entrycont['address'] != ''):
|
|
| 343 |
entry.append(entrycont['address'] + ',') |
|
| 344 |
if entrycont.has_key('edition') and (entrycont['edition'] != ''):
|
|
| 345 |
entry.append(entrycont['edition'] + ' edition,') |
|
| 346 |
if entrycont.has_key('howpublished') and (entrycont['howpublished'] != ''):
|
|
| 347 |
entry.append(entrycont['howpublished'] + ',') |
|
| 348 |
if entrycont.has_key('volume') and (entrycont['volume'] != ''):
|
|
| 349 |
eline = entrycont['volume']; |
|
| 350 |
if entrycont.has_key('number') and (entrycont['number'] != ''):
|
|
| 351 |
eline += '(' + entrycont['number'] + ')'
|
|
| 352 |
if entrycont.has_key('pages') and (entrycont['pages'] != ''):
|
|
| 353 |
eline += ':' + entrycont['pages'] |
|
| 354 |
eline += ',' |
|
| 355 |
entry.append(eline) |
|
| 356 |
else: |
|
| 357 |
if entrycont.has_key('pages') and (entrycont['pages'] != ''):
|
|
| 358 |
entry.append('pages ' + entrycont['pages'] + ',')
|
|
| 359 |
if entrycont.has_key('year') and (entrycont['year'] != ''):
|
|
| 360 |
if entrycont.has_key('month') and (entrycont['month'] != ''):
|
|
| 361 |
entry.append(entrycont['month'] + ' ' + entrycont['year'] + '.') |
|
| 362 |
else: |
|
| 363 |
entry.append(entrycont['year'] + '.') |
|
| 364 |
if entrycont.has_key('note') and (entrycont['note'] != ''):
|
|
| 365 |
entry.append(entrycont['note'] + '.') |
|
| 366 |
if entrycont.has_key('url') and (entrycont['url'] != ''):
|
|
| 367 |
entry.append(entrycont['url'] + '.') |
|
| 368 |
|
|
| 369 |
# generate keys for sorting and for the output |
|
| 370 |
sortkey = '' |
|
| 371 |
bibkey = '' |
|
| 372 |
if entrycont.has_key('author'):
|
|
| 373 |
for author in entrycont['author']['list']: |
|
| 374 |
sortkey += copychars(author, author.rfind(' ')+1, len(author))
|
|
| 375 |
bibkey = entrycont['author']['abbrev'] |
|
| 376 |
else: |
|
| 377 |
bibkey = 'x' |
|
| 378 |
if entrycont.has_key('year'):
|
|
| 379 |
sortkey += entrycont['year'] |
|
| 380 |
bibkey += entrycont['year'][-2:] |
|
| 381 |
if entrycont.has_key('title'):
|
|
| 382 |
sortkey += entrycont['title'] |
|
| 383 |
if entrycont.has_key('key'):
|
|
| 384 |
sortkey = entrycont['key'] + sortkey |
|
| 385 |
bibkey = entrycont['key'] |
|
| 386 |
entry.insert(0, sortkey) |
|
| 387 |
entry.insert(1, bibkey) |
|
| 388 |
entry.insert(2, entryid) |
|
| 389 |
|
|
| 390 |
# add the entry to the file contents |
|
| 391 |
filecont.append(entry) |
|
| 392 |
|
|
| 393 |
else: |
|
| 394 |
# field, publication info |
|
| 395 |
field = '' |
|
| 396 |
data = '' |
|
| 397 |
|
|
| 398 |
# field = {data} entries
|
|
| 399 |
if bracedata_rex.match(line): |
|
| 400 |
field = bracefield_rex.sub('\g<1>', line)
|
|
| 401 |
field = string.lower(field) |
|
| 402 |
data = bracedata_rex.sub('\g<2>', line)
|
|
| 403 |
|
|
| 404 |
# field = "data" entries |
|
| 405 |
elif quotedata_rex.match(line): |
|
| 406 |
field = quotefield_rex.sub('\g<1>', line)
|
|
| 407 |
field = string.lower(field) |
|
| 408 |
data = quotedata_rex.sub('\g<2>', line)
|
|
| 409 |
|
|
| 410 |
# field = data entries |
|
| 411 |
elif data_rex.match(line): |
|
| 412 |
field = field_rex.sub('\g<1>', line)
|
|
| 413 |
field = string.lower(field) |
|
| 414 |
data = data_rex.sub('\g<2>', line)
|
|
| 415 |
|
|
| 416 |
if field == 'url': |
|
| 417 |
data = '\\url{' + data.strip() + '}'
|
|
| 418 |
|
|
| 419 |
if field in ('author', 'editor'):
|
|
| 420 |
entrycont[field] = bibtexauthor(data) |
|
| 421 |
line = '' |
|
| 422 |
elif field == 'title': |
|
| 423 |
line = bibtextitle(data, entrytype) |
|
| 424 |
elif field != '': |
|
| 425 |
line = removebraces(transformurls(data.strip())) |
|
| 426 |
|
|
| 427 |
if line != '': |
|
| 428 |
line = latexreplacements(line) |
|
| 429 |
entrycont[field] = line |
|
| 430 |
|
|
| 431 |
|
|
| 432 |
# sort entries |
|
| 433 |
filecont.sort(entry_cmp) |
|
| 434 |
|
|
| 435 |
# count the bibtex keys |
|
| 436 |
keytable = {}
|
|
| 437 |
counttable = {}
|
|
| 438 |
for entry in filecont: |
|
| 439 |
bibkey = entry[1] |
|
| 440 |
if not keytable.has_key(bibkey): |
|
| 441 |
keytable[bibkey] = 1 |
|
| 442 |
else: |
|
| 443 |
keytable[bibkey] += 1 |
|
| 444 |
|
|
| 445 |
for bibkey in keytable.keys(): |
|
| 446 |
counttable[bibkey] = 0 |
|
| 447 |
|
|
| 448 |
# generate output |
|
| 449 |
for entry in filecont: |
|
| 450 |
# generate output key form the bibtex key |
|
| 451 |
bibkey = entry[1] |
|
| 452 |
entryid = entry[2] |
|
| 453 |
if keytable[bibkey] == 1: |
|
| 454 |
outkey = bibkey |
|
| 455 |
else: |
|
| 456 |
outkey = bibkey + chr(97 + counttable[bibkey]) |
|
| 457 |
counttable[bibkey] += 1 |
|
| 458 |
|
|
| 459 |
# append the entry code to the output |
|
| 460 |
file.append('\\section ' + entryid + ' [' + outkey + ']')
|
|
| 461 |
file.append('<div style="' + divstyle + '">')
|
|
| 462 |
for line in entry[3:]: |
|
| 463 |
file.append(line) |
|
| 464 |
file.append('</div>')
|
|
| 465 |
file.append('')
|
|
| 466 |
|
|
| 467 |
return file |
|
| 468 |
|
|
| 469 |
|
|
| 470 |
# |
|
| 471 |
# return 1 iff abbr is in line but not inside braces or quotes |
|
| 472 |
# assumes that abbr appears only once on the line (out of braces and quotes) |
|
| 473 |
# |
|
| 474 |
def verify_out_of_braces(line, abbr): |
|
| 475 |
|
|
| 476 |
phrase_split = delimiter_rex.split(line) |
|
| 477 |
|
|
| 478 |
abbr_rex = re.compile( '\\b' + abbr + '\\b', re.I) |
|
| 479 |
|
|
| 480 |
open_brace = 0 |
|
| 481 |
open_quote = 0 |
|
| 482 |
|
|
| 483 |
for phrase in phrase_split: |
|
| 484 |
if phrase == "{":
|
|
| 485 |
open_brace = open_brace + 1 |
|
| 486 |
elif phrase == "}": |
|
| 487 |
open_brace = open_brace - 1 |
|
| 488 |
elif phrase == '"': |
|
| 489 |
if open_quote == 1: |
|
| 490 |
open_quote = 0 |
|
| 491 |
else: |
|
| 492 |
open_quote = 1 |
|
| 493 |
elif abbr_rex.search(phrase): |
|
| 494 |
if open_brace == 0 and open_quote == 0: |
|
| 495 |
return 1 |
|
| 496 |
|
|
| 497 |
return 0 |
|
| 498 |
|
|
| 499 |
|
|
| 500 |
# |
|
| 501 |
# a line in the form phrase1 # phrase2 # ... # phrasen |
|
| 502 |
# is returned as phrase1 phrase2 ... phrasen |
|
| 503 |
# with the correct punctuation |
|
| 504 |
# Bug: Doesn't always work with multiple abbreviations plugged in |
|
| 505 |
# |
|
| 506 |
def concat_line(line): |
|
| 507 |
# only look at part after equals |
|
| 508 |
field = field_rex.sub('\g<1>',line)
|
|
| 509 |
rest = field_rex.sub('\g<2>',line)
|
|
| 510 |
|
|
| 511 |
concat_line = field + ' =' |
|
| 512 |
|
|
| 513 |
pound_split = concatsplit_rex.split(rest) |
|
| 514 |
|
|
| 515 |
phrase_count = 0 |
|
| 516 |
length = len(pound_split) |
|
| 517 |
|
|
| 518 |
for phrase in pound_split: |
|
| 519 |
phrase = phrase.strip() |
|
| 520 |
if phrase_count != 0: |
|
| 521 |
if phrase.startswith('"') or phrase.startswith('{'):
|
|
| 522 |
phrase = phrase[1:] |
|
| 523 |
elif phrase.startswith('"'):
|
|
| 524 |
phrase = phrase.replace('"','{',1)
|
|
| 525 |
|
|
| 526 |
if phrase_count != length-1: |
|
| 527 |
if phrase.endswith('"') or phrase.endswith('}'):
|
|
| 528 |
phrase = phrase[:-1] |
|
| 529 |
else: |
|
| 530 |
if phrase.endswith('"'):
|
|
| 531 |
phrase = phrase[:-1] |
|
| 532 |
phrase = phrase + "}" |
|
| 533 |
elif phrase.endswith('",'):
|
|
| 534 |
phrase = phrase[:-2] |
|
| 535 |
phrase = phrase + "}," |
|
| 536 |
|
|
| 537 |
# if phrase did have \#, add the \# back |
|
| 538 |
if phrase.endswith('\\'):
|
|
| 539 |
phrase = phrase + "#" |
|
| 540 |
concat_line = concat_line + ' ' + phrase |
|
| 541 |
|
|
| 542 |
phrase_count = phrase_count + 1 |
|
| 543 |
|
|
| 544 |
return concat_line |
|
| 545 |
|
|
| 546 |
|
|
| 547 |
# |
|
| 548 |
# substitute abbreviations into filecont |
|
| 549 |
# @param filecont_source - string of data from file |
|
| 550 |
# |
|
| 551 |
def bibtex_replace_abbreviations(filecont_source): |
|
| 552 |
filecont = filecont_source.splitlines() |
|
| 553 |
|
|
| 554 |
# These are defined in bibtex, so we'll define them too |
|
| 555 |
abbr_list = ['jan','feb','mar','apr','may','jun', |
|
| 556 |
'jul','aug','sep','oct','nov','dec'] |
|
| 557 |
value_list = ['January','February','March','April', |
|
| 558 |
'May','June','July','August','September', |
|
| 559 |
'October','November','December'] |
|
| 560 |
|
|
| 561 |
abbr_rex = [] |
|
| 562 |
total_abbr_count = 0 |
|
| 563 |
|
|
| 564 |
front = '\\b' |
|
| 565 |
back = '(,?)\\b' |
|
| 566 |
|
|
| 567 |
for x in abbr_list: |
|
| 568 |
abbr_rex.append( re.compile( front + abbr_list[total_abbr_count] + back, re.I ) ) |
|
| 569 |
total_abbr_count = total_abbr_count + 1 |
|
| 570 |
|
|
| 571 |
|
|
| 572 |
abbrdef_rex = re.compile('\s*@string\s*{\s*('+ valid_name_chars +'*)\s*=(.*)',
|
|
| 573 |
re.I) |
|
| 574 |
|
|
| 575 |
comment_rex = re.compile('@comment\s*{',re.I)
|
|
| 576 |
preamble_rex = re.compile('@preamble\s*{',re.I)
|
|
| 577 |
|
|
| 578 |
waiting_for_end_string = 0 |
|
| 579 |
i = 0 |
|
| 580 |
filecont2 = '' |
|
| 581 |
|
|
| 582 |
for line in filecont: |
|
| 583 |
if line == ' ' or line == '': |
|
| 584 |
continue |
|
| 585 |
|
|
| 586 |
if waiting_for_end_string: |
|
| 587 |
if re.search('}',line):
|
|
| 588 |
waiting_for_end_string = 0 |
|
| 589 |
continue |
|
| 590 |
|
|
| 591 |
if abbrdef_rex.search(line): |
|
| 592 |
abbr = abbrdef_rex.sub('\g<1>', line)
|
|
| 593 |
|
|
| 594 |
if abbr_list.count(abbr) == 0: |
|
| 595 |
val = abbrdef_rex.sub('\g<2>', line)
|
|
| 596 |
abbr_list.append(abbr) |
|
| 597 |
value_list.append(string.strip(val)) |
|
| 598 |
abbr_rex.append( re.compile( front + abbr_list[total_abbr_count] + back, re.I ) ) |
|
| 599 |
total_abbr_count = total_abbr_count + 1 |
|
| 600 |
waiting_for_end_string = 1 |
|
| 601 |
continue |
|
| 602 |
|
|
| 603 |
if comment_rex.search(line): |
|
| 604 |
waiting_for_end_string = 1 |
|
| 605 |
continue |
|
| 606 |
|
|
| 607 |
if preamble_rex.search(line): |
|
| 608 |
waiting_for_end_string = 1 |
|
| 609 |
continue |
|
| 610 |
|
|
| 611 |
|
|
| 612 |
# replace subsequent abbreviations with the value |
|
| 613 |
abbr_count = 0 |
|
| 614 |
|
|
| 615 |
for x in abbr_list: |
|
| 616 |
|
|
| 617 |
if abbr_rex[abbr_count].search(line): |
|
| 618 |
if verify_out_of_braces(line,abbr_list[abbr_count]) == 1: |
|
| 619 |
line = abbr_rex[abbr_count].sub( value_list[abbr_count] + '\g<1>', line) |
|
| 620 |
# Check for # concatenations |
|
| 621 |
if concatsplit_rex.search(line): |
|
| 622 |
line = concat_line(line) |
|
| 623 |
abbr_count = abbr_count + 1 |
|
| 624 |
|
|
| 625 |
|
|
| 626 |
filecont2 = filecont2 + line + '\n' |
|
| 627 |
i = i+1 |
|
| 628 |
|
|
| 629 |
|
|
| 630 |
# Do one final pass over file |
|
| 631 |
|
|
| 632 |
# make sure that didn't end up with {" or }" after the substitution
|
|
| 633 |
filecont2 = filecont2.replace('{"','{{')
|
|
| 634 |
filecont2 = filecont2.replace('"}','}}')
|
|
| 635 |
|
|
| 636 |
afterquotevalue_rex = re.compile('"\s*,\s*')
|
|
| 637 |
afterbrace_rex = re.compile('"\s*}')
|
|
| 638 |
afterbracevalue_rex = re.compile('(=\s*{[^=]*)},\s*')
|
|
| 639 |
|
|
| 640 |
# add new lines to data that changed because of abbreviation substitutions |
|
| 641 |
filecont2 = afterquotevalue_rex.sub('",\n', filecont2)
|
|
| 642 |
filecont2 = afterbrace_rex.sub('"\n}', filecont2)
|
|
| 643 |
filecont2 = afterbracevalue_rex.sub('\g<1>},\n', filecont2)
|
|
| 644 |
|
|
| 645 |
return filecont2 |
|
| 646 |
|
|
| 647 |
# |
|
| 648 |
# convert @type( ... ) to @type{ ... }
|
|
| 649 |
# |
|
| 650 |
def no_outer_parens(filecont): |
|
| 651 |
|
|
| 652 |
# do checking for open parens |
|
| 653 |
# will convert to braces |
|
| 654 |
paren_split = re.split('([(){}])',filecont)
|
|
| 655 |
|
|
| 656 |
open_paren_count = 0 |
|
| 657 |
open_type = 0 |
|
| 658 |
look_next = 0 |
|
| 659 |
|
|
| 660 |
# rebuild filecont |
|
| 661 |
filecont = '' |
|
| 662 |
|
|
| 663 |
at_rex = re.compile('@\w*')
|
|
| 664 |
|
|
| 665 |
for phrase in paren_split: |
|
| 666 |
if look_next == 1: |
|
| 667 |
if phrase == '(':
|
|
| 668 |
phrase = '{'
|
|
| 669 |
open_paren_count = open_paren_count + 1 |
|
| 670 |
else: |
|
| 671 |
open_type = 0 |
|
| 672 |
look_next = 0 |
|
| 673 |
|
|
| 674 |
if phrase == '(':
|
|
| 675 |
open_paren_count = open_paren_count + 1 |
|
| 676 |
|
|
| 677 |
elif phrase == ')': |
|
| 678 |
open_paren_count = open_paren_count - 1 |
|
| 679 |
if open_type == 1 and open_paren_count == 0: |
|
| 680 |
phrase = '}' |
|
| 681 |
open_type = 0 |
|
| 682 |
|
|
| 683 |
elif at_rex.search( phrase ): |
|
| 684 |
open_type = 1 |
|
| 685 |
look_next = 1 |
|
| 686 |
|
|
| 687 |
filecont = filecont + phrase |
|
| 688 |
|
|
| 689 |
return filecont |
|
| 690 |
|
|
| 691 |
|
|
| 692 |
# |
|
| 693 |
# make all whitespace into just one space |
|
| 694 |
# format the bibtex file into a usable form. |
|
| 695 |
# |
|
| 696 |
def bibtexwasher(filecont_source): |
|
| 697 |
|
|
| 698 |
space_rex = re.compile('\s+')
|
|
| 699 |
comment_rex = re.compile('\s*%')
|
|
| 700 |
|
|
| 701 |
filecont = [] |
|
| 702 |
|
|
| 703 |
# remove trailing and excessive whitespace |
|
| 704 |
# ignore comments |
|
| 705 |
for line in filecont_source: |
|
| 706 |
line = string.strip(line) |
|
| 707 |
line = space_rex.sub(' ', line)
|
|
| 708 |
# ignore comments |
|
| 709 |
if not comment_rex.match(line) and line != '': |
|
| 710 |
filecont.append(' '+ line)
|
|
| 711 |
|
|
| 712 |
filecont = string.join(filecont, '') |
|
| 713 |
|
|
| 714 |
# the file is in one long string |
|
| 715 |
|
|
| 716 |
filecont = no_outer_parens(filecont) |
|
| 717 |
|
|
| 718 |
# |
|
| 719 |
# split lines according to preferred syntax scheme |
|
| 720 |
# |
|
| 721 |
filecont = re.sub('(=\s*{[^=]*)},', '\g<1>},\n', filecont)
|
|
| 722 |
|
|
| 723 |
# add new lines after commas that are after values |
|
| 724 |
filecont = re.sub('"\s*,', '",\n', filecont)
|
|
| 725 |
filecont = re.sub('=\s*([\w\d]+)\s*,', '= \g<1>,\n', filecont)
|
|
| 726 |
filecont = re.sub('(@\w*)\s*({(\s*)[^,\s]*)\s*,',
|
|
| 727 |
'\n\n\g<1>\g<2>,\n', filecont) |
|
| 728 |
|
|
| 729 |
# add new lines after } |
|
| 730 |
filecont = re.sub('"\s*}','"\n}\n', filecont)
|
|
| 731 |
filecont = re.sub('}\s*,','},\n', filecont)
|
|
| 732 |
|
|
| 733 |
|
|
| 734 |
filecont = re.sub('@(\w*)', '\n@\g<1>', filecont)
|
|
| 735 |
|
|
| 736 |
# character encoding, reserved latex characters |
|
| 737 |
filecont = re.sub('{\\\&}', '&', filecont)
|
|
| 738 |
filecont = re.sub('\\\&', '&', filecont)
|
|
| 739 |
|
|
| 740 |
# do checking for open braces to get format correct |
|
| 741 |
open_brace_count = 0 |
|
| 742 |
brace_split = re.split('([{}])',filecont)
|
|
| 743 |
|
|
| 744 |
# rebuild filecont |
|
| 745 |
filecont = '' |
|
| 746 |
|
|
| 747 |
for phrase in brace_split: |
|
| 748 |
if phrase == '{':
|
|
| 749 |
open_brace_count = open_brace_count + 1 |
|
| 750 |
elif phrase == '}': |
|
| 751 |
open_brace_count = open_brace_count - 1 |
|
| 752 |
if open_brace_count == 0: |
|
| 753 |
filecont = filecont + '\n' |
|
| 754 |
|
|
| 755 |
filecont = filecont + phrase |
|
| 756 |
|
|
| 757 |
filecont2 = bibtex_replace_abbreviations(filecont) |
|
| 758 |
|
|
| 759 |
# gather |
|
| 760 |
filecont = filecont2.splitlines() |
|
| 761 |
i=0 |
|
| 762 |
j=0 # count the number of blank lines |
|
| 763 |
for line in filecont: |
|
| 764 |
# ignore blank lines |
|
| 765 |
if line == '' or line == ' ': |
|
| 766 |
j = j+1 |
|
| 767 |
continue |
|
| 768 |
filecont[i] = line + '\n' |
|
| 769 |
i = i+1 |
|
| 770 |
|
|
| 771 |
# get rid of the extra stuff at the end of the array |
|
| 772 |
# (The extra stuff are duplicates that are in the array because |
|
| 773 |
# blank lines were removed.) |
|
| 774 |
length = len( filecont) |
|
| 775 |
filecont[length-j:length] = [] |
|
| 776 |
|
|
| 777 |
return filecont |
|
| 778 |
|
|
| 779 |
|
|
| 780 |
def filehandler(filepath): |
|
| 781 |
try: |
|
| 782 |
fd = open(filepath, 'r') |
|
| 783 |
filecont_source = fd.readlines() |
|
| 784 |
fd.close() |
|
| 785 |
except: |
|
| 786 |
print 'Could not open file:', filepath |
|
| 787 |
washeddata = bibtexwasher(filecont_source) |
|
| 788 |
outdata = bibtexdecoder(washeddata) |
|
| 789 |
print '/**' |
|
| 790 |
print '\page references References' |
|
| 791 |
|
|
| 792 |
for line in outdata: |
|
| 793 |
print line |
|
| 794 |
print '*/' |
|
| 795 |
|
|
| 796 |
|
|
| 797 |
# main program |
|
| 798 |
|
|
| 799 |
def main(): |
|
| 800 |
import sys |
|
| 801 |
if sys.argv[1:]: |
|
| 802 |
filepath = sys.argv[1] |
|
| 803 |
else: |
|
| 804 |
print "No input file" |
|
| 805 |
sys.exit() |
|
| 806 |
filehandler(filepath) |
|
| 807 |
|
|
| 808 |
if __name__ == "__main__": main() |
|
| 809 |
|
|
| 810 |
|
|
| 811 |
# end python script |
| 1 |
#!/bin/bash |
|
| 2 |
# |
|
| 3 |
# This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 |
# |
|
| 5 |
# Copyright (C) 2003-2009 |
|
| 6 |
# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
| 7 |
# (Egervary Research Group on Combinatorial Optimization, EGRES). |
|
| 8 |
# |
|
| 9 |
# Permission to use, modify and distribute this software is granted |
|
| 10 |
# provided that this copyright notice appears in all copies. For |
|
| 11 |
# precise terms see the accompanying LICENSE file. |
|
| 12 |
# |
|
| 13 |
# This software is provided "AS IS" with no warranty of any kind, |
|
| 14 |
# express or implied, and with no claim as to its suitability for any |
|
| 15 |
# purpose. |
|
| 16 |
|
|
| 17 |
|
|
| 18 |
if [ ! -f ~/.lemon-bootstrap ]; then |
|
| 19 |
echo 'Create ~/.lemon-bootstrap'. |
|
| 20 |
cat >~/.lemon-bootstrap <<EOF |
|
| 21 |
# |
|
| 22 |
# Default settings for bootstraping the LEMON source code repository |
|
| 23 |
# |
|
| 24 |
EOF |
|
| 25 |
fi |
|
| 26 |
|
|
| 27 |
source ~/.lemon-bootstrap |
|
| 28 |
if [ -f ../../../.lemon-bootstrap ]; then source ../../../.lemon-bootstrap; fi |
|
| 29 |
if [ -f ../../.lemon-bootstrap ]; then source ../../.lemon-bootstrap; fi |
|
| 30 |
if [ -f ../.lemon-bootstrap ]; then source ../.lemon-bootstrap; fi |
|
| 31 |
if [ -f ./.lemon-bootstrap ]; then source ./.lemon-bootstrap; fi |
|
| 32 |
|
|
| 33 |
|
|
| 34 |
function augment_config() {
|
|
| 35 |
if [ "x${!1}" == "x" ]; then
|
|
| 36 |
eval $1=$2 |
|
| 37 |
echo Add "'$1'" to '~/.lemon-bootstrap'. |
|
| 38 |
echo >>~/.lemon-bootstrap |
|
| 39 |
echo $3 >>~/.lemon-bootstrap |
|
| 40 |
echo $1=$2 >>~/.lemon-bootstrap |
|
| 41 |
fi |
|
| 42 |
} |
|
| 43 |
|
|
| 44 |
augment_config LEMON_INSTALL_PREFIX /usr/local \ |
|
| 45 |
"# LEMON installation prefix" |
|
| 46 |
|
|
| 47 |
augment_config COIN_OR_PREFIX /usr/local/coin-or \ |
|
| 48 |
"# COIN-OR installation root prefix (used for CLP/CBC)" |
|
| 49 |
|
|
| 50 |
augment_config SOPLEX_PREFIX /usr/local/soplex \ |
|
| 51 |
"# Soplex build prefix" |
|
| 52 |
|
|
| 53 |
|
|
| 54 |
function ask() {
|
|
| 55 |
echo -n "$1 [$2]? " |
|
| 56 |
read _an |
|
| 57 |
if [ "x$_an" == "x" ]; then |
|
| 58 |
ret="$2" |
|
| 59 |
else |
|
| 60 |
ret=$_an |
|
| 61 |
fi |
|
| 62 |
} |
|
| 63 |
|
|
| 64 |
function yesorno() {
|
|
| 65 |
ret='rossz' |
|
| 66 |
while [ "$ret" != "y" -a "$ret" != "n" -a "$ret" != "yes" -a "$ret" != "no" ]; do |
|
| 67 |
ask "$1" "$2" |
|
| 68 |
done |
|
| 69 |
if [ "$ret" != "y" -a "$ret" != "yes" ]; then |
|
| 70 |
return 1 |
|
| 71 |
else |
|
| 72 |
return 0 |
|
| 73 |
fi |
|
| 74 |
} |
|
| 75 |
|
|
| 76 |
if yesorno "External build" "n" |
|
| 77 |
then |
|
| 78 |
CONFIGURE_PATH=".." |
|
| 79 |
else |
|
| 80 |
CONFIGURE_PATH="." |
|
| 81 |
if yesorno "Autoreconf" "y" |
|
| 82 |
then |
|
| 83 |
AUTORE=yes |
|
| 84 |
else |
|
| 85 |
AUTORE=no |
|
| 86 |
fi |
|
| 87 |
fi |
|
| 88 |
|
|
| 89 |
if yesorno "Optimize" "n" |
|
| 90 |
then |
|
| 91 |
opt_flags=' -O2' |
|
| 92 |
else |
|
| 93 |
opt_flags='' |
|
| 94 |
fi |
|
| 95 |
|
|
| 96 |
if yesorno "Stop on warning" "y" |
|
| 97 |
then |
|
| 98 |
werror_flags=' -Werror' |
|
| 99 |
else |
|
| 100 |
werror_flags='' |
|
| 101 |
fi |
|
| 102 |
|
|
| 103 |
cxx_flags="CXXFLAGS=-ggdb$opt_flags$werror_flags" |
|
| 104 |
|
|
| 105 |
if yesorno "Check with valgrind" "n" |
|
| 106 |
then |
|
| 107 |
valgrind_flags=' --enable-valgrind' |
|
| 108 |
else |
|
| 109 |
valgrind_flags='' |
|
| 110 |
fi |
|
| 111 |
|
|
| 112 |
if [ -f ${COIN_OR_PREFIX}/include/coin/config_coinutils.h ]; then
|
|
| 113 |
if yesorno "Use COIN-OR (CBC/CLP)" "n" |
|
| 114 |
then |
|
| 115 |
coin_flag="--with-coin=$COIN_OR_PREFIX" |
|
| 116 |
else |
|
| 117 |
coin_flag="" |
|
| 118 |
fi |
|
| 119 |
else |
|
| 120 |
coin_flag="" |
|
| 121 |
fi |
|
| 122 |
|
|
| 123 |
if [ -f ${SOPLEX_PREFIX}/src/soplex.h ]; then
|
|
| 124 |
if yesorno "Use Soplex" "n" |
|
| 125 |
then |
|
| 126 |
soplex_flag="--with-soplex=$SOPLEX_PREFIX" |
|
| 127 |
else |
|
| 128 |
soplex_flag="" |
|
| 129 |
fi |
|
| 130 |
else |
|
| 131 |
soplex_flag="" |
|
| 132 |
fi |
|
| 133 |
|
|
| 134 |
if [ "x$AUTORE" == "xyes" ]; then |
|
| 135 |
autoreconf -vif; |
|
| 136 |
fi |
|
| 137 |
${CONFIGURE_PATH}/configure --prefix=$LEMON_INSTALL_PREFIX \
|
|
| 138 |
$valgrind_flags \ |
|
| 139 |
"$cxx_flags" \ |
|
| 140 |
$coin_flag \ |
|
| 141 |
$soplex_flag \ |
|
| 142 |
$* |
| 1 |
#!/bin/sh |
|
| 2 |
|
|
| 3 |
# Run in valgrind, with leak checking enabled |
|
| 4 |
|
|
| 5 |
valgrind -q --leak-check=full "$@" 2> .valgrind-log |
|
| 6 |
|
|
| 7 |
# Save the test result |
|
| 8 |
|
|
| 9 |
result="$?" |
|
| 10 |
|
|
| 11 |
# Valgrind should generate no error messages |
|
| 12 |
|
|
| 13 |
log_contents="`cat .valgrind-log`" |
|
| 14 |
|
|
| 15 |
if [ "$log_contents" != "" ]; then |
|
| 16 |
cat .valgrind-log >&2 |
|
| 17 |
result=1 |
|
| 18 |
fi |
|
| 19 |
|
|
| 20 |
rm -f .valgrind-log |
|
| 21 |
|
|
| 22 |
exit $result |
| 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
| 2 |
* |
|
| 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 |
* |
|
| 5 |
* Copyright (C) 2003-2009 |
|
| 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
| 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
|
| 8 |
* |
|
| 9 |
* Permission to use, modify and distribute this software is granted |
|
| 10 |
* provided that this copyright notice appears in all copies. For |
|
| 11 |
* precise terms see the accompanying LICENSE file. |
|
| 12 |
* |
|
| 13 |
* This software is provided "AS IS" with no warranty of any kind, |
|
| 14 |
* express or implied, and with no claim as to its suitability for any |
|
| 15 |
* purpose. |
|
| 16 |
* |
|
| 17 |
*/ |
|
| 18 |
|
|
| 19 |
#include <iostream> |
|
| 20 |
#include <sstream> |
|
| 21 |
|
|
| 22 |
#include <lemon/smart_graph.h> |
|
| 23 |
#include <lemon/lgf_reader.h> |
|
| 24 |
#include <lemon/path.h> |
|
| 25 |
#include <lemon/concepts/digraph.h> |
|
| 26 |
#include <lemon/concept_check.h> |
|
| 27 |
|
|
| 28 |
#include <lemon/karp.h> |
|
| 29 |
#include <lemon/hartmann_orlin.h> |
|
| 30 |
#include <lemon/howard.h> |
|
| 31 |
|
|
| 32 |
#include "test_tools.h" |
|
| 33 |
|
|
| 34 |
using namespace lemon; |
|
| 35 |
|
|
| 36 |
char test_lgf[] = |
|
| 37 |
"@nodes\n" |
|
| 38 |
"label\n" |
|
| 39 |
"1\n" |
|
| 40 |
"2\n" |
|
| 41 |
"3\n" |
|
| 42 |
"4\n" |
|
| 43 |
"5\n" |
|
| 44 |
"6\n" |
|
| 45 |
"7\n" |
|
| 46 |
"@arcs\n" |
|
| 47 |
" len1 len2 len3 len4 c1 c2 c3 c4\n" |
|
| 48 |
"1 2 1 1 1 1 0 0 0 0\n" |
|
| 49 |
"2 4 5 5 5 5 1 0 0 0\n" |
|
| 50 |
"2 3 8 8 8 8 0 0 0 0\n" |
|
| 51 |
"3 2 -2 0 0 0 1 0 0 0\n" |
|
| 52 |
"3 4 4 4 4 4 0 0 0 0\n" |
|
| 53 |
"3 7 -4 -4 -4 -4 0 0 0 0\n" |
|
| 54 |
"4 1 2 2 2 2 0 0 0 0\n" |
|
| 55 |
"4 3 3 3 3 3 1 0 0 0\n" |
|
| 56 |
"4 4 3 3 0 0 0 0 1 0\n" |
|
| 57 |
"5 2 4 4 4 4 0 0 0 0\n" |
|
| 58 |
"5 6 3 3 3 3 0 1 0 0\n" |
|
| 59 |
"6 5 2 2 2 2 0 1 0 0\n" |
|
| 60 |
"6 4 -1 -1 -1 -1 0 0 0 0\n" |
|
| 61 |
"6 7 1 1 1 1 0 0 0 0\n" |
|
| 62 |
"7 7 4 4 4 -1 0 0 0 1\n"; |
|
| 63 |
|
|
| 64 |
|
|
| 65 |
// Check the interface of an MMC algorithm |
|
| 66 |
template <typename GR, typename Value> |
|
| 67 |
struct MmcClassConcept |
|
| 68 |
{
|
|
| 69 |
template <typename MMC> |
|
| 70 |
struct Constraints {
|
|
| 71 |
void constraints() {
|
|
| 72 |
const Constraints& me = *this; |
|
| 73 |
|
|
| 74 |
typedef typename MMC |
|
| 75 |
::template SetPath<ListPath<GR> > |
|
| 76 |
::template SetLargeValue<Value> |
|
| 77 |
::Create MmcAlg; |
|
| 78 |
MmcAlg mmc(me.g, me.length); |
|
| 79 |
const MmcAlg& const_mmc = mmc; |
|
| 80 |
|
|
| 81 |
typename MmcAlg::Tolerance tol = const_mmc.tolerance(); |
|
| 82 |
mmc.tolerance(tol); |
|
| 83 |
|
|
| 84 |
b = mmc.cycle(p).run(); |
|
| 85 |
b = mmc.findMinMean(); |
|
| 86 |
b = mmc.findCycle(); |
|
| 87 |
|
|
| 88 |
v = const_mmc.cycleLength(); |
|
| 89 |
i = const_mmc.cycleArcNum(); |
|
| 90 |
d = const_mmc.cycleMean(); |
|
| 91 |
p = const_mmc.cycle(); |
|
| 92 |
} |
|
| 93 |
|
|
| 94 |
typedef concepts::ReadMap<typename GR::Arc, Value> LM; |
|
| 95 |
|
|
| 96 |
GR g; |
|
| 97 |
LM length; |
|
| 98 |
ListPath<GR> p; |
|
| 99 |
Value v; |
|
| 100 |
int i; |
|
| 101 |
double d; |
|
| 102 |
bool b; |
|
| 103 |
}; |
|
| 104 |
}; |
|
| 105 |
|
|
| 106 |
// Perform a test with the given parameters |
|
| 107 |
template <typename MMC> |
|
| 108 |
void checkMmcAlg(const SmartDigraph& gr, |
|
| 109 |
const SmartDigraph::ArcMap<int>& lm, |
|
| 110 |
const SmartDigraph::ArcMap<int>& cm, |
|
| 111 |
int length, int size) {
|
|
| 112 |
MMC alg(gr, lm); |
|
| 113 |
alg.findMinMean(); |
|
| 114 |
check(alg.cycleMean() == static_cast<double>(length) / size, |
|
| 115 |
"Wrong cycle mean"); |
|
| 116 |
alg.findCycle(); |
|
| 117 |
check(alg.cycleLength() == length && alg.cycleArcNum() == size, |
|
| 118 |
"Wrong path"); |
|
| 119 |
SmartDigraph::ArcMap<int> cycle(gr, 0); |
|
| 120 |
for (typename MMC::Path::ArcIt a(alg.cycle()); a != INVALID; ++a) {
|
|
| 121 |
++cycle[a]; |
|
| 122 |
} |
|
| 123 |
for (SmartDigraph::ArcIt a(gr); a != INVALID; ++a) {
|
|
| 124 |
check(cm[a] == cycle[a], "Wrong path"); |
|
| 125 |
} |
|
| 126 |
} |
|
| 127 |
|
|
| 128 |
// Class for comparing types |
|
| 129 |
template <typename T1, typename T2> |
|
| 130 |
struct IsSameType {
|
|
| 131 |
static const int result = 0; |
|
| 132 |
}; |
|
| 133 |
|
|
| 134 |
template <typename T> |
|
| 135 |
struct IsSameType<T,T> {
|
|
| 136 |
static const int result = 1; |
|
| 137 |
}; |
|
| 138 |
|
|
| 139 |
|
|
| 140 |
int main() {
|
|
| 141 |
#ifdef LEMON_HAVE_LONG_LONG |
|
| 142 |
typedef long long long_int; |
|
| 143 |
#else |
|
| 144 |
typedef long long_int; |
|
| 145 |
#endif |
|
| 146 |
|
|
| 147 |
// Check the interface |
|
| 148 |
{
|
|
| 149 |
typedef concepts::Digraph GR; |
|
| 150 |
|
|
| 151 |
// Karp |
|
| 152 |
checkConcept< MmcClassConcept<GR, int>, |
|
| 153 |
Karp<GR, concepts::ReadMap<GR::Arc, int> > >(); |
|
| 154 |
checkConcept< MmcClassConcept<GR, float>, |
|
| 155 |
Karp<GR, concepts::ReadMap<GR::Arc, float> > >(); |
|
| 156 |
|
|
| 157 |
// HartmannOrlin |
|
| 158 |
checkConcept< MmcClassConcept<GR, int>, |
|
| 159 |
HartmannOrlin<GR, concepts::ReadMap<GR::Arc, int> > >(); |
|
| 160 |
checkConcept< MmcClassConcept<GR, float>, |
|
| 161 |
HartmannOrlin<GR, concepts::ReadMap<GR::Arc, float> > >(); |
|
| 162 |
|
|
| 163 |
// Howard |
|
| 164 |
checkConcept< MmcClassConcept<GR, int>, |
|
| 165 |
Howard<GR, concepts::ReadMap<GR::Arc, int> > >(); |
|
| 166 |
checkConcept< MmcClassConcept<GR, float>, |
|
| 167 |
Howard<GR, concepts::ReadMap<GR::Arc, float> > >(); |
|
| 168 |
|
|
| 169 |
if (IsSameType<Howard<GR, concepts::ReadMap<GR::Arc, int> >::LargeValue, |
|
| 170 |
long_int>::result == 0) check(false, "Wrong LargeValue type"); |
|
| 171 |
if (IsSameType<Howard<GR, concepts::ReadMap<GR::Arc, float> >::LargeValue, |
|
| 172 |
double>::result == 0) check(false, "Wrong LargeValue type"); |
|
| 173 |
} |
|
| 174 |
|
|
| 175 |
// Run various tests |
|
| 176 |
{
|
|
| 177 |
typedef SmartDigraph GR; |
|
| 178 |
DIGRAPH_TYPEDEFS(GR); |
|
| 179 |
|
|
| 180 |
GR gr; |
|
| 181 |
IntArcMap l1(gr), l2(gr), l3(gr), l4(gr); |
|
| 182 |
IntArcMap c1(gr), c2(gr), c3(gr), c4(gr); |
|
| 183 |
|
|
| 184 |
std::istringstream input(test_lgf); |
|
| 185 |
digraphReader(gr, input). |
|
| 186 |
arcMap("len1", l1).
|
|
| 187 |
arcMap("len2", l2).
|
|
| 188 |
arcMap("len3", l3).
|
|
| 189 |
arcMap("len4", l4).
|
|
| 190 |
arcMap("c1", c1).
|
|
| 191 |
arcMap("c2", c2).
|
|
| 192 |
arcMap("c3", c3).
|
|
| 193 |
arcMap("c4", c4).
|
|
| 194 |
run(); |
|
| 195 |
|
|
| 196 |
// Karp |
|
| 197 |
checkMmcAlg<Karp<GR, IntArcMap> >(gr, l1, c1, 6, 3); |
|
| 198 |
checkMmcAlg<Karp<GR, IntArcMap> >(gr, l2, c2, 5, 2); |
|
| 199 |
checkMmcAlg<Karp<GR, IntArcMap> >(gr, l3, c3, 0, 1); |
|
| 200 |
checkMmcAlg<Karp<GR, IntArcMap> >(gr, l4, c4, -1, 1); |
|
| 201 |
|
|
| 202 |
// HartmannOrlin |
|
| 203 |
checkMmcAlg<HartmannOrlin<GR, IntArcMap> >(gr, l1, c1, 6, 3); |
|
| 204 |
checkMmcAlg<HartmannOrlin<GR, IntArcMap> >(gr, l2, c2, 5, 2); |
|
| 205 |
checkMmcAlg<HartmannOrlin<GR, IntArcMap> >(gr, l3, c3, 0, 1); |
|
| 206 |
checkMmcAlg<HartmannOrlin<GR, IntArcMap> >(gr, l4, c4, -1, 1); |
|
| 207 |
|
|
| 208 |
// Howard |
|
| 209 |
checkMmcAlg<Howard<GR, IntArcMap> >(gr, l1, c1, 6, 3); |
|
| 210 |
checkMmcAlg<Howard<GR, IntArcMap> >(gr, l2, c2, 5, 2); |
|
| 211 |
checkMmcAlg<Howard<GR, IntArcMap> >(gr, l3, c3, 0, 1); |
|
| 212 |
checkMmcAlg<Howard<GR, IntArcMap> >(gr, l4, c4, -1, 1); |
|
| 213 |
} |
|
| 214 |
|
|
| 215 |
return 0; |
|
| 216 |
} |
| ... | ... |
@@ -17,6 +17,7 @@ |
| 17 | 17 |
cmake/FindCPLEX.cmake \ |
| 18 | 18 |
cmake/FindGLPK.cmake \ |
| 19 | 19 |
cmake/FindCOIN.cmake \ |
| 20 |
cmake/LEMONConfig.cmake.in \ |
|
| 20 | 21 |
cmake/version.cmake.in \ |
| 21 | 22 |
cmake/version.cmake \ |
| 22 | 23 |
cmake/nsis/lemon.ico \ |
| ... | ... |
@@ -43,6 +44,7 @@ |
| 43 | 44 |
include test/Makefile.am |
| 44 | 45 |
include doc/Makefile.am |
| 45 | 46 |
include tools/Makefile.am |
| 47 |
include scripts/Makefile.am |
|
| 46 | 48 |
|
| 47 | 49 |
DIST_SUBDIRS = demo |
| 48 | 50 |
| ... | ... |
@@ -41,6 +41,7 @@ |
| 41 | 41 |
AC_PROG_LIBTOOL |
| 42 | 42 |
|
| 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]) |
| 45 | 46 |
|
| 46 | 47 |
dnl Detect Intel compiler. |
| ... | ... |
@@ -82,6 +83,21 @@ |
| 82 | 83 |
fi |
| 83 | 84 |
AM_CONDITIONAL([WANT_TOOLS], [test x"$enable_tools" != x"no"]) |
| 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. |
| 86 | 102 |
AC_CHECK_HEADERS(limits.h sys/time.h sys/times.h unistd.h) |
| 87 | 103 |
|
| ... | ... |
@@ -127,6 +143,7 @@ |
| 127 | 143 |
echo CBC support................... : $lx_cbc_found |
| 128 | 144 |
echo |
| 129 | 145 |
echo Build additional tools........ : $enable_tools |
| 146 |
echo Use valgrind for tests........ : $use_valgrind |
|
| 130 | 147 |
echo |
| 131 | 148 |
echo The packace will be installed in |
| 132 | 149 |
echo -n ' ' |
| ... | ... |
@@ -9,7 +9,7 @@ |
| 9 | 9 |
@ONLY |
| 10 | 10 |
) |
| 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/)
|
| 14 | 14 |
SET(GHOSTSCRIPT_OPTIONS -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha) |
| 15 | 15 |
ADD_CUSTOM_TARGET(html |
| ... | ... |
@@ -28,6 +28,7 @@ |
| 28 | 28 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_4.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_4.eps
|
| 29 | 29 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/strongly_connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/strongly_connected_components.eps
|
| 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
|
| 32 | 33 |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
| 33 | 34 |
) |
| 1 |
# Doxyfile 1.5. |
|
| 1 |
# Doxyfile 1.5.9 |
|
| 2 | 2 |
|
| 3 | 3 |
#--------------------------------------------------------------------------- |
| 4 | 4 |
# Project related configuration options |
| ... | ... |
@@ -21,7 +21,6 @@ |
| 21 | 21 |
JAVADOC_AUTOBRIEF = NO |
| 22 | 22 |
QT_AUTOBRIEF = NO |
| 23 | 23 |
MULTILINE_CPP_IS_BRIEF = NO |
| 24 |
DETAILS_AT_TOP = YES |
|
| 25 | 24 |
INHERIT_DOCS = NO |
| 26 | 25 |
SEPARATE_MEMBER_PAGES = NO |
| 27 | 26 |
TAB_SIZE = 8 |
| ... | ... |
@@ -91,7 +90,8 @@ |
| 91 | 90 |
"@abs_top_srcdir@/lemon/concepts" \ |
| 92 | 91 |
"@abs_top_srcdir@/demo" \ |
| 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 |
| 96 | 96 |
FILE_PATTERNS = *.h \ |
| 97 | 97 |
*.cc \ |
| ... | ... |
@@ -223,7 +223,7 @@ |
| 223 | 223 |
EXPAND_AS_DEFINED = |
| 224 | 224 |
SKIP_FUNCTION_MACROS = YES |
| 225 | 225 |
#--------------------------------------------------------------------------- |
| 226 |
# |
|
| 226 |
# Options related to the search engine |
|
| 227 | 227 |
#--------------------------------------------------------------------------- |
| 228 | 228 |
TAGFILES = "@abs_top_srcdir@/doc/libstdc++.tag = http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/ " |
| 229 | 229 |
GENERATE_TAGFILE = html/lemon.tag |
| ... | ... |
@@ -66,7 +66,19 @@ |
| 66 | 66 |
exit 1; \ |
| 67 | 67 |
fi |
| 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 \
|
| 71 | 83 |
cd doc; \ |
| 72 | 84 |
doxygen Doxyfile; \ |
| ... | ... |
@@ -280,6 +280,28 @@ |
| 280 | 280 |
*/ |
| 281 | 281 |
|
| 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 |
| 284 | 306 |
\brief This group contains the several algorithms |
| 285 | 307 |
implemented in LEMON. |
| ... | ... |
@@ -294,7 +316,8 @@ |
| 294 | 316 |
\brief Common graph search algorithms. |
| 295 | 317 |
|
| 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 |
*/ |
| 299 | 322 |
|
| 300 | 323 |
/** |
| ... | ... |
@@ -302,7 +325,8 @@ |
| 302 | 325 |
@ingroup algs |
| 303 | 326 |
\brief Algorithms for finding shortest paths. |
| 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 |
|
| 307 | 331 |
- \ref Dijkstra algorithm for finding shortest paths from a source node |
| 308 | 332 |
when all arc lengths are non-negative. |
| ... | ... |
@@ -319,12 +343,21 @@ |
| 319 | 343 |
*/ |
| 320 | 344 |
|
| 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 |
| 323 | 356 |
@ingroup algs |
| 324 | 357 |
\brief Algorithms for finding maximum flows. |
| 325 | 358 |
|
| 326 | 359 |
This group contains the algorithms for finding maximum flows and |
| 327 |
feasible circulations. |
|
| 360 |
feasible circulations \ref clrs01algorithms, \ref amo93networkflows. |
|
| 328 | 361 |
|
| 329 | 362 |
The \e maximum \e flow \e problem is to find a flow of maximum value between |
| 330 | 363 |
a single source and a single target. Formally, there is a \f$G=(V,A)\f$ |
| ... | ... |
@@ -339,12 +372,16 @@ |
| 339 | 372 |
\f[ 0 \leq f(uv) \leq cap(uv) \quad \forall uv\in A \f] |
| 340 | 373 |
|
| 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 |
| 349 | 386 |
also provide functions to query the minimum cut, which is the dual |
| 350 | 387 |
problem of maximum flow. |
| ... | ... |
@@ -362,18 +399,22 @@ |
| 362 | 399 |
\brief Algorithms for finding minimum cost flows and circulations. |
| 363 | 400 |
|
| 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 |
|
| 368 | 406 |
LEMON contains several algorithms for this problem. |
| 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 |
|
| 378 | 419 |
In general NetworkSimplex is the most efficient implementation, |
| 379 | 420 |
but in special cases other algorithms could be faster. |
| ... | ... |
@@ -396,7 +437,7 @@ |
| 396 | 437 |
cut is the \f$X\f$ solution of the next optimization problem: |
| 397 | 438 |
|
| 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 |
|
| 401 | 442 |
LEMON contains several algorithms related to minimum cut problems: |
| 402 | 443 |
|
| ... | ... |
@@ -412,27 +453,40 @@ |
| 412 | 453 |
*/ |
| 413 | 454 |
|
| 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 |
*/ |
| 437 | 491 |
|
| 438 | 492 |
/** |
| ... | ... |
@@ -476,12 +530,36 @@ |
| 476 | 530 |
*/ |
| 477 | 531 |
|
| 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 |
*/ |
| 486 | 564 |
|
| 487 | 565 |
/** |
| ... | ... |
@@ -494,15 +572,6 @@ |
| 494 | 572 |
*/ |
| 495 | 573 |
|
| 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 |
| 507 | 576 |
\brief This group contains some general optimization frameworks |
| 508 | 577 |
implemented in LEMON. |
| ... | ... |
@@ -512,13 +581,16 @@ |
| 512 | 581 |
*/ |
| 513 | 582 |
|
| 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 |
*/ |
| 523 | 595 |
|
| 524 | 596 |
/** |
| ... | ... |
@@ -608,7 +680,7 @@ |
| 608 | 680 |
*/ |
| 609 | 681 |
|
| 610 | 682 |
/** |
| 611 |
@defgroup dimacs_group DIMACS |
|
| 683 |
@defgroup dimacs_group DIMACS Format |
|
| 612 | 684 |
@ingroup io_group |
| 613 | 685 |
\brief Read and write files in DIMACS format |
| 614 | 686 |
|
| ... | ... |
@@ -657,8 +729,8 @@ |
| 657 | 729 |
@ingroup concept |
| 658 | 730 |
\brief Skeleton and concept checking classes for graph structures |
| 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 |
*/ |
| 663 | 735 |
|
| 664 | 736 |
/** |
| ... | ... |
@@ -670,6 +742,15 @@ |
| 670 | 742 |
*/ |
| 671 | 743 |
|
| 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 |
| 674 | 755 |
|
| 675 | 756 |
@defgroup demos Demo Programs |
| ... | ... |
@@ -681,13 +762,4 @@ |
| 681 | 762 |
<tt>make check</tt> commands. |
| 682 | 763 |
*/ |
| 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 |
} |
| ... | ... |
@@ -21,14 +21,11 @@ |
| 21 | 21 |
|
| 22 | 22 |
\section intro Introduction |
| 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 |
|
| 33 | 30 |
<b> |
| 34 | 31 |
LEMON is an <a class="el" href="http://opensource.org/">open source</a> |
| ... | ... |
@@ -38,7 +35,16 @@ |
| 38 | 35 |
\ref license "license terms". |
| 39 | 36 |
</b> |
| 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 |
|
| 43 | 49 |
If you would like to get to know the library, see |
| 44 | 50 |
<a class="el" href="http://lemon.cs.elte.hu/pub/tutorial/">LEMON Tutorial</a>. |
| ... | ... |
@@ -26,7 +26,7 @@ |
| 26 | 26 |
The \e minimum \e cost \e flow \e problem is to find a feasible flow of |
| 27 | 27 |
minimum total cost from a set of supply nodes to a set of demand nodes |
| 28 | 28 |
in a network with capacity constraints (lower and upper bounds) |
| 29 |
and arc costs. |
|
| 29 |
and arc costs \ref amo93networkflows. |
|
| 30 | 30 |
|
| 31 | 31 |
Formally, let \f$G=(V,A)\f$ be a digraph, \f$lower: A\rightarrow\mathbf{R}\f$,
|
| 32 | 32 |
\f$upper: A\rightarrow\mathbf{R}\cup\{+\infty\}\f$ denote the lower and
|
| ... | ... |
@@ -78,7 +78,7 @@ |
| 78 | 78 |
- if \f$lower(uv)<f(uv)<upper(uv)\f$, then \f$cost^\pi(uv)=0\f$; |
| 79 | 79 |
- if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$. |
| 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$,
|
| 83 | 83 |
then \f$\pi(u)=0\f$. |
| 84 | 84 |
|
| ... | ... |
@@ -145,7 +145,7 @@ |
| 145 | 145 |
- if \f$lower(uv)<f(uv)<upper(uv)\f$, then \f$cost^\pi(uv)=0\f$; |
| 146 | 146 |
- if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$. |
| 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$,
|
| 150 | 150 |
then \f$\pi(u)=0\f$. |
| 151 | 151 |
| ... | ... |
@@ -86,7 +86,10 @@ |
| 86 | 86 |
lemon/gomory_hu.h \ |
| 87 | 87 |
lemon/graph_to_eps.h \ |
| 88 | 88 |
lemon/grid_graph.h \ |
| 89 |
lemon/hartmann_orlin.h \ |
|
| 90 |
lemon/howard.h \ |
|
| 89 | 91 |
lemon/hypercube_graph.h \ |
| 92 |
lemon/karp.h \ |
|
| 90 | 93 |
lemon/kary_heap.h \ |
| 91 | 94 |
lemon/kruskal.h \ |
| 92 | 95 |
lemon/hao_orlin.h \ |
| ... | ... |
@@ -111,6 +114,7 @@ |
| 111 | 114 |
lemon/random.h \ |
| 112 | 115 |
lemon/smart_graph.h \ |
| 113 | 116 |
lemon/soplex.h \ |
| 117 |
lemon/static_graph.h \ |
|
| 114 | 118 |
lemon/suurballe.h \ |
| 115 | 119 |
lemon/time_measure.h \ |
| 116 | 120 |
lemon/tolerance.h \ |
| ... | ... |
@@ -360,6 +360,9 @@ |
| 360 | 360 |
/// by adding or removing nodes or arcs, unless the \c GR template |
| 361 | 361 |
/// parameter is set to be \c const. |
| 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. |
| 364 | 367 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
| 365 | 368 |
/// It can also be specified to be \c const. |
| ... | ... |
@@ -719,6 +722,8 @@ |
| 719 | 722 |
/// by adding or removing nodes or arcs, unless the \c GR template |
| 720 | 723 |
/// parameter is set to be \c const. |
| 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. |
| 723 | 728 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
| 724 | 729 |
/// It can also be specified to be \c const. |
| ... | ... |
@@ -1314,6 +1319,8 @@ |
| 1314 | 1319 |
/// by adding or removing nodes or edges, unless the \c GR template |
| 1315 | 1320 |
/// parameter is set to be \c const. |
| 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. |
| 1318 | 1325 |
/// It must conform to the \ref concepts::Graph "Graph" concept. |
| 1319 | 1326 |
/// It can also be specified to be \c const. |
| ... | ... |
@@ -1471,6 +1478,8 @@ |
| 1471 | 1478 |
/// by adding or removing nodes or arcs/edges, unless the \c GR template |
| 1472 | 1479 |
/// parameter is set to be \c const. |
| 1473 | 1480 |
/// |
| 1481 |
/// This class provides only linear time item counting. |
|
| 1482 |
/// |
|
| 1474 | 1483 |
/// \tparam GR The type of the adapted digraph or graph. |
| 1475 | 1484 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept |
| 1476 | 1485 |
/// or the \ref concepts::Graph "Graph" concept. |
| ... | ... |
@@ -1619,6 +1628,8 @@ |
| 1619 | 1628 |
/// by adding or removing nodes or arcs, unless the \c GR template |
| 1620 | 1629 |
/// parameter is set to be \c const. |
| 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. |
| 1623 | 1634 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
| 1624 | 1635 |
/// It can also be specified to be \c const. |
| ... | ... |
@@ -1729,6 +1740,8 @@ |
| 1729 | 1740 |
/// by adding or removing nodes or edges, unless the \c GR template |
| 1730 | 1741 |
/// parameter is set to be \c const. |
| 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. |
| 1733 | 1746 |
/// It must conform to the \ref concepts::Graph "Graph" concept. |
| 1734 | 1747 |
/// It can also be specified to be \c const. |
| ... | ... |
@@ -2232,6 +2245,9 @@ |
| 2232 | 2245 |
/// by adding or removing nodes or edges, unless the \c GR template |
| 2233 | 2246 |
/// parameter is set to be \c const. |
| 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. |
| 2236 | 2252 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
| 2237 | 2253 |
/// It can also be specified to be \c const. |
| ... | ... |
@@ -2535,6 +2551,9 @@ |
| 2535 | 2551 |
/// by adding or removing nodes or arcs, unless the \c GR template |
| 2536 | 2552 |
/// parameter is set to be \c const. |
| 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. |
| 2539 | 2558 |
/// It must conform to the \ref concepts::Graph "Graph" concept. |
| 2540 | 2559 |
/// It can also be specified to be \c const. |
| ... | ... |
@@ -2678,6 +2697,8 @@ |
| 2678 | 2697 |
/// arcs). |
| 2679 | 2698 |
/// This class conforms to the \ref concepts::Digraph "Digraph" concept. |
| 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. |
| 2682 | 2703 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
| 2683 | 2704 |
/// It is implicitly \c const. |
| ... | ... |
@@ -3325,6 +3346,9 @@ |
| 3325 | 3346 |
/// costs/capacities of the original digraph to the \e bind \e arcs |
| 3326 | 3347 |
/// in the adaptor. |
| 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. |
| 3329 | 3353 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
| 3330 | 3354 |
/// It is implicitly \c const. |
| ... | ... |
@@ -23,6 +23,7 @@ |
| 23 | 23 |
/// \file |
| 24 | 24 |
/// \brief Bellman-Ford algorithm. |
| 25 | 25 |
|
| 26 |
#include <lemon/list_graph.h> |
|
| 26 | 27 |
#include <lemon/bits/path_dump.h> |
| 27 | 28 |
#include <lemon/core.h> |
| 28 | 29 |
#include <lemon/error.h> |
| ... | ... |
@@ -299,7 +300,7 @@ |
| 299 | 300 |
/// |
| 300 | 301 |
/// \ref named-templ-param "Named parameter" for setting |
| 301 | 302 |
/// \c OperationTraits type. |
| 302 |
/// For more information see \ref BellmanFordDefaultOperationTraits. |
|
| 303 |
/// For more information, see \ref BellmanFordDefaultOperationTraits. |
|
| 303 | 304 |
template <class T> |
| 304 | 305 |
struct SetOperationTraits |
| 305 | 306 |
: public BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> > {
|
| ... | ... |
@@ -717,7 +718,7 @@ |
| 717 | 718 |
/// is not reached from the root(s) or if \c v is a root. |
| 718 | 719 |
/// |
| 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 |
/// |
| 722 | 723 |
/// \pre Either \ref run() or \ref init() must be called before |
| 723 | 724 |
/// using this function. |
| ... | ... |
@@ -732,7 +733,7 @@ |
| 732 | 733 |
/// is not reached from the root(s) or if \c v is a root. |
| 733 | 734 |
/// |
| 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 |
/// |
| 737 | 738 |
/// \pre Either \ref run() or \ref init() must be called before |
| 738 | 739 |
/// using this function. |
| ... | ... |
@@ -775,7 +776,7 @@ |
| 775 | 776 |
/// This function gives back a directed cycle with negative total |
| 776 | 777 |
/// length if the algorithm has already found one. |
| 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); |
| 780 | 781 |
lemon::Path<Digraph> cycle; |
| 781 | 782 |
for (int i = 0; i < int(_process.size()); ++i) {
|
| ... | ... |
@@ -47,7 +47,7 @@ |
| 47 | 47 |
/// |
| 48 | 48 |
///The type of the map that stores the predecessor |
| 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; |
| 52 | 52 |
///Instantiates a \c PredMap. |
| 53 | 53 |
|
| ... | ... |
@@ -62,7 +62,8 @@ |
| 62 | 62 |
///The type of the map that indicates which nodes are processed. |
| 63 | 63 |
|
| 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; |
| 67 | 68 |
///Instantiates a \c ProcessedMap. |
| 68 | 69 |
|
| ... | ... |
@@ -81,7 +82,7 @@ |
| 81 | 82 |
///The type of the map that indicates which nodes are reached. |
| 82 | 83 |
|
| 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; |
| 86 | 87 |
///Instantiates a \c ReachedMap. |
| 87 | 88 |
|
| ... | ... |
@@ -96,7 +97,7 @@ |
| 96 | 97 |
///The type of the map that stores the distances of the nodes. |
| 97 | 98 |
|
| 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; |
| 101 | 102 |
///Instantiates a \c DistMap. |
| 102 | 103 |
|
| ... | ... |
@@ -225,7 +226,7 @@ |
| 225 | 226 |
/// |
| 226 | 227 |
///\ref named-templ-param "Named parameter" for setting |
| 227 | 228 |
///\c PredMap type. |
| 228 |
///It must |
|
| 229 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
| 229 | 230 |
template <class T> |
| 230 | 231 |
struct SetPredMap : public Bfs< Digraph, SetPredMapTraits<T> > {
|
| 231 | 232 |
typedef Bfs< Digraph, SetPredMapTraits<T> > Create; |
| ... | ... |
@@ -245,7 +246,7 @@ |
| 245 | 246 |
/// |
| 246 | 247 |
///\ref named-templ-param "Named parameter" for setting |
| 247 | 248 |
///\c DistMap type. |
| 248 |
///It must |
|
| 249 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
| 249 | 250 |
template <class T> |
| 250 | 251 |
struct SetDistMap : public Bfs< Digraph, SetDistMapTraits<T> > {
|
| 251 | 252 |
typedef Bfs< Digraph, SetDistMapTraits<T> > Create; |
| ... | ... |
@@ -265,7 +266,7 @@ |
| 265 | 266 |
/// |
| 266 | 267 |
///\ref named-templ-param "Named parameter" for setting |
| 267 | 268 |
///\c ReachedMap type. |
| 268 |
///It must |
|
| 269 |
///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
| 269 | 270 |
template <class T> |
| 270 | 271 |
struct SetReachedMap : public Bfs< Digraph, SetReachedMapTraits<T> > {
|
| 271 | 272 |
typedef Bfs< Digraph, SetReachedMapTraits<T> > Create; |
| ... | ... |
@@ -285,7 +286,7 @@ |
| 285 | 286 |
/// |
| 286 | 287 |
///\ref named-templ-param "Named parameter" for setting |
| 287 | 288 |
///\c ProcessedMap type. |
| 288 |
///It must |
|
| 289 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
| 289 | 290 |
template <class T> |
| 290 | 291 |
struct SetProcessedMap : public Bfs< Digraph, SetProcessedMapTraits<T> > {
|
| 291 | 292 |
typedef Bfs< Digraph, SetProcessedMapTraits<T> > Create; |
| ... | ... |
@@ -413,8 +414,8 @@ |
| 413 | 414 |
///\name Execution Control |
| 414 | 415 |
///The simplest way to execute the BFS algorithm is to use one of the |
| 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 |
| 419 | 420 |
///performed with one of the \ref start() functions. |
| 420 | 421 |
|
| ... | ... |
@@ -700,12 +701,8 @@ |
| 700 | 701 |
|
| 701 | 702 |
///Runs the algorithm to visit all nodes in the digraph. |
| 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 |
/// |
| 710 | 707 |
///\note <tt>b.run(s)</tt> is just a shortcut of the following code. |
| 711 | 708 |
///\code |
| ... | ... |
@@ -737,9 +734,9 @@ |
| 737 | 734 |
|
| 738 | 735 |
///@{
|
| 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 |
/// |
| 744 | 741 |
///\warning \c t should be reached from the root(s). |
| 745 | 742 |
/// |
| ... | ... |
@@ -747,9 +744,9 @@ |
| 747 | 744 |
///must be called before using this function. |
| 748 | 745 |
Path path(Node t) const { return Path(*G, *_pred, t); }
|
| 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 |
/// |
| 754 | 751 |
///\warning If node \c v is not reached from the root(s), then |
| 755 | 752 |
///the return value of this function is undefined. |
| ... | ... |
@@ -758,29 +755,31 @@ |
| 758 | 755 |
///must be called before using this function. |
| 759 | 756 |
int dist(Node v) const { return (*_dist)[v]; }
|
| 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 |
| 764 | 762 |
///tree for the node \c v, i.e. it returns the last arc of a |
| 765 | 763 |
///shortest path from a root to \c v. It is \c INVALID if \c v |
| 766 | 764 |
///is not reached from the root(s) or if \c v is a root. |
| 767 | 765 |
/// |
| 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 |
/// |
| 771 | 769 |
///\pre Either \ref run(Node) "run()" or \ref init() |
| 772 | 770 |
///must be called before using this function. |
| 773 | 771 |
Arc predArc(Node v) const { return (*_pred)[v];}
|
| 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. |
| 781 | 780 |
/// |
| 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 |
/// |
| 785 | 784 |
///\pre Either \ref run(Node) "run()" or \ref init() |
| 786 | 785 |
///must be called before using this function. |
| ... | ... |
@@ -801,13 +800,13 @@ |
| 801 | 800 |
///predecessor arcs. |
| 802 | 801 |
/// |
| 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 |
/// |
| 806 | 805 |
///\pre Either \ref run(Node) "run()" or \ref init() |
| 807 | 806 |
///must be called before using this function. |
| 808 | 807 |
const PredMap &predMap() const { return *_pred;}
|
| 809 | 808 |
|
| 810 |
///Checks if |
|
| 809 |
///Checks if the given node is reached from the root(s). |
|
| 811 | 810 |
|
| 812 | 811 |
///Returns \c true if \c v is reached from the root(s). |
| 813 | 812 |
/// |
| ... | ... |
@@ -833,7 +832,7 @@ |
| 833 | 832 |
/// |
| 834 | 833 |
///The type of the map that stores the predecessor |
| 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; |
| 838 | 837 |
///Instantiates a PredMap. |
| 839 | 838 |
|
| ... | ... |
@@ -848,8 +847,8 @@ |
| 848 | 847 |
///The type of the map that indicates which nodes are processed. |
| 849 | 848 |
|
| 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; |
| 854 | 853 |
///Instantiates a ProcessedMap. |
| 855 | 854 |
|
| ... | ... |
@@ -868,7 +867,7 @@ |
| 868 | 867 |
///The type of the map that indicates which nodes are reached. |
| 869 | 868 |
|
| 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; |
| 873 | 872 |
///Instantiates a ReachedMap. |
| 874 | 873 |
|
| ... | ... |
@@ -883,7 +882,7 @@ |
| 883 | 882 |
///The type of the map that stores the distances of the nodes. |
| 884 | 883 |
|
| 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; |
| 888 | 887 |
///Instantiates a DistMap. |
| 889 | 888 |
|
| ... | ... |
@@ -898,18 +897,14 @@ |
| 898 | 897 |
///The type of the shortest paths. |
| 899 | 898 |
|
| 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; |
| 903 | 902 |
}; |
| 904 | 903 |
|
| 905 | 904 |
/// Default traits class used by BfsWizard |
| 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> |
| 914 | 909 |
class BfsWizardBase : public BfsWizardDefaultTraits<GR> |
| 915 | 910 |
{
|
| ... | ... |
@@ -937,7 +932,7 @@ |
| 937 | 932 |
public: |
| 938 | 933 |
/// Constructor. |
| 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. |
| 942 | 937 |
BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0), |
| 943 | 938 |
_dist(0), _path(0), _di(0) {}
|
| ... | ... |
@@ -967,7 +962,6 @@ |
| 967 | 962 |
{
|
| 968 | 963 |
typedef TR Base; |
| 969 | 964 |
|
| 970 |
///The type of the digraph the algorithm runs on. |
|
| 971 | 965 |
typedef typename TR::Digraph Digraph; |
| 972 | 966 |
|
| 973 | 967 |
typedef typename Digraph::Node Node; |
| ... | ... |
@@ -975,16 +969,10 @@ |
| 975 | 969 |
typedef typename Digraph::Arc Arc; |
| 976 | 970 |
typedef typename Digraph::OutArcIt OutArcIt; |
| 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; |
| 989 | 977 |
|
| 990 | 978 |
public: |
| ... | ... |
@@ -1054,8 +1042,8 @@ |
| 1054 | 1042 |
|
| 1055 | 1043 |
///Runs BFS algorithm to visit all nodes in the digraph. |
| 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() |
| 1060 | 1048 |
{
|
| 1061 | 1049 |
run(INVALID); |
| ... | ... |
@@ -1067,11 +1055,12 @@ |
| 1067 | 1055 |
static PredMap *createPredMap(const Digraph &) { return 0; };
|
| 1068 | 1056 |
SetPredMapBase(const TR &b) : TR(b) {}
|
| 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> |
| 1076 | 1065 |
BfsWizard<SetPredMapBase<T> > predMap(const T &t) |
| 1077 | 1066 |
{
|
| ... | ... |
@@ -1085,11 +1074,12 @@ |
| 1085 | 1074 |
static ReachedMap *createReachedMap(const Digraph &) { return 0; };
|
| 1086 | 1075 |
SetReachedMapBase(const TR &b) : TR(b) {}
|
| 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> |
| 1094 | 1084 |
BfsWizard<SetReachedMapBase<T> > reachedMap(const T &t) |
| 1095 | 1085 |
{
|
| ... | ... |
@@ -1103,11 +1093,13 @@ |
| 1103 | 1093 |
static DistMap *createDistMap(const Digraph &) { return 0; };
|
| 1104 | 1094 |
SetDistMapBase(const TR &b) : TR(b) {}
|
| 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> |
| 1112 | 1104 |
BfsWizard<SetDistMapBase<T> > distMap(const T &t) |
| 1113 | 1105 |
{
|
| ... | ... |
@@ -1121,11 +1113,12 @@ |
| 1121 | 1113 |
static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
|
| 1122 | 1114 |
SetProcessedMapBase(const TR &b) : TR(b) {}
|
| 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> |
| 1130 | 1123 |
BfsWizard<SetProcessedMapBase<T> > processedMap(const T &t) |
| 1131 | 1124 |
{
|
| ... | ... |
@@ -1264,7 +1257,7 @@ |
| 1264 | 1257 |
/// \brief The type of the map that indicates which nodes are reached. |
| 1265 | 1258 |
/// |
| 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; |
| 1269 | 1262 |
|
| 1270 | 1263 |
/// \brief Instantiates a ReachedMap. |
| ... | ... |
@@ -1425,8 +1418,8 @@ |
| 1425 | 1418 |
/// \name Execution Control |
| 1426 | 1419 |
/// The simplest way to execute the BFS algorithm is to use one of the |
| 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 |
| 1431 | 1424 |
/// performed with one of the \ref start() functions. |
| 1432 | 1425 |
|
| ... | ... |
@@ -1698,12 +1691,8 @@ |
| 1698 | 1691 |
|
| 1699 | 1692 |
/// \brief Runs the algorithm to visit all nodes in the digraph. |
| 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 |
/// |
| 1708 | 1697 |
/// \note <tt>b.run(s)</tt> is just a shortcut of the following code. |
| 1709 | 1698 |
///\code |
| ... | ... |
@@ -1735,7 +1724,7 @@ |
| 1735 | 1724 |
|
| 1736 | 1725 |
///@{
|
| 1737 | 1726 |
|
| 1738 |
/// \brief Checks if |
|
| 1727 |
/// \brief Checks if the given node is reached from the root(s). |
|
| 1739 | 1728 |
/// |
| 1740 | 1729 |
/// Returns \c true if \c v is reached from the root(s). |
| 1741 | 1730 |
/// |
| ... | ... |
@@ -56,11 +56,11 @@ |
| 56 | 56 |
return Parent::maxArcId(); |
| 57 | 57 |
} |
| 58 | 58 |
|
| 59 |
Node fromId(int id, Node) |
|
| 59 |
static Node fromId(int id, Node) {
|
|
| 60 | 60 |
return Parent::nodeFromId(id); |
| 61 | 61 |
} |
| 62 | 62 |
|
| 63 |
Arc fromId(int id, Arc) |
|
| 63 |
static Arc fromId(int id, Arc) {
|
|
| 64 | 64 |
return Parent::arcFromId(id); |
| 65 | 65 |
} |
| 66 | 66 |
|
| ... | ... |
@@ -355,15 +355,15 @@ |
| 355 | 355 |
return Parent::maxEdgeId(); |
| 356 | 356 |
} |
| 357 | 357 |
|
| 358 |
Node fromId(int id, Node) |
|
| 358 |
static Node fromId(int id, Node) {
|
|
| 359 | 359 |
return Parent::nodeFromId(id); |
| 360 | 360 |
} |
| 361 | 361 |
|
| 362 |
Arc fromId(int id, Arc) |
|
| 362 |
static Arc fromId(int id, Arc) {
|
|
| 363 | 363 |
return Parent::arcFromId(id); |
| 364 | 364 |
} |
| 365 | 365 |
|
| 366 |
Edge fromId(int id, Edge) |
|
| 366 |
static Edge fromId(int id, Edge) {
|
|
| 367 | 367 |
return Parent::edgeFromId(id); |
| 368 | 368 |
} |
| 369 | 369 |
| ... | ... |
@@ -49,6 +49,8 @@ |
| 49 | 49 |
typedef typename Parent::Reference Reference; |
| 50 | 50 |
typedef typename Parent::ConstReference ConstReference; |
| 51 | 51 |
|
| 52 |
typedef typename Parent::ReferenceMapTag ReferenceMapTag; |
|
| 53 |
|
|
| 52 | 54 |
class MapIt; |
| 53 | 55 |
class ConstMapIt; |
| 54 | 56 |
|
| ... | ... |
@@ -191,6 +193,8 @@ |
| 191 | 193 |
typedef typename Parent::Reference Reference; |
| 192 | 194 |
typedef typename Parent::ConstReference ConstReference; |
| 193 | 195 |
|
| 196 |
typedef typename Parent::ReferenceMapTag ReferenceMapTag; |
|
| 197 |
|
|
| 194 | 198 |
class MapIt; |
| 195 | 199 |
class ConstMapIt; |
| 196 | 200 |
| ... | ... |
@@ -94,6 +94,18 @@ |
| 94 | 94 |
return _prob->numberRows() - 1; |
| 95 | 95 |
} |
| 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 |
|
| 98 | 110 |
void CbcMip::_eraseCol(int i) {
|
| 99 | 111 |
_prob->deleteColumn(i); |
| ... | ... |
@@ -72,7 +72,11 @@ |
| 72 | 72 |
/// The type of the map that stores the flow values. |
| 73 | 73 |
/// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" |
| 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 |
|
| 77 | 81 |
/// \brief Instantiates a FlowMap. |
| 78 | 82 |
/// |
| ... | ... |
@@ -87,9 +91,12 @@ |
| 87 | 91 |
/// |
| 88 | 92 |
/// The elevator type used by the algorithm. |
| 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 |
|
| 94 | 101 |
/// \brief Instantiates an Elevator. |
| 95 | 102 |
/// |
| ... | ... |
@@ -299,7 +306,7 @@ |
| 299 | 306 |
/// The Elevator should have standard constructor interface to be |
| 300 | 307 |
/// able to automatically created by the algorithm (i.e. the |
| 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 |
| 304 | 311 |
/// before calling \ref run() or \ref init(). |
| 305 | 312 |
/// \sa SetElevator |
| ... | ... |
@@ -469,8 +476,8 @@ |
| 469 | 476 |
|
| 470 | 477 |
/// \name Execution Control |
| 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. |
| 475 | 482 |
|
| 476 | 483 |
///@{
|
| ... | ... |
@@ -78,6 +78,19 @@ |
| 78 | 78 |
return _prob->numberRows() - 1; |
| 79 | 79 |
} |
| 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 |
|
| 82 | 95 |
void ClpLp::_eraseCol(int c) {
|
| 83 | 96 |
_col_names_ref.erase(_prob->getColumnName(c)); |
| ... | ... |
@@ -35,46 +35,40 @@ |
| 35 | 35 |
/// |
| 36 | 36 |
/// \brief Class describing the concept of directed graphs. |
| 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 |
|
| 69 | 63 |
/// This class identifies a node of the digraph. It also serves |
| 70 | 64 |
/// as a base class of the node iterators, |
| 71 |
/// thus they |
|
| 65 |
/// thus they convert to this type. |
|
| 72 | 66 |
class Node {
|
| 73 | 67 |
public: |
| 74 | 68 |
/// Default constructor |
| 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() { }
|
| 79 | 73 |
/// Copy constructor. |
| 80 | 74 |
|
| ... | ... |
@@ -82,40 +76,39 @@ |
| 82 | 76 |
/// |
| 83 | 77 |
Node(const Node&) { }
|
| 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. |
| 89 | 83 |
Node(Invalid) { }
|
| 90 | 84 |
/// Equality operator |
| 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; }
|
| 95 | 91 |
|
| 96 | 92 |
/// Inequality operator |
| 97 | 93 |
|
| 98 |
/// \sa operator==(Node n) |
|
| 99 |
/// |
|
| 94 |
/// Inequality operator. |
|
| 100 | 95 |
bool operator!=(Node) const { return true; }
|
| 101 | 96 |
|
| 102 | 97 |
/// Artificial ordering operator. |
| 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 |
| 120 | 113 |
/// int count=0; |
| 121 | 114 |
/// for (Digraph::NodeIt n(g); n!=INVALID; ++n) ++count; |
| ... | ... |
@@ -124,30 +117,28 @@ |
| 124 | 117 |
public: |
| 125 | 118 |
/// Default constructor |
| 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() { }
|
| 130 | 123 |
/// Copy constructor. |
| 131 | 124 |
|
| 132 | 125 |
/// Copy constructor. |
| 133 | 126 |
/// |
| 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. |
| 139 | 132 |
NodeIt(Invalid) { }
|
| 140 | 133 |
/// Sets the iterator to the first node. |
| 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&) { }
|
| 152 | 143 |
/// Next node. |
| 153 | 144 |
|
| ... | ... |
@@ -157,7 +148,7 @@ |
| 157 | 148 |
}; |
| 158 | 149 |
|
| 159 | 150 |
|
| 160 |
/// |
|
| 151 |
/// The arc type of the digraph |
|
| 161 | 152 |
|
| 162 | 153 |
/// This class identifies an arc of the digraph. It also serves |
| 163 | 154 |
/// as a base class of the arc iterators, |
| ... | ... |
@@ -166,207 +157,214 @@ |
| 166 | 157 |
public: |
| 167 | 158 |
/// Default constructor |
| 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() { }
|
| 172 | 163 |
/// Copy constructor. |
| 173 | 164 |
|
| 174 | 165 |
/// Copy constructor. |
| 175 | 166 |
/// |
| 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) { }
|
| 182 | 173 |
/// Equality operator |
| 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; }
|
| 187 | 180 |
/// Inequality operator |
| 188 | 181 |
|
| 189 |
/// \sa operator==(Arc n) |
|
| 190 |
/// |
|
| 182 |
/// Inequality operator. |
|
| 191 | 183 |
bool operator!=(Arc) const { return true; }
|
| 192 | 184 |
|
| 193 | 185 |
/// Artificial ordering operator. |
| 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; }
|
| 202 | 193 |
}; |
| 203 | 194 |
|
| 204 |
/// |
|
| 195 |
/// Iterator class for the outgoing arcs of a node. |
|
| 205 | 196 |
|
| 206 | 197 |
/// This iterator goes trough the \e outgoing arcs of a certain node |
| 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 {
|
| 217 | 207 |
public: |
| 218 | 208 |
/// Default constructor |
| 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() { }
|
| 223 | 213 |
/// Copy constructor. |
| 224 | 214 |
|
| 225 | 215 |
/// Copy constructor. |
| 226 | 216 |
/// |
| 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 |
|
| 246 | 235 |
/// Assign the iterator to the next |
| 247 | 236 |
/// outgoing arc of the corresponding node. |
| 248 | 237 |
OutArcIt& operator++() { return *this; }
|
| 249 | 238 |
}; |
| 250 | 239 |
|
| 251 |
/// |
|
| 240 |
/// Iterator class for the incoming arcs of a node. |
|
| 252 | 241 |
|
| 253 | 242 |
/// This iterator goes trough the \e incoming arcs of a certain node |
| 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 {
|
| 264 | 252 |
public: |
| 265 | 253 |
/// Default constructor |
| 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() { }
|
| 270 | 258 |
/// Copy constructor. |
| 271 | 259 |
|
| 272 | 260 |
/// Copy constructor. |
| 273 | 261 |
/// |
| 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&) { }
|
| 291 | 278 |
/// Next incoming arc |
| 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 |
| 306 | 294 |
class ArcIt : public Arc {
|
| 307 | 295 |
public: |
| 308 | 296 |
/// Default constructor |
| 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() { }
|
| 313 | 301 |
/// Copy constructor. |
| 314 | 302 |
|
| 315 | 303 |
/// Copy constructor. |
| 316 | 304 |
/// |
| 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; }
|
| 371 | 369 |
|
| 372 | 370 |
void first(Node&) const {}
|
| ... | ... |
@@ -392,45 +390,46 @@ |
| 392 | 390 |
// Dummy parameter. |
| 393 | 391 |
int maxId(Arc) const { return -1; }
|
| 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 |
|
| 401 | 404 |
/// \brief The running node of the iterator. |
| 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 |
|
| 407 | 410 |
/// \brief The base node of the iterator. |
| 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 |
|
| 413 | 416 |
/// \brief The running node of the iterator. |
| 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> |
| 428 | 427 |
class NodeMap : public ReferenceMap<Node, T, T&, const T&> {
|
| 429 | 428 |
public: |
| 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) { }
|
| 435 | 434 |
|
| 436 | 435 |
private: |
| ... | ... |
@@ -445,17 +444,19 @@ |
| 445 | 444 |
} |
| 446 | 445 |
}; |
| 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> |
| 452 | 452 |
class ArcMap : public ReferenceMap<Arc, T, T&, const T&> {
|
| 453 | 453 |
public: |
| 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: |
| 460 | 461 |
///Copy constructor |
| 461 | 462 |
ArcMap(const ArcMap& em) : |
| ... | ... |
@@ -18,12 +18,14 @@ |
| 18 | 18 |
|
| 19 | 19 |
///\ingroup graph_concepts |
| 20 | 20 |
///\file |
| 21 |
///\brief The concept of |
|
| 21 |
///\brief The concept of undirected graphs. |
|
| 22 | 22 |
|
| 23 | 23 |
#ifndef LEMON_CONCEPTS_GRAPH_H |
| 24 | 24 |
#define LEMON_CONCEPTS_GRAPH_H |
| 25 | 25 |
|
| 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> |
| 28 | 30 |
|
| 29 | 31 |
namespace lemon {
|
| ... | ... |
@@ -31,63 +33,74 @@ |
| 31 | 33 |
|
| 32 | 34 |
/// \ingroup graph_concepts |
| 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. |
| 76 | 91 |
typedef True UndirectedTag; |
| 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 {
|
| 86 | 99 |
public: |
| 87 | 100 |
/// Default constructor |
| 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() { }
|
| 92 | 105 |
/// Copy constructor. |
| 93 | 106 |
|
| ... | ... |
@@ -95,40 +108,40 @@ |
| 95 | 108 |
/// |
| 96 | 109 |
Node(const Node&) { }
|
| 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. |
| 102 | 115 |
Node(Invalid) { }
|
| 103 | 116 |
/// Equality operator |
| 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; }
|
| 108 | 123 |
|
| 109 | 124 |
/// Inequality operator |
| 110 | 125 |
|
| 111 |
/// \sa operator==(Node n) |
|
| 112 |
/// |
|
| 126 |
/// Inequality operator. |
|
| 113 | 127 |
bool operator!=(Node) const { return true; }
|
| 114 | 128 |
|
| 115 | 129 |
/// Artificial ordering operator. |
| 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 |
| 122 | 135 |
/// ordering of the items. |
| 123 | 136 |
bool operator<(Node) const { return false; }
|
| 124 | 137 |
|
| 125 | 138 |
}; |
| 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 |
| 133 | 146 |
/// int count=0; |
| 134 | 147 |
/// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count; |
| ... | ... |
@@ -137,30 +150,28 @@ |
| 137 | 150 |
public: |
| 138 | 151 |
/// Default constructor |
| 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() { }
|
| 143 | 156 |
/// Copy constructor. |
| 144 | 157 |
|
| 145 | 158 |
/// Copy constructor. |
| 146 | 159 |
/// |
| 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. |
| 152 | 165 |
NodeIt(Invalid) { }
|
| 153 | 166 |
/// Sets the iterator to the first node. |
| 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&) { }
|
| 165 | 176 |
/// Next node. |
| 166 | 177 |
|
| ... | ... |
@@ -170,54 +181,55 @@ |
| 170 | 181 |
}; |
| 171 | 182 |
|
| 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 {
|
| 178 | 190 |
public: |
| 179 | 191 |
/// Default constructor |
| 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() { }
|
| 184 | 196 |
/// Copy constructor. |
| 185 | 197 |
|
| 186 | 198 |
/// Copy constructor. |
| 187 | 199 |
/// |
| 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) { }
|
| 194 | 206 |
/// Equality operator |
| 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; }
|
| 199 | 213 |
/// Inequality operator |
| 200 | 214 |
|
| 201 |
/// \sa operator==(Edge n) |
|
| 202 |
/// |
|
| 215 |
/// Inequality operator. |
|
| 203 | 216 |
bool operator!=(Edge) const { return true; }
|
| 204 | 217 |
|
| 205 | 218 |
/// Artificial ordering operator. |
| 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; }
|
| 214 | 226 |
}; |
| 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 |
| 222 | 234 |
/// int count=0; |
| 223 | 235 |
/// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count; |
| ... | ... |
@@ -226,290 +238,285 @@ |
| 226 | 238 |
public: |
| 227 | 239 |
/// Default constructor |
| 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() { }
|
| 232 | 244 |
/// Copy constructor. |
| 233 | 245 |
|
| 234 | 246 |
/// Copy constructor. |
| 235 | 247 |
/// |
| 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&) { }
|
| 253 | 264 |
/// Next edge |
| 254 | 265 |
|
| 255 | 266 |
/// Assign the iterator to the next edge. |
| 267 |
/// |
|
| 256 | 268 |
EdgeIt& operator++() { return *this; }
|
| 257 | 269 |
}; |
| 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 |
/// |
| 270 | 279 |
///\code |
| 271 | 280 |
/// int count=0; |
| 272 | 281 |
/// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count; |
| 273 | 282 |
///\endcode |
| 283 |
/// |
|
| 284 |
/// \warning Loop edges will be iterated twice. |
|
| 274 | 285 |
class IncEdgeIt : public Edge {
|
| 275 | 286 |
public: |
| 276 | 287 |
/// Default constructor |
| 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() { }
|
| 281 | 292 |
/// Copy constructor. |
| 282 | 293 |
|
| 283 | 294 |
/// Copy constructor. |
| 284 | 295 |
/// |
| 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. |
| 306 | 316 |
IncEdgeIt& operator++() { return *this; }
|
| 307 | 317 |
}; |
| 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 {
|
| 315 | 325 |
public: |
| 316 | 326 |
/// Default constructor |
| 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() { }
|
| 321 | 331 |
/// Copy constructor. |
| 322 | 332 |
|
| 323 | 333 |
/// Copy constructor. |
| 324 | 334 |
/// |
| 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) { }
|
| 331 | 341 |
/// Equality operator |
| 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; }
|
| 336 | 348 |
/// Inequality operator |
| 337 | 349 |
|
| 338 |
/// \sa operator==(Arc n) |
|
| 339 |
/// |
|
| 350 |
/// Inequality operator. |
|
| 340 | 351 |
bool operator!=(Arc) const { return true; }
|
| 341 | 352 |
|
| 342 | 353 |
/// Artificial ordering operator. |
| 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 |
| 364 | 378 |
class ArcIt : public Arc {
|
| 365 | 379 |
public: |
| 366 | 380 |
/// Default constructor |
| 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() { }
|
| 371 | 385 |
/// Copy constructor. |
| 372 | 386 |
|
| 373 | 387 |
/// Copy constructor. |
| 374 | 388 |
/// |
| 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; }
|
| 396 | 410 |
}; |
| 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 {
|
| 411 | 424 |
public: |
| 412 | 425 |
/// Default constructor |
| 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() { }
|
| 417 | 430 |
/// Copy constructor. |
| 418 | 431 |
|
| 419 | 432 |
/// Copy constructor. |
| 420 | 433 |
/// |
| 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) {
|
| 434 | 445 |
ignore_unused_variable_warning(n); |
| 435 | 446 |
ignore_unused_variable_warning(g); |
| 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 |
|
| 445 | 455 |
/// Assign the iterator to the next |
| 446 | 456 |
/// outgoing arc of the corresponding node. |
| 447 | 457 |
OutArcIt& operator++() { return *this; }
|
| 448 | 458 |
}; |
| 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 {
|
| 463 | 472 |
public: |
| 464 | 473 |
/// Default constructor |
| 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() { }
|
| 469 | 478 |
/// Copy constructor. |
| 470 | 479 |
|
| 471 | 480 |
/// Copy constructor. |
| 472 | 481 |
/// |
| 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) {
|
| 486 | 493 |
ignore_unused_variable_warning(n); |
| 487 | 494 |
ignore_unused_variable_warning(g); |
| 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&) { }
|
| 495 | 501 |
/// Next incoming arc |
| 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; }
|
| 500 | 506 |
}; |
| 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> |
| 506 | 513 |
class NodeMap : public ReferenceMap<Node, T, T&, const T&> |
| 507 | 514 |
{
|
| 508 | 515 |
public: |
| 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) { }
|
| 514 | 521 |
|
| 515 | 522 |
private: |
| ... | ... |
@@ -524,18 +531,20 @@ |
| 524 | 531 |
} |
| 525 | 532 |
}; |
| 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> |
| 531 | 539 |
class ArcMap : public ReferenceMap<Arc, T, T&, const T&> |
| 532 | 540 |
{
|
| 533 | 541 |
public: |
| 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: |
| 540 | 549 |
///Copy constructor |
| 541 | 550 |
ArcMap(const ArcMap& em) : |
| ... | ... |
@@ -548,18 +557,20 @@ |
| 548 | 557 |
} |
| 549 | 558 |
}; |
| 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> |
| 555 | 565 |
class EdgeMap : public ReferenceMap<Edge, T, T&, const T&> |
| 556 | 566 |
{
|
| 557 | 567 |
public: |
| 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: |
| 564 | 575 |
///Copy constructor |
| 565 | 576 |
EdgeMap(const EdgeMap& em) : |
| ... | ... |
@@ -572,107 +583,124 @@ |
| 572 | 583 |
} |
| 573 | 584 |
}; |
| 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() |
| 620 | 596 |
/// \sa direction() |
| 621 | 597 |
Node u(Edge) const { return INVALID; }
|
| 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() |
| 634 | 609 |
/// \sa direction() |
| 635 | 610 |
Node v(Edge) const { return INVALID; }
|
| 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 {}
|
| 677 | 705 |
void next(Node&) const {}
|
| 678 | 706 |
|
| ... | ... |
@@ -705,47 +733,39 @@ |
| 705 | 733 |
// Dummy parameter. |
| 706 | 734 |
int maxId(Arc) const { return -1; }
|
| 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 |
|
| 750 | 770 |
template <typename _Graph> |
| 751 | 771 |
struct Constraints {
|
| ... | ... |
@@ -18,7 +18,7 @@ |
| 18 | 18 |
|
| 19 | 19 |
///\ingroup graph_concepts |
| 20 | 20 |
///\file |
| 21 |
///\brief The |
|
| 21 |
///\brief The concepts of graph components. |
|
| 22 | 22 |
|
| 23 | 23 |
#ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H |
| 24 | 24 |
#define LEMON_CONCEPTS_GRAPH_COMPONENTS_H |
| ... | ... |
@@ -92,7 +92,7 @@ |
| 92 | 92 |
/// It makes possible to use graph item types as key types in |
| 93 | 93 |
/// associative containers (e.g. \c std::map). |
| 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 |
| 97 | 97 |
/// ordering of the items. |
| 98 | 98 |
bool operator<(const GraphItem&) const { return false; }
|
| ... | ... |
@@ -182,7 +182,8 @@ |
| 182 | 182 |
|
| 183 | 183 |
template<typename _ReferenceMap> |
| 184 | 184 |
struct Constraints {
|
| 185 |
|
|
| 185 |
typename enable_if<typename _ReferenceMap::ReferenceMapTag, void>::type |
|
| 186 |
constraints() {
|
|
| 186 | 187 |
checkConcept<ReadWriteMap<K, T>, _ReferenceMap >(); |
| 187 | 188 |
ref = m[key]; |
| 188 | 189 |
m[key] = val; |
| ... | ... |
@@ -18,7 +18,7 @@ |
| 18 | 18 |
|
| 19 | 19 |
///\ingroup concept |
| 20 | 20 |
///\file |
| 21 |
///\brief |
|
| 21 |
///\brief The concept of paths |
|
| 22 | 22 |
/// |
| 23 | 23 |
|
| 24 | 24 |
#ifndef LEMON_CONCEPTS_PATH_H |
| ... | ... |
@@ -38,13 +38,22 @@ |
| 38 | 38 |
/// |
| 39 | 39 |
/// A skeleton structure for representing directed paths in a |
| 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> |
| 49 | 58 |
class Path {
|
| 50 | 59 |
public: |
| ... | ... |
@@ -59,18 +68,18 @@ |
| 59 | 68 |
/// \brief Default constructor |
| 60 | 69 |
Path() {}
|
| 61 | 70 |
|
| 62 |
/// \brief Template constructor |
|
| 71 |
/// \brief Template copy constructor |
|
| 63 | 72 |
template <typename CPath> |
| 64 | 73 |
Path(const CPath& cpath) {}
|
| 65 | 74 |
|
| 66 |
/// \brief Template assigment |
|
| 75 |
/// \brief Template assigment operator |
|
| 67 | 76 |
template <typename CPath> |
| 68 | 77 |
Path& operator=(const CPath& cpath) {
|
| 69 | 78 |
ignore_unused_variable_warning(cpath); |
| 70 | 79 |
return *this; |
| 71 | 80 |
} |
| 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;}
|
| 75 | 84 |
|
| 76 | 85 |
/// Returns whether the path is empty. |
| ... | ... |
@@ -79,19 +88,19 @@ |
| 79 | 88 |
/// Resets the path to an empty path. |
| 80 | 89 |
void clear() {}
|
| 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 {
|
| 86 | 95 |
public: |
| 87 | 96 |
/// Default constructor |
| 88 | 97 |
ArcIt() {}
|
| 89 | 98 |
/// Invalid constructor |
| 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; }
|
| 96 | 105 |
|
| 97 | 106 |
/// Next arc |
| ... | ... |
@@ -192,24 +201,18 @@ |
| 192 | 201 |
/// \brief A skeleton structure for path dumpers. |
| 193 | 202 |
/// |
| 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. |
| 208 | 214 |
/// |
| 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> |
| 214 | 217 |
class PathDumper {
|
| 215 | 218 |
public: |
| ... | ... |
@@ -219,7 +222,7 @@ |
| 219 | 222 |
/// Arc type of the underlying digraph. |
| 220 | 223 |
typedef typename Digraph::Arc Arc; |
| 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;}
|
| 224 | 227 |
|
| 225 | 228 |
/// Returns whether the path is empty. |
| ... | ... |
@@ -227,25 +230,24 @@ |
| 227 | 230 |
|
| 228 | 231 |
/// \brief Forward or reverse dumping |
| 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 {
|
| 240 | 242 |
public: |
| 241 | 243 |
/// Default constructor |
| 242 | 244 |
ArcIt() {}
|
| 243 | 245 |
/// Invalid constructor |
| 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; }
|
| 250 | 252 |
|
| 251 | 253 |
/// Next arc |
| ... | ... |
@@ -260,20 +262,21 @@ |
| 260 | 262 |
|
| 261 | 263 |
}; |
| 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 {
|
| 268 | 271 |
public: |
| 269 | 272 |
/// Default constructor |
| 270 | 273 |
RevArcIt() {}
|
| 271 | 274 |
/// Invalid constructor |
| 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; }
|
| 278 | 281 |
|
| 279 | 282 |
/// Next arc |
| ... | ... |
@@ -212,7 +212,7 @@ |
| 212 | 212 |
|
| 213 | 213 |
/// 'Do nothing' version of Counter. |
| 214 | 214 |
|
| 215 |
/// This class can be used in the same way as \ref Counter |
|
| 215 |
/// This class can be used in the same way as \ref Counter, but it |
|
| 216 | 216 |
/// does not count at all and does not print report on destruction. |
| 217 | 217 |
/// |
| 218 | 218 |
/// Replacing a \ref Counter with a \ref NoCounter makes it possible |
| ... | ... |
@@ -111,6 +111,39 @@ |
| 111 | 111 |
return i; |
| 112 | 112 |
} |
| 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 |
|
| 115 | 148 |
void CplexBase::_eraseCol(int i) {
|
| 116 | 149 |
CPXdelcols(cplexEnv(), _prob, i, i); |
| ... | ... |
@@ -47,7 +47,7 @@ |
| 47 | 47 |
/// |
| 48 | 48 |
///The type of the map that stores the predecessor |
| 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; |
| 52 | 52 |
///Instantiates a \c PredMap. |
| 53 | 53 |
|
| ... | ... |
@@ -62,7 +62,8 @@ |
| 62 | 62 |
///The type of the map that indicates which nodes are processed. |
| 63 | 63 |
|
| 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; |
| 67 | 68 |
///Instantiates a \c ProcessedMap. |
| 68 | 69 |
|
| ... | ... |
@@ -81,7 +82,7 @@ |
| 81 | 82 |
///The type of the map that indicates which nodes are reached. |
| 82 | 83 |
|
| 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; |
| 86 | 87 |
///Instantiates a \c ReachedMap. |
| 87 | 88 |
|
| ... | ... |
@@ -96,7 +97,7 @@ |
| 96 | 97 |
///The type of the map that stores the distances of the nodes. |
| 97 | 98 |
|
| 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; |
| 101 | 102 |
///Instantiates a \c DistMap. |
| 102 | 103 |
|
| ... | ... |
@@ -224,7 +225,7 @@ |
| 224 | 225 |
/// |
| 225 | 226 |
///\ref named-templ-param "Named parameter" for setting |
| 226 | 227 |
///\c PredMap type. |
| 227 |
///It must |
|
| 228 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
| 228 | 229 |
template <class T> |
| 229 | 230 |
struct SetPredMap : public Dfs<Digraph, SetPredMapTraits<T> > {
|
| 230 | 231 |
typedef Dfs<Digraph, SetPredMapTraits<T> > Create; |
| ... | ... |
@@ -244,7 +245,7 @@ |
| 244 | 245 |
/// |
| 245 | 246 |
///\ref named-templ-param "Named parameter" for setting |
| 246 | 247 |
///\c DistMap type. |
| 247 |
///It must |
|
| 248 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
| 248 | 249 |
template <class T> |
| 249 | 250 |
struct SetDistMap : public Dfs< Digraph, SetDistMapTraits<T> > {
|
| 250 | 251 |
typedef Dfs<Digraph, SetDistMapTraits<T> > Create; |
| ... | ... |
@@ -264,7 +265,7 @@ |
| 264 | 265 |
/// |
| 265 | 266 |
///\ref named-templ-param "Named parameter" for setting |
| 266 | 267 |
///\c ReachedMap type. |
| 267 |
///It must |
|
| 268 |
///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
| 268 | 269 |
template <class T> |
| 269 | 270 |
struct SetReachedMap : public Dfs< Digraph, SetReachedMapTraits<T> > {
|
| 270 | 271 |
typedef Dfs< Digraph, SetReachedMapTraits<T> > Create; |
| ... | ... |
@@ -284,7 +285,7 @@ |
| 284 | 285 |
/// |
| 285 | 286 |
///\ref named-templ-param "Named parameter" for setting |
| 286 | 287 |
///\c ProcessedMap type. |
| 287 |
///It must |
|
| 288 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
| 288 | 289 |
template <class T> |
| 289 | 290 |
struct SetProcessedMap : public Dfs< Digraph, SetProcessedMapTraits<T> > {
|
| 290 | 291 |
typedef Dfs< Digraph, SetProcessedMapTraits<T> > Create; |
| ... | ... |
@@ -411,8 +412,8 @@ |
| 411 | 412 |
///\name Execution Control |
| 412 | 413 |
///The simplest way to execute the DFS algorithm is to use one of the |
| 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(). |
| 417 | 418 |
///This procedure can be repeated if there are nodes that have not |
| 418 | 419 |
///been reached. |
| ... | ... |
@@ -632,12 +633,8 @@ |
| 632 | 633 |
|
| 633 | 634 |
///Runs the algorithm to visit all nodes in the digraph. |
| 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 |
/// |
| 642 | 639 |
///\note <tt>d.run()</tt> is just a shortcut of the following code. |
| 643 | 640 |
///\code |
| ... | ... |
@@ -669,9 +666,9 @@ |
| 669 | 666 |
|
| 670 | 667 |
///@{
|
| 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 |
/// |
| 676 | 673 |
///\warning \c t should be reached from the root(s). |
| 677 | 674 |
/// |
| ... | ... |
@@ -679,9 +676,9 @@ |
| 679 | 676 |
///must be called before using this function. |
| 680 | 677 |
Path path(Node t) const { return Path(*G, *_pred, t); }
|
| 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 |
/// |
| 686 | 683 |
///\warning If node \c v is not reached from the root(s), then |
| 687 | 684 |
///the return value of this function is undefined. |
| ... | ... |
@@ -690,7 +687,7 @@ |
| 690 | 687 |
///must be called before using this function. |
| 691 | 688 |
int dist(Node v) const { return (*_dist)[v]; }
|
| 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 |
|
| 695 | 692 |
///This function returns the 'previous arc' of the %DFS tree for the |
| 696 | 693 |
///node \c v, i.e. it returns the last arc of a %DFS path from a |
| ... | ... |
@@ -698,21 +695,21 @@ |
| 698 | 695 |
///root(s) or if \c v is a root. |
| 699 | 696 |
/// |
| 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 |
/// |
| 703 | 700 |
///\pre Either \ref run(Node) "run()" or \ref init() |
| 704 | 701 |
///must be called before using this function. |
| 705 | 702 |
Arc predArc(Node v) const { return (*_pred)[v];}
|
| 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 |
|
| 709 | 706 |
///This function returns the 'previous node' of the %DFS |
| 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. |
| 713 | 710 |
/// |
| 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 |
/// |
| 717 | 714 |
///\pre Either \ref run(Node) "run()" or \ref init() |
| 718 | 715 |
///must be called before using this function. |
| ... | ... |
@@ -733,13 +730,13 @@ |
| 733 | 730 |
///predecessor arcs. |
| 734 | 731 |
/// |
| 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 |
/// |
| 738 | 735 |
///\pre Either \ref run(Node) "run()" or \ref init() |
| 739 | 736 |
///must be called before using this function. |
| 740 | 737 |
const PredMap &predMap() const { return *_pred;}
|
| 741 | 738 |
|
| 742 |
///Checks if |
|
| 739 |
///Checks if the given node. node is reached from the root(s). |
|
| 743 | 740 |
|
| 744 | 741 |
///Returns \c true if \c v is reached from the root(s). |
| 745 | 742 |
/// |
| ... | ... |
@@ -765,7 +762,7 @@ |
| 765 | 762 |
/// |
| 766 | 763 |
///The type of the map that stores the predecessor |
| 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; |
| 770 | 767 |
///Instantiates a PredMap. |
| 771 | 768 |
|
| ... | ... |
@@ -780,8 +777,8 @@ |
| 780 | 777 |
///The type of the map that indicates which nodes are processed. |
| 781 | 778 |
|
| 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; |
| 786 | 783 |
///Instantiates a ProcessedMap. |
| 787 | 784 |
|
| ... | ... |
@@ -800,7 +797,7 @@ |
| 800 | 797 |
///The type of the map that indicates which nodes are reached. |
| 801 | 798 |
|
| 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; |
| 805 | 802 |
///Instantiates a ReachedMap. |
| 806 | 803 |
|
| ... | ... |
@@ -815,7 +812,7 @@ |
| 815 | 812 |
///The type of the map that stores the distances of the nodes. |
| 816 | 813 |
|
| 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; |
| 820 | 817 |
///Instantiates a DistMap. |
| 821 | 818 |
|
| ... | ... |
@@ -830,18 +827,14 @@ |
| 830 | 827 |
///The type of the DFS paths. |
| 831 | 828 |
|
| 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; |
| 835 | 832 |
}; |
| 836 | 833 |
|
| 837 | 834 |
/// Default traits class used by DfsWizard |
| 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> |
| 846 | 839 |
class DfsWizardBase : public DfsWizardDefaultTraits<GR> |
| 847 | 840 |
{
|
| ... | ... |
@@ -869,7 +862,7 @@ |
| 869 | 862 |
public: |
| 870 | 863 |
/// Constructor. |
| 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. |
| 874 | 867 |
DfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0), |
| 875 | 868 |
_dist(0), _path(0), _di(0) {}
|
| ... | ... |
@@ -899,7 +892,6 @@ |
| 899 | 892 |
{
|
| 900 | 893 |
typedef TR Base; |
| 901 | 894 |
|
| 902 |
///The type of the digraph the algorithm runs on. |
|
| 903 | 895 |
typedef typename TR::Digraph Digraph; |
| 904 | 896 |
|
| 905 | 897 |
typedef typename Digraph::Node Node; |
| ... | ... |
@@ -907,16 +899,10 @@ |
| 907 | 899 |
typedef typename Digraph::Arc Arc; |
| 908 | 900 |
typedef typename Digraph::OutArcIt OutArcIt; |
| 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; |
| 921 | 907 |
|
| 922 | 908 |
public: |
| ... | ... |
@@ -986,8 +972,8 @@ |
| 986 | 972 |
|
| 987 | 973 |
///Runs DFS algorithm to visit all nodes in the digraph. |
| 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() |
| 992 | 978 |
{
|
| 993 | 979 |
run(INVALID); |
| ... | ... |
@@ -999,11 +985,12 @@ |
| 999 | 985 |
static PredMap *createPredMap(const Digraph &) { return 0; };
|
| 1000 | 986 |
SetPredMapBase(const TR &b) : TR(b) {}
|
| 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> |
| 1008 | 995 |
DfsWizard<SetPredMapBase<T> > predMap(const T &t) |
| 1009 | 996 |
{
|
| ... | ... |
@@ -1017,11 +1004,12 @@ |
| 1017 | 1004 |
static ReachedMap *createReachedMap(const Digraph &) { return 0; };
|
| 1018 | 1005 |
SetReachedMapBase(const TR &b) : TR(b) {}
|
| 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> |
| 1026 | 1014 |
DfsWizard<SetReachedMapBase<T> > reachedMap(const T &t) |
| 1027 | 1015 |
{
|
| ... | ... |
@@ -1035,11 +1023,13 @@ |
| 1035 | 1023 |
static DistMap *createDistMap(const Digraph &) { return 0; };
|
| 1036 | 1024 |
SetDistMapBase(const TR &b) : TR(b) {}
|
| 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> |
| 1044 | 1034 |
DfsWizard<SetDistMapBase<T> > distMap(const T &t) |
| 1045 | 1035 |
{
|
| ... | ... |
@@ -1053,11 +1043,12 @@ |
| 1053 | 1043 |
static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
|
| 1054 | 1044 |
SetProcessedMapBase(const TR &b) : TR(b) {}
|
| 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> |
| 1062 | 1053 |
DfsWizard<SetProcessedMapBase<T> > processedMap(const T &t) |
| 1063 | 1054 |
{
|
| ... | ... |
@@ -1208,7 +1199,7 @@ |
| 1208 | 1199 |
/// \brief The type of the map that indicates which nodes are reached. |
| 1209 | 1200 |
/// |
| 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; |
| 1213 | 1204 |
|
| 1214 | 1205 |
/// \brief Instantiates a ReachedMap. |
| ... | ... |
@@ -1369,8 +1360,8 @@ |
| 1369 | 1360 |
/// \name Execution Control |
| 1370 | 1361 |
/// The simplest way to execute the DFS algorithm is to use one of the |
| 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(). |
| 1375 | 1366 |
/// This procedure can be repeated if there are nodes that have not |
| 1376 | 1367 |
/// been reached. |
| ... | ... |
@@ -1583,12 +1574,8 @@ |
| 1583 | 1574 |
|
| 1584 | 1575 |
/// \brief Runs the algorithm to visit all nodes in the digraph. |
| 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 |
/// |
| 1593 | 1580 |
/// \note <tt>d.run()</tt> is just a shortcut of the following code. |
| 1594 | 1581 |
///\code |
| ... | ... |
@@ -1620,7 +1607,7 @@ |
| 1620 | 1607 |
|
| 1621 | 1608 |
///@{
|
| 1622 | 1609 |
|
| 1623 |
/// \brief Checks if |
|
| 1610 |
/// \brief Checks if the given node is reached from the root(s). |
|
| 1624 | 1611 |
/// |
| 1625 | 1612 |
/// Returns \c true if \c v is reached from the root(s). |
| 1626 | 1613 |
/// |
| ... | ... |
@@ -70,9 +70,9 @@ |
| 70 | 70 |
///The type of the map that stores the arc lengths. |
| 71 | 71 |
|
| 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; |
| 77 | 77 |
|
| 78 | 78 |
/// Operation traits for %Dijkstra algorithm. |
| ... | ... |
@@ -116,7 +116,7 @@ |
| 116 | 116 |
/// |
| 117 | 117 |
///The type of the map that stores the predecessor |
| 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; |
| 121 | 121 |
///Instantiates a \c PredMap. |
| 122 | 122 |
|
| ... | ... |
@@ -131,8 +131,8 @@ |
| 131 | 131 |
///The type of the map that indicates which nodes are processed. |
| 132 | 132 |
|
| 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; |
| 137 | 137 |
///Instantiates a \c ProcessedMap. |
| 138 | 138 |
|
| ... | ... |
@@ -151,7 +151,7 @@ |
| 151 | 151 |
///The type of the map that stores the distances of the nodes. |
| 152 | 152 |
|
| 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; |
| 156 | 156 |
///Instantiates a \c DistMap. |
| 157 | 157 |
|
| ... | ... |
@@ -169,6 +169,10 @@ |
| 169 | 169 |
/// \ingroup shortest_path |
| 170 | 170 |
///This class provides an efficient implementation of the %Dijkstra algorithm. |
| 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 |
| 173 | 177 |
///\ref concepts::ReadMap "ReadMap", |
| 174 | 178 |
///so it is easy to change it to any kind of length. |
| ... | ... |
@@ -201,8 +205,8 @@ |
| 201 | 205 |
///The type of the digraph the algorithm runs on. |
| 202 | 206 |
typedef typename TR::Digraph Digraph; |
| 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. |
| 207 | 211 |
typedef typename TR::LengthMap LengthMap; |
| 208 | 212 |
///\brief The type of the map that stores the predecessor arcs of the |
| ... | ... |
@@ -304,7 +308,7 @@ |
| 304 | 308 |
/// |
| 305 | 309 |
///\ref named-templ-param "Named parameter" for setting |
| 306 | 310 |
///\c PredMap type. |
| 307 |
///It must |
|
| 311 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
| 308 | 312 |
template <class T> |
| 309 | 313 |
struct SetPredMap |
| 310 | 314 |
: public Dijkstra< Digraph, LengthMap, SetPredMapTraits<T> > {
|
| ... | ... |
@@ -325,7 +329,7 @@ |
| 325 | 329 |
/// |
| 326 | 330 |
///\ref named-templ-param "Named parameter" for setting |
| 327 | 331 |
///\c DistMap type. |
| 328 |
///It must |
|
| 332 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
| 329 | 333 |
template <class T> |
| 330 | 334 |
struct SetDistMap |
| 331 | 335 |
: public Dijkstra< Digraph, LengthMap, SetDistMapTraits<T> > {
|
| ... | ... |
@@ -346,7 +350,7 @@ |
| 346 | 350 |
/// |
| 347 | 351 |
///\ref named-templ-param "Named parameter" for setting |
| 348 | 352 |
///\c ProcessedMap type. |
| 349 |
///It must |
|
| 353 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
| 350 | 354 |
template <class T> |
| 351 | 355 |
struct SetProcessedMap |
| 352 | 356 |
: public Dijkstra< Digraph, LengthMap, SetProcessedMapTraits<T> > {
|
| ... | ... |
@@ -422,7 +426,7 @@ |
| 422 | 426 |
///automatically created by the algorithm (i.e. the digraph should be |
| 423 | 427 |
///passed to the constructor of the cross reference and the cross |
| 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 |
| 427 | 431 |
///calling \ref run(Node) "run()" or \ref init(). |
| 428 | 432 |
///\sa SetHeap |
| ... | ... |
@@ -443,6 +447,7 @@ |
| 443 | 447 |
/// |
| 444 | 448 |
///\ref named-templ-param "Named parameter" for setting |
| 445 | 449 |
///\c OperationTraits type. |
| 450 |
/// For more information, see \ref DijkstraDefaultOperationTraits. |
|
| 446 | 451 |
template <class T> |
| 447 | 452 |
struct SetOperationTraits |
| 448 | 453 |
: public Dijkstra<Digraph, LengthMap, SetOperationTraitsTraits<T> > {
|
| ... | ... |
@@ -584,8 +589,8 @@ |
| 584 | 589 |
///\name Execution Control |
| 585 | 590 |
///The simplest way to execute the %Dijkstra algorithm is to use |
| 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 |
| 590 | 595 |
///performed with one of the \ref start() functions. |
| 591 | 596 |
|
| ... | ... |
@@ -801,14 +806,14 @@ |
| 801 | 806 |
///\name Query Functions |
| 802 | 807 |
///The results of the %Dijkstra algorithm can be obtained using these |
| 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. |
| 806 | 811 |
|
| 807 | 812 |
///@{
|
| 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 |
/// |
| 813 | 818 |
///\warning \c t should be reached from the root(s). |
| 814 | 819 |
/// |
| ... | ... |
@@ -816,9 +821,9 @@ |
| 816 | 821 |
///must be called before using this function. |
| 817 | 822 |
Path path(Node t) const { return Path(*G, *_pred, t); }
|
| 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 |
/// |
| 823 | 828 |
///\warning If node \c v is not reached from the root(s), then |
| 824 | 829 |
///the return value of this function is undefined. |
| ... | ... |
@@ -827,29 +832,31 @@ |
| 827 | 832 |
///must be called before using this function. |
| 828 | 833 |
Value dist(Node v) const { return (*_dist)[v]; }
|
| 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 |
| 833 | 839 |
///tree for the node \c v, i.e. it returns the last arc of a |
| 834 | 840 |
///shortest path from a root to \c v. It is \c INVALID if \c v |
| 835 | 841 |
///is not reached from the root(s) or if \c v is a root. |
| 836 | 842 |
/// |
| 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 |
/// |
| 840 | 846 |
///\pre Either \ref run(Node) "run()" or \ref init() |
| 841 | 847 |
///must be called before using this function. |
| 842 | 848 |
Arc predArc(Node v) const { return (*_pred)[v]; }
|
| 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. |
| 850 | 857 |
/// |
| 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 |
/// |
| 854 | 861 |
///\pre Either \ref run(Node) "run()" or \ref init() |
| 855 | 862 |
///must be called before using this function. |
| ... | ... |
@@ -870,13 +877,13 @@ |
| 870 | 877 |
///predecessor arcs. |
| 871 | 878 |
/// |
| 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 |
/// |
| 875 | 882 |
///\pre Either \ref run(Node) "run()" or \ref init() |
| 876 | 883 |
///must be called before using this function. |
| 877 | 884 |
const PredMap &predMap() const { return *_pred;}
|
| 878 | 885 |
|
| 879 |
///Checks if |
|
| 886 |
///Checks if the given node is reached from the root(s). |
|
| 880 | 887 |
|
| 881 | 888 |
///Returns \c true if \c v is reached from the root(s). |
| 882 | 889 |
/// |
| ... | ... |
@@ -895,9 +902,9 @@ |
| 895 | 902 |
bool processed(Node v) const { return (*_heap_cross_ref)[v] ==
|
| 896 | 903 |
Heap::POST_HEAP; } |
| 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. |
| 902 | 909 |
/// |
| 903 | 910 |
///\pre Either \ref run(Node) "run()" or \ref init() |
| ... | ... |
@@ -924,9 +931,9 @@ |
| 924 | 931 |
///The type of the map that stores the arc lengths. |
| 925 | 932 |
|
| 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; |
| 931 | 938 |
|
| 932 | 939 |
/// Operation traits for Dijkstra algorithm. |
| ... | ... |
@@ -973,7 +980,7 @@ |
| 973 | 980 |
/// |
| 974 | 981 |
///The type of the map that stores the predecessor |
| 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; |
| 978 | 985 |
///Instantiates a PredMap. |
| 979 | 986 |
|
| ... | ... |
@@ -988,8 +995,8 @@ |
| 988 | 995 |
///The type of the map that indicates which nodes are processed. |
| 989 | 996 |
|
| 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; |
| 994 | 1001 |
///Instantiates a ProcessedMap. |
| 995 | 1002 |
|
| ... | ... |
@@ -1008,7 +1015,7 @@ |
| 1008 | 1015 |
///The type of the map that stores the distances of the nodes. |
| 1009 | 1016 |
|
| 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; |
| 1013 | 1020 |
///Instantiates a DistMap. |
| 1014 | 1021 |
|
| ... | ... |
@@ -1023,18 +1030,15 @@ |
| 1023 | 1030 |
///The type of the shortest paths. |
| 1024 | 1031 |
|
| 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; |
| 1028 | 1035 |
}; |
| 1029 | 1036 |
|
| 1030 | 1037 |
/// Default traits class used by DijkstraWizard |
| 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> |
| 1039 | 1043 |
class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LEN> |
| 1040 | 1044 |
{
|
| ... | ... |
@@ -1093,7 +1097,6 @@ |
| 1093 | 1097 |
{
|
| 1094 | 1098 |
typedef TR Base; |
| 1095 | 1099 |
|
| 1096 |
///The type of the digraph the algorithm runs on. |
|
| 1097 | 1100 |
typedef typename TR::Digraph Digraph; |
| 1098 | 1101 |
|
| 1099 | 1102 |
typedef typename Digraph::Node Node; |
| ... | ... |
@@ -1101,20 +1104,12 @@ |
| 1101 | 1104 |
typedef typename Digraph::Arc Arc; |
| 1102 | 1105 |
typedef typename Digraph::OutArcIt OutArcIt; |
| 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; |
| 1119 | 1114 |
|
| 1120 | 1115 |
public: |
| ... | ... |
@@ -1186,11 +1181,12 @@ |
| 1186 | 1181 |
static PredMap *createPredMap(const Digraph &) { return 0; };
|
| 1187 | 1182 |
SetPredMapBase(const TR &b) : TR(b) {}
|
| 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> |
| 1195 | 1191 |
DijkstraWizard<SetPredMapBase<T> > predMap(const T &t) |
| 1196 | 1192 |
{
|
| ... | ... |
@@ -1204,11 +1200,13 @@ |
| 1204 | 1200 |
static DistMap *createDistMap(const Digraph &) { return 0; };
|
| 1205 | 1201 |
SetDistMapBase(const TR &b) : TR(b) {}
|
| 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> |
| 1213 | 1211 |
DijkstraWizard<SetDistMapBase<T> > distMap(const T &t) |
| 1214 | 1212 |
{
|
| ... | ... |
@@ -1222,11 +1220,12 @@ |
| 1222 | 1220 |
static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
|
| 1223 | 1221 |
SetProcessedMapBase(const TR &b) : TR(b) {}
|
| 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> |
| 1231 | 1230 |
DijkstraWizard<SetProcessedMapBase<T> > processedMap(const T &t) |
| 1232 | 1231 |
{
|
| ... | ... |
@@ -1239,6 +1238,7 @@ |
| 1239 | 1238 |
typedef T Path; |
| 1240 | 1239 |
SetPathBase(const TR &b) : TR(b) {}
|
| 1241 | 1240 |
}; |
| 1241 |
|
|
| 1242 | 1242 |
///\brief \ref named-func-param "Named parameter" |
| 1243 | 1243 |
///for getting the shortest path to the target node. |
| 1244 | 1244 |
/// |
| ... | ... |
@@ -21,16 +21,9 @@ |
| 21 | 21 |
|
| 22 | 22 |
#include <iostream> |
| 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 |
|
| 35 | 28 |
namespace lemon {
|
| 36 | 29 |
|
| ... | ... |
@@ -40,7 +33,7 @@ |
| 40 | 33 |
///tools for handling two dimensional coordinates |
| 41 | 34 |
namespace dim2 {
|
| 42 | 35 |
|
| 43 |
/// \addtogroup |
|
| 36 |
/// \addtogroup geomdat |
|
| 44 | 37 |
/// @{
|
| 45 | 38 |
|
| 46 | 39 |
/// Two dimensional vector (plain vector) |
| ... | ... |
@@ -255,13 +255,14 @@ |
| 255 | 255 |
/// that node can be removed from the underlying graph, in this case |
| 256 | 256 |
/// all arcs incident to the given node is erased from the arc set. |
| 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 |
| 259 | 263 |
/// this class. Its interface must conform to the |
| 260 | 264 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph" |
| 261 | 265 |
/// concept. |
| 262 |
/// |
|
| 263 |
/// This class fully conforms to the \ref concepts::Digraph |
|
| 264 |
/// "Digraph" concept. |
|
| 265 | 266 |
template <typename GR> |
| 266 | 267 |
class ListArcSet : public ArcSetExtender<ListArcSetBase<GR> > {
|
| 267 | 268 |
typedef ArcSetExtender<ListArcSetBase<GR> > Parent; |
| ... | ... |
@@ -685,13 +686,14 @@ |
| 685 | 686 |
/// be removed from the underlying graph, in this case all edges |
| 686 | 687 |
/// incident to the given node is erased from the arc set. |
| 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 |
| 689 | 694 |
/// with this class. Its interface must conform to the |
| 690 | 695 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph" |
| 691 | 696 |
/// concept. |
| 692 |
/// |
|
| 693 |
/// This class fully conforms to the \ref concepts::Graph "Graph" |
|
| 694 |
/// concept. |
|
| 695 | 697 |
template <typename GR> |
| 696 | 698 |
class ListEdgeSet : public EdgeSetExtender<ListEdgeSetBase<GR> > {
|
| 697 | 699 |
typedef EdgeSetExtender<ListEdgeSetBase<GR> > Parent; |
| ... | ... |
@@ -867,7 +869,7 @@ |
| 867 | 869 |
arc.id = arcs.size() - 1; |
| 868 | 870 |
} |
| 869 | 871 |
|
| 870 |
void next(Arc& arc) |
|
| 872 |
static void next(Arc& arc) {
|
|
| 871 | 873 |
--arc.id; |
| 872 | 874 |
} |
| 873 | 875 |
|
| ... | ... |
@@ -954,13 +956,14 @@ |
| 954 | 956 |
/// single-linked lists for enumerate outgoing and incoming |
| 955 | 957 |
/// arcs. Therefore the arcs cannot be erased from the arc sets. |
| 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 |
| 958 | 964 |
/// node is the source or target of one arc in the arc set, then |
| 959 | 965 |
/// the arc set is invalidated, and it cannot be used anymore. The |
| 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> |
| 965 | 968 |
class SmartArcSet : public ArcSetExtender<SmartArcSetBase<GR> > {
|
| 966 | 969 |
typedef ArcSetExtender<SmartArcSetBase<GR> > Parent; |
| ... | ... |
@@ -1173,7 +1176,7 @@ |
| 1173 | 1176 |
arc.id = arcs.size() - 1; |
| 1174 | 1177 |
} |
| 1175 | 1178 |
|
| 1176 |
void next(Arc& arc) |
|
| 1179 |
static void next(Arc& arc) {
|
|
| 1177 | 1180 |
--arc.id; |
| 1178 | 1181 |
} |
| 1179 | 1182 |
|
| ... | ... |
@@ -1181,7 +1184,7 @@ |
| 1181 | 1184 |
arc.id = arcs.size() / 2 - 1; |
| 1182 | 1185 |
} |
| 1183 | 1186 |
|
| 1184 |
void next(Edge& arc) |
|
| 1187 |
static void next(Edge& arc) {
|
|
| 1185 | 1188 |
--arc.id; |
| 1186 | 1189 |
} |
| 1187 | 1190 |
|
| ... | ... |
@@ -1304,13 +1307,14 @@ |
| 1304 | 1307 |
/// single-linked lists for enumerate incident edges. Therefore the |
| 1305 | 1308 |
/// edges cannot be erased from the edge sets. |
| 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 |
| 1308 | 1315 |
/// node is incident to one edge in the edge set, then the edge set |
| 1309 | 1316 |
/// is invalidated, and it cannot be used anymore. The validity can |
| 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> |
| 1315 | 1319 |
class SmartEdgeSet : public EdgeSetExtender<SmartEdgeSetBase<GR> > {
|
| 1316 | 1320 |
typedef EdgeSetExtender<SmartEdgeSetBase<GR> > Parent; |
| ... | ... |
@@ -24,7 +24,7 @@ |
| 24 | 24 |
|
| 25 | 25 |
///\ingroup graphs |
| 26 | 26 |
///\file |
| 27 |
///\brief |
|
| 27 |
///\brief FullDigraph and FullGraph classes. |
|
| 28 | 28 |
|
| 29 | 29 |
namespace lemon {
|
| 30 | 30 |
|
| ... | ... |
@@ -51,7 +51,7 @@ |
| 51 | 51 |
typedef True ArcNumTag; |
| 52 | 52 |
|
| 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 |
|
| 56 | 56 |
Arc arc(const Node& s, const Node& t) const {
|
| 57 | 57 |
return Arc(s._id * _node_num + t._id); |
| ... | ... |
@@ -148,24 +148,28 @@ |
| 148 | 148 |
|
| 149 | 149 |
/// \ingroup graphs |
| 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 |
/// |
| 170 | 174 |
/// \sa FullGraph |
| 171 | 175 |
class FullDigraph : public ExtendedFullDigraphBase {
|
| ... | ... |
@@ -173,7 +177,9 @@ |
| 173 | 177 |
|
| 174 | 178 |
public: |
| 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); }
|
| 178 | 184 |
|
| 179 | 185 |
/// \brief Constructor |
| ... | ... |
@@ -184,8 +190,8 @@ |
| 184 | 190 |
|
| 185 | 191 |
/// \brief Resizes the digraph |
| 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. |
| 190 | 196 |
void resize(int n) {
|
| 191 | 197 |
Parent::notifier(Arc()).clear(); |
| ... | ... |
@@ -197,24 +203,26 @@ |
| 197 | 203 |
|
| 198 | 204 |
/// \brief Returns the node with the given index. |
| 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() |
| 204 | 211 |
Node operator()(int ix) const { return Parent::operator()(ix); }
|
| 205 | 212 |
|
| 206 | 213 |
/// \brief Returns the index of the given node. |
| 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 |
|
| 214 | 222 |
/// \brief Returns the arc connecting the given nodes. |
| 215 | 223 |
/// |
| 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); |
| 219 | 227 |
} |
| 220 | 228 |
|
| ... | ... |
@@ -283,7 +291,7 @@ |
| 283 | 291 |
public: |
| 284 | 292 |
|
| 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 |
|
| 288 | 296 |
Edge edge(const Node& u, const Node& v) const {
|
| 289 | 297 |
if (u._id < v._id) {
|
| ... | ... |
@@ -520,21 +528,25 @@ |
| 520 | 528 |
/// |
| 521 | 529 |
/// \brief An undirected full graph class. |
| 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 |
/// |
| 539 | 551 |
/// \sa FullDigraph |
| 540 | 552 |
class FullGraph : public ExtendedFullGraphBase {
|
| ... | ... |
@@ -542,7 +554,9 @@ |
| 542 | 554 |
|
| 543 | 555 |
public: |
| 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); }
|
| 547 | 561 |
|
| 548 | 562 |
/// \brief Constructor |
| ... | ... |
@@ -553,8 +567,8 @@ |
| 553 | 567 |
|
| 554 | 568 |
/// \brief Resizes the graph |
| 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. |
| 559 | 573 |
void resize(int n) {
|
| 560 | 574 |
Parent::notifier(Arc()).clear(); |
| ... | ... |
@@ -568,31 +582,33 @@ |
| 568 | 582 |
|
| 569 | 583 |
/// \brief Returns the node with the given index. |
| 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() |
| 575 | 590 |
Node operator()(int ix) const { return Parent::operator()(ix); }
|
| 576 | 591 |
|
| 577 | 592 |
/// \brief Returns the index of the given node. |
| 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 |
|
| 585 | 601 |
/// \brief Returns the arc connecting the given nodes. |
| 586 | 602 |
/// |
| 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); |
| 590 | 606 |
} |
| 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); |
| 597 | 613 |
} |
| 598 | 614 |
| ... | ... |
@@ -59,6 +59,42 @@ |
| 59 | 59 |
return i; |
| 60 | 60 |
} |
| 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) {
|
| 63 | 99 |
int ca[2]; |
| 64 | 100 |
ca[1] = i; |
| ... | ... |
@@ -294,11 +294,9 @@ |
| 294 | 294 |
/// |
| 295 | 295 |
/// \pre \ref run() must be called before using this function. |
| 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 {
|
| 303 | 301 |
Node sn = s, tn = t; |
| 304 | 302 |
bool s_root=false; |
| ... | ... |
@@ -359,10 +357,10 @@ |
| 359 | 357 |
/// This example counts the nodes in the minimum cut separating \c s from |
| 360 | 358 |
/// \c t. |
| 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 |
| 367 | 365 |
class MinCutNodeIt |
| 368 | 366 |
{
|
| ... | ... |
@@ -394,7 +392,7 @@ |
| 394 | 392 |
/// MinCutNodeIt(gomory, t, s, false); |
| 395 | 393 |
/// \endcode |
| 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 |
| 399 | 397 |
/// MinCutNodeIt(gomory, s, t, true); |
| 400 | 398 |
/// \endcode |
| ... | ... |
@@ -456,10 +454,10 @@ |
| 456 | 454 |
/// This example computes the value of the minimum cut separating \c s from |
| 457 | 455 |
/// \c t. |
| 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]; |
| 464 | 462 |
/// \endcode |
| 465 | 463 |
/// The result will be the same as the value returned by |
| ... | ... |
@@ -142,7 +142,7 @@ |
| 142 | 142 |
///Constructor |
| 143 | 143 |
///\param gr Reference to the graph to be printed. |
| 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 |
| 147 | 147 |
///will be explicitly deallocated by the destructor. |
| 148 | 148 |
DefaultGraphToEpsTraits(const GR &gr, std::ostream& ost = std::cout, |
| ... | ... |
@@ -512,7 +512,7 @@ |
| 512 | 512 |
|
| 513 | 513 |
///Turn on/off pre-scaling |
| 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. |
| 517 | 517 |
/// |
| 518 | 518 |
///This (p)rescaling can be turned off with this function. |
| ... | ... |
@@ -1114,7 +1114,7 @@ |
| 1114 | 1114 |
///Generates an EPS file from a graph. |
| 1115 | 1115 |
///\param g Reference to the graph to be printed. |
| 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 |
/// |
| 1119 | 1119 |
///This function also has a lot of |
| 1120 | 1120 |
///\ref named-templ-func-param "named parameters", |
| ... | ... |
@@ -1126,7 +1126,7 @@ |
| 1126 | 1126 |
/// .arcWidthScale(.4).run(); |
| 1127 | 1127 |
///\endcode |
| 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 |
/// |
| 1131 | 1131 |
///\warning Don't forget to put the \ref GraphToEps::run() "run()" |
| 1132 | 1132 |
///to the end of the parameter list. |
| ... | ... |
@@ -470,18 +470,22 @@ |
| 470 | 470 |
/// |
| 471 | 471 |
/// \brief Grid graph class |
| 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() |
| 482 | 482 |
/// and \c down() functions, where the bottom-left corner is the |
| 483 | 483 |
/// origin. |
| 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 |
| 486 | 490 |
/// \image latex grid_graph.eps "Grid graph" width=\textwidth |
| 487 | 491 |
/// |
| ... | ... |
@@ -496,16 +500,21 @@ |
| 496 | 500 |
/// } |
| 497 | 501 |
///\endcode |
| 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 {
|
| 502 | 509 |
typedef ExtendedGridGraphBase Parent; |
| 503 | 510 |
|
| 504 | 511 |
public: |
| 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 {
|
| 510 | 519 |
public: |
| 511 | 520 |
/// \brief The key type of the map |
| ... | ... |
@@ -514,13 +523,9 @@ |
| 514 | 523 |
typedef dim2::Point<int> Value; |
| 515 | 524 |
|
| 516 | 525 |
/// \brief Constructor |
| 517 |
/// |
|
| 518 |
/// Constructor |
|
| 519 | 526 |
IndexMap(const GridGraph& graph) : _graph(graph) {}
|
| 520 | 527 |
|
| 521 | 528 |
/// \brief The subscript operator |
| 522 |
/// |
|
| 523 |
/// The subscript operator. |
|
| 524 | 529 |
Value operator[](Key key) const {
|
| 525 | 530 |
return _graph.pos(key); |
| 526 | 531 |
} |
| ... | ... |
@@ -540,13 +545,9 @@ |
| 540 | 545 |
typedef int Value; |
| 541 | 546 |
|
| 542 | 547 |
/// \brief Constructor |
| 543 |
/// |
|
| 544 |
/// Constructor |
|
| 545 | 548 |
ColMap(const GridGraph& graph) : _graph(graph) {}
|
| 546 | 549 |
|
| 547 | 550 |
/// \brief The subscript operator |
| 548 |
/// |
|
| 549 |
/// The subscript operator. |
|
| 550 | 551 |
Value operator[](Key key) const {
|
| 551 | 552 |
return _graph.col(key); |
| 552 | 553 |
} |
| ... | ... |
@@ -566,13 +567,9 @@ |
| 566 | 567 |
typedef int Value; |
| 567 | 568 |
|
| 568 | 569 |
/// \brief Constructor |
| 569 |
/// |
|
| 570 |
/// Constructor |
|
| 571 | 570 |
RowMap(const GridGraph& graph) : _graph(graph) {}
|
| 572 | 571 |
|
| 573 | 572 |
/// \brief The subscript operator |
| 574 |
/// |
|
| 575 |
/// The subscript operator. |
|
| 576 | 573 |
Value operator[](Key key) const {
|
| 577 | 574 |
return _graph.row(key); |
| 578 | 575 |
} |
| ... | ... |
@@ -583,15 +580,14 @@ |
| 583 | 580 |
|
| 584 | 581 |
/// \brief Constructor |
| 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) {
|
| 596 | 592 |
Parent::notifier(Arc()).clear(); |
| 597 | 593 |
Parent::notifier(Edge()).clear(); |
| ... | ... |
@@ -609,42 +605,42 @@ |
| 609 | 605 |
return Parent::operator()(i, j); |
| 610 | 606 |
} |
| 611 | 607 |
|
| 612 |
/// \brief |
|
| 608 |
/// \brief The column index of the node. |
|
| 613 | 609 |
/// |
| 614 | 610 |
/// Gives back the column index of the node. |
| 615 | 611 |
int col(Node n) const {
|
| 616 | 612 |
return Parent::col(n); |
| 617 | 613 |
} |
| 618 | 614 |
|
| 619 |
/// \brief |
|
| 615 |
/// \brief The row index of the node. |
|
| 620 | 616 |
/// |
| 621 | 617 |
/// Gives back the row index of the node. |
| 622 | 618 |
int row(Node n) const {
|
| 623 | 619 |
return Parent::row(n); |
| 624 | 620 |
} |
| 625 | 621 |
|
| 626 |
/// \brief |
|
| 622 |
/// \brief The position of the node. |
|
| 627 | 623 |
/// |
| 628 | 624 |
/// Gives back the position of the node, ie. the <tt>(col,row)</tt> pair. |
| 629 | 625 |
dim2::Point<int> pos(Node n) const {
|
| 630 | 626 |
return Parent::pos(n); |
| 631 | 627 |
} |
| 632 | 628 |
|
| 633 |
/// \brief |
|
| 629 |
/// \brief The number of the columns. |
|
| 634 | 630 |
/// |
| 635 | 631 |
/// Gives back the number of the columns. |
| 636 | 632 |
int width() const {
|
| 637 | 633 |
return Parent::width(); |
| 638 | 634 |
} |
| 639 | 635 |
|
| 640 |
/// \brief |
|
| 636 |
/// \brief The number of the rows. |
|
| 641 | 637 |
/// |
| 642 | 638 |
/// Gives back the number of the rows. |
| 643 | 639 |
int height() const {
|
| 644 | 640 |
return Parent::height(); |
| 645 | 641 |
} |
| 646 | 642 |
|
| 647 |
/// \brief |
|
| 643 |
/// \brief The arc goes right from the node. |
|
| 648 | 644 |
/// |
| 649 | 645 |
/// Gives back the arc goes right from the node. If there is not |
| 650 | 646 |
/// outgoing arc then it gives back INVALID. |
| ... | ... |
@@ -652,7 +648,7 @@ |
| 652 | 648 |
return Parent::right(n); |
| 653 | 649 |
} |
| 654 | 650 |
|
| 655 |
/// \brief |
|
| 651 |
/// \brief The arc goes left from the node. |
|
| 656 | 652 |
/// |
| 657 | 653 |
/// Gives back the arc goes left from the node. If there is not |
| 658 | 654 |
/// outgoing arc then it gives back INVALID. |
| ... | ... |
@@ -660,7 +656,7 @@ |
| 660 | 656 |
return Parent::left(n); |
| 661 | 657 |
} |
| 662 | 658 |
|
| 663 |
/// \brief |
|
| 659 |
/// \brief The arc goes up from the node. |
|
| 664 | 660 |
/// |
| 665 | 661 |
/// Gives back the arc goes up from the node. If there is not |
| 666 | 662 |
/// outgoing arc then it gives back INVALID. |
| ... | ... |
@@ -668,7 +664,7 @@ |
| 668 | 664 |
return Parent::up(n); |
| 669 | 665 |
} |
| 670 | 666 |
|
| 671 |
/// \brief |
|
| 667 |
/// \brief The arc goes down from the node. |
|
| 672 | 668 |
/// |
| 673 | 669 |
/// Gives back the arc goes down from the node. If there is not |
| 674 | 670 |
/// outgoing arc then it gives back INVALID. |
| ... | ... |
@@ -262,7 +262,7 @@ |
| 262 | 262 |
return arc._id >> _dim; |
| 263 | 263 |
} |
| 264 | 264 |
|
| 265 |
int index(Node node) |
|
| 265 |
static int index(Node node) {
|
|
| 266 | 266 |
return node._id; |
| 267 | 267 |
} |
| 268 | 268 |
|
| ... | ... |
@@ -282,17 +282,23 @@ |
| 282 | 282 |
/// |
| 283 | 283 |
/// \brief Hypercube graph class |
| 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 |
/// |
| 290 | 299 |
/// \note The type of the indices is chosen to \c int for efficiency |
| 291 | 300 |
/// reasons. Thus the maximum dimension of this implementation is 26 |
| 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 {
|
| 297 | 303 |
typedef ExtendedHypercubeGraphBase Parent; |
| 298 | 304 |
|
| ... | ... |
@@ -303,6 +309,21 @@ |
| 303 | 309 |
/// Constructs a hypercube graph with \c dim dimensions. |
| 304 | 310 |
HypercubeGraph(int dim) { construct(dim); }
|
| 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. |
| 307 | 328 |
/// |
| 308 | 329 |
/// Gives back the number of dimensions. |
| ... | ... |
@@ -320,7 +341,7 @@ |
| 320 | 341 |
/// \brief The dimension id of an edge. |
| 321 | 342 |
/// |
| 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 {
|
| 325 | 346 |
return Parent::dimension(edge); |
| 326 | 347 |
} |
| ... | ... |
@@ -328,7 +349,7 @@ |
| 328 | 349 |
/// \brief The dimension id of an arc. |
| 329 | 350 |
/// |
| 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 {
|
| 333 | 354 |
return Parent::dimension(arc); |
| 334 | 355 |
} |
| ... | ... |
@@ -337,7 +358,7 @@ |
| 337 | 358 |
/// |
| 338 | 359 |
/// Gives back the index of the given node. |
| 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); |
| 342 | 363 |
} |
| 343 | 364 |
| ... | ... |
@@ -427,7 +427,7 @@ |
| 427 | 427 |
/// run(); |
| 428 | 428 |
///\endcode |
| 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 |
| 432 | 432 |
/// selected for reading by giving an optional name parameter to the |
| 433 | 433 |
/// \c nodes(), \c arcs() or \c attributes() functions. |
| ... | ... |
@@ -2221,7 +2221,7 @@ |
| 2221 | 2221 |
/// and the comment lines are filtered out, and the leading |
| 2222 | 2222 |
/// whitespaces are trimmed from each processed string. |
| 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. |
| 2226 | 2226 |
///\code |
| 2227 | 2227 |
/// @numbers |
| ... | ... |
@@ -21,7 +21,7 @@ |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup graphs |
| 23 | 23 |
///\file |
| 24 |
///\brief ListDigraph |
|
| 24 |
///\brief ListDigraph and ListGraph classes. |
|
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/core.h> |
| 27 | 27 |
#include <lemon/error.h> |
| ... | ... |
@@ -32,6 +32,8 @@ |
| 32 | 32 |
|
| 33 | 33 |
namespace lemon {
|
| 34 | 34 |
|
| 35 |
class ListDigraph; |
|
| 36 |
|
|
| 35 | 37 |
class ListDigraphBase {
|
| 36 | 38 |
|
| 37 | 39 |
protected: |
| ... | ... |
@@ -62,6 +64,7 @@ |
| 62 | 64 |
|
| 63 | 65 |
class Node {
|
| 64 | 66 |
friend class ListDigraphBase; |
| 67 |
friend class ListDigraph; |
|
| 65 | 68 |
protected: |
| 66 | 69 |
|
| 67 | 70 |
int id; |
| ... | ... |
@@ -77,6 +80,7 @@ |
| 77 | 80 |
|
| 78 | 81 |
class Arc {
|
| 79 | 82 |
friend class ListDigraphBase; |
| 83 |
friend class ListDigraph; |
|
| 80 | 84 |
protected: |
| 81 | 85 |
|
| 82 | 86 |
int id; |
| ... | ... |
@@ -116,20 +120,20 @@ |
| 116 | 120 |
void first(Arc& arc) const {
|
| 117 | 121 |
int n; |
| 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 |
} |
| 123 | 127 |
|
| 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 |
} |
| 134 | 138 |
} |
| 135 | 139 |
|
| ... | ... |
@@ -311,31 +315,27 @@ |
| 311 | 315 |
|
| 312 | 316 |
///A general directed graph structure. |
| 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 {
|
| 326 | 332 |
typedef ExtendedListDigraphBase Parent; |
| 327 | 333 |
|
| 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 &) {}
|
| 340 | 340 |
public: |
| 341 | 341 |
|
| ... | ... |
@@ -347,71 +347,72 @@ |
| 347 | 347 |
|
| 348 | 348 |
///Add a new node to the digraph. |
| 349 | 349 |
|
| 350 |
/// |
|
| 350 |
///This function adds a new node to the digraph. |
|
| 351 | 351 |
///\return The new node. |
| 352 | 352 |
Node addNode() { return Parent::addNode(); }
|
| 353 | 353 |
|
| 354 | 354 |
///Add a new arc to the digraph. |
| 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); |
| 361 | 361 |
} |
| 362 | 362 |
|
| 363 | 363 |
///\brief Erase a node from the digraph. |
| 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 |
|
| 369 | 372 |
///\brief Erase an arc from the digraph. |
| 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 |
|
| 375 | 380 |
/// Node validity check |
| 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); }
|
| 384 | 388 |
|
| 385 | 389 |
/// Arc validity check |
| 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 |
/// |
| 403 | 405 |
///\warning This functionality cannot be used together with the Snapshot |
| 404 | 406 |
///feature. |
| 405 | 407 |
void changeTarget(Arc a, Node n) {
|
| 406 | 408 |
Parent::changeTarget(a,n); |
| 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 |
/// |
| 416 | 417 |
///\warning This functionality cannot be used together with the Snapshot |
| 417 | 418 |
///feature. |
| ... | ... |
@@ -419,94 +420,76 @@ |
| 419 | 420 |
Parent::changeSource(a,n); |
| 420 | 421 |
} |
| 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 |
/// |
| 428 | 429 |
///\warning This functionality cannot be used together with the Snapshot |
| 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 |
/// |
| 468 | 452 |
///\warning This functionality cannot be used together with the Snapshot |
| 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 |
} |
| 488 | 472 |
|
| 489 | 473 |
///Split a node. |
| 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. |
| 503 | 487 |
Node split(Node n, bool connect = true) {
|
| 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 |
} |
| 511 | 494 |
if (connect) addArc(n,b); |
| 512 | 495 |
return b; |
| ... | ... |
@@ -514,21 +497,53 @@ |
| 514 | 497 |
|
| 515 | 498 |
///Split an arc. |
| 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 |
/// |
| 523 | 509 |
///\warning This functionality cannot be used together with the |
| 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 |
| 533 | 548 |
/// it later. |
| 534 | 549 |
/// |
| ... | ... |
@@ -537,9 +552,15 @@ |
| 537 | 552 |
/// The newly added nodes and arcs can be removed using the |
| 538 | 553 |
/// restore() function. |
| 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 {
|
| 544 | 565 |
protected: |
| 545 | 566 |
|
| ... | ... |
@@ -709,39 +730,40 @@ |
| 709 | 730 |
/// \brief Default constructor. |
| 710 | 731 |
/// |
| 711 | 732 |
/// Default constructor. |
| 712 |
/// |
|
| 733 |
/// You have to call save() to actually make a snapshot. |
|
| 713 | 734 |
Snapshot() |
| 714 | 735 |
: digraph(0), node_observer_proxy(*this), |
| 715 | 736 |
arc_observer_proxy(*this) {}
|
| 716 | 737 |
|
| 717 | 738 |
/// \brief Constructor that immediately makes a snapshot. |
| 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 |
} |
| 726 | 746 |
|
| 727 | 747 |
/// \brief Make a snapshot. |
| 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()) {
|
| 736 | 754 |
detach(); |
| 737 | 755 |
clear(); |
| 738 | 756 |
} |
| 739 |
attach( |
|
| 757 |
attach(gr); |
|
| 740 | 758 |
} |
| 741 | 759 |
|
| 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() {
|
| 746 | 768 |
detach(); |
| 747 | 769 |
for(std::list<Arc>::iterator it = added_arcs.begin(); |
| ... | ... |
@@ -755,9 +777,9 @@ |
| 755 | 777 |
clear(); |
| 756 | 778 |
} |
| 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 {
|
| 762 | 784 |
return attached(); |
| 763 | 785 |
} |
| ... | ... |
@@ -795,10 +817,6 @@ |
| 795 | 817 |
|
| 796 | 818 |
typedef ListGraphBase Graph; |
| 797 | 819 |
|
| 798 |
class Node; |
|
| 799 |
class Arc; |
|
| 800 |
class Edge; |
|
| 801 |
|
|
| 802 | 820 |
class Node {
|
| 803 | 821 |
friend class ListGraphBase; |
| 804 | 822 |
protected: |
| ... | ... |
@@ -848,8 +866,6 @@ |
| 848 | 866 |
bool operator<(const Arc& arc) const {return id < arc.id;}
|
| 849 | 867 |
}; |
| 850 | 868 |
|
| 851 |
|
|
| 852 |
|
|
| 853 | 869 |
ListGraphBase() |
| 854 | 870 |
: nodes(), first_node(-1), |
| 855 | 871 |
first_free_node(-1), arcs(), first_free_arc(-1) {}
|
| ... | ... |
@@ -1164,31 +1180,27 @@ |
| 1164 | 1180 |
|
| 1165 | 1181 |
///A general undirected graph structure. |
| 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 {
|
| 1179 | 1197 |
typedef ExtendedListGraphBase Parent; |
| 1180 | 1198 |
|
| 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 &) {}
|
| 1193 | 1205 |
public: |
| 1194 | 1206 |
/// Constructor |
| ... | ... |
@@ -1201,94 +1213,102 @@ |
| 1201 | 1213 |
|
| 1202 | 1214 |
/// \brief Add a new node to the graph. |
| 1203 | 1215 |
/// |
| 1204 |
/// |
|
| 1216 |
/// This function adds a new node to the graph. |
|
| 1205 | 1217 |
/// \return The new node. |
| 1206 | 1218 |
Node addNode() { return Parent::addNode(); }
|
| 1207 | 1219 |
|
| 1208 | 1220 |
/// \brief Add a new edge to the graph. |
| 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 |
/// |
| 1264 | 1279 |
///\warning This functionality cannot be used together with the |
| 1265 | 1280 |
///Snapshot feature. |
| 1266 | 1281 |
void changeU(Edge e, Node n) {
|
| 1267 | 1282 |
Parent::changeU(e,n); |
| 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 |
/// |
| 1277 | 1293 |
///\warning This functionality cannot be used together with the |
| 1278 | 1294 |
///Snapshot feature. |
| 1279 | 1295 |
void changeV(Edge e, Node n) {
|
| 1280 | 1296 |
Parent::changeV(e,n); |
| 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 |
/// |
| 1293 | 1313 |
///\warning This functionality cannot be used together with the |
| 1294 | 1314 |
///Snapshot feature. |
| ... | ... |
@@ -1307,6 +1327,34 @@ |
| 1307 | 1327 |
erase(b); |
| 1308 | 1328 |
} |
| 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 |
|
| 1311 | 1359 |
/// \brief Class to make a snapshot of the graph and restore |
| 1312 | 1360 |
/// it later. |
| ... | ... |
@@ -1316,9 +1364,15 @@ |
| 1316 | 1364 |
/// The newly added nodes and edges can be removed |
| 1317 | 1365 |
/// using the restore() function. |
| 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 {
|
| 1323 | 1377 |
protected: |
| 1324 | 1378 |
|
| ... | ... |
@@ -1488,39 +1542,40 @@ |
| 1488 | 1542 |
/// \brief Default constructor. |
| 1489 | 1543 |
/// |
| 1490 | 1544 |
/// Default constructor. |
| 1491 |
/// |
|
| 1545 |
/// You have to call save() to actually make a snapshot. |
|
| 1492 | 1546 |
Snapshot() |
| 1493 | 1547 |
: graph(0), node_observer_proxy(*this), |
| 1494 | 1548 |
edge_observer_proxy(*this) {}
|
| 1495 | 1549 |
|
| 1496 | 1550 |
/// \brief Constructor that immediately makes a snapshot. |
| 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 |
} |
| 1505 | 1558 |
|
| 1506 | 1559 |
/// \brief Make a snapshot. |
| 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()) {
|
| 1515 | 1566 |
detach(); |
| 1516 | 1567 |
clear(); |
| 1517 | 1568 |
} |
| 1518 |
attach( |
|
| 1569 |
attach(gr); |
|
| 1519 | 1570 |
} |
| 1520 | 1571 |
|
| 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() {
|
| 1525 | 1580 |
detach(); |
| 1526 | 1581 |
for(std::list<Edge>::iterator it = added_edges.begin(); |
| ... | ... |
@@ -1534,9 +1589,9 @@ |
| 1534 | 1589 |
clear(); |
| 1535 | 1590 |
} |
| 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 {
|
| 1541 | 1596 |
return attached(); |
| 1542 | 1597 |
} |
| ... | ... |
@@ -146,7 +146,7 @@ |
| 146 | 146 |
|
| 147 | 147 |
///Iterator for iterate over the columns of an LP problem |
| 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: |
| 151 | 151 |
///\code |
| 152 | 152 |
/// int count=0; |
| ... | ... |
@@ -241,7 +241,7 @@ |
| 241 | 241 |
|
| 242 | 242 |
///Iterator for iterate over the rows of an LP problem |
| 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: |
| 246 | 246 |
///\code |
| 247 | 247 |
/// int count=0; |
| ... | ... |
@@ -943,6 +943,14 @@ |
| 943 | 943 |
virtual int _addCol() = 0; |
| 944 | 944 |
virtual int _addRow() = 0; |
| 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; |
| 947 | 955 |
virtual void _eraseRow(int row) = 0; |
| 948 | 956 |
|
| ... | ... |
@@ -1207,8 +1215,10 @@ |
| 1207 | 1215 |
///\param u is the upper bound (\ref INF means no bound) |
| 1208 | 1216 |
///\return The created row. |
| 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; |
| 1213 | 1223 |
} |
| 1214 | 1224 |
|
| ... | ... |
@@ -1217,8 +1227,12 @@ |
| 1217 | 1227 |
///\param c is a linear expression (see \ref Constr) |
| 1218 | 1228 |
///\return The created row. |
| 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; |
| 1223 | 1237 |
} |
| 1224 | 1238 |
///Erase a column (i.e a variable) from the LP |
| ... | ... |
@@ -56,7 +56,7 @@ |
| 56 | 56 |
/// its type definitions, or if you have to provide a writable map, |
| 57 | 57 |
/// but data written to it is not required (i.e. it will be sent to |
| 58 | 58 |
/// <tt>/dev/null</tt>). |
| 59 |
/// It conforms the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
| 59 |
/// It conforms to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
| 60 | 60 |
/// |
| 61 | 61 |
/// \sa ConstMap |
| 62 | 62 |
template<typename K, typename V> |
| ... | ... |
@@ -89,7 +89,7 @@ |
| 89 | 89 |
/// value to each key. |
| 90 | 90 |
/// |
| 91 | 91 |
/// In other aspects it is equivalent to \c NullMap. |
| 92 |
/// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap" |
|
| 92 |
/// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap" |
|
| 93 | 93 |
/// concept, but it absorbs the data written to it. |
| 94 | 94 |
/// |
| 95 | 95 |
/// The simplest way of using this map is through the constMap() |
| ... | ... |
@@ -158,7 +158,7 @@ |
| 158 | 158 |
/// value to each key. |
| 159 | 159 |
/// |
| 160 | 160 |
/// In other aspects it is equivalent to \c NullMap. |
| 161 |
/// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap" |
|
| 161 |
/// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap" |
|
| 162 | 162 |
/// concept, but it absorbs the data written to it. |
| 163 | 163 |
/// |
| 164 | 164 |
/// The simplest way of using this map is through the constMap() |
| ... | ... |
@@ -230,10 +230,10 @@ |
| 230 | 230 |
/// |
| 231 | 231 |
/// This map is essentially a wrapper for \c std::vector. It assigns |
| 232 | 232 |
/// values to integer keys from the range <tt>[0..size-1]</tt>. |
| 233 |
/// It can be used with some data structures, for example |
|
| 234 |
/// \c UnionFind, \c BinHeap, when the used items are small |
|
| 235 |
/// integers. This map conforms the \ref concepts::ReferenceMap |
|
| 236 |
/// "ReferenceMap" concept. |
|
| 233 |
/// It can be used together with some data structures, e.g. |
|
| 234 |
/// heap types and \c UnionFind, when the used items are small |
|
| 235 |
/// integers. This map conforms to the \ref concepts::ReferenceMap |
|
| 236 |
/// "ReferenceMap" concept. |
|
| 237 | 237 |
/// |
| 238 | 238 |
/// The simplest way of using this map is through the rangeMap() |
| 239 | 239 |
/// function. |
| ... | ... |
@@ -340,7 +340,7 @@ |
| 340 | 340 |
/// that you can specify a default value for the keys that are not |
| 341 | 341 |
/// stored actually. This value can be different from the default |
| 342 | 342 |
/// contructed value (i.e. \c %Value()). |
| 343 |
/// This type conforms the \ref concepts::ReferenceMap "ReferenceMap" |
|
| 343 |
/// This type conforms to the \ref concepts::ReferenceMap "ReferenceMap" |
|
| 344 | 344 |
/// concept. |
| 345 | 345 |
/// |
| 346 | 346 |
/// This map is useful if a default value should be assigned to most of |
| ... | ... |
@@ -348,9 +348,9 @@ |
| 348 | 348 |
/// keys (i.e. the map is "sparse"). |
| 349 | 349 |
/// The name of this type also refers to this important usage. |
| 350 | 350 |
/// |
| 351 |
/// Apart form that this map can be used in many other cases since it |
|
| 351 |
/// Apart form that, this map can be used in many other cases since it |
|
| 352 | 352 |
/// is based on \c std::map, which is a general associative container. |
| 353 |
/// However keep in mind that it is usually not as efficient as other |
|
| 353 |
/// However, keep in mind that it is usually not as efficient as other |
|
| 354 | 354 |
/// maps. |
| 355 | 355 |
/// |
| 356 | 356 |
/// The simplest way of using this map is through the sparseMap() |
| ... | ... |
@@ -706,7 +706,7 @@ |
| 706 | 706 |
/// "readable map" to another type using the default conversion. |
| 707 | 707 |
/// The \c Key type of it is inherited from \c M and the \c Value |
| 708 | 708 |
/// type is \c V. |
| 709 |
/// This type conforms the \ref concepts::ReadMap "ReadMap" concept. |
|
| 709 |
/// This type conforms to the \ref concepts::ReadMap "ReadMap" concept. |
|
| 710 | 710 |
/// |
| 711 | 711 |
/// The simplest way of using this map is through the convertMap() |
| 712 | 712 |
/// function. |
| ... | ... |
@@ -1785,22 +1785,22 @@ |
| 1785 | 1785 |
/// |
| 1786 | 1786 |
/// The most important usage of it is storing certain nodes or arcs |
| 1787 | 1787 |
/// that were marked \c true by an algorithm. |
| 1788 |
/// For example it makes easier to store the nodes in the processing |
|
| 1788 |
/// For example, it makes easier to store the nodes in the processing |
|
| 1789 | 1789 |
/// order of Dfs algorithm, as the following examples show. |
| 1790 | 1790 |
/// \code |
| 1791 | 1791 |
/// std::vector<Node> v; |
| 1792 |
/// dfs(g |
|
| 1792 |
/// dfs(g).processedMap(loggerBoolMap(std::back_inserter(v))).run(s); |
|
| 1793 | 1793 |
/// \endcode |
| 1794 | 1794 |
/// \code |
| 1795 | 1795 |
/// std::vector<Node> v(countNodes(g)); |
| 1796 |
/// dfs(g |
|
| 1796 |
/// dfs(g).processedMap(loggerBoolMap(v.begin())).run(s); |
|
| 1797 | 1797 |
/// \endcode |
| 1798 | 1798 |
/// |
| 1799 | 1799 |
/// \note The container of the iterator must contain enough space |
| 1800 | 1800 |
/// for the elements or the iterator should be an inserter iterator. |
| 1801 | 1801 |
/// |
| 1802 | 1802 |
/// \note LoggerBoolMap is just \ref concepts::WriteMap "writable", so |
| 1803 |
/// it cannot be used when a readable map is needed, for example as |
|
| 1803 |
/// it cannot be used when a readable map is needed, for example, as |
|
| 1804 | 1804 |
/// \c ReachedMap for \c Bfs, \c Dfs and \c Dijkstra algorithms. |
| 1805 | 1805 |
/// |
| 1806 | 1806 |
/// \relates LoggerBoolMap |
| ... | ... |
@@ -1825,7 +1825,7 @@ |
| 1825 | 1825 |
/// Using this map you get access (i.e. can read) the inner id values of |
| 1826 | 1826 |
/// the items stored in the graph, which is returned by the \c id() |
| 1827 | 1827 |
/// function of the graph. This map can be inverted with its member |
| 1828 |
/// class \c InverseMap or with the \c operator() member. |
|
| 1828 |
/// class \c InverseMap or with the \c operator()() member. |
|
| 1829 | 1829 |
/// |
| 1830 | 1830 |
/// \tparam GR The graph type. |
| 1831 | 1831 |
/// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or |
| ... | ... |
@@ -1865,9 +1865,11 @@ |
| 1865 | 1865 |
|
| 1866 | 1866 |
public: |
| 1867 | 1867 |
|
| 1868 |
/// \brief |
|
| 1868 |
/// \brief The inverse map type of IdMap. |
|
| 1869 | 1869 |
/// |
| 1870 |
/// |
|
| 1870 |
/// The inverse map type of IdMap. The subscript operator gives back |
|
| 1871 |
/// an item by its id. |
|
| 1872 |
/// This type conforms to the \ref concepts::ReadMap "ReadMap" concept. |
|
| 1871 | 1873 |
/// \see inverse() |
| 1872 | 1874 |
class InverseMap {
|
| 1873 | 1875 |
public: |
| ... | ... |
@@ -1882,9 +1884,9 @@ |
| 1882 | 1884 |
/// Constructor for creating an id-to-item map. |
| 1883 | 1885 |
explicit InverseMap(const IdMap& map) : _graph(map._graph) {}
|
| 1884 | 1886 |
|
| 1885 |
/// \brief Gives back |
|
| 1887 |
/// \brief Gives back an item by its id. |
|
| 1886 | 1888 |
/// |
| 1887 |
/// Gives back |
|
| 1889 |
/// Gives back an item by its id. |
|
| 1888 | 1890 |
Item operator[](int id) const { return _graph->fromId(id, Item());}
|
| 1889 | 1891 |
|
| 1890 | 1892 |
private: |
| ... | ... |
@@ -1897,14 +1899,31 @@ |
| 1897 | 1899 |
InverseMap inverse() const { return InverseMap(*_graph);}
|
| 1898 | 1900 |
}; |
| 1899 | 1901 |
|
| 1902 |
/// \brief Returns an \c IdMap class. |
|
| 1903 |
/// |
|
| 1904 |
/// This function just returns an \c IdMap class. |
|
| 1905 |
/// \relates IdMap |
|
| 1906 |
template <typename K, typename GR> |
|
| 1907 |
inline IdMap<GR, K> idMap(const GR& graph) {
|
|
| 1908 |
return IdMap<GR, K>(graph); |
|
| 1909 |
} |
|
| 1900 | 1910 |
|
| 1901 | 1911 |
/// \brief General cross reference graph map type. |
| 1902 | 1912 |
|
| 1903 | 1913 |
/// This class provides simple invertable graph maps. |
| 1904 | 1914 |
/// It wraps a standard graph map (\c NodeMap, \c ArcMap or \c EdgeMap) |
| 1905 | 1915 |
/// and if a key is set to a new value, then stores it in the inverse map. |
| 1906 |
/// The values of the map can be accessed |
|
| 1907 |
/// with stl compatible forward iterator. |
|
| 1916 |
/// The graph items can be accessed by their values either using |
|
| 1917 |
/// \c InverseMap or \c operator()(), and the values of the map can be |
|
| 1918 |
/// accessed with an STL compatible forward iterator (\c ValueIt). |
|
| 1919 |
/// |
|
| 1920 |
/// This map is intended to be used when all associated values are |
|
| 1921 |
/// different (the map is actually invertable) or there are only a few |
|
| 1922 |
/// items with the same value. |
|
| 1923 |
/// Otherwise consider to use \c IterableValueMap, which is more |
|
| 1924 |
/// suitable and more efficient for such cases. It provides iterators |
|
| 1925 |
/// to traverse the items with the same associated value, but |
|
| 1926 |
/// it does not have \c InverseMap. |
|
| 1908 | 1927 |
/// |
| 1909 | 1928 |
/// This type is not reference map, so it cannot be modified with |
| 1910 | 1929 |
/// the subscript operator. |
| ... | ... |
@@ -1945,56 +1964,66 @@ |
| 1945 | 1964 |
|
| 1946 | 1965 |
/// \brief Forward iterator for values. |
| 1947 | 1966 |
/// |
| 1948 |
/// This iterator is an |
|
| 1967 |
/// This iterator is an STL compatible forward |
|
| 1949 | 1968 |
/// iterator on the values of the map. The values can |
| 1950 | 1969 |
/// be accessed in the <tt>[beginValue, endValue)</tt> range. |
| 1951 | 1970 |
/// They are considered with multiplicity, so each value is |
| 1952 | 1971 |
/// traversed for each item it is assigned to. |
| 1953 |
class |
|
| 1972 |
class ValueIt |
|
| 1954 | 1973 |
: public std::iterator<std::forward_iterator_tag, Value> {
|
| 1955 | 1974 |
friend class CrossRefMap; |
| 1956 | 1975 |
private: |
| 1957 |
|
|
| 1976 |
ValueIt(typename Container::const_iterator _it) |
|
| 1958 | 1977 |
: it(_it) {}
|
| 1959 | 1978 |
public: |
| 1960 | 1979 |
|
| 1961 |
ValueIterator() {}
|
|
| 1962 |
|
|
| 1963 |
ValueIterator& operator++() { ++it; return *this; }
|
|
| 1964 |
ValueIterator operator++(int) {
|
|
| 1965 |
|
|
| 1980 |
/// Constructor |
|
| 1981 |
ValueIt() {}
|
|
| 1982 |
|
|
| 1983 |
/// \e |
|
| 1984 |
ValueIt& operator++() { ++it; return *this; }
|
|
| 1985 |
/// \e |
|
| 1986 |
ValueIt operator++(int) {
|
|
| 1987 |
ValueIt tmp(*this); |
|
| 1966 | 1988 |
operator++(); |
| 1967 | 1989 |
return tmp; |
| 1968 | 1990 |
} |
| 1969 | 1991 |
|
| 1992 |
/// \e |
|
| 1970 | 1993 |
const Value& operator*() const { return it->first; }
|
| 1994 |
/// \e |
|
| 1971 | 1995 |
const Value* operator->() const { return &(it->first); }
|
| 1972 | 1996 |
|
| 1973 |
bool operator==(ValueIterator jt) const { return it == jt.it; }
|
|
| 1974 |
bool operator!=(ValueIterator jt) const { return it != jt.it; }
|
|
| 1997 |
/// \e |
|
| 1998 |
bool operator==(ValueIt jt) const { return it == jt.it; }
|
|
| 1999 |
/// \e |
|
| 2000 |
bool operator!=(ValueIt jt) const { return it != jt.it; }
|
|
| 1975 | 2001 |
|
| 1976 | 2002 |
private: |
| 1977 | 2003 |
typename Container::const_iterator it; |
| 1978 | 2004 |
}; |
| 2005 |
|
|
| 2006 |
/// Alias for \c ValueIt |
|
| 2007 |
typedef ValueIt ValueIterator; |
|
| 1979 | 2008 |
|
| 1980 | 2009 |
/// \brief Returns an iterator to the first value. |
| 1981 | 2010 |
/// |
| 1982 |
/// Returns an |
|
| 2011 |
/// Returns an STL compatible iterator to the |
|
| 1983 | 2012 |
/// first value of the map. The values of the |
| 1984 | 2013 |
/// map can be accessed in the <tt>[beginValue, endValue)</tt> |
| 1985 | 2014 |
/// range. |
| 1986 |
ValueIterator beginValue() const {
|
|
| 1987 |
return ValueIterator(_inv_map.begin()); |
|
| 2015 |
ValueIt beginValue() const {
|
|
| 2016 |
return ValueIt(_inv_map.begin()); |
|
| 1988 | 2017 |
} |
| 1989 | 2018 |
|
| 1990 | 2019 |
/// \brief Returns an iterator after the last value. |
| 1991 | 2020 |
/// |
| 1992 |
/// Returns an |
|
| 2021 |
/// Returns an STL compatible iterator after the |
|
| 1993 | 2022 |
/// last value of the map. The values of the |
| 1994 | 2023 |
/// map can be accessed in the <tt>[beginValue, endValue)</tt> |
| 1995 | 2024 |
/// range. |
| 1996 |
ValueIterator endValue() const {
|
|
| 1997 |
return ValueIterator(_inv_map.end()); |
|
| 2025 |
ValueIt endValue() const {
|
|
| 2026 |
return ValueIt(_inv_map.end()); |
|
| 1998 | 2027 |
} |
| 1999 | 2028 |
|
| 2000 | 2029 |
/// \brief Sets the value associated with the given key. |
| ... | ... |
@@ -2032,6 +2061,14 @@ |
| 2032 | 2061 |
typename Container::const_iterator it = _inv_map.find(val); |
| 2033 | 2062 |
return it != _inv_map.end() ? it->second : INVALID; |
| 2034 | 2063 |
} |
| 2064 |
|
|
| 2065 |
/// \brief Returns the number of items with the given value. |
|
| 2066 |
/// |
|
| 2067 |
/// This function returns the number of items with the given value |
|
| 2068 |
/// associated with it. |
|
| 2069 |
int count(const Value &val) const {
|
|
| 2070 |
return _inv_map.count(val); |
|
| 2071 |
} |
|
| 2035 | 2072 |
|
| 2036 | 2073 |
protected: |
| 2037 | 2074 |
|
| ... | ... |
@@ -2082,10 +2119,12 @@ |
| 2082 | 2119 |
|
| 2083 | 2120 |
public: |
| 2084 | 2121 |
|
| 2085 |
/// \brief The inverse map type. |
|
| 2122 |
/// \brief The inverse map type of CrossRefMap. |
|
| 2086 | 2123 |
/// |
| 2087 |
/// The inverse of this map. The subscript operator of the map |
|
| 2088 |
/// gives back the item that was last assigned to the value. |
|
| 2124 |
/// The inverse map type of CrossRefMap. The subscript operator gives |
|
| 2125 |
/// back an item by its value. |
|
| 2126 |
/// This type conforms to the \ref concepts::ReadMap "ReadMap" concept. |
|
| 2127 |
/// \see inverse() |
|
| 2089 | 2128 |
class InverseMap {
|
| 2090 | 2129 |
public: |
| 2091 | 2130 |
/// \brief Constructor |
| ... | ... |
@@ -2112,20 +2151,20 @@ |
| 2112 | 2151 |
const CrossRefMap& _inverted; |
| 2113 | 2152 |
}; |
| 2114 | 2153 |
|
| 2115 |
/// \brief |
|
| 2154 |
/// \brief Gives back the inverse of the map. |
|
| 2116 | 2155 |
/// |
| 2117 |
/// |
|
| 2156 |
/// Gives back the inverse of the CrossRefMap. |
|
| 2118 | 2157 |
InverseMap inverse() const {
|
| 2119 | 2158 |
return InverseMap(*this); |
| 2120 | 2159 |
} |
| 2121 | 2160 |
|
| 2122 | 2161 |
}; |
| 2123 | 2162 |
|
| 2124 |
/// \brief Provides continuous and unique |
|
| 2163 |
/// \brief Provides continuous and unique id for the |
|
| 2125 | 2164 |
/// items of a graph. |
| 2126 | 2165 |
/// |
| 2127 | 2166 |
/// RangeIdMap provides a unique and continuous |
| 2128 |
/// |
|
| 2167 |
/// id for each item of a given type (\c Node, \c Arc or |
|
| 2129 | 2168 |
/// \c Edge) in a graph. This id is |
| 2130 | 2169 |
/// - \b unique: different items get different ids, |
| 2131 | 2170 |
/// - \b continuous: the range of the ids is the set of integers |
| ... | ... |
@@ -2136,7 +2175,7 @@ |
| 2136 | 2175 |
/// Thus this id is not (necessarily) the same as what can get using |
| 2137 | 2176 |
/// the \c id() function of the graph or \ref IdMap. |
| 2138 | 2177 |
/// This map can be inverted with its member class \c InverseMap, |
| 2139 |
/// or with the \c operator() member. |
|
| 2178 |
/// or with the \c operator()() member. |
|
| 2140 | 2179 |
/// |
| 2141 | 2180 |
/// \tparam GR The graph type. |
| 2142 | 2181 |
/// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or |
| ... | ... |
@@ -2264,16 +2303,16 @@ |
| 2264 | 2303 |
_inv_map[pi] = q; |
| 2265 | 2304 |
} |
| 2266 | 2305 |
|
| 2267 |
/// \brief Gives back the \e |
|
| 2306 |
/// \brief Gives back the \e range \e id of the item |
|
| 2268 | 2307 |
/// |
| 2269 |
/// Gives back the \e |
|
| 2308 |
/// Gives back the \e range \e id of the item. |
|
| 2270 | 2309 |
int operator[](const Item& item) const {
|
| 2271 | 2310 |
return Map::operator[](item); |
| 2272 | 2311 |
} |
| 2273 | 2312 |
|
| 2274 |
/// \brief Gives back the item belonging to a \e |
|
| 2313 |
/// \brief Gives back the item belonging to a \e range \e id |
|
| 2275 | 2314 |
/// |
| 2276 |
/// Gives back the item belonging to |
|
| 2315 |
/// Gives back the item belonging to the given \e range \e id. |
|
| 2277 | 2316 |
Item operator()(int id) const {
|
| 2278 | 2317 |
return _inv_map[id]; |
| 2279 | 2318 |
} |
| ... | ... |
@@ -2287,7 +2326,9 @@ |
| 2287 | 2326 |
|
| 2288 | 2327 |
/// \brief The inverse map type of RangeIdMap. |
| 2289 | 2328 |
/// |
| 2290 |
/// The inverse map type of RangeIdMap. |
|
| 2329 |
/// The inverse map type of RangeIdMap. The subscript operator gives |
|
| 2330 |
/// back an item by its \e range \e id. |
|
| 2331 |
/// This type conforms to the \ref concepts::ReadMap "ReadMap" concept. |
|
| 2291 | 2332 |
class InverseMap {
|
| 2292 | 2333 |
public: |
| 2293 | 2334 |
/// \brief Constructor |
| ... | ... |
@@ -2305,7 +2346,7 @@ |
| 2305 | 2346 |
/// \brief Subscript operator. |
| 2306 | 2347 |
/// |
| 2307 | 2348 |
/// Subscript operator. It gives back the item |
| 2308 |
/// that the |
|
| 2349 |
/// that the given \e range \e id currently belongs to. |
|
| 2309 | 2350 |
Value operator[](const Key& key) const {
|
| 2310 | 2351 |
return _inverted(key); |
| 2311 | 2352 |
} |
| ... | ... |
@@ -2323,18 +2364,27 @@ |
| 2323 | 2364 |
|
| 2324 | 2365 |
/// \brief Gives back the inverse of the map. |
| 2325 | 2366 |
/// |
| 2326 |
/// Gives back the inverse of the |
|
| 2367 |
/// Gives back the inverse of the RangeIdMap. |
|
| 2327 | 2368 |
const InverseMap inverse() const {
|
| 2328 | 2369 |
return InverseMap(*this); |
| 2329 | 2370 |
} |
| 2330 | 2371 |
}; |
| 2331 | 2372 |
|
| 2373 |
/// \brief Returns a \c RangeIdMap class. |
|
| 2374 |
/// |
|
| 2375 |
/// This function just returns an \c RangeIdMap class. |
|
| 2376 |
/// \relates RangeIdMap |
|
| 2377 |
template <typename K, typename GR> |
|
| 2378 |
inline RangeIdMap<GR, K> rangeIdMap(const GR& graph) {
|
|
| 2379 |
return RangeIdMap<GR, K>(graph); |
|
| 2380 |
} |
|
| 2381 |
|
|
| 2332 | 2382 |
/// \brief Dynamic iterable \c bool map. |
| 2333 | 2383 |
/// |
| 2334 | 2384 |
/// This class provides a special graph map type which can store a |
| 2335 | 2385 |
/// \c bool value for graph items (\c Node, \c Arc or \c Edge). |
| 2336 | 2386 |
/// For both \c true and \c false values it is possible to iterate on |
| 2337 |
/// the keys. |
|
| 2387 |
/// the keys mapped to the value. |
|
| 2338 | 2388 |
/// |
| 2339 | 2389 |
/// This type is a reference map, so it can be modified with the |
| 2340 | 2390 |
/// subscript operator. |
| ... | ... |
@@ -2703,6 +2753,11 @@ |
| 2703 | 2753 |
/// For each non-negative value it is possible to iterate on the keys |
| 2704 | 2754 |
/// mapped to the value. |
| 2705 | 2755 |
/// |
| 2756 |
/// This map is intended to be used with small integer values, for which |
|
| 2757 |
/// it is efficient, and supports iteration only for non-negative values. |
|
| 2758 |
/// If you need large values and/or iteration for negative integers, |
|
| 2759 |
/// consider to use \ref IterableValueMap instead. |
|
| 2760 |
/// |
|
| 2706 | 2761 |
/// This type is a reference map, so it can be modified with the |
| 2707 | 2762 |
/// subscript operator. |
| 2708 | 2763 |
/// |
| ... | ... |
@@ -2984,15 +3039,17 @@ |
| 2984 | 3039 |
|
| 2985 | 3040 |
/// \brief Dynamic iterable map for comparable values. |
| 2986 | 3041 |
/// |
| 2987 |
/// This class provides a special graph map type which can store |
|
| 3042 |
/// This class provides a special graph map type which can store a |
|
| 2988 | 3043 |
/// comparable value for graph items (\c Node, \c Arc or \c Edge). |
| 2989 | 3044 |
/// For each value it is possible to iterate on the keys mapped to |
| 2990 |
/// the value |
|
| 3045 |
/// the value (\c ItemIt), and the values of the map can be accessed |
|
| 3046 |
/// with an STL compatible forward iterator (\c ValueIt). |
|
| 3047 |
/// The map stores a linked list for each value, which contains |
|
| 3048 |
/// the items mapped to the value, and the used values are stored |
|
| 3049 |
/// in balanced binary tree (\c std::map). |
|
| 2991 | 3050 |
/// |
| 2992 |
/// The map stores for each value a linked list with |
|
| 2993 |
/// the items which mapped to the value, and the values are stored |
|
| 2994 |
/// in balanced binary tree. The values of the map can be accessed |
|
| 2995 |
/// with stl compatible forward iterator. |
|
| 3051 |
/// \ref IterableBoolMap and \ref IterableIntMap are similar classes |
|
| 3052 |
/// specialized for \c bool and \c int values, respectively. |
|
| 2996 | 3053 |
/// |
| 2997 | 3054 |
/// This type is not reference map, so it cannot be modified with |
| 2998 | 3055 |
/// the subscript operator. |
| ... | ... |
@@ -3071,31 +3128,38 @@ |
| 3071 | 3128 |
|
| 3072 | 3129 |
/// \brief Forward iterator for values. |
| 3073 | 3130 |
/// |
| 3074 |
/// This iterator is an |
|
| 3131 |
/// This iterator is an STL compatible forward |
|
| 3075 | 3132 |
/// iterator on the values of the map. The values can |
| 3076 | 3133 |
/// be accessed in the <tt>[beginValue, endValue)</tt> range. |
| 3077 |
class |
|
| 3134 |
class ValueIt |
|
| 3078 | 3135 |
: public std::iterator<std::forward_iterator_tag, Value> {
|
| 3079 | 3136 |
friend class IterableValueMap; |
| 3080 | 3137 |
private: |
| 3081 |
|
|
| 3138 |
ValueIt(typename std::map<Value, Key>::const_iterator _it) |
|
| 3082 | 3139 |
: it(_it) {}
|
| 3083 | 3140 |
public: |
| 3084 | 3141 |
|
| 3085 |
ValueIterator() {}
|
|
| 3086 |
|
|
| 3087 |
ValueIterator& operator++() { ++it; return *this; }
|
|
| 3088 |
ValueIterator operator++(int) {
|
|
| 3089 |
|
|
| 3142 |
/// Constructor |
|
| 3143 |
ValueIt() {}
|
|
| 3144 |
|
|
| 3145 |
/// \e |
|
| 3146 |
ValueIt& operator++() { ++it; return *this; }
|
|
| 3147 |
/// \e |
|
| 3148 |
ValueIt operator++(int) {
|
|
| 3149 |
ValueIt tmp(*this); |
|
| 3090 | 3150 |
operator++(); |
| 3091 | 3151 |
return tmp; |
| 3092 | 3152 |
} |
| 3093 | 3153 |
|
| 3154 |
/// \e |
|
| 3094 | 3155 |
const Value& operator*() const { return it->first; }
|
| 3156 |
/// \e |
|
| 3095 | 3157 |
const Value* operator->() const { return &(it->first); }
|
| 3096 | 3158 |
|
| 3097 |
bool operator==(ValueIterator jt) const { return it == jt.it; }
|
|
| 3098 |
bool operator!=(ValueIterator jt) const { return it != jt.it; }
|
|
| 3159 |
/// \e |
|
| 3160 |
bool operator==(ValueIt jt) const { return it == jt.it; }
|
|
| 3161 |
/// \e |
|
| 3162 |
bool operator!=(ValueIt jt) const { return it != jt.it; }
|
|
| 3099 | 3163 |
|
| 3100 | 3164 |
private: |
| 3101 | 3165 |
typename std::map<Value, Key>::const_iterator it; |
| ... | ... |
@@ -3103,22 +3167,22 @@ |
| 3103 | 3167 |
|
| 3104 | 3168 |
/// \brief Returns an iterator to the first value. |
| 3105 | 3169 |
/// |
| 3106 |
/// Returns an |
|
| 3170 |
/// Returns an STL compatible iterator to the |
|
| 3107 | 3171 |
/// first value of the map. The values of the |
| 3108 | 3172 |
/// map can be accessed in the <tt>[beginValue, endValue)</tt> |
| 3109 | 3173 |
/// range. |
| 3110 |
ValueIterator beginValue() const {
|
|
| 3111 |
return ValueIterator(_first.begin()); |
|
| 3174 |
ValueIt beginValue() const {
|
|
| 3175 |
return ValueIt(_first.begin()); |
|
| 3112 | 3176 |
} |
| 3113 | 3177 |
|
| 3114 | 3178 |
/// \brief Returns an iterator after the last value. |
| 3115 | 3179 |
/// |
| 3116 |
/// Returns an |
|
| 3180 |
/// Returns an STL compatible iterator after the |
|
| 3117 | 3181 |
/// last value of the map. The values of the |
| 3118 | 3182 |
/// map can be accessed in the <tt>[beginValue, endValue)</tt> |
| 3119 | 3183 |
/// range. |
| 3120 |
ValueIterator endValue() const {
|
|
| 3121 |
return ValueIterator(_first.end()); |
|
| 3184 |
ValueIt endValue() const {
|
|
| 3185 |
return ValueIt(_first.end()); |
|
| 3122 | 3186 |
} |
| 3123 | 3187 |
|
| 3124 | 3188 |
/// \brief Set operation of the map. |
| ... | ... |
@@ -3236,9 +3300,9 @@ |
| 3236 | 3300 |
class SourceMap {
|
| 3237 | 3301 |
public: |
| 3238 | 3302 |
|
| 3239 |
///\ |
|
| 3303 |
/// The key type (the \c Arc type of the digraph). |
|
| 3240 | 3304 |
typedef typename GR::Arc Key; |
| 3241 |
///\ |
|
| 3305 |
/// The value type (the \c Node type of the digraph). |
|
| 3242 | 3306 |
typedef typename GR::Node Value; |
| 3243 | 3307 |
|
| 3244 | 3308 |
/// \brief Constructor |
| ... | ... |
@@ -3277,9 +3341,9 @@ |
| 3277 | 3341 |
class TargetMap {
|
| 3278 | 3342 |
public: |
| 3279 | 3343 |
|
| 3280 |
///\ |
|
| 3344 |
/// The key type (the \c Arc type of the digraph). |
|
| 3281 | 3345 |
typedef typename GR::Arc Key; |
| 3282 |
///\ |
|
| 3346 |
/// The value type (the \c Node type of the digraph). |
|
| 3283 | 3347 |
typedef typename GR::Node Value; |
| 3284 | 3348 |
|
| 3285 | 3349 |
/// \brief Constructor |
| ... | ... |
@@ -3319,8 +3383,10 @@ |
| 3319 | 3383 |
class ForwardMap {
|
| 3320 | 3384 |
public: |
| 3321 | 3385 |
|
| 3386 |
/// The key type (the \c Edge type of the digraph). |
|
| 3387 |
typedef typename GR::Edge Key; |
|
| 3388 |
/// The value type (the \c Arc type of the digraph). |
|
| 3322 | 3389 |
typedef typename GR::Arc Value; |
| 3323 |
typedef typename GR::Edge Key; |
|
| 3324 | 3390 |
|
| 3325 | 3391 |
/// \brief Constructor |
| 3326 | 3392 |
/// |
| ... | ... |
@@ -3359,8 +3425,10 @@ |
| 3359 | 3425 |
class BackwardMap {
|
| 3360 | 3426 |
public: |
| 3361 | 3427 |
|
| 3428 |
/// The key type (the \c Edge type of the digraph). |
|
| 3429 |
typedef typename GR::Edge Key; |
|
| 3430 |
/// The value type (the \c Arc type of the digraph). |
|
| 3362 | 3431 |
typedef typename GR::Arc Value; |
| 3363 |
typedef typename GR::Edge Key; |
|
| 3364 | 3432 |
|
| 3365 | 3433 |
/// \brief Constructor |
| 3366 | 3434 |
/// |
| ... | ... |
@@ -3398,7 +3466,7 @@ |
| 3398 | 3466 |
/// \warning Besides \c addNode() and \c addArc(), a digraph structure |
| 3399 | 3467 |
/// may provide alternative ways to modify the digraph. |
| 3400 | 3468 |
/// The correct behavior of InDegMap is not guarantied if these additional |
| 3401 |
/// features are used. For example the functions |
|
| 3469 |
/// features are used. For example, the functions |
|
| 3402 | 3470 |
/// \ref ListDigraph::changeSource() "changeSource()", |
| 3403 | 3471 |
/// \ref ListDigraph::changeTarget() "changeTarget()" and |
| 3404 | 3472 |
/// \ref ListDigraph::reverseArc() "reverseArc()" |
| ... | ... |
@@ -3528,7 +3596,7 @@ |
| 3528 | 3596 |
/// \warning Besides \c addNode() and \c addArc(), a digraph structure |
| 3529 | 3597 |
/// may provide alternative ways to modify the digraph. |
| 3530 | 3598 |
/// The correct behavior of OutDegMap is not guarantied if these additional |
| 3531 |
/// features are used. For example the functions |
|
| 3599 |
/// features are used. For example, the functions |
|
| 3532 | 3600 |
/// \ref ListDigraph::changeSource() "changeSource()", |
| 3533 | 3601 |
/// \ref ListDigraph::changeTarget() "changeTarget()" and |
| 3534 | 3602 |
/// \ref ListDigraph::reverseArc() "reverseArc()" |
| ... | ... |
@@ -3696,6 +3764,293 @@ |
| 3696 | 3764 |
return PotentialDifferenceMap<GR, POT>(gr, potential); |
| 3697 | 3765 |
} |
| 3698 | 3766 |
|
| 3767 |
|
|
| 3768 |
/// \brief Copy the values of a graph map to another map. |
|
| 3769 |
/// |
|
| 3770 |
/// This function copies the values of a graph map to another graph map. |
|
| 3771 |
/// \c To::Key must be equal or convertible to \c From::Key and |
|
| 3772 |
/// \c From::Value must be equal or convertible to \c To::Value. |
|
| 3773 |
/// |
|
| 3774 |
/// For example, an edge map of \c int value type can be copied to |
|
| 3775 |
/// an arc map of \c double value type in an undirected graph, but |
|
| 3776 |
/// an arc map cannot be copied to an edge map. |
|
| 3777 |
/// Note that even a \ref ConstMap can be copied to a standard graph map, |
|
| 3778 |
/// but \ref mapFill() can also be used for this purpose. |
|
| 3779 |
/// |
|
| 3780 |
/// \param gr The graph for which the maps are defined. |
|
| 3781 |
/// \param from The map from which the values have to be copied. |
|
| 3782 |
/// It must conform to the \ref concepts::ReadMap "ReadMap" concept. |
|
| 3783 |
/// \param to The map to which the values have to be copied. |
|
| 3784 |
/// It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
| 3785 |
template <typename GR, typename From, typename To> |
|
| 3786 |
void mapCopy(const GR& gr, const From& from, To& to) {
|
|
| 3787 |
typedef typename To::Key Item; |
|
| 3788 |
typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt; |
|
| 3789 |
|
|
| 3790 |
for (ItemIt it(gr); it != INVALID; ++it) {
|
|
| 3791 |
to.set(it, from[it]); |
|
| 3792 |
} |
|
| 3793 |
} |
|
| 3794 |
|
|
| 3795 |
/// \brief Compare two graph maps. |
|
| 3796 |
/// |
|
| 3797 |
/// This function compares the values of two graph maps. It returns |
|
| 3798 |
/// \c true if the maps assign the same value for all items in the graph. |
|
| 3799 |
/// The \c Key type of the maps (\c Node, \c Arc or \c Edge) must be equal |
|
| 3800 |
/// and their \c Value types must be comparable using \c %operator==(). |
|
| 3801 |
/// |
|
| 3802 |
/// \param gr The graph for which the maps are defined. |
|
| 3803 |
/// \param map1 The first map. |
|
| 3804 |
/// \param map2 The second map. |
|
| 3805 |
template <typename GR, typename Map1, typename Map2> |
|
| 3806 |
bool mapCompare(const GR& gr, const Map1& map1, const Map2& map2) {
|
|
| 3807 |
typedef typename Map2::Key Item; |
|
| 3808 |
typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt; |
|
| 3809 |
|
|
| 3810 |
for (ItemIt it(gr); it != INVALID; ++it) {
|
|
| 3811 |
if (!(map1[it] == map2[it])) return false; |
|
| 3812 |
} |
|
| 3813 |
return true; |
|
| 3814 |
} |
|
| 3815 |
|
|
| 3816 |
/// \brief Return an item having minimum value of a graph map. |
|
| 3817 |
/// |
|
| 3818 |
/// This function returns an item (\c Node, \c Arc or \c Edge) having |
|
| 3819 |
/// minimum value of the given graph map. |
|
| 3820 |
/// If the item set is empty, it returns \c INVALID. |
|
| 3821 |
/// |
|
| 3822 |
/// \param gr The graph for which the map is defined. |
|
| 3823 |
/// \param map The graph map. |
|
| 3824 |
template <typename GR, typename Map> |
|
| 3825 |
typename Map::Key mapMin(const GR& gr, const Map& map) {
|
|
| 3826 |
return mapMin(gr, map, std::less<typename Map::Value>()); |
|
| 3827 |
} |
|
| 3828 |
|
|
| 3829 |
/// \brief Return an item having minimum value of a graph map. |
|
| 3830 |
/// |
|
| 3831 |
/// This function returns an item (\c Node, \c Arc or \c Edge) having |
|
| 3832 |
/// minimum value of the given graph map. |
|
| 3833 |
/// If the item set is empty, it returns \c INVALID. |
|
| 3834 |
/// |
|
| 3835 |
/// \param gr The graph for which the map is defined. |
|
| 3836 |
/// \param map The graph map. |
|
| 3837 |
/// \param comp Comparison function object. |
|
| 3838 |
template <typename GR, typename Map, typename Comp> |
|
| 3839 |
typename Map::Key mapMin(const GR& gr, const Map& map, const Comp& comp) {
|
|
| 3840 |
typedef typename Map::Key Item; |
|
| 3841 |
typedef typename Map::Value Value; |
|
| 3842 |
typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt; |
|
| 3843 |
|
|
| 3844 |
ItemIt min_item(gr); |
|
| 3845 |
if (min_item == INVALID) return INVALID; |
|
| 3846 |
Value min = map[min_item]; |
|
| 3847 |
for (ItemIt it(gr); it != INVALID; ++it) {
|
|
| 3848 |
if (comp(map[it], min)) {
|
|
| 3849 |
min = map[it]; |
|
| 3850 |
min_item = it; |
|
| 3851 |
} |
|
| 3852 |
} |
|
| 3853 |
return min_item; |
|
| 3854 |
} |
|
| 3855 |
|
|
| 3856 |
/// \brief Return an item having maximum value of a graph map. |
|
| 3857 |
/// |
|
| 3858 |
/// This function returns an item (\c Node, \c Arc or \c Edge) having |
|
| 3859 |
/// maximum value of the given graph map. |
|
| 3860 |
/// If the item set is empty, it returns \c INVALID. |
|
| 3861 |
/// |
|
| 3862 |
/// \param gr The graph for which the map is defined. |
|
| 3863 |
/// \param map The graph map. |
|
| 3864 |
template <typename GR, typename Map> |
|
| 3865 |
typename Map::Key mapMax(const GR& gr, const Map& map) {
|
|
| 3866 |
return mapMax(gr, map, std::less<typename Map::Value>()); |
|
| 3867 |
} |
|
| 3868 |
|
|
| 3869 |
/// \brief Return an item having maximum value of a graph map. |
|
| 3870 |
/// |
|
| 3871 |
/// This function returns an item (\c Node, \c Arc or \c Edge) having |
|
| 3872 |
/// maximum value of the given graph map. |
|
| 3873 |
/// If the item set is empty, it returns \c INVALID. |
|
| 3874 |
/// |
|
| 3875 |
/// \param gr The graph for which the map is defined. |
|
| 3876 |
/// \param map The graph map. |
|
| 3877 |
/// \param comp Comparison function object. |
|
| 3878 |
template <typename GR, typename Map, typename Comp> |
|
| 3879 |
typename Map::Key mapMax(const GR& gr, const Map& map, const Comp& comp) {
|
|
| 3880 |
typedef typename Map::Key Item; |
|
| 3881 |
typedef typename Map::Value Value; |
|
| 3882 |
typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt; |
|
| 3883 |
|
|
| 3884 |
ItemIt max_item(gr); |
|
| 3885 |
if (max_item == INVALID) return INVALID; |
|
| 3886 |
Value max = map[max_item]; |
|
| 3887 |
for (ItemIt it(gr); it != INVALID; ++it) {
|
|
| 3888 |
if (comp(max, map[it])) {
|
|
| 3889 |
max = map[it]; |
|
| 3890 |
max_item = it; |
|
| 3891 |
} |
|
| 3892 |
} |
|
| 3893 |
return max_item; |
|
| 3894 |
} |
|
| 3895 |
|
|
| 3896 |
/// \brief Return the minimum value of a graph map. |
|
| 3897 |
/// |
|
| 3898 |
/// This function returns the minimum value of the given graph map. |
|
| 3899 |
/// The corresponding item set of the graph must not be empty. |
|
| 3900 |
/// |
|
| 3901 |
/// \param gr The graph for which the map is defined. |
|
| 3902 |
/// \param map The graph map. |
|
| 3903 |
template <typename GR, typename Map> |
|
| 3904 |
typename Map::Value mapMinValue(const GR& gr, const Map& map) {
|
|
| 3905 |
return map[mapMin(gr, map, std::less<typename Map::Value>())]; |
|
| 3906 |
} |
|
| 3907 |
|
|
| 3908 |
/// \brief Return the minimum value of a graph map. |
|
| 3909 |
/// |
|
| 3910 |
/// This function returns the minimum value of the given graph map. |
|
| 3911 |
/// The corresponding item set of the graph must not be empty. |
|
| 3912 |
/// |
|
| 3913 |
/// \param gr The graph for which the map is defined. |
|
| 3914 |
/// \param map The graph map. |
|
| 3915 |
/// \param comp Comparison function object. |
|
| 3916 |
template <typename GR, typename Map, typename Comp> |
|
| 3917 |
typename Map::Value |
|
| 3918 |
mapMinValue(const GR& gr, const Map& map, const Comp& comp) {
|
|
| 3919 |
return map[mapMin(gr, map, comp)]; |
|
| 3920 |
} |
|
| 3921 |
|
|
| 3922 |
/// \brief Return the maximum value of a graph map. |
|
| 3923 |
/// |
|
| 3924 |
/// This function returns the maximum value of the given graph map. |
|
| 3925 |
/// The corresponding item set of the graph must not be empty. |
|
| 3926 |
/// |
|
| 3927 |
/// \param gr The graph for which the map is defined. |
|
| 3928 |
/// \param map The graph map. |
|
| 3929 |
template <typename GR, typename Map> |
|
| 3930 |
typename Map::Value mapMaxValue(const GR& gr, const Map& map) {
|
|
| 3931 |
return map[mapMax(gr, map, std::less<typename Map::Value>())]; |
|
| 3932 |
} |
|
| 3933 |
|
|
| 3934 |
/// \brief Return the maximum value of a graph map. |
|
| 3935 |
/// |
|
| 3936 |
/// This function returns the maximum value of the given graph map. |
|
| 3937 |
/// The corresponding item set of the graph must not be empty. |
|
| 3938 |
/// |
|
| 3939 |
/// \param gr The graph for which the map is defined. |
|
| 3940 |
/// \param map The graph map. |
|
| 3941 |
/// \param comp Comparison function object. |
|
| 3942 |
template <typename GR, typename Map, typename Comp> |
|
| 3943 |
typename Map::Value |
|
| 3944 |
mapMaxValue(const GR& gr, const Map& map, const Comp& comp) {
|
|
| 3945 |
return map[mapMax(gr, map, comp)]; |
|
| 3946 |
} |
|
| 3947 |
|
|
| 3948 |
/// \brief Return an item having a specified value in a graph map. |
|
| 3949 |
/// |
|
| 3950 |
/// This function returns an item (\c Node, \c Arc or \c Edge) having |
|
| 3951 |
/// the specified assigned value in the given graph map. |
|
| 3952 |
/// If no such item exists, it returns \c INVALID. |
|
| 3953 |
/// |
|
| 3954 |
/// \param gr The graph for which the map is defined. |
|
| 3955 |
/// \param map The graph map. |
|
| 3956 |
/// \param val The value that have to be found. |
|
| 3957 |
template <typename GR, typename Map> |
|
| 3958 |
typename Map::Key |
|
| 3959 |
mapFind(const GR& gr, const Map& map, const typename Map::Value& val) {
|
|
| 3960 |
typedef typename Map::Key Item; |
|
| 3961 |
typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt; |
|
| 3962 |
|
|
| 3963 |
for (ItemIt it(gr); it != INVALID; ++it) {
|
|
| 3964 |
if (map[it] == val) return it; |
|
| 3965 |
} |
|
| 3966 |
return INVALID; |
|
| 3967 |
} |
|
| 3968 |
|
|
| 3969 |
/// \brief Return an item having value for which a certain predicate is |
|
| 3970 |
/// true in a graph map. |
|
| 3971 |
/// |
|
| 3972 |
/// This function returns an item (\c Node, \c Arc or \c Edge) having |
|
| 3973 |
/// such assigned value for which the specified predicate is true |
|
| 3974 |
/// in the given graph map. |
|
| 3975 |
/// If no such item exists, it returns \c INVALID. |
|
| 3976 |
/// |
|
| 3977 |
/// \param gr The graph for which the map is defined. |
|
| 3978 |
/// \param map The graph map. |
|
| 3979 |
/// \param pred The predicate function object. |
|
| 3980 |
template <typename GR, typename Map, typename Pred> |
|
| 3981 |
typename Map::Key |
|
| 3982 |
mapFindIf(const GR& gr, const Map& map, const Pred& pred) {
|
|
| 3983 |
typedef typename Map::Key Item; |
|
| 3984 |
typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt; |
|
| 3985 |
|
|
| 3986 |
for (ItemIt it(gr); it != INVALID; ++it) {
|
|
| 3987 |
if (pred(map[it])) return it; |
|
| 3988 |
} |
|
| 3989 |
return INVALID; |
|
| 3990 |
} |
|
| 3991 |
|
|
| 3992 |
/// \brief Return the number of items having a specified value in a |
|
| 3993 |
/// graph map. |
|
| 3994 |
/// |
|
| 3995 |
/// This function returns the number of items (\c Node, \c Arc or \c Edge) |
|
| 3996 |
/// having the specified assigned value in the given graph map. |
|
| 3997 |
/// |
|
| 3998 |
/// \param gr The graph for which the map is defined. |
|
| 3999 |
/// \param map The graph map. |
|
| 4000 |
/// \param val The value that have to be counted. |
|
| 4001 |
template <typename GR, typename Map> |
|
| 4002 |
int mapCount(const GR& gr, const Map& map, const typename Map::Value& val) {
|
|
| 4003 |
typedef typename Map::Key Item; |
|
| 4004 |
typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt; |
|
| 4005 |
|
|
| 4006 |
int cnt = 0; |
|
| 4007 |
for (ItemIt it(gr); it != INVALID; ++it) {
|
|
| 4008 |
if (map[it] == val) ++cnt; |
|
| 4009 |
} |
|
| 4010 |
return cnt; |
|
| 4011 |
} |
|
| 4012 |
|
|
| 4013 |
/// \brief Return the number of items having values for which a certain |
|
| 4014 |
/// predicate is true in a graph map. |
|
| 4015 |
/// |
|
| 4016 |
/// This function returns the number of items (\c Node, \c Arc or \c Edge) |
|
| 4017 |
/// having such assigned values for which the specified predicate is true |
|
| 4018 |
/// in the given graph map. |
|
| 4019 |
/// |
|
| 4020 |
/// \param gr The graph for which the map is defined. |
|
| 4021 |
/// \param map The graph map. |
|
| 4022 |
/// \param pred The predicate function object. |
|
| 4023 |
template <typename GR, typename Map, typename Pred> |
|
| 4024 |
int mapCountIf(const GR& gr, const Map& map, const Pred& pred) {
|
|
| 4025 |
typedef typename Map::Key Item; |
|
| 4026 |
typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt; |
|
| 4027 |
|
|
| 4028 |
int cnt = 0; |
|
| 4029 |
for (ItemIt it(gr); it != INVALID; ++it) {
|
|
| 4030 |
if (pred(map[it])) ++cnt; |
|
| 4031 |
} |
|
| 4032 |
return cnt; |
|
| 4033 |
} |
|
| 4034 |
|
|
| 4035 |
/// \brief Fill a graph map with a certain value. |
|
| 4036 |
/// |
|
| 4037 |
/// This function sets the specified value for all items (\c Node, |
|
| 4038 |
/// \c Arc or \c Edge) in the given graph map. |
|
| 4039 |
/// |
|
| 4040 |
/// \param gr The graph for which the map is defined. |
|
| 4041 |
/// \param map The graph map. It must conform to the |
|
| 4042 |
/// \ref concepts::WriteMap "WriteMap" concept. |
|
| 4043 |
/// \param val The value. |
|
| 4044 |
template <typename GR, typename Map> |
|
| 4045 |
void mapFill(const GR& gr, Map& map, const typename Map::Value& val) {
|
|
| 4046 |
typedef typename Map::Key Item; |
|
| 4047 |
typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt; |
|
| 4048 |
|
|
| 4049 |
for (ItemIt it(gr); it != INVALID; ++it) {
|
|
| 4050 |
map.set(it, val); |
|
| 4051 |
} |
|
| 4052 |
} |
|
| 4053 |
|
|
| 3699 | 4054 |
/// @} |
| 3700 | 4055 |
} |
| 3701 | 4056 |
| ... | ... |
@@ -488,8 +488,8 @@ |
| 488 | 488 |
/// \name Execution Control |
| 489 | 489 |
/// The simplest way to execute the algorithm is to use |
| 490 | 490 |
/// one of the member functions called \c run(...). \n |
| 491 |
/// If you need more control on the execution, |
|
| 492 |
/// first you must call \ref init(), then you can add several |
|
| 491 |
/// If you need better control on the execution, |
|
| 492 |
/// you have to call \ref init() first, then you can add several |
|
| 493 | 493 |
/// source nodes with \ref addSource(). |
| 494 | 494 |
/// Finally \ref start() will perform the arborescence |
| 495 | 495 |
/// computation. |
| ... | ... |
@@ -40,7 +40,9 @@ |
| 40 | 40 |
/// for finding a \ref min_cost_flow "minimum cost flow". |
| 41 | 41 |
/// |
| 42 | 42 |
/// \ref NetworkSimplex implements the primal Network Simplex algorithm |
| 43 |
/// for finding a \ref min_cost_flow "minimum cost flow" |
|
| 43 |
/// for finding a \ref min_cost_flow "minimum cost flow" |
|
| 44 |
/// \ref amo93networkflows, \ref dantzig63linearprog, |
|
| 45 |
/// \ref kellyoneill91netsimplex. |
|
| 44 | 46 |
/// This algorithm is a specialized version of the linear programming |
| 45 | 47 |
/// simplex method directly for the minimum cost flow problem. |
| 46 | 48 |
/// It is one of the most efficient solution methods. |
| ... | ... |
@@ -48,7 +50,7 @@ |
| 48 | 50 |
/// In general this class is the fastest implementation available |
| 49 | 51 |
/// in LEMON for the minimum cost flow problem. |
| 50 | 52 |
/// Moreover it supports both directions of the supply/demand inequality |
| 51 |
/// constraints. For more information see \ref SupplyType. |
|
| 53 |
/// constraints. For more information, see \ref SupplyType. |
|
| 52 | 54 |
/// |
| 53 | 55 |
/// Most of the parameters of the problem (except for the digraph) |
| 54 | 56 |
/// can be given using separate functions, and the algorithm can be |
| ... | ... |
@@ -57,16 +59,16 @@ |
| 57 | 59 |
/// |
| 58 | 60 |
/// \tparam GR The digraph type the algorithm runs on. |
| 59 | 61 |
/// \tparam V The value type used for flow amounts, capacity bounds |
| 60 |
/// and supply values in the algorithm. By default it is \c int. |
|
| 62 |
/// and supply values in the algorithm. By default, it is \c int. |
|
| 61 | 63 |
/// \tparam C The value type used for costs and potentials in the |
| 62 |
/// algorithm. By default it is the same as \c V. |
|
| 64 |
/// algorithm. By default, it is the same as \c V. |
|
| 63 | 65 |
/// |
| 64 | 66 |
/// \warning Both value types must be signed and all input data must |
| 65 | 67 |
/// be integer. |
| 66 | 68 |
/// |
| 67 | 69 |
/// \note %NetworkSimplex provides five different pivot rule |
| 68 | 70 |
/// implementations, from which the most efficient one is used |
| 69 |
/// by default. For more information see \ref PivotRule. |
|
| 71 |
/// by default. For more information, see \ref PivotRule. |
|
| 70 | 72 |
template <typename GR, typename V = int, typename C = V> |
| 71 | 73 |
class NetworkSimplex |
| 72 | 74 |
{
|
| ... | ... |
@@ -122,35 +124,35 @@ |
| 122 | 124 |
/// \ref NetworkSimplex provides five different pivot rule |
| 123 | 125 |
/// implementations that significantly affect the running time |
| 124 | 126 |
/// of the algorithm. |
| 125 |
/// By default \ref BLOCK_SEARCH "Block Search" is used, which |
|
| 127 |
/// By default, \ref BLOCK_SEARCH "Block Search" is used, which |
|
| 126 | 128 |
/// proved to be the most efficient and the most robust on various |
| 127 | 129 |
/// test inputs according to our benchmark tests. |
| 128 |
/// However another pivot rule can be selected using the \ref run() |
|
| 130 |
/// However, another pivot rule can be selected using the \ref run() |
|
| 129 | 131 |
/// function with the proper parameter. |
| 130 | 132 |
enum PivotRule {
|
| 131 | 133 |
|
| 132 |
/// The First Eligible pivot rule. |
|
| 134 |
/// The \e First \e Eligible pivot rule. |
|
| 133 | 135 |
/// The next eligible arc is selected in a wraparound fashion |
| 134 | 136 |
/// in every iteration. |
| 135 | 137 |
FIRST_ELIGIBLE, |
| 136 | 138 |
|
| 137 |
/// The Best Eligible pivot rule. |
|
| 139 |
/// The \e Best \e Eligible pivot rule. |
|
| 138 | 140 |
/// The best eligible arc is selected in every iteration. |
| 139 | 141 |
BEST_ELIGIBLE, |
| 140 | 142 |
|
| 141 |
/// The Block Search pivot rule. |
|
| 143 |
/// The \e Block \e Search pivot rule. |
|
| 142 | 144 |
/// A specified number of arcs are examined in every iteration |
| 143 | 145 |
/// in a wraparound fashion and the best eligible arc is selected |
| 144 | 146 |
/// from this block. |
| 145 | 147 |
BLOCK_SEARCH, |
| 146 | 148 |
|
| 147 |
/// The Candidate List pivot rule. |
|
| 149 |
/// The \e Candidate \e List pivot rule. |
|
| 148 | 150 |
/// In a major iteration a candidate list is built from eligible arcs |
| 149 | 151 |
/// in a wraparound fashion and in the following minor iterations |
| 150 | 152 |
/// the best eligible arc is selected from this list. |
| 151 | 153 |
CANDIDATE_LIST, |
| 152 | 154 |
|
| 153 |
/// The Altering Candidate List pivot rule. |
|
| 155 |
/// The \e Altering \e Candidate \e List pivot rule. |
|
| 154 | 156 |
/// It is a modified version of the Candidate List method. |
| 155 | 157 |
/// It keeps only the several best eligible arcs from the former |
| 156 | 158 |
/// candidate list and extends this list in every iteration. |
| ... | ... |
@@ -161,8 +163,6 @@ |
| 161 | 163 |
|
| 162 | 164 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR); |
| 163 | 165 |
|
| 164 |
typedef std::vector<Arc> ArcVector; |
|
| 165 |
typedef std::vector<Node> NodeVector; |
|
| 166 | 166 |
typedef std::vector<int> IntVector; |
| 167 | 167 |
typedef std::vector<bool> BoolVector; |
| 168 | 168 |
typedef std::vector<Value> ValueVector; |
| ... | ... |
@@ -364,33 +364,32 @@ |
| 364 | 364 |
bool findEnteringArc() {
|
| 365 | 365 |
Cost c, min = 0; |
| 366 | 366 |
int cnt = _block_size; |
| 367 |
int e |
|
| 367 |
int e; |
|
| 368 | 368 |
for (e = _next_arc; e < _search_arc_num; ++e) {
|
| 369 | 369 |
c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); |
| 370 | 370 |
if (c < min) {
|
| 371 | 371 |
min = c; |
| 372 |
|
|
| 372 |
_in_arc = e; |
|
| 373 | 373 |
} |
| 374 | 374 |
if (--cnt == 0) {
|
| 375 |
if (min < 0) |
|
| 375 |
if (min < 0) goto search_end; |
|
| 376 | 376 |
cnt = _block_size; |
| 377 | 377 |
} |
| 378 | 378 |
} |
| 379 |
if (min == 0 || cnt > 0) {
|
|
| 380 |
for (e = 0; e < _next_arc; ++e) {
|
|
| 381 |
c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); |
|
| 382 |
if (c < min) {
|
|
| 383 |
min = c; |
|
| 384 |
min_arc = e; |
|
| 385 |
} |
|
| 386 |
if (--cnt == 0) {
|
|
| 387 |
if (min < 0) break; |
|
| 388 |
cnt = _block_size; |
|
| 389 |
|
|
| 379 |
for (e = 0; e < _next_arc; ++e) {
|
|
| 380 |
c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); |
|
| 381 |
if (c < min) {
|
|
| 382 |
min = c; |
|
| 383 |
_in_arc = e; |
|
| 384 |
} |
|
| 385 |
if (--cnt == 0) {
|
|
| 386 |
if (min < 0) goto search_end; |
|
| 387 |
cnt = _block_size; |
|
| 390 | 388 |
} |
| 391 | 389 |
} |
| 392 | 390 |
if (min >= 0) return false; |
| 393 |
|
|
| 391 |
|
|
| 392 |
search_end: |
|
| 394 | 393 |
_next_arc = e; |
| 395 | 394 |
return true; |
| 396 | 395 |
} |
| ... | ... |
@@ -428,7 +427,7 @@ |
| 428 | 427 |
_next_arc(0) |
| 429 | 428 |
{
|
| 430 | 429 |
// The main parameters of the pivot rule |
| 431 |
const double LIST_LENGTH_FACTOR = |
|
| 430 |
const double LIST_LENGTH_FACTOR = 0.25; |
|
| 432 | 431 |
const int MIN_LIST_LENGTH = 10; |
| 433 | 432 |
const double MINOR_LIMIT_FACTOR = 0.1; |
| 434 | 433 |
const int MIN_MINOR_LIMIT = 3; |
| ... | ... |
@@ -445,7 +444,7 @@ |
| 445 | 444 |
/// Find next entering arc |
| 446 | 445 |
bool findEnteringArc() {
|
| 447 | 446 |
Cost min, c; |
| 448 |
int e |
|
| 447 |
int e; |
|
| 449 | 448 |
if (_curr_length > 0 && _minor_count < _minor_limit) {
|
| 450 | 449 |
// Minor iteration: select the best eligible arc from the |
| 451 | 450 |
// current candidate list |
| ... | ... |
@@ -456,16 +455,13 @@ |
| 456 | 455 |
c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); |
| 457 | 456 |
if (c < min) {
|
| 458 | 457 |
min = c; |
| 459 |
|
|
| 458 |
_in_arc = e; |
|
| 460 | 459 |
} |
| 461 |
if (c >= 0) {
|
|
| 460 |
else if (c >= 0) {
|
|
| 462 | 461 |
_candidates[i--] = _candidates[--_curr_length]; |
| 463 | 462 |
} |
| 464 | 463 |
} |
| 465 |
if (min < 0) {
|
|
| 466 |
_in_arc = min_arc; |
|
| 467 |
return true; |
|
| 468 |
} |
|
| 464 |
if (min < 0) return true; |
|
| 469 | 465 |
} |
| 470 | 466 |
|
| 471 | 467 |
// Major iteration: build a new candidate list |
| ... | ... |
@@ -477,27 +473,26 @@ |
| 477 | 473 |
_candidates[_curr_length++] = e; |
| 478 | 474 |
if (c < min) {
|
| 479 | 475 |
min = c; |
| 480 |
|
|
| 476 |
_in_arc = e; |
|
| 481 | 477 |
} |
| 482 |
if (_curr_length == _list_length) |
|
| 478 |
if (_curr_length == _list_length) goto search_end; |
|
| 483 | 479 |
} |
| 484 | 480 |
} |
| 485 |
if (_curr_length < _list_length) {
|
|
| 486 |
for (e = 0; e < _next_arc; ++e) {
|
|
| 487 |
c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); |
|
| 488 |
if (c < 0) {
|
|
| 489 |
_candidates[_curr_length++] = e; |
|
| 490 |
if (c < min) {
|
|
| 491 |
min = c; |
|
| 492 |
min_arc = e; |
|
| 493 |
} |
|
| 494 |
if (_curr_length == _list_length) break; |
|
| 481 |
for (e = 0; e < _next_arc; ++e) {
|
|
| 482 |
c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); |
|
| 483 |
if (c < 0) {
|
|
| 484 |
_candidates[_curr_length++] = e; |
|
| 485 |
if (c < min) {
|
|
| 486 |
min = c; |
|
| 487 |
_in_arc = e; |
|
| 495 | 488 |
} |
| 489 |
if (_curr_length == _list_length) goto search_end; |
|
| 496 | 490 |
} |
| 497 | 491 |
} |
| 498 | 492 |
if (_curr_length == 0) return false; |
| 493 |
|
|
| 494 |
search_end: |
|
| 499 | 495 |
_minor_count = 1; |
| 500 |
_in_arc = min_arc; |
|
| 501 | 496 |
_next_arc = e; |
| 502 | 497 |
return true; |
| 503 | 498 |
} |
| ... | ... |
@@ -549,7 +544,7 @@ |
| 549 | 544 |
_next_arc(0), _cand_cost(ns._search_arc_num), _sort_func(_cand_cost) |
| 550 | 545 |
{
|
| 551 | 546 |
// The main parameters of the pivot rule |
| 552 |
const double BLOCK_SIZE_FACTOR = 1. |
|
| 547 |
const double BLOCK_SIZE_FACTOR = 1.0; |
|
| 553 | 548 |
const int MIN_BLOCK_SIZE = 10; |
| 554 | 549 |
const double HEAD_LENGTH_FACTOR = 0.1; |
| 555 | 550 |
const int MIN_HEAD_LENGTH = 3; |
| ... | ... |
@@ -578,39 +573,35 @@ |
| 578 | 573 |
|
| 579 | 574 |
// Extend the list |
| 580 | 575 |
int cnt = _block_size; |
| 581 |
int last_arc = 0; |
|
| 582 | 576 |
int limit = _head_length; |
| 583 | 577 |
|
| 584 |
for ( |
|
| 578 |
for (e = _next_arc; e < _search_arc_num; ++e) {
|
|
| 585 | 579 |
_cand_cost[e] = _state[e] * |
| 586 | 580 |
(_cost[e] + _pi[_source[e]] - _pi[_target[e]]); |
| 587 | 581 |
if (_cand_cost[e] < 0) {
|
| 588 | 582 |
_candidates[_curr_length++] = e; |
| 589 |
last_arc = e; |
|
| 590 | 583 |
} |
| 591 | 584 |
if (--cnt == 0) {
|
| 592 |
if (_curr_length > limit) |
|
| 585 |
if (_curr_length > limit) goto search_end; |
|
| 593 | 586 |
limit = 0; |
| 594 | 587 |
cnt = _block_size; |
| 595 | 588 |
} |
| 596 | 589 |
} |
| 597 |
if (_curr_length <= limit) {
|
|
| 598 |
for (int e = 0; e < _next_arc; ++e) {
|
|
| 599 |
_cand_cost[e] = _state[e] * |
|
| 600 |
(_cost[e] + _pi[_source[e]] - _pi[_target[e]]); |
|
| 601 |
if (_cand_cost[e] < 0) {
|
|
| 602 |
_candidates[_curr_length++] = e; |
|
| 603 |
last_arc = e; |
|
| 604 |
} |
|
| 605 |
if (--cnt == 0) {
|
|
| 606 |
if (_curr_length > limit) break; |
|
| 607 |
limit = 0; |
|
| 608 |
cnt = _block_size; |
|
| 609 |
|
|
| 590 |
for (e = 0; e < _next_arc; ++e) {
|
|
| 591 |
_cand_cost[e] = _state[e] * |
|
| 592 |
(_cost[e] + _pi[_source[e]] - _pi[_target[e]]); |
|
| 593 |
if (_cand_cost[e] < 0) {
|
|
| 594 |
_candidates[_curr_length++] = e; |
|
| 595 |
} |
|
| 596 |
if (--cnt == 0) {
|
|
| 597 |
if (_curr_length > limit) goto search_end; |
|
| 598 |
limit = 0; |
|
| 599 |
cnt = _block_size; |
|
| 610 | 600 |
} |
| 611 | 601 |
} |
| 612 | 602 |
if (_curr_length == 0) return false; |
| 613 |
|
|
| 603 |
|
|
| 604 |
search_end: |
|
| 614 | 605 |
|
| 615 | 606 |
// Make heap of the candidate list (approximating a partial sort) |
| 616 | 607 |
make_heap( _candidates.begin(), _candidates.begin() + _curr_length, |
| ... | ... |
@@ -618,6 +609,7 @@ |
| 618 | 609 |
|
| 619 | 610 |
// Pop the first element of the heap |
| 620 | 611 |
_in_arc = _candidates[0]; |
| 612 |
_next_arc = e; |
|
| 621 | 613 |
pop_heap( _candidates.begin(), _candidates.begin() + _curr_length, |
| 622 | 614 |
_sort_func ); |
| 623 | 615 |
_curr_length = std::min(_head_length, _curr_length - 1); |
| ... | ... |
@@ -633,7 +625,11 @@ |
| 633 | 625 |
/// The constructor of the class. |
| 634 | 626 |
/// |
| 635 | 627 |
/// \param graph The digraph the algorithm runs on. |
| 636 |
|
|
| 628 |
/// \param arc_mixing Indicate if the arcs have to be stored in a |
|
| 629 |
/// mixed order in the internal data structure. |
|
| 630 |
/// In special cases, it could lead to better overall performance, |
|
| 631 |
/// but it is usually slower. Therefore it is disabled by default. |
|
| 632 |
NetworkSimplex(const GR& graph, bool arc_mixing = false) : |
|
| 637 | 633 |
_graph(graph), _node_id(graph), _arc_id(graph), |
| 638 | 634 |
INF(std::numeric_limits<Value>::has_infinity ? |
| 639 | 635 |
std::numeric_limits<Value>::infinity() : |
| ... | ... |
@@ -671,31 +667,33 @@ |
| 671 | 667 |
_last_succ.resize(all_node_num); |
| 672 | 668 |
_state.resize(max_arc_num); |
| 673 | 669 |
|
| 674 |
// Copy the graph |
|
| 670 |
// Copy the graph |
|
| 675 | 671 |
int i = 0; |
| 676 | 672 |
for (NodeIt n(_graph); n != INVALID; ++n, ++i) {
|
| 677 | 673 |
_node_id[n] = i; |
| 678 | 674 |
} |
| 679 |
int k = std::max(int(std::sqrt(double(_arc_num))), 10); |
|
| 680 |
i = 0; |
|
| 681 |
for (ArcIt a(_graph); a != INVALID; ++a) {
|
|
| 682 |
_arc_id[a] = i; |
|
| 683 |
_source[i] = _node_id[_graph.source(a)]; |
|
| 684 |
_target[i] = _node_id[_graph.target(a)]; |
|
| 685 |
|
|
| 675 |
if (arc_mixing) {
|
|
| 676 |
// Store the arcs in a mixed order |
|
| 677 |
int k = std::max(int(std::sqrt(double(_arc_num))), 10); |
|
| 678 |
int i = 0, j = 0; |
|
| 679 |
for (ArcIt a(_graph); a != INVALID; ++a) {
|
|
| 680 |
_arc_id[a] = i; |
|
| 681 |
_source[i] = _node_id[_graph.source(a)]; |
|
| 682 |
_target[i] = _node_id[_graph.target(a)]; |
|
| 683 |
if ((i += k) >= _arc_num) i = ++j; |
|
| 684 |
} |
|
| 685 |
} else {
|
|
| 686 |
// Store the arcs in the original order |
|
| 687 |
int i = 0; |
|
| 688 |
for (ArcIt a(_graph); a != INVALID; ++a, ++i) {
|
|
| 689 |
_arc_id[a] = i; |
|
| 690 |
_source[i] = _node_id[_graph.source(a)]; |
|
| 691 |
_target[i] = _node_id[_graph.target(a)]; |
|
| 692 |
} |
|
| 686 | 693 |
} |
| 687 | 694 |
|
| 688 |
// Initialize maps |
|
| 689 |
for (int i = 0; i != _node_num; ++i) {
|
|
| 690 |
_supply[i] = 0; |
|
| 691 |
} |
|
| 692 |
for (int i = 0; i != _arc_num; ++i) {
|
|
| 693 |
_lower[i] = 0; |
|
| 694 |
_upper[i] = INF; |
|
| 695 |
_cost[i] = 1; |
|
| 696 |
} |
|
| 697 |
_have_lower = false; |
|
| 698 |
|
|
| 695 |
// Reset parameters |
|
| 696 |
reset(); |
|
| 699 | 697 |
} |
| 700 | 698 |
|
| 701 | 699 |
/// \name Parameters |
| ... | ... |
@@ -768,7 +766,6 @@ |
| 768 | 766 |
/// This function sets the supply values of the nodes. |
| 769 | 767 |
/// If neither this function nor \ref stSupply() is used before |
| 770 | 768 |
/// calling \ref run(), the supply of each node will be set to zero. |
| 771 |
/// (It makes sense only if non-zero lower bounds are given.) |
|
| 772 | 769 |
/// |
| 773 | 770 |
/// \param map A node map storing the supply values. |
| 774 | 771 |
/// Its \c Value type must be convertible to the \c Value type |
| ... | ... |
@@ -789,7 +786,6 @@ |
| 789 | 786 |
/// and the required flow value. |
| 790 | 787 |
/// If neither this function nor \ref supplyMap() is used before |
| 791 | 788 |
/// calling \ref run(), the supply of each node will be set to zero. |
| 792 |
/// (It makes sense only if non-zero lower bounds are given.) |
|
| 793 | 789 |
/// |
| 794 | 790 |
/// Using this function has the same effect as using \ref supplyMap() |
| 795 | 791 |
/// with such a map in which \c k is assigned to \c s, \c -k is |
| ... | ... |
@@ -816,7 +812,7 @@ |
| 816 | 812 |
/// If it is not used before calling \ref run(), the \ref GEQ supply |
| 817 | 813 |
/// type will be used. |
| 818 | 814 |
/// |
| 819 |
/// For more information see \ref SupplyType. |
|
| 815 |
/// For more information, see \ref SupplyType. |
|
| 820 | 816 |
/// |
| 821 | 817 |
/// \return <tt>(*this)</tt> |
| 822 | 818 |
NetworkSimplex& supplyType(SupplyType supply_type) {
|
| ... | ... |
@@ -848,11 +844,11 @@ |
| 848 | 844 |
/// that have been given are kept for the next call, unless |
| 849 | 845 |
/// \ref reset() is called, thus only the modified parameters |
| 850 | 846 |
/// have to be set again. See \ref reset() for examples. |
| 851 |
/// However the underlying digraph must not be modified after this |
|
| 847 |
/// However, the underlying digraph must not be modified after this |
|
| 852 | 848 |
/// class have been constructed, since it copies and extends the graph. |
| 853 | 849 |
/// |
| 854 | 850 |
/// \param pivot_rule The pivot rule that will be used during the |
| 855 |
/// algorithm. For more information see \ref PivotRule. |
|
| 851 |
/// algorithm. For more information, see \ref PivotRule. |
|
| 856 | 852 |
/// |
| 857 | 853 |
/// \return \c INFEASIBLE if no feasible flow exists, |
| 858 | 854 |
/// \n \c OPTIMAL if the problem has optimal solution |
| ... | ... |
@@ -877,7 +873,7 @@ |
| 877 | 873 |
/// It is useful for multiple run() calls. If this function is not |
| 878 | 874 |
/// used, all the parameters given before are kept for the next |
| 879 | 875 |
/// \ref run() call. |
| 880 |
/// However the underlying digraph must not be modified after this |
|
| 876 |
/// However, the underlying digraph must not be modified after this |
|
| 881 | 877 |
/// class have been constructed, since it copies and extends the graph. |
| 882 | 878 |
/// |
| 883 | 879 |
/// For example, |
| ... | ... |
@@ -70,7 +70,7 @@ |
| 70 | 70 |
/// It simply makes a copy of the given path. |
| 71 | 71 |
template <typename CPath> |
| 72 | 72 |
Path(const CPath& cpath) {
|
| 73 |
|
|
| 73 |
pathCopy(cpath, *this); |
|
| 74 | 74 |
} |
| 75 | 75 |
|
| 76 | 76 |
/// \brief Template copy assignment |
| ... | ... |
@@ -78,7 +78,7 @@ |
| 78 | 78 |
/// This operator makes a copy of a path of any other type. |
| 79 | 79 |
template <typename CPath> |
| 80 | 80 |
Path& operator=(const CPath& cpath) {
|
| 81 |
|
|
| 81 |
pathCopy(cpath, *this); |
|
| 82 | 82 |
return *this; |
| 83 | 83 |
} |
| 84 | 84 |
|
| ... | ... |
@@ -258,7 +258,7 @@ |
| 258 | 258 |
/// makes a copy of the given path. |
| 259 | 259 |
template <typename CPath> |
| 260 | 260 |
SimplePath(const CPath& cpath) {
|
| 261 |
|
|
| 261 |
pathCopy(cpath, *this); |
|
| 262 | 262 |
} |
| 263 | 263 |
|
| 264 | 264 |
/// \brief Template copy assignment |
| ... | ... |
@@ -267,7 +267,7 @@ |
| 267 | 267 |
/// makes a copy of the given path. |
| 268 | 268 |
template <typename CPath> |
| 269 | 269 |
SimplePath& operator=(const CPath& cpath) {
|
| 270 |
|
|
| 270 |
pathCopy(cpath, *this); |
|
| 271 | 271 |
return *this; |
| 272 | 272 |
} |
| 273 | 273 |
|
| ... | ... |
@@ -437,7 +437,7 @@ |
| 437 | 437 |
/// makes a copy of the given path. |
| 438 | 438 |
template <typename CPath> |
| 439 | 439 |
ListPath(const CPath& cpath) : first(0), last(0) {
|
| 440 |
|
|
| 440 |
pathCopy(cpath, *this); |
|
| 441 | 441 |
} |
| 442 | 442 |
|
| 443 | 443 |
/// \brief Destructor of the path |
| ... | ... |
@@ -453,7 +453,7 @@ |
| 453 | 453 |
/// makes a copy of the given path. |
| 454 | 454 |
template <typename CPath> |
| 455 | 455 |
ListPath& operator=(const CPath& cpath) {
|
| 456 |
|
|
| 456 |
pathCopy(cpath, *this); |
|
| 457 | 457 |
return *this; |
| 458 | 458 |
} |
| 459 | 459 |
|
| ... | ... |
@@ -763,7 +763,7 @@ |
| 763 | 763 |
/// This path can be initialized from any other path type. |
| 764 | 764 |
template <typename CPath> |
| 765 | 765 |
StaticPath(const CPath& cpath) : arcs(0) {
|
| 766 |
|
|
| 766 |
pathCopy(cpath, *this); |
|
| 767 | 767 |
} |
| 768 | 768 |
|
| 769 | 769 |
/// \brief Destructor of the path |
| ... | ... |
@@ -779,7 +779,7 @@ |
| 779 | 779 |
/// makes a copy of the given path. |
| 780 | 780 |
template <typename CPath> |
| 781 | 781 |
StaticPath& operator=(const CPath& cpath) {
|
| 782 |
|
|
| 782 |
pathCopy(cpath, *this); |
|
| 783 | 783 |
return *this; |
| 784 | 784 |
} |
| 785 | 785 |
|
| ... | ... |
@@ -928,57 +928,57 @@ |
| 928 | 928 |
static const bool value = true; |
| 929 | 929 |
}; |
| 930 | 930 |
|
| 931 |
template <typename Target, typename Source, |
|
| 932 |
bool buildEnable = BuildTagIndicator<Target>::value> |
|
| 931 |
template <typename From, typename To, |
|
| 932 |
bool buildEnable = BuildTagIndicator<To>::value> |
|
| 933 | 933 |
struct PathCopySelectorForward {
|
| 934 |
static void copy(Target& target, const Source& source) {
|
|
| 935 |
target.clear(); |
|
| 936 |
for (typename Source::ArcIt it(source); it != INVALID; ++it) {
|
|
| 937 |
target.addBack(it); |
|
| 934 |
static void copy(const From& from, To& to) {
|
|
| 935 |
to.clear(); |
|
| 936 |
for (typename From::ArcIt it(from); it != INVALID; ++it) {
|
|
| 937 |
to.addBack(it); |
|
| 938 | 938 |
} |
| 939 | 939 |
} |
| 940 | 940 |
}; |
| 941 | 941 |
|
| 942 |
template <typename Target, typename Source> |
|
| 943 |
struct PathCopySelectorForward<Target, Source, true> {
|
|
| 944 |
static void copy(Target& target, const Source& source) {
|
|
| 945 |
target.clear(); |
|
| 946 |
|
|
| 942 |
template <typename From, typename To> |
|
| 943 |
struct PathCopySelectorForward<From, To, true> {
|
|
| 944 |
static void copy(const From& from, To& to) {
|
|
| 945 |
to.clear(); |
|
| 946 |
to.build(from); |
|
| 947 | 947 |
} |
| 948 | 948 |
}; |
| 949 | 949 |
|
| 950 |
template <typename Target, typename Source, |
|
| 951 |
bool buildEnable = BuildTagIndicator<Target>::value> |
|
| 950 |
template <typename From, typename To, |
|
| 951 |
bool buildEnable = BuildTagIndicator<To>::value> |
|
| 952 | 952 |
struct PathCopySelectorBackward {
|
| 953 |
static void copy(Target& target, const Source& source) {
|
|
| 954 |
target.clear(); |
|
| 955 |
for (typename Source::RevArcIt it(source); it != INVALID; ++it) {
|
|
| 956 |
target.addFront(it); |
|
| 953 |
static void copy(const From& from, To& to) {
|
|
| 954 |
to.clear(); |
|
| 955 |
for (typename From::RevArcIt it(from); it != INVALID; ++it) {
|
|
| 956 |
to.addFront(it); |
|
| 957 | 957 |
} |
| 958 | 958 |
} |
| 959 | 959 |
}; |
| 960 | 960 |
|
| 961 |
template <typename Target, typename Source> |
|
| 962 |
struct PathCopySelectorBackward<Target, Source, true> {
|
|
| 963 |
static void copy(Target& target, const Source& source) {
|
|
| 964 |
target.clear(); |
|
| 965 |
|
|
| 961 |
template <typename From, typename To> |
|
| 962 |
struct PathCopySelectorBackward<From, To, true> {
|
|
| 963 |
static void copy(const From& from, To& to) {
|
|
| 964 |
to.clear(); |
|
| 965 |
to.buildRev(from); |
|
| 966 | 966 |
} |
| 967 | 967 |
}; |
| 968 | 968 |
|
| 969 | 969 |
|
| 970 |
template <typename Target, typename Source, |
|
| 971 |
bool revEnable = RevPathTagIndicator<Source>::value> |
|
| 970 |
template <typename From, typename To, |
|
| 971 |
bool revEnable = RevPathTagIndicator<From>::value> |
|
| 972 | 972 |
struct PathCopySelector {
|
| 973 |
static void copy(Target& target, const Source& source) {
|
|
| 974 |
PathCopySelectorForward<Target, Source>::copy(target, source); |
|
| 973 |
static void copy(const From& from, To& to) {
|
|
| 974 |
PathCopySelectorForward<From, To>::copy(from, to); |
|
| 975 | 975 |
} |
| 976 | 976 |
}; |
| 977 | 977 |
|
| 978 |
template <typename Target, typename Source> |
|
| 979 |
struct PathCopySelector<Target, Source, true> {
|
|
| 980 |
static void copy(Target& target, const Source& source) {
|
|
| 981 |
PathCopySelectorBackward<Target, Source>::copy(target, source); |
|
| 978 |
template <typename From, typename To> |
|
| 979 |
struct PathCopySelector<From, To, true> {
|
|
| 980 |
static void copy(const From& from, To& to) {
|
|
| 981 |
PathCopySelectorBackward<From, To>::copy(from, to); |
|
| 982 | 982 |
} |
| 983 | 983 |
}; |
| 984 | 984 |
|
| ... | ... |
@@ -987,11 +987,19 @@ |
| 987 | 987 |
|
| 988 | 988 |
/// \brief Make a copy of a path. |
| 989 | 989 |
/// |
| 990 |
/// This function makes a copy of a path. |
|
| 991 |
template <typename Target, typename Source> |
|
| 992 |
void copyPath(Target& target, const Source& source) {
|
|
| 993 |
checkConcept<concepts::PathDumper<typename Source::Digraph>, Source>(); |
|
| 994 |
|
|
| 990 |
/// This function makes a copy of a path. |
|
| 991 |
template <typename From, typename To> |
|
| 992 |
void pathCopy(const From& from, To& to) {
|
|
| 993 |
checkConcept<concepts::PathDumper<typename From::Digraph>, From>(); |
|
| 994 |
_path_bits::PathCopySelector<From, To>::copy(from, to); |
|
| 995 |
} |
|
| 996 |
|
|
| 997 |
/// \brief Deprecated version of \ref pathCopy(). |
|
| 998 |
/// |
|
| 999 |
/// Deprecated version of \ref pathCopy() (only for reverse compatibility). |
|
| 1000 |
template <typename To, typename From> |
|
| 1001 |
void copyPath(To& to, const From& from) {
|
|
| 1002 |
pathCopy(from, to); |
|
| 995 | 1003 |
} |
| 996 | 1004 |
|
| 997 | 1005 |
/// \brief Check the consistency of a path. |
| ... | ... |
@@ -1015,18 +1023,20 @@ |
| 1015 | 1023 |
|
| 1016 | 1024 |
/// \brief The source of a path |
| 1017 | 1025 |
/// |
| 1018 |
/// This function returns the source of the given path. |
|
| 1026 |
/// This function returns the source node of the given path. |
|
| 1027 |
/// If the path is empty, then it returns \c INVALID. |
|
| 1019 | 1028 |
template <typename Digraph, typename Path> |
| 1020 | 1029 |
typename Digraph::Node pathSource(const Digraph& digraph, const Path& path) {
|
| 1021 |
return digraph.source(path.front()); |
|
| 1030 |
return path.empty() ? INVALID : digraph.source(path.front()); |
|
| 1022 | 1031 |
} |
| 1023 | 1032 |
|
| 1024 | 1033 |
/// \brief The target of a path |
| 1025 | 1034 |
/// |
| 1026 |
/// This function returns the target of the given path. |
|
| 1035 |
/// This function returns the target node of the given path. |
|
| 1036 |
/// If the path is empty, then it returns \c INVALID. |
|
| 1027 | 1037 |
template <typename Digraph, typename Path> |
| 1028 | 1038 |
typename Digraph::Node pathTarget(const Digraph& digraph, const Path& path) {
|
| 1029 |
return digraph.target(path.back()); |
|
| 1039 |
return path.empty() ? INVALID : digraph.target(path.back()); |
|
| 1030 | 1040 |
} |
| 1031 | 1041 |
|
| 1032 | 1042 |
/// \brief Class which helps to iterate through the nodes of a path |
| ... | ... |
@@ -52,7 +52,11 @@ |
| 52 | 52 |
/// |
| 53 | 53 |
/// The type of the map that stores the flow values. |
| 54 | 54 |
/// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
| 55 |
#ifdef DOXYGEN |
|
| 56 |
typedef GR::ArcMap<Value> FlowMap; |
|
| 57 |
#else |
|
| 55 | 58 |
typedef typename Digraph::template ArcMap<Value> FlowMap; |
| 59 |
#endif |
|
| 56 | 60 |
|
| 57 | 61 |
/// \brief Instantiates a FlowMap. |
| 58 | 62 |
/// |
| ... | ... |
@@ -67,9 +71,12 @@ |
| 67 | 71 |
/// |
| 68 | 72 |
/// The elevator type used by Preflow algorithm. |
| 69 | 73 |
/// |
| 70 |
/// \sa Elevator |
|
| 71 |
/// \sa LinkedElevator |
|
| 72 |
|
|
| 74 |
/// \sa Elevator, LinkedElevator |
|
| 75 |
#ifdef DOXYGEN |
|
| 76 |
typedef lemon::Elevator<GR, GR::Node> Elevator; |
|
| 77 |
#else |
|
| 78 |
typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator; |
|
| 79 |
#endif |
|
| 73 | 80 |
|
| 74 | 81 |
/// \brief Instantiates an Elevator. |
| 75 | 82 |
/// |
| ... | ... |
@@ -95,7 +102,8 @@ |
| 95 | 102 |
/// |
| 96 | 103 |
/// This class provides an implementation of Goldberg-Tarjan's \e preflow |
| 97 | 104 |
/// \e push-relabel algorithm producing a \ref max_flow |
| 98 |
/// "flow of maximum value" in a digraph |
|
| 105 |
/// "flow of maximum value" in a digraph \ref clrs01algorithms, |
|
| 106 |
/// \ref amo93networkflows, \ref goldberg88newapproach. |
|
| 99 | 107 |
/// The preflow algorithms are the fastest known maximum |
| 100 | 108 |
/// flow algorithms. The current implementation uses a mixture of the |
| 101 | 109 |
/// \e "highest label" and the \e "bound decrease" heuristics. |
| ... | ... |
@@ -257,7 +265,7 @@ |
| 257 | 265 |
/// The Elevator should have standard constructor interface to be |
| 258 | 266 |
/// able to automatically created by the algorithm (i.e. the |
| 259 | 267 |
/// digraph and the maximum level should be passed to it). |
| 260 |
/// However an external elevator object could also be passed to the |
|
| 268 |
/// However, an external elevator object could also be passed to the |
|
| 261 | 269 |
/// algorithm with the \ref elevator(Elevator&) "elevator()" function |
| 262 | 270 |
/// before calling \ref run() or \ref init(). |
| 263 | 271 |
/// \sa SetElevator |
| ... | ... |
@@ -391,8 +399,8 @@ |
| 391 | 399 |
/// \name Execution Control |
| 392 | 400 |
/// The simplest way to execute the preflow algorithm is to use |
| 393 | 401 |
/// \ref run() or \ref runMinCut().\n |
| 394 |
/// If you need more control on the initial solution or the execution, |
|
| 395 |
/// first you have to call one of the \ref init() functions, then |
|
| 402 |
/// If you need better control on the initial solution or the execution, |
|
| 403 |
/// you have to call one of the \ref init() functions first, then |
|
| 396 | 404 |
/// \ref startFirstPhase() and if you need it \ref startSecondPhase(). |
| 397 | 405 |
|
| 398 | 406 |
///@{
|
| ... | ... |
@@ -32,10 +32,7 @@ |
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
|
| 34 | 34 |
class SmartDigraph; |
| 35 |
///Base of SmartDigraph |
|
| 36 | 35 |
|
| 37 |
///Base of SmartDigraph |
|
| 38 |
/// |
|
| 39 | 36 |
class SmartDigraphBase {
|
| 40 | 37 |
protected: |
| 41 | 38 |
|
| ... | ... |
@@ -187,28 +184,28 @@ |
| 187 | 184 |
/// |
| 188 | 185 |
///\brief A smart directed graph class. |
| 189 | 186 |
/// |
| 190 |
///This is a simple and fast digraph implementation. |
|
| 191 |
///It is also quite memory efficient, but at the price |
|
| 192 |
///that <b> it does support only limited (only stack-like) |
|
| 193 |
///node and arc deletions</b>. |
|
| 194 |
/// |
|
| 187 |
///\ref SmartDigraph is a simple and fast digraph implementation. |
|
| 188 |
///It is also quite memory efficient but at the price |
|
| 189 |
///that it does not support node and arc deletion |
|
| 190 |
///(except for the Snapshot feature). |
|
| 195 | 191 |
/// |
| 196 |
///\ |
|
| 192 |
///This type fully conforms to the \ref concepts::Digraph "Digraph concept" |
|
| 193 |
///and it also provides some additional functionalities. |
|
| 194 |
///Most of its member functions and nested classes are documented |
|
| 195 |
///only in the concept class. |
|
| 196 |
/// |
|
| 197 |
///This class provides constant time counting for nodes and arcs. |
|
| 198 |
/// |
|
| 199 |
///\sa concepts::Digraph |
|
| 200 |
///\sa SmartGraph |
|
| 197 | 201 |
class SmartDigraph : public ExtendedSmartDigraphBase {
|
| 198 | 202 |
typedef ExtendedSmartDigraphBase Parent; |
| 199 | 203 |
|
| 200 | 204 |
private: |
| 201 |
|
|
| 202 |
///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead. |
|
| 203 |
|
|
| 204 |
///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead. |
|
| 205 |
/// |
|
| 205 |
/// Digraphs are \e not copy constructible. Use DigraphCopy instead. |
|
| 206 | 206 |
SmartDigraph(const SmartDigraph &) : ExtendedSmartDigraphBase() {};
|
| 207 |
///\brief Assignment of SmartDigraph to another one is \e not allowed. |
|
| 208 |
///Use DigraphCopy() instead. |
|
| 209 |
|
|
| 210 |
///Assignment of SmartDigraph to another one is \e not allowed. |
|
| 211 |
/// |
|
| 207 |
/// \brief Assignment of a digraph to another one is \e not allowed. |
|
| 208 |
/// Use DigraphCopy instead. |
|
| 212 | 209 |
void operator=(const SmartDigraph &) {}
|
| 213 | 210 |
|
| 214 | 211 |
public: |
| ... | ... |
@@ -221,79 +218,49 @@ |
| 221 | 218 |
|
| 222 | 219 |
///Add a new node to the digraph. |
| 223 | 220 |
|
| 224 |
/// Add a new node to the digraph. |
|
| 225 |
/// \return The new node. |
|
| 221 |
///This function adds a new node to the digraph. |
|
| 222 |
///\return The new node. |
|
| 226 | 223 |
Node addNode() { return Parent::addNode(); }
|
| 227 | 224 |
|
| 228 | 225 |
///Add a new arc to the digraph. |
| 229 | 226 |
|
| 230 |
/// |
|
| 227 |
///This function adds a new arc to the digraph with source node \c s |
|
| 231 | 228 |
///and target node \c t. |
| 232 | 229 |
///\return The new arc. |
| 233 |
Arc addArc( |
|
| 230 |
Arc addArc(Node s, Node t) {
|
|
| 234 | 231 |
return Parent::addArc(s, t); |
| 235 | 232 |
} |
| 236 | 233 |
|
| 237 |
/// \brief Using this it is possible to avoid the superfluous memory |
|
| 238 |
/// allocation. |
|
| 239 |
|
|
| 240 |
/// Using this it is possible to avoid the superfluous memory |
|
| 241 |
/// allocation: if you know that the digraph you want to build will |
|
| 242 |
/// be very large (e.g. it will contain millions of nodes and/or arcs) |
|
| 243 |
/// then it is worth reserving space for this amount before starting |
|
| 244 |
/// to build the digraph. |
|
| 245 |
/// \sa reserveArc |
|
| 246 |
void reserveNode(int n) { nodes.reserve(n); };
|
|
| 247 |
|
|
| 248 |
/// \brief Using this it is possible to avoid the superfluous memory |
|
| 249 |
/// allocation. |
|
| 250 |
|
|
| 251 |
/// Using this it is possible to avoid the superfluous memory |
|
| 252 |
/// allocation: if you know that the digraph you want to build will |
|
| 253 |
/// be very large (e.g. it will contain millions of nodes and/or arcs) |
|
| 254 |
/// then it is worth reserving space for this amount before starting |
|
| 255 |
/// to build the digraph. |
|
| 256 |
/// \sa reserveNode |
|
| 257 |
void reserveArc(int m) { arcs.reserve(m); };
|
|
| 258 |
|
|
| 259 | 234 |
/// \brief Node validity check |
| 260 | 235 |
/// |
| 261 |
/// This function gives back true if the given node is valid, |
|
| 262 |
/// ie. it is a real node of the graph. |
|
| 236 |
/// This function gives back \c true if the given node is valid, |
|
| 237 |
/// i.e. it is a real node of the digraph. |
|
| 263 | 238 |
/// |
| 264 | 239 |
/// \warning A removed node (using Snapshot) could become valid again |
| 265 |
/// |
|
| 240 |
/// if new nodes are added to the digraph. |
|
| 266 | 241 |
bool valid(Node n) const { return Parent::valid(n); }
|
| 267 | 242 |
|
| 268 | 243 |
/// \brief Arc validity check |
| 269 | 244 |
/// |
| 270 |
/// This function gives back true if the given arc is valid, |
|
| 271 |
/// ie. it is a real arc of the graph. |
|
| 245 |
/// This function gives back \c true if the given arc is valid, |
|
| 246 |
/// i.e. it is a real arc of the digraph. |
|
| 272 | 247 |
/// |
| 273 | 248 |
/// \warning A removed arc (using Snapshot) could become valid again |
| 274 |
/// |
|
| 249 |
/// if new arcs are added to the graph. |
|
| 275 | 250 |
bool valid(Arc a) const { return Parent::valid(a); }
|
| 276 | 251 |
|
| 277 |
///Clear the digraph. |
|
| 278 |
|
|
| 279 |
///Erase all the nodes and arcs from the digraph. |
|
| 280 |
/// |
|
| 281 |
void clear() {
|
|
| 282 |
Parent::clear(); |
|
| 283 |
} |
|
| 284 |
|
|
| 285 | 252 |
///Split a node. |
| 286 | 253 |
|
| 287 |
///This function splits a node. First a new node is added to the digraph, |
|
| 288 |
///then the source of each outgoing arc of \c n is moved to this new node. |
|
| 289 |
///If \c connect is \c true (this is the default value), then a new arc |
|
| 290 |
///from \c n to the newly created node is also added. |
|
| 254 |
///This function splits the given node. First, a new node is added |
|
| 255 |
///to the digraph, then the source of each outgoing arc of node \c n |
|
| 256 |
///is moved to this new node. |
|
| 257 |
///If the second parameter \c connect is \c true (this is the default |
|
| 258 |
///value), then a new arc from node \c n to the newly created node |
|
| 259 |
///is also added. |
|
| 291 | 260 |
///\return The newly created node. |
| 292 | 261 |
/// |
| 293 |
///\note The <tt>Arc</tt>s |
|
| 294 |
///referencing a moved arc remain |
|
| 295 |
///valid. However <tt>InArc</tt>'s and <tt>OutArc</tt>'s |
|
| 296 |
///may be invalidated. |
|
| 262 |
///\note All iterators remain valid. |
|
| 263 |
/// |
|
| 297 | 264 |
///\warning This functionality cannot be used together with the Snapshot |
| 298 | 265 |
///feature. |
| 299 | 266 |
Node split(Node n, bool connect = true) |
| ... | ... |
@@ -308,6 +275,34 @@ |
| 308 | 275 |
return b; |
| 309 | 276 |
} |
| 310 | 277 |
|
| 278 |
///Clear the digraph. |
|
| 279 |
|
|
| 280 |
///This function erases all nodes and arcs from the digraph. |
|
| 281 |
/// |
|
| 282 |
void clear() {
|
|
| 283 |
Parent::clear(); |
|
| 284 |
} |
|
| 285 |
|
|
| 286 |
/// Reserve memory for nodes. |
|
| 287 |
|
|
| 288 |
/// Using this function, it is possible to avoid superfluous memory |
|
| 289 |
/// allocation: if you know that the digraph you want to build will |
|
| 290 |
/// be large (e.g. it will contain millions of nodes and/or arcs), |
|
| 291 |
/// then it is worth reserving space for this amount before starting |
|
| 292 |
/// to build the digraph. |
|
| 293 |
/// \sa reserveArc() |
|
| 294 |
void reserveNode(int n) { nodes.reserve(n); };
|
|
| 295 |
|
|
| 296 |
/// Reserve memory for arcs. |
|
| 297 |
|
|
| 298 |
/// Using this function, it is possible to avoid superfluous memory |
|
| 299 |
/// allocation: if you know that the digraph you want to build will |
|
| 300 |
/// be large (e.g. it will contain millions of nodes and/or arcs), |
|
| 301 |
/// then it is worth reserving space for this amount before starting |
|
| 302 |
/// to build the digraph. |
|
| 303 |
/// \sa reserveNode() |
|
| 304 |
void reserveArc(int m) { arcs.reserve(m); };
|
|
| 305 |
|
|
| 311 | 306 |
public: |
| 312 | 307 |
|
| 313 | 308 |
class Snapshot; |
| ... | ... |
@@ -332,20 +327,23 @@ |
| 332 | 327 |
|
| 333 | 328 |
public: |
| 334 | 329 |
|
| 335 |
///Class to make a snapshot of the digraph and to |
|
| 330 |
///Class to make a snapshot of the digraph and to restore it later. |
|
| 336 | 331 |
|
| 337 |
///Class to make a snapshot of the digraph and to |
|
| 332 |
///Class to make a snapshot of the digraph and to restore it later. |
|
| 338 | 333 |
/// |
| 339 | 334 |
///The newly added nodes and arcs can be removed using the |
| 340 |
///restore() function. |
|
| 341 |
///\note After you restore a state, you cannot restore |
|
| 342 |
///a later state, in other word you cannot add again the arcs deleted |
|
| 343 |
///by restore() using another one Snapshot instance. |
|
| 335 |
///restore() function. This is the only way for deleting nodes and/or |
|
| 336 |
///arcs from a SmartDigraph structure. |
|
| 344 | 337 |
/// |
| 345 |
///\warning If you do not use correctly the snapshot that can cause |
|
| 346 |
///either broken program, invalid state of the digraph, valid but |
|
| 347 |
///not the restored digraph or no change. Because the runtime performance |
|
| 348 |
///the validity of the snapshot is not stored. |
|
| 338 |
///\note After a state is restored, you cannot restore a later state, |
|
| 339 |
///i.e. you cannot add the removed nodes and arcs again using |
|
| 340 |
///another Snapshot instance. |
|
| 341 |
/// |
|
| 342 |
///\warning Node splitting cannot be restored. |
|
| 343 |
///\warning The validity of the snapshot is not stored due to |
|
| 344 |
///performance reasons. If you do not use the snapshot correctly, |
|
| 345 |
///it can cause broken program, invalid or not restored state of |
|
| 346 |
///the digraph or no change. |
|
| 349 | 347 |
class Snapshot |
| 350 | 348 |
{
|
| 351 | 349 |
SmartDigraph *_graph; |
| ... | ... |
@@ -357,39 +355,32 @@ |
| 357 | 355 |
///Default constructor. |
| 358 | 356 |
|
| 359 | 357 |
///Default constructor. |
| 360 |
///To actually make a snapshot you must call save(). |
|
| 361 |
/// |
|
| 358 |
///You have to call save() to actually make a snapshot. |
|
| 362 | 359 |
Snapshot() : _graph(0) {}
|
| 363 | 360 |
///Constructor that immediately makes a snapshot |
| 364 | 361 |
|
| 365 |
///This constructor immediately makes a snapshot of the digraph. |
|
| 366 |
///\param graph The digraph we make a snapshot of. |
|
| 367 |
|
|
| 362 |
///This constructor immediately makes a snapshot of the given digraph. |
|
| 363 |
/// |
|
| 364 |
Snapshot(SmartDigraph &gr) : _graph(&gr) {
|
|
| 368 | 365 |
node_num=_graph->nodes.size(); |
| 369 | 366 |
arc_num=_graph->arcs.size(); |
| 370 | 367 |
} |
| 371 | 368 |
|
| 372 | 369 |
///Make a snapshot. |
| 373 | 370 |
|
| 374 |
///Make a snapshot of the digraph. |
|
| 375 |
/// |
|
| 376 |
///This function |
|
| 371 |
///This function makes a snapshot of the given digraph. |
|
| 372 |
///It can be called more than once. In case of a repeated |
|
| 377 | 373 |
///call, the previous snapshot gets lost. |
| 378 |
///\param graph The digraph we make the snapshot of. |
|
| 379 |
void save(SmartDigraph &graph) |
|
| 380 |
{
|
|
| 381 |
_graph=&graph; |
|
| 374 |
void save(SmartDigraph &gr) {
|
|
| 375 |
_graph=&gr; |
|
| 382 | 376 |
node_num=_graph->nodes.size(); |
| 383 | 377 |
arc_num=_graph->arcs.size(); |
| 384 | 378 |
} |
| 385 | 379 |
|
| 386 | 380 |
///Undo the changes until a snapshot. |
| 387 | 381 |
|
| 388 |
///Undo the changes until a snapshot created by save(). |
|
| 389 |
/// |
|
| 390 |
///\note After you restored a state, you cannot restore |
|
| 391 |
///a later state, in other word you cannot add again the arcs deleted |
|
| 392 |
/// |
|
| 382 |
///This function undos the changes until the last snapshot |
|
| 383 |
///created by save() or Snapshot(SmartDigraph&). |
|
| 393 | 384 |
void restore() |
| 394 | 385 |
{
|
| 395 | 386 |
_graph->restoreSnapshot(*this); |
| ... | ... |
@@ -508,7 +499,7 @@ |
| 508 | 499 |
node._id = nodes.size() - 1; |
| 509 | 500 |
} |
| 510 | 501 |
|
| 511 |
void next(Node& node) |
|
| 502 |
static void next(Node& node) {
|
|
| 512 | 503 |
--node._id; |
| 513 | 504 |
} |
| 514 | 505 |
|
| ... | ... |
@@ -516,7 +507,7 @@ |
| 516 | 507 |
arc._id = arcs.size() - 1; |
| 517 | 508 |
} |
| 518 | 509 |
|
| 519 |
void next(Arc& arc) |
|
| 510 |
static void next(Arc& arc) {
|
|
| 520 | 511 |
--arc._id; |
| 521 | 512 |
} |
| 522 | 513 |
|
| ... | ... |
@@ -524,7 +515,7 @@ |
| 524 | 515 |
arc._id = arcs.size() / 2 - 1; |
| 525 | 516 |
} |
| 526 | 517 |
|
| 527 |
void next(Edge& arc) |
|
| 518 |
static void next(Edge& arc) {
|
|
| 528 | 519 |
--arc._id; |
| 529 | 520 |
} |
| 530 | 521 |
|
| ... | ... |
@@ -621,29 +612,28 @@ |
| 621 | 612 |
/// |
| 622 | 613 |
/// \brief A smart undirected graph class. |
| 623 | 614 |
/// |
| 624 |
/// This is a simple and fast graph implementation. |
|
| 625 |
/// It is also quite memory efficient, but at the price |
|
| 626 |
/// that <b> it does support only limited (only stack-like) |
|
| 627 |
/// node and arc deletions</b>. |
|
| 628 |
/// |
|
| 615 |
/// \ref SmartGraph is a simple and fast graph implementation. |
|
| 616 |
/// It is also quite memory efficient but at the price |
|
| 617 |
/// that it does not support node and edge deletion |
|
| 618 |
/// (except for the Snapshot feature). |
|
| 629 | 619 |
/// |
| 630 |
/// \ |
|
| 620 |
/// This type fully conforms to the \ref concepts::Graph "Graph concept" |
|
| 621 |
/// and it also provides some additional functionalities. |
|
| 622 |
/// Most of its member functions and nested classes are documented |
|
| 623 |
/// only in the concept class. |
|
| 624 |
/// |
|
| 625 |
/// This class provides constant time counting for nodes, edges and arcs. |
|
| 626 |
/// |
|
| 627 |
/// \sa concepts::Graph |
|
| 628 |
/// \sa SmartDigraph |
|
| 631 | 629 |
class SmartGraph : public ExtendedSmartGraphBase {
|
| 632 | 630 |
typedef ExtendedSmartGraphBase Parent; |
| 633 | 631 |
|
| 634 | 632 |
private: |
| 635 |
|
|
| 636 |
///SmartGraph is \e not copy constructible. Use GraphCopy() instead. |
|
| 637 |
|
|
| 638 |
///SmartGraph is \e not copy constructible. Use GraphCopy() instead. |
|
| 639 |
/// |
|
| 633 |
/// Graphs are \e not copy constructible. Use GraphCopy instead. |
|
| 640 | 634 |
SmartGraph(const SmartGraph &) : ExtendedSmartGraphBase() {};
|
| 641 |
|
|
| 642 |
///\brief Assignment of SmartGraph to another one is \e not allowed. |
|
| 643 |
///Use GraphCopy() instead. |
|
| 644 |
|
|
| 645 |
///Assignment of SmartGraph to another one is \e not allowed. |
|
| 646 |
///Use GraphCopy() instead. |
|
| 635 |
/// \brief Assignment of a graph to another one is \e not allowed. |
|
| 636 |
/// Use GraphCopy instead. |
|
| 647 | 637 |
void operator=(const SmartGraph &) {}
|
| 648 | 638 |
|
| 649 | 639 |
public: |
| ... | ... |
@@ -654,56 +644,77 @@ |
| 654 | 644 |
/// |
| 655 | 645 |
SmartGraph() {}
|
| 656 | 646 |
|
| 657 |
///Add a new node to the graph. |
|
| 658 |
|
|
| 659 |
/// Add a new node to the graph. |
|
| 647 |
/// \brief Add a new node to the graph. |
|
| 648 |
/// |
|
| 649 |
/// This function adds a new node to the graph. |
|
| 660 | 650 |
/// \return The new node. |
| 661 | 651 |
Node addNode() { return Parent::addNode(); }
|
| 662 | 652 |
|
| 663 |
///Add a new edge to the graph. |
|
| 664 |
|
|
| 665 |
///Add a new edge to the graph with node \c s |
|
| 666 |
///and \c t. |
|
| 667 |
///\return The new edge. |
|
| 668 |
Edge addEdge(const Node& s, const Node& t) {
|
|
| 669 |
|
|
| 653 |
/// \brief Add a new edge to the graph. |
|
| 654 |
/// |
|
| 655 |
/// This function adds a new edge to the graph between nodes |
|
| 656 |
/// \c u and \c v with inherent orientation from node \c u to |
|
| 657 |
/// node \c v. |
|
| 658 |
/// \return The new edge. |
|
| 659 |
Edge addEdge(Node u, Node v) {
|
|
| 660 |
return Parent::addEdge(u, v); |
|
| 670 | 661 |
} |
| 671 | 662 |
|
| 672 | 663 |
/// \brief Node validity check |
| 673 | 664 |
/// |
| 674 |
/// This function gives back true if the given node is valid, |
|
| 675 |
/// ie. it is a real node of the graph. |
|
| 665 |
/// This function gives back \c true if the given node is valid, |
|
| 666 |
/// i.e. it is a real node of the graph. |
|
| 676 | 667 |
/// |
| 677 | 668 |
/// \warning A removed node (using Snapshot) could become valid again |
| 678 |
/// |
|
| 669 |
/// if new nodes are added to the graph. |
|
| 679 | 670 |
bool valid(Node n) const { return Parent::valid(n); }
|
| 680 | 671 |
|
| 672 |
/// \brief Edge validity check |
|
| 673 |
/// |
|
| 674 |
/// This function gives back \c true if the given edge is valid, |
|
| 675 |
/// i.e. it is a real edge of the graph. |
|
| 676 |
/// |
|
| 677 |
/// \warning A removed edge (using Snapshot) could become valid again |
|
| 678 |
/// if new edges are added to the graph. |
|
| 679 |
bool valid(Edge e) const { return Parent::valid(e); }
|
|
| 680 |
|
|
| 681 | 681 |
/// \brief Arc validity check |
| 682 | 682 |
/// |
| 683 |
/// This function gives back true if the given arc is valid, |
|
| 684 |
/// ie. it is a real arc of the graph. |
|
| 683 |
/// This function gives back \c true if the given arc is valid, |
|
| 684 |
/// i.e. it is a real arc of the graph. |
|
| 685 | 685 |
/// |
| 686 | 686 |
/// \warning A removed arc (using Snapshot) could become valid again |
| 687 |
/// |
|
| 687 |
/// if new edges are added to the graph. |
|
| 688 | 688 |
bool valid(Arc a) const { return Parent::valid(a); }
|
| 689 | 689 |
|
| 690 |
/// \brief Edge validity check |
|
| 691 |
/// |
|
| 692 |
/// This function gives back true if the given edge is valid, |
|
| 693 |
/// ie. it is a real edge of the graph. |
|
| 694 |
/// |
|
| 695 |
/// \warning A removed edge (using Snapshot) could become valid again |
|
| 696 |
/// when new edges are added to the graph. |
|
| 697 |
bool valid(Edge e) const { return Parent::valid(e); }
|
|
| 698 |
|
|
| 699 | 690 |
///Clear the graph. |
| 700 | 691 |
|
| 701 |
/// |
|
| 692 |
///This function erases all nodes and arcs from the graph. |
|
| 702 | 693 |
/// |
| 703 | 694 |
void clear() {
|
| 704 | 695 |
Parent::clear(); |
| 705 | 696 |
} |
| 706 | 697 |
|
| 698 |
/// Reserve memory for nodes. |
|
| 699 |
|
|
| 700 |
/// Using this function, it is possible to avoid superfluous memory |
|
| 701 |
/// allocation: if you know that the graph you want to build will |
|
| 702 |
/// be large (e.g. it will contain millions of nodes and/or edges), |
|
| 703 |
/// then it is worth reserving space for this amount before starting |
|
| 704 |
/// to build the graph. |
|
| 705 |
/// \sa reserveEdge() |
|
| 706 |
void reserveNode(int n) { nodes.reserve(n); };
|
|
| 707 |
|
|
| 708 |
/// Reserve memory for edges. |
|
| 709 |
|
|
| 710 |
/// Using this function, it is possible to avoid superfluous memory |
|
| 711 |
/// allocation: if you know that the graph you want to build will |
|
| 712 |
/// be large (e.g. it will contain millions of nodes and/or edges), |
|
| 713 |
/// then it is worth reserving space for this amount before starting |
|
| 714 |
/// to build the graph. |
|
| 715 |
/// \sa reserveNode() |
|
| 716 |
void reserveEdge(int m) { arcs.reserve(2 * m); };
|
|
| 717 |
|
|
| 707 | 718 |
public: |
| 708 | 719 |
|
| 709 | 720 |
class Snapshot; |
| ... | ... |
@@ -742,21 +753,22 @@ |
| 742 | 753 |
|
| 743 | 754 |
public: |
| 744 | 755 |
|
| 745 |
///Class to make a snapshot of the |
|
| 756 |
///Class to make a snapshot of the graph and to restore it later. |
|
| 746 | 757 |
|
| 747 |
///Class to make a snapshot of the |
|
| 758 |
///Class to make a snapshot of the graph and to restore it later. |
|
| 748 | 759 |
/// |
| 749 |
///The newly added nodes and arcs can be removed using the |
|
| 750 |
///restore() function. |
|
| 760 |
///The newly added nodes and edges can be removed using the |
|
| 761 |
///restore() function. This is the only way for deleting nodes and/or |
|
| 762 |
///edges from a SmartGraph structure. |
|
| 751 | 763 |
/// |
| 752 |
///\note After you restore a state, you cannot restore |
|
| 753 |
///a later state, in other word you cannot add again the arcs deleted |
|
| 754 |
/// |
|
| 764 |
///\note After a state is restored, you cannot restore a later state, |
|
| 765 |
///i.e. you cannot add the removed nodes and edges again using |
|
| 766 |
///another Snapshot instance. |
|
| 755 | 767 |
/// |
| 756 |
///\warning If you do not use correctly the snapshot that can cause |
|
| 757 |
///either broken program, invalid state of the digraph, valid but |
|
| 758 |
///not the restored digraph or no change. Because the runtime performance |
|
| 759 |
///the validity of the snapshot is not stored. |
|
| 768 |
///\warning The validity of the snapshot is not stored due to |
|
| 769 |
///performance reasons. If you do not use the snapshot correctly, |
|
| 770 |
///it can cause broken program, invalid or not restored state of |
|
| 771 |
///the graph or no change. |
|
| 760 | 772 |
class Snapshot |
| 761 | 773 |
{
|
| 762 | 774 |
SmartGraph *_graph; |
| ... | ... |
@@ -768,36 +780,30 @@ |
| 768 | 780 |
///Default constructor. |
| 769 | 781 |
|
| 770 | 782 |
///Default constructor. |
| 771 |
///To actually make a snapshot you must call save(). |
|
| 772 |
/// |
|
| 783 |
///You have to call save() to actually make a snapshot. |
|
| 773 | 784 |
Snapshot() : _graph(0) {}
|
| 774 | 785 |
///Constructor that immediately makes a snapshot |
| 775 | 786 |
|
| 776 |
///This constructor immediately makes a snapshot of the digraph. |
|
| 777 |
///\param graph The digraph we make a snapshot of. |
|
| 778 |
Snapshot(SmartGraph &graph) {
|
|
| 779 |
graph.saveSnapshot(*this); |
|
| 787 |
/// This constructor immediately makes a snapshot of the given graph. |
|
| 788 |
/// |
|
| 789 |
Snapshot(SmartGraph &gr) {
|
|
| 790 |
gr.saveSnapshot(*this); |
|
| 780 | 791 |
} |
| 781 | 792 |
|
| 782 | 793 |
///Make a snapshot. |
| 783 | 794 |
|
| 784 |
///Make a snapshot of the graph. |
|
| 785 |
/// |
|
| 786 |
///This function |
|
| 795 |
///This function makes a snapshot of the given graph. |
|
| 796 |
///It can be called more than once. In case of a repeated |
|
| 787 | 797 |
///call, the previous snapshot gets lost. |
| 788 |
///\param graph The digraph we make the snapshot of. |
|
| 789 |
void save(SmartGraph &graph) |
|
| 798 |
void save(SmartGraph &gr) |
|
| 790 | 799 |
{
|
| 791 |
|
|
| 800 |
gr.saveSnapshot(*this); |
|
| 792 | 801 |
} |
| 793 | 802 |
|
| 794 |
///Undo the changes until |
|
| 803 |
///Undo the changes until the last snapshot. |
|
| 795 | 804 |
|
| 796 |
///Undo the changes until a snapshot created by save(). |
|
| 797 |
/// |
|
| 798 |
///\note After you restored a state, you cannot restore |
|
| 799 |
///a later state, in other word you cannot add again the arcs deleted |
|
| 800 |
/// |
|
| 805 |
///This function undos the changes until the last snapshot |
|
| 806 |
///created by save() or Snapshot(SmartGraph&). |
|
| 801 | 807 |
void restore() |
| 802 | 808 |
{
|
| 803 | 809 |
_graph->restoreSnapshot(*this); |
| ... | ... |
@@ -91,6 +91,19 @@ |
| 91 | 91 |
return soplex->nRows() - 1; |
| 92 | 92 |
} |
| 93 | 93 |
|
| 94 |
int SoplexLp::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
|
|
| 95 |
soplex::DSVector v; |
|
| 96 |
for (ExprIterator it = b; it != e; ++it) {
|
|
| 97 |
v.add(it->first, it->second); |
|
| 98 |
} |
|
| 99 |
soplex::LPRow r(l, v, u); |
|
| 100 |
soplex->addRow(r); |
|
| 101 |
|
|
| 102 |
_row_names.push_back(std::string()); |
|
| 103 |
|
|
| 104 |
return soplex->nRows() - 1; |
|
| 105 |
} |
|
| 106 |
|
|
| 94 | 107 |
|
| 95 | 108 |
void SoplexLp::_eraseCol(int i) {
|
| 96 | 109 |
soplex->removeCol(i); |
| ... | ... |
@@ -375,7 +375,7 @@ |
| 375 | 375 |
|
| 376 | 376 |
///This function returns the number of stop() exections that is |
| 377 | 377 |
///necessary to really stop the timer. |
| 378 |
///For example the timer |
|
| 378 |
///For example, the timer |
|
| 379 | 379 |
///is running if and only if the return value is \c true |
| 380 | 380 |
///(i.e. greater than |
| 381 | 381 |
///zero). |
| ... | ... |
@@ -43,7 +43,7 @@ |
| 43 | 43 |
/// the find operation uses path compression. |
| 44 | 44 |
/// This is a very simple but efficient implementation, providing |
| 45 | 45 |
/// only four methods: join (union), find, insert and size. |
| 46 |
/// For more features see the \ref UnionFindEnum class. |
|
| 46 |
/// For more features, see the \ref UnionFindEnum class. |
|
| 47 | 47 |
/// |
| 48 | 48 |
/// It is primarily used in Kruskal algorithm for finding minimal |
| 49 | 49 |
/// cost spanning tree in a graph. |
| ... | ... |
@@ -88,7 +88,7 @@ |
| 88 | 88 |
elif test x"$with_coin" != x"yes"; then |
| 89 | 89 |
CBC_LDFLAGS="-L$with_coin/lib" |
| 90 | 90 |
fi |
| 91 |
CBC_LIBS="-lOsi -lCbc |
|
| 91 |
CBC_LIBS="-lOsi -lCbc -lCbcSolver -lClp -lOsiClp -lCoinUtils -lVol -lOsiVol -lCgl -lm -llapack -lblas" |
|
| 92 | 92 |
|
| 93 | 93 |
lx_save_cxxflags="$CXXFLAGS" |
| 94 | 94 |
lx_save_ldflags="$LDFLAGS" |
| 1 | 1 |
#! /usr/bin/env python |
| 2 |
# |
|
| 3 |
# This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 |
# |
|
| 5 |
# Copyright (C) 2003-2009 |
|
| 6 |
# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
| 7 |
# (Egervary Research Group on Combinatorial Optimization, EGRES). |
|
| 8 |
# |
|
| 9 |
# Permission to use, modify and distribute this software is granted |
|
| 10 |
# provided that this copyright notice appears in all copies. For |
|
| 11 |
# precise terms see the accompanying LICENSE file. |
|
| 12 |
# |
|
| 13 |
# This software is provided "AS IS" with no warranty of any kind, |
|
| 14 |
# express or implied, and with no claim as to its suitability for any |
|
| 15 |
# purpose. |
|
| 2 | 16 |
|
| 3 | 17 |
import sys |
| 4 | 18 |
| 1 | 1 |
#!/bin/bash |
| 2 |
# |
|
| 3 |
# This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 |
# |
|
| 5 |
# Copyright (C) 2003-2009 |
|
| 6 |
# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
| 7 |
# (Egervary Research Group on Combinatorial Optimization, EGRES). |
|
| 8 |
# |
|
| 9 |
# Permission to use, modify and distribute this software is granted |
|
| 10 |
# provided that this copyright notice appears in all copies. For |
|
| 11 |
# precise terms see the accompanying LICENSE file. |
|
| 12 |
# |
|
| 13 |
# This software is provided "AS IS" with no warranty of any kind, |
|
| 14 |
# express or implied, and with no claim as to its suitability for any |
|
| 15 |
# purpose. |
|
| 2 | 16 |
|
| 3 | 17 |
set -e |
| 4 | 18 |
| 1 | 1 |
#!/bin/bash |
| 2 |
# |
|
| 3 |
# This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 |
# |
|
| 5 |
# Copyright (C) 2003-2009 |
|
| 6 |
# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
| 7 |
# (Egervary Research Group on Combinatorial Optimization, EGRES). |
|
| 8 |
# |
|
| 9 |
# Permission to use, modify and distribute this software is granted |
|
| 10 |
# provided that this copyright notice appears in all copies. For |
|
| 11 |
# precise terms see the accompanying LICENSE file. |
|
| 12 |
# |
|
| 13 |
# This software is provided "AS IS" with no warranty of any kind, |
|
| 14 |
# express or implied, and with no claim as to its suitability for any |
|
| 15 |
# purpose. |
|
| 2 | 16 |
|
| 3 | 17 |
YEAR=`date +%Y` |
| 4 | 18 |
HGROOT=`hg root` |
| 1 |
if USE_VALGRIND |
|
| 2 |
TESTS_ENVIRONMENT=$(top_srcdir)/scripts/valgrind-wrapper.sh |
|
| 3 |
endif |
|
| 4 |
|
|
| 1 | 5 |
EXTRA_DIST += \ |
| 2 | 6 |
test/CMakeLists.txt |
| 3 | 7 |
|
| ... | ... |
@@ -30,6 +34,7 @@ |
| 30 | 34 |
test/matching_test \ |
| 31 | 35 |
test/min_cost_arborescence_test \ |
| 32 | 36 |
test/min_cost_flow_test \ |
| 37 |
test/min_mean_cycle_test \ |
|
| 33 | 38 |
test/path_test \ |
| 34 | 39 |
test/planarity_test \ |
| 35 | 40 |
test/preflow_test \ |
| ... | ... |
@@ -79,6 +84,7 @@ |
| 79 | 84 |
test_matching_test_SOURCES = test/matching_test.cc |
| 80 | 85 |
test_min_cost_arborescence_test_SOURCES = test/min_cost_arborescence_test.cc |
| 81 | 86 |
test_min_cost_flow_test_SOURCES = test/min_cost_flow_test.cc |
| 87 |
test_min_mean_cycle_test_SOURCES = test/min_mean_cycle_test.cc |
|
| 82 | 88 |
test_path_test_SOURCES = test/path_test.cc |
| 83 | 89 |
test_planarity_test_SOURCES = test/planarity_test.cc |
| 84 | 90 |
test_preflow_test_SOURCES = test/preflow_test.cc |
| ... | ... |
@@ -1371,51 +1371,43 @@ |
| 1371 | 1371 |
GridGraph::Node n4 = graph(1,1); |
| 1372 | 1372 |
|
| 1373 | 1373 |
GridGraph::EdgeMap<bool> dir_map(graph); |
| 1374 |
dir_map[graph.right(n1)] = graph.u(graph.right(n1)) == n1; |
|
| 1375 |
dir_map[graph.up(n1)] = graph.u(graph.up(n1)) != n1; |
|
| 1376 |
dir_map[graph.left(n4)] = graph.u(graph.left(n4)) != n4; |
|
| 1377 |
dir_map[graph.down(n4)] = graph.u(graph.down(n4)) != n4; |
|
| 1374 |
dir_map[graph.right(n1)] = graph.u(graph.right(n1)) != n1; |
|
| 1375 |
dir_map[graph.up(n1)] = graph.u(graph.up(n1)) == n1; |
|
| 1376 |
dir_map[graph.left(n4)] = graph.u(graph.left(n4)) == n4; |
|
| 1377 |
dir_map[graph.down(n4)] = graph.u(graph.down(n4)) == n4; |
|
| 1378 | 1378 |
|
| 1379 | 1379 |
// Apply several adaptors on the grid graph |
| 1380 |
typedef SplitNodes< ReverseDigraph< const Orienter< |
|
| 1381 |
const GridGraph, GridGraph::EdgeMap<bool> > > > |
|
| 1382 |
RevSplitGridGraph; |
|
| 1383 |
typedef ReverseDigraph<const RevSplitGridGraph> SplitGridGraph; |
|
| 1380 |
typedef SplitNodes<Orienter< const GridGraph, GridGraph::EdgeMap<bool> > > |
|
| 1381 |
SplitGridGraph; |
|
| 1384 | 1382 |
typedef Undirector<const SplitGridGraph> USplitGridGraph; |
| 1385 |
typedef Undirector<const USplitGridGraph> UUSplitGridGraph; |
|
| 1386 |
checkConcept<concepts::Digraph, RevSplitGridGraph>(); |
|
| 1387 | 1383 |
checkConcept<concepts::Digraph, SplitGridGraph>(); |
| 1388 | 1384 |
checkConcept<concepts::Graph, USplitGridGraph>(); |
| 1389 |
checkConcept<concepts::Graph, UUSplitGridGraph>(); |
|
| 1390 | 1385 |
|
| 1391 |
RevSplitGridGraph rev_adaptor = |
|
| 1392 |
splitNodes(reverseDigraph(orienter(graph, dir_map))); |
|
| 1393 |
SplitGridGraph adaptor = |
|
| 1386 |
SplitGridGraph adaptor = splitNodes(orienter(graph, dir_map)); |
|
| 1394 | 1387 |
USplitGridGraph uadaptor = undirector(adaptor); |
| 1395 |
UUSplitGridGraph uuadaptor = undirector(uadaptor); |
|
| 1396 | 1388 |
|
| 1397 | 1389 |
// Check adaptor |
| 1398 | 1390 |
checkGraphNodeList(adaptor, 8); |
| 1399 | 1391 |
checkGraphArcList(adaptor, 8); |
| 1400 | 1392 |
checkGraphConArcList(adaptor, 8); |
| 1401 | 1393 |
|
| 1402 |
checkGraphOutArcList(adaptor, rev_adaptor.inNode(n1), 1); |
|
| 1403 |
checkGraphOutArcList(adaptor, rev_adaptor.outNode(n1), 1); |
|
| 1404 |
checkGraphOutArcList(adaptor, rev_adaptor.inNode(n2), 2); |
|
| 1405 |
checkGraphOutArcList(adaptor, rev_adaptor.outNode(n2), 1); |
|
| 1406 |
checkGraphOutArcList(adaptor, rev_adaptor.inNode(n3), 1); |
|
| 1407 |
checkGraphOutArcList(adaptor, rev_adaptor.outNode(n3), 1); |
|
| 1408 |
checkGraphOutArcList(adaptor, rev_adaptor.inNode(n4), 0); |
|
| 1409 |
checkGraphOutArcList(adaptor, rev_adaptor.outNode(n4), 1); |
|
| 1394 |
checkGraphOutArcList(adaptor, adaptor.inNode(n1), 1); |
|
| 1395 |
checkGraphOutArcList(adaptor, adaptor.outNode(n1), 1); |
|
| 1396 |
checkGraphOutArcList(adaptor, adaptor.inNode(n2), 1); |
|
| 1397 |
checkGraphOutArcList(adaptor, adaptor.outNode(n2), 0); |
|
| 1398 |
checkGraphOutArcList(adaptor, adaptor.inNode(n3), 1); |
|
| 1399 |
checkGraphOutArcList(adaptor, adaptor.outNode(n3), 1); |
|
| 1400 |
checkGraphOutArcList(adaptor, adaptor.inNode(n4), 1); |
|
| 1401 |
checkGraphOutArcList(adaptor, adaptor.outNode(n4), 2); |
|
| 1410 | 1402 |
|
| 1411 |
checkGraphInArcList(adaptor, rev_adaptor.inNode(n1), 1); |
|
| 1412 |
checkGraphInArcList(adaptor, rev_adaptor.outNode(n1), 1); |
|
| 1413 |
checkGraphInArcList(adaptor, rev_adaptor.inNode(n2), 1); |
|
| 1414 |
checkGraphInArcList(adaptor, rev_adaptor.outNode(n2), 0); |
|
| 1415 |
checkGraphInArcList(adaptor, rev_adaptor.inNode(n3), 1); |
|
| 1416 |
checkGraphInArcList(adaptor, rev_adaptor.outNode(n3), 1); |
|
| 1417 |
checkGraphInArcList(adaptor, rev_adaptor.inNode(n4), 1); |
|
| 1418 |
checkGraphInArcList(adaptor, rev_adaptor.outNode(n4), 2); |
|
| 1403 |
checkGraphInArcList(adaptor, adaptor.inNode(n1), 1); |
|
| 1404 |
checkGraphInArcList(adaptor, adaptor.outNode(n1), 1); |
|
| 1405 |
checkGraphInArcList(adaptor, adaptor.inNode(n2), 2); |
|
| 1406 |
checkGraphInArcList(adaptor, adaptor.outNode(n2), 1); |
|
| 1407 |
checkGraphInArcList(adaptor, adaptor.inNode(n3), 1); |
|
| 1408 |
checkGraphInArcList(adaptor, adaptor.outNode(n3), 1); |
|
| 1409 |
checkGraphInArcList(adaptor, adaptor.inNode(n4), 0); |
|
| 1410 |
checkGraphInArcList(adaptor, adaptor.outNode(n4), 1); |
|
| 1419 | 1411 |
|
| 1420 | 1412 |
checkNodeIds(adaptor); |
| 1421 | 1413 |
checkArcIds(adaptor); |
| ... | ... |
@@ -1438,29 +1430,14 @@ |
| 1438 | 1430 |
checkGraphEdgeMap(uadaptor); |
| 1439 | 1431 |
checkGraphArcMap(uadaptor); |
| 1440 | 1432 |
|
| 1441 |
checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n1), 2); |
|
| 1442 |
checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n1), 2); |
|
| 1443 |
checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n2), 3); |
|
| 1444 |
checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n2), 1); |
|
| 1445 |
checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n3), 2); |
|
| 1446 |
checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n3), 2); |
|
| 1447 |
checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n4), 1); |
|
| 1448 |
checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n4), 3); |
|
| 1449 |
|
|
| 1450 |
// Check uuadaptor |
|
| 1451 |
checkGraphNodeList(uuadaptor, 8); |
|
| 1452 |
checkGraphEdgeList(uuadaptor, 16); |
|
| 1453 |
checkGraphArcList(uuadaptor, 32); |
|
| 1454 |
checkGraphConEdgeList(uuadaptor, 16); |
|
| 1455 |
checkGraphConArcList(uuadaptor, 32); |
|
| 1456 |
|
|
| 1457 |
checkNodeIds(uuadaptor); |
|
| 1458 |
checkEdgeIds(uuadaptor); |
|
| 1459 |
checkArcIds(uuadaptor); |
|
| 1460 |
|
|
| 1461 |
checkGraphNodeMap(uuadaptor); |
|
| 1462 |
checkGraphEdgeMap(uuadaptor); |
|
| 1463 |
|
|
| 1433 |
checkGraphIncEdgeArcLists(uadaptor, adaptor.inNode(n1), 2); |
|
| 1434 |
checkGraphIncEdgeArcLists(uadaptor, adaptor.outNode(n1), 2); |
|
| 1435 |
checkGraphIncEdgeArcLists(uadaptor, adaptor.inNode(n2), 3); |
|
| 1436 |
checkGraphIncEdgeArcLists(uadaptor, adaptor.outNode(n2), 1); |
|
| 1437 |
checkGraphIncEdgeArcLists(uadaptor, adaptor.inNode(n3), 2); |
|
| 1438 |
checkGraphIncEdgeArcLists(uadaptor, adaptor.outNode(n3), 2); |
|
| 1439 |
checkGraphIncEdgeArcLists(uadaptor, adaptor.inNode(n4), 1); |
|
| 1440 |
checkGraphIncEdgeArcLists(uadaptor, adaptor.outNode(n4), 3); |
|
| 1464 | 1441 |
} |
| 1465 | 1442 |
|
| 1466 | 1443 |
int main(int, const char **) {
|
| ... | ... |
@@ -65,7 +65,7 @@ |
| 65 | 65 |
Node s, t, n; |
| 66 | 66 |
Arc e; |
| 67 | 67 |
Value l; |
| 68 |
int k; |
|
| 68 |
int k=3; |
|
| 69 | 69 |
bool b; |
| 70 | 70 |
BF::DistMap d(gr); |
| 71 | 71 |
BF::PredMap p(gr); |
| ... | ... |
@@ -96,6 +96,7 @@ |
| 96 | 96 |
d = const_bf_test.distMap(); |
| 97 | 97 |
p = const_bf_test.predMap(); |
| 98 | 98 |
pp = const_bf_test.path(t); |
| 99 |
pp = const_bf_test.negativeCycle(); |
|
| 99 | 100 |
|
| 100 | 101 |
for (BF::ActiveIt it(const_bf_test); it != INVALID; ++it) {}
|
| 101 | 102 |
} |
| ... | ... |
@@ -132,6 +133,7 @@ |
| 132 | 133 |
s = bf_test.predNode(t); |
| 133 | 134 |
b = bf_test.reached(t); |
| 134 | 135 |
pp = bf_test.path(t); |
| 136 |
pp = bf_test.negativeCycle(); |
|
| 135 | 137 |
} |
| 136 | 138 |
} |
| 137 | 139 |
| ... | ... |
@@ -19,6 +19,7 @@ |
| 19 | 19 |
#include <lemon/concepts/digraph.h> |
| 20 | 20 |
#include <lemon/list_graph.h> |
| 21 | 21 |
#include <lemon/smart_graph.h> |
| 22 |
#include <lemon/static_graph.h> |
|
| 22 | 23 |
#include <lemon/full_graph.h> |
| 23 | 24 |
|
| 24 | 25 |
#include "test_tools.h" |
| ... | ... |
@@ -35,6 +36,9 @@ |
| 35 | 36 |
checkGraphNodeList(G, 0); |
| 36 | 37 |
checkGraphArcList(G, 0); |
| 37 | 38 |
|
| 39 |
G.reserveNode(3); |
|
| 40 |
G.reserveArc(4); |
|
| 41 |
|
|
| 38 | 42 |
Node |
| 39 | 43 |
n1 = G.addNode(), |
| 40 | 44 |
n2 = G.addNode(), |
| ... | ... |
@@ -283,6 +287,14 @@ |
| 283 | 287 |
G.addArc(G.addNode(), G.addNode()); |
| 284 | 288 |
|
| 285 | 289 |
snapshot.restore(); |
| 290 |
snapshot.save(G); |
|
| 291 |
|
|
| 292 |
checkGraphNodeList(G, 4); |
|
| 293 |
checkGraphArcList(G, 4); |
|
| 294 |
|
|
| 295 |
G.addArc(G.addNode(), G.addNode()); |
|
| 296 |
|
|
| 297 |
snapshot.restore(); |
|
| 286 | 298 |
|
| 287 | 299 |
checkGraphNodeList(G, 4); |
| 288 | 300 |
checkGraphArcList(G, 4); |
| ... | ... |
@@ -317,6 +329,10 @@ |
| 317 | 329 |
checkConcept<ExtendableDigraphComponent<>, SmartDigraph>(); |
| 318 | 330 |
checkConcept<ClearableDigraphComponent<>, SmartDigraph>(); |
| 319 | 331 |
} |
| 332 |
{ // Checking StaticDigraph
|
|
| 333 |
checkConcept<Digraph, StaticDigraph>(); |
|
| 334 |
checkConcept<ClearableDigraphComponent<>, StaticDigraph>(); |
|
| 335 |
} |
|
| 320 | 336 |
{ // Checking FullDigraph
|
| 321 | 337 |
checkConcept<Digraph, FullDigraph>(); |
| 322 | 338 |
} |
| ... | ... |
@@ -372,10 +388,122 @@ |
| 372 | 388 |
check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
| 373 | 389 |
} |
| 374 | 390 |
|
| 391 |
void checkStaticDigraph() {
|
|
| 392 |
SmartDigraph g; |
|
| 393 |
SmartDigraph::NodeMap<StaticDigraph::Node> nref(g); |
|
| 394 |
SmartDigraph::ArcMap<StaticDigraph::Arc> aref(g); |
|
| 395 |
|
|
| 396 |
StaticDigraph G; |
|
| 397 |
|
|
| 398 |
checkGraphNodeList(G, 0); |
|
| 399 |
checkGraphArcList(G, 0); |
|
| 400 |
|
|
| 401 |
G.build(g, nref, aref); |
|
| 402 |
|
|
| 403 |
checkGraphNodeList(G, 0); |
|
| 404 |
checkGraphArcList(G, 0); |
|
| 405 |
|
|
| 406 |
SmartDigraph::Node |
|
| 407 |
n1 = g.addNode(), |
|
| 408 |
n2 = g.addNode(), |
|
| 409 |
n3 = g.addNode(); |
|
| 410 |
|
|
| 411 |
G.build(g, nref, aref); |
|
| 412 |
|
|
| 413 |
checkGraphNodeList(G, 3); |
|
| 414 |
checkGraphArcList(G, 0); |
|
| 415 |
|
|
| 416 |
SmartDigraph::Arc a1 = g.addArc(n1, n2); |
|
| 417 |
|
|
| 418 |
G.build(g, nref, aref); |
|
| 419 |
|
|
| 420 |
check(G.source(aref[a1]) == nref[n1] && G.target(aref[a1]) == nref[n2], |
|
| 421 |
"Wrong arc or wrong references"); |
|
| 422 |
checkGraphNodeList(G, 3); |
|
| 423 |
checkGraphArcList(G, 1); |
|
| 424 |
|
|
| 425 |
checkGraphOutArcList(G, nref[n1], 1); |
|
| 426 |
checkGraphOutArcList(G, nref[n2], 0); |
|
| 427 |
checkGraphOutArcList(G, nref[n3], 0); |
|
| 428 |
|
|
| 429 |
checkGraphInArcList(G, nref[n1], 0); |
|
| 430 |
checkGraphInArcList(G, nref[n2], 1); |
|
| 431 |
checkGraphInArcList(G, nref[n3], 0); |
|
| 432 |
|
|
| 433 |
checkGraphConArcList(G, 1); |
|
| 434 |
|
|
| 435 |
SmartDigraph::Arc |
|
| 436 |
a2 = g.addArc(n2, n1), |
|
| 437 |
a3 = g.addArc(n2, n3), |
|
| 438 |
a4 = g.addArc(n2, n3); |
|
| 439 |
|
|
| 440 |
digraphCopy(g, G).nodeRef(nref).run(); |
|
| 441 |
|
|
| 442 |
checkGraphNodeList(G, 3); |
|
| 443 |
checkGraphArcList(G, 4); |
|
| 444 |
|
|
| 445 |
checkGraphOutArcList(G, nref[n1], 1); |
|
| 446 |
checkGraphOutArcList(G, nref[n2], 3); |
|
| 447 |
checkGraphOutArcList(G, nref[n3], 0); |
|
| 448 |
|
|
| 449 |
checkGraphInArcList(G, nref[n1], 1); |
|
| 450 |
checkGraphInArcList(G, nref[n2], 1); |
|
| 451 |
checkGraphInArcList(G, nref[n3], 2); |
|
| 452 |
|
|
| 453 |
checkGraphConArcList(G, 4); |
|
| 454 |
|
|
| 455 |
std::vector<std::pair<int,int> > arcs; |
|
| 456 |
arcs.push_back(std::make_pair(0,1)); |
|
| 457 |
arcs.push_back(std::make_pair(0,2)); |
|
| 458 |
arcs.push_back(std::make_pair(1,3)); |
|
| 459 |
arcs.push_back(std::make_pair(1,2)); |
|
| 460 |
arcs.push_back(std::make_pair(3,0)); |
|
| 461 |
arcs.push_back(std::make_pair(3,3)); |
|
| 462 |
arcs.push_back(std::make_pair(4,2)); |
|
| 463 |
arcs.push_back(std::make_pair(4,3)); |
|
| 464 |
arcs.push_back(std::make_pair(4,1)); |
|
| 465 |
|
|
| 466 |
G.build(6, arcs.begin(), arcs.end()); |
|
| 467 |
|
|
| 468 |
checkGraphNodeList(G, 6); |
|
| 469 |
checkGraphArcList(G, 9); |
|
| 470 |
|
|
| 471 |
checkGraphOutArcList(G, G.node(0), 2); |
|
| 472 |
checkGraphOutArcList(G, G.node(1), 2); |
|
| 473 |
checkGraphOutArcList(G, G.node(2), 0); |
|
| 474 |
checkGraphOutArcList(G, G.node(3), 2); |
|
| 475 |
checkGraphOutArcList(G, G.node(4), 3); |
|
| 476 |
checkGraphOutArcList(G, G.node(5), 0); |
|
| 477 |
|
|
| 478 |
checkGraphInArcList(G, G.node(0), 1); |
|
| 479 |
checkGraphInArcList(G, G.node(1), 2); |
|
| 480 |
checkGraphInArcList(G, G.node(2), 3); |
|
| 481 |
checkGraphInArcList(G, G.node(3), 3); |
|
| 482 |
checkGraphInArcList(G, G.node(4), 0); |
|
| 483 |
checkGraphInArcList(G, G.node(5), 0); |
|
| 484 |
|
|
| 485 |
checkGraphConArcList(G, 9); |
|
| 486 |
|
|
| 487 |
checkNodeIds(G); |
|
| 488 |
checkArcIds(G); |
|
| 489 |
checkGraphNodeMap(G); |
|
| 490 |
checkGraphArcMap(G); |
|
| 491 |
|
|
| 492 |
int n = G.nodeNum(); |
|
| 493 |
int m = G.arcNum(); |
|
| 494 |
check(G.index(G.node(n-1)) == n-1, "Wrong index."); |
|
| 495 |
check(G.index(G.arc(m-1)) == m-1, "Wrong index."); |
|
| 496 |
} |
|
| 497 |
|
|
| 375 | 498 |
void checkFullDigraph(int num) {
|
| 376 | 499 |
typedef FullDigraph Digraph; |
| 377 | 500 |
DIGRAPH_TYPEDEFS(Digraph); |
| 501 |
|
|
| 378 | 502 |
Digraph G(num); |
| 503 |
check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size"); |
|
| 504 |
|
|
| 505 |
G.resize(num); |
|
| 506 |
check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size"); |
|
| 379 | 507 |
|
| 380 | 508 |
checkGraphNodeList(G, num); |
| 381 | 509 |
checkGraphArcList(G, num * num); |
| ... | ... |
@@ -419,6 +547,9 @@ |
| 419 | 547 |
checkDigraphSnapshot<SmartDigraph>(); |
| 420 | 548 |
checkDigraphValidity<SmartDigraph>(); |
| 421 | 549 |
} |
| 550 |
{ // Checking StaticDigraph
|
|
| 551 |
checkStaticDigraph(); |
|
| 552 |
} |
|
| 422 | 553 |
{ // Checking FullDigraph
|
| 423 | 554 |
checkFullDigraph(8); |
| 424 | 555 |
} |
| ... | ... |
@@ -38,6 +38,9 @@ |
| 38 | 38 |
checkGraphEdgeList(G, 0); |
| 39 | 39 |
checkGraphArcList(G, 0); |
| 40 | 40 |
|
| 41 |
G.reserveNode(3); |
|
| 42 |
G.reserveEdge(3); |
|
| 43 |
|
|
| 41 | 44 |
Node |
| 42 | 45 |
n1 = G.addNode(), |
| 43 | 46 |
n2 = G.addNode(), |
| ... | ... |
@@ -256,6 +259,15 @@ |
| 256 | 259 |
G.addEdge(G.addNode(), G.addNode()); |
| 257 | 260 |
|
| 258 | 261 |
snapshot.restore(); |
| 262 |
snapshot.save(G); |
|
| 263 |
|
|
| 264 |
checkGraphNodeList(G, 4); |
|
| 265 |
checkGraphEdgeList(G, 3); |
|
| 266 |
checkGraphArcList(G, 6); |
|
| 267 |
|
|
| 268 |
G.addEdge(G.addNode(), G.addNode()); |
|
| 269 |
|
|
| 270 |
snapshot.restore(); |
|
| 259 | 271 |
|
| 260 | 272 |
checkGraphNodeList(G, 4); |
| 261 | 273 |
checkGraphEdgeList(G, 3); |
| ... | ... |
@@ -267,6 +279,13 @@ |
| 267 | 279 |
GRAPH_TYPEDEFS(Graph); |
| 268 | 280 |
|
| 269 | 281 |
Graph G(num); |
| 282 |
check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2, |
|
| 283 |
"Wrong size"); |
|
| 284 |
|
|
| 285 |
G.resize(num); |
|
| 286 |
check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2, |
|
| 287 |
"Wrong size"); |
|
| 288 |
|
|
| 270 | 289 |
checkGraphNodeList(G, num); |
| 271 | 290 |
checkGraphEdgeList(G, num * (num - 1) / 2); |
| 272 | 291 |
|
| ... | ... |
@@ -411,6 +430,10 @@ |
| 411 | 430 |
check(G.width() == width, "Wrong column number"); |
| 412 | 431 |
check(G.height() == height, "Wrong row number"); |
| 413 | 432 |
|
| 433 |
G.resize(width, height); |
|
| 434 |
check(G.width() == width, "Wrong column number"); |
|
| 435 |
check(G.height() == height, "Wrong row number"); |
|
| 436 |
|
|
| 414 | 437 |
for (int i = 0; i < width; ++i) {
|
| 415 | 438 |
for (int j = 0; j < height; ++j) {
|
| 416 | 439 |
check(G.col(G(i, j)) == i, "Wrong column"); |
| ... | ... |
@@ -486,6 +509,11 @@ |
| 486 | 509 |
GRAPH_TYPEDEFS(HypercubeGraph); |
| 487 | 510 |
|
| 488 | 511 |
HypercubeGraph G(dim); |
| 512 |
check(G.dimension() == dim, "Wrong dimension"); |
|
| 513 |
|
|
| 514 |
G.resize(dim); |
|
| 515 |
check(G.dimension() == dim, "Wrong dimension"); |
|
| 516 |
|
|
| 489 | 517 |
checkGraphNodeList(G, 1 << dim); |
| 490 | 518 |
checkGraphEdgeList(G, dim * (1 << (dim-1))); |
| 491 | 519 |
checkGraphArcList(G, dim * (1 << dim)); |
| ... | ... |
@@ -22,7 +22,11 @@ |
| 22 | 22 |
#include <lemon/concept_check.h> |
| 23 | 23 |
#include <lemon/concepts/maps.h> |
| 24 | 24 |
#include <lemon/maps.h> |
| 25 |
#include <lemon/list_graph.h> |
|
| 25 | 26 |
#include <lemon/smart_graph.h> |
| 27 |
#include <lemon/adaptors.h> |
|
| 28 |
#include <lemon/dfs.h> |
|
| 29 |
#include <algorithm> |
|
| 26 | 30 |
|
| 27 | 31 |
#include "test_tools.h" |
| 28 | 32 |
|
| ... | ... |
@@ -34,9 +38,22 @@ |
| 34 | 38 |
struct B {};
|
| 35 | 39 |
|
| 36 | 40 |
class C {
|
| 37 |
int |
|
| 41 |
int _x; |
|
| 38 | 42 |
public: |
| 39 |
C(int |
|
| 43 |
C(int x) : _x(x) {}
|
|
| 44 |
int get() const { return _x; }
|
|
| 45 |
}; |
|
| 46 |
inline bool operator<(C c1, C c2) { return c1.get() < c2.get(); }
|
|
| 47 |
inline bool operator==(C c1, C c2) { return c1.get() == c2.get(); }
|
|
| 48 |
|
|
| 49 |
C createC(int x) { return C(x); }
|
|
| 50 |
|
|
| 51 |
template <typename T> |
|
| 52 |
class Less {
|
|
| 53 |
T _t; |
|
| 54 |
public: |
|
| 55 |
Less(T t): _t(t) {}
|
|
| 56 |
bool operator()(const T& t) const { return t < _t; }
|
|
| 40 | 57 |
}; |
| 41 | 58 |
|
| 42 | 59 |
class F {
|
| ... | ... |
@@ -53,6 +70,14 @@ |
| 53 | 70 |
|
| 54 | 71 |
int binc(int a, B) { return a+1; }
|
| 55 | 72 |
|
| 73 |
template <typename T> |
|
| 74 |
class Sum {
|
|
| 75 |
T& _sum; |
|
| 76 |
public: |
|
| 77 |
Sum(T& sum) : _sum(sum) {}
|
|
| 78 |
void operator()(const T& t) { _sum += t; }
|
|
| 79 |
}; |
|
| 80 |
|
|
| 56 | 81 |
typedef ReadMap<A, double> DoubleMap; |
| 57 | 82 |
typedef ReadWriteMap<A, double> DoubleWriteMap; |
| 58 | 83 |
typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap; |
| ... | ... |
@@ -329,6 +354,10 @@ |
| 329 | 354 |
// LoggerBoolMap |
| 330 | 355 |
{
|
| 331 | 356 |
typedef std::vector<int> vec; |
| 357 |
checkConcept<WriteMap<int, bool>, LoggerBoolMap<vec::iterator> >(); |
|
| 358 |
checkConcept<WriteMap<int, bool>, |
|
| 359 |
LoggerBoolMap<std::back_insert_iterator<vec> > >(); |
|
| 360 |
|
|
| 332 | 361 |
vec v1; |
| 333 | 362 |
vec v2(10); |
| 334 | 363 |
LoggerBoolMap<std::back_insert_iterator<vec> > |
| ... | ... |
@@ -348,6 +377,223 @@ |
| 348 | 377 |
for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin(); |
| 349 | 378 |
it != map2.end(); ++it ) |
| 350 | 379 |
check(v1[i++] == *it, "Something is wrong with LoggerBoolMap"); |
| 380 |
|
|
| 381 |
typedef ListDigraph Graph; |
|
| 382 |
DIGRAPH_TYPEDEFS(Graph); |
|
| 383 |
Graph gr; |
|
| 384 |
|
|
| 385 |
Node n0 = gr.addNode(); |
|
| 386 |
Node n1 = gr.addNode(); |
|
| 387 |
Node n2 = gr.addNode(); |
|
| 388 |
Node n3 = gr.addNode(); |
|
| 389 |
|
|
| 390 |
gr.addArc(n3, n0); |
|
| 391 |
gr.addArc(n3, n2); |
|
| 392 |
gr.addArc(n0, n2); |
|
| 393 |
gr.addArc(n2, n1); |
|
| 394 |
gr.addArc(n0, n1); |
|
| 395 |
|
|
| 396 |
{
|
|
| 397 |
std::vector<Node> v; |
|
| 398 |
dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run(); |
|
| 399 |
|
|
| 400 |
check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3, |
|
| 401 |
"Something is wrong with LoggerBoolMap"); |
|
| 402 |
} |
|
| 403 |
{
|
|
| 404 |
std::vector<Node> v(countNodes(gr)); |
|
| 405 |
dfs(gr).processedMap(loggerBoolMap(v.begin())).run(); |
|
| 406 |
|
|
| 407 |
check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3, |
|
| 408 |
"Something is wrong with LoggerBoolMap"); |
|
| 409 |
} |
|
| 410 |
} |
|
| 411 |
|
|
| 412 |
// IdMap, RangeIdMap |
|
| 413 |
{
|
|
| 414 |
typedef ListDigraph Graph; |
|
| 415 |
DIGRAPH_TYPEDEFS(Graph); |
|
| 416 |
|
|
| 417 |
checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >(); |
|
| 418 |
checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >(); |
|
| 419 |
checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >(); |
|
| 420 |
checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >(); |
|
| 421 |
|
|
| 422 |
Graph gr; |
|
| 423 |
IdMap<Graph, Node> nmap(gr); |
|
| 424 |
IdMap<Graph, Arc> amap(gr); |
|
| 425 |
RangeIdMap<Graph, Node> nrmap(gr); |
|
| 426 |
RangeIdMap<Graph, Arc> armap(gr); |
|
| 427 |
|
|
| 428 |
Node n0 = gr.addNode(); |
|
| 429 |
Node n1 = gr.addNode(); |
|
| 430 |
Node n2 = gr.addNode(); |
|
| 431 |
|
|
| 432 |
Arc a0 = gr.addArc(n0, n1); |
|
| 433 |
Arc a1 = gr.addArc(n0, n2); |
|
| 434 |
Arc a2 = gr.addArc(n2, n1); |
|
| 435 |
Arc a3 = gr.addArc(n2, n0); |
|
| 436 |
|
|
| 437 |
check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap"); |
|
| 438 |
check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap"); |
|
| 439 |
check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap"); |
|
| 440 |
|
|
| 441 |
check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap"); |
|
| 442 |
check(amap[a1] == gr.id(a1) && amap(gr.id(a1)) == a1, "Wrong IdMap"); |
|
| 443 |
check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap"); |
|
| 444 |
check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap"); |
|
| 445 |
|
|
| 446 |
check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap"); |
|
| 447 |
check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap"); |
|
| 448 |
|
|
| 449 |
check(nrmap.size() == 3 && armap.size() == 4, |
|
| 450 |
"Wrong RangeIdMap::size()"); |
|
| 451 |
|
|
| 452 |
check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap"); |
|
| 453 |
check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap"); |
|
| 454 |
check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap"); |
|
| 455 |
|
|
| 456 |
check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap"); |
|
| 457 |
check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap"); |
|
| 458 |
check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap"); |
|
| 459 |
check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap"); |
|
| 460 |
|
|
| 461 |
check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap"); |
|
| 462 |
check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap"); |
|
| 463 |
|
|
| 464 |
gr.erase(n1); |
|
| 465 |
|
|
| 466 |
if (nrmap[n0] == 1) nrmap.swap(n0, n2); |
|
| 467 |
nrmap.swap(n2, n0); |
|
| 468 |
if (armap[a1] == 1) armap.swap(a1, a3); |
|
| 469 |
armap.swap(a3, a1); |
|
| 470 |
|
|
| 471 |
check(nrmap.size() == 2 && armap.size() == 2, |
|
| 472 |
"Wrong RangeIdMap::size()"); |
|
| 473 |
|
|
| 474 |
check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap"); |
|
| 475 |
check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap"); |
|
| 476 |
|
|
| 477 |
check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap"); |
|
| 478 |
check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap"); |
|
| 479 |
|
|
| 480 |
check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap"); |
|
| 481 |
check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap"); |
|
| 482 |
} |
|
| 483 |
|
|
| 484 |
// SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap |
|
| 485 |
{
|
|
| 486 |
typedef ListGraph Graph; |
|
| 487 |
GRAPH_TYPEDEFS(Graph); |
|
| 488 |
|
|
| 489 |
checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >(); |
|
| 490 |
checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >(); |
|
| 491 |
checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >(); |
|
| 492 |
checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >(); |
|
| 493 |
checkConcept<ReadMap<Node, int>, InDegMap<Graph> >(); |
|
| 494 |
checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >(); |
|
| 495 |
|
|
| 496 |
Graph gr; |
|
| 497 |
Node n0 = gr.addNode(); |
|
| 498 |
Node n1 = gr.addNode(); |
|
| 499 |
Node n2 = gr.addNode(); |
|
| 500 |
|
|
| 501 |
gr.addEdge(n0,n1); |
|
| 502 |
gr.addEdge(n1,n2); |
|
| 503 |
gr.addEdge(n0,n2); |
|
| 504 |
gr.addEdge(n2,n1); |
|
| 505 |
gr.addEdge(n1,n2); |
|
| 506 |
gr.addEdge(n0,n1); |
|
| 507 |
|
|
| 508 |
for (EdgeIt e(gr); e != INVALID; ++e) {
|
|
| 509 |
check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap"); |
|
| 510 |
check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap"); |
|
| 511 |
} |
|
| 512 |
|
|
| 513 |
check(mapCompare(gr, |
|
| 514 |
sourceMap(orienter(gr, constMap<Edge, bool>(true))), |
|
| 515 |
targetMap(orienter(gr, constMap<Edge, bool>(false)))), |
|
| 516 |
"Wrong SourceMap or TargetMap"); |
|
| 517 |
|
|
| 518 |
typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph; |
|
| 519 |
Digraph dgr(gr, constMap<Edge, bool>(true)); |
|
| 520 |
OutDegMap<Digraph> odm(dgr); |
|
| 521 |
InDegMap<Digraph> idm(dgr); |
|
| 522 |
|
|
| 523 |
check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap"); |
|
| 524 |
check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap"); |
|
| 525 |
|
|
| 526 |
gr.addEdge(n2, n0); |
|
| 527 |
|
|
| 528 |
check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap"); |
|
| 529 |
check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap"); |
|
| 530 |
} |
|
| 531 |
|
|
| 532 |
// CrossRefMap |
|
| 533 |
{
|
|
| 534 |
typedef ListDigraph Graph; |
|
| 535 |
DIGRAPH_TYPEDEFS(Graph); |
|
| 536 |
|
|
| 537 |
checkConcept<ReadWriteMap<Node, int>, |
|
| 538 |
CrossRefMap<Graph, Node, int> >(); |
|
| 539 |
checkConcept<ReadWriteMap<Node, bool>, |
|
| 540 |
CrossRefMap<Graph, Node, bool> >(); |
|
| 541 |
checkConcept<ReadWriteMap<Node, double>, |
|
| 542 |
CrossRefMap<Graph, Node, double> >(); |
|
| 543 |
|
|
| 544 |
Graph gr; |
|
| 545 |
typedef CrossRefMap<Graph, Node, char> CRMap; |
|
| 546 |
CRMap map(gr); |
|
| 547 |
|
|
| 548 |
Node n0 = gr.addNode(); |
|
| 549 |
Node n1 = gr.addNode(); |
|
| 550 |
Node n2 = gr.addNode(); |
|
| 551 |
|
|
| 552 |
map.set(n0, 'A'); |
|
| 553 |
map.set(n1, 'B'); |
|
| 554 |
map.set(n2, 'C'); |
|
| 555 |
|
|
| 556 |
check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
|
|
| 557 |
"Wrong CrossRefMap"); |
|
| 558 |
check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
|
|
| 559 |
"Wrong CrossRefMap"); |
|
| 560 |
check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
|
|
| 561 |
"Wrong CrossRefMap"); |
|
| 562 |
check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
|
|
| 563 |
"Wrong CrossRefMap::count()"); |
|
| 564 |
|
|
| 565 |
CRMap::ValueIt it = map.beginValue(); |
|
| 566 |
check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' && |
|
| 567 |
it == map.endValue(), "Wrong value iterator"); |
|
| 568 |
|
|
| 569 |
map.set(n2, 'A'); |
|
| 570 |
|
|
| 571 |
check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A', |
|
| 572 |
"Wrong CrossRefMap"); |
|
| 573 |
check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
|
|
| 574 |
check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
|
|
| 575 |
check(map('C') == INVALID && map.inverse()['C'] == INVALID,
|
|
| 576 |
"Wrong CrossRefMap"); |
|
| 577 |
check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
|
|
| 578 |
"Wrong CrossRefMap::count()"); |
|
| 579 |
|
|
| 580 |
it = map.beginValue(); |
|
| 581 |
check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' && |
|
| 582 |
it == map.endValue(), "Wrong value iterator"); |
|
| 583 |
|
|
| 584 |
map.set(n0, 'C'); |
|
| 585 |
|
|
| 586 |
check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A', |
|
| 587 |
"Wrong CrossRefMap"); |
|
| 588 |
check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
|
|
| 589 |
check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
|
|
| 590 |
check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
|
|
| 591 |
check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
|
|
| 592 |
"Wrong CrossRefMap::count()"); |
|
| 593 |
|
|
| 594 |
it = map.beginValue(); |
|
| 595 |
check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' && |
|
| 596 |
it == map.endValue(), "Wrong value iterator"); |
|
| 351 | 597 |
} |
| 352 | 598 |
|
| 353 | 599 |
// CrossRefMap |
| ... | ... |
@@ -546,10 +792,10 @@ |
| 546 | 792 |
check(static_cast<Item>(it) == INVALID, "Wrong value"); |
| 547 | 793 |
} |
| 548 | 794 |
|
| 549 |
for (Ivm:: |
|
| 795 |
for (Ivm::ValueIt vit = map1.beginValue(); |
|
| 550 | 796 |
vit != map1.endValue(); ++vit) {
|
| 551 | 797 |
check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit, |
| 552 |
"Wrong |
|
| 798 |
"Wrong ValueIt"); |
|
| 553 | 799 |
} |
| 554 | 800 |
|
| 555 | 801 |
for (int i = 0; i < num; ++i) {
|
| ... | ... |
@@ -571,5 +817,183 @@ |
| 571 | 817 |
check(n == num, "Wrong number"); |
| 572 | 818 |
|
| 573 | 819 |
} |
| 820 |
|
|
| 821 |
// Graph map utilities: |
|
| 822 |
// mapMin(), mapMax(), mapMinValue(), mapMaxValue() |
|
| 823 |
// mapFind(), mapFindIf(), mapCount(), mapCountIf() |
|
| 824 |
// mapCopy(), mapCompare(), mapFill() |
|
| 825 |
{
|
|
| 826 |
DIGRAPH_TYPEDEFS(SmartDigraph); |
|
| 827 |
|
|
| 828 |
SmartDigraph g; |
|
| 829 |
Node n1 = g.addNode(); |
|
| 830 |
Node n2 = g.addNode(); |
|
| 831 |
Node n3 = g.addNode(); |
|
| 832 |
|
|
| 833 |
SmartDigraph::NodeMap<int> map1(g); |
|
| 834 |
SmartDigraph::ArcMap<char> map2(g); |
|
| 835 |
ConstMap<Node, A> cmap1 = A(); |
|
| 836 |
ConstMap<Arc, C> cmap2 = C(0); |
|
| 837 |
|
|
| 838 |
map1[n1] = 10; |
|
| 839 |
map1[n2] = 5; |
|
| 840 |
map1[n3] = 12; |
|
| 841 |
|
|
| 842 |
// mapMin(), mapMax(), mapMinValue(), mapMaxValue() |
|
| 843 |
check(mapMin(g, map1) == n2, "Wrong mapMin()"); |
|
| 844 |
check(mapMax(g, map1) == n3, "Wrong mapMax()"); |
|
| 845 |
check(mapMin(g, map1, std::greater<int>()) == n3, "Wrong mapMin()"); |
|
| 846 |
check(mapMax(g, map1, std::greater<int>()) == n2, "Wrong mapMax()"); |
|
| 847 |
check(mapMinValue(g, map1) == 5, "Wrong mapMinValue()"); |
|
| 848 |
check(mapMaxValue(g, map1) == 12, "Wrong mapMaxValue()"); |
|
| 849 |
|
|
| 850 |
check(mapMin(g, map2) == INVALID, "Wrong mapMin()"); |
|
| 851 |
check(mapMax(g, map2) == INVALID, "Wrong mapMax()"); |
|
| 852 |
|
|
| 853 |
check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()"); |
|
| 854 |
check(mapMax(g, cmap2) == INVALID, "Wrong mapMax()"); |
|
| 855 |
|
|
| 856 |
Arc a1 = g.addArc(n1, n2); |
|
| 857 |
Arc a2 = g.addArc(n1, n3); |
|
| 858 |
Arc a3 = g.addArc(n2, n3); |
|
| 859 |
Arc a4 = g.addArc(n3, n1); |
|
| 860 |
|
|
| 861 |
map2[a1] = 'b'; |
|
| 862 |
map2[a2] = 'a'; |
|
| 863 |
map2[a3] = 'b'; |
|
| 864 |
map2[a4] = 'c'; |
|
| 865 |
|
|
| 866 |
// mapMin(), mapMax(), mapMinValue(), mapMaxValue() |
|
| 867 |
check(mapMin(g, map2) == a2, "Wrong mapMin()"); |
|
| 868 |
check(mapMax(g, map2) == a4, "Wrong mapMax()"); |
|
| 869 |
check(mapMin(g, map2, std::greater<int>()) == a4, "Wrong mapMin()"); |
|
| 870 |
check(mapMax(g, map2, std::greater<int>()) == a2, "Wrong mapMax()"); |
|
| 871 |
check(mapMinValue(g, map2, std::greater<int>()) == 'c', |
|
| 872 |
"Wrong mapMinValue()"); |
|
| 873 |
check(mapMaxValue(g, map2, std::greater<int>()) == 'a', |
|
| 874 |
"Wrong mapMaxValue()"); |
|
| 875 |
|
|
| 876 |
check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()"); |
|
| 877 |
check(mapMax(g, cmap2) != INVALID, "Wrong mapMax()"); |
|
| 878 |
check(mapMaxValue(g, cmap2) == C(0), "Wrong mapMaxValue()"); |
|
| 879 |
|
|
| 880 |
check(mapMin(g, composeMap(functorToMap(&createC), map2)) == a2, |
|
| 881 |
"Wrong mapMin()"); |
|
| 882 |
check(mapMax(g, composeMap(functorToMap(&createC), map2)) == a4, |
|
| 883 |
"Wrong mapMax()"); |
|
| 884 |
check(mapMinValue(g, composeMap(functorToMap(&createC), map2)) == C('a'),
|
|
| 885 |
"Wrong mapMinValue()"); |
|
| 886 |
check(mapMaxValue(g, composeMap(functorToMap(&createC), map2)) == C('c'),
|
|
| 887 |
"Wrong mapMaxValue()"); |
|
| 888 |
|
|
| 889 |
// mapFind(), mapFindIf() |
|
| 890 |
check(mapFind(g, map1, 5) == n2, "Wrong mapFind()"); |
|
| 891 |
check(mapFind(g, map1, 6) == INVALID, "Wrong mapFind()"); |
|
| 892 |
check(mapFind(g, map2, 'a') == a2, "Wrong mapFind()"); |
|
| 893 |
check(mapFind(g, map2, 'e') == INVALID, "Wrong mapFind()"); |
|
| 894 |
check(mapFind(g, cmap2, C(0)) == ArcIt(g), "Wrong mapFind()"); |
|
| 895 |
check(mapFind(g, cmap2, C(1)) == INVALID, "Wrong mapFind()"); |
|
| 896 |
|
|
| 897 |
check(mapFindIf(g, map1, Less<int>(7)) == n2, |
|
| 898 |
"Wrong mapFindIf()"); |
|
| 899 |
check(mapFindIf(g, map1, Less<int>(5)) == INVALID, |
|
| 900 |
"Wrong mapFindIf()"); |
|
| 901 |
check(mapFindIf(g, map2, Less<char>('d')) == ArcIt(g),
|
|
| 902 |
"Wrong mapFindIf()"); |
|
| 903 |
check(mapFindIf(g, map2, Less<char>('a')) == INVALID,
|
|
| 904 |
"Wrong mapFindIf()"); |
|
| 905 |
|
|
| 906 |
// mapCount(), mapCountIf() |
|
| 907 |
check(mapCount(g, map1, 5) == 1, "Wrong mapCount()"); |
|
| 908 |
check(mapCount(g, map1, 6) == 0, "Wrong mapCount()"); |
|
| 909 |
check(mapCount(g, map2, 'a') == 1, "Wrong mapCount()"); |
|
| 910 |
check(mapCount(g, map2, 'b') == 2, "Wrong mapCount()"); |
|
| 911 |
check(mapCount(g, map2, 'e') == 0, "Wrong mapCount()"); |
|
| 912 |
check(mapCount(g, cmap2, C(0)) == 4, "Wrong mapCount()"); |
|
| 913 |
check(mapCount(g, cmap2, C(1)) == 0, "Wrong mapCount()"); |
|
| 914 |
|
|
| 915 |
check(mapCountIf(g, map1, Less<int>(11)) == 2, |
|
| 916 |
"Wrong mapCountIf()"); |
|
| 917 |
check(mapCountIf(g, map1, Less<int>(13)) == 3, |
|
| 918 |
"Wrong mapCountIf()"); |
|
| 919 |
check(mapCountIf(g, map1, Less<int>(5)) == 0, |
|
| 920 |
"Wrong mapCountIf()"); |
|
| 921 |
check(mapCountIf(g, map2, Less<char>('d')) == 4,
|
|
| 922 |
"Wrong mapCountIf()"); |
|
| 923 |
check(mapCountIf(g, map2, Less<char>('c')) == 3,
|
|
| 924 |
"Wrong mapCountIf()"); |
|
| 925 |
check(mapCountIf(g, map2, Less<char>('a')) == 0,
|
|
| 926 |
"Wrong mapCountIf()"); |
|
| 927 |
|
|
| 928 |
// MapIt, ConstMapIt |
|
| 929 |
/* |
|
| 930 |
These tests can be used after applying bugfix #330 |
|
| 931 |
typedef SmartDigraph::NodeMap<int>::MapIt MapIt; |
|
| 932 |
typedef SmartDigraph::NodeMap<int>::ConstMapIt ConstMapIt; |
|
| 933 |
check(*std::min_element(MapIt(map1), MapIt(INVALID)) == 5, |
|
| 934 |
"Wrong NodeMap<>::MapIt"); |
|
| 935 |
check(*std::max_element(ConstMapIt(map1), ConstMapIt(INVALID)) == 12, |
|
| 936 |
"Wrong NodeMap<>::MapIt"); |
|
| 937 |
|
|
| 938 |
int sum = 0; |
|
| 939 |
std::for_each(MapIt(map1), MapIt(INVALID), Sum<int>(sum)); |
|
| 940 |
check(sum == 27, "Wrong NodeMap<>::MapIt"); |
|
| 941 |
std::for_each(ConstMapIt(map1), ConstMapIt(INVALID), Sum<int>(sum)); |
|
| 942 |
check(sum == 54, "Wrong NodeMap<>::ConstMapIt"); |
|
| 943 |
*/ |
|
| 944 |
|
|
| 945 |
// mapCopy(), mapCompare(), mapFill() |
|
| 946 |
check(mapCompare(g, map1, map1), "Wrong mapCompare()"); |
|
| 947 |
check(mapCompare(g, cmap2, cmap2), "Wrong mapCompare()"); |
|
| 948 |
check(mapCompare(g, map1, shiftMap(map1, 0)), "Wrong mapCompare()"); |
|
| 949 |
check(mapCompare(g, map2, scaleMap(map2, 1)), "Wrong mapCompare()"); |
|
| 950 |
check(!mapCompare(g, map1, shiftMap(map1, 1)), "Wrong mapCompare()"); |
|
| 951 |
|
|
| 952 |
SmartDigraph::NodeMap<int> map3(g, 0); |
|
| 953 |
SmartDigraph::ArcMap<char> map4(g, 'a'); |
|
| 954 |
|
|
| 955 |
check(!mapCompare(g, map1, map3), "Wrong mapCompare()"); |
|
| 956 |
check(!mapCompare(g, map2, map4), "Wrong mapCompare()"); |
|
| 957 |
|
|
| 958 |
mapCopy(g, map1, map3); |
|
| 959 |
mapCopy(g, map2, map4); |
|
| 960 |
|
|
| 961 |
check(mapCompare(g, map1, map3), "Wrong mapCompare() or mapCopy()"); |
|
| 962 |
check(mapCompare(g, map2, map4), "Wrong mapCompare() or mapCopy()"); |
|
| 963 |
|
|
| 964 |
Undirector<SmartDigraph> ug(g); |
|
| 965 |
Undirector<SmartDigraph>::EdgeMap<char> umap1(ug, 'x'); |
|
| 966 |
Undirector<SmartDigraph>::ArcMap<double> umap2(ug, 3.14); |
|
| 967 |
|
|
| 968 |
check(!mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()"); |
|
| 969 |
check(!mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()"); |
|
| 970 |
check(!mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()"); |
|
| 971 |
check(!mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()"); |
|
| 972 |
|
|
| 973 |
mapCopy(g, map2, umap1); |
|
| 974 |
|
|
| 975 |
check(mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()"); |
|
| 976 |
check(mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()"); |
|
| 977 |
check(mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()"); |
|
| 978 |
check(mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()"); |
|
| 979 |
|
|
| 980 |
mapCopy(g, map2, umap1); |
|
| 981 |
mapCopy(g, umap1, map2); |
|
| 982 |
mapCopy(ug, map2, umap1); |
|
| 983 |
mapCopy(ug, umap1, map2); |
|
| 984 |
|
|
| 985 |
check(!mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()"); |
|
| 986 |
mapCopy(ug, umap1, umap2); |
|
| 987 |
check(mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()"); |
|
| 988 |
|
|
| 989 |
check(!mapCompare(g, map1, constMap<Node>(2)), "Wrong mapCompare()"); |
|
| 990 |
mapFill(g, map1, 2); |
|
| 991 |
check(mapCompare(g, constMap<Node>(2), map1), "Wrong mapFill()"); |
|
| 992 |
|
|
| 993 |
check(!mapCompare(g, map2, constMap<Arc>('z')), "Wrong mapCompare()");
|
|
| 994 |
mapCopy(g, constMap<Arc>('z'), map2);
|
|
| 995 |
check(mapCompare(g, constMap<Arc>('z'), map2), "Wrong mapCopy()");
|
|
| 996 |
} |
|
| 997 |
|
|
| 574 | 998 |
return 0; |
| 575 | 999 |
} |
| ... | ... |
@@ -50,7 +50,8 @@ |
| 50 | 50 |
|
| 51 | 51 |
if (stat == MipSolver::OPTIMAL) {
|
| 52 | 52 |
std::ostringstream sbuf; |
| 53 |
|
|
| 53 |
sbuf << "Wrong optimal value ("<< mip.solValue()
|
|
| 54 |
<<" instead of " << exp_opt << ")"; |
|
| 54 | 55 |
check(std::abs(mip.solValue()-exp_opt) < 1e-3, sbuf.str()); |
| 55 | 56 |
//+ecvt(exp_opt,2) |
| 56 | 57 |
} |
| ... | ... |
@@ -37,10 +37,14 @@ |
| 37 | 37 |
///\code check(0==1,"This is obviously false.");\endcode will |
| 38 | 38 |
///print something like this (and then exits). |
| 39 | 39 |
///\verbatim file_name.cc:123: error: This is obviously false. \endverbatim |
| 40 |
#define check(rc, msg) \ |
|
| 41 |
if(!(rc)) { \
|
|
| 42 |
std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \ |
|
| 43 |
abort(); \ |
|
| 44 |
|
|
| 40 |
#define check(rc, msg) \ |
|
| 41 |
{ \
|
|
| 42 |
if(!(rc)) { \
|
|
| 43 |
std::cerr << __FILE__ ":" << __LINE__ << ": error: " \ |
|
| 44 |
<< msg << std::endl; \ |
|
| 45 |
abort(); \ |
|
| 46 |
} else { } \
|
|
| 47 |
} \ |
|
| 48 |
|
|
| 45 | 49 |
|
| 46 | 50 |
#endif |
0 comments (0 inline)