1.1 --- a/CMakeLists.txt Thu Dec 10 17:05:35 2009 +0100
1.2 +++ b/CMakeLists.txt Thu Dec 10 17:18:25 2009 +0100
1.3 @@ -35,6 +35,8 @@
1.4 CHECK_TYPE_SIZE("long long" LONG_LONG)
1.5 SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
1.6
1.7 +INCLUDE(FindPythonInterp)
1.8 +
1.9 ENABLE_TESTING()
1.10
1.11 ADD_SUBDIRECTORY(lemon)
2.1 --- a/Makefile.am Thu Dec 10 17:05:35 2009 +0100
2.2 +++ b/Makefile.am Thu Dec 10 17:18:25 2009 +0100
2.3 @@ -17,6 +17,7 @@
2.4 cmake/FindCPLEX.cmake \
2.5 cmake/FindGLPK.cmake \
2.6 cmake/FindCOIN.cmake \
2.7 + cmake/LEMONConfig.cmake.in \
2.8 cmake/version.cmake.in \
2.9 cmake/version.cmake \
2.10 cmake/nsis/lemon.ico \
2.11 @@ -43,6 +44,7 @@
2.12 include test/Makefile.am
2.13 include doc/Makefile.am
2.14 include tools/Makefile.am
2.15 +include scripts/Makefile.am
2.16
2.17 DIST_SUBDIRS = demo
2.18
3.1 --- a/configure.ac Thu Dec 10 17:05:35 2009 +0100
3.2 +++ b/configure.ac Thu Dec 10 17:18:25 2009 +0100
3.3 @@ -41,6 +41,7 @@
3.4 AC_PROG_LIBTOOL
3.5
3.6 AC_CHECK_PROG([doxygen_found],[doxygen],[yes],[no])
3.7 +AC_CHECK_PROG([python_found],[python],[yes],[no])
3.8 AC_CHECK_PROG([gs_found],[gs],[yes],[no])
3.9
3.10 dnl Detect Intel compiler.
3.11 @@ -82,6 +83,21 @@
3.12 fi
3.13 AM_CONDITIONAL([WANT_TOOLS], [test x"$enable_tools" != x"no"])
3.14
3.15 +dnl Support for running test cases using valgrind.
3.16 +use_valgrind=no
3.17 +AC_ARG_ENABLE([valgrind],
3.18 +AS_HELP_STRING([--enable-valgrind], [use valgrind when running tests]),
3.19 + [use_valgrind=yes])
3.20 +
3.21 +if [[ "$use_valgrind" = "yes" ]]; then
3.22 + AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no)
3.23 +
3.24 + if [[ "$HAVE_VALGRIND" = "no" ]]; then
3.25 + AC_MSG_ERROR([Valgrind not found in PATH.])
3.26 + fi
3.27 +fi
3.28 +AM_CONDITIONAL(USE_VALGRIND, [test "$use_valgrind" = "yes"])
3.29 +
3.30 dnl Checks for header files.
3.31 AC_CHECK_HEADERS(limits.h sys/time.h sys/times.h unistd.h)
3.32
3.33 @@ -127,6 +143,7 @@
3.34 echo CBC support................... : $lx_cbc_found
3.35 echo
3.36 echo Build additional tools........ : $enable_tools
3.37 +echo Use valgrind for tests........ : $use_valgrind
3.38 echo
3.39 echo The packace will be installed in
3.40 echo -n ' '
4.1 --- a/doc/CMakeLists.txt Thu Dec 10 17:05:35 2009 +0100
4.2 +++ b/doc/CMakeLists.txt Thu Dec 10 17:18:25 2009 +0100
4.3 @@ -9,7 +9,7 @@
4.4 @ONLY
4.5 )
4.6
4.7 -IF(DOXYGEN_EXECUTABLE AND GHOSTSCRIPT_EXECUTABLE)
4.8 +IF(DOXYGEN_EXECUTABLE AND PYTHONINTERP_FOUND AND GHOSTSCRIPT_EXECUTABLE)
4.9 FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/)
4.10 SET(GHOSTSCRIPT_OPTIONS -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha)
4.11 ADD_CUSTOM_TARGET(html
4.12 @@ -28,6 +28,7 @@
4.13 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_4.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_4.eps
4.14 COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/strongly_connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/strongly_connected_components.eps
4.15 COMMAND ${CMAKE_COMMAND} -E remove_directory html
4.16 + COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/bib2dox.py ${CMAKE_CURRENT_SOURCE_DIR}/references.bib >references.dox
4.17 COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile
4.18 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
4.19 )
5.1 --- a/doc/Doxyfile.in Thu Dec 10 17:05:35 2009 +0100
5.2 +++ b/doc/Doxyfile.in Thu Dec 10 17:18:25 2009 +0100
5.3 @@ -1,4 +1,4 @@
5.4 -# Doxyfile 1.5.7.1
5.5 +# Doxyfile 1.5.9
5.6
5.7 #---------------------------------------------------------------------------
5.8 # Project related configuration options
5.9 @@ -21,7 +21,6 @@
5.10 JAVADOC_AUTOBRIEF = NO
5.11 QT_AUTOBRIEF = NO
5.12 MULTILINE_CPP_IS_BRIEF = NO
5.13 -DETAILS_AT_TOP = YES
5.14 INHERIT_DOCS = NO
5.15 SEPARATE_MEMBER_PAGES = NO
5.16 TAB_SIZE = 8
5.17 @@ -91,7 +90,8 @@
5.18 "@abs_top_srcdir@/lemon/concepts" \
5.19 "@abs_top_srcdir@/demo" \
5.20 "@abs_top_srcdir@/tools" \
5.21 - "@abs_top_srcdir@/test/test_tools.h"
5.22 + "@abs_top_srcdir@/test/test_tools.h" \
5.23 + "@abs_top_builddir@/doc/references.dox"
5.24 INPUT_ENCODING = UTF-8
5.25 FILE_PATTERNS = *.h \
5.26 *.cc \
5.27 @@ -223,7 +223,7 @@
5.28 EXPAND_AS_DEFINED =
5.29 SKIP_FUNCTION_MACROS = YES
5.30 #---------------------------------------------------------------------------
5.31 -# Configuration::additions related to external references
5.32 +# Options related to the search engine
5.33 #---------------------------------------------------------------------------
5.34 TAGFILES = "@abs_top_srcdir@/doc/libstdc++.tag = http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/ "
5.35 GENERATE_TAGFILE = html/lemon.tag
6.1 --- a/doc/Makefile.am Thu Dec 10 17:05:35 2009 +0100
6.2 +++ b/doc/Makefile.am Thu Dec 10 17:18:25 2009 +0100
6.3 @@ -66,7 +66,19 @@
6.4 exit 1; \
6.5 fi
6.6
6.7 -html-local: $(DOC_PNG_IMAGES)
6.8 +references.dox: doc/references.bib
6.9 + if test ${python_found} = yes; then \
6.10 + cd doc; \
6.11 + python @abs_top_srcdir@/scripts/bib2dox.py @abs_top_builddir@/$< >$@; \
6.12 + cd ..; \
6.13 + else \
6.14 + echo; \
6.15 + echo "Python not found."; \
6.16 + echo; \
6.17 + exit 1; \
6.18 + fi
6.19 +
6.20 +html-local: $(DOC_PNG_IMAGES) references.dox
6.21 if test ${doxygen_found} = yes; then \
6.22 cd doc; \
6.23 doxygen Doxyfile; \
7.1 --- a/doc/groups.dox Thu Dec 10 17:05:35 2009 +0100
7.2 +++ b/doc/groups.dox Thu Dec 10 17:18:25 2009 +0100
7.3 @@ -226,14 +226,6 @@
7.4 */
7.5
7.6 /**
7.7 -@defgroup matrices Matrices
7.8 -@ingroup datas
7.9 -\brief Two dimensional data storages implemented in LEMON.
7.10 -
7.11 -This group contains two dimensional data storages implemented in LEMON.
7.12 -*/
7.13 -
7.14 -/**
7.15 @defgroup paths Path Structures
7.16 @ingroup datas
7.17 \brief %Path structures implemented in LEMON.
7.18 @@ -246,7 +238,36 @@
7.19 efficient to have e.g. the Dijkstra algorithm to store its result in
7.20 any kind of path structure.
7.21
7.22 -\sa lemon::concepts::Path
7.23 +\sa \ref concepts::Path "Path concept"
7.24 +*/
7.25 +
7.26 +/**
7.27 +@defgroup heaps Heap Structures
7.28 +@ingroup datas
7.29 +\brief %Heap structures implemented in LEMON.
7.30 +
7.31 +This group contains the heap structures implemented in LEMON.
7.32 +
7.33 +LEMON provides several heap classes. They are efficient implementations
7.34 +of the abstract data type \e priority \e queue. They store items with
7.35 +specified values called \e priorities in such a way that finding and
7.36 +removing the item with minimum priority are efficient.
7.37 +The basic operations are adding and erasing items, changing the priority
7.38 +of an item, etc.
7.39 +
7.40 +Heaps are crucial in several algorithms, such as Dijkstra and Prim.
7.41 +The heap implementations have the same interface, thus any of them can be
7.42 +used easily in such algorithms.
7.43 +
7.44 +\sa \ref concepts::Heap "Heap concept"
7.45 +*/
7.46 +
7.47 +/**
7.48 +@defgroup matrices Matrices
7.49 +@ingroup datas
7.50 +\brief Two dimensional data storages implemented in LEMON.
7.51 +
7.52 +This group contains two dimensional data storages implemented in LEMON.
7.53 */
7.54
7.55 /**
7.56 @@ -259,6 +280,28 @@
7.57 */
7.58
7.59 /**
7.60 +@defgroup geomdat Geometric Data Structures
7.61 +@ingroup auxdat
7.62 +\brief Geometric data structures implemented in LEMON.
7.63 +
7.64 +This group contains geometric data structures implemented in LEMON.
7.65 +
7.66 + - \ref lemon::dim2::Point "dim2::Point" implements a two dimensional
7.67 + vector with the usual operations.
7.68 + - \ref lemon::dim2::Box "dim2::Box" can be used to determine the
7.69 + rectangular bounding box of a set of \ref lemon::dim2::Point
7.70 + "dim2::Point"'s.
7.71 +*/
7.72 +
7.73 +/**
7.74 +@defgroup matrices Matrices
7.75 +@ingroup auxdat
7.76 +\brief Two dimensional data storages implemented in LEMON.
7.77 +
7.78 +This group contains two dimensional data storages implemented in LEMON.
7.79 +*/
7.80 +
7.81 +/**
7.82 @defgroup algs Algorithms
7.83 \brief This group contains the several algorithms
7.84 implemented in LEMON.
7.85 @@ -273,7 +316,8 @@
7.86 \brief Common graph search algorithms.
7.87
7.88 This group contains the common graph search algorithms, namely
7.89 -\e breadth-first \e search (BFS) and \e depth-first \e search (DFS).
7.90 +\e breadth-first \e search (BFS) and \e depth-first \e search (DFS)
7.91 +\ref clrs01algorithms.
7.92 */
7.93
7.94 /**
7.95 @@ -281,7 +325,8 @@
7.96 @ingroup algs
7.97 \brief Algorithms for finding shortest paths.
7.98
7.99 -This group contains the algorithms for finding shortest paths in digraphs.
7.100 +This group contains the algorithms for finding shortest paths in digraphs
7.101 +\ref clrs01algorithms.
7.102
7.103 - \ref Dijkstra algorithm for finding shortest paths from a source node
7.104 when all arc lengths are non-negative.
7.105 @@ -298,12 +343,21 @@
7.106 */
7.107
7.108 /**
7.109 +@defgroup spantree Minimum Spanning Tree Algorithms
7.110 +@ingroup algs
7.111 +\brief Algorithms for finding minimum cost spanning trees and arborescences.
7.112 +
7.113 +This group contains the algorithms for finding minimum cost spanning
7.114 +trees and arborescences \ref clrs01algorithms.
7.115 +*/
7.116 +
7.117 +/**
7.118 @defgroup max_flow Maximum Flow Algorithms
7.119 @ingroup algs
7.120 \brief Algorithms for finding maximum flows.
7.121
7.122 This group contains the algorithms for finding maximum flows and
7.123 -feasible circulations.
7.124 +feasible circulations \ref clrs01algorithms, \ref amo93networkflows.
7.125
7.126 The \e maximum \e flow \e problem is to find a flow of maximum value between
7.127 a single source and a single target. Formally, there is a \f$G=(V,A)\f$
7.128 @@ -318,12 +372,16 @@
7.129 \f[ 0 \leq f(uv) \leq cap(uv) \quad \forall uv\in A \f]
7.130
7.131 LEMON contains several algorithms for solving maximum flow problems:
7.132 -- \ref EdmondsKarp Edmonds-Karp algorithm.
7.133 -- \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm.
7.134 -- \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees.
7.135 -- \ref GoldbergTarjan Preflow push-relabel algorithm with dynamic trees.
7.136 +- \ref EdmondsKarp Edmonds-Karp algorithm
7.137 + \ref edmondskarp72theoretical.
7.138 +- \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm
7.139 + \ref goldberg88newapproach.
7.140 +- \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees
7.141 + \ref dinic70algorithm, \ref sleator83dynamic.
7.142 +- \ref GoldbergTarjan !Preflow push-relabel algorithm with dynamic trees
7.143 + \ref goldberg88newapproach, \ref sleator83dynamic.
7.144
7.145 -In most cases the \ref Preflow "Preflow" algorithm provides the
7.146 +In most cases the \ref Preflow algorithm provides the
7.147 fastest method for computing a maximum flow. All implementations
7.148 also provide functions to query the minimum cut, which is the dual
7.149 problem of maximum flow.
7.150 @@ -341,18 +399,22 @@
7.151 \brief Algorithms for finding minimum cost flows and circulations.
7.152
7.153 This group contains the algorithms for finding minimum cost flows and
7.154 -circulations. For more information about this problem and its dual
7.155 -solution see \ref min_cost_flow "Minimum Cost Flow Problem".
7.156 +circulations \ref amo93networkflows. For more information about this
7.157 +problem and its dual solution, see \ref min_cost_flow
7.158 +"Minimum Cost Flow Problem".
7.159
7.160 LEMON contains several algorithms for this problem.
7.161 - \ref NetworkSimplex Primal Network Simplex algorithm with various
7.162 - pivot strategies.
7.163 + pivot strategies \ref dantzig63linearprog, \ref kellyoneill91netsimplex.
7.164 - \ref CostScaling Push-Relabel and Augment-Relabel algorithms based on
7.165 - cost scaling.
7.166 + cost scaling \ref goldberg90approximation, \ref goldberg97efficient,
7.167 + \ref bunnagel98efficient.
7.168 - \ref CapacityScaling Successive Shortest %Path algorithm with optional
7.169 - capacity scaling.
7.170 - - \ref CancelAndTighten The Cancel and Tighten algorithm.
7.171 - - \ref CycleCanceling Cycle-Canceling algorithms.
7.172 + capacity scaling \ref edmondskarp72theoretical.
7.173 + - \ref CancelAndTighten The Cancel and Tighten algorithm
7.174 + \ref goldberg89cyclecanceling.
7.175 + - \ref CycleCanceling Cycle-Canceling algorithms
7.176 + \ref klein67primal, \ref goldberg89cyclecanceling.
7.177
7.178 In general NetworkSimplex is the most efficient implementation,
7.179 but in special cases other algorithms could be faster.
7.180 @@ -375,7 +437,7 @@
7.181 cut is the \f$X\f$ solution of the next optimization problem:
7.182
7.183 \f[ \min_{X \subset V, X\not\in \{\emptyset, V\}}
7.184 - \sum_{uv\in A, u\in X, v\not\in X}cap(uv) \f]
7.185 + \sum_{uv\in A: u\in X, v\not\in X}cap(uv) \f]
7.186
7.187 LEMON contains several algorithms related to minimum cut problems:
7.188
7.189 @@ -391,27 +453,40 @@
7.190 */
7.191
7.192 /**
7.193 -@defgroup graph_properties Connectivity and Other Graph Properties
7.194 +@defgroup min_mean_cycle Minimum Mean Cycle Algorithms
7.195 @ingroup algs
7.196 -\brief Algorithms for discovering the graph properties
7.197 +\brief Algorithms for finding minimum mean cycles.
7.198
7.199 -This group contains the algorithms for discovering the graph properties
7.200 -like connectivity, bipartiteness, euler property, simplicity etc.
7.201 +This group contains the algorithms for finding minimum mean cycles
7.202 +\ref clrs01algorithms, \ref amo93networkflows.
7.203
7.204 -\image html edge_biconnected_components.png
7.205 -\image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth
7.206 -*/
7.207 +The \e minimum \e mean \e cycle \e problem is to find a directed cycle
7.208 +of minimum mean length (cost) in a digraph.
7.209 +The mean length of a cycle is the average length of its arcs, i.e. the
7.210 +ratio between the total length of the cycle and the number of arcs on it.
7.211
7.212 -/**
7.213 -@defgroup planar Planarity Embedding and Drawing
7.214 -@ingroup algs
7.215 -\brief Algorithms for planarity checking, embedding and drawing
7.216 +This problem has an important connection to \e conservative \e length
7.217 +\e functions, too. A length function on the arcs of a digraph is called
7.218 +conservative if and only if there is no directed cycle of negative total
7.219 +length. For an arbitrary length function, the negative of the minimum
7.220 +cycle mean is the smallest \f$\epsilon\f$ value so that increasing the
7.221 +arc lengths uniformly by \f$\epsilon\f$ results in a conservative length
7.222 +function.
7.223
7.224 -This group contains the algorithms for planarity checking,
7.225 -embedding and drawing.
7.226 +LEMON contains three algorithms for solving the minimum mean cycle problem:
7.227 +- \ref Karp "Karp"'s original algorithm \ref amo93networkflows,
7.228 + \ref dasdan98minmeancycle.
7.229 +- \ref HartmannOrlin "Hartmann-Orlin"'s algorithm, which is an improved
7.230 + version of Karp's algorithm \ref dasdan98minmeancycle.
7.231 +- \ref Howard "Howard"'s policy iteration algorithm
7.232 + \ref dasdan98minmeancycle.
7.233
7.234 -\image html planar.png
7.235 -\image latex planar.eps "Plane graph" width=\textwidth
7.236 +In practice, the Howard algorithm proved to be by far the most efficient
7.237 +one, though the best known theoretical bound on its running time is
7.238 +exponential.
7.239 +Both Karp and HartmannOrlin algorithms run in time O(ne) and use space
7.240 +O(n<sup>2</sup>+e), but the latter one is typically faster due to the
7.241 +applied early termination scheme.
7.242 */
7.243
7.244 /**
7.245 @@ -455,12 +530,36 @@
7.246 */
7.247
7.248 /**
7.249 -@defgroup spantree Minimum Spanning Tree Algorithms
7.250 +@defgroup graph_properties Connectivity and Other Graph Properties
7.251 @ingroup algs
7.252 -\brief Algorithms for finding minimum cost spanning trees and arborescences.
7.253 +\brief Algorithms for discovering the graph properties
7.254
7.255 -This group contains the algorithms for finding minimum cost spanning
7.256 -trees and arborescences.
7.257 +This group contains the algorithms for discovering the graph properties
7.258 +like connectivity, bipartiteness, euler property, simplicity etc.
7.259 +
7.260 +\image html connected_components.png
7.261 +\image latex connected_components.eps "Connected components" width=\textwidth
7.262 +*/
7.263 +
7.264 +/**
7.265 +@defgroup planar Planarity Embedding and Drawing
7.266 +@ingroup algs
7.267 +\brief Algorithms for planarity checking, embedding and drawing
7.268 +
7.269 +This group contains the algorithms for planarity checking,
7.270 +embedding and drawing.
7.271 +
7.272 +\image html planar.png
7.273 +\image latex planar.eps "Plane graph" width=\textwidth
7.274 +*/
7.275 +
7.276 +/**
7.277 +@defgroup approx Approximation Algorithms
7.278 +@ingroup algs
7.279 +\brief Approximation algorithms.
7.280 +
7.281 +This group contains the approximation and heuristic algorithms
7.282 +implemented in LEMON.
7.283 */
7.284
7.285 /**
7.286 @@ -473,15 +572,6 @@
7.287 */
7.288
7.289 /**
7.290 -@defgroup approx Approximation Algorithms
7.291 -@ingroup algs
7.292 -\brief Approximation algorithms.
7.293 -
7.294 -This group contains the approximation and heuristic algorithms
7.295 -implemented in LEMON.
7.296 -*/
7.297 -
7.298 -/**
7.299 @defgroup gen_opt_group General Optimization Tools
7.300 \brief This group contains some general optimization frameworks
7.301 implemented in LEMON.
7.302 @@ -491,13 +581,16 @@
7.303 */
7.304
7.305 /**
7.306 -@defgroup lp_group Lp and Mip Solvers
7.307 +@defgroup lp_group LP and MIP Solvers
7.308 @ingroup gen_opt_group
7.309 -\brief Lp and Mip solver interfaces for LEMON.
7.310 +\brief LP and MIP solver interfaces for LEMON.
7.311
7.312 -This group contains Lp and Mip solver interfaces for LEMON. The
7.313 -various LP solvers could be used in the same manner with this
7.314 -interface.
7.315 +This group contains LP and MIP solver interfaces for LEMON.
7.316 +Various LP solvers could be used in the same manner with this
7.317 +high-level interface.
7.318 +
7.319 +The currently supported solvers are \ref glpk, \ref clp, \ref cbc,
7.320 +\ref cplex, \ref soplex.
7.321 */
7.322
7.323 /**
7.324 @@ -587,7 +680,7 @@
7.325 */
7.326
7.327 /**
7.328 -@defgroup dimacs_group DIMACS format
7.329 +@defgroup dimacs_group DIMACS Format
7.330 @ingroup io_group
7.331 \brief Read and write files in DIMACS format
7.332
7.333 @@ -636,8 +729,8 @@
7.334 @ingroup concept
7.335 \brief Skeleton and concept checking classes for graph structures
7.336
7.337 -This group contains the skeletons and concept checking classes of LEMON's
7.338 -graph structures and helper classes used to implement these.
7.339 +This group contains the skeletons and concept checking classes of
7.340 +graph structures.
7.341 */
7.342
7.343 /**
7.344 @@ -649,6 +742,15 @@
7.345 */
7.346
7.347 /**
7.348 +@defgroup tools Standalone Utility Applications
7.349 +
7.350 +Some utility applications are listed here.
7.351 +
7.352 +The standard compilation procedure (<tt>./configure;make</tt>) will compile
7.353 +them, as well.
7.354 +*/
7.355 +
7.356 +/**
7.357 \anchor demoprograms
7.358
7.359 @defgroup demos Demo Programs
7.360 @@ -660,13 +762,4 @@
7.361 <tt>make check</tt> commands.
7.362 */
7.363
7.364 -/**
7.365 -@defgroup tools Standalone Utility Applications
7.366 -
7.367 -Some utility applications are listed here.
7.368 -
7.369 -The standard compilation procedure (<tt>./configure;make</tt>) will compile
7.370 -them, as well.
7.371 -*/
7.372 -
7.373 }
8.1 --- a/doc/mainpage.dox Thu Dec 10 17:05:35 2009 +0100
8.2 +++ b/doc/mainpage.dox Thu Dec 10 17:18:25 2009 +0100
8.3 @@ -21,14 +21,11 @@
8.4
8.5 \section intro Introduction
8.6
8.7 -\subsection whatis What is LEMON
8.8 -
8.9 -LEMON stands for <b>L</b>ibrary for <b>E</b>fficient <b>M</b>odeling
8.10 -and <b>O</b>ptimization in <b>N</b>etworks.
8.11 -It is a C++ template
8.12 -library aimed at combinatorial optimization tasks which
8.13 -often involve in working
8.14 -with graphs.
8.15 +<b>LEMON</b> stands for <i><b>L</b>ibrary for <b>E</b>fficient <b>M</b>odeling
8.16 +and <b>O</b>ptimization in <b>N</b>etworks</i>.
8.17 +It is a C++ template library providing efficient implementation of common
8.18 +data structures and algorithms with focus on combinatorial optimization
8.19 +problems in graphs and networks.
8.20
8.21 <b>
8.22 LEMON is an <a class="el" href="http://opensource.org/">open source</a>
8.23 @@ -38,7 +35,16 @@
8.24 \ref license "license terms".
8.25 </b>
8.26
8.27 -\subsection howtoread How to read the documentation
8.28 +The project is maintained by the
8.29 +<a href="http://www.cs.elte.hu/egres/">Egerváry Research Group on
8.30 +Combinatorial Optimization</a> \ref egres
8.31 +at the Operations Research Department of the
8.32 +<a href="http://www.elte.hu/">Eötvös Loránd University,
8.33 +Budapest</a>, Hungary.
8.34 +LEMON is also a member of the <a href="http://www.coin-or.org/">COIN-OR</a>
8.35 +initiative \ref coinor.
8.36 +
8.37 +\section howtoread How to Read the Documentation
8.38
8.39 If you would like to get to know the library, see
8.40 <a class="el" href="http://lemon.cs.elte.hu/pub/tutorial/">LEMON Tutorial</a>.
9.1 --- a/doc/min_cost_flow.dox Thu Dec 10 17:05:35 2009 +0100
9.2 +++ b/doc/min_cost_flow.dox Thu Dec 10 17:18:25 2009 +0100
9.3 @@ -26,7 +26,7 @@
9.4 The \e minimum \e cost \e flow \e problem is to find a feasible flow of
9.5 minimum total cost from a set of supply nodes to a set of demand nodes
9.6 in a network with capacity constraints (lower and upper bounds)
9.7 -and arc costs.
9.8 +and arc costs \ref amo93networkflows.
9.9
9.10 Formally, let \f$G=(V,A)\f$ be a digraph, \f$lower: A\rightarrow\mathbf{R}\f$,
9.11 \f$upper: A\rightarrow\mathbf{R}\cup\{+\infty\}\f$ denote the lower and
9.12 @@ -78,7 +78,7 @@
9.13 - if \f$lower(uv)<f(uv)<upper(uv)\f$, then \f$cost^\pi(uv)=0\f$;
9.14 - if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$.
9.15 - For all \f$u\in V\f$ nodes:
9.16 - - \f$\pi(u)<=0\f$;
9.17 + - \f$\pi(u)\leq 0\f$;
9.18 - if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$,
9.19 then \f$\pi(u)=0\f$.
9.20
9.21 @@ -145,7 +145,7 @@
9.22 - if \f$lower(uv)<f(uv)<upper(uv)\f$, then \f$cost^\pi(uv)=0\f$;
9.23 - if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$.
9.24 - For all \f$u\in V\f$ nodes:
9.25 - - \f$\pi(u)>=0\f$;
9.26 + - \f$\pi(u)\geq 0\f$;
9.27 - if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$,
9.28 then \f$\pi(u)=0\f$.
9.29
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/doc/references.bib Thu Dec 10 17:18:25 2009 +0100
10.3 @@ -0,0 +1,301 @@
10.4 +%%%%% Defining LEMON %%%%%
10.5 +
10.6 +@misc{lemon,
10.7 + key = {LEMON},
10.8 + title = {{LEMON} -- {L}ibrary for {E}fficient {M}odeling and
10.9 + {O}ptimization in {N}etworks},
10.10 + howpublished = {\url{http://lemon.cs.elte.hu/}},
10.11 + year = 2009
10.12 +}
10.13 +
10.14 +@misc{egres,
10.15 + key = {EGRES},
10.16 + title = {{EGRES} -- {E}gerv{\'a}ry {R}esearch {G}roup on
10.17 + {C}ombinatorial {O}ptimization},
10.18 + url = {http://www.cs.elte.hu/egres/}
10.19 +}
10.20 +
10.21 +@misc{coinor,
10.22 + key = {COIN-OR},
10.23 + title = {{COIN-OR} -- {C}omputational {I}nfrastructure for
10.24 + {O}perations {R}esearch},
10.25 + url = {http://www.coin-or.org/}
10.26 +}
10.27 +
10.28 +
10.29 +%%%%% Other libraries %%%%%%
10.30 +
10.31 +@misc{boost,
10.32 + key = {Boost},
10.33 + title = {{B}oost {C++} {L}ibraries},
10.34 + url = {http://www.boost.org/}
10.35 +}
10.36 +
10.37 +@book{bglbook,
10.38 + author = {Jeremy G. Siek and Lee-Quan Lee and Andrew
10.39 + Lumsdaine},
10.40 + title = {The Boost Graph Library: User Guide and Reference
10.41 + Manual},
10.42 + publisher = {Addison-Wesley},
10.43 + year = 2002
10.44 +}
10.45 +
10.46 +@misc{leda,
10.47 + key = {LEDA},
10.48 + title = {{LEDA} -- {L}ibrary of {E}fficient {D}ata {T}ypes and
10.49 + {A}lgorithms},
10.50 + url = {http://www.algorithmic-solutions.com/}
10.51 +}
10.52 +
10.53 +@book{ledabook,
10.54 + author = {Kurt Mehlhorn and Stefan N{\"a}her},
10.55 + title = {{LEDA}: {A} platform for combinatorial and geometric
10.56 + computing},
10.57 + isbn = {0-521-56329-1},
10.58 + publisher = {Cambridge University Press},
10.59 + address = {New York, NY, USA},
10.60 + year = 1999
10.61 +}
10.62 +
10.63 +
10.64 +%%%%% Tools that LEMON depends on %%%%%
10.65 +
10.66 +@misc{cmake,
10.67 + key = {CMake},
10.68 + title = {{CMake} -- {C}ross {P}latform {M}ake},
10.69 + url = {http://www.cmake.org/}
10.70 +}
10.71 +
10.72 +@misc{doxygen,
10.73 + key = {Doxygen},
10.74 + title = {{Doxygen} -- {S}ource code documentation generator
10.75 + tool},
10.76 + url = {http://www.doxygen.org/}
10.77 +}
10.78 +
10.79 +
10.80 +%%%%% LP/MIP libraries %%%%%
10.81 +
10.82 +@misc{glpk,
10.83 + key = {GLPK},
10.84 + title = {{GLPK} -- {GNU} {L}inear {P}rogramming {K}it},
10.85 + url = {http://www.gnu.org/software/glpk/}
10.86 +}
10.87 +
10.88 +@misc{clp,
10.89 + key = {Clp},
10.90 + title = {{Clp} -- {Coin-Or} {L}inear {P}rogramming},
10.91 + url = {http://projects.coin-or.org/Clp/}
10.92 +}
10.93 +
10.94 +@misc{cbc,
10.95 + key = {Cbc},
10.96 + title = {{Cbc} -- {Coin-Or} {B}ranch and {C}ut},
10.97 + url = {http://projects.coin-or.org/Cbc/}
10.98 +}
10.99 +
10.100 +@misc{cplex,
10.101 + key = {CPLEX},
10.102 + title = {{ILOG} {CPLEX}},
10.103 + url = {http://www.ilog.com/}
10.104 +}
10.105 +
10.106 +@misc{soplex,
10.107 + key = {SoPlex},
10.108 + title = {{SoPlex} -- {T}he {S}equential {O}bject-{O}riented
10.109 + {S}implex},
10.110 + url = {http://soplex.zib.de/}
10.111 +}
10.112 +
10.113 +
10.114 +%%%%% General books %%%%%
10.115 +
10.116 +@book{amo93networkflows,
10.117 + author = {Ravindra K. Ahuja and Thomas L. Magnanti and James
10.118 + B. Orlin},
10.119 + title = {Network Flows: Theory, Algorithms, and Applications},
10.120 + publisher = {Prentice-Hall, Inc.},
10.121 + year = 1993,
10.122 + month = feb,
10.123 + isbn = {978-0136175490}
10.124 +}
10.125 +
10.126 +@book{schrijver03combinatorial,
10.127 + author = {Alexander Schrijver},
10.128 + title = {Combinatorial Optimization: Polyhedra and Efficiency},
10.129 + publisher = {Springer-Verlag},
10.130 + year = 2003,
10.131 + isbn = {978-3540443896}
10.132 +}
10.133 +
10.134 +@book{clrs01algorithms,
10.135 + author = {Thomas H. Cormen and Charles E. Leiserson and Ronald
10.136 + L. Rivest and Clifford Stein},
10.137 + title = {Introduction to Algorithms},
10.138 + publisher = {The MIT Press},
10.139 + year = 2001,
10.140 + edition = {2nd}
10.141 +}
10.142 +
10.143 +@book{stroustrup00cpp,
10.144 + author = {Bjarne Stroustrup},
10.145 + title = {The C++ Programming Language},
10.146 + edition = {3rd},
10.147 + publisher = {Addison-Wesley Professional},
10.148 + isbn = 0201700735,
10.149 + month = {February},
10.150 + year = 2000
10.151 +}
10.152 +
10.153 +
10.154 +%%%%% Maximum flow algorithms %%%%%
10.155 +
10.156 +@article{edmondskarp72theoretical,
10.157 + author = {Jack Edmonds and Richard M. Karp},
10.158 + title = {Theoretical improvements in algorithmic efficiency
10.159 + for network flow problems},
10.160 + journal = {Journal of the ACM},
10.161 + year = 1972,
10.162 + volume = 19,
10.163 + number = 2,
10.164 + pages = {248-264}
10.165 +}
10.166 +
10.167 +@article{goldberg88newapproach,
10.168 + author = {Andrew V. Goldberg and Robert E. Tarjan},
10.169 + title = {A new approach to the maximum flow problem},
10.170 + journal = {Journal of the ACM},
10.171 + year = 1988,
10.172 + volume = 35,
10.173 + number = 4,
10.174 + pages = {921-940}
10.175 +}
10.176 +
10.177 +@article{dinic70algorithm,
10.178 + author = {E. A. Dinic},
10.179 + title = {Algorithm for solution of a problem of maximum flow
10.180 + in a network with power estimation},
10.181 + journal = {Soviet Math. Doklady},
10.182 + year = 1970,
10.183 + volume = 11,
10.184 + pages = {1277-1280}
10.185 +}
10.186 +
10.187 +@article{goldberg08partial,
10.188 + author = {Andrew V. Goldberg},
10.189 + title = {The Partial Augment-Relabel Algorithm for the
10.190 + Maximum Flow Problem},
10.191 + journal = {16th Annual European Symposium on Algorithms},
10.192 + year = 2008,
10.193 + pages = {466-477}
10.194 +}
10.195 +
10.196 +@article{sleator83dynamic,
10.197 + author = {Daniel D. Sleator and Robert E. Tarjan},
10.198 + title = {A data structure for dynamic trees},
10.199 + journal = {Journal of Computer and System Sciences},
10.200 + year = 1983,
10.201 + volume = 26,
10.202 + number = 3,
10.203 + pages = {362-391}
10.204 +}
10.205 +
10.206 +
10.207 +%%%%% Minimum mean cycle algorithms %%%%%
10.208 +
10.209 +@article{karp78characterization,
10.210 + author = {Richard M. Karp},
10.211 + title = {A characterization of the minimum cycle mean in a
10.212 + digraph},
10.213 + journal = {Discrete Math.},
10.214 + year = 1978,
10.215 + volume = 23,
10.216 + pages = {309-311}
10.217 +}
10.218 +
10.219 +@article{dasdan98minmeancycle,
10.220 + author = {Ali Dasdan and Rajesh K. Gupta},
10.221 + title = {Faster Maximum and Minimum Mean Cycle Alogrithms for
10.222 + System Performance Analysis},
10.223 + journal = {IEEE Transactions on Computer-Aided Design of
10.224 + Integrated Circuits and Systems},
10.225 + year = 1998,
10.226 + volume = 17,
10.227 + number = 10,
10.228 + pages = {889-899}
10.229 +}
10.230 +
10.231 +
10.232 +%%%%% Minimum cost flow algorithms %%%%%
10.233 +
10.234 +@article{klein67primal,
10.235 + author = {Morton Klein},
10.236 + title = {A primal method for minimal cost flows with
10.237 + applications to the assignment and transportation
10.238 + problems},
10.239 + journal = {Management Science},
10.240 + year = 1967,
10.241 + volume = 14,
10.242 + pages = {205-220}
10.243 +}
10.244 +
10.245 +@article{goldberg89cyclecanceling,
10.246 + author = {Andrew V. Goldberg and Robert E. Tarjan},
10.247 + title = {Finding minimum-cost circulations by canceling
10.248 + negative cycles},
10.249 + journal = {Journal of the ACM},
10.250 + year = 1989,
10.251 + volume = 36,
10.252 + number = 4,
10.253 + pages = {873-886}
10.254 +}
10.255 +
10.256 +@article{goldberg90approximation,
10.257 + author = {Andrew V. Goldberg and Robert E. Tarjan},
10.258 + title = {Finding Minimum-Cost Circulations by Successive
10.259 + Approximation},
10.260 + journal = {Mathematics of Operations Research},
10.261 + year = 1990,
10.262 + volume = 15,
10.263 + number = 3,
10.264 + pages = {430-466}
10.265 +}
10.266 +
10.267 +@article{goldberg97efficient,
10.268 + author = {Andrew V. Goldberg},
10.269 + title = {An Efficient Implementation of a Scaling
10.270 + Minimum-Cost Flow Algorithm},
10.271 + journal = {Journal of Algorithms},
10.272 + year = 1997,
10.273 + volume = 22,
10.274 + number = 1,
10.275 + pages = {1-29}
10.276 +}
10.277 +
10.278 +@article{bunnagel98efficient,
10.279 + author = {Ursula B{\"u}nnagel and Bernhard Korte and Jens
10.280 + Vygen},
10.281 + title = {Efficient implementation of the {G}oldberg-{T}arjan
10.282 + minimum-cost flow algorithm},
10.283 + journal = {Optimization Methods and Software},
10.284 + year = 1998,
10.285 + volume = 10,
10.286 + pages = {157-174}
10.287 +}
10.288 +
10.289 +@book{dantzig63linearprog,
10.290 + author = {George B. Dantzig},
10.291 + title = {Linear Programming and Extensions},
10.292 + publisher = {Princeton University Press},
10.293 + year = 1963
10.294 +}
10.295 +
10.296 +@mastersthesis{kellyoneill91netsimplex,
10.297 + author = {Damian J. Kelly and Garrett M. O'Neill},
10.298 + title = {The Minimum Cost Flow Problem and The Network
10.299 + Simplex Method},
10.300 + school = {University College},
10.301 + address = {Dublin, Ireland},
10.302 + year = 1991,
10.303 + month = sep,
10.304 +}
11.1 --- a/lemon/Makefile.am Thu Dec 10 17:05:35 2009 +0100
11.2 +++ b/lemon/Makefile.am Thu Dec 10 17:18:25 2009 +0100
11.3 @@ -57,8 +57,10 @@
11.4 lemon/adaptors.h \
11.5 lemon/arg_parser.h \
11.6 lemon/assert.h \
11.7 + lemon/bellman_ford.h \
11.8 lemon/bfs.h \
11.9 lemon/bin_heap.h \
11.10 + lemon/binom_heap.h \
11.11 lemon/bucket_heap.h \
11.12 lemon/cbc.h \
11.13 lemon/circulation.h \
11.14 @@ -78,12 +80,17 @@
11.15 lemon/error.h \
11.16 lemon/euler.h \
11.17 lemon/fib_heap.h \
11.18 + lemon/fourary_heap.h \
11.19 lemon/full_graph.h \
11.20 lemon/glpk.h \
11.21 lemon/gomory_hu.h \
11.22 lemon/graph_to_eps.h \
11.23 lemon/grid_graph.h \
11.24 + lemon/hartmann_orlin.h \
11.25 + lemon/howard.h \
11.26 lemon/hypercube_graph.h \
11.27 + lemon/karp.h \
11.28 + lemon/kary_heap.h \
11.29 lemon/kruskal.h \
11.30 lemon/hao_orlin.h \
11.31 lemon/lgf_reader.h \
11.32 @@ -92,20 +99,22 @@
11.33 lemon/lp.h \
11.34 lemon/lp_base.h \
11.35 lemon/lp_skeleton.h \
11.36 - lemon/list_graph.h \
11.37 lemon/maps.h \
11.38 lemon/matching.h \
11.39 lemon/math.h \
11.40 lemon/min_cost_arborescence.h \
11.41 lemon/nauty_reader.h \
11.42 lemon/network_simplex.h \
11.43 + lemon/pairing_heap.h \
11.44 lemon/path.h \
11.45 + lemon/planarity.h \
11.46 lemon/preflow.h \
11.47 lemon/radix_heap.h \
11.48 lemon/radix_sort.h \
11.49 lemon/random.h \
11.50 lemon/smart_graph.h \
11.51 lemon/soplex.h \
11.52 + lemon/static_graph.h \
11.53 lemon/suurballe.h \
11.54 lemon/time_measure.h \
11.55 lemon/tolerance.h \
12.1 --- a/lemon/adaptors.h Thu Dec 10 17:05:35 2009 +0100
12.2 +++ b/lemon/adaptors.h Thu Dec 10 17:18:25 2009 +0100
12.3 @@ -360,6 +360,9 @@
12.4 /// by adding or removing nodes or arcs, unless the \c GR template
12.5 /// parameter is set to be \c const.
12.6 ///
12.7 + /// This class provides item counting in the same time as the adapted
12.8 + /// digraph structure.
12.9 + ///
12.10 /// \tparam DGR The type of the adapted digraph.
12.11 /// It must conform to the \ref concepts::Digraph "Digraph" concept.
12.12 /// It can also be specified to be \c const.
12.13 @@ -719,6 +722,8 @@
12.14 /// by adding or removing nodes or arcs, unless the \c GR template
12.15 /// parameter is set to be \c const.
12.16 ///
12.17 + /// This class provides only linear time counting for nodes and arcs.
12.18 + ///
12.19 /// \tparam DGR The type of the adapted digraph.
12.20 /// It must conform to the \ref concepts::Digraph "Digraph" concept.
12.21 /// It can also be specified to be \c const.
12.22 @@ -1314,6 +1319,8 @@
12.23 /// by adding or removing nodes or edges, unless the \c GR template
12.24 /// parameter is set to be \c const.
12.25 ///
12.26 + /// This class provides only linear time counting for nodes, edges and arcs.
12.27 + ///
12.28 /// \tparam GR The type of the adapted graph.
12.29 /// It must conform to the \ref concepts::Graph "Graph" concept.
12.30 /// It can also be specified to be \c const.
12.31 @@ -1471,6 +1478,8 @@
12.32 /// by adding or removing nodes or arcs/edges, unless the \c GR template
12.33 /// parameter is set to be \c const.
12.34 ///
12.35 + /// This class provides only linear time item counting.
12.36 + ///
12.37 /// \tparam GR The type of the adapted digraph or graph.
12.38 /// It must conform to the \ref concepts::Digraph "Digraph" concept
12.39 /// or the \ref concepts::Graph "Graph" concept.
12.40 @@ -1619,6 +1628,8 @@
12.41 /// by adding or removing nodes or arcs, unless the \c GR template
12.42 /// parameter is set to be \c const.
12.43 ///
12.44 + /// This class provides only linear time counting for nodes and arcs.
12.45 + ///
12.46 /// \tparam DGR The type of the adapted digraph.
12.47 /// It must conform to the \ref concepts::Digraph "Digraph" concept.
12.48 /// It can also be specified to be \c const.
12.49 @@ -1729,6 +1740,8 @@
12.50 /// by adding or removing nodes or edges, unless the \c GR template
12.51 /// parameter is set to be \c const.
12.52 ///
12.53 + /// This class provides only linear time counting for nodes, edges and arcs.
12.54 + ///
12.55 /// \tparam GR The type of the adapted graph.
12.56 /// It must conform to the \ref concepts::Graph "Graph" concept.
12.57 /// It can also be specified to be \c const.
12.58 @@ -2232,6 +2245,9 @@
12.59 /// by adding or removing nodes or edges, unless the \c GR template
12.60 /// parameter is set to be \c const.
12.61 ///
12.62 + /// This class provides item counting in the same time as the adapted
12.63 + /// digraph structure.
12.64 + ///
12.65 /// \tparam DGR The type of the adapted digraph.
12.66 /// It must conform to the \ref concepts::Digraph "Digraph" concept.
12.67 /// It can also be specified to be \c const.
12.68 @@ -2535,6 +2551,9 @@
12.69 /// by adding or removing nodes or arcs, unless the \c GR template
12.70 /// parameter is set to be \c const.
12.71 ///
12.72 + /// This class provides item counting in the same time as the adapted
12.73 + /// graph structure.
12.74 + ///
12.75 /// \tparam GR The type of the adapted graph.
12.76 /// It must conform to the \ref concepts::Graph "Graph" concept.
12.77 /// It can also be specified to be \c const.
12.78 @@ -2678,6 +2697,8 @@
12.79 /// arcs).
12.80 /// This class conforms to the \ref concepts::Digraph "Digraph" concept.
12.81 ///
12.82 + /// This class provides only linear time counting for nodes and arcs.
12.83 + ///
12.84 /// \tparam DGR The type of the adapted digraph.
12.85 /// It must conform to the \ref concepts::Digraph "Digraph" concept.
12.86 /// It is implicitly \c const.
12.87 @@ -3325,6 +3346,9 @@
12.88 /// costs/capacities of the original digraph to the \e bind \e arcs
12.89 /// in the adaptor.
12.90 ///
12.91 + /// This class provides item counting in the same time as the adapted
12.92 + /// digraph structure.
12.93 + ///
12.94 /// \tparam DGR The type of the adapted digraph.
12.95 /// It must conform to the \ref concepts::Digraph "Digraph" concept.
12.96 /// It is implicitly \c const.
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/lemon/bellman_ford.h Thu Dec 10 17:18:25 2009 +0100
13.3 @@ -0,0 +1,1101 @@
13.4 +/* -*- C++ -*-
13.5 + *
13.6 + * This file is a part of LEMON, a generic C++ optimization library
13.7 + *
13.8 + * Copyright (C) 2003-2008
13.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
13.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
13.11 + *
13.12 + * Permission to use, modify and distribute this software is granted
13.13 + * provided that this copyright notice appears in all copies. For
13.14 + * precise terms see the accompanying LICENSE file.
13.15 + *
13.16 + * This software is provided "AS IS" with no warranty of any kind,
13.17 + * express or implied, and with no claim as to its suitability for any
13.18 + * purpose.
13.19 + *
13.20 + */
13.21 +
13.22 +#ifndef LEMON_BELLMAN_FORD_H
13.23 +#define LEMON_BELLMAN_FORD_H
13.24 +
13.25 +/// \ingroup shortest_path
13.26 +/// \file
13.27 +/// \brief Bellman-Ford algorithm.
13.28 +
13.29 +#include <lemon/list_graph.h>
13.30 +#include <lemon/bits/path_dump.h>
13.31 +#include <lemon/core.h>
13.32 +#include <lemon/error.h>
13.33 +#include <lemon/maps.h>
13.34 +#include <lemon/path.h>
13.35 +
13.36 +#include <limits>
13.37 +
13.38 +namespace lemon {
13.39 +
13.40 + /// \brief Default OperationTraits for the BellmanFord algorithm class.
13.41 + ///
13.42 + /// This operation traits class defines all computational operations
13.43 + /// and constants that are used in the Bellman-Ford algorithm.
13.44 + /// The default implementation is based on the \c numeric_limits class.
13.45 + /// If the numeric type does not have infinity value, then the maximum
13.46 + /// value is used as extremal infinity value.
13.47 + template <
13.48 + typename V,
13.49 + bool has_inf = std::numeric_limits<V>::has_infinity>
13.50 + struct BellmanFordDefaultOperationTraits {
13.51 + /// \e
13.52 + typedef V Value;
13.53 + /// \brief Gives back the zero value of the type.
13.54 + static Value zero() {
13.55 + return static_cast<Value>(0);
13.56 + }
13.57 + /// \brief Gives back the positive infinity value of the type.
13.58 + static Value infinity() {
13.59 + return std::numeric_limits<Value>::infinity();
13.60 + }
13.61 + /// \brief Gives back the sum of the given two elements.
13.62 + static Value plus(const Value& left, const Value& right) {
13.63 + return left + right;
13.64 + }
13.65 + /// \brief Gives back \c true only if the first value is less than
13.66 + /// the second.
13.67 + static bool less(const Value& left, const Value& right) {
13.68 + return left < right;
13.69 + }
13.70 + };
13.71 +
13.72 + template <typename V>
13.73 + struct BellmanFordDefaultOperationTraits<V, false> {
13.74 + typedef V Value;
13.75 + static Value zero() {
13.76 + return static_cast<Value>(0);
13.77 + }
13.78 + static Value infinity() {
13.79 + return std::numeric_limits<Value>::max();
13.80 + }
13.81 + static Value plus(const Value& left, const Value& right) {
13.82 + if (left == infinity() || right == infinity()) return infinity();
13.83 + return left + right;
13.84 + }
13.85 + static bool less(const Value& left, const Value& right) {
13.86 + return left < right;
13.87 + }
13.88 + };
13.89 +
13.90 + /// \brief Default traits class of BellmanFord class.
13.91 + ///
13.92 + /// Default traits class of BellmanFord class.
13.93 + /// \param GR The type of the digraph.
13.94 + /// \param LEN The type of the length map.
13.95 + template<typename GR, typename LEN>
13.96 + struct BellmanFordDefaultTraits {
13.97 + /// The type of the digraph the algorithm runs on.
13.98 + typedef GR Digraph;
13.99 +
13.100 + /// \brief The type of the map that stores the arc lengths.
13.101 + ///
13.102 + /// The type of the map that stores the arc lengths.
13.103 + /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
13.104 + typedef LEN LengthMap;
13.105 +
13.106 + /// The type of the arc lengths.
13.107 + typedef typename LEN::Value Value;
13.108 +
13.109 + /// \brief Operation traits for Bellman-Ford algorithm.
13.110 + ///
13.111 + /// It defines the used operations and the infinity value for the
13.112 + /// given \c Value type.
13.113 + /// \see BellmanFordDefaultOperationTraits
13.114 + typedef BellmanFordDefaultOperationTraits<Value> OperationTraits;
13.115 +
13.116 + /// \brief The type of the map that stores the last arcs of the
13.117 + /// shortest paths.
13.118 + ///
13.119 + /// The type of the map that stores the last
13.120 + /// arcs of the shortest paths.
13.121 + /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
13.122 + typedef typename GR::template NodeMap<typename GR::Arc> PredMap;
13.123 +
13.124 + /// \brief Instantiates a \c PredMap.
13.125 + ///
13.126 + /// This function instantiates a \ref PredMap.
13.127 + /// \param g is the digraph to which we would like to define the
13.128 + /// \ref PredMap.
13.129 + static PredMap *createPredMap(const GR& g) {
13.130 + return new PredMap(g);
13.131 + }
13.132 +
13.133 + /// \brief The type of the map that stores the distances of the nodes.
13.134 + ///
13.135 + /// The type of the map that stores the distances of the nodes.
13.136 + /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
13.137 + typedef typename GR::template NodeMap<typename LEN::Value> DistMap;
13.138 +
13.139 + /// \brief Instantiates a \c DistMap.
13.140 + ///
13.141 + /// This function instantiates a \ref DistMap.
13.142 + /// \param g is the digraph to which we would like to define the
13.143 + /// \ref DistMap.
13.144 + static DistMap *createDistMap(const GR& g) {
13.145 + return new DistMap(g);
13.146 + }
13.147 +
13.148 + };
13.149 +
13.150 + /// \brief %BellmanFord algorithm class.
13.151 + ///
13.152 + /// \ingroup shortest_path
13.153 + /// This class provides an efficient implementation of the Bellman-Ford
13.154 + /// algorithm. The maximum time complexity of the algorithm is
13.155 + /// <tt>O(ne)</tt>.
13.156 + ///
13.157 + /// The Bellman-Ford algorithm solves the single-source shortest path
13.158 + /// problem when the arcs can have negative lengths, but the digraph
13.159 + /// should not contain directed cycles with negative total length.
13.160 + /// If all arc costs are non-negative, consider to use the Dijkstra
13.161 + /// algorithm instead, since it is more efficient.
13.162 + ///
13.163 + /// The arc lengths are passed to the algorithm using a
13.164 + /// \ref concepts::ReadMap "ReadMap", so it is easy to change it to any
13.165 + /// kind of length. The type of the length values is determined by the
13.166 + /// \ref concepts::ReadMap::Value "Value" type of the length map.
13.167 + ///
13.168 + /// There is also a \ref bellmanFord() "function-type interface" for the
13.169 + /// Bellman-Ford algorithm, which is convenient in the simplier cases and
13.170 + /// it can be used easier.
13.171 + ///
13.172 + /// \tparam GR The type of the digraph the algorithm runs on.
13.173 + /// The default type is \ref ListDigraph.
13.174 + /// \tparam LEN A \ref concepts::ReadMap "readable" arc map that specifies
13.175 + /// the lengths of the arcs. The default map type is
13.176 + /// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
13.177 +#ifdef DOXYGEN
13.178 + template <typename GR, typename LEN, typename TR>
13.179 +#else
13.180 + template <typename GR=ListDigraph,
13.181 + typename LEN=typename GR::template ArcMap<int>,
13.182 + typename TR=BellmanFordDefaultTraits<GR,LEN> >
13.183 +#endif
13.184 + class BellmanFord {
13.185 + public:
13.186 +
13.187 + ///The type of the underlying digraph.
13.188 + typedef typename TR::Digraph Digraph;
13.189 +
13.190 + /// \brief The type of the arc lengths.
13.191 + typedef typename TR::LengthMap::Value Value;
13.192 + /// \brief The type of the map that stores the arc lengths.
13.193 + typedef typename TR::LengthMap LengthMap;
13.194 + /// \brief The type of the map that stores the last
13.195 + /// arcs of the shortest paths.
13.196 + typedef typename TR::PredMap PredMap;
13.197 + /// \brief The type of the map that stores the distances of the nodes.
13.198 + typedef typename TR::DistMap DistMap;
13.199 + /// The type of the paths.
13.200 + typedef PredMapPath<Digraph, PredMap> Path;
13.201 + ///\brief The \ref BellmanFordDefaultOperationTraits
13.202 + /// "operation traits class" of the algorithm.
13.203 + typedef typename TR::OperationTraits OperationTraits;
13.204 +
13.205 + ///The \ref BellmanFordDefaultTraits "traits class" of the algorithm.
13.206 + typedef TR Traits;
13.207 +
13.208 + private:
13.209 +
13.210 + typedef typename Digraph::Node Node;
13.211 + typedef typename Digraph::NodeIt NodeIt;
13.212 + typedef typename Digraph::Arc Arc;
13.213 + typedef typename Digraph::OutArcIt OutArcIt;
13.214 +
13.215 + // Pointer to the underlying digraph.
13.216 + const Digraph *_gr;
13.217 + // Pointer to the length map
13.218 + const LengthMap *_length;
13.219 + // Pointer to the map of predecessors arcs.
13.220 + PredMap *_pred;
13.221 + // Indicates if _pred is locally allocated (true) or not.
13.222 + bool _local_pred;
13.223 + // Pointer to the map of distances.
13.224 + DistMap *_dist;
13.225 + // Indicates if _dist is locally allocated (true) or not.
13.226 + bool _local_dist;
13.227 +
13.228 + typedef typename Digraph::template NodeMap<bool> MaskMap;
13.229 + MaskMap *_mask;
13.230 +
13.231 + std::vector<Node> _process;
13.232 +
13.233 + // Creates the maps if necessary.
13.234 + void create_maps() {
13.235 + if(!_pred) {
13.236 + _local_pred = true;
13.237 + _pred = Traits::createPredMap(*_gr);
13.238 + }
13.239 + if(!_dist) {
13.240 + _local_dist = true;
13.241 + _dist = Traits::createDistMap(*_gr);
13.242 + }
13.243 + _mask = new MaskMap(*_gr, false);
13.244 + }
13.245 +
13.246 + public :
13.247 +
13.248 + typedef BellmanFord Create;
13.249 +
13.250 + /// \name Named Template Parameters
13.251 +
13.252 + ///@{
13.253 +
13.254 + template <class T>
13.255 + struct SetPredMapTraits : public Traits {
13.256 + typedef T PredMap;
13.257 + static PredMap *createPredMap(const Digraph&) {
13.258 + LEMON_ASSERT(false, "PredMap is not initialized");
13.259 + return 0; // ignore warnings
13.260 + }
13.261 + };
13.262 +
13.263 + /// \brief \ref named-templ-param "Named parameter" for setting
13.264 + /// \c PredMap type.
13.265 + ///
13.266 + /// \ref named-templ-param "Named parameter" for setting
13.267 + /// \c PredMap type.
13.268 + /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
13.269 + template <class T>
13.270 + struct SetPredMap
13.271 + : public BellmanFord< Digraph, LengthMap, SetPredMapTraits<T> > {
13.272 + typedef BellmanFord< Digraph, LengthMap, SetPredMapTraits<T> > Create;
13.273 + };
13.274 +
13.275 + template <class T>
13.276 + struct SetDistMapTraits : public Traits {
13.277 + typedef T DistMap;
13.278 + static DistMap *createDistMap(const Digraph&) {
13.279 + LEMON_ASSERT(false, "DistMap is not initialized");
13.280 + return 0; // ignore warnings
13.281 + }
13.282 + };
13.283 +
13.284 + /// \brief \ref named-templ-param "Named parameter" for setting
13.285 + /// \c DistMap type.
13.286 + ///
13.287 + /// \ref named-templ-param "Named parameter" for setting
13.288 + /// \c DistMap type.
13.289 + /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
13.290 + template <class T>
13.291 + struct SetDistMap
13.292 + : public BellmanFord< Digraph, LengthMap, SetDistMapTraits<T> > {
13.293 + typedef BellmanFord< Digraph, LengthMap, SetDistMapTraits<T> > Create;
13.294 + };
13.295 +
13.296 + template <class T>
13.297 + struct SetOperationTraitsTraits : public Traits {
13.298 + typedef T OperationTraits;
13.299 + };
13.300 +
13.301 + /// \brief \ref named-templ-param "Named parameter" for setting
13.302 + /// \c OperationTraits type.
13.303 + ///
13.304 + /// \ref named-templ-param "Named parameter" for setting
13.305 + /// \c OperationTraits type.
13.306 + /// For more information, see \ref BellmanFordDefaultOperationTraits.
13.307 + template <class T>
13.308 + struct SetOperationTraits
13.309 + : public BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> > {
13.310 + typedef BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> >
13.311 + Create;
13.312 + };
13.313 +
13.314 + ///@}
13.315 +
13.316 + protected:
13.317 +
13.318 + BellmanFord() {}
13.319 +
13.320 + public:
13.321 +
13.322 + /// \brief Constructor.
13.323 + ///
13.324 + /// Constructor.
13.325 + /// \param g The digraph the algorithm runs on.
13.326 + /// \param length The length map used by the algorithm.
13.327 + BellmanFord(const Digraph& g, const LengthMap& length) :
13.328 + _gr(&g), _length(&length),
13.329 + _pred(0), _local_pred(false),
13.330 + _dist(0), _local_dist(false), _mask(0) {}
13.331 +
13.332 + ///Destructor.
13.333 + ~BellmanFord() {
13.334 + if(_local_pred) delete _pred;
13.335 + if(_local_dist) delete _dist;
13.336 + if(_mask) delete _mask;
13.337 + }
13.338 +
13.339 + /// \brief Sets the length map.
13.340 + ///
13.341 + /// Sets the length map.
13.342 + /// \return <tt>(*this)</tt>
13.343 + BellmanFord &lengthMap(const LengthMap &map) {
13.344 + _length = ↦
13.345 + return *this;
13.346 + }
13.347 +
13.348 + /// \brief Sets the map that stores the predecessor arcs.
13.349 + ///
13.350 + /// Sets the map that stores the predecessor arcs.
13.351 + /// If you don't use this function before calling \ref run()
13.352 + /// or \ref init(), an instance will be allocated automatically.
13.353 + /// The destructor deallocates this automatically allocated map,
13.354 + /// of course.
13.355 + /// \return <tt>(*this)</tt>
13.356 + BellmanFord &predMap(PredMap &map) {
13.357 + if(_local_pred) {
13.358 + delete _pred;
13.359 + _local_pred=false;
13.360 + }
13.361 + _pred = ↦
13.362 + return *this;
13.363 + }
13.364 +
13.365 + /// \brief Sets the map that stores the distances of the nodes.
13.366 + ///
13.367 + /// Sets the map that stores the distances of the nodes calculated
13.368 + /// by the algorithm.
13.369 + /// If you don't use this function before calling \ref run()
13.370 + /// or \ref init(), an instance will be allocated automatically.
13.371 + /// The destructor deallocates this automatically allocated map,
13.372 + /// of course.
13.373 + /// \return <tt>(*this)</tt>
13.374 + BellmanFord &distMap(DistMap &map) {
13.375 + if(_local_dist) {
13.376 + delete _dist;
13.377 + _local_dist=false;
13.378 + }
13.379 + _dist = ↦
13.380 + return *this;
13.381 + }
13.382 +
13.383 + /// \name Execution Control
13.384 + /// The simplest way to execute the Bellman-Ford algorithm is to use
13.385 + /// one of the member functions called \ref run().\n
13.386 + /// If you need better control on the execution, you have to call
13.387 + /// \ref init() first, then you can add several source nodes
13.388 + /// with \ref addSource(). Finally the actual path computation can be
13.389 + /// performed with \ref start(), \ref checkedStart() or
13.390 + /// \ref limitedStart().
13.391 +
13.392 + ///@{
13.393 +
13.394 + /// \brief Initializes the internal data structures.
13.395 + ///
13.396 + /// Initializes the internal data structures. The optional parameter
13.397 + /// is the initial distance of each node.
13.398 + void init(const Value value = OperationTraits::infinity()) {
13.399 + create_maps();
13.400 + for (NodeIt it(*_gr); it != INVALID; ++it) {
13.401 + _pred->set(it, INVALID);
13.402 + _dist->set(it, value);
13.403 + }
13.404 + _process.clear();
13.405 + if (OperationTraits::less(value, OperationTraits::infinity())) {
13.406 + for (NodeIt it(*_gr); it != INVALID; ++it) {
13.407 + _process.push_back(it);
13.408 + _mask->set(it, true);
13.409 + }
13.410 + }
13.411 + }
13.412 +
13.413 + /// \brief Adds a new source node.
13.414 + ///
13.415 + /// This function adds a new source node. The optional second parameter
13.416 + /// is the initial distance of the node.
13.417 + void addSource(Node source, Value dst = OperationTraits::zero()) {
13.418 + _dist->set(source, dst);
13.419 + if (!(*_mask)[source]) {
13.420 + _process.push_back(source);
13.421 + _mask->set(source, true);
13.422 + }
13.423 + }
13.424 +
13.425 + /// \brief Executes one round from the Bellman-Ford algorithm.
13.426 + ///
13.427 + /// If the algoritm calculated the distances in the previous round
13.428 + /// exactly for the paths of at most \c k arcs, then this function
13.429 + /// will calculate the distances exactly for the paths of at most
13.430 + /// <tt>k+1</tt> arcs. Performing \c k iterations using this function
13.431 + /// calculates the shortest path distances exactly for the paths
13.432 + /// consisting of at most \c k arcs.
13.433 + ///
13.434 + /// \warning The paths with limited arc number cannot be retrieved
13.435 + /// easily with \ref path() or \ref predArc() functions. If you also
13.436 + /// need the shortest paths and not only the distances, you should
13.437 + /// store the \ref predMap() "predecessor map" after each iteration
13.438 + /// and build the path manually.
13.439 + ///
13.440 + /// \return \c true when the algorithm have not found more shorter
13.441 + /// paths.
13.442 + ///
13.443 + /// \see ActiveIt
13.444 + bool processNextRound() {
13.445 + for (int i = 0; i < int(_process.size()); ++i) {
13.446 + _mask->set(_process[i], false);
13.447 + }
13.448 + std::vector<Node> nextProcess;
13.449 + std::vector<Value> values(_process.size());
13.450 + for (int i = 0; i < int(_process.size()); ++i) {
13.451 + values[i] = (*_dist)[_process[i]];
13.452 + }
13.453 + for (int i = 0; i < int(_process.size()); ++i) {
13.454 + for (OutArcIt it(*_gr, _process[i]); it != INVALID; ++it) {
13.455 + Node target = _gr->target(it);
13.456 + Value relaxed = OperationTraits::plus(values[i], (*_length)[it]);
13.457 + if (OperationTraits::less(relaxed, (*_dist)[target])) {
13.458 + _pred->set(target, it);
13.459 + _dist->set(target, relaxed);
13.460 + if (!(*_mask)[target]) {
13.461 + _mask->set(target, true);
13.462 + nextProcess.push_back(target);
13.463 + }
13.464 + }
13.465 + }
13.466 + }
13.467 + _process.swap(nextProcess);
13.468 + return _process.empty();
13.469 + }
13.470 +
13.471 + /// \brief Executes one weak round from the Bellman-Ford algorithm.
13.472 + ///
13.473 + /// If the algorithm calculated the distances in the previous round
13.474 + /// at least for the paths of at most \c k arcs, then this function
13.475 + /// will calculate the distances at least for the paths of at most
13.476 + /// <tt>k+1</tt> arcs.
13.477 + /// This function does not make it possible to calculate the shortest
13.478 + /// path distances exactly for paths consisting of at most \c k arcs,
13.479 + /// this is why it is called weak round.
13.480 + ///
13.481 + /// \return \c true when the algorithm have not found more shorter
13.482 + /// paths.
13.483 + ///
13.484 + /// \see ActiveIt
13.485 + bool processNextWeakRound() {
13.486 + for (int i = 0; i < int(_process.size()); ++i) {
13.487 + _mask->set(_process[i], false);
13.488 + }
13.489 + std::vector<Node> nextProcess;
13.490 + for (int i = 0; i < int(_process.size()); ++i) {
13.491 + for (OutArcIt it(*_gr, _process[i]); it != INVALID; ++it) {
13.492 + Node target = _gr->target(it);
13.493 + Value relaxed =
13.494 + OperationTraits::plus((*_dist)[_process[i]], (*_length)[it]);
13.495 + if (OperationTraits::less(relaxed, (*_dist)[target])) {
13.496 + _pred->set(target, it);
13.497 + _dist->set(target, relaxed);
13.498 + if (!(*_mask)[target]) {
13.499 + _mask->set(target, true);
13.500 + nextProcess.push_back(target);
13.501 + }
13.502 + }
13.503 + }
13.504 + }
13.505 + _process.swap(nextProcess);
13.506 + return _process.empty();
13.507 + }
13.508 +
13.509 + /// \brief Executes the algorithm.
13.510 + ///
13.511 + /// Executes the algorithm.
13.512 + ///
13.513 + /// This method runs the Bellman-Ford algorithm from the root node(s)
13.514 + /// in order to compute the shortest path to each node.
13.515 + ///
13.516 + /// The algorithm computes
13.517 + /// - the shortest path tree (forest),
13.518 + /// - the distance of each node from the root(s).
13.519 + ///
13.520 + /// \pre init() must be called and at least one root node should be
13.521 + /// added with addSource() before using this function.
13.522 + void start() {
13.523 + int num = countNodes(*_gr) - 1;
13.524 + for (int i = 0; i < num; ++i) {
13.525 + if (processNextWeakRound()) break;
13.526 + }
13.527 + }
13.528 +
13.529 + /// \brief Executes the algorithm and checks the negative cycles.
13.530 + ///
13.531 + /// Executes the algorithm and checks the negative cycles.
13.532 + ///
13.533 + /// This method runs the Bellman-Ford algorithm from the root node(s)
13.534 + /// in order to compute the shortest path to each node and also checks
13.535 + /// if the digraph contains cycles with negative total length.
13.536 + ///
13.537 + /// The algorithm computes
13.538 + /// - the shortest path tree (forest),
13.539 + /// - the distance of each node from the root(s).
13.540 + ///
13.541 + /// \return \c false if there is a negative cycle in the digraph.
13.542 + ///
13.543 + /// \pre init() must be called and at least one root node should be
13.544 + /// added with addSource() before using this function.
13.545 + bool checkedStart() {
13.546 + int num = countNodes(*_gr);
13.547 + for (int i = 0; i < num; ++i) {
13.548 + if (processNextWeakRound()) return true;
13.549 + }
13.550 + return _process.empty();
13.551 + }
13.552 +
13.553 + /// \brief Executes the algorithm with arc number limit.
13.554 + ///
13.555 + /// Executes the algorithm with arc number limit.
13.556 + ///
13.557 + /// This method runs the Bellman-Ford algorithm from the root node(s)
13.558 + /// in order to compute the shortest path distance for each node
13.559 + /// using only the paths consisting of at most \c num arcs.
13.560 + ///
13.561 + /// The algorithm computes
13.562 + /// - the limited distance of each node from the root(s),
13.563 + /// - the predecessor arc for each node.
13.564 + ///
13.565 + /// \warning The paths with limited arc number cannot be retrieved
13.566 + /// easily with \ref path() or \ref predArc() functions. If you also
13.567 + /// need the shortest paths and not only the distances, you should
13.568 + /// store the \ref predMap() "predecessor map" after each iteration
13.569 + /// and build the path manually.
13.570 + ///
13.571 + /// \pre init() must be called and at least one root node should be
13.572 + /// added with addSource() before using this function.
13.573 + void limitedStart(int num) {
13.574 + for (int i = 0; i < num; ++i) {
13.575 + if (processNextRound()) break;
13.576 + }
13.577 + }
13.578 +
13.579 + /// \brief Runs the algorithm from the given root node.
13.580 + ///
13.581 + /// This method runs the Bellman-Ford algorithm from the given root
13.582 + /// node \c s in order to compute the shortest path to each node.
13.583 + ///
13.584 + /// The algorithm computes
13.585 + /// - the shortest path tree (forest),
13.586 + /// - the distance of each node from the root(s).
13.587 + ///
13.588 + /// \note bf.run(s) is just a shortcut of the following code.
13.589 + /// \code
13.590 + /// bf.init();
13.591 + /// bf.addSource(s);
13.592 + /// bf.start();
13.593 + /// \endcode
13.594 + void run(Node s) {
13.595 + init();
13.596 + addSource(s);
13.597 + start();
13.598 + }
13.599 +
13.600 + /// \brief Runs the algorithm from the given root node with arc
13.601 + /// number limit.
13.602 + ///
13.603 + /// This method runs the Bellman-Ford algorithm from the given root
13.604 + /// node \c s in order to compute the shortest path distance for each
13.605 + /// node using only the paths consisting of at most \c num arcs.
13.606 + ///
13.607 + /// The algorithm computes
13.608 + /// - the limited distance of each node from the root(s),
13.609 + /// - the predecessor arc for each node.
13.610 + ///
13.611 + /// \warning The paths with limited arc number cannot be retrieved
13.612 + /// easily with \ref path() or \ref predArc() functions. If you also
13.613 + /// need the shortest paths and not only the distances, you should
13.614 + /// store the \ref predMap() "predecessor map" after each iteration
13.615 + /// and build the path manually.
13.616 + ///
13.617 + /// \note bf.run(s, num) is just a shortcut of the following code.
13.618 + /// \code
13.619 + /// bf.init();
13.620 + /// bf.addSource(s);
13.621 + /// bf.limitedStart(num);
13.622 + /// \endcode
13.623 + void run(Node s, int num) {
13.624 + init();
13.625 + addSource(s);
13.626 + limitedStart(num);
13.627 + }
13.628 +
13.629 + ///@}
13.630 +
13.631 + /// \brief LEMON iterator for getting the active nodes.
13.632 + ///
13.633 + /// This class provides a common style LEMON iterator that traverses
13.634 + /// the active nodes of the Bellman-Ford algorithm after the last
13.635 + /// phase. These nodes should be checked in the next phase to
13.636 + /// find augmenting arcs outgoing from them.
13.637 + class ActiveIt {
13.638 + public:
13.639 +
13.640 + /// \brief Constructor.
13.641 + ///
13.642 + /// Constructor for getting the active nodes of the given BellmanFord
13.643 + /// instance.
13.644 + ActiveIt(const BellmanFord& algorithm) : _algorithm(&algorithm)
13.645 + {
13.646 + _index = _algorithm->_process.size() - 1;
13.647 + }
13.648 +
13.649 + /// \brief Invalid constructor.
13.650 + ///
13.651 + /// Invalid constructor.
13.652 + ActiveIt(Invalid) : _algorithm(0), _index(-1) {}
13.653 +
13.654 + /// \brief Conversion to \c Node.
13.655 + ///
13.656 + /// Conversion to \c Node.
13.657 + operator Node() const {
13.658 + return _index >= 0 ? _algorithm->_process[_index] : INVALID;
13.659 + }
13.660 +
13.661 + /// \brief Increment operator.
13.662 + ///
13.663 + /// Increment operator.
13.664 + ActiveIt& operator++() {
13.665 + --_index;
13.666 + return *this;
13.667 + }
13.668 +
13.669 + bool operator==(const ActiveIt& it) const {
13.670 + return static_cast<Node>(*this) == static_cast<Node>(it);
13.671 + }
13.672 + bool operator!=(const ActiveIt& it) const {
13.673 + return static_cast<Node>(*this) != static_cast<Node>(it);
13.674 + }
13.675 + bool operator<(const ActiveIt& it) const {
13.676 + return static_cast<Node>(*this) < static_cast<Node>(it);
13.677 + }
13.678 +
13.679 + private:
13.680 + const BellmanFord* _algorithm;
13.681 + int _index;
13.682 + };
13.683 +
13.684 + /// \name Query Functions
13.685 + /// The result of the Bellman-Ford algorithm can be obtained using these
13.686 + /// functions.\n
13.687 + /// Either \ref run() or \ref init() should be called before using them.
13.688 +
13.689 + ///@{
13.690 +
13.691 + /// \brief The shortest path to the given node.
13.692 + ///
13.693 + /// Gives back the shortest path to the given node from the root(s).
13.694 + ///
13.695 + /// \warning \c t should be reached from the root(s).
13.696 + ///
13.697 + /// \pre Either \ref run() or \ref init() must be called before
13.698 + /// using this function.
13.699 + Path path(Node t) const
13.700 + {
13.701 + return Path(*_gr, *_pred, t);
13.702 + }
13.703 +
13.704 + /// \brief The distance of the given node from the root(s).
13.705 + ///
13.706 + /// Returns the distance of the given node from the root(s).
13.707 + ///
13.708 + /// \warning If node \c v is not reached from the root(s), then
13.709 + /// the return value of this function is undefined.
13.710 + ///
13.711 + /// \pre Either \ref run() or \ref init() must be called before
13.712 + /// using this function.
13.713 + Value dist(Node v) const { return (*_dist)[v]; }
13.714 +
13.715 + /// \brief Returns the 'previous arc' of the shortest path tree for
13.716 + /// the given node.
13.717 + ///
13.718 + /// This function returns the 'previous arc' of the shortest path
13.719 + /// tree for node \c v, i.e. it returns the last arc of a
13.720 + /// shortest path from a root to \c v. It is \c INVALID if \c v
13.721 + /// is not reached from the root(s) or if \c v is a root.
13.722 + ///
13.723 + /// The shortest path tree used here is equal to the shortest path
13.724 + /// tree used in \ref predNode() and \ref predMap().
13.725 + ///
13.726 + /// \pre Either \ref run() or \ref init() must be called before
13.727 + /// using this function.
13.728 + Arc predArc(Node v) const { return (*_pred)[v]; }
13.729 +
13.730 + /// \brief Returns the 'previous node' of the shortest path tree for
13.731 + /// the given node.
13.732 + ///
13.733 + /// This function returns the 'previous node' of the shortest path
13.734 + /// tree for node \c v, i.e. it returns the last but one node of
13.735 + /// a shortest path from a root to \c v. It is \c INVALID if \c v
13.736 + /// is not reached from the root(s) or if \c v is a root.
13.737 + ///
13.738 + /// The shortest path tree used here is equal to the shortest path
13.739 + /// tree used in \ref predArc() and \ref predMap().
13.740 + ///
13.741 + /// \pre Either \ref run() or \ref init() must be called before
13.742 + /// using this function.
13.743 + Node predNode(Node v) const {
13.744 + return (*_pred)[v] == INVALID ? INVALID : _gr->source((*_pred)[v]);
13.745 + }
13.746 +
13.747 + /// \brief Returns a const reference to the node map that stores the
13.748 + /// distances of the nodes.
13.749 + ///
13.750 + /// Returns a const reference to the node map that stores the distances
13.751 + /// of the nodes calculated by the algorithm.
13.752 + ///
13.753 + /// \pre Either \ref run() or \ref init() must be called before
13.754 + /// using this function.
13.755 + const DistMap &distMap() const { return *_dist;}
13.756 +
13.757 + /// \brief Returns a const reference to the node map that stores the
13.758 + /// predecessor arcs.
13.759 + ///
13.760 + /// Returns a const reference to the node map that stores the predecessor
13.761 + /// arcs, which form the shortest path tree (forest).
13.762 + ///
13.763 + /// \pre Either \ref run() or \ref init() must be called before
13.764 + /// using this function.
13.765 + const PredMap &predMap() const { return *_pred; }
13.766 +
13.767 + /// \brief Checks if a node is reached from the root(s).
13.768 + ///
13.769 + /// Returns \c true if \c v is reached from the root(s).
13.770 + ///
13.771 + /// \pre Either \ref run() or \ref init() must be called before
13.772 + /// using this function.
13.773 + bool reached(Node v) const {
13.774 + return (*_dist)[v] != OperationTraits::infinity();
13.775 + }
13.776 +
13.777 + /// \brief Gives back a negative cycle.
13.778 + ///
13.779 + /// This function gives back a directed cycle with negative total
13.780 + /// length if the algorithm has already found one.
13.781 + /// Otherwise it gives back an empty path.
13.782 + lemon::Path<Digraph> negativeCycle() const {
13.783 + typename Digraph::template NodeMap<int> state(*_gr, -1);
13.784 + lemon::Path<Digraph> cycle;
13.785 + for (int i = 0; i < int(_process.size()); ++i) {
13.786 + if (state[_process[i]] != -1) continue;
13.787 + for (Node v = _process[i]; (*_pred)[v] != INVALID;
13.788 + v = _gr->source((*_pred)[v])) {
13.789 + if (state[v] == i) {
13.790 + cycle.addFront((*_pred)[v]);
13.791 + for (Node u = _gr->source((*_pred)[v]); u != v;
13.792 + u = _gr->source((*_pred)[u])) {
13.793 + cycle.addFront((*_pred)[u]);
13.794 + }
13.795 + return cycle;
13.796 + }
13.797 + else if (state[v] >= 0) {
13.798 + break;
13.799 + }
13.800 + state[v] = i;
13.801 + }
13.802 + }
13.803 + return cycle;
13.804 + }
13.805 +
13.806 + ///@}
13.807 + };
13.808 +
13.809 + /// \brief Default traits class of bellmanFord() function.
13.810 + ///
13.811 + /// Default traits class of bellmanFord() function.
13.812 + /// \tparam GR The type of the digraph.
13.813 + /// \tparam LEN The type of the length map.
13.814 + template <typename GR, typename LEN>
13.815 + struct BellmanFordWizardDefaultTraits {
13.816 + /// The type of the digraph the algorithm runs on.
13.817 + typedef GR Digraph;
13.818 +
13.819 + /// \brief The type of the map that stores the arc lengths.
13.820 + ///
13.821 + /// The type of the map that stores the arc lengths.
13.822 + /// It must meet the \ref concepts::ReadMap "ReadMap" concept.
13.823 + typedef LEN LengthMap;
13.824 +
13.825 + /// The type of the arc lengths.
13.826 + typedef typename LEN::Value Value;
13.827 +
13.828 + /// \brief Operation traits for Bellman-Ford algorithm.
13.829 + ///
13.830 + /// It defines the used operations and the infinity value for the
13.831 + /// given \c Value type.
13.832 + /// \see BellmanFordDefaultOperationTraits
13.833 + typedef BellmanFordDefaultOperationTraits<Value> OperationTraits;
13.834 +
13.835 + /// \brief The type of the map that stores the last
13.836 + /// arcs of the shortest paths.
13.837 + ///
13.838 + /// The type of the map that stores the last arcs of the shortest paths.
13.839 + /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
13.840 + typedef typename GR::template NodeMap<typename GR::Arc> PredMap;
13.841 +
13.842 + /// \brief Instantiates a \c PredMap.
13.843 + ///
13.844 + /// This function instantiates a \ref PredMap.
13.845 + /// \param g is the digraph to which we would like to define the
13.846 + /// \ref PredMap.
13.847 + static PredMap *createPredMap(const GR &g) {
13.848 + return new PredMap(g);
13.849 + }
13.850 +
13.851 + /// \brief The type of the map that stores the distances of the nodes.
13.852 + ///
13.853 + /// The type of the map that stores the distances of the nodes.
13.854 + /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
13.855 + typedef typename GR::template NodeMap<Value> DistMap;
13.856 +
13.857 + /// \brief Instantiates a \c DistMap.
13.858 + ///
13.859 + /// This function instantiates a \ref DistMap.
13.860 + /// \param g is the digraph to which we would like to define the
13.861 + /// \ref DistMap.
13.862 + static DistMap *createDistMap(const GR &g) {
13.863 + return new DistMap(g);
13.864 + }
13.865 +
13.866 + ///The type of the shortest paths.
13.867 +
13.868 + ///The type of the shortest paths.
13.869 + ///It must meet the \ref concepts::Path "Path" concept.
13.870 + typedef lemon::Path<Digraph> Path;
13.871 + };
13.872 +
13.873 + /// \brief Default traits class used by BellmanFordWizard.
13.874 + ///
13.875 + /// Default traits class used by BellmanFordWizard.
13.876 + /// \tparam GR The type of the digraph.
13.877 + /// \tparam LEN The type of the length map.
13.878 + template <typename GR, typename LEN>
13.879 + class BellmanFordWizardBase
13.880 + : public BellmanFordWizardDefaultTraits<GR, LEN> {
13.881 +
13.882 + typedef BellmanFordWizardDefaultTraits<GR, LEN> Base;
13.883 + protected:
13.884 + // Type of the nodes in the digraph.
13.885 + typedef typename Base::Digraph::Node Node;
13.886 +
13.887 + // Pointer to the underlying digraph.
13.888 + void *_graph;
13.889 + // Pointer to the length map
13.890 + void *_length;
13.891 + // Pointer to the map of predecessors arcs.
13.892 + void *_pred;
13.893 + // Pointer to the map of distances.
13.894 + void *_dist;
13.895 + //Pointer to the shortest path to the target node.
13.896 + void *_path;
13.897 + //Pointer to the distance of the target node.
13.898 + void *_di;
13.899 +
13.900 + public:
13.901 + /// Constructor.
13.902 +
13.903 + /// This constructor does not require parameters, it initiates
13.904 + /// all of the attributes to default values \c 0.
13.905 + BellmanFordWizardBase() :
13.906 + _graph(0), _length(0), _pred(0), _dist(0), _path(0), _di(0) {}
13.907 +
13.908 + /// Constructor.
13.909 +
13.910 + /// This constructor requires two parameters,
13.911 + /// others are initiated to \c 0.
13.912 + /// \param gr The digraph the algorithm runs on.
13.913 + /// \param len The length map.
13.914 + BellmanFordWizardBase(const GR& gr,
13.915 + const LEN& len) :
13.916 + _graph(reinterpret_cast<void*>(const_cast<GR*>(&gr))),
13.917 + _length(reinterpret_cast<void*>(const_cast<LEN*>(&len))),
13.918 + _pred(0), _dist(0), _path(0), _di(0) {}
13.919 +
13.920 + };
13.921 +
13.922 + /// \brief Auxiliary class for the function-type interface of the
13.923 + /// \ref BellmanFord "Bellman-Ford" algorithm.
13.924 + ///
13.925 + /// This auxiliary class is created to implement the
13.926 + /// \ref bellmanFord() "function-type interface" of the
13.927 + /// \ref BellmanFord "Bellman-Ford" algorithm.
13.928 + /// It does not have own \ref run() method, it uses the
13.929 + /// functions and features of the plain \ref BellmanFord.
13.930 + ///
13.931 + /// This class should only be used through the \ref bellmanFord()
13.932 + /// function, which makes it easier to use the algorithm.
13.933 + template<class TR>
13.934 + class BellmanFordWizard : public TR {
13.935 + typedef TR Base;
13.936 +
13.937 + typedef typename TR::Digraph Digraph;
13.938 +
13.939 + typedef typename Digraph::Node Node;
13.940 + typedef typename Digraph::NodeIt NodeIt;
13.941 + typedef typename Digraph::Arc Arc;
13.942 + typedef typename Digraph::OutArcIt ArcIt;
13.943 +
13.944 + typedef typename TR::LengthMap LengthMap;
13.945 + typedef typename LengthMap::Value Value;
13.946 + typedef typename TR::PredMap PredMap;
13.947 + typedef typename TR::DistMap DistMap;
13.948 + typedef typename TR::Path Path;
13.949 +
13.950 + public:
13.951 + /// Constructor.
13.952 + BellmanFordWizard() : TR() {}
13.953 +
13.954 + /// \brief Constructor that requires parameters.
13.955 + ///
13.956 + /// Constructor that requires parameters.
13.957 + /// These parameters will be the default values for the traits class.
13.958 + /// \param gr The digraph the algorithm runs on.
13.959 + /// \param len The length map.
13.960 + BellmanFordWizard(const Digraph& gr, const LengthMap& len)
13.961 + : TR(gr, len) {}
13.962 +
13.963 + /// \brief Copy constructor
13.964 + BellmanFordWizard(const TR &b) : TR(b) {}
13.965 +
13.966 + ~BellmanFordWizard() {}
13.967 +
13.968 + /// \brief Runs the Bellman-Ford algorithm from the given source node.
13.969 + ///
13.970 + /// This method runs the Bellman-Ford algorithm from the given source
13.971 + /// node in order to compute the shortest path to each node.
13.972 + void run(Node s) {
13.973 + BellmanFord<Digraph,LengthMap,TR>
13.974 + bf(*reinterpret_cast<const Digraph*>(Base::_graph),
13.975 + *reinterpret_cast<const LengthMap*>(Base::_length));
13.976 + if (Base::_pred) bf.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
13.977 + if (Base::_dist) bf.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
13.978 + bf.run(s);
13.979 + }
13.980 +
13.981 + /// \brief Runs the Bellman-Ford algorithm to find the shortest path
13.982 + /// between \c s and \c t.
13.983 + ///
13.984 + /// This method runs the Bellman-Ford algorithm from node \c s
13.985 + /// in order to compute the shortest path to node \c t.
13.986 + /// Actually, it computes the shortest path to each node, but using
13.987 + /// this function you can retrieve the distance and the shortest path
13.988 + /// for a single target node easier.
13.989 + ///
13.990 + /// \return \c true if \c t is reachable form \c s.
13.991 + bool run(Node s, Node t) {
13.992 + BellmanFord<Digraph,LengthMap,TR>
13.993 + bf(*reinterpret_cast<const Digraph*>(Base::_graph),
13.994 + *reinterpret_cast<const LengthMap*>(Base::_length));
13.995 + if (Base::_pred) bf.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
13.996 + if (Base::_dist) bf.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
13.997 + bf.run(s);
13.998 + if (Base::_path) *reinterpret_cast<Path*>(Base::_path) = bf.path(t);
13.999 + if (Base::_di) *reinterpret_cast<Value*>(Base::_di) = bf.dist(t);
13.1000 + return bf.reached(t);
13.1001 + }
13.1002 +
13.1003 + template<class T>
13.1004 + struct SetPredMapBase : public Base {
13.1005 + typedef T PredMap;
13.1006 + static PredMap *createPredMap(const Digraph &) { return 0; };
13.1007 + SetPredMapBase(const TR &b) : TR(b) {}
13.1008 + };
13.1009 +
13.1010 + /// \brief \ref named-templ-param "Named parameter" for setting
13.1011 + /// the predecessor map.
13.1012 + ///
13.1013 + /// \ref named-templ-param "Named parameter" for setting
13.1014 + /// the map that stores the predecessor arcs of the nodes.
13.1015 + template<class T>
13.1016 + BellmanFordWizard<SetPredMapBase<T> > predMap(const T &t) {
13.1017 + Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
13.1018 + return BellmanFordWizard<SetPredMapBase<T> >(*this);
13.1019 + }
13.1020 +
13.1021 + template<class T>
13.1022 + struct SetDistMapBase : public Base {
13.1023 + typedef T DistMap;
13.1024 + static DistMap *createDistMap(const Digraph &) { return 0; };
13.1025 + SetDistMapBase(const TR &b) : TR(b) {}
13.1026 + };
13.1027 +
13.1028 + /// \brief \ref named-templ-param "Named parameter" for setting
13.1029 + /// the distance map.
13.1030 + ///
13.1031 + /// \ref named-templ-param "Named parameter" for setting
13.1032 + /// the map that stores the distances of the nodes calculated
13.1033 + /// by the algorithm.
13.1034 + template<class T>
13.1035 + BellmanFordWizard<SetDistMapBase<T> > distMap(const T &t) {
13.1036 + Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
13.1037 + return BellmanFordWizard<SetDistMapBase<T> >(*this);
13.1038 + }
13.1039 +
13.1040 + template<class T>
13.1041 + struct SetPathBase : public Base {
13.1042 + typedef T Path;
13.1043 + SetPathBase(const TR &b) : TR(b) {}
13.1044 + };
13.1045 +
13.1046 + /// \brief \ref named-func-param "Named parameter" for getting
13.1047 + /// the shortest path to the target node.
13.1048 + ///
13.1049 + /// \ref named-func-param "Named parameter" for getting
13.1050 + /// the shortest path to the target node.
13.1051 + template<class T>
13.1052 + BellmanFordWizard<SetPathBase<T> > path(const T &t)
13.1053 + {
13.1054 + Base::_path=reinterpret_cast<void*>(const_cast<T*>(&t));
13.1055 + return BellmanFordWizard<SetPathBase<T> >(*this);
13.1056 + }
13.1057 +
13.1058 + /// \brief \ref named-func-param "Named parameter" for getting
13.1059 + /// the distance of the target node.
13.1060 + ///
13.1061 + /// \ref named-func-param "Named parameter" for getting
13.1062 + /// the distance of the target node.
13.1063 + BellmanFordWizard dist(const Value &d)
13.1064 + {
13.1065 + Base::_di=reinterpret_cast<void*>(const_cast<Value*>(&d));
13.1066 + return *this;
13.1067 + }
13.1068 +
13.1069 + };
13.1070 +
13.1071 + /// \brief Function type interface for the \ref BellmanFord "Bellman-Ford"
13.1072 + /// algorithm.
13.1073 + ///
13.1074 + /// \ingroup shortest_path
13.1075 + /// Function type interface for the \ref BellmanFord "Bellman-Ford"
13.1076 + /// algorithm.
13.1077 + ///
13.1078 + /// This function also has several \ref named-templ-func-param
13.1079 + /// "named parameters", they are declared as the members of class
13.1080 + /// \ref BellmanFordWizard.
13.1081 + /// The following examples show how to use these parameters.
13.1082 + /// \code
13.1083 + /// // Compute shortest path from node s to each node
13.1084 + /// bellmanFord(g,length).predMap(preds).distMap(dists).run(s);
13.1085 + ///
13.1086 + /// // Compute shortest path from s to t
13.1087 + /// bool reached = bellmanFord(g,length).path(p).dist(d).run(s,t);
13.1088 + /// \endcode
13.1089 + /// \warning Don't forget to put the \ref BellmanFordWizard::run() "run()"
13.1090 + /// to the end of the parameter list.
13.1091 + /// \sa BellmanFordWizard
13.1092 + /// \sa BellmanFord
13.1093 + template<typename GR, typename LEN>
13.1094 + BellmanFordWizard<BellmanFordWizardBase<GR,LEN> >
13.1095 + bellmanFord(const GR& digraph,
13.1096 + const LEN& length)
13.1097 + {
13.1098 + return BellmanFordWizard<BellmanFordWizardBase<GR,LEN> >(digraph, length);
13.1099 + }
13.1100 +
13.1101 +} //END OF NAMESPACE LEMON
13.1102 +
13.1103 +#endif
13.1104 +
14.1 --- a/lemon/bfs.h Thu Dec 10 17:05:35 2009 +0100
14.2 +++ b/lemon/bfs.h Thu Dec 10 17:18:25 2009 +0100
14.3 @@ -47,7 +47,7 @@
14.4 ///
14.5 ///The type of the map that stores the predecessor
14.6 ///arcs of the shortest paths.
14.7 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.8 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.9 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
14.10 ///Instantiates a \c PredMap.
14.11
14.12 @@ -62,7 +62,8 @@
14.13 ///The type of the map that indicates which nodes are processed.
14.14
14.15 ///The type of the map that indicates which nodes are processed.
14.16 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.17 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.18 + ///By default, it is a NullMap.
14.19 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
14.20 ///Instantiates a \c ProcessedMap.
14.21
14.22 @@ -81,7 +82,7 @@
14.23 ///The type of the map that indicates which nodes are reached.
14.24
14.25 ///The type of the map that indicates which nodes are reached.
14.26 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
14.27 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
14.28 typedef typename Digraph::template NodeMap<bool> ReachedMap;
14.29 ///Instantiates a \c ReachedMap.
14.30
14.31 @@ -96,7 +97,7 @@
14.32 ///The type of the map that stores the distances of the nodes.
14.33
14.34 ///The type of the map that stores the distances of the nodes.
14.35 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.36 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.37 typedef typename Digraph::template NodeMap<int> DistMap;
14.38 ///Instantiates a \c DistMap.
14.39
14.40 @@ -225,7 +226,7 @@
14.41 ///
14.42 ///\ref named-templ-param "Named parameter" for setting
14.43 ///\c PredMap type.
14.44 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.45 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.46 template <class T>
14.47 struct SetPredMap : public Bfs< Digraph, SetPredMapTraits<T> > {
14.48 typedef Bfs< Digraph, SetPredMapTraits<T> > Create;
14.49 @@ -245,7 +246,7 @@
14.50 ///
14.51 ///\ref named-templ-param "Named parameter" for setting
14.52 ///\c DistMap type.
14.53 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.54 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.55 template <class T>
14.56 struct SetDistMap : public Bfs< Digraph, SetDistMapTraits<T> > {
14.57 typedef Bfs< Digraph, SetDistMapTraits<T> > Create;
14.58 @@ -265,7 +266,7 @@
14.59 ///
14.60 ///\ref named-templ-param "Named parameter" for setting
14.61 ///\c ReachedMap type.
14.62 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
14.63 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
14.64 template <class T>
14.65 struct SetReachedMap : public Bfs< Digraph, SetReachedMapTraits<T> > {
14.66 typedef Bfs< Digraph, SetReachedMapTraits<T> > Create;
14.67 @@ -285,7 +286,7 @@
14.68 ///
14.69 ///\ref named-templ-param "Named parameter" for setting
14.70 ///\c ProcessedMap type.
14.71 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.72 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.73 template <class T>
14.74 struct SetProcessedMap : public Bfs< Digraph, SetProcessedMapTraits<T> > {
14.75 typedef Bfs< Digraph, SetProcessedMapTraits<T> > Create;
14.76 @@ -413,8 +414,8 @@
14.77 ///\name Execution Control
14.78 ///The simplest way to execute the BFS algorithm is to use one of the
14.79 ///member functions called \ref run(Node) "run()".\n
14.80 - ///If you need more control on the execution, first you have to call
14.81 - ///\ref init(), then you can add several source nodes with
14.82 + ///If you need better control on the execution, you have to call
14.83 + ///\ref init() first, then you can add several source nodes with
14.84 ///\ref addSource(). Finally the actual path computation can be
14.85 ///performed with one of the \ref start() functions.
14.86
14.87 @@ -700,12 +701,8 @@
14.88
14.89 ///Runs the algorithm to visit all nodes in the digraph.
14.90
14.91 - ///This method runs the %BFS algorithm in order to
14.92 - ///compute the shortest path to each node.
14.93 - ///
14.94 - ///The algorithm computes
14.95 - ///- the shortest path tree (forest),
14.96 - ///- the distance of each node from the root(s).
14.97 + ///This method runs the %BFS algorithm in order to visit all nodes
14.98 + ///in the digraph.
14.99 ///
14.100 ///\note <tt>b.run(s)</tt> is just a shortcut of the following code.
14.101 ///\code
14.102 @@ -737,9 +734,9 @@
14.103
14.104 ///@{
14.105
14.106 - ///The shortest path to a node.
14.107 + ///The shortest path to the given node.
14.108
14.109 - ///Returns the shortest path to a node.
14.110 + ///Returns the shortest path to the given node from the root(s).
14.111 ///
14.112 ///\warning \c t should be reached from the root(s).
14.113 ///
14.114 @@ -747,9 +744,9 @@
14.115 ///must be called before using this function.
14.116 Path path(Node t) const { return Path(*G, *_pred, t); }
14.117
14.118 - ///The distance of a node from the root(s).
14.119 + ///The distance of the given node from the root(s).
14.120
14.121 - ///Returns the distance of a node from the root(s).
14.122 + ///Returns the distance of the given node from the root(s).
14.123 ///
14.124 ///\warning If node \c v is not reached from the root(s), then
14.125 ///the return value of this function is undefined.
14.126 @@ -758,29 +755,31 @@
14.127 ///must be called before using this function.
14.128 int dist(Node v) const { return (*_dist)[v]; }
14.129
14.130 - ///Returns the 'previous arc' of the shortest path tree for a node.
14.131 -
14.132 + ///\brief Returns the 'previous arc' of the shortest path tree for
14.133 + ///the given node.
14.134 + ///
14.135 ///This function returns the 'previous arc' of the shortest path
14.136 ///tree for the node \c v, i.e. it returns the last arc of a
14.137 ///shortest path from a root to \c v. It is \c INVALID if \c v
14.138 ///is not reached from the root(s) or if \c v is a root.
14.139 ///
14.140 ///The shortest path tree used here is equal to the shortest path
14.141 - ///tree used in \ref predNode().
14.142 + ///tree used in \ref predNode() and \ref predMap().
14.143 ///
14.144 ///\pre Either \ref run(Node) "run()" or \ref init()
14.145 ///must be called before using this function.
14.146 Arc predArc(Node v) const { return (*_pred)[v];}
14.147
14.148 - ///Returns the 'previous node' of the shortest path tree for a node.
14.149 -
14.150 + ///\brief Returns the 'previous node' of the shortest path tree for
14.151 + ///the given node.
14.152 + ///
14.153 ///This function returns the 'previous node' of the shortest path
14.154 ///tree for the node \c v, i.e. it returns the last but one node
14.155 - ///from a shortest path from a root to \c v. It is \c INVALID
14.156 + ///of a shortest path from a root to \c v. It is \c INVALID
14.157 ///if \c v is not reached from the root(s) or if \c v is a root.
14.158 ///
14.159 ///The shortest path tree used here is equal to the shortest path
14.160 - ///tree used in \ref predArc().
14.161 + ///tree used in \ref predArc() and \ref predMap().
14.162 ///
14.163 ///\pre Either \ref run(Node) "run()" or \ref init()
14.164 ///must be called before using this function.
14.165 @@ -801,13 +800,13 @@
14.166 ///predecessor arcs.
14.167 ///
14.168 ///Returns a const reference to the node map that stores the predecessor
14.169 - ///arcs, which form the shortest path tree.
14.170 + ///arcs, which form the shortest path tree (forest).
14.171 ///
14.172 ///\pre Either \ref run(Node) "run()" or \ref init()
14.173 ///must be called before using this function.
14.174 const PredMap &predMap() const { return *_pred;}
14.175
14.176 - ///Checks if a node is reached from the root(s).
14.177 + ///Checks if the given node is reached from the root(s).
14.178
14.179 ///Returns \c true if \c v is reached from the root(s).
14.180 ///
14.181 @@ -833,7 +832,7 @@
14.182 ///
14.183 ///The type of the map that stores the predecessor
14.184 ///arcs of the shortest paths.
14.185 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.186 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.187 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
14.188 ///Instantiates a PredMap.
14.189
14.190 @@ -848,8 +847,8 @@
14.191 ///The type of the map that indicates which nodes are processed.
14.192
14.193 ///The type of the map that indicates which nodes are processed.
14.194 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.195 - ///By default it is a NullMap.
14.196 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.197 + ///By default, it is a NullMap.
14.198 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
14.199 ///Instantiates a ProcessedMap.
14.200
14.201 @@ -868,7 +867,7 @@
14.202 ///The type of the map that indicates which nodes are reached.
14.203
14.204 ///The type of the map that indicates which nodes are reached.
14.205 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
14.206 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
14.207 typedef typename Digraph::template NodeMap<bool> ReachedMap;
14.208 ///Instantiates a ReachedMap.
14.209
14.210 @@ -883,7 +882,7 @@
14.211 ///The type of the map that stores the distances of the nodes.
14.212
14.213 ///The type of the map that stores the distances of the nodes.
14.214 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.215 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.216 typedef typename Digraph::template NodeMap<int> DistMap;
14.217 ///Instantiates a DistMap.
14.218
14.219 @@ -898,18 +897,14 @@
14.220 ///The type of the shortest paths.
14.221
14.222 ///The type of the shortest paths.
14.223 - ///It must meet the \ref concepts::Path "Path" concept.
14.224 + ///It must conform to the \ref concepts::Path "Path" concept.
14.225 typedef lemon::Path<Digraph> Path;
14.226 };
14.227
14.228 /// Default traits class used by BfsWizard
14.229
14.230 - /// To make it easier to use Bfs algorithm
14.231 - /// we have created a wizard class.
14.232 - /// This \ref BfsWizard class needs default traits,
14.233 - /// as well as the \ref Bfs class.
14.234 - /// The \ref BfsWizardBase is a class to be the default traits of the
14.235 - /// \ref BfsWizard class.
14.236 + /// Default traits class used by BfsWizard.
14.237 + /// \tparam GR The type of the digraph.
14.238 template<class GR>
14.239 class BfsWizardBase : public BfsWizardDefaultTraits<GR>
14.240 {
14.241 @@ -937,7 +932,7 @@
14.242 public:
14.243 /// Constructor.
14.244
14.245 - /// This constructor does not require parameters, therefore it initiates
14.246 + /// This constructor does not require parameters, it initiates
14.247 /// all of the attributes to \c 0.
14.248 BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
14.249 _dist(0), _path(0), _di(0) {}
14.250 @@ -967,7 +962,6 @@
14.251 {
14.252 typedef TR Base;
14.253
14.254 - ///The type of the digraph the algorithm runs on.
14.255 typedef typename TR::Digraph Digraph;
14.256
14.257 typedef typename Digraph::Node Node;
14.258 @@ -975,16 +969,10 @@
14.259 typedef typename Digraph::Arc Arc;
14.260 typedef typename Digraph::OutArcIt OutArcIt;
14.261
14.262 - ///\brief The type of the map that stores the predecessor
14.263 - ///arcs of the shortest paths.
14.264 typedef typename TR::PredMap PredMap;
14.265 - ///\brief The type of the map that stores the distances of the nodes.
14.266 typedef typename TR::DistMap DistMap;
14.267 - ///\brief The type of the map that indicates which nodes are reached.
14.268 typedef typename TR::ReachedMap ReachedMap;
14.269 - ///\brief The type of the map that indicates which nodes are processed.
14.270 typedef typename TR::ProcessedMap ProcessedMap;
14.271 - ///The type of the shortest paths
14.272 typedef typename TR::Path Path;
14.273
14.274 public:
14.275 @@ -1054,8 +1042,8 @@
14.276
14.277 ///Runs BFS algorithm to visit all nodes in the digraph.
14.278
14.279 - ///This method runs BFS algorithm in order to compute
14.280 - ///the shortest path to each node.
14.281 + ///This method runs BFS algorithm in order to visit all nodes
14.282 + ///in the digraph.
14.283 void run()
14.284 {
14.285 run(INVALID);
14.286 @@ -1067,11 +1055,12 @@
14.287 static PredMap *createPredMap(const Digraph &) { return 0; };
14.288 SetPredMapBase(const TR &b) : TR(b) {}
14.289 };
14.290 - ///\brief \ref named-func-param "Named parameter"
14.291 - ///for setting PredMap object.
14.292 +
14.293 + ///\brief \ref named-templ-param "Named parameter" for setting
14.294 + ///the predecessor map.
14.295 ///
14.296 - ///\ref named-func-param "Named parameter"
14.297 - ///for setting PredMap object.
14.298 + ///\ref named-templ-param "Named parameter" function for setting
14.299 + ///the map that stores the predecessor arcs of the nodes.
14.300 template<class T>
14.301 BfsWizard<SetPredMapBase<T> > predMap(const T &t)
14.302 {
14.303 @@ -1085,11 +1074,12 @@
14.304 static ReachedMap *createReachedMap(const Digraph &) { return 0; };
14.305 SetReachedMapBase(const TR &b) : TR(b) {}
14.306 };
14.307 - ///\brief \ref named-func-param "Named parameter"
14.308 - ///for setting ReachedMap object.
14.309 +
14.310 + ///\brief \ref named-templ-param "Named parameter" for setting
14.311 + ///the reached map.
14.312 ///
14.313 - /// \ref named-func-param "Named parameter"
14.314 - ///for setting ReachedMap object.
14.315 + ///\ref named-templ-param "Named parameter" function for setting
14.316 + ///the map that indicates which nodes are reached.
14.317 template<class T>
14.318 BfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
14.319 {
14.320 @@ -1103,11 +1093,13 @@
14.321 static DistMap *createDistMap(const Digraph &) { return 0; };
14.322 SetDistMapBase(const TR &b) : TR(b) {}
14.323 };
14.324 - ///\brief \ref named-func-param "Named parameter"
14.325 - ///for setting DistMap object.
14.326 +
14.327 + ///\brief \ref named-templ-param "Named parameter" for setting
14.328 + ///the distance map.
14.329 ///
14.330 - /// \ref named-func-param "Named parameter"
14.331 - ///for setting DistMap object.
14.332 + ///\ref named-templ-param "Named parameter" function for setting
14.333 + ///the map that stores the distances of the nodes calculated
14.334 + ///by the algorithm.
14.335 template<class T>
14.336 BfsWizard<SetDistMapBase<T> > distMap(const T &t)
14.337 {
14.338 @@ -1121,11 +1113,12 @@
14.339 static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
14.340 SetProcessedMapBase(const TR &b) : TR(b) {}
14.341 };
14.342 - ///\brief \ref named-func-param "Named parameter"
14.343 - ///for setting ProcessedMap object.
14.344 +
14.345 + ///\brief \ref named-func-param "Named parameter" for setting
14.346 + ///the processed map.
14.347 ///
14.348 - /// \ref named-func-param "Named parameter"
14.349 - ///for setting ProcessedMap object.
14.350 + ///\ref named-templ-param "Named parameter" function for setting
14.351 + ///the map that indicates which nodes are processed.
14.352 template<class T>
14.353 BfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
14.354 {
14.355 @@ -1264,7 +1257,7 @@
14.356 /// \brief The type of the map that indicates which nodes are reached.
14.357 ///
14.358 /// The type of the map that indicates which nodes are reached.
14.359 - /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
14.360 + /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
14.361 typedef typename Digraph::template NodeMap<bool> ReachedMap;
14.362
14.363 /// \brief Instantiates a ReachedMap.
14.364 @@ -1425,8 +1418,8 @@
14.365 /// \name Execution Control
14.366 /// The simplest way to execute the BFS algorithm is to use one of the
14.367 /// member functions called \ref run(Node) "run()".\n
14.368 - /// If you need more control on the execution, first you have to call
14.369 - /// \ref init(), then you can add several source nodes with
14.370 + /// If you need better control on the execution, you have to call
14.371 + /// \ref init() first, then you can add several source nodes with
14.372 /// \ref addSource(). Finally the actual path computation can be
14.373 /// performed with one of the \ref start() functions.
14.374
14.375 @@ -1698,12 +1691,8 @@
14.376
14.377 /// \brief Runs the algorithm to visit all nodes in the digraph.
14.378 ///
14.379 - /// This method runs the %BFS algorithm in order to
14.380 - /// compute the shortest path to each node.
14.381 - ///
14.382 - /// The algorithm computes
14.383 - /// - the shortest path tree (forest),
14.384 - /// - the distance of each node from the root(s).
14.385 + /// This method runs the %BFS algorithm in order to visit all nodes
14.386 + /// in the digraph.
14.387 ///
14.388 /// \note <tt>b.run(s)</tt> is just a shortcut of the following code.
14.389 ///\code
14.390 @@ -1735,7 +1724,7 @@
14.391
14.392 ///@{
14.393
14.394 - /// \brief Checks if a node is reached from the root(s).
14.395 + /// \brief Checks if the given node is reached from the root(s).
14.396 ///
14.397 /// Returns \c true if \c v is reached from the root(s).
14.398 ///
15.1 --- a/lemon/bin_heap.h Thu Dec 10 17:05:35 2009 +0100
15.2 +++ b/lemon/bin_heap.h Thu Dec 10 17:18:25 2009 +0100
15.3 @@ -19,9 +19,9 @@
15.4 #ifndef LEMON_BIN_HEAP_H
15.5 #define LEMON_BIN_HEAP_H
15.6
15.7 -///\ingroup auxdat
15.8 +///\ingroup heaps
15.9 ///\file
15.10 -///\brief Binary Heap implementation.
15.11 +///\brief Binary heap implementation.
15.12
15.13 #include <vector>
15.14 #include <utility>
15.15 @@ -29,45 +29,41 @@
15.16
15.17 namespace lemon {
15.18
15.19 - ///\ingroup auxdat
15.20 + /// \ingroup heaps
15.21 ///
15.22 - ///\brief A Binary Heap implementation.
15.23 + /// \brief Binary heap data structure.
15.24 ///
15.25 - ///This class implements the \e binary \e heap data structure.
15.26 + /// This class implements the \e binary \e heap data structure.
15.27 + /// It fully conforms to the \ref concepts::Heap "heap concept".
15.28 ///
15.29 - ///A \e heap is a data structure for storing items with specified values
15.30 - ///called \e priorities in such a way that finding the item with minimum
15.31 - ///priority is efficient. \c CMP specifies the ordering of the priorities.
15.32 - ///In a heap one can change the priority of an item, add or erase an
15.33 - ///item, etc.
15.34 - ///
15.35 - ///\tparam PR Type of the priority of the items.
15.36 - ///\tparam IM A read and writable item map with int values, used internally
15.37 - ///to handle the cross references.
15.38 - ///\tparam CMP A functor class for the ordering of the priorities.
15.39 - ///The default is \c std::less<PR>.
15.40 - ///
15.41 - ///\sa FibHeap
15.42 - ///\sa Dijkstra
15.43 + /// \tparam PR Type of the priorities of the items.
15.44 + /// \tparam IM A read-writable item map with \c int values, used
15.45 + /// internally to handle the cross references.
15.46 + /// \tparam CMP A functor class for comparing the priorities.
15.47 + /// The default is \c std::less<PR>.
15.48 +#ifdef DOXYGEN
15.49 + template <typename PR, typename IM, typename CMP>
15.50 +#else
15.51 template <typename PR, typename IM, typename CMP = std::less<PR> >
15.52 +#endif
15.53 class BinHeap {
15.54 + public:
15.55
15.56 - public:
15.57 - ///\e
15.58 + /// Type of the item-int map.
15.59 typedef IM ItemIntMap;
15.60 - ///\e
15.61 + /// Type of the priorities.
15.62 typedef PR Prio;
15.63 - ///\e
15.64 + /// Type of the items stored in the heap.
15.65 typedef typename ItemIntMap::Key Item;
15.66 - ///\e
15.67 + /// Type of the item-priority pairs.
15.68 typedef std::pair<Item,Prio> Pair;
15.69 - ///\e
15.70 + /// Functor type for comparing the priorities.
15.71 typedef CMP Compare;
15.72
15.73 - /// \brief Type to represent the items states.
15.74 + /// \brief Type to represent the states of the items.
15.75 ///
15.76 - /// Each Item element have a state associated to it. It may be "in heap",
15.77 - /// "pre heap" or "post heap". The latter two are indifferent from the
15.78 + /// Each item has a state associated to it. It can be "in heap",
15.79 + /// "pre-heap" or "post-heap". The latter two are indifferent from the
15.80 /// heap's point of view, but may be useful to the user.
15.81 ///
15.82 /// The item-int map must be initialized in such way that it assigns
15.83 @@ -84,42 +80,43 @@
15.84 ItemIntMap &_iim;
15.85
15.86 public:
15.87 - /// \brief The constructor.
15.88 +
15.89 + /// \brief Constructor.
15.90 ///
15.91 - /// The constructor.
15.92 - /// \param map should be given to the constructor, since it is used
15.93 - /// internally to handle the cross references. The value of the map
15.94 - /// must be \c PRE_HEAP (<tt>-1</tt>) for every item.
15.95 + /// Constructor.
15.96 + /// \param map A map that assigns \c int values to the items.
15.97 + /// It is used internally to handle the cross references.
15.98 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
15.99 explicit BinHeap(ItemIntMap &map) : _iim(map) {}
15.100
15.101 - /// \brief The constructor.
15.102 + /// \brief Constructor.
15.103 ///
15.104 - /// The constructor.
15.105 - /// \param map should be given to the constructor, since it is used
15.106 - /// internally to handle the cross references. The value of the map
15.107 - /// should be PRE_HEAP (-1) for each element.
15.108 - ///
15.109 - /// \param comp The comparator function object.
15.110 + /// Constructor.
15.111 + /// \param map A map that assigns \c int values to the items.
15.112 + /// It is used internally to handle the cross references.
15.113 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
15.114 + /// \param comp The function object used for comparing the priorities.
15.115 BinHeap(ItemIntMap &map, const Compare &comp)
15.116 : _iim(map), _comp(comp) {}
15.117
15.118
15.119 - /// The number of items stored in the heap.
15.120 + /// \brief The number of items stored in the heap.
15.121 ///
15.122 - /// \brief Returns the number of items stored in the heap.
15.123 + /// This function returns the number of items stored in the heap.
15.124 int size() const { return _data.size(); }
15.125
15.126 - /// \brief Checks if the heap stores no items.
15.127 + /// \brief Check if the heap is empty.
15.128 ///
15.129 - /// Returns \c true if and only if the heap stores no items.
15.130 + /// This function returns \c true if the heap is empty.
15.131 bool empty() const { return _data.empty(); }
15.132
15.133 - /// \brief Make empty this heap.
15.134 + /// \brief Make the heap empty.
15.135 ///
15.136 - /// Make empty this heap. It does not change the cross reference map.
15.137 - /// If you want to reuse what is not surely empty you should first clear
15.138 - /// the heap and after that you should set the cross reference map for
15.139 - /// each item to \c PRE_HEAP.
15.140 + /// This functon makes the heap empty.
15.141 + /// It does not change the cross reference map. If you want to reuse
15.142 + /// a heap that is not surely empty, you should first clear it and
15.143 + /// then you should set the cross reference map to \c PRE_HEAP
15.144 + /// for each item.
15.145 void clear() {
15.146 _data.clear();
15.147 }
15.148 @@ -127,12 +124,12 @@
15.149 private:
15.150 static int parent(int i) { return (i-1)/2; }
15.151
15.152 - static int second_child(int i) { return 2*i+2; }
15.153 + static int secondChild(int i) { return 2*i+2; }
15.154 bool less(const Pair &p1, const Pair &p2) const {
15.155 return _comp(p1.second, p2.second);
15.156 }
15.157
15.158 - int bubble_up(int hole, Pair p) {
15.159 + int bubbleUp(int hole, Pair p) {
15.160 int par = parent(hole);
15.161 while( hole>0 && less(p,_data[par]) ) {
15.162 move(_data[par],hole);
15.163 @@ -143,8 +140,8 @@
15.164 return hole;
15.165 }
15.166
15.167 - int bubble_down(int hole, Pair p, int length) {
15.168 - int child = second_child(hole);
15.169 + int bubbleDown(int hole, Pair p, int length) {
15.170 + int child = secondChild(hole);
15.171 while(child < length) {
15.172 if( less(_data[child-1], _data[child]) ) {
15.173 --child;
15.174 @@ -153,7 +150,7 @@
15.175 goto ok;
15.176 move(_data[child], hole);
15.177 hole = child;
15.178 - child = second_child(hole);
15.179 + child = secondChild(hole);
15.180 }
15.181 child--;
15.182 if( child<length && less(_data[child], p) ) {
15.183 @@ -171,87 +168,91 @@
15.184 }
15.185
15.186 public:
15.187 +
15.188 /// \brief Insert a pair of item and priority into the heap.
15.189 ///
15.190 - /// Adds \c p.first to the heap with priority \c p.second.
15.191 + /// This function inserts \c p.first to the heap with priority
15.192 + /// \c p.second.
15.193 /// \param p The pair to insert.
15.194 + /// \pre \c p.first must not be stored in the heap.
15.195 void push(const Pair &p) {
15.196 int n = _data.size();
15.197 _data.resize(n+1);
15.198 - bubble_up(n, p);
15.199 + bubbleUp(n, p);
15.200 }
15.201
15.202 - /// \brief Insert an item into the heap with the given heap.
15.203 + /// \brief Insert an item into the heap with the given priority.
15.204 ///
15.205 - /// Adds \c i to the heap with priority \c p.
15.206 + /// This function inserts the given item into the heap with the
15.207 + /// given priority.
15.208 /// \param i The item to insert.
15.209 /// \param p The priority of the item.
15.210 + /// \pre \e i must not be stored in the heap.
15.211 void push(const Item &i, const Prio &p) { push(Pair(i,p)); }
15.212
15.213 - /// \brief Returns the item with minimum priority relative to \c Compare.
15.214 + /// \brief Return the item having minimum priority.
15.215 ///
15.216 - /// This method returns the item with minimum priority relative to \c
15.217 - /// Compare.
15.218 - /// \pre The heap must be nonempty.
15.219 + /// This function returns the item having minimum priority.
15.220 + /// \pre The heap must be non-empty.
15.221 Item top() const {
15.222 return _data[0].first;
15.223 }
15.224
15.225 - /// \brief Returns the minimum priority relative to \c Compare.
15.226 + /// \brief The minimum priority.
15.227 ///
15.228 - /// It returns the minimum priority relative to \c Compare.
15.229 - /// \pre The heap must be nonempty.
15.230 + /// This function returns the minimum priority.
15.231 + /// \pre The heap must be non-empty.
15.232 Prio prio() const {
15.233 return _data[0].second;
15.234 }
15.235
15.236 - /// \brief Deletes the item with minimum priority relative to \c Compare.
15.237 + /// \brief Remove the item having minimum priority.
15.238 ///
15.239 - /// This method deletes the item with minimum priority relative to \c
15.240 - /// Compare from the heap.
15.241 + /// This function removes the item having minimum priority.
15.242 /// \pre The heap must be non-empty.
15.243 void pop() {
15.244 int n = _data.size()-1;
15.245 _iim.set(_data[0].first, POST_HEAP);
15.246 if (n > 0) {
15.247 - bubble_down(0, _data[n], n);
15.248 + bubbleDown(0, _data[n], n);
15.249 }
15.250 _data.pop_back();
15.251 }
15.252
15.253 - /// \brief Deletes \c i from the heap.
15.254 + /// \brief Remove the given item from the heap.
15.255 ///
15.256 - /// This method deletes item \c i from the heap.
15.257 - /// \param i The item to erase.
15.258 - /// \pre The item should be in the heap.
15.259 + /// This function removes the given item from the heap if it is
15.260 + /// already stored.
15.261 + /// \param i The item to delete.
15.262 + /// \pre \e i must be in the heap.
15.263 void erase(const Item &i) {
15.264 int h = _iim[i];
15.265 int n = _data.size()-1;
15.266 _iim.set(_data[h].first, POST_HEAP);
15.267 if( h < n ) {
15.268 - if ( bubble_up(h, _data[n]) == h) {
15.269 - bubble_down(h, _data[n], n);
15.270 + if ( bubbleUp(h, _data[n]) == h) {
15.271 + bubbleDown(h, _data[n], n);
15.272 }
15.273 }
15.274 _data.pop_back();
15.275 }
15.276
15.277 -
15.278 - /// \brief Returns the priority of \c i.
15.279 + /// \brief The priority of the given item.
15.280 ///
15.281 - /// This function returns the priority of item \c i.
15.282 + /// This function returns the priority of the given item.
15.283 /// \param i The item.
15.284 - /// \pre \c i must be in the heap.
15.285 + /// \pre \e i must be in the heap.
15.286 Prio operator[](const Item &i) const {
15.287 int idx = _iim[i];
15.288 return _data[idx].second;
15.289 }
15.290
15.291 - /// \brief \c i gets to the heap with priority \c p independently
15.292 - /// if \c i was already there.
15.293 + /// \brief Set the priority of an item or insert it, if it is
15.294 + /// not stored in the heap.
15.295 ///
15.296 - /// This method calls \ref push(\c i, \c p) if \c i is not stored
15.297 - /// in the heap and sets the priority of \c i to \c p otherwise.
15.298 + /// This method sets the priority of the given item if it is
15.299 + /// already stored in the heap. Otherwise it inserts the given
15.300 + /// item into the heap with the given priority.
15.301 /// \param i The item.
15.302 /// \param p The priority.
15.303 void set(const Item &i, const Prio &p) {
15.304 @@ -260,44 +261,42 @@
15.305 push(i,p);
15.306 }
15.307 else if( _comp(p, _data[idx].second) ) {
15.308 - bubble_up(idx, Pair(i,p));
15.309 + bubbleUp(idx, Pair(i,p));
15.310 }
15.311 else {
15.312 - bubble_down(idx, Pair(i,p), _data.size());
15.313 + bubbleDown(idx, Pair(i,p), _data.size());
15.314 }
15.315 }
15.316
15.317 - /// \brief Decreases the priority of \c i to \c p.
15.318 + /// \brief Decrease the priority of an item to the given value.
15.319 ///
15.320 - /// This method decreases the priority of item \c i to \c p.
15.321 + /// This function decreases the priority of an item to the given value.
15.322 /// \param i The item.
15.323 /// \param p The priority.
15.324 - /// \pre \c i must be stored in the heap with priority at least \c
15.325 - /// p relative to \c Compare.
15.326 + /// \pre \e i must be stored in the heap with priority at least \e p.
15.327 void decrease(const Item &i, const Prio &p) {
15.328 int idx = _iim[i];
15.329 - bubble_up(idx, Pair(i,p));
15.330 + bubbleUp(idx, Pair(i,p));
15.331 }
15.332
15.333 - /// \brief Increases the priority of \c i to \c p.
15.334 + /// \brief Increase the priority of an item to the given value.
15.335 ///
15.336 - /// This method sets the priority of item \c i to \c p.
15.337 + /// This function increases the priority of an item to the given value.
15.338 /// \param i The item.
15.339 /// \param p The priority.
15.340 - /// \pre \c i must be stored in the heap with priority at most \c
15.341 - /// p relative to \c Compare.
15.342 + /// \pre \e i must be stored in the heap with priority at most \e p.
15.343 void increase(const Item &i, const Prio &p) {
15.344 int idx = _iim[i];
15.345 - bubble_down(idx, Pair(i,p), _data.size());
15.346 + bubbleDown(idx, Pair(i,p), _data.size());
15.347 }
15.348
15.349 - /// \brief Returns if \c item is in, has already been in, or has
15.350 - /// never been in the heap.
15.351 + /// \brief Return the state of an item.
15.352 ///
15.353 - /// This method returns PRE_HEAP if \c item has never been in the
15.354 - /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
15.355 - /// otherwise. In the latter case it is possible that \c item will
15.356 - /// get back to the heap again.
15.357 + /// This method returns \c PRE_HEAP if the given item has never
15.358 + /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
15.359 + /// and \c POST_HEAP otherwise.
15.360 + /// In the latter case it is possible that the item will get back
15.361 + /// to the heap again.
15.362 /// \param i The item.
15.363 State state(const Item &i) const {
15.364 int s = _iim[i];
15.365 @@ -306,11 +305,11 @@
15.366 return State(s);
15.367 }
15.368
15.369 - /// \brief Sets the state of the \c item in the heap.
15.370 + /// \brief Set the state of an item in the heap.
15.371 ///
15.372 - /// Sets the state of the \c item in the heap. It can be used to
15.373 - /// manually clear the heap when it is important to achive the
15.374 - /// better time complexity.
15.375 + /// This function sets the state of the given item in the heap.
15.376 + /// It can be used to manually clear the heap when it is important
15.377 + /// to achive better time complexity.
15.378 /// \param i The item.
15.379 /// \param st The state. It should not be \c IN_HEAP.
15.380 void state(const Item& i, State st) {
15.381 @@ -327,12 +326,13 @@
15.382 }
15.383 }
15.384
15.385 - /// \brief Replaces an item in the heap.
15.386 + /// \brief Replace an item in the heap.
15.387 ///
15.388 - /// The \c i item is replaced with \c j item. The \c i item should
15.389 - /// be in the heap, while the \c j should be out of the heap. The
15.390 - /// \c i item will out of the heap and \c j will be in the heap
15.391 - /// with the same prioriority as prevoiusly the \c i item.
15.392 + /// This function replaces item \c i with item \c j.
15.393 + /// Item \c i must be in the heap, while \c j must be out of the heap.
15.394 + /// After calling this method, item \c i will be out of the
15.395 + /// heap and \c j will be in the heap with the same prioriority
15.396 + /// as item \c i had before.
15.397 void replace(const Item& i, const Item& j) {
15.398 int idx = _iim[i];
15.399 _iim.set(i, _iim[j]);
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/lemon/binom_heap.h Thu Dec 10 17:18:25 2009 +0100
16.3 @@ -0,0 +1,445 @@
16.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
16.5 + *
16.6 + * This file is a part of LEMON, a generic C++ optimization library.
16.7 + *
16.8 + * Copyright (C) 2003-2009
16.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
16.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
16.11 + *
16.12 + * Permission to use, modify and distribute this software is granted
16.13 + * provided that this copyright notice appears in all copies. For
16.14 + * precise terms see the accompanying LICENSE file.
16.15 + *
16.16 + * This software is provided "AS IS" with no warranty of any kind,
16.17 + * express or implied, and with no claim as to its suitability for any
16.18 + * purpose.
16.19 + *
16.20 + */
16.21 +
16.22 +#ifndef LEMON_BINOM_HEAP_H
16.23 +#define LEMON_BINOM_HEAP_H
16.24 +
16.25 +///\file
16.26 +///\ingroup heaps
16.27 +///\brief Binomial Heap implementation.
16.28 +
16.29 +#include <vector>
16.30 +#include <utility>
16.31 +#include <functional>
16.32 +#include <lemon/math.h>
16.33 +#include <lemon/counter.h>
16.34 +
16.35 +namespace lemon {
16.36 +
16.37 + /// \ingroup heaps
16.38 + ///
16.39 + ///\brief Binomial heap data structure.
16.40 + ///
16.41 + /// This class implements the \e binomial \e heap data structure.
16.42 + /// It fully conforms to the \ref concepts::Heap "heap concept".
16.43 + ///
16.44 + /// The methods \ref increase() and \ref erase() are not efficient
16.45 + /// in a binomial heap. In case of many calls of these operations,
16.46 + /// it is better to use other heap structure, e.g. \ref BinHeap
16.47 + /// "binary heap".
16.48 + ///
16.49 + /// \tparam PR Type of the priorities of the items.
16.50 + /// \tparam IM A read-writable item map with \c int values, used
16.51 + /// internally to handle the cross references.
16.52 + /// \tparam CMP A functor class for comparing the priorities.
16.53 + /// The default is \c std::less<PR>.
16.54 +#ifdef DOXYGEN
16.55 + template <typename PR, typename IM, typename CMP>
16.56 +#else
16.57 + template <typename PR, typename IM, typename CMP = std::less<PR> >
16.58 +#endif
16.59 + class BinomHeap {
16.60 + public:
16.61 + /// Type of the item-int map.
16.62 + typedef IM ItemIntMap;
16.63 + /// Type of the priorities.
16.64 + typedef PR Prio;
16.65 + /// Type of the items stored in the heap.
16.66 + typedef typename ItemIntMap::Key Item;
16.67 + /// Functor type for comparing the priorities.
16.68 + typedef CMP Compare;
16.69 +
16.70 + /// \brief Type to represent the states of the items.
16.71 + ///
16.72 + /// Each item has a state associated to it. It can be "in heap",
16.73 + /// "pre-heap" or "post-heap". The latter two are indifferent from the
16.74 + /// heap's point of view, but may be useful to the user.
16.75 + ///
16.76 + /// The item-int map must be initialized in such way that it assigns
16.77 + /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
16.78 + enum State {
16.79 + IN_HEAP = 0, ///< = 0.
16.80 + PRE_HEAP = -1, ///< = -1.
16.81 + POST_HEAP = -2 ///< = -2.
16.82 + };
16.83 +
16.84 + private:
16.85 + class Store;
16.86 +
16.87 + std::vector<Store> _data;
16.88 + int _min, _head;
16.89 + ItemIntMap &_iim;
16.90 + Compare _comp;
16.91 + int _num_items;
16.92 +
16.93 + public:
16.94 + /// \brief Constructor.
16.95 + ///
16.96 + /// Constructor.
16.97 + /// \param map A map that assigns \c int values to the items.
16.98 + /// It is used internally to handle the cross references.
16.99 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
16.100 + explicit BinomHeap(ItemIntMap &map)
16.101 + : _min(0), _head(-1), _iim(map), _num_items(0) {}
16.102 +
16.103 + /// \brief Constructor.
16.104 + ///
16.105 + /// Constructor.
16.106 + /// \param map A map that assigns \c int values to the items.
16.107 + /// It is used internally to handle the cross references.
16.108 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
16.109 + /// \param comp The function object used for comparing the priorities.
16.110 + BinomHeap(ItemIntMap &map, const Compare &comp)
16.111 + : _min(0), _head(-1), _iim(map), _comp(comp), _num_items(0) {}
16.112 +
16.113 + /// \brief The number of items stored in the heap.
16.114 + ///
16.115 + /// This function returns the number of items stored in the heap.
16.116 + int size() const { return _num_items; }
16.117 +
16.118 + /// \brief Check if the heap is empty.
16.119 + ///
16.120 + /// This function returns \c true if the heap is empty.
16.121 + bool empty() const { return _num_items==0; }
16.122 +
16.123 + /// \brief Make the heap empty.
16.124 + ///
16.125 + /// This functon makes the heap empty.
16.126 + /// It does not change the cross reference map. If you want to reuse
16.127 + /// a heap that is not surely empty, you should first clear it and
16.128 + /// then you should set the cross reference map to \c PRE_HEAP
16.129 + /// for each item.
16.130 + void clear() {
16.131 + _data.clear(); _min=0; _num_items=0; _head=-1;
16.132 + }
16.133 +
16.134 + /// \brief Set the priority of an item or insert it, if it is
16.135 + /// not stored in the heap.
16.136 + ///
16.137 + /// This method sets the priority of the given item if it is
16.138 + /// already stored in the heap. Otherwise it inserts the given
16.139 + /// item into the heap with the given priority.
16.140 + /// \param item The item.
16.141 + /// \param value The priority.
16.142 + void set (const Item& item, const Prio& value) {
16.143 + int i=_iim[item];
16.144 + if ( i >= 0 && _data[i].in ) {
16.145 + if ( _comp(value, _data[i].prio) ) decrease(item, value);
16.146 + if ( _comp(_data[i].prio, value) ) increase(item, value);
16.147 + } else push(item, value);
16.148 + }
16.149 +
16.150 + /// \brief Insert an item into the heap with the given priority.
16.151 + ///
16.152 + /// This function inserts the given item into the heap with the
16.153 + /// given priority.
16.154 + /// \param item The item to insert.
16.155 + /// \param value The priority of the item.
16.156 + /// \pre \e item must not be stored in the heap.
16.157 + void push (const Item& item, const Prio& value) {
16.158 + int i=_iim[item];
16.159 + if ( i<0 ) {
16.160 + int s=_data.size();
16.161 + _iim.set( item,s );
16.162 + Store st;
16.163 + st.name=item;
16.164 + st.prio=value;
16.165 + _data.push_back(st);
16.166 + i=s;
16.167 + }
16.168 + else {
16.169 + _data[i].parent=_data[i].right_neighbor=_data[i].child=-1;
16.170 + _data[i].degree=0;
16.171 + _data[i].in=true;
16.172 + _data[i].prio=value;
16.173 + }
16.174 +
16.175 + if( 0==_num_items ) {
16.176 + _head=i;
16.177 + _min=i;
16.178 + } else {
16.179 + merge(i);
16.180 + if( _comp(_data[i].prio, _data[_min].prio) ) _min=i;
16.181 + }
16.182 + ++_num_items;
16.183 + }
16.184 +
16.185 + /// \brief Return the item having minimum priority.
16.186 + ///
16.187 + /// This function returns the item having minimum priority.
16.188 + /// \pre The heap must be non-empty.
16.189 + Item top() const { return _data[_min].name; }
16.190 +
16.191 + /// \brief The minimum priority.
16.192 + ///
16.193 + /// This function returns the minimum priority.
16.194 + /// \pre The heap must be non-empty.
16.195 + Prio prio() const { return _data[_min].prio; }
16.196 +
16.197 + /// \brief The priority of the given item.
16.198 + ///
16.199 + /// This function returns the priority of the given item.
16.200 + /// \param item The item.
16.201 + /// \pre \e item must be in the heap.
16.202 + const Prio& operator[](const Item& item) const {
16.203 + return _data[_iim[item]].prio;
16.204 + }
16.205 +
16.206 + /// \brief Remove the item having minimum priority.
16.207 + ///
16.208 + /// This function removes the item having minimum priority.
16.209 + /// \pre The heap must be non-empty.
16.210 + void pop() {
16.211 + _data[_min].in=false;
16.212 +
16.213 + int head_child=-1;
16.214 + if ( _data[_min].child!=-1 ) {
16.215 + int child=_data[_min].child;
16.216 + int neighb;
16.217 + while( child!=-1 ) {
16.218 + neighb=_data[child].right_neighbor;
16.219 + _data[child].parent=-1;
16.220 + _data[child].right_neighbor=head_child;
16.221 + head_child=child;
16.222 + child=neighb;
16.223 + }
16.224 + }
16.225 +
16.226 + if ( _data[_head].right_neighbor==-1 ) {
16.227 + // there was only one root
16.228 + _head=head_child;
16.229 + }
16.230 + else {
16.231 + // there were more roots
16.232 + if( _head!=_min ) { unlace(_min); }
16.233 + else { _head=_data[_head].right_neighbor; }
16.234 + merge(head_child);
16.235 + }
16.236 + _min=findMin();
16.237 + --_num_items;
16.238 + }
16.239 +
16.240 + /// \brief Remove the given item from the heap.
16.241 + ///
16.242 + /// This function removes the given item from the heap if it is
16.243 + /// already stored.
16.244 + /// \param item The item to delete.
16.245 + /// \pre \e item must be in the heap.
16.246 + void erase (const Item& item) {
16.247 + int i=_iim[item];
16.248 + if ( i >= 0 && _data[i].in ) {
16.249 + decrease( item, _data[_min].prio-1 );
16.250 + pop();
16.251 + }
16.252 + }
16.253 +
16.254 + /// \brief Decrease the priority of an item to the given value.
16.255 + ///
16.256 + /// This function decreases the priority of an item to the given value.
16.257 + /// \param item The item.
16.258 + /// \param value The priority.
16.259 + /// \pre \e item must be stored in the heap with priority at least \e value.
16.260 + void decrease (Item item, const Prio& value) {
16.261 + int i=_iim[item];
16.262 + int p=_data[i].parent;
16.263 + _data[i].prio=value;
16.264 +
16.265 + while( p!=-1 && _comp(value, _data[p].prio) ) {
16.266 + _data[i].name=_data[p].name;
16.267 + _data[i].prio=_data[p].prio;
16.268 + _data[p].name=item;
16.269 + _data[p].prio=value;
16.270 + _iim[_data[i].name]=i;
16.271 + i=p;
16.272 + p=_data[p].parent;
16.273 + }
16.274 + _iim[item]=i;
16.275 + if ( _comp(value, _data[_min].prio) ) _min=i;
16.276 + }
16.277 +
16.278 + /// \brief Increase the priority of an item to the given value.
16.279 + ///
16.280 + /// This function increases the priority of an item to the given value.
16.281 + /// \param item The item.
16.282 + /// \param value The priority.
16.283 + /// \pre \e item must be stored in the heap with priority at most \e value.
16.284 + void increase (Item item, const Prio& value) {
16.285 + erase(item);
16.286 + push(item, value);
16.287 + }
16.288 +
16.289 + /// \brief Return the state of an item.
16.290 + ///
16.291 + /// This method returns \c PRE_HEAP if the given item has never
16.292 + /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
16.293 + /// and \c POST_HEAP otherwise.
16.294 + /// In the latter case it is possible that the item will get back
16.295 + /// to the heap again.
16.296 + /// \param item The item.
16.297 + State state(const Item &item) const {
16.298 + int i=_iim[item];
16.299 + if( i>=0 ) {
16.300 + if ( _data[i].in ) i=0;
16.301 + else i=-2;
16.302 + }
16.303 + return State(i);
16.304 + }
16.305 +
16.306 + /// \brief Set the state of an item in the heap.
16.307 + ///
16.308 + /// This function sets the state of the given item in the heap.
16.309 + /// It can be used to manually clear the heap when it is important
16.310 + /// to achive better time complexity.
16.311 + /// \param i The item.
16.312 + /// \param st The state. It should not be \c IN_HEAP.
16.313 + void state(const Item& i, State st) {
16.314 + switch (st) {
16.315 + case POST_HEAP:
16.316 + case PRE_HEAP:
16.317 + if (state(i) == IN_HEAP) {
16.318 + erase(i);
16.319 + }
16.320 + _iim[i] = st;
16.321 + break;
16.322 + case IN_HEAP:
16.323 + break;
16.324 + }
16.325 + }
16.326 +
16.327 + private:
16.328 +
16.329 + // Find the minimum of the roots
16.330 + int findMin() {
16.331 + if( _head!=-1 ) {
16.332 + int min_loc=_head, min_val=_data[_head].prio;
16.333 + for( int x=_data[_head].right_neighbor; x!=-1;
16.334 + x=_data[x].right_neighbor ) {
16.335 + if( _comp( _data[x].prio,min_val ) ) {
16.336 + min_val=_data[x].prio;
16.337 + min_loc=x;
16.338 + }
16.339 + }
16.340 + return min_loc;
16.341 + }
16.342 + else return -1;
16.343 + }
16.344 +
16.345 + // Merge the heap with another heap starting at the given position
16.346 + void merge(int a) {
16.347 + if( _head==-1 || a==-1 ) return;
16.348 + if( _data[a].right_neighbor==-1 &&
16.349 + _data[a].degree<=_data[_head].degree ) {
16.350 + _data[a].right_neighbor=_head;
16.351 + _head=a;
16.352 + } else {
16.353 + interleave(a);
16.354 + }
16.355 + if( _data[_head].right_neighbor==-1 ) return;
16.356 +
16.357 + int x=_head;
16.358 + int x_prev=-1, x_next=_data[x].right_neighbor;
16.359 + while( x_next!=-1 ) {
16.360 + if( _data[x].degree!=_data[x_next].degree ||
16.361 + ( _data[x_next].right_neighbor!=-1 &&
16.362 + _data[_data[x_next].right_neighbor].degree==_data[x].degree ) ) {
16.363 + x_prev=x;
16.364 + x=x_next;
16.365 + }
16.366 + else {
16.367 + if( _comp(_data[x_next].prio,_data[x].prio) ) {
16.368 + if( x_prev==-1 ) {
16.369 + _head=x_next;
16.370 + } else {
16.371 + _data[x_prev].right_neighbor=x_next;
16.372 + }
16.373 + fuse(x,x_next);
16.374 + x=x_next;
16.375 + }
16.376 + else {
16.377 + _data[x].right_neighbor=_data[x_next].right_neighbor;
16.378 + fuse(x_next,x);
16.379 + }
16.380 + }
16.381 + x_next=_data[x].right_neighbor;
16.382 + }
16.383 + }
16.384 +
16.385 + // Interleave the elements of the given list into the list of the roots
16.386 + void interleave(int a) {
16.387 + int p=_head, q=a;
16.388 + int curr=_data.size();
16.389 + _data.push_back(Store());
16.390 +
16.391 + while( p!=-1 || q!=-1 ) {
16.392 + if( q==-1 || ( p!=-1 && _data[p].degree<_data[q].degree ) ) {
16.393 + _data[curr].right_neighbor=p;
16.394 + curr=p;
16.395 + p=_data[p].right_neighbor;
16.396 + }
16.397 + else {
16.398 + _data[curr].right_neighbor=q;
16.399 + curr=q;
16.400 + q=_data[q].right_neighbor;
16.401 + }
16.402 + }
16.403 +
16.404 + _head=_data.back().right_neighbor;
16.405 + _data.pop_back();
16.406 + }
16.407 +
16.408 + // Lace node a under node b
16.409 + void fuse(int a, int b) {
16.410 + _data[a].parent=b;
16.411 + _data[a].right_neighbor=_data[b].child;
16.412 + _data[b].child=a;
16.413 +
16.414 + ++_data[b].degree;
16.415 + }
16.416 +
16.417 + // Unlace node a (if it has siblings)
16.418 + void unlace(int a) {
16.419 + int neighb=_data[a].right_neighbor;
16.420 + int other=_head;
16.421 +
16.422 + while( _data[other].right_neighbor!=a )
16.423 + other=_data[other].right_neighbor;
16.424 + _data[other].right_neighbor=neighb;
16.425 + }
16.426 +
16.427 + private:
16.428 +
16.429 + class Store {
16.430 + friend class BinomHeap;
16.431 +
16.432 + Item name;
16.433 + int parent;
16.434 + int right_neighbor;
16.435 + int child;
16.436 + int degree;
16.437 + bool in;
16.438 + Prio prio;
16.439 +
16.440 + Store() : parent(-1), right_neighbor(-1), child(-1), degree(0),
16.441 + in(true) {}
16.442 + };
16.443 + };
16.444 +
16.445 +} //namespace lemon
16.446 +
16.447 +#endif //LEMON_BINOM_HEAP_H
16.448 +
17.1 --- a/lemon/bits/edge_set_extender.h Thu Dec 10 17:05:35 2009 +0100
17.2 +++ b/lemon/bits/edge_set_extender.h Thu Dec 10 17:18:25 2009 +0100
17.3 @@ -537,7 +537,7 @@
17.4 typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent;
17.5
17.6 public:
17.7 - ArcMap(const Graph& _g)
17.8 + explicit ArcMap(const Graph& _g)
17.9 : Parent(_g) {}
17.10 ArcMap(const Graph& _g, const _Value& _v)
17.11 : Parent(_g, _v) {}
17.12 @@ -561,7 +561,7 @@
17.13 typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
17.14
17.15 public:
17.16 - EdgeMap(const Graph& _g)
17.17 + explicit EdgeMap(const Graph& _g)
17.18 : Parent(_g) {}
17.19
17.20 EdgeMap(const Graph& _g, const _Value& _v)
18.1 --- a/lemon/bits/graph_extender.h Thu Dec 10 17:05:35 2009 +0100
18.2 +++ b/lemon/bits/graph_extender.h Thu Dec 10 17:18:25 2009 +0100
18.3 @@ -56,11 +56,11 @@
18.4 return Parent::maxArcId();
18.5 }
18.6
18.7 - Node fromId(int id, Node) const {
18.8 + static Node fromId(int id, Node) {
18.9 return Parent::nodeFromId(id);
18.10 }
18.11
18.12 - Arc fromId(int id, Arc) const {
18.13 + static Arc fromId(int id, Arc) {
18.14 return Parent::arcFromId(id);
18.15 }
18.16
18.17 @@ -355,15 +355,15 @@
18.18 return Parent::maxEdgeId();
18.19 }
18.20
18.21 - Node fromId(int id, Node) const {
18.22 + static Node fromId(int id, Node) {
18.23 return Parent::nodeFromId(id);
18.24 }
18.25
18.26 - Arc fromId(int id, Arc) const {
18.27 + static Arc fromId(int id, Arc) {
18.28 return Parent::arcFromId(id);
18.29 }
18.30
18.31 - Edge fromId(int id, Edge) const {
18.32 + static Edge fromId(int id, Edge) {
18.33 return Parent::edgeFromId(id);
18.34 }
18.35
18.36 @@ -604,7 +604,7 @@
18.37 typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
18.38
18.39 public:
18.40 - NodeMap(const Graph& graph)
18.41 + explicit NodeMap(const Graph& graph)
18.42 : Parent(graph) {}
18.43 NodeMap(const Graph& graph, const _Value& value)
18.44 : Parent(graph, value) {}
18.45 @@ -628,7 +628,7 @@
18.46 typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent;
18.47
18.48 public:
18.49 - ArcMap(const Graph& graph)
18.50 + explicit ArcMap(const Graph& graph)
18.51 : Parent(graph) {}
18.52 ArcMap(const Graph& graph, const _Value& value)
18.53 : Parent(graph, value) {}
18.54 @@ -652,7 +652,7 @@
18.55 typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
18.56
18.57 public:
18.58 - EdgeMap(const Graph& graph)
18.59 + explicit EdgeMap(const Graph& graph)
18.60 : Parent(graph) {}
18.61
18.62 EdgeMap(const Graph& graph, const _Value& value)
19.1 --- a/lemon/bucket_heap.h Thu Dec 10 17:05:35 2009 +0100
19.2 +++ b/lemon/bucket_heap.h Thu Dec 10 17:18:25 2009 +0100
19.3 @@ -19,9 +19,9 @@
19.4 #ifndef LEMON_BUCKET_HEAP_H
19.5 #define LEMON_BUCKET_HEAP_H
19.6
19.7 -///\ingroup auxdat
19.8 +///\ingroup heaps
19.9 ///\file
19.10 -///\brief Bucket Heap implementation.
19.11 +///\brief Bucket heap implementation.
19.12
19.13 #include <vector>
19.14 #include <utility>
19.15 @@ -53,35 +53,41 @@
19.16
19.17 }
19.18
19.19 - /// \ingroup auxdat
19.20 + /// \ingroup heaps
19.21 ///
19.22 - /// \brief A Bucket Heap implementation.
19.23 + /// \brief Bucket heap data structure.
19.24 ///
19.25 - /// This class implements the \e bucket \e heap data structure. A \e heap
19.26 - /// is a data structure for storing items with specified values called \e
19.27 - /// priorities in such a way that finding the item with minimum priority is
19.28 - /// efficient. The bucket heap is very simple implementation, it can store
19.29 - /// only integer priorities and it stores for each priority in the
19.30 - /// \f$ [0..C) \f$ range a list of items. So it should be used only when
19.31 - /// the priorities are small. It is not intended to use as dijkstra heap.
19.32 + /// This class implements the \e bucket \e heap data structure.
19.33 + /// It practically conforms to the \ref concepts::Heap "heap concept",
19.34 + /// but it has some limitations.
19.35 ///
19.36 - /// \param IM A read and write Item int map, used internally
19.37 - /// to handle the cross references.
19.38 - /// \param MIN If the given parameter is false then instead of the
19.39 - /// minimum value the maximum can be retrivied with the top() and
19.40 - /// prio() member functions.
19.41 + /// The bucket heap is a very simple structure. It can store only
19.42 + /// \c int priorities and it maintains a list of items for each priority
19.43 + /// in the range <tt>[0..C)</tt>. So it should only be used when the
19.44 + /// priorities are small. It is not intended to use as a Dijkstra heap.
19.45 + ///
19.46 + /// \tparam IM A read-writable item map with \c int values, used
19.47 + /// internally to handle the cross references.
19.48 + /// \tparam MIN Indicate if the heap is a \e min-heap or a \e max-heap.
19.49 + /// The default is \e min-heap. If this parameter is set to \c false,
19.50 + /// then the comparison is reversed, so the top(), prio() and pop()
19.51 + /// functions deal with the item having maximum priority instead of the
19.52 + /// minimum.
19.53 + ///
19.54 + /// \sa SimpleBucketHeap
19.55 template <typename IM, bool MIN = true>
19.56 class BucketHeap {
19.57
19.58 public:
19.59 - /// \e
19.60 - typedef typename IM::Key Item;
19.61 - /// \e
19.62 +
19.63 + /// Type of the item-int map.
19.64 + typedef IM ItemIntMap;
19.65 + /// Type of the priorities.
19.66 typedef int Prio;
19.67 - /// \e
19.68 - typedef std::pair<Item, Prio> Pair;
19.69 - /// \e
19.70 - typedef IM ItemIntMap;
19.71 + /// Type of the items stored in the heap.
19.72 + typedef typename ItemIntMap::Key Item;
19.73 + /// Type of the item-priority pairs.
19.74 + typedef std::pair<Item,Prio> Pair;
19.75
19.76 private:
19.77
19.78 @@ -89,10 +95,10 @@
19.79
19.80 public:
19.81
19.82 - /// \brief Type to represent the items states.
19.83 + /// \brief Type to represent the states of the items.
19.84 ///
19.85 - /// Each Item element have a state associated to it. It may be "in heap",
19.86 - /// "pre heap" or "post heap". The latter two are indifferent from the
19.87 + /// Each item has a state associated to it. It can be "in heap",
19.88 + /// "pre-heap" or "post-heap". The latter two are indifferent from the
19.89 /// heap's point of view, but may be useful to the user.
19.90 ///
19.91 /// The item-int map must be initialized in such way that it assigns
19.92 @@ -104,37 +110,39 @@
19.93 };
19.94
19.95 public:
19.96 - /// \brief The constructor.
19.97 +
19.98 + /// \brief Constructor.
19.99 ///
19.100 - /// The constructor.
19.101 - /// \param map should be given to the constructor, since it is used
19.102 - /// internally to handle the cross references. The value of the map
19.103 - /// should be PRE_HEAP (-1) for each element.
19.104 + /// Constructor.
19.105 + /// \param map A map that assigns \c int values to the items.
19.106 + /// It is used internally to handle the cross references.
19.107 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
19.108 explicit BucketHeap(ItemIntMap &map) : _iim(map), _minimum(0) {}
19.109
19.110 - /// The number of items stored in the heap.
19.111 + /// \brief The number of items stored in the heap.
19.112 ///
19.113 - /// \brief Returns the number of items stored in the heap.
19.114 + /// This function returns the number of items stored in the heap.
19.115 int size() const { return _data.size(); }
19.116
19.117 - /// \brief Checks if the heap stores no items.
19.118 + /// \brief Check if the heap is empty.
19.119 ///
19.120 - /// Returns \c true if and only if the heap stores no items.
19.121 + /// This function returns \c true if the heap is empty.
19.122 bool empty() const { return _data.empty(); }
19.123
19.124 - /// \brief Make empty this heap.
19.125 + /// \brief Make the heap empty.
19.126 ///
19.127 - /// Make empty this heap. It does not change the cross reference
19.128 - /// map. If you want to reuse a heap what is not surely empty you
19.129 - /// should first clear the heap and after that you should set the
19.130 - /// cross reference map for each item to \c PRE_HEAP.
19.131 + /// This functon makes the heap empty.
19.132 + /// It does not change the cross reference map. If you want to reuse
19.133 + /// a heap that is not surely empty, you should first clear it and
19.134 + /// then you should set the cross reference map to \c PRE_HEAP
19.135 + /// for each item.
19.136 void clear() {
19.137 _data.clear(); _first.clear(); _minimum = 0;
19.138 }
19.139
19.140 private:
19.141
19.142 - void relocate_last(int idx) {
19.143 + void relocateLast(int idx) {
19.144 if (idx + 1 < int(_data.size())) {
19.145 _data[idx] = _data.back();
19.146 if (_data[idx].prev != -1) {
19.147 @@ -174,19 +182,24 @@
19.148 }
19.149
19.150 public:
19.151 +
19.152 /// \brief Insert a pair of item and priority into the heap.
19.153 ///
19.154 - /// Adds \c p.first to the heap with priority \c p.second.
19.155 + /// This function inserts \c p.first to the heap with priority
19.156 + /// \c p.second.
19.157 /// \param p The pair to insert.
19.158 + /// \pre \c p.first must not be stored in the heap.
19.159 void push(const Pair& p) {
19.160 push(p.first, p.second);
19.161 }
19.162
19.163 /// \brief Insert an item into the heap with the given priority.
19.164 ///
19.165 - /// Adds \c i to the heap with priority \c p.
19.166 + /// This function inserts the given item into the heap with the
19.167 + /// given priority.
19.168 /// \param i The item to insert.
19.169 /// \param p The priority of the item.
19.170 + /// \pre \e i must not be stored in the heap.
19.171 void push(const Item &i, const Prio &p) {
19.172 int idx = _data.size();
19.173 _iim[i] = idx;
19.174 @@ -197,10 +210,10 @@
19.175 }
19.176 }
19.177
19.178 - /// \brief Returns the item with minimum priority.
19.179 + /// \brief Return the item having minimum priority.
19.180 ///
19.181 - /// This method returns the item with minimum priority.
19.182 - /// \pre The heap must be nonempty.
19.183 + /// This function returns the item having minimum priority.
19.184 + /// \pre The heap must be non-empty.
19.185 Item top() const {
19.186 while (_first[_minimum] == -1) {
19.187 Direction::increase(_minimum);
19.188 @@ -208,10 +221,10 @@
19.189 return _data[_first[_minimum]].item;
19.190 }
19.191
19.192 - /// \brief Returns the minimum priority.
19.193 + /// \brief The minimum priority.
19.194 ///
19.195 - /// It returns the minimum priority.
19.196 - /// \pre The heap must be nonempty.
19.197 + /// This function returns the minimum priority.
19.198 + /// \pre The heap must be non-empty.
19.199 Prio prio() const {
19.200 while (_first[_minimum] == -1) {
19.201 Direction::increase(_minimum);
19.202 @@ -219,9 +232,9 @@
19.203 return _minimum;
19.204 }
19.205
19.206 - /// \brief Deletes the item with minimum priority.
19.207 + /// \brief Remove the item having minimum priority.
19.208 ///
19.209 - /// This method deletes the item with minimum priority from the heap.
19.210 + /// This function removes the item having minimum priority.
19.211 /// \pre The heap must be non-empty.
19.212 void pop() {
19.213 while (_first[_minimum] == -1) {
19.214 @@ -230,37 +243,38 @@
19.215 int idx = _first[_minimum];
19.216 _iim[_data[idx].item] = -2;
19.217 unlace(idx);
19.218 - relocate_last(idx);
19.219 + relocateLast(idx);
19.220 }
19.221
19.222 - /// \brief Deletes \c i from the heap.
19.223 + /// \brief Remove the given item from the heap.
19.224 ///
19.225 - /// This method deletes item \c i from the heap, if \c i was
19.226 - /// already stored in the heap.
19.227 - /// \param i The item to erase.
19.228 + /// This function removes the given item from the heap if it is
19.229 + /// already stored.
19.230 + /// \param i The item to delete.
19.231 + /// \pre \e i must be in the heap.
19.232 void erase(const Item &i) {
19.233 int idx = _iim[i];
19.234 _iim[_data[idx].item] = -2;
19.235 unlace(idx);
19.236 - relocate_last(idx);
19.237 + relocateLast(idx);
19.238 }
19.239
19.240 -
19.241 - /// \brief Returns the priority of \c i.
19.242 + /// \brief The priority of the given item.
19.243 ///
19.244 - /// This function returns the priority of item \c i.
19.245 - /// \pre \c i must be in the heap.
19.246 + /// This function returns the priority of the given item.
19.247 /// \param i The item.
19.248 + /// \pre \e i must be in the heap.
19.249 Prio operator[](const Item &i) const {
19.250 int idx = _iim[i];
19.251 return _data[idx].value;
19.252 }
19.253
19.254 - /// \brief \c i gets to the heap with priority \c p independently
19.255 - /// if \c i was already there.
19.256 + /// \brief Set the priority of an item or insert it, if it is
19.257 + /// not stored in the heap.
19.258 ///
19.259 - /// This method calls \ref push(\c i, \c p) if \c i is not stored
19.260 - /// in the heap and sets the priority of \c i to \c p otherwise.
19.261 + /// This method sets the priority of the given item if it is
19.262 + /// already stored in the heap. Otherwise it inserts the given
19.263 + /// item into the heap with the given priority.
19.264 /// \param i The item.
19.265 /// \param p The priority.
19.266 void set(const Item &i, const Prio &p) {
19.267 @@ -274,13 +288,12 @@
19.268 }
19.269 }
19.270
19.271 - /// \brief Decreases the priority of \c i to \c p.
19.272 + /// \brief Decrease the priority of an item to the given value.
19.273 ///
19.274 - /// This method decreases the priority of item \c i to \c p.
19.275 - /// \pre \c i must be stored in the heap with priority at least \c
19.276 - /// p relative to \c Compare.
19.277 + /// This function decreases the priority of an item to the given value.
19.278 /// \param i The item.
19.279 /// \param p The priority.
19.280 + /// \pre \e i must be stored in the heap with priority at least \e p.
19.281 void decrease(const Item &i, const Prio &p) {
19.282 int idx = _iim[i];
19.283 unlace(idx);
19.284 @@ -291,13 +304,12 @@
19.285 lace(idx);
19.286 }
19.287
19.288 - /// \brief Increases the priority of \c i to \c p.
19.289 + /// \brief Increase the priority of an item to the given value.
19.290 ///
19.291 - /// This method sets the priority of item \c i to \c p.
19.292 - /// \pre \c i must be stored in the heap with priority at most \c
19.293 - /// p relative to \c Compare.
19.294 + /// This function increases the priority of an item to the given value.
19.295 /// \param i The item.
19.296 /// \param p The priority.
19.297 + /// \pre \e i must be stored in the heap with priority at most \e p.
19.298 void increase(const Item &i, const Prio &p) {
19.299 int idx = _iim[i];
19.300 unlace(idx);
19.301 @@ -305,13 +317,13 @@
19.302 lace(idx);
19.303 }
19.304
19.305 - /// \brief Returns if \c item is in, has already been in, or has
19.306 - /// never been in the heap.
19.307 + /// \brief Return the state of an item.
19.308 ///
19.309 - /// This method returns PRE_HEAP if \c item has never been in the
19.310 - /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
19.311 - /// otherwise. In the latter case it is possible that \c item will
19.312 - /// get back to the heap again.
19.313 + /// This method returns \c PRE_HEAP if the given item has never
19.314 + /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
19.315 + /// and \c POST_HEAP otherwise.
19.316 + /// In the latter case it is possible that the item will get back
19.317 + /// to the heap again.
19.318 /// \param i The item.
19.319 State state(const Item &i) const {
19.320 int idx = _iim[i];
19.321 @@ -319,11 +331,11 @@
19.322 return State(idx);
19.323 }
19.324
19.325 - /// \brief Sets the state of the \c item in the heap.
19.326 + /// \brief Set the state of an item in the heap.
19.327 ///
19.328 - /// Sets the state of the \c item in the heap. It can be used to
19.329 - /// manually clear the heap when it is important to achive the
19.330 - /// better time complexity.
19.331 + /// This function sets the state of the given item in the heap.
19.332 + /// It can be used to manually clear the heap when it is important
19.333 + /// to achive better time complexity.
19.334 /// \param i The item.
19.335 /// \param st The state. It should not be \c IN_HEAP.
19.336 void state(const Item& i, State st) {
19.337 @@ -359,33 +371,44 @@
19.338
19.339 }; // class BucketHeap
19.340
19.341 - /// \ingroup auxdat
19.342 + /// \ingroup heaps
19.343 ///
19.344 - /// \brief A Simplified Bucket Heap implementation.
19.345 + /// \brief Simplified bucket heap data structure.
19.346 ///
19.347 /// This class implements a simplified \e bucket \e heap data
19.348 - /// structure. It does not provide some functionality but it faster
19.349 - /// and simplier data structure than the BucketHeap. The main
19.350 - /// difference is that the BucketHeap stores for every key a double
19.351 - /// linked list while this class stores just simple lists. In the
19.352 - /// other way it does not support erasing each elements just the
19.353 - /// minimal and it does not supports key increasing, decreasing.
19.354 + /// structure. It does not provide some functionality, but it is
19.355 + /// faster and simpler than BucketHeap. The main difference is
19.356 + /// that BucketHeap stores a doubly-linked list for each key while
19.357 + /// this class stores only simply-linked lists. It supports erasing
19.358 + /// only for the item having minimum priority and it does not support
19.359 + /// key increasing and decreasing.
19.360 ///
19.361 - /// \param IM A read and write Item int map, used internally
19.362 - /// to handle the cross references.
19.363 - /// \param MIN If the given parameter is false then instead of the
19.364 - /// minimum value the maximum can be retrivied with the top() and
19.365 - /// prio() member functions.
19.366 + /// Note that this implementation does not conform to the
19.367 + /// \ref concepts::Heap "heap concept" due to the lack of some
19.368 + /// functionality.
19.369 + ///
19.370 + /// \tparam IM A read-writable item map with \c int values, used
19.371 + /// internally to handle the cross references.
19.372 + /// \tparam MIN Indicate if the heap is a \e min-heap or a \e max-heap.
19.373 + /// The default is \e min-heap. If this parameter is set to \c false,
19.374 + /// then the comparison is reversed, so the top(), prio() and pop()
19.375 + /// functions deal with the item having maximum priority instead of the
19.376 + /// minimum.
19.377 ///
19.378 /// \sa BucketHeap
19.379 template <typename IM, bool MIN = true >
19.380 class SimpleBucketHeap {
19.381
19.382 public:
19.383 - typedef typename IM::Key Item;
19.384 +
19.385 + /// Type of the item-int map.
19.386 + typedef IM ItemIntMap;
19.387 + /// Type of the priorities.
19.388 typedef int Prio;
19.389 - typedef std::pair<Item, Prio> Pair;
19.390 - typedef IM ItemIntMap;
19.391 + /// Type of the items stored in the heap.
19.392 + typedef typename ItemIntMap::Key Item;
19.393 + /// Type of the item-priority pairs.
19.394 + typedef std::pair<Item,Prio> Pair;
19.395
19.396 private:
19.397
19.398 @@ -393,10 +416,10 @@
19.399
19.400 public:
19.401
19.402 - /// \brief Type to represent the items states.
19.403 + /// \brief Type to represent the states of the items.
19.404 ///
19.405 - /// Each Item element have a state associated to it. It may be "in heap",
19.406 - /// "pre heap" or "post heap". The latter two are indifferent from the
19.407 + /// Each item has a state associated to it. It can be "in heap",
19.408 + /// "pre-heap" or "post-heap". The latter two are indifferent from the
19.409 /// heap's point of view, but may be useful to the user.
19.410 ///
19.411 /// The item-int map must be initialized in such way that it assigns
19.412 @@ -409,48 +432,53 @@
19.413
19.414 public:
19.415
19.416 - /// \brief The constructor.
19.417 + /// \brief Constructor.
19.418 ///
19.419 - /// The constructor.
19.420 - /// \param map should be given to the constructor, since it is used
19.421 - /// internally to handle the cross references. The value of the map
19.422 - /// should be PRE_HEAP (-1) for each element.
19.423 + /// Constructor.
19.424 + /// \param map A map that assigns \c int values to the items.
19.425 + /// It is used internally to handle the cross references.
19.426 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
19.427 explicit SimpleBucketHeap(ItemIntMap &map)
19.428 : _iim(map), _free(-1), _num(0), _minimum(0) {}
19.429
19.430 - /// \brief Returns the number of items stored in the heap.
19.431 + /// \brief The number of items stored in the heap.
19.432 ///
19.433 - /// The number of items stored in the heap.
19.434 + /// This function returns the number of items stored in the heap.
19.435 int size() const { return _num; }
19.436
19.437 - /// \brief Checks if the heap stores no items.
19.438 + /// \brief Check if the heap is empty.
19.439 ///
19.440 - /// Returns \c true if and only if the heap stores no items.
19.441 + /// This function returns \c true if the heap is empty.
19.442 bool empty() const { return _num == 0; }
19.443
19.444 - /// \brief Make empty this heap.
19.445 + /// \brief Make the heap empty.
19.446 ///
19.447 - /// Make empty this heap. It does not change the cross reference
19.448 - /// map. If you want to reuse a heap what is not surely empty you
19.449 - /// should first clear the heap and after that you should set the
19.450 - /// cross reference map for each item to \c PRE_HEAP.
19.451 + /// This functon makes the heap empty.
19.452 + /// It does not change the cross reference map. If you want to reuse
19.453 + /// a heap that is not surely empty, you should first clear it and
19.454 + /// then you should set the cross reference map to \c PRE_HEAP
19.455 + /// for each item.
19.456 void clear() {
19.457 _data.clear(); _first.clear(); _free = -1; _num = 0; _minimum = 0;
19.458 }
19.459
19.460 /// \brief Insert a pair of item and priority into the heap.
19.461 ///
19.462 - /// Adds \c p.first to the heap with priority \c p.second.
19.463 + /// This function inserts \c p.first to the heap with priority
19.464 + /// \c p.second.
19.465 /// \param p The pair to insert.
19.466 + /// \pre \c p.first must not be stored in the heap.
19.467 void push(const Pair& p) {
19.468 push(p.first, p.second);
19.469 }
19.470
19.471 /// \brief Insert an item into the heap with the given priority.
19.472 ///
19.473 - /// Adds \c i to the heap with priority \c p.
19.474 + /// This function inserts the given item into the heap with the
19.475 + /// given priority.
19.476 /// \param i The item to insert.
19.477 /// \param p The priority of the item.
19.478 + /// \pre \e i must not be stored in the heap.
19.479 void push(const Item &i, const Prio &p) {
19.480 int idx;
19.481 if (_free == -1) {
19.482 @@ -471,10 +499,10 @@
19.483 ++_num;
19.484 }
19.485
19.486 - /// \brief Returns the item with minimum priority.
19.487 + /// \brief Return the item having minimum priority.
19.488 ///
19.489 - /// This method returns the item with minimum priority.
19.490 - /// \pre The heap must be nonempty.
19.491 + /// This function returns the item having minimum priority.
19.492 + /// \pre The heap must be non-empty.
19.493 Item top() const {
19.494 while (_first[_minimum] == -1) {
19.495 Direction::increase(_minimum);
19.496 @@ -482,10 +510,10 @@
19.497 return _data[_first[_minimum]].item;
19.498 }
19.499
19.500 - /// \brief Returns the minimum priority.
19.501 + /// \brief The minimum priority.
19.502 ///
19.503 - /// It returns the minimum priority.
19.504 - /// \pre The heap must be nonempty.
19.505 + /// This function returns the minimum priority.
19.506 + /// \pre The heap must be non-empty.
19.507 Prio prio() const {
19.508 while (_first[_minimum] == -1) {
19.509 Direction::increase(_minimum);
19.510 @@ -493,9 +521,9 @@
19.511 return _minimum;
19.512 }
19.513
19.514 - /// \brief Deletes the item with minimum priority.
19.515 + /// \brief Remove the item having minimum priority.
19.516 ///
19.517 - /// This method deletes the item with minimum priority from the heap.
19.518 + /// This function removes the item having minimum priority.
19.519 /// \pre The heap must be non-empty.
19.520 void pop() {
19.521 while (_first[_minimum] == -1) {
19.522 @@ -509,16 +537,15 @@
19.523 --_num;
19.524 }
19.525
19.526 - /// \brief Returns the priority of \c i.
19.527 + /// \brief The priority of the given item.
19.528 ///
19.529 - /// This function returns the priority of item \c i.
19.530 - /// \warning This operator is not a constant time function
19.531 - /// because it scans the whole data structure to find the proper
19.532 - /// value.
19.533 - /// \pre \c i must be in the heap.
19.534 + /// This function returns the priority of the given item.
19.535 /// \param i The item.
19.536 + /// \pre \e i must be in the heap.
19.537 + /// \warning This operator is not a constant time function because
19.538 + /// it scans the whole data structure to find the proper value.
19.539 Prio operator[](const Item &i) const {
19.540 - for (int k = 0; k < _first.size(); ++k) {
19.541 + for (int k = 0; k < int(_first.size()); ++k) {
19.542 int idx = _first[k];
19.543 while (idx != -1) {
19.544 if (_data[idx].item == i) {
19.545 @@ -530,13 +557,13 @@
19.546 return -1;
19.547 }
19.548
19.549 - /// \brief Returns if \c item is in, has already been in, or has
19.550 - /// never been in the heap.
19.551 + /// \brief Return the state of an item.
19.552 ///
19.553 - /// This method returns PRE_HEAP if \c item has never been in the
19.554 - /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
19.555 - /// otherwise. In the latter case it is possible that \c item will
19.556 - /// get back to the heap again.
19.557 + /// This method returns \c PRE_HEAP if the given item has never
19.558 + /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
19.559 + /// and \c POST_HEAP otherwise.
19.560 + /// In the latter case it is possible that the item will get back
19.561 + /// to the heap again.
19.562 /// \param i The item.
19.563 State state(const Item &i) const {
19.564 int idx = _iim[i];
20.1 --- a/lemon/cbc.cc Thu Dec 10 17:05:35 2009 +0100
20.2 +++ b/lemon/cbc.cc Thu Dec 10 17:18:25 2009 +0100
20.3 @@ -94,6 +94,18 @@
20.4 return _prob->numberRows() - 1;
20.5 }
20.6
20.7 + int CbcMip::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
20.8 + std::vector<int> indexes;
20.9 + std::vector<Value> values;
20.10 +
20.11 + for(ExprIterator it = b; it != e; ++it) {
20.12 + indexes.push_back(it->first);
20.13 + values.push_back(it->second);
20.14 + }
20.15 +
20.16 + _prob->addRow(values.size(), &indexes.front(), &values.front(), l, u);
20.17 + return _prob->numberRows() - 1;
20.18 + }
20.19
20.20 void CbcMip::_eraseCol(int i) {
20.21 _prob->deleteColumn(i);
21.1 --- a/lemon/cbc.h Thu Dec 10 17:05:35 2009 +0100
21.2 +++ b/lemon/cbc.h Thu Dec 10 17:18:25 2009 +0100
21.3 @@ -62,6 +62,7 @@
21.4
21.5 virtual int _addCol();
21.6 virtual int _addRow();
21.7 + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
21.8
21.9 virtual void _eraseCol(int i);
21.10 virtual void _eraseRow(int i);
22.1 --- a/lemon/circulation.h Thu Dec 10 17:05:35 2009 +0100
22.2 +++ b/lemon/circulation.h Thu Dec 10 17:18:25 2009 +0100
22.3 @@ -72,7 +72,11 @@
22.4 /// The type of the map that stores the flow values.
22.5 /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap"
22.6 /// concept.
22.7 +#ifdef DOXYGEN
22.8 + typedef GR::ArcMap<Value> FlowMap;
22.9 +#else
22.10 typedef typename Digraph::template ArcMap<Value> FlowMap;
22.11 +#endif
22.12
22.13 /// \brief Instantiates a FlowMap.
22.14 ///
22.15 @@ -87,9 +91,12 @@
22.16 ///
22.17 /// The elevator type used by the algorithm.
22.18 ///
22.19 - /// \sa Elevator
22.20 - /// \sa LinkedElevator
22.21 + /// \sa Elevator, LinkedElevator
22.22 +#ifdef DOXYGEN
22.23 + typedef lemon::Elevator<GR, GR::Node> Elevator;
22.24 +#else
22.25 typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator;
22.26 +#endif
22.27
22.28 /// \brief Instantiates an Elevator.
22.29 ///
22.30 @@ -299,7 +306,7 @@
22.31 /// The Elevator should have standard constructor interface to be
22.32 /// able to automatically created by the algorithm (i.e. the
22.33 /// digraph and the maximum level should be passed to it).
22.34 - /// However an external elevator object could also be passed to the
22.35 + /// However, an external elevator object could also be passed to the
22.36 /// algorithm with the \ref elevator(Elevator&) "elevator()" function
22.37 /// before calling \ref run() or \ref init().
22.38 /// \sa SetElevator
22.39 @@ -450,25 +457,27 @@
22.40 return *_level;
22.41 }
22.42
22.43 - /// \brief Sets the tolerance used by algorithm.
22.44 + /// \brief Sets the tolerance used by the algorithm.
22.45 ///
22.46 - /// Sets the tolerance used by algorithm.
22.47 - Circulation& tolerance(const Tolerance& tolerance) const {
22.48 + /// Sets the tolerance object used by the algorithm.
22.49 + /// \return <tt>(*this)</tt>
22.50 + Circulation& tolerance(const Tolerance& tolerance) {
22.51 _tol = tolerance;
22.52 return *this;
22.53 }
22.54
22.55 /// \brief Returns a const reference to the tolerance.
22.56 ///
22.57 - /// Returns a const reference to the tolerance.
22.58 + /// Returns a const reference to the tolerance object used by
22.59 + /// the algorithm.
22.60 const Tolerance& tolerance() const {
22.61 - return tolerance;
22.62 + return _tol;
22.63 }
22.64
22.65 /// \name Execution Control
22.66 /// The simplest way to execute the algorithm is to call \ref run().\n
22.67 - /// If you need more control on the initial solution or the execution,
22.68 - /// first you have to call one of the \ref init() functions, then
22.69 + /// If you need better control on the initial solution or the execution,
22.70 + /// you have to call one of the \ref init() functions first, then
22.71 /// the \ref start() function.
22.72
22.73 ///@{
23.1 --- a/lemon/clp.cc Thu Dec 10 17:05:35 2009 +0100
23.2 +++ b/lemon/clp.cc Thu Dec 10 17:18:25 2009 +0100
23.3 @@ -78,6 +78,19 @@
23.4 return _prob->numberRows() - 1;
23.5 }
23.6
23.7 + int ClpLp::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
23.8 + std::vector<int> indexes;
23.9 + std::vector<Value> values;
23.10 +
23.11 + for(ExprIterator it = b; it != e; ++it) {
23.12 + indexes.push_back(it->first);
23.13 + values.push_back(it->second);
23.14 + }
23.15 +
23.16 + _prob->addRow(values.size(), &indexes.front(), &values.front(), l, u);
23.17 + return _prob->numberRows() - 1;
23.18 + }
23.19 +
23.20
23.21 void ClpLp::_eraseCol(int c) {
23.22 _col_names_ref.erase(_prob->getColumnName(c));
24.1 --- a/lemon/clp.h Thu Dec 10 17:05:35 2009 +0100
24.2 +++ b/lemon/clp.h Thu Dec 10 17:18:25 2009 +0100
24.3 @@ -75,6 +75,7 @@
24.4
24.5 virtual int _addCol();
24.6 virtual int _addRow();
24.7 + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
24.8
24.9 virtual void _eraseCol(int i);
24.10 virtual void _eraseRow(int i);
25.1 --- a/lemon/concepts/digraph.h Thu Dec 10 17:05:35 2009 +0100
25.2 +++ b/lemon/concepts/digraph.h Thu Dec 10 17:18:25 2009 +0100
25.3 @@ -35,46 +35,40 @@
25.4 ///
25.5 /// \brief Class describing the concept of directed graphs.
25.6 ///
25.7 - /// This class describes the \ref concept "concept" of the
25.8 - /// immutable directed digraphs.
25.9 + /// This class describes the common interface of all directed
25.10 + /// graphs (digraphs).
25.11 ///
25.12 - /// Note that actual digraph implementation like @ref ListDigraph or
25.13 - /// @ref SmartDigraph may have several additional functionality.
25.14 + /// Like all concept classes, it only provides an interface
25.15 + /// without any sensible implementation. So any general algorithm for
25.16 + /// directed graphs should compile with this class, but it will not
25.17 + /// run properly, of course.
25.18 + /// An actual digraph implementation like \ref ListDigraph or
25.19 + /// \ref SmartDigraph may have additional functionality.
25.20 ///
25.21 - /// \sa concept
25.22 + /// \sa Graph
25.23 class Digraph {
25.24 private:
25.25 - ///Digraphs are \e not copy constructible. Use DigraphCopy() instead.
25.26 + /// Diraphs are \e not copy constructible. Use DigraphCopy instead.
25.27 + Digraph(const Digraph &) {}
25.28 + /// \brief Assignment of a digraph to another one is \e not allowed.
25.29 + /// Use DigraphCopy instead.
25.30 + void operator=(const Digraph &) {}
25.31
25.32 - ///Digraphs are \e not copy constructible. Use DigraphCopy() instead.
25.33 - ///
25.34 - Digraph(const Digraph &) {};
25.35 - ///\brief Assignment of \ref Digraph "Digraph"s to another ones are
25.36 - ///\e not allowed. Use DigraphCopy() instead.
25.37 + public:
25.38 + /// Default constructor.
25.39 + Digraph() { }
25.40
25.41 - ///Assignment of \ref Digraph "Digraph"s to another ones are
25.42 - ///\e not allowed. Use DigraphCopy() instead.
25.43 -
25.44 - void operator=(const Digraph &) {}
25.45 - public:
25.46 - ///\e
25.47 -
25.48 - /// Defalult constructor.
25.49 -
25.50 - /// Defalult constructor.
25.51 - ///
25.52 - Digraph() { }
25.53 - /// Class for identifying a node of the digraph
25.54 + /// The node type of the digraph
25.55
25.56 /// This class identifies a node of the digraph. It also serves
25.57 /// as a base class of the node iterators,
25.58 - /// thus they will convert to this type.
25.59 + /// thus they convert to this type.
25.60 class Node {
25.61 public:
25.62 /// Default constructor
25.63
25.64 - /// @warning The default constructor sets the iterator
25.65 - /// to an undefined value.
25.66 + /// Default constructor.
25.67 + /// \warning It sets the object to an undefined value.
25.68 Node() { }
25.69 /// Copy constructor.
25.70
25.71 @@ -82,40 +76,39 @@
25.72 ///
25.73 Node(const Node&) { }
25.74
25.75 - /// Invalid constructor \& conversion.
25.76 + /// %Invalid constructor \& conversion.
25.77
25.78 - /// This constructor initializes the iterator to be invalid.
25.79 + /// Initializes the object to be invalid.
25.80 /// \sa Invalid for more details.
25.81 Node(Invalid) { }
25.82 /// Equality operator
25.83
25.84 + /// Equality operator.
25.85 + ///
25.86 /// Two iterators are equal if and only if they point to the
25.87 - /// same object or both are invalid.
25.88 + /// same object or both are \c INVALID.
25.89 bool operator==(Node) const { return true; }
25.90
25.91 /// Inequality operator
25.92
25.93 - /// \sa operator==(Node n)
25.94 - ///
25.95 + /// Inequality operator.
25.96 bool operator!=(Node) const { return true; }
25.97
25.98 /// Artificial ordering operator.
25.99
25.100 - /// To allow the use of digraph descriptors as key type in std::map or
25.101 - /// similar associative container we require this.
25.102 + /// Artificial ordering operator.
25.103 ///
25.104 - /// \note This operator only have to define some strict ordering of
25.105 - /// the items; this order has nothing to do with the iteration
25.106 - /// ordering of the items.
25.107 + /// \note This operator only has to define some strict ordering of
25.108 + /// the nodes; this order has nothing to do with the iteration
25.109 + /// ordering of the nodes.
25.110 bool operator<(Node) const { return false; }
25.111 -
25.112 };
25.113
25.114 - /// This iterator goes through each node.
25.115 + /// Iterator class for the nodes.
25.116
25.117 - /// This iterator goes through each node.
25.118 - /// Its usage is quite simple, for example you can count the number
25.119 - /// of nodes in digraph \c g of type \c Digraph like this:
25.120 + /// This iterator goes through each node of the digraph.
25.121 + /// Its usage is quite simple, for example, you can count the number
25.122 + /// of nodes in a digraph \c g of type \c %Digraph like this:
25.123 ///\code
25.124 /// int count=0;
25.125 /// for (Digraph::NodeIt n(g); n!=INVALID; ++n) ++count;
25.126 @@ -124,30 +117,28 @@
25.127 public:
25.128 /// Default constructor
25.129
25.130 - /// @warning The default constructor sets the iterator
25.131 - /// to an undefined value.
25.132 + /// Default constructor.
25.133 + /// \warning It sets the iterator to an undefined value.
25.134 NodeIt() { }
25.135 /// Copy constructor.
25.136
25.137 /// Copy constructor.
25.138 ///
25.139 NodeIt(const NodeIt& n) : Node(n) { }
25.140 - /// Invalid constructor \& conversion.
25.141 + /// %Invalid constructor \& conversion.
25.142
25.143 - /// Initialize the iterator to be invalid.
25.144 + /// Initializes the iterator to be invalid.
25.145 /// \sa Invalid for more details.
25.146 NodeIt(Invalid) { }
25.147 /// Sets the iterator to the first node.
25.148
25.149 - /// Sets the iterator to the first node of \c g.
25.150 + /// Sets the iterator to the first node of the given digraph.
25.151 ///
25.152 - NodeIt(const Digraph&) { }
25.153 - /// Node -> NodeIt conversion.
25.154 + explicit NodeIt(const Digraph&) { }
25.155 + /// Sets the iterator to the given node.
25.156
25.157 - /// Sets the iterator to the node of \c the digraph pointed by
25.158 - /// the trivial iterator.
25.159 - /// This feature necessitates that each time we
25.160 - /// iterate the arc-set, the iteration order is the same.
25.161 + /// Sets the iterator to the given node of the given digraph.
25.162 + ///
25.163 NodeIt(const Digraph&, const Node&) { }
25.164 /// Next node.
25.165
25.166 @@ -157,7 +148,7 @@
25.167 };
25.168
25.169
25.170 - /// Class for identifying an arc of the digraph
25.171 + /// The arc type of the digraph
25.172
25.173 /// This class identifies an arc of the digraph. It also serves
25.174 /// as a base class of the arc iterators,
25.175 @@ -166,207 +157,214 @@
25.176 public:
25.177 /// Default constructor
25.178
25.179 - /// @warning The default constructor sets the iterator
25.180 - /// to an undefined value.
25.181 + /// Default constructor.
25.182 + /// \warning It sets the object to an undefined value.
25.183 Arc() { }
25.184 /// Copy constructor.
25.185
25.186 /// Copy constructor.
25.187 ///
25.188 Arc(const Arc&) { }
25.189 - /// Initialize the iterator to be invalid.
25.190 + /// %Invalid constructor \& conversion.
25.191
25.192 - /// Initialize the iterator to be invalid.
25.193 - ///
25.194 + /// Initializes the object to be invalid.
25.195 + /// \sa Invalid for more details.
25.196 Arc(Invalid) { }
25.197 /// Equality operator
25.198
25.199 + /// Equality operator.
25.200 + ///
25.201 /// Two iterators are equal if and only if they point to the
25.202 - /// same object or both are invalid.
25.203 + /// same object or both are \c INVALID.
25.204 bool operator==(Arc) const { return true; }
25.205 /// Inequality operator
25.206
25.207 - /// \sa operator==(Arc n)
25.208 - ///
25.209 + /// Inequality operator.
25.210 bool operator!=(Arc) const { return true; }
25.211
25.212 /// Artificial ordering operator.
25.213
25.214 - /// To allow the use of digraph descriptors as key type in std::map or
25.215 - /// similar associative container we require this.
25.216 + /// Artificial ordering operator.
25.217 ///
25.218 - /// \note This operator only have to define some strict ordering of
25.219 - /// the items; this order has nothing to do with the iteration
25.220 - /// ordering of the items.
25.221 + /// \note This operator only has to define some strict ordering of
25.222 + /// the arcs; this order has nothing to do with the iteration
25.223 + /// ordering of the arcs.
25.224 bool operator<(Arc) const { return false; }
25.225 };
25.226
25.227 - /// This iterator goes trough the outgoing arcs of a node.
25.228 + /// Iterator class for the outgoing arcs of a node.
25.229
25.230 /// This iterator goes trough the \e outgoing arcs of a certain node
25.231 /// of a digraph.
25.232 - /// Its usage is quite simple, for example you can count the number
25.233 + /// Its usage is quite simple, for example, you can count the number
25.234 /// of outgoing arcs of a node \c n
25.235 - /// in digraph \c g of type \c Digraph as follows.
25.236 + /// in a digraph \c g of type \c %Digraph as follows.
25.237 ///\code
25.238 /// int count=0;
25.239 - /// for (Digraph::OutArcIt e(g, n); e!=INVALID; ++e) ++count;
25.240 + /// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count;
25.241 ///\endcode
25.242 -
25.243 class OutArcIt : public Arc {
25.244 public:
25.245 /// Default constructor
25.246
25.247 - /// @warning The default constructor sets the iterator
25.248 - /// to an undefined value.
25.249 + /// Default constructor.
25.250 + /// \warning It sets the iterator to an undefined value.
25.251 OutArcIt() { }
25.252 /// Copy constructor.
25.253
25.254 /// Copy constructor.
25.255 ///
25.256 OutArcIt(const OutArcIt& e) : Arc(e) { }
25.257 - /// Initialize the iterator to be invalid.
25.258 + /// %Invalid constructor \& conversion.
25.259
25.260 - /// Initialize the iterator to be invalid.
25.261 + /// Initializes the iterator to be invalid.
25.262 + /// \sa Invalid for more details.
25.263 + OutArcIt(Invalid) { }
25.264 + /// Sets the iterator to the first outgoing arc.
25.265 +
25.266 + /// Sets the iterator to the first outgoing arc of the given node.
25.267 ///
25.268 - OutArcIt(Invalid) { }
25.269 - /// This constructor sets the iterator to the first outgoing arc.
25.270 + OutArcIt(const Digraph&, const Node&) { }
25.271 + /// Sets the iterator to the given arc.
25.272
25.273 - /// This constructor sets the iterator to the first outgoing arc of
25.274 - /// the node.
25.275 - OutArcIt(const Digraph&, const Node&) { }
25.276 - /// Arc -> OutArcIt conversion
25.277 -
25.278 - /// Sets the iterator to the value of the trivial iterator.
25.279 - /// This feature necessitates that each time we
25.280 - /// iterate the arc-set, the iteration order is the same.
25.281 + /// Sets the iterator to the given arc of the given digraph.
25.282 + ///
25.283 OutArcIt(const Digraph&, const Arc&) { }
25.284 - ///Next outgoing arc
25.285 + /// Next outgoing arc
25.286
25.287 /// Assign the iterator to the next
25.288 /// outgoing arc of the corresponding node.
25.289 OutArcIt& operator++() { return *this; }
25.290 };
25.291
25.292 - /// This iterator goes trough the incoming arcs of a node.
25.293 + /// Iterator class for the incoming arcs of a node.
25.294
25.295 /// This iterator goes trough the \e incoming arcs of a certain node
25.296 /// of a digraph.
25.297 - /// Its usage is quite simple, for example you can count the number
25.298 - /// of outgoing arcs of a node \c n
25.299 - /// in digraph \c g of type \c Digraph as follows.
25.300 + /// Its usage is quite simple, for example, you can count the number
25.301 + /// of incoming arcs of a node \c n
25.302 + /// in a digraph \c g of type \c %Digraph as follows.
25.303 ///\code
25.304 /// int count=0;
25.305 - /// for(Digraph::InArcIt e(g, n); e!=INVALID; ++e) ++count;
25.306 + /// for(Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count;
25.307 ///\endcode
25.308 -
25.309 class InArcIt : public Arc {
25.310 public:
25.311 /// Default constructor
25.312
25.313 - /// @warning The default constructor sets the iterator
25.314 - /// to an undefined value.
25.315 + /// Default constructor.
25.316 + /// \warning It sets the iterator to an undefined value.
25.317 InArcIt() { }
25.318 /// Copy constructor.
25.319
25.320 /// Copy constructor.
25.321 ///
25.322 InArcIt(const InArcIt& e) : Arc(e) { }
25.323 - /// Initialize the iterator to be invalid.
25.324 + /// %Invalid constructor \& conversion.
25.325
25.326 - /// Initialize the iterator to be invalid.
25.327 + /// Initializes the iterator to be invalid.
25.328 + /// \sa Invalid for more details.
25.329 + InArcIt(Invalid) { }
25.330 + /// Sets the iterator to the first incoming arc.
25.331 +
25.332 + /// Sets the iterator to the first incoming arc of the given node.
25.333 ///
25.334 - InArcIt(Invalid) { }
25.335 - /// This constructor sets the iterator to first incoming arc.
25.336 + InArcIt(const Digraph&, const Node&) { }
25.337 + /// Sets the iterator to the given arc.
25.338
25.339 - /// This constructor set the iterator to the first incoming arc of
25.340 - /// the node.
25.341 - InArcIt(const Digraph&, const Node&) { }
25.342 - /// Arc -> InArcIt conversion
25.343 -
25.344 - /// Sets the iterator to the value of the trivial iterator \c e.
25.345 - /// This feature necessitates that each time we
25.346 - /// iterate the arc-set, the iteration order is the same.
25.347 + /// Sets the iterator to the given arc of the given digraph.
25.348 + ///
25.349 InArcIt(const Digraph&, const Arc&) { }
25.350 /// Next incoming arc
25.351
25.352 - /// Assign the iterator to the next inarc of the corresponding node.
25.353 - ///
25.354 + /// Assign the iterator to the next
25.355 + /// incoming arc of the corresponding node.
25.356 InArcIt& operator++() { return *this; }
25.357 };
25.358 - /// This iterator goes through each arc.
25.359
25.360 - /// This iterator goes through each arc of a digraph.
25.361 - /// Its usage is quite simple, for example you can count the number
25.362 - /// of arcs in a digraph \c g of type \c Digraph as follows:
25.363 + /// Iterator class for the arcs.
25.364 +
25.365 + /// This iterator goes through each arc of the digraph.
25.366 + /// Its usage is quite simple, for example, you can count the number
25.367 + /// of arcs in a digraph \c g of type \c %Digraph as follows:
25.368 ///\code
25.369 /// int count=0;
25.370 - /// for(Digraph::ArcIt e(g); e!=INVALID; ++e) ++count;
25.371 + /// for(Digraph::ArcIt a(g); a!=INVALID; ++a) ++count;
25.372 ///\endcode
25.373 class ArcIt : public Arc {
25.374 public:
25.375 /// Default constructor
25.376
25.377 - /// @warning The default constructor sets the iterator
25.378 - /// to an undefined value.
25.379 + /// Default constructor.
25.380 + /// \warning It sets the iterator to an undefined value.
25.381 ArcIt() { }
25.382 /// Copy constructor.
25.383
25.384 /// Copy constructor.
25.385 ///
25.386 ArcIt(const ArcIt& e) : Arc(e) { }
25.387 - /// Initialize the iterator to be invalid.
25.388 + /// %Invalid constructor \& conversion.
25.389
25.390 - /// Initialize the iterator to be invalid.
25.391 + /// Initializes the iterator to be invalid.
25.392 + /// \sa Invalid for more details.
25.393 + ArcIt(Invalid) { }
25.394 + /// Sets the iterator to the first arc.
25.395 +
25.396 + /// Sets the iterator to the first arc of the given digraph.
25.397 ///
25.398 - ArcIt(Invalid) { }
25.399 - /// This constructor sets the iterator to the first arc.
25.400 + explicit ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); }
25.401 + /// Sets the iterator to the given arc.
25.402
25.403 - /// This constructor sets the iterator to the first arc of \c g.
25.404 - ///@param g the digraph
25.405 - ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); }
25.406 - /// Arc -> ArcIt conversion
25.407 -
25.408 - /// Sets the iterator to the value of the trivial iterator \c e.
25.409 - /// This feature necessitates that each time we
25.410 - /// iterate the arc-set, the iteration order is the same.
25.411 + /// Sets the iterator to the given arc of the given digraph.
25.412 + ///
25.413 ArcIt(const Digraph&, const Arc&) { }
25.414 - ///Next arc
25.415 + /// Next arc
25.416
25.417 /// Assign the iterator to the next arc.
25.418 + ///
25.419 ArcIt& operator++() { return *this; }
25.420 };
25.421 - ///Gives back the target node of an arc.
25.422
25.423 - ///Gives back the target node of an arc.
25.424 + /// \brief The source node of the arc.
25.425 ///
25.426 - Node target(Arc) const { return INVALID; }
25.427 - ///Gives back the source node of an arc.
25.428 -
25.429 - ///Gives back the source node of an arc.
25.430 - ///
25.431 + /// Returns the source node of the given arc.
25.432 Node source(Arc) const { return INVALID; }
25.433
25.434 - /// \brief Returns the ID of the node.
25.435 + /// \brief The target node of the arc.
25.436 + ///
25.437 + /// Returns the target node of the given arc.
25.438 + Node target(Arc) const { return INVALID; }
25.439 +
25.440 + /// \brief The ID of the node.
25.441 + ///
25.442 + /// Returns the ID of the given node.
25.443 int id(Node) const { return -1; }
25.444
25.445 - /// \brief Returns the ID of the arc.
25.446 + /// \brief The ID of the arc.
25.447 + ///
25.448 + /// Returns the ID of the given arc.
25.449 int id(Arc) const { return -1; }
25.450
25.451 - /// \brief Returns the node with the given ID.
25.452 + /// \brief The node with the given ID.
25.453 ///
25.454 - /// \pre The argument should be a valid node ID in the graph.
25.455 + /// Returns the node with the given ID.
25.456 + /// \pre The argument should be a valid node ID in the digraph.
25.457 Node nodeFromId(int) const { return INVALID; }
25.458
25.459 - /// \brief Returns the arc with the given ID.
25.460 + /// \brief The arc with the given ID.
25.461 ///
25.462 - /// \pre The argument should be a valid arc ID in the graph.
25.463 + /// Returns the arc with the given ID.
25.464 + /// \pre The argument should be a valid arc ID in the digraph.
25.465 Arc arcFromId(int) const { return INVALID; }
25.466
25.467 - /// \brief Returns an upper bound on the node IDs.
25.468 + /// \brief An upper bound on the node IDs.
25.469 + ///
25.470 + /// Returns an upper bound on the node IDs.
25.471 int maxNodeId() const { return -1; }
25.472
25.473 - /// \brief Returns an upper bound on the arc IDs.
25.474 + /// \brief An upper bound on the arc IDs.
25.475 + ///
25.476 + /// Returns an upper bound on the arc IDs.
25.477 int maxArcId() const { return -1; }
25.478
25.479 void first(Node&) const {}
25.480 @@ -392,45 +390,46 @@
25.481 // Dummy parameter.
25.482 int maxId(Arc) const { return -1; }
25.483
25.484 + /// \brief The opposite node on the arc.
25.485 + ///
25.486 + /// Returns the opposite node on the given arc.
25.487 + Node oppositeNode(Node, Arc) const { return INVALID; }
25.488 +
25.489 /// \brief The base node of the iterator.
25.490 ///
25.491 - /// Gives back the base node of the iterator.
25.492 - /// It is always the target of the pointed arc.
25.493 - Node baseNode(const InArcIt&) const { return INVALID; }
25.494 + /// Returns the base node of the given outgoing arc iterator
25.495 + /// (i.e. the source node of the corresponding arc).
25.496 + Node baseNode(OutArcIt) const { return INVALID; }
25.497
25.498 /// \brief The running node of the iterator.
25.499 ///
25.500 - /// Gives back the running node of the iterator.
25.501 - /// It is always the source of the pointed arc.
25.502 - Node runningNode(const InArcIt&) const { return INVALID; }
25.503 + /// Returns the running node of the given outgoing arc iterator
25.504 + /// (i.e. the target node of the corresponding arc).
25.505 + Node runningNode(OutArcIt) const { return INVALID; }
25.506
25.507 /// \brief The base node of the iterator.
25.508 ///
25.509 - /// Gives back the base node of the iterator.
25.510 - /// It is always the source of the pointed arc.
25.511 - Node baseNode(const OutArcIt&) const { return INVALID; }
25.512 + /// Returns the base node of the given incomming arc iterator
25.513 + /// (i.e. the target node of the corresponding arc).
25.514 + Node baseNode(InArcIt) const { return INVALID; }
25.515
25.516 /// \brief The running node of the iterator.
25.517 ///
25.518 - /// Gives back the running node of the iterator.
25.519 - /// It is always the target of the pointed arc.
25.520 - Node runningNode(const OutArcIt&) const { return INVALID; }
25.521 + /// Returns the running node of the given incomming arc iterator
25.522 + /// (i.e. the source node of the corresponding arc).
25.523 + Node runningNode(InArcIt) const { return INVALID; }
25.524
25.525 - /// \brief The opposite node on the given arc.
25.526 + /// \brief Standard graph map type for the nodes.
25.527 ///
25.528 - /// Gives back the opposite node on the given arc.
25.529 - Node oppositeNode(const Node&, const Arc&) const { return INVALID; }
25.530 -
25.531 - /// \brief Reference map of the nodes to type \c T.
25.532 - ///
25.533 - /// Reference map of the nodes to type \c T.
25.534 + /// Standard graph map type for the nodes.
25.535 + /// It conforms to the ReferenceMap concept.
25.536 template<class T>
25.537 class NodeMap : public ReferenceMap<Node, T, T&, const T&> {
25.538 public:
25.539
25.540 - ///\e
25.541 - NodeMap(const Digraph&) { }
25.542 - ///\e
25.543 + /// Constructor
25.544 + explicit NodeMap(const Digraph&) { }
25.545 + /// Constructor with given initial value
25.546 NodeMap(const Digraph&, T) { }
25.547
25.548 private:
25.549 @@ -445,17 +444,19 @@
25.550 }
25.551 };
25.552
25.553 - /// \brief Reference map of the arcs to type \c T.
25.554 + /// \brief Standard graph map type for the arcs.
25.555 ///
25.556 - /// Reference map of the arcs to type \c T.
25.557 + /// Standard graph map type for the arcs.
25.558 + /// It conforms to the ReferenceMap concept.
25.559 template<class T>
25.560 class ArcMap : public ReferenceMap<Arc, T, T&, const T&> {
25.561 public:
25.562
25.563 - ///\e
25.564 - ArcMap(const Digraph&) { }
25.565 - ///\e
25.566 + /// Constructor
25.567 + explicit ArcMap(const Digraph&) { }
25.568 + /// Constructor with given initial value
25.569 ArcMap(const Digraph&, T) { }
25.570 +
25.571 private:
25.572 ///Copy constructor
25.573 ArcMap(const ArcMap& em) :
26.1 --- a/lemon/concepts/graph.h Thu Dec 10 17:05:35 2009 +0100
26.2 +++ b/lemon/concepts/graph.h Thu Dec 10 17:18:25 2009 +0100
26.3 @@ -18,12 +18,14 @@
26.4
26.5 ///\ingroup graph_concepts
26.6 ///\file
26.7 -///\brief The concept of Undirected Graphs.
26.8 +///\brief The concept of undirected graphs.
26.9
26.10 #ifndef LEMON_CONCEPTS_GRAPH_H
26.11 #define LEMON_CONCEPTS_GRAPH_H
26.12
26.13 #include <lemon/concepts/graph_components.h>
26.14 +#include <lemon/concepts/maps.h>
26.15 +#include <lemon/concept_check.h>
26.16 #include <lemon/core.h>
26.17
26.18 namespace lemon {
26.19 @@ -31,63 +33,74 @@
26.20
26.21 /// \ingroup graph_concepts
26.22 ///
26.23 - /// \brief Class describing the concept of Undirected Graphs.
26.24 + /// \brief Class describing the concept of undirected graphs.
26.25 ///
26.26 - /// This class describes the common interface of all Undirected
26.27 - /// Graphs.
26.28 + /// This class describes the common interface of all undirected
26.29 + /// graphs.
26.30 ///
26.31 - /// As all concept describing classes it provides only interface
26.32 - /// without any sensible implementation. So any algorithm for
26.33 - /// undirected graph should compile with this class, but it will not
26.34 + /// Like all concept classes, it only provides an interface
26.35 + /// without any sensible implementation. So any general algorithm for
26.36 + /// undirected graphs should compile with this class, but it will not
26.37 /// run properly, of course.
26.38 + /// An actual graph implementation like \ref ListGraph or
26.39 + /// \ref SmartGraph may have additional functionality.
26.40 ///
26.41 - /// The LEMON undirected graphs also fulfill the concept of
26.42 - /// directed graphs (\ref lemon::concepts::Digraph "Digraph
26.43 - /// Concept"). Each edges can be seen as two opposite
26.44 - /// directed arc and consequently the undirected graph can be
26.45 - /// seen as the direceted graph of these directed arcs. The
26.46 - /// Graph has the Edge inner class for the edges and
26.47 - /// the Arc type for the directed arcs. The Arc type is
26.48 - /// convertible to Edge or inherited from it so from a directed
26.49 - /// arc we can get the represented edge.
26.50 + /// The undirected graphs also fulfill the concept of \ref Digraph
26.51 + /// "directed graphs", since each edge can also be regarded as two
26.52 + /// oppositely directed arcs.
26.53 + /// Undirected graphs provide an Edge type for the undirected edges and
26.54 + /// an Arc type for the directed arcs. The Arc type is convertible to
26.55 + /// Edge or inherited from it, i.e. the corresponding edge can be
26.56 + /// obtained from an arc.
26.57 + /// EdgeIt and EdgeMap classes can be used for the edges, while ArcIt
26.58 + /// and ArcMap classes can be used for the arcs (just like in digraphs).
26.59 + /// Both InArcIt and OutArcIt iterates on the same edges but with
26.60 + /// opposite direction. IncEdgeIt also iterates on the same edges
26.61 + /// as OutArcIt and InArcIt, but it is not convertible to Arc,
26.62 + /// only to Edge.
26.63 ///
26.64 - /// In the sense of the LEMON each edge has a default
26.65 - /// direction (it should be in every computer implementation,
26.66 - /// because the order of edge's nodes defines an
26.67 - /// orientation). With the default orientation we can define that
26.68 - /// the directed arc is forward or backward directed. With the \c
26.69 - /// direction() and \c direct() function we can get the direction
26.70 - /// of the directed arc and we can direct an edge.
26.71 + /// In LEMON, each undirected edge has an inherent orientation.
26.72 + /// Thus it can defined if an arc is forward or backward oriented in
26.73 + /// an undirected graph with respect to this default oriantation of
26.74 + /// the represented edge.
26.75 + /// With the direction() and direct() functions the direction
26.76 + /// of an arc can be obtained and set, respectively.
26.77 ///
26.78 - /// The EdgeIt is an iterator for the edges. We can use
26.79 - /// the EdgeMap to map values for the edges. The InArcIt and
26.80 - /// OutArcIt iterates on the same edges but with opposite
26.81 - /// direction. The IncEdgeIt iterates also on the same edges
26.82 - /// as the OutArcIt and InArcIt but it is not convertible to Arc just
26.83 - /// to Edge.
26.84 + /// Only nodes and edges can be added to or removed from an undirected
26.85 + /// graph and the corresponding arcs are added or removed automatically.
26.86 + ///
26.87 + /// \sa Digraph
26.88 class Graph {
26.89 + private:
26.90 + /// Graphs are \e not copy constructible. Use DigraphCopy instead.
26.91 + Graph(const Graph&) {}
26.92 + /// \brief Assignment of a graph to another one is \e not allowed.
26.93 + /// Use DigraphCopy instead.
26.94 + void operator=(const Graph&) {}
26.95 +
26.96 public:
26.97 - /// \brief The undirected graph should be tagged by the
26.98 - /// UndirectedTag.
26.99 + /// Default constructor.
26.100 + Graph() {}
26.101 +
26.102 + /// \brief Undirected graphs should be tagged with \c UndirectedTag.
26.103 ///
26.104 - /// The undirected graph should be tagged by the UndirectedTag. This
26.105 - /// tag helps the enable_if technics to make compile time
26.106 + /// Undirected graphs should be tagged with \c UndirectedTag.
26.107 + ///
26.108 + /// This tag helps the \c enable_if technics to make compile time
26.109 /// specializations for undirected graphs.
26.110 typedef True UndirectedTag;
26.111
26.112 - /// \brief The base type of node iterators,
26.113 - /// or in other words, the trivial node iterator.
26.114 - ///
26.115 - /// This is the base type of each node iterator,
26.116 - /// thus each kind of node iterator converts to this.
26.117 - /// More precisely each kind of node iterator should be inherited
26.118 - /// from the trivial node iterator.
26.119 + /// The node type of the graph
26.120 +
26.121 + /// This class identifies a node of the graph. It also serves
26.122 + /// as a base class of the node iterators,
26.123 + /// thus they convert to this type.
26.124 class Node {
26.125 public:
26.126 /// Default constructor
26.127
26.128 - /// @warning The default constructor sets the iterator
26.129 - /// to an undefined value.
26.130 + /// Default constructor.
26.131 + /// \warning It sets the object to an undefined value.
26.132 Node() { }
26.133 /// Copy constructor.
26.134
26.135 @@ -95,40 +108,40 @@
26.136 ///
26.137 Node(const Node&) { }
26.138
26.139 - /// Invalid constructor \& conversion.
26.140 + /// %Invalid constructor \& conversion.
26.141
26.142 - /// This constructor initializes the iterator to be invalid.
26.143 + /// Initializes the object to be invalid.
26.144 /// \sa Invalid for more details.
26.145 Node(Invalid) { }
26.146 /// Equality operator
26.147
26.148 + /// Equality operator.
26.149 + ///
26.150 /// Two iterators are equal if and only if they point to the
26.151 - /// same object or both are invalid.
26.152 + /// same object or both are \c INVALID.
26.153 bool operator==(Node) const { return true; }
26.154
26.155 /// Inequality operator
26.156
26.157 - /// \sa operator==(Node n)
26.158 - ///
26.159 + /// Inequality operator.
26.160 bool operator!=(Node) const { return true; }
26.161
26.162 /// Artificial ordering operator.
26.163
26.164 - /// To allow the use of graph descriptors as key type in std::map or
26.165 - /// similar associative container we require this.
26.166 + /// Artificial ordering operator.
26.167 ///
26.168 - /// \note This operator only have to define some strict ordering of
26.169 + /// \note This operator only has to define some strict ordering of
26.170 /// the items; this order has nothing to do with the iteration
26.171 /// ordering of the items.
26.172 bool operator<(Node) const { return false; }
26.173
26.174 };
26.175
26.176 - /// This iterator goes through each node.
26.177 + /// Iterator class for the nodes.
26.178
26.179 - /// This iterator goes through each node.
26.180 - /// Its usage is quite simple, for example you can count the number
26.181 - /// of nodes in graph \c g of type \c Graph like this:
26.182 + /// This iterator goes through each node of the graph.
26.183 + /// Its usage is quite simple, for example, you can count the number
26.184 + /// of nodes in a graph \c g of type \c %Graph like this:
26.185 ///\code
26.186 /// int count=0;
26.187 /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
26.188 @@ -137,30 +150,28 @@
26.189 public:
26.190 /// Default constructor
26.191
26.192 - /// @warning The default constructor sets the iterator
26.193 - /// to an undefined value.
26.194 + /// Default constructor.
26.195 + /// \warning It sets the iterator to an undefined value.
26.196 NodeIt() { }
26.197 /// Copy constructor.
26.198
26.199 /// Copy constructor.
26.200 ///
26.201 NodeIt(const NodeIt& n) : Node(n) { }
26.202 - /// Invalid constructor \& conversion.
26.203 + /// %Invalid constructor \& conversion.
26.204
26.205 - /// Initialize the iterator to be invalid.
26.206 + /// Initializes the iterator to be invalid.
26.207 /// \sa Invalid for more details.
26.208 NodeIt(Invalid) { }
26.209 /// Sets the iterator to the first node.
26.210
26.211 - /// Sets the iterator to the first node of \c g.
26.212 + /// Sets the iterator to the first node of the given digraph.
26.213 ///
26.214 - NodeIt(const Graph&) { }
26.215 - /// Node -> NodeIt conversion.
26.216 + explicit NodeIt(const Graph&) { }
26.217 + /// Sets the iterator to the given node.
26.218
26.219 - /// Sets the iterator to the node of \c the graph pointed by
26.220 - /// the trivial iterator.
26.221 - /// This feature necessitates that each time we
26.222 - /// iterate the arc-set, the iteration order is the same.
26.223 + /// Sets the iterator to the given node of the given digraph.
26.224 + ///
26.225 NodeIt(const Graph&, const Node&) { }
26.226 /// Next node.
26.227
26.228 @@ -170,54 +181,55 @@
26.229 };
26.230
26.231
26.232 - /// The base type of the edge iterators.
26.233 + /// The edge type of the graph
26.234
26.235 - /// The base type of the edge iterators.
26.236 - ///
26.237 + /// This class identifies an edge of the graph. It also serves
26.238 + /// as a base class of the edge iterators,
26.239 + /// thus they will convert to this type.
26.240 class Edge {
26.241 public:
26.242 /// Default constructor
26.243
26.244 - /// @warning The default constructor sets the iterator
26.245 - /// to an undefined value.
26.246 + /// Default constructor.
26.247 + /// \warning It sets the object to an undefined value.
26.248 Edge() { }
26.249 /// Copy constructor.
26.250
26.251 /// Copy constructor.
26.252 ///
26.253 Edge(const Edge&) { }
26.254 - /// Initialize the iterator to be invalid.
26.255 + /// %Invalid constructor \& conversion.
26.256
26.257 - /// Initialize the iterator to be invalid.
26.258 - ///
26.259 + /// Initializes the object to be invalid.
26.260 + /// \sa Invalid for more details.
26.261 Edge(Invalid) { }
26.262 /// Equality operator
26.263
26.264 + /// Equality operator.
26.265 + ///
26.266 /// Two iterators are equal if and only if they point to the
26.267 - /// same object or both are invalid.
26.268 + /// same object or both are \c INVALID.
26.269 bool operator==(Edge) const { return true; }
26.270 /// Inequality operator
26.271
26.272 - /// \sa operator==(Edge n)
26.273 - ///
26.274 + /// Inequality operator.
26.275 bool operator!=(Edge) const { return true; }
26.276
26.277 /// Artificial ordering operator.
26.278
26.279 - /// To allow the use of graph descriptors as key type in std::map or
26.280 - /// similar associative container we require this.
26.281 + /// Artificial ordering operator.
26.282 ///
26.283 - /// \note This operator only have to define some strict ordering of
26.284 - /// the items; this order has nothing to do with the iteration
26.285 - /// ordering of the items.
26.286 + /// \note This operator only has to define some strict ordering of
26.287 + /// the edges; this order has nothing to do with the iteration
26.288 + /// ordering of the edges.
26.289 bool operator<(Edge) const { return false; }
26.290 };
26.291
26.292 - /// This iterator goes through each edge.
26.293 + /// Iterator class for the edges.
26.294
26.295 - /// This iterator goes through each edge of a graph.
26.296 - /// Its usage is quite simple, for example you can count the number
26.297 - /// of edges in a graph \c g of type \c Graph as follows:
26.298 + /// This iterator goes through each edge of the graph.
26.299 + /// Its usage is quite simple, for example, you can count the number
26.300 + /// of edges in a graph \c g of type \c %Graph as follows:
26.301 ///\code
26.302 /// int count=0;
26.303 /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
26.304 @@ -226,290 +238,285 @@
26.305 public:
26.306 /// Default constructor
26.307
26.308 - /// @warning The default constructor sets the iterator
26.309 - /// to an undefined value.
26.310 + /// Default constructor.
26.311 + /// \warning It sets the iterator to an undefined value.
26.312 EdgeIt() { }
26.313 /// Copy constructor.
26.314
26.315 /// Copy constructor.
26.316 ///
26.317 EdgeIt(const EdgeIt& e) : Edge(e) { }
26.318 - /// Initialize the iterator to be invalid.
26.319 + /// %Invalid constructor \& conversion.
26.320
26.321 - /// Initialize the iterator to be invalid.
26.322 + /// Initializes the iterator to be invalid.
26.323 + /// \sa Invalid for more details.
26.324 + EdgeIt(Invalid) { }
26.325 + /// Sets the iterator to the first edge.
26.326 +
26.327 + /// Sets the iterator to the first edge of the given graph.
26.328 ///
26.329 - EdgeIt(Invalid) { }
26.330 - /// This constructor sets the iterator to the first edge.
26.331 + explicit EdgeIt(const Graph&) { }
26.332 + /// Sets the iterator to the given edge.
26.333
26.334 - /// This constructor sets the iterator to the first edge.
26.335 - EdgeIt(const Graph&) { }
26.336 - /// Edge -> EdgeIt conversion
26.337 -
26.338 - /// Sets the iterator to the value of the trivial iterator.
26.339 - /// This feature necessitates that each time we
26.340 - /// iterate the edge-set, the iteration order is the
26.341 - /// same.
26.342 + /// Sets the iterator to the given edge of the given graph.
26.343 + ///
26.344 EdgeIt(const Graph&, const Edge&) { }
26.345 /// Next edge
26.346
26.347 /// Assign the iterator to the next edge.
26.348 + ///
26.349 EdgeIt& operator++() { return *this; }
26.350 };
26.351
26.352 - /// \brief This iterator goes trough the incident undirected
26.353 - /// arcs of a node.
26.354 - ///
26.355 - /// This iterator goes trough the incident edges
26.356 - /// of a certain node of a graph. You should assume that the
26.357 - /// loop arcs will be iterated twice.
26.358 - ///
26.359 - /// Its usage is quite simple, for example you can compute the
26.360 - /// degree (i.e. count the number of incident arcs of a node \c n
26.361 - /// in graph \c g of type \c Graph as follows.
26.362 + /// Iterator class for the incident edges of a node.
26.363 +
26.364 + /// This iterator goes trough the incident undirected edges
26.365 + /// of a certain node of a graph.
26.366 + /// Its usage is quite simple, for example, you can compute the
26.367 + /// degree (i.e. the number of incident edges) of a node \c n
26.368 + /// in a graph \c g of type \c %Graph as follows.
26.369 ///
26.370 ///\code
26.371 /// int count=0;
26.372 /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count;
26.373 ///\endcode
26.374 + ///
26.375 + /// \warning Loop edges will be iterated twice.
26.376 class IncEdgeIt : public Edge {
26.377 public:
26.378 /// Default constructor
26.379
26.380 - /// @warning The default constructor sets the iterator
26.381 - /// to an undefined value.
26.382 + /// Default constructor.
26.383 + /// \warning It sets the iterator to an undefined value.
26.384 IncEdgeIt() { }
26.385 /// Copy constructor.
26.386
26.387 /// Copy constructor.
26.388 ///
26.389 IncEdgeIt(const IncEdgeIt& e) : Edge(e) { }
26.390 - /// Initialize the iterator to be invalid.
26.391 + /// %Invalid constructor \& conversion.
26.392
26.393 - /// Initialize the iterator to be invalid.
26.394 + /// Initializes the iterator to be invalid.
26.395 + /// \sa Invalid for more details.
26.396 + IncEdgeIt(Invalid) { }
26.397 + /// Sets the iterator to the first incident edge.
26.398 +
26.399 + /// Sets the iterator to the first incident edge of the given node.
26.400 ///
26.401 - IncEdgeIt(Invalid) { }
26.402 - /// This constructor sets the iterator to first incident arc.
26.403 + IncEdgeIt(const Graph&, const Node&) { }
26.404 + /// Sets the iterator to the given edge.
26.405
26.406 - /// This constructor set the iterator to the first incident arc of
26.407 - /// the node.
26.408 - IncEdgeIt(const Graph&, const Node&) { }
26.409 - /// Edge -> IncEdgeIt conversion
26.410 + /// Sets the iterator to the given edge of the given graph.
26.411 + ///
26.412 + IncEdgeIt(const Graph&, const Edge&) { }
26.413 + /// Next incident edge
26.414
26.415 - /// Sets the iterator to the value of the trivial iterator \c e.
26.416 - /// This feature necessitates that each time we
26.417 - /// iterate the arc-set, the iteration order is the same.
26.418 - IncEdgeIt(const Graph&, const Edge&) { }
26.419 - /// Next incident arc
26.420 -
26.421 - /// Assign the iterator to the next incident arc
26.422 + /// Assign the iterator to the next incident edge
26.423 /// of the corresponding node.
26.424 IncEdgeIt& operator++() { return *this; }
26.425 };
26.426
26.427 - /// The directed arc type.
26.428 + /// The arc type of the graph
26.429
26.430 - /// The directed arc type. It can be converted to the
26.431 - /// edge or it should be inherited from the undirected
26.432 - /// edge.
26.433 + /// This class identifies a directed arc of the graph. It also serves
26.434 + /// as a base class of the arc iterators,
26.435 + /// thus they will convert to this type.
26.436 class Arc {
26.437 public:
26.438 /// Default constructor
26.439
26.440 - /// @warning The default constructor sets the iterator
26.441 - /// to an undefined value.
26.442 + /// Default constructor.
26.443 + /// \warning It sets the object to an undefined value.
26.444 Arc() { }
26.445 /// Copy constructor.
26.446
26.447 /// Copy constructor.
26.448 ///
26.449 Arc(const Arc&) { }
26.450 - /// Initialize the iterator to be invalid.
26.451 + /// %Invalid constructor \& conversion.
26.452
26.453 - /// Initialize the iterator to be invalid.
26.454 - ///
26.455 + /// Initializes the object to be invalid.
26.456 + /// \sa Invalid for more details.
26.457 Arc(Invalid) { }
26.458 /// Equality operator
26.459
26.460 + /// Equality operator.
26.461 + ///
26.462 /// Two iterators are equal if and only if they point to the
26.463 - /// same object or both are invalid.
26.464 + /// same object or both are \c INVALID.
26.465 bool operator==(Arc) const { return true; }
26.466 /// Inequality operator
26.467
26.468 - /// \sa operator==(Arc n)
26.469 - ///
26.470 + /// Inequality operator.
26.471 bool operator!=(Arc) const { return true; }
26.472
26.473 /// Artificial ordering operator.
26.474
26.475 - /// To allow the use of graph descriptors as key type in std::map or
26.476 - /// similar associative container we require this.
26.477 + /// Artificial ordering operator.
26.478 ///
26.479 - /// \note This operator only have to define some strict ordering of
26.480 - /// the items; this order has nothing to do with the iteration
26.481 - /// ordering of the items.
26.482 + /// \note This operator only has to define some strict ordering of
26.483 + /// the arcs; this order has nothing to do with the iteration
26.484 + /// ordering of the arcs.
26.485 bool operator<(Arc) const { return false; }
26.486
26.487 - /// Converison to Edge
26.488 + /// Converison to \c Edge
26.489 +
26.490 + /// Converison to \c Edge.
26.491 + ///
26.492 operator Edge() const { return Edge(); }
26.493 };
26.494 - /// This iterator goes through each directed arc.
26.495
26.496 - /// This iterator goes through each arc of a graph.
26.497 - /// Its usage is quite simple, for example you can count the number
26.498 - /// of arcs in a graph \c g of type \c Graph as follows:
26.499 + /// Iterator class for the arcs.
26.500 +
26.501 + /// This iterator goes through each directed arc of the graph.
26.502 + /// Its usage is quite simple, for example, you can count the number
26.503 + /// of arcs in a graph \c g of type \c %Graph as follows:
26.504 ///\code
26.505 /// int count=0;
26.506 - /// for(Graph::ArcIt e(g); e!=INVALID; ++e) ++count;
26.507 + /// for(Graph::ArcIt a(g); a!=INVALID; ++a) ++count;
26.508 ///\endcode
26.509 class ArcIt : public Arc {
26.510 public:
26.511 /// Default constructor
26.512
26.513 - /// @warning The default constructor sets the iterator
26.514 - /// to an undefined value.
26.515 + /// Default constructor.
26.516 + /// \warning It sets the iterator to an undefined value.
26.517 ArcIt() { }
26.518 /// Copy constructor.
26.519
26.520 /// Copy constructor.
26.521 ///
26.522 ArcIt(const ArcIt& e) : Arc(e) { }
26.523 - /// Initialize the iterator to be invalid.
26.524 + /// %Invalid constructor \& conversion.
26.525
26.526 - /// Initialize the iterator to be invalid.
26.527 + /// Initializes the iterator to be invalid.
26.528 + /// \sa Invalid for more details.
26.529 + ArcIt(Invalid) { }
26.530 + /// Sets the iterator to the first arc.
26.531 +
26.532 + /// Sets the iterator to the first arc of the given graph.
26.533 ///
26.534 - ArcIt(Invalid) { }
26.535 - /// This constructor sets the iterator to the first arc.
26.536 + explicit ArcIt(const Graph &g) { ignore_unused_variable_warning(g); }
26.537 + /// Sets the iterator to the given arc.
26.538
26.539 - /// This constructor sets the iterator to the first arc of \c g.
26.540 - ///@param g the graph
26.541 - ArcIt(const Graph &g) { ignore_unused_variable_warning(g); }
26.542 - /// Arc -> ArcIt conversion
26.543 -
26.544 - /// Sets the iterator to the value of the trivial iterator \c e.
26.545 - /// This feature necessitates that each time we
26.546 - /// iterate the arc-set, the iteration order is the same.
26.547 + /// Sets the iterator to the given arc of the given graph.
26.548 + ///
26.549 ArcIt(const Graph&, const Arc&) { }
26.550 - ///Next arc
26.551 + /// Next arc
26.552
26.553 /// Assign the iterator to the next arc.
26.554 + ///
26.555 ArcIt& operator++() { return *this; }
26.556 };
26.557
26.558 - /// This iterator goes trough the outgoing directed arcs of a node.
26.559 + /// Iterator class for the outgoing arcs of a node.
26.560
26.561 - /// This iterator goes trough the \e outgoing arcs of a certain node
26.562 - /// of a graph.
26.563 - /// Its usage is quite simple, for example you can count the number
26.564 + /// This iterator goes trough the \e outgoing directed arcs of a
26.565 + /// certain node of a graph.
26.566 + /// Its usage is quite simple, for example, you can count the number
26.567 /// of outgoing arcs of a node \c n
26.568 - /// in graph \c g of type \c Graph as follows.
26.569 + /// in a graph \c g of type \c %Graph as follows.
26.570 ///\code
26.571 /// int count=0;
26.572 - /// for (Graph::OutArcIt e(g, n); e!=INVALID; ++e) ++count;
26.573 + /// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count;
26.574 ///\endcode
26.575 -
26.576 class OutArcIt : public Arc {
26.577 public:
26.578 /// Default constructor
26.579
26.580 - /// @warning The default constructor sets the iterator
26.581 - /// to an undefined value.
26.582 + /// Default constructor.
26.583 + /// \warning It sets the iterator to an undefined value.
26.584 OutArcIt() { }
26.585 /// Copy constructor.
26.586
26.587 /// Copy constructor.
26.588 ///
26.589 OutArcIt(const OutArcIt& e) : Arc(e) { }
26.590 - /// Initialize the iterator to be invalid.
26.591 + /// %Invalid constructor \& conversion.
26.592
26.593 - /// Initialize the iterator to be invalid.
26.594 + /// Initializes the iterator to be invalid.
26.595 + /// \sa Invalid for more details.
26.596 + OutArcIt(Invalid) { }
26.597 + /// Sets the iterator to the first outgoing arc.
26.598 +
26.599 + /// Sets the iterator to the first outgoing arc of the given node.
26.600 ///
26.601 - OutArcIt(Invalid) { }
26.602 - /// This constructor sets the iterator to the first outgoing arc.
26.603 -
26.604 - /// This constructor sets the iterator to the first outgoing arc of
26.605 - /// the node.
26.606 - ///@param n the node
26.607 - ///@param g the graph
26.608 OutArcIt(const Graph& n, const Node& g) {
26.609 ignore_unused_variable_warning(n);
26.610 ignore_unused_variable_warning(g);
26.611 }
26.612 - /// Arc -> OutArcIt conversion
26.613 + /// Sets the iterator to the given arc.
26.614
26.615 - /// Sets the iterator to the value of the trivial iterator.
26.616 - /// This feature necessitates that each time we
26.617 - /// iterate the arc-set, the iteration order is the same.
26.618 + /// Sets the iterator to the given arc of the given graph.
26.619 + ///
26.620 OutArcIt(const Graph&, const Arc&) { }
26.621 - ///Next outgoing arc
26.622 + /// Next outgoing arc
26.623
26.624 /// Assign the iterator to the next
26.625 /// outgoing arc of the corresponding node.
26.626 OutArcIt& operator++() { return *this; }
26.627 };
26.628
26.629 - /// This iterator goes trough the incoming directed arcs of a node.
26.630 + /// Iterator class for the incoming arcs of a node.
26.631
26.632 - /// This iterator goes trough the \e incoming arcs of a certain node
26.633 - /// of a graph.
26.634 - /// Its usage is quite simple, for example you can count the number
26.635 - /// of outgoing arcs of a node \c n
26.636 - /// in graph \c g of type \c Graph as follows.
26.637 + /// This iterator goes trough the \e incoming directed arcs of a
26.638 + /// certain node of a graph.
26.639 + /// Its usage is quite simple, for example, you can count the number
26.640 + /// of incoming arcs of a node \c n
26.641 + /// in a graph \c g of type \c %Graph as follows.
26.642 ///\code
26.643 /// int count=0;
26.644 - /// for(Graph::InArcIt e(g, n); e!=INVALID; ++e) ++count;
26.645 + /// for (Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count;
26.646 ///\endcode
26.647 -
26.648 class InArcIt : public Arc {
26.649 public:
26.650 /// Default constructor
26.651
26.652 - /// @warning The default constructor sets the iterator
26.653 - /// to an undefined value.
26.654 + /// Default constructor.
26.655 + /// \warning It sets the iterator to an undefined value.
26.656 InArcIt() { }
26.657 /// Copy constructor.
26.658
26.659 /// Copy constructor.
26.660 ///
26.661 InArcIt(const InArcIt& e) : Arc(e) { }
26.662 - /// Initialize the iterator to be invalid.
26.663 + /// %Invalid constructor \& conversion.
26.664
26.665 - /// Initialize the iterator to be invalid.
26.666 + /// Initializes the iterator to be invalid.
26.667 + /// \sa Invalid for more details.
26.668 + InArcIt(Invalid) { }
26.669 + /// Sets the iterator to the first incoming arc.
26.670 +
26.671 + /// Sets the iterator to the first incoming arc of the given node.
26.672 ///
26.673 - InArcIt(Invalid) { }
26.674 - /// This constructor sets the iterator to first incoming arc.
26.675 -
26.676 - /// This constructor set the iterator to the first incoming arc of
26.677 - /// the node.
26.678 - ///@param n the node
26.679 - ///@param g the graph
26.680 InArcIt(const Graph& g, const Node& n) {
26.681 ignore_unused_variable_warning(n);
26.682 ignore_unused_variable_warning(g);
26.683 }
26.684 - /// Arc -> InArcIt conversion
26.685 + /// Sets the iterator to the given arc.
26.686
26.687 - /// Sets the iterator to the value of the trivial iterator \c e.
26.688 - /// This feature necessitates that each time we
26.689 - /// iterate the arc-set, the iteration order is the same.
26.690 + /// Sets the iterator to the given arc of the given graph.
26.691 + ///
26.692 InArcIt(const Graph&, const Arc&) { }
26.693 /// Next incoming arc
26.694
26.695 - /// Assign the iterator to the next inarc of the corresponding node.
26.696 - ///
26.697 + /// Assign the iterator to the next
26.698 + /// incoming arc of the corresponding node.
26.699 InArcIt& operator++() { return *this; }
26.700 };
26.701
26.702 - /// \brief Reference map of the nodes to type \c T.
26.703 + /// \brief Standard graph map type for the nodes.
26.704 ///
26.705 - /// Reference map of the nodes to type \c T.
26.706 + /// Standard graph map type for the nodes.
26.707 + /// It conforms to the ReferenceMap concept.
26.708 template<class T>
26.709 class NodeMap : public ReferenceMap<Node, T, T&, const T&>
26.710 {
26.711 public:
26.712
26.713 - ///\e
26.714 - NodeMap(const Graph&) { }
26.715 - ///\e
26.716 + /// Constructor
26.717 + explicit NodeMap(const Graph&) { }
26.718 + /// Constructor with given initial value
26.719 NodeMap(const Graph&, T) { }
26.720
26.721 private:
26.722 @@ -524,18 +531,20 @@
26.723 }
26.724 };
26.725
26.726 - /// \brief Reference map of the arcs to type \c T.
26.727 + /// \brief Standard graph map type for the arcs.
26.728 ///
26.729 - /// Reference map of the arcs to type \c T.
26.730 + /// Standard graph map type for the arcs.
26.731 + /// It conforms to the ReferenceMap concept.
26.732 template<class T>
26.733 class ArcMap : public ReferenceMap<Arc, T, T&, const T&>
26.734 {
26.735 public:
26.736
26.737 - ///\e
26.738 - ArcMap(const Graph&) { }
26.739 - ///\e
26.740 + /// Constructor
26.741 + explicit ArcMap(const Graph&) { }
26.742 + /// Constructor with given initial value
26.743 ArcMap(const Graph&, T) { }
26.744 +
26.745 private:
26.746 ///Copy constructor
26.747 ArcMap(const ArcMap& em) :
26.748 @@ -548,18 +557,20 @@
26.749 }
26.750 };
26.751
26.752 - /// Reference map of the edges to type \c T.
26.753 -
26.754 - /// Reference map of the edges to type \c T.
26.755 + /// \brief Standard graph map type for the edges.
26.756 + ///
26.757 + /// Standard graph map type for the edges.
26.758 + /// It conforms to the ReferenceMap concept.
26.759 template<class T>
26.760 class EdgeMap : public ReferenceMap<Edge, T, T&, const T&>
26.761 {
26.762 public:
26.763
26.764 - ///\e
26.765 - EdgeMap(const Graph&) { }
26.766 - ///\e
26.767 + /// Constructor
26.768 + explicit EdgeMap(const Graph&) { }
26.769 + /// Constructor with given initial value
26.770 EdgeMap(const Graph&, T) { }
26.771 +
26.772 private:
26.773 ///Copy constructor
26.774 EdgeMap(const EdgeMap& em) :
26.775 @@ -572,107 +583,124 @@
26.776 }
26.777 };
26.778
26.779 - /// \brief Direct the given edge.
26.780 + /// \brief The first node of the edge.
26.781 ///
26.782 - /// Direct the given edge. The returned arc source
26.783 - /// will be the given node.
26.784 - Arc direct(const Edge&, const Node&) const {
26.785 - return INVALID;
26.786 - }
26.787 -
26.788 - /// \brief Direct the given edge.
26.789 + /// Returns the first node of the given edge.
26.790 ///
26.791 - /// Direct the given edge. The returned arc
26.792 - /// represents the given edge and the direction comes
26.793 - /// from the bool parameter. The source of the edge and
26.794 - /// the directed arc is the same when the given bool is true.
26.795 - Arc direct(const Edge&, bool) const {
26.796 - return INVALID;
26.797 - }
26.798 -
26.799 - /// \brief Returns true if the arc has default orientation.
26.800 - ///
26.801 - /// Returns whether the given directed arc is same orientation as
26.802 - /// the corresponding edge's default orientation.
26.803 - bool direction(Arc) const { return true; }
26.804 -
26.805 - /// \brief Returns the opposite directed arc.
26.806 - ///
26.807 - /// Returns the opposite directed arc.
26.808 - Arc oppositeArc(Arc) const { return INVALID; }
26.809 -
26.810 - /// \brief Opposite node on an arc
26.811 - ///
26.812 - /// \return The opposite of the given node on the given edge.
26.813 - Node oppositeNode(Node, Edge) const { return INVALID; }
26.814 -
26.815 - /// \brief First node of the edge.
26.816 - ///
26.817 - /// \return The first node of the given edge.
26.818 - ///
26.819 - /// Naturally edges don't have direction and thus
26.820 - /// don't have source and target node. However we use \c u() and \c v()
26.821 - /// methods to query the two nodes of the arc. The direction of the
26.822 - /// arc which arises this way is called the inherent direction of the
26.823 - /// edge, and is used to define the "default" direction
26.824 - /// of the directed versions of the arcs.
26.825 + /// Edges don't have source and target nodes, however, methods
26.826 + /// u() and v() are used to query the two end-nodes of an edge.
26.827 + /// The orientation of an edge that arises this way is called
26.828 + /// the inherent direction, it is used to define the default
26.829 + /// direction for the corresponding arcs.
26.830 /// \sa v()
26.831 /// \sa direction()
26.832 Node u(Edge) const { return INVALID; }
26.833
26.834 - /// \brief Second node of the edge.
26.835 + /// \brief The second node of the edge.
26.836 ///
26.837 - /// \return The second node of the given edge.
26.838 + /// Returns the second node of the given edge.
26.839 ///
26.840 - /// Naturally edges don't have direction and thus
26.841 - /// don't have source and target node. However we use \c u() and \c v()
26.842 - /// methods to query the two nodes of the arc. The direction of the
26.843 - /// arc which arises this way is called the inherent direction of the
26.844 - /// edge, and is used to define the "default" direction
26.845 - /// of the directed versions of the arcs.
26.846 + /// Edges don't have source and target nodes, however, methods
26.847 + /// u() and v() are used to query the two end-nodes of an edge.
26.848 + /// The orientation of an edge that arises this way is called
26.849 + /// the inherent direction, it is used to define the default
26.850 + /// direction for the corresponding arcs.
26.851 /// \sa u()
26.852 /// \sa direction()
26.853 Node v(Edge) const { return INVALID; }
26.854
26.855 - /// \brief Source node of the directed arc.
26.856 + /// \brief The source node of the arc.
26.857 + ///
26.858 + /// Returns the source node of the given arc.
26.859 Node source(Arc) const { return INVALID; }
26.860
26.861 - /// \brief Target node of the directed arc.
26.862 + /// \brief The target node of the arc.
26.863 + ///
26.864 + /// Returns the target node of the given arc.
26.865 Node target(Arc) const { return INVALID; }
26.866
26.867 - /// \brief Returns the id of the node.
26.868 + /// \brief The ID of the node.
26.869 + ///
26.870 + /// Returns the ID of the given node.
26.871 int id(Node) const { return -1; }
26.872
26.873 - /// \brief Returns the id of the edge.
26.874 + /// \brief The ID of the edge.
26.875 + ///
26.876 + /// Returns the ID of the given edge.
26.877 int id(Edge) const { return -1; }
26.878
26.879 - /// \brief Returns the id of the arc.
26.880 + /// \brief The ID of the arc.
26.881 + ///
26.882 + /// Returns the ID of the given arc.
26.883 int id(Arc) const { return -1; }
26.884
26.885 - /// \brief Returns the node with the given id.
26.886 + /// \brief The node with the given ID.
26.887 ///
26.888 - /// \pre The argument should be a valid node id in the graph.
26.889 + /// Returns the node with the given ID.
26.890 + /// \pre The argument should be a valid node ID in the graph.
26.891 Node nodeFromId(int) const { return INVALID; }
26.892
26.893 - /// \brief Returns the edge with the given id.
26.894 + /// \brief The edge with the given ID.
26.895 ///
26.896 - /// \pre The argument should be a valid edge id in the graph.
26.897 + /// Returns the edge with the given ID.
26.898 + /// \pre The argument should be a valid edge ID in the graph.
26.899 Edge edgeFromId(int) const { return INVALID; }
26.900
26.901 - /// \brief Returns the arc with the given id.
26.902 + /// \brief The arc with the given ID.
26.903 ///
26.904 - /// \pre The argument should be a valid arc id in the graph.
26.905 + /// Returns the arc with the given ID.
26.906 + /// \pre The argument should be a valid arc ID in the graph.
26.907 Arc arcFromId(int) const { return INVALID; }
26.908
26.909 - /// \brief Returns an upper bound on the node IDs.
26.910 + /// \brief An upper bound on the node IDs.
26.911 + ///
26.912 + /// Returns an upper bound on the node IDs.
26.913 int maxNodeId() const { return -1; }
26.914
26.915 - /// \brief Returns an upper bound on the edge IDs.
26.916 + /// \brief An upper bound on the edge IDs.
26.917 + ///
26.918 + /// Returns an upper bound on the edge IDs.
26.919 int maxEdgeId() const { return -1; }
26.920
26.921 - /// \brief Returns an upper bound on the arc IDs.
26.922 + /// \brief An upper bound on the arc IDs.
26.923 + ///
26.924 + /// Returns an upper bound on the arc IDs.
26.925 int maxArcId() const { return -1; }
26.926
26.927 + /// \brief The direction of the arc.
26.928 + ///
26.929 + /// Returns \c true if the direction of the given arc is the same as
26.930 + /// the inherent orientation of the represented edge.
26.931 + bool direction(Arc) const { return true; }
26.932 +
26.933 + /// \brief Direct the edge.
26.934 + ///
26.935 + /// Direct the given edge. The returned arc
26.936 + /// represents the given edge and its direction comes
26.937 + /// from the bool parameter. If it is \c true, then the direction
26.938 + /// of the arc is the same as the inherent orientation of the edge.
26.939 + Arc direct(Edge, bool) const {
26.940 + return INVALID;
26.941 + }
26.942 +
26.943 + /// \brief Direct the edge.
26.944 + ///
26.945 + /// Direct the given edge. The returned arc represents the given
26.946 + /// edge and its source node is the given node.
26.947 + Arc direct(Edge, Node) const {
26.948 + return INVALID;
26.949 + }
26.950 +
26.951 + /// \brief The oppositely directed arc.
26.952 + ///
26.953 + /// Returns the oppositely directed arc representing the same edge.
26.954 + Arc oppositeArc(Arc) const { return INVALID; }
26.955 +
26.956 + /// \brief The opposite node on the edge.
26.957 + ///
26.958 + /// Returns the opposite node on the given edge.
26.959 + Node oppositeNode(Node, Edge) const { return INVALID; }
26.960 +
26.961 void first(Node&) const {}
26.962 void next(Node&) const {}
26.963
26.964 @@ -705,47 +733,39 @@
26.965 // Dummy parameter.
26.966 int maxId(Arc) const { return -1; }
26.967
26.968 - /// \brief Base node of the iterator
26.969 + /// \brief The base node of the iterator.
26.970 ///
26.971 - /// Returns the base node (the source in this case) of the iterator
26.972 - Node baseNode(OutArcIt e) const {
26.973 - return source(e);
26.974 - }
26.975 - /// \brief Running node of the iterator
26.976 + /// Returns the base node of the given incident edge iterator.
26.977 + Node baseNode(IncEdgeIt) const { return INVALID; }
26.978 +
26.979 + /// \brief The running node of the iterator.
26.980 ///
26.981 - /// Returns the running node (the target in this case) of the
26.982 - /// iterator
26.983 - Node runningNode(OutArcIt e) const {
26.984 - return target(e);
26.985 - }
26.986 + /// Returns the running node of the given incident edge iterator.
26.987 + Node runningNode(IncEdgeIt) const { return INVALID; }
26.988
26.989 - /// \brief Base node of the iterator
26.990 + /// \brief The base node of the iterator.
26.991 ///
26.992 - /// Returns the base node (the target in this case) of the iterator
26.993 - Node baseNode(InArcIt e) const {
26.994 - return target(e);
26.995 - }
26.996 - /// \brief Running node of the iterator
26.997 + /// Returns the base node of the given outgoing arc iterator
26.998 + /// (i.e. the source node of the corresponding arc).
26.999 + Node baseNode(OutArcIt) const { return INVALID; }
26.1000 +
26.1001 + /// \brief The running node of the iterator.
26.1002 ///
26.1003 - /// Returns the running node (the source in this case) of the
26.1004 - /// iterator
26.1005 - Node runningNode(InArcIt e) const {
26.1006 - return source(e);
26.1007 - }
26.1008 + /// Returns the running node of the given outgoing arc iterator
26.1009 + /// (i.e. the target node of the corresponding arc).
26.1010 + Node runningNode(OutArcIt) const { return INVALID; }
26.1011
26.1012 - /// \brief Base node of the iterator
26.1013 + /// \brief The base node of the iterator.
26.1014 ///
26.1015 - /// Returns the base node of the iterator
26.1016 - Node baseNode(IncEdgeIt) const {
26.1017 - return INVALID;
26.1018 - }
26.1019 + /// Returns the base node of the given incomming arc iterator
26.1020 + /// (i.e. the target node of the corresponding arc).
26.1021 + Node baseNode(InArcIt) const { return INVALID; }
26.1022
26.1023 - /// \brief Running node of the iterator
26.1024 + /// \brief The running node of the iterator.
26.1025 ///
26.1026 - /// Returns the running node of the iterator
26.1027 - Node runningNode(IncEdgeIt) const {
26.1028 - return INVALID;
26.1029 - }
26.1030 + /// Returns the running node of the given incomming arc iterator
26.1031 + /// (i.e. the source node of the corresponding arc).
26.1032 + Node runningNode(InArcIt) const { return INVALID; }
26.1033
26.1034 template <typename _Graph>
26.1035 struct Constraints {
27.1 --- a/lemon/concepts/graph_components.h Thu Dec 10 17:05:35 2009 +0100
27.2 +++ b/lemon/concepts/graph_components.h Thu Dec 10 17:18:25 2009 +0100
27.3 @@ -18,7 +18,7 @@
27.4
27.5 ///\ingroup graph_concepts
27.6 ///\file
27.7 -///\brief The concept of graph components.
27.8 +///\brief The concepts of graph components.
27.9
27.10 #ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H
27.11 #define LEMON_CONCEPTS_GRAPH_COMPONENTS_H
27.12 @@ -92,7 +92,7 @@
27.13 /// It makes possible to use graph item types as key types in
27.14 /// associative containers (e.g. \c std::map).
27.15 ///
27.16 - /// \note This operator only have to define some strict ordering of
27.17 + /// \note This operator only has to define some strict ordering of
27.18 /// the items; this order has nothing to do with the iteration
27.19 /// ordering of the items.
27.20 bool operator<(const GraphItem&) const { return false; }
28.1 --- a/lemon/concepts/heap.h Thu Dec 10 17:05:35 2009 +0100
28.2 +++ b/lemon/concepts/heap.h Thu Dec 10 17:18:25 2009 +0100
28.3 @@ -16,13 +16,13 @@
28.4 *
28.5 */
28.6
28.7 +#ifndef LEMON_CONCEPTS_HEAP_H
28.8 +#define LEMON_CONCEPTS_HEAP_H
28.9 +
28.10 ///\ingroup concept
28.11 ///\file
28.12 ///\brief The concept of heaps.
28.13
28.14 -#ifndef LEMON_CONCEPTS_HEAP_H
28.15 -#define LEMON_CONCEPTS_HEAP_H
28.16 -
28.17 #include <lemon/core.h>
28.18 #include <lemon/concept_check.h>
28.19
28.20 @@ -35,21 +35,27 @@
28.21
28.22 /// \brief The heap concept.
28.23 ///
28.24 - /// Concept class describing the main interface of heaps. A \e heap
28.25 - /// is a data structure for storing items with specified values called
28.26 - /// \e priorities in such a way that finding the item with minimum
28.27 - /// priority is efficient. In a heap one can change the priority of an
28.28 - /// item, add or erase an item, etc.
28.29 + /// This concept class describes the main interface of heaps.
28.30 + /// The various \ref heaps "heap structures" are efficient
28.31 + /// implementations of the abstract data type \e priority \e queue.
28.32 + /// They store items with specified values called \e priorities
28.33 + /// in such a way that finding and removing the item with minimum
28.34 + /// priority are efficient. The basic operations are adding and
28.35 + /// erasing items, changing the priority of an item, etc.
28.36 ///
28.37 - /// \tparam PR Type of the priority of the items.
28.38 - /// \tparam IM A read and writable item map with int values, used
28.39 + /// Heaps are crucial in several algorithms, such as Dijkstra and Prim.
28.40 + /// Any class that conforms to this concept can be used easily in such
28.41 + /// algorithms.
28.42 + ///
28.43 + /// \tparam PR Type of the priorities of the items.
28.44 + /// \tparam IM A read-writable item map with \c int values, used
28.45 /// internally to handle the cross references.
28.46 - /// \tparam Comp A functor class for the ordering of the priorities.
28.47 + /// \tparam CMP A functor class for comparing the priorities.
28.48 /// The default is \c std::less<PR>.
28.49 #ifdef DOXYGEN
28.50 - template <typename PR, typename IM, typename Comp = std::less<PR> >
28.51 + template <typename PR, typename IM, typename CMP>
28.52 #else
28.53 - template <typename PR, typename IM>
28.54 + template <typename PR, typename IM, typename CMP = std::less<PR> >
28.55 #endif
28.56 class Heap {
28.57 public:
28.58 @@ -64,109 +70,125 @@
28.59 /// \brief Type to represent the states of the items.
28.60 ///
28.61 /// Each item has a state associated to it. It can be "in heap",
28.62 - /// "pre heap" or "post heap". The later two are indifferent
28.63 - /// from the point of view of the heap, but may be useful for
28.64 - /// the user.
28.65 + /// "pre-heap" or "post-heap". The latter two are indifferent from the
28.66 + /// heap's point of view, but may be useful to the user.
28.67 ///
28.68 /// The item-int map must be initialized in such way that it assigns
28.69 /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
28.70 enum State {
28.71 IN_HEAP = 0, ///< = 0. The "in heap" state constant.
28.72 - PRE_HEAP = -1, ///< = -1. The "pre heap" state constant.
28.73 - POST_HEAP = -2 ///< = -2. The "post heap" state constant.
28.74 + PRE_HEAP = -1, ///< = -1. The "pre-heap" state constant.
28.75 + POST_HEAP = -2 ///< = -2. The "post-heap" state constant.
28.76 };
28.77
28.78 - /// \brief The constructor.
28.79 + /// \brief Constructor.
28.80 ///
28.81 - /// The constructor.
28.82 + /// Constructor.
28.83 /// \param map A map that assigns \c int values to keys of type
28.84 /// \c Item. It is used internally by the heap implementations to
28.85 /// handle the cross references. The assigned value must be
28.86 - /// \c PRE_HEAP (<tt>-1</tt>) for every item.
28.87 + /// \c PRE_HEAP (<tt>-1</tt>) for each item.
28.88 explicit Heap(ItemIntMap &map) {}
28.89
28.90 + /// \brief Constructor.
28.91 + ///
28.92 + /// Constructor.
28.93 + /// \param map A map that assigns \c int values to keys of type
28.94 + /// \c Item. It is used internally by the heap implementations to
28.95 + /// handle the cross references. The assigned value must be
28.96 + /// \c PRE_HEAP (<tt>-1</tt>) for each item.
28.97 + /// \param comp The function object used for comparing the priorities.
28.98 + explicit Heap(ItemIntMap &map, const CMP &comp) {}
28.99 +
28.100 /// \brief The number of items stored in the heap.
28.101 ///
28.102 - /// Returns the number of items stored in the heap.
28.103 + /// This function returns the number of items stored in the heap.
28.104 int size() const { return 0; }
28.105
28.106 - /// \brief Checks if the heap is empty.
28.107 + /// \brief Check if the heap is empty.
28.108 ///
28.109 - /// Returns \c true if the heap is empty.
28.110 + /// This function returns \c true if the heap is empty.
28.111 bool empty() const { return false; }
28.112
28.113 - /// \brief Makes the heap empty.
28.114 + /// \brief Make the heap empty.
28.115 ///
28.116 - /// Makes the heap empty.
28.117 - void clear();
28.118 + /// This functon makes the heap empty.
28.119 + /// It does not change the cross reference map. If you want to reuse
28.120 + /// a heap that is not surely empty, you should first clear it and
28.121 + /// then you should set the cross reference map to \c PRE_HEAP
28.122 + /// for each item.
28.123 + void clear() {}
28.124
28.125 - /// \brief Inserts an item into the heap with the given priority.
28.126 + /// \brief Insert an item into the heap with the given priority.
28.127 ///
28.128 - /// Inserts the given item into the heap with the given priority.
28.129 + /// This function inserts the given item into the heap with the
28.130 + /// given priority.
28.131 /// \param i The item to insert.
28.132 /// \param p The priority of the item.
28.133 + /// \pre \e i must not be stored in the heap.
28.134 void push(const Item &i, const Prio &p) {}
28.135
28.136 - /// \brief Returns the item having minimum priority.
28.137 + /// \brief Return the item having minimum priority.
28.138 ///
28.139 - /// Returns the item having minimum priority.
28.140 + /// This function returns the item having minimum priority.
28.141 /// \pre The heap must be non-empty.
28.142 Item top() const {}
28.143
28.144 /// \brief The minimum priority.
28.145 ///
28.146 - /// Returns the minimum priority.
28.147 + /// This function returns the minimum priority.
28.148 /// \pre The heap must be non-empty.
28.149 Prio prio() const {}
28.150
28.151 - /// \brief Removes the item having minimum priority.
28.152 + /// \brief Remove the item having minimum priority.
28.153 ///
28.154 - /// Removes the item having minimum priority.
28.155 + /// This function removes the item having minimum priority.
28.156 /// \pre The heap must be non-empty.
28.157 void pop() {}
28.158
28.159 - /// \brief Removes an item from the heap.
28.160 + /// \brief Remove the given item from the heap.
28.161 ///
28.162 - /// Removes the given item from the heap if it is already stored.
28.163 + /// This function removes the given item from the heap if it is
28.164 + /// already stored.
28.165 /// \param i The item to delete.
28.166 + /// \pre \e i must be in the heap.
28.167 void erase(const Item &i) {}
28.168
28.169 - /// \brief The priority of an item.
28.170 + /// \brief The priority of the given item.
28.171 ///
28.172 - /// Returns the priority of the given item.
28.173 + /// This function returns the priority of the given item.
28.174 /// \param i The item.
28.175 - /// \pre \c i must be in the heap.
28.176 + /// \pre \e i must be in the heap.
28.177 Prio operator[](const Item &i) const {}
28.178
28.179 - /// \brief Sets the priority of an item or inserts it, if it is
28.180 + /// \brief Set the priority of an item or insert it, if it is
28.181 /// not stored in the heap.
28.182 ///
28.183 /// This method sets the priority of the given item if it is
28.184 - /// already stored in the heap.
28.185 - /// Otherwise it inserts the given item with the given priority.
28.186 + /// already stored in the heap. Otherwise it inserts the given
28.187 + /// item into the heap with the given priority.
28.188 ///
28.189 /// \param i The item.
28.190 /// \param p The priority.
28.191 void set(const Item &i, const Prio &p) {}
28.192
28.193 - /// \brief Decreases the priority of an item to the given value.
28.194 + /// \brief Decrease the priority of an item to the given value.
28.195 ///
28.196 - /// Decreases the priority of an item to the given value.
28.197 + /// This function decreases the priority of an item to the given value.
28.198 /// \param i The item.
28.199 /// \param p The priority.
28.200 - /// \pre \c i must be stored in the heap with priority at least \c p.
28.201 + /// \pre \e i must be stored in the heap with priority at least \e p.
28.202 void decrease(const Item &i, const Prio &p) {}
28.203
28.204 - /// \brief Increases the priority of an item to the given value.
28.205 + /// \brief Increase the priority of an item to the given value.
28.206 ///
28.207 - /// Increases the priority of an item to the given value.
28.208 + /// This function increases the priority of an item to the given value.
28.209 /// \param i The item.
28.210 /// \param p The priority.
28.211 - /// \pre \c i must be stored in the heap with priority at most \c p.
28.212 + /// \pre \e i must be stored in the heap with priority at most \e p.
28.213 void increase(const Item &i, const Prio &p) {}
28.214
28.215 - /// \brief Returns if an item is in, has already been in, or has
28.216 - /// never been in the heap.
28.217 + /// \brief Return the state of an item.
28.218 ///
28.219 /// This method returns \c PRE_HEAP if the given item has never
28.220 /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
28.221 @@ -176,11 +198,11 @@
28.222 /// \param i The item.
28.223 State state(const Item &i) const {}
28.224
28.225 - /// \brief Sets the state of an item in the heap.
28.226 + /// \brief Set the state of an item in the heap.
28.227 ///
28.228 - /// Sets the state of the given item in the heap. It can be used
28.229 - /// to manually clear the heap when it is important to achive the
28.230 - /// better time complexity.
28.231 + /// This function sets the state of the given item in the heap.
28.232 + /// It can be used to manually clear the heap when it is important
28.233 + /// to achive better time complexity.
28.234 /// \param i The item.
28.235 /// \param st The state. It should not be \c IN_HEAP.
28.236 void state(const Item& i, State st) {}
29.1 --- a/lemon/concepts/path.h Thu Dec 10 17:05:35 2009 +0100
29.2 +++ b/lemon/concepts/path.h Thu Dec 10 17:18:25 2009 +0100
29.3 @@ -18,7 +18,7 @@
29.4
29.5 ///\ingroup concept
29.6 ///\file
29.7 -///\brief Classes for representing paths in digraphs.
29.8 +///\brief The concept of paths
29.9 ///
29.10
29.11 #ifndef LEMON_CONCEPTS_PATH_H
29.12 @@ -38,13 +38,22 @@
29.13 ///
29.14 /// A skeleton structure for representing directed paths in a
29.15 /// digraph.
29.16 + /// In a sense, a path can be treated as a list of arcs.
29.17 + /// LEMON path types just store this list. As a consequence, they cannot
29.18 + /// enumerate the nodes on the path directly and a zero length path
29.19 + /// cannot store its source node.
29.20 + ///
29.21 + /// The arcs of a path should be stored in the order of their directions,
29.22 + /// i.e. the target node of each arc should be the same as the source
29.23 + /// node of the next arc. This consistency could be checked using
29.24 + /// \ref checkPath().
29.25 + /// The source and target nodes of a (consistent) path can be obtained
29.26 + /// using \ref pathSource() and \ref pathTarget().
29.27 + ///
29.28 + /// A path can be constructed from another path of any type using the
29.29 + /// copy constructor or the assignment operator.
29.30 + ///
29.31 /// \tparam GR The digraph type in which the path is.
29.32 - ///
29.33 - /// In a sense, the path can be treated as a list of arcs. The
29.34 - /// lemon path type stores just this list. As a consequence it
29.35 - /// cannot enumerate the nodes in the path and the zero length
29.36 - /// paths cannot store the source.
29.37 - ///
29.38 template <typename GR>
29.39 class Path {
29.40 public:
29.41 @@ -59,18 +68,18 @@
29.42 /// \brief Default constructor
29.43 Path() {}
29.44
29.45 - /// \brief Template constructor
29.46 + /// \brief Template copy constructor
29.47 template <typename CPath>
29.48 Path(const CPath& cpath) {}
29.49
29.50 - /// \brief Template assigment
29.51 + /// \brief Template assigment operator
29.52 template <typename CPath>
29.53 Path& operator=(const CPath& cpath) {
29.54 ignore_unused_variable_warning(cpath);
29.55 return *this;
29.56 }
29.57
29.58 - /// Length of the path ie. the number of arcs in the path.
29.59 + /// Length of the path, i.e. the number of arcs on the path.
29.60 int length() const { return 0;}
29.61
29.62 /// Returns whether the path is empty.
29.63 @@ -79,19 +88,19 @@
29.64 /// Resets the path to an empty path.
29.65 void clear() {}
29.66
29.67 - /// \brief LEMON style iterator for path arcs
29.68 + /// \brief LEMON style iterator for enumerating the arcs of a path.
29.69 ///
29.70 - /// This class is used to iterate on the arcs of the paths.
29.71 + /// LEMON style iterator class for enumerating the arcs of a path.
29.72 class ArcIt {
29.73 public:
29.74 /// Default constructor
29.75 ArcIt() {}
29.76 /// Invalid constructor
29.77 ArcIt(Invalid) {}
29.78 - /// Constructor for first arc
29.79 + /// Sets the iterator to the first arc of the given path
29.80 ArcIt(const Path &) {}
29.81
29.82 - /// Conversion to Arc
29.83 + /// Conversion to \c Arc
29.84 operator Arc() const { return INVALID; }
29.85
29.86 /// Next arc
29.87 @@ -192,24 +201,18 @@
29.88 /// \brief A skeleton structure for path dumpers.
29.89 ///
29.90 /// A skeleton structure for path dumpers. The path dumpers are
29.91 - /// the generalization of the paths. The path dumpers can
29.92 - /// enumerate the arcs of the path wheter in forward or in
29.93 - /// backward order. In most time these classes are not used
29.94 - /// directly rather it used to assign a dumped class to a real
29.95 - /// path type.
29.96 + /// the generalization of the paths, they can enumerate the arcs
29.97 + /// of the path either in forward or in backward order.
29.98 + /// These classes are typically not used directly, they are rather
29.99 + /// used to be assigned to a real path type.
29.100 ///
29.101 /// The main purpose of this concept is that the shortest path
29.102 - /// algorithms can enumerate easily the arcs in reverse order.
29.103 - /// If we would like to give back a real path from these
29.104 - /// algorithms then we should create a temporarly path object. In
29.105 - /// LEMON such algorithms gives back a path dumper what can
29.106 - /// assigned to a real path and the dumpers can be implemented as
29.107 + /// algorithms can enumerate the arcs easily in reverse order.
29.108 + /// In LEMON, such algorithms give back a (reverse) path dumper that
29.109 + /// can be assigned to a real path. The dumpers can be implemented as
29.110 /// an adaptor class to the predecessor map.
29.111 ///
29.112 /// \tparam GR The digraph type in which the path is.
29.113 - ///
29.114 - /// The paths can be constructed from any path type by a
29.115 - /// template constructor or a template assignment operator.
29.116 template <typename GR>
29.117 class PathDumper {
29.118 public:
29.119 @@ -219,7 +222,7 @@
29.120 /// Arc type of the underlying digraph.
29.121 typedef typename Digraph::Arc Arc;
29.122
29.123 - /// Length of the path ie. the number of arcs in the path.
29.124 + /// Length of the path, i.e. the number of arcs on the path.
29.125 int length() const { return 0;}
29.126
29.127 /// Returns whether the path is empty.
29.128 @@ -227,25 +230,24 @@
29.129
29.130 /// \brief Forward or reverse dumping
29.131 ///
29.132 - /// If the RevPathTag is defined and true then reverse dumping
29.133 - /// is provided in the path dumper. In this case instead of the
29.134 - /// ArcIt the RevArcIt iterator should be implemented in the
29.135 - /// dumper.
29.136 + /// If this tag is defined to be \c True, then reverse dumping
29.137 + /// is provided in the path dumper. In this case, \c RevArcIt
29.138 + /// iterator should be implemented instead of \c ArcIt iterator.
29.139 typedef False RevPathTag;
29.140
29.141 - /// \brief LEMON style iterator for path arcs
29.142 + /// \brief LEMON style iterator for enumerating the arcs of a path.
29.143 ///
29.144 - /// This class is used to iterate on the arcs of the paths.
29.145 + /// LEMON style iterator class for enumerating the arcs of a path.
29.146 class ArcIt {
29.147 public:
29.148 /// Default constructor
29.149 ArcIt() {}
29.150 /// Invalid constructor
29.151 ArcIt(Invalid) {}
29.152 - /// Constructor for first arc
29.153 + /// Sets the iterator to the first arc of the given path
29.154 ArcIt(const PathDumper&) {}
29.155
29.156 - /// Conversion to Arc
29.157 + /// Conversion to \c Arc
29.158 operator Arc() const { return INVALID; }
29.159
29.160 /// Next arc
29.161 @@ -260,20 +262,21 @@
29.162
29.163 };
29.164
29.165 - /// \brief LEMON style iterator for path arcs
29.166 + /// \brief LEMON style iterator for enumerating the arcs of a path
29.167 + /// in reverse direction.
29.168 ///
29.169 - /// This class is used to iterate on the arcs of the paths in
29.170 - /// reverse direction.
29.171 + /// LEMON style iterator class for enumerating the arcs of a path
29.172 + /// in reverse direction.
29.173 class RevArcIt {
29.174 public:
29.175 /// Default constructor
29.176 RevArcIt() {}
29.177 /// Invalid constructor
29.178 RevArcIt(Invalid) {}
29.179 - /// Constructor for first arc
29.180 + /// Sets the iterator to the last arc of the given path
29.181 RevArcIt(const PathDumper &) {}
29.182
29.183 - /// Conversion to Arc
29.184 + /// Conversion to \c Arc
29.185 operator Arc() const { return INVALID; }
29.186
29.187 /// Next arc
30.1 --- a/lemon/counter.h Thu Dec 10 17:05:35 2009 +0100
30.2 +++ b/lemon/counter.h Thu Dec 10 17:18:25 2009 +0100
30.3 @@ -212,7 +212,7 @@
30.4
30.5 /// 'Do nothing' version of Counter.
30.6
30.7 - /// This class can be used in the same way as \ref Counter however it
30.8 + /// This class can be used in the same way as \ref Counter, but it
30.9 /// does not count at all and does not print report on destruction.
30.10 ///
30.11 /// Replacing a \ref Counter with a \ref NoCounter makes it possible
31.1 --- a/lemon/cplex.cc Thu Dec 10 17:05:35 2009 +0100
31.2 +++ b/lemon/cplex.cc Thu Dec 10 17:18:25 2009 +0100
31.3 @@ -111,6 +111,39 @@
31.4 return i;
31.5 }
31.6
31.7 + int CplexBase::_addRow(Value lb, ExprIterator b,
31.8 + ExprIterator e, Value ub) {
31.9 + int i = CPXgetnumrows(cplexEnv(), _prob);
31.10 + if (lb == -INF) {
31.11 + const char s = 'L';
31.12 + CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0);
31.13 + } else if (ub == INF) {
31.14 + const char s = 'G';
31.15 + CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
31.16 + } else if (lb == ub){
31.17 + const char s = 'E';
31.18 + CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
31.19 + } else {
31.20 + const char s = 'R';
31.21 + double len = ub - lb;
31.22 + CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, &len, 0);
31.23 + }
31.24 +
31.25 + std::vector<int> indices;
31.26 + std::vector<int> rowlist;
31.27 + std::vector<Value> values;
31.28 +
31.29 + for(ExprIterator it=b; it!=e; ++it) {
31.30 + indices.push_back(it->first);
31.31 + values.push_back(it->second);
31.32 + rowlist.push_back(i);
31.33 + }
31.34 +
31.35 + CPXchgcoeflist(cplexEnv(), _prob, values.size(),
31.36 + &rowlist.front(), &indices.front(), &values.front());
31.37 +
31.38 + return i;
31.39 + }
31.40
31.41 void CplexBase::_eraseCol(int i) {
31.42 CPXdelcols(cplexEnv(), _prob, i, i);
32.1 --- a/lemon/cplex.h Thu Dec 10 17:05:35 2009 +0100
32.2 +++ b/lemon/cplex.h Thu Dec 10 17:18:25 2009 +0100
32.3 @@ -93,6 +93,7 @@
32.4
32.5 virtual int _addCol();
32.6 virtual int _addRow();
32.7 + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
32.8
32.9 virtual void _eraseCol(int i);
32.10 virtual void _eraseRow(int i);
33.1 --- a/lemon/dfs.h Thu Dec 10 17:05:35 2009 +0100
33.2 +++ b/lemon/dfs.h Thu Dec 10 17:18:25 2009 +0100
33.3 @@ -47,7 +47,7 @@
33.4 ///
33.5 ///The type of the map that stores the predecessor
33.6 ///arcs of the %DFS paths.
33.7 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.8 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.9 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
33.10 ///Instantiates a \c PredMap.
33.11
33.12 @@ -62,7 +62,8 @@
33.13 ///The type of the map that indicates which nodes are processed.
33.14
33.15 ///The type of the map that indicates which nodes are processed.
33.16 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.17 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.18 + ///By default, it is a NullMap.
33.19 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
33.20 ///Instantiates a \c ProcessedMap.
33.21
33.22 @@ -81,7 +82,7 @@
33.23 ///The type of the map that indicates which nodes are reached.
33.24
33.25 ///The type of the map that indicates which nodes are reached.
33.26 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
33.27 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
33.28 typedef typename Digraph::template NodeMap<bool> ReachedMap;
33.29 ///Instantiates a \c ReachedMap.
33.30
33.31 @@ -96,7 +97,7 @@
33.32 ///The type of the map that stores the distances of the nodes.
33.33
33.34 ///The type of the map that stores the distances of the nodes.
33.35 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.36 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.37 typedef typename Digraph::template NodeMap<int> DistMap;
33.38 ///Instantiates a \c DistMap.
33.39
33.40 @@ -224,7 +225,7 @@
33.41 ///
33.42 ///\ref named-templ-param "Named parameter" for setting
33.43 ///\c PredMap type.
33.44 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.45 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.46 template <class T>
33.47 struct SetPredMap : public Dfs<Digraph, SetPredMapTraits<T> > {
33.48 typedef Dfs<Digraph, SetPredMapTraits<T> > Create;
33.49 @@ -244,7 +245,7 @@
33.50 ///
33.51 ///\ref named-templ-param "Named parameter" for setting
33.52 ///\c DistMap type.
33.53 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.54 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.55 template <class T>
33.56 struct SetDistMap : public Dfs< Digraph, SetDistMapTraits<T> > {
33.57 typedef Dfs<Digraph, SetDistMapTraits<T> > Create;
33.58 @@ -264,7 +265,7 @@
33.59 ///
33.60 ///\ref named-templ-param "Named parameter" for setting
33.61 ///\c ReachedMap type.
33.62 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
33.63 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
33.64 template <class T>
33.65 struct SetReachedMap : public Dfs< Digraph, SetReachedMapTraits<T> > {
33.66 typedef Dfs< Digraph, SetReachedMapTraits<T> > Create;
33.67 @@ -284,7 +285,7 @@
33.68 ///
33.69 ///\ref named-templ-param "Named parameter" for setting
33.70 ///\c ProcessedMap type.
33.71 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.72 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.73 template <class T>
33.74 struct SetProcessedMap : public Dfs< Digraph, SetProcessedMapTraits<T> > {
33.75 typedef Dfs< Digraph, SetProcessedMapTraits<T> > Create;
33.76 @@ -411,8 +412,8 @@
33.77 ///\name Execution Control
33.78 ///The simplest way to execute the DFS algorithm is to use one of the
33.79 ///member functions called \ref run(Node) "run()".\n
33.80 - ///If you need more control on the execution, first you have to call
33.81 - ///\ref init(), then you can add a source node with \ref addSource()
33.82 + ///If you need better control on the execution, you have to call
33.83 + ///\ref init() first, then you can add a source node with \ref addSource()
33.84 ///and perform the actual computation with \ref start().
33.85 ///This procedure can be repeated if there are nodes that have not
33.86 ///been reached.
33.87 @@ -632,12 +633,8 @@
33.88
33.89 ///Runs the algorithm to visit all nodes in the digraph.
33.90
33.91 - ///This method runs the %DFS algorithm in order to compute the
33.92 - ///%DFS path to each node.
33.93 - ///
33.94 - ///The algorithm computes
33.95 - ///- the %DFS tree (forest),
33.96 - ///- the distance of each node from the root(s) in the %DFS tree.
33.97 + ///This method runs the %DFS algorithm in order to visit all nodes
33.98 + ///in the digraph.
33.99 ///
33.100 ///\note <tt>d.run()</tt> is just a shortcut of the following code.
33.101 ///\code
33.102 @@ -669,9 +666,9 @@
33.103
33.104 ///@{
33.105
33.106 - ///The DFS path to a node.
33.107 + ///The DFS path to the given node.
33.108
33.109 - ///Returns the DFS path to a node.
33.110 + ///Returns the DFS path to the given node from the root(s).
33.111 ///
33.112 ///\warning \c t should be reached from the root(s).
33.113 ///
33.114 @@ -679,9 +676,9 @@
33.115 ///must be called before using this function.
33.116 Path path(Node t) const { return Path(*G, *_pred, t); }
33.117
33.118 - ///The distance of a node from the root(s).
33.119 + ///The distance of the given node from the root(s).
33.120
33.121 - ///Returns the distance of a node from the root(s).
33.122 + ///Returns the distance of the given node from the root(s).
33.123 ///
33.124 ///\warning If node \c v is not reached from the root(s), then
33.125 ///the return value of this function is undefined.
33.126 @@ -690,7 +687,7 @@
33.127 ///must be called before using this function.
33.128 int dist(Node v) const { return (*_dist)[v]; }
33.129
33.130 - ///Returns the 'previous arc' of the %DFS tree for a node.
33.131 + ///Returns the 'previous arc' of the %DFS tree for the given node.
33.132
33.133 ///This function returns the 'previous arc' of the %DFS tree for the
33.134 ///node \c v, i.e. it returns the last arc of a %DFS path from a
33.135 @@ -698,21 +695,21 @@
33.136 ///root(s) or if \c v is a root.
33.137 ///
33.138 ///The %DFS tree used here is equal to the %DFS tree used in
33.139 - ///\ref predNode().
33.140 + ///\ref predNode() and \ref predMap().
33.141 ///
33.142 ///\pre Either \ref run(Node) "run()" or \ref init()
33.143 ///must be called before using this function.
33.144 Arc predArc(Node v) const { return (*_pred)[v];}
33.145
33.146 - ///Returns the 'previous node' of the %DFS tree.
33.147 + ///Returns the 'previous node' of the %DFS tree for the given node.
33.148
33.149 ///This function returns the 'previous node' of the %DFS
33.150 ///tree for the node \c v, i.e. it returns the last but one node
33.151 - ///from a %DFS path from a root to \c v. It is \c INVALID
33.152 + ///of a %DFS path from a root to \c v. It is \c INVALID
33.153 ///if \c v is not reached from the root(s) or if \c v is a root.
33.154 ///
33.155 ///The %DFS tree used here is equal to the %DFS tree used in
33.156 - ///\ref predArc().
33.157 + ///\ref predArc() and \ref predMap().
33.158 ///
33.159 ///\pre Either \ref run(Node) "run()" or \ref init()
33.160 ///must be called before using this function.
33.161 @@ -733,13 +730,13 @@
33.162 ///predecessor arcs.
33.163 ///
33.164 ///Returns a const reference to the node map that stores the predecessor
33.165 - ///arcs, which form the DFS tree.
33.166 + ///arcs, which form the DFS tree (forest).
33.167 ///
33.168 ///\pre Either \ref run(Node) "run()" or \ref init()
33.169 ///must be called before using this function.
33.170 const PredMap &predMap() const { return *_pred;}
33.171
33.172 - ///Checks if a node is reached from the root(s).
33.173 + ///Checks if the given node. node is reached from the root(s).
33.174
33.175 ///Returns \c true if \c v is reached from the root(s).
33.176 ///
33.177 @@ -765,7 +762,7 @@
33.178 ///
33.179 ///The type of the map that stores the predecessor
33.180 ///arcs of the %DFS paths.
33.181 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.182 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.183 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
33.184 ///Instantiates a PredMap.
33.185
33.186 @@ -780,8 +777,8 @@
33.187 ///The type of the map that indicates which nodes are processed.
33.188
33.189 ///The type of the map that indicates which nodes are processed.
33.190 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.191 - ///By default it is a NullMap.
33.192 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.193 + ///By default, it is a NullMap.
33.194 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
33.195 ///Instantiates a ProcessedMap.
33.196
33.197 @@ -800,7 +797,7 @@
33.198 ///The type of the map that indicates which nodes are reached.
33.199
33.200 ///The type of the map that indicates which nodes are reached.
33.201 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
33.202 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
33.203 typedef typename Digraph::template NodeMap<bool> ReachedMap;
33.204 ///Instantiates a ReachedMap.
33.205
33.206 @@ -815,7 +812,7 @@
33.207 ///The type of the map that stores the distances of the nodes.
33.208
33.209 ///The type of the map that stores the distances of the nodes.
33.210 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.211 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.212 typedef typename Digraph::template NodeMap<int> DistMap;
33.213 ///Instantiates a DistMap.
33.214
33.215 @@ -830,18 +827,14 @@
33.216 ///The type of the DFS paths.
33.217
33.218 ///The type of the DFS paths.
33.219 - ///It must meet the \ref concepts::Path "Path" concept.
33.220 + ///It must conform to the \ref concepts::Path "Path" concept.
33.221 typedef lemon::Path<Digraph> Path;
33.222 };
33.223
33.224 /// Default traits class used by DfsWizard
33.225
33.226 - /// To make it easier to use Dfs algorithm
33.227 - /// we have created a wizard class.
33.228 - /// This \ref DfsWizard class needs default traits,
33.229 - /// as well as the \ref Dfs class.
33.230 - /// The \ref DfsWizardBase is a class to be the default traits of the
33.231 - /// \ref DfsWizard class.
33.232 + /// Default traits class used by DfsWizard.
33.233 + /// \tparam GR The type of the digraph.
33.234 template<class GR>
33.235 class DfsWizardBase : public DfsWizardDefaultTraits<GR>
33.236 {
33.237 @@ -869,7 +862,7 @@
33.238 public:
33.239 /// Constructor.
33.240
33.241 - /// This constructor does not require parameters, therefore it initiates
33.242 + /// This constructor does not require parameters, it initiates
33.243 /// all of the attributes to \c 0.
33.244 DfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
33.245 _dist(0), _path(0), _di(0) {}
33.246 @@ -899,7 +892,6 @@
33.247 {
33.248 typedef TR Base;
33.249
33.250 - ///The type of the digraph the algorithm runs on.
33.251 typedef typename TR::Digraph Digraph;
33.252
33.253 typedef typename Digraph::Node Node;
33.254 @@ -907,16 +899,10 @@
33.255 typedef typename Digraph::Arc Arc;
33.256 typedef typename Digraph::OutArcIt OutArcIt;
33.257
33.258 - ///\brief The type of the map that stores the predecessor
33.259 - ///arcs of the DFS paths.
33.260 typedef typename TR::PredMap PredMap;
33.261 - ///\brief The type of the map that stores the distances of the nodes.
33.262 typedef typename TR::DistMap DistMap;
33.263 - ///\brief The type of the map that indicates which nodes are reached.
33.264 typedef typename TR::ReachedMap ReachedMap;
33.265 - ///\brief The type of the map that indicates which nodes are processed.
33.266 typedef typename TR::ProcessedMap ProcessedMap;
33.267 - ///The type of the DFS paths
33.268 typedef typename TR::Path Path;
33.269
33.270 public:
33.271 @@ -986,8 +972,8 @@
33.272
33.273 ///Runs DFS algorithm to visit all nodes in the digraph.
33.274
33.275 - ///This method runs DFS algorithm in order to compute
33.276 - ///the DFS path to each node.
33.277 + ///This method runs DFS algorithm in order to visit all nodes
33.278 + ///in the digraph.
33.279 void run()
33.280 {
33.281 run(INVALID);
33.282 @@ -999,11 +985,12 @@
33.283 static PredMap *createPredMap(const Digraph &) { return 0; };
33.284 SetPredMapBase(const TR &b) : TR(b) {}
33.285 };
33.286 - ///\brief \ref named-func-param "Named parameter"
33.287 - ///for setting PredMap object.
33.288 +
33.289 + ///\brief \ref named-templ-param "Named parameter" for setting
33.290 + ///the predecessor map.
33.291 ///
33.292 - ///\ref named-func-param "Named parameter"
33.293 - ///for setting PredMap object.
33.294 + ///\ref named-templ-param "Named parameter" function for setting
33.295 + ///the map that stores the predecessor arcs of the nodes.
33.296 template<class T>
33.297 DfsWizard<SetPredMapBase<T> > predMap(const T &t)
33.298 {
33.299 @@ -1017,11 +1004,12 @@
33.300 static ReachedMap *createReachedMap(const Digraph &) { return 0; };
33.301 SetReachedMapBase(const TR &b) : TR(b) {}
33.302 };
33.303 - ///\brief \ref named-func-param "Named parameter"
33.304 - ///for setting ReachedMap object.
33.305 +
33.306 + ///\brief \ref named-templ-param "Named parameter" for setting
33.307 + ///the reached map.
33.308 ///
33.309 - /// \ref named-func-param "Named parameter"
33.310 - ///for setting ReachedMap object.
33.311 + ///\ref named-templ-param "Named parameter" function for setting
33.312 + ///the map that indicates which nodes are reached.
33.313 template<class T>
33.314 DfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
33.315 {
33.316 @@ -1035,11 +1023,13 @@
33.317 static DistMap *createDistMap(const Digraph &) { return 0; };
33.318 SetDistMapBase(const TR &b) : TR(b) {}
33.319 };
33.320 - ///\brief \ref named-func-param "Named parameter"
33.321 - ///for setting DistMap object.
33.322 +
33.323 + ///\brief \ref named-templ-param "Named parameter" for setting
33.324 + ///the distance map.
33.325 ///
33.326 - /// \ref named-func-param "Named parameter"
33.327 - ///for setting DistMap object.
33.328 + ///\ref named-templ-param "Named parameter" function for setting
33.329 + ///the map that stores the distances of the nodes calculated
33.330 + ///by the algorithm.
33.331 template<class T>
33.332 DfsWizard<SetDistMapBase<T> > distMap(const T &t)
33.333 {
33.334 @@ -1053,11 +1043,12 @@
33.335 static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
33.336 SetProcessedMapBase(const TR &b) : TR(b) {}
33.337 };
33.338 - ///\brief \ref named-func-param "Named parameter"
33.339 - ///for setting ProcessedMap object.
33.340 +
33.341 + ///\brief \ref named-func-param "Named parameter" for setting
33.342 + ///the processed map.
33.343 ///
33.344 - /// \ref named-func-param "Named parameter"
33.345 - ///for setting ProcessedMap object.
33.346 + ///\ref named-templ-param "Named parameter" function for setting
33.347 + ///the map that indicates which nodes are processed.
33.348 template<class T>
33.349 DfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
33.350 {
33.351 @@ -1208,7 +1199,7 @@
33.352 /// \brief The type of the map that indicates which nodes are reached.
33.353 ///
33.354 /// The type of the map that indicates which nodes are reached.
33.355 - /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
33.356 + /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
33.357 typedef typename Digraph::template NodeMap<bool> ReachedMap;
33.358
33.359 /// \brief Instantiates a ReachedMap.
33.360 @@ -1369,8 +1360,8 @@
33.361 /// \name Execution Control
33.362 /// The simplest way to execute the DFS algorithm is to use one of the
33.363 /// member functions called \ref run(Node) "run()".\n
33.364 - /// If you need more control on the execution, first you have to call
33.365 - /// \ref init(), then you can add a source node with \ref addSource()
33.366 + /// If you need better control on the execution, you have to call
33.367 + /// \ref init() first, then you can add a source node with \ref addSource()
33.368 /// and perform the actual computation with \ref start().
33.369 /// This procedure can be repeated if there are nodes that have not
33.370 /// been reached.
33.371 @@ -1583,12 +1574,8 @@
33.372
33.373 /// \brief Runs the algorithm to visit all nodes in the digraph.
33.374
33.375 - /// This method runs the %DFS algorithm in order to
33.376 - /// compute the %DFS path to each node.
33.377 - ///
33.378 - /// The algorithm computes
33.379 - /// - the %DFS tree (forest),
33.380 - /// - the distance of each node from the root(s) in the %DFS tree.
33.381 + /// This method runs the %DFS algorithm in order to visit all nodes
33.382 + /// in the digraph.
33.383 ///
33.384 /// \note <tt>d.run()</tt> is just a shortcut of the following code.
33.385 ///\code
33.386 @@ -1620,7 +1607,7 @@
33.387
33.388 ///@{
33.389
33.390 - /// \brief Checks if a node is reached from the root(s).
33.391 + /// \brief Checks if the given node is reached from the root(s).
33.392 ///
33.393 /// Returns \c true if \c v is reached from the root(s).
33.394 ///
34.1 --- a/lemon/dijkstra.h Thu Dec 10 17:05:35 2009 +0100
34.2 +++ b/lemon/dijkstra.h Thu Dec 10 17:18:25 2009 +0100
34.3 @@ -70,9 +70,9 @@
34.4 ///The type of the map that stores the arc lengths.
34.5
34.6 ///The type of the map that stores the arc lengths.
34.7 - ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
34.8 + ///It must conform to the \ref concepts::ReadMap "ReadMap" concept.
34.9 typedef LEN LengthMap;
34.10 - ///The type of the length of the arcs.
34.11 + ///The type of the arc lengths.
34.12 typedef typename LEN::Value Value;
34.13
34.14 /// Operation traits for %Dijkstra algorithm.
34.15 @@ -116,7 +116,7 @@
34.16 ///
34.17 ///The type of the map that stores the predecessor
34.18 ///arcs of the shortest paths.
34.19 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
34.20 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
34.21 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
34.22 ///Instantiates a \c PredMap.
34.23
34.24 @@ -131,8 +131,8 @@
34.25 ///The type of the map that indicates which nodes are processed.
34.26
34.27 ///The type of the map that indicates which nodes are processed.
34.28 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
34.29 - ///By default it is a NullMap.
34.30 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
34.31 + ///By default, it is a NullMap.
34.32 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
34.33 ///Instantiates a \c ProcessedMap.
34.34
34.35 @@ -151,7 +151,7 @@
34.36 ///The type of the map that stores the distances of the nodes.
34.37
34.38 ///The type of the map that stores the distances of the nodes.
34.39 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
34.40 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
34.41 typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap;
34.42 ///Instantiates a \c DistMap.
34.43
34.44 @@ -169,6 +169,10 @@
34.45 /// \ingroup shortest_path
34.46 ///This class provides an efficient implementation of the %Dijkstra algorithm.
34.47 ///
34.48 + ///The %Dijkstra algorithm solves the single-source shortest path problem
34.49 + ///when all arc lengths are non-negative. If there are negative lengths,
34.50 + ///the BellmanFord algorithm should be used instead.
34.51 + ///
34.52 ///The arc lengths are passed to the algorithm using a
34.53 ///\ref concepts::ReadMap "ReadMap",
34.54 ///so it is easy to change it to any kind of length.
34.55 @@ -201,8 +205,8 @@
34.56 ///The type of the digraph the algorithm runs on.
34.57 typedef typename TR::Digraph Digraph;
34.58
34.59 - ///The type of the length of the arcs.
34.60 - typedef typename TR::LengthMap::Value Value;
34.61 + ///The type of the arc lengths.
34.62 + typedef typename TR::Value Value;
34.63 ///The type of the map that stores the arc lengths.
34.64 typedef typename TR::LengthMap LengthMap;
34.65 ///\brief The type of the map that stores the predecessor arcs of the
34.66 @@ -304,7 +308,7 @@
34.67 ///
34.68 ///\ref named-templ-param "Named parameter" for setting
34.69 ///\c PredMap type.
34.70 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
34.71 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
34.72 template <class T>
34.73 struct SetPredMap
34.74 : public Dijkstra< Digraph, LengthMap, SetPredMapTraits<T> > {
34.75 @@ -325,7 +329,7 @@
34.76 ///
34.77 ///\ref named-templ-param "Named parameter" for setting
34.78 ///\c DistMap type.
34.79 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
34.80 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
34.81 template <class T>
34.82 struct SetDistMap
34.83 : public Dijkstra< Digraph, LengthMap, SetDistMapTraits<T> > {
34.84 @@ -346,7 +350,7 @@
34.85 ///
34.86 ///\ref named-templ-param "Named parameter" for setting
34.87 ///\c ProcessedMap type.
34.88 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
34.89 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
34.90 template <class T>
34.91 struct SetProcessedMap
34.92 : public Dijkstra< Digraph, LengthMap, SetProcessedMapTraits<T> > {
34.93 @@ -422,7 +426,7 @@
34.94 ///automatically created by the algorithm (i.e. the digraph should be
34.95 ///passed to the constructor of the cross reference and the cross
34.96 ///reference should be passed to the constructor of the heap).
34.97 - ///However external heap and cross reference objects could also be
34.98 + ///However, external heap and cross reference objects could also be
34.99 ///passed to the algorithm using the \ref heap() function before
34.100 ///calling \ref run(Node) "run()" or \ref init().
34.101 ///\sa SetHeap
34.102 @@ -443,6 +447,7 @@
34.103 ///
34.104 ///\ref named-templ-param "Named parameter" for setting
34.105 ///\c OperationTraits type.
34.106 + /// For more information, see \ref DijkstraDefaultOperationTraits.
34.107 template <class T>
34.108 struct SetOperationTraits
34.109 : public Dijkstra<Digraph, LengthMap, SetOperationTraitsTraits<T> > {
34.110 @@ -584,8 +589,8 @@
34.111 ///\name Execution Control
34.112 ///The simplest way to execute the %Dijkstra algorithm is to use
34.113 ///one of the member functions called \ref run(Node) "run()".\n
34.114 - ///If you need more control on the execution, first you have to call
34.115 - ///\ref init(), then you can add several source nodes with
34.116 + ///If you need better control on the execution, you have to call
34.117 + ///\ref init() first, then you can add several source nodes with
34.118 ///\ref addSource(). Finally the actual path computation can be
34.119 ///performed with one of the \ref start() functions.
34.120
34.121 @@ -801,14 +806,14 @@
34.122 ///\name Query Functions
34.123 ///The results of the %Dijkstra algorithm can be obtained using these
34.124 ///functions.\n
34.125 - ///Either \ref run(Node) "run()" or \ref start() should be called
34.126 + ///Either \ref run(Node) "run()" or \ref init() should be called
34.127 ///before using them.
34.128
34.129 ///@{
34.130
34.131 - ///The shortest path to a node.
34.132 + ///The shortest path to the given node.
34.133
34.134 - ///Returns the shortest path to a node.
34.135 + ///Returns the shortest path to the given node from the root(s).
34.136 ///
34.137 ///\warning \c t should be reached from the root(s).
34.138 ///
34.139 @@ -816,9 +821,9 @@
34.140 ///must be called before using this function.
34.141 Path path(Node t) const { return Path(*G, *_pred, t); }
34.142
34.143 - ///The distance of a node from the root(s).
34.144 + ///The distance of the given node from the root(s).
34.145
34.146 - ///Returns the distance of a node from the root(s).
34.147 + ///Returns the distance of the given node from the root(s).
34.148 ///
34.149 ///\warning If node \c v is not reached from the root(s), then
34.150 ///the return value of this function is undefined.
34.151 @@ -827,29 +832,31 @@
34.152 ///must be called before using this function.
34.153 Value dist(Node v) const { return (*_dist)[v]; }
34.154
34.155 - ///Returns the 'previous arc' of the shortest path tree for a node.
34.156 -
34.157 + ///\brief Returns the 'previous arc' of the shortest path tree for
34.158 + ///the given node.
34.159 + ///
34.160 ///This function returns the 'previous arc' of the shortest path
34.161 ///tree for the node \c v, i.e. it returns the last arc of a
34.162 ///shortest path from a root to \c v. It is \c INVALID if \c v
34.163 ///is not reached from the root(s) or if \c v is a root.
34.164 ///
34.165 ///The shortest path tree used here is equal to the shortest path
34.166 - ///tree used in \ref predNode().
34.167 + ///tree used in \ref predNode() and \ref predMap().
34.168 ///
34.169 ///\pre Either \ref run(Node) "run()" or \ref init()
34.170 ///must be called before using this function.
34.171 Arc predArc(Node v) const { return (*_pred)[v]; }
34.172
34.173 - ///Returns the 'previous node' of the shortest path tree for a node.
34.174 -
34.175 + ///\brief Returns the 'previous node' of the shortest path tree for
34.176 + ///the given node.
34.177 + ///
34.178 ///This function returns the 'previous node' of the shortest path
34.179 ///tree for the node \c v, i.e. it returns the last but one node
34.180 - ///from a shortest path from a root to \c v. It is \c INVALID
34.181 + ///of a shortest path from a root to \c v. It is \c INVALID
34.182 ///if \c v is not reached from the root(s) or if \c v is a root.
34.183 ///
34.184 ///The shortest path tree used here is equal to the shortest path
34.185 - ///tree used in \ref predArc().
34.186 + ///tree used in \ref predArc() and \ref predMap().
34.187 ///
34.188 ///\pre Either \ref run(Node) "run()" or \ref init()
34.189 ///must be called before using this function.
34.190 @@ -870,13 +877,13 @@
34.191 ///predecessor arcs.
34.192 ///
34.193 ///Returns a const reference to the node map that stores the predecessor
34.194 - ///arcs, which form the shortest path tree.
34.195 + ///arcs, which form the shortest path tree (forest).
34.196 ///
34.197 ///\pre Either \ref run(Node) "run()" or \ref init()
34.198 ///must be called before using this function.
34.199 const PredMap &predMap() const { return *_pred;}
34.200
34.201 - ///Checks if a node is reached from the root(s).
34.202 + ///Checks if the given node is reached from the root(s).
34.203
34.204 ///Returns \c true if \c v is reached from the root(s).
34.205 ///
34.206 @@ -895,9 +902,9 @@
34.207 bool processed(Node v) const { return (*_heap_cross_ref)[v] ==
34.208 Heap::POST_HEAP; }
34.209
34.210 - ///The current distance of a node from the root(s).
34.211 + ///The current distance of the given node from the root(s).
34.212
34.213 - ///Returns the current distance of a node from the root(s).
34.214 + ///Returns the current distance of the given node from the root(s).
34.215 ///It may be decreased in the following processes.
34.216 ///
34.217 ///\pre Either \ref run(Node) "run()" or \ref init()
34.218 @@ -924,9 +931,9 @@
34.219 ///The type of the map that stores the arc lengths.
34.220
34.221 ///The type of the map that stores the arc lengths.
34.222 - ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
34.223 + ///It must conform to the \ref concepts::ReadMap "ReadMap" concept.
34.224 typedef LEN LengthMap;
34.225 - ///The type of the length of the arcs.
34.226 + ///The type of the arc lengths.
34.227 typedef typename LEN::Value Value;
34.228
34.229 /// Operation traits for Dijkstra algorithm.
34.230 @@ -973,7 +980,7 @@
34.231 ///
34.232 ///The type of the map that stores the predecessor
34.233 ///arcs of the shortest paths.
34.234 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
34.235 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
34.236 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
34.237 ///Instantiates a PredMap.
34.238
34.239 @@ -988,8 +995,8 @@
34.240 ///The type of the map that indicates which nodes are processed.
34.241
34.242 ///The type of the map that indicates which nodes are processed.
34.243 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
34.244 - ///By default it is a NullMap.
34.245 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
34.246 + ///By default, it is a NullMap.
34.247 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
34.248 ///Instantiates a ProcessedMap.
34.249
34.250 @@ -1008,7 +1015,7 @@
34.251 ///The type of the map that stores the distances of the nodes.
34.252
34.253 ///The type of the map that stores the distances of the nodes.
34.254 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
34.255 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
34.256 typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap;
34.257 ///Instantiates a DistMap.
34.258
34.259 @@ -1023,18 +1030,15 @@
34.260 ///The type of the shortest paths.
34.261
34.262 ///The type of the shortest paths.
34.263 - ///It must meet the \ref concepts::Path "Path" concept.
34.264 + ///It must conform to the \ref concepts::Path "Path" concept.
34.265 typedef lemon::Path<Digraph> Path;
34.266 };
34.267
34.268 /// Default traits class used by DijkstraWizard
34.269
34.270 - /// To make it easier to use Dijkstra algorithm
34.271 - /// we have created a wizard class.
34.272 - /// This \ref DijkstraWizard class needs default traits,
34.273 - /// as well as the \ref Dijkstra class.
34.274 - /// The \ref DijkstraWizardBase is a class to be the default traits of the
34.275 - /// \ref DijkstraWizard class.
34.276 + /// Default traits class used by DijkstraWizard.
34.277 + /// \tparam GR The type of the digraph.
34.278 + /// \tparam LEN The type of the length map.
34.279 template<typename GR, typename LEN>
34.280 class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LEN>
34.281 {
34.282 @@ -1093,7 +1097,6 @@
34.283 {
34.284 typedef TR Base;
34.285
34.286 - ///The type of the digraph the algorithm runs on.
34.287 typedef typename TR::Digraph Digraph;
34.288
34.289 typedef typename Digraph::Node Node;
34.290 @@ -1101,20 +1104,12 @@
34.291 typedef typename Digraph::Arc Arc;
34.292 typedef typename Digraph::OutArcIt OutArcIt;
34.293
34.294 - ///The type of the map that stores the arc lengths.
34.295 typedef typename TR::LengthMap LengthMap;
34.296 - ///The type of the length of the arcs.
34.297 typedef typename LengthMap::Value Value;
34.298 - ///\brief The type of the map that stores the predecessor
34.299 - ///arcs of the shortest paths.
34.300 typedef typename TR::PredMap PredMap;
34.301 - ///The type of the map that stores the distances of the nodes.
34.302 typedef typename TR::DistMap DistMap;
34.303 - ///The type of the map that indicates which nodes are processed.
34.304 typedef typename TR::ProcessedMap ProcessedMap;
34.305 - ///The type of the shortest paths
34.306 typedef typename TR::Path Path;
34.307 - ///The heap type used by the dijkstra algorithm.
34.308 typedef typename TR::Heap Heap;
34.309
34.310 public:
34.311 @@ -1186,11 +1181,12 @@
34.312 static PredMap *createPredMap(const Digraph &) { return 0; };
34.313 SetPredMapBase(const TR &b) : TR(b) {}
34.314 };
34.315 - ///\brief \ref named-func-param "Named parameter"
34.316 - ///for setting PredMap object.
34.317 +
34.318 + ///\brief \ref named-templ-param "Named parameter" for setting
34.319 + ///the predecessor map.
34.320 ///
34.321 - ///\ref named-func-param "Named parameter"
34.322 - ///for setting PredMap object.
34.323 + ///\ref named-templ-param "Named parameter" function for setting
34.324 + ///the map that stores the predecessor arcs of the nodes.
34.325 template<class T>
34.326 DijkstraWizard<SetPredMapBase<T> > predMap(const T &t)
34.327 {
34.328 @@ -1204,11 +1200,13 @@
34.329 static DistMap *createDistMap(const Digraph &) { return 0; };
34.330 SetDistMapBase(const TR &b) : TR(b) {}
34.331 };
34.332 - ///\brief \ref named-func-param "Named parameter"
34.333 - ///for setting DistMap object.
34.334 +
34.335 + ///\brief \ref named-templ-param "Named parameter" for setting
34.336 + ///the distance map.
34.337 ///
34.338 - ///\ref named-func-param "Named parameter"
34.339 - ///for setting DistMap object.
34.340 + ///\ref named-templ-param "Named parameter" function for setting
34.341 + ///the map that stores the distances of the nodes calculated
34.342 + ///by the algorithm.
34.343 template<class T>
34.344 DijkstraWizard<SetDistMapBase<T> > distMap(const T &t)
34.345 {
34.346 @@ -1222,11 +1220,12 @@
34.347 static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
34.348 SetProcessedMapBase(const TR &b) : TR(b) {}
34.349 };
34.350 - ///\brief \ref named-func-param "Named parameter"
34.351 - ///for setting ProcessedMap object.
34.352 +
34.353 + ///\brief \ref named-func-param "Named parameter" for setting
34.354 + ///the processed map.
34.355 ///
34.356 - /// \ref named-func-param "Named parameter"
34.357 - ///for setting ProcessedMap object.
34.358 + ///\ref named-templ-param "Named parameter" function for setting
34.359 + ///the map that indicates which nodes are processed.
34.360 template<class T>
34.361 DijkstraWizard<SetProcessedMapBase<T> > processedMap(const T &t)
34.362 {
34.363 @@ -1239,6 +1238,7 @@
34.364 typedef T Path;
34.365 SetPathBase(const TR &b) : TR(b) {}
34.366 };
34.367 +
34.368 ///\brief \ref named-func-param "Named parameter"
34.369 ///for getting the shortest path to the target node.
34.370 ///
35.1 --- a/lemon/dim2.h Thu Dec 10 17:05:35 2009 +0100
35.2 +++ b/lemon/dim2.h Thu Dec 10 17:18:25 2009 +0100
35.3 @@ -21,16 +21,9 @@
35.4
35.5 #include <iostream>
35.6
35.7 -///\ingroup misc
35.8 +///\ingroup geomdat
35.9 ///\file
35.10 ///\brief A simple two dimensional vector and a bounding box implementation
35.11 -///
35.12 -/// The class \ref lemon::dim2::Point "dim2::Point" implements
35.13 -/// a two dimensional vector with the usual operations.
35.14 -///
35.15 -/// The class \ref lemon::dim2::Box "dim2::Box" can be used to determine
35.16 -/// the rectangular bounding box of a set of
35.17 -/// \ref lemon::dim2::Point "dim2::Point"'s.
35.18
35.19 namespace lemon {
35.20
35.21 @@ -40,7 +33,7 @@
35.22 ///tools for handling two dimensional coordinates
35.23 namespace dim2 {
35.24
35.25 - /// \addtogroup misc
35.26 + /// \addtogroup geomdat
35.27 /// @{
35.28
35.29 /// Two dimensional vector (plain vector)
36.1 --- a/lemon/edge_set.h Thu Dec 10 17:05:35 2009 +0100
36.2 +++ b/lemon/edge_set.h Thu Dec 10 17:18:25 2009 +0100
36.3 @@ -255,13 +255,14 @@
36.4 /// that node can be removed from the underlying graph, in this case
36.5 /// all arcs incident to the given node is erased from the arc set.
36.6 ///
36.7 + /// This class fully conforms to the \ref concepts::Digraph
36.8 + /// "Digraph" concept.
36.9 + /// It provides only linear time counting for nodes and arcs.
36.10 + ///
36.11 /// \param GR The type of the graph which shares its node set with
36.12 /// this class. Its interface must conform to the
36.13 /// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph"
36.14 /// concept.
36.15 - ///
36.16 - /// This class fully conforms to the \ref concepts::Digraph
36.17 - /// "Digraph" concept.
36.18 template <typename GR>
36.19 class ListArcSet : public ArcSetExtender<ListArcSetBase<GR> > {
36.20 typedef ArcSetExtender<ListArcSetBase<GR> > Parent;
36.21 @@ -685,13 +686,14 @@
36.22 /// be removed from the underlying graph, in this case all edges
36.23 /// incident to the given node is erased from the arc set.
36.24 ///
36.25 + /// This class fully conforms to the \ref concepts::Graph "Graph"
36.26 + /// concept.
36.27 + /// It provides only linear time counting for nodes, edges and arcs.
36.28 + ///
36.29 /// \param GR The type of the graph which shares its node set
36.30 /// with this class. Its interface must conform to the
36.31 /// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph"
36.32 /// concept.
36.33 - ///
36.34 - /// This class fully conforms to the \ref concepts::Graph "Graph"
36.35 - /// concept.
36.36 template <typename GR>
36.37 class ListEdgeSet : public EdgeSetExtender<ListEdgeSetBase<GR> > {
36.38 typedef EdgeSetExtender<ListEdgeSetBase<GR> > Parent;
36.39 @@ -867,7 +869,7 @@
36.40 arc.id = arcs.size() - 1;
36.41 }
36.42
36.43 - void next(Arc& arc) const {
36.44 + static void next(Arc& arc) {
36.45 --arc.id;
36.46 }
36.47
36.48 @@ -954,13 +956,14 @@
36.49 /// single-linked lists for enumerate outgoing and incoming
36.50 /// arcs. Therefore the arcs cannot be erased from the arc sets.
36.51 ///
36.52 + /// This class fully conforms to the \ref concepts::Digraph "Digraph"
36.53 + /// concept.
36.54 + /// It provides only linear time counting for nodes and arcs.
36.55 + ///
36.56 /// \warning If a node is erased from the underlying graph and this
36.57 /// node is the source or target of one arc in the arc set, then
36.58 /// the arc set is invalidated, and it cannot be used anymore. The
36.59 /// validity can be checked with the \c valid() member function.
36.60 - ///
36.61 - /// This class fully conforms to the \ref concepts::Digraph
36.62 - /// "Digraph" concept.
36.63 template <typename GR>
36.64 class SmartArcSet : public ArcSetExtender<SmartArcSetBase<GR> > {
36.65 typedef ArcSetExtender<SmartArcSetBase<GR> > Parent;
36.66 @@ -1173,7 +1176,7 @@
36.67 arc.id = arcs.size() - 1;
36.68 }
36.69
36.70 - void next(Arc& arc) const {
36.71 + static void next(Arc& arc) {
36.72 --arc.id;
36.73 }
36.74
36.75 @@ -1181,7 +1184,7 @@
36.76 arc.id = arcs.size() / 2 - 1;
36.77 }
36.78
36.79 - void next(Edge& arc) const {
36.80 + static void next(Edge& arc) {
36.81 --arc.id;
36.82 }
36.83
36.84 @@ -1304,13 +1307,14 @@
36.85 /// single-linked lists for enumerate incident edges. Therefore the
36.86 /// edges cannot be erased from the edge sets.
36.87 ///
36.88 + /// This class fully conforms to the \ref concepts::Graph "Graph"
36.89 + /// concept.
36.90 + /// It provides only linear time counting for nodes, edges and arcs.
36.91 + ///
36.92 /// \warning If a node is erased from the underlying graph and this
36.93 /// node is incident to one edge in the edge set, then the edge set
36.94 /// is invalidated, and it cannot be used anymore. The validity can
36.95 /// be checked with the \c valid() member function.
36.96 - ///
36.97 - /// This class fully conforms to the \ref concepts::Graph
36.98 - /// "Graph" concept.
36.99 template <typename GR>
36.100 class SmartEdgeSet : public EdgeSetExtender<SmartEdgeSetBase<GR> > {
36.101 typedef EdgeSetExtender<SmartEdgeSetBase<GR> > Parent;
37.1 --- a/lemon/fib_heap.h Thu Dec 10 17:05:35 2009 +0100
37.2 +++ b/lemon/fib_heap.h Thu Dec 10 17:18:25 2009 +0100
37.3 @@ -20,53 +20,49 @@
37.4 #define LEMON_FIB_HEAP_H
37.5
37.6 ///\file
37.7 -///\ingroup auxdat
37.8 -///\brief Fibonacci Heap implementation.
37.9 +///\ingroup heaps
37.10 +///\brief Fibonacci heap implementation.
37.11
37.12 #include <vector>
37.13 +#include <utility>
37.14 #include <functional>
37.15 #include <lemon/math.h>
37.16
37.17 namespace lemon {
37.18
37.19 - /// \ingroup auxdat
37.20 + /// \ingroup heaps
37.21 ///
37.22 - ///\brief Fibonacci Heap.
37.23 + /// \brief Fibonacci heap data structure.
37.24 ///
37.25 - ///This class implements the \e Fibonacci \e heap data structure. A \e heap
37.26 - ///is a data structure for storing items with specified values called \e
37.27 - ///priorities in such a way that finding the item with minimum priority is
37.28 - ///efficient. \c CMP specifies the ordering of the priorities. In a heap
37.29 - ///one can change the priority of an item, add or erase an item, etc.
37.30 + /// This class implements the \e Fibonacci \e heap data structure.
37.31 + /// It fully conforms to the \ref concepts::Heap "heap concept".
37.32 ///
37.33 - ///The methods \ref increase and \ref erase are not efficient in a Fibonacci
37.34 - ///heap. In case of many calls to these operations, it is better to use a
37.35 - ///\ref BinHeap "binary heap".
37.36 + /// The methods \ref increase() and \ref erase() are not efficient in a
37.37 + /// Fibonacci heap. In case of many calls of these operations, it is
37.38 + /// better to use other heap structure, e.g. \ref BinHeap "binary heap".
37.39 ///
37.40 - ///\param PRIO Type of the priority of the items.
37.41 - ///\param IM A read and writable Item int map, used internally
37.42 - ///to handle the cross references.
37.43 - ///\param CMP A class for the ordering of the priorities. The
37.44 - ///default is \c std::less<PRIO>.
37.45 - ///
37.46 - ///\sa BinHeap
37.47 - ///\sa Dijkstra
37.48 + /// \tparam PR Type of the priorities of the items.
37.49 + /// \tparam IM A read-writable item map with \c int values, used
37.50 + /// internally to handle the cross references.
37.51 + /// \tparam CMP A functor class for comparing the priorities.
37.52 + /// The default is \c std::less<PR>.
37.53 #ifdef DOXYGEN
37.54 - template <typename PRIO, typename IM, typename CMP>
37.55 + template <typename PR, typename IM, typename CMP>
37.56 #else
37.57 - template <typename PRIO, typename IM, typename CMP = std::less<PRIO> >
37.58 + template <typename PR, typename IM, typename CMP = std::less<PR> >
37.59 #endif
37.60 class FibHeap {
37.61 public:
37.62 - ///\e
37.63 +
37.64 + /// Type of the item-int map.
37.65 typedef IM ItemIntMap;
37.66 - ///\e
37.67 - typedef PRIO Prio;
37.68 - ///\e
37.69 + /// Type of the priorities.
37.70 + typedef PR Prio;
37.71 + /// Type of the items stored in the heap.
37.72 typedef typename ItemIntMap::Key Item;
37.73 - ///\e
37.74 + /// Type of the item-priority pairs.
37.75 typedef std::pair<Item,Prio> Pair;
37.76 - ///\e
37.77 + /// Functor type for comparing the priorities.
37.78 typedef CMP Compare;
37.79
37.80 private:
37.81 @@ -80,10 +76,10 @@
37.82
37.83 public:
37.84
37.85 - /// \brief Type to represent the items states.
37.86 + /// \brief Type to represent the states of the items.
37.87 ///
37.88 - /// Each Item element have a state associated to it. It may be "in heap",
37.89 - /// "pre heap" or "post heap". The latter two are indifferent from the
37.90 + /// Each item has a state associated to it. It can be "in heap",
37.91 + /// "pre-heap" or "post-heap". The latter two are indifferent from the
37.92 /// heap's point of view, but may be useful to the user.
37.93 ///
37.94 /// The item-int map must be initialized in such way that it assigns
37.95 @@ -94,60 +90,54 @@
37.96 POST_HEAP = -2 ///< = -2.
37.97 };
37.98
37.99 - /// \brief The constructor
37.100 + /// \brief Constructor.
37.101 ///
37.102 - /// \c map should be given to the constructor, since it is
37.103 - /// used internally to handle the cross references.
37.104 + /// Constructor.
37.105 + /// \param map A map that assigns \c int values to the items.
37.106 + /// It is used internally to handle the cross references.
37.107 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
37.108 explicit FibHeap(ItemIntMap &map)
37.109 : _minimum(0), _iim(map), _num() {}
37.110
37.111 - /// \brief The constructor
37.112 + /// \brief Constructor.
37.113 ///
37.114 - /// \c map should be given to the constructor, since it is used
37.115 - /// internally to handle the cross references. \c comp is an
37.116 - /// object for ordering of the priorities.
37.117 + /// Constructor.
37.118 + /// \param map A map that assigns \c int values to the items.
37.119 + /// It is used internally to handle the cross references.
37.120 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
37.121 + /// \param comp The function object used for comparing the priorities.
37.122 FibHeap(ItemIntMap &map, const Compare &comp)
37.123 : _minimum(0), _iim(map), _comp(comp), _num() {}
37.124
37.125 /// \brief The number of items stored in the heap.
37.126 ///
37.127 - /// Returns the number of items stored in the heap.
37.128 + /// This function returns the number of items stored in the heap.
37.129 int size() const { return _num; }
37.130
37.131 - /// \brief Checks if the heap stores no items.
37.132 + /// \brief Check if the heap is empty.
37.133 ///
37.134 - /// Returns \c true if and only if the heap stores no items.
37.135 + /// This function returns \c true if the heap is empty.
37.136 bool empty() const { return _num==0; }
37.137
37.138 - /// \brief Make empty this heap.
37.139 + /// \brief Make the heap empty.
37.140 ///
37.141 - /// Make empty this heap. It does not change the cross reference
37.142 - /// map. If you want to reuse a heap what is not surely empty you
37.143 - /// should first clear the heap and after that you should set the
37.144 - /// cross reference map for each item to \c PRE_HEAP.
37.145 + /// This functon makes the heap empty.
37.146 + /// It does not change the cross reference map. If you want to reuse
37.147 + /// a heap that is not surely empty, you should first clear it and
37.148 + /// then you should set the cross reference map to \c PRE_HEAP
37.149 + /// for each item.
37.150 void clear() {
37.151 _data.clear(); _minimum = 0; _num = 0;
37.152 }
37.153
37.154 - /// \brief \c item gets to the heap with priority \c value independently
37.155 - /// if \c item was already there.
37.156 + /// \brief Insert an item into the heap with the given priority.
37.157 ///
37.158 - /// This method calls \ref push(\c item, \c value) if \c item is not
37.159 - /// stored in the heap and it calls \ref decrease(\c item, \c value) or
37.160 - /// \ref increase(\c item, \c value) otherwise.
37.161 - void set (const Item& item, const Prio& value) {
37.162 - int i=_iim[item];
37.163 - if ( i >= 0 && _data[i].in ) {
37.164 - if ( _comp(value, _data[i].prio) ) decrease(item, value);
37.165 - if ( _comp(_data[i].prio, value) ) increase(item, value);
37.166 - } else push(item, value);
37.167 - }
37.168 -
37.169 - /// \brief Adds \c item to the heap with priority \c value.
37.170 - ///
37.171 - /// Adds \c item to the heap with priority \c value.
37.172 - /// \pre \c item must not be stored in the heap.
37.173 - void push (const Item& item, const Prio& value) {
37.174 + /// This function inserts the given item into the heap with the
37.175 + /// given priority.
37.176 + /// \param item The item to insert.
37.177 + /// \param prio The priority of the item.
37.178 + /// \pre \e item must not be stored in the heap.
37.179 + void push (const Item& item, const Prio& prio) {
37.180 int i=_iim[item];
37.181 if ( i < 0 ) {
37.182 int s=_data.size();
37.183 @@ -168,47 +158,37 @@
37.184 _data[i].right_neighbor=_data[_minimum].right_neighbor;
37.185 _data[_minimum].right_neighbor=i;
37.186 _data[i].left_neighbor=_minimum;
37.187 - if ( _comp( value, _data[_minimum].prio) ) _minimum=i;
37.188 + if ( _comp( prio, _data[_minimum].prio) ) _minimum=i;
37.189 } else {
37.190 _data[i].right_neighbor=_data[i].left_neighbor=i;
37.191 _minimum=i;
37.192 }
37.193 - _data[i].prio=value;
37.194 + _data[i].prio=prio;
37.195 ++_num;
37.196 }
37.197
37.198 - /// \brief Returns the item with minimum priority relative to \c Compare.
37.199 + /// \brief Return the item having minimum priority.
37.200 ///
37.201 - /// This method returns the item with minimum priority relative to \c
37.202 - /// Compare.
37.203 - /// \pre The heap must be nonempty.
37.204 + /// This function returns the item having minimum priority.
37.205 + /// \pre The heap must be non-empty.
37.206 Item top() const { return _data[_minimum].name; }
37.207
37.208 - /// \brief Returns the minimum priority relative to \c Compare.
37.209 + /// \brief The minimum priority.
37.210 ///
37.211 - /// It returns the minimum priority relative to \c Compare.
37.212 - /// \pre The heap must be nonempty.
37.213 - const Prio& prio() const { return _data[_minimum].prio; }
37.214 + /// This function returns the minimum priority.
37.215 + /// \pre The heap must be non-empty.
37.216 + Prio prio() const { return _data[_minimum].prio; }
37.217
37.218 - /// \brief Returns the priority of \c item.
37.219 + /// \brief Remove the item having minimum priority.
37.220 ///
37.221 - /// It returns the priority of \c item.
37.222 - /// \pre \c item must be in the heap.
37.223 - const Prio& operator[](const Item& item) const {
37.224 - return _data[_iim[item]].prio;
37.225 - }
37.226 -
37.227 - /// \brief Deletes the item with minimum priority relative to \c Compare.
37.228 - ///
37.229 - /// This method deletes the item with minimum priority relative to \c
37.230 - /// Compare from the heap.
37.231 + /// This function removes the item having minimum priority.
37.232 /// \pre The heap must be non-empty.
37.233 void pop() {
37.234 /*The first case is that there are only one root.*/
37.235 if ( _data[_minimum].left_neighbor==_minimum ) {
37.236 _data[_minimum].in=false;
37.237 if ( _data[_minimum].degree!=0 ) {
37.238 - makeroot(_data[_minimum].child);
37.239 + makeRoot(_data[_minimum].child);
37.240 _minimum=_data[_minimum].child;
37.241 balance();
37.242 }
37.243 @@ -221,7 +201,7 @@
37.244 int child=_data[_minimum].child;
37.245 int last_child=_data[child].left_neighbor;
37.246
37.247 - makeroot(child);
37.248 + makeRoot(child);
37.249
37.250 _data[left].right_neighbor=child;
37.251 _data[child].left_neighbor=left;
37.252 @@ -234,10 +214,12 @@
37.253 --_num;
37.254 }
37.255
37.256 - /// \brief Deletes \c item from the heap.
37.257 + /// \brief Remove the given item from the heap.
37.258 ///
37.259 - /// This method deletes \c item from the heap, if \c item was already
37.260 - /// stored in the heap. It is quite inefficient in Fibonacci heaps.
37.261 + /// This function removes the given item from the heap if it is
37.262 + /// already stored.
37.263 + /// \param item The item to delete.
37.264 + /// \pre \e item must be in the heap.
37.265 void erase (const Item& item) {
37.266 int i=_iim[item];
37.267
37.268 @@ -252,43 +234,68 @@
37.269 }
37.270 }
37.271
37.272 - /// \brief Decreases the priority of \c item to \c value.
37.273 + /// \brief The priority of the given item.
37.274 ///
37.275 - /// This method decreases the priority of \c item to \c value.
37.276 - /// \pre \c item must be stored in the heap with priority at least \c
37.277 - /// value relative to \c Compare.
37.278 - void decrease (Item item, const Prio& value) {
37.279 + /// This function returns the priority of the given item.
37.280 + /// \param item The item.
37.281 + /// \pre \e item must be in the heap.
37.282 + Prio operator[](const Item& item) const {
37.283 + return _data[_iim[item]].prio;
37.284 + }
37.285 +
37.286 + /// \brief Set the priority of an item or insert it, if it is
37.287 + /// not stored in the heap.
37.288 + ///
37.289 + /// This method sets the priority of the given item if it is
37.290 + /// already stored in the heap. Otherwise it inserts the given
37.291 + /// item into the heap with the given priority.
37.292 + /// \param item The item.
37.293 + /// \param prio The priority.
37.294 + void set (const Item& item, const Prio& prio) {
37.295 int i=_iim[item];
37.296 - _data[i].prio=value;
37.297 + if ( i >= 0 && _data[i].in ) {
37.298 + if ( _comp(prio, _data[i].prio) ) decrease(item, prio);
37.299 + if ( _comp(_data[i].prio, prio) ) increase(item, prio);
37.300 + } else push(item, prio);
37.301 + }
37.302 +
37.303 + /// \brief Decrease the priority of an item to the given value.
37.304 + ///
37.305 + /// This function decreases the priority of an item to the given value.
37.306 + /// \param item The item.
37.307 + /// \param prio The priority.
37.308 + /// \pre \e item must be stored in the heap with priority at least \e prio.
37.309 + void decrease (const Item& item, const Prio& prio) {
37.310 + int i=_iim[item];
37.311 + _data[i].prio=prio;
37.312 int p=_data[i].parent;
37.313
37.314 - if ( p!=-1 && _comp(value, _data[p].prio) ) {
37.315 + if ( p!=-1 && _comp(prio, _data[p].prio) ) {
37.316 cut(i,p);
37.317 cascade(p);
37.318 }
37.319 - if ( _comp(value, _data[_minimum].prio) ) _minimum=i;
37.320 + if ( _comp(prio, _data[_minimum].prio) ) _minimum=i;
37.321 }
37.322
37.323 - /// \brief Increases the priority of \c item to \c value.
37.324 + /// \brief Increase the priority of an item to the given value.
37.325 ///
37.326 - /// This method sets the priority of \c item to \c value. Though
37.327 - /// there is no precondition on the priority of \c item, this
37.328 - /// method should be used only if it is indeed necessary to increase
37.329 - /// (relative to \c Compare) the priority of \c item, because this
37.330 - /// method is inefficient.
37.331 - void increase (Item item, const Prio& value) {
37.332 + /// This function increases the priority of an item to the given value.
37.333 + /// \param item The item.
37.334 + /// \param prio The priority.
37.335 + /// \pre \e item must be stored in the heap with priority at most \e prio.
37.336 + void increase (const Item& item, const Prio& prio) {
37.337 erase(item);
37.338 - push(item, value);
37.339 + push(item, prio);
37.340 }
37.341
37.342 -
37.343 - /// \brief Returns if \c item is in, has already been in, or has never
37.344 - /// been in the heap.
37.345 + /// \brief Return the state of an item.
37.346 ///
37.347 - /// This method returns PRE_HEAP if \c item has never been in the
37.348 - /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
37.349 - /// otherwise. In the latter case it is possible that \c item will
37.350 - /// get back to the heap again.
37.351 + /// This method returns \c PRE_HEAP if the given item has never
37.352 + /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
37.353 + /// and \c POST_HEAP otherwise.
37.354 + /// In the latter case it is possible that the item will get back
37.355 + /// to the heap again.
37.356 + /// \param item The item.
37.357 State state(const Item &item) const {
37.358 int i=_iim[item];
37.359 if( i>=0 ) {
37.360 @@ -298,11 +305,11 @@
37.361 return State(i);
37.362 }
37.363
37.364 - /// \brief Sets the state of the \c item in the heap.
37.365 + /// \brief Set the state of an item in the heap.
37.366 ///
37.367 - /// Sets the state of the \c item in the heap. It can be used to
37.368 - /// manually clear the heap when it is important to achive the
37.369 - /// better time _complexity.
37.370 + /// This function sets the state of the given item in the heap.
37.371 + /// It can be used to manually clear the heap when it is important
37.372 + /// to achive better time complexity.
37.373 /// \param i The item.
37.374 /// \param st The state. It should not be \c IN_HEAP.
37.375 void state(const Item& i, State st) {
37.376 @@ -365,7 +372,7 @@
37.377 } while ( s != m );
37.378 }
37.379
37.380 - void makeroot(int c) {
37.381 + void makeRoot(int c) {
37.382 int s=c;
37.383 do {
37.384 _data[s].parent=-1;
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
38.2 +++ b/lemon/fourary_heap.h Thu Dec 10 17:18:25 2009 +0100
38.3 @@ -0,0 +1,342 @@
38.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
38.5 + *
38.6 + * This file is a part of LEMON, a generic C++ optimization library.
38.7 + *
38.8 + * Copyright (C) 2003-2009
38.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
38.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
38.11 + *
38.12 + * Permission to use, modify and distribute this software is granted
38.13 + * provided that this copyright notice appears in all copies. For
38.14 + * precise terms see the accompanying LICENSE file.
38.15 + *
38.16 + * This software is provided "AS IS" with no warranty of any kind,
38.17 + * express or implied, and with no claim as to its suitability for any
38.18 + * purpose.
38.19 + *
38.20 + */
38.21 +
38.22 +#ifndef LEMON_FOURARY_HEAP_H
38.23 +#define LEMON_FOURARY_HEAP_H
38.24 +
38.25 +///\ingroup heaps
38.26 +///\file
38.27 +///\brief Fourary heap implementation.
38.28 +
38.29 +#include <vector>
38.30 +#include <utility>
38.31 +#include <functional>
38.32 +
38.33 +namespace lemon {
38.34 +
38.35 + /// \ingroup heaps
38.36 + ///
38.37 + ///\brief Fourary heap data structure.
38.38 + ///
38.39 + /// This class implements the \e fourary \e heap data structure.
38.40 + /// It fully conforms to the \ref concepts::Heap "heap concept".
38.41 + ///
38.42 + /// The fourary heap is a specialization of the \ref KaryHeap "K-ary heap"
38.43 + /// for <tt>K=4</tt>. It is similar to the \ref BinHeap "binary heap",
38.44 + /// but its nodes have at most four children, instead of two.
38.45 + ///
38.46 + /// \tparam PR Type of the priorities of the items.
38.47 + /// \tparam IM A read-writable item map with \c int values, used
38.48 + /// internally to handle the cross references.
38.49 + /// \tparam CMP A functor class for comparing the priorities.
38.50 + /// The default is \c std::less<PR>.
38.51 + ///
38.52 + ///\sa BinHeap
38.53 + ///\sa KaryHeap
38.54 +#ifdef DOXYGEN
38.55 + template <typename PR, typename IM, typename CMP>
38.56 +#else
38.57 + template <typename PR, typename IM, typename CMP = std::less<PR> >
38.58 +#endif
38.59 + class FouraryHeap {
38.60 + public:
38.61 + /// Type of the item-int map.
38.62 + typedef IM ItemIntMap;
38.63 + /// Type of the priorities.
38.64 + typedef PR Prio;
38.65 + /// Type of the items stored in the heap.
38.66 + typedef typename ItemIntMap::Key Item;
38.67 + /// Type of the item-priority pairs.
38.68 + typedef std::pair<Item,Prio> Pair;
38.69 + /// Functor type for comparing the priorities.
38.70 + typedef CMP Compare;
38.71 +
38.72 + /// \brief Type to represent the states of the items.
38.73 + ///
38.74 + /// Each item has a state associated to it. It can be "in heap",
38.75 + /// "pre-heap" or "post-heap". The latter two are indifferent from the
38.76 + /// heap's point of view, but may be useful to the user.
38.77 + ///
38.78 + /// The item-int map must be initialized in such way that it assigns
38.79 + /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
38.80 + enum State {
38.81 + IN_HEAP = 0, ///< = 0.
38.82 + PRE_HEAP = -1, ///< = -1.
38.83 + POST_HEAP = -2 ///< = -2.
38.84 + };
38.85 +
38.86 + private:
38.87 + std::vector<Pair> _data;
38.88 + Compare _comp;
38.89 + ItemIntMap &_iim;
38.90 +
38.91 + public:
38.92 + /// \brief Constructor.
38.93 + ///
38.94 + /// Constructor.
38.95 + /// \param map A map that assigns \c int values to the items.
38.96 + /// It is used internally to handle the cross references.
38.97 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
38.98 + explicit FouraryHeap(ItemIntMap &map) : _iim(map) {}
38.99 +
38.100 + /// \brief Constructor.
38.101 + ///
38.102 + /// Constructor.
38.103 + /// \param map A map that assigns \c int values to the items.
38.104 + /// It is used internally to handle the cross references.
38.105 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
38.106 + /// \param comp The function object used for comparing the priorities.
38.107 + FouraryHeap(ItemIntMap &map, const Compare &comp)
38.108 + : _iim(map), _comp(comp) {}
38.109 +
38.110 + /// \brief The number of items stored in the heap.
38.111 + ///
38.112 + /// This function returns the number of items stored in the heap.
38.113 + int size() const { return _data.size(); }
38.114 +
38.115 + /// \brief Check if the heap is empty.
38.116 + ///
38.117 + /// This function returns \c true if the heap is empty.
38.118 + bool empty() const { return _data.empty(); }
38.119 +
38.120 + /// \brief Make the heap empty.
38.121 + ///
38.122 + /// This functon makes the heap empty.
38.123 + /// It does not change the cross reference map. If you want to reuse
38.124 + /// a heap that is not surely empty, you should first clear it and
38.125 + /// then you should set the cross reference map to \c PRE_HEAP
38.126 + /// for each item.
38.127 + void clear() { _data.clear(); }
38.128 +
38.129 + private:
38.130 + static int parent(int i) { return (i-1)/4; }
38.131 + static int firstChild(int i) { return 4*i+1; }
38.132 +
38.133 + bool less(const Pair &p1, const Pair &p2) const {
38.134 + return _comp(p1.second, p2.second);
38.135 + }
38.136 +
38.137 + void bubbleUp(int hole, Pair p) {
38.138 + int par = parent(hole);
38.139 + while( hole>0 && less(p,_data[par]) ) {
38.140 + move(_data[par],hole);
38.141 + hole = par;
38.142 + par = parent(hole);
38.143 + }
38.144 + move(p, hole);
38.145 + }
38.146 +
38.147 + void bubbleDown(int hole, Pair p, int length) {
38.148 + if( length>1 ) {
38.149 + int child = firstChild(hole);
38.150 + while( child+3<length ) {
38.151 + int min=child;
38.152 + if( less(_data[++child], _data[min]) ) min=child;
38.153 + if( less(_data[++child], _data[min]) ) min=child;
38.154 + if( less(_data[++child], _data[min]) ) min=child;
38.155 + if( !less(_data[min], p) )
38.156 + goto ok;
38.157 + move(_data[min], hole);
38.158 + hole = min;
38.159 + child = firstChild(hole);
38.160 + }
38.161 + if ( child<length ) {
38.162 + int min = child;
38.163 + if( ++child<length && less(_data[child], _data[min]) ) min=child;
38.164 + if( ++child<length && less(_data[child], _data[min]) ) min=child;
38.165 + if( less(_data[min], p) ) {
38.166 + move(_data[min], hole);
38.167 + hole = min;
38.168 + }
38.169 + }
38.170 + }
38.171 + ok:
38.172 + move(p, hole);
38.173 + }
38.174 +
38.175 + void move(const Pair &p, int i) {
38.176 + _data[i] = p;
38.177 + _iim.set(p.first, i);
38.178 + }
38.179 +
38.180 + public:
38.181 + /// \brief Insert a pair of item and priority into the heap.
38.182 + ///
38.183 + /// This function inserts \c p.first to the heap with priority
38.184 + /// \c p.second.
38.185 + /// \param p The pair to insert.
38.186 + /// \pre \c p.first must not be stored in the heap.
38.187 + void push(const Pair &p) {
38.188 + int n = _data.size();
38.189 + _data.resize(n+1);
38.190 + bubbleUp(n, p);
38.191 + }
38.192 +
38.193 + /// \brief Insert an item into the heap with the given priority.
38.194 + ///
38.195 + /// This function inserts the given item into the heap with the
38.196 + /// given priority.
38.197 + /// \param i The item to insert.
38.198 + /// \param p The priority of the item.
38.199 + /// \pre \e i must not be stored in the heap.
38.200 + void push(const Item &i, const Prio &p) { push(Pair(i,p)); }
38.201 +
38.202 + /// \brief Return the item having minimum priority.
38.203 + ///
38.204 + /// This function returns the item having minimum priority.
38.205 + /// \pre The heap must be non-empty.
38.206 + Item top() const { return _data[0].first; }
38.207 +
38.208 + /// \brief The minimum priority.
38.209 + ///
38.210 + /// This function returns the minimum priority.
38.211 + /// \pre The heap must be non-empty.
38.212 + Prio prio() const { return _data[0].second; }
38.213 +
38.214 + /// \brief Remove the item having minimum priority.
38.215 + ///
38.216 + /// This function removes the item having minimum priority.
38.217 + /// \pre The heap must be non-empty.
38.218 + void pop() {
38.219 + int n = _data.size()-1;
38.220 + _iim.set(_data[0].first, POST_HEAP);
38.221 + if (n>0) bubbleDown(0, _data[n], n);
38.222 + _data.pop_back();
38.223 + }
38.224 +
38.225 + /// \brief Remove the given item from the heap.
38.226 + ///
38.227 + /// This function removes the given item from the heap if it is
38.228 + /// already stored.
38.229 + /// \param i The item to delete.
38.230 + /// \pre \e i must be in the heap.
38.231 + void erase(const Item &i) {
38.232 + int h = _iim[i];
38.233 + int n = _data.size()-1;
38.234 + _iim.set(_data[h].first, POST_HEAP);
38.235 + if( h<n ) {
38.236 + if( less(_data[parent(h)], _data[n]) )
38.237 + bubbleDown(h, _data[n], n);
38.238 + else
38.239 + bubbleUp(h, _data[n]);
38.240 + }
38.241 + _data.pop_back();
38.242 + }
38.243 +
38.244 + /// \brief The priority of the given item.
38.245 + ///
38.246 + /// This function returns the priority of the given item.
38.247 + /// \param i The item.
38.248 + /// \pre \e i must be in the heap.
38.249 + Prio operator[](const Item &i) const {
38.250 + int idx = _iim[i];
38.251 + return _data[idx].second;
38.252 + }
38.253 +
38.254 + /// \brief Set the priority of an item or insert it, if it is
38.255 + /// not stored in the heap.
38.256 + ///
38.257 + /// This method sets the priority of the given item if it is
38.258 + /// already stored in the heap. Otherwise it inserts the given
38.259 + /// item into the heap with the given priority.
38.260 + /// \param i The item.
38.261 + /// \param p The priority.
38.262 + void set(const Item &i, const Prio &p) {
38.263 + int idx = _iim[i];
38.264 + if( idx < 0 )
38.265 + push(i,p);
38.266 + else if( _comp(p, _data[idx].second) )
38.267 + bubbleUp(idx, Pair(i,p));
38.268 + else
38.269 + bubbleDown(idx, Pair(i,p), _data.size());
38.270 + }
38.271 +
38.272 + /// \brief Decrease the priority of an item to the given value.
38.273 + ///
38.274 + /// This function decreases the priority of an item to the given value.
38.275 + /// \param i The item.
38.276 + /// \param p The priority.
38.277 + /// \pre \e i must be stored in the heap with priority at least \e p.
38.278 + void decrease(const Item &i, const Prio &p) {
38.279 + int idx = _iim[i];
38.280 + bubbleUp(idx, Pair(i,p));
38.281 + }
38.282 +
38.283 + /// \brief Increase the priority of an item to the given value.
38.284 + ///
38.285 + /// This function increases the priority of an item to the given value.
38.286 + /// \param i The item.
38.287 + /// \param p The priority.
38.288 + /// \pre \e i must be stored in the heap with priority at most \e p.
38.289 + void increase(const Item &i, const Prio &p) {
38.290 + int idx = _iim[i];
38.291 + bubbleDown(idx, Pair(i,p), _data.size());
38.292 + }
38.293 +
38.294 + /// \brief Return the state of an item.
38.295 + ///
38.296 + /// This method returns \c PRE_HEAP if the given item has never
38.297 + /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
38.298 + /// and \c POST_HEAP otherwise.
38.299 + /// In the latter case it is possible that the item will get back
38.300 + /// to the heap again.
38.301 + /// \param i The item.
38.302 + State state(const Item &i) const {
38.303 + int s = _iim[i];
38.304 + if (s>=0) s=0;
38.305 + return State(s);
38.306 + }
38.307 +
38.308 + /// \brief Set the state of an item in the heap.
38.309 + ///
38.310 + /// This function sets the state of the given item in the heap.
38.311 + /// It can be used to manually clear the heap when it is important
38.312 + /// to achive better time complexity.
38.313 + /// \param i The item.
38.314 + /// \param st The state. It should not be \c IN_HEAP.
38.315 + void state(const Item& i, State st) {
38.316 + switch (st) {
38.317 + case POST_HEAP:
38.318 + case PRE_HEAP:
38.319 + if (state(i) == IN_HEAP) erase(i);
38.320 + _iim[i] = st;
38.321 + break;
38.322 + case IN_HEAP:
38.323 + break;
38.324 + }
38.325 + }
38.326 +
38.327 + /// \brief Replace an item in the heap.
38.328 + ///
38.329 + /// This function replaces item \c i with item \c j.
38.330 + /// Item \c i must be in the heap, while \c j must be out of the heap.
38.331 + /// After calling this method, item \c i will be out of the
38.332 + /// heap and \c j will be in the heap with the same prioriority
38.333 + /// as item \c i had before.
38.334 + void replace(const Item& i, const Item& j) {
38.335 + int idx = _iim[i];
38.336 + _iim.set(i, _iim[j]);
38.337 + _iim.set(j, idx);
38.338 + _data[idx].first = j;
38.339 + }
38.340 +
38.341 + }; // class FouraryHeap
38.342 +
38.343 +} // namespace lemon
38.344 +
38.345 +#endif // LEMON_FOURARY_HEAP_H
39.1 --- a/lemon/full_graph.h Thu Dec 10 17:05:35 2009 +0100
39.2 +++ b/lemon/full_graph.h Thu Dec 10 17:18:25 2009 +0100
39.3 @@ -24,7 +24,7 @@
39.4
39.5 ///\ingroup graphs
39.6 ///\file
39.7 -///\brief FullGraph and FullDigraph classes.
39.8 +///\brief FullDigraph and FullGraph classes.
39.9
39.10 namespace lemon {
39.11
39.12 @@ -51,7 +51,7 @@
39.13 typedef True ArcNumTag;
39.14
39.15 Node operator()(int ix) const { return Node(ix); }
39.16 - int index(const Node& node) const { return node._id; }
39.17 + static int index(const Node& node) { return node._id; }
39.18
39.19 Arc arc(const Node& s, const Node& t) const {
39.20 return Arc(s._id * _node_num + t._id);
39.21 @@ -148,24 +148,28 @@
39.22
39.23 /// \ingroup graphs
39.24 ///
39.25 - /// \brief A full digraph class.
39.26 + /// \brief A directed full graph class.
39.27 ///
39.28 - /// This is a simple and fast directed full graph implementation.
39.29 - /// From each node go arcs to each node (including the source node),
39.30 - /// therefore the number of the arcs in the digraph is the square of
39.31 - /// the node number. This digraph type is completely static, so you
39.32 - /// can neither add nor delete either arcs or nodes, and it needs
39.33 - /// constant space in memory.
39.34 + /// FullDigraph is a simple and fast implmenetation of directed full
39.35 + /// (complete) graphs. It contains an arc from each node to each node
39.36 + /// (including a loop for each node), therefore the number of arcs
39.37 + /// is the square of the number of nodes.
39.38 + /// This class is completely static and it needs constant memory space.
39.39 + /// Thus you can neither add nor delete nodes or arcs, however
39.40 + /// the structure can be resized using resize().
39.41 ///
39.42 - /// This class fully conforms to the \ref concepts::Digraph
39.43 - /// "Digraph concept".
39.44 + /// This type fully conforms to the \ref concepts::Digraph "Digraph concept".
39.45 + /// Most of its member functions and nested classes are documented
39.46 + /// only in the concept class.
39.47 ///
39.48 - /// The \c FullDigraph and \c FullGraph classes are very similar,
39.49 + /// This class provides constant time counting for nodes and arcs.
39.50 + ///
39.51 + /// \note FullDigraph and FullGraph classes are very similar,
39.52 /// but there are two differences. While this class conforms only
39.53 - /// to the \ref concepts::Digraph "Digraph" concept, the \c FullGraph
39.54 - /// class conforms to the \ref concepts::Graph "Graph" concept,
39.55 - /// moreover \c FullGraph does not contain a loop arc for each
39.56 - /// node as \c FullDigraph does.
39.57 + /// to the \ref concepts::Digraph "Digraph" concept, FullGraph
39.58 + /// conforms to the \ref concepts::Graph "Graph" concept,
39.59 + /// moreover FullGraph does not contain a loop for each
39.60 + /// node as this class does.
39.61 ///
39.62 /// \sa FullGraph
39.63 class FullDigraph : public ExtendedFullDigraphBase {
39.64 @@ -173,7 +177,9 @@
39.65
39.66 public:
39.67
39.68 - /// \brief Constructor
39.69 + /// \brief Default constructor.
39.70 + ///
39.71 + /// Default constructor. The number of nodes and arcs will be zero.
39.72 FullDigraph() { construct(0); }
39.73
39.74 /// \brief Constructor
39.75 @@ -184,8 +190,8 @@
39.76
39.77 /// \brief Resizes the digraph
39.78 ///
39.79 - /// Resizes the digraph. The function will fully destroy and
39.80 - /// rebuild the digraph. This cause that the maps of the digraph will
39.81 + /// This function resizes the digraph. It fully destroys and
39.82 + /// rebuilds the structure, therefore the maps of the digraph will be
39.83 /// reallocated automatically and the previous values will be lost.
39.84 void resize(int n) {
39.85 Parent::notifier(Arc()).clear();
39.86 @@ -197,24 +203,26 @@
39.87
39.88 /// \brief Returns the node with the given index.
39.89 ///
39.90 - /// Returns the node with the given index. Since it is a static
39.91 - /// digraph its nodes can be indexed with integers from the range
39.92 - /// <tt>[0..nodeNum()-1]</tt>.
39.93 + /// Returns the node with the given index. Since this structure is
39.94 + /// completely static, the nodes can be indexed with integers from
39.95 + /// the range <tt>[0..nodeNum()-1]</tt>.
39.96 + /// The index of a node is the same as its ID.
39.97 /// \sa index()
39.98 Node operator()(int ix) const { return Parent::operator()(ix); }
39.99
39.100 /// \brief Returns the index of the given node.
39.101 ///
39.102 - /// Returns the index of the given node. Since it is a static
39.103 - /// digraph its nodes can be indexed with integers from the range
39.104 - /// <tt>[0..nodeNum()-1]</tt>.
39.105 - /// \sa operator()
39.106 - int index(const Node& node) const { return Parent::index(node); }
39.107 + /// Returns the index of the given node. Since this structure is
39.108 + /// completely static, the nodes can be indexed with integers from
39.109 + /// the range <tt>[0..nodeNum()-1]</tt>.
39.110 + /// The index of a node is the same as its ID.
39.111 + /// \sa operator()()
39.112 + static int index(const Node& node) { return Parent::index(node); }
39.113
39.114 /// \brief Returns the arc connecting the given nodes.
39.115 ///
39.116 /// Returns the arc connecting the given nodes.
39.117 - Arc arc(const Node& u, const Node& v) const {
39.118 + Arc arc(Node u, Node v) const {
39.119 return Parent::arc(u, v);
39.120 }
39.121
39.122 @@ -283,7 +291,7 @@
39.123 public:
39.124
39.125 Node operator()(int ix) const { return Node(ix); }
39.126 - int index(const Node& node) const { return node._id; }
39.127 + static int index(const Node& node) { return node._id; }
39.128
39.129 Edge edge(const Node& u, const Node& v) const {
39.130 if (u._id < v._id) {
39.131 @@ -520,21 +528,25 @@
39.132 ///
39.133 /// \brief An undirected full graph class.
39.134 ///
39.135 - /// This is a simple and fast undirected full graph
39.136 - /// implementation. From each node go edge to each other node,
39.137 - /// therefore the number of edges in the graph is \f$n(n-1)/2\f$.
39.138 - /// This graph type is completely static, so you can neither
39.139 - /// add nor delete either edges or nodes, and it needs constant
39.140 - /// space in memory.
39.141 + /// FullGraph is a simple and fast implmenetation of undirected full
39.142 + /// (complete) graphs. It contains an edge between every distinct pair
39.143 + /// of nodes, therefore the number of edges is <tt>n(n-1)/2</tt>.
39.144 + /// This class is completely static and it needs constant memory space.
39.145 + /// Thus you can neither add nor delete nodes or edges, however
39.146 + /// the structure can be resized using resize().
39.147 ///
39.148 - /// This class fully conforms to the \ref concepts::Graph "Graph concept".
39.149 + /// This type fully conforms to the \ref concepts::Graph "Graph concept".
39.150 + /// Most of its member functions and nested classes are documented
39.151 + /// only in the concept class.
39.152 ///
39.153 - /// The \c FullGraph and \c FullDigraph classes are very similar,
39.154 - /// but there are two differences. While the \c FullDigraph class
39.155 + /// This class provides constant time counting for nodes, edges and arcs.
39.156 + ///
39.157 + /// \note FullDigraph and FullGraph classes are very similar,
39.158 + /// but there are two differences. While FullDigraph
39.159 /// conforms only to the \ref concepts::Digraph "Digraph" concept,
39.160 /// this class conforms to the \ref concepts::Graph "Graph" concept,
39.161 - /// moreover \c FullGraph does not contain a loop arc for each
39.162 - /// node as \c FullDigraph does.
39.163 + /// moreover this class does not contain a loop for each
39.164 + /// node as FullDigraph does.
39.165 ///
39.166 /// \sa FullDigraph
39.167 class FullGraph : public ExtendedFullGraphBase {
39.168 @@ -542,7 +554,9 @@
39.169
39.170 public:
39.171
39.172 - /// \brief Constructor
39.173 + /// \brief Default constructor.
39.174 + ///
39.175 + /// Default constructor. The number of nodes and edges will be zero.
39.176 FullGraph() { construct(0); }
39.177
39.178 /// \brief Constructor
39.179 @@ -553,8 +567,8 @@
39.180
39.181 /// \brief Resizes the graph
39.182 ///
39.183 - /// Resizes the graph. The function will fully destroy and
39.184 - /// rebuild the graph. This cause that the maps of the graph will
39.185 + /// This function resizes the graph. It fully destroys and
39.186 + /// rebuilds the structure, therefore the maps of the graph will be
39.187 /// reallocated automatically and the previous values will be lost.
39.188 void resize(int n) {
39.189 Parent::notifier(Arc()).clear();
39.190 @@ -568,31 +582,33 @@
39.191
39.192 /// \brief Returns the node with the given index.
39.193 ///
39.194 - /// Returns the node with the given index. Since it is a static
39.195 - /// graph its nodes can be indexed with integers from the range
39.196 - /// <tt>[0..nodeNum()-1]</tt>.
39.197 + /// Returns the node with the given index. Since this structure is
39.198 + /// completely static, the nodes can be indexed with integers from
39.199 + /// the range <tt>[0..nodeNum()-1]</tt>.
39.200 + /// The index of a node is the same as its ID.
39.201 /// \sa index()
39.202 Node operator()(int ix) const { return Parent::operator()(ix); }
39.203
39.204 /// \brief Returns the index of the given node.
39.205 ///
39.206 - /// Returns the index of the given node. Since it is a static
39.207 - /// graph its nodes can be indexed with integers from the range
39.208 - /// <tt>[0..nodeNum()-1]</tt>.
39.209 - /// \sa operator()
39.210 - int index(const Node& node) const { return Parent::index(node); }
39.211 + /// Returns the index of the given node. Since this structure is
39.212 + /// completely static, the nodes can be indexed with integers from
39.213 + /// the range <tt>[0..nodeNum()-1]</tt>.
39.214 + /// The index of a node is the same as its ID.
39.215 + /// \sa operator()()
39.216 + static int index(const Node& node) { return Parent::index(node); }
39.217
39.218 /// \brief Returns the arc connecting the given nodes.
39.219 ///
39.220 /// Returns the arc connecting the given nodes.
39.221 - Arc arc(const Node& s, const Node& t) const {
39.222 + Arc arc(Node s, Node t) const {
39.223 return Parent::arc(s, t);
39.224 }
39.225
39.226 - /// \brief Returns the edge connects the given nodes.
39.227 + /// \brief Returns the edge connecting the given nodes.
39.228 ///
39.229 - /// Returns the edge connects the given nodes.
39.230 - Edge edge(const Node& u, const Node& v) const {
39.231 + /// Returns the edge connecting the given nodes.
39.232 + Edge edge(Node u, Node v) const {
39.233 return Parent::edge(u, v);
39.234 }
39.235
40.1 --- a/lemon/glpk.cc Thu Dec 10 17:05:35 2009 +0100
40.2 +++ b/lemon/glpk.cc Thu Dec 10 17:18:25 2009 +0100
40.3 @@ -59,6 +59,42 @@
40.4 return i;
40.5 }
40.6
40.7 + int GlpkBase::_addRow(Value lo, ExprIterator b,
40.8 + ExprIterator e, Value up) {
40.9 + int i = glp_add_rows(lp, 1);
40.10 +
40.11 + if (lo == -INF) {
40.12 + if (up == INF) {
40.13 + glp_set_row_bnds(lp, i, GLP_FR, lo, up);
40.14 + } else {
40.15 + glp_set_row_bnds(lp, i, GLP_UP, lo, up);
40.16 + }
40.17 + } else {
40.18 + if (up == INF) {
40.19 + glp_set_row_bnds(lp, i, GLP_LO, lo, up);
40.20 + } else if (lo != up) {
40.21 + glp_set_row_bnds(lp, i, GLP_DB, lo, up);
40.22 + } else {
40.23 + glp_set_row_bnds(lp, i, GLP_FX, lo, up);
40.24 + }
40.25 + }
40.26 +
40.27 + std::vector<int> indexes;
40.28 + std::vector<Value> values;
40.29 +
40.30 + indexes.push_back(0);
40.31 + values.push_back(0);
40.32 +
40.33 + for(ExprIterator it = b; it != e; ++it) {
40.34 + indexes.push_back(it->first);
40.35 + values.push_back(it->second);
40.36 + }
40.37 +
40.38 + glp_set_mat_row(lp, i, values.size() - 1,
40.39 + &indexes.front(), &values.front());
40.40 + return i;
40.41 + }
40.42 +
40.43 void GlpkBase::_eraseCol(int i) {
40.44 int ca[2];
40.45 ca[1] = i;
41.1 --- a/lemon/glpk.h Thu Dec 10 17:05:35 2009 +0100
41.2 +++ b/lemon/glpk.h Thu Dec 10 17:18:25 2009 +0100
41.3 @@ -54,6 +54,7 @@
41.4
41.5 virtual int _addCol();
41.6 virtual int _addRow();
41.7 + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
41.8
41.9 virtual void _eraseCol(int i);
41.10 virtual void _eraseRow(int i);
42.1 --- a/lemon/gomory_hu.h Thu Dec 10 17:05:35 2009 +0100
42.2 +++ b/lemon/gomory_hu.h Thu Dec 10 17:18:25 2009 +0100
42.3 @@ -294,11 +294,9 @@
42.4 ///
42.5 /// \pre \ref run() must be called before using this function.
42.6 template <typename CutMap>
42.7 - Value minCutMap(const Node& s, ///<
42.8 + Value minCutMap(const Node& s,
42.9 const Node& t,
42.10 - ///<
42.11 CutMap& cutMap
42.12 - ///<
42.13 ) const {
42.14 Node sn = s, tn = t;
42.15 bool s_root=false;
42.16 @@ -359,10 +357,10 @@
42.17 /// This example counts the nodes in the minimum cut separating \c s from
42.18 /// \c t.
42.19 /// \code
42.20 - /// GomoruHu<Graph> gom(g, capacities);
42.21 + /// GomoryHu<Graph> gom(g, capacities);
42.22 /// gom.run();
42.23 /// int cnt=0;
42.24 - /// for(GomoruHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt;
42.25 + /// for(GomoryHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt;
42.26 /// \endcode
42.27 class MinCutNodeIt
42.28 {
42.29 @@ -394,7 +392,7 @@
42.30 /// MinCutNodeIt(gomory, t, s, false);
42.31 /// \endcode
42.32 /// does not necessarily give the same set of nodes.
42.33 - /// However it is ensured that
42.34 + /// However, it is ensured that
42.35 /// \code
42.36 /// MinCutNodeIt(gomory, s, t, true);
42.37 /// \endcode
42.38 @@ -456,10 +454,10 @@
42.39 /// This example computes the value of the minimum cut separating \c s from
42.40 /// \c t.
42.41 /// \code
42.42 - /// GomoruHu<Graph> gom(g, capacities);
42.43 + /// GomoryHu<Graph> gom(g, capacities);
42.44 /// gom.run();
42.45 /// int value=0;
42.46 - /// for(GomoruHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e)
42.47 + /// for(GomoryHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e)
42.48 /// value+=capacities[e];
42.49 /// \endcode
42.50 /// The result will be the same as the value returned by
43.1 --- a/lemon/graph_to_eps.h Thu Dec 10 17:05:35 2009 +0100
43.2 +++ b/lemon/graph_to_eps.h Thu Dec 10 17:18:25 2009 +0100
43.3 @@ -142,7 +142,7 @@
43.4 ///Constructor
43.5 ///\param gr Reference to the graph to be printed.
43.6 ///\param ost Reference to the output stream.
43.7 - ///By default it is <tt>std::cout</tt>.
43.8 + ///By default, it is <tt>std::cout</tt>.
43.9 ///\param pros If it is \c true, then the \c ostream referenced by \c os
43.10 ///will be explicitly deallocated by the destructor.
43.11 DefaultGraphToEpsTraits(const GR &gr, std::ostream& ost = std::cout,
43.12 @@ -512,7 +512,7 @@
43.13
43.14 ///Turn on/off pre-scaling
43.15
43.16 - ///By default graphToEps() rescales the whole image in order to avoid
43.17 + ///By default, graphToEps() rescales the whole image in order to avoid
43.18 ///very big or very small bounding boxes.
43.19 ///
43.20 ///This (p)rescaling can be turned off with this function.
43.21 @@ -1114,7 +1114,7 @@
43.22 ///Generates an EPS file from a graph.
43.23 ///\param g Reference to the graph to be printed.
43.24 ///\param os Reference to the output stream.
43.25 -///By default it is <tt>std::cout</tt>.
43.26 +///By default, it is <tt>std::cout</tt>.
43.27 ///
43.28 ///This function also has a lot of
43.29 ///\ref named-templ-func-param "named parameters",
43.30 @@ -1126,7 +1126,7 @@
43.31 /// .arcWidthScale(.4).run();
43.32 ///\endcode
43.33 ///
43.34 -///For more detailed examples see the \ref graph_to_eps_demo.cc demo file.
43.35 +///For more detailed examples, see the \ref graph_to_eps_demo.cc demo file.
43.36 ///
43.37 ///\warning Don't forget to put the \ref GraphToEps::run() "run()"
43.38 ///to the end of the parameter list.
44.1 --- a/lemon/grid_graph.h Thu Dec 10 17:05:35 2009 +0100
44.2 +++ b/lemon/grid_graph.h Thu Dec 10 17:18:25 2009 +0100
44.3 @@ -470,18 +470,22 @@
44.4 ///
44.5 /// \brief Grid graph class
44.6 ///
44.7 - /// This class implements a special graph type. The nodes of the
44.8 - /// graph can be indexed by two integer \c (i,j) value where \c i is
44.9 - /// in the \c [0..width()-1] range and j is in the \c
44.10 - /// [0..height()-1] range. Two nodes are connected in the graph if
44.11 - /// the indexes differ exactly on one position and exactly one is
44.12 - /// the difference. The nodes of the graph can be indexed by position
44.13 - /// with the \c operator()() function. The positions of the nodes can be
44.14 - /// get with \c pos(), \c col() and \c row() members. The outgoing
44.15 + /// GridGraph implements a special graph type. The nodes of the
44.16 + /// graph can be indexed by two integer values \c (i,j) where \c i is
44.17 + /// in the range <tt>[0..width()-1]</tt> and j is in the range
44.18 + /// <tt>[0..height()-1]</tt>. Two nodes are connected in the graph if
44.19 + /// the indices differ exactly on one position and the difference is
44.20 + /// also exactly one. The nodes of the graph can be obtained by position
44.21 + /// using the \c operator()() function and the indices of the nodes can