1.1 --- a/CMakeLists.txt Tue Aug 18 10:08:28 2009 +0200
1.2 +++ b/CMakeLists.txt Thu Nov 05 08:39:49 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 Tue Aug 18 10:08:28 2009 +0200
2.2 +++ b/Makefile.am Thu Nov 05 08:39:49 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 \
3.1 --- a/configure.ac Tue Aug 18 10:08:28 2009 +0200
3.2 +++ b/configure.ac Thu Nov 05 08:39:49 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.
4.1 --- a/doc/CMakeLists.txt Tue Aug 18 10:08:28 2009 +0200
4.2 +++ b/doc/CMakeLists.txt Thu Nov 05 08:39:49 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 Tue Aug 18 10:08:28 2009 +0200
5.2 +++ b/doc/Doxyfile.in Thu Nov 05 08:39:49 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 Tue Aug 18 10:08:28 2009 +0200
6.2 +++ b/doc/Makefile.am Thu Nov 05 08:39:49 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 Tue Aug 18 10:08:28 2009 +0200
7.2 +++ b/doc/groups.dox Thu Nov 05 08:39:49 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 @@ -425,30 +487,6 @@
7.190 */
7.191
7.192 /**
7.193 -@defgroup graph_properties Connectivity and Other Graph Properties
7.194 -@ingroup algs
7.195 -\brief Algorithms for discovering the graph properties
7.196 -
7.197 -This group contains the algorithms for discovering the graph properties
7.198 -like connectivity, bipartiteness, euler property, simplicity etc.
7.199 -
7.200 -\image html edge_biconnected_components.png
7.201 -\image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth
7.202 -*/
7.203 -
7.204 -/**
7.205 -@defgroup planar Planarity Embedding and Drawing
7.206 -@ingroup algs
7.207 -\brief Algorithms for planarity checking, embedding and drawing
7.208 -
7.209 -This group contains the algorithms for planarity checking,
7.210 -embedding and drawing.
7.211 -
7.212 -\image html planar.png
7.213 -\image latex planar.eps "Plane graph" width=\textwidth
7.214 -*/
7.215 -
7.216 -/**
7.217 @defgroup matching Matching Algorithms
7.218 @ingroup algs
7.219 \brief Algorithms for finding matchings in graphs and bipartite graphs.
7.220 @@ -489,12 +527,36 @@
7.221 */
7.222
7.223 /**
7.224 -@defgroup spantree Minimum Spanning Tree Algorithms
7.225 +@defgroup graph_properties Connectivity and Other Graph Properties
7.226 @ingroup algs
7.227 -\brief Algorithms for finding minimum cost spanning trees and arborescences.
7.228 +\brief Algorithms for discovering the graph properties
7.229
7.230 -This group contains the algorithms for finding minimum cost spanning
7.231 -trees and arborescences.
7.232 +This group contains the algorithms for discovering the graph properties
7.233 +like connectivity, bipartiteness, euler property, simplicity etc.
7.234 +
7.235 +\image html connected_components.png
7.236 +\image latex connected_components.eps "Connected components" width=\textwidth
7.237 +*/
7.238 +
7.239 +/**
7.240 +@defgroup planar Planarity Embedding and Drawing
7.241 +@ingroup algs
7.242 +\brief Algorithms for planarity checking, embedding and drawing
7.243 +
7.244 +This group contains the algorithms for planarity checking,
7.245 +embedding and drawing.
7.246 +
7.247 +\image html planar.png
7.248 +\image latex planar.eps "Plane graph" width=\textwidth
7.249 +*/
7.250 +
7.251 +/**
7.252 +@defgroup approx Approximation Algorithms
7.253 +@ingroup algs
7.254 +\brief Approximation algorithms.
7.255 +
7.256 +This group contains the approximation and heuristic algorithms
7.257 +implemented in LEMON.
7.258 */
7.259
7.260 /**
7.261 @@ -507,15 +569,6 @@
7.262 */
7.263
7.264 /**
7.265 -@defgroup approx Approximation Algorithms
7.266 -@ingroup algs
7.267 -\brief Approximation algorithms.
7.268 -
7.269 -This group contains the approximation and heuristic algorithms
7.270 -implemented in LEMON.
7.271 -*/
7.272 -
7.273 -/**
7.274 @defgroup gen_opt_group General Optimization Tools
7.275 \brief This group contains some general optimization frameworks
7.276 implemented in LEMON.
7.277 @@ -525,13 +578,16 @@
7.278 */
7.279
7.280 /**
7.281 -@defgroup lp_group Lp and Mip Solvers
7.282 +@defgroup lp_group LP and MIP Solvers
7.283 @ingroup gen_opt_group
7.284 -\brief Lp and Mip solver interfaces for LEMON.
7.285 +\brief LP and MIP solver interfaces for LEMON.
7.286
7.287 -This group contains Lp and Mip solver interfaces for LEMON. The
7.288 -various LP solvers could be used in the same manner with this
7.289 -interface.
7.290 +This group contains LP and MIP solver interfaces for LEMON.
7.291 +Various LP solvers could be used in the same manner with this
7.292 +high-level interface.
7.293 +
7.294 +The currently supported solvers are \ref glpk, \ref clp, \ref cbc,
7.295 +\ref cplex, \ref soplex.
7.296 */
7.297
7.298 /**
7.299 @@ -621,7 +677,7 @@
7.300 */
7.301
7.302 /**
7.303 -@defgroup dimacs_group DIMACS format
7.304 +@defgroup dimacs_group DIMACS Format
7.305 @ingroup io_group
7.306 \brief Read and write files in DIMACS format
7.307
7.308 @@ -670,8 +726,8 @@
7.309 @ingroup concept
7.310 \brief Skeleton and concept checking classes for graph structures
7.311
7.312 -This group contains the skeletons and concept checking classes of LEMON's
7.313 -graph structures and helper classes used to implement these.
7.314 +This group contains the skeletons and concept checking classes of
7.315 +graph structures.
7.316 */
7.317
7.318 /**
7.319 @@ -683,6 +739,15 @@
7.320 */
7.321
7.322 /**
7.323 +@defgroup tools Standalone Utility Applications
7.324 +
7.325 +Some utility applications are listed here.
7.326 +
7.327 +The standard compilation procedure (<tt>./configure;make</tt>) will compile
7.328 +them, as well.
7.329 +*/
7.330 +
7.331 +/**
7.332 \anchor demoprograms
7.333
7.334 @defgroup demos Demo Programs
7.335 @@ -694,13 +759,4 @@
7.336 <tt>make check</tt> commands.
7.337 */
7.338
7.339 -/**
7.340 -@defgroup tools Standalone Utility Applications
7.341 -
7.342 -Some utility applications are listed here.
7.343 -
7.344 -The standard compilation procedure (<tt>./configure;make</tt>) will compile
7.345 -them, as well.
7.346 -*/
7.347 -
7.348 }
8.1 --- a/doc/mainpage.dox Tue Aug 18 10:08:28 2009 +0200
8.2 +++ b/doc/mainpage.dox Thu Nov 05 08:39:49 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 Tue Aug 18 10:08:28 2009 +0200
9.2 +++ b/doc/min_cost_flow.dox Thu Nov 05 08:39:49 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
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/doc/references.bib Thu Nov 05 08:39:49 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 Tue Aug 18 10:08:28 2009 +0200
11.2 +++ b/lemon/Makefile.am Thu Nov 05 08:39:49 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,6 +80,7 @@
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 @@ -87,6 +90,7 @@
11.23 lemon/howard.h \
11.24 lemon/hypercube_graph.h \
11.25 lemon/karp.h \
11.26 + lemon/kary_heap.h \
11.27 lemon/kruskal.h \
11.28 lemon/hao_orlin.h \
11.29 lemon/lgf_reader.h \
11.30 @@ -95,13 +99,13 @@
11.31 lemon/lp.h \
11.32 lemon/lp_base.h \
11.33 lemon/lp_skeleton.h \
11.34 - lemon/list_graph.h \
11.35 lemon/maps.h \
11.36 lemon/matching.h \
11.37 lemon/math.h \
11.38 lemon/min_cost_arborescence.h \
11.39 lemon/nauty_reader.h \
11.40 lemon/network_simplex.h \
11.41 + lemon/pairing_heap.h \
11.42 lemon/path.h \
11.43 lemon/preflow.h \
11.44 lemon/radix_heap.h \
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/lemon/bellman_ford.h Thu Nov 05 08:39:49 2009 +0100
12.3 @@ -0,0 +1,1100 @@
12.4 +/* -*- C++ -*-
12.5 + *
12.6 + * This file is a part of LEMON, a generic C++ optimization library
12.7 + *
12.8 + * Copyright (C) 2003-2008
12.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
12.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
12.11 + *
12.12 + * Permission to use, modify and distribute this software is granted
12.13 + * provided that this copyright notice appears in all copies. For
12.14 + * precise terms see the accompanying LICENSE file.
12.15 + *
12.16 + * This software is provided "AS IS" with no warranty of any kind,
12.17 + * express or implied, and with no claim as to its suitability for any
12.18 + * purpose.
12.19 + *
12.20 + */
12.21 +
12.22 +#ifndef LEMON_BELLMAN_FORD_H
12.23 +#define LEMON_BELLMAN_FORD_H
12.24 +
12.25 +/// \ingroup shortest_path
12.26 +/// \file
12.27 +/// \brief Bellman-Ford algorithm.
12.28 +
12.29 +#include <lemon/bits/path_dump.h>
12.30 +#include <lemon/core.h>
12.31 +#include <lemon/error.h>
12.32 +#include <lemon/maps.h>
12.33 +#include <lemon/path.h>
12.34 +
12.35 +#include <limits>
12.36 +
12.37 +namespace lemon {
12.38 +
12.39 + /// \brief Default OperationTraits for the BellmanFord algorithm class.
12.40 + ///
12.41 + /// This operation traits class defines all computational operations
12.42 + /// and constants that are used in the Bellman-Ford algorithm.
12.43 + /// The default implementation is based on the \c numeric_limits class.
12.44 + /// If the numeric type does not have infinity value, then the maximum
12.45 + /// value is used as extremal infinity value.
12.46 + template <
12.47 + typename V,
12.48 + bool has_inf = std::numeric_limits<V>::has_infinity>
12.49 + struct BellmanFordDefaultOperationTraits {
12.50 + /// \e
12.51 + typedef V Value;
12.52 + /// \brief Gives back the zero value of the type.
12.53 + static Value zero() {
12.54 + return static_cast<Value>(0);
12.55 + }
12.56 + /// \brief Gives back the positive infinity value of the type.
12.57 + static Value infinity() {
12.58 + return std::numeric_limits<Value>::infinity();
12.59 + }
12.60 + /// \brief Gives back the sum of the given two elements.
12.61 + static Value plus(const Value& left, const Value& right) {
12.62 + return left + right;
12.63 + }
12.64 + /// \brief Gives back \c true only if the first value is less than
12.65 + /// the second.
12.66 + static bool less(const Value& left, const Value& right) {
12.67 + return left < right;
12.68 + }
12.69 + };
12.70 +
12.71 + template <typename V>
12.72 + struct BellmanFordDefaultOperationTraits<V, false> {
12.73 + typedef V Value;
12.74 + static Value zero() {
12.75 + return static_cast<Value>(0);
12.76 + }
12.77 + static Value infinity() {
12.78 + return std::numeric_limits<Value>::max();
12.79 + }
12.80 + static Value plus(const Value& left, const Value& right) {
12.81 + if (left == infinity() || right == infinity()) return infinity();
12.82 + return left + right;
12.83 + }
12.84 + static bool less(const Value& left, const Value& right) {
12.85 + return left < right;
12.86 + }
12.87 + };
12.88 +
12.89 + /// \brief Default traits class of BellmanFord class.
12.90 + ///
12.91 + /// Default traits class of BellmanFord class.
12.92 + /// \param GR The type of the digraph.
12.93 + /// \param LEN The type of the length map.
12.94 + template<typename GR, typename LEN>
12.95 + struct BellmanFordDefaultTraits {
12.96 + /// The type of the digraph the algorithm runs on.
12.97 + typedef GR Digraph;
12.98 +
12.99 + /// \brief The type of the map that stores the arc lengths.
12.100 + ///
12.101 + /// The type of the map that stores the arc lengths.
12.102 + /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
12.103 + typedef LEN LengthMap;
12.104 +
12.105 + /// The type of the arc lengths.
12.106 + typedef typename LEN::Value Value;
12.107 +
12.108 + /// \brief Operation traits for Bellman-Ford algorithm.
12.109 + ///
12.110 + /// It defines the used operations and the infinity value for the
12.111 + /// given \c Value type.
12.112 + /// \see BellmanFordDefaultOperationTraits
12.113 + typedef BellmanFordDefaultOperationTraits<Value> OperationTraits;
12.114 +
12.115 + /// \brief The type of the map that stores the last arcs of the
12.116 + /// shortest paths.
12.117 + ///
12.118 + /// The type of the map that stores the last
12.119 + /// arcs of the shortest paths.
12.120 + /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
12.121 + typedef typename GR::template NodeMap<typename GR::Arc> PredMap;
12.122 +
12.123 + /// \brief Instantiates a \c PredMap.
12.124 + ///
12.125 + /// This function instantiates a \ref PredMap.
12.126 + /// \param g is the digraph to which we would like to define the
12.127 + /// \ref PredMap.
12.128 + static PredMap *createPredMap(const GR& g) {
12.129 + return new PredMap(g);
12.130 + }
12.131 +
12.132 + /// \brief The type of the map that stores the distances of the nodes.
12.133 + ///
12.134 + /// The type of the map that stores the distances of the nodes.
12.135 + /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
12.136 + typedef typename GR::template NodeMap<typename LEN::Value> DistMap;
12.137 +
12.138 + /// \brief Instantiates a \c DistMap.
12.139 + ///
12.140 + /// This function instantiates a \ref DistMap.
12.141 + /// \param g is the digraph to which we would like to define the
12.142 + /// \ref DistMap.
12.143 + static DistMap *createDistMap(const GR& g) {
12.144 + return new DistMap(g);
12.145 + }
12.146 +
12.147 + };
12.148 +
12.149 + /// \brief %BellmanFord algorithm class.
12.150 + ///
12.151 + /// \ingroup shortest_path
12.152 + /// This class provides an efficient implementation of the Bellman-Ford
12.153 + /// algorithm. The maximum time complexity of the algorithm is
12.154 + /// <tt>O(ne)</tt>.
12.155 + ///
12.156 + /// The Bellman-Ford algorithm solves the single-source shortest path
12.157 + /// problem when the arcs can have negative lengths, but the digraph
12.158 + /// should not contain directed cycles with negative total length.
12.159 + /// If all arc costs are non-negative, consider to use the Dijkstra
12.160 + /// algorithm instead, since it is more efficient.
12.161 + ///
12.162 + /// The arc lengths are passed to the algorithm using a
12.163 + /// \ref concepts::ReadMap "ReadMap", so it is easy to change it to any
12.164 + /// kind of length. The type of the length values is determined by the
12.165 + /// \ref concepts::ReadMap::Value "Value" type of the length map.
12.166 + ///
12.167 + /// There is also a \ref bellmanFord() "function-type interface" for the
12.168 + /// Bellman-Ford algorithm, which is convenient in the simplier cases and
12.169 + /// it can be used easier.
12.170 + ///
12.171 + /// \tparam GR The type of the digraph the algorithm runs on.
12.172 + /// The default type is \ref ListDigraph.
12.173 + /// \tparam LEN A \ref concepts::ReadMap "readable" arc map that specifies
12.174 + /// the lengths of the arcs. The default map type is
12.175 + /// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
12.176 +#ifdef DOXYGEN
12.177 + template <typename GR, typename LEN, typename TR>
12.178 +#else
12.179 + template <typename GR=ListDigraph,
12.180 + typename LEN=typename GR::template ArcMap<int>,
12.181 + typename TR=BellmanFordDefaultTraits<GR,LEN> >
12.182 +#endif
12.183 + class BellmanFord {
12.184 + public:
12.185 +
12.186 + ///The type of the underlying digraph.
12.187 + typedef typename TR::Digraph Digraph;
12.188 +
12.189 + /// \brief The type of the arc lengths.
12.190 + typedef typename TR::LengthMap::Value Value;
12.191 + /// \brief The type of the map that stores the arc lengths.
12.192 + typedef typename TR::LengthMap LengthMap;
12.193 + /// \brief The type of the map that stores the last
12.194 + /// arcs of the shortest paths.
12.195 + typedef typename TR::PredMap PredMap;
12.196 + /// \brief The type of the map that stores the distances of the nodes.
12.197 + typedef typename TR::DistMap DistMap;
12.198 + /// The type of the paths.
12.199 + typedef PredMapPath<Digraph, PredMap> Path;
12.200 + ///\brief The \ref BellmanFordDefaultOperationTraits
12.201 + /// "operation traits class" of the algorithm.
12.202 + typedef typename TR::OperationTraits OperationTraits;
12.203 +
12.204 + ///The \ref BellmanFordDefaultTraits "traits class" of the algorithm.
12.205 + typedef TR Traits;
12.206 +
12.207 + private:
12.208 +
12.209 + typedef typename Digraph::Node Node;
12.210 + typedef typename Digraph::NodeIt NodeIt;
12.211 + typedef typename Digraph::Arc Arc;
12.212 + typedef typename Digraph::OutArcIt OutArcIt;
12.213 +
12.214 + // Pointer to the underlying digraph.
12.215 + const Digraph *_gr;
12.216 + // Pointer to the length map
12.217 + const LengthMap *_length;
12.218 + // Pointer to the map of predecessors arcs.
12.219 + PredMap *_pred;
12.220 + // Indicates if _pred is locally allocated (true) or not.
12.221 + bool _local_pred;
12.222 + // Pointer to the map of distances.
12.223 + DistMap *_dist;
12.224 + // Indicates if _dist is locally allocated (true) or not.
12.225 + bool _local_dist;
12.226 +
12.227 + typedef typename Digraph::template NodeMap<bool> MaskMap;
12.228 + MaskMap *_mask;
12.229 +
12.230 + std::vector<Node> _process;
12.231 +
12.232 + // Creates the maps if necessary.
12.233 + void create_maps() {
12.234 + if(!_pred) {
12.235 + _local_pred = true;
12.236 + _pred = Traits::createPredMap(*_gr);
12.237 + }
12.238 + if(!_dist) {
12.239 + _local_dist = true;
12.240 + _dist = Traits::createDistMap(*_gr);
12.241 + }
12.242 + _mask = new MaskMap(*_gr, false);
12.243 + }
12.244 +
12.245 + public :
12.246 +
12.247 + typedef BellmanFord Create;
12.248 +
12.249 + /// \name Named Template Parameters
12.250 +
12.251 + ///@{
12.252 +
12.253 + template <class T>
12.254 + struct SetPredMapTraits : public Traits {
12.255 + typedef T PredMap;
12.256 + static PredMap *createPredMap(const Digraph&) {
12.257 + LEMON_ASSERT(false, "PredMap is not initialized");
12.258 + return 0; // ignore warnings
12.259 + }
12.260 + };
12.261 +
12.262 + /// \brief \ref named-templ-param "Named parameter" for setting
12.263 + /// \c PredMap type.
12.264 + ///
12.265 + /// \ref named-templ-param "Named parameter" for setting
12.266 + /// \c PredMap type.
12.267 + /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
12.268 + template <class T>
12.269 + struct SetPredMap
12.270 + : public BellmanFord< Digraph, LengthMap, SetPredMapTraits<T> > {
12.271 + typedef BellmanFord< Digraph, LengthMap, SetPredMapTraits<T> > Create;
12.272 + };
12.273 +
12.274 + template <class T>
12.275 + struct SetDistMapTraits : public Traits {
12.276 + typedef T DistMap;
12.277 + static DistMap *createDistMap(const Digraph&) {
12.278 + LEMON_ASSERT(false, "DistMap is not initialized");
12.279 + return 0; // ignore warnings
12.280 + }
12.281 + };
12.282 +
12.283 + /// \brief \ref named-templ-param "Named parameter" for setting
12.284 + /// \c DistMap type.
12.285 + ///
12.286 + /// \ref named-templ-param "Named parameter" for setting
12.287 + /// \c DistMap type.
12.288 + /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
12.289 + template <class T>
12.290 + struct SetDistMap
12.291 + : public BellmanFord< Digraph, LengthMap, SetDistMapTraits<T> > {
12.292 + typedef BellmanFord< Digraph, LengthMap, SetDistMapTraits<T> > Create;
12.293 + };
12.294 +
12.295 + template <class T>
12.296 + struct SetOperationTraitsTraits : public Traits {
12.297 + typedef T OperationTraits;
12.298 + };
12.299 +
12.300 + /// \brief \ref named-templ-param "Named parameter" for setting
12.301 + /// \c OperationTraits type.
12.302 + ///
12.303 + /// \ref named-templ-param "Named parameter" for setting
12.304 + /// \c OperationTraits type.
12.305 + /// For more information see \ref BellmanFordDefaultOperationTraits.
12.306 + template <class T>
12.307 + struct SetOperationTraits
12.308 + : public BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> > {
12.309 + typedef BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> >
12.310 + Create;
12.311 + };
12.312 +
12.313 + ///@}
12.314 +
12.315 + protected:
12.316 +
12.317 + BellmanFord() {}
12.318 +
12.319 + public:
12.320 +
12.321 + /// \brief Constructor.
12.322 + ///
12.323 + /// Constructor.
12.324 + /// \param g The digraph the algorithm runs on.
12.325 + /// \param length The length map used by the algorithm.
12.326 + BellmanFord(const Digraph& g, const LengthMap& length) :
12.327 + _gr(&g), _length(&length),
12.328 + _pred(0), _local_pred(false),
12.329 + _dist(0), _local_dist(false), _mask(0) {}
12.330 +
12.331 + ///Destructor.
12.332 + ~BellmanFord() {
12.333 + if(_local_pred) delete _pred;
12.334 + if(_local_dist) delete _dist;
12.335 + if(_mask) delete _mask;
12.336 + }
12.337 +
12.338 + /// \brief Sets the length map.
12.339 + ///
12.340 + /// Sets the length map.
12.341 + /// \return <tt>(*this)</tt>
12.342 + BellmanFord &lengthMap(const LengthMap &map) {
12.343 + _length = ↦
12.344 + return *this;
12.345 + }
12.346 +
12.347 + /// \brief Sets the map that stores the predecessor arcs.
12.348 + ///
12.349 + /// Sets the map that stores the predecessor arcs.
12.350 + /// If you don't use this function before calling \ref run()
12.351 + /// or \ref init(), an instance will be allocated automatically.
12.352 + /// The destructor deallocates this automatically allocated map,
12.353 + /// of course.
12.354 + /// \return <tt>(*this)</tt>
12.355 + BellmanFord &predMap(PredMap &map) {
12.356 + if(_local_pred) {
12.357 + delete _pred;
12.358 + _local_pred=false;
12.359 + }
12.360 + _pred = ↦
12.361 + return *this;
12.362 + }
12.363 +
12.364 + /// \brief Sets the map that stores the distances of the nodes.
12.365 + ///
12.366 + /// Sets the map that stores the distances of the nodes calculated
12.367 + /// by the algorithm.
12.368 + /// If you don't use this function before calling \ref run()
12.369 + /// or \ref init(), an instance will be allocated automatically.
12.370 + /// The destructor deallocates this automatically allocated map,
12.371 + /// of course.
12.372 + /// \return <tt>(*this)</tt>
12.373 + BellmanFord &distMap(DistMap &map) {
12.374 + if(_local_dist) {
12.375 + delete _dist;
12.376 + _local_dist=false;
12.377 + }
12.378 + _dist = ↦
12.379 + return *this;
12.380 + }
12.381 +
12.382 + /// \name Execution Control
12.383 + /// The simplest way to execute the Bellman-Ford algorithm is to use
12.384 + /// one of the member functions called \ref run().\n
12.385 + /// If you need better control on the execution, you have to call
12.386 + /// \ref init() first, then you can add several source nodes
12.387 + /// with \ref addSource(). Finally the actual path computation can be
12.388 + /// performed with \ref start(), \ref checkedStart() or
12.389 + /// \ref limitedStart().
12.390 +
12.391 + ///@{
12.392 +
12.393 + /// \brief Initializes the internal data structures.
12.394 + ///
12.395 + /// Initializes the internal data structures. The optional parameter
12.396 + /// is the initial distance of each node.
12.397 + void init(const Value value = OperationTraits::infinity()) {
12.398 + create_maps();
12.399 + for (NodeIt it(*_gr); it != INVALID; ++it) {
12.400 + _pred->set(it, INVALID);
12.401 + _dist->set(it, value);
12.402 + }
12.403 + _process.clear();
12.404 + if (OperationTraits::less(value, OperationTraits::infinity())) {
12.405 + for (NodeIt it(*_gr); it != INVALID; ++it) {
12.406 + _process.push_back(it);
12.407 + _mask->set(it, true);
12.408 + }
12.409 + }
12.410 + }
12.411 +
12.412 + /// \brief Adds a new source node.
12.413 + ///
12.414 + /// This function adds a new source node. The optional second parameter
12.415 + /// is the initial distance of the node.
12.416 + void addSource(Node source, Value dst = OperationTraits::zero()) {
12.417 + _dist->set(source, dst);
12.418 + if (!(*_mask)[source]) {
12.419 + _process.push_back(source);
12.420 + _mask->set(source, true);
12.421 + }
12.422 + }
12.423 +
12.424 + /// \brief Executes one round from the Bellman-Ford algorithm.
12.425 + ///
12.426 + /// If the algoritm calculated the distances in the previous round
12.427 + /// exactly for the paths of at most \c k arcs, then this function
12.428 + /// will calculate the distances exactly for the paths of at most
12.429 + /// <tt>k+1</tt> arcs. Performing \c k iterations using this function
12.430 + /// calculates the shortest path distances exactly for the paths
12.431 + /// consisting of at most \c k arcs.
12.432 + ///
12.433 + /// \warning The paths with limited arc number cannot be retrieved
12.434 + /// easily with \ref path() or \ref predArc() functions. If you also
12.435 + /// need the shortest paths and not only the distances, you should
12.436 + /// store the \ref predMap() "predecessor map" after each iteration
12.437 + /// and build the path manually.
12.438 + ///
12.439 + /// \return \c true when the algorithm have not found more shorter
12.440 + /// paths.
12.441 + ///
12.442 + /// \see ActiveIt
12.443 + bool processNextRound() {
12.444 + for (int i = 0; i < int(_process.size()); ++i) {
12.445 + _mask->set(_process[i], false);
12.446 + }
12.447 + std::vector<Node> nextProcess;
12.448 + std::vector<Value> values(_process.size());
12.449 + for (int i = 0; i < int(_process.size()); ++i) {
12.450 + values[i] = (*_dist)[_process[i]];
12.451 + }
12.452 + for (int i = 0; i < int(_process.size()); ++i) {
12.453 + for (OutArcIt it(*_gr, _process[i]); it != INVALID; ++it) {
12.454 + Node target = _gr->target(it);
12.455 + Value relaxed = OperationTraits::plus(values[i], (*_length)[it]);
12.456 + if (OperationTraits::less(relaxed, (*_dist)[target])) {
12.457 + _pred->set(target, it);
12.458 + _dist->set(target, relaxed);
12.459 + if (!(*_mask)[target]) {
12.460 + _mask->set(target, true);
12.461 + nextProcess.push_back(target);
12.462 + }
12.463 + }
12.464 + }
12.465 + }
12.466 + _process.swap(nextProcess);
12.467 + return _process.empty();
12.468 + }
12.469 +
12.470 + /// \brief Executes one weak round from the Bellman-Ford algorithm.
12.471 + ///
12.472 + /// If the algorithm calculated the distances in the previous round
12.473 + /// at least for the paths of at most \c k arcs, then this function
12.474 + /// will calculate the distances at least for the paths of at most
12.475 + /// <tt>k+1</tt> arcs.
12.476 + /// This function does not make it possible to calculate the shortest
12.477 + /// path distances exactly for paths consisting of at most \c k arcs,
12.478 + /// this is why it is called weak round.
12.479 + ///
12.480 + /// \return \c true when the algorithm have not found more shorter
12.481 + /// paths.
12.482 + ///
12.483 + /// \see ActiveIt
12.484 + bool processNextWeakRound() {
12.485 + for (int i = 0; i < int(_process.size()); ++i) {
12.486 + _mask->set(_process[i], false);
12.487 + }
12.488 + std::vector<Node> nextProcess;
12.489 + for (int i = 0; i < int(_process.size()); ++i) {
12.490 + for (OutArcIt it(*_gr, _process[i]); it != INVALID; ++it) {
12.491 + Node target = _gr->target(it);
12.492 + Value relaxed =
12.493 + OperationTraits::plus((*_dist)[_process[i]], (*_length)[it]);
12.494 + if (OperationTraits::less(relaxed, (*_dist)[target])) {
12.495 + _pred->set(target, it);
12.496 + _dist->set(target, relaxed);
12.497 + if (!(*_mask)[target]) {
12.498 + _mask->set(target, true);
12.499 + nextProcess.push_back(target);
12.500 + }
12.501 + }
12.502 + }
12.503 + }
12.504 + _process.swap(nextProcess);
12.505 + return _process.empty();
12.506 + }
12.507 +
12.508 + /// \brief Executes the algorithm.
12.509 + ///
12.510 + /// Executes the algorithm.
12.511 + ///
12.512 + /// This method runs the Bellman-Ford algorithm from the root node(s)
12.513 + /// in order to compute the shortest path to each node.
12.514 + ///
12.515 + /// The algorithm computes
12.516 + /// - the shortest path tree (forest),
12.517 + /// - the distance of each node from the root(s).
12.518 + ///
12.519 + /// \pre init() must be called and at least one root node should be
12.520 + /// added with addSource() before using this function.
12.521 + void start() {
12.522 + int num = countNodes(*_gr) - 1;
12.523 + for (int i = 0; i < num; ++i) {
12.524 + if (processNextWeakRound()) break;
12.525 + }
12.526 + }
12.527 +
12.528 + /// \brief Executes the algorithm and checks the negative cycles.
12.529 + ///
12.530 + /// Executes the algorithm and checks the negative cycles.
12.531 + ///
12.532 + /// This method runs the Bellman-Ford algorithm from the root node(s)
12.533 + /// in order to compute the shortest path to each node and also checks
12.534 + /// if the digraph contains cycles with negative total length.
12.535 + ///
12.536 + /// The algorithm computes
12.537 + /// - the shortest path tree (forest),
12.538 + /// - the distance of each node from the root(s).
12.539 + ///
12.540 + /// \return \c false if there is a negative cycle in the digraph.
12.541 + ///
12.542 + /// \pre init() must be called and at least one root node should be
12.543 + /// added with addSource() before using this function.
12.544 + bool checkedStart() {
12.545 + int num = countNodes(*_gr);
12.546 + for (int i = 0; i < num; ++i) {
12.547 + if (processNextWeakRound()) return true;
12.548 + }
12.549 + return _process.empty();
12.550 + }
12.551 +
12.552 + /// \brief Executes the algorithm with arc number limit.
12.553 + ///
12.554 + /// Executes the algorithm with arc number limit.
12.555 + ///
12.556 + /// This method runs the Bellman-Ford algorithm from the root node(s)
12.557 + /// in order to compute the shortest path distance for each node
12.558 + /// using only the paths consisting of at most \c num arcs.
12.559 + ///
12.560 + /// The algorithm computes
12.561 + /// - the limited distance of each node from the root(s),
12.562 + /// - the predecessor arc for each node.
12.563 + ///
12.564 + /// \warning The paths with limited arc number cannot be retrieved
12.565 + /// easily with \ref path() or \ref predArc() functions. If you also
12.566 + /// need the shortest paths and not only the distances, you should
12.567 + /// store the \ref predMap() "predecessor map" after each iteration
12.568 + /// and build the path manually.
12.569 + ///
12.570 + /// \pre init() must be called and at least one root node should be
12.571 + /// added with addSource() before using this function.
12.572 + void limitedStart(int num) {
12.573 + for (int i = 0; i < num; ++i) {
12.574 + if (processNextRound()) break;
12.575 + }
12.576 + }
12.577 +
12.578 + /// \brief Runs the algorithm from the given root node.
12.579 + ///
12.580 + /// This method runs the Bellman-Ford algorithm from the given root
12.581 + /// node \c s in order to compute the shortest path to each node.
12.582 + ///
12.583 + /// The algorithm computes
12.584 + /// - the shortest path tree (forest),
12.585 + /// - the distance of each node from the root(s).
12.586 + ///
12.587 + /// \note bf.run(s) is just a shortcut of the following code.
12.588 + /// \code
12.589 + /// bf.init();
12.590 + /// bf.addSource(s);
12.591 + /// bf.start();
12.592 + /// \endcode
12.593 + void run(Node s) {
12.594 + init();
12.595 + addSource(s);
12.596 + start();
12.597 + }
12.598 +
12.599 + /// \brief Runs the algorithm from the given root node with arc
12.600 + /// number limit.
12.601 + ///
12.602 + /// This method runs the Bellman-Ford algorithm from the given root
12.603 + /// node \c s in order to compute the shortest path distance for each
12.604 + /// node using only the paths consisting of at most \c num arcs.
12.605 + ///
12.606 + /// The algorithm computes
12.607 + /// - the limited distance of each node from the root(s),
12.608 + /// - the predecessor arc for each node.
12.609 + ///
12.610 + /// \warning The paths with limited arc number cannot be retrieved
12.611 + /// easily with \ref path() or \ref predArc() functions. If you also
12.612 + /// need the shortest paths and not only the distances, you should
12.613 + /// store the \ref predMap() "predecessor map" after each iteration
12.614 + /// and build the path manually.
12.615 + ///
12.616 + /// \note bf.run(s, num) is just a shortcut of the following code.
12.617 + /// \code
12.618 + /// bf.init();
12.619 + /// bf.addSource(s);
12.620 + /// bf.limitedStart(num);
12.621 + /// \endcode
12.622 + void run(Node s, int num) {
12.623 + init();
12.624 + addSource(s);
12.625 + limitedStart(num);
12.626 + }
12.627 +
12.628 + ///@}
12.629 +
12.630 + /// \brief LEMON iterator for getting the active nodes.
12.631 + ///
12.632 + /// This class provides a common style LEMON iterator that traverses
12.633 + /// the active nodes of the Bellman-Ford algorithm after the last
12.634 + /// phase. These nodes should be checked in the next phase to
12.635 + /// find augmenting arcs outgoing from them.
12.636 + class ActiveIt {
12.637 + public:
12.638 +
12.639 + /// \brief Constructor.
12.640 + ///
12.641 + /// Constructor for getting the active nodes of the given BellmanFord
12.642 + /// instance.
12.643 + ActiveIt(const BellmanFord& algorithm) : _algorithm(&algorithm)
12.644 + {
12.645 + _index = _algorithm->_process.size() - 1;
12.646 + }
12.647 +
12.648 + /// \brief Invalid constructor.
12.649 + ///
12.650 + /// Invalid constructor.
12.651 + ActiveIt(Invalid) : _algorithm(0), _index(-1) {}
12.652 +
12.653 + /// \brief Conversion to \c Node.
12.654 + ///
12.655 + /// Conversion to \c Node.
12.656 + operator Node() const {
12.657 + return _index >= 0 ? _algorithm->_process[_index] : INVALID;
12.658 + }
12.659 +
12.660 + /// \brief Increment operator.
12.661 + ///
12.662 + /// Increment operator.
12.663 + ActiveIt& operator++() {
12.664 + --_index;
12.665 + return *this;
12.666 + }
12.667 +
12.668 + bool operator==(const ActiveIt& it) const {
12.669 + return static_cast<Node>(*this) == static_cast<Node>(it);
12.670 + }
12.671 + bool operator!=(const ActiveIt& it) const {
12.672 + return static_cast<Node>(*this) != static_cast<Node>(it);
12.673 + }
12.674 + bool operator<(const ActiveIt& it) const {
12.675 + return static_cast<Node>(*this) < static_cast<Node>(it);
12.676 + }
12.677 +
12.678 + private:
12.679 + const BellmanFord* _algorithm;
12.680 + int _index;
12.681 + };
12.682 +
12.683 + /// \name Query Functions
12.684 + /// The result of the Bellman-Ford algorithm can be obtained using these
12.685 + /// functions.\n
12.686 + /// Either \ref run() or \ref init() should be called before using them.
12.687 +
12.688 + ///@{
12.689 +
12.690 + /// \brief The shortest path to the given node.
12.691 + ///
12.692 + /// Gives back the shortest path to the given node from the root(s).
12.693 + ///
12.694 + /// \warning \c t should be reached from the root(s).
12.695 + ///
12.696 + /// \pre Either \ref run() or \ref init() must be called before
12.697 + /// using this function.
12.698 + Path path(Node t) const
12.699 + {
12.700 + return Path(*_gr, *_pred, t);
12.701 + }
12.702 +
12.703 + /// \brief The distance of the given node from the root(s).
12.704 + ///
12.705 + /// Returns the distance of the given node from the root(s).
12.706 + ///
12.707 + /// \warning If node \c v is not reached from the root(s), then
12.708 + /// the return value of this function is undefined.
12.709 + ///
12.710 + /// \pre Either \ref run() or \ref init() must be called before
12.711 + /// using this function.
12.712 + Value dist(Node v) const { return (*_dist)[v]; }
12.713 +
12.714 + /// \brief Returns the 'previous arc' of the shortest path tree for
12.715 + /// the given node.
12.716 + ///
12.717 + /// This function returns the 'previous arc' of the shortest path
12.718 + /// tree for node \c v, i.e. it returns the last arc of a
12.719 + /// shortest path from a root to \c v. It is \c INVALID if \c v
12.720 + /// is not reached from the root(s) or if \c v is a root.
12.721 + ///
12.722 + /// The shortest path tree used here is equal to the shortest path
12.723 + /// tree used in \ref predNode() and \predMap().
12.724 + ///
12.725 + /// \pre Either \ref run() or \ref init() must be called before
12.726 + /// using this function.
12.727 + Arc predArc(Node v) const { return (*_pred)[v]; }
12.728 +
12.729 + /// \brief Returns the 'previous node' of the shortest path tree for
12.730 + /// the given node.
12.731 + ///
12.732 + /// This function returns the 'previous node' of the shortest path
12.733 + /// tree for node \c v, i.e. it returns the last but one node of
12.734 + /// a shortest path from a root to \c v. It is \c INVALID if \c v
12.735 + /// is not reached from the root(s) or if \c v is a root.
12.736 + ///
12.737 + /// The shortest path tree used here is equal to the shortest path
12.738 + /// tree used in \ref predArc() and \predMap().
12.739 + ///
12.740 + /// \pre Either \ref run() or \ref init() must be called before
12.741 + /// using this function.
12.742 + Node predNode(Node v) const {
12.743 + return (*_pred)[v] == INVALID ? INVALID : _gr->source((*_pred)[v]);
12.744 + }
12.745 +
12.746 + /// \brief Returns a const reference to the node map that stores the
12.747 + /// distances of the nodes.
12.748 + ///
12.749 + /// Returns a const reference to the node map that stores the distances
12.750 + /// of the nodes calculated by the algorithm.
12.751 + ///
12.752 + /// \pre Either \ref run() or \ref init() must be called before
12.753 + /// using this function.
12.754 + const DistMap &distMap() const { return *_dist;}
12.755 +
12.756 + /// \brief Returns a const reference to the node map that stores the
12.757 + /// predecessor arcs.
12.758 + ///
12.759 + /// Returns a const reference to the node map that stores the predecessor
12.760 + /// arcs, which form the shortest path tree (forest).
12.761 + ///
12.762 + /// \pre Either \ref run() or \ref init() must be called before
12.763 + /// using this function.
12.764 + const PredMap &predMap() const { return *_pred; }
12.765 +
12.766 + /// \brief Checks if a node is reached from the root(s).
12.767 + ///
12.768 + /// Returns \c true if \c v is reached from the root(s).
12.769 + ///
12.770 + /// \pre Either \ref run() or \ref init() must be called before
12.771 + /// using this function.
12.772 + bool reached(Node v) const {
12.773 + return (*_dist)[v] != OperationTraits::infinity();
12.774 + }
12.775 +
12.776 + /// \brief Gives back a negative cycle.
12.777 + ///
12.778 + /// This function gives back a directed cycle with negative total
12.779 + /// length if the algorithm has already found one.
12.780 + /// Otherwise it gives back an empty path.
12.781 + lemon::Path<Digraph> negativeCycle() {
12.782 + typename Digraph::template NodeMap<int> state(*_gr, -1);
12.783 + lemon::Path<Digraph> cycle;
12.784 + for (int i = 0; i < int(_process.size()); ++i) {
12.785 + if (state[_process[i]] != -1) continue;
12.786 + for (Node v = _process[i]; (*_pred)[v] != INVALID;
12.787 + v = _gr->source((*_pred)[v])) {
12.788 + if (state[v] == i) {
12.789 + cycle.addFront((*_pred)[v]);
12.790 + for (Node u = _gr->source((*_pred)[v]); u != v;
12.791 + u = _gr->source((*_pred)[u])) {
12.792 + cycle.addFront((*_pred)[u]);
12.793 + }
12.794 + return cycle;
12.795 + }
12.796 + else if (state[v] >= 0) {
12.797 + break;
12.798 + }
12.799 + state[v] = i;
12.800 + }
12.801 + }
12.802 + return cycle;
12.803 + }
12.804 +
12.805 + ///@}
12.806 + };
12.807 +
12.808 + /// \brief Default traits class of bellmanFord() function.
12.809 + ///
12.810 + /// Default traits class of bellmanFord() function.
12.811 + /// \tparam GR The type of the digraph.
12.812 + /// \tparam LEN The type of the length map.
12.813 + template <typename GR, typename LEN>
12.814 + struct BellmanFordWizardDefaultTraits {
12.815 + /// The type of the digraph the algorithm runs on.
12.816 + typedef GR Digraph;
12.817 +
12.818 + /// \brief The type of the map that stores the arc lengths.
12.819 + ///
12.820 + /// The type of the map that stores the arc lengths.
12.821 + /// It must meet the \ref concepts::ReadMap "ReadMap" concept.
12.822 + typedef LEN LengthMap;
12.823 +
12.824 + /// The type of the arc lengths.
12.825 + typedef typename LEN::Value Value;
12.826 +
12.827 + /// \brief Operation traits for Bellman-Ford algorithm.
12.828 + ///
12.829 + /// It defines the used operations and the infinity value for the
12.830 + /// given \c Value type.
12.831 + /// \see BellmanFordDefaultOperationTraits
12.832 + typedef BellmanFordDefaultOperationTraits<Value> OperationTraits;
12.833 +
12.834 + /// \brief The type of the map that stores the last
12.835 + /// arcs of the shortest paths.
12.836 + ///
12.837 + /// The type of the map that stores the last arcs of the shortest paths.
12.838 + /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
12.839 + typedef typename GR::template NodeMap<typename GR::Arc> PredMap;
12.840 +
12.841 + /// \brief Instantiates a \c PredMap.
12.842 + ///
12.843 + /// This function instantiates a \ref PredMap.
12.844 + /// \param g is the digraph to which we would like to define the
12.845 + /// \ref PredMap.
12.846 + static PredMap *createPredMap(const GR &g) {
12.847 + return new PredMap(g);
12.848 + }
12.849 +
12.850 + /// \brief The type of the map that stores the distances of the nodes.
12.851 + ///
12.852 + /// The type of the map that stores the distances of the nodes.
12.853 + /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
12.854 + typedef typename GR::template NodeMap<Value> DistMap;
12.855 +
12.856 + /// \brief Instantiates a \c DistMap.
12.857 + ///
12.858 + /// This function instantiates a \ref DistMap.
12.859 + /// \param g is the digraph to which we would like to define the
12.860 + /// \ref DistMap.
12.861 + static DistMap *createDistMap(const GR &g) {
12.862 + return new DistMap(g);
12.863 + }
12.864 +
12.865 + ///The type of the shortest paths.
12.866 +
12.867 + ///The type of the shortest paths.
12.868 + ///It must meet the \ref concepts::Path "Path" concept.
12.869 + typedef lemon::Path<Digraph> Path;
12.870 + };
12.871 +
12.872 + /// \brief Default traits class used by BellmanFordWizard.
12.873 + ///
12.874 + /// Default traits class used by BellmanFordWizard.
12.875 + /// \tparam GR The type of the digraph.
12.876 + /// \tparam LEN The type of the length map.
12.877 + template <typename GR, typename LEN>
12.878 + class BellmanFordWizardBase
12.879 + : public BellmanFordWizardDefaultTraits<GR, LEN> {
12.880 +
12.881 + typedef BellmanFordWizardDefaultTraits<GR, LEN> Base;
12.882 + protected:
12.883 + // Type of the nodes in the digraph.
12.884 + typedef typename Base::Digraph::Node Node;
12.885 +
12.886 + // Pointer to the underlying digraph.
12.887 + void *_graph;
12.888 + // Pointer to the length map
12.889 + void *_length;
12.890 + // Pointer to the map of predecessors arcs.
12.891 + void *_pred;
12.892 + // Pointer to the map of distances.
12.893 + void *_dist;
12.894 + //Pointer to the shortest path to the target node.
12.895 + void *_path;
12.896 + //Pointer to the distance of the target node.
12.897 + void *_di;
12.898 +
12.899 + public:
12.900 + /// Constructor.
12.901 +
12.902 + /// This constructor does not require parameters, it initiates
12.903 + /// all of the attributes to default values \c 0.
12.904 + BellmanFordWizardBase() :
12.905 + _graph(0), _length(0), _pred(0), _dist(0), _path(0), _di(0) {}
12.906 +
12.907 + /// Constructor.
12.908 +
12.909 + /// This constructor requires two parameters,
12.910 + /// others are initiated to \c 0.
12.911 + /// \param gr The digraph the algorithm runs on.
12.912 + /// \param len The length map.
12.913 + BellmanFordWizardBase(const GR& gr,
12.914 + const LEN& len) :
12.915 + _graph(reinterpret_cast<void*>(const_cast<GR*>(&gr))),
12.916 + _length(reinterpret_cast<void*>(const_cast<LEN*>(&len))),
12.917 + _pred(0), _dist(0), _path(0), _di(0) {}
12.918 +
12.919 + };
12.920 +
12.921 + /// \brief Auxiliary class for the function-type interface of the
12.922 + /// \ref BellmanFord "Bellman-Ford" algorithm.
12.923 + ///
12.924 + /// This auxiliary class is created to implement the
12.925 + /// \ref bellmanFord() "function-type interface" of the
12.926 + /// \ref BellmanFord "Bellman-Ford" algorithm.
12.927 + /// It does not have own \ref run() method, it uses the
12.928 + /// functions and features of the plain \ref BellmanFord.
12.929 + ///
12.930 + /// This class should only be used through the \ref bellmanFord()
12.931 + /// function, which makes it easier to use the algorithm.
12.932 + template<class TR>
12.933 + class BellmanFordWizard : public TR {
12.934 + typedef TR Base;
12.935 +
12.936 + typedef typename TR::Digraph Digraph;
12.937 +
12.938 + typedef typename Digraph::Node Node;
12.939 + typedef typename Digraph::NodeIt NodeIt;
12.940 + typedef typename Digraph::Arc Arc;
12.941 + typedef typename Digraph::OutArcIt ArcIt;
12.942 +
12.943 + typedef typename TR::LengthMap LengthMap;
12.944 + typedef typename LengthMap::Value Value;
12.945 + typedef typename TR::PredMap PredMap;
12.946 + typedef typename TR::DistMap DistMap;
12.947 + typedef typename TR::Path Path;
12.948 +
12.949 + public:
12.950 + /// Constructor.
12.951 + BellmanFordWizard() : TR() {}
12.952 +
12.953 + /// \brief Constructor that requires parameters.
12.954 + ///
12.955 + /// Constructor that requires parameters.
12.956 + /// These parameters will be the default values for the traits class.
12.957 + /// \param gr The digraph the algorithm runs on.
12.958 + /// \param len The length map.
12.959 + BellmanFordWizard(const Digraph& gr, const LengthMap& len)
12.960 + : TR(gr, len) {}
12.961 +
12.962 + /// \brief Copy constructor
12.963 + BellmanFordWizard(const TR &b) : TR(b) {}
12.964 +
12.965 + ~BellmanFordWizard() {}
12.966 +
12.967 + /// \brief Runs the Bellman-Ford algorithm from the given source node.
12.968 + ///
12.969 + /// This method runs the Bellman-Ford algorithm from the given source
12.970 + /// node in order to compute the shortest path to each node.
12.971 + void run(Node s) {
12.972 + BellmanFord<Digraph,LengthMap,TR>
12.973 + bf(*reinterpret_cast<const Digraph*>(Base::_graph),
12.974 + *reinterpret_cast<const LengthMap*>(Base::_length));
12.975 + if (Base::_pred) bf.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
12.976 + if (Base::_dist) bf.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
12.977 + bf.run(s);
12.978 + }
12.979 +
12.980 + /// \brief Runs the Bellman-Ford algorithm to find the shortest path
12.981 + /// between \c s and \c t.
12.982 + ///
12.983 + /// This method runs the Bellman-Ford algorithm from node \c s
12.984 + /// in order to compute the shortest path to node \c t.
12.985 + /// Actually, it computes the shortest path to each node, but using
12.986 + /// this function you can retrieve the distance and the shortest path
12.987 + /// for a single target node easier.
12.988 + ///
12.989 + /// \return \c true if \c t is reachable form \c s.
12.990 + bool run(Node s, Node t) {
12.991 + BellmanFord<Digraph,LengthMap,TR>
12.992 + bf(*reinterpret_cast<const Digraph*>(Base::_graph),
12.993 + *reinterpret_cast<const LengthMap*>(Base::_length));
12.994 + if (Base::_pred) bf.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
12.995 + if (Base::_dist) bf.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
12.996 + bf.run(s);
12.997 + if (Base::_path) *reinterpret_cast<Path*>(Base::_path) = bf.path(t);
12.998 + if (Base::_di) *reinterpret_cast<Value*>(Base::_di) = bf.dist(t);
12.999 + return bf.reached(t);
12.1000 + }
12.1001 +
12.1002 + template<class T>
12.1003 + struct SetPredMapBase : public Base {
12.1004 + typedef T PredMap;
12.1005 + static PredMap *createPredMap(const Digraph &) { return 0; };
12.1006 + SetPredMapBase(const TR &b) : TR(b) {}
12.1007 + };
12.1008 +
12.1009 + /// \brief \ref named-templ-param "Named parameter" for setting
12.1010 + /// the predecessor map.
12.1011 + ///
12.1012 + /// \ref named-templ-param "Named parameter" for setting
12.1013 + /// the map that stores the predecessor arcs of the nodes.
12.1014 + template<class T>
12.1015 + BellmanFordWizard<SetPredMapBase<T> > predMap(const T &t) {
12.1016 + Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
12.1017 + return BellmanFordWizard<SetPredMapBase<T> >(*this);
12.1018 + }
12.1019 +
12.1020 + template<class T>
12.1021 + struct SetDistMapBase : public Base {
12.1022 + typedef T DistMap;
12.1023 + static DistMap *createDistMap(const Digraph &) { return 0; };
12.1024 + SetDistMapBase(const TR &b) : TR(b) {}
12.1025 + };
12.1026 +
12.1027 + /// \brief \ref named-templ-param "Named parameter" for setting
12.1028 + /// the distance map.
12.1029 + ///
12.1030 + /// \ref named-templ-param "Named parameter" for setting
12.1031 + /// the map that stores the distances of the nodes calculated
12.1032 + /// by the algorithm.
12.1033 + template<class T>
12.1034 + BellmanFordWizard<SetDistMapBase<T> > distMap(const T &t) {
12.1035 + Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
12.1036 + return BellmanFordWizard<SetDistMapBase<T> >(*this);
12.1037 + }
12.1038 +
12.1039 + template<class T>
12.1040 + struct SetPathBase : public Base {
12.1041 + typedef T Path;
12.1042 + SetPathBase(const TR &b) : TR(b) {}
12.1043 + };
12.1044 +
12.1045 + /// \brief \ref named-func-param "Named parameter" for getting
12.1046 + /// the shortest path to the target node.
12.1047 + ///
12.1048 + /// \ref named-func-param "Named parameter" for getting
12.1049 + /// the shortest path to the target node.
12.1050 + template<class T>
12.1051 + BellmanFordWizard<SetPathBase<T> > path(const T &t)
12.1052 + {
12.1053 + Base::_path=reinterpret_cast<void*>(const_cast<T*>(&t));
12.1054 + return BellmanFordWizard<SetPathBase<T> >(*this);
12.1055 + }
12.1056 +
12.1057 + /// \brief \ref named-func-param "Named parameter" for getting
12.1058 + /// the distance of the target node.
12.1059 + ///
12.1060 + /// \ref named-func-param "Named parameter" for getting
12.1061 + /// the distance of the target node.
12.1062 + BellmanFordWizard dist(const Value &d)
12.1063 + {
12.1064 + Base::_di=reinterpret_cast<void*>(const_cast<Value*>(&d));
12.1065 + return *this;
12.1066 + }
12.1067 +
12.1068 + };
12.1069 +
12.1070 + /// \brief Function type interface for the \ref BellmanFord "Bellman-Ford"
12.1071 + /// algorithm.
12.1072 + ///
12.1073 + /// \ingroup shortest_path
12.1074 + /// Function type interface for the \ref BellmanFord "Bellman-Ford"
12.1075 + /// algorithm.
12.1076 + ///
12.1077 + /// This function also has several \ref named-templ-func-param
12.1078 + /// "named parameters", they are declared as the members of class
12.1079 + /// \ref BellmanFordWizard.
12.1080 + /// The following examples show how to use these parameters.
12.1081 + /// \code
12.1082 + /// // Compute shortest path from node s to each node
12.1083 + /// bellmanFord(g,length).predMap(preds).distMap(dists).run(s);
12.1084 + ///
12.1085 + /// // Compute shortest path from s to t
12.1086 + /// bool reached = bellmanFord(g,length).path(p).dist(d).run(s,t);
12.1087 + /// \endcode
12.1088 + /// \warning Don't forget to put the \ref BellmanFordWizard::run() "run()"
12.1089 + /// to the end of the parameter list.
12.1090 + /// \sa BellmanFordWizard
12.1091 + /// \sa BellmanFord
12.1092 + template<typename GR, typename LEN>
12.1093 + BellmanFordWizard<BellmanFordWizardBase<GR,LEN> >
12.1094 + bellmanFord(const GR& digraph,
12.1095 + const LEN& length)
12.1096 + {
12.1097 + return BellmanFordWizard<BellmanFordWizardBase<GR,LEN> >(digraph, length);
12.1098 + }
12.1099 +
12.1100 +} //END OF NAMESPACE LEMON
12.1101 +
12.1102 +#endif
12.1103 +
13.1 --- a/lemon/bfs.h Tue Aug 18 10:08:28 2009 +0200
13.2 +++ b/lemon/bfs.h Thu Nov 05 08:39:49 2009 +0100
13.3 @@ -47,7 +47,7 @@
13.4 ///
13.5 ///The type of the map that stores the predecessor
13.6 ///arcs of the shortest paths.
13.7 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
13.8 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
13.9 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
13.10 ///Instantiates a \c PredMap.
13.11
13.12 @@ -62,7 +62,8 @@
13.13 ///The type of the map that indicates which nodes are processed.
13.14
13.15 ///The type of the map that indicates which nodes are processed.
13.16 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
13.17 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
13.18 + ///By default it is a NullMap.
13.19 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
13.20 ///Instantiates a \c ProcessedMap.
13.21
13.22 @@ -81,7 +82,7 @@
13.23 ///The type of the map that indicates which nodes are reached.
13.24
13.25 ///The type of the map that indicates which nodes are reached.
13.26 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
13.27 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
13.28 typedef typename Digraph::template NodeMap<bool> ReachedMap;
13.29 ///Instantiates a \c ReachedMap.
13.30
13.31 @@ -96,7 +97,7 @@
13.32 ///The type of the map that stores the distances of the nodes.
13.33
13.34 ///The type of the map that stores the distances of the nodes.
13.35 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
13.36 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
13.37 typedef typename Digraph::template NodeMap<int> DistMap;
13.38 ///Instantiates a \c DistMap.
13.39
13.40 @@ -225,7 +226,7 @@
13.41 ///
13.42 ///\ref named-templ-param "Named parameter" for setting
13.43 ///\c PredMap type.
13.44 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
13.45 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
13.46 template <class T>
13.47 struct SetPredMap : public Bfs< Digraph, SetPredMapTraits<T> > {
13.48 typedef Bfs< Digraph, SetPredMapTraits<T> > Create;
13.49 @@ -245,7 +246,7 @@
13.50 ///
13.51 ///\ref named-templ-param "Named parameter" for setting
13.52 ///\c DistMap type.
13.53 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
13.54 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
13.55 template <class T>
13.56 struct SetDistMap : public Bfs< Digraph, SetDistMapTraits<T> > {
13.57 typedef Bfs< Digraph, SetDistMapTraits<T> > Create;
13.58 @@ -265,7 +266,7 @@
13.59 ///
13.60 ///\ref named-templ-param "Named parameter" for setting
13.61 ///\c ReachedMap type.
13.62 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
13.63 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
13.64 template <class T>
13.65 struct SetReachedMap : public Bfs< Digraph, SetReachedMapTraits<T> > {
13.66 typedef Bfs< Digraph, SetReachedMapTraits<T> > Create;
13.67 @@ -285,7 +286,7 @@
13.68 ///
13.69 ///\ref named-templ-param "Named parameter" for setting
13.70 ///\c ProcessedMap type.
13.71 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
13.72 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
13.73 template <class T>
13.74 struct SetProcessedMap : public Bfs< Digraph, SetProcessedMapTraits<T> > {
13.75 typedef Bfs< Digraph, SetProcessedMapTraits<T> > Create;
13.76 @@ -413,8 +414,8 @@
13.77 ///\name Execution Control
13.78 ///The simplest way to execute the BFS algorithm is to use one of the
13.79 ///member functions called \ref run(Node) "run()".\n
13.80 - ///If you need more control on the execution, first you have to call
13.81 - ///\ref init(), then you can add several source nodes with
13.82 + ///If you need better control on the execution, you have to call
13.83 + ///\ref init() first, then you can add several source nodes with
13.84 ///\ref addSource(). Finally the actual path computation can be
13.85 ///performed with one of the \ref start() functions.
13.86
13.87 @@ -737,9 +738,9 @@
13.88
13.89 ///@{
13.90
13.91 - ///The shortest path to a node.
13.92 + ///The shortest path to the given node.
13.93
13.94 - ///Returns the shortest path to a node.
13.95 + ///Returns the shortest path to the given node from the root(s).
13.96 ///
13.97 ///\warning \c t should be reached from the root(s).
13.98 ///
13.99 @@ -747,9 +748,9 @@
13.100 ///must be called before using this function.
13.101 Path path(Node t) const { return Path(*G, *_pred, t); }
13.102
13.103 - ///The distance of a node from the root(s).
13.104 + ///The distance of the given node from the root(s).
13.105
13.106 - ///Returns the distance of a node from the root(s).
13.107 + ///Returns the distance of the given node from the root(s).
13.108 ///
13.109 ///\warning If node \c v is not reached from the root(s), then
13.110 ///the return value of this function is undefined.
13.111 @@ -758,29 +759,31 @@
13.112 ///must be called before using this function.
13.113 int dist(Node v) const { return (*_dist)[v]; }
13.114
13.115 - ///Returns the 'previous arc' of the shortest path tree for a node.
13.116 -
13.117 + ///\brief Returns the 'previous arc' of the shortest path tree for
13.118 + ///the given node.
13.119 + ///
13.120 ///This function returns the 'previous arc' of the shortest path
13.121 ///tree for the node \c v, i.e. it returns the last arc of a
13.122 ///shortest path from a root to \c v. It is \c INVALID if \c v
13.123 ///is not reached from the root(s) or if \c v is a root.
13.124 ///
13.125 ///The shortest path tree used here is equal to the shortest path
13.126 - ///tree used in \ref predNode().
13.127 + ///tree used in \ref predNode() and \ref predMap().
13.128 ///
13.129 ///\pre Either \ref run(Node) "run()" or \ref init()
13.130 ///must be called before using this function.
13.131 Arc predArc(Node v) const { return (*_pred)[v];}
13.132
13.133 - ///Returns the 'previous node' of the shortest path tree for a node.
13.134 -
13.135 + ///\brief Returns the 'previous node' of the shortest path tree for
13.136 + ///the given node.
13.137 + ///
13.138 ///This function returns the 'previous node' of the shortest path
13.139 ///tree for the node \c v, i.e. it returns the last but one node
13.140 - ///from a shortest path from a root to \c v. It is \c INVALID
13.141 + ///of a shortest path from a root to \c v. It is \c INVALID
13.142 ///if \c v is not reached from the root(s) or if \c v is a root.
13.143 ///
13.144 ///The shortest path tree used here is equal to the shortest path
13.145 - ///tree used in \ref predArc().
13.146 + ///tree used in \ref predArc() and \ref predMap().
13.147 ///
13.148 ///\pre Either \ref run(Node) "run()" or \ref init()
13.149 ///must be called before using this function.
13.150 @@ -801,13 +804,13 @@
13.151 ///predecessor arcs.
13.152 ///
13.153 ///Returns a const reference to the node map that stores the predecessor
13.154 - ///arcs, which form the shortest path tree.
13.155 + ///arcs, which form the shortest path tree (forest).
13.156 ///
13.157 ///\pre Either \ref run(Node) "run()" or \ref init()
13.158 ///must be called before using this function.
13.159 const PredMap &predMap() const { return *_pred;}
13.160
13.161 - ///Checks if a node is reached from the root(s).
13.162 + ///Checks if the given node is reached from the root(s).
13.163
13.164 ///Returns \c true if \c v is reached from the root(s).
13.165 ///
13.166 @@ -833,7 +836,7 @@
13.167 ///
13.168 ///The type of the map that stores the predecessor
13.169 ///arcs of the shortest paths.
13.170 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
13.171 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
13.172 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
13.173 ///Instantiates a PredMap.
13.174
13.175 @@ -848,7 +851,7 @@
13.176 ///The type of the map that indicates which nodes are processed.
13.177
13.178 ///The type of the map that indicates which nodes are processed.
13.179 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
13.180 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
13.181 ///By default it is a NullMap.
13.182 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
13.183 ///Instantiates a ProcessedMap.
13.184 @@ -868,7 +871,7 @@
13.185 ///The type of the map that indicates which nodes are reached.
13.186
13.187 ///The type of the map that indicates which nodes are reached.
13.188 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
13.189 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
13.190 typedef typename Digraph::template NodeMap<bool> ReachedMap;
13.191 ///Instantiates a ReachedMap.
13.192
13.193 @@ -883,7 +886,7 @@
13.194 ///The type of the map that stores the distances of the nodes.
13.195
13.196 ///The type of the map that stores the distances of the nodes.
13.197 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
13.198 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
13.199 typedef typename Digraph::template NodeMap<int> DistMap;
13.200 ///Instantiates a DistMap.
13.201
13.202 @@ -898,18 +901,14 @@
13.203 ///The type of the shortest paths.
13.204
13.205 ///The type of the shortest paths.
13.206 - ///It must meet the \ref concepts::Path "Path" concept.
13.207 + ///It must conform to the \ref concepts::Path "Path" concept.
13.208 typedef lemon::Path<Digraph> Path;
13.209 };
13.210
13.211 /// Default traits class used by BfsWizard
13.212
13.213 - /// To make it easier to use Bfs algorithm
13.214 - /// we have created a wizard class.
13.215 - /// This \ref BfsWizard class needs default traits,
13.216 - /// as well as the \ref Bfs class.
13.217 - /// The \ref BfsWizardBase is a class to be the default traits of the
13.218 - /// \ref BfsWizard class.
13.219 + /// Default traits class used by BfsWizard.
13.220 + /// \tparam GR The type of the digraph.
13.221 template<class GR>
13.222 class BfsWizardBase : public BfsWizardDefaultTraits<GR>
13.223 {
13.224 @@ -937,7 +936,7 @@
13.225 public:
13.226 /// Constructor.
13.227
13.228 - /// This constructor does not require parameters, therefore it initiates
13.229 + /// This constructor does not require parameters, it initiates
13.230 /// all of the attributes to \c 0.
13.231 BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
13.232 _dist(0), _path(0), _di(0) {}
13.233 @@ -967,7 +966,6 @@
13.234 {
13.235 typedef TR Base;
13.236
13.237 - ///The type of the digraph the algorithm runs on.
13.238 typedef typename TR::Digraph Digraph;
13.239
13.240 typedef typename Digraph::Node Node;
13.241 @@ -975,16 +973,10 @@
13.242 typedef typename Digraph::Arc Arc;
13.243 typedef typename Digraph::OutArcIt OutArcIt;
13.244
13.245 - ///\brief The type of the map that stores the predecessor
13.246 - ///arcs of the shortest paths.
13.247 typedef typename TR::PredMap PredMap;
13.248 - ///\brief The type of the map that stores the distances of the nodes.
13.249 typedef typename TR::DistMap DistMap;
13.250 - ///\brief The type of the map that indicates which nodes are reached.
13.251 typedef typename TR::ReachedMap ReachedMap;
13.252 - ///\brief The type of the map that indicates which nodes are processed.
13.253 typedef typename TR::ProcessedMap ProcessedMap;
13.254 - ///The type of the shortest paths
13.255 typedef typename TR::Path Path;
13.256
13.257 public:
13.258 @@ -1067,11 +1059,12 @@
13.259 static PredMap *createPredMap(const Digraph &) { return 0; };
13.260 SetPredMapBase(const TR &b) : TR(b) {}
13.261 };
13.262 - ///\brief \ref named-func-param "Named parameter"
13.263 - ///for setting PredMap object.
13.264 +
13.265 + ///\brief \ref named-templ-param "Named parameter" for setting
13.266 + ///the predecessor map.
13.267 ///
13.268 - ///\ref named-func-param "Named parameter"
13.269 - ///for setting PredMap object.
13.270 + ///\ref named-templ-param "Named parameter" function for setting
13.271 + ///the map that stores the predecessor arcs of the nodes.
13.272 template<class T>
13.273 BfsWizard<SetPredMapBase<T> > predMap(const T &t)
13.274 {
13.275 @@ -1085,11 +1078,12 @@
13.276 static ReachedMap *createReachedMap(const Digraph &) { return 0; };
13.277 SetReachedMapBase(const TR &b) : TR(b) {}
13.278 };
13.279 - ///\brief \ref named-func-param "Named parameter"
13.280 - ///for setting ReachedMap object.
13.281 +
13.282 + ///\brief \ref named-templ-param "Named parameter" for setting
13.283 + ///the reached map.
13.284 ///
13.285 - /// \ref named-func-param "Named parameter"
13.286 - ///for setting ReachedMap object.
13.287 + ///\ref named-templ-param "Named parameter" function for setting
13.288 + ///the map that indicates which nodes are reached.
13.289 template<class T>
13.290 BfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
13.291 {
13.292 @@ -1103,11 +1097,13 @@
13.293 static DistMap *createDistMap(const Digraph &) { return 0; };
13.294 SetDistMapBase(const TR &b) : TR(b) {}
13.295 };
13.296 - ///\brief \ref named-func-param "Named parameter"
13.297 - ///for setting DistMap object.
13.298 +
13.299 + ///\brief \ref named-templ-param "Named parameter" for setting
13.300 + ///the distance map.
13.301 ///
13.302 - /// \ref named-func-param "Named parameter"
13.303 - ///for setting DistMap object.
13.304 + ///\ref named-templ-param "Named parameter" function for setting
13.305 + ///the map that stores the distances of the nodes calculated
13.306 + ///by the algorithm.
13.307 template<class T>
13.308 BfsWizard<SetDistMapBase<T> > distMap(const T &t)
13.309 {
13.310 @@ -1121,11 +1117,12 @@
13.311 static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
13.312 SetProcessedMapBase(const TR &b) : TR(b) {}
13.313 };
13.314 - ///\brief \ref named-func-param "Named parameter"
13.315 - ///for setting ProcessedMap object.
13.316 +
13.317 + ///\brief \ref named-func-param "Named parameter" for setting
13.318 + ///the processed map.
13.319 ///
13.320 - /// \ref named-func-param "Named parameter"
13.321 - ///for setting ProcessedMap object.
13.322 + ///\ref named-templ-param "Named parameter" function for setting
13.323 + ///the map that indicates which nodes are processed.
13.324 template<class T>
13.325 BfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
13.326 {
13.327 @@ -1264,7 +1261,7 @@
13.328 /// \brief The type of the map that indicates which nodes are reached.
13.329 ///
13.330 /// The type of the map that indicates which nodes are reached.
13.331 - /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
13.332 + /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
13.333 typedef typename Digraph::template NodeMap<bool> ReachedMap;
13.334
13.335 /// \brief Instantiates a ReachedMap.
13.336 @@ -1425,8 +1422,8 @@
13.337 /// \name Execution Control
13.338 /// The simplest way to execute the BFS algorithm is to use one of the
13.339 /// member functions called \ref run(Node) "run()".\n
13.340 - /// If you need more control on the execution, first you have to call
13.341 - /// \ref init(), then you can add several source nodes with
13.342 + /// If you need better control on the execution, you have to call
13.343 + /// \ref init() first, then you can add several source nodes with
13.344 /// \ref addSource(). Finally the actual path computation can be
13.345 /// performed with one of the \ref start() functions.
13.346
13.347 @@ -1735,7 +1732,7 @@
13.348
13.349 ///@{
13.350
13.351 - /// \brief Checks if a node is reached from the root(s).
13.352 + /// \brief Checks if the given node is reached from the root(s).
13.353 ///
13.354 /// Returns \c true if \c v is reached from the root(s).
13.355 ///
14.1 --- a/lemon/bin_heap.h Tue Aug 18 10:08:28 2009 +0200
14.2 +++ b/lemon/bin_heap.h Thu Nov 05 08:39:49 2009 +0100
14.3 @@ -19,9 +19,9 @@
14.4 #ifndef LEMON_BIN_HEAP_H
14.5 #define LEMON_BIN_HEAP_H
14.6
14.7 -///\ingroup auxdat
14.8 +///\ingroup heaps
14.9 ///\file
14.10 -///\brief Binary Heap implementation.
14.11 +///\brief Binary heap implementation.
14.12
14.13 #include <vector>
14.14 #include <utility>
14.15 @@ -29,45 +29,41 @@
14.16
14.17 namespace lemon {
14.18
14.19 - ///\ingroup auxdat
14.20 + /// \ingroup heaps
14.21 ///
14.22 - ///\brief A Binary Heap implementation.
14.23 + /// \brief Binary heap data structure.
14.24 ///
14.25 - ///This class implements the \e binary \e heap data structure.
14.26 + /// This class implements the \e binary \e heap data structure.
14.27 + /// It fully conforms to the \ref concepts::Heap "heap concept".
14.28 ///
14.29 - ///A \e heap is a data structure for storing items with specified values
14.30 - ///called \e priorities in such a way that finding the item with minimum
14.31 - ///priority is efficient. \c CMP specifies the ordering of the priorities.
14.32 - ///In a heap one can change the priority of an item, add or erase an
14.33 - ///item, etc.
14.34 - ///
14.35 - ///\tparam PR Type of the priority of the items.
14.36 - ///\tparam IM A read and writable item map with int values, used internally
14.37 - ///to handle the cross references.
14.38 - ///\tparam CMP A functor class for the ordering of the priorities.
14.39 - ///The default is \c std::less<PR>.
14.40 - ///
14.41 - ///\sa FibHeap
14.42 - ///\sa Dijkstra
14.43 + /// \tparam PR Type of the priorities of the items.
14.44 + /// \tparam IM A read-writable item map with \c int values, used
14.45 + /// internally to handle the cross references.
14.46 + /// \tparam CMP A functor class for comparing the priorities.
14.47 + /// The default is \c std::less<PR>.
14.48 +#ifdef DOXYGEN
14.49 + template <typename PR, typename IM, typename CMP>
14.50 +#else
14.51 template <typename PR, typename IM, typename CMP = std::less<PR> >
14.52 +#endif
14.53 class BinHeap {
14.54 + public:
14.55
14.56 - public:
14.57 - ///\e
14.58 + /// Type of the item-int map.
14.59 typedef IM ItemIntMap;
14.60 - ///\e
14.61 + /// Type of the priorities.
14.62 typedef PR Prio;
14.63 - ///\e
14.64 + /// Type of the items stored in the heap.
14.65 typedef typename ItemIntMap::Key Item;
14.66 - ///\e
14.67 + /// Type of the item-priority pairs.
14.68 typedef std::pair<Item,Prio> Pair;
14.69 - ///\e
14.70 + /// Functor type for comparing the priorities.
14.71 typedef CMP Compare;
14.72
14.73 - /// \brief Type to represent the items states.
14.74 + /// \brief Type to represent the states of the items.
14.75 ///
14.76 - /// Each Item element have a state associated to it. It may be "in heap",
14.77 - /// "pre heap" or "post heap". The latter two are indifferent from the
14.78 + /// Each item has a state associated to it. It can be "in heap",
14.79 + /// "pre-heap" or "post-heap". The latter two are indifferent from the
14.80 /// heap's point of view, but may be useful to the user.
14.81 ///
14.82 /// The item-int map must be initialized in such way that it assigns
14.83 @@ -84,42 +80,43 @@
14.84 ItemIntMap &_iim;
14.85
14.86 public:
14.87 - /// \brief The constructor.
14.88 +
14.89 + /// \brief Constructor.
14.90 ///
14.91 - /// The constructor.
14.92 - /// \param map should be given to the constructor, since it is used
14.93 - /// internally to handle the cross references. The value of the map
14.94 - /// must be \c PRE_HEAP (<tt>-1</tt>) for every item.
14.95 + /// Constructor.
14.96 + /// \param map A map that assigns \c int values to the items.
14.97 + /// It is used internally to handle the cross references.
14.98 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
14.99 explicit BinHeap(ItemIntMap &map) : _iim(map) {}
14.100
14.101 - /// \brief The constructor.
14.102 + /// \brief Constructor.
14.103 ///
14.104 - /// The constructor.
14.105 - /// \param map should be given to the constructor, since it is used
14.106 - /// internally to handle the cross references. The value of the map
14.107 - /// should be PRE_HEAP (-1) for each element.
14.108 - ///
14.109 - /// \param comp The comparator function object.
14.110 + /// Constructor.
14.111 + /// \param map A map that assigns \c int values to the items.
14.112 + /// It is used internally to handle the cross references.
14.113 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
14.114 + /// \param comp The function object used for comparing the priorities.
14.115 BinHeap(ItemIntMap &map, const Compare &comp)
14.116 : _iim(map), _comp(comp) {}
14.117
14.118
14.119 - /// The number of items stored in the heap.
14.120 + /// \brief The number of items stored in the heap.
14.121 ///
14.122 - /// \brief Returns the number of items stored in the heap.
14.123 + /// This function returns the number of items stored in the heap.
14.124 int size() const { return _data.size(); }
14.125
14.126 - /// \brief Checks if the heap stores no items.
14.127 + /// \brief Check if the heap is empty.
14.128 ///
14.129 - /// Returns \c true if and only if the heap stores no items.
14.130 + /// This function returns \c true if the heap is empty.
14.131 bool empty() const { return _data.empty(); }
14.132
14.133 - /// \brief Make empty this heap.
14.134 + /// \brief Make the heap empty.
14.135 ///
14.136 - /// Make empty this heap. It does not change the cross reference map.
14.137 - /// If you want to reuse what is not surely empty you should first clear
14.138 - /// the heap and after that you should set the cross reference map for
14.139 - /// each item to \c PRE_HEAP.
14.140 + /// This functon makes the heap empty.
14.141 + /// It does not change the cross reference map. If you want to reuse
14.142 + /// a heap that is not surely empty, you should first clear it and
14.143 + /// then you should set the cross reference map to \c PRE_HEAP
14.144 + /// for each item.
14.145 void clear() {
14.146 _data.clear();
14.147 }
14.148 @@ -127,12 +124,12 @@
14.149 private:
14.150 static int parent(int i) { return (i-1)/2; }
14.151
14.152 - static int second_child(int i) { return 2*i+2; }
14.153 + static int secondChild(int i) { return 2*i+2; }
14.154 bool less(const Pair &p1, const Pair &p2) const {
14.155 return _comp(p1.second, p2.second);
14.156 }
14.157
14.158 - int bubble_up(int hole, Pair p) {
14.159 + int bubbleUp(int hole, Pair p) {
14.160 int par = parent(hole);
14.161 while( hole>0 && less(p,_data[par]) ) {
14.162 move(_data[par],hole);
14.163 @@ -143,8 +140,8 @@
14.164 return hole;
14.165 }
14.166
14.167 - int bubble_down(int hole, Pair p, int length) {
14.168 - int child = second_child(hole);
14.169 + int bubbleDown(int hole, Pair p, int length) {
14.170 + int child = secondChild(hole);
14.171 while(child < length) {
14.172 if( less(_data[child-1], _data[child]) ) {
14.173 --child;
14.174 @@ -153,7 +150,7 @@
14.175 goto ok;
14.176 move(_data[child], hole);
14.177 hole = child;
14.178 - child = second_child(hole);
14.179 + child = secondChild(hole);
14.180 }
14.181 child--;
14.182 if( child<length && less(_data[child], p) ) {
14.183 @@ -171,87 +168,91 @@
14.184 }
14.185
14.186 public:
14.187 +
14.188 /// \brief Insert a pair of item and priority into the heap.
14.189 ///
14.190 - /// Adds \c p.first to the heap with priority \c p.second.
14.191 + /// This function inserts \c p.first to the heap with priority
14.192 + /// \c p.second.
14.193 /// \param p The pair to insert.
14.194 + /// \pre \c p.first must not be stored in the heap.
14.195 void push(const Pair &p) {
14.196 int n = _data.size();
14.197 _data.resize(n+1);
14.198 - bubble_up(n, p);
14.199 + bubbleUp(n, p);
14.200 }
14.201
14.202 - /// \brief Insert an item into the heap with the given heap.
14.203 + /// \brief Insert an item into the heap with the given priority.
14.204 ///
14.205 - /// Adds \c i to the heap with priority \c p.
14.206 + /// This function inserts the given item into the heap with the
14.207 + /// given priority.
14.208 /// \param i The item to insert.
14.209 /// \param p The priority of the item.
14.210 + /// \pre \e i must not be stored in the heap.
14.211 void push(const Item &i, const Prio &p) { push(Pair(i,p)); }
14.212
14.213 - /// \brief Returns the item with minimum priority relative to \c Compare.
14.214 + /// \brief Return the item having minimum priority.
14.215 ///
14.216 - /// This method returns the item with minimum priority relative to \c
14.217 - /// Compare.
14.218 - /// \pre The heap must be nonempty.
14.219 + /// This function returns the item having minimum priority.
14.220 + /// \pre The heap must be non-empty.
14.221 Item top() const {
14.222 return _data[0].first;
14.223 }
14.224
14.225 - /// \brief Returns the minimum priority relative to \c Compare.
14.226 + /// \brief The minimum priority.
14.227 ///
14.228 - /// It returns the minimum priority relative to \c Compare.
14.229 - /// \pre The heap must be nonempty.
14.230 + /// This function returns the minimum priority.
14.231 + /// \pre The heap must be non-empty.
14.232 Prio prio() const {
14.233 return _data[0].second;
14.234 }
14.235
14.236 - /// \brief Deletes the item with minimum priority relative to \c Compare.
14.237 + /// \brief Remove the item having minimum priority.
14.238 ///
14.239 - /// This method deletes the item with minimum priority relative to \c
14.240 - /// Compare from the heap.
14.241 + /// This function removes the item having minimum priority.
14.242 /// \pre The heap must be non-empty.
14.243 void pop() {
14.244 int n = _data.size()-1;
14.245 _iim.set(_data[0].first, POST_HEAP);
14.246 if (n > 0) {
14.247 - bubble_down(0, _data[n], n);
14.248 + bubbleDown(0, _data[n], n);
14.249 }
14.250 _data.pop_back();
14.251 }
14.252
14.253 - /// \brief Deletes \c i from the heap.
14.254 + /// \brief Remove the given item from the heap.
14.255 ///
14.256 - /// This method deletes item \c i from the heap.
14.257 - /// \param i The item to erase.
14.258 - /// \pre The item should be in the heap.
14.259 + /// This function removes the given item from the heap if it is
14.260 + /// already stored.
14.261 + /// \param i The item to delete.
14.262 + /// \pre \e i must be in the heap.
14.263 void erase(const Item &i) {
14.264 int h = _iim[i];
14.265 int n = _data.size()-1;
14.266 _iim.set(_data[h].first, POST_HEAP);
14.267 if( h < n ) {
14.268 - if ( bubble_up(h, _data[n]) == h) {
14.269 - bubble_down(h, _data[n], n);
14.270 + if ( bubbleUp(h, _data[n]) == h) {
14.271 + bubbleDown(h, _data[n], n);
14.272 }
14.273 }
14.274 _data.pop_back();
14.275 }
14.276
14.277 -
14.278 - /// \brief Returns the priority of \c i.
14.279 + /// \brief The priority of the given item.
14.280 ///
14.281 - /// This function returns the priority of item \c i.
14.282 + /// This function returns the priority of the given item.
14.283 /// \param i The item.
14.284 - /// \pre \c i must be in the heap.
14.285 + /// \pre \e i must be in the heap.
14.286 Prio operator[](const Item &i) const {
14.287 int idx = _iim[i];
14.288 return _data[idx].second;
14.289 }
14.290
14.291 - /// \brief \c i gets to the heap with priority \c p independently
14.292 - /// if \c i was already there.
14.293 + /// \brief Set the priority of an item or insert it, if it is
14.294 + /// not stored in the heap.
14.295 ///
14.296 - /// This method calls \ref push(\c i, \c p) if \c i is not stored
14.297 - /// in the heap and sets the priority of \c i to \c p otherwise.
14.298 + /// This method sets the priority of the given item if it is
14.299 + /// already stored in the heap. Otherwise it inserts the given
14.300 + /// item into the heap with the given priority.
14.301 /// \param i The item.
14.302 /// \param p The priority.
14.303 void set(const Item &i, const Prio &p) {
14.304 @@ -260,44 +261,42 @@
14.305 push(i,p);
14.306 }
14.307 else if( _comp(p, _data[idx].second) ) {
14.308 - bubble_up(idx, Pair(i,p));
14.309 + bubbleUp(idx, Pair(i,p));
14.310 }
14.311 else {
14.312 - bubble_down(idx, Pair(i,p), _data.size());
14.313 + bubbleDown(idx, Pair(i,p), _data.size());
14.314 }
14.315 }
14.316
14.317 - /// \brief Decreases the priority of \c i to \c p.
14.318 + /// \brief Decrease the priority of an item to the given value.
14.319 ///
14.320 - /// This method decreases the priority of item \c i to \c p.
14.321 + /// This function decreases the priority of an item to the given value.
14.322 /// \param i The item.
14.323 /// \param p The priority.
14.324 - /// \pre \c i must be stored in the heap with priority at least \c
14.325 - /// p relative to \c Compare.
14.326 + /// \pre \e i must be stored in the heap with priority at least \e p.
14.327 void decrease(const Item &i, const Prio &p) {
14.328 int idx = _iim[i];
14.329 - bubble_up(idx, Pair(i,p));
14.330 + bubbleUp(idx, Pair(i,p));
14.331 }
14.332
14.333 - /// \brief Increases the priority of \c i to \c p.
14.334 + /// \brief Increase the priority of an item to the given value.
14.335 ///
14.336 - /// This method sets the priority of item \c i to \c p.
14.337 + /// This function increases the priority of an item to the given value.
14.338 /// \param i The item.
14.339 /// \param p The priority.
14.340 - /// \pre \c i must be stored in the heap with priority at most \c
14.341 - /// p relative to \c Compare.
14.342 + /// \pre \e i must be stored in the heap with priority at most \e p.
14.343 void increase(const Item &i, const Prio &p) {
14.344 int idx = _iim[i];
14.345 - bubble_down(idx, Pair(i,p), _data.size());
14.346 + bubbleDown(idx, Pair(i,p), _data.size());
14.347 }
14.348
14.349 - /// \brief Returns if \c item is in, has already been in, or has
14.350 - /// never been in the heap.
14.351 + /// \brief Return the state of an item.
14.352 ///
14.353 - /// This method returns PRE_HEAP if \c item has never been in the
14.354 - /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
14.355 - /// otherwise. In the latter case it is possible that \c item will
14.356 - /// get back to the heap again.
14.357 + /// This method returns \c PRE_HEAP if the given item has never
14.358 + /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
14.359 + /// and \c POST_HEAP otherwise.
14.360 + /// In the latter case it is possible that the item will get back
14.361 + /// to the heap again.
14.362 /// \param i The item.
14.363 State state(const Item &i) const {
14.364 int s = _iim[i];
14.365 @@ -306,11 +305,11 @@
14.366 return State(s);
14.367 }
14.368
14.369 - /// \brief Sets the state of the \c item in the heap.
14.370 + /// \brief Set the state of an item in the heap.
14.371 ///
14.372 - /// Sets the state of the \c item in the heap. It can be used to
14.373 - /// manually clear the heap when it is important to achive the
14.374 - /// better time complexity.
14.375 + /// This function sets the state of the given item in the heap.
14.376 + /// It can be used to manually clear the heap when it is important
14.377 + /// to achive better time complexity.
14.378 /// \param i The item.
14.379 /// \param st The state. It should not be \c IN_HEAP.
14.380 void state(const Item& i, State st) {
14.381 @@ -327,12 +326,13 @@
14.382 }
14.383 }
14.384
14.385 - /// \brief Replaces an item in the heap.
14.386 + /// \brief Replace an item in the heap.
14.387 ///
14.388 - /// The \c i item is replaced with \c j item. The \c i item should
14.389 - /// be in the heap, while the \c j should be out of the heap. The
14.390 - /// \c i item will out of the heap and \c j will be in the heap
14.391 - /// with the same prioriority as prevoiusly the \c i item.
14.392 + /// This function replaces item \c i with item \c j.
14.393 + /// Item \c i must be in the heap, while \c j must be out of the heap.
14.394 + /// After calling this method, item \c i will be out of the
14.395 + /// heap and \c j will be in the heap with the same prioriority
14.396 + /// as item \c i had before.
14.397 void replace(const Item& i, const Item& j) {
14.398 int idx = _iim[i];
14.399 _iim.set(i, _iim[j]);
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
15.2 +++ b/lemon/binom_heap.h Thu Nov 05 08:39:49 2009 +0100
15.3 @@ -0,0 +1,445 @@
15.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
15.5 + *
15.6 + * This file is a part of LEMON, a generic C++ optimization library.
15.7 + *
15.8 + * Copyright (C) 2003-2009
15.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
15.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
15.11 + *
15.12 + * Permission to use, modify and distribute this software is granted
15.13 + * provided that this copyright notice appears in all copies. For
15.14 + * precise terms see the accompanying LICENSE file.
15.15 + *
15.16 + * This software is provided "AS IS" with no warranty of any kind,
15.17 + * express or implied, and with no claim as to its suitability for any
15.18 + * purpose.
15.19 + *
15.20 + */
15.21 +
15.22 +#ifndef LEMON_BINOM_HEAP_H
15.23 +#define LEMON_BINOM_HEAP_H
15.24 +
15.25 +///\file
15.26 +///\ingroup heaps
15.27 +///\brief Binomial Heap implementation.
15.28 +
15.29 +#include <vector>
15.30 +#include <utility>
15.31 +#include <functional>
15.32 +#include <lemon/math.h>
15.33 +#include <lemon/counter.h>
15.34 +
15.35 +namespace lemon {
15.36 +
15.37 + /// \ingroup heaps
15.38 + ///
15.39 + ///\brief Binomial heap data structure.
15.40 + ///
15.41 + /// This class implements the \e binomial \e heap data structure.
15.42 + /// It fully conforms to the \ref concepts::Heap "heap concept".
15.43 + ///
15.44 + /// The methods \ref increase() and \ref erase() are not efficient
15.45 + /// in a binomial heap. In case of many calls of these operations,
15.46 + /// it is better to use other heap structure, e.g. \ref BinHeap
15.47 + /// "binary heap".
15.48 + ///
15.49 + /// \tparam PR Type of the priorities of the items.
15.50 + /// \tparam IM A read-writable item map with \c int values, used
15.51 + /// internally to handle the cross references.
15.52 + /// \tparam CMP A functor class for comparing the priorities.
15.53 + /// The default is \c std::less<PR>.
15.54 +#ifdef DOXYGEN
15.55 + template <typename PR, typename IM, typename CMP>
15.56 +#else
15.57 + template <typename PR, typename IM, typename CMP = std::less<PR> >
15.58 +#endif
15.59 + class BinomHeap {
15.60 + public:
15.61 + /// Type of the item-int map.
15.62 + typedef IM ItemIntMap;
15.63 + /// Type of the priorities.
15.64 + typedef PR Prio;
15.65 + /// Type of the items stored in the heap.
15.66 + typedef typename ItemIntMap::Key Item;
15.67 + /// Functor type for comparing the priorities.
15.68 + typedef CMP Compare;
15.69 +
15.70 + /// \brief Type to represent the states of the items.
15.71 + ///
15.72 + /// Each item has a state associated to it. It can be "in heap",
15.73 + /// "pre-heap" or "post-heap". The latter two are indifferent from the
15.74 + /// heap's point of view, but may be useful to the user.
15.75 + ///
15.76 + /// The item-int map must be initialized in such way that it assigns
15.77 + /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
15.78 + enum State {
15.79 + IN_HEAP = 0, ///< = 0.
15.80 + PRE_HEAP = -1, ///< = -1.
15.81 + POST_HEAP = -2 ///< = -2.
15.82 + };
15.83 +
15.84 + private:
15.85 + class Store;
15.86 +
15.87 + std::vector<Store> _data;
15.88 + int _min, _head;
15.89 + ItemIntMap &_iim;
15.90 + Compare _comp;
15.91 + int _num_items;
15.92 +
15.93 + public:
15.94 + /// \brief Constructor.
15.95 + ///
15.96 + /// Constructor.
15.97 + /// \param map A map that assigns \c int values to the items.
15.98 + /// It is used internally to handle the cross references.
15.99 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
15.100 + explicit BinomHeap(ItemIntMap &map)
15.101 + : _min(0), _head(-1), _iim(map), _num_items(0) {}
15.102 +
15.103 + /// \brief Constructor.
15.104 + ///
15.105 + /// Constructor.
15.106 + /// \param map A map that assigns \c int values to the items.
15.107 + /// It is used internally to handle the cross references.
15.108 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
15.109 + /// \param comp The function object used for comparing the priorities.
15.110 + BinomHeap(ItemIntMap &map, const Compare &comp)
15.111 + : _min(0), _head(-1), _iim(map), _comp(comp), _num_items(0) {}
15.112 +
15.113 + /// \brief The number of items stored in the heap.
15.114 + ///
15.115 + /// This function returns the number of items stored in the heap.
15.116 + int size() const { return _num_items; }
15.117 +
15.118 + /// \brief Check if the heap is empty.
15.119 + ///
15.120 + /// This function returns \c true if the heap is empty.
15.121 + bool empty() const { return _num_items==0; }
15.122 +
15.123 + /// \brief Make the heap empty.
15.124 + ///
15.125 + /// This functon makes the heap empty.
15.126 + /// It does not change the cross reference map. If you want to reuse
15.127 + /// a heap that is not surely empty, you should first clear it and
15.128 + /// then you should set the cross reference map to \c PRE_HEAP
15.129 + /// for each item.
15.130 + void clear() {
15.131 + _data.clear(); _min=0; _num_items=0; _head=-1;
15.132 + }
15.133 +
15.134 + /// \brief Set the priority of an item or insert it, if it is
15.135 + /// not stored in the heap.
15.136 + ///
15.137 + /// This method sets the priority of the given item if it is
15.138 + /// already stored in the heap. Otherwise it inserts the given
15.139 + /// item into the heap with the given priority.
15.140 + /// \param item The item.
15.141 + /// \param value The priority.
15.142 + void set (const Item& item, const Prio& value) {
15.143 + int i=_iim[item];
15.144 + if ( i >= 0 && _data[i].in ) {
15.145 + if ( _comp(value, _data[i].prio) ) decrease(item, value);
15.146 + if ( _comp(_data[i].prio, value) ) increase(item, value);
15.147 + } else push(item, value);
15.148 + }
15.149 +
15.150 + /// \brief Insert an item into the heap with the given priority.
15.151 + ///
15.152 + /// This function inserts the given item into the heap with the
15.153 + /// given priority.
15.154 + /// \param item The item to insert.
15.155 + /// \param value The priority of the item.
15.156 + /// \pre \e item must not be stored in the heap.
15.157 + void push (const Item& item, const Prio& value) {
15.158 + int i=_iim[item];
15.159 + if ( i<0 ) {
15.160 + int s=_data.size();
15.161 + _iim.set( item,s );
15.162 + Store st;
15.163 + st.name=item;
15.164 + st.prio=value;
15.165 + _data.push_back(st);
15.166 + i=s;
15.167 + }
15.168 + else {
15.169 + _data[i].parent=_data[i].right_neighbor=_data[i].child=-1;
15.170 + _data[i].degree=0;
15.171 + _data[i].in=true;
15.172 + _data[i].prio=value;
15.173 + }
15.174 +
15.175 + if( 0==_num_items ) {
15.176 + _head=i;
15.177 + _min=i;
15.178 + } else {
15.179 + merge(i);
15.180 + if( _comp(_data[i].prio, _data[_min].prio) ) _min=i;
15.181 + }
15.182 + ++_num_items;
15.183 + }
15.184 +
15.185 + /// \brief Return the item having minimum priority.
15.186 + ///
15.187 + /// This function returns the item having minimum priority.
15.188 + /// \pre The heap must be non-empty.
15.189 + Item top() const { return _data[_min].name; }
15.190 +
15.191 + /// \brief The minimum priority.
15.192 + ///
15.193 + /// This function returns the minimum priority.
15.194 + /// \pre The heap must be non-empty.
15.195 + Prio prio() const { return _data[_min].prio; }
15.196 +
15.197 + /// \brief The priority of the given item.
15.198 + ///
15.199 + /// This function returns the priority of the given item.
15.200 + /// \param item The item.
15.201 + /// \pre \e item must be in the heap.
15.202 + const Prio& operator[](const Item& item) const {
15.203 + return _data[_iim[item]].prio;
15.204 + }
15.205 +
15.206 + /// \brief Remove the item having minimum priority.
15.207 + ///
15.208 + /// This function removes the item having minimum priority.
15.209 + /// \pre The heap must be non-empty.
15.210 + void pop() {
15.211 + _data[_min].in=false;
15.212 +
15.213 + int head_child=-1;
15.214 + if ( _data[_min].child!=-1 ) {
15.215 + int child=_data[_min].child;
15.216 + int neighb;
15.217 + while( child!=-1 ) {
15.218 + neighb=_data[child].right_neighbor;
15.219 + _data[child].parent=-1;
15.220 + _data[child].right_neighbor=head_child;
15.221 + head_child=child;
15.222 + child=neighb;
15.223 + }
15.224 + }
15.225 +
15.226 + if ( _data[_head].right_neighbor==-1 ) {
15.227 + // there was only one root
15.228 + _head=head_child;
15.229 + }
15.230 + else {
15.231 + // there were more roots
15.232 + if( _head!=_min ) { unlace(_min); }
15.233 + else { _head=_data[_head].right_neighbor; }
15.234 + merge(head_child);
15.235 + }
15.236 + _min=findMin();
15.237 + --_num_items;
15.238 + }
15.239 +
15.240 + /// \brief Remove the given item from the heap.
15.241 + ///
15.242 + /// This function removes the given item from the heap if it is
15.243 + /// already stored.
15.244 + /// \param item The item to delete.
15.245 + /// \pre \e item must be in the heap.
15.246 + void erase (const Item& item) {
15.247 + int i=_iim[item];
15.248 + if ( i >= 0 && _data[i].in ) {
15.249 + decrease( item, _data[_min].prio-1 );
15.250 + pop();
15.251 + }
15.252 + }
15.253 +
15.254 + /// \brief Decrease the priority of an item to the given value.
15.255 + ///
15.256 + /// This function decreases the priority of an item to the given value.
15.257 + /// \param item The item.
15.258 + /// \param value The priority.
15.259 + /// \pre \e item must be stored in the heap with priority at least \e value.
15.260 + void decrease (Item item, const Prio& value) {
15.261 + int i=_iim[item];
15.262 + int p=_data[i].parent;
15.263 + _data[i].prio=value;
15.264 +
15.265 + while( p!=-1 && _comp(value, _data[p].prio) ) {
15.266 + _data[i].name=_data[p].name;
15.267 + _data[i].prio=_data[p].prio;
15.268 + _data[p].name=item;
15.269 + _data[p].prio=value;
15.270 + _iim[_data[i].name]=i;
15.271 + i=p;
15.272 + p=_data[p].parent;
15.273 + }
15.274 + _iim[item]=i;
15.275 + if ( _comp(value, _data[_min].prio) ) _min=i;
15.276 + }
15.277 +
15.278 + /// \brief Increase the priority of an item to the given value.
15.279 + ///
15.280 + /// This function increases the priority of an item to the given value.
15.281 + /// \param item The item.
15.282 + /// \param value The priority.
15.283 + /// \pre \e item must be stored in the heap with priority at most \e value.
15.284 + void increase (Item item, const Prio& value) {
15.285 + erase(item);
15.286 + push(item, value);
15.287 + }
15.288 +
15.289 + /// \brief Return the state of an item.
15.290 + ///
15.291 + /// This method returns \c PRE_HEAP if the given item has never
15.292 + /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
15.293 + /// and \c POST_HEAP otherwise.
15.294 + /// In the latter case it is possible that the item will get back
15.295 + /// to the heap again.
15.296 + /// \param item The item.
15.297 + State state(const Item &item) const {
15.298 + int i=_iim[item];
15.299 + if( i>=0 ) {
15.300 + if ( _data[i].in ) i=0;
15.301 + else i=-2;
15.302 + }
15.303 + return State(i);
15.304 + }
15.305 +
15.306 + /// \brief Set the state of an item in the heap.
15.307 + ///
15.308 + /// This function sets the state of the given item in the heap.
15.309 + /// It can be used to manually clear the heap when it is important
15.310 + /// to achive better time complexity.
15.311 + /// \param i The item.
15.312 + /// \param st The state. It should not be \c IN_HEAP.
15.313 + void state(const Item& i, State st) {
15.314 + switch (st) {
15.315 + case POST_HEAP:
15.316 + case PRE_HEAP:
15.317 + if (state(i) == IN_HEAP) {
15.318 + erase(i);
15.319 + }
15.320 + _iim[i] = st;
15.321 + break;
15.322 + case IN_HEAP:
15.323 + break;
15.324 + }
15.325 + }
15.326 +
15.327 + private:
15.328 +
15.329 + // Find the minimum of the roots
15.330 + int findMin() {
15.331 + if( _head!=-1 ) {
15.332 + int min_loc=_head, min_val=_data[_head].prio;
15.333 + for( int x=_data[_head].right_neighbor; x!=-1;
15.334 + x=_data[x].right_neighbor ) {
15.335 + if( _comp( _data[x].prio,min_val ) ) {
15.336 + min_val=_data[x].prio;
15.337 + min_loc=x;
15.338 + }
15.339 + }
15.340 + return min_loc;
15.341 + }
15.342 + else return -1;
15.343 + }
15.344 +
15.345 + // Merge the heap with another heap starting at the given position
15.346 + void merge(int a) {
15.347 + if( _head==-1 || a==-1 ) return;
15.348 + if( _data[a].right_neighbor==-1 &&
15.349 + _data[a].degree<=_data[_head].degree ) {
15.350 + _data[a].right_neighbor=_head;
15.351 + _head=a;
15.352 + } else {
15.353 + interleave(a);
15.354 + }
15.355 + if( _data[_head].right_neighbor==-1 ) return;
15.356 +
15.357 + int x=_head;
15.358 + int x_prev=-1, x_next=_data[x].right_neighbor;
15.359 + while( x_next!=-1 ) {
15.360 + if( _data[x].degree!=_data[x_next].degree ||
15.361 + ( _data[x_next].right_neighbor!=-1 &&
15.362 + _data[_data[x_next].right_neighbor].degree==_data[x].degree ) ) {
15.363 + x_prev=x;
15.364 + x=x_next;
15.365 + }
15.366 + else {
15.367 + if( _comp(_data[x_next].prio,_data[x].prio) ) {
15.368 + if( x_prev==-1 ) {
15.369 + _head=x_next;
15.370 + } else {
15.371 + _data[x_prev].right_neighbor=x_next;
15.372 + }
15.373 + fuse(x,x_next);
15.374 + x=x_next;
15.375 + }
15.376 + else {
15.377 + _data[x].right_neighbor=_data[x_next].right_neighbor;
15.378 + fuse(x_next,x);
15.379 + }
15.380 + }
15.381 + x_next=_data[x].right_neighbor;
15.382 + }
15.383 + }
15.384 +
15.385 + // Interleave the elements of the given list into the list of the roots
15.386 + void interleave(int a) {
15.387 + int p=_head, q=a;
15.388 + int curr=_data.size();
15.389 + _data.push_back(Store());
15.390 +
15.391 + while( p!=-1 || q!=-1 ) {
15.392 + if( q==-1 || ( p!=-1 && _data[p].degree<_data[q].degree ) ) {
15.393 + _data[curr].right_neighbor=p;
15.394 + curr=p;
15.395 + p=_data[p].right_neighbor;
15.396 + }
15.397 + else {
15.398 + _data[curr].right_neighbor=q;
15.399 + curr=q;
15.400 + q=_data[q].right_neighbor;
15.401 + }
15.402 + }
15.403 +
15.404 + _head=_data.back().right_neighbor;
15.405 + _data.pop_back();
15.406 + }
15.407 +
15.408 + // Lace node a under node b
15.409 + void fuse(int a, int b) {
15.410 + _data[a].parent=b;
15.411 + _data[a].right_neighbor=_data[b].child;
15.412 + _data[b].child=a;
15.413 +
15.414 + ++_data[b].degree;
15.415 + }
15.416 +
15.417 + // Unlace node a (if it has siblings)
15.418 + void unlace(int a) {
15.419 + int neighb=_data[a].right_neighbor;
15.420 + int other=_head;
15.421 +
15.422 + while( _data[other].right_neighbor!=a )
15.423 + other=_data[other].right_neighbor;
15.424 + _data[other].right_neighbor=neighb;
15.425 + }
15.426 +
15.427 + private:
15.428 +
15.429 + class Store {
15.430 + friend class BinomHeap;
15.431 +
15.432 + Item name;
15.433 + int parent;
15.434 + int right_neighbor;
15.435 + int child;
15.436 + int degree;
15.437 + bool in;
15.438 + Prio prio;
15.439 +
15.440 + Store() : parent(-1), right_neighbor(-1), child(-1), degree(0),
15.441 + in(true) {}
15.442 + };
15.443 + };
15.444 +
15.445 +} //namespace lemon
15.446 +
15.447 +#endif //LEMON_BINOM_HEAP_H
15.448 +
16.1 --- a/lemon/bits/edge_set_extender.h Tue Aug 18 10:08:28 2009 +0200
16.2 +++ b/lemon/bits/edge_set_extender.h Thu Nov 05 08:39:49 2009 +0100
16.3 @@ -537,7 +537,7 @@
16.4 typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent;
16.5
16.6 public:
16.7 - ArcMap(const Graph& _g)
16.8 + explicit ArcMap(const Graph& _g)
16.9 : Parent(_g) {}
16.10 ArcMap(const Graph& _g, const _Value& _v)
16.11 : Parent(_g, _v) {}
16.12 @@ -561,7 +561,7 @@
16.13 typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
16.14
16.15 public:
16.16 - EdgeMap(const Graph& _g)
16.17 + explicit EdgeMap(const Graph& _g)
16.18 : Parent(_g) {}
16.19
16.20 EdgeMap(const Graph& _g, const _Value& _v)
17.1 --- a/lemon/bits/graph_extender.h Tue Aug 18 10:08:28 2009 +0200
17.2 +++ b/lemon/bits/graph_extender.h Thu Nov 05 08:39:49 2009 +0100
17.3 @@ -604,7 +604,7 @@
17.4 typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
17.5
17.6 public:
17.7 - NodeMap(const Graph& graph)
17.8 + explicit NodeMap(const Graph& graph)
17.9 : Parent(graph) {}
17.10 NodeMap(const Graph& graph, const _Value& value)
17.11 : Parent(graph, value) {}
17.12 @@ -628,7 +628,7 @@
17.13 typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent;
17.14
17.15 public:
17.16 - ArcMap(const Graph& graph)
17.17 + explicit ArcMap(const Graph& graph)
17.18 : Parent(graph) {}
17.19 ArcMap(const Graph& graph, const _Value& value)
17.20 : Parent(graph, value) {}
17.21 @@ -652,7 +652,7 @@
17.22 typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
17.23
17.24 public:
17.25 - EdgeMap(const Graph& graph)
17.26 + explicit EdgeMap(const Graph& graph)
17.27 : Parent(graph) {}
17.28
17.29 EdgeMap(const Graph& graph, const _Value& value)
18.1 --- a/lemon/bits/map_extender.h Tue Aug 18 10:08:28 2009 +0200
18.2 +++ b/lemon/bits/map_extender.h Thu Nov 05 08:39:49 2009 +0100
18.3 @@ -49,6 +49,8 @@
18.4 typedef typename Parent::Reference Reference;
18.5 typedef typename Parent::ConstReference ConstReference;
18.6
18.7 + typedef typename Parent::ReferenceMapTag ReferenceMapTag;
18.8 +
18.9 class MapIt;
18.10 class ConstMapIt;
18.11
18.12 @@ -191,6 +193,8 @@
18.13 typedef typename Parent::Reference Reference;
18.14 typedef typename Parent::ConstReference ConstReference;
18.15
18.16 + typedef typename Parent::ReferenceMapTag ReferenceMapTag;
18.17 +
18.18 class MapIt;
18.19 class ConstMapIt;
18.20
19.1 --- a/lemon/bucket_heap.h Tue Aug 18 10:08:28 2009 +0200
19.2 +++ b/lemon/bucket_heap.h Thu Nov 05 08:39:49 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 Tue Aug 18 10:08:28 2009 +0200
20.2 +++ b/lemon/cbc.cc Thu Nov 05 08:39:49 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 Tue Aug 18 10:08:28 2009 +0200
21.2 +++ b/lemon/cbc.h Thu Nov 05 08:39:49 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 Tue Aug 18 10:08:28 2009 +0200
22.2 +++ b/lemon/circulation.h Thu Nov 05 08:39:49 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 @@ -450,25 +457,27 @@
22.31 return *_level;
22.32 }
22.33
22.34 - /// \brief Sets the tolerance used by algorithm.
22.35 + /// \brief Sets the tolerance used by the algorithm.
22.36 ///
22.37 - /// Sets the tolerance used by algorithm.
22.38 - Circulation& tolerance(const Tolerance& tolerance) const {
22.39 + /// Sets the tolerance object used by the algorithm.
22.40 + /// \return <tt>(*this)</tt>
22.41 + Circulation& tolerance(const Tolerance& tolerance) {
22.42 _tol = tolerance;
22.43 return *this;
22.44 }
22.45
22.46 /// \brief Returns a const reference to the tolerance.
22.47 ///
22.48 - /// Returns a const reference to the tolerance.
22.49 + /// Returns a const reference to the tolerance object used by
22.50 + /// the algorithm.
22.51 const Tolerance& tolerance() const {
22.52 - return tolerance;
22.53 + return _tol;
22.54 }
22.55
22.56 /// \name Execution Control
22.57 /// The simplest way to execute the algorithm is to call \ref run().\n
22.58 - /// If you need more control on the initial solution or the execution,
22.59 - /// first you have to call one of the \ref init() functions, then
22.60 + /// If you need better control on the initial solution or the execution,
22.61 + /// you have to call one of the \ref init() functions first, then
22.62 /// the \ref start() function.
22.63
22.64 ///@{
23.1 --- a/lemon/clp.cc Tue Aug 18 10:08:28 2009 +0200
23.2 +++ b/lemon/clp.cc Thu Nov 05 08:39:49 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 Tue Aug 18 10:08:28 2009 +0200
24.2 +++ b/lemon/clp.h Thu Nov 05 08:39:49 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 Tue Aug 18 10:08:28 2009 +0200
25.2 +++ b/lemon/concepts/digraph.h Thu Nov 05 08:39:49 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 + /// This iterator goes through each node of the digraph.
25.119 /// Its usage is quite simple, for example you can count the number
25.120 - /// of nodes in digraph \c g of type \c Digraph like this:
25.121 + /// of nodes in a digraph \c g of type \c %Digraph like this:
25.122 ///\code
25.123 /// int count=0;
25.124 /// for (Digraph::NodeIt n(g); n!=INVALID; ++n) ++count;
25.125 @@ -124,30 +117,28 @@
25.126 public:
25.127 /// Default constructor
25.128
25.129 - /// @warning The default constructor sets the iterator
25.130 - /// to an undefined value.
25.131 + /// Default constructor.
25.132 + /// \warning It sets the iterator to an undefined value.
25.133 NodeIt() { }
25.134 /// Copy constructor.
25.135
25.136 /// Copy constructor.
25.137 ///
25.138 NodeIt(const NodeIt& n) : Node(n) { }
25.139 - /// Invalid constructor \& conversion.
25.140 + /// %Invalid constructor \& conversion.
25.141
25.142 - /// Initialize the iterator to be invalid.
25.143 + /// Initializes the iterator to be invalid.
25.144 /// \sa Invalid for more details.
25.145 NodeIt(Invalid) { }
25.146 /// Sets the iterator to the first node.
25.147
25.148 - /// Sets the iterator to the first node of \c g.
25.149 + /// Sets the iterator to the first node of the given digraph.
25.150 ///
25.151 - NodeIt(const Digraph&) { }
25.152 - /// Node -> NodeIt conversion.
25.153 + explicit NodeIt(const Digraph&) { }
25.154 + /// Sets the iterator to the given node.
25.155
25.156 - /// Sets the iterator to the node of \c the digraph pointed by
25.157 - /// the trivial iterator.
25.158 - /// This feature necessitates that each time we
25.159 - /// iterate the arc-set, the iteration order is the same.
25.160 + /// Sets the iterator to the given node of the given digraph.
25.161 + ///
25.162 NodeIt(const Digraph&, const Node&) { }
25.163 /// Next node.
25.164
25.165 @@ -157,7 +148,7 @@
25.166 };
25.167
25.168
25.169 - /// Class for identifying an arc of the digraph
25.170 + /// The arc type of the digraph
25.171
25.172 /// This class identifies an arc of the digraph. It also serves
25.173 /// as a base class of the arc iterators,
25.174 @@ -166,207 +157,214 @@
25.175 public:
25.176 /// Default constructor
25.177
25.178 - /// @warning The default constructor sets the iterator
25.179 - /// to an undefined value.
25.180 + /// Default constructor.
25.181 + /// \warning It sets the object to an undefined value.
25.182 Arc() { }
25.183 /// Copy constructor.
25.184
25.185 /// Copy constructor.
25.186 ///
25.187 Arc(const Arc&) { }
25.188 - /// Initialize the iterator to be invalid.
25.189 + /// %Invalid constructor \& conversion.
25.190
25.191 - /// Initialize the iterator to be invalid.
25.192 - ///
25.193 + /// Initializes the object to be invalid.
25.194 + /// \sa Invalid for more details.
25.195 Arc(Invalid) { }
25.196 /// Equality operator
25.197
25.198 + /// Equality operator.
25.199 + ///
25.200 /// Two iterators are equal if and only if they point to the
25.201 - /// same object or both are invalid.
25.202 + /// same object or both are \c INVALID.
25.203 bool operator==(Arc) const { return true; }
25.204 /// Inequality operator
25.205
25.206 - /// \sa operator==(Arc n)
25.207 - ///
25.208 + /// Inequality operator.
25.209 bool operator!=(Arc) const { return true; }
25.210
25.211 /// Artificial ordering operator.
25.212
25.213 - /// To allow the use of digraph descriptors as key type in std::map or
25.214 - /// similar associative container we require this.
25.215 + /// Artificial ordering operator.
25.216 ///
25.217 - /// \note This operator only have to define some strict ordering of
25.218 - /// the items; this order has nothing to do with the iteration
25.219 - /// ordering of the items.
25.220 + /// \note This operator only has to define some strict ordering of
25.221 + /// the arcs; this order has nothing to do with the iteration
25.222 + /// ordering of the arcs.
25.223 bool operator<(Arc) const { return false; }
25.224 };
25.225
25.226 - /// This iterator goes trough the outgoing arcs of a node.
25.227 + /// Iterator class for the outgoing arcs of a node.
25.228
25.229 /// This iterator goes trough the \e outgoing arcs of a certain node
25.230 /// of a digraph.
25.231 /// Its usage is quite simple, for example you can count the number
25.232 /// of outgoing arcs of a node \c n
25.233 - /// in digraph \c g of type \c Digraph as follows.
25.234 + /// in a digraph \c g of type \c %Digraph as follows.
25.235 ///\code
25.236 /// int count=0;
25.237 - /// for (Digraph::OutArcIt e(g, n); e!=INVALID; ++e) ++count;
25.238 + /// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count;
25.239 ///\endcode
25.240 -
25.241 class OutArcIt : public Arc {
25.242 public:
25.243 /// Default constructor
25.244
25.245 - /// @warning The default constructor sets the iterator
25.246 - /// to an undefined value.
25.247 + /// Default constructor.
25.248 + /// \warning It sets the iterator to an undefined value.
25.249 OutArcIt() { }
25.250 /// Copy constructor.
25.251
25.252 /// Copy constructor.
25.253 ///
25.254 OutArcIt(const OutArcIt& e) : Arc(e) { }
25.255 - /// Initialize the iterator to be invalid.
25.256 + /// %Invalid constructor \& conversion.
25.257
25.258 - /// Initialize the iterator to be invalid.
25.259 + /// Initializes the iterator to be invalid.
25.260 + /// \sa Invalid for more details.
25.261 + OutArcIt(Invalid) { }
25.262 + /// Sets the iterator to the first outgoing arc.
25.263 +
25.264 + /// Sets the iterator to the first outgoing arc of the given node.
25.265 ///
25.266 - OutArcIt(Invalid) { }
25.267 - /// This constructor sets the iterator to the first outgoing arc.
25.268 + OutArcIt(const Digraph&, const Node&) { }
25.269 + /// Sets the iterator to the given arc.
25.270
25.271 - /// This constructor sets the iterator to the first outgoing arc of
25.272 - /// the node.
25.273 - OutArcIt(const Digraph&, const Node&) { }
25.274 - /// Arc -> OutArcIt conversion
25.275 -
25.276 - /// Sets the iterator to the value of the trivial iterator.
25.277 - /// This feature necessitates that each time we
25.278 - /// iterate the arc-set, the iteration order is the same.
25.279 + /// Sets the iterator to the given arc of the given digraph.
25.280 + ///
25.281 OutArcIt(const Digraph&, const Arc&) { }
25.282 - ///Next outgoing arc
25.283 + /// Next outgoing arc
25.284
25.285 /// Assign the iterator to the next
25.286 /// outgoing arc of the corresponding node.
25.287 OutArcIt& operator++() { return *this; }
25.288 };
25.289
25.290 - /// This iterator goes trough the incoming arcs of a node.
25.291 + /// Iterator class for the incoming arcs of a node.
25.292
25.293 /// This iterator goes trough the \e incoming arcs of a certain node
25.294 /// of a digraph.
25.295 /// Its usage is quite simple, for example you can count the number
25.296 - /// of outgoing arcs of a node \c n
25.297 - /// in digraph \c g of type \c Digraph as follows.
25.298 + /// of incoming arcs of a node \c n
25.299 + /// in a digraph \c g of type \c %Digraph as follows.
25.300 ///\code
25.301 /// int count=0;
25.302 - /// for(Digraph::InArcIt e(g, n); e!=INVALID; ++e) ++count;
25.303 + /// for(Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count;
25.304 ///\endcode
25.305 -
25.306 class InArcIt : public Arc {
25.307 public:
25.308 /// Default constructor
25.309
25.310 - /// @warning The default constructor sets the iterator
25.311 - /// to an undefined value.
25.312 + /// Default constructor.
25.313 + /// \warning It sets the iterator to an undefined value.
25.314 InArcIt() { }
25.315 /// Copy constructor.
25.316
25.317 /// Copy constructor.
25.318 ///
25.319 InArcIt(const InArcIt& e) : Arc(e) { }
25.320 - /// Initialize the iterator to be invalid.
25.321 + /// %Invalid constructor \& conversion.
25.322
25.323 - /// Initialize the iterator to be invalid.
25.324 + /// Initializes the iterator to be invalid.
25.325 + /// \sa Invalid for more details.
25.326 + InArcIt(Invalid) { }
25.327 + /// Sets the iterator to the first incoming arc.
25.328 +
25.329 + /// Sets the iterator to the first incoming arc of the given node.
25.330 ///
25.331 - InArcIt(Invalid) { }
25.332 - /// This constructor sets the iterator to first incoming arc.
25.333 + InArcIt(const Digraph&, const Node&) { }
25.334 + /// Sets the iterator to the given arc.
25.335
25.336 - /// This constructor set the iterator to the first incoming arc of
25.337 - /// the node.
25.338 - InArcIt(const Digraph&, const Node&) { }
25.339 - /// Arc -> InArcIt conversion
25.340 -
25.341 - /// Sets the iterator to the value of the trivial iterator \c e.
25.342 - /// This feature necessitates that each time we
25.343 - /// iterate the arc-set, the iteration order is the same.
25.344 + /// Sets the iterator to the given arc of the given digraph.
25.345 + ///
25.346 InArcIt(const Digraph&, const Arc&) { }
25.347 /// Next incoming arc
25.348
25.349 - /// Assign the iterator to the next inarc of the corresponding node.
25.350 - ///
25.351 + /// Assign the iterator to the next
25.352 + /// incoming arc of the corresponding node.
25.353 InArcIt& operator++() { return *this; }
25.354 };
25.355 - /// This iterator goes through each arc.
25.356
25.357 - /// This iterator goes through each arc of a digraph.
25.358 + /// Iterator class for the arcs.
25.359 +
25.360 + /// This iterator goes through each arc of the 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 + /// of arcs in a digraph \c g of type \c %Digraph as follows:
25.364 ///\code
25.365 /// int count=0;
25.366 - /// for(Digraph::ArcIt e(g); e!=INVALID; ++e) ++count;
25.367 + /// for(Digraph::ArcIt a(g); a!=INVALID; ++a) ++count;
25.368 ///\endcode
25.369 class ArcIt : public Arc {
25.370 public:
25.371 /// Default constructor
25.372
25.373 - /// @warning The default constructor sets the iterator
25.374 - /// to an undefined value.
25.375 + /// Default constructor.
25.376 + /// \warning It sets the iterator to an undefined value.
25.377 ArcIt() { }
25.378 /// Copy constructor.
25.379
25.380 /// Copy constructor.
25.381 ///
25.382 ArcIt(const ArcIt& e) : Arc(e) { }
25.383 - /// Initialize the iterator to be invalid.
25.384 + /// %Invalid constructor \& conversion.
25.385
25.386 - /// Initialize the iterator to be invalid.
25.387 + /// Initializes the iterator to be invalid.
25.388 + /// \sa Invalid for more details.
25.389 + ArcIt(Invalid) { }
25.390 + /// Sets the iterator to the first arc.
25.391 +
25.392 + /// Sets the iterator to the first arc of the given digraph.
25.393 ///
25.394 - ArcIt(Invalid) { }
25.395 - /// This constructor sets the iterator to the first arc.
25.396 + explicit ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); }
25.397 + /// Sets the iterator to the given arc.
25.398
25.399 - /// This constructor sets the iterator to the first arc of \c g.
25.400 - ///@param g the digraph
25.401 - ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); }
25.402 - /// Arc -> ArcIt conversion
25.403 -
25.404 - /// Sets the iterator to the value of the trivial iterator \c e.
25.405 - /// This feature necessitates that each time we
25.406 - /// iterate the arc-set, the iteration order is the same.
25.407 + /// Sets the iterator to the given arc of the given digraph.
25.408 + ///
25.409 ArcIt(const Digraph&, const Arc&) { }
25.410 - ///Next arc
25.411 + /// Next arc
25.412
25.413 /// Assign the iterator to the next arc.
25.414 + ///
25.415 ArcIt& operator++() { return *this; }
25.416 };
25.417 - ///Gives back the target node of an arc.
25.418
25.419 - ///Gives back the target node of an arc.
25.420 + /// \brief The source node of the arc.
25.421 ///
25.422 - Node target(Arc) const { return INVALID; }
25.423 - ///Gives back the source node of an arc.
25.424 -
25.425 - ///Gives back the source node of an arc.
25.426 - ///
25.427 + /// Returns the source node of the given arc.
25.428 Node source(Arc) const { return INVALID; }
25.429
25.430 - /// \brief Returns the ID of the node.
25.431 + /// \brief The target node of the arc.
25.432 + ///
25.433 + /// Returns the target node of the given arc.
25.434 + Node target(Arc) const { return INVALID; }
25.435 +
25.436 + /// \brief The ID of the node.
25.437 + ///
25.438 + /// Returns the ID of the given node.
25.439 int id(Node) const { return -1; }
25.440
25.441 - /// \brief Returns the ID of the arc.
25.442 + /// \brief The ID of the arc.
25.443 + ///
25.444 + /// Returns the ID of the given arc.
25.445 int id(Arc) const { return -1; }
25.446
25.447 - /// \brief Returns the node with the given ID.
25.448 + /// \brief The node with the given ID.
25.449 ///
25.450 - /// \pre The argument should be a valid node ID in the graph.
25.451 + /// Returns the node with the given ID.
25.452 + /// \pre The argument should be a valid node ID in the digraph.
25.453 Node nodeFromId(int) const { return INVALID; }
25.454
25.455 - /// \brief Returns the arc with the given ID.
25.456 + /// \brief The arc with the given ID.
25.457 ///
25.458 - /// \pre The argument should be a valid arc ID in the graph.
25.459 + /// Returns the arc with the given ID.
25.460 + /// \pre The argument should be a valid arc ID in the digraph.
25.461 Arc arcFromId(int) const { return INVALID; }
25.462
25.463 - /// \brief Returns an upper bound on the node IDs.
25.464 + /// \brief An upper bound on the node IDs.
25.465 + ///
25.466 + /// Returns an upper bound on the node IDs.
25.467 int maxNodeId() const { return -1; }
25.468
25.469 - /// \brief Returns an upper bound on the arc IDs.
25.470 + /// \brief An upper bound on the arc IDs.
25.471 + ///
25.472 + /// Returns an upper bound on the arc IDs.
25.473 int maxArcId() const { return -1; }
25.474
25.475 void first(Node&) const {}
25.476 @@ -392,45 +390,46 @@
25.477 // Dummy parameter.
25.478 int maxId(Arc) const { return -1; }
25.479
25.480 + /// \brief The opposite node on the arc.
25.481 + ///
25.482 + /// Returns the opposite node on the given arc.
25.483 + Node oppositeNode(Node, Arc) const { return INVALID; }
25.484 +
25.485 /// \brief The base node of the iterator.
25.486 ///
25.487 - /// Gives back the base node of the iterator.
25.488 - /// It is always the target of the pointed arc.
25.489 - Node baseNode(const InArcIt&) const { return INVALID; }
25.490 + /// Returns the base node of the given outgoing arc iterator
25.491 + /// (i.e. the source node of the corresponding arc).
25.492 + Node baseNode(OutArcIt) const { return INVALID; }
25.493
25.494 /// \brief The running node of the iterator.
25.495 ///
25.496 - /// Gives back the running node of the iterator.
25.497 - /// It is always the source of the pointed arc.
25.498 - Node runningNode(const InArcIt&) const { return INVALID; }
25.499 + /// Returns the running node of the given outgoing arc iterator
25.500 + /// (i.e. the target node of the corresponding arc).
25.501 + Node runningNode(OutArcIt) const { return INVALID; }
25.502
25.503 /// \brief The base node of the iterator.
25.504 ///
25.505 - /// Gives back the base node of the iterator.
25.506 - /// It is always the source of the pointed arc.
25.507 - Node baseNode(const OutArcIt&) const { return INVALID; }
25.508 + /// Returns the base node of the given incomming arc iterator
25.509 + /// (i.e. the target node of the corresponding arc).
25.510 + Node baseNode(InArcIt) const { return INVALID; }
25.511
25.512 /// \brief The running node of the iterator.
25.513 ///
25.514 - /// Gives back the running node of the iterator.
25.515 - /// It is always the target of the pointed arc.
25.516 - Node runningNode(const OutArcIt&) const { return INVALID; }
25.517 + /// Returns the running node of the given incomming arc iterator
25.518 + /// (i.e. the source node of the corresponding arc).
25.519 + Node runningNode(InArcIt) const { return INVALID; }
25.520
25.521 - /// \brief The opposite node on the given arc.
25.522 + /// \brief Standard graph map type for the nodes.
25.523 ///
25.524 - /// Gives back the opposite node on the given arc.
25.525 - Node oppositeNode(const Node&, const Arc&) const { return INVALID; }
25.526 -
25.527 - /// \brief Reference map of the nodes to type \c T.
25.528 - ///
25.529 - /// Reference map of the nodes to type \c T.
25.530 + /// Standard graph map type for the nodes.
25.531 + /// It conforms to the ReferenceMap concept.
25.532 template<class T>
25.533 class NodeMap : public ReferenceMap<Node, T, T&, const T&> {
25.534 public:
25.535
25.536 - ///\e
25.537 - NodeMap(const Digraph&) { }
25.538 - ///\e
25.539 + /// Constructor
25.540 + explicit NodeMap(const Digraph&) { }
25.541 + /// Constructor with given initial value
25.542 NodeMap(const Digraph&, T) { }
25.543
25.544 private:
25.545 @@ -445,17 +444,19 @@
25.546 }
25.547 };
25.548
25.549 - /// \brief Reference map of the arcs to type \c T.
25.550 + /// \brief Standard graph map type for the arcs.
25.551 ///
25.552 - /// Reference map of the arcs to type \c T.
25.553 + /// Standard graph map type for the arcs.
25.554 + /// It conforms to the ReferenceMap concept.
25.555 template<class T>
25.556 class ArcMap : public ReferenceMap<Arc, T, T&, const T&> {
25.557 public:
25.558
25.559 - ///\e
25.560 - ArcMap(const Digraph&) { }
25.561 - ///\e
25.562 + /// Constructor
25.563 + explicit ArcMap(const Digraph&) { }
25.564 + /// Constructor with given initial value
25.565 ArcMap(const Digraph&, T) { }
25.566 +
25.567 private:
25.568 ///Copy constructor
25.569 ArcMap(const ArcMap& em) :
26.1 --- a/lemon/concepts/graph.h Tue Aug 18 10:08:28 2009 +0200
26.2 +++ b/lemon/concepts/graph.h Thu Nov 05 08:39:49 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 + /// This iterator goes through each node of the graph.
26.181 /// Its usage is quite simple, for example you can count the number
26.182 - /// of nodes in graph \c g of type \c Graph like this:
26.183 + /// of nodes in a graph \c g of type \c %Graph like this:
26.184 ///\code
26.185 /// int count=0;
26.186 /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
26.187 @@ -137,30 +150,28 @@
26.188 public:
26.189 /// Default constructor
26.190
26.191 - /// @warning The default constructor sets the iterator
26.192 - /// to an undefined value.
26.193 + /// Default constructor.
26.194 + /// \warning It sets the iterator to an undefined value.
26.195 NodeIt() { }
26.196 /// Copy constructor.
26.197
26.198 /// Copy constructor.
26.199 ///
26.200 NodeIt(const NodeIt& n) : Node(n) { }
26.201 - /// Invalid constructor \& conversion.
26.202 + /// %Invalid constructor \& conversion.
26.203
26.204 - /// Initialize the iterator to be invalid.
26.205 + /// Initializes the iterator to be invalid.
26.206 /// \sa Invalid for more details.
26.207 NodeIt(Invalid) { }
26.208 /// Sets the iterator to the first node.
26.209
26.210 - /// Sets the iterator to the first node of \c g.
26.211 + /// Sets the iterator to the first node of the given digraph.
26.212 ///
26.213 - NodeIt(const Graph&) { }
26.214 - /// Node -> NodeIt conversion.
26.215 + explicit NodeIt(const Graph&) { }
26.216 + /// Sets the iterator to the given node.
26.217
26.218 - /// Sets the iterator to the node of \c the graph pointed by
26.219 - /// the trivial iterator.
26.220 - /// This feature necessitates that each time we
26.221 - /// iterate the arc-set, the iteration order is the same.
26.222 + /// Sets the iterator to the given node of the given digraph.
26.223 + ///
26.224 NodeIt(const Graph&, const Node&) { }
26.225 /// Next node.
26.226
26.227 @@ -170,54 +181,55 @@
26.228 };
26.229
26.230
26.231 - /// The base type of the edge iterators.
26.232 + /// The edge type of the graph
26.233
26.234 - /// The base type of the edge iterators.
26.235 - ///
26.236 + /// This class identifies an edge of the graph. It also serves
26.237 + /// as a base class of the edge iterators,
26.238 + /// thus they will convert to this type.
26.239 class Edge {
26.240 public:
26.241 /// Default constructor
26.242
26.243 - /// @warning The default constructor sets the iterator
26.244 - /// to an undefined value.
26.245 + /// Default constructor.
26.246 + /// \warning It sets the object to an undefined value.
26.247 Edge() { }
26.248 /// Copy constructor.
26.249
26.250 /// Copy constructor.
26.251 ///
26.252 Edge(const Edge&) { }
26.253 - /// Initialize the iterator to be invalid.
26.254 + /// %Invalid constructor \& conversion.
26.255
26.256 - /// Initialize the iterator to be invalid.
26.257 - ///
26.258 + /// Initializes the object to be invalid.
26.259 + /// \sa Invalid for more details.
26.260 Edge(Invalid) { }
26.261 /// Equality operator
26.262
26.263 + /// Equality operator.
26.264 + ///
26.265 /// Two iterators are equal if and only if they point to the
26.266 - /// same object or both are invalid.
26.267 + /// same object or both are \c INVALID.
26.268 bool operator==(Edge) const { return true; }
26.269 /// Inequality operator
26.270
26.271 - /// \sa operator==(Edge n)
26.272 - ///
26.273 + /// Inequality operator.
26.274 bool operator!=(Edge) const { return true; }
26.275
26.276 /// Artificial ordering operator.
26.277
26.278 - /// To allow the use of graph descriptors as key type in std::map or
26.279 - /// similar associative container we require this.
26.280 + /// Artificial ordering operator.
26.281 ///
26.282 - /// \note This operator only have to define some strict ordering of
26.283 - /// the items; this order has nothing to do with the iteration
26.284 - /// ordering of the items.
26.285 + /// \note This operator only has to define some strict ordering of
26.286 + /// the edges; this order has nothing to do with the iteration
26.287 + /// ordering of the edges.
26.288 bool operator<(Edge) const { return false; }
26.289 };
26.290
26.291 - /// This iterator goes through each edge.
26.292 + /// Iterator class for the edges.
26.293
26.294 - /// This iterator goes through each edge of a graph.
26.295 + /// This iterator goes through each edge of the 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 + /// of edges in a graph \c g of type \c %Graph as follows:
26.299 ///\code
26.300 /// int count=0;
26.301 /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
26.302 @@ -226,290 +238,285 @@
26.303 public:
26.304 /// Default constructor
26.305
26.306 - /// @warning The default constructor sets the iterator
26.307 - /// to an undefined value.
26.308 + /// Default constructor.
26.309 + /// \warning It sets the iterator to an undefined value.
26.310 EdgeIt() { }
26.311 /// Copy constructor.
26.312
26.313 /// Copy constructor.
26.314 ///
26.315 EdgeIt(const EdgeIt& e) : Edge(e) { }
26.316 - /// Initialize the iterator to be invalid.
26.317 + /// %Invalid constructor \& conversion.
26.318
26.319 - /// Initialize the iterator to be invalid.
26.320 + /// Initializes the iterator to be invalid.
26.321 + /// \sa Invalid for more details.
26.322 + EdgeIt(Invalid) { }
26.323 + /// Sets the iterator to the first edge.
26.324 +
26.325 + /// Sets the iterator to the first edge of the given graph.
26.326 ///
26.327 - EdgeIt(Invalid) { }
26.328 - /// This constructor sets the iterator to the first edge.
26.329 + explicit EdgeIt(const Graph&) { }
26.330 + /// Sets the iterator to the given edge.
26.331
26.332 - /// This constructor sets the iterator to the first edge.
26.333 - EdgeIt(const Graph&) { }
26.334 - /// Edge -> EdgeIt conversion
26.335 -
26.336 - /// Sets the iterator to the value of the trivial iterator.
26.337 - /// This feature necessitates that each time we
26.338 - /// iterate the edge-set, the iteration order is the
26.339 - /// same.
26.340 + /// Sets the iterator to the given edge of the given graph.
26.341 + ///
26.342 EdgeIt(const Graph&, const Edge&) { }
26.343 /// Next edge
26.344
26.345 /// Assign the iterator to the next edge.
26.346 + ///
26.347 EdgeIt& operator++() { return *this; }
26.348 };
26.349
26.350 - /// \brief This iterator goes trough the incident undirected
26.351 - /// arcs of a node.
26.352 - ///
26.353 - /// This iterator goes trough the incident edges
26.354 - /// of a certain node of a graph. You should assume that the
26.355 - /// loop arcs will be iterated twice.
26.356 - ///
26.357 + /// Iterator class for the incident edges of a node.
26.358 +
26.359 + /// This iterator goes trough the incident undirected edges
26.360 + /// of a certain node of a graph.
26.361 /// Its usage is quite simple, for example you can compute the
26.362 - /// degree (i.e. count the number of incident arcs of a node \c n
26.363 - /// in graph \c g of type \c Graph as follows.
26.364 + /// degree (i.e. the number of incident edges) of a node \c n
26.365 + /// in a graph \c g of type \c %Graph as follows.
26.366 ///
26.367 ///\code
26.368 /// int count=0;
26.369 /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count;
26.370 ///\endcode
26.371 + ///
26.372 + /// \warning Loop edges will be iterated twice.
26.373 class IncEdgeIt : public Edge {
26.374 public:
26.375 /// Default constructor
26.376
26.377 - /// @warning The default constructor sets the iterator
26.378 - /// to an undefined value.
26.379 + /// Default constructor.
26.380 + /// \warning It sets the iterator to an undefined value.
26.381 IncEdgeIt() { }
26.382 /// Copy constructor.
26.383
26.384 /// Copy constructor.
26.385 ///
26.386 IncEdgeIt(const IncEdgeIt& e) : Edge(e) { }
26.387 - /// Initialize the iterator to be invalid.
26.388 + /// %Invalid constructor \& conversion.
26.389
26.390 - /// Initialize the iterator to be invalid.
26.391 + /// Initializes the iterator to be invalid.
26.392 + /// \sa Invalid for more details.
26.393 + IncEdgeIt(Invalid) { }
26.394 + /// Sets the iterator to the first incident edge.
26.395 +
26.396 + /// Sets the iterator to the first incident edge of the given node.
26.397 ///
26.398 - IncEdgeIt(Invalid) { }
26.399 - /// This constructor sets the iterator to first incident arc.
26.400 + IncEdgeIt(const Graph&, const Node&) { }
26.401 + /// Sets the iterator to the given edge.
26.402
26.403 - /// This constructor set the iterator to the first incident arc of
26.404 - /// the node.
26.405 - IncEdgeIt(const Graph&, const Node&) { }
26.406 - /// Edge -> IncEdgeIt conversion
26.407 + /// Sets the iterator to the given edge of the given graph.
26.408 + ///
26.409 + IncEdgeIt(const Graph&, const Edge&) { }
26.410 + /// Next incident edge
26.411
26.412 - /// Sets the iterator to the value of the trivial iterator \c e.
26.413 - /// This feature necessitates that each time we
26.414 - /// iterate the arc-set, the iteration order is the same.
26.415 - IncEdgeIt(const Graph&, const Edge&) { }
26.416 - /// Next incident arc
26.417 -
26.418 - /// Assign the iterator to the next incident arc
26.419 + /// Assign the iterator to the next incident edge
26.420 /// of the corresponding node.
26.421 IncEdgeIt& operator++() { return *this; }
26.422 };
26.423
26.424 - /// The directed arc type.
26.425 + /// The arc type of the graph
26.426
26.427 - /// The directed arc type. It can be converted to the
26.428 - /// edge or it should be inherited from the undirected
26.429 - /// edge.
26.430 + /// This class identifies a directed arc of the graph. It also serves
26.431 + /// as a base class of the arc iterators,
26.432 + /// thus they will convert to this type.
26.433 class Arc {
26.434 public:
26.435 /// Default constructor
26.436
26.437 - /// @warning The default constructor sets the iterator
26.438 - /// to an undefined value.
26.439 + /// Default constructor.
26.440 + /// \warning It sets the object to an undefined value.
26.441 Arc() { }
26.442 /// Copy constructor.
26.443
26.444 /// Copy constructor.
26.445 ///
26.446 Arc(const Arc&) { }
26.447 - /// Initialize the iterator to be invalid.
26.448 + /// %Invalid constructor \& conversion.
26.449
26.450 - /// Initialize the iterator to be invalid.
26.451 - ///
26.452 + /// Initializes the object to be invalid.
26.453 + /// \sa Invalid for more details.
26.454 Arc(Invalid) { }
26.455 /// Equality operator
26.456
26.457 + /// Equality operator.
26.458 + ///
26.459 /// Two iterators are equal if and only if they point to the
26.460 - /// same object or both are invalid.
26.461 + /// same object or both are \c INVALID.
26.462 bool operator==(Arc) const { return true; }
26.463 /// Inequality operator
26.464
26.465 - /// \sa operator==(Arc n)
26.466 - ///
26.467 + /// Inequality operator.
26.468 bool operator!=(Arc) const { return true; }
26.469
26.470 /// Artificial ordering operator.
26.471
26.472 - /// To allow the use of graph descriptors as key type in std::map or
26.473 - /// similar associative container we require this.
26.474 + /// Artificial ordering operator.
26.475 ///
26.476 - /// \note This operator only have to define some strict ordering of
26.477 - /// the items; this order has nothing to do with the iteration
26.478 - /// ordering of the items.
26.479 + /// \note This operator only has to define some strict ordering of
26.480 + /// the arcs; this order has nothing to do with the iteration
26.481 + /// ordering of the arcs.
26.482 bool operator<(Arc) const { return false; }
26.483
26.484 - /// Converison to Edge
26.485 + /// Converison to \c Edge
26.486 +
26.487 + /// Converison to \c Edge.
26.488 + ///
26.489 operator Edge() const { return Edge(); }
26.490 };
26.491 - /// This iterator goes through each directed arc.
26.492
26.493 - /// This iterator goes through each arc of a graph.
26.494 + /// Iterator class for the arcs.
26.495 +
26.496 + /// This iterator goes through each directed arc of the 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 + /// of arcs in a graph \c g of type \c %Graph as follows:
26.500 ///\code
26.501 /// int count=0;
26.502 - /// for(Graph::ArcIt e(g); e!=INVALID; ++e) ++count;
26.503 + /// for(Graph::ArcIt a(g); a!=INVALID; ++a) ++count;
26.504 ///\endcode
26.505 class ArcIt : public Arc {
26.506 public:
26.507 /// Default constructor
26.508
26.509 - /// @warning The default constructor sets the iterator
26.510 - /// to an undefined value.
26.511 + /// Default constructor.
26.512 + /// \warning It sets the iterator to an undefined value.
26.513 ArcIt() { }
26.514 /// Copy constructor.
26.515
26.516 /// Copy constructor.
26.517 ///
26.518 ArcIt(const ArcIt& e) : Arc(e) { }
26.519 - /// Initialize the iterator to be invalid.
26.520 + /// %Invalid constructor \& conversion.
26.521
26.522 - /// Initialize the iterator to be invalid.
26.523 + /// Initializes the iterator to be invalid.
26.524 + /// \sa Invalid for more details.
26.525 + ArcIt(Invalid) { }
26.526 + /// Sets the iterator to the first arc.
26.527 +
26.528 + /// Sets the iterator to the first arc of the given graph.
26.529 ///
26.530 - ArcIt(Invalid) { }
26.531 - /// This constructor sets the iterator to the first arc.
26.532 + explicit ArcIt(const Graph &g) { ignore_unused_variable_warning(g); }
26.533 + /// Sets the iterator to the given arc.
26.534
26.535 - /// This constructor sets the iterator to the first arc of \c g.
26.536 - ///@param g the graph
26.537 - ArcIt(const Graph &g) { ignore_unused_variable_warning(g); }
26.538 - /// Arc -> ArcIt conversion
26.539 -
26.540 - /// Sets the iterator to the value of the trivial iterator \c e.
26.541 - /// This feature necessitates that each time we
26.542 - /// iterate the arc-set, the iteration order is the same.
26.543 + /// Sets the iterator to the given arc of the given graph.
26.544 + ///
26.545 ArcIt(const Graph&, const Arc&) { }
26.546 - ///Next arc
26.547 + /// Next arc
26.548
26.549 /// Assign the iterator to the next arc.
26.550 + ///
26.551 ArcIt& operator++() { return *this; }
26.552 };
26.553
26.554 - /// This iterator goes trough the outgoing directed arcs of a node.
26.555 + /// Iterator class for the outgoing arcs of a node.
26.556
26.557 - /// This iterator goes trough the \e outgoing arcs of a certain node
26.558 - /// of a graph.
26.559 + /// This iterator goes trough the \e outgoing directed arcs of a
26.560 + /// certain node of a graph.
26.561 /// Its usage is quite simple, for example you can count the number
26.562 /// of outgoing arcs of a node \c n
26.563 - /// in graph \c g of type \c Graph as follows.
26.564 + /// in a graph \c g of type \c %Graph as follows.
26.565 ///\code
26.566 /// int count=0;
26.567 - /// for (Graph::OutArcIt e(g, n); e!=INVALID; ++e) ++count;
26.568 + /// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count;
26.569 ///\endcode
26.570 -
26.571 class OutArcIt : public Arc {
26.572 public:
26.573 /// Default constructor
26.574
26.575 - /// @warning The default constructor sets the iterator
26.576 - /// to an undefined value.
26.577 + /// Default constructor.
26.578 + /// \warning It sets the iterator to an undefined value.
26.579 OutArcIt() { }
26.580 /// Copy constructor.
26.581
26.582 /// Copy constructor.
26.583 ///
26.584 OutArcIt(const OutArcIt& e) : Arc(e) { }
26.585 - /// Initialize the iterator to be invalid.
26.586 + /// %Invalid constructor \& conversion.
26.587
26.588 - /// Initialize the iterator to be invalid.
26.589 + /// Initializes the iterator to be invalid.
26.590 + /// \sa Invalid for more details.
26.591 + OutArcIt(Invalid) { }
26.592 + /// Sets the iterator to the first outgoing arc.
26.593 +
26.594 + /// Sets the iterator to the first outgoing arc of the given node.
26.595 ///
26.596 - OutArcIt(Invalid) { }
26.597 - /// This constructor sets the iterator to the first outgoing arc.
26.598 -
26.599 - /// This constructor sets the iterator to the first outgoing arc of
26.600 - /// the node.
26.601 - ///@param n the node
26.602 - ///@param g the graph
26.603 OutArcIt(const Graph& n, const Node& g) {
26.604 ignore_unused_variable_warning(n);
26.605 ignore_unused_variable_warning(g);
26.606 }
26.607 - /// Arc -> OutArcIt conversion
26.608 + /// Sets the iterator to the given arc.
26.609
26.610 - /// Sets the iterator to the value of the trivial iterator.
26.611 - /// This feature necessitates that each time we
26.612 - /// iterate the arc-set, the iteration order is the same.
26.613 + /// Sets the iterator to the given arc of the given graph.
26.614 + ///
26.615 OutArcIt(const Graph&, const Arc&) { }
26.616 - ///Next outgoing arc
26.617 + /// Next outgoing arc
26.618
26.619 /// Assign the iterator to the next
26.620 /// outgoing arc of the corresponding node.
26.621 OutArcIt& operator++() { return *this; }
26.622 };
26.623
26.624 - /// This iterator goes trough the incoming directed arcs of a node.
26.625 + /// Iterator class for the incoming arcs of a node.
26.626
26.627 - /// This iterator goes trough the \e incoming arcs of a certain node
26.628 - /// of a graph.
26.629 + /// This iterator goes trough the \e incoming directed arcs of a
26.630 + /// certain node of a graph.
26.631 /// Its usage is quite simple, for example you can count the number
26.632 - /// of outgoing arcs of a node \c n
26.633 - /// in graph \c g of type \c Graph as follows.
26.634 + /// of incoming arcs of a node \c n
26.635 + /// in a graph \c g of type \c %Graph as follows.
26.636 ///\code
26.637 /// int count=0;
26.638 - /// for(Graph::InArcIt e(g, n); e!=INVALID; ++e) ++count;
26.639 + /// for (Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count;
26.640 ///\endcode
26.641 -
26.642 class InArcIt : public Arc {
26.643 public:
26.644 /// Default constructor
26.645
26.646 - /// @warning The default constructor sets the iterator
26.647 - /// to an undefined value.
26.648 + /// Default constructor.
26.649 + /// \warning It sets the iterator to an undefined value.
26.650 InArcIt() { }
26.651 /// Copy constructor.
26.652
26.653 /// Copy constructor.
26.654 ///
26.655 InArcIt(const InArcIt& e) : Arc(e) { }
26.656 - /// Initialize the iterator to be invalid.
26.657 + /// %Invalid constructor \& conversion.
26.658
26.659 - /// Initialize the iterator to be invalid.
26.660 + /// Initializes the iterator to be invalid.
26.661 + /// \sa Invalid for more details.
26.662 + InArcIt(Invalid) { }
26.663 + /// Sets the iterator to the first incoming arc.
26.664 +
26.665 + /// Sets the iterator to the first incoming arc of the given node.
26.666 ///
26.667 - InArcIt(Invalid) { }
26.668 - /// This constructor sets the iterator to first incoming arc.
26.669 -
26.670 - /// This constructor set the iterator to the first incoming arc of
26.671 - /// the node.
26.672 - ///@param n the node
26.673 - ///@param g the graph
26.674 InArcIt(const Graph& g, const Node& n) {
26.675 ignore_unused_variable_warning(n);
26.676 ignore_unused_variable_warning(g);
26.677 }
26.678 - /// Arc -> InArcIt conversion
26.679 + /// Sets the iterator to the given arc.
26.680
26.681 - /// Sets the iterator to the value of the trivial iterator \c e.
26.682 - /// This feature necessitates that each time we
26.683 - /// iterate the arc-set, the iteration order is the same.
26.684 + /// Sets the iterator to the given arc of the given graph.
26.685 + ///
26.686 InArcIt(const Graph&, const Arc&) { }
26.687 /// Next incoming arc
26.688
26.689 - /// Assign the iterator to the next inarc of the corresponding node.
26.690 - ///
26.691 + /// Assign the iterator to the next
26.692 + /// incoming arc of the corresponding node.
26.693 InArcIt& operator++() { return *this; }
26.694 };
26.695
26.696 - /// \brief Reference map of the nodes to type \c T.
26.697 + /// \brief Standard graph map type for the nodes.
26.698 ///
26.699 - /// Reference map of the nodes to type \c T.
26.700 + /// Standard graph map type for the nodes.
26.701 + /// It conforms to the ReferenceMap concept.
26.702 template<class T>
26.703 class NodeMap : public ReferenceMap<Node, T, T&, const T&>
26.704 {
26.705 public:
26.706
26.707 - ///\e
26.708 - NodeMap(const Graph&) { }
26.709 - ///\e
26.710 + /// Constructor
26.711 + explicit NodeMap(const Graph&) { }
26.712 + /// Constructor with given initial value
26.713 NodeMap(const Graph&, T) { }
26.714
26.715 private:
26.716 @@ -524,18 +531,20 @@
26.717 }
26.718 };
26.719
26.720 - /// \brief Reference map of the arcs to type \c T.
26.721 + /// \brief Standard graph map type for the arcs.
26.722 ///
26.723 - /// Reference map of the arcs to type \c T.
26.724 + /// Standard graph map type for the arcs.
26.725 + /// It conforms to the ReferenceMap concept.
26.726 template<class T>
26.727 class ArcMap : public ReferenceMap<Arc, T, T&, const T&>
26.728 {
26.729 public:
26.730
26.731 - ///\e
26.732 - ArcMap(const Graph&) { }
26.733 - ///\e
26.734 + /// Constructor
26.735 + explicit ArcMap(const Graph&) { }
26.736 + /// Constructor with given initial value
26.737 ArcMap(const Graph&, T) { }
26.738 +
26.739 private:
26.740 ///Copy constructor
26.741 ArcMap(const ArcMap& em) :
26.742 @@ -548,18 +557,20 @@
26.743 }
26.744 };
26.745
26.746 - /// Reference map of the edges to type \c T.
26.747 -
26.748 - /// Reference map of the edges to type \c T.
26.749 + /// \brief Standard graph map type for the edges.
26.750 + ///
26.751 + /// Standard graph map type for the edges.
26.752 + /// It conforms to the ReferenceMap concept.
26.753 template<class T>
26.754 class EdgeMap : public ReferenceMap<Edge, T, T&, const T&>
26.755 {
26.756 public:
26.757
26.758 - ///\e
26.759 - EdgeMap(const Graph&) { }
26.760 - ///\e
26.761 + /// Constructor
26.762 + explicit EdgeMap(const Graph&) { }
26.763 + /// Constructor with given initial value
26.764 EdgeMap(const Graph&, T) { }
26.765 +
26.766 private:
26.767 ///Copy constructor
26.768 EdgeMap(const EdgeMap& em) :
26.769 @@ -572,107 +583,124 @@
26.770 }
26.771 };
26.772
26.773 - /// \brief Direct the given edge.
26.774 + /// \brief The first node of the edge.
26.775 ///
26.776 - /// Direct the given edge. The returned arc source
26.777 - /// will be the given node.
26.778 - Arc direct(const Edge&, const Node&) const {
26.779 - return INVALID;
26.780 - }
26.781 -
26.782 - /// \brief Direct the given edge.
26.783 + /// Returns the first node of the given edge.
26.784 ///
26.785 - /// Direct the given edge. The returned arc
26.786 - /// represents the given edge and the direction comes
26.787 - /// from the bool parameter. The source of the edge and
26.788 - /// the directed arc is the same when the given bool is true.
26.789 - Arc direct(const Edge&, bool) const {
26.790 - return INVALID;
26.791 - }
26.792 -
26.793 - /// \brief Returns true if the arc has default orientation.
26.794 - ///
26.795 - /// Returns whether the given directed arc is same orientation as
26.796 - /// the corresponding edge's default orientation.
26.797 - bool direction(Arc) const { return true; }
26.798 -
26.799 - /// \brief Returns the opposite directed arc.
26.800 - ///
26.801 - /// Returns the opposite directed arc.
26.802 - Arc oppositeArc(Arc) const { return INVALID; }
26.803 -
26.804 - /// \brief Opposite node on an arc
26.805 - ///
26.806 - /// \return The opposite of the given node on the given edge.
26.807 - Node oppositeNode(Node, Edge) const { return INVALID; }
26.808 -
26.809 - /// \brief First node of the edge.
26.810 - ///
26.811 - /// \return The first node of the given edge.
26.812 - ///
26.813 - /// Naturally edges don't have direction and thus
26.814 - /// don't have source and target node. However we use \c u() and \c v()
26.815 - /// methods to query the two nodes of the arc. The direction of the
26.816 - /// arc which arises this way is called the inherent direction of the
26.817 - /// edge, and is used to define the "default" direction
26.818 - /// of the directed versions of the arcs.
26.819 + /// Edges don't have source and target nodes, however methods
26.820 + /// u() and v() are used to query the two end-nodes of an edge.
26.821 + /// The orientation of an edge that arises this way is called
26.822 + /// the inherent direction, it is used to define the default
26.823 + /// direction for the corresponding arcs.
26.824 /// \sa v()
26.825 /// \sa direction()
26.826 Node u(Edge) const { return INVALID; }
26.827
26.828 - /// \brief Second node of the edge.
26.829 + /// \brief The second node of the edge.
26.830 ///
26.831 - /// \return The second node of the given edge.
26.832 + /// Returns the second node of the given edge.
26.833 ///
26.834 - /// Naturally edges don't have direction and thus
26.835 - /// don't have source and target node. However we use \c u() and \c v()
26.836 - /// methods to query the two nodes of the arc. The direction of the
26.837 - /// arc which arises this way is called the inherent direction of the
26.838 - /// edge, and is used to define the "default" direction
26.839 - /// of the directed versions of the arcs.
26.840 + /// Edges don't have source and target nodes, however methods
26.841 + /// u() and v() are used to query the two end-nodes of an edge.
26.842 + /// The orientation of an edge that arises this way is called
26.843 + /// the inherent direction, it is used to define the default
26.844 + /// direction for the corresponding arcs.
26.845 /// \sa u()
26.846 /// \sa direction()
26.847 Node v(Edge) const { return INVALID; }
26.848
26.849 - /// \brief Source node of the directed arc.
26.850 + /// \brief The source node of the arc.
26.851 + ///
26.852 + /// Returns the source node of the given arc.
26.853 Node source(Arc) const { return INVALID; }
26.854
26.855 - /// \brief Target node of the directed arc.
26.856 + /// \brief The target node of the arc.
26.857 + ///
26.858 + /// Returns the target node of the given arc.
26.859 Node target(Arc) const { return INVALID; }
26.860
26.861 - /// \brief Returns the id of the node.
26.862 + /// \brief The ID of the node.
26.863 + ///
26.864 + /// Returns the ID of the given node.
26.865 int id(Node) const { return -1; }
26.866
26.867 - /// \brief Returns the id of the edge.
26.868 + /// \brief The ID of the edge.
26.869 + ///
26.870 + /// Returns the ID of the given edge.
26.871 int id(Edge) const { return -1; }
26.872
26.873 - /// \brief Returns the id of the arc.
26.874 + /// \brief The ID of the arc.
26.875 + ///
26.876 + /// Returns the ID of the given arc.
26.877 int id(Arc) const { return -1; }
26.878
26.879 - /// \brief Returns the node with the given id.
26.880 + /// \brief The node with the given ID.
26.881 ///
26.882 - /// \pre The argument should be a valid node id in the graph.
26.883 + /// Returns the node with the given ID.
26.884 + /// \pre The argument should be a valid node ID in the graph.
26.885 Node nodeFromId(int) const { return INVALID; }
26.886
26.887 - /// \brief Returns the edge with the given id.
26.888 + /// \brief The edge with the given ID.
26.889 ///
26.890 - /// \pre The argument should be a valid edge id in the graph.
26.891 + /// Returns the edge with the given ID.
26.892 + /// \pre The argument should be a valid edge ID in the graph.
26.893 Edge edgeFromId(int) const { return INVALID; }
26.894
26.895 - /// \brief Returns the arc with the given id.
26.896 + /// \brief The arc with the given ID.
26.897 ///
26.898 - /// \pre The argument should be a valid arc id in the graph.
26.899 + /// Returns the arc with the given ID.
26.900 + /// \pre The argument should be a valid arc ID in the graph.
26.901 Arc arcFromId(int) const { return INVALID; }
26.902
26.903 - /// \brief Returns an upper bound on the node IDs.
26.904 + /// \brief An upper bound on the node IDs.
26.905 + ///
26.906 + /// Returns an upper bound on the node IDs.
26.907 int maxNodeId() const { return -1; }
26.908
26.909 - /// \brief Returns an upper bound on the edge IDs.
26.910 + /// \brief An upper bound on the edge IDs.
26.911 + ///
26.912 + /// Returns an upper bound on the edge IDs.
26.913 int maxEdgeId() const { return -1; }
26.914
26.915 - /// \brief Returns an upper bound on the arc IDs.
26.916 + /// \brief An upper bound on the arc IDs.
26.917 + ///
26.918 + /// Returns an upper bound on the arc IDs.
26.919 int maxArcId() const { return -1; }
26.920
26.921 + /// \brief The direction of the arc.
26.922 + ///
26.923 + /// Returns \c true if the direction of the given arc is the same as
26.924 + /// the inherent orientation of the represented edge.
26.925 + bool direction(Arc) const { return true; }
26.926 +
26.927 + /// \brief Direct the edge.
26.928 + ///
26.929 + /// Direct the given edge. The returned arc
26.930 + /// represents the given edge and its direction comes
26.931 + /// from the bool parameter. If it is \c true, then the direction
26.932 + /// of the arc is the same as the inherent orientation of the edge.
26.933 + Arc direct(Edge, bool) const {
26.934 + return INVALID;
26.935 + }
26.936 +
26.937 + /// \brief Direct the edge.
26.938 + ///
26.939 + /// Direct the given edge. The returned arc represents the given
26.940 + /// edge and its source node is the given node.
26.941 + Arc direct(Edge, Node) const {
26.942 + return INVALID;
26.943 + }
26.944 +
26.945 + /// \brief The oppositely directed arc.
26.946 + ///
26.947 + /// Returns the oppositely directed arc representing the same edge.
26.948 + Arc oppositeArc(Arc) const { return INVALID; }
26.949 +
26.950 + /// \brief The opposite node on the edge.
26.951 + ///
26.952 + /// Returns the opposite node on the given edge.
26.953 + Node oppositeNode(Node, Edge) const { return INVALID; }
26.954 +
26.955 void first(Node&) const {}
26.956 void next(Node&) const {}
26.957
26.958 @@ -705,47 +733,39 @@
26.959 // Dummy parameter.
26.960 int maxId(Arc) const { return -1; }
26.961
26.962 - /// \brief Base node of the iterator
26.963 + /// \brief The base node of the iterator.
26.964 ///
26.965 - /// Returns the base node (the source in this case) of the iterator
26.966 - Node baseNode(OutArcIt e) const {
26.967 - return source(e);
26.968 - }
26.969 - /// \brief Running node of the iterator
26.970 + /// Returns the base node of the given incident edge iterator.
26.971 + Node baseNode(IncEdgeIt) const { return INVALID; }
26.972 +
26.973 + /// \brief The running node of the iterator.
26.974 ///
26.975 - /// Returns the running node (the target in this case) of the
26.976 - /// iterator
26.977 - Node runningNode(OutArcIt e) const {
26.978 - return target(e);
26.979 - }
26.980 + /// Returns the running node of the given incident edge iterator.
26.981 + Node runningNode(IncEdgeIt) const { return INVALID; }
26.982
26.983 - /// \brief Base node of the iterator
26.984 + /// \brief The base node of the iterator.
26.985 ///
26.986 - /// Returns the base node (the target in this case) of the iterator
26.987 - Node baseNode(InArcIt e) const {
26.988 - return target(e);
26.989 - }
26.990 - /// \brief Running node of the iterator
26.991 + /// Returns the base node of the given outgoing arc iterator
26.992 + /// (i.e. the source node of the corresponding arc).
26.993 + Node baseNode(OutArcIt) const { return INVALID; }
26.994 +
26.995 + /// \brief The running node of the iterator.
26.996 ///
26.997 - /// Returns the running node (the source in this case) of the
26.998 - /// iterator
26.999 - Node runningNode(InArcIt e) const {
26.1000 - return source(e);
26.1001 - }
26.1002 + /// Returns the running node of the given outgoing arc iterator
26.1003 + /// (i.e. the target node of the corresponding arc).
26.1004 + Node runningNode(OutArcIt) const { return INVALID; }
26.1005
26.1006 - /// \brief Base node of the iterator
26.1007 + /// \brief The base node of the iterator.
26.1008 ///
26.1009 - /// Returns the base node of the iterator
26.1010 - Node baseNode(IncEdgeIt) const {
26.1011 - return INVALID;
26.1012 - }
26.1013 + /// Returns the base node of the given incomming arc iterator
26.1014 + /// (i.e. the target node of the corresponding arc).
26.1015 + Node baseNode(InArcIt) const { return INVALID; }
26.1016
26.1017 - /// \brief Running node of the iterator
26.1018 + /// \brief The running node of the iterator.
26.1019 ///
26.1020 - /// Returns the running node of the iterator
26.1021 - Node runningNode(IncEdgeIt) const {
26.1022 - return INVALID;
26.1023 - }
26.1024 + /// Returns the running node of the given incomming arc iterator
26.1025 + /// (i.e. the source node of the corresponding arc).
26.1026 + Node runningNode(InArcIt) const { return INVALID; }
26.1027
26.1028 template <typename _Graph>
26.1029 struct Constraints {
27.1 --- a/lemon/concepts/graph_components.h Tue Aug 18 10:08:28 2009 +0200
27.2 +++ b/lemon/concepts/graph_components.h Thu Nov 05 08:39:49 2009 +0100
27.3 @@ -92,7 +92,7 @@
27.4 /// It makes possible to use graph item types as key types in
27.5 /// associative containers (e.g. \c std::map).
27.6 ///
27.7 - /// \note This operator only have to define some strict ordering of
27.8 + /// \note This operator only has to define some strict ordering of
27.9 /// the items; this order has nothing to do with the iteration
27.10 /// ordering of the items.
27.11 bool operator<(const GraphItem&) const { return false; }
28.1 --- a/lemon/concepts/heap.h Tue Aug 18 10:08:28 2009 +0200
28.2 +++ b/lemon/concepts/heap.h Thu Nov 05 08:39:49 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/maps.h Tue Aug 18 10:08:28 2009 +0200
29.2 +++ b/lemon/concepts/maps.h Thu Nov 05 08:39:49 2009 +0100
29.3 @@ -182,7 +182,8 @@
29.4
29.5 template<typename _ReferenceMap>
29.6 struct Constraints {
29.7 - void constraints() {
29.8 + typename enable_if<typename _ReferenceMap::ReferenceMapTag, void>::type
29.9 + constraints() {
29.10 checkConcept<ReadWriteMap<K, T>, _ReferenceMap >();
29.11 ref = m[key];
29.12 m[key] = val;
30.1 --- a/lemon/cplex.cc Tue Aug 18 10:08:28 2009 +0200
30.2 +++ b/lemon/cplex.cc Thu Nov 05 08:39:49 2009 +0100
30.3 @@ -111,6 +111,39 @@
30.4 return i;
30.5 }
30.6
30.7 + int CplexBase::_addRow(Value lb, ExprIterator b,
30.8 + ExprIterator e, Value ub) {
30.9 + int i = CPXgetnumrows(cplexEnv(), _prob);
30.10 + if (lb == -INF) {
30.11 + const char s = 'L';
30.12 + CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0);
30.13 + } else if (ub == INF) {
30.14 + const char s = 'G';
30.15 + CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
30.16 + } else if (lb == ub){
30.17 + const char s = 'E';
30.18 + CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
30.19 + } else {
30.20 + const char s = 'R';
30.21 + double len = ub - lb;
30.22 + CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, &len, 0);
30.23 + }
30.24 +
30.25 + std::vector<int> indices;
30.26 + std::vector<int> rowlist;
30.27 + std::vector<Value> values;
30.28 +
30.29 + for(ExprIterator it=b; it!=e; ++it) {
30.30 + indices.push_back(it->first);
30.31 + values.push_back(it->second);
30.32 + rowlist.push_back(i);
30.33 + }
30.34 +
30.35 + CPXchgcoeflist(cplexEnv(), _prob, values.size(),
30.36 + &rowlist.front(), &indices.front(), &values.front());
30.37 +
30.38 + return i;
30.39 + }
30.40
30.41 void CplexBase::_eraseCol(int i) {
30.42 CPXdelcols(cplexEnv(), _prob, i, i);
31.1 --- a/lemon/cplex.h Tue Aug 18 10:08:28 2009 +0200
31.2 +++ b/lemon/cplex.h Thu Nov 05 08:39:49 2009 +0100
31.3 @@ -93,6 +93,7 @@
31.4
31.5 virtual int _addCol();
31.6 virtual int _addRow();
31.7 + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
31.8
31.9 virtual void _eraseCol(int i);
31.10 virtual void _eraseRow(int i);
32.1 --- a/lemon/dfs.h Tue Aug 18 10:08:28 2009 +0200
32.2 +++ b/lemon/dfs.h Thu Nov 05 08:39:49 2009 +0100
32.3 @@ -47,7 +47,7 @@
32.4 ///
32.5 ///The type of the map that stores the predecessor
32.6 ///arcs of the %DFS paths.
32.7 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
32.8 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
32.9 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
32.10 ///Instantiates a \c PredMap.
32.11
32.12 @@ -62,7 +62,8 @@
32.13 ///The type of the map that indicates which nodes are processed.
32.14
32.15 ///The type of the map that indicates which nodes are processed.
32.16 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
32.17 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
32.18 + ///By default it is a NullMap.
32.19 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
32.20 ///Instantiates a \c ProcessedMap.
32.21
32.22 @@ -81,7 +82,7 @@
32.23 ///The type of the map that indicates which nodes are reached.
32.24
32.25 ///The type of the map that indicates which nodes are reached.
32.26 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
32.27 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
32.28 typedef typename Digraph::template NodeMap<bool> ReachedMap;
32.29 ///Instantiates a \c ReachedMap.
32.30
32.31 @@ -96,7 +97,7 @@
32.32 ///The type of the map that stores the distances of the nodes.
32.33
32.34 ///The type of the map that stores the distances of the nodes.
32.35 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
32.36 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
32.37 typedef typename Digraph::template NodeMap<int> DistMap;
32.38 ///Instantiates a \c DistMap.
32.39
32.40 @@ -224,7 +225,7 @@
32.41 ///
32.42 ///\ref named-templ-param "Named parameter" for setting
32.43 ///\c PredMap type.
32.44 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
32.45 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
32.46 template <class T>
32.47 struct SetPredMap : public Dfs<Digraph, SetPredMapTraits<T> > {
32.48 typedef Dfs<Digraph, SetPredMapTraits<T> > Create;
32.49 @@ -244,7 +245,7 @@
32.50 ///
32.51 ///\ref named-templ-param "Named parameter" for setting
32.52 ///\c DistMap type.
32.53 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
32.54 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
32.55 template <class T>
32.56 struct SetDistMap : public Dfs< Digraph, SetDistMapTraits<T> > {
32.57 typedef Dfs<Digraph, SetDistMapTraits<T> > Create;
32.58 @@ -264,7 +265,7 @@
32.59 ///
32.60 ///\ref named-templ-param "Named parameter" for setting
32.61 ///\c ReachedMap type.
32.62 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
32.63 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
32.64 template <class T>
32.65 struct SetReachedMap : public Dfs< Digraph, SetReachedMapTraits<T> > {
32.66 typedef Dfs< Digraph, SetReachedMapTraits<T> > Create;
32.67 @@ -284,7 +285,7 @@
32.68 ///
32.69 ///\ref named-templ-param "Named parameter" for setting
32.70 ///\c ProcessedMap type.
32.71 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
32.72 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
32.73 template <class T>
32.74 struct SetProcessedMap : public Dfs< Digraph, SetProcessedMapTraits<T> > {
32.75 typedef Dfs< Digraph, SetProcessedMapTraits<T> > Create;
32.76 @@ -411,8 +412,8 @@
32.77 ///\name Execution Control
32.78 ///The simplest way to execute the DFS algorithm is to use one of the
32.79 ///member functions called \ref run(Node) "run()".\n
32.80 - ///If you need more control on the execution, first you have to call
32.81 - ///\ref init(), then you can add a source node with \ref addSource()
32.82 + ///If you need better control on the execution, you have to call
32.83 + ///\ref init() first, then you can add a source node with \ref addSource()
32.84 ///and perform the actual computation with \ref start().
32.85 ///This procedure can be repeated if there are nodes that have not
32.86 ///been reached.
32.87 @@ -669,9 +670,9 @@
32.88
32.89 ///@{
32.90
32.91 - ///The DFS path to a node.
32.92 + ///The DFS path to the given node.
32.93
32.94 - ///Returns the DFS path to a node.
32.95 + ///Returns the DFS path to the given node from the root(s).
32.96 ///
32.97 ///\warning \c t should be reached from the root(s).
32.98 ///
32.99 @@ -679,9 +680,9 @@
32.100 ///must be called before using this function.
32.101 Path path(Node t) const { return Path(*G, *_pred, t); }
32.102
32.103 - ///The distance of a node from the root(s).
32.104 + ///The distance of the given node from the root(s).
32.105
32.106 - ///Returns the distance of a node from the root(s).
32.107 + ///Returns the distance of the given node from the root(s).
32.108 ///
32.109 ///\warning If node \c v is not reached from the root(s), then
32.110 ///the return value of this function is undefined.
32.111 @@ -690,7 +691,7 @@
32.112 ///must be called before using this function.
32.113 int dist(Node v) const { return (*_dist)[v]; }
32.114
32.115 - ///Returns the 'previous arc' of the %DFS tree for a node.
32.116 + ///Returns the 'previous arc' of the %DFS tree for the given node.
32.117
32.118 ///This function returns the 'previous arc' of the %DFS tree for the
32.119 ///node \c v, i.e. it returns the last arc of a %DFS path from a
32.120 @@ -698,21 +699,21 @@
32.121 ///root(s) or if \c v is a root.
32.122 ///
32.123 ///The %DFS tree used here is equal to the %DFS tree used in
32.124 - ///\ref predNode().
32.125 + ///\ref predNode() and \ref predMap().
32.126 ///
32.127 ///\pre Either \ref run(Node) "run()" or \ref init()
32.128 ///must be called before using this function.
32.129 Arc predArc(Node v) const { return (*_pred)[v];}
32.130
32.131 - ///Returns the 'previous node' of the %DFS tree.
32.132 + ///Returns the 'previous node' of the %DFS tree for the given node.
32.133
32.134 ///This function returns the 'previous node' of the %DFS
32.135 ///tree for the node \c v, i.e. it returns the last but one node
32.136 - ///from a %DFS path from a root to \c v. It is \c INVALID
32.137 + ///of a %DFS path from a root to \c v. It is \c INVALID
32.138 ///if \c v is not reached from the root(s) or if \c v is a root.
32.139 ///
32.140 ///The %DFS tree used here is equal to the %DFS tree used in
32.141 - ///\ref predArc().
32.142 + ///\ref predArc() and \ref predMap().
32.143 ///
32.144 ///\pre Either \ref run(Node) "run()" or \ref init()
32.145 ///must be called before using this function.
32.146 @@ -733,13 +734,13 @@
32.147 ///predecessor arcs.
32.148 ///
32.149 ///Returns a const reference to the node map that stores the predecessor
32.150 - ///arcs, which form the DFS tree.
32.151 + ///arcs, which form the DFS tree (forest).
32.152 ///
32.153 ///\pre Either \ref run(Node) "run()" or \ref init()
32.154 ///must be called before using this function.
32.155 const PredMap &predMap() const { return *_pred;}
32.156
32.157 - ///Checks if a node is reached from the root(s).
32.158 + ///Checks if the given node. node is reached from the root(s).
32.159
32.160 ///Returns \c true if \c v is reached from the root(s).
32.161 ///
32.162 @@ -765,7 +766,7 @@
32.163 ///
32.164 ///The type of the map that stores the predecessor
32.165 ///arcs of the %DFS paths.
32.166 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
32.167 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
32.168 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
32.169 ///Instantiates a PredMap.
32.170
32.171 @@ -780,7 +781,7 @@
32.172 ///The type of the map that indicates which nodes are processed.
32.173
32.174 ///The type of the map that indicates which nodes are processed.
32.175 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
32.176 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
32.177 ///By default it is a NullMap.
32.178 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
32.179 ///Instantiates a ProcessedMap.
32.180 @@ -800,7 +801,7 @@
32.181 ///The type of the map that indicates which nodes are reached.
32.182
32.183 ///The type of the map that indicates which nodes are reached.
32.184 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
32.185 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
32.186 typedef typename Digraph::template NodeMap<bool> ReachedMap;
32.187 ///Instantiates a ReachedMap.
32.188
32.189 @@ -815,7 +816,7 @@
32.190 ///The type of the map that stores the distances of the nodes.
32.191
32.192 ///The type of the map that stores the distances of the nodes.
32.193 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
32.194 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
32.195 typedef typename Digraph::template NodeMap<int> DistMap;
32.196 ///Instantiates a DistMap.
32.197
32.198 @@ -830,18 +831,14 @@
32.199 ///The type of the DFS paths.
32.200
32.201 ///The type of the DFS paths.
32.202 - ///It must meet the \ref concepts::Path "Path" concept.
32.203 + ///It must conform to the \ref concepts::Path "Path" concept.
32.204 typedef lemon::Path<Digraph> Path;
32.205 };
32.206
32.207 /// Default traits class used by DfsWizard
32.208
32.209 - /// To make it easier to use Dfs algorithm
32.210 - /// we have created a wizard class.
32.211 - /// This \ref DfsWizard class needs default traits,
32.212 - /// as well as the \ref Dfs class.
32.213 - /// The \ref DfsWizardBase is a class to be the default traits of the
32.214 - /// \ref DfsWizard class.
32.215 + /// Default traits class used by DfsWizard.
32.216 + /// \tparam GR The type of the digraph.
32.217 template<class GR>
32.218 class DfsWizardBase : public DfsWizardDefaultTraits<GR>
32.219 {
32.220 @@ -869,7 +866,7 @@
32.221 public:
32.222 /// Constructor.
32.223
32.224 - /// This constructor does not require parameters, therefore it initiates
32.225 + /// This constructor does not require parameters, it initiates
32.226 /// all of the attributes to \c 0.
32.227 DfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
32.228 _dist(0), _path(0), _di(0) {}
32.229 @@ -899,7 +896,6 @@
32.230 {
32.231 typedef TR Base;
32.232
32.233 - ///The type of the digraph the algorithm runs on.
32.234 typedef typename TR::Digraph Digraph;
32.235
32.236 typedef typename Digraph::Node Node;
32.237 @@ -907,16 +903,10 @@
32.238 typedef typename Digraph::Arc Arc;
32.239 typedef typename Digraph::OutArcIt OutArcIt;
32.240
32.241 - ///\brief The type of the map that stores the predecessor
32.242 - ///arcs of the DFS paths.
32.243 typedef typename TR::PredMap PredMap;
32.244 - ///\brief The type of the map that stores the distances of the nodes.
32.245 typedef typename TR::DistMap DistMap;
32.246 - ///\brief The type of the map that indicates which nodes are reached.
32.247 typedef typename TR::ReachedMap ReachedMap;
32.248 - ///\brief The type of the map that indicates which nodes are processed.
32.249 typedef typename TR::ProcessedMap ProcessedMap;
32.250 - ///The type of the DFS paths
32.251 typedef typename TR::Path Path;
32.252
32.253 public:
32.254 @@ -999,11 +989,12 @@
32.255 static PredMap *createPredMap(const Digraph &) { return 0; };
32.256 SetPredMapBase(const TR &b) : TR(b) {}
32.257 };
32.258 - ///\brief \ref named-func-param "Named parameter"
32.259 - ///for setting PredMap object.
32.260 +
32.261 + ///\brief \ref named-templ-param "Named parameter" for setting
32.262 + ///the predecessor map.
32.263 ///
32.264 - ///\ref named-func-param "Named parameter"
32.265 - ///for setting PredMap object.
32.266 + ///\ref named-templ-param "Named parameter" function for setting
32.267 + ///the map that stores the predecessor arcs of the nodes.
32.268 template<class T>
32.269 DfsWizard<SetPredMapBase<T> > predMap(const T &t)
32.270 {
32.271 @@ -1017,11 +1008,12 @@
32.272 static ReachedMap *createReachedMap(const Digraph &) { return 0; };
32.273 SetReachedMapBase(const TR &b) : TR(b) {}
32.274 };
32.275 - ///\brief \ref named-func-param "Named parameter"
32.276 - ///for setting ReachedMap object.
32.277 +
32.278 + ///\brief \ref named-templ-param "Named parameter" for setting
32.279 + ///the reached map.
32.280 ///
32.281 - /// \ref named-func-param "Named parameter"
32.282 - ///for setting ReachedMap object.
32.283 + ///\ref named-templ-param "Named parameter" function for setting
32.284 + ///the map that indicates which nodes are reached.
32.285 template<class T>
32.286 DfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
32.287 {
32.288 @@ -1035,11 +1027,13 @@
32.289 static DistMap *createDistMap(const Digraph &) { return 0; };
32.290 SetDistMapBase(const TR &b) : TR(b) {}
32.291 };
32.292 - ///\brief \ref named-func-param "Named parameter"
32.293 - ///for setting DistMap object.
32.294 +
32.295 + ///\brief \ref named-templ-param "Named parameter" for setting
32.296 + ///the distance map.
32.297 ///
32.298 - /// \ref named-func-param "Named parameter"
32.299 - ///for setting DistMap object.
32.300 + ///\ref named-templ-param "Named parameter" function for setting
32.301 + ///the map that stores the distances of the nodes calculated
32.302 + ///by the algorithm.
32.303 template<class T>
32.304 DfsWizard<SetDistMapBase<T> > distMap(const T &t)
32.305 {
32.306 @@ -1053,11 +1047,12 @@
32.307 static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
32.308 SetProcessedMapBase(const TR &b) : TR(b) {}
32.309 };
32.310 - ///\brief \ref named-func-param "Named parameter"
32.311 - ///for setting ProcessedMap object.
32.312 +
32.313 + ///\brief \ref named-func-param "Named parameter" for setting
32.314 + ///the processed map.
32.315 ///
32.316 - /// \ref named-func-param "Named parameter"
32.317 - ///for setting ProcessedMap object.
32.318 + ///\ref named-templ-param "Named parameter" function for setting
32.319 + ///the map that indicates which nodes are processed.
32.320 template<class T>
32.321 DfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
32.322 {
32.323 @@ -1208,7 +1203,7 @@
32.324 /// \brief The type of the map that indicates which nodes are reached.
32.325 ///
32.326 /// The type of the map that indicates which nodes are reached.
32.327 - /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
32.328 + /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
32.329 typedef typename Digraph::template NodeMap<bool> ReachedMap;
32.330
32.331 /// \brief Instantiates a ReachedMap.
32.332 @@ -1369,8 +1364,8 @@
32.333 /// \name Execution Control
32.334 /// The simplest way to execute the DFS algorithm is to use one of the
32.335 /// member functions called \ref run(Node) "run()".\n
32.336 - /// If you need more control on the execution, first you have to call
32.337 - /// \ref init(), then you can add a source node with \ref addSource()
32.338 + /// If you need better control on the execution, you have to call
32.339 + /// \ref init() first, then you can add a source node with \ref addSource()
32.340 /// and perform the actual computation with \ref start().
32.341 /// This procedure can be repeated if there are nodes that have not
32.342 /// been reached.
32.343 @@ -1620,7 +1615,7 @@
32.344
32.345 ///@{
32.346
32.347 - /// \brief Checks if a node is reached from the root(s).
32.348 + /// \brief Checks if the given node is reached from the root(s).
32.349 ///
32.350 /// Returns \c true if \c v is reached from the root(s).
32.351 ///
33.1 --- a/lemon/dijkstra.h Tue Aug 18 10:08:28 2009 +0200
33.2 +++ b/lemon/dijkstra.h Thu Nov 05 08:39:49 2009 +0100
33.3 @@ -70,9 +70,9 @@
33.4 ///The type of the map that stores the arc lengths.
33.5
33.6 ///The type of the map that stores the arc lengths.
33.7 - ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
33.8 + ///It must conform to the \ref concepts::ReadMap "ReadMap" concept.
33.9 typedef LEN LengthMap;
33.10 - ///The type of the length of the arcs.
33.11 + ///The type of the arc lengths.
33.12 typedef typename LEN::Value Value;
33.13
33.14 /// Operation traits for %Dijkstra algorithm.
33.15 @@ -116,7 +116,7 @@
33.16 ///
33.17 ///The type of the map that stores the predecessor
33.18 ///arcs of the shortest paths.
33.19 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.20 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.21 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
33.22 ///Instantiates a \c PredMap.
33.23
33.24 @@ -131,7 +131,7 @@
33.25 ///The type of the map that indicates which nodes are processed.
33.26
33.27 ///The type of the map that indicates which nodes are processed.
33.28 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.29 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.30 ///By default it is a NullMap.
33.31 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
33.32 ///Instantiates a \c ProcessedMap.
33.33 @@ -151,7 +151,7 @@
33.34 ///The type of the map that stores the distances of the nodes.
33.35
33.36 ///The type of the map that stores the distances of the nodes.
33.37 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.38 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.39 typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap;
33.40 ///Instantiates a \c DistMap.
33.41
33.42 @@ -169,6 +169,10 @@
33.43 /// \ingroup shortest_path
33.44 ///This class provides an efficient implementation of the %Dijkstra algorithm.
33.45 ///
33.46 + ///The %Dijkstra algorithm solves the single-source shortest path problem
33.47 + ///when all arc lengths are non-negative. If there are negative lengths,
33.48 + ///the BellmanFord algorithm should be used instead.
33.49 + ///
33.50 ///The arc lengths are passed to the algorithm using a
33.51 ///\ref concepts::ReadMap "ReadMap",
33.52 ///so it is easy to change it to any kind of length.
33.53 @@ -201,7 +205,7 @@
33.54 ///The type of the digraph the algorithm runs on.
33.55 typedef typename TR::Digraph Digraph;
33.56
33.57 - ///The type of the length of the arcs.
33.58 + ///The type of the arc lengths.
33.59 typedef typename TR::LengthMap::Value Value;
33.60 ///The type of the map that stores the arc lengths.
33.61 typedef typename TR::LengthMap LengthMap;
33.62 @@ -304,7 +308,7 @@
33.63 ///
33.64 ///\ref named-templ-param "Named parameter" for setting
33.65 ///\c PredMap type.
33.66 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.67 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.68 template <class T>
33.69 struct SetPredMap
33.70 : public Dijkstra< Digraph, LengthMap, SetPredMapTraits<T> > {
33.71 @@ -325,7 +329,7 @@
33.72 ///
33.73 ///\ref named-templ-param "Named parameter" for setting
33.74 ///\c DistMap type.
33.75 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.76 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.77 template <class T>
33.78 struct SetDistMap
33.79 : public Dijkstra< Digraph, LengthMap, SetDistMapTraits<T> > {
33.80 @@ -346,7 +350,7 @@
33.81 ///
33.82 ///\ref named-templ-param "Named parameter" for setting
33.83 ///\c ProcessedMap type.
33.84 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.85 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.86 template <class T>
33.87 struct SetProcessedMap
33.88 : public Dijkstra< Digraph, LengthMap, SetProcessedMapTraits<T> > {
33.89 @@ -443,6 +447,7 @@
33.90 ///
33.91 ///\ref named-templ-param "Named parameter" for setting
33.92 ///\c OperationTraits type.
33.93 + /// For more information see \ref DijkstraDefaultOperationTraits.
33.94 template <class T>
33.95 struct SetOperationTraits
33.96 : public Dijkstra<Digraph, LengthMap, SetOperationTraitsTraits<T> > {
33.97 @@ -584,8 +589,8 @@
33.98 ///\name Execution Control
33.99 ///The simplest way to execute the %Dijkstra algorithm is to use
33.100 ///one of the member functions called \ref run(Node) "run()".\n
33.101 - ///If you need more control on the execution, first you have to call
33.102 - ///\ref init(), then you can add several source nodes with
33.103 + ///If you need better control on the execution, you have to call
33.104 + ///\ref init() first, then you can add several source nodes with
33.105 ///\ref addSource(). Finally the actual path computation can be
33.106 ///performed with one of the \ref start() functions.
33.107
33.108 @@ -801,14 +806,14 @@
33.109 ///\name Query Functions
33.110 ///The results of the %Dijkstra algorithm can be obtained using these
33.111 ///functions.\n
33.112 - ///Either \ref run(Node) "run()" or \ref start() should be called
33.113 + ///Either \ref run(Node) "run()" or \ref init() should be called
33.114 ///before using them.
33.115
33.116 ///@{
33.117
33.118 - ///The shortest path to a node.
33.119 + ///The shortest path to the given node.
33.120
33.121 - ///Returns the shortest path to a node.
33.122 + ///Returns the shortest path to the given node from the root(s).
33.123 ///
33.124 ///\warning \c t should be reached from the root(s).
33.125 ///
33.126 @@ -816,9 +821,9 @@
33.127 ///must be called before using this function.
33.128 Path path(Node t) const { return Path(*G, *_pred, t); }
33.129
33.130 - ///The distance of a node from the root(s).
33.131 + ///The distance of the given node from the root(s).
33.132
33.133 - ///Returns the distance of a node from the root(s).
33.134 + ///Returns the distance of the given node from the root(s).
33.135 ///
33.136 ///\warning If node \c v is not reached from the root(s), then
33.137 ///the return value of this function is undefined.
33.138 @@ -827,29 +832,31 @@
33.139 ///must be called before using this function.
33.140 Value dist(Node v) const { return (*_dist)[v]; }
33.141
33.142 - ///Returns the 'previous arc' of the shortest path tree for a node.
33.143 -
33.144 + ///\brief Returns the 'previous arc' of the shortest path tree for
33.145 + ///the given node.
33.146 + ///
33.147 ///This function returns the 'previous arc' of the shortest path
33.148 ///tree for the node \c v, i.e. it returns the last arc of a
33.149 ///shortest path from a root to \c v. It is \c INVALID if \c v
33.150 ///is not reached from the root(s) or if \c v is a root.
33.151 ///
33.152 ///The shortest path tree used here is equal to the shortest path
33.153 - ///tree used in \ref predNode().
33.154 + ///tree used in \ref predNode() and \ref predMap().
33.155 ///
33.156 ///\pre Either \ref run(Node) "run()" or \ref init()
33.157 ///must be called before using this function.
33.158 Arc predArc(Node v) const { return (*_pred)[v]; }
33.159
33.160 - ///Returns the 'previous node' of the shortest path tree for a node.
33.161 -
33.162 + ///\brief Returns the 'previous node' of the shortest path tree for
33.163 + ///the given node.
33.164 + ///
33.165 ///This function returns the 'previous node' of the shortest path
33.166 ///tree for the node \c v, i.e. it returns the last but one node
33.167 - ///from a shortest path from a root to \c v. It is \c INVALID
33.168 + ///of a shortest path from a root to \c v. It is \c INVALID
33.169 ///if \c v is not reached from the root(s) or if \c v is a root.
33.170 ///
33.171 ///The shortest path tree used here is equal to the shortest path
33.172 - ///tree used in \ref predArc().
33.173 + ///tree used in \ref predArc() and \ref predMap().
33.174 ///
33.175 ///\pre Either \ref run(Node) "run()" or \ref init()
33.176 ///must be called before using this function.
33.177 @@ -870,13 +877,13 @@
33.178 ///predecessor arcs.
33.179 ///
33.180 ///Returns a const reference to the node map that stores the predecessor
33.181 - ///arcs, which form the shortest path tree.
33.182 + ///arcs, which form the shortest path tree (forest).
33.183 ///
33.184 ///\pre Either \ref run(Node) "run()" or \ref init()
33.185 ///must be called before using this function.
33.186 const PredMap &predMap() const { return *_pred;}
33.187
33.188 - ///Checks if a node is reached from the root(s).
33.189 + ///Checks if the given node is reached from the root(s).
33.190
33.191 ///Returns \c true if \c v is reached from the root(s).
33.192 ///
33.193 @@ -895,9 +902,9 @@
33.194 bool processed(Node v) const { return (*_heap_cross_ref)[v] ==
33.195 Heap::POST_HEAP; }
33.196
33.197 - ///The current distance of a node from the root(s).
33.198 + ///The current distance of the given node from the root(s).
33.199
33.200 - ///Returns the current distance of a node from the root(s).
33.201 + ///Returns the current distance of the given node from the root(s).
33.202 ///It may be decreased in the following processes.
33.203 ///
33.204 ///\pre Either \ref run(Node) "run()" or \ref init()
33.205 @@ -924,9 +931,9 @@
33.206 ///The type of the map that stores the arc lengths.
33.207
33.208 ///The type of the map that stores the arc lengths.
33.209 - ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
33.210 + ///It must conform to the \ref concepts::ReadMap "ReadMap" concept.
33.211 typedef LEN LengthMap;
33.212 - ///The type of the length of the arcs.
33.213 + ///The type of the arc lengths.
33.214 typedef typename LEN::Value Value;
33.215
33.216 /// Operation traits for Dijkstra algorithm.
33.217 @@ -973,7 +980,7 @@
33.218 ///
33.219 ///The type of the map that stores the predecessor
33.220 ///arcs of the shortest paths.
33.221 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.222 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.223 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
33.224 ///Instantiates a PredMap.
33.225
33.226 @@ -988,7 +995,7 @@
33.227 ///The type of the map that indicates which nodes are processed.
33.228
33.229 ///The type of the map that indicates which nodes are processed.
33.230 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.231 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.232 ///By default it is a NullMap.
33.233 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
33.234 ///Instantiates a ProcessedMap.
33.235 @@ -1008,7 +1015,7 @@
33.236 ///The type of the map that stores the distances of the nodes.
33.237
33.238 ///The type of the map that stores the distances of the nodes.
33.239 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
33.240 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
33.241 typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap;
33.242 ///Instantiates a DistMap.
33.243
33.244 @@ -1023,18 +1030,15 @@
33.245 ///The type of the shortest paths.
33.246
33.247 ///The type of the shortest paths.
33.248 - ///It must meet the \ref concepts::Path "Path" concept.
33.249 + ///It must conform to the \ref concepts::Path "Path" concept.
33.250 typedef lemon::Path<Digraph> Path;
33.251 };
33.252
33.253 /// Default traits class used by DijkstraWizard
33.254
33.255 - /// To make it easier to use Dijkstra algorithm
33.256 - /// we have created a wizard class.
33.257 - /// This \ref DijkstraWizard class needs default traits,
33.258 - /// as well as the \ref Dijkstra class.
33.259 - /// The \ref DijkstraWizardBase is a class to be the default traits of the
33.260 - /// \ref DijkstraWizard class.
33.261 + /// Default traits class used by DijkstraWizard.
33.262 + /// \tparam GR The type of the digraph.
33.263 + /// \tparam LEN The type of the length map.
33.264 template<typename GR, typename LEN>
33.265 class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LEN>
33.266 {
33.267 @@ -1093,7 +1097,6 @@
33.268 {
33.269 typedef TR Base;
33.270
33.271 - ///The type of the digraph the algorithm runs on.
33.272 typedef typename TR::Digraph Digraph;
33.273
33.274 typedef typename Digraph::Node Node;
33.275 @@ -1101,20 +1104,12 @@
33.276 typedef typename Digraph::Arc Arc;
33.277 typedef typename Digraph::OutArcIt OutArcIt;
33.278
33.279 - ///The type of the map that stores the arc lengths.
33.280 typedef typename TR::LengthMap LengthMap;
33.281 - ///The type of the length of the arcs.
33.282 typedef typename LengthMap::Value Value;
33.283 - ///\brief The type of the map that stores the predecessor
33.284 - ///arcs of the shortest paths.
33.285 typedef typename TR::PredMap PredMap;
33.286 - ///The type of the map that stores the distances of the nodes.
33.287 typedef typename TR::DistMap DistMap;
33.288 - ///The type of the map that indicates which nodes are processed.
33.289 typedef typename TR::ProcessedMap ProcessedMap;
33.290 - ///The type of the shortest paths
33.291 typedef typename TR::Path Path;
33.292 - ///The heap type used by the dijkstra algorithm.
33.293 typedef typename TR::Heap Heap;
33.294
33.295 public:
33.296 @@ -1186,11 +1181,12 @@
33.297 static PredMap *createPredMap(const Digraph &) { return 0; };
33.298 SetPredMapBase(const TR &b) : TR(b) {}
33.299 };
33.300 - ///\brief \ref named-func-param "Named parameter"
33.301 - ///for setting PredMap object.
33.302 +
33.303 + ///\brief \ref named-templ-param "Named parameter" for setting
33.304 + ///the predecessor map.
33.305 ///
33.306 - ///\ref named-func-param "Named parameter"
33.307 - ///for setting PredMap object.
33.308 + ///\ref named-templ-param "Named parameter" function for setting
33.309 + ///the map that stores the predecessor arcs of the nodes.
33.310 template<class T>
33.311 DijkstraWizard<SetPredMapBase<T> > predMap(const T &t)
33.312 {
33.313 @@ -1204,11 +1200,13 @@
33.314 static DistMap *createDistMap(const Digraph &) { return 0; };
33.315 SetDistMapBase(const TR &b) : TR(b) {}
33.316 };
33.317 - ///\brief \ref named-func-param "Named parameter"
33.318 - ///for setting DistMap object.
33.319 +
33.320 + ///\brief \ref named-templ-param "Named parameter" for setting
33.321 + ///the distance map.
33.322 ///
33.323 - ///\ref named-func-param "Named parameter"
33.324 - ///for setting DistMap object.
33.325 + ///\ref named-templ-param "Named parameter" function for setting
33.326 + ///the map that stores the distances of the nodes calculated
33.327 + ///by the algorithm.
33.328 template<class T>
33.329 DijkstraWizard<SetDistMapBase<T> > distMap(const T &t)
33.330 {
33.331 @@ -1222,11 +1220,12 @@
33.332 static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
33.333 SetProcessedMapBase(const TR &b) : TR(b) {}
33.334 };
33.335 - ///\brief \ref named-func-param "Named parameter"
33.336 - ///for setting ProcessedMap object.
33.337 +
33.338 + ///\brief \ref named-func-param "Named parameter" for setting
33.339 + ///the processed map.
33.340 ///
33.341 - /// \ref named-func-param "Named parameter"
33.342 - ///for setting ProcessedMap object.
33.343 + ///\ref named-templ-param "Named parameter" function for setting
33.344 + ///the map that indicates which nodes are processed.
33.345 template<class T>
33.346 DijkstraWizard<SetProcessedMapBase<T> > processedMap(const T &t)
33.347 {
33.348 @@ -1239,6 +1238,7 @@
33.349 typedef T Path;
33.350 SetPathBase(const TR &b) : TR(b) {}
33.351 };
33.352 +
33.353 ///\brief \ref named-func-param "Named parameter"
33.354 ///for getting the shortest path to the target node.
33.355 ///
34.1 --- a/lemon/dim2.h Tue Aug 18 10:08:28 2009 +0200
34.2 +++ b/lemon/dim2.h Thu Nov 05 08:39:49 2009 +0100
34.3 @@ -21,16 +21,9 @@
34.4
34.5 #include <iostream>
34.6
34.7 -///\ingroup misc
34.8 +///\ingroup geomdat
34.9 ///\file
34.10 ///\brief A simple two dimensional vector and a bounding box implementation
34.11 -///
34.12 -/// The class \ref lemon::dim2::Point "dim2::Point" implements
34.13 -/// a two dimensional vector with the usual operations.
34.14 -///
34.15 -/// The class \ref lemon::dim2::Box "dim2::Box" can be used to determine
34.16 -/// the rectangular bounding box of a set of
34.17 -/// \ref lemon::dim2::Point "dim2::Point"'s.
34.18
34.19 namespace lemon {
34.20
34.21 @@ -40,7 +33,7 @@
34.22 ///tools for handling two dimensional coordinates
34.23 namespace dim2 {
34.24
34.25 - /// \addtogroup misc
34.26 + /// \addtogroup geomdat
34.27 /// @{
34.28
34.29 /// Two dimensional vector (plain vector)
35.1 --- a/lemon/fib_heap.h Tue Aug 18 10:08:28 2009 +0200
35.2 +++ b/lemon/fib_heap.h Thu Nov 05 08:39:49 2009 +0100
35.3 @@ -20,53 +20,49 @@
35.4 #define LEMON_FIB_HEAP_H
35.5
35.6 ///\file
35.7 -///\ingroup auxdat
35.8 -///\brief Fibonacci Heap implementation.
35.9 +///\ingroup heaps
35.10 +///\brief Fibonacci heap implementation.
35.11
35.12 #include <vector>
35.13 +#include <utility>
35.14 #include <functional>
35.15 #include <lemon/math.h>
35.16
35.17 namespace lemon {
35.18
35.19 - /// \ingroup auxdat
35.20 + /// \ingroup heaps
35.21 ///
35.22 - ///\brief Fibonacci Heap.
35.23 + /// \brief Fibonacci heap data structure.
35.24 ///
35.25 - ///This class implements the \e Fibonacci \e heap data structure. A \e heap
35.26 - ///is a data structure for storing items with specified values called \e
35.27 - ///priorities in such a way that finding the item with minimum priority is
35.28 - ///efficient. \c CMP specifies the ordering of the priorities. In a heap
35.29 - ///one can change the priority of an item, add or erase an item, etc.
35.30 + /// This class implements the \e Fibonacci \e heap data structure.
35.31 + /// It fully conforms to the \ref concepts::Heap "heap concept".
35.32 ///
35.33 - ///The methods \ref increase and \ref erase are not efficient in a Fibonacci
35.34 - ///heap. In case of many calls to these operations, it is better to use a
35.35 - ///\ref BinHeap "binary heap".
35.36 + /// The methods \ref increase() and \ref erase() are not efficient in a
35.37 + /// Fibonacci heap. In case of many calls of these operations, it is
35.38 + /// better to use other heap structure, e.g. \ref BinHeap "binary heap".
35.39 ///
35.40 - ///\param PRIO Type of the priority of the items.
35.41 - ///\param IM A read and writable Item int map, used internally
35.42 - ///to handle the cross references.
35.43 - ///\param CMP A class for the ordering of the priorities. The
35.44 - ///default is \c std::less<PRIO>.
35.45 - ///
35.46 - ///\sa BinHeap
35.47 - ///\sa Dijkstra
35.48 + /// \tparam PR Type of the priorities of the items.
35.49 + /// \tparam IM A read-writable item map with \c int values, used
35.50 + /// internally to handle the cross references.
35.51 + /// \tparam CMP A functor class for comparing the priorities.
35.52 + /// The default is \c std::less<PR>.
35.53 #ifdef DOXYGEN
35.54 - template <typename PRIO, typename IM, typename CMP>
35.55 + template <typename PR, typename IM, typename CMP>
35.56 #else
35.57 - template <typename PRIO, typename IM, typename CMP = std::less<PRIO> >
35.58 + template <typename PR, typename IM, typename CMP = std::less<PR> >
35.59 #endif
35.60 class FibHeap {
35.61 public:
35.62 - ///\e
35.63 +
35.64 + /// Type of the item-int map.
35.65 typedef IM ItemIntMap;
35.66 - ///\e
35.67 - typedef PRIO Prio;
35.68 - ///\e
35.69 + /// Type of the priorities.
35.70 + typedef PR Prio;
35.71 + /// Type of the items stored in the heap.
35.72 typedef typename ItemIntMap::Key Item;
35.73 - ///\e
35.74 + /// Type of the item-priority pairs.
35.75 typedef std::pair<Item,Prio> Pair;
35.76 - ///\e
35.77 + /// Functor type for comparing the priorities.
35.78 typedef CMP Compare;
35.79
35.80 private:
35.81 @@ -80,10 +76,10 @@
35.82
35.83 public:
35.84
35.85 - /// \brief Type to represent the items states.
35.86 + /// \brief Type to represent the states of the items.
35.87 ///
35.88 - /// Each Item element have a state associated to it. It may be "in heap",
35.89 - /// "pre heap" or "post heap". The latter two are indifferent from the
35.90 + /// Each item has a state associated to it. It can be "in heap",
35.91 + /// "pre-heap" or "post-heap". The latter two are indifferent from the
35.92 /// heap's point of view, but may be useful to the user.
35.93 ///
35.94 /// The item-int map must be initialized in such way that it assigns
35.95 @@ -94,60 +90,54 @@
35.96 POST_HEAP = -2 ///< = -2.
35.97 };
35.98
35.99 - /// \brief The constructor
35.100 + /// \brief Constructor.
35.101 ///
35.102 - /// \c map should be given to the constructor, since it is
35.103 - /// used internally to handle the cross references.
35.104 + /// Constructor.
35.105 + /// \param map A map that assigns \c int values to the items.
35.106 + /// It is used internally to handle the cross references.
35.107 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
35.108 explicit FibHeap(ItemIntMap &map)
35.109 : _minimum(0), _iim(map), _num() {}
35.110
35.111 - /// \brief The constructor
35.112 + /// \brief Constructor.
35.113 ///
35.114 - /// \c map should be given to the constructor, since it is used
35.115 - /// internally to handle the cross references. \c comp is an
35.116 - /// object for ordering of the priorities.
35.117 + /// Constructor.
35.118 + /// \param map A map that assigns \c int values to the items.
35.119 + /// It is used internally to handle the cross references.
35.120 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
35.121 + /// \param comp The function object used for comparing the priorities.
35.122 FibHeap(ItemIntMap &map, const Compare &comp)
35.123 : _minimum(0), _iim(map), _comp(comp), _num() {}
35.124
35.125 /// \brief The number of items stored in the heap.
35.126 ///
35.127 - /// Returns the number of items stored in the heap.
35.128 + /// This function returns the number of items stored in the heap.
35.129 int size() const { return _num; }
35.130
35.131 - /// \brief Checks if the heap stores no items.
35.132 + /// \brief Check if the heap is empty.
35.133 ///
35.134 - /// Returns \c true if and only if the heap stores no items.
35.135 + /// This function returns \c true if the heap is empty.
35.136 bool empty() const { return _num==0; }
35.137
35.138 - /// \brief Make empty this heap.
35.139 + /// \brief Make the heap empty.
35.140 ///
35.141 - /// Make empty this heap. It does not change the cross reference
35.142 - /// map. If you want to reuse a heap what is not surely empty you
35.143 - /// should first clear the heap and after that you should set the
35.144 - /// cross reference map for each item to \c PRE_HEAP.
35.145 + /// This functon makes the heap empty.
35.146 + /// It does not change the cross reference map. If you want to reuse
35.147 + /// a heap that is not surely empty, you should first clear it and
35.148 + /// then you should set the cross reference map to \c PRE_HEAP
35.149 + /// for each item.
35.150 void clear() {
35.151 _data.clear(); _minimum = 0; _num = 0;
35.152 }
35.153
35.154 - /// \brief \c item gets to the heap with priority \c value independently
35.155 - /// if \c item was already there.
35.156 + /// \brief Insert an item into the heap with the given priority.
35.157 ///
35.158 - /// This method calls \ref push(\c item, \c value) if \c item is not
35.159 - /// stored in the heap and it calls \ref decrease(\c item, \c value) or
35.160 - /// \ref increase(\c item, \c value) otherwise.
35.161 - void set (const Item& item, const Prio& value) {
35.162 - int i=_iim[item];
35.163 - if ( i >= 0 && _data[i].in ) {
35.164 - if ( _comp(value, _data[i].prio) ) decrease(item, value);
35.165 - if ( _comp(_data[i].prio, value) ) increase(item, value);
35.166 - } else push(item, value);
35.167 - }
35.168 -
35.169 - /// \brief Adds \c item to the heap with priority \c value.
35.170 - ///
35.171 - /// Adds \c item to the heap with priority \c value.
35.172 - /// \pre \c item must not be stored in the heap.
35.173 - void push (const Item& item, const Prio& value) {
35.174 + /// This function inserts the given item into the heap with the
35.175 + /// given priority.
35.176 + /// \param item The item to insert.
35.177 + /// \param prio The priority of the item.
35.178 + /// \pre \e item must not be stored in the heap.
35.179 + void push (const Item& item, const Prio& prio) {
35.180 int i=_iim[item];
35.181 if ( i < 0 ) {
35.182 int s=_data.size();
35.183 @@ -168,47 +158,37 @@
35.184 _data[i].right_neighbor=_data[_minimum].right_neighbor;
35.185 _data[_minimum].right_neighbor=i;
35.186 _data[i].left_neighbor=_minimum;
35.187 - if ( _comp( value, _data[_minimum].prio) ) _minimum=i;
35.188 + if ( _comp( prio, _data[_minimum].prio) ) _minimum=i;
35.189 } else {
35.190 _data[i].right_neighbor=_data[i].left_neighbor=i;
35.191 _minimum=i;
35.192 }
35.193 - _data[i].prio=value;
35.194 + _data[i].prio=prio;
35.195 ++_num;
35.196 }
35.197
35.198 - /// \brief Returns the item with minimum priority relative to \c Compare.
35.199 + /// \brief Return the item having minimum priority.
35.200 ///
35.201 - /// This method returns the item with minimum priority relative to \c
35.202 - /// Compare.
35.203 - /// \pre The heap must be nonempty.
35.204 + /// This function returns the item having minimum priority.
35.205 + /// \pre The heap must be non-empty.
35.206 Item top() const { return _data[_minimum].name; }
35.207
35.208 - /// \brief Returns the minimum priority relative to \c Compare.
35.209 + /// \brief The minimum priority.
35.210 ///
35.211 - /// It returns the minimum priority relative to \c Compare.
35.212 - /// \pre The heap must be nonempty.
35.213 - const Prio& prio() const { return _data[_minimum].prio; }
35.214 + /// This function returns the minimum priority.
35.215 + /// \pre The heap must be non-empty.
35.216 + Prio prio() const { return _data[_minimum].prio; }
35.217
35.218 - /// \brief Returns the priority of \c item.
35.219 + /// \brief Remove the item having minimum priority.
35.220 ///
35.221 - /// It returns the priority of \c item.
35.222 - /// \pre \c item must be in the heap.
35.223 - const Prio& operator[](const Item& item) const {
35.224 - return _data[_iim[item]].prio;
35.225 - }
35.226 -
35.227 - /// \brief Deletes the item with minimum priority relative to \c Compare.
35.228 - ///
35.229 - /// This method deletes the item with minimum priority relative to \c
35.230 - /// Compare from the heap.
35.231 + /// This function removes the item having minimum priority.
35.232 /// \pre The heap must be non-empty.
35.233 void pop() {
35.234 /*The first case is that there are only one root.*/
35.235 if ( _data[_minimum].left_neighbor==_minimum ) {
35.236 _data[_minimum].in=false;
35.237 if ( _data[_minimum].degree!=0 ) {
35.238 - makeroot(_data[_minimum].child);
35.239 + makeRoot(_data[_minimum].child);
35.240 _minimum=_data[_minimum].child;
35.241 balance();
35.242 }
35.243 @@ -221,7 +201,7 @@
35.244 int child=_data[_minimum].child;
35.245 int last_child=_data[child].left_neighbor;
35.246
35.247 - makeroot(child);
35.248 + makeRoot(child);
35.249
35.250 _data[left].right_neighbor=child;
35.251 _data[child].left_neighbor=left;
35.252 @@ -234,10 +214,12 @@
35.253 --_num;
35.254 }
35.255
35.256 - /// \brief Deletes \c item from the heap.
35.257 + /// \brief Remove the given item from the heap.
35.258 ///
35.259 - /// This method deletes \c item from the heap, if \c item was already
35.260 - /// stored in the heap. It is quite inefficient in Fibonacci heaps.
35.261 + /// This function removes the given item from the heap if it is
35.262 + /// already stored.
35.263 + /// \param item The item to delete.
35.264 + /// \pre \e item must be in the heap.
35.265 void erase (const Item& item) {
35.266 int i=_iim[item];
35.267
35.268 @@ -252,43 +234,68 @@
35.269 }
35.270 }
35.271
35.272 - /// \brief Decreases the priority of \c item to \c value.
35.273 + /// \brief The priority of the given item.
35.274 ///
35.275 - /// This method decreases the priority of \c item to \c value.
35.276 - /// \pre \c item must be stored in the heap with priority at least \c
35.277 - /// value relative to \c Compare.
35.278 - void decrease (Item item, const Prio& value) {
35.279 + /// This function returns the priority of the given item.
35.280 + /// \param item The item.
35.281 + /// \pre \e item must be in the heap.
35.282 + Prio operator[](const Item& item) const {
35.283 + return _data[_iim[item]].prio;
35.284 + }
35.285 +
35.286 + /// \brief Set the priority of an item or insert it, if it is
35.287 + /// not stored in the heap.
35.288 + ///
35.289 + /// This method sets the priority of the given item if it is
35.290 + /// already stored in the heap. Otherwise it inserts the given
35.291 + /// item into the heap with the given priority.
35.292 + /// \param item The item.
35.293 + /// \param prio The priority.
35.294 + void set (const Item& item, const Prio& prio) {
35.295 int i=_iim[item];
35.296 - _data[i].prio=value;
35.297 + if ( i >= 0 && _data[i].in ) {
35.298 + if ( _comp(prio, _data[i].prio) ) decrease(item, prio);
35.299 + if ( _comp(_data[i].prio, prio) ) increase(item, prio);
35.300 + } else push(item, prio);
35.301 + }
35.302 +
35.303 + /// \brief Decrease the priority of an item to the given value.
35.304 + ///
35.305 + /// This function decreases the priority of an item to the given value.
35.306 + /// \param item The item.
35.307 + /// \param prio The priority.
35.308 + /// \pre \e item must be stored in the heap with priority at least \e prio.
35.309 + void decrease (const Item& item, const Prio& prio) {
35.310 + int i=_iim[item];
35.311 + _data[i].prio=prio;
35.312 int p=_data[i].parent;
35.313
35.314 - if ( p!=-1 && _comp(value, _data[p].prio) ) {
35.315 + if ( p!=-1 && _comp(prio, _data[p].prio) ) {
35.316 cut(i,p);
35.317 cascade(p);
35.318 }
35.319 - if ( _comp(value, _data[_minimum].prio) ) _minimum=i;
35.320 + if ( _comp(prio, _data[_minimum].prio) ) _minimum=i;
35.321 }
35.322
35.323 - /// \brief Increases the priority of \c item to \c value.
35.324 + /// \brief Increase the priority of an item to the given value.
35.325 ///
35.326 - /// This method sets the priority of \c item to \c value. Though
35.327 - /// there is no precondition on the priority of \c item, this
35.328 - /// method should be used only if it is indeed necessary to increase
35.329 - /// (relative to \c Compare) the priority of \c item, because this
35.330 - /// method is inefficient.
35.331 - void increase (Item item, const Prio& value) {
35.332 + /// This function increases the priority of an item to the given value.
35.333 + /// \param item The item.
35.334 + /// \param prio The priority.
35.335 + /// \pre \e item must be stored in the heap with priority at most \e prio.
35.336 + void increase (const Item& item, const Prio& prio) {
35.337 erase(item);
35.338 - push(item, value);
35.339 + push(item, prio);
35.340 }
35.341
35.342 -
35.343 - /// \brief Returns if \c item is in, has already been in, or has never
35.344 - /// been in the heap.
35.345 + /// \brief Return the state of an item.
35.346 ///
35.347 - /// This method returns PRE_HEAP if \c item has never been in the
35.348 - /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
35.349 - /// otherwise. In the latter case it is possible that \c item will
35.350 - /// get back to the heap again.
35.351 + /// This method returns \c PRE_HEAP if the given item has never
35.352 + /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
35.353 + /// and \c POST_HEAP otherwise.
35.354 + /// In the latter case it is possible that the item will get back
35.355 + /// to the heap again.
35.356 + /// \param item The item.
35.357 State state(const Item &item) const {
35.358 int i=_iim[item];
35.359 if( i>=0 ) {
35.360 @@ -298,11 +305,11 @@
35.361 return State(i);
35.362 }
35.363
35.364 - /// \brief Sets the state of the \c item in the heap.
35.365 + /// \brief Set the state of an item in the heap.
35.366 ///
35.367 - /// Sets the state of the \c item in the heap. It can be used to
35.368 - /// manually clear the heap when it is important to achive the
35.369 - /// better time _complexity.
35.370 + /// This function sets the state of the given item in the heap.
35.371 + /// It can be used to manually clear the heap when it is important
35.372 + /// to achive better time complexity.
35.373 /// \param i The item.
35.374 /// \param st The state. It should not be \c IN_HEAP.
35.375 void state(const Item& i, State st) {
35.376 @@ -365,7 +372,7 @@
35.377 } while ( s != m );
35.378 }
35.379
35.380 - void makeroot(int c) {
35.381 + void makeRoot(int c) {
35.382 int s=c;
35.383 do {
35.384 _data[s].parent=-1;
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
36.2 +++ b/lemon/fourary_heap.h Thu Nov 05 08:39:49 2009 +0100
36.3 @@ -0,0 +1,342 @@
36.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
36.5 + *
36.6 + * This file is a part of LEMON, a generic C++ optimization library.
36.7 + *
36.8 + * Copyright (C) 2003-2009
36.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
36.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
36.11 + *
36.12 + * Permission to use, modify and distribute this software is granted
36.13 + * provided that this copyright notice appears in all copies. For
36.14 + * precise terms see the accompanying LICENSE file.
36.15 + *
36.16 + * This software is provided "AS IS" with no warranty of any kind,
36.17 + * express or implied, and with no claim as to its suitability for any
36.18 + * purpose.
36.19 + *
36.20 + */
36.21 +
36.22 +#ifndef LEMON_FOURARY_HEAP_H
36.23 +#define LEMON_FOURARY_HEAP_H
36.24 +
36.25 +///\ingroup heaps
36.26 +///\file
36.27 +///\brief Fourary heap implementation.
36.28 +
36.29 +#include <vector>
36.30 +#include <utility>
36.31 +#include <functional>
36.32 +
36.33 +namespace lemon {
36.34 +
36.35 + /// \ingroup heaps
36.36 + ///
36.37 + ///\brief Fourary heap data structure.
36.38 + ///
36.39 + /// This class implements the \e fourary \e heap data structure.
36.40 + /// It fully conforms to the \ref concepts::Heap "heap concept".
36.41 + ///
36.42 + /// The fourary heap is a specialization of the \ref KaryHeap "K-ary heap"
36.43 + /// for <tt>K=4</tt>. It is similar to the \ref BinHeap "binary heap",
36.44 + /// but its nodes have at most four children, instead of two.
36.45 + ///
36.46 + /// \tparam PR Type of the priorities of the items.
36.47 + /// \tparam IM A read-writable item map with \c int values, used
36.48 + /// internally to handle the cross references.
36.49 + /// \tparam CMP A functor class for comparing the priorities.
36.50 + /// The default is \c std::less<PR>.
36.51 + ///
36.52 + ///\sa BinHeap
36.53 + ///\sa KaryHeap
36.54 +#ifdef DOXYGEN
36.55 + template <typename PR, typename IM, typename CMP>
36.56 +#else
36.57 + template <typename PR, typename IM, typename CMP = std::less<PR> >
36.58 +#endif
36.59 + class FouraryHeap {
36.60 + public:
36.61 + /// Type of the item-int map.
36.62 + typedef IM ItemIntMap;
36.63 + /// Type of the priorities.
36.64 + typedef PR Prio;
36.65 + /// Type of the items stored in the heap.
36.66 + typedef typename ItemIntMap::Key Item;
36.67 + /// Type of the item-priority pairs.
36.68 + typedef std::pair<Item,Prio> Pair;
36.69 + /// Functor type for comparing the priorities.
36.70 + typedef CMP Compare;
36.71 +
36.72 + /// \brief Type to represent the states of the items.
36.73 + ///
36.74 + /// Each item has a state associated to it. It can be "in heap",
36.75 + /// "pre-heap" or "post-heap". The latter two are indifferent from the
36.76 + /// heap's point of view, but may be useful to the user.
36.77 + ///
36.78 + /// The item-int map must be initialized in such way that it assigns
36.79 + /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
36.80 + enum State {
36.81 + IN_HEAP = 0, ///< = 0.
36.82 + PRE_HEAP = -1, ///< = -1.
36.83 + POST_HEAP = -2 ///< = -2.
36.84 + };
36.85 +
36.86 + private:
36.87 + std::vector<Pair> _data;
36.88 + Compare _comp;
36.89 + ItemIntMap &_iim;
36.90 +
36.91 + public:
36.92 + /// \brief Constructor.
36.93 + ///
36.94 + /// Constructor.
36.95 + /// \param map A map that assigns \c int values to the items.
36.96 + /// It is used internally to handle the cross references.
36.97 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
36.98 + explicit FouraryHeap(ItemIntMap &map) : _iim(map) {}
36.99 +
36.100 + /// \brief Constructor.
36.101 + ///
36.102 + /// Constructor.
36.103 + /// \param map A map that assigns \c int values to the items.
36.104 + /// It is used internally to handle the cross references.
36.105 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
36.106 + /// \param comp The function object used for comparing the priorities.
36.107 + FouraryHeap(ItemIntMap &map, const Compare &comp)
36.108 + : _iim(map), _comp(comp) {}
36.109 +
36.110 + /// \brief The number of items stored in the heap.
36.111 + ///
36.112 + /// This function returns the number of items stored in the heap.
36.113 + int size() const { return _data.size(); }
36.114 +
36.115 + /// \brief Check if the heap is empty.
36.116 + ///
36.117 + /// This function returns \c true if the heap is empty.
36.118 + bool empty() const { return _data.empty(); }
36.119 +
36.120 + /// \brief Make the heap empty.
36.121 + ///
36.122 + /// This functon makes the heap empty.
36.123 + /// It does not change the cross reference map. If you want to reuse
36.124 + /// a heap that is not surely empty, you should first clear it and
36.125 + /// then you should set the cross reference map to \c PRE_HEAP
36.126 + /// for each item.
36.127 + void clear() { _data.clear(); }
36.128 +
36.129 + private:
36.130 + static int parent(int i) { return (i-1)/4; }
36.131 + static int firstChild(int i) { return 4*i+1; }
36.132 +
36.133 + bool less(const Pair &p1, const Pair &p2) const {
36.134 + return _comp(p1.second, p2.second);
36.135 + }
36.136 +
36.137 + void bubbleUp(int hole, Pair p) {
36.138 + int par = parent(hole);
36.139 + while( hole>0 && less(p,_data[par]) ) {
36.140 + move(_data[par],hole);
36.141 + hole = par;
36.142 + par = parent(hole);
36.143 + }
36.144 + move(p, hole);
36.145 + }
36.146 +
36.147 + void bubbleDown(int hole, Pair p, int length) {
36.148 + if( length>1 ) {
36.149 + int child = firstChild(hole);
36.150 + while( child+3<length ) {
36.151 + int min=child;
36.152 + if( less(_data[++child], _data[min]) ) min=child;
36.153 + if( less(_data[++child], _data[min]) ) min=child;
36.154 + if( less(_data[++child], _data[min]) ) min=child;
36.155 + if( !less(_data[min], p) )
36.156 + goto ok;
36.157 + move(_data[min], hole);
36.158 + hole = min;
36.159 + child = firstChild(hole);
36.160 + }
36.161 + if ( child<length ) {
36.162 + int min = child;
36.163 + if( ++child<length && less(_data[child], _data[min]) ) min=child;
36.164 + if( ++child<length && less(_data[child], _data[min]) ) min=child;
36.165 + if( less(_data[min], p) ) {
36.166 + move(_data[min], hole);
36.167 + hole = min;
36.168 + }
36.169 + }
36.170 + }
36.171 + ok:
36.172 + move(p, hole);
36.173 + }
36.174 +
36.175 + void move(const Pair &p, int i) {
36.176 + _data[i] = p;
36.177 + _iim.set(p.first, i);
36.178 + }
36.179 +
36.180 + public:
36.181 + /// \brief Insert a pair of item and priority into the heap.
36.182 + ///
36.183 + /// This function inserts \c p.first to the heap with priority
36.184 + /// \c p.second.
36.185 + /// \param p The pair to insert.
36.186 + /// \pre \c p.first must not be stored in the heap.
36.187 + void push(const Pair &p) {
36.188 + int n = _data.size();
36.189 + _data.resize(n+1);
36.190 + bubbleUp(n, p);
36.191 + }
36.192 +
36.193 + /// \brief Insert an item into the heap with the given priority.
36.194 + ///
36.195 + /// This function inserts the given item into the heap with the
36.196 + /// given priority.
36.197 + /// \param i The item to insert.
36.198 + /// \param p The priority of the item.
36.199 + /// \pre \e i must not be stored in the heap.
36.200 + void push(const Item &i, const Prio &p) { push(Pair(i,p)); }
36.201 +
36.202 + /// \brief Return the item having minimum priority.
36.203 + ///
36.204 + /// This function returns the item having minimum priority.
36.205 + /// \pre The heap must be non-empty.
36.206 + Item top() const { return _data[0].first; }
36.207 +
36.208 + /// \brief The minimum priority.
36.209 + ///
36.210 + /// This function returns the minimum priority.
36.211 + /// \pre The heap must be non-empty.
36.212 + Prio prio() const { return _data[0].second; }
36.213 +
36.214 + /// \brief Remove the item having minimum priority.
36.215 + ///
36.216 + /// This function removes the item having minimum priority.
36.217 + /// \pre The heap must be non-empty.
36.218 + void pop() {
36.219 + int n = _data.size()-1;
36.220 + _iim.set(_data[0].first, POST_HEAP);
36.221 + if (n>0) bubbleDown(0, _data[n], n);
36.222 + _data.pop_back();
36.223 + }
36.224 +
36.225 + /// \brief Remove the given item from the heap.
36.226 + ///
36.227 + /// This function removes the given item from the heap if it is
36.228 + /// already stored.
36.229 + /// \param i The item to delete.
36.230 + /// \pre \e i must be in the heap.
36.231 + void erase(const Item &i) {
36.232 + int h = _iim[i];
36.233 + int n = _data.size()-1;
36.234 + _iim.set(_data[h].first, POST_HEAP);
36.235 + if( h<n ) {
36.236 + if( less(_data[parent(h)], _data[n]) )
36.237 + bubbleDown(h, _data[n], n);
36.238 + else
36.239 + bubbleUp(h, _data[n]);
36.240 + }
36.241 + _data.pop_back();
36.242 + }
36.243 +
36.244 + /// \brief The priority of the given item.
36.245 + ///
36.246 + /// This function returns the priority of the given item.
36.247 + /// \param i The item.
36.248 + /// \pre \e i must be in the heap.
36.249 + Prio operator[](const Item &i) const {
36.250 + int idx = _iim[i];
36.251 + return _data[idx].second;
36.252 + }
36.253 +
36.254 + /// \brief Set the priority of an item or insert it, if it is
36.255 + /// not stored in the heap.
36.256 + ///
36.257 + /// This method sets the priority of the given item if it is
36.258 + /// already stored in the heap. Otherwise it inserts the given
36.259 + /// item into the heap with the given priority.
36.260 + /// \param i The item.
36.261 + /// \param p The priority.
36.262 + void set(const Item &i, const Prio &p) {
36.263 + int idx = _iim[i];
36.264 + if( idx < 0 )
36.265 + push(i,p);
36.266 + else if( _comp(p, _data[idx].second) )
36.267 + bubbleUp(idx, Pair(i,p));
36.268 + else
36.269 + bubbleDown(idx, Pair(i,p), _data.size());
36.270 + }
36.271 +
36.272 + /// \brief Decrease the priority of an item to the given value.
36.273 + ///
36.274 + /// This function decreases the priority of an item to the given value.
36.275 + /// \param i The item.
36.276 + /// \param p The priority.
36.277 + /// \pre \e i must be stored in the heap with priority at least \e p.
36.278 + void decrease(const Item &i, const Prio &p) {
36.279 + int idx = _iim[i];
36.280 + bubbleUp(idx, Pair(i,p));
36.281 + }
36.282 +
36.283 + /// \brief Increase the priority of an item to the given value.
36.284 + ///
36.285 + /// This function increases the priority of an item to the given value.
36.286 + /// \param i The item.
36.287 + /// \param p The priority.
36.288 + /// \pre \e i must be stored in the heap with priority at most \e p.
36.289 + void increase(const Item &i, const Prio &p) {
36.290 + int idx = _iim[i];
36.291 + bubbleDown(idx, Pair(i,p), _data.size());
36.292 + }
36.293 +
36.294 + /// \brief Return the state of an item.
36.295 + ///
36.296 + /// This method returns \c PRE_HEAP if the given item has never
36.297 + /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
36.298 + /// and \c POST_HEAP otherwise.
36.299 + /// In the latter case it is possible that the item will get back
36.300 + /// to the heap again.
36.301 + /// \param i The item.
36.302 + State state(const Item &i) const {
36.303 + int s = _iim[i];
36.304 + if (s>=0) s=0;
36.305 + return State(s);
36.306 + }
36.307 +
36.308 + /// \brief Set the state of an item in the heap.
36.309 + ///
36.310 + /// This function sets the state of the given item in the heap.
36.311 + /// It can be used to manually clear the heap when it is important
36.312 + /// to achive better time complexity.
36.313 + /// \param i The item.
36.314 + /// \param st The state. It should not be \c IN_HEAP.
36.315 + void state(const Item& i, State st) {
36.316 + switch (st) {
36.317 + case POST_HEAP:
36.318 + case PRE_HEAP:
36.319 + if (state(i) == IN_HEAP) erase(i);
36.320 + _iim[i] = st;
36.321 + break;
36.322 + case IN_HEAP:
36.323 + break;
36.324 + }
36.325 + }
36.326 +
36.327 + /// \brief Replace an item in the heap.
36.328 + ///
36.329 + /// This function replaces item \c i with item \c j.
36.330 + /// Item \c i must be in the heap, while \c j must be out of the heap.
36.331 + /// After calling this method, item \c i will be out of the
36.332 + /// heap and \c j will be in the heap with the same prioriority
36.333 + /// as item \c i had before.
36.334 + void replace(const Item& i, const Item& j) {
36.335 + int idx = _iim[i];
36.336 + _iim.set(i, _iim[j]);
36.337 + _iim.set(j, idx);
36.338 + _data[idx].first = j;
36.339 + }
36.340 +
36.341 + }; // class FouraryHeap
36.342 +
36.343 +} // namespace lemon
36.344 +
36.345 +#endif // LEMON_FOURARY_HEAP_H
37.1 --- a/lemon/full_graph.h Tue Aug 18 10:08:28 2009 +0200
37.2 +++ b/lemon/full_graph.h Thu Nov 05 08:39:49 2009 +0100
37.3 @@ -24,7 +24,7 @@
37.4
37.5 ///\ingroup graphs
37.6 ///\file
37.7 -///\brief FullGraph and FullDigraph classes.
37.8 +///\brief FullDigraph and FullGraph classes.
37.9
37.10 namespace lemon {
37.11
37.12 @@ -148,24 +148,26 @@
37.13
37.14 /// \ingroup graphs
37.15 ///
37.16 - /// \brief A full digraph class.
37.17 + /// \brief A directed full graph class.
37.18 ///
37.19 - /// This is a simple and fast directed full graph implementation.
37.20 - /// From each node go arcs to each node (including the source node),
37.21 - /// therefore the number of the arcs in the digraph is the square of
37.22 - /// the node number. This digraph type is completely static, so you
37.23 - /// can neither add nor delete either arcs or nodes, and it needs
37.24 - /// constant space in memory.
37.25 + /// FullDigraph is a simple and fast implmenetation of directed full
37.26 + /// (complete) graphs. It contains an arc from each node to each node
37.27 + /// (including a loop for each node), therefore the number of arcs
37.28 + /// is the square of the number of nodes.
37.29 + /// This class is completely static and it needs constant memory space.
37.30 + /// Thus you can neither add nor delete nodes or arcs, however
37.31 + /// the structure can be resized using resize().
37.32 ///
37.33 - /// This class fully conforms to the \ref concepts::Digraph
37.34 - /// "Digraph concept".
37.35 + /// This type fully conforms to the \ref concepts::Digraph "Digraph concept".
37.36 + /// Most of its member functions and nested classes are documented
37.37 + /// only in the concept class.
37.38 ///
37.39 - /// The \c FullDigraph and \c FullGraph classes are very similar,
37.40 + /// \note FullDigraph and FullGraph classes are very similar,
37.41 /// but there are two differences. While this class conforms only
37.42 - /// to the \ref concepts::Digraph "Digraph" concept, the \c FullGraph
37.43 - /// class conforms to the \ref concepts::Graph "Graph" concept,
37.44 - /// moreover \c FullGraph does not contain a loop arc for each
37.45 - /// node as \c FullDigraph does.
37.46 + /// to the \ref concepts::Digraph "Digraph" concept, FullGraph
37.47 + /// conforms to the \ref concepts::Graph "Graph" concept,
37.48 + /// moreover FullGraph does not contain a loop for each
37.49 + /// node as this class does.
37.50 ///
37.51 /// \sa FullGraph
37.52 class FullDigraph : public ExtendedFullDigraphBase {
37.53 @@ -173,7 +175,9 @@
37.54
37.55 public:
37.56
37.57 - /// \brief Constructor
37.58 + /// \brief Default constructor.
37.59 + ///
37.60 + /// Default constructor. The number of nodes and arcs will be zero.
37.61 FullDigraph() { construct(0); }
37.62
37.63 /// \brief Constructor
37.64 @@ -184,8 +188,8 @@
37.65
37.66 /// \brief Resizes the digraph
37.67 ///
37.68 - /// Resizes the digraph. The function will fully destroy and
37.69 - /// rebuild the digraph. This cause that the maps of the digraph will
37.70 + /// This function resizes the digraph. It fully destroys and
37.71 + /// rebuilds the structure, therefore the maps of the digraph will be
37.72 /// reallocated automatically and the previous values will be lost.
37.73 void resize(int n) {
37.74 Parent::notifier(Arc()).clear();
37.75 @@ -197,24 +201,24 @@
37.76
37.77 /// \brief Returns the node with the given index.
37.78 ///
37.79 - /// Returns the node with the given index. Since it is a static
37.80 - /// digraph its nodes can be indexed with integers from the range
37.81 - /// <tt>[0..nodeNum()-1]</tt>.
37.82 + /// Returns the node with the given index. Since this structure is
37.83 + /// completely static, the nodes can be indexed with integers from
37.84 + /// the range <tt>[0..nodeNum()-1]</tt>.
37.85 /// \sa index()
37.86 Node operator()(int ix) const { return Parent::operator()(ix); }
37.87
37.88 /// \brief Returns the index of the given node.
37.89 ///
37.90 - /// Returns the index of the given node. Since it is a static
37.91 - /// digraph its nodes can be indexed with integers from the range
37.92 - /// <tt>[0..nodeNum()-1]</tt>.
37.93 - /// \sa operator()
37.94 - int index(const Node& node) const { return Parent::index(node); }
37.95 + /// Returns the index of the given node. Since this structure is
37.96 + /// completely static, the nodes can be indexed with integers from
37.97 + /// the range <tt>[0..nodeNum()-1]</tt>.
37.98 + /// \sa operator()()
37.99 + int index(Node node) const { return Parent::index(node); }
37.100
37.101 /// \brief Returns the arc connecting the given nodes.
37.102 ///
37.103 /// Returns the arc connecting the given nodes.
37.104 - Arc arc(const Node& u, const Node& v) const {
37.105 + Arc arc(Node u, Node v) const {
37.106 return Parent::arc(u, v);
37.107 }
37.108
37.109 @@ -520,21 +524,23 @@
37.110 ///
37.111 /// \brief An undirected full graph class.
37.112 ///
37.113 - /// This is a simple and fast undirected full graph
37.114 - /// implementation. From each node go edge to each other node,
37.115 - /// therefore the number of edges in the graph is \f$n(n-1)/2\f$.
37.116 - /// This graph type is completely static, so you can neither
37.117 - /// add nor delete either edges or nodes, and it needs constant
37.118 - /// space in memory.
37.119 + /// FullGraph is a simple and fast implmenetation of undirected full
37.120 + /// (complete) graphs. It contains an edge between every distinct pair
37.121 + /// of nodes, therefore the number of edges is <tt>n(n-1)/2</tt>.
37.122 + /// This class is completely static and it needs constant memory space.
37.123 + /// Thus you can neither add nor delete nodes or edges, however
37.124 + /// the structure can be resized using resize().
37.125 ///
37.126 - /// This class fully conforms to the \ref concepts::Graph "Graph concept".
37.127 + /// This type fully conforms to the \ref concepts::Graph "Graph concept".
37.128 + /// Most of its member functions and nested classes are documented
37.129 + /// only in the concept class.
37.130 ///
37.131 - /// The \c FullGraph and \c FullDigraph classes are very similar,
37.132 - /// but there are two differences. While the \c FullDigraph class
37.133 + /// \note FullDigraph and FullGraph classes are very similar,
37.134 + /// but there are two differences. While FullDigraph
37.135 /// conforms only to the \ref concepts::Digraph "Digraph" concept,
37.136 /// this class conforms to the \ref concepts::Graph "Graph" concept,
37.137 - /// moreover \c FullGraph does not contain a loop arc for each
37.138 - /// node as \c FullDigraph does.
37.139 + /// moreover this class does not contain a loop for each
37.140 + /// node as FullDigraph does.
37.141 ///
37.142 /// \sa FullDigraph
37.143 class FullGraph : public ExtendedFullGraphBase {
37.144 @@ -542,7 +548,9 @@
37.145
37.146 public:
37.147
37.148 - /// \brief Constructor
37.149 + /// \brief Default constructor.
37.150 + ///
37.151 + /// Default constructor. The number of nodes and edges will be zero.
37.152 FullGraph() { construct(0); }
37.153
37.154 /// \brief Constructor
37.155 @@ -553,8 +561,8 @@
37.156
37.157 /// \brief Resizes the graph
37.158 ///
37.159 - /// Resizes the graph. The function will fully destroy and
37.160 - /// rebuild the graph. This cause that the maps of the graph will
37.161 + /// This function resizes the graph. It fully destroys and
37.162 + /// rebuilds the structure, therefore the maps of the graph will be
37.163 /// reallocated automatically and the previous values will be lost.
37.164 void resize(int n) {
37.165 Parent::notifier(Arc()).clear();
37.166 @@ -568,31 +576,31 @@
37.167
37.168 /// \brief Returns the node with the given index.
37.169 ///
37.170 - /// Returns the node with the given index. Since it is a static
37.171 - /// graph its nodes can be indexed with integers from the range
37.172 - /// <tt>[0..nodeNum()-1]</tt>.
37.173 + /// Returns the node with the given index. Since this structure is
37.174 + /// completely static, the nodes can be indexed with integers from
37.175 + /// the range <tt>[0..nodeNum()-1]</tt>.
37.176 /// \sa index()
37.177 Node operator()(int ix) const { return Parent::operator()(ix); }
37.178
37.179 /// \brief Returns the index of the given node.
37.180 ///
37.181 - /// Returns the index of the given node. Since it is a static
37.182 - /// graph its nodes can be indexed with integers from the range
37.183 - /// <tt>[0..nodeNum()-1]</tt>.
37.184 - /// \sa operator()
37.185 - int index(const Node& node) const { return Parent::index(node); }
37.186 + /// Returns the index of the given node. Since this structure is
37.187 + /// completely static, the nodes can be indexed with integers from
37.188 + /// the range <tt>[0..nodeNum()-1]</tt>.
37.189 + /// \sa operator()()
37.190 + int index(Node node) const { return Parent::index(node); }
37.191
37.192 /// \brief Returns the arc connecting the given nodes.
37.193 ///
37.194 /// Returns the arc connecting the given nodes.
37.195 - Arc arc(const Node& s, const Node& t) const {
37.196 + Arc arc(Node s, Node t) const {
37.197 return Parent::arc(s, t);
37.198 }
37.199
37.200 - /// \brief Returns the edge connects the given nodes.
37.201 + /// \brief Returns the edge connecting the given nodes.
37.202 ///
37.203 - /// Returns the edge connects the given nodes.
37.204 - Edge edge(const Node& u, const Node& v) const {
37.205 + /// Returns the edge connecting the given nodes.
37.206 + Edge edge(Node u, Node v) const {
37.207 return Parent::edge(u, v);
37.208 }
37.209
38.1 --- a/lemon/glpk.cc Tue Aug 18 10:08:28 2009 +0200
38.2 +++ b/lemon/glpk.cc Thu Nov 05 08:39:49 2009 +0100
38.3 @@ -59,6 +59,42 @@
38.4 return i;
38.5 }
38.6
38.7 + int GlpkBase::_addRow(Value lo, ExprIterator b,
38.8 + ExprIterator e, Value up) {
38.9 + int i = glp_add_rows(lp, 1);
38.10 +
38.11 + if (lo == -INF) {
38.12 + if (up == INF) {
38.13 + glp_set_row_bnds(lp, i, GLP_FR, lo, up);
38.14 + } else {
38.15 + glp_set_row_bnds(lp, i, GLP_UP, lo, up);
38.16 + }
38.17 + } else {
38.18 + if (up == INF) {
38.19 + glp_set_row_bnds(lp, i, GLP_LO, lo, up);
38.20 + } else if (lo != up) {
38.21 + glp_set_row_bnds(lp, i, GLP_DB, lo, up);
38.22 + } else {
38.23 + glp_set_row_bnds(lp, i, GLP_FX, lo, up);
38.24 + }
38.25 + }
38.26 +
38.27 + std::vector<int> indexes;
38.28 + std::vector<Value> values;
38.29 +
38.30 + indexes.push_back(0);
38.31 + values.push_back(0);
38.32 +
38.33 + for(ExprIterator it = b; it != e; ++it) {
38.34 + indexes.push_back(it->first);
38.35 + values.push_back(it->second);
38.36 + }
38.37 +
38.38 + glp_set_mat_row(lp, i, values.size() - 1,
38.39 + &indexes.front(), &values.front());
38.40 + return i;
38.41 + }
38.42 +
38.43 void GlpkBase::_eraseCol(int i) {
38.44 int ca[2];
38.45 ca[1] = i;
39.1 --- a/lemon/glpk.h Tue Aug 18 10:08:28 2009 +0200
39.2 +++ b/lemon/glpk.h Thu Nov 05 08:39:49 2009 +0100
39.3 @@ -54,6 +54,7 @@
39.4
39.5 virtual int _addCol();
39.6 virtual int _addRow();
39.7 + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
39.8
39.9 virtual void _eraseCol(int i);
39.10 virtual void _eraseRow(int i);
40.1 --- a/lemon/gomory_hu.h Tue Aug 18 10:08:28 2009 +0200
40.2 +++ b/lemon/gomory_hu.h Thu Nov 05 08:39:49 2009 +0100
40.3 @@ -359,10 +359,10 @@
40.4 /// This example counts the nodes in the minimum cut separating \c s from
40.5 /// \c t.
40.6 /// \code
40.7 - /// GomoruHu<Graph> gom(g, capacities);
40.8 + /// GomoryHu<Graph> gom(g, capacities);
40.9 /// gom.run();
40.10 /// int cnt=0;
40.11 - /// for(GomoruHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt;
40.12 + /// for(GomoryHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt;
40.13 /// \endcode
40.14 class MinCutNodeIt
40.15 {
40.16 @@ -456,10 +456,10 @@
40.17 /// This example computes the value of the minimum cut separating \c s from
40.18 /// \c t.
40.19 /// \code
40.20 - /// GomoruHu<Graph> gom(g, capacities);
40.21 + /// GomoryHu<Graph> gom(g, capacities);
40.22 /// gom.run();
40.23 /// int value=0;
40.24 - /// for(GomoruHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e)
40.25 + /// for(GomoryHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e)
40.26 /// value+=capacities[e];
40.27 /// \endcode
40.28 /// The result will be the same as the value returned by
41.1 --- a/lemon/grid_graph.h Tue Aug 18 10:08:28 2009 +0200
41.2 +++ b/lemon/grid_graph.h Thu Nov 05 08:39:49 2009 +0100
41.3 @@ -470,18 +470,22 @@
41.4 ///
41.5 /// \brief Grid graph class
41.6 ///
41.7 - /// This class implements a special graph type. The nodes of the
41.8 - /// graph can be indexed by two integer \c (i,j) value where \c i is
41.9 - /// in the \c [0..width()-1] range and j is in the \c
41.10 - /// [0..height()-1] range. Two nodes are connected in the graph if
41.11 - /// the indexes differ exactly on one position and exactly one is
41.12 - /// the difference. The nodes of the graph can be indexed by position
41.13 - /// with the \c operator()() function. The positions of the nodes can be
41.14 - /// get with \c pos(), \c col() and \c row() members. The outgoing
41.15 + /// GridGraph implements a special graph type. The nodes of the
41.16 + /// graph can be indexed by two integer values \c (i,j) where \c i is
41.17 + /// in the range <tt>[0..width()-1]</tt> and j is in the range
41.18 + /// <tt>[0..height()-1]</tt>. Two nodes are connected in the graph if
41.19 + /// the indices differ exactly on one position and the difference is
41.20 + /// also exactly one. The nodes of the graph can be obtained by position
41.21 + /// using the \c operator()() function and the indices of the nodes can
41.22 + /// be obtained using \c pos(), \c col() and \c row() members. The outgoing
41.23 /// arcs can be retrieved with the \c right(), \c up(), \c left()
41.24 /// and \c down() functions, where the bottom-left corner is the
41.25 /// origin.
41.26 ///
41.27 + /// This class is completely static and it needs constant memory space.
41.28 + /// Thus you can neither add nor delete nodes or edges, however
41.29 + /// the structure can be resized using resize().
41.30 + ///
41.31 /// \image html grid_graph.png
41.32 /// \image latex grid_graph.eps "Grid graph" width=\textwidth
41.33 ///
41.34 @@ -496,16 +500,19 @@
41.35 /// }
41.36 ///\endcode
41.37 ///
41.38 - /// This graph type fully conforms to the \ref concepts::Graph
41.39 - /// "Graph concept".
41.40 + /// This type fully conforms to the \ref concepts::Graph "Graph concept".
41.41 + /// Most of its member functions and nested classes are documented
41.42 + /// only in the concept class.
41.43 class GridGraph : public ExtendedGridGraphBase {
41.44 typedef ExtendedGridGraphBase Parent;
41.45
41.46 public:
41.47
41.48 - /// \brief Map to get the indices of the nodes as dim2::Point<int>.
41.49 + /// \brief Map to get the indices of the nodes as \ref dim2::Point
41.50 + /// "dim2::Point<int>".
41.51 ///
41.52 - /// Map to get the indices of the nodes as dim2::Point<int>.
41.53 + /// Map to get the indices of the nodes as \ref dim2::Point
41.54 + /// "dim2::Point<int>".
41.55 class IndexMap {
41.56 public:
41.57 /// \brief The key type of the map
41.58 @@ -514,13 +521,9 @@
41.59 typedef dim2::Point<int> Value;
41.60
41.61 /// \brief Constructor
41.62 - ///
41.63 - /// Constructor
41.64 IndexMap(const GridGraph& graph) : _graph(graph) {}
41.65
41.66 /// \brief The subscript operator
41.67 - ///
41.68 - /// The subscript operator.
41.69 Value operator[](Key key) const {
41.70 return _graph.pos(key);
41.71 }
41.72 @@ -540,13 +543,9 @@
41.73 typedef int Value;
41.74
41.75 /// \brief Constructor
41.76 - ///
41.77 - /// Constructor
41.78 ColMap(const GridGraph& graph) : _graph(graph) {}
41.79
41.80 /// \brief The subscript operator
41.81 - ///
41.82 - /// The subscript operator.
41.83 Value operator[](Key key) const {
41.84 return _graph.col(key);
41.85 }
41.86 @@ -566,13 +565,9 @@
41.87 typedef int Value;
41.88
41.89 /// \brief Constructor
41.90 - ///
41.91 - /// Constructor
41.92 RowMap(const GridGraph& graph) : _graph(graph) {}
41.93
41.94 /// \brief The subscript operator
41.95 - ///
41.96 - /// The subscript operator.
41.97 Value operator[](Key key) const {
41.98 return _graph.row(key);
41.99 }
41.100 @@ -583,15 +578,14 @@
41.101
41.102 /// \brief Constructor
41.103 ///
41.104 - /// Construct a grid graph with given size.
41.105 + /// Construct a grid graph with the given size.
41.106 GridGraph(int width, int height) { construct(width, height); }
41.107
41.108 - /// \brief Resize the graph
41.109 + /// \brief Resizes the graph
41.110 ///
41.111 - /// Resize the graph. The function will fully destroy and rebuild
41.112 - /// the graph. This cause that the maps of the graph will
41.113 - /// reallocated automatically and the previous values will be
41.114 - /// lost.
41.115 + /// This function resizes the graph. It fully destroys and
41.116 + /// rebuilds the structure, therefore the maps of the graph will be
41.117 + /// reallocated automatically and the previous values will be lost.
41.118 void resize(int width, int height) {
41.119 Parent::notifier(Arc()).clear();
41.120 Parent::notifier(Edge()).clear();
41.121 @@ -609,42 +603,42 @@
41.122 return Parent::operator()(i, j);
41.123 }
41.124
41.125 - /// \brief Gives back the column index of the node.
41.126 + /// \brief The column index of the node.
41.127 ///
41.128 /// Gives back the column index of the node.
41.129 int col(Node n) const {
41.130 return Parent::col(n);
41.131 }
41.132
41.133 - /// \brief Gives back the row index of the node.
41.134 + /// \brief The row index of the node.
41.135 ///
41.136 /// Gives back the row index of the node.
41.137 int row(Node n) const {
41.138 return Parent::row(n);
41.139 }
41.140
41.141 - /// \brief Gives back the position of the node.
41.142 + /// \brief The position of the node.
41.143 ///
41.144 /// Gives back the position of the node, ie. the <tt>(col,row)</tt> pair.
41.145 dim2::Point<int> pos(Node n) const {
41.146 return Parent::pos(n);
41.147 }
41.148
41.149 - /// \brief Gives back the number of the columns.
41.150 + /// \brief The number of the columns.
41.151 ///
41.152 /// Gives back the number of the columns.
41.153 int width() const {
41.154 return Parent::width();
41.155 }
41.156
41.157 - /// \brief Gives back the number of the rows.
41.158 + /// \brief The number of the rows.
41.159 ///
41.160 /// Gives back the number of the rows.
41.161 int height() const {
41.162 return Parent::height();
41.163 }
41.164
41.165 - /// \brief Gives back the arc goes right from the node.
41.166 + /// \brief The arc goes right from the node.
41.167 ///
41.168 /// Gives back the arc goes right from the node. If there is not
41.169 /// outgoing arc then it gives back INVALID.
41.170 @@ -652,7 +646,7 @@
41.171 return Parent::right(n);
41.172 }
41.173
41.174 - /// \brief Gives back the arc goes left from the node.
41.175 + /// \brief The arc goes left from the node.
41.176 ///
41.177 /// Gives back the arc goes left from the node. If there is not
41.178 /// outgoing arc then it gives back INVALID.
41.179 @@ -660,7 +654,7 @@
41.180 return Parent::left(n);
41.181 }
41.182
41.183 - /// \brief Gives back the arc goes up from the node.
41.184 + /// \brief The arc goes up from the node.
41.185 ///
41.186 /// Gives back the arc goes up from the node. If there is not
41.187 /// outgoing arc then it gives back INVALID.
41.188 @@ -668,7 +662,7 @@
41.189 return Parent::up(n);
41.190 }
41.191
41.192 - /// \brief Gives back the arc goes down from the node.
41.193 + /// \brief The arc goes down from the node.
41.194 ///
41.195 /// Gives back the arc goes down from the node. If there is not
41.196 /// outgoing arc then it gives back INVALID.
42.1 --- a/lemon/hypercube_graph.h Tue Aug 18 10:08:28 2009 +0200
42.2 +++ b/lemon/hypercube_graph.h Thu Nov 05 08:39:49 2009 +0100
42.3 @@ -282,17 +282,21 @@
42.4 ///
42.5 /// \brief Hypercube graph class
42.6 ///
42.7 - /// This class implements a special graph type. The nodes of the graph
42.8 - /// are indiced with integers with at most \c dim binary digits.
42.9 + /// HypercubeGraph implements a special graph type. The nodes of the
42.10 + /// graph are indexed with integers having at most \c dim binary digits.
42.11 /// Two nodes are connected in the graph if and only if their indices
42.12 /// differ only on one position in the binary form.
42.13 + /// This class is completely static and it needs constant memory space.
42.14 + /// Thus you can neither add nor delete nodes or edges, however
42.15 + /// the structure can be resized using resize().
42.16 + ///
42.17 + /// This type fully conforms to the \ref concepts::Graph "Graph concept".
42.18 + /// Most of its member functions and nested classes are documented
42.19 + /// only in the concept class.
42.20 ///
42.21 /// \note The type of the indices is chosen to \c int for efficiency
42.22 /// reasons. Thus the maximum dimension of this implementation is 26
42.23 /// (assuming that the size of \c int is 32 bit).
42.24 - ///
42.25 - /// This graph type fully conforms to the \ref concepts::Graph
42.26 - /// "Graph concept".
42.27 class HypercubeGraph : public ExtendedHypercubeGraphBase {
42.28 typedef ExtendedHypercubeGraphBase Parent;
42.29
42.30 @@ -303,6 +307,21 @@
42.31 /// Constructs a hypercube graph with \c dim dimensions.
42.32 HypercubeGraph(int dim) { construct(dim); }
42.33
42.34 + /// \brief Resizes the graph
42.35 + ///
42.36 + /// This function resizes the graph. It fully destroys and
42.37 + /// rebuilds the structure, therefore the maps of the graph will be
42.38 + /// reallocated automatically and the previous values will be lost.
42.39 + void resize(int dim) {
42.40 + Parent::notifier(Arc()).clear();
42.41 + Parent::notifier(Edge()).clear();
42.42 + Parent::notifier(Node()).clear();
42.43 + construct(dim);
42.44 + Parent::notifier(Node()).build();
42.45 + Parent::notifier(Edge()).build();
42.46 + Parent::notifier(Arc()).build();
42.47 + }
42.48 +
42.49 /// \brief The number of dimensions.
42.50 ///
42.51 /// Gives back the number of dimensions.
42.52 @@ -320,7 +339,7 @@
42.53 /// \brief The dimension id of an edge.
42.54 ///
42.55 /// Gives back the dimension id of the given edge.
42.56 - /// It is in the [0..dim-1] range.
42.57 + /// It is in the range <tt>[0..dim-1]</tt>.
42.58 int dimension(Edge edge) const {
42.59 return Parent::dimension(edge);
42.60 }
42.61 @@ -328,7 +347,7 @@
42.62 /// \brief The dimension id of an arc.
42.63 ///
42.64 /// Gives back the dimension id of the given arc.
42.65 - /// It is in the [0..dim-1] range.
42.66 + /// It is in the range <tt>[0..dim-1]</tt>.
42.67 int dimension(Arc arc) const {
42.68 return Parent::dimension(arc);
42.69 }
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
43.2 +++ b/lemon/kary_heap.h Thu Nov 05 08:39:49 2009 +0100
43.3 @@ -0,0 +1,352 @@
43.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
43.5 + *
43.6 + * This file is a part of LEMON, a generic C++ optimization library.
43.7 + *
43.8 + * Copyright (C) 2003-2009
43.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
43.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
43.11 + *
43.12 + * Permission to use, modify and distribute this software is granted
43.13 + * provided that this copyright notice appears in all copies. For
43.14 + * precise terms see the accompanying LICENSE file.
43.15 + *
43.16 + * This software is provided "AS IS" with no warranty of any kind,
43.17 + * express or implied, and with no claim as to its suitability for any
43.18 + * purpose.
43.19 + *
43.20 + */
43.21 +
43.22 +#ifndef LEMON_KARY_HEAP_H
43.23 +#define LEMON_KARY_HEAP_H
43.24 +
43.25 +///\ingroup heaps
43.26 +///\file
43.27 +///\brief Fourary heap implementation.
43.28 +
43.29 +#include <vector>
43.30 +#include <utility>
43.31 +#include <functional>
43.32 +
43.33 +namespace lemon {
43.34 +
43.35 + /// \ingroup heaps
43.36 + ///
43.37 + ///\brief K-ary heap data structure.
43.38 + ///
43.39 + /// This class implements the \e K-ary \e heap data structure.
43.40 + /// It fully conforms to the \ref concepts::Heap "heap concept".
43.41 + ///
43.42 + /// The \ref KaryHeap "K-ary heap" is a generalization of the
43.43 + /// \ref BinHeap "binary heap" structure, its nodes have at most
43.44 + /// \c K children, instead of two.
43.45 + /// \ref BinHeap and \ref FouraryHeap are specialized implementations
43.46 + /// of this structure for <tt>K=2</tt> and <tt>K=4</tt>, respectively.
43.47 + ///
43.48 + /// \tparam PR Type of the priorities of the items.
43.49 + /// \tparam IM A read-writable item map with \c int values, used
43.50 + /// internally to handle the cross references.
43.51 + /// \tparam K The degree of the heap, each node have at most \e K
43.52 + /// children. The default is 16. Powers of two are suggested to use
43.53 + /// so that the multiplications and divisions needed to traverse the
43.54 + /// nodes of the heap could be performed faster.
43.55 + /// \tparam CMP A functor class for comparing the priorities.
43.56 + /// The default is \c std::less<PR>.
43.57 + ///
43.58 + ///\sa BinHeap
43.59 + ///\sa FouraryHeap
43.60 +#ifdef DOXYGEN
43.61 + template <typename PR, typename IM, int K, typename CMP>
43.62 +#else
43.63 + template <typename PR, typename IM, int K = 16,
43.64 + typename CMP = std::less<PR> >
43.65 +#endif
43.66 + class KaryHeap {
43.67 + public:
43.68 + /// Type of the item-int map.
43.69 + typedef IM ItemIntMap;
43.70 + /// Type of the priorities.
43.71 + typedef PR Prio;
43.72 + /// Type of the items stored in the heap.
43.73 + typedef typename ItemIntMap::Key Item;
43.74 + /// Type of the item-priority pairs.
43.75 + typedef std::pair<Item,Prio> Pair;
43.76 + /// Functor type for comparing the priorities.
43.77 + typedef CMP Compare;
43.78 +
43.79 + /// \brief Type to represent the states of the items.
43.80 + ///
43.81 + /// Each item has a state associated to it. It can be "in heap",
43.82 + /// "pre-heap" or "post-heap". The latter two are indifferent from the
43.83 + /// heap's point of view, but may be useful to the user.
43.84 + ///
43.85 + /// The item-int map must be initialized in such way that it assigns
43.86 + /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
43.87 + enum State {
43.88 + IN_HEAP = 0, ///< = 0.
43.89 + PRE_HEAP = -1, ///< = -1.
43.90 + POST_HEAP = -2 ///< = -2.
43.91 + };
43.92 +
43.93 + private:
43.94 + std::vector<Pair> _data;
43.95 + Compare _comp;
43.96 + ItemIntMap &_iim;
43.97 +
43.98 + public:
43.99 + /// \brief Constructor.
43.100 + ///
43.101 + /// Constructor.
43.102 + /// \param map A map that assigns \c int values to the items.
43.103 + /// It is used internally to handle the cross references.
43.104 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
43.105 + explicit KaryHeap(ItemIntMap &map) : _iim(map) {}
43.106 +
43.107 + /// \brief Constructor.
43.108 + ///
43.109 + /// Constructor.
43.110 + /// \param map A map that assigns \c int values to the items.
43.111 + /// It is used internally to handle the cross references.
43.112 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
43.113 + /// \param comp The function object used for comparing the priorities.
43.114 + KaryHeap(ItemIntMap &map, const Compare &comp)
43.115 + : _iim(map), _comp(comp) {}
43.116 +
43.117 + /// \brief The number of items stored in the heap.
43.118 + ///
43.119 + /// This function returns the number of items stored in the heap.
43.120 + int size() const { return _data.size(); }
43.121 +
43.122 + /// \brief Check if the heap is empty.
43.123 + ///
43.124 + /// This function returns \c true if the heap is empty.
43.125 + bool empty() const { return _data.empty(); }
43.126 +
43.127 + /// \brief Make the heap empty.
43.128 + ///
43.129 + /// This functon makes the heap empty.
43.130 + /// It does not change the cross reference map. If you want to reuse
43.131 + /// a heap that is not surely empty, you should first clear it and
43.132 + /// then you should set the cross reference map to \c PRE_HEAP
43.133 + /// for each item.
43.134 + void clear() { _data.clear(); }
43.135 +
43.136 + private:
43.137 + int parent(int i) { return (i-1)/K; }
43.138 + int firstChild(int i) { return K*i+1; }
43.139 +
43.140 + bool less(const Pair &p1, const Pair &p2) const {
43.141 + return _comp(p1.second, p2.second);
43.142 + }
43.143 +
43.144 + void bubbleUp(int hole, Pair p) {
43.145 + int par = parent(hole);
43.146 + while( hole>0 && less(p,_data[par]) ) {
43.147 + move(_data[par],hole);
43.148 + hole = par;
43.149 + par = parent(hole);
43.150 + }
43.151 + move(p, hole);
43.152 + }
43.153 +
43.154 + void bubbleDown(int hole, Pair p, int length) {
43.155 + if( length>1 ) {
43.156 + int child = firstChild(hole);
43.157 + while( child+K<=length ) {
43.158 + int min=child;
43.159 + for (int i=1; i<K; ++i) {
43.160 + if( less(_data[child+i], _data[min]) )
43.161 + min=child+i;
43.162 + }
43.163 + if( !less(_data[min], p) )
43.164 + goto ok;
43.165 + move(_data[min], hole);
43.166 + hole = min;
43.167 + child = firstChild(hole);
43.168 + }
43.169 + if ( child<length ) {
43.170 + int min = child;
43.171 + while (++child < length) {
43.172 + if( less(_data[child], _data[min]) )
43.173 + min=child;
43.174 + }
43.175 + if( less(_data[min], p) ) {
43.176 + move(_data[min], hole);
43.177 + hole = min;
43.178 + }
43.179 + }
43.180 + }
43.181 + ok:
43.182 + move(p, hole);
43.183 + }
43.184 +
43.185 + void move(const Pair &p, int i) {
43.186 + _data[i] = p;
43.187 + _iim.set(p.first, i);
43.188 + }
43.189 +
43.190 + public:
43.191 + /// \brief Insert a pair of item and priority into the heap.
43.192 + ///
43.193 + /// This function inserts \c p.first to the heap with priority
43.194 + /// \c p.second.
43.195 + /// \param p The pair to insert.
43.196 + /// \pre \c p.first must not be stored in the heap.
43.197 + void push(const Pair &p) {
43.198 + int n = _data.size();
43.199 + _data.resize(n+1);
43.200 + bubbleUp(n, p);
43.201 + }
43.202 +
43.203 + /// \brief Insert an item into the heap with the given priority.
43.204 + ///
43.205 + /// This function inserts the given item into the heap with the
43.206 + /// given priority.
43.207 + /// \param i The item to insert.
43.208 + /// \param p The priority of the item.
43.209 + /// \pre \e i must not be stored in the heap.
43.210 + void push(const Item &i, const Prio &p) { push(Pair(i,p)); }
43.211 +
43.212 + /// \brief Return the item having minimum priority.
43.213 + ///
43.214 + /// This function returns the item having minimum priority.
43.215 + /// \pre The heap must be non-empty.
43.216 + Item top() const { return _data[0].first; }
43.217 +
43.218 + /// \brief The minimum priority.
43.219 + ///
43.220 + /// This function returns the minimum priority.
43.221 + /// \pre The heap must be non-empty.
43.222 + Prio prio() const { return _data[0].second; }
43.223 +
43.224 + /// \brief Remove the item having minimum priority.
43.225 + ///
43.226 + /// This function removes the item having minimum priority.
43.227 + /// \pre The heap must be non-empty.
43.228 + void pop() {
43.229 + int n = _data.size()-1;
43.230 + _iim.set(_data[0].first, POST_HEAP);
43.231 + if (n>0) bubbleDown(0, _data[n], n);
43.232 + _data.pop_back();
43.233 + }
43.234 +
43.235 + /// \brief Remove the given item from the heap.
43.236 + ///
43.237 + /// This function removes the given item from the heap if it is
43.238 + /// already stored.
43.239 + /// \param i The item to delete.
43.240 + /// \pre \e i must be in the heap.
43.241 + void erase(const Item &i) {
43.242 + int h = _iim[i];
43.243 + int n = _data.size()-1;
43.244 + _iim.set(_data[h].first, POST_HEAP);
43.245 + if( h<n ) {
43.246 + if( less(_data[parent(h)], _data[n]) )
43.247 + bubbleDown(h, _data[n], n);
43.248 + else
43.249 + bubbleUp(h, _data[n]);
43.250 + }
43.251 + _data.pop_back();
43.252 + }
43.253 +
43.254 + /// \brief The priority of the given item.
43.255 + ///
43.256 + /// This function returns the priority of the given item.
43.257 + /// \param i The item.
43.258 + /// \pre \e i must be in the heap.
43.259 + Prio operator[](const Item &i) const {
43.260 + int idx = _iim[i];
43.261 + return _data[idx].second;
43.262 + }
43.263 +
43.264 + /// \brief Set the priority of an item or insert it, if it is
43.265 + /// not stored in the heap.
43.266 + ///
43.267 + /// This method sets the priority of the given item if it is
43.268 + /// already stored in the heap. Otherwise it inserts the given
43.269 + /// item into the heap with the given priority.
43.270 + /// \param i The item.
43.271 + /// \param p The priority.
43.272 + void set(const Item &i, const Prio &p) {
43.273 + int idx = _iim[i];
43.274 + if( idx<0 )
43.275 + push(i,p);
43.276 + else if( _comp(p, _data[idx].second) )
43.277 + bubbleUp(idx, Pair(i,p));
43.278 + else
43.279 + bubbleDown(idx, Pair(i,p), _data.size());
43.280 + }
43.281 +
43.282 + /// \brief Decrease the priority of an item to the given value.
43.283 + ///
43.284 + /// This function decreases the priority of an item to the given value.
43.285 + /// \param i The item.
43.286 + /// \param p The priority.
43.287 + /// \pre \e i must be stored in the heap with priority at least \e p.
43.288 + void decrease(const Item &i, const Prio &p) {
43.289 + int idx = _iim[i];
43.290 + bubbleUp(idx, Pair(i,p));
43.291 + }
43.292 +
43.293 + /// \brief Increase the priority of an item to the given value.
43.294 + ///
43.295 + /// This function increases the priority of an item to the given value.
43.296 + /// \param i The item.
43.297 + /// \param p The priority.
43.298 + /// \pre \e i must be stored in the heap with priority at most \e p.
43.299 + void increase(const Item &i, const Prio &p) {
43.300 + int idx = _iim[i];
43.301 + bubbleDown(idx, Pair(i,p), _data.size());
43.302 + }
43.303 +
43.304 + /// \brief Return the state of an item.
43.305 + ///
43.306 + /// This method returns \c PRE_HEAP if the given item has never
43.307 + /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
43.308 + /// and \c POST_HEAP otherwise.
43.309 + /// In the latter case it is possible that the item will get back
43.310 + /// to the heap again.
43.311 + /// \param i The item.
43.312 + State state(const Item &i) const {
43.313 + int s = _iim[i];
43.314 + if (s>=0) s=0;
43.315 + return State(s);
43.316 + }
43.317 +
43.318 + /// \brief Set the state of an item in the heap.
43.319 + ///
43.320 + /// This function sets the state of the given item in the heap.
43.321 + /// It can be used to manually clear the heap when it is important
43.322 + /// to achive better time complexity.
43.323 + /// \param i The item.
43.324 + /// \param st The state. It should not be \c IN_HEAP.
43.325 + void state(const Item& i, State st) {
43.326 + switch (st) {
43.327 + case POST_HEAP:
43.328 + case PRE_HEAP:
43.329 + if (state(i) == IN_HEAP) erase(i);
43.330 + _iim[i] = st;
43.331 + break;
43.332 + case IN_HEAP:
43.333 + break;
43.334 + }
43.335 + }
43.336 +
43.337 + /// \brief Replace an item in the heap.
43.338 + ///
43.339 + /// This function replaces item \c i with item \c j.
43.340 + /// Item \c i must be in the heap, while \c j must be out of the heap.
43.341 + /// After calling this method, item \c i will be out of the
43.342 + /// heap and \c j will be in the heap with the same prioriority
43.343 + /// as item \c i had before.
43.344 + void replace(const Item& i, const Item& j) {
43.345 + int idx=_iim[i];
43.346 + _iim.set(i, _iim[j]);
43.347 + _iim.set(j, idx);
43.348 + _data[idx].first=j;
43.349 + }
43.350 +
43.351 + }; // class KaryHeap
43.352 +
43.353 +} // namespace lemon
43.354 +
43.355 +#endif // LEMON_KARY_HEAP_H
44.1 --- a/lemon/list_graph.h Tue Aug 18 10:08:28 2009 +0200
44.2 +++ b/lemon/list_graph.h Thu Nov 05 08:39:49 2009 +0100
44.3 @@ -21,7 +21,7 @@
44.4
44.5 ///\ingroup graphs
44.6 ///\file
44.7 -///\brief ListDigraph, ListGraph classes.
44.8 +///\brief ListDigraph and ListGraph classes.
44.9
44.10 #include <lemon/core.h>
44.11 #include <lemon/error.h>
44.12 @@ -32,6 +32,8 @@
44.13
44.14 namespace lemon {
44.15
44.16 + class ListDigraph;
44.17 +
44.18 class ListDigraphBase {
44.19
44.20 protected:
44.21 @@ -62,6 +64,7 @@
44.22
44.23 class Node {
44.24 friend class ListDigraphBase;
44.25 + friend class ListDigraph;
44.26 protected:
44.27
44.28 int id;
44.29 @@ -77,6 +80,7 @@
44.30
44.31 class Arc {
44.32 friend class ListDigraphBase;
44.33 + friend class ListDigraph;
44.34 protected:
44.35
44.36 int id;
44.37 @@ -116,20 +120,20 @@
44.38 void first(Arc& arc) const {
44.39 int n;
44.40 for(n = first_node;
44.41 - n!=-1 && nodes[n].first_in == -1;
44.42 + n != -1 && nodes[n].first_out == -1;
44.43 n = nodes[n].next) {}
44.44 - arc.id = (n == -1) ? -1 : nodes[n].first_in;
44.45 + arc.id = (n == -1) ? -1 : nodes[n].first_out;
44.46 }
44.47
44.48 void next(Arc& arc) const {
44.49 - if (arcs[arc.id].next_in != -1) {
44.50 - arc.id = arcs[arc.id].next_in;
44.51 + if (arcs[arc.id].next_out != -1) {
44.52 + arc.id = arcs[arc.id].next_out;
44.53 } else {
44.54 int n;
44.55 - for(n = nodes[arcs[arc.id].target].next;
44.56 - n!=-1 && nodes[n].first_in == -1;
44.57 + for(n = nodes[arcs[arc.id].source].next;
44.58 + n != -1 && nodes[n].first_out == -1;
44.59 n = nodes[n].next) {}
44.60 - arc.id = (n == -1) ? -1 : nodes[n].first_in;
44.61 + arc.id = (n == -1) ? -1 : nodes[n].first_out;
44.62 }
44.63 }
44.64
44.65 @@ -311,31 +315,25 @@
44.66
44.67 ///A general directed graph structure.
44.68
44.69 - ///\ref ListDigraph is a simple and fast <em>directed graph</em>
44.70 - ///implementation based on static linked lists that are stored in
44.71 + ///\ref ListDigraph is a versatile and fast directed graph
44.72 + ///implementation based on linked lists that are stored in
44.73 ///\c std::vector structures.
44.74 ///
44.75 - ///It conforms to the \ref concepts::Digraph "Digraph concept" and it
44.76 - ///also provides several useful additional functionalities.
44.77 - ///Most of the member functions and nested classes are documented
44.78 + ///This type fully conforms to the \ref concepts::Digraph "Digraph concept"
44.79 + ///and it also provides several useful additional functionalities.
44.80 + ///Most of its member functions and nested classes are documented
44.81 ///only in the concept class.
44.82 ///
44.83 ///\sa concepts::Digraph
44.84 -
44.85 + ///\sa ListGraph
44.86 class ListDigraph : public ExtendedListDigraphBase {
44.87 typedef ExtendedListDigraphBase Parent;
44.88
44.89 private:
44.90 - ///ListDigraph is \e not copy constructible. Use copyDigraph() instead.
44.91 -
44.92 - ///ListDigraph is \e not copy constructible. Use copyDigraph() instead.
44.93 - ///
44.94 + /// Digraphs are \e not copy constructible. Use DigraphCopy instead.
44.95 ListDigraph(const ListDigraph &) :ExtendedListDigraphBase() {};
44.96 - ///\brief Assignment of ListDigraph to another one is \e not allowed.
44.97 - ///Use copyDigraph() instead.
44.98 -
44.99 - ///Assignment of ListDigraph to another one is \e not allowed.
44.100 - ///Use copyDigraph() instead.
44.101 + /// \brief Assignment of a digraph to another one is \e not allowed.
44.102 + /// Use DigraphCopy instead.
44.103 void operator=(const ListDigraph &) {}
44.104 public:
44.105
44.106 @@ -347,71 +345,65 @@
44.107
44.108 ///Add a new node to the digraph.
44.109
44.110 - ///Add a new node to the digraph.
44.111 + ///This function adds a new node to the digraph.
44.112 ///\return The new node.
44.113 Node addNode() { return Parent::addNode(); }
44.114
44.115 ///Add a new arc to the digraph.
44.116
44.117 - ///Add a new arc to the digraph with source node \c s
44.118 + ///This function adds a new arc to the digraph with source node \c s
44.119 ///and target node \c t.
44.120 ///\return The new arc.
44.121 - Arc addArc(const Node& s, const Node& t) {
44.122 + Arc addArc(Node s, Node t) {
44.123 return Parent::addArc(s, t);
44.124 }
44.125
44.126 ///\brief Erase a node from the digraph.
44.127 ///
44.128 - ///Erase a node from the digraph.
44.129 - ///
44.130 - void erase(const Node& n) { Parent::erase(n); }
44.131 + ///This function erases the given node from the digraph.
44.132 + void erase(Node n) { Parent::erase(n); }
44.133
44.134 ///\brief Erase an arc from the digraph.
44.135 ///
44.136 - ///Erase an arc from the digraph.
44.137 - ///
44.138 - void erase(const Arc& a) { Parent::erase(a); }
44.139 + ///This function erases the given arc from the digraph.
44.140 + void erase(Arc a) { Parent::erase(a); }
44.141
44.142 /// Node validity check
44.143
44.144 - /// This function gives back true if the given node is valid,
44.145 - /// ie. it is a real node of the graph.
44.146 + /// This function gives back \c true if the given node is valid,
44.147 + /// i.e. it is a real node of the digraph.
44.148 ///
44.149 - /// \warning A Node pointing to a removed item
44.150 - /// could become valid again later if new nodes are
44.151 - /// added to the graph.
44.152 + /// \warning A removed node could become valid again if new nodes are
44.153 + /// added to the digraph.
44.154 bool valid(Node n) const { return Parent::valid(n); }
44.155
44.156 /// Arc validity check
44.157
44.158 - /// This function gives back true if the given arc is valid,
44.159 - /// ie. it is a real arc of the graph.
44.160 + /// This function gives back \c true if the given arc is valid,
44.161 + /// i.e. it is a real arc of the digraph.
44.162 ///
44.163 - /// \warning An Arc pointing to a removed item
44.164 - /// could become valid again later if new nodes are
44.165 - /// added to the graph.
44.166 + /// \warning A removed arc could become valid again if new arcs are
44.167 + /// added to the digraph.
44.168 bool valid(Arc a) const { return Parent::valid(a); }
44.169
44.170 - /// Change the target of \c a to \c n
44.171 + /// Change the target node of an arc
44.172
44.173 - /// Change the target of \c a to \c n
44.174 + /// This function changes the target node of the given arc \c a to \c n.
44.175 ///
44.176 - ///\note The <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s referencing
44.177 - ///the changed arc remain valid. However <tt>InArcIt</tt>s are
44.178 - ///invalidated.
44.179 + ///\note \c ArcIt and \c OutArcIt iterators referencing the changed
44.180 + ///arc remain valid, however \c InArcIt iterators are invalidated.
44.181 ///
44.182 ///\warning This functionality cannot be used together with the Snapshot
44.183 ///feature.
44.184 void changeTarget(Arc a, Node n) {
44.185 Parent::changeTarget(a,n);
44.186 }
44.187 - /// Change the source of \c a to \c n
44.188 + /// Change the source node of an arc
44.189
44.190 - /// Change the source of \c a to \c n
44.191 + /// This function changes the source node of the given arc \c a to \c n.
44.192 ///
44.193 - ///\note The <tt>InArcIt</tt>s referencing the changed arc remain
44.194 - ///valid. However the <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s are
44.195 - ///invalidated.
44.196 + ///\note \c InArcIt iterators referencing the changed arc remain
44.197 + ///valid, however \c ArcIt and \c OutArcIt iterators are invalidated.
44.198 ///
44.199 ///\warning This functionality cannot be used together with the Snapshot
44.200 ///feature.
44.201 @@ -419,94 +411,76 @@
44.202 Parent::changeSource(a,n);
44.203 }
44.204
44.205 - /// Invert the direction of an arc.
44.206 + /// Reverse the direction of an arc.
44.207
44.208 - ///\note The <tt>ArcIt</tt>s referencing the changed arc remain
44.209 - ///valid. However <tt>OutArcIt</tt>s and <tt>InArcIt</tt>s are
44.210 - ///invalidated.
44.211 + /// This function reverses the direction of the given arc.
44.212 + ///\note \c ArcIt, \c OutArcIt and \c InArcIt iterators referencing
44.213 + ///the changed arc are invalidated.
44.214 ///
44.215 ///\warning This functionality cannot be used together with the Snapshot
44.216 ///feature.
44.217 - void reverseArc(Arc e) {
44.218 - Node t=target(e);
44.219 - changeTarget(e,source(e));
44.220 - changeSource(e,t);
44.221 + void reverseArc(Arc a) {
44.222 + Node t=target(a);
44.223 + changeTarget(a,source(a));
44.224 + changeSource(a,t);
44.225 }
44.226
44.227 - /// Reserve memory for nodes.
44.228 -
44.229 - /// Using this function it is possible to avoid the superfluous memory
44.230 - /// allocation: if you know that the digraph you want to build will
44.231 - /// be very large (e.g. it will contain millions of nodes and/or arcs)
44.232 - /// then it is worth reserving space for this amount before starting
44.233 - /// to build the digraph.
44.234 - /// \sa reserveArc
44.235 - void reserveNode(int n) { nodes.reserve(n); };
44.236 -
44.237 - /// Reserve memory for arcs.
44.238 -
44.239 - /// Using this function it is possible to avoid the superfluous memory
44.240 - /// allocation: if you know that the digraph you want to build will
44.241 - /// be very large (e.g. it will contain millions of nodes and/or arcs)
44.242 - /// then it is worth reserving space for this amount before starting
44.243 - /// to build the digraph.
44.244 - /// \sa reserveNode
44.245 - void reserveArc(int m) { arcs.reserve(m); };
44.246 -
44.247 ///Contract two nodes.
44.248
44.249 - ///This function contracts two nodes.
44.250 - ///Node \p b will be removed but instead of deleting
44.251 - ///incident arcs, they will be joined to \p a.
44.252 - ///The last parameter \p r controls whether to remove loops. \c true
44.253 - ///means that loops will be removed.
44.254 + ///This function contracts the given two nodes.
44.255 + ///Node \c v is removed, but instead of deleting its
44.256 + ///incident arcs, they are joined to node \c u.
44.257 + ///If the last parameter \c r is \c true (this is the default value),
44.258 + ///then the newly created loops are removed.
44.259 ///
44.260 - ///\note The <tt>ArcIt</tt>s referencing a moved arc remain
44.261 - ///valid. However <tt>InArcIt</tt>s and <tt>OutArcIt</tt>s
44.262 - ///may be invalidated.
44.263 + ///\note The moved arcs are joined to node \c u using changeSource()
44.264 + ///or changeTarget(), thus \c ArcIt and \c OutArcIt iterators are
44.265 + ///invalidated for the outgoing arcs of node \c v and \c InArcIt
44.266 + ///iterators are invalidated for the incomming arcs of \c v.
44.267 + ///Moreover all iterators referencing node \c v or the removed
44.268 + ///loops are also invalidated. Other iterators remain valid.
44.269 ///
44.270 ///\warning This functionality cannot be used together with the Snapshot
44.271 ///feature.
44.272 - void contract(Node a, Node b, bool r = true)
44.273 + void contract(Node u, Node v, bool r = true)
44.274 {
44.275 - for(OutArcIt e(*this,b);e!=INVALID;) {
44.276 + for(OutArcIt e(*this,v);e!=INVALID;) {
44.277 OutArcIt f=e;
44.278 ++f;
44.279 - if(r && target(e)==a) erase(e);
44.280 - else changeSource(e,a);
44.281 + if(r && target(e)==u) erase(e);
44.282 + else changeSource(e,u);
44.283 e=f;
44.284 }
44.285 - for(InArcIt e(*this,b);e!=INVALID;) {
44.286 + for(InArcIt e(*this,v);e!=INVALID;) {
44.287 InArcIt f=e;
44.288 ++f;
44.289 - if(r && source(e)==a) erase(e);
44.290 - else changeTarget(e,a);
44.291 + if(r && source(e)==u) erase(e);
44.292 + else changeTarget(e,u);
44.293 e=f;
44.294 }
44.295 - erase(b);
44.296 + erase(v);
44.297 }
44.298
44.299 ///Split a node.
44.300
44.301 - ///This function splits a node. First a new node is added to the digraph,
44.302 - ///then the source of each outgoing arc of \c n is moved to this new node.
44.303 - ///If \c connect is \c true (this is the default value), then a new arc
44.304 - ///from \c n to the newly created node is also added.
44.305 + ///This function splits the given node. First, a new node is added
44.306 + ///to the digraph, then the source of each outgoing arc of node \c n
44.307 + ///is moved to this new node.
44.308 + ///If the second parameter \c connect is \c true (this is the default
44.309 + ///value), then a new arc from node \c n to the newly created node
44.310 + ///is also added.
44.311 ///\return The newly created node.
44.312 ///
44.313 - ///\note The <tt>ArcIt</tt>s referencing a moved arc remain
44.314 - ///valid. However <tt>InArcIt</tt>s and <tt>OutArcIt</tt>s may
44.315 - ///be invalidated.
44.316 + ///\note All iterators remain valid.
44.317 ///
44.318 - ///\warning This functionality cannot be used in conjunction with the
44.319 + ///\warning This functionality cannot be used together with the
44.320 ///Snapshot feature.
44.321 Node split(Node n, bool connect = true) {
44.322 Node b = addNode();
44.323 - for(OutArcIt e(*this,n);e!=INVALID;) {
44.324 - OutArcIt f=e;
44.325 - ++f;
44.326 - changeSource(e,b);
44.327 - e=f;
44.328 + nodes[b.id].first_out=nodes[n.id].first_out;
44.329 + nodes[n.id].first_out=-1;
44.330 + for(int i=nodes[b.id].first_out; i!=-1; i=arcs[i].next_out) {
44.331 + arcs[i].source=b.id;
44.332 }
44.333 if (connect) addArc(n,b);
44.334 return b;
44.335 @@ -514,21 +488,52 @@
44.336
44.337 ///Split an arc.
44.338
44.339 - ///This function splits an arc. First a new node \c b is added to
44.340 - ///the digraph, then the original arc is re-targeted to \c
44.341 - ///b. Finally an arc from \c b to the original target is added.
44.342 + ///This function splits the given arc. First, a new node \c v is
44.343 + ///added to the digraph, then the target node of the original arc
44.344 + ///is set to \c v. Finally, an arc from \c v to the original target
44.345 + ///is added.
44.346 + ///\return The newly created node.
44.347 ///
44.348 - ///\return The newly created node.
44.349 + ///\note \c InArcIt iterators referencing the original arc are
44.350 + ///invalidated. Other iterators remain valid.
44.351 ///
44.352 ///\warning This functionality cannot be used together with the
44.353 ///Snapshot feature.
44.354 - Node split(Arc e) {
44.355 - Node b = addNode();
44.356 - addArc(b,target(e));
44.357 - changeTarget(e,b);
44.358 - return b;
44.359 + Node split(Arc a) {
44.360 + Node v = addNode();
44.361 + addArc(v,target(a));
44.362 + changeTarget(a,v);
44.363 + return v;
44.364 }
44.365
44.366 + ///Clear the digraph.
44.367 +
44.368 + ///This function erases all nodes and arcs from the digraph.
44.369 + ///
44.370 + void clear() {
44.371 + Parent::clear();
44.372 + }
44.373 +
44.374 + /// Reserve memory for nodes.
44.375 +
44.376 + /// Using this function, it is possible to avoid superfluous memory
44.377 + /// allocation: if you know that the digraph you want to build will
44.378 + /// be large (e.g. it will contain millions of nodes and/or arcs),
44.379 + /// then it is worth reserving space for this amount before starting
44.380 + /// to build the digraph.
44.381 + /// \sa reserveArc()
44.382 + void reserveNode(int n) { nodes.reserve(n); };
44.383 +
44.384 + /// Reserve memory for arcs.
44.385 +
44.386 + /// Using this function, it is possible to avoid superfluous memory
44.387 + /// allocation: if you know that the digraph you want to build will
44.388 + /// be large (e.g. it will contain millions of nodes and/or arcs),
44.389 + /// then it is worth reserving space for this amount before starting
44.390 + /// to build the digraph.
44.391 + /// \sa reserveNode()
44.392 + void reserveArc(int m) { arcs.reserve(m); };
44.393 +
44.394 /// \brief Class to make a snapshot of the digraph and restore
44.395 /// it later.
44.396 ///
44.397 @@ -537,9 +542,15 @@
44.398 /// The newly added nodes and arcs can be removed using the
44.399 /// restore() function.
44.400 ///
44.401 - /// \warning Arc and node deletions and other modifications (e.g.
44.402 - /// contracting, splitting, reversing arcs or nodes) cannot be
44.403 + /// \note After a state is restored, you cannot restore a later state,
44.404 + /// i.e. you cannot add the removed nodes and arcs again using
44.405 + /// another Snapshot instance.
44.406 + ///
44.407 + /// \warning Node and arc deletions and other modifications (e.g.
44.408 + /// reversing, contracting, splitting arcs or nodes) cannot be
44.409 /// restored. These events invalidate the snapshot.
44.410 + /// However the arcs and nodes that were added to the digraph after
44.411 + /// making the current snapshot can be removed without invalidating it.
44.412 class Snapshot {
44.413 protected:
44.414
44.415 @@ -709,39 +720,40 @@
44.416 /// \brief Default constructor.
44.417 ///
44.418 /// Default constructor.
44.419 - /// To actually make a snapshot you must call save().
44.420 + /// You have to call save() to actually make a snapshot.
44.421 Snapshot()
44.422 : digraph(0), node_observer_proxy(*this),
44.423 arc_observer_proxy(*this) {}
44.424
44.425 /// \brief Constructor that immediately makes a snapshot.
44.426 ///
44.427 - /// This constructor immediately makes a snapshot of the digraph.
44.428 - /// \param _digraph The digraph we make a snapshot of.
44.429 - Snapshot(ListDigraph &_digraph)
44.430 + /// This constructor immediately makes a snapshot of the given digraph.
44.431 + Snapshot(ListDigraph &gr)
44.432 : node_observer_proxy(*this),
44.433 arc_observer_proxy(*this) {
44.434 - attach(_digraph);
44.435 + attach(gr);
44.436 }
44.437
44.438 /// \brief Make a snapshot.
44.439 ///
44.440 - /// Make a snapshot of the digraph.
44.441 - ///
44.442 - /// This function can be called more than once. In case of a repeated
44.443 + /// This function makes a snapshot of the given digraph.
44.444 + /// It can be called more than once. In case of a repeated
44.445 /// call, the previous snapshot gets lost.
44.446 - /// \param _digraph The digraph we make the snapshot of.
44.447 - void save(ListDigraph &_digraph) {
44.448 + void save(ListDigraph &gr) {
44.449 if (attached()) {
44.450 detach();
44.451 clear();
44.452 }
44.453 - attach(_digraph);
44.454 + attach(gr);
44.455 }
44.456
44.457 /// \brief Undo the changes until the last snapshot.
44.458 - //
44.459 - /// Undo the changes until the last snapshot created by save().
44.460 + ///
44.461 + /// This function undos the changes until the last snapshot
44.462 + /// created by save() or Snapshot(ListDigraph&).
44.463 + ///
44.464 + /// \warning This method invalidates the snapshot, i.e. repeated
44.465 + /// restoring is not supported unless you call save() again.
44.466 void restore() {
44.467 detach();
44.468 for(std::list<Arc>::iterator it = added_arcs.begin();
44.469 @@ -755,9 +767,9 @@
44.470 clear();
44.471 }
44.472
44.473 - /// \brief Gives back true when the snapshot is valid.
44.474 + /// \brief Returns \c true if the snapshot is valid.
44.475 ///
44.476 - /// Gives back true when the snapshot is valid.
44.477 + /// This function returns \c true if the snapshot is valid.
44.478 bool valid() const {
44.479 return attached();
44.480 }
44.481 @@ -795,10 +807,6 @@
44.482
44.483 typedef ListGraphBase Graph;
44.484
44.485 - class Node;
44.486 - class Arc;
44.487 - class Edge;
44.488 -
44.489 class Node {
44.490 friend class ListGraphBase;
44.491 protected:
44.492 @@ -848,8 +856,6 @@
44.493 bool operator<(const Arc& arc) const {return id < arc.id;}
44.494 };
44.495
44.496 -
44.497 -
44.498 ListGraphBase()
44.499 : nodes(), first_node(-1),
44.500 first_free_node(-1), arcs(), first_free_arc(-1) {}
44.501 @@ -1164,31 +1170,25 @@
44.502
44.503 ///A general undirected graph structure.
44.504
44.505 - ///\ref ListGraph is a simple and fast <em>undirected graph</em>
44.506 - ///implementation based on static linked lists that are stored in
44.507 + ///\ref ListGraph is a versatile and fast undirected graph
44.508 + ///implementation based on linked lists that are stored in
44.509 ///\c std::vector structures.
44.510 ///
44.511 - ///It conforms to the \ref concepts::Graph "Graph concept" and it
44.512 - ///also provides several useful additional functionalities.
44.513 - ///Most of the member functions and nested classes are documented
44.514 + ///This type fully conforms to the \ref concepts::Graph "Graph concept"
44.515 + ///and it also provides several useful additional functionalities.
44.516 + ///Most of its member functions and nested classes are documented
44.517 ///only in the concept class.
44.518 ///
44.519 ///\sa concepts::Graph
44.520 -
44.521 + ///\sa ListDigraph
44.522 class ListGraph : public ExtendedListGraphBase {
44.523 typedef ExtendedListGraphBase Parent;
44.524
44.525 private:
44.526 - ///ListGraph is \e not copy constructible. Use copyGraph() instead.
44.527 -
44.528 - ///ListGraph is \e not copy constructible. Use copyGraph() instead.
44.529 - ///
44.530 + /// Graphs are \e not copy constructible. Use GraphCopy instead.
44.531 ListGraph(const ListGraph &) :ExtendedListGraphBase() {};
44.532 - ///\brief Assignment of ListGraph to another one is \e not allowed.
44.533 - ///Use copyGraph() instead.
44.534 -
44.535 - ///Assignment of ListGraph to another one is \e not allowed.
44.536 - ///Use copyGraph() instead.
44.537 + /// \brief Assignment of a graph to another one is \e not allowed.
44.538 + /// Use GraphCopy instead.
44.539 void operator=(const ListGraph &) {}
44.540 public:
44.541 /// Constructor
44.542 @@ -1201,94 +1201,95 @@
44.543
44.544 /// \brief Add a new node to the graph.
44.545 ///
44.546 - /// Add a new node to the graph.
44.547 + /// This function adds a new node to the graph.
44.548 /// \return The new node.
44.549 Node addNode() { return Parent::addNode(); }
44.550
44.551 /// \brief Add a new edge to the graph.
44.552 ///
44.553 - /// Add a new edge to the graph with source node \c s
44.554 - /// and target node \c t.
44.555 + /// This function adds a new edge to the graph between nodes
44.556 + /// \c u and \c v with inherent orientation from node \c u to
44.557 + /// node \c v.
44.558 /// \return The new edge.
44.559 - Edge addEdge(const Node& s, const Node& t) {
44.560 - return Parent::addEdge(s, t);
44.561 + Edge addEdge(Node u, Node v) {
44.562 + return Parent::addEdge(u, v);
44.563 }
44.564
44.565 - /// \brief Erase a node from the graph.
44.566 + ///\brief Erase a node from the graph.
44.567 ///
44.568 - /// Erase a node from the graph.
44.569 + /// This function erases the given node from the graph.
44.570 + void erase(Node n) { Parent::erase(n); }
44.571 +
44.572 + ///\brief Erase an edge from the graph.
44.573 ///
44.574 - void erase(const Node& n) { Parent::erase(n); }
44.575 -
44.576 - /// \brief Erase an edge from the graph.
44.577 - ///
44.578 - /// Erase an edge from the graph.
44.579 - ///
44.580 - void erase(const Edge& e) { Parent::erase(e); }
44.581 + /// This function erases the given edge from the graph.
44.582 + void erase(Edge e) { Parent::erase(e); }
44.583 /// Node validity check
44.584
44.585 - /// This function gives back true if the given node is valid,
44.586 - /// ie. it is a real node of the graph.
44.587 + /// This function gives back \c true if the given node is valid,
44.588 + /// i.e. it is a real node of the graph.
44.589 ///
44.590 - /// \warning A Node pointing to a removed item
44.591 - /// could become valid again later if new nodes are
44.592 + /// \warning A removed node could become valid again if new nodes are
44.593 /// added to the graph.
44.594 bool valid(Node n) const { return Parent::valid(n); }
44.595 + /// Edge validity check
44.596 +
44.597 + /// This function gives back \c true if the given edge is valid,
44.598 + /// i.e. it is a real edge of the graph.
44.599 + ///
44.600 + /// \warning A removed edge could become valid again if new edges are
44.601 + /// added to the graph.
44.602 + bool valid(Edge e) const { return Parent::valid(e); }
44.603 /// Arc validity check
44.604
44.605 - /// This function gives back true if the given arc is valid,
44.606 - /// ie. it is a real arc of the graph.
44.607 + /// This function gives back \c true if the given arc is valid,
44.608 + /// i.e. it is a real arc of the graph.
44.609 ///
44.610 - /// \warning An Arc pointing to a removed item
44.611 - /// could become valid again later if new edges are
44.612 + /// \warning A removed arc could become valid again if new edges are
44.613 /// added to the graph.
44.614 bool valid(Arc a) const { return Parent::valid(a); }
44.615 - /// Edge validity check
44.616
44.617 - /// This function gives back true if the given edge is valid,
44.618 - /// ie. it is a real arc of the graph.
44.619 + /// \brief Change the first node of an edge.
44.620 ///
44.621 - /// \warning A Edge pointing to a removed item
44.622 - /// could become valid again later if new edges are
44.623 - /// added to the graph.
44.624 - bool valid(Edge e) const { return Parent::valid(e); }
44.625 - /// \brief Change the end \c u of \c e to \c n
44.626 + /// This function changes the first node of the given edge \c e to \c n.
44.627 ///
44.628 - /// This function changes the end \c u of \c e to node \c n.
44.629 - ///
44.630 - ///\note The <tt>EdgeIt</tt>s and <tt>ArcIt</tt>s referencing the
44.631 - ///changed edge are invalidated and if the changed node is the
44.632 - ///base node of an iterator then this iterator is also
44.633 - ///invalidated.
44.634 + ///\note \c EdgeIt and \c ArcIt iterators referencing the
44.635 + ///changed edge are invalidated and all other iterators whose
44.636 + ///base node is the changed node are also invalidated.
44.637 ///
44.638 ///\warning This functionality cannot be used together with the
44.639 ///Snapshot feature.
44.640 void changeU(Edge e, Node n) {
44.641 Parent::changeU(e,n);
44.642 }
44.643 - /// \brief Change the end \c v of \c e to \c n
44.644 + /// \brief Change the second node of an edge.
44.645 ///
44.646 - /// This function changes the end \c v of \c e to \c n.
44.647 + /// This function changes the second node of the given edge \c e to \c n.
44.648 ///
44.649 - ///\note The <tt>EdgeIt</tt>s referencing the changed edge remain
44.650 - ///valid, however <tt>ArcIt</tt>s and if the changed node is the
44.651 - ///base node of an iterator then this iterator is invalidated.
44.652 + ///\note \c EdgeIt iterators referencing the changed edge remain
44.653 + ///valid, however \c ArcIt iterators referencing the changed edge and
44.654 + ///all other iterators whose base node is the changed node are also
44.655 + ///invalidated.
44.656 ///
44.657 ///\warning This functionality cannot be used together with the
44.658 ///Snapshot feature.
44.659 void changeV(Edge e, Node n) {
44.660 Parent::changeV(e,n);
44.661 }
44.662 +
44.663 /// \brief Contract two nodes.
44.664 ///
44.665 - /// This function contracts two nodes.
44.666 - /// Node \p b will be removed but instead of deleting
44.667 - /// its neighboring arcs, they will be joined to \p a.
44.668 - /// The last parameter \p r controls whether to remove loops. \c true
44.669 - /// means that loops will be removed.
44.670 + /// This function contracts the given two nodes.
44.671 + /// Node \c b is removed, but instead of deleting
44.672 + /// its incident edges, they are joined to node \c a.
44.673 + /// If the last parameter \c r is \c true (this is the default value),
44.674 + /// then the newly created loops are removed.
44.675 ///
44.676 - /// \note The <tt>ArcIt</tt>s referencing a moved arc remain
44.677 - /// valid.
44.678 + /// \note The moved edges are joined to node \c a using changeU()
44.679 + /// or changeV(), thus all edge and arc iterators whose base node is
44.680 + /// \c b are invalidated.
44.681 + /// Moreover all iterators referencing node \c b or the removed
44.682 + /// loops are also invalidated. Other iterators remain valid.
44.683 ///
44.684 ///\warning This functionality cannot be used together with the
44.685 ///Snapshot feature.
44.686 @@ -1307,6 +1308,33 @@
44.687 erase(b);
44.688 }
44.689
44.690 + ///Clear the graph.
44.691 +
44.692 + ///This function erases all nodes and arcs from the graph.
44.693 + ///
44.694 + void clear() {
44.695 + Parent::clear();
44.696 + }
44.697 +
44.698 + /// Reserve memory for nodes.
44.699 +
44.700 + /// Using this function, it is possible to avoid superfluous memory
44.701 + /// allocation: if you know that the graph you want to build will
44.702 + /// be large (e.g. it will contain millions of nodes and/or edges),
44.703 + /// then it is worth reserving space for this amount before starting
44.704 + /// to build the graph.
44.705 + /// \sa reserveEdge()
44.706 + void reserveNode(int n) { nodes.reserve(n); };
44.707 +
44.708 + /// Reserve memory for edges.
44.709 +
44.710 + /// Using this function, it is possible to avoid superfluous memory
44.711 + /// allocation: if you know that the graph you want to build will
44.712 + /// be large (e.g. it will contain millions of nodes and/or edges),
44.713 + /// then it is worth reserving space for this amount before starting
44.714 + /// to build the graph.
44.715 + /// \sa reserveNode()
44.716 + void reserveEdge(int m) { arcs.reserve(2 * m); };
44.717
44.718 /// \brief Class to make a snapshot of the graph and restore
44.719 /// it later.
44.720 @@ -1316,9 +1344,15 @@
44.721 /// The newly added nodes and edges can be removed
44.722 /// using the restore() function.
44.723 ///
44.724 - /// \warning Edge and node deletions and other modifications
44.725 - /// (e.g. changing nodes of edges, contracting nodes) cannot be
44.726 - /// restored. These events invalidate the snapshot.
44.727 + /// \note After a state is restored, you cannot restore a later state,
44.728 + /// i.e. you cannot add the removed nodes and edges again using
44.729 + /// another Snapshot instance.
44.730 + ///
44.731 + /// \warning Node and edge deletions and other modifications
44.732 + /// (e.g. changing the end-nodes of edges or contracting nodes)
44.733 + /// cannot be restored. These events invalidate the snapshot.
44.734 + /// However the edges and nodes that were added to the graph after
44.735 + /// making the current snapshot can be removed without invalidating it.
44.736 class Snapshot {
44.737 protected:
44.738
44.739 @@ -1488,39 +1522,40 @@
44.740 /// \brief Default constructor.
44.741 ///
44.742 /// Default constructor.
44.743 - /// To actually make a snapshot you must call save().
44.744 + /// You have to call save() to actually make a snapshot.
44.745 Snapshot()
44.746 : graph(0), node_observer_proxy(*this),
44.747 edge_observer_proxy(*this) {}
44.748
44.749 /// \brief Constructor that immediately makes a snapshot.
44.750 ///
44.751 - /// This constructor immediately makes a snapshot of the graph.
44.752 - /// \param _graph The graph we make a snapshot of.
44.753 - Snapshot(ListGraph &_graph)
44.754 + /// This constructor immediately makes a snapshot of the given graph.
44.755 + Snapshot(ListGraph &gr)
44.756 : node_observer_proxy(*this),
44.757 edge_observer_proxy(*this) {
44.758 - attach(_graph);
44.759 + attach(gr);
44.760 }
44.761
44.762 /// \brief Make a snapshot.
44.763 ///
44.764 - /// Make a snapshot of the graph.
44.765 - ///
44.766 - /// This function can be called more than once. In case of a repeated
44.767 + /// This function makes a snapshot of the given graph.
44.768 + /// It can be called more than once. In case of a repeated
44.769 /// call, the previous snapshot gets lost.
44.770 - /// \param _graph The graph we make the snapshot of.
44.771 - void save(ListGraph &_graph) {
44.772 + void save(ListGraph &gr) {
44.773 if (attached()) {
44.774 detach();
44.775 clear();
44.776 }
44.777 - attach(_graph);
44.778 + attach(gr);
44.779 }
44.780
44.781 /// \brief Undo the changes until the last snapshot.
44.782 - //
44.783 - /// Undo the changes until the last snapshot created by save().
44.784 + ///
44.785 + /// This function undos the changes until the last snapshot
44.786 + /// created by save() or Snapshot(ListGraph&).
44.787 + ///
44.788 + /// \warning This method invalidates the snapshot, i.e. repeated
44.789 + /// restoring is not supported unless you call save() again.
44.790 void restore() {
44.791 detach();
44.792 for(std::list<Edge>::iterator it = added_edges.begin();
44.793 @@ -1534,9 +1569,9 @@
44.794 clear();
44.795 }
44.796
44.797 - /// \brief Gives back true when the snapshot is valid.
44.798 + /// \brief Returns \c true if the snapshot is valid.
44.799 ///
44.800 - /// Gives back true when the snapshot is valid.
44.801 + /// This function returns \c true if the snapshot is valid.
44.802 bool valid() const {
44.803 return attached();
44.804 }
45.1 --- a/lemon/lp_base.h Tue Aug 18 10:08:28 2009 +0200
45.2 +++ b/lemon/lp_base.h Thu Nov 05 08:39:49 2009 +0100
45.3 @@ -943,6 +943,14 @@
45.4 virtual int _addCol() = 0;
45.5 virtual int _addRow() = 0;
45.6
45.7 + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
45.8 + int row = _addRow();
45.9 + _setRowCoeffs(row, b, e);
45.10 + _setRowLowerBound(row, l);
45.11 + _setRowUpperBound(row, u);
45.12 + return row;
45.13 + }
45.14 +
45.15 virtual void _eraseCol(int col) = 0;
45.16 virtual void _eraseRow(int row) = 0;
45.17
45.18 @@ -1207,8 +1215,10 @@
45.19 ///\param u is the upper bound (\ref INF means no bound)
45.20 ///\return The created row.
45.21 Row addRow(Value l,const Expr &e, Value u) {
45.22 - Row r=addRow();
45.23 - row(r,l,e,u);
45.24 + Row r;
45.25 + e.simplify();
45.26 + r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), cols),
45.27 + ExprIterator(e.comps.end(), cols), u - *e));
45.28 return r;
45.29 }
45.30
45.31 @@ -1217,8 +1227,12 @@
45.32 ///\param c is a linear expression (see \ref Constr)
45.33 ///\return The created row.
45.34 Row addRow(const Constr &c) {
45.35 - Row r=addRow();
45.36 - row(r,c);
45.37 + Row r;
45.38 + c.expr().simplify();
45.39 + r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound():-INF,
45.40 + ExprIterator(c.expr().comps.begin(), cols),
45.41 + ExprIterator(c.expr().comps.end(), cols),
45.42 + c.upperBounded()?c.upperBound():INF));
45.43 return r;
45.44 }
45.45 ///Erase a column (i.e a variable) from the LP
46.1 --- a/lemon/lp_skeleton.cc Tue Aug 18 10:08:28 2009 +0200
46.2 +++ b/lemon/lp_skeleton.cc Thu Nov 05 08:39:49 2009 +0100
46.3 @@ -32,6 +32,11 @@
46.4 return ++row_num;
46.5 }
46.6
46.7 + int SkeletonSolverBase::_addRow(Value, ExprIterator, ExprIterator, Value)
46.8 + {
46.9 + return ++row_num;
46.10 + }
46.11 +
46.12 void SkeletonSolverBase::_eraseCol(int) {}
46.13 void SkeletonSolverBase::_eraseRow(int) {}
46.14
47.1 --- a/lemon/lp_skeleton.h Tue Aug 18 10:08:28 2009 +0200
47.2 +++ b/lemon/lp_skeleton.h Thu Nov 05 08:39:49 2009 +0100
47.3 @@ -45,6 +45,8 @@
47.4 /// \e
47.5 virtual int _addRow();
47.6 /// \e
47.7 + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
47.8 + /// \e
47.9 virtual void _eraseCol(int i);
47.10 /// \e
47.11 virtual void _eraseRow(int i);
48.1 --- a/lemon/maps.h Tue Aug 18 10:08:28 2009 +0200
48.2 +++ b/lemon/maps.h Thu Nov 05 08:39:49 2009 +0100
48.3 @@ -22,6 +22,7 @@
48.4 #include <iterator>
48.5 #include <functional>
48.6 #include <vector>
48.7 +#include <map>
48.8
48.9 #include <lemon/core.h>
48.10
48.11 @@ -29,8 +30,6 @@
48.12 ///\ingroup maps
48.13 ///\brief Miscellaneous property maps
48.14
48.15 -#include <map>
48.16 -
48.17 namespace lemon {
48.18
48.19 /// \addtogroup maps
48.20 @@ -57,7 +56,7 @@
48.21 /// its type definitions, or if you have to provide a writable map,
48.22 /// but data written to it is not required (i.e. it will be sent to
48.23 /// <tt>/dev/null</tt>).
48.24 - /// It conforms the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
48.25 + /// It conforms to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
48.26 ///
48.27 /// \sa ConstMap
48.28 template<typename K, typename V>
48.29 @@ -90,7 +89,7 @@
48.30 /// value to each key.
48.31 ///
48.32 /// In other aspects it is equivalent to \c NullMap.
48.33 - /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
48.34 + /// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap"
48.35 /// concept, but it absorbs the data written to it.
48.36 ///
48.37 /// The simplest way of using this map is through the constMap()
48.38 @@ -159,7 +158,7 @@
48.39 /// value to each key.
48.40 ///
48.41 /// In other aspects it is equivalent to \c NullMap.
48.42 - /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
48.43 + /// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap"
48.44 /// concept, but it absorbs the data written to it.
48.45 ///
48.46 /// The simplest way of using this map is through the constMap()
48.47 @@ -233,7 +232,7 @@
48.48 /// values to integer keys from the range <tt>[0..size-1]</tt>.
48.49 /// It can be used with some data structures, for example
48.50 /// \c UnionFind, \c BinHeap, when the used items are small
48.51 - /// integers. This map conforms the \ref concepts::ReferenceMap
48.52 + /// integers. This map conforms to the \ref concepts::ReferenceMap
48.53 /// "ReferenceMap" concept.
48.54 ///
48.55 /// The simplest way of using this map is through the rangeMap()
48.56 @@ -341,7 +340,7 @@
48.57 /// that you can specify a default value for the keys that are not
48.58 /// stored actually. This value can be different from the default
48.59 /// contructed value (i.e. \c %Value()).
48.60 - /// This type conforms the \ref concepts::ReferenceMap "ReferenceMap"
48.61 + /// This type conforms to the \ref concepts::ReferenceMap "ReferenceMap"
48.62 /// concept.
48.63 ///
48.64 /// This map is useful if a default value should be assigned to most of
48.65 @@ -707,7 +706,7 @@
48.66 /// "readable map" to another type using the default conversion.
48.67 /// The \c Key type of it is inherited from \c M and the \c Value
48.68 /// type is \c V.
48.69 - /// This type conforms the \ref concepts::ReadMap "ReadMap" concept.
48.70 + /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
48.71 ///
48.72 /// The simplest way of using this map is through the convertMap()
48.73 /// function.
48.74 @@ -1790,11 +1789,11 @@
48.75 /// order of Dfs algorithm, as the following examples show.
48.76 /// \code
48.77 /// std::vector<Node> v;
48.78 - /// dfs(g,s).processedMap(loggerBoolMap(std::back_inserter(v))).run();
48.79 + /// dfs(g).processedMap(loggerBoolMap(std::back_inserter(v))).run(s);
48.80 /// \endcode
48.81 /// \code
48.82 /// std::vector<Node> v(countNodes(g));
48.83 - /// dfs(g,s).processedMap(loggerBoolMap(v.begin())).run();
48.84 + /// dfs(g).processedMap(loggerBoolMap(v.begin())).run(s);
48.85 /// \endcode
48.86 ///
48.87 /// \note The container of the iterator must contain enough space
48.88 @@ -1818,7 +1817,7 @@
48.89 /// \brief Provides an immutable and unique id for each item in a graph.
48.90 ///
48.91 /// IdMap provides a unique and immutable id for each item of the
48.92 - /// same type (\c Node, \c Arc or \c Edge) in a graph. This id is
48.93 + /// same type (\c Node, \c Arc or \c Edge) in a graph. This id is
48.94 /// - \b unique: different items get different ids,
48.95 /// - \b immutable: the id of an item does not change (even if you
48.96 /// delete other nodes).
48.97 @@ -1826,7 +1825,7 @@
48.98 /// Using this map you get access (i.e. can read) the inner id values of
48.99 /// the items stored in the graph, which is returned by the \c id()
48.100 /// function of the graph. This map can be inverted with its member
48.101 - /// class \c InverseMap or with the \c operator() member.
48.102 + /// class \c InverseMap or with the \c operator()() member.
48.103 ///
48.104 /// \tparam GR The graph type.
48.105 /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
48.106 @@ -1866,9 +1865,11 @@
48.107
48.108 public:
48.109
48.110 - /// \brief This class represents the inverse of its owner (IdMap).
48.111 + /// \brief The inverse map type of IdMap.
48.112 ///
48.113 - /// This class represents the inverse of its owner (IdMap).
48.114 + /// The inverse map type of IdMap. The subscript operator gives back
48.115 + /// an item by its id.
48.116 + /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
48.117 /// \see inverse()
48.118 class InverseMap {
48.119 public:
48.120 @@ -1883,9 +1884,9 @@
48.121 /// Constructor for creating an id-to-item map.
48.122 explicit InverseMap(const IdMap& map) : _graph(map._graph) {}
48.123
48.124 - /// \brief Gives back the given item from its id.
48.125 + /// \brief Gives back an item by its id.
48.126 ///
48.127 - /// Gives back the given item from its id.
48.128 + /// Gives back an item by its id.
48.129 Item operator[](int id) const { return _graph->fromId(id, Item());}
48.130
48.131 private:
48.132 @@ -1898,16 +1899,34 @@
48.133 InverseMap inverse() const { return InverseMap(*_graph);}
48.134 };
48.135
48.136 + /// \brief Returns an \c IdMap class.
48.137 + ///
48.138 + /// This function just returns an \c IdMap class.
48.139 + /// \relates IdMap
48.140 + template <typename K, typename GR>
48.141 + inline IdMap<GR, K> idMap(const GR& graph) {
48.142 + return IdMap<GR, K>(graph);
48.143 + }
48.144
48.145 /// \brief General cross reference graph map type.
48.146
48.147 /// This class provides simple invertable graph maps.
48.148 - /// It wraps an arbitrary \ref concepts::ReadWriteMap "ReadWriteMap"
48.149 - /// and if a key is set to a new value then store it
48.150 - /// in the inverse map.
48.151 + /// It wraps a standard graph map (\c NodeMap, \c ArcMap or \c EdgeMap)
48.152 + /// and if a key is set to a new value, then stores it in the inverse map.
48.153 + /// The graph items can be accessed by their values either using
48.154 + /// \c InverseMap or \c operator()(), and the values of the map can be
48.155 + /// accessed with an STL compatible forward iterator (\c ValueIt).
48.156 + ///
48.157 + /// This map is intended to be used when all associated values are
48.158 + /// different (the map is actually invertable) or there are only a few
48.159 + /// items with the same value.
48.160 + /// Otherwise consider to use \c IterableValueMap, which is more
48.161 + /// suitable and more efficient for such cases. It provides iterators
48.162 + /// to traverse the items with the same associated value, however
48.163 + /// it does not have \c InverseMap.
48.164 ///
48.165 - /// The values of the map can be accessed
48.166 - /// with stl compatible forward iterator.
48.167 + /// This type is not reference map, so it cannot be modified with
48.168 + /// the subscript operator.
48.169 ///
48.170 /// \tparam GR The graph type.
48.171 /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
48.172 @@ -1923,7 +1942,7 @@
48.173 typedef typename ItemSetTraits<GR, K>::
48.174 template Map<V>::Type Map;
48.175
48.176 - typedef std::map<V, K> Container;
48.177 + typedef std::multimap<V, K> Container;
48.178 Container _inv_map;
48.179
48.180 public:
48.181 @@ -1945,54 +1964,66 @@
48.182
48.183 /// \brief Forward iterator for values.
48.184 ///
48.185 - /// This iterator is an stl compatible forward
48.186 + /// This iterator is an STL compatible forward
48.187 /// iterator on the values of the map. The values can
48.188 /// be accessed in the <tt>[beginValue, endValue)</tt> range.
48.189 - class ValueIterator
48.190 + /// They are considered with multiplicity, so each value is
48.191 + /// traversed for each item it is assigned to.
48.192 + class ValueIt
48.193 : public std::iterator<std::forward_iterator_tag, Value> {
48.194 friend class CrossRefMap;
48.195 private:
48.196 - ValueIterator(typename Container::const_iterator _it)
48.197 + ValueIt(typename Container::const_iterator _it)
48.198 : it(_it) {}
48.199 public:
48.200
48.201 - ValueIterator() {}
48.202 -
48.203 - ValueIterator& operator++() { ++it; return *this; }
48.204 - ValueIterator operator++(int) {
48.205 - ValueIterator tmp(*this);
48.206 + /// Constructor
48.207 + ValueIt() {}
48.208 +
48.209 + /// \e
48.210 + ValueIt& operator++() { ++it; return *this; }
48.211 + /// \e
48.212 + ValueIt operator++(int) {
48.213 + ValueIt tmp(*this);
48.214 operator++();
48.215 return tmp;
48.216 }
48.217
48.218 + /// \e
48.219 const Value& operator*() const { return it->first; }
48.220 + /// \e
48.221 const Value* operator->() const { return &(it->first); }
48.222
48.223 - bool operator==(ValueIterator jt) const { return it == jt.it; }
48.224 - bool operator!=(ValueIterator jt) const { return it != jt.it; }
48.225 + /// \e
48.226 + bool operator==(ValueIt jt) const { return it == jt.it; }
48.227 + /// \e
48.228 + bool operator!=(ValueIt jt) const { return it != jt.it; }
48.229
48.230 private:
48.231 typename Container::const_iterator it;
48.232 };
48.233 +
48.234 + /// Alias for \c ValueIt
48.235 + typedef ValueIt ValueIterator;
48.236
48.237 /// \brief Returns an iterator to the first value.
48.238 ///
48.239 - /// Returns an stl compatible iterator to the
48.240 + /// Returns an STL compatible iterator to the
48.241 /// first value of the map. The values of the
48.242 /// map can be accessed in the <tt>[beginValue, endValue)</tt>
48.243 /// range.
48.244 - ValueIterator beginValue() const {
48.245 - return ValueIterator(_inv_map.begin());
48.246 + ValueIt beginValue() const {
48.247 + return ValueIt(_inv_map.begin());
48.248 }
48.249
48.250 /// \brief Returns an iterator after the last value.
48.251 ///
48.252 - /// Returns an stl compatible iterator after the
48.253 + /// Returns an STL compatible iterator after the
48.254 /// last value of the map. The values of the
48.255 /// map can be accessed in the <tt>[beginValue, endValue)</tt>
48.256 /// range.
48.257 - ValueIterator endValue() const {
48.258 - return ValueIterator(_inv_map.end());
48.259 + ValueIt endValue() const {
48.260 + return ValueIt(_inv_map.end());
48.261 }
48.262
48.263 /// \brief Sets the value associated with the given key.
48.264 @@ -2000,11 +2031,15 @@
48.265 /// Sets the value associated with the given key.
48.266 void set(const Key& key, const Value& val) {
48.267 Value oldval = Map::operator[](key);
48.268 - typename Container::iterator it = _inv_map.find(oldval);
48.269 - if (it != _inv_map.end() && it->second == key) {
48.270 - _inv_map.erase(it);
48.271 + typename Container::iterator it;
48.272 + for (it = _inv_map.equal_range(oldval).first;
48.273 + it != _inv_map.equal_range(oldval).second; ++it) {
48.274 + if (it->second == key) {
48.275 + _inv_map.erase(it);
48.276 + break;
48.277 + }
48.278 }
48.279 - _inv_map.insert(make_pair(val, key));
48.280 + _inv_map.insert(std::make_pair(val, key));
48.281 Map::set(key, val);
48.282 }
48.283
48.284 @@ -2016,13 +2051,24 @@
48.285 return Map::operator[](key);
48.286 }
48.287
48.288 - /// \brief Gives back the item by its value.
48.289 + /// \brief Gives back an item by its value.
48.290 ///
48.291 - /// Gives back the item by its value.
48.292 - Key operator()(const Value& key) const {
48.293 - typename Container::const_iterator it = _inv_map.find(key);
48.294 + /// This function gives back an item that is assigned to
48.295 + /// the given value or \c INVALID if no such item exists.
48.296 + /// If there are more items with the same associated value,
48.297 + /// only one of them is returned.
48.298 + Key operator()(const Value& val) const {
48.299 + typename Container::const_iterator it = _inv_map.find(val);
48.300 return it != _inv_map.end() ? it->second : INVALID;
48.301 }
48.302 +
48.303 + /// \brief Returns the number of items with the given value.
48.304 + ///
48.305 + /// This function returns the number of items with the given value
48.306 + /// associated with it.
48.307 + int count(const Value &val) const {
48.308 + return _inv_map.count(val);
48.309 + }
48.310
48.311 protected:
48.312
48.313 @@ -2032,9 +2078,13 @@
48.314 /// \c AlterationNotifier.
48.315 virtual void erase(const Key& key) {
48.316 Value val = Map::operator[](key);
48.317 - typename Container::iterator it = _inv_map.find(val);
48.318 - if (it != _inv_map.end() && it->second == key) {
48.319 - _inv_map.erase(it);
48.320 + typename Container::iterator it;
48.321 + for (it = _inv_map.equal_range(val).first;
48.322 + it != _inv_map.equal_range(val).second; ++it) {
48.323 + if (it->second == key) {
48.324 + _inv_map.erase(it);
48.325 + break;
48.326 + }
48.327 }
48.328 Map::erase(key);
48.329 }
48.330 @@ -2046,9 +2096,13 @@
48.331 virtual void erase(const std::vector<Key>& keys) {
48.332 for (int i = 0; i < int(keys.size()); ++i) {
48.333 Value val = Map::operator[](keys[i]);
48.334 - typename Container::iterator it = _inv_map.find(val);
48.335 - if (it != _inv_map.end() && it->second == keys[i]) {
48.336 - _inv_map.erase(it);
48.337 + typename Container::iterator it;
48.338 + for (it = _inv_map.equal_range(val).first;
48.339 + it != _inv_map.equal_range(val).second; ++it) {
48.340 + if (it->second == keys[i]) {
48.341 + _inv_map.erase(it);
48.342 + break;
48.343 + }
48.344 }
48.345 }
48.346 Map::erase(keys);
48.347 @@ -2065,10 +2119,12 @@
48.348
48.349 public:
48.350
48.351 - /// \brief The inverse map type.
48.352 + /// \brief The inverse map type of CrossRefMap.
48.353 ///
48.354 - /// The inverse of this map. The subscript operator of the map
48.355 - /// gives back the item that was last assigned to the value.
48.356 + /// The inverse map type of CrossRefMap. The subscript operator gives
48.357 + /// back an item by its value.
48.358 + /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
48.359 + /// \see inverse()
48.360 class InverseMap {
48.361 public:
48.362 /// \brief Constructor
48.363 @@ -2084,8 +2140,9 @@
48.364
48.365 /// \brief Subscript operator.
48.366 ///
48.367 - /// Subscript operator. It gives back the item
48.368 - /// that was last assigned to the given value.
48.369 + /// Subscript operator. It gives back an item
48.370 + /// that is assigned to the given value or \c INVALID
48.371 + /// if no such item exists.
48.372 Value operator[](const Key& key) const {
48.373 return _inverted(key);
48.374 }
48.375 @@ -2094,20 +2151,20 @@
48.376 const CrossRefMap& _inverted;
48.377 };
48.378
48.379 - /// \brief It gives back the read-only inverse map.
48.380 + /// \brief Gives back the inverse of the map.
48.381 ///
48.382 - /// It gives back the read-only inverse map.
48.383 + /// Gives back the inverse of the CrossRefMap.
48.384 InverseMap inverse() const {
48.385 return InverseMap(*this);
48.386 }
48.387
48.388 };
48.389
48.390 - /// \brief Provides continuous and unique ID for the
48.391 + /// \brief Provides continuous and unique id for the
48.392 /// items of a graph.
48.393 ///
48.394 /// RangeIdMap provides a unique and continuous
48.395 - /// ID for each item of a given type (\c Node, \c Arc or
48.396 + /// id for each item of a given type (\c Node, \c Arc or
48.397 /// \c Edge) in a graph. This id is
48.398 /// - \b unique: different items get different ids,
48.399 /// - \b continuous: the range of the ids is the set of integers
48.400 @@ -2118,7 +2175,7 @@
48.401 /// Thus this id is not (necessarily) the same as what can get using
48.402 /// the \c id() function of the graph or \ref IdMap.
48.403 /// This map can be inverted with its member class \c InverseMap,
48.404 - /// or with the \c operator() member.
48.405 + /// or with the \c operator()() member.
48.406 ///
48.407 /// \tparam GR The graph type.
48.408 /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
48.409 @@ -2246,16 +2303,16 @@
48.410 _inv_map[pi] = q;
48.411 }
48.412
48.413 - /// \brief Gives back the \e RangeId of the item
48.414 + /// \brief Gives back the \e range \e id of the item
48.415 ///
48.416 - /// Gives back the \e RangeId of the item.
48.417 + /// Gives back the \e range \e id of the item.
48.418 int operator[](const Item& item) const {
48.419 return Map::operator[](item);
48.420 }
48.421
48.422 - /// \brief Gives back the item belonging to a \e RangeId
48.423 - ///
48.424 - /// Gives back the item belonging to a \e RangeId.
48.425 + /// \brief Gives back the item belonging to a \e range \e id
48.426 + ///
48.427 + /// Gives back the item belonging to the given \e range \e id.
48.428 Item operator()(int id) const {
48.429 return _inv_map[id];
48.430 }
48.431 @@ -2269,7 +2326,9 @@
48.432
48.433 /// \brief The inverse map type of RangeIdMap.
48.434 ///
48.435 - /// The inverse map type of RangeIdMap.
48.436 + /// The inverse map type of RangeIdMap. The subscript operator gives
48.437 + /// back an item by its \e range \e id.
48.438 + /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
48.439 class InverseMap {
48.440 public:
48.441 /// \brief Constructor
48.442 @@ -2287,7 +2346,7 @@
48.443 /// \brief Subscript operator.
48.444 ///
48.445 /// Subscript operator. It gives back the item
48.446 - /// that the descriptor currently belongs to.
48.447 + /// that the given \e range \e id currently belongs to.
48.448 Value operator[](const Key& key) const {
48.449 return _inverted(key);
48.450 }
48.451 @@ -2305,12 +2364,932 @@
48.452
48.453 /// \brief Gives back the inverse of the map.
48.454 ///
48.455 - /// Gives back the inverse of the map.
48.456 + /// Gives back the inverse of the RangeIdMap.
48.457 const InverseMap inverse() const {
48.458 return InverseMap(*this);
48.459 }
48.460 };
48.461
48.462 + /// \brief Returns a \c RangeIdMap class.
48.463 + ///
48.464 + /// This function just returns an \c RangeIdMap class.
48.465 + /// \relates RangeIdMap
48.466 + template <typename K, typename GR>
48.467 + inline RangeIdMap<GR, K> rangeIdMap(const GR& graph) {
48.468 + return RangeIdMap<GR, K>(graph);
48.469 + }
48.470 +
48.471 + /// \brief Dynamic iterable \c bool map.
48.472 + ///
48.473 + /// This class provides a special graph map type which can store a
48.474 + /// \c bool value for graph items (\c Node, \c Arc or \c Edge).
48.475 + /// For both \c true and \c false values it is possible to iterate on
48.476 + /// the keys mapped to the value.
48.477 + ///
48.478 + /// This type is a reference map, so it can be modified with the
48.479 + /// subscript operator.
48.480 + ///
48.481 + /// \tparam GR The graph type.
48.482 + /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
48.483 + /// \c GR::Edge).
48.484 + ///
48.485 + /// \see IterableIntMap, IterableValueMap
48.486 + /// \see CrossRefMap
48.487 + template <typename GR, typename K>
48.488 + class IterableBoolMap
48.489 + : protected ItemSetTraits<GR, K>::template Map<int>::Type {
48.490 + private:
48.491 + typedef GR Graph;
48.492 +
48.493 + typedef typename ItemSetTraits<GR, K>::ItemIt KeyIt;
48.494 + typedef typename ItemSetTraits<GR, K>::template Map<int>::Type Parent;
48.495 +
48.496 + std::vector<K> _array;
48.497 + int _sep;
48.498 +
48.499 + public:
48.500 +
48.501 + /// Indicates that the map is reference map.
48.502 + typedef True ReferenceMapTag;
48.503 +
48.504 + /// The key type
48.505 + typedef K Key;
48.506 + /// The value type
48.507 + typedef bool Value;
48.508 + /// The const reference type.
48.509 + typedef const Value& ConstReference;
48.510 +
48.511 + private:
48.512 +
48.513 + int position(const Key& key) const {
48.514 + return Parent::operator[](key);
48.515 + }
48.516 +
48.517 + public:
48.518 +
48.519 + /// \brief Reference to the value of the map.
48.520 + ///
48.521 + /// This class is similar to the \c bool type. It can be converted to
48.522 + /// \c bool and it provides the same operators.
48.523 + class Reference {
48.524 + friend class IterableBoolMap;
48.525 + private:
48.526 + Reference(IterableBoolMap& map, const Key& key)
48.527 + : _key(key), _map(map) {}
48.528 + public:
48.529 +
48.530 + Reference& operator=(const Reference& value) {
48.531 + _map.set(_key, static_cast<bool>(value));
48.532 + return *this;
48.533 + }
48.534 +
48.535 + operator bool() const {
48.536 + return static_cast<const IterableBoolMap&>(_map)[_key];
48.537 + }
48.538 +
48.539 + Reference& operator=(bool value) {
48.540 + _map.set(_key, value);
48.541 + return *this;
48.542 + }
48.543 + Reference& operator&=(bool value) {
48.544 + _map.set(_key, _map[_key] & value);
48.545 + return *this;
48.546 + }
48.547 + Reference& operator|=(bool value) {
48.548 + _map.set(_key, _map[_key] | value);
48.549 + return *this;
48.550 + }
48.551 + Reference& operator^=(bool value) {
48.552 + _map.set(_key, _map[_key] ^ value);
48.553 + return *this;
48.554 + }
48.555 + private:
48.556 + Key _key;
48.557 + IterableBoolMap& _map;
48.558 + };
48.559 +
48.560 + /// \brief Constructor of the map with a default value.
48.561 + ///
48.562 + /// Constructor of the map with a default value.
48.563 + explicit IterableBoolMap(const Graph& graph, bool def = false)
48.564 + : Parent(graph) {
48.565 + typename Parent::Notifier* nf = Parent::notifier();
48.566 + Key it;
48.567 + for (nf->first(it); it != INVALID; nf->next(it)) {
48.568 + Parent::set(it, _array.size());
48.569 + _array.push_back(it);
48.570 + }
48.571 + _sep = (def ? _array.size() : 0);
48.572 + }
48.573 +
48.574 + /// \brief Const subscript operator of the map.
48.575 + ///
48.576 + /// Const subscript operator of the map.
48.577 + bool operator[](const Key& key) const {
48.578 + return position(key) < _sep;
48.579 + }
48.580 +
48.581 + /// \brief Subscript operator of the map.
48.582 + ///
48.583 + /// Subscript operator of the map.
48.584 + Reference operator[](const Key& key) {
48.585 + return Reference(*this, key);
48.586 + }
48.587 +
48.588 + /// \brief Set operation of the map.
48.589 + ///
48.590 + /// Set operation of the map.
48.591 + void set(const Key& key, bool value) {
48.592 + int pos = position(key);
48.593 + if (value) {
48.594 + if (pos < _sep) return;
48.595 + Key tmp = _array[_sep];
48.596 + _array[_sep] = key;
48.597 + Parent::set(key, _sep);
48.598 + _array[pos] = tmp;
48.599 + Parent::set(tmp, pos);
48.600 + ++_sep;
48.601 + } else {
48.602 + if (pos >= _sep) return;
48.603 + --_sep;
48.604 + Key tmp = _array[_sep];
48.605 + _array[_sep] = key;
48.606 + Parent::set(key, _sep);
48.607 + _array[pos] = tmp;
48.608 + Parent::set(tmp, pos);
48.609 + }
48.610 + }
48.611 +
48.612 + /// \brief Set all items.
48.613 + ///
48.614 + /// Set all items in the map.
48.615 + /// \note Constant time operation.
48.616 + void setAll(bool value) {
48.617 + _sep = (value ? _array.size() : 0);
48.618 + }
48.619 +
48.620 + /// \brief Returns the number of the keys mapped to \c true.
48.621 + ///
48.622 + /// Returns the number of the keys mapped to \c true.
48.623 + int trueNum() const {
48.624 + return _sep;
48.625 + }
48.626 +
48.627 + /// \brief Returns the number of the keys mapped to \c false.
48.628 + ///
48.629 + /// Returns the number of the keys mapped to \c false.
48.630 + int falseNum() const {
48.631 + return _array.size() - _sep;
48.632 + }
48.633 +
48.634 + /// \brief Iterator for the keys mapped to \c true.
48.635 + ///
48.636 + /// Iterator for the keys mapped to \c true. It works
48.637 + /// like a graph item iterator, it can be converted to
48.638 + /// the key type of the map, incremented with \c ++ operator, and
48.639 + /// if the iterator leaves the last valid key, it will be equal to
48.640 + /// \c INVALID.
48.641 + class TrueIt : public Key {
48.642 + public:
48.643 + typedef Key Parent;
48.644 +
48.645 + /// \brief Creates an iterator.
48.646 + ///
48.647 + /// Creates an iterator. It iterates on the
48.648 + /// keys mapped to \c true.
48.649 + /// \param map The IterableBoolMap.
48.650 + explicit TrueIt(const IterableBoolMap& map)
48.651 + : Parent(map._sep > 0 ? map._array[map._sep - 1] : INVALID),
48.652 + _map(&map) {}
48.653 +
48.654 + /// \brief Invalid constructor \& conversion.
48.655 + ///
48.656 + /// This constructor initializes the iterator to be invalid.
48.657 + /// \sa Invalid for more details.
48.658 + TrueIt(Invalid) : Parent(INVALID), _map(0) {}
48.659 +
48.660 + /// \brief Increment operator.
48.661 + ///
48.662 + /// Increment operator.
48.663 + TrueIt& operator++() {
48.664 + int pos = _map->position(*this);
48.665 + Parent::operator=(pos > 0 ? _map->_array[pos - 1] : INVALID);
48.666 + return *this;
48.667 + }
48.668 +
48.669 + private:
48.670 + const IterableBoolMap* _map;
48.671 + };
48.672 +
48.673 + /// \brief Iterator for the keys mapped to \c false.
48.674 + ///
48.675 + /// Iterator for the keys mapped to \c false. It works
48.676 + /// like a graph item iterator, it can be converted to
48.677 + /// the key type of the map, incremented with \c ++ operator, and
48.678 + /// if the iterator leaves the last valid key, it will be equal to
48.679 + /// \c INVALID.
48.680 + class FalseIt : public Key {
48.681 + public:
48.682 + typedef Key Parent;
48.683 +
48.684 + /// \brief Creates an iterator.
48.685 + ///
48.686 + /// Creates an iterator. It iterates on the
48.687 + /// keys mapped to \c false.
48.688 + /// \param map The IterableBoolMap.
48.689 + explicit FalseIt(const IterableBoolMap& map)
48.690 + : Parent(map._sep < int(map._array.size()) ?
48.691 + map._array.back() : INVALID), _map(&map) {}
48.692 +
48.693 + /// \brief Invalid constructor \& conversion.
48.694 + ///
48.695 + /// This constructor initializes the iterator to be invalid.
48.696 + /// \sa Invalid for more details.
48.697 + FalseIt(Invalid) : Parent(INVALID), _map(0) {}
48.698 +
48.699 + /// \brief Increment operator.
48.700 + ///
48.701 + /// Increment operator.
48.702 + FalseIt& operator++() {
48.703 + int pos = _map->position(*this);
48.704 + Parent::operator=(pos > _map->_sep ? _map->_array[pos - 1] : INVALID);
48.705 + return *this;
48.706 + }
48.707 +
48.708 + private:
48.709 + const IterableBoolMap* _map;
48.710 + };
48.711 +
48.712 + /// \brief Iterator for the keys mapped to a given value.
48.713 + ///
48.714 + /// Iterator for the keys mapped to a given value. It works
48.715 + /// like a graph item iterator, it can be converted to
48.716 + /// the key type of the map, incremented with \c ++ operator, and
48.717 + /// if the iterator leaves the last valid key, it will be equal to
48.718 + /// \c INVALID.
48.719 + class ItemIt : public Key {
48.720 + public:
48.721 + typedef Key Parent;
48.722 +
48.723 + /// \brief Creates an iterator with a value.
48.724 + ///
48.725 + /// Creates an iterator with a value. It iterates on the
48.726 + /// keys mapped to the given value.
48.727 + /// \param map The IterableBoolMap.
48.728 + /// \param value The value.
48.729 + ItemIt(const IterableBoolMap& map, bool value)
48.730 + : Parent(value ?
48.731 + (map._sep > 0 ?
48.732 + map._array[map._sep - 1] : INVALID) :
48.733 + (map._sep < int(map._array.size()) ?
48.734 + map._array.back() : INVALID)), _map(&map) {}
48.735 +
48.736 + /// \brief Invalid constructor \& conversion.
48.737 + ///
48.738 + /// This constructor initializes the iterator to be invalid.
48.739 + /// \sa Invalid for more details.
48.740 + ItemIt(Invalid) : Parent(INVALID), _map(0) {}
48.741 +
48.742 + /// \brief Increment operator.
48.743 + ///
48.744 + /// Increment operator.
48.745 + ItemIt& operator++() {
48.746 + int pos = _map->position(*this);
48.747 + int _sep = pos >= _map->_sep ? _map->_sep : 0;
48.748 + Parent::operator=(pos > _sep ? _map->_array[pos - 1] : INVALID);
48.749 + return *this;
48.750 + }
48.751 +
48.752 + private:
48.753 + const IterableBoolMap* _map;
48.754 + };
48.755 +
48.756 + protected:
48.757 +
48.758 + virtual void add(const Key& key) {
48.759 + Parent::add(key);
48.760 + Parent::set(key, _array.size());
48.761 + _array.push_back(key);
48.762 + }
48.763 +
48.764 + virtual void add(const std::vector<Key>& keys) {
48.765 + Parent::add(keys);
48.766 + for (int i = 0; i < int(keys.size()); ++i) {
48.767 + Parent::set(keys[i], _array.size());
48.768 + _array.push_back(keys[i]);
48.769 + }
48.770 + }
48.771 +
48.772 + virtual void erase(const Key& key) {
48.773 + int pos = position(key);
48.774 + if (pos < _sep) {
48.775 + --_sep;
48.776 + Parent::set(_array[_sep], pos);
48.777 + _array[pos] = _array[_sep];
48.778 + Parent::set(_array.back(), _sep);
48.779 + _array[_sep] = _array.back();
48.780 + _array.pop_back();
48.781 + } else {
48.782 + Parent::set(_array.back(), pos);
48.783 + _array[pos] = _array.back();
48.784 + _array.pop_back();
48.785 + }
48.786 + Parent::erase(key);
48.787 + }
48.788 +
48.789 + virtual void erase(const std::vector<Key>& keys) {
48.790 + for (int i = 0; i < int(keys.size()); ++i) {
48.791 + int pos = position(keys[i]);
48.792 + if (pos < _sep) {
48.793 + --_sep;
48.794 + Parent::set(_array[_sep], pos);
48.795 + _array[pos] = _array[_sep];
48.796 + Parent::set(_array.back(), _sep);
48.797 + _array[_sep] = _array.back();
48.798 + _array.pop_back();
48.799 + } else {
48.800 + Parent::set(_array.back(), pos);
48.801 + _array[pos] = _array.back();
48.802 + _array.pop_back();
48.803 + }
48.804 + }
48.805 + Parent::erase(keys);
48.806 + }
48.807 +
48.808 + virtual void build() {
48.809 + Parent::build();
48.810 + typename Parent::Notifier* nf = Parent::notifier();
48.811 + Key it;
48.812 + for (nf->first(it); it != INVALID; nf->next(it)) {
48.813 + Parent::set(it, _array.size());
48.814 + _array.push_back(it);
48.815 + }
48.816 + _sep = 0;
48.817 + }
48.818 +
48.819 + virtual void clear() {
48.820 + _array.clear();
48.821 + _sep = 0;
48.822 + Parent::clear();
48.823 + }
48.824 +
48.825 + };
48.826 +
48.827 +
48.828 + namespace _maps_bits {
48.829 + template <typename Item>
48.830 + struct IterableIntMapNode {
48.831 + IterableIntMapNode() : value(-1) {}
48.832 + IterableIntMapNode(int _value) : value(_value) {}
48.833 + Item prev, next;
48.834 + int value;
48.835 + };
48.836 + }
48.837 +
48.838 + /// \brief Dynamic iterable integer map.
48.839 + ///
48.840 + /// This class provides a special graph map type which can store an
48.841 + /// integer value for graph items (\c Node, \c Arc or \c Edge).
48.842 + /// For each non-negative value it is possible to iterate on the keys
48.843 + /// mapped to the value.
48.844 + ///
48.845 + /// This map is intended to be used with small integer values, for which
48.846 + /// it is efficient, and supports iteration only for non-negative values.
48.847 + /// If you need large values and/or iteration for negative integers,
48.848 + /// consider to use \ref IterableValueMap instead.
48.849 + ///
48.850 + /// This type is a reference map, so it can be modified with the
48.851 + /// subscript operator.
48.852 + ///
48.853 + /// \note The size of the data structure depends on the largest
48.854 + /// value in the map.
48.855 + ///
48.856 + /// \tparam GR The graph type.
48.857 + /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
48.858 + /// \c GR::Edge).
48.859 + ///
48.860 + /// \see IterableBoolMap, IterableValueMap
48.861 + /// \see CrossRefMap
48.862 + template <typename GR, typename K>
48.863 + class IterableIntMap
48.864 + : protected ItemSetTraits<GR, K>::
48.865 + template Map<_maps_bits::IterableIntMapNode<K> >::Type {
48.866 + public:
48.867 + typedef typename ItemSetTraits<GR, K>::
48.868 + template Map<_maps_bits::IterableIntMapNode<K> >::Type Parent;
48.869 +
48.870 + /// The key type
48.871 + typedef K Key;
48.872 + /// The value type
48.873 + typedef int Value;
48.874 + /// The graph type
48.875 + typedef GR Graph;
48.876 +
48.877 + /// \brief Constructor of the map.
48.878 + ///
48.879 + /// Constructor of the map. It sets all values to -1.
48.880 + explicit IterableIntMap(const Graph& graph)
48.881 + : Parent(graph) {}
48.882 +
48.883 + /// \brief Constructor of the map with a given value.
48.884 + ///
48.885 + /// Constructor of the map with a given value.
48.886 + explicit IterableIntMap(const Graph& graph, int value)
48.887 + : Parent(graph, _maps_bits::IterableIntMapNode<K>(value)) {
48.888 + if (value >= 0) {
48.889 + for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
48.890 + lace(it);
48.891 + }
48.892 + }
48.893 + }
48.894 +
48.895 + private:
48.896 +
48.897 + void unlace(const Key& key) {
48.898 + typename Parent::Value& node = Parent::operator[](key);
48.899 + if (node.value < 0) return;
48.900 + if (node.prev != INVALID) {
48.901 + Parent::operator[](node.prev).next = node.next;
48.902 + } else {
48.903 + _first[node.value] = node.next;
48.904 + }
48.905 + if (node.next != INVALID) {
48.906 + Parent::operator[](node.next).prev = node.prev;
48.907 + }
48.908 + while (!_first.empty() && _first.back() == INVALID) {
48.909 + _first.pop_back();
48.910 + }
48.911 + }
48.912 +
48.913 + void lace(const Key& key) {
48.914 + typename Parent::Value& node = Parent::operator[](key);
48.915 + if (node.value < 0) return;
48.916 + if (node.value >= int(_first.size())) {
48.917 + _first.resize(node.value + 1, INVALID);
48.918 + }
48.919 + node.prev = INVALID;
48.920 + node.next = _first[node.value];
48.921 + if (node.next != INVALID) {
48.922 + Parent::operator[](node.next).prev = key;
48.923 + }
48.924 + _first[node.value] = key;
48.925 + }
48.926 +
48.927 + public:
48.928 +
48.929 + /// Indicates that the map is reference map.
48.930 + typedef True ReferenceMapTag;
48.931 +
48.932 + /// \brief Reference to the value of the map.
48.933 + ///
48.934 + /// This class is similar to the \c int type. It can
48.935 + /// be converted to \c int and it has the same operators.
48.936 + class Reference {
48.937 + friend class IterableIntMap;
48.938 + private:
48.939 + Reference(IterableIntMap& map, const Key& key)
48.940 + : _key(key), _map(map) {}
48.941 + public:
48.942 +
48.943 + Reference& operator=(const Reference& value) {
48.944 + _map.set(_key, static_cast<const int&>(value));
48.945 + return *this;
48.946 + }
48.947 +
48.948 + operator const int&() const {
48.949 + return static_cast<const IterableIntMap&>(_map)[_key];
48.950 + }
48.951 +
48.952 + Reference& operator=(int value) {
48.953 + _map.set(_key, value);
48.954 + return *this;
48.955 + }
48.956 + Reference& operator++() {
48.957 + _map.set(_key, _map[_key] + 1);
48.958 + return *this;
48.959 + }
48.960 + int operator++(int) {
48.961 + int value = _map[_key];
48.962 + _map.set(_key, value + 1);
48.963 + return value;
48.964 + }
48.965 + Reference& operator--() {
48.966 + _map.set(_key, _map[_key] - 1);
48.967 + return *this;
48.968 + }
48.969 + int operator--(int) {
48.970 + int value = _map[_key];
48.971 + _map.set(_key, value - 1);
48.972 + return value;
48.973 + }
48.974 + Reference& operator+=(int value) {
48.975 + _map.set(_key, _map[_key] + value);
48.976 + return *this;
48.977 + }
48.978 + Reference& operator-=(int value) {
48.979 + _map.set(_key, _map[_key] - value);
48.980 + return *this;
48.981 + }
48.982 + Reference& operator*=(int value) {
48.983 + _map.set(_key, _map[_key] * value);
48.984 + return *this;
48.985 + }
48.986 + Reference& operator/=(int value) {
48.987 + _map.set(_key, _map[_key] / value);
48.988 + return *this;
48.989 + }
48.990 + Reference& operator%=(int value) {
48.991 + _map.set(_key, _map[_key] % value);
48.992 + return *this;
48.993 + }
48.994 + Reference& operator&=(int value) {
48.995 + _map.set(_key, _map[_key] & value);
48.996 + return *this;
48.997 + }
48.998 + Reference& operator|=(int value) {
48.999 + _map.set(_key, _map[_key] | value);
48.1000 + return *this;
48.1001 + }
48.1002 + Reference& operator^=(int value) {
48.1003 + _map.set(_key, _map[_key] ^ value);
48.1004 + return *this;
48.1005 + }
48.1006 + Reference& operator<<=(int value) {
48.1007 + _map.set(_key, _map[_key] << value);
48.1008 + return *this;
48.1009 + }
48.1010 + Reference& operator>>=(int value) {
48.1011 + _map.set(_key, _map[_key] >> value);
48.1012 + return *this;
48.1013 + }
48.1014 +
48.1015 + private:
48.1016 + Key _key;
48.1017 + IterableIntMap& _map;
48.1018 + };
48.1019 +
48.1020 + /// The const reference type.
48.1021 + typedef const Value& ConstReference;
48.1022 +
48.1023 + /// \brief Gives back the maximal value plus one.
48.1024 + ///
48.1025 + /// Gives back the maximal value plus one.
48.1026 + int size() const {
48.1027 + return _first.size();
48.1028 + }
48.1029 +
48.1030 + /// \brief Set operation of the map.
48.1031 + ///
48.1032 + /// Set operation of the map.
48.1033 + void set(const Key& key, const Value& value) {
48.1034 + unlace(key);
48.1035 + Parent::operator[](key).value = value;
48.1036 + lace(key);
48.1037 + }
48.1038 +
48.1039 + /// \brief Const subscript operator of the map.
48.1040 + ///
48.1041 + /// Const subscript operator of the map.
48.1042 + const Value& operator[](const Key& key) const {
48.1043 + return Parent::operator[](key).value;
48.1044 + }
48.1045 +
48.1046 + /// \brief Subscript operator of the map.
48.1047 + ///
48.1048 + /// Subscript operator of the map.
48.1049 + Reference operator[](const Key& key) {
48.1050 + return Reference(*this, key);
48.1051 + }
48.1052 +
48.1053 + /// \brief Iterator for the keys with the same value.
48.1054 + ///
48.1055 + /// Iterator for the keys with the same value. It works
48.1056 + /// like a graph item iterator, it can be converted to
48.1057 + /// the item type of the map, incremented with \c ++ operator, and
48.1058 + /// if the iterator leaves the last valid item, it will be equal to
48.1059 + /// \c INVALID.
48.1060 + class ItemIt : public Key {
48.1061 + public:
48.1062 + typedef Key Parent;
48.1063 +
48.1064 + /// \brief Invalid constructor \& conversion.
48.1065 + ///
48.1066 + /// This constructor initializes the iterator to be invalid.
48.1067 + /// \sa Invalid for more details.
48.1068 + ItemIt(Invalid) : Parent(INVALID), _map(0) {}
48.1069 +
48.1070 + /// \brief Creates an iterator with a value.
48.1071 + ///
48.1072 + /// Creates an iterator with a value. It iterates on the
48.1073 + /// keys mapped to the given value.
48.1074 + /// \param map The IterableIntMap.
48.1075 + /// \param value The value.
48.1076 + ItemIt(const IterableIntMap& map, int value) : _map(&map) {
48.1077 + if (value < 0 || value >= int(_map->_first.size())) {
48.1078 + Parent::operator=(INVALID);
48.1079 + } else {
48.1080 + Parent::operator=(_map->_first[value]);
48.1081 + }
48.1082 + }
48.1083 +
48.1084 + /// \brief Increment operator.
48.1085 + ///
48.1086 + /// Increment operator.
48.1087 + ItemIt& operator++() {
48.1088 + Parent::operator=(_map->IterableIntMap::Parent::
48.1089 + operator[](static_cast<Parent&>(*this)).next);
48.1090 + return *this;
48.1091 + }
48.1092 +
48.1093 + private:
48.1094 + const IterableIntMap* _map;
48.1095 + };
48.1096 +
48.1097 + protected:
48.1098 +
48.1099 + virtual void erase(const Key& key) {
48.1100 + unlace(key);
48.1101 + Parent::erase(key);
48.1102 + }
48.1103 +
48.1104 + virtual void erase(const std::vector<Key>& keys) {
48.1105 + for (int i = 0; i < int(keys.size()); ++i) {
48.1106 + unlace(keys[i]);
48.1107 + }
48.1108 + Parent::erase(keys);
48.1109 + }
48.1110 +
48.1111 + virtual void clear() {
48.1112 + _first.clear();
48.1113 + Parent::clear();
48.1114 + }
48.1115 +
48.1116 + private:
48.1117 + std::vector<Key> _first;
48.1118 + };
48.1119 +
48.1120 + namespace _maps_bits {
48.1121 + template <typename Item, typename Value>
48.1122 + struct IterableValueMapNode {
48.1123 + IterableValueMapNode(Value _value = Value()) : value(_value) {}
48.1124 + Item prev, next;
48.1125 + Value value;
48.1126 + };
48.1127 + }
48.1128 +
48.1129 + /// \brief Dynamic iterable map for comparable values.
48.1130 + ///
48.1131 + /// This class provides a special graph map type which can store a
48.1132 + /// comparable value for graph items (\c Node, \c Arc or \c Edge).
48.1133 + /// For each value it is possible to iterate on the keys mapped to
48.1134 + /// the value (\c ItemIt), and the values of the map can be accessed
48.1135 + /// with an STL compatible forward iterator (\c ValueIt).
48.1136 + /// The map stores a linked list for each value, which contains
48.1137 + /// the items mapped to the value, and the used values are stored
48.1138 + /// in balanced binary tree (\c std::map).
48.1139 + ///
48.1140 + /// \ref IterableBoolMap and \ref IterableIntMap are similar classes
48.1141 + /// specialized for \c bool and \c int values, respectively.
48.1142 + ///
48.1143 + /// This type is not reference map, so it cannot be modified with
48.1144 + /// the subscript operator.
48.1145 + ///
48.1146 + /// \tparam GR The graph type.
48.1147 + /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
48.1148 + /// \c GR::Edge).
48.1149 + /// \tparam V The value type of the map. It can be any comparable
48.1150 + /// value type.
48.1151 + ///
48.1152 + /// \see IterableBoolMap, IterableIntMap
48.1153 + /// \see CrossRefMap
48.1154 + template <typename GR, typename K, typename V>
48.1155 + class IterableValueMap
48.1156 + : protected ItemSetTraits<GR, K>::
48.1157 + template Map<_maps_bits::IterableValueMapNode<K, V> >::Type {
48.1158 + public:
48.1159 + typedef typename ItemSetTraits<GR, K>::
48.1160 + template Map<_maps_bits::IterableValueMapNode<K, V> >::Type Parent;
48.1161 +
48.1162 + /// The key type
48.1163 + typedef K Key;
48.1164 + /// The value type
48.1165 + typedef V Value;
48.1166 + /// The graph type
48.1167 + typedef GR Graph;
48.1168 +
48.1169 + public:
48.1170 +
48.1171 + /// \brief Constructor of the map with a given value.
48.1172 + ///
48.1173 + /// Constructor of the map with a given value.
48.1174 + explicit IterableValueMap(const Graph& graph,
48.1175 + const Value& value = Value())
48.1176 + : Parent(graph, _maps_bits::IterableValueMapNode<K, V>(value)) {
48.1177 + for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
48.1178 + lace(it);
48.1179 + }
48.1180 + }
48.1181 +
48.1182 + protected:
48.1183 +
48.1184 + void unlace(const Key& key) {
48.1185 + typename Parent::Value& node = Parent::operator[](key);
48.1186 + if (node.prev != INVALID) {
48.1187 + Parent::operator[](node.prev).next = node.next;
48.1188 + } else {
48.1189 + if (node.next != INVALID) {
48.1190 + _first[node.value] = node.next;
48.1191 + } else {
48.1192 + _first.erase(node.value);
48.1193 + }
48.1194 + }
48.1195 + if (node.next != INVALID) {
48.1196 + Parent::operator[](node.next).prev = node.prev;
48.1197 + }
48.1198 + }
48.1199 +
48.1200 + void lace(const Key& key) {
48.1201 + typename Parent::Value& node = Parent::operator[](key);
48.1202 + typename std::map<Value, Key>::iterator it = _first.find(node.value);
48.1203 + if (it == _first.end()) {
48.1204 + node.prev = node.next = INVALID;
48.1205 + _first.insert(std::make_pair(node.value, key));
48.1206 + } else {
48.1207 + node.prev = INVALID;
48.1208 + node.next = it->second;
48.1209 + if (node.next != INVALID) {
48.1210 + Parent::operator[](node.next).prev = key;
48.1211 + }
48.1212 + it->second = key;
48.1213 + }
48.1214 + }
48.1215 +
48.1216 + public:
48.1217 +
48.1218 + /// \brief Forward iterator for values.
48.1219 + ///
48.1220 + /// This iterator is an STL compatible forward
48.1221 + /// iterator on the values of the map. The values can
48.1222 + /// be accessed in the <tt>[beginValue, endValue)</tt> range.
48.1223 + class ValueIt
48.1224 + : public std::iterator<std::forward_iterator_tag, Value> {
48.1225 + friend class IterableValueMap;
48.1226 + private:
48.1227 + ValueIt(typename std::map<Value, Key>::const_iterator _it)
48.1228 + : it(_it) {}
48.1229 + public:
48.1230 +
48.1231 + /// Constructor
48.1232 + ValueIt() {}
48.1233 +
48.1234 + /// \e
48.1235 + ValueIt& operator++() { ++it; return *this; }
48.1236 + /// \e
48.1237 + ValueIt operator++(int) {
48.1238 + ValueIt tmp(*this);
48.1239 + operator++();
48.1240 + return tmp;
48.1241 + }
48.1242 +
48.1243 + /// \e
48.1244 + const Value& operator*() const { return it->first; }
48.1245 + /// \e
48.1246 + const Value* operator->() const { return &(it->first); }
48.1247 +
48.1248 + /// \e
48.1249 + bool operator==(ValueIt jt) const { return it == jt.it; }
48.1250 + /// \e
48.1251 + bool operator!=(ValueIt jt) const { return it != jt.it; }
48.1252 +
48.1253 + private:
48.1254 + typename std::map<Value, Key>::const_iterator it;
48.1255 + };
48.1256 +
48.1257 + /// \brief Returns an iterator to the first value.
48.1258 + ///
48.1259 + /// Returns an STL compatible iterator to the
48.1260 + /// first value of the map. The values of the
48.1261 + /// map can be accessed in the <tt>[beginValue, endValue)</tt>
48.1262 + /// range.
48.1263 + ValueIt beginValue() const {
48.1264 + return ValueIt(_first.begin());
48.1265 + }
48.1266 +
48.1267 + /// \brief Returns an iterator after the last value.
48.1268 + ///
48.1269 + /// Returns an STL compatible iterator after the
48.1270 + /// last value of the map. The values of the
48.1271 + /// map can be accessed in the <tt>[beginValue, endValue)</tt>
48.1272 + /// range.
48.1273 + ValueIt endValue() const {
48.1274 + return ValueIt(_first.end());
48.1275 + }
48.1276 +
48.1277 + /// \brief Set operation of the map.
48.1278 + ///
48.1279 + /// Set operation of the map.
48.1280 + void set(const Key& key, const Value& value) {
48.1281 + unlace(key);
48.1282 + Parent::operator[](key).value = value;
48.1283 + lace(key);
48.1284 + }
48.1285 +
48.1286 + /// \brief Const subscript operator of the map.
48.1287 + ///
48.1288 + /// Const subscript operator of the map.
48.1289 + const Value& operator[](const Key& key) const {
48.1290 + return Parent::operator[](key).value;
48.1291 + }
48.1292 +
48.1293 + /// \brief Iterator for the keys with the same value.
48.1294 + ///
48.1295 + /// Iterator for the keys with the same value. It works
48.1296 + /// like a graph item iterator, it can be converted to
48.1297 + /// the item type of the map, incremented with \c ++ operator, and
48.1298 + /// if the iterator leaves the last valid item, it will be equal to
48.1299 + /// \c INVALID.
48.1300 + class ItemIt : public Key {
48.1301 + public:
48.1302 + typedef Key Parent;
48.1303 +
48.1304 + /// \brief Invalid constructor \& conversion.
48.1305 + ///
48.1306 + /// This constructor initializes the iterator to be invalid.
48.1307 + /// \sa Invalid for more details.
48.1308 + ItemIt(Invalid) : Parent(INVALID), _map(0) {}
48.1309 +
48.1310 + /// \brief Creates an iterator with a value.
48.1311 + ///
48.1312 + /// Creates an iterator with a value. It iterates on the
48.1313 + /// keys which have the given value.
48.1314 + /// \param map The IterableValueMap
48.1315 + /// \param value The value
48.1316 + ItemIt(const IterableValueMap& map, const Value& value) : _map(&map) {
48.1317 + typename std::map<Value, Key>::const_iterator it =
48.1318 + map._first.find(value);
48.1319 + if (it == map._first.end()) {
48.1320 + Parent::operator=(INVALID);
48.1321 + } else {
48.1322 + Parent::operator=(it->second);
48.1323 + }
48.1324 + }
48.1325 +
48.1326 + /// \brief Increment operator.
48.1327 + ///
48.1328 + /// Increment Operator.
48.1329 + ItemIt& operator++() {
48.1330 + Parent::operator=(_map->IterableValueMap::Parent::
48.1331 + operator[](static_cast<Parent&>(*this)).next);
48.1332 + return *this;
48.1333 + }
48.1334 +
48.1335 +
48.1336 + private:
48.1337 + const IterableValueMap* _map;
48.1338 + };
48.1339 +
48.1340 + protected:
48.1341 +
48.1342 + virtual void add(const Key& key) {
48.1343 + Parent::add(key);
48.1344 + unlace(key);
48.1345 + }
48.1346 +
48.1347 + virtual void add(const std::vector<Key>& keys) {
48.1348 + Parent::add(keys);
48.1349 + for (int i = 0; i < int(keys.size()); ++i) {
48.1350 + lace(keys[i]);
48.1351 + }
48.1352 + }
48.1353 +
48.1354 + virtual void erase(const Key& key) {
48.1355 + unlace(key);
48.1356 + Parent::erase(key);
48.1357 + }
48.1358 +
48.1359 + virtual void erase(const std::vector<Key>& keys) {
48.1360 + for (int i = 0; i < int(keys.size()); ++i) {
48.1361 + unlace(keys[i]);
48.1362 + }
48.1363 + Parent::erase(keys);
48.1364 + }
48.1365 +
48.1366 + virtual void build() {
48.1367 + Parent::build();
48.1368 + for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
48.1369 + lace(it);
48.1370 + }
48.1371 + }
48.1372 +
48.1373 + virtual void clear() {
48.1374 + _first.clear();
48.1375 + Parent::clear();
48.1376 + }
48.1377 +
48.1378 + private:
48.1379 + std::map<Value, Key> _first;
48.1380 + };
48.1381 +
48.1382 /// \brief Map of the source nodes of arcs in a digraph.
48.1383 ///
48.1384 /// SourceMap provides access for the source node of each arc in a digraph,
48.1385 @@ -2321,9 +3300,9 @@
48.1386 class SourceMap {
48.1387 public:
48.1388
48.1389 - ///\e
48.1390 + /// The key type (the \c Arc type of the digraph).
48.1391 typedef typename GR::Arc Key;
48.1392 - ///\e
48.1393 + /// The value type (the \c Node type of the digraph).
48.1394 typedef typename GR::Node Value;
48.1395
48.1396 /// \brief Constructor
48.1397 @@ -2362,9 +3341,9 @@
48.1398 class TargetMap {
48.1399 public:
48.1400
48.1401 - ///\e
48.1402 + /// The key type (the \c Arc type of the digraph).
48.1403 typedef typename GR::Arc Key;
48.1404 - ///\e
48.1405 + /// The value type (the \c Node type of the digraph).
48.1406 typedef typename GR::Node Value;
48.1407
48.1408 /// \brief Constructor
48.1409 @@ -2404,8 +3383,10 @@
48.1410 class ForwardMap {
48.1411 public:
48.1412
48.1413 + /// The key type (the \c Edge type of the digraph).
48.1414 + typedef typename GR::Edge Key;
48.1415 + /// The value type (the \c Arc type of the digraph).
48.1416 typedef typename GR::Arc Value;
48.1417 - typedef typename GR::Edge Key;
48.1418
48.1419 /// \brief Constructor
48.1420 ///
48.1421 @@ -2444,8 +3425,10 @@
48.1422 class BackwardMap {
48.1423 public:
48.1424
48.1425 + /// The key type (the \c Edge type of the digraph).
48.1426 + typedef typename GR::Edge Key;
48.1427 + /// The value type (the \c Arc type of the digraph).
48.1428 typedef typename GR::Arc Value;
48.1429 - typedef typename GR::Edge Key;
48.1430
48.1431 /// \brief Constructor
48.1432 ///
48.1433 @@ -2480,7 +3463,7 @@
48.1434 /// in constant time. On the other hand, the values are updated automatically
48.1435 /// whenever the digraph changes.
48.1436 ///
48.1437 - /// \warning Besides \c addNode() and \c addArc(), a digraph structure
48.1438 + /// \warning Besides \c addNode() and \c addArc(), a digraph structure
48.1439 /// may provide alternative ways to modify the digraph.
48.1440 /// The correct behavior of InDegMap is not guarantied if these additional
48.1441 /// features are used. For example the functions
48.1442 @@ -2496,7 +3479,7 @@
48.1443 ::ItemNotifier::ObserverBase {
48.1444
48.1445 public:
48.1446 -
48.1447 +
48.1448 /// The graph type of InDegMap
48.1449 typedef GR Graph;
48.1450 typedef GR Digraph;
48.1451 @@ -2610,7 +3593,7 @@
48.1452 /// in constant time. On the other hand, the values are updated automatically
48.1453 /// whenever the digraph changes.
48.1454 ///
48.1455 - /// \warning Besides \c addNode() and \c addArc(), a digraph structure
48.1456 + /// \warning Besides \c addNode() and \c addArc(), a digraph structure
48.1457 /// may provide alternative ways to modify the digraph.
48.1458 /// The correct behavior of OutDegMap is not guarantied if these additional
48.1459 /// features are used. For example the functions
49.1 --- a/lemon/min_cost_arborescence.h Tue Aug 18 10:08:28 2009 +0200
49.2 +++ b/lemon/min_cost_arborescence.h Thu Nov 05 08:39:49 2009 +0100
49.3 @@ -488,8 +488,8 @@
49.4 /// \name Execution Control
49.5 /// The simplest way to execute the algorithm is to use
49.6 /// one of the member functions called \c run(...). \n
49.7 - /// If you need more control on the execution,
49.8 - /// first you must call \ref init(), then you can add several
49.9 + /// If you need better control on the execution,
49.10 + /// you have to call \ref init() first, then you can add several
49.11 /// source nodes with \ref addSource().
49.12 /// Finally \ref start() will perform the arborescence
49.13 /// computation.
50.1 --- a/lemon/network_simplex.h Tue Aug 18 10:08:28 2009 +0200
50.2 +++ b/lemon/network_simplex.h Thu Nov 05 08:39:49 2009 +0100
50.3 @@ -40,7 +40,9 @@
50.4 /// for finding a \ref min_cost_flow "minimum cost flow".
50.5 ///
50.6 /// \ref NetworkSimplex implements the primal Network Simplex algorithm
50.7 - /// for finding a \ref min_cost_flow "minimum cost flow".
50.8 + /// for finding a \ref min_cost_flow "minimum cost flow"
50.9 + /// \ref amo93networkflows, \ref dantzig63linearprog,
50.10 + /// \ref kellyoneill91netsimplex.
50.11 /// This algorithm is a specialized version of the linear programming
50.12 /// simplex method directly for the minimum cost flow problem.
50.13 /// It is one of the most efficient solution methods.
50.14 @@ -161,8 +163,6 @@
50.15
50.16 TEMPLATE_DIGRAPH_TYPEDEFS(GR);
50.17
50.18 - typedef std::vector<Arc> ArcVector;
50.19 - typedef std::vector<Node> NodeVector;
50.20 typedef std::vector<int> IntVector;
50.21 typedef std::vector<bool> BoolVector;
50.22 typedef std::vector<Value> ValueVector;
50.23 @@ -364,33 +364,32 @@
50.24 bool findEnteringArc() {
50.25 Cost c, min = 0;
50.26 int cnt = _block_size;
50.27 - int e, min_arc = _next_arc;
50.28 + int e;
50.29 for (e = _next_arc; e < _search_arc_num; ++e) {
50.30 c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
50.31 if (c < min) {
50.32 min = c;
50.33 - min_arc = e;
50.34 + _in_arc = e;
50.35 }
50.36 if (--cnt == 0) {
50.37 - if (min < 0) break;
50.38 + if (min < 0) goto search_end;
50.39 cnt = _block_size;
50.40 }
50.41 }
50.42 - if (min == 0 || cnt > 0) {
50.43 - for (e = 0; e < _next_arc; ++e) {
50.44 - c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
50.45 - if (c < min) {
50.46 - min = c;
50.47 - min_arc = e;
50.48 - }
50.49 - if (--cnt == 0) {
50.50 - if (min < 0) break;
50.51 - cnt = _block_size;
50.52 - }
50.53 + for (e = 0; e < _next_arc; ++e) {
50.54 + c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
50.55 + if (c < min) {
50.56 + min = c;
50.57 + _in_arc = e;
50.58 + }
50.59 + if (--cnt == 0) {
50.60 + if (min < 0) goto search_end;
50.61 + cnt = _block_size;
50.62 }
50.63 }
50.64 if (min >= 0) return false;
50.65 - _in_arc = min_arc;
50.66 +
50.67 + search_end:
50.68 _next_arc = e;
50.69 return true;
50.70 }
50.71 @@ -428,7 +427,7 @@
50.72 _next_arc(0)
50.73 {
50.74 // The main parameters of the pivot rule
50.75 - const double LIST_LENGTH_FACTOR = 1.0;
50.76 + const double LIST_LENGTH_FACTOR = 0.25;
50.77 const int MIN_LIST_LENGTH = 10;
50.78 const double MINOR_LIMIT_FACTOR = 0.1;
50.79 const int MIN_MINOR_LIMIT = 3;
50.80 @@ -445,7 +444,7 @@
50.81 /// Find next entering arc
50.82 bool findEnteringArc() {
50.83 Cost min, c;
50.84 - int e, min_arc = _next_arc;
50.85 + int e;
50.86 if (_curr_length > 0 && _minor_count < _minor_limit) {
50.87 // Minor iteration: select the best eligible arc from the
50.88 // current candidate list
50.89 @@ -456,16 +455,13 @@
50.90 c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
50.91 if (c < min) {
50.92 min = c;
50.93 - min_arc = e;
50.94 + _in_arc = e;
50.95 }
50.96 - if (c >= 0) {
50.97 + else if (c >= 0) {
50.98 _candidates[i--] = _candidates[--_curr_length];
50.99 }
50.100 }
50.101 - if (min < 0) {
50.102 - _in_arc = min_arc;
50.103 - return true;
50.104 - }
50.105 + if (min < 0) return true;
50.106 }
50.107
50.108 // Major iteration: build a new candidate list
50.109 @@ -477,27 +473,26 @@
50.110 _candidates[_curr_length++] = e;
50.111 if (c < min) {
50.112 min = c;
50.113 - min_arc = e;
50.114 + _in_arc = e;
50.115 }
50.116 - if (_curr_length == _list_length) break;
50.117 + if (_curr_length == _list_length) goto search_end;
50.118 }
50.119 }
50.120 - if (_curr_length < _list_length) {
50.121 - for (e = 0; e < _next_arc; ++e) {
50.122 - c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
50.123 - if (c < 0) {
50.124 - _candidates[_curr_length++] = e;
50.125 - if (c < min) {
50.126 - min = c;
50.127 - min_arc = e;
50.128 - }
50.129 - if (_curr_length == _list_length) break;
50.130 + for (e = 0; e < _next_arc; ++e) {
50.131 + c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
50.132 + if (c < 0) {
50.133 + _candidates[_curr_length++] = e;
50.134 + if (c < min) {
50.135 + min = c;
50.136 + _in_arc = e;
50.137 }
50.138 + if (_curr_length == _list_length) goto search_end;
50.139 }
50.140 }
50.141 if (_curr_length == 0) return false;
50.142 +
50.143 + search_end:
50.144 _minor_count = 1;
50.145 - _in_arc = min_arc;
50.146 _next_arc = e;
50.147 return true;
50.148 }
50.149 @@ -549,7 +544,7 @@
50.150 _next_arc(0), _cand_cost(ns._search_arc_num), _sort_func(_cand_cost)
50.151 {
50.152 // The main parameters of the pivot rule
50.153 - const double BLOCK_SIZE_FACTOR = 1.5;
50.154 + const double BLOCK_SIZE_FACTOR = 1.0;
50.155 const int MIN_BLOCK_SIZE = 10;
50.156 const double HEAD_LENGTH_FACTOR = 0.1;
50.157 const int MIN_HEAD_LENGTH = 3;
50.158 @@ -578,39 +573,35 @@
50.159
50.160 // Extend the list
50.161 int cnt = _block_size;
50.162 - int last_arc = 0;
50.163 int limit = _head_length;
50.164
50.165 - for (int e = _next_arc; e < _search_arc_num; ++e) {
50.166 + for (e = _next_arc; e < _search_arc_num; ++e) {
50.167 _cand_cost[e] = _state[e] *
50.168 (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
50.169 if (_cand_cost[e] < 0) {
50.170 _candidates[_curr_length++] = e;
50.171 - last_arc = e;
50.172 }
50.173 if (--cnt == 0) {
50.174 - if (_curr_length > limit) break;
50.175 + if (_curr_length > limit) goto search_end;
50.176 limit = 0;
50.177 cnt = _block_size;
50.178 }
50.179 }
50.180 - if (_curr_length <= limit) {
50.181 - for (int e = 0; e < _next_arc; ++e) {
50.182 - _cand_cost[e] = _state[e] *
50.183 - (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
50.184 - if (_cand_cost[e] < 0) {
50.185 - _candidates[_curr_length++] = e;
50.186 - last_arc = e;
50.187 - }
50.188 - if (--cnt == 0) {
50.189 - if (_curr_length > limit) break;
50.190 - limit = 0;
50.191 - cnt = _block_size;
50.192 - }
50.193 + for (e = 0; e < _next_arc; ++e) {
50.194 + _cand_cost[e] = _state[e] *
50.195 + (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
50.196 + if (_cand_cost[e] < 0) {
50.197 + _candidates[_curr_length++] = e;
50.198 + }
50.199 + if (--cnt == 0) {
50.200 + if (_curr_length > limit) goto search_end;
50.201 + limit = 0;
50.202 + cnt = _block_size;
50.203 }
50.204 }
50.205 if (_curr_length == 0) return false;
50.206 - _next_arc = last_arc + 1;
50.207 +
50.208 + search_end:
50.209
50.210 // Make heap of the candidate list (approximating a partial sort)
50.211 make_heap( _candidates.begin(), _candidates.begin() + _curr_length,
50.212 @@ -618,6 +609,7 @@
50.213
50.214 // Pop the first element of the heap
50.215 _in_arc = _candidates[0];
50.216 + _next_arc = e;
50.217 pop_heap( _candidates.begin(), _candidates.begin() + _curr_length,
50.218 _sort_func );
50.219 _curr_length = std::min(_head_length, _curr_length - 1);
50.220 @@ -633,7 +625,11 @@
50.221 /// The constructor of the class.
50.222 ///
50.223 /// \param graph The digraph the algorithm runs on.
50.224 - NetworkSimplex(const GR& graph) :
50.225 + /// \param arc_mixing Indicate if the arcs have to be stored in a
50.226 + /// mixed order in the internal data structure.
50.227 + /// In special cases, it could lead to better overall performance,
50.228 + /// but it is usually slower. Therefore it is disabled by default.
50.229 + NetworkSimplex(const GR& graph, bool arc_mixing = false) :
50.230 _graph(graph), _node_id(graph), _arc_id(graph),
50.231 INF(std::numeric_limits<Value>::has_infinity ?
50.232 std::numeric_limits<Value>::infinity() :
50.233 @@ -671,31 +667,33 @@
50.234 _last_succ.resize(all_node_num);
50.235 _state.resize(max_arc_num);
50.236
50.237 - // Copy the graph (store the arcs in a mixed order)
50.238 + // Copy the graph
50.239 int i = 0;
50.240 for (NodeIt n(_graph); n != INVALID; ++n, ++i) {
50.241 _node_id[n] = i;
50.242 }
50.243 - int k = std::max(int(std::sqrt(double(_arc_num))), 10);
50.244 - i = 0;
50.245 - for (ArcIt a(_graph); a != INVALID; ++a) {
50.246 - _arc_id[a] = i;
50.247 - _source[i] = _node_id[_graph.source(a)];
50.248 - _target[i] = _node_id[_graph.target(a)];
50.249 - if ((i += k) >= _arc_num) i = (i % k) + 1;
50.250 + if (arc_mixing) {
50.251 + // Store the arcs in a mixed order
50.252 + int k = std::max(int(std::sqrt(double(_arc_num))), 10);
50.253 + int i = 0, j = 0;
50.254 + for (ArcIt a(_graph); a != INVALID; ++a) {
50.255 + _arc_id[a] = i;
50.256 + _source[i] = _node_id[_graph.source(a)];
50.257 + _target[i] = _node_id[_graph.target(a)];
50.258 + if ((i += k) >= _arc_num) i = ++j;
50.259 + }
50.260 + } else {
50.261 + // Store the arcs in the original order
50.262 + int i = 0;
50.263 + for (ArcIt a(_graph); a != INVALID; ++a, ++i) {
50.264 + _arc_id[a] = i;
50.265 + _source[i] = _node_id[_graph.source(a)];
50.266 + _target[i] = _node_id[_graph.target(a)];
50.267 + }
50.268 }
50.269
50.270 - // Initialize maps
50.271 - for (int i = 0; i != _node_num; ++i) {
50.272 - _supply[i] = 0;
50.273 - }
50.274 - for (int i = 0; i != _arc_num; ++i) {
50.275 - _lower[i] = 0;
50.276 - _upper[i] = INF;
50.277 - _cost[i] = 1;
50.278 - }
50.279 - _have_lower = false;
50.280 - _stype = GEQ;
50.281 + // Reset parameters
50.282 + reset();
50.283 }
50.284
50.285 /// \name Parameters
50.286 @@ -768,7 +766,6 @@
50.287 /// This function sets the supply values of the nodes.
50.288 /// If neither this function nor \ref stSupply() is used before
50.289 /// calling \ref run(), the supply of each node will be set to zero.
50.290 - /// (It makes sense only if non-zero lower bounds are given.)
50.291 ///
50.292 /// \param map A node map storing the supply values.
50.293 /// Its \c Value type must be convertible to the \c Value type
50.294 @@ -789,7 +786,6 @@
50.295 /// and the required flow value.
50.296 /// If neither this function nor \ref supplyMap() is used before
50.297 /// calling \ref run(), the supply of each node will be set to zero.
50.298 - /// (It makes sense only if non-zero lower bounds are given.)
50.299 ///
50.300 /// Using this function has the same effect as using \ref supplyMap()
50.301 /// with such a map in which \c k is assigned to \c s, \c -k is
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
51.2 +++ b/lemon/pairing_heap.h Thu Nov 05 08:39:49 2009 +0100
51.3 @@ -0,0 +1,474 @@
51.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
51.5 + *
51.6 + * This file is a part of LEMON, a generic C++ optimization library.
51.7 + *
51.8 + * Copyright (C) 2003-2009
51.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
51.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
51.11 + *
51.12 + * Permission to use, modify and distribute this software is granted
51.13 + * provided that this copyright notice appears in all copies. For
51.14 + * precise terms see the accompanying LICENSE file.
51.15 + *
51.16 + * This software is provided "AS IS" with no warranty of any kind,
51.17 + * express or implied, and with no claim as to its suitability for any
51.18 + * purpose.
51.19 + *
51.20 + */
51.21 +
51.22 +#ifndef LEMON_PAIRING_HEAP_H
51.23 +#define LEMON_PAIRING_HEAP_H
51.24 +
51.25 +///\file
51.26 +///\ingroup heaps
51.27 +///\brief Pairing heap implementation.
51.28 +
51.29 +#include <vector>
51.30 +#include <utility>
51.31 +#include <functional>
51.32 +#include <lemon/math.h>
51.33 +
51.34 +namespace lemon {
51.35 +
51.36 + /// \ingroup heaps
51.37 + ///
51.38 + ///\brief Pairing Heap.
51.39 + ///
51.40 + /// This class implements the \e pairing \e heap data structure.
51.41 + /// It fully conforms to the \ref concepts::Heap "heap concept".
51.42 + ///
51.43 + /// The methods \ref increase() and \ref erase() are not efficient
51.44 + /// in a pairing heap. In case of many calls of these operations,
51.45 + /// it is better to use other heap structure, e.g. \ref BinHeap
51.46 + /// "binary heap".
51.47 + ///
51.48 + /// \tparam PR Type of the priorities of the items.
51.49 + /// \tparam IM A read-writable item map with \c int values, used
51.50 + /// internally to handle the cross references.
51.51 + /// \tparam CMP A functor class for comparing the priorities.
51.52 + /// The default is \c std::less<PR>.
51.53 +#ifdef DOXYGEN
51.54 + template <typename PR, typename IM, typename CMP>
51.55 +#else
51.56 + template <typename PR, typename IM, typename CMP = std::less<PR> >
51.57 +#endif
51.58 + class PairingHeap {
51.59 + public:
51.60 + /// Type of the item-int map.
51.61 + typedef IM ItemIntMap;
51.62 + /// Type of the priorities.
51.63 + typedef PR Prio;
51.64 + /// Type of the items stored in the heap.
51.65 + typedef typename ItemIntMap::Key Item;
51.66 + /// Functor type for comparing the priorities.
51.67 + typedef CMP Compare;
51.68 +
51.69 + /// \brief Type to represent the states of the items.
51.70 + ///
51.71 + /// Each item has a state associated to it. It can be "in heap",
51.72 + /// "pre-heap" or "post-heap". The latter two are indifferent from the
51.73 + /// heap's point of view, but may be useful to the user.
51.74 + ///
51.75 + /// The item-int map must be initialized in such way that it assigns
51.76 + /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
51.77 + enum State {
51.78 + IN_HEAP = 0, ///< = 0.
51.79 + PRE_HEAP = -1, ///< = -1.
51.80 + POST_HEAP = -2 ///< = -2.
51.81 + };
51.82 +
51.83 + private:
51.84 + class store;
51.85 +
51.86 + std::vector<store> _data;
51.87 + int _min;
51.88 + ItemIntMap &_iim;
51.89 + Compare _comp;
51.90 + int _num_items;
51.91 +
51.92 + public:
51.93 + /// \brief Constructor.
51.94 + ///
51.95 + /// Constructor.
51.96 + /// \param map A map that assigns \c int values to the items.
51.97 + /// It is used internally to handle the cross references.
51.98 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
51.99 + explicit PairingHeap(ItemIntMap &map)
51.100 + : _min(0), _iim(map), _num_items(0) {}
51.101 +
51.102 + /// \brief Constructor.
51.103 + ///
51.104 + /// Constructor.
51.105 + /// \param map A map that assigns \c int values to the items.
51.106 + /// It is used internally to handle the cross references.
51.107 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
51.108 + /// \param comp The function object used for comparing the priorities.
51.109 + PairingHeap(ItemIntMap &map, const Compare &comp)
51.110 + : _min(0), _iim(map), _comp(comp), _num_items(0) {}
51.111 +
51.112 + /// \brief The number of items stored in the heap.
51.113 + ///
51.114 + /// This function returns the number of items stored in the heap.
51.115 + int size() const { return _num_items; }
51.116 +
51.117 + /// \brief Check if the heap is empty.
51.118 + ///
51.119 + /// This function returns \c true if the heap is empty.
51.120 + bool empty() const { return _num_items==0; }
51.121 +
51.122 + /// \brief Make the heap empty.
51.123 + ///
51.124 + /// This functon makes the heap empty.
51.125 + /// It does not change the cross reference map. If you want to reuse
51.126 + /// a heap that is not surely empty, you should first clear it and
51.127 + /// then you should set the cross reference map to \c PRE_HEAP
51.128 + /// for each item.
51.129 + void clear() {
51.130 + _data.clear();
51.131 + _min = 0;
51.132 + _num_items = 0;
51.133 + }
51.134 +
51.135 + /// \brief Set the priority of an item or insert it, if it is
51.136 + /// not stored in the heap.
51.137 + ///
51.138 + /// This method sets the priority of the given item if it is
51.139 + /// already stored in the heap. Otherwise it inserts the given
51.140 + /// item into the heap with the given priority.
51.141 + /// \param item The item.
51.142 + /// \param value The priority.
51.143 + void set (const Item& item, const Prio& value) {
51.144 + int i=_iim[item];
51.145 + if ( i>=0 && _data[i].in ) {
51.146 + if ( _comp(value, _data[i].prio) ) decrease(item, value);
51.147 + if ( _comp(_data[i].prio, value) ) increase(item, value);
51.148 + } else push(item, value);
51.149 + }
51.150 +
51.151 + /// \brief Insert an item into the heap with the given priority.
51.152 + ///
51.153 + /// This function inserts the given item into the heap with the
51.154 + /// given priority.
51.155 + /// \param item The item to insert.
51.156 + /// \param value The priority of the item.
51.157 + /// \pre \e item must not be stored in the heap.
51.158 + void push (const Item& item, const Prio& value) {
51.159 + int i=_iim[item];
51.160 + if( i<0 ) {
51.161 + int s=_data.size();
51.162 + _iim.set(item, s);
51.163 + store st;
51.164 + st.name=item;
51.165 + _data.push_back(st);
51.166 + i=s;
51.167 + } else {
51.168 + _data[i].parent=_data[i].child=-1;
51.169 + _data[i].left_child=false;
51.170 + _data[i].degree=0;
51.171 + _data[i].in=true;
51.172 + }
51.173 +
51.174 + _data[i].prio=value;
51.175 +
51.176 + if ( _num_items!=0 ) {
51.177 + if ( _comp( value, _data[_min].prio) ) {
51.178 + fuse(i,_min);
51.179 + _min=i;
51.180 + }
51.181 + else fuse(_min,i);
51.182 + }
51.183 + else _min=i;
51.184 +
51.185 + ++_num_items;
51.186 + }
51.187 +
51.188 + /// \brief Return the item having minimum priority.
51.189 + ///
51.190 + /// This function returns the item having minimum priority.
51.191 + /// \pre The heap must be non-empty.
51.192 + Item top() const { return _data[_min].name; }
51.193 +
51.194 + /// \brief The minimum priority.
51.195 + ///
51.196 + /// This function returns the minimum priority.
51.197 + /// \pre The heap must be non-empty.
51.198 + const Prio& prio() const { return _data[_min].prio; }
51.199 +
51.200 + /// \brief The priority of the given item.
51.201 + ///
51.202 + /// This function returns the priority of the given item.
51.203 + /// \param item The item.
51.204 + /// \pre \e item must be in the heap.
51.205 + const Prio& operator[](const Item& item) const {
51.206 + return _data[_iim[item]].prio;
51.207 + }
51.208 +
51.209 + /// \brief Remove the item having minimum priority.
51.210 + ///
51.211 + /// This function removes the item having minimum priority.
51.212 + /// \pre The heap must be non-empty.
51.213 + void pop() {
51.214 + std::vector<int> trees;
51.215 + int i=0, child_right = 0;
51.216 + _data[_min].in=false;
51.217 +
51.218 + if( -1!=_data[_min].child ) {
51.219 + i=_data[_min].child;
51.220 + trees.push_back(i);
51.221 + _data[i].parent = -1;
51.222 + _data[_min].child = -1;
51.223 +
51.224 + int ch=-1;
51.225 + while( _data[i].child!=-1 ) {
51.226 + ch=_data[i].child;
51.227 + if( _data[ch].left_child && i==_data[ch].parent ) {
51.228 + break;
51.229 + } else {
51.230 + if( _data[ch].left_child ) {
51.231 + child_right=_data[ch].parent;
51.232 + _data[ch].parent = i;
51.233 + --_data[i].degree;
51.234 + }
51.235 + else {
51.236 + child_right=ch;
51.237 + _data[i].child=-1;
51.238 + _data[i].degree=0;
51.239 + }
51.240 + _data[child_right].parent = -1;
51.241 + trees.push_back(child_right);
51.242 + i = child_right;
51.243 + }
51.244 + }
51.245 +
51.246 + int num_child = trees.size();
51.247 + int other;
51.248 + for( i=0; i<num_child-1; i+=2 ) {
51.249 + if ( !_comp(_data[trees[i]].prio, _data[trees[i+1]].prio) ) {
51.250 + other=trees[i];
51.251 + trees[i]=trees[i+1];
51.252 + trees[i+1]=other;
51.253 + }
51.254 + fuse( trees[i], trees[i+1] );
51.255 + }
51.256 +
51.257 + i = (0==(num_child % 2)) ? num_child-2 : num_child-1;
51.258 + while(i>=2) {
51.259 + if ( _comp(_data[trees[i]].prio, _data[trees[i-2]].prio) ) {
51.260 + other=trees[i];
51.261 + trees[i]=trees[i-2];
51.262 + trees[i-2]=other;
51.263 + }
51.264 + fuse( trees[i-2], trees[i] );
51.265 + i-=2;
51.266 + }
51.267 + _min = trees[0];
51.268 + }
51.269 + else {
51.270 + _min = _data[_min].child;
51.271 + }
51.272 +
51.273 + if (_min >= 0) _data[_min].left_child = false;
51.274 + --_num_items;
51.275 + }
51.276 +
51.277 + /// \brief Remove the given item from the heap.
51.278 + ///
51.279 + /// This function removes the given item from the heap if it is
51.280 + /// already stored.
51.281 + /// \param item The item to delete.
51.282 + /// \pre \e item must be in the heap.
51.283 + void erase (const Item& item) {
51.284 + int i=_iim[item];
51.285 + if ( i>=0 && _data[i].in ) {
51.286 + decrease( item, _data[_min].prio-1 );
51.287 + pop();
51.288 + }
51.289 + }
51.290 +
51.291 + /// \brief Decrease the priority of an item to the given value.
51.292 + ///
51.293 + /// This function decreases the priority of an item to the given value.
51.294 + /// \param item The item.
51.295 + /// \param value The priority.
51.296 + /// \pre \e item must be stored in the heap with priority at least \e value.
51.297 + void decrease (Item item, const Prio& value) {
51.298 + int i=_iim[item];
51.299 + _data[i].prio=value;
51.300 + int p=_data[i].parent;
51.301 +
51.302 + if( _data[i].left_child && i!=_data[p].child ) {
51.303 + p=_data[p].parent;
51.304 + }
51.305 +
51.306 + if ( p!=-1 && _comp(value,_data[p].prio) ) {
51.307 + cut(i,p);
51.308 + if ( _comp(_data[_min].prio,value) ) {
51.309 + fuse(_min,i);
51.310 + } else {
51.311 + fuse(i,_min);
51.312 + _min=i;
51.313 + }
51.314 + }
51.315 + }
51.316 +
51.317 + /// \brief Increase the priority of an item to the given value.
51.318 + ///
51.319 + /// This function increases the priority of an item to the given value.
51.320 + /// \param item The item.
51.321 + /// \param value The priority.
51.322 + /// \pre \e item must be stored in the heap with priority at most \e value.
51.323 + void increase (Item item, const Prio& value) {
51.324 + erase(item);
51.325 + push(item,value);
51.326 + }
51.327 +
51.328 + /// \brief Return the state of an item.
51.329 + ///
51.330 + /// This method returns \c PRE_HEAP if the given item has never
51.331 + /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
51.332 + /// and \c POST_HEAP otherwise.
51.333 + /// In the latter case it is possible that the item will get back
51.334 + /// to the heap again.
51.335 + /// \param item The item.
51.336 + State state(const Item &item) const {
51.337 + int i=_iim[item];
51.338 + if( i>=0 ) {
51.339 + if( _data[i].in ) i=0;
51.340 + else i=-2;
51.341 + }
51.342 + return State(i);
51.343 + }
51.344 +
51.345 + /// \brief Set the state of an item in the heap.
51.346 + ///
51.347 + /// This function sets the state of the given item in the heap.
51.348 + /// It can be used to manually clear the heap when it is important
51.349 + /// to achive better time complexity.
51.350 + /// \param i The item.
51.351 + /// \param st The state. It should not be \c IN_HEAP.
51.352 + void state(const Item& i, State st) {
51.353 + switch (st) {
51.354 + case POST_HEAP:
51.355 + case PRE_HEAP:
51.356 + if (state(i) == IN_HEAP) erase(i);
51.357 + _iim[i]=st;
51.358 + break;
51.359 + case IN_HEAP:
51.360 + break;
51.361 + }
51.362 + }
51.363 +
51.364 + private:
51.365 +
51.366 + void cut(int a, int b) {
51.367 + int child_a;
51.368 + switch (_data[a].degree) {
51.369 + case 2:
51.370 + child_a = _data[_data[a].child].parent;
51.371 + if( _data[a].left_child ) {
51.372 + _data[child_a].left_child=true;
51.373 + _data[b].child=child_a;
51.374 + _data[child_a].parent=_data[a].parent;
51.375 + }
51.376 + else {
51.377 + _data[child_a].left_child=false;
51.378 + _data[child_a].parent=b;
51.379 + if( a!=_data[b].child )
51.380 + _data[_data[b].child].parent=child_a;
51.381 + else
51.382 + _data[b].child=child_a;
51.383 + }
51.384 + --_data[a].degree;
51.385 + _data[_data[a].child].parent=a;
51.386 + break;
51.387 +
51.388 + case 1:
51.389 + child_a = _data[a].child;
51.390 + if( !_data[child_a].left_child ) {
51.391 + --_data[a].degree;
51.392 + if( _data[a].left_child ) {
51.393 + _data[child_a].left_child=true;
51.394 + _data[child_a].parent=_data[a].parent;
51.395 + _data[b].child=child_a;
51.396 + }
51.397 + else {
51.398 + _data[child_a].left_child=false;
51.399 + _data[child_a].parent=b;
51.400 + if( a!=_data[b].child )
51.401 + _data[_data[b].child].parent=child_a;
51.402 + else
51.403 + _data[b].child=child_a;
51.404 + }
51.405 + _data[a].child=-1;
51.406 + }
51.407 + else {
51.408 + --_data[b].degree;
51.409 + if( _data[a].left_child ) {
51.410 + _data[b].child =
51.411 + (1==_data[b].degree) ? _data[a].parent : -1;
51.412 + } else {
51.413 + if (1==_data[b].degree)
51.414 + _data[_data[b].child].parent=b;
51.415 + else
51.416 + _data[b].child=-1;
51.417 + }
51.418 + }
51.419 + break;
51.420 +
51.421 + case 0:
51.422 + --_data[b].degree;
51.423 + if( _data[a].left_child ) {
51.424 + _data[b].child =
51.425 + (0!=_data[b].degree) ? _data[a].parent : -1;
51.426 + } else {
51.427 + if( 0!=_data[b].degree )
51.428 + _data[_data[b].child].parent=b;
51.429 + else
51.430 + _data[b].child=-1;
51.431 + }
51.432 + break;
51.433 + }
51.434 + _data[a].parent=-1;
51.435 + _data[a].left_child=false;
51.436 + }
51.437 +
51.438 + void fuse(int a, int b) {
51.439 + int child_a = _data[a].child;
51.440 + int child_b = _data[b].child;
51.441 + _data[a].child=b;
51.442 + _data[b].parent=a;
51.443 + _data[b].left_child=true;
51.444 +
51.445 + if( -1!=child_a ) {
51.446 + _data[b].child=child_a;
51.447 + _data[child_a].parent=b;
51.448 + _data[child_a].left_child=false;
51.449 + ++_data[b].degree;
51.450 +
51.451 + if( -1!=child_b ) {
51.452 + _data[b].child=child_b;
51.453 + _data[child_b].parent=child_a;
51.454 + }
51.455 + }
51.456 + else { ++_data[a].degree; }
51.457 + }
51.458 +
51.459 + class store {
51.460 + friend class PairingHeap;
51.461 +
51.462 + Item name;
51.463 + int parent;
51.464 + int child;
51.465 + bool left_child;
51.466 + int degree;
51.467 + bool in;
51.468 + Prio prio;
51.469 +
51.470 + store() : parent(-1), child(-1), left_child(false), degree(0), in(true) {}
51.471 + };
51.472 + };
51.473 +
51.474 +} //namespace lemon
51.475 +
51.476 +#endif //LEMON_PAIRING_HEAP_H
51.477 +
52.1 --- a/lemon/path.h Tue Aug 18 10:08:28 2009 +0200
52.2 +++ b/lemon/path.h Thu Nov 05 08:39:49 2009 +0100
52.3 @@ -1015,18 +1015,20 @@
52.4
52.5 /// \brief The source of a path
52.6 ///
52.7 - /// This function returns the source of the given path.
52.8 + /// This function returns the source node of the given path.
52.9 + /// If the path is empty, then it returns \c INVALID.
52.10 template <typename Digraph, typename Path>
52.11 typename Digraph::Node pathSource(const Digraph& digraph, const Path& path) {
52.12 - return digraph.source(path.front());
52.13 + return path.empty() ? INVALID : digraph.source(path.front());
52.14 }
52.15
52.16 /// \brief The target of a path
52.17 ///
52.18 - /// This function returns the target of the given path.
52.19 + /// This function returns the target node of the given path.
52.20 + /// If the path is empty, then it returns \c INVALID.
52.21 template <typename Digraph, typename Path>
52.22 typename Digraph::Node pathTarget(const Digraph& digraph, const Path& path) {
52.23 - return digraph.target(path.back());
52.24 + return path.empty() ? INVALID : digraph.target(path.back());
52.25 }
52.26
52.27 /// \brief Class which helps to iterate through the nodes of a path
53.1 --- a/lemon/preflow.h Tue Aug 18 10:08:28 2009 +0200
53.2 +++ b/lemon/preflow.h Thu Nov 05 08:39:49 2009 +0100
53.3 @@ -52,7 +52,11 @@
53.4 ///
53.5 /// The type of the map that stores the flow values.
53.6 /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
53.7 +#ifdef DOXYGEN
53.8 + typedef GR::ArcMap<Value> FlowMap;
53.9 +#else
53.10 typedef typename Digraph::template ArcMap<Value> FlowMap;
53.11 +#endif
53.12
53.13 /// \brief Instantiates a FlowMap.
53.14 ///
53.15 @@ -67,9 +71,12 @@
53.16 ///
53.17 /// The elevator type used by Preflow algorithm.
53.18 ///
53.19 - /// \sa Elevator
53.20 - /// \sa LinkedElevator
53.21 - typedef LinkedElevator<Digraph, typename Digraph::Node> Elevator;
53.22 + /// \sa Elevator, LinkedElevator
53.23 +#ifdef DOXYGEN
53.24 + typedef lemon::Elevator<GR, GR::Node> Elevator;
53.25 +#else
53.26 + typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator;
53.27 +#endif
53.28
53.29 /// \brief Instantiates an Elevator.
53.30 ///
53.31 @@ -95,9 +102,10 @@
53.32 ///
53.33 /// This class provides an implementation of Goldberg-Tarjan's \e preflow
53.34 /// \e push-relabel algorithm producing a \ref max_flow
53.35 - /// "flow of maximum value" in a digraph.
53.36 + /// "flow of maximum value" in a digraph \ref clrs01algorithms,
53.37 + /// \ref amo93networkflows, \ref goldberg88newapproach.
53.38 /// The preflow algorithms are the fastest known maximum
53.39 - /// flow algorithms. The current implementation use a mixture of the
53.40 + /// flow algorithms. The current implementation uses a mixture of the
53.41 /// \e "highest label" and the \e "bound decrease" heuristics.
53.42 /// The worst case time complexity of the algorithm is \f$O(n^2\sqrt{e})\f$.
53.43 ///
53.44 @@ -371,26 +379,28 @@
53.45 return *_level;
53.46 }
53.47
53.48 - /// \brief Sets the tolerance used by algorithm.
53.49 + /// \brief Sets the tolerance used by the algorithm.
53.50 ///
53.51 - /// Sets the tolerance used by algorithm.
53.52 - Preflow& tolerance(const Tolerance& tolerance) const {
53.53 + /// Sets the tolerance object used by the algorithm.
53.54 + /// \return <tt>(*this)</tt>
53.55 + Preflow& tolerance(const Tolerance& tolerance) {
53.56 _tolerance = tolerance;
53.57 return *this;
53.58 }
53.59
53.60 /// \brief Returns a const reference to the tolerance.
53.61 ///
53.62 - /// Returns a const reference to the tolerance.
53.63 + /// Returns a const reference to the tolerance object used by
53.64 + /// the algorithm.
53.65 const Tolerance& tolerance() const {
53.66 - return tolerance;
53.67 + return _tolerance;
53.68 }
53.69
53.70 /// \name Execution Control
53.71 /// The simplest way to execute the preflow algorithm is to use
53.72 /// \ref run() or \ref runMinCut().\n
53.73 - /// If you need more control on the initial solution or the execution,
53.74 - /// first you have to call one of the \ref init() functions, then
53.75 + /// If you need better control on the initial solution or the execution,
53.76 + /// you have to call one of the \ref init() functions first, then
53.77 /// \ref startFirstPhase() and if you need it \ref startSecondPhase().
53.78
53.79 ///@{
54.1 --- a/lemon/radix_heap.h Tue Aug 18 10:08:28 2009 +0200
54.2 +++ b/lemon/radix_heap.h Thu Nov 05 08:39:49 2009 +0100
54.3 @@ -19,9 +19,9 @@
54.4 #ifndef LEMON_RADIX_HEAP_H
54.5 #define LEMON_RADIX_HEAP_H
54.6
54.7 -///\ingroup auxdat
54.8 +///\ingroup heaps
54.9 ///\file
54.10 -///\brief Radix Heap implementation.
54.11 +///\brief Radix heap implementation.
54.12
54.13 #include <vector>
54.14 #include <lemon/error.h>
54.15 @@ -29,56 +29,54 @@
54.16 namespace lemon {
54.17
54.18
54.19 - /// \ingroup auxdata
54.20 + /// \ingroup heaps
54.21 ///
54.22 - /// \brief A Radix Heap implementation.
54.23 + /// \brief Radix heap data structure.
54.24 ///
54.25 - /// This class implements the \e radix \e heap data structure. A \e heap
54.26 - /// is a data structure for storing items with specified values called \e
54.27 - /// priorities in such a way that finding the item with minimum priority is
54.28 - /// efficient. This heap type can store only items with \e int priority.
54.29 - /// In a heap one can change the priority of an item, add or erase an
54.30 - /// item, but the priority cannot be decreased under the last removed
54.31 - /// item's priority.
54.32 + /// This class implements the \e radix \e heap data structure.
54.33 + /// It practically conforms to the \ref concepts::Heap "heap concept",
54.34 + /// but it has some limitations due its special implementation.
54.35 + /// The type of the priorities must be \c int and the priority of an
54.36 + /// item cannot be decreased under the priority of the last removed item.
54.37 ///
54.38 - /// \param IM A read and writable Item int map, used internally
54.39 - /// to handle the cross references.
54.40 - ///
54.41 - /// \see BinHeap
54.42 - /// \see Dijkstra
54.43 + /// \tparam IM A read-writable item map with \c int values, used
54.44 + /// internally to handle the cross references.
54.45 template <typename IM>
54.46 class RadixHeap {
54.47
54.48 public:
54.49 - typedef typename IM::Key Item;
54.50 +
54.51 + /// Type of the item-int map.
54.52 + typedef IM ItemIntMap;
54.53 + /// Type of the priorities.
54.54 typedef int Prio;
54.55 - typedef IM ItemIntMap;
54.56 + /// Type of the items stored in the heap.
54.57 + typedef typename ItemIntMap::Key Item;
54.58
54.59 /// \brief Exception thrown by RadixHeap.
54.60 ///
54.61 - /// This Exception is thrown when a smaller priority
54.62 - /// is inserted into the \e RadixHeap then the last time erased.
54.63 + /// This exception is thrown when an item is inserted into a
54.64 + /// RadixHeap with a priority smaller than the last erased one.
54.65 /// \see RadixHeap
54.66 -
54.67 - class UnderFlowPriorityError : public Exception {
54.68 + class PriorityUnderflowError : public Exception {
54.69 public:
54.70 virtual const char* what() const throw() {
54.71 - return "lemon::RadixHeap::UnderFlowPriorityError";
54.72 + return "lemon::RadixHeap::PriorityUnderflowError";
54.73 }
54.74 };
54.75
54.76 - /// \brief Type to represent the items states.
54.77 + /// \brief Type to represent the states of the items.
54.78 ///
54.79 - /// Each Item element have a state associated to it. It may be "in heap",
54.80 - /// "pre heap" or "post heap". The latter two are indifferent from the
54.81 + /// Each item has a state associated to it. It can be "in heap",
54.82 + /// "pre-heap" or "post-heap". The latter two are indifferent from the
54.83 /// heap's point of view, but may be useful to the user.
54.84 ///
54.85 - /// The ItemIntMap \e should be initialized in such way that it maps
54.86 - /// PRE_HEAP (-1) to any element to be put in the heap...
54.87 + /// The item-int map must be initialized in such way that it assigns
54.88 + /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
54.89 enum State {
54.90 - IN_HEAP = 0,
54.91 - PRE_HEAP = -1,
54.92 - POST_HEAP = -2
54.93 + IN_HEAP = 0, ///< = 0.
54.94 + PRE_HEAP = -1, ///< = -1.
54.95 + POST_HEAP = -2 ///< = -2.
54.96 };
54.97
54.98 private:
54.99 @@ -96,52 +94,55 @@
54.100 RadixBox(int _min, int _size) : first(-1), min(_min), size(_size) {}
54.101 };
54.102
54.103 - std::vector<RadixItem> data;
54.104 - std::vector<RadixBox> boxes;
54.105 + std::vector<RadixItem> _data;
54.106 + std::vector<RadixBox> _boxes;
54.107
54.108 ItemIntMap &_iim;
54.109
54.110 + public:
54.111
54.112 - public:
54.113 - /// \brief The constructor.
54.114 + /// \brief Constructor.
54.115 ///
54.116 - /// The constructor.
54.117 - ///
54.118 - /// \param map It should be given to the constructor, since it is used
54.119 - /// internally to handle the cross references. The value of the map
54.120 - /// should be PRE_HEAP (-1) for each element.
54.121 - ///
54.122 - /// \param minimal The initial minimal value of the heap.
54.123 - /// \param capacity It determines the initial capacity of the heap.
54.124 - RadixHeap(ItemIntMap &map, int minimal = 0, int capacity = 0)
54.125 - : _iim(map) {
54.126 - boxes.push_back(RadixBox(minimal, 1));
54.127 - boxes.push_back(RadixBox(minimal + 1, 1));
54.128 - while (lower(boxes.size() - 1, capacity + minimal - 1)) {
54.129 + /// Constructor.
54.130 + /// \param map A map that assigns \c int values to the items.
54.131 + /// It is used internally to handle the cross references.
54.132 + /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
54.133 + /// \param minimum The initial minimum value of the heap.
54.134 + /// \param capacity The initial capacity of the heap.
54.135 + RadixHeap(ItemIntMap &map, int minimum = 0, int capacity = 0)
54.136 + : _iim(map)
54.137 + {
54.138 + _boxes.push_back(RadixBox(minimum, 1));
54.139 + _boxes.push_back(RadixBox(minimum + 1, 1));
54.140 + while (lower(_boxes.size() - 1, capacity + minimum - 1)) {
54.141 extend();
54.142 }
54.143 }
54.144
54.145 - /// The number of items stored in the heap.
54.146 + /// \brief The number of items stored in the heap.
54.147 ///
54.148 - /// \brief Returns the number of items stored in the heap.
54.149 - int size() const { return data.size(); }
54.150 - /// \brief Checks if the heap stores no items.
54.151 + /// This function returns the number of items stored in the heap.
54.152 + int size() const { return _data.size(); }
54.153 +
54.154 + /// \brief Check if the heap is empty.
54.155 ///
54.156 - /// Returns \c true if and only if the heap stores no items.
54.157 - bool empty() const { return data.empty(); }
54.158 + /// This function returns \c true if the heap is empty.
54.159 + bool empty() const { return _data.empty(); }
54.160
54.161 - /// \brief Make empty this heap.
54.162 + /// \brief Make the heap empty.
54.163 ///
54.164 - /// Make empty this heap. It does not change the cross reference
54.165 - /// map. If you want to reuse a heap what is not surely empty you
54.166 - /// should first clear the heap and after that you should set the
54.167 - /// cross reference map for each item to \c PRE_HEAP.
54.168 - void clear(int minimal = 0, int capacity = 0) {
54.169 - data.clear(); boxes.clear();
54.170 - boxes.push_back(RadixBox(minimal, 1));
54.171 - boxes.push_back(RadixBox(minimal + 1, 1));
54.172 - while (lower(boxes.size() - 1, capacity + minimal - 1)) {
54.173 + /// This functon makes the heap empty.
54.174 + /// It does not change the cross reference map. If you want to reuse
54.175 + /// a heap that is not surely empty, you should first clear it and
54.176 + /// then you should set the cross reference map to \c PRE_HEAP
54.177 + /// for each item.
54.178 + /// \param minimum The minimum value of the heap.
54.179 + /// \param capacity The capacity of the heap.
54.180 + void clear(int minimum = 0, int capacity = 0) {
54.181 + _data.clear(); _boxes.clear();
54.182 + _boxes.push_back(RadixBox(minimum, 1));
54.183 + _boxes.push_back(RadixBox(minimum + 1, 1));
54.184 + while (lower(_boxes.size() - 1, capacity + minimum - 1)) {
54.185 extend();
54.186 }
54.187 }
54.188 @@ -149,255 +150,259 @@
54.189 private:
54.190
54.191 bool upper(int box, Prio pr) {
54.192 - return pr < boxes[box].min;
54.193 + return pr < _boxes[box].min;
54.194 }
54.195
54.196 bool lower(int box, Prio pr) {
54.197 - return pr >= boxes[box].min + boxes[box].size;
54.198 + return pr >= _boxes[box].min + _boxes[box].size;
54.199 }
54.200
54.201 - /// \brief Remove item from the box list.
54.202 + // Remove item from the box list
54.203 void remove(int index) {
54.204 - if (data[index].prev >= 0) {
54.205 - data[data[index].prev].next = data[index].next;
54.206 + if (_data[index].prev >= 0) {
54.207 + _data[_data[index].prev].next = _data[index].next;
54.208 } else {
54.209 - boxes[data[index].box].first = data[index].next;
54.210 + _boxes[_data[index].box].first = _data[index].next;
54.211 }
54.212 - if (data[index].next >= 0) {
54.213 - data[data[index].next].prev = data[index].prev;
54.214 + if (_data[index].next >= 0) {
54.215 + _data[_data[index].next].prev = _data[index].prev;
54.216 }
54.217 }
54.218
54.219 - /// \brief Insert item into the box list.
54.220 + // Insert item into the box list
54.221 void insert(int box, int index) {
54.222 - if (boxes[box].first == -1) {
54.223 - boxes[box].first = index;
54.224 - data[index].next = data[index].prev = -1;
54.225 + if (_boxes[box].first == -1) {
54.226 + _boxes[box].first = index;
54.227 + _data[index].next = _data[index].prev = -1;
54.228 } else {
54.229 - data[index].next = boxes[box].first;
54.230 - data[boxes[box].first].prev = index;
54.231 - data[index].prev = -1;
54.232 - boxes[box].first = index;
54.233 + _data[index].next = _boxes[box].first;
54.234 + _data[_boxes[box].first].prev = index;
54.235 + _data[index].prev = -1;
54.236 + _boxes[box].first = index;
54.237 }
54.238 - data[index].box = box;
54.239 + _data[index].box = box;
54.240 }
54.241
54.242 - /// \brief Add a new box to the box list.
54.243 + // Add a new box to the box list
54.244 void extend() {
54.245 - int min = boxes.back().min + boxes.back().size;
54.246 - int bs = 2 * boxes.back().size;
54.247 - boxes.push_back(RadixBox(min, bs));
54.248 + int min = _boxes.back().min + _boxes.back().size;
54.249 + int bs = 2 * _boxes.back().size;
54.250 + _boxes.push_back(RadixBox(min, bs));
54.251 }
54.252
54.253 - /// \brief Move an item up into the proper box.
54.254 - void bubble_up(int index) {
54.255 - if (!lower(data[index].box, data[index].prio)) return;
54.256 + // Move an item up into the proper box.
54.257 + void bubbleUp(int index) {
54.258 + if (!lower(_data[index].box, _data[index].prio)) return;
54.259 remove(index);
54.260 - int box = findUp(data[index].box, data[index].prio);
54.261 + int box = findUp(_data[index].box, _data[index].prio);
54.262 insert(box, index);
54.263 }
54.264
54.265 - /// \brief Find up the proper box for the item with the given prio.
54.266 + // Find up the proper box for the item with the given priority
54.267 int findUp(int start, int pr) {
54.268 while (lower(start, pr)) {
54.269 - if (++start == int(boxes.size())) {
54.270 + if (++start == int(_boxes.size())) {
54.271 extend();
54.272 }
54.273 }
54.274 return start;
54.275 }
54.276
54.277 - /// \brief Move an item down into the proper box.
54.278 - void bubble_down(int index) {
54.279 - if (!upper(data[index].box, data[index].prio)) return;
54.280 + // Move an item down into the proper box
54.281 + void bubbleDown(int index) {
54.282 + if (!upper(_data[index].box, _data[index].prio)) return;
54.283 remove(index);
54.284 - int box = findDown(data[index].box, data[index].prio);
54.285 + int box = findDown(_data[index].box, _data[index].prio);
54.286 insert(box, index);
54.287 }
54.288
54.289 - /// \brief Find up the proper box for the item with the given prio.
54.290 + // Find down the proper box for the item with the given priority
54.291 int findDown(int start, int pr) {
54.292 while (upper(start, pr)) {
54.293 - if (--start < 0) throw UnderFlowPriorityError();
54.294 + if (--start < 0) throw PriorityUnderflowError();
54.295 }
54.296 return start;
54.297 }
54.298
54.299 - /// \brief Find the first not empty box.
54.300 + // Find the first non-empty box
54.301 int findFirst() {
54.302 int first = 0;
54.303 - while (boxes[first].first == -1) ++first;
54.304 + while (_boxes[first].first == -1) ++first;
54.305 return first;
54.306 }
54.307
54.308 - /// \brief Gives back the minimal prio of the box.
54.309 + // Gives back the minimum priority of the given box
54.310 int minValue(int box) {
54.311 - int min = data[boxes[box].first].prio;
54.312 - for (int k = boxes[box].first; k != -1; k = data[k].next) {
54.313 - if (data[k].prio < min) min = data[k].prio;
54.314 + int min = _data[_boxes[box].first].prio;
54.315 + for (int k = _boxes[box].first; k != -1; k = _data[k].next) {
54.316 + if (_data[k].prio < min) min = _data[k].prio;
54.317 }
54.318 return min;
54.319 }
54.320
54.321 - /// \brief Rearrange the items of the heap and makes the
54.322 - /// first box not empty.
54.323 + // Rearrange the items of the heap and make the first box non-empty
54.324 void moveDown() {
54.325 int box = findFirst();
54.326 if (box == 0) return;
54.327 int min = minValue(box);
54.328 for (int i = 0; i <= box; ++i) {
54.329 - boxes[i].min = min;
54.330 - min += boxes[i].size;
54.331 + _boxes[i].min = min;
54.332 + min += _boxes[i].size;
54.333 }
54.334 - int curr = boxes[box].first, next;
54.335 + int curr = _boxes[box].first, next;
54.336 while (curr != -1) {
54.337 - next = data[curr].next;
54.338 - bubble_down(curr);
54.339 + next = _data[curr].next;
54.340 + bubbleDown(curr);
54.341 curr = next;
54.342 }
54.343 }
54.344
54.345 - void relocate_last(int index) {
54.346 - if (index != int(data.size()) - 1) {
54.347 - data[index] = data.back();
54.348 - if (data[index].prev != -1) {
54.349 - data[data[index].prev].next = index;
54.350 + void relocateLast(int index) {
54.351 + if (index != int(_data.size()) - 1) {
54.352 + _data[index] = _data.back();
54.353 + if (_data[index].prev != -1) {
54.354 + _data[_data[index].prev].next = index;
54.355 } else {
54.356 - boxes[data[index].box].first = index;
54.357 + _boxes[_data[index].box].first = index;
54.358 }
54.359 - if (data[index].next != -1) {
54.360 - data[data[index].next].prev = index;
54.361 + if (_data[index].next != -1) {
54.362 + _data[_data[index].next].prev = index;
54.363 }
54.364 - _iim[data[index].item] = index;
54.365 + _iim[_data[index].item] = index;
54.366 }
54.367 - data.pop_back();
54.368 + _data.pop_back();
54.369 }
54.370
54.371 public:
54.372
54.373 /// \brief Insert an item into the heap with the given priority.
54.374 ///
54.375 - /// Adds \c i to the heap with priority \c p.
54.376 + /// This function inserts the given item into the heap with the
54.377 + /// given priority.
54.378 /// \param i The item to insert.
54.379 /// \param p The priority of the item.
54.380 + /// \pre \e i must not be stored in the heap.
54.381 + /// \warning This method may throw an \c UnderFlowPriorityException.
54.382 void push(const Item &i, const Prio &p) {
54.383 - int n = data.size();
54.384 + int n = _data.size();
54.385 _iim.set(i, n);
54.386 - data.push_back(RadixItem(i, p));
54.387 - while (lower(boxes.size() - 1, p)) {
54.388 + _data.push_back(RadixItem(i, p));
54.389 + while (lower(_boxes.size() - 1, p)) {
54.390 extend();
54.391 }
54.392 - int box = findDown(boxes.size() - 1, p);
54.393 + int box = findDown(_boxes.size() - 1, p);
54.394 insert(box, n);
54.395 }
54.396
54.397 - /// \brief Returns the item with minimum priority.
54.398 + /// \brief Return the item having minimum priority.
54.399 ///
54.400 - /// This method returns the item with minimum priority.
54.401 - /// \pre The heap must be nonempty.
54.402 + /// This function returns the item having minimum priority.
54.403 + /// \pre The heap must be non-empty.
54.404 Item top() const {
54.405 const_cast<RadixHeap<ItemIntMap>&>(*this).moveDown();
54.406 - return data[boxes[0].first].item;
54.407 + return _data[_boxes[0].first].item;
54.408 }
54.409
54.410 - /// \brief Returns the minimum priority.
54.411 + /// \brief The minimum priority.
54.412 ///
54.413 - /// It returns the minimum priority.
54.414 - /// \pre The heap must be nonempty.
54.415 + /// This function returns the minimum priority.
54.416 + /// \pre The heap must be non-empty.
54.417 Prio prio() const {
54.418 const_cast<RadixHeap<ItemIntMap>&>(*this).moveDown();
54.419 - return data[boxes[0].first].prio;
54.420 + return _data[_boxes[0].first].prio;
54.421 }
54.422
54.423 - /// \brief Deletes the item with minimum priority.
54.424 + /// \brief Remove the item having minimum priority.
54.425 ///
54.426 - /// This method deletes the item with minimum priority.
54.427 + /// This function removes the item having minimum priority.
54.428 /// \pre The heap must be non-empty.
54.429 void pop() {
54.430 moveDown();
54.431 - int index = boxes[0].first;
54.432 - _iim[data[index].item] = POST_HEAP;
54.433 + int index = _boxes[0].first;
54.434 + _iim[_data[index].item] = POST_HEAP;
54.435 remove(index);
54.436 - relocate_last(index);
54.437 + relocateLast(index);
54.438 }
54.439
54.440 - /// \brief Deletes \c i from the heap.
54.441 + /// \brief Remove the given item from the heap.
54.442 ///
54.443 - /// This method deletes item \c i from the heap, if \c i was
54.444 - /// already stored in the heap.
54.445 - /// \param i The item to erase.
54.446 + /// This function removes the given item from the heap if it is
54.447 + /// already stored.
54.448 + /// \param i The item to delete.
54.449 + /// \pre \e i must be in the heap.
54.450 void erase(const Item &i) {
54.451 int index = _iim[i];
54.452 _iim[i] = POST_HEAP;
54.453 remove(index);
54.454 - relocate_last(index);
54.455 + relocateLast(index);
54.456 }
54.457
54.458 - /// \brief Returns the priority of \c i.
54.459 + /// \brief The priority of the given item.
54.460 ///
54.461 - /// This function returns the priority of item \c i.
54.462 - /// \pre \c i must be in the heap.
54.463 + /// This function returns the priority of the given item.
54.464 /// \param i The item.
54.465 + /// \pre \e i must be in the heap.
54.466 Prio operator[](const Item &i) const {
54.467 int idx = _iim[i];
54.468 - return data[idx].prio;
54.469 + return _data[idx].prio;
54.470 }
54.471
54.472 - /// \brief \c i gets to the heap with priority \c p independently
54.473 - /// if \c i was already there.
54.474 + /// \brief Set the priority of an item or insert it, if it is
54.475 + /// not stored in the heap.
54.476 ///
54.477 - /// This method calls \ref push(\c i, \c p) if \c i is not stored
54.478 - /// in the heap and sets the priority of \c i to \c p otherwise.
54.479 - /// It may throw an \e UnderFlowPriorityException.
54.480 + /// This method sets the priority of the given item if it is
54.481 + /// already stored in the heap. Otherwise it inserts the given
54.482 + /// item into the heap with the given priority.
54.483 /// \param i The item.
54.484 /// \param p The priority.
54.485 + /// \pre \e i must be in the heap.
54.486 + /// \warning This method may throw an \c UnderFlowPriorityException.
54.487 void set(const Item &i, const Prio &p) {
54.488 int idx = _iim[i];
54.489 if( idx < 0 ) {
54.490 push(i, p);
54.491 }
54.492 - else if( p >= data[idx].prio ) {
54.493 - data[idx].prio = p;
54.494 - bubble_up(idx);
54.495 + else if( p >= _data[idx].prio ) {
54.496 + _data[idx].prio = p;
54.497 + bubbleUp(idx);
54.498 } else {
54.499 - data[idx].prio = p;
54.500 - bubble_down(idx);
54.501 + _data[idx].prio = p;
54.502 + bubbleDown(idx);
54.503 }
54.504 }
54.505
54.506 -
54.507 - /// \brief Decreases the priority of \c i to \c p.
54.508 + /// \brief Decrease the priority of an item to the given value.
54.509 ///
54.510 - /// This method decreases the priority of item \c i to \c p.
54.511 - /// \pre \c i must be stored in the heap with priority at least \c p, and
54.512 - /// \c should be greater or equal to the last removed item's priority.
54.513 + /// This function decreases the priority of an item to the given value.
54.514 /// \param i The item.
54.515 /// \param p The priority.
54.516 + /// \pre \e i must be stored in the heap with priority at least \e p.
54.517 + /// \warning This method may throw an \c UnderFlowPriorityException.
54.518 void decrease(const Item &i, const Prio &p) {
54.519 int idx = _iim[i];
54.520 - data[idx].prio = p;
54.521 - bubble_down(idx);
54.522 + _data[idx].prio = p;
54.523 + bubbleDown(idx);
54.524 }
54.525
54.526 - /// \brief Increases the priority of \c i to \c p.
54.527 + /// \brief Increase the priority of an item to the given value.
54.528 ///
54.529 - /// This method sets the priority of item \c i to \c p.
54.530 - /// \pre \c i must be stored in the heap with priority at most \c p
54.531 + /// This function increases the priority of an item to the given value.
54.532 /// \param i The item.
54.533 /// \param p The priority.
54.534 + /// \pre \e i must be stored in the heap with priority at most \e p.
54.535 void increase(const Item &i, const Prio &p) {
54.536 int idx = _iim[i];
54.537 - data[idx].prio = p;
54.538 - bubble_up(idx);
54.539 + _data[idx].prio = p;
54.540 + bubbleUp(idx);
54.541 }
54.542
54.543 - /// \brief Returns if \c item is in, has already been in, or has
54.544 - /// never been in the heap.
54.545 + /// \brief Return the state of an item.
54.546 ///
54.547 - /// This method returns PRE_HEAP if \c item has never been in the
54.548 - /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
54.549 - /// otherwise. In the latter case it is possible that \c item will
54.550 - /// get back to the heap again.
54.551 + /// This method returns \c PRE_HEAP if the given item has never
54.552 + /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
54.553 + /// and \c POST_HEAP otherwise.
54.554 + /// In the latter case it is possible that the item will get back
54.555 + /// to the heap again.
54.556 /// \param i The item.
54.557 State state(const Item &i) const {
54.558 int s = _iim[i];
54.559 @@ -405,11 +410,11 @@
54.560 return State(s);
54.561 }
54.562
54.563 - /// \brief Sets the state of the \c item in the heap.
54.564 + /// \brief Set the state of an item in the heap.
54.565 ///
54.566 - /// Sets the state of the \c item in the heap. It can be used to
54.567 - /// manually clear the heap when it is important to achive the
54.568 - /// better time complexity.
54.569 + /// This function sets the state of the given item in the heap.
54.570 + /// It can be used to manually clear the heap when it is important
54.571 + /// to achive better time complexity.
54.572 /// \param i The item.
54.573 /// \param st The state. It should not be \c IN_HEAP.
54.574 void state(const Item& i, State st) {
55.1 --- a/lemon/smart_graph.h Tue Aug 18 10:08:28 2009 +0200
55.2 +++ b/lemon/smart_graph.h Thu Nov 05 08:39:49 2009 +0100
55.3 @@ -32,10 +32,7 @@
55.4 namespace lemon {
55.5
55.6 class SmartDigraph;
55.7 - ///Base of SmartDigraph
55.8
55.9 - ///Base of SmartDigraph
55.10 - ///
55.11 class SmartDigraphBase {
55.12 protected:
55.13
55.14 @@ -187,28 +184,26 @@
55.15 ///
55.16 ///\brief A smart directed graph class.
55.17 ///
55.18 - ///This is a simple and fast digraph implementation.
55.19 - ///It is also quite memory efficient, but at the price
55.20 - ///that <b> it does support only limited (only stack-like)
55.21 - ///node and arc deletions</b>.
55.22 - ///It fully conforms to the \ref concepts::Digraph "Digraph concept".
55.23 + ///\ref SmartDigraph is a simple and fast digraph implementation.
55.24 + ///It is also quite memory efficient but at the price
55.25 + ///that it does not support node and arc deletion
55.26 + ///(except for the Snapshot feature).
55.27 ///
55.28 - ///\sa concepts::Digraph.
55.29 + ///This type fully conforms to the \ref concepts::Digraph "Digraph concept"
55.30 + ///and it also provides some additional functionalities.
55.31 + ///Most of its member functions and nested classes are documented
55.32 + ///only in the concept class.
55.33 + ///
55.34 + ///\sa concepts::Digraph
55.35 + ///\sa SmartGraph
55.36 class SmartDigraph : public ExtendedSmartDigraphBase {
55.37 typedef ExtendedSmartDigraphBase Parent;
55.38
55.39 private:
55.40 -
55.41 - ///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead.
55.42 -
55.43 - ///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead.
55.44 - ///
55.45 + /// Digraphs are \e not copy constructible. Use DigraphCopy instead.
55.46 SmartDigraph(const SmartDigraph &) : ExtendedSmartDigraphBase() {};
55.47 - ///\brief Assignment of SmartDigraph to another one is \e not allowed.
55.48 - ///Use DigraphCopy() instead.
55.49 -
55.50 - ///Assignment of SmartDigraph to another one is \e not allowed.
55.51 - ///Use DigraphCopy() instead.
55.52 + /// \brief Assignment of a digraph to another one is \e not allowed.
55.53 + /// Use DigraphCopy instead.
55.54 void operator=(const SmartDigraph &) {}
55.55
55.56 public:
55.57 @@ -221,79 +216,49 @@
55.58
55.59 ///Add a new node to the digraph.
55.60
55.61 - /// Add a new node to the digraph.
55.62 - /// \return The new node.
55.63 + ///This function adds a new node to the digraph.
55.64 + ///\return The new node.
55.65 Node addNode() { return Parent::addNode(); }
55.66
55.67 ///Add a new arc to the digraph.
55.68
55.69 - ///Add a new arc to the digraph with source node \c s
55.70 + ///This function adds a new arc to the digraph with source node \c s
55.71 ///and target node \c t.
55.72 ///\return The new arc.
55.73 - Arc addArc(const Node& s, const Node& t) {
55.74 + Arc addArc(Node s, Node t) {
55.75 return Parent::addArc(s, t);
55.76 }
55.77
55.78 - /// \brief Using this it is possible to avoid the superfluous memory
55.79 - /// allocation.
55.80 -
55.81 - /// Using this it is possible to avoid the superfluous memory
55.82 - /// allocation: if you know that the digraph you want to build will
55.83 - /// be very large (e.g. it will contain millions of nodes and/or arcs)
55.84 - /// then it is worth reserving space for this amount before starting
55.85 - /// to build the digraph.
55.86 - /// \sa reserveArc
55.87 - void reserveNode(int n) { nodes.reserve(n); };
55.88 -
55.89 - /// \brief Using this it is possible to avoid the superfluous memory
55.90 - /// allocation.
55.91 -
55.92 - /// Using this it is possible to avoid the superfluous memory
55.93 - /// allocation: if you know that the digraph you want to build will
55.94 - /// be very large (e.g. it will contain millions of nodes and/or arcs)
55.95 - /// then it is worth reserving space for this amount before starting
55.96 - /// to build the digraph.
55.97 - /// \sa reserveNode
55.98 - void reserveArc(int m) { arcs.reserve(m); };
55.99 -
55.100 /// \brief Node validity check
55.101 ///
55.102 - /// This function gives back true if the given node is valid,
55.103 - /// ie. it is a real node of the graph.
55.104 + /// This function gives back \c true if the given node is valid,
55.105 + /// i.e. it is a real node of the digraph.
55.106 ///
55.107 /// \warning A removed node (using Snapshot) could become valid again
55.108 - /// when new nodes are added to the graph.
55.109 + /// if new nodes are added to the digraph.
55.110 bool valid(Node n) const { return Parent::valid(n); }
55.111
55.112 /// \brief Arc validity check
55.113 ///
55.114 - /// This function gives back true if the given arc is valid,
55.115 - /// ie. it is a real arc of the graph.
55.116 + /// This function gives back \c true if the given arc is valid,
55.117 + /// i.e. it is a real arc of the digraph.
55.118 ///
55.119 /// \warning A removed arc (using Snapshot) could become valid again
55.120 - /// when new arcs are added to the graph.
55.121 + /// if new arcs are added to the graph.
55.122 bool valid(Arc a) const { return Parent::valid(a); }
55.123
55.124 - ///Clear the digraph.
55.125 -
55.126 - ///Erase all the nodes and arcs from the digraph.
55.127 - ///
55.128 - void clear() {
55.129 - Parent::clear();
55.130 - }
55.131 -
55.132 ///Split a node.
55.133
55.134 - ///This function splits a node. First a new node is added to the digraph,
55.135 - ///then the source of each outgoing arc of \c n is moved to this new node.
55.136 - ///If \c connect is \c true (this is the default value), then a new arc
55.137 - ///from \c n to the newly created node is also added.
55.138 + ///This function splits the given node. First, a new node is added
55.139 + ///to the digraph, then the source of each outgoing arc of node \c n
55.140 + ///is moved to this new node.
55.141 + ///If the second parameter \c connect is \c true (this is the default
55.142 + ///value), then a new arc from node \c n to the newly created node
55.143 + ///is also added.
55.144 ///\return The newly created node.
55.145 ///
55.146 - ///\note The <tt>Arc</tt>s
55.147 - ///referencing a moved arc remain
55.148 - ///valid. However <tt>InArc</tt>'s and <tt>OutArc</tt>'s
55.149 - ///may be invalidated.
55.150 + ///\note All iterators remain valid.
55.151 + ///
55.152 ///\warning This functionality cannot be used together with the Snapshot
55.153 ///feature.
55.154 Node split(Node n, bool connect = true)
55.155 @@ -308,6 +273,34 @@
55.156 return b;
55.157 }
55.158
55.159 + ///Clear the digraph.
55.160 +
55.161 + ///This function erases all nodes and arcs from the digraph.
55.162 + ///
55.163 + void clear() {
55.164 + Parent::clear();
55.165 + }
55.166 +
55.167 + /// Reserve memory for nodes.
55.168 +
55.169 + /// Using this function, it is possible to avoid superfluous memory
55.170 + /// allocation: if you know that the digraph you want to build will
55.171 + /// be large (e.g. it will contain millions of nodes and/or arcs),
55.172 + /// then it is worth reserving space for this amount before starting
55.173 + /// to build the digraph.
55.174 + /// \sa reserveArc()
55.175 + void reserveNode(int n) { nodes.reserve(n); };
55.176 +
55.177 + /// Reserve memory for arcs.
55.178 +
55.179 + /// Using this function, it is possible to avoid superfluous memory
55.180 + /// allocation: if you know that the digraph you want to build will
55.181 + /// be large (e.g. it will contain millions of nodes and/or arcs),
55.182 + /// then it is worth reserving space for this amount before starting
55.183 + /// to build the digraph.
55.184 + /// \sa reserveNode()
55.185 + void reserveArc(int m) { arcs.reserve(m); };
55.186 +
55.187 public:
55.188
55.189 class Snapshot;
55.190 @@ -332,20 +325,23 @@
55.191
55.192 public:
55.193
55.194 - ///Class to make a snapshot of the digraph and to restrore to it later.
55.195 + ///Class to make a snapshot of the digraph and to restore it later.
55.196
55.197 - ///Class to make a snapshot of the digraph and to restrore to it later.
55.198 + ///Class to make a snapshot of the digraph and to restore it later.
55.199 ///
55.200 ///The newly added nodes and arcs can be removed using the
55.201 - ///restore() function.
55.202 - ///\note After you restore a state, you cannot restore
55.203 - ///a later state, in other word you cannot add again the arcs deleted
55.204 - ///by restore() using another one Snapshot instance.
55.205 + ///restore() function. This is the only way for deleting nodes and/or
55.206 + ///arcs from a SmartDigraph structure.
55.207 ///
55.208 - ///\warning If you do not use correctly the snapshot that can cause
55.209 - ///either broken program, invalid state of the digraph, valid but
55.210 - ///not the restored digraph or no change. Because the runtime performance
55.211 - ///the validity of the snapshot is not stored.
55.212 + ///\note After a state is restored, you cannot restore a later state,
55.213 + ///i.e. you cannot add the removed nodes and arcs again using
55.214 + ///another Snapshot instance.
55.215 + ///
55.216 + ///\warning Node splitting cannot be restored.
55.217 + ///\warning The validity of the snapshot is not stored due to
55.218 + ///performance reasons. If you do not use the snapshot correctly,
55.219 + ///it can cause broken program, invalid or not restored state of
55.220 + ///the digraph or no change.
55.221 class Snapshot
55.222 {
55.223 SmartDigraph *_graph;
55.224 @@ -357,39 +353,32 @@
55.225 ///Default constructor.
55.226
55.227 ///Default constructor.
55.228 - ///To actually make a snapshot you must call save().
55.229 - ///
55.230 + ///You have to call save() to actually make a snapshot.
55.231 Snapshot() : _graph(0) {}
55.232 ///Constructor that immediately makes a snapshot
55.233
55.234 - ///This constructor immediately makes a snapshot of the digraph.
55.235 - ///\param graph The digraph we make a snapshot of.
55.236 - Snapshot(SmartDigraph &graph) : _graph(&graph) {
55.237 + ///This constructor immediately makes a snapshot of the given digraph.
55.238 + ///
55.239 + Snapshot(SmartDigraph &gr) : _graph(&gr) {
55.240 node_num=_graph->nodes.size();
55.241 arc_num=_graph->arcs.size();
55.242 }
55.243
55.244 ///Make a snapshot.
55.245
55.246 - ///Make a snapshot of the digraph.
55.247 - ///
55.248 - ///This function can be called more than once. In case of a repeated
55.249 + ///This function makes a snapshot of the given digraph.
55.250 + ///It can be called more than once. In case of a repeated
55.251 ///call, the previous snapshot gets lost.
55.252 - ///\param graph The digraph we make the snapshot of.
55.253 - void save(SmartDigraph &graph)
55.254 - {
55.255 - _graph=&graph;
55.256 + void save(SmartDigraph &gr) {
55.257 + _graph=&gr;
55.258 node_num=_graph->nodes.size();
55.259 arc_num=_graph->arcs.size();
55.260 }
55.261
55.262 ///Undo the changes until a snapshot.
55.263
55.264 - ///Undo the changes until a snapshot created by save().
55.265 - ///
55.266 - ///\note After you restored a state, you cannot restore
55.267 - ///a later state, in other word you cannot add again the arcs deleted
55.268 - ///by restore().
55.269 + ///This function undos the changes until the last snapshot
55.270 + ///created by save() or Snapshot(SmartDigraph&).
55.271 void restore()
55.272 {
55.273 _graph->restoreSnapshot(*this);
55.274 @@ -621,29 +610,26 @@
55.275 ///
55.276 /// \brief A smart undirected graph class.
55.277 ///
55.278 - /// This is a simple and fast graph implementation.
55.279 - /// It is also quite memory efficient, but at the price
55.280 - /// that <b> it does support only limited (only stack-like)
55.281 - /// node and arc deletions</b>.
55.282 - /// It fully conforms to the \ref concepts::Graph "Graph concept".
55.283 + /// \ref SmartGraph is a simple and fast graph implementation.
55.284 + /// It is also quite memory efficient but at the price
55.285 + /// that it does not support node and edge deletion
55.286 + /// (except for the Snapshot feature).
55.287 ///
55.288 - /// \sa concepts::Graph.
55.289 + /// This type fully conforms to the \ref concepts::Graph "Graph concept"
55.290 + /// and it also provides some additional functionalities.
55.291 + /// Most of its member functions and nested classes are documented
55.292 + /// only in the concept class.
55.293 + ///
55.294 + /// \sa concepts::Graph
55.295 + /// \sa SmartDigraph
55.296 class SmartGraph : public ExtendedSmartGraphBase {
55.297 typedef ExtendedSmartGraphBase Parent;
55.298
55.299 private:
55.300 -
55.301 - ///SmartGraph is \e not copy constructible. Use GraphCopy() instead.
55.302 -
55.303 - ///SmartGraph is \e not copy constructible. Use GraphCopy() instead.
55.304 - ///
55.305 + /// Graphs are \e not copy constructible. Use GraphCopy instead.
55.306 SmartGraph(const SmartGraph &) : ExtendedSmartGraphBase() {};
55.307 -
55.308 - ///\brief Assignment of SmartGraph to another one is \e not allowed.
55.309 - ///Use GraphCopy() instead.
55.310 -
55.311 - ///Assignment of SmartGraph to another one is \e not allowed.
55.312 - ///Use GraphCopy() instead.
55.313 + /// \brief Assignment of a graph to another one is \e not allowed.
55.314 + /// Use GraphCopy instead.
55.315 void operator=(const SmartGraph &) {}
55.316
55.317 public:
55.318 @@ -654,56 +640,77 @@
55.319 ///
55.320 SmartGraph() {}
55.321
55.322 - ///Add a new node to the graph.
55.323 -
55.324 - /// Add a new node to the graph.
55.325 + /// \brief Add a new node to the graph.
55.326 + ///
55.327 + /// This function adds a new node to the graph.
55.328 /// \return The new node.
55.329 Node addNode() { return Parent::addNode(); }
55.330
55.331 - ///Add a new edge to the graph.
55.332 -
55.333 - ///Add a new edge to the graph with node \c s
55.334 - ///and \c t.
55.335 - ///\return The new edge.
55.336 - Edge addEdge(const Node& s, const Node& t) {
55.337 - return Parent::addEdge(s, t);
55.338 + /// \brief Add a new edge to the graph.
55.339 + ///
55.340 + /// This function adds a new edge to the graph between nodes
55.341 + /// \c u and \c v with inherent orientation from node \c u to
55.342 + /// node \c v.
55.343 + /// \return The new edge.
55.344 + Edge addEdge(Node u, Node v) {
55.345 + return Parent::addEdge(u, v);
55.346 }
55.347
55.348 /// \brief Node validity check
55.349 ///
55.350 - /// This function gives back true if the given node is valid,
55.351 - /// ie. it is a real node of the graph.
55.352 + /// This function gives back \c true if the given node is valid,
55.353 + /// i.e. it is a real node of the graph.
55.354 ///
55.355 /// \warning A removed node (using Snapshot) could become valid again
55.356 - /// when new nodes are added to the graph.
55.357 + /// if new nodes are added to the graph.
55.358 bool valid(Node n) const { return Parent::valid(n); }
55.359
55.360 + /// \brief Edge validity check
55.361 + ///
55.362 + /// This function gives back \c true if the given edge is valid,
55.363 + /// i.e. it is a real edge of the graph.
55.364 + ///
55.365 + /// \warning A removed edge (using Snapshot) could become valid again
55.366 + /// if new edges are added to the graph.
55.367 + bool valid(Edge e) const { return Parent::valid(e); }
55.368 +
55.369 /// \brief Arc validity check
55.370 ///
55.371 - /// This function gives back true if the given arc is valid,
55.372 - /// ie. it is a real arc of the graph.
55.373 + /// This function gives back \c true if the given arc is valid,
55.374 + /// i.e. it is a real arc of the graph.
55.375 ///
55.376 /// \warning A removed arc (using Snapshot) could become valid again
55.377 - /// when new edges are added to the graph.
55.378 + /// if new edges are added to the graph.
55.379 bool valid(Arc a) const { return Parent::valid(a); }
55.380
55.381 - /// \brief Edge validity check
55.382 - ///
55.383 - /// This function gives back true if the given edge is valid,
55.384 - /// ie. it is a real edge of the graph.
55.385 - ///
55.386 - /// \warning A removed edge (using Snapshot) could become valid again
55.387 - /// when new edges are added to the graph.
55.388 - bool valid(Edge e) const { return Parent::valid(e); }
55.389 -
55.390 ///Clear the graph.
55.391
55.392 - ///Erase all the nodes and edges from the graph.
55.393 + ///This function erases all nodes and arcs from the graph.
55.394 ///
55.395 void clear() {
55.396 Parent::clear();
55.397 }
55.398
55.399 + /// Reserve memory for nodes.
55.400 +
55.401 + /// Using this function, it is possible to avoid superfluous memory
55.402 + /// allocation: if you know that the graph you want to build will
55.403 + /// be large (e.g. it will contain millions of nodes and/or edges),
55.404 + /// then it is worth reserving space for this amount before starting
55.405 + /// to build the graph.
55.406 + /// \sa reserveEdge()
55.407 + void reserveNode(int n) { nodes.reserve(n); };
55.408 +
55.409 + /// Reserve memory for edges.
55.410 +
55.411 + /// Using this function, it is possible to avoid superfluous memory
55.412 + /// allocation: if you know that the graph you want to build will
55.413 + /// be large (e.g. it will contain millions of nodes and/or edges),
55.414 + /// then it is worth reserving space for this amount before starting
55.415 + /// to build the graph.
55.416 + /// \sa reserveNode()
55.417 + void reserveEdge(int m) { arcs.reserve(2 * m); };
55.418 +
55.419 public:
55.420
55.421 class Snapshot;
55.422 @@ -742,21 +749,22 @@
55.423
55.424 public:
55.425
55.426 - ///Class to make a snapshot of the digraph and to restrore to it later.
55.427 + ///Class to make a snapshot of the graph and to restore it later.
55.428
55.429 - ///Class to make a snapshot of the digraph and to restrore to it later.
55.430 + ///Class to make a snapshot of the graph and to restore it later.
55.431 ///
55.432 - ///The newly added nodes and arcs can be removed using the
55.433 - ///restore() function.
55.434 + ///The newly added nodes and edges can be removed using the
55.435 + ///restore() function. This is the only way for deleting nodes and/or
55.436 + ///edges from a SmartGraph structure.
55.437 ///
55.438 - ///\note After you restore a state, you cannot restore
55.439 - ///a later state, in other word you cannot add again the arcs deleted
55.440 - ///by restore() using another one Snapshot instance.
55.441 + ///\note After a state is restored, you cannot restore a later state,
55.442 + ///i.e. you cannot add the removed nodes and edges again using
55.443 + ///another Snapshot instance.
55.444 ///
55.445 - ///\warning If you do not use correctly the snapshot that can cause
55.446 - ///either broken program, invalid state of the digraph, valid but
55.447 - ///not the restored digraph or no change. Because the runtime performance
55.448 - ///the validity of the snapshot is not stored.
55.449 + ///\warning The validity of the snapshot is not stored due to
55.450 + ///performance reasons. If you do not use the snapshot correctly,
55.451 + ///it can cause broken program, invalid or not restored state of
55.452 + ///the graph or no change.
55.453 class Snapshot
55.454 {
55.455 SmartGraph *_graph;
55.456 @@ -768,36 +776,30 @@
55.457 ///Default constructor.
55.458
55.459 ///Default constructor.
55.460 - ///To actually make a snapshot you must call save().
55.461 - ///
55.462 + ///You have to call save() to actually make a snapshot.
55.463 Snapshot() : _graph(0) {}
55.464 ///Constructor that immediately makes a snapshot
55.465
55.466 - ///This constructor immediately makes a snapshot of the digraph.
55.467 - ///\param graph The digraph we make a snapshot of.
55.468 - Snapshot(SmartGraph &graph) {
55.469 - graph.saveSnapshot(*this);
55.470 + /// This constructor immediately makes a snapshot of the given graph.
55.471 + ///
55.472 + Snapshot(SmartGraph &gr) {
55.473 + gr.saveSnapshot(*this);
55.474 }
55.475
55.476 ///Make a snapshot.
55.477
55.478 - ///Make a snapshot of the graph.
55.479 - ///
55.480 - ///This function can be called more than once. In case of a repeated
55.481 + ///This function makes a snapshot of the given graph.
55.482 + ///It can be called more than once. In case of a repeated
55.483 ///call, the previous snapshot gets lost.
55.484 - ///\param graph The digraph we make the snapshot of.
55.485 - void save(SmartGraph &graph)
55.486 + void save(SmartGraph &gr)
55.487 {
55.488 - graph.saveSnapshot(*this);
55.489 + gr.saveSnapshot(*this);
55.490 }
55.491
55.492 - ///Undo the changes until a snapshot.
55.493 + ///Undo the changes until the last snapshot.
55.494
55.495 - ///Undo the changes until a snapshot created by save().
55.496 - ///
55.497 - ///\note After you restored a state, you cannot restore
55.498 - ///a later state, in other word you cannot add again the arcs deleted
55.499 - ///by restore().
55.500 + ///This function undos the changes until the last snapshot
55.501 + ///created by save() or Snapshot(SmartGraph&).
55.502 void restore()
55.503 {
55.504 _graph->restoreSnapshot(*this);
56.1 --- a/lemon/soplex.cc Tue Aug 18 10:08:28 2009 +0200
56.2 +++ b/lemon/soplex.cc Thu Nov 05 08:39:49 2009 +0100
56.3 @@ -91,6 +91,19 @@
56.4 return soplex->nRows() - 1;
56.5 }
56.6
56.7 + int SoplexLp::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
56.8 + soplex::DSVector v;
56.9 + for (ExprIterator it = b; it != e; ++it) {
56.10 + v.add(it->first, it->second);
56.11 + }
56.12 + soplex::LPRow r(l, v, u);
56.13 + soplex->addRow(r);
56.14 +
56.15 + _row_names.push_back(std::string());
56.16 +
56.17 + return soplex->nRows() - 1;
56.18 + }
56.19 +
56.20
56.21 void SoplexLp::_eraseCol(int i) {
56.22 soplex->removeCol(i);
57.1 --- a/lemon/soplex.h Tue Aug 18 10:08:28 2009 +0200
57.2 +++ b/lemon/soplex.h Thu Nov 05 08:39:49 2009 +0100
57.3 @@ -84,6 +84,7 @@
57.4
57.5 virtual int _addCol();
57.6 virtual int _addRow();
57.7 + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
57.8
57.9 virtual void _eraseCol(int i);
57.10 virtual void _eraseRow(int i);
58.1 --- a/m4/lx_check_coin.m4 Tue Aug 18 10:08:28 2009 +0200
58.2 +++ b/m4/lx_check_coin.m4 Thu Nov 05 08:39:49 2009 +0100
58.3 @@ -88,7 +88,7 @@
58.4 elif test x"$with_coin" != x"yes"; then
58.5 CBC_LDFLAGS="-L$with_coin/lib"
58.6 fi
58.7 - CBC_LIBS="-lOsi -lCbc -lOsiCbc -lCbcSolver -lClp -lOsiClp -lCoinUtils -lVol -lOsiVol -lCgl -lm -llapack -lblas"
58.8 + CBC_LIBS="-lOsi -lCbc -lCbcSolver -lClp -lOsiClp -lCoinUtils -lVol -lOsiVol -lCgl -lm -llapack -lblas"
58.9
58.10 lx_save_cxxflags="$CXXFLAGS"
58.11 lx_save_ldflags="$LDFLAGS"
59.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
59.2 +++ b/scripts/bib2dox.py Thu Nov 05 08:39:49 2009 +0100
59.3 @@ -0,0 +1,811 @@
59.4 +#!/usr/bin/env /usr/local/Python/bin/python2.1
59.5 +"""
59.6 + BibTeX to Doxygen converter
59.7 + Usage: python bib2dox.py bibfile.bib > bibfile.dox
59.8 +
59.9 + This code is the modification of the BibTeX to XML converter
59.10 + by Vidar Bronken Gundersen et al. See the original copyright notices below.
59.11 +
59.12 + **********************************************************************
59.13 +
59.14 + Decoder for bibliographic data, BibTeX
59.15 + Usage: python bibtex2xml.py bibfile.bib > bibfile.xml
59.16 +
59.17 + v.8
59.18 + (c)2002-06-23 Vidar Bronken Gundersen
59.19 + http://bibtexml.sf.net/
59.20 + Reuse approved as long as this notification is kept.
59.21 + Licence: GPL.
59.22 +
59.23 + Contributions/thanks to:
59.24 + Egon Willighagen, http://sf.net/projects/jreferences/
59.25 + Richard Mahoney (for providing a test case)
59.26 +
59.27 + Editted by Sara Sprenkle to be more robust and handle more bibtex features.
59.28 + (c) 2003-01-15
59.29 +
59.30 + 1. Changed bibtex: tags to bibxml: tags.
59.31 + 2. Use xmlns:bibxml="http://bibtexml.sf.net/"
59.32 + 3. Allow spaces between @type and first {
59.33 + 4. "author" fields with multiple authors split by " and "
59.34 + are put in separate xml "bibxml:author" tags.
59.35 + 5. Option for Titles: words are capitalized
59.36 + only if first letter in title or capitalized inside braces
59.37 + 6. Removes braces from within field values
59.38 + 7. Ignores comments in bibtex file (including @comment{ or % )
59.39 + 8. Replaces some special latex tags, e.g., replaces ~ with ' '
59.40 + 9. Handles bibtex @string abbreviations
59.41 + --> includes bibtex's default abbreviations for months
59.42 + --> does concatenation of abbr # " more " and " more " # abbr
59.43 + 10. Handles @type( ... ) or @type{ ... }
59.44 + 11. The keywords field is split on , or ; and put into separate xml
59.45 + "bibxml:keywords" tags
59.46 + 12. Ignores @preamble
59.47 +
59.48 + Known Limitations
59.49 + 1. Does not transform Latex encoding like math mode and special
59.50 + latex symbols.
59.51 + 2. Does not parse author fields into first and last names.
59.52 + E.g., It does not do anything special to an author whose name is
59.53 + in the form LAST_NAME, FIRST_NAME
59.54 + In "author" tag, will show up as
59.55 + <bibxml:author>LAST_NAME, FIRST_NAME</bibxml:author>
59.56 + 3. Does not handle "crossref" fields other than to print
59.57 + <bibxml:crossref>...</bibxml:crossref>
59.58 + 4. Does not inform user of the input's format errors. You just won't
59.59 + be able to transform the file later with XSL
59.60 +
59.61 + You will have to manually edit the XML output if you need to handle
59.62 + these (and unknown) limitations.
59.63 +
59.64 +"""
59.65 +
59.66 +import string, re
59.67 +
59.68 +# set of valid name characters
59.69 +valid_name_chars = '[\w\-:]'
59.70 +
59.71 +#
59.72 +# define global regular expression variables
59.73 +#
59.74 +author_rex = re.compile('\s+and\s+')
59.75 +rembraces_rex = re.compile('[{}]')
59.76 +capitalize_rex = re.compile('({[^}]*})')
59.77 +
59.78 +# used by bibtexkeywords(data)
59.79 +keywords_rex = re.compile('[,;]')
59.80 +
59.81 +# used by concat_line(line)
59.82 +concatsplit_rex = re.compile('\s*#\s*')
59.83 +
59.84 +# split on {, }, or " in verify_out_of_braces
59.85 +delimiter_rex = re.compile('([{}"])',re.I)
59.86 +
59.87 +field_rex = re.compile('\s*(\w*)\s*=\s*(.*)')
59.88 +data_rex = re.compile('\s*(\w*)\s*=\s*([^,]*),?')
59.89 +
59.90 +url_rex = re.compile('\\\url\{([^}]*)\}')
59.91 +
59.92 +#
59.93 +# styles for html formatting
59.94 +#
59.95 +divstyle = 'margin-top: -4ex; margin-left: 8em;'
59.96 +
59.97 +#
59.98 +# return the string parameter without braces
59.99 +#
59.100 +def transformurls(str):
59.101 + return url_rex.sub(r'<a href="\1">\1</a>', str)
59.102 +
59.103 +#
59.104 +# return the string parameter without braces
59.105 +#
59.106 +def removebraces(str):
59.107 + return rembraces_rex.sub('', str)
59.108 +
59.109 +#
59.110 +# latex-specific replacements
59.111 +# (do this after braces were removed)
59.112 +#
59.113 +def latexreplacements(line):
59.114 + line = string.replace(line, '~', ' ')
59.115 + line = string.replace(line, '\\\'a', 'á')
59.116 + line = string.replace(line, '\\"a', 'ä')
59.117 + line = string.replace(line, '\\\'e', 'é')
59.118 + line = string.replace(line, '\\"e', 'ë')
59.119 + line = string.replace(line, '\\\'i', 'í')
59.120 + line = string.replace(line, '\\"i', 'ï')
59.121 + line = string.replace(line, '\\\'o', 'ó')
59.122 + line = string.replace(line, '\\"o', 'ö')
59.123 + line = string.replace(line, '\\\'u', 'ú')
59.124 + line = string.replace(line, '\\"u', 'ü')
59.125 + line = string.replace(line, '\\H o', 'õ')
59.126 + line = string.replace(line, '\\H u', 'ü') # ũ does not exist
59.127 + line = string.replace(line, '\\\'A', 'Á')
59.128 + line = string.replace(line, '\\"A', 'Ä')
59.129 + line = string.replace(line, '\\\'E', 'É')
59.130 + line = string.replace(line, '\\"E', 'Ë')
59.131 + line = string.replace(line, '\\\'I', 'Í')
59.132 + line = string.replace(line, '\\"I', 'Ï')
59.133 + line = string.replace(line, '\\\'O', 'Ó')
59.134 + line = string.replace(line, '\\"O', 'Ö')
59.135 + line = string.replace(line, '\\\'U', 'Ú')
59.136 + line = string.replace(line, '\\"U', 'Ü')
59.137 + line = string.replace(line, '\\H O', 'Õ')
59.138 + line = string.replace(line, '\\H U', 'Ü') # Ũ does not exist
59.139 +
59.140 + return line
59.141 +
59.142 +#
59.143 +# copy characters form a string decoding html expressions (&xyz;)
59.144 +#
59.145 +def copychars(str, ifrom, count):
59.146 + result = ''
59.147 + i = ifrom
59.148 + c = 0
59.149 + html_spec = False
59.150 + while (i < len(str)) and (c < count):
59.151 + if str[i] == '&':
59.152 + html_spec = True;
59.153 + if i+1 < len(str):
59.154 + result += str[i+1]
59.155 + c += 1
59.156 + i += 2
59.157 + else:
59.158 + if not html_spec:
59.159 + if ((str[i] >= 'A') and (str[i] <= 'Z')) or \
59.160 + ((str[i] >= 'a') and (str[i] <= 'z')):
59.161 + result += str[i]
59.162 + c += 1
59.163 + elif str[i] == ';':
59.164 + html_spec = False;
59.165 + i += 1
59.166 +
59.167 + return result
59.168 +
59.169 +
59.170 +#
59.171 +# Handle a list of authors (separated by 'and').
59.172 +# It gives back an array of the follwing values:
59.173 +# - num: the number of authors,
59.174 +# - list: the list of the author names,
59.175 +# - text: the bibtex text (separated by commas and/or 'and')
59.176 +# - abbrev: abbreviation that can be used for indicate the
59.177 +# bibliography entries
59.178 +#
59.179 +def bibtexauthor(data):
59.180 + result = {}
59.181 + bibtex = ''
59.182 + result['list'] = author_rex.split(data)
59.183 + result['num'] = len(result['list'])
59.184 + for i, author in enumerate(result['list']):
59.185 + # general transformations
59.186 + author = latexreplacements(removebraces(author.strip()))
59.187 + # transform "Xyz, A. B." to "A. B. Xyz"
59.188 + pos = author.find(',')
59.189 + if pos != -1:
59.190 + author = author[pos+1:].strip() + ' ' + author[:pos].strip()
59.191 + result['list'][i] = author
59.192 + bibtex += author + '#'
59.193 + bibtex = bibtex[:-1]
59.194 + if result['num'] > 1:
59.195 + ix = bibtex.rfind('#')
59.196 + if result['num'] == 2:
59.197 + bibtex = bibtex[:ix] + ' and ' + bibtex[ix+1:]
59.198 + else:
59.199 + bibtex = bibtex[:ix] + ', and ' + bibtex[ix+1:]
59.200 + bibtex = bibtex.replace('#', ', ')
59.201 + result['text'] = bibtex
59.202 +
59.203 + result['abbrev'] = ''
59.204 + for author in result['list']:
59.205 + pos = author.rfind(' ') + 1
59.206 + count = 1
59.207 + if result['num'] == 1:
59.208 + count = 3
59.209 + result['abbrev'] += copychars(author, pos, count)
59.210 +
59.211 + return result
59.212 +
59.213 +
59.214 +#
59.215 +# data = title string
59.216 +# @return the capitalized title (first letter is capitalized), rest are capitalized
59.217 +# only if capitalized inside braces
59.218 +#
59.219 +def capitalizetitle(data):
59.220 + title_list = capitalize_rex.split(data)
59.221 + title = ''
59.222 + count = 0
59.223 + for phrase in title_list:
59.224 + check = string.lstrip(phrase)
59.225 +
59.226 + # keep phrase's capitalization the same
59.227 + if check.find('{') == 0:
59.228 + title += removebraces(phrase)
59.229 + else:
59.230 + # first word --> capitalize first letter (after spaces)
59.231 + if count == 0:
59.232 + title += check.capitalize()
59.233 + else:
59.234 + title += phrase.lower()
59.235 + count = count + 1
59.236 +
59.237 + return title
59.238 +
59.239 +
59.240 +#
59.241 +# @return the bibtex for the title
59.242 +# @param data --> title string
59.243 +# braces are removed from title
59.244 +#
59.245 +def bibtextitle(data, entrytype):
59.246 + if entrytype in ('book', 'inbook'):
59.247 + title = removebraces(data.strip())
59.248 + else:
59.249 + title = removebraces(capitalizetitle(data.strip()))
59.250 + bibtex = title
59.251 + return bibtex
59.252 +
59.253 +
59.254 +#
59.255 +# function to compare entry lists
59.256 +#
59.257 +def entry_cmp(x, y):
59.258 + return cmp(x[0], y[0])
59.259 +
59.260 +
59.261 +#
59.262 +# print the XML for the transformed "filecont_source"
59.263 +#
59.264 +def bibtexdecoder(filecont_source):
59.265 + filecont = []
59.266 + file = []
59.267 +
59.268 + # want @<alphanumeric chars><spaces>{<spaces><any chars>,
59.269 + pubtype_rex = re.compile('@(\w*)\s*{\s*(.*),')
59.270 + endtype_rex = re.compile('}\s*$')
59.271 + endtag_rex = re.compile('^\s*}\s*$')
59.272 +
59.273 + bracefield_rex = re.compile('\s*(\w*)\s*=\s*(.*)')
59.274 + bracedata_rex = re.compile('\s*(\w*)\s*=\s*{(.*)},?')
59.275 +
59.276 + quotefield_rex = re.compile('\s*(\w*)\s*=\s*(.*)')
59.277 + quotedata_rex = re.compile('\s*(\w*)\s*=\s*"(.*)",?')
59.278 +
59.279 + for line in filecont_source:
59.280 + line = line[:-1]
59.281 +
59.282 + # encode character entities
59.283 + line = string.replace(line, '&', '&')
59.284 + line = string.replace(line, '<', '<')
59.285 + line = string.replace(line, '>', '>')
59.286 +
59.287 + # start entry: publication type (store for later use)
59.288 + if pubtype_rex.match(line):
59.289 + # want @<alphanumeric chars><spaces>{<spaces><any chars>,
59.290 + entrycont = {}
59.291 + entry = []
59.292 + entrytype = pubtype_rex.sub('\g<1>',line)
59.293 + entrytype = string.lower(entrytype)
59.294 + entryid = pubtype_rex.sub('\g<2>', line)
59.295 +
59.296 + # end entry if just a }
59.297 + elif endtype_rex.match(line):
59.298 + # generate doxygen code for the entry
59.299 +
59.300 + # enty type related formattings
59.301 + if entrytype in ('book', 'inbook'):
59.302 + entrycont['title'] = '<em>' + entrycont['title'] + '</em>'
59.303 + if not entrycont.has_key('author'):
59.304 + entrycont['author'] = entrycont['editor']
59.305 + entrycont['author']['text'] += ', editors'
59.306 + elif entrytype == 'article':
59.307 + entrycont['journal'] = '<em>' + entrycont['journal'] + '</em>'
59.308 + elif entrytype in ('inproceedings', 'incollection', 'conference'):
59.309 + entrycont['booktitle'] = '<em>' + entrycont['booktitle'] + '</em>'
59.310 + elif entrytype == 'techreport':
59.311 + if not entrycont.has_key('type'):
59.312 + entrycont['type'] = 'Technical report'
59.313 + elif entrytype == 'mastersthesis':
59.314 + entrycont['type'] = 'Master\'s thesis'
59.315 + elif entrytype == 'phdthesis':
59.316 + entrycont['type'] = 'PhD thesis'
59.317 +
59.318 + for eline in entrycont:
59.319 + if eline != '':
59.320 + eline = latexreplacements(eline)
59.321 +
59.322 + if entrycont.has_key('pages') and (entrycont['pages'] != ''):
59.323 + entrycont['pages'] = string.replace(entrycont['pages'], '--', '-')
59.324 +
59.325 + if entrycont.has_key('author') and (entrycont['author'] != ''):
59.326 + entry.append(entrycont['author']['text'] + '.')
59.327 + if entrycont.has_key('title') and (entrycont['title'] != ''):
59.328 + entry.append(entrycont['title'] + '.')
59.329 + if entrycont.has_key('journal') and (entrycont['journal'] != ''):
59.330 + entry.append(entrycont['journal'] + ',')
59.331 + if entrycont.has_key('booktitle') and (entrycont['booktitle'] != ''):
59.332 + entry.append('In ' + entrycont['booktitle'] + ',')
59.333 + if entrycont.has_key('type') and (entrycont['type'] != ''):
59.334 + eline = entrycont['type']
59.335 + if entrycont.has_key('number') and (entrycont['number'] != ''):
59.336 + eline += ' ' + entrycont['number']
59.337 + eline += ','
59.338 + entry.append(eline)
59.339 + if entrycont.has_key('institution') and (entrycont['institution'] != ''):
59.340 + entry.append(entrycont['institution'] + ',')
59.341 + if entrycont.has_key('publisher') and (entrycont['publisher'] != ''):
59.342 + entry.append(entrycont['publisher'] + ',')
59.343 + if entrycont.has_key('school') and (entrycont['school'] != ''):
59.344 + entry.append(entrycont['school'] + ',')
59.345 + if entrycont.has_key('address') and (entrycont['address'] != ''):
59.346 + entry.append(entrycont['address'] + ',')
59.347 + if entrycont.has_key('edition') and (entrycont['edition'] != ''):
59.348 + entry.append(entrycont['edition'] + ' edition,')
59.349 + if entrycont.has_key('howpublished') and (entrycont['howpublished'] != ''):
59.350 + entry.append(entrycont['howpublished'] + ',')
59.351 + if entrycont.has_key('volume') and (entrycont['volume'] != ''):
59.352 + eline = entrycont['volume'];
59.353 + if entrycont.has_key('number') and (entrycont['number'] != ''):
59.354 + eline += '(' + entrycont['number'] + ')'
59.355 + if entrycont.has_key('pages') and (entrycont['pages'] != ''):
59.356 + eline += ':' + entrycont['pages']
59.357 + eline += ','
59.358 + entry.append(eline)
59.359 + else:
59.360 + if entrycont.has_key('pages') and (entrycont['pages'] != ''):
59.361 + entry.append('pages ' + entrycont['pages'] + ',')
59.362 + if entrycont.has_key('year') and (entrycont['year'] != ''):
59.363 + if entrycont.has_key('month') and (entrycont['month'] != ''):
59.364 + entry.append(entrycont['month'] + ' ' + entrycont['year'] + '.')
59.365 + else:
59.366 + entry.append(entrycont['year'] + '.')
59.367 + if entrycont.has_key('note') and (entrycont['note'] != ''):
59.368 + entry.append(entrycont['note'] + '.')
59.369 + if entrycont.has_key('url') and (entrycont['url'] != ''):
59.370 + entry.append(entrycont['url'] + '.')
59.371 +
59.372 + # generate keys for sorting and for the output
59.373 + sortkey = ''
59.374 + bibkey = ''
59.375 + if entrycont.has_key('author'):
59.376 + for author in entrycont['author']['list']:
59.377 + sortkey += copychars(author, author.rfind(' ')+1, len(author))
59.378 + bibkey = entrycont['author']['abbrev']
59.379 + else:
59.380 + bibkey = 'x'
59.381 + if entrycont.has_key('year'):
59.382 + sortkey += entrycont['year']
59.383 + bibkey += entrycont['year'][-2:]
59.384 + if entrycont.has_key('title'):
59.385 + sortkey += entrycont['title']
59.386 + if entrycont.has_key('key'):
59.387 + sortkey = entrycont['key'] + sortkey
59.388 + bibkey = entrycont['key']
59.389 + entry.insert(0, sortkey)
59.390 + entry.insert(1, bibkey)
59.391 + entry.insert(2, entryid)
59.392 +
59.393 + # add the entry to the file contents
59.394 + filecont.append(entry)
59.395 +
59.396 + else:
59.397 + # field, publication info
59.398 + field = ''
59.399 + data = ''
59.400 +
59.401 + # field = {data} entries
59.402 + if bracedata_rex.match(line):
59.403 + field = bracefield_rex.sub('\g<1>', line)
59.404 + field = string.lower(field)
59.405 + data = bracedata_rex.sub('\g<2>', line)
59.406 +
59.407 + # field = "data" entries
59.408 + elif quotedata_rex.match(line):
59.409 + field = quotefield_rex.sub('\g<1>', line)
59.410 + field = string.lower(field)
59.411 + data = quotedata_rex.sub('\g<2>', line)
59.412 +
59.413 + # field = data entries
59.414 + elif data_rex.match(line):
59.415 + field = field_rex.sub('\g<1>', line)
59.416 + field = string.lower(field)
59.417 + data = data_rex.sub('\g<2>', line)
59.418 +
59.419 + if field == 'url':
59.420 + data = '\\url{' + data.strip() + '}'
59.421 +
59.422 + if field in ('author', 'editor'):
59.423 + entrycont[field] = bibtexauthor(data)
59.424 + line = ''
59.425 + elif field == 'title':
59.426 + line = bibtextitle(data, entrytype)
59.427 + elif field != '':
59.428 + line = removebraces(transformurls(data.strip()))
59.429 +
59.430 + if line != '':
59.431 + line = latexreplacements(line)
59.432 + entrycont[field] = line
59.433 +
59.434 +
59.435 + # sort entries
59.436 + filecont.sort(entry_cmp)
59.437 +
59.438 + # count the bibtex keys
59.439 + keytable = {}
59.440 + counttable = {}
59.441 + for entry in filecont:
59.442 + bibkey = entry[1]
59.443 + if not keytable.has_key(bibkey):
59.444 + keytable[bibkey] = 1
59.445 + else:
59.446 + keytable[bibkey] += 1
59.447 +
59.448 + for bibkey in keytable.keys():
59.449 + counttable[bibkey] = 0
59.450 +
59.451 + # generate output
59.452 + for entry in filecont:
59.453 + # generate output key form the bibtex key
59.454 + bibkey = entry[1]
59.455 + entryid = entry[2]
59.456 + if keytable[bibkey] == 1:
59.457 + outkey = bibkey
59.458 + else:
59.459 + outkey = bibkey + chr(97 + counttable[bibkey])
59.460 + counttable[bibkey] += 1
59.461 +
59.462 + # append the entry code to the output
59.463 + file.append('\\section ' + entryid + ' [' + outkey + ']')
59.464 + file.append('<div style="' + divstyle + '">')
59.465 + for line in entry[3:]:
59.466 + file.append(line)
59.467 + file.append('</div>')
59.468 + file.append('')
59.469 +
59.470 + return file
59.471 +
59.472 +
59.473 +#
59.474 +# return 1 iff abbr is in line but not inside braces or quotes
59.475 +# assumes that abbr appears only once on the line (out of braces and quotes)
59.476 +#
59.477 +def verify_out_of_braces(line, abbr):
59.478 +
59.479 + phrase_split = delimiter_rex.split(line)
59.480 +
59.481 + abbr_rex = re.compile( '\\b' + abbr + '\\b', re.I)
59.482 +
59.483 + open_brace = 0
59.484 + open_quote = 0
59.485 +
59.486 + for phrase in phrase_split:
59.487 + if phrase == "{":
59.488 + open_brace = open_brace + 1
59.489 + elif phrase == "}":
59.490 + open_brace = open_brace - 1
59.491 + elif phrase == '"':
59.492 + if open_quote == 1:
59.493 + open_quote = 0
59.494 + else:
59.495 + open_quote = 1
59.496 + elif abbr_rex.search(phrase):
59.497 + if open_brace == 0 and open_quote == 0:
59.498 + return 1
59.499 +
59.500 + return 0
59.501 +
59.502 +
59.503 +#
59.504 +# a line in the form phrase1 # phrase2 # ... # phrasen
59.505 +# is returned as phrase1 phrase2 ... phrasen
59.506 +# with the correct punctuation
59.507 +# Bug: Doesn't always work with multiple abbreviations plugged in
59.508 +#
59.509 +def concat_line(line):
59.510 + # only look at part after equals
59.511 + field = field_rex.sub('\g<1>',line)
59.512 + rest = field_rex.sub('\g<2>',line)
59.513 +
59.514 + concat_line = field + ' ='
59.515 +
59.516 + pound_split = concatsplit_rex.split(rest)
59.517 +
59.518 + phrase_count = 0
59.519 + length = len(pound_split)
59.520 +
59.521 + for phrase in pound_split:
59.522 + phrase = phrase.strip()
59.523 + if phrase_count != 0:
59.524 + if phrase.startswith('"') or phrase.startswith('{'):
59.525 + phrase = phrase[1:]
59.526 + elif phrase.startswith('"'):
59.527 + phrase = phrase.replace('"','{',1)
59.528 +
59.529 + if phrase_count != length-1:
59.530 + if phrase.endswith('"') or phrase.endswith('}'):
59.531 + phrase = phrase[:-1]
59.532 + else:
59.533 + if phrase.endswith('"'):
59.534 + phrase = phrase[:-1]
59.535 + phrase = phrase + "}"
59.536 + elif phrase.endswith('",'):
59.537 + phrase = phrase[:-2]
59.538 + phrase = phrase + "},"
59.539 +
59.540 + # if phrase did have \#, add the \# back
59.541 + if phrase.endswith('\\'):
59.542 + phrase = phrase + "#"
59.543 + concat_line = concat_line + ' ' + phrase
59.544 +
59.545 + phrase_count = phrase_count + 1
59.546 +
59.547 + return concat_line
59.548 +
59.549 +
59.550 +#
59.551 +# substitute abbreviations into filecont
59.552 +# @param filecont_source - string of data from file
59.553 +#
59.554 +def bibtex_replace_abbreviations(filecont_source):
59.555 + filecont = filecont_source.splitlines()
59.556 +
59.557 + # These are defined in bibtex, so we'll define them too
59.558 + abbr_list = ['jan','feb','mar','apr','may','jun',
59.559 + 'jul','aug','sep','oct','nov','dec']
59.560 + value_list = ['January','February','March','April',
59.561 + 'May','June','July','August','September',
59.562 + 'October','November','December']
59.563 +
59.564 + abbr_rex = []
59.565 + total_abbr_count = 0
59.566 +
59.567 + front = '\\b'
59.568 + back = '(,?)\\b'
59.569 +
59.570 + for x in abbr_list:
59.571 + abbr_rex.append( re.compile( front + abbr_list[total_abbr_count] + back, re.I ) )
59.572 + total_abbr_count = total_abbr_count + 1
59.573 +
59.574 +
59.575 + abbrdef_rex = re.compile('\s*@string\s*{\s*('+ valid_name_chars +'*)\s*=(.*)',
59.576 + re.I)
59.577 +
59.578 + comment_rex = re.compile('@comment\s*{',re.I)
59.579 + preamble_rex = re.compile('@preamble\s*{',re.I)
59.580 +
59.581 + waiting_for_end_string = 0
59.582 + i = 0
59.583 + filecont2 = ''
59.584 +
59.585 + for line in filecont:
59.586 + if line == ' ' or line == '':
59.587 + continue
59.588 +
59.589 + if waiting_for_end_string:
59.590 + if re.search('}',line):
59.591 + waiting_for_end_string = 0
59.592 + continue
59.593 +
59.594 + if abbrdef_rex.search(line):
59.595 + abbr = abbrdef_rex.sub('\g<1>', line)
59.596 +
59.597 + if abbr_list.count(abbr) == 0:
59.598 + val = abbrdef_rex.sub('\g<2>', line)
59.599 + abbr_list.append(abbr)
59.600 + value_list.append(string.strip(val))
59.601 + abbr_rex.append( re.compile( front + abbr_list[total_abbr_count] + back, re.I ) )
59.602 + total_abbr_count = total_abbr_count + 1
59.603 + waiting_for_end_string = 1
59.604 + continue
59.605 +
59.606 + if comment_rex.search(line):
59.607 + waiting_for_end_string = 1
59.608 + continue
59.609 +
59.610 + if preamble_rex.search(line):
59.611 + waiting_for_end_string = 1
59.612 + continue
59.613 +
59.614 +
59.615 + # replace subsequent abbreviations with the value
59.616 + abbr_count = 0
59.617 +
59.618 + for x in abbr_list:
59.619 +
59.620 + if abbr_rex[abbr_count].search(line):
59.621 + if verify_out_of_braces(line,abbr_list[abbr_count]) == 1:
59.622 + line = abbr_rex[abbr_count].sub( value_list[abbr_count] + '\g<1>', line)
59.623 + # Check for # concatenations
59.624 + if concatsplit_rex.search(line):
59.625 + line = concat_line(line)
59.626 + abbr_count = abbr_count + 1
59.627 +
59.628 +
59.629 + filecont2 = filecont2 + line + '\n'
59.630 + i = i+1
59.631 +
59.632 +
59.633 + # Do one final pass over file
59.634 +
59.635 + # make sure that didn't end up with {" or }" after the substitution
59.636 + filecont2 = filecont2.replace('{"','{{')
59.637 + filecont2 = filecont2.replace('"}','}}')
59.638 +
59.639 + afterquotevalue_rex = re.compile('"\s*,\s*')
59.640 + afterbrace_rex = re.compile('"\s*}')
59.641 + afterbracevalue_rex = re.compile('(=\s*{[^=]*)},\s*')
59.642 +
59.643 + # add new lines to data that changed because of abbreviation substitutions
59.644 + filecont2 = afterquotevalue_rex.sub('",\n', filecont2)
59.645 + filecont2 = afterbrace_rex.sub('"\n}', filecont2)
59.646 + filecont2 = afterbracevalue_rex.sub('\g<1>},\n', filecont2)
59.647 +
59.648 + return filecont2
59.649 +
59.650 +#
59.651 +# convert @type( ... ) to @type{ ... }
59.652 +#
59.653 +def no_outer_parens(filecont):
59.654 +
59.655 + # do checking for open parens
59.656 + # will convert to braces
59.657 + paren_split = re.split('([(){}])',filecont)
59.658 +
59.659 + open_paren_count = 0
59.660 + open_type = 0
59.661 + look_next = 0
59.662 +
59.663 + # rebuild filecont
59.664 + filecont = ''
59.665 +
59.666 + at_rex = re.compile('@\w*')
59.667 +
59.668 + for phrase in paren_split:
59.669 + if look_next == 1:
59.670 + if phrase == '(':
59.671 + phrase = '{'
59.672 + open_paren_count = open_paren_count + 1
59.673 + else:
59.674 + open_type = 0
59.675 + look_next = 0
59.676 +
59.677 + if phrase == '(':
59.678 + open_paren_count = open_paren_count + 1
59.679 +
59.680 + elif phrase == ')':
59.681 + open_paren_count = open_paren_count - 1
59.682 + if open_type == 1 and open_paren_count == 0:
59.683 + phrase = '}'
59.684 + open_type = 0
59.685 +
59.686 + elif at_rex.search( phrase ):
59.687 + open_type = 1
59.688 + look_next = 1
59.689 +
59.690 + filecont = filecont + phrase
59.691 +
59.692 + return filecont
59.693 +
59.694 +
59.695 +#
59.696 +# make all whitespace into just one space
59.697 +# format the bibtex file into a usable form.
59.698 +#
59.699 +def bibtexwasher(filecont_source):
59.700 +
59.701 + space_rex = re.compile('\s+')
59.702 + comment_rex = re.compile('\s*%')
59.703 +
59.704 + filecont = []
59.705 +
59.706 + # remove trailing and excessive whitespace
59.707 + # ignore comments
59.708 + for line in filecont_source:
59.709 + line = string.strip(line)
59.710 + line = space_rex.sub(' ', line)
59.711 + # ignore comments
59.712 + if not comment_rex.match(line) and line != '':
59.713 + filecont.append(' '+ line)
59.714 +
59.715 + filecont = string.join(filecont, '')
59.716 +
59.717 + # the file is in one long string
59.718 +
59.719 + filecont = no_outer_parens(filecont)
59.720 +
59.721 + #
59.722 + # split lines according to preferred syntax scheme
59.723 + #
59.724 + filecont = re.sub('(=\s*{[^=]*)},', '\g<1>},\n', filecont)
59.725 +
59.726 + # add new lines after commas that are after values
59.727 + filecont = re.sub('"\s*,', '",\n', filecont)
59.728 + filecont = re.sub('=\s*([\w\d]+)\s*,', '= \g<1>,\n', filecont)
59.729 + filecont = re.sub('(@\w*)\s*({(\s*)[^,\s]*)\s*,',
59.730 + '\n\n\g<1>\g<2>,\n', filecont)
59.731 +
59.732 + # add new lines after }
59.733 + filecont = re.sub('"\s*}','"\n}\n', filecont)
59.734 + filecont = re.sub('}\s*,','},\n', filecont)
59.735 +
59.736 +
59.737 + filecont = re.sub('@(\w*)', '\n@\g<1>', filecont)
59.738 +
59.739 + # character encoding, reserved latex characters
59.740 + filecont = re.sub('{\\\&}', '&', filecont)
59.741 + filecont = re.sub('\\\&', '&', filecont)
59.742 +
59.743 + # do checking for open braces to get format correct
59.744 + open_brace_count = 0
59.745 + brace_split = re.split('([{}])',filecont)
59.746 +
59.747 + # rebuild filecont
59.748 + filecont = ''
59.749 +
59.750 + for phrase in brace_split:
59.751 + if phrase == '{':
59.752 + open_brace_count = open_brace_count + 1
59.753 + elif phrase == '}':
59.754 + open_brace_count = open_brace_count - 1
59.755 + if open_brace_count == 0:
59.756 + filecont = filecont + '\n'
59.757 +
59.758 + filecont = filecont + phrase
59.759 +
59.760 + filecont2 = bibtex_replace_abbreviations(filecont)
59.761 +
59.762 + # gather
59.763 + filecont = filecont2.splitlines()
59.764 + i=0
59.765 + j=0 # count the number of blank lines
59.766 + for line in filecont:
59.767 + # ignore blank lines
59.768 + if line == '' or line == ' ':
59.769 + j = j+1
59.770 + continue
59.771 + filecont[i] = line + '\n'
59.772 + i = i+1
59.773 +
59.774 + # get rid of the extra stuff at the end of the array
59.775 + # (The extra stuff are duplicates that are in the array because
59.776 + # blank lines were removed.)
59.777 + length = len( filecont)
59.778 + filecont[length-j:length] = []
59.779 +
59.780 + return filecont
59.781 +
59.782 +
59.783 +def filehandler(filepath):
59.784 + try:
59.785 + fd = open(filepath, 'r')
59.786 + filecont_source = fd.readlines()
59.787 + fd.close()
59.788 + except:
59.789 + print 'Could not open file:', filepath
59.790 + washeddata = bibtexwasher(filecont_source)
59.791 + outdata = bibtexdecoder(washeddata)
59.792 + print '/**'
59.793 + print '\page references References'
59.794 + print
59.795 + for line in outdata:
59.796 + print line
59.797 + print '*/'
59.798 +
59.799 +
59.800 +# main program
59.801 +
59.802 +def main():
59.803 + import sys
59.804 + if sys.argv[1:]:
59.805 + filepath = sys.argv[1]
59.806 + else:
59.807 + print "No input file"
59.808 + sys.exit()
59.809 + filehandler(filepath)
59.810 +
59.811 +if __name__ == "__main__": main()
59.812 +
59.813 +
59.814 +# end python script
60.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
60.2 +++ b/scripts/bootstrap.sh Thu Nov 05 08:39:49 2009 +0100
60.3 @@ -0,0 +1,134 @@
60.4 +#!/bin/bash
60.5 +#
60.6 +# This file is a part of LEMON, a generic C++ optimization library.
60.7 +#
60.8 +# Copyright (C) 2003-2009
60.9 +# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
60.10 +# (Egervary Research Group on Combinatorial Optimization, EGRES).
60.11 +#
60.12 +# Permission to use, modify and distribute this software is granted
60.13 +# provided that this copyright notice appears in all copies. For
60.14 +# precise terms see the accompanying LICENSE file.
60.15 +#
60.16 +# This software is provided "AS IS" with no warranty of any kind,
60.17 +# express or implied, and with no claim as to its suitability for any
60.18 +# purpose.
60.19 +
60.20 +
60.21 +if [ ! -f ~/.lemon-bootstrap ]; then
60.22 + echo 'Create ~/.lemon-bootstrap'.
60.23 + cat >~/.lemon-bootstrap <<EOF
60.24 +#
60.25 +# Default settings for bootstraping the LEMON source code repository
60.26 +#
60.27 +EOF
60.28 +fi
60.29 +
60.30 +source ~/.lemon-bootstrap
60.31 +if [ -f ../../../.lemon-bootstrap ]; then source ../../../.lemon-bootstrap; fi
60.32 +if [ -f ../../.lemon-bootstrap ]; then source ../../.lemon-bootstrap; fi
60.33 +if [ -f ../.lemon-bootstrap ]; then source ../.lemon-bootstrap; fi
60.34 +if [ -f ./.lemon-bootstrap ]; then source ./.lemon-bootstrap; fi
60.35 +
60.36 +
60.37 +function augment_config() {
60.38 + if [ "x${!1}" == "x" ]; then
60.39 + eval $1=$2
60.40 + echo Add "'$1'" to '~/.lemon-bootstrap'.
60.41 + echo >>~/.lemon-bootstrap
60.42 + echo $3 >>~/.lemon-bootstrap
60.43 + echo $1=$2 >>~/.lemon-bootstrap
60.44 + fi
60.45 +}
60.46 +
60.47 +augment_config LEMON_INSTALL_PREFIX /usr/local \
60.48 + "# LEMON installation prefix"
60.49 +
60.50 +augment_config COIN_OR_PREFIX /usr/local/coin-or \
60.51 + "# COIN-OR installation root prefix (used for CLP/CBC)"
60.52 +
60.53 +augment_config SOPLEX_PREFIX /usr/local/soplex \
60.54 + "# Soplex build prefix"
60.55 +
60.56 +
60.57 +function ask() {
60.58 +echo -n "$1 [$2]? "
60.59 +read _an
60.60 +if [ "x$_an" == "x" ]; then
60.61 + ret="$2"
60.62 +else
60.63 + ret=$_an
60.64 +fi
60.65 +}
60.66 +
60.67 +function yesorno() {
60.68 + ret='rossz'
60.69 + while [ "$ret" != "y" -a "$ret" != "n" -a "$ret" != "yes" -a "$ret" != "no" ]; do
60.70 + ask "$1" "$2"
60.71 + done
60.72 + if [ "$ret" != "y" -a "$ret" != "yes" ]; then
60.73 + return 1
60.74 + else
60.75 + return 0
60.76 + fi
60.77 +}
60.78 +
60.79 +if yesorno "External build" "n"
60.80 +then
60.81 + CONFIGURE_PATH=".."
60.82 +else
60.83 + CONFIGURE_PATH="."
60.84 + if yesorno "Autoreconf" "y"
60.85 + then
60.86 + AUTORE=yes
60.87 + else
60.88 + AUTORE=no
60.89 + fi
60.90 +fi
60.91 +
60.92 +if yesorno "Optimize" "n"
60.93 +then
60.94 + opt_flags=' -O2'
60.95 +else
60.96 + opt_flags=''
60.97 +fi
60.98 +
60.99 +if yesorno "Stop on warning" "y"
60.100 +then
60.101 + werror_flags=' -Werror'
60.102 +else
60.103 + werror_flags=''
60.104 +fi
60.105 +
60.106 +cxx_flags="CXXFLAGS=-ggdb$opt_flags$werror_flags"
60.107 +
60.108 +if [ -f ${COIN_OR_PREFIX}/include/coin/config_coinutils.h ]; then
60.109 + if yesorno "Use COIN-OR (CBC/CLP)" "n"
60.110 + then
60.111 + coin_flag="--with-coin=$COIN_OR_PREFIX"
60.112 + else
60.113 + coin_flag=""
60.114 + fi
60.115 +else
60.116 + coin_flag=""
60.117 +fi
60.118 +
60.119 +if [ -f ${SOPLEX_PREFIX}/src/soplex.h ]; then
60.120 + if yesorno "Use Soplex" "n"
60.121 + then
60.122 + soplex_flag="--with-soplex=$SOPLEX_PREFIX"
60.123 + else
60.124 + soplex_flag=""
60.125 + fi
60.126 +else
60.127 + soplex_flag=""
60.128 +fi
60.129 +
60.130 +if [ "x$AUTORE" == "xyes" ]; then
60.131 + autoreconf -vif;
60.132 +fi
60.133 +${CONFIGURE_PATH}/configure --prefix=$LEMON_INSTALL_PREFIX \
60.134 +"$cxx_flags" \
60.135 +$coin_flag \
60.136 +$soplex_flag \
60.137 +$*
61.1 --- a/scripts/chg-len.py Tue Aug 18 10:08:28 2009 +0200
61.2 +++ b/scripts/chg-len.py Thu Nov 05 08:39:49 2009 +0100
61.3 @@ -1,4 +1,18 @@
61.4 #! /usr/bin/env python
61.5 +#
61.6 +# This file is a part of LEMON, a generic C++ optimization library.
61.7 +#
61.8 +# Copyright (C) 2003-2009
61.9 +# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
61.10 +# (Egervary Research Group on Combinatorial Optimization, EGRES).
61.11 +#
61.12 +# Permission to use, modify and distribute this software is granted
61.13 +# provided that this copyright notice appears in all copies. For
61.14 +# precise terms see the accompanying LICENSE file.
61.15 +#
61.16 +# This software is provided "AS IS" with no warranty of any kind,
61.17 +# express or implied, and with no claim as to its suitability for any
61.18 +# purpose.
61.19
61.20 import sys
61.21
62.1 --- a/scripts/mk-release.sh Tue Aug 18 10:08:28 2009 +0200
62.2 +++ b/scripts/mk-release.sh Thu Nov 05 08:39:49 2009 +0100
62.3 @@ -1,4 +1,18 @@
62.4 #!/bin/bash
62.5 +#
62.6 +# This file is a part of LEMON, a generic C++ optimization library.
62.7 +#
62.8 +# Copyright (C) 2003-2009
62.9 +# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
62.10 +# (Egervary Research Group on Combinatorial Optimization, EGRES).
62.11 +#
62.12 +# Permission to use, modify and distribute this software is granted
62.13 +# provided that this copyright notice appears in all copies. For
62.14 +# precise terms see the accompanying LICENSE file.
62.15 +#
62.16 +# This software is provided "AS IS" with no warranty of any kind,
62.17 +# express or implied, and with no claim as to its suitability for any
62.18 +# purpose.
62.19
62.20 set -e
62.21
63.1 --- a/scripts/unify-sources.sh Tue Aug 18 10:08:28 2009 +0200
63.2 +++ b/scripts/unify-sources.sh Thu Nov 05 08:39:49 2009 +0100
63.3 @@ -1,4 +1,18 @@
63.4 #!/bin/bash
63.5 +#
63.6 +# This file is a part of LEMON, a generic C++ optimization library.
63.7 +#
63.8 +# Copyright (C) 2003-2009
63.9 +# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
63.10 +# (Egervary Research Group on Combinatorial Optimization, EGRES).
63.11 +#
63.12 +# Permission to use, modify and distribute this software is granted
63.13 +# provided that this copyright notice appears in all copies. For
63.14 +# precise terms see the accompanying LICENSE file.
63.15 +#
63.16 +# This software is provided "AS IS" with no warranty of any kind,
63.17 +# express or implied, and with no claim as to its suitability for any
63.18 +# purpose.
63.19
63.20 YEAR=`date +%Y`
63.21 HGROOT=`hg root`
64.1 --- a/test/CMakeLists.txt Tue Aug 18 10:08:28 2009 +0200
64.2 +++ b/test/CMakeLists.txt Thu Nov 05 08:39:49 2009 +0100
64.3 @@ -9,6 +9,7 @@
64.4
64.5 SET(TESTS
64.6 adaptors_test
64.7 + bellman_ford_test
64.8 bfs_test
64.9 circulation_test
64.10 connectivity_test
65.1 --- a/test/Makefile.am Tue Aug 18 10:08:28 2009 +0200
65.2 +++ b/test/Makefile.am Thu Nov 05 08:39:49 2009 +0100
65.3 @@ -7,6 +7,7 @@
65.4
65.5 check_PROGRAMS += \
65.6 test/adaptors_test \
65.7 + test/bellman_ford_test \
65.8 test/bfs_test \
65.9 test/circulation_test \
65.10 test/connectivity_test \
65.11 @@ -53,6 +54,7 @@
65.12 XFAIL_TESTS += test/test_tools_fail$(EXEEXT)
65.13
65.14 test_adaptors_test_SOURCES = test/adaptors_test.cc
65.15 +test_bellman_ford_test_SOURCES = test/bellman_ford_test.cc
65.16 test_bfs_test_SOURCES = test/bfs_test.cc
65.17 test_circulation_test_SOURCES = test/circulation_test.cc
65.18 test_counter_test_SOURCES = test/counter_test.cc
66.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
66.2 +++ b/test/bellman_ford_test.cc Thu Nov 05 08:39:49 2009 +0100
66.3 @@ -0,0 +1,283 @@
66.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
66.5 + *
66.6 + * This file is a part of LEMON, a generic C++ optimization library.
66.7 + *
66.8 + * Copyright (C) 2003-2009
66.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
66.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
66.11 + *
66.12 + * Permission to use, modify and distribute this software is granted
66.13 + * provided that this copyright notice appears in all copies. For
66.14 + * precise terms see the accompanying LICENSE file.
66.15 + *
66.16 + * This software is provided "AS IS" with no warranty of any kind,
66.17 + * express or implied, and with no claim as to its suitability for any
66.18 + * purpose.
66.19 + *
66.20 + */
66.21 +
66.22 +#include <lemon/concepts/digraph.h>
66.23 +#include <lemon/smart_graph.h>
66.24 +#include <lemon/list_graph.h>
66.25 +#include <lemon/lgf_reader.h>
66.26 +#include <lemon/bellman_ford.h>
66.27 +#include <lemon/path.h>
66.28 +
66.29 +#include "graph_test.h"
66.30 +#include "test_tools.h"
66.31 +
66.32 +using namespace lemon;
66.33 +
66.34 +char test_lgf[] =
66.35 + "@nodes\n"
66.36 + "label\n"
66.37 + "0\n"
66.38 + "1\n"
66.39 + "2\n"
66.40 + "3\n"
66.41 + "4\n"
66.42 + "@arcs\n"
66.43 + " length\n"
66.44 + "0 1 3\n"
66.45 + "1 2 -3\n"
66.46 + "1 2 -5\n"
66.47 + "1 3 -2\n"
66.48 + "0 2 -1\n"
66.49 + "1 2 -4\n"
66.50 + "0 3 2\n"
66.51 + "4 2 -5\n"
66.52 + "2 3 1\n"
66.53 + "@attributes\n"
66.54 + "source 0\n"
66.55 + "target 3\n";
66.56 +
66.57 +
66.58 +void checkBellmanFordCompile()
66.59 +{
66.60 + typedef int Value;
66.61 + typedef concepts::Digraph Digraph;
66.62 + typedef concepts::ReadMap<Digraph::Arc,Value> LengthMap;
66.63 + typedef BellmanFord<Digraph, LengthMap> BF;
66.64 + typedef Digraph::Node Node;
66.65 + typedef Digraph::Arc Arc;
66.66 +
66.67 + Digraph gr;
66.68 + Node s, t, n;
66.69 + Arc e;
66.70 + Value l;
66.71 + int k;
66.72 + bool b;
66.73 + BF::DistMap d(gr);
66.74 + BF::PredMap p(gr);
66.75 + LengthMap length;
66.76 + concepts::Path<Digraph> pp;
66.77 +
66.78 + {
66.79 + BF bf_test(gr,length);
66.80 + const BF& const_bf_test = bf_test;
66.81 +
66.82 + bf_test.run(s);
66.83 + bf_test.run(s,k);
66.84 +
66.85 + bf_test.init();
66.86 + bf_test.addSource(s);
66.87 + bf_test.addSource(s, 1);
66.88 + b = bf_test.processNextRound();
66.89 + b = bf_test.processNextWeakRound();
66.90 +
66.91 + bf_test.start();
66.92 + bf_test.checkedStart();
66.93 + bf_test.limitedStart(k);
66.94 +
66.95 + l = const_bf_test.dist(t);
66.96 + e = const_bf_test.predArc(t);
66.97 + s = const_bf_test.predNode(t);
66.98 + b = const_bf_test.reached(t);
66.99 + d = const_bf_test.distMap();
66.100 + p = const_bf_test.predMap();
66.101 + pp = const_bf_test.path(t);
66.102 +
66.103 + for (BF::ActiveIt it(const_bf_test); it != INVALID; ++it) {}
66.104 + }
66.105 + {
66.106 + BF::SetPredMap<concepts::ReadWriteMap<Node,Arc> >
66.107 + ::SetDistMap<concepts::ReadWriteMap<Node,Value> >
66.108 + ::SetOperationTraits<BellmanFordDefaultOperationTraits<Value> >
66.109 + ::Create bf_test(gr,length);
66.110 +
66.111 + LengthMap length_map;
66.112 + concepts::ReadWriteMap<Node,Arc> pred_map;
66.113 + concepts::ReadWriteMap<Node,Value> dist_map;
66.114 +
66.115 + bf_test
66.116 + .lengthMap(length_map)
66.117 + .predMap(pred_map)
66.118 + .distMap(dist_map);
66.119 +
66.120 + bf_test.run(s);
66.121 + bf_test.run(s,k);
66.122 +
66.123 + bf_test.init();
66.124 + bf_test.addSource(s);
66.125 + bf_test.addSource(s, 1);
66.126 + b = bf_test.processNextRound();
66.127 + b = bf_test.processNextWeakRound();
66.128 +
66.129 + bf_test.start();
66.130 + bf_test.checkedStart();
66.131 + bf_test.limitedStart(k);
66.132 +
66.133 + l = bf_test.dist(t);
66.134 + e = bf_test.predArc(t);
66.135 + s = bf_test.predNode(t);
66.136 + b = bf_test.reached(t);
66.137 + pp = bf_test.path(t);
66.138 + }
66.139 +}
66.140 +
66.141 +void checkBellmanFordFunctionCompile()
66.142 +{
66.143 + typedef int Value;
66.144 + typedef concepts::Digraph Digraph;
66.145 + typedef Digraph::Arc Arc;
66.146 + typedef Digraph::Node Node;
66.147 + typedef concepts::ReadMap<Digraph::Arc,Value> LengthMap;
66.148 +
66.149 + Digraph g;
66.150 + bool b;
66.151 + bellmanFord(g,LengthMap()).run(Node());
66.152 + b = bellmanFord(g,LengthMap()).run(Node(),Node());
66.153 + bellmanFord(g,LengthMap())
66.154 + .predMap(concepts::ReadWriteMap<Node,Arc>())
66.155 + .distMap(concepts::ReadWriteMap<Node,Value>())
66.156 + .run(Node());
66.157 + b=bellmanFord(g,LengthMap())
66.158 + .predMap(concepts::ReadWriteMap<Node,Arc>())
66.159 + .distMap(concepts::ReadWriteMap<Node,Value>())
66.160 + .path(concepts::Path<Digraph>())
66.161 + .dist(Value())
66.162 + .run(Node(),Node());
66.163 +}
66.164 +
66.165 +
66.166 +template <typename Digraph, typename Value>
66.167 +void checkBellmanFord() {
66.168 + TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
66.169 + typedef typename Digraph::template ArcMap<Value> LengthMap;
66.170 +
66.171 + Digraph gr;
66.172 + Node s, t;
66.173 + LengthMap length(gr);
66.174 +
66.175 + std::istringstream input(test_lgf);
66.176 + digraphReader(gr, input).
66.177 + arcMap("length", length).
66.178 + node("source", s).
66.179 + node("target", t).
66.180 + run();
66.181 +
66.182 + BellmanFord<Digraph, LengthMap>
66.183 + bf(gr, length);
66.184 + bf.run(s);
66.185 + Path<Digraph> p = bf.path(t);
66.186 +
66.187 + check(bf.reached(t) && bf.dist(t) == -1, "Bellman-Ford found a wrong path.");
66.188 + check(p.length() == 3, "path() found a wrong path.");
66.189 + check(checkPath(gr, p), "path() found a wrong path.");
66.190 + check(pathSource(gr, p) == s, "path() found a wrong path.");
66.191 + check(pathTarget(gr, p) == t, "path() found a wrong path.");
66.192 +
66.193 + ListPath<Digraph> path;
66.194 + Value dist;
66.195 + bool reached = bellmanFord(gr,length).path(path).dist(dist).run(s,t);
66.196 +
66.197 + check(reached && dist == -1, "Bellman-Ford found a wrong path.");
66.198 + check(path.length() == 3, "path() found a wrong path.");
66.199 + check(checkPath(gr, path), "path() found a wrong path.");
66.200 + check(pathSource(gr, path) == s, "path() found a wrong path.");
66.201 + check(pathTarget(gr, path) == t, "path() found a wrong path.");
66.202 +
66.203 + for(ArcIt e(gr); e!=INVALID; ++e) {
66.204 + Node u=gr.source(e);
66.205 + Node v=gr.target(e);
66.206 + check(!bf.reached(u) || (bf.dist(v) - bf.dist(u) <= length[e]),
66.207 + "Wrong output. dist(target)-dist(source)-arc_length=" <<
66.208 + bf.dist(v) - bf.dist(u) - length[e]);
66.209 + }
66.210 +
66.211 + for(NodeIt v(gr); v!=INVALID; ++v) {
66.212 + if (bf.reached(v)) {
66.213 + check(v==s || bf.predArc(v)!=INVALID, "Wrong tree.");
66.214 + if (bf.predArc(v)!=INVALID ) {
66.215 + Arc e=bf.predArc(v);
66.216 + Node u=gr.source(e);
66.217 + check(u==bf.predNode(v),"Wrong tree.");
66.218 + check(bf.dist(v) - bf.dist(u) == length[e],
66.219 + "Wrong distance! Difference: " <<
66.220 + bf.dist(v) - bf.dist(u) - length[e]);
66.221 + }
66.222 + }
66.223 + }
66.224 +}
66.225 +
66.226 +void checkBellmanFordNegativeCycle() {
66.227 + DIGRAPH_TYPEDEFS(SmartDigraph);
66.228 +
66.229 + SmartDigraph gr;
66.230 + IntArcMap length(gr);
66.231 +
66.232 + Node n1 = gr.addNode();
66.233 + Node n2 = gr.addNode();
66.234 + Node n3 = gr.addNode();
66.235 + Node n4 = gr.addNode();
66.236 +
66.237 + Arc a1 = gr.addArc(n1, n2);
66.238 + Arc a2 = gr.addArc(n2, n2);
66.239 +
66.240 + length[a1] = 2;
66.241 + length[a2] = -1;
66.242 +
66.243 + {
66.244 + BellmanFord<SmartDigraph, IntArcMap> bf(gr, length);
66.245 + bf.run(n1);
66.246 + StaticPath<SmartDigraph> p = bf.negativeCycle();
66.247 + check(p.length() == 1 && p.front() == p.back() && p.front() == a2,
66.248 + "Wrong negative cycle.");
66.249 + }
66.250 +
66.251 + length[a2] = 0;
66.252 +
66.253 + {
66.254 + BellmanFord<SmartDigraph, IntArcMap> bf(gr, length);
66.255 + bf.run(n1);
66.256 + check(bf.negativeCycle().empty(),
66.257 + "Negative cycle should not be found.");
66.258 + }
66.259 +
66.260 + length[gr.addArc(n1, n3)] = 5;
66.261 + length[gr.addArc(n4, n3)] = 1;
66.262 + length[gr.addArc(n2, n4)] = 2;
66.263 + length[gr.addArc(n3, n2)] = -4;
66.264 +
66.265 + {
66.266 + BellmanFord<SmartDigraph, IntArcMap> bf(gr, length);
66.267 + bf.init();
66.268 + bf.addSource(n1);
66.269 + for (int i = 0; i < 4; ++i) {
66.270 + check(bf.negativeCycle().empty(),
66.271 + "Negative cycle should not be found.");
66.272 + bf.processNextRound();
66.273 + }
66.274 + StaticPath<SmartDigraph> p = bf.negativeCycle();
66.275 + check(p.length() == 3, "Wrong negative cycle.");
66.276 + check(length[p.nth(0)] + length[p.nth(1)] + length[p.nth(2)] == -1,
66.277 + "Wrong negative cycle.");
66.278 + }
66.279 +}
66.280 +
66.281 +int main() {
66.282 + checkBellmanFord<ListDigraph, int>();
66.283 + checkBellmanFord<SmartDigraph, double>();
66.284 + checkBellmanFordNegativeCycle();
66.285 + return 0;
66.286 +}
67.1 --- a/test/circulation_test.cc Tue Aug 18 10:08:28 2009 +0200
67.2 +++ b/test/circulation_test.cc Thu Nov 05 08:39:49 2009 +0100
67.3 @@ -87,6 +87,11 @@
67.4 .upperMap(ucap)
67.5 .supplyMap(supply)
67.6 .flowMap(flow);
67.7 +
67.8 + const CirculationType::Elevator& elev = const_circ_test.elevator();
67.9 + circ_test.elevator(const_cast<CirculationType::Elevator&>(elev));
67.10 + CirculationType::Tolerance tol = const_circ_test.tolerance();
67.11 + circ_test.tolerance(tol);
67.12
67.13 circ_test.init();
67.14 circ_test.greedyInit();
68.1 --- a/test/digraph_test.cc Tue Aug 18 10:08:28 2009 +0200
68.2 +++ b/test/digraph_test.cc Thu Nov 05 08:39:49 2009 +0100
68.3 @@ -35,6 +35,9 @@
68.4 checkGraphNodeList(G, 0);
68.5 checkGraphArcList(G, 0);
68.6
68.7 + G.reserveNode(3);
68.8 + G.reserveArc(4);
68.9 +
68.10 Node
68.11 n1 = G.addNode(),
68.12 n2 = G.addNode(),
68.13 @@ -283,6 +286,14 @@
68.14 G.addArc(G.addNode(), G.addNode());
68.15
68.16 snapshot.restore();
68.17 + snapshot.save(G);
68.18 +
68.19 + checkGraphNodeList(G, 4);
68.20 + checkGraphArcList(G, 4);
68.21 +
68.22 + G.addArc(G.addNode(), G.addNode());
68.23 +
68.24 + snapshot.restore();
68.25
68.26 checkGraphNodeList(G, 4);
68.27 checkGraphArcList(G, 4);
68.28 @@ -375,7 +386,12 @@
68.29 void checkFullDigraph(int num) {
68.30 typedef FullDigraph Digraph;
68.31 DIGRAPH_TYPEDEFS(Digraph);
68.32 +
68.33 Digraph G(num);
68.34 + check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
68.35 +
68.36 + G.resize(num);
68.37 + check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
68.38
68.39 checkGraphNodeList(G, num);
68.40 checkGraphArcList(G, num * num);
69.1 --- a/test/graph_test.cc Tue Aug 18 10:08:28 2009 +0200
69.2 +++ b/test/graph_test.cc Thu Nov 05 08:39:49 2009 +0100
69.3 @@ -38,6 +38,9 @@
69.4 checkGraphEdgeList(G, 0);
69.5 checkGraphArcList(G, 0);
69.6
69.7 + G.reserveNode(3);
69.8 + G.reserveEdge(3);
69.9 +
69.10 Node
69.11 n1 = G.addNode(),
69.12 n2 = G.addNode(),
69.13 @@ -256,6 +259,15 @@
69.14 G.addEdge(G.addNode(), G.addNode());
69.15
69.16 snapshot.restore();
69.17 + snapshot.save(G);
69.18 +
69.19 + checkGraphNodeList(G, 4);
69.20 + checkGraphEdgeList(G, 3);
69.21 + checkGraphArcList(G, 6);
69.22 +
69.23 + G.addEdge(G.addNode(), G.addNode());
69.24 +
69.25 + snapshot.restore();
69.26
69.27 checkGraphNodeList(G, 4);
69.28 checkGraphEdgeList(G, 3);
69.29 @@ -267,6 +279,13 @@
69.30 GRAPH_TYPEDEFS(Graph);
69.31
69.32 Graph G(num);
69.33 + check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
69.34 + "Wrong size");
69.35 +
69.36 + G.resize(num);
69.37 + check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
69.38 + "Wrong size");
69.39 +
69.40 checkGraphNodeList(G, num);
69.41 checkGraphEdgeList(G, num * (num - 1) / 2);
69.42
69.43 @@ -411,6 +430,10 @@
69.44 check(G.width() == width, "Wrong column number");
69.45 check(G.height() == height, "Wrong row number");
69.46
69.47 + G.resize(width, height);
69.48 + check(G.width() == width, "Wrong column number");
69.49 + check(G.height() == height, "Wrong row number");
69.50 +
69.51 for (int i = 0; i < width; ++i) {
69.52 for (int j = 0; j < height; ++j) {
69.53 check(G.col(G(i, j)) == i, "Wrong column");
69.54 @@ -486,6 +509,11 @@
69.55 GRAPH_TYPEDEFS(HypercubeGraph);
69.56
69.57 HypercubeGraph G(dim);
69.58 + check(G.dimension() == dim, "Wrong dimension");
69.59 +
69.60 + G.resize(dim);
69.61 + check(G.dimension() == dim, "Wrong dimension");
69.62 +
69.63 checkGraphNodeList(G, 1 << dim);
69.64 checkGraphEdgeList(G, dim * (1 << (dim-1)));
69.65 checkGraphArcList(G, dim * (1 << dim));
70.1 --- a/test/heap_test.cc Tue Aug 18 10:08:28 2009 +0200
70.2 +++ b/test/heap_test.cc Thu Nov 05 08:39:49 2009 +0100
70.3 @@ -25,14 +25,17 @@
70.4 #include <lemon/concepts/heap.h>
70.5
70.6 #include <lemon/smart_graph.h>
70.7 -
70.8 #include <lemon/lgf_reader.h>
70.9 #include <lemon/dijkstra.h>
70.10 #include <lemon/maps.h>
70.11
70.12 #include <lemon/bin_heap.h>
70.13 +#include <lemon/fourary_heap.h>
70.14 +#include <lemon/kary_heap.h>
70.15 #include <lemon/fib_heap.h>
70.16 +#include <lemon/pairing_heap.h>
70.17 #include <lemon/radix_heap.h>
70.18 +#include <lemon/binom_heap.h>
70.19 #include <lemon/bucket_heap.h>
70.20
70.21 #include "test_tools.h"
70.22 @@ -89,18 +92,16 @@
70.23 template <typename Heap>
70.24 void heapSortTest() {
70.25 RangeMap<int> map(test_len, -1);
70.26 -
70.27 Heap heap(map);
70.28
70.29 std::vector<int> v(test_len);
70.30 -
70.31 for (int i = 0; i < test_len; ++i) {
70.32 v[i] = test_seq[i];
70.33 heap.push(i, v[i]);
70.34 }
70.35 std::sort(v.begin(), v.end());
70.36 for (int i = 0; i < test_len; ++i) {
70.37 - check(v[i] == heap.prio() ,"Wrong order in heap sort.");
70.38 + check(v[i] == heap.prio(), "Wrong order in heap sort.");
70.39 heap.pop();
70.40 }
70.41 }
70.42 @@ -112,7 +113,6 @@
70.43 Heap heap(map);
70.44
70.45 std::vector<int> v(test_len);
70.46 -
70.47 for (int i = 0; i < test_len; ++i) {
70.48 v[i] = test_seq[i];
70.49 heap.push(i, v[i]);
70.50 @@ -123,13 +123,11 @@
70.51 }
70.52 std::sort(v.begin(), v.end());
70.53 for (int i = 0; i < test_len; ++i) {
70.54 - check(v[i] == heap.prio() ,"Wrong order in heap increase test.");
70.55 + check(v[i] == heap.prio(), "Wrong order in heap increase test.");
70.56 heap.pop();
70.57 }
70.58 }
70.59
70.60 -
70.61 -
70.62 template <typename Heap>
70.63 void dijkstraHeapTest(const Digraph& digraph, const IntArcMap& length,
70.64 Node source) {
70.65 @@ -144,7 +142,7 @@
70.66 Node t = digraph.target(a);
70.67 if (dijkstra.reached(s)) {
70.68 check( dijkstra.dist(t) - dijkstra.dist(s) <= length[a],
70.69 - "Error in a shortest path tree!");
70.70 + "Error in shortest path tree.");
70.71 }
70.72 }
70.73
70.74 @@ -153,7 +151,7 @@
70.75 Arc a = dijkstra.predArc(n);
70.76 Node s = digraph.source(a);
70.77 check( dijkstra.dist(n) - dijkstra.dist(s) == length[a],
70.78 - "Error in a shortest path tree!");
70.79 + "Error in shortest path tree.");
70.80 }
70.81 }
70.82
70.83 @@ -175,6 +173,7 @@
70.84 node("source", source).
70.85 run();
70.86
70.87 + // BinHeap
70.88 {
70.89 typedef BinHeap<Prio, ItemIntMap> IntHeap;
70.90 checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
70.91 @@ -186,6 +185,31 @@
70.92 dijkstraHeapTest<NodeHeap>(digraph, length, source);
70.93 }
70.94
70.95 + // FouraryHeap
70.96 + {
70.97 + typedef FouraryHeap<Prio, ItemIntMap> IntHeap;
70.98 + checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
70.99 + heapSortTest<IntHeap>();
70.100 + heapIncreaseTest<IntHeap>();
70.101 +
70.102 + typedef FouraryHeap<Prio, IntNodeMap > NodeHeap;
70.103 + checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
70.104 + dijkstraHeapTest<NodeHeap>(digraph, length, source);
70.105 + }
70.106 +
70.107 + // KaryHeap
70.108 + {
70.109 + typedef KaryHeap<Prio, ItemIntMap> IntHeap;
70.110 + checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
70.111 + heapSortTest<IntHeap>();
70.112 + heapIncreaseTest<IntHeap>();
70.113 +
70.114 + typedef KaryHeap<Prio, IntNodeMap > NodeHeap;
70.115 + checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
70.116 + dijkstraHeapTest<NodeHeap>(digraph, length, source);
70.117 + }
70.118 +
70.119 + // FibHeap
70.120 {
70.121 typedef FibHeap<Prio, ItemIntMap> IntHeap;
70.122 checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
70.123 @@ -197,6 +221,19 @@
70.124 dijkstraHeapTest<NodeHeap>(digraph, length, source);
70.125 }
70.126
70.127 + // PairingHeap
70.128 + {
70.129 + typedef PairingHeap<Prio, ItemIntMap> IntHeap;
70.130 + checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
70.131 + heapSortTest<IntHeap>();
70.132 + heapIncreaseTest<IntHeap>();
70.133 +
70.134 + typedef PairingHeap<Prio, IntNodeMap > NodeHeap;
70.135 + checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
70.136 + dijkstraHeapTest<NodeHeap>(digraph, length, source);
70.137 + }
70.138 +
70.139 + // RadixHeap
70.140 {
70.141 typedef RadixHeap<ItemIntMap> IntHeap;
70.142 checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
70.143 @@ -208,6 +245,19 @@
70.144 dijkstraHeapTest<NodeHeap>(digraph, length, source);
70.145 }
70.146
70.147 + // BinomHeap
70.148 + {
70.149 + typedef BinomHeap<Prio, ItemIntMap> IntHeap;
70.150 + checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
70.151 + heapSortTest<IntHeap>();
70.152 + heapIncreaseTest<IntHeap>();
70.153 +
70.154 + typedef BinomHeap<Prio, IntNodeMap > NodeHeap;
70.155 + checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
70.156 + dijkstraHeapTest<NodeHeap>(digraph, length, source);
70.157 + }
70.158 +
70.159 + // BucketHeap, SimpleBucketHeap
70.160 {
70.161 typedef BucketHeap<ItemIntMap> IntHeap;
70.162 checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
70.163 @@ -217,8 +267,10 @@
70.164 typedef BucketHeap<IntNodeMap > NodeHeap;
70.165 checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
70.166 dijkstraHeapTest<NodeHeap>(digraph, length, source);
70.167 +
70.168 + typedef SimpleBucketHeap<ItemIntMap> SimpleIntHeap;
70.169 + heapSortTest<SimpleIntHeap>();
70.170 }
70.171
70.172 -
70.173 return 0;
70.174 }
71.1 --- a/test/maps_test.cc Tue Aug 18 10:08:28 2009 +0200
71.2 +++ b/test/maps_test.cc Thu Nov 05 08:39:49 2009 +0100
71.3 @@ -22,6 +22,10 @@
71.4 #include <lemon/concept_check.h>
71.5 #include <lemon/concepts/maps.h>
71.6 #include <lemon/maps.h>
71.7 +#include <lemon/list_graph.h>
71.8 +#include <lemon/smart_graph.h>
71.9 +#include <lemon/adaptors.h>
71.10 +#include <lemon/dfs.h>
71.11
71.12 #include "test_tools.h"
71.13
71.14 @@ -60,6 +64,12 @@
71.15 typedef ReadWriteMap<A, bool> BoolWriteMap;
71.16 typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap;
71.17
71.18 +template<typename Map1, typename Map2, typename ItemIt>
71.19 +void compareMap(const Map1& map1, const Map2& map2, ItemIt it) {
71.20 + for (; it != INVALID; ++it)
71.21 + check(map1[it] == map2[it], "The maps are not equal");
71.22 +}
71.23 +
71.24 int main()
71.25 {
71.26 // Map concepts
71.27 @@ -328,6 +338,10 @@
71.28 // LoggerBoolMap
71.29 {
71.30 typedef std::vector<int> vec;
71.31 + checkConcept<WriteMap<int, bool>, LoggerBoolMap<vec::iterator> >();
71.32 + checkConcept<WriteMap<int, bool>,
71.33 + LoggerBoolMap<std::back_insert_iterator<vec> > >();
71.34 +
71.35 vec v1;
71.36 vec v2(10);
71.37 LoggerBoolMap<std::back_insert_iterator<vec> >
71.38 @@ -347,7 +361,444 @@
71.39 for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
71.40 it != map2.end(); ++it )
71.41 check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
71.42 +
71.43 + typedef ListDigraph Graph;
71.44 + DIGRAPH_TYPEDEFS(Graph);
71.45 + Graph gr;
71.46 +
71.47 + Node n0 = gr.addNode();
71.48 + Node n1 = gr.addNode();
71.49 + Node n2 = gr.addNode();
71.50 + Node n3 = gr.addNode();
71.51 +
71.52 + gr.addArc(n3, n0);
71.53 + gr.addArc(n3, n2);
71.54 + gr.addArc(n0, n2);
71.55 + gr.addArc(n2, n1);
71.56 + gr.addArc(n0, n1);
71.57 +
71.58 + {
71.59 + std::vector<Node> v;
71.60 + dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run();
71.61 +
71.62 + check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
71.63 + "Something is wrong with LoggerBoolMap");
71.64 + }
71.65 + {
71.66 + std::vector<Node> v(countNodes(gr));
71.67 + dfs(gr).processedMap(loggerBoolMap(v.begin())).run();
71.68 +
71.69 + check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
71.70 + "Something is wrong with LoggerBoolMap");
71.71 + }
71.72 + }
71.73 +
71.74 + // IdMap, RangeIdMap
71.75 + {
71.76 + typedef ListDigraph Graph;
71.77 + DIGRAPH_TYPEDEFS(Graph);
71.78 +
71.79 + checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >();
71.80 + checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >();
71.81 + checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >();
71.82 + checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >();
71.83 +
71.84 + Graph gr;
71.85 + IdMap<Graph, Node> nmap(gr);
71.86 + IdMap<Graph, Arc> amap(gr);
71.87 + RangeIdMap<Graph, Node> nrmap(gr);
71.88 + RangeIdMap<Graph, Arc> armap(gr);
71.89 +
71.90 + Node n0 = gr.addNode();
71.91 + Node n1 = gr.addNode();
71.92 + Node n2 = gr.addNode();
71.93 +
71.94 + Arc a0 = gr.addArc(n0, n1);
71.95 + Arc a1 = gr.addArc(n0, n2);
71.96 + Arc a2 = gr.addArc(n2, n1);
71.97 + Arc a3 = gr.addArc(n2, n0);
71.98 +
71.99 + check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap");
71.100 + check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap");
71.101 + check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap");
71.102 +
71.103 + check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap");
71.104 + check(amap[a1] == gr.id(a1) && amap(gr.id(a1)) == a1, "Wrong IdMap");
71.105 + check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap");
71.106 + check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap");
71.107 +
71.108 + check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap");
71.109 + check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap");
71.110 +
71.111 + check(nrmap.size() == 3 && armap.size() == 4,
71.112 + "Wrong RangeIdMap::size()");
71.113 +
71.114 + check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
71.115 + check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
71.116 + check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
71.117 +
71.118 + check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
71.119 + check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
71.120 + check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
71.121 + check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
71.122 +
71.123 + check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
71.124 + check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
71.125 +
71.126 + gr.erase(n1);
71.127 +
71.128 + if (nrmap[n0] == 1) nrmap.swap(n0, n2);
71.129 + nrmap.swap(n2, n0);
71.130 + if (armap[a1] == 1) armap.swap(a1, a3);
71.131 + armap.swap(a3, a1);
71.132 +
71.133 + check(nrmap.size() == 2 && armap.size() == 2,
71.134 + "Wrong RangeIdMap::size()");
71.135 +
71.136 + check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
71.137 + check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
71.138 +
71.139 + check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
71.140 + check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
71.141 +
71.142 + check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
71.143 + check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
71.144 + }
71.145 +
71.146 + // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
71.147 + {
71.148 + typedef ListGraph Graph;
71.149 + GRAPH_TYPEDEFS(Graph);
71.150 +
71.151 + checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
71.152 + checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
71.153 + checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
71.154 + checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
71.155 + checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
71.156 + checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >();
71.157 +
71.158 + Graph gr;
71.159 + Node n0 = gr.addNode();
71.160 + Node n1 = gr.addNode();
71.161 + Node n2 = gr.addNode();
71.162 +
71.163 + gr.addEdge(n0,n1);
71.164 + gr.addEdge(n1,n2);
71.165 + gr.addEdge(n0,n2);
71.166 + gr.addEdge(n2,n1);
71.167 + gr.addEdge(n1,n2);
71.168 + gr.addEdge(n0,n1);
71.169 +
71.170 + for (EdgeIt e(gr); e != INVALID; ++e) {
71.171 + check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
71.172 + check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
71.173 + }
71.174 +
71.175 + compareMap(sourceMap(orienter(gr, constMap<Edge, bool>(true))),
71.176 + targetMap(orienter(gr, constMap<Edge, bool>(false))),
71.177 + EdgeIt(gr));
71.178 +
71.179 + typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
71.180 + Digraph dgr(gr, constMap<Edge, bool>(true));
71.181 + OutDegMap<Digraph> odm(dgr);
71.182 + InDegMap<Digraph> idm(dgr);
71.183 +
71.184 + check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
71.185 + check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
71.186 +
71.187 + gr.addEdge(n2, n0);
71.188 +
71.189 + check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
71.190 + check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
71.191 + }
71.192 +
71.193 + // CrossRefMap
71.194 + {
71.195 + typedef ListDigraph Graph;
71.196 + DIGRAPH_TYPEDEFS(Graph);
71.197 +
71.198 + checkConcept<ReadWriteMap<Node, int>,
71.199 + CrossRefMap<Graph, Node, int> >();
71.200 + checkConcept<ReadWriteMap<Node, bool>,
71.201 + CrossRefMap<Graph, Node, bool> >();
71.202 + checkConcept<ReadWriteMap<Node, double>,
71.203 + CrossRefMap<Graph, Node, double> >();
71.204 +
71.205 + Graph gr;
71.206 + typedef CrossRefMap<Graph, Node, char> CRMap;
71.207 + CRMap map(gr);
71.208 +
71.209 + Node n0 = gr.addNode();
71.210 + Node n1 = gr.addNode();
71.211 + Node n2 = gr.addNode();
71.212 +
71.213 + map.set(n0, 'A');
71.214 + map.set(n1, 'B');
71.215 + map.set(n2, 'C');
71.216 +
71.217 + check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
71.218 + "Wrong CrossRefMap");
71.219 + check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
71.220 + "Wrong CrossRefMap");
71.221 + check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
71.222 + "Wrong CrossRefMap");
71.223 + check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
71.224 + "Wrong CrossRefMap::count()");
71.225 +
71.226 + CRMap::ValueIt it = map.beginValue();
71.227 + check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
71.228 + it == map.endValue(), "Wrong value iterator");
71.229 +
71.230 + map.set(n2, 'A');
71.231 +
71.232 + check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
71.233 + "Wrong CrossRefMap");
71.234 + check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
71.235 + check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
71.236 + check(map('C') == INVALID && map.inverse()['C'] == INVALID,
71.237 + "Wrong CrossRefMap");
71.238 + check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
71.239 + "Wrong CrossRefMap::count()");
71.240 +
71.241 + it = map.beginValue();
71.242 + check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' &&
71.243 + it == map.endValue(), "Wrong value iterator");
71.244 +
71.245 + map.set(n0, 'C');
71.246 +
71.247 + check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
71.248 + "Wrong CrossRefMap");
71.249 + check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
71.250 + check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
71.251 + check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
71.252 + check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
71.253 + "Wrong CrossRefMap::count()");
71.254 +
71.255 + it = map.beginValue();
71.256 + check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
71.257 + it == map.endValue(), "Wrong value iterator");
71.258 }
71.259
71.260 + // CrossRefMap
71.261 + {
71.262 + typedef SmartDigraph Graph;
71.263 + DIGRAPH_TYPEDEFS(Graph);
71.264 +
71.265 + checkConcept<ReadWriteMap<Node, int>,
71.266 + CrossRefMap<Graph, Node, int> >();
71.267 +
71.268 + Graph gr;
71.269 + typedef CrossRefMap<Graph, Node, char> CRMap;
71.270 + typedef CRMap::ValueIterator ValueIt;
71.271 + CRMap map(gr);
71.272 +
71.273 + Node n0 = gr.addNode();
71.274 + Node n1 = gr.addNode();
71.275 + Node n2 = gr.addNode();
71.276 +
71.277 + map.set(n0, 'A');
71.278 + map.set(n1, 'B');
71.279 + map.set(n2, 'C');
71.280 + map.set(n2, 'A');
71.281 + map.set(n0, 'C');
71.282 +
71.283 + check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
71.284 + "Wrong CrossRefMap");
71.285 + check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
71.286 + check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
71.287 + check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
71.288 +
71.289 + ValueIt it = map.beginValue();
71.290 + check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
71.291 + it == map.endValue(), "Wrong value iterator");
71.292 + }
71.293 +
71.294 + // Iterable bool map
71.295 + {
71.296 + typedef SmartGraph Graph;
71.297 + typedef SmartGraph::Node Item;
71.298 +
71.299 + typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm;
71.300 + checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>();
71.301 +
71.302 + const int num = 10;
71.303 + Graph g;
71.304 + std::vector<Item> items;
71.305 + for (int i = 0; i < num; ++i) {
71.306 + items.push_back(g.addNode());
71.307 + }
71.308 +
71.309 + Ibm map1(g, true);
71.310 + int n = 0;
71.311 + for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
71.312 + check(map1[static_cast<Item>(it)], "Wrong TrueIt");
71.313 + ++n;
71.314 + }
71.315 + check(n == num, "Wrong number");
71.316 +
71.317 + n = 0;
71.318 + for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
71.319 + check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
71.320 + ++n;
71.321 + }
71.322 + check(n == num, "Wrong number");
71.323 + check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt");
71.324 + check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false");
71.325 +
71.326 + map1[items[5]] = true;
71.327 +
71.328 + n = 0;
71.329 + for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
71.330 + check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
71.331 + ++n;
71.332 + }
71.333 + check(n == num, "Wrong number");
71.334 +
71.335 + map1[items[num / 2]] = false;
71.336 + check(map1[items[num / 2]] == false, "Wrong map value");
71.337 +
71.338 + n = 0;
71.339 + for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
71.340 + check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
71.341 + ++n;
71.342 + }
71.343 + check(n == num - 1, "Wrong number");
71.344 +
71.345 + n = 0;
71.346 + for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
71.347 + check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
71.348 + ++n;
71.349 + }
71.350 + check(n == 1, "Wrong number");
71.351 +
71.352 + map1[items[0]] = false;
71.353 + check(map1[items[0]] == false, "Wrong map value");
71.354 +
71.355 + map1[items[num - 1]] = false;
71.356 + check(map1[items[num - 1]] == false, "Wrong map value");
71.357 +
71.358 + n = 0;
71.359 + for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
71.360 + check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
71.361 + ++n;
71.362 + }
71.363 + check(n == num - 3, "Wrong number");
71.364 + check(map1.trueNum() == num - 3, "Wrong number");
71.365 +
71.366 + n = 0;
71.367 + for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
71.368 + check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
71.369 + ++n;
71.370 + }
71.371 + check(n == 3, "Wrong number");
71.372 + check(map1.falseNum() == 3, "Wrong number");
71.373 + }
71.374 +
71.375 + // Iterable int map
71.376 + {
71.377 + typedef SmartGraph Graph;
71.378 + typedef SmartGraph::Node Item;
71.379 + typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim;
71.380 +
71.381 + checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>();
71.382 +
71.383 + const int num = 10;
71.384 + Graph g;
71.385 + std::vector<Item> items;
71.386 + for (int i = 0; i < num; ++i) {
71.387 + items.push_back(g.addNode());
71.388 + }
71.389 +
71.390 + Iim map1(g);
71.391 + check(map1.size() == 0, "Wrong size");
71.392 +
71.393 + for (int i = 0; i < num; ++i) {
71.394 + map1[items[i]] = i;
71.395 + }
71.396 + check(map1.size() == num, "Wrong size");
71.397 +
71.398 + for (int i = 0; i < num; ++i) {
71.399 + Iim::ItemIt it(map1, i);
71.400 + check(static_cast<Item>(it) == items[i], "Wrong value");
71.401 + ++it;
71.402 + check(static_cast<Item>(it) == INVALID, "Wrong value");
71.403 + }
71.404 +
71.405 + for (int i = 0; i < num; ++i) {
71.406 + map1[items[i]] = i % 2;
71.407 + }
71.408 + check(map1.size() == 2, "Wrong size");
71.409 +
71.410 + int n = 0;
71.411 + for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) {
71.412 + check(map1[static_cast<Item>(it)] == 0, "Wrong value");
71.413 + ++n;
71.414 + }
71.415 + check(n == (num + 1) / 2, "Wrong number");
71.416 +
71.417 + for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) {
71.418 + check(map1[static_cast<Item>(it)] == 1, "Wrong value");
71.419 + ++n;
71.420 + }
71.421 + check(n == num, "Wrong number");
71.422 +
71.423 + }
71.424 +
71.425 + // Iterable value map
71.426 + {
71.427 + typedef SmartGraph Graph;
71.428 + typedef SmartGraph::Node Item;
71.429 + typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm;
71.430 +
71.431 + checkConcept<ReadWriteMap<Item, double>, Ivm>();
71.432 +
71.433 + const int num = 10;
71.434 + Graph g;
71.435 + std::vector<Item> items;
71.436 + for (int i = 0; i < num; ++i) {
71.437 + items.push_back(g.addNode());
71.438 + }
71.439 +
71.440 + Ivm map1(g, 0.0);
71.441 + check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size");
71.442 + check(*map1.beginValue() == 0.0, "Wrong value");
71.443 +
71.444 + for (int i = 0; i < num; ++i) {
71.445 + map1.set(items[i], static_cast<double>(i));
71.446 + }
71.447 + check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size");
71.448 +
71.449 + for (int i = 0; i < num; ++i) {
71.450 + Ivm::ItemIt it(map1, static_cast<double>(i));
71.451 + check(static_cast<Item>(it) == items[i], "Wrong value");
71.452 + ++it;
71.453 + check(static_cast<Item>(it) == INVALID, "Wrong value");
71.454 + }
71.455 +
71.456 + for (Ivm::ValueIt vit = map1.beginValue();
71.457 + vit != map1.endValue(); ++vit) {
71.458 + check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit,
71.459 + "Wrong ValueIt");
71.460 + }
71.461 +
71.462 + for (int i = 0; i < num; ++i) {
71.463 + map1.set(items[i], static_cast<double>(i % 2));
71.464 + }
71.465 + check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size");
71.466 +
71.467 + int n = 0;
71.468 + for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) {
71.469 + check(map1[static_cast<Item>(it)] == 0.0, "Wrong value");
71.470 + ++n;
71.471 + }
71.472 + check(n == (num + 1) / 2, "Wrong number");
71.473 +
71.474 + for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) {
71.475 + check(map1[static_cast<Item>(it)] == 1.0, "Wrong value");
71.476 + ++n;
71.477 + }
71.478 + check(n == num, "Wrong number");
71.479 +
71.480 + }
71.481 return 0;
71.482 }
72.1 --- a/test/mip_test.cc Tue Aug 18 10:08:28 2009 +0200
72.2 +++ b/test/mip_test.cc Thu Nov 05 08:39:49 2009 +0100
72.3 @@ -50,7 +50,8 @@
72.4
72.5 if (stat == MipSolver::OPTIMAL) {
72.6 std::ostringstream sbuf;
72.7 - buf << "Wrong optimal value: the right optimum is " << exp_opt;
72.8 + sbuf << "Wrong optimal value ("<< mip.solValue()
72.9 + <<" instead of " << exp_opt << ")";
72.10 check(std::abs(mip.solValue()-exp_opt) < 1e-3, sbuf.str());
72.11 //+ecvt(exp_opt,2)
72.12 }
73.1 --- a/test/preflow_test.cc Tue Aug 18 10:08:28 2009 +0200
73.2 +++ b/test/preflow_test.cc Thu Nov 05 08:39:49 2009 +0100
73.3 @@ -94,6 +94,11 @@
73.4 ::Create PreflowType;
73.5 PreflowType preflow_test(g, cap, n, n);
73.6 const PreflowType& const_preflow_test = preflow_test;
73.7 +
73.8 + const PreflowType::Elevator& elev = const_preflow_test.elevator();
73.9 + preflow_test.elevator(const_cast<PreflowType::Elevator&>(elev));
73.10 + PreflowType::Tolerance tol = const_preflow_test.tolerance();
73.11 + preflow_test.tolerance(tol);
73.12
73.13 preflow_test
73.14 .capacityMap(cap)
74.1 --- a/tools/lemon-0.x-to-1.x.sh Tue Aug 18 10:08:28 2009 +0200
74.2 +++ b/tools/lemon-0.x-to-1.x.sh Thu Nov 05 08:39:49 2009 +0100
74.3 @@ -35,10 +35,10 @@
74.4 -e "s/IncEdgeIt/_In_cEd_geIt_label_/g"\
74.5 -e "s/Edge\>/_Ar_c_label_/g"\
74.6 -e "s/\<edge\>/_ar_c_label_/g"\
74.7 - -e "s/_edge\>/_ar_c_label_/g"\
74.8 + -e "s/_edge\>/__ar_c_label_/g"\
74.9 -e "s/Edges\>/_Ar_c_label_s/g"\
74.10 -e "s/\<edges\>/_ar_c_label_s/g"\
74.11 - -e "s/_edges\>/_ar_c_label_s/g"\
74.12 + -e "s/_edges\>/__ar_c_label_s/g"\
74.13 -e "s/\([Ee]\)dge\([a-z]\)/_\1d_ge_label_\2/g"\
74.14 -e "s/\([a-z]\)edge/\1_ed_ge_label_/g"\
74.15 -e "s/Edge/_Ar_c_label_/g"\
74.16 @@ -68,6 +68,11 @@
74.17 -e "s/_blu_e_label_/blue/g"\
74.18 -e "s/_GR_APH_TY_PEDE_FS_label_/GRAPH_TYPEDEFS/g"\
74.19 -e "s/_DIGR_APH_TY_PEDE_FS_label_/DIGRAPH_TYPEDEFS/g"\
74.20 + -e "s/\<digraph_adaptor\.h\>/adaptors.h/g"\
74.21 + -e "s/\<digraph_utils\.h\>/core.h/g"\
74.22 + -e "s/\<digraph_reader\.h\>/lgf_reader.h/g"\
74.23 + -e "s/\<digraph_writer\.h\>/lgf_writer.h/g"\
74.24 + -e "s/\<topology\.h\>/connectivity.h/g"\
74.25 -e "s/DigraphToEps/GraphToEps/g"\
74.26 -e "s/digraphToEps/graphToEps/g"\
74.27 -e "s/\<DefPredMap\>/SetPredMap/g"\