1.1 --- a/CMakeLists.txt Sun Oct 04 10:15:32 2009 +0200
1.2 +++ b/CMakeLists.txt Wed Dec 09 11:14:06 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 Sun Oct 04 10:15:32 2009 +0200
2.2 +++ b/Makefile.am Wed Dec 09 11:14:06 2009 +0100
2.3 @@ -17,6 +17,7 @@
2.4 cmake/FindCPLEX.cmake \
2.5 cmake/FindGLPK.cmake \
2.6 cmake/FindCOIN.cmake \
2.7 + cmake/LEMONConfig.cmake.in \
2.8 cmake/version.cmake.in \
2.9 cmake/version.cmake \
2.10 cmake/nsis/lemon.ico \
2.11 @@ -43,6 +44,7 @@
2.12 include test/Makefile.am
2.13 include doc/Makefile.am
2.14 include tools/Makefile.am
2.15 +include scripts/Makefile.am
2.16
2.17 DIST_SUBDIRS = demo
2.18
3.1 --- a/configure.ac Sun Oct 04 10:15:32 2009 +0200
3.2 +++ b/configure.ac Wed Dec 09 11:14:06 2009 +0100
3.3 @@ -41,6 +41,7 @@
3.4 AC_PROG_LIBTOOL
3.5
3.6 AC_CHECK_PROG([doxygen_found],[doxygen],[yes],[no])
3.7 +AC_CHECK_PROG([python_found],[python],[yes],[no])
3.8 AC_CHECK_PROG([gs_found],[gs],[yes],[no])
3.9
3.10 dnl Detect Intel compiler.
3.11 @@ -82,6 +83,21 @@
3.12 fi
3.13 AM_CONDITIONAL([WANT_TOOLS], [test x"$enable_tools" != x"no"])
3.14
3.15 +dnl Support for running test cases using valgrind.
3.16 +use_valgrind=no
3.17 +AC_ARG_ENABLE([valgrind],
3.18 +AS_HELP_STRING([--enable-valgrind], [use valgrind when running tests]),
3.19 + [use_valgrind=yes])
3.20 +
3.21 +if [[ "$use_valgrind" = "yes" ]]; then
3.22 + AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no)
3.23 +
3.24 + if [[ "$HAVE_VALGRIND" = "no" ]]; then
3.25 + AC_MSG_ERROR([Valgrind not found in PATH.])
3.26 + fi
3.27 +fi
3.28 +AM_CONDITIONAL(USE_VALGRIND, [test "$use_valgrind" = "yes"])
3.29 +
3.30 dnl Checks for header files.
3.31 AC_CHECK_HEADERS(limits.h sys/time.h sys/times.h unistd.h)
3.32
3.33 @@ -127,6 +143,7 @@
3.34 echo CBC support................... : $lx_cbc_found
3.35 echo
3.36 echo Build additional tools........ : $enable_tools
3.37 +echo Use valgrind for tests........ : $use_valgrind
3.38 echo
3.39 echo The packace will be installed in
3.40 echo -n ' '
4.1 --- a/doc/CMakeLists.txt Sun Oct 04 10:15:32 2009 +0200
4.2 +++ b/doc/CMakeLists.txt Wed Dec 09 11:14:06 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 Sun Oct 04 10:15:32 2009 +0200
5.2 +++ b/doc/Doxyfile.in Wed Dec 09 11:14:06 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 Sun Oct 04 10:15:32 2009 +0200
6.2 +++ b/doc/Makefile.am Wed Dec 09 11:14:06 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 Sun Oct 04 10:15:32 2009 +0200
7.2 +++ b/doc/groups.dox Wed Dec 09 11:14:06 2009 +0100
7.3 @@ -280,6 +280,28 @@
7.4 */
7.5
7.6 /**
7.7 +@defgroup geomdat Geometric Data Structures
7.8 +@ingroup auxdat
7.9 +\brief Geometric data structures implemented in LEMON.
7.10 +
7.11 +This group contains geometric data structures implemented in LEMON.
7.12 +
7.13 + - \ref lemon::dim2::Point "dim2::Point" implements a two dimensional
7.14 + vector with the usual operations.
7.15 + - \ref lemon::dim2::Box "dim2::Box" can be used to determine the
7.16 + rectangular bounding box of a set of \ref lemon::dim2::Point
7.17 + "dim2::Point"'s.
7.18 +*/
7.19 +
7.20 +/**
7.21 +@defgroup matrices Matrices
7.22 +@ingroup auxdat
7.23 +\brief Two dimensional data storages implemented in LEMON.
7.24 +
7.25 +This group contains two dimensional data storages implemented in LEMON.
7.26 +*/
7.27 +
7.28 +/**
7.29 @defgroup algs Algorithms
7.30 \brief This group contains the several algorithms
7.31 implemented in LEMON.
7.32 @@ -294,7 +316,8 @@
7.33 \brief Common graph search algorithms.
7.34
7.35 This group contains the common graph search algorithms, namely
7.36 -\e breadth-first \e search (BFS) and \e depth-first \e search (DFS).
7.37 +\e breadth-first \e search (BFS) and \e depth-first \e search (DFS)
7.38 +\ref clrs01algorithms.
7.39 */
7.40
7.41 /**
7.42 @@ -302,7 +325,8 @@
7.43 @ingroup algs
7.44 \brief Algorithms for finding shortest paths.
7.45
7.46 -This group contains the algorithms for finding shortest paths in digraphs.
7.47 +This group contains the algorithms for finding shortest paths in digraphs
7.48 +\ref clrs01algorithms.
7.49
7.50 - \ref Dijkstra algorithm for finding shortest paths from a source node
7.51 when all arc lengths are non-negative.
7.52 @@ -319,12 +343,21 @@
7.53 */
7.54
7.55 /**
7.56 +@defgroup spantree Minimum Spanning Tree Algorithms
7.57 +@ingroup algs
7.58 +\brief Algorithms for finding minimum cost spanning trees and arborescences.
7.59 +
7.60 +This group contains the algorithms for finding minimum cost spanning
7.61 +trees and arborescences \ref clrs01algorithms.
7.62 +*/
7.63 +
7.64 +/**
7.65 @defgroup max_flow Maximum Flow Algorithms
7.66 @ingroup algs
7.67 \brief Algorithms for finding maximum flows.
7.68
7.69 This group contains the algorithms for finding maximum flows and
7.70 -feasible circulations.
7.71 +feasible circulations \ref clrs01algorithms, \ref amo93networkflows.
7.72
7.73 The \e maximum \e flow \e problem is to find a flow of maximum value between
7.74 a single source and a single target. Formally, there is a \f$G=(V,A)\f$
7.75 @@ -339,12 +372,16 @@
7.76 \f[ 0 \leq f(uv) \leq cap(uv) \quad \forall uv\in A \f]
7.77
7.78 LEMON contains several algorithms for solving maximum flow problems:
7.79 -- \ref EdmondsKarp Edmonds-Karp algorithm.
7.80 -- \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm.
7.81 -- \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees.
7.82 -- \ref GoldbergTarjan Preflow push-relabel algorithm with dynamic trees.
7.83 +- \ref EdmondsKarp Edmonds-Karp algorithm
7.84 + \ref edmondskarp72theoretical.
7.85 +- \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm
7.86 + \ref goldberg88newapproach.
7.87 +- \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees
7.88 + \ref dinic70algorithm, \ref sleator83dynamic.
7.89 +- \ref GoldbergTarjan !Preflow push-relabel algorithm with dynamic trees
7.90 + \ref goldberg88newapproach, \ref sleator83dynamic.
7.91
7.92 -In most cases the \ref Preflow "Preflow" algorithm provides the
7.93 +In most cases the \ref Preflow algorithm provides the
7.94 fastest method for computing a maximum flow. All implementations
7.95 also provide functions to query the minimum cut, which is the dual
7.96 problem of maximum flow.
7.97 @@ -362,18 +399,22 @@
7.98 \brief Algorithms for finding minimum cost flows and circulations.
7.99
7.100 This group contains the algorithms for finding minimum cost flows and
7.101 -circulations. For more information about this problem and its dual
7.102 -solution see \ref min_cost_flow "Minimum Cost Flow Problem".
7.103 +circulations \ref amo93networkflows. For more information about this
7.104 +problem and its dual solution, see \ref min_cost_flow
7.105 +"Minimum Cost Flow Problem".
7.106
7.107 LEMON contains several algorithms for this problem.
7.108 - \ref NetworkSimplex Primal Network Simplex algorithm with various
7.109 - pivot strategies.
7.110 + pivot strategies \ref dantzig63linearprog, \ref kellyoneill91netsimplex.
7.111 - \ref CostScaling Push-Relabel and Augment-Relabel algorithms based on
7.112 - cost scaling.
7.113 + cost scaling \ref goldberg90approximation, \ref goldberg97efficient,
7.114 + \ref bunnagel98efficient.
7.115 - \ref CapacityScaling Successive Shortest %Path algorithm with optional
7.116 - capacity scaling.
7.117 - - \ref CancelAndTighten The Cancel and Tighten algorithm.
7.118 - - \ref CycleCanceling Cycle-Canceling algorithms.
7.119 + capacity scaling \ref edmondskarp72theoretical.
7.120 + - \ref CancelAndTighten The Cancel and Tighten algorithm
7.121 + \ref goldberg89cyclecanceling.
7.122 + - \ref CycleCanceling Cycle-Canceling algorithms
7.123 + \ref klein67primal, \ref goldberg89cyclecanceling.
7.124
7.125 In general NetworkSimplex is the most efficient implementation,
7.126 but in special cases other algorithms could be faster.
7.127 @@ -396,7 +437,7 @@
7.128 cut is the \f$X\f$ solution of the next optimization problem:
7.129
7.130 \f[ \min_{X \subset V, X\not\in \{\emptyset, V\}}
7.131 - \sum_{uv\in A, u\in X, v\not\in X}cap(uv) \f]
7.132 + \sum_{uv\in A: u\in X, v\not\in X}cap(uv) \f]
7.133
7.134 LEMON contains several algorithms related to minimum cut problems:
7.135
7.136 @@ -412,27 +453,40 @@
7.137 */
7.138
7.139 /**
7.140 -@defgroup graph_properties Connectivity and Other Graph Properties
7.141 +@defgroup min_mean_cycle Minimum Mean Cycle Algorithms
7.142 @ingroup algs
7.143 -\brief Algorithms for discovering the graph properties
7.144 +\brief Algorithms for finding minimum mean cycles.
7.145
7.146 -This group contains the algorithms for discovering the graph properties
7.147 -like connectivity, bipartiteness, euler property, simplicity etc.
7.148 +This group contains the algorithms for finding minimum mean cycles
7.149 +\ref clrs01algorithms, \ref amo93networkflows.
7.150
7.151 -\image html edge_biconnected_components.png
7.152 -\image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth
7.153 -*/
7.154 +The \e minimum \e mean \e cycle \e problem is to find a directed cycle
7.155 +of minimum mean length (cost) in a digraph.
7.156 +The mean length of a cycle is the average length of its arcs, i.e. the
7.157 +ratio between the total length of the cycle and the number of arcs on it.
7.158
7.159 -/**
7.160 -@defgroup planar Planarity Embedding and Drawing
7.161 -@ingroup algs
7.162 -\brief Algorithms for planarity checking, embedding and drawing
7.163 +This problem has an important connection to \e conservative \e length
7.164 +\e functions, too. A length function on the arcs of a digraph is called
7.165 +conservative if and only if there is no directed cycle of negative total
7.166 +length. For an arbitrary length function, the negative of the minimum
7.167 +cycle mean is the smallest \f$\epsilon\f$ value so that increasing the
7.168 +arc lengths uniformly by \f$\epsilon\f$ results in a conservative length
7.169 +function.
7.170
7.171 -This group contains the algorithms for planarity checking,
7.172 -embedding and drawing.
7.173 +LEMON contains three algorithms for solving the minimum mean cycle problem:
7.174 +- \ref Karp "Karp"'s original algorithm \ref amo93networkflows,
7.175 + \ref dasdan98minmeancycle.
7.176 +- \ref HartmannOrlin "Hartmann-Orlin"'s algorithm, which is an improved
7.177 + version of Karp's algorithm \ref dasdan98minmeancycle.
7.178 +- \ref Howard "Howard"'s policy iteration algorithm
7.179 + \ref dasdan98minmeancycle.
7.180
7.181 -\image html planar.png
7.182 -\image latex planar.eps "Plane graph" width=\textwidth
7.183 +In practice, the Howard algorithm proved to be by far the most efficient
7.184 +one, though the best known theoretical bound on its running time is
7.185 +exponential.
7.186 +Both Karp and HartmannOrlin algorithms run in time O(ne) and use space
7.187 +O(n<sup>2</sup>+e), but the latter one is typically faster due to the
7.188 +applied early termination scheme.
7.189 */
7.190
7.191 /**
7.192 @@ -476,12 +530,36 @@
7.193 */
7.194
7.195 /**
7.196 -@defgroup spantree Minimum Spanning Tree Algorithms
7.197 +@defgroup graph_properties Connectivity and Other Graph Properties
7.198 @ingroup algs
7.199 -\brief Algorithms for finding minimum cost spanning trees and arborescences.
7.200 +\brief Algorithms for discovering the graph properties
7.201
7.202 -This group contains the algorithms for finding minimum cost spanning
7.203 -trees and arborescences.
7.204 +This group contains the algorithms for discovering the graph properties
7.205 +like connectivity, bipartiteness, euler property, simplicity etc.
7.206 +
7.207 +\image html connected_components.png
7.208 +\image latex connected_components.eps "Connected components" width=\textwidth
7.209 +*/
7.210 +
7.211 +/**
7.212 +@defgroup planar Planarity Embedding and Drawing
7.213 +@ingroup algs
7.214 +\brief Algorithms for planarity checking, embedding and drawing
7.215 +
7.216 +This group contains the algorithms for planarity checking,
7.217 +embedding and drawing.
7.218 +
7.219 +\image html planar.png
7.220 +\image latex planar.eps "Plane graph" width=\textwidth
7.221 +*/
7.222 +
7.223 +/**
7.224 +@defgroup approx Approximation Algorithms
7.225 +@ingroup algs
7.226 +\brief Approximation algorithms.
7.227 +
7.228 +This group contains the approximation and heuristic algorithms
7.229 +implemented in LEMON.
7.230 */
7.231
7.232 /**
7.233 @@ -494,15 +572,6 @@
7.234 */
7.235
7.236 /**
7.237 -@defgroup approx Approximation Algorithms
7.238 -@ingroup algs
7.239 -\brief Approximation algorithms.
7.240 -
7.241 -This group contains the approximation and heuristic algorithms
7.242 -implemented in LEMON.
7.243 -*/
7.244 -
7.245 -/**
7.246 @defgroup gen_opt_group General Optimization Tools
7.247 \brief This group contains some general optimization frameworks
7.248 implemented in LEMON.
7.249 @@ -512,13 +581,16 @@
7.250 */
7.251
7.252 /**
7.253 -@defgroup lp_group Lp and Mip Solvers
7.254 +@defgroup lp_group LP and MIP Solvers
7.255 @ingroup gen_opt_group
7.256 -\brief Lp and Mip solver interfaces for LEMON.
7.257 +\brief LP and MIP solver interfaces for LEMON.
7.258
7.259 -This group contains Lp and Mip solver interfaces for LEMON. The
7.260 -various LP solvers could be used in the same manner with this
7.261 -interface.
7.262 +This group contains LP and MIP solver interfaces for LEMON.
7.263 +Various LP solvers could be used in the same manner with this
7.264 +high-level interface.
7.265 +
7.266 +The currently supported solvers are \ref glpk, \ref clp, \ref cbc,
7.267 +\ref cplex, \ref soplex.
7.268 */
7.269
7.270 /**
7.271 @@ -608,7 +680,7 @@
7.272 */
7.273
7.274 /**
7.275 -@defgroup dimacs_group DIMACS format
7.276 +@defgroup dimacs_group DIMACS Format
7.277 @ingroup io_group
7.278 \brief Read and write files in DIMACS format
7.279
7.280 @@ -657,8 +729,8 @@
7.281 @ingroup concept
7.282 \brief Skeleton and concept checking classes for graph structures
7.283
7.284 -This group contains the skeletons and concept checking classes of LEMON's
7.285 -graph structures and helper classes used to implement these.
7.286 +This group contains the skeletons and concept checking classes of
7.287 +graph structures.
7.288 */
7.289
7.290 /**
7.291 @@ -670,6 +742,15 @@
7.292 */
7.293
7.294 /**
7.295 +@defgroup tools Standalone Utility Applications
7.296 +
7.297 +Some utility applications are listed here.
7.298 +
7.299 +The standard compilation procedure (<tt>./configure;make</tt>) will compile
7.300 +them, as well.
7.301 +*/
7.302 +
7.303 +/**
7.304 \anchor demoprograms
7.305
7.306 @defgroup demos Demo Programs
7.307 @@ -681,13 +762,4 @@
7.308 <tt>make check</tt> commands.
7.309 */
7.310
7.311 -/**
7.312 -@defgroup tools Standalone Utility Applications
7.313 -
7.314 -Some utility applications are listed here.
7.315 -
7.316 -The standard compilation procedure (<tt>./configure;make</tt>) will compile
7.317 -them, as well.
7.318 -*/
7.319 -
7.320 }
8.1 --- a/doc/mainpage.dox Sun Oct 04 10:15:32 2009 +0200
8.2 +++ b/doc/mainpage.dox Wed Dec 09 11:14:06 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 Sun Oct 04 10:15:32 2009 +0200
9.2 +++ b/doc/min_cost_flow.dox Wed Dec 09 11:14:06 2009 +0100
9.3 @@ -26,7 +26,7 @@
9.4 The \e minimum \e cost \e flow \e problem is to find a feasible flow of
9.5 minimum total cost from a set of supply nodes to a set of demand nodes
9.6 in a network with capacity constraints (lower and upper bounds)
9.7 -and arc costs.
9.8 +and arc costs \ref amo93networkflows.
9.9
9.10 Formally, let \f$G=(V,A)\f$ be a digraph, \f$lower: A\rightarrow\mathbf{R}\f$,
9.11 \f$upper: A\rightarrow\mathbf{R}\cup\{+\infty\}\f$ denote the lower and
9.12 @@ -78,7 +78,7 @@
9.13 - if \f$lower(uv)<f(uv)<upper(uv)\f$, then \f$cost^\pi(uv)=0\f$;
9.14 - if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$.
9.15 - For all \f$u\in V\f$ nodes:
9.16 - - \f$\pi(u)<=0\f$;
9.17 + - \f$\pi(u)\leq 0\f$;
9.18 - if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$,
9.19 then \f$\pi(u)=0\f$.
9.20
9.21 @@ -145,7 +145,7 @@
9.22 - if \f$lower(uv)<f(uv)<upper(uv)\f$, then \f$cost^\pi(uv)=0\f$;
9.23 - if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$.
9.24 - For all \f$u\in V\f$ nodes:
9.25 - - \f$\pi(u)>=0\f$;
9.26 + - \f$\pi(u)\geq 0\f$;
9.27 - if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$,
9.28 then \f$\pi(u)=0\f$.
9.29
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/doc/references.bib Wed Dec 09 11:14:06 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 Sun Oct 04 10:15:32 2009 +0200
11.2 +++ b/lemon/Makefile.am Wed Dec 09 11:14:06 2009 +0100
11.3 @@ -86,7 +86,10 @@
11.4 lemon/gomory_hu.h \
11.5 lemon/graph_to_eps.h \
11.6 lemon/grid_graph.h \
11.7 + lemon/hartmann_orlin.h \
11.8 + lemon/howard.h \
11.9 lemon/hypercube_graph.h \
11.10 + lemon/karp.h \
11.11 lemon/kary_heap.h \
11.12 lemon/kruskal.h \
11.13 lemon/hao_orlin.h \
11.14 @@ -111,6 +114,7 @@
11.15 lemon/random.h \
11.16 lemon/smart_graph.h \
11.17 lemon/soplex.h \
11.18 + lemon/static_graph.h \
11.19 lemon/suurballe.h \
11.20 lemon/time_measure.h \
11.21 lemon/tolerance.h \
12.1 --- a/lemon/adaptors.h Sun Oct 04 10:15:32 2009 +0200
12.2 +++ b/lemon/adaptors.h Wed Dec 09 11:14:06 2009 +0100
12.3 @@ -360,6 +360,9 @@
12.4 /// by adding or removing nodes or arcs, unless the \c GR template
12.5 /// parameter is set to be \c const.
12.6 ///
12.7 + /// This class provides item counting in the same time as the adapted
12.8 + /// digraph structure.
12.9 + ///
12.10 /// \tparam DGR The type of the adapted digraph.
12.11 /// It must conform to the \ref concepts::Digraph "Digraph" concept.
12.12 /// It can also be specified to be \c const.
12.13 @@ -719,6 +722,8 @@
12.14 /// by adding or removing nodes or arcs, unless the \c GR template
12.15 /// parameter is set to be \c const.
12.16 ///
12.17 + /// This class provides only linear time counting for nodes and arcs.
12.18 + ///
12.19 /// \tparam DGR The type of the adapted digraph.
12.20 /// It must conform to the \ref concepts::Digraph "Digraph" concept.
12.21 /// It can also be specified to be \c const.
12.22 @@ -1314,6 +1319,8 @@
12.23 /// by adding or removing nodes or edges, unless the \c GR template
12.24 /// parameter is set to be \c const.
12.25 ///
12.26 + /// This class provides only linear time counting for nodes, edges and arcs.
12.27 + ///
12.28 /// \tparam GR The type of the adapted graph.
12.29 /// It must conform to the \ref concepts::Graph "Graph" concept.
12.30 /// It can also be specified to be \c const.
12.31 @@ -1471,6 +1478,8 @@
12.32 /// by adding or removing nodes or arcs/edges, unless the \c GR template
12.33 /// parameter is set to be \c const.
12.34 ///
12.35 + /// This class provides only linear time item counting.
12.36 + ///
12.37 /// \tparam GR The type of the adapted digraph or graph.
12.38 /// It must conform to the \ref concepts::Digraph "Digraph" concept
12.39 /// or the \ref concepts::Graph "Graph" concept.
12.40 @@ -1619,6 +1628,8 @@
12.41 /// by adding or removing nodes or arcs, unless the \c GR template
12.42 /// parameter is set to be \c const.
12.43 ///
12.44 + /// This class provides only linear time counting for nodes and arcs.
12.45 + ///
12.46 /// \tparam DGR The type of the adapted digraph.
12.47 /// It must conform to the \ref concepts::Digraph "Digraph" concept.
12.48 /// It can also be specified to be \c const.
12.49 @@ -1729,6 +1740,8 @@
12.50 /// by adding or removing nodes or edges, unless the \c GR template
12.51 /// parameter is set to be \c const.
12.52 ///
12.53 + /// This class provides only linear time counting for nodes, edges and arcs.
12.54 + ///
12.55 /// \tparam GR The type of the adapted graph.
12.56 /// It must conform to the \ref concepts::Graph "Graph" concept.
12.57 /// It can also be specified to be \c const.
12.58 @@ -2232,6 +2245,9 @@
12.59 /// by adding or removing nodes or edges, unless the \c GR template
12.60 /// parameter is set to be \c const.
12.61 ///
12.62 + /// This class provides item counting in the same time as the adapted
12.63 + /// digraph structure.
12.64 + ///
12.65 /// \tparam DGR The type of the adapted digraph.
12.66 /// It must conform to the \ref concepts::Digraph "Digraph" concept.
12.67 /// It can also be specified to be \c const.
12.68 @@ -2535,6 +2551,9 @@
12.69 /// by adding or removing nodes or arcs, unless the \c GR template
12.70 /// parameter is set to be \c const.
12.71 ///
12.72 + /// This class provides item counting in the same time as the adapted
12.73 + /// graph structure.
12.74 + ///
12.75 /// \tparam GR The type of the adapted graph.
12.76 /// It must conform to the \ref concepts::Graph "Graph" concept.
12.77 /// It can also be specified to be \c const.
12.78 @@ -2678,6 +2697,8 @@
12.79 /// arcs).
12.80 /// This class conforms to the \ref concepts::Digraph "Digraph" concept.
12.81 ///
12.82 + /// This class provides only linear time counting for nodes and arcs.
12.83 + ///
12.84 /// \tparam DGR The type of the adapted digraph.
12.85 /// It must conform to the \ref concepts::Digraph "Digraph" concept.
12.86 /// It is implicitly \c const.
12.87 @@ -3325,6 +3346,9 @@
12.88 /// costs/capacities of the original digraph to the \e bind \e arcs
12.89 /// in the adaptor.
12.90 ///
12.91 + /// This class provides item counting in the same time as the adapted
12.92 + /// digraph structure.
12.93 + ///
12.94 /// \tparam DGR The type of the adapted digraph.
12.95 /// It must conform to the \ref concepts::Digraph "Digraph" concept.
12.96 /// It is implicitly \c const.
13.1 --- a/lemon/bellman_ford.h Sun Oct 04 10:15:32 2009 +0200
13.2 +++ b/lemon/bellman_ford.h Wed Dec 09 11:14:06 2009 +0100
13.3 @@ -23,6 +23,7 @@
13.4 /// \file
13.5 /// \brief Bellman-Ford algorithm.
13.6
13.7 +#include <lemon/list_graph.h>
13.8 #include <lemon/bits/path_dump.h>
13.9 #include <lemon/core.h>
13.10 #include <lemon/error.h>
13.11 @@ -299,7 +300,7 @@
13.12 ///
13.13 /// \ref named-templ-param "Named parameter" for setting
13.14 /// \c OperationTraits type.
13.15 - /// For more information see \ref BellmanFordDefaultOperationTraits.
13.16 + /// For more information, see \ref BellmanFordDefaultOperationTraits.
13.17 template <class T>
13.18 struct SetOperationTraits
13.19 : public BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> > {
13.20 @@ -717,7 +718,7 @@
13.21 /// is not reached from the root(s) or if \c v is a root.
13.22 ///
13.23 /// The shortest path tree used here is equal to the shortest path
13.24 - /// tree used in \ref predNode() and \predMap().
13.25 + /// tree used in \ref predNode() and \ref predMap().
13.26 ///
13.27 /// \pre Either \ref run() or \ref init() must be called before
13.28 /// using this function.
13.29 @@ -732,7 +733,7 @@
13.30 /// is not reached from the root(s) or if \c v is a root.
13.31 ///
13.32 /// The shortest path tree used here is equal to the shortest path
13.33 - /// tree used in \ref predArc() and \predMap().
13.34 + /// tree used in \ref predArc() and \ref predMap().
13.35 ///
13.36 /// \pre Either \ref run() or \ref init() must be called before
13.37 /// using this function.
13.38 @@ -775,7 +776,7 @@
13.39 /// This function gives back a directed cycle with negative total
13.40 /// length if the algorithm has already found one.
13.41 /// Otherwise it gives back an empty path.
13.42 - lemon::Path<Digraph> negativeCycle() {
13.43 + lemon::Path<Digraph> negativeCycle() const {
13.44 typename Digraph::template NodeMap<int> state(*_gr, -1);
13.45 lemon::Path<Digraph> cycle;
13.46 for (int i = 0; i < int(_process.size()); ++i) {
14.1 --- a/lemon/bfs.h Sun Oct 04 10:15:32 2009 +0200
14.2 +++ b/lemon/bfs.h Wed Dec 09 11:14:06 2009 +0100
14.3 @@ -47,7 +47,7 @@
14.4 ///
14.5 ///The type of the map that stores the predecessor
14.6 ///arcs of the shortest paths.
14.7 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.8 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.9 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
14.10 ///Instantiates a \c PredMap.
14.11
14.12 @@ -62,7 +62,8 @@
14.13 ///The type of the map that indicates which nodes are processed.
14.14
14.15 ///The type of the map that indicates which nodes are processed.
14.16 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.17 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.18 + ///By default, it is a NullMap.
14.19 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
14.20 ///Instantiates a \c ProcessedMap.
14.21
14.22 @@ -81,7 +82,7 @@
14.23 ///The type of the map that indicates which nodes are reached.
14.24
14.25 ///The type of the map that indicates which nodes are reached.
14.26 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
14.27 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
14.28 typedef typename Digraph::template NodeMap<bool> ReachedMap;
14.29 ///Instantiates a \c ReachedMap.
14.30
14.31 @@ -96,7 +97,7 @@
14.32 ///The type of the map that stores the distances of the nodes.
14.33
14.34 ///The type of the map that stores the distances of the nodes.
14.35 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.36 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.37 typedef typename Digraph::template NodeMap<int> DistMap;
14.38 ///Instantiates a \c DistMap.
14.39
14.40 @@ -225,7 +226,7 @@
14.41 ///
14.42 ///\ref named-templ-param "Named parameter" for setting
14.43 ///\c PredMap type.
14.44 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.45 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.46 template <class T>
14.47 struct SetPredMap : public Bfs< Digraph, SetPredMapTraits<T> > {
14.48 typedef Bfs< Digraph, SetPredMapTraits<T> > Create;
14.49 @@ -245,7 +246,7 @@
14.50 ///
14.51 ///\ref named-templ-param "Named parameter" for setting
14.52 ///\c DistMap type.
14.53 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.54 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.55 template <class T>
14.56 struct SetDistMap : public Bfs< Digraph, SetDistMapTraits<T> > {
14.57 typedef Bfs< Digraph, SetDistMapTraits<T> > Create;
14.58 @@ -265,7 +266,7 @@
14.59 ///
14.60 ///\ref named-templ-param "Named parameter" for setting
14.61 ///\c ReachedMap type.
14.62 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
14.63 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
14.64 template <class T>
14.65 struct SetReachedMap : public Bfs< Digraph, SetReachedMapTraits<T> > {
14.66 typedef Bfs< Digraph, SetReachedMapTraits<T> > Create;
14.67 @@ -285,7 +286,7 @@
14.68 ///
14.69 ///\ref named-templ-param "Named parameter" for setting
14.70 ///\c ProcessedMap type.
14.71 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.72 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.73 template <class T>
14.74 struct SetProcessedMap : public Bfs< Digraph, SetProcessedMapTraits<T> > {
14.75 typedef Bfs< Digraph, SetProcessedMapTraits<T> > Create;
14.76 @@ -413,8 +414,8 @@
14.77 ///\name Execution Control
14.78 ///The simplest way to execute the BFS algorithm is to use one of the
14.79 ///member functions called \ref run(Node) "run()".\n
14.80 - ///If you need more control on the execution, first you have to call
14.81 - ///\ref init(), then you can add several source nodes with
14.82 + ///If you need better control on the execution, you have to call
14.83 + ///\ref init() first, then you can add several source nodes with
14.84 ///\ref addSource(). Finally the actual path computation can be
14.85 ///performed with one of the \ref start() functions.
14.86
14.87 @@ -700,12 +701,8 @@
14.88
14.89 ///Runs the algorithm to visit all nodes in the digraph.
14.90
14.91 - ///This method runs the %BFS algorithm in order to
14.92 - ///compute the shortest path to each node.
14.93 - ///
14.94 - ///The algorithm computes
14.95 - ///- the shortest path tree (forest),
14.96 - ///- the distance of each node from the root(s).
14.97 + ///This method runs the %BFS algorithm in order to visit all nodes
14.98 + ///in the digraph.
14.99 ///
14.100 ///\note <tt>b.run(s)</tt> is just a shortcut of the following code.
14.101 ///\code
14.102 @@ -737,9 +734,9 @@
14.103
14.104 ///@{
14.105
14.106 - ///The shortest path to a node.
14.107 + ///The shortest path to the given node.
14.108
14.109 - ///Returns the shortest path to a node.
14.110 + ///Returns the shortest path to the given node from the root(s).
14.111 ///
14.112 ///\warning \c t should be reached from the root(s).
14.113 ///
14.114 @@ -747,9 +744,9 @@
14.115 ///must be called before using this function.
14.116 Path path(Node t) const { return Path(*G, *_pred, t); }
14.117
14.118 - ///The distance of a node from the root(s).
14.119 + ///The distance of the given node from the root(s).
14.120
14.121 - ///Returns the distance of a node from the root(s).
14.122 + ///Returns the distance of the given node from the root(s).
14.123 ///
14.124 ///\warning If node \c v is not reached from the root(s), then
14.125 ///the return value of this function is undefined.
14.126 @@ -758,29 +755,31 @@
14.127 ///must be called before using this function.
14.128 int dist(Node v) const { return (*_dist)[v]; }
14.129
14.130 - ///Returns the 'previous arc' of the shortest path tree for a node.
14.131 -
14.132 + ///\brief Returns the 'previous arc' of the shortest path tree for
14.133 + ///the given node.
14.134 + ///
14.135 ///This function returns the 'previous arc' of the shortest path
14.136 ///tree for the node \c v, i.e. it returns the last arc of a
14.137 ///shortest path from a root to \c v. It is \c INVALID if \c v
14.138 ///is not reached from the root(s) or if \c v is a root.
14.139 ///
14.140 ///The shortest path tree used here is equal to the shortest path
14.141 - ///tree used in \ref predNode().
14.142 + ///tree used in \ref predNode() and \ref predMap().
14.143 ///
14.144 ///\pre Either \ref run(Node) "run()" or \ref init()
14.145 ///must be called before using this function.
14.146 Arc predArc(Node v) const { return (*_pred)[v];}
14.147
14.148 - ///Returns the 'previous node' of the shortest path tree for a node.
14.149 -
14.150 + ///\brief Returns the 'previous node' of the shortest path tree for
14.151 + ///the given node.
14.152 + ///
14.153 ///This function returns the 'previous node' of the shortest path
14.154 ///tree for the node \c v, i.e. it returns the last but one node
14.155 - ///from a shortest path from a root to \c v. It is \c INVALID
14.156 + ///of a shortest path from a root to \c v. It is \c INVALID
14.157 ///if \c v is not reached from the root(s) or if \c v is a root.
14.158 ///
14.159 ///The shortest path tree used here is equal to the shortest path
14.160 - ///tree used in \ref predArc().
14.161 + ///tree used in \ref predArc() and \ref predMap().
14.162 ///
14.163 ///\pre Either \ref run(Node) "run()" or \ref init()
14.164 ///must be called before using this function.
14.165 @@ -801,13 +800,13 @@
14.166 ///predecessor arcs.
14.167 ///
14.168 ///Returns a const reference to the node map that stores the predecessor
14.169 - ///arcs, which form the shortest path tree.
14.170 + ///arcs, which form the shortest path tree (forest).
14.171 ///
14.172 ///\pre Either \ref run(Node) "run()" or \ref init()
14.173 ///must be called before using this function.
14.174 const PredMap &predMap() const { return *_pred;}
14.175
14.176 - ///Checks if a node is reached from the root(s).
14.177 + ///Checks if the given node is reached from the root(s).
14.178
14.179 ///Returns \c true if \c v is reached from the root(s).
14.180 ///
14.181 @@ -833,7 +832,7 @@
14.182 ///
14.183 ///The type of the map that stores the predecessor
14.184 ///arcs of the shortest paths.
14.185 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.186 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.187 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
14.188 ///Instantiates a PredMap.
14.189
14.190 @@ -848,8 +847,8 @@
14.191 ///The type of the map that indicates which nodes are processed.
14.192
14.193 ///The type of the map that indicates which nodes are processed.
14.194 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.195 - ///By default it is a NullMap.
14.196 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.197 + ///By default, it is a NullMap.
14.198 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
14.199 ///Instantiates a ProcessedMap.
14.200
14.201 @@ -868,7 +867,7 @@
14.202 ///The type of the map that indicates which nodes are reached.
14.203
14.204 ///The type of the map that indicates which nodes are reached.
14.205 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
14.206 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
14.207 typedef typename Digraph::template NodeMap<bool> ReachedMap;
14.208 ///Instantiates a ReachedMap.
14.209
14.210 @@ -883,7 +882,7 @@
14.211 ///The type of the map that stores the distances of the nodes.
14.212
14.213 ///The type of the map that stores the distances of the nodes.
14.214 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
14.215 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
14.216 typedef typename Digraph::template NodeMap<int> DistMap;
14.217 ///Instantiates a DistMap.
14.218
14.219 @@ -898,18 +897,14 @@
14.220 ///The type of the shortest paths.
14.221
14.222 ///The type of the shortest paths.
14.223 - ///It must meet the \ref concepts::Path "Path" concept.
14.224 + ///It must conform to the \ref concepts::Path "Path" concept.
14.225 typedef lemon::Path<Digraph> Path;
14.226 };
14.227
14.228 /// Default traits class used by BfsWizard
14.229
14.230 - /// To make it easier to use Bfs algorithm
14.231 - /// we have created a wizard class.
14.232 - /// This \ref BfsWizard class needs default traits,
14.233 - /// as well as the \ref Bfs class.
14.234 - /// The \ref BfsWizardBase is a class to be the default traits of the
14.235 - /// \ref BfsWizard class.
14.236 + /// Default traits class used by BfsWizard.
14.237 + /// \tparam GR The type of the digraph.
14.238 template<class GR>
14.239 class BfsWizardBase : public BfsWizardDefaultTraits<GR>
14.240 {
14.241 @@ -937,7 +932,7 @@
14.242 public:
14.243 /// Constructor.
14.244
14.245 - /// This constructor does not require parameters, therefore it initiates
14.246 + /// This constructor does not require parameters, it initiates
14.247 /// all of the attributes to \c 0.
14.248 BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
14.249 _dist(0), _path(0), _di(0) {}
14.250 @@ -967,7 +962,6 @@
14.251 {
14.252 typedef TR Base;
14.253
14.254 - ///The type of the digraph the algorithm runs on.
14.255 typedef typename TR::Digraph Digraph;
14.256
14.257 typedef typename Digraph::Node Node;
14.258 @@ -975,16 +969,10 @@
14.259 typedef typename Digraph::Arc Arc;
14.260 typedef typename Digraph::OutArcIt OutArcIt;
14.261
14.262 - ///\brief The type of the map that stores the predecessor
14.263 - ///arcs of the shortest paths.
14.264 typedef typename TR::PredMap PredMap;
14.265 - ///\brief The type of the map that stores the distances of the nodes.
14.266 typedef typename TR::DistMap DistMap;
14.267 - ///\brief The type of the map that indicates which nodes are reached.
14.268 typedef typename TR::ReachedMap ReachedMap;
14.269 - ///\brief The type of the map that indicates which nodes are processed.
14.270 typedef typename TR::ProcessedMap ProcessedMap;
14.271 - ///The type of the shortest paths
14.272 typedef typename TR::Path Path;
14.273
14.274 public:
14.275 @@ -1054,8 +1042,8 @@
14.276
14.277 ///Runs BFS algorithm to visit all nodes in the digraph.
14.278
14.279 - ///This method runs BFS algorithm in order to compute
14.280 - ///the shortest path to each node.
14.281 + ///This method runs BFS algorithm in order to visit all nodes
14.282 + ///in the digraph.
14.283 void run()
14.284 {
14.285 run(INVALID);
14.286 @@ -1067,11 +1055,12 @@
14.287 static PredMap *createPredMap(const Digraph &) { return 0; };
14.288 SetPredMapBase(const TR &b) : TR(b) {}
14.289 };
14.290 - ///\brief \ref named-func-param "Named parameter"
14.291 - ///for setting PredMap object.
14.292 +
14.293 + ///\brief \ref named-templ-param "Named parameter" for setting
14.294 + ///the predecessor map.
14.295 ///
14.296 - ///\ref named-func-param "Named parameter"
14.297 - ///for setting PredMap object.
14.298 + ///\ref named-templ-param "Named parameter" function for setting
14.299 + ///the map that stores the predecessor arcs of the nodes.
14.300 template<class T>
14.301 BfsWizard<SetPredMapBase<T> > predMap(const T &t)
14.302 {
14.303 @@ -1085,11 +1074,12 @@
14.304 static ReachedMap *createReachedMap(const Digraph &) { return 0; };
14.305 SetReachedMapBase(const TR &b) : TR(b) {}
14.306 };
14.307 - ///\brief \ref named-func-param "Named parameter"
14.308 - ///for setting ReachedMap object.
14.309 +
14.310 + ///\brief \ref named-templ-param "Named parameter" for setting
14.311 + ///the reached map.
14.312 ///
14.313 - /// \ref named-func-param "Named parameter"
14.314 - ///for setting ReachedMap object.
14.315 + ///\ref named-templ-param "Named parameter" function for setting
14.316 + ///the map that indicates which nodes are reached.
14.317 template<class T>
14.318 BfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
14.319 {
14.320 @@ -1103,11 +1093,13 @@
14.321 static DistMap *createDistMap(const Digraph &) { return 0; };
14.322 SetDistMapBase(const TR &b) : TR(b) {}
14.323 };
14.324 - ///\brief \ref named-func-param "Named parameter"
14.325 - ///for setting DistMap object.
14.326 +
14.327 + ///\brief \ref named-templ-param "Named parameter" for setting
14.328 + ///the distance map.
14.329 ///
14.330 - /// \ref named-func-param "Named parameter"
14.331 - ///for setting DistMap object.
14.332 + ///\ref named-templ-param "Named parameter" function for setting
14.333 + ///the map that stores the distances of the nodes calculated
14.334 + ///by the algorithm.
14.335 template<class T>
14.336 BfsWizard<SetDistMapBase<T> > distMap(const T &t)
14.337 {
14.338 @@ -1121,11 +1113,12 @@
14.339 static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
14.340 SetProcessedMapBase(const TR &b) : TR(b) {}
14.341 };
14.342 - ///\brief \ref named-func-param "Named parameter"
14.343 - ///for setting ProcessedMap object.
14.344 +
14.345 + ///\brief \ref named-func-param "Named parameter" for setting
14.346 + ///the processed map.
14.347 ///
14.348 - /// \ref named-func-param "Named parameter"
14.349 - ///for setting ProcessedMap object.
14.350 + ///\ref named-templ-param "Named parameter" function for setting
14.351 + ///the map that indicates which nodes are processed.
14.352 template<class T>
14.353 BfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
14.354 {
14.355 @@ -1264,7 +1257,7 @@
14.356 /// \brief The type of the map that indicates which nodes are reached.
14.357 ///
14.358 /// The type of the map that indicates which nodes are reached.
14.359 - /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
14.360 + /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
14.361 typedef typename Digraph::template NodeMap<bool> ReachedMap;
14.362
14.363 /// \brief Instantiates a ReachedMap.
14.364 @@ -1425,8 +1418,8 @@
14.365 /// \name Execution Control
14.366 /// The simplest way to execute the BFS algorithm is to use one of the
14.367 /// member functions called \ref run(Node) "run()".\n
14.368 - /// If you need more control on the execution, first you have to call
14.369 - /// \ref init(), then you can add several source nodes with
14.370 + /// If you need better control on the execution, you have to call
14.371 + /// \ref init() first, then you can add several source nodes with
14.372 /// \ref addSource(). Finally the actual path computation can be
14.373 /// performed with one of the \ref start() functions.
14.374
14.375 @@ -1698,12 +1691,8 @@
14.376
14.377 /// \brief Runs the algorithm to visit all nodes in the digraph.
14.378 ///
14.379 - /// This method runs the %BFS algorithm in order to
14.380 - /// compute the shortest path to each node.
14.381 - ///
14.382 - /// The algorithm computes
14.383 - /// - the shortest path tree (forest),
14.384 - /// - the distance of each node from the root(s).
14.385 + /// This method runs the %BFS algorithm in order to visit all nodes
14.386 + /// in the digraph.
14.387 ///
14.388 /// \note <tt>b.run(s)</tt> is just a shortcut of the following code.
14.389 ///\code
14.390 @@ -1735,7 +1724,7 @@
14.391
14.392 ///@{
14.393
14.394 - /// \brief Checks if a node is reached from the root(s).
14.395 + /// \brief Checks if the given node is reached from the root(s).
14.396 ///
14.397 /// Returns \c true if \c v is reached from the root(s).
14.398 ///
15.1 --- a/lemon/bits/graph_extender.h Sun Oct 04 10:15:32 2009 +0200
15.2 +++ b/lemon/bits/graph_extender.h Wed Dec 09 11:14:06 2009 +0100
15.3 @@ -56,11 +56,11 @@
15.4 return Parent::maxArcId();
15.5 }
15.6
15.7 - Node fromId(int id, Node) const {
15.8 + static Node fromId(int id, Node) {
15.9 return Parent::nodeFromId(id);
15.10 }
15.11
15.12 - Arc fromId(int id, Arc) const {
15.13 + static Arc fromId(int id, Arc) {
15.14 return Parent::arcFromId(id);
15.15 }
15.16
15.17 @@ -355,15 +355,15 @@
15.18 return Parent::maxEdgeId();
15.19 }
15.20
15.21 - Node fromId(int id, Node) const {
15.22 + static Node fromId(int id, Node) {
15.23 return Parent::nodeFromId(id);
15.24 }
15.25
15.26 - Arc fromId(int id, Arc) const {
15.27 + static Arc fromId(int id, Arc) {
15.28 return Parent::arcFromId(id);
15.29 }
15.30
15.31 - Edge fromId(int id, Edge) const {
15.32 + static Edge fromId(int id, Edge) {
15.33 return Parent::edgeFromId(id);
15.34 }
15.35
16.1 --- a/lemon/bits/map_extender.h Sun Oct 04 10:15:32 2009 +0200
16.2 +++ b/lemon/bits/map_extender.h Wed Dec 09 11:14:06 2009 +0100
16.3 @@ -49,6 +49,8 @@
16.4 typedef typename Parent::Reference Reference;
16.5 typedef typename Parent::ConstReference ConstReference;
16.6
16.7 + typedef typename Parent::ReferenceMapTag ReferenceMapTag;
16.8 +
16.9 class MapIt;
16.10 class ConstMapIt;
16.11
16.12 @@ -191,6 +193,8 @@
16.13 typedef typename Parent::Reference Reference;
16.14 typedef typename Parent::ConstReference ConstReference;
16.15
16.16 + typedef typename Parent::ReferenceMapTag ReferenceMapTag;
16.17 +
16.18 class MapIt;
16.19 class ConstMapIt;
16.20
17.1 --- a/lemon/cbc.cc Sun Oct 04 10:15:32 2009 +0200
17.2 +++ b/lemon/cbc.cc Wed Dec 09 11:14:06 2009 +0100
17.3 @@ -94,6 +94,18 @@
17.4 return _prob->numberRows() - 1;
17.5 }
17.6
17.7 + int CbcMip::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
17.8 + std::vector<int> indexes;
17.9 + std::vector<Value> values;
17.10 +
17.11 + for(ExprIterator it = b; it != e; ++it) {
17.12 + indexes.push_back(it->first);
17.13 + values.push_back(it->second);
17.14 + }
17.15 +
17.16 + _prob->addRow(values.size(), &indexes.front(), &values.front(), l, u);
17.17 + return _prob->numberRows() - 1;
17.18 + }
17.19
17.20 void CbcMip::_eraseCol(int i) {
17.21 _prob->deleteColumn(i);
18.1 --- a/lemon/cbc.h Sun Oct 04 10:15:32 2009 +0200
18.2 +++ b/lemon/cbc.h Wed Dec 09 11:14:06 2009 +0100
18.3 @@ -62,6 +62,7 @@
18.4
18.5 virtual int _addCol();
18.6 virtual int _addRow();
18.7 + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
18.8
18.9 virtual void _eraseCol(int i);
18.10 virtual void _eraseRow(int i);
19.1 --- a/lemon/circulation.h Sun Oct 04 10:15:32 2009 +0200
19.2 +++ b/lemon/circulation.h Wed Dec 09 11:14:06 2009 +0100
19.3 @@ -72,7 +72,11 @@
19.4 /// The type of the map that stores the flow values.
19.5 /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap"
19.6 /// concept.
19.7 +#ifdef DOXYGEN
19.8 + typedef GR::ArcMap<Value> FlowMap;
19.9 +#else
19.10 typedef typename Digraph::template ArcMap<Value> FlowMap;
19.11 +#endif
19.12
19.13 /// \brief Instantiates a FlowMap.
19.14 ///
19.15 @@ -87,9 +91,12 @@
19.16 ///
19.17 /// The elevator type used by the algorithm.
19.18 ///
19.19 - /// \sa Elevator
19.20 - /// \sa LinkedElevator
19.21 + /// \sa Elevator, LinkedElevator
19.22 +#ifdef DOXYGEN
19.23 + typedef lemon::Elevator<GR, GR::Node> Elevator;
19.24 +#else
19.25 typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator;
19.26 +#endif
19.27
19.28 /// \brief Instantiates an Elevator.
19.29 ///
19.30 @@ -299,7 +306,7 @@
19.31 /// The Elevator should have standard constructor interface to be
19.32 /// able to automatically created by the algorithm (i.e. the
19.33 /// digraph and the maximum level should be passed to it).
19.34 - /// However an external elevator object could also be passed to the
19.35 + /// However, an external elevator object could also be passed to the
19.36 /// algorithm with the \ref elevator(Elevator&) "elevator()" function
19.37 /// before calling \ref run() or \ref init().
19.38 /// \sa SetElevator
19.39 @@ -469,8 +476,8 @@
19.40
19.41 /// \name Execution Control
19.42 /// The simplest way to execute the algorithm is to call \ref run().\n
19.43 - /// If you need more control on the initial solution or the execution,
19.44 - /// first you have to call one of the \ref init() functions, then
19.45 + /// If you need better control on the initial solution or the execution,
19.46 + /// you have to call one of the \ref init() functions first, then
19.47 /// the \ref start() function.
19.48
19.49 ///@{
20.1 --- a/lemon/clp.cc Sun Oct 04 10:15:32 2009 +0200
20.2 +++ b/lemon/clp.cc Wed Dec 09 11:14:06 2009 +0100
20.3 @@ -78,6 +78,19 @@
20.4 return _prob->numberRows() - 1;
20.5 }
20.6
20.7 + int ClpLp::_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
20.21 void ClpLp::_eraseCol(int c) {
20.22 _col_names_ref.erase(_prob->getColumnName(c));
21.1 --- a/lemon/clp.h Sun Oct 04 10:15:32 2009 +0200
21.2 +++ b/lemon/clp.h Wed Dec 09 11:14:06 2009 +0100
21.3 @@ -75,6 +75,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/concepts/digraph.h Sun Oct 04 10:15:32 2009 +0200
22.2 +++ b/lemon/concepts/digraph.h Wed Dec 09 11:14:06 2009 +0100
22.3 @@ -35,46 +35,40 @@
22.4 ///
22.5 /// \brief Class describing the concept of directed graphs.
22.6 ///
22.7 - /// This class describes the \ref concept "concept" of the
22.8 - /// immutable directed digraphs.
22.9 + /// This class describes the common interface of all directed
22.10 + /// graphs (digraphs).
22.11 ///
22.12 - /// Note that actual digraph implementation like @ref ListDigraph or
22.13 - /// @ref SmartDigraph may have several additional functionality.
22.14 + /// Like all concept classes, it only provides an interface
22.15 + /// without any sensible implementation. So any general algorithm for
22.16 + /// directed graphs should compile with this class, but it will not
22.17 + /// run properly, of course.
22.18 + /// An actual digraph implementation like \ref ListDigraph or
22.19 + /// \ref SmartDigraph may have additional functionality.
22.20 ///
22.21 - /// \sa concept
22.22 + /// \sa Graph
22.23 class Digraph {
22.24 private:
22.25 - ///Digraphs are \e not copy constructible. Use DigraphCopy() instead.
22.26 + /// Diraphs are \e not copy constructible. Use DigraphCopy instead.
22.27 + Digraph(const Digraph &) {}
22.28 + /// \brief Assignment of a digraph to another one is \e not allowed.
22.29 + /// Use DigraphCopy instead.
22.30 + void operator=(const Digraph &) {}
22.31
22.32 - ///Digraphs are \e not copy constructible. Use DigraphCopy() instead.
22.33 - ///
22.34 - Digraph(const Digraph &) {};
22.35 - ///\brief Assignment of \ref Digraph "Digraph"s to another ones are
22.36 - ///\e not allowed. Use DigraphCopy() instead.
22.37 + public:
22.38 + /// Default constructor.
22.39 + Digraph() { }
22.40
22.41 - ///Assignment of \ref Digraph "Digraph"s to another ones are
22.42 - ///\e not allowed. Use DigraphCopy() instead.
22.43 -
22.44 - void operator=(const Digraph &) {}
22.45 - public:
22.46 - ///\e
22.47 -
22.48 - /// Defalult constructor.
22.49 -
22.50 - /// Defalult constructor.
22.51 - ///
22.52 - Digraph() { }
22.53 - /// Class for identifying a node of the digraph
22.54 + /// The node type of the digraph
22.55
22.56 /// This class identifies a node of the digraph. It also serves
22.57 /// as a base class of the node iterators,
22.58 - /// thus they will convert to this type.
22.59 + /// thus they convert to this type.
22.60 class Node {
22.61 public:
22.62 /// Default constructor
22.63
22.64 - /// @warning The default constructor sets the iterator
22.65 - /// to an undefined value.
22.66 + /// Default constructor.
22.67 + /// \warning It sets the object to an undefined value.
22.68 Node() { }
22.69 /// Copy constructor.
22.70
22.71 @@ -82,40 +76,39 @@
22.72 ///
22.73 Node(const Node&) { }
22.74
22.75 - /// Invalid constructor \& conversion.
22.76 + /// %Invalid constructor \& conversion.
22.77
22.78 - /// This constructor initializes the iterator to be invalid.
22.79 + /// Initializes the object to be invalid.
22.80 /// \sa Invalid for more details.
22.81 Node(Invalid) { }
22.82 /// Equality operator
22.83
22.84 + /// Equality operator.
22.85 + ///
22.86 /// Two iterators are equal if and only if they point to the
22.87 - /// same object or both are invalid.
22.88 + /// same object or both are \c INVALID.
22.89 bool operator==(Node) const { return true; }
22.90
22.91 /// Inequality operator
22.92
22.93 - /// \sa operator==(Node n)
22.94 - ///
22.95 + /// Inequality operator.
22.96 bool operator!=(Node) const { return true; }
22.97
22.98 /// Artificial ordering operator.
22.99
22.100 - /// To allow the use of digraph descriptors as key type in std::map or
22.101 - /// similar associative container we require this.
22.102 + /// Artificial ordering operator.
22.103 ///
22.104 - /// \note This operator only have to define some strict ordering of
22.105 - /// the items; this order has nothing to do with the iteration
22.106 - /// ordering of the items.
22.107 + /// \note This operator only has to define some strict ordering of
22.108 + /// the nodes; this order has nothing to do with the iteration
22.109 + /// ordering of the nodes.
22.110 bool operator<(Node) const { return false; }
22.111 -
22.112 };
22.113
22.114 - /// This iterator goes through each node.
22.115 + /// Iterator class for the nodes.
22.116
22.117 - /// This iterator goes through each node.
22.118 - /// Its usage is quite simple, for example you can count the number
22.119 - /// of nodes in digraph \c g of type \c Digraph like this:
22.120 + /// This iterator goes through each node of the digraph.
22.121 + /// Its usage is quite simple, for example, you can count the number
22.122 + /// of nodes in a digraph \c g of type \c %Digraph like this:
22.123 ///\code
22.124 /// int count=0;
22.125 /// for (Digraph::NodeIt n(g); n!=INVALID; ++n) ++count;
22.126 @@ -124,30 +117,28 @@
22.127 public:
22.128 /// Default constructor
22.129
22.130 - /// @warning The default constructor sets the iterator
22.131 - /// to an undefined value.
22.132 + /// Default constructor.
22.133 + /// \warning It sets the iterator to an undefined value.
22.134 NodeIt() { }
22.135 /// Copy constructor.
22.136
22.137 /// Copy constructor.
22.138 ///
22.139 NodeIt(const NodeIt& n) : Node(n) { }
22.140 - /// Invalid constructor \& conversion.
22.141 + /// %Invalid constructor \& conversion.
22.142
22.143 - /// Initialize the iterator to be invalid.
22.144 + /// Initializes the iterator to be invalid.
22.145 /// \sa Invalid for more details.
22.146 NodeIt(Invalid) { }
22.147 /// Sets the iterator to the first node.
22.148
22.149 - /// Sets the iterator to the first node of \c g.
22.150 + /// Sets the iterator to the first node of the given digraph.
22.151 ///
22.152 - NodeIt(const Digraph&) { }
22.153 - /// Node -> NodeIt conversion.
22.154 + explicit NodeIt(const Digraph&) { }
22.155 + /// Sets the iterator to the given node.
22.156
22.157 - /// Sets the iterator to the node of \c the digraph pointed by
22.158 - /// the trivial iterator.
22.159 - /// This feature necessitates that each time we
22.160 - /// iterate the arc-set, the iteration order is the same.
22.161 + /// Sets the iterator to the given node of the given digraph.
22.162 + ///
22.163 NodeIt(const Digraph&, const Node&) { }
22.164 /// Next node.
22.165
22.166 @@ -157,7 +148,7 @@
22.167 };
22.168
22.169
22.170 - /// Class for identifying an arc of the digraph
22.171 + /// The arc type of the digraph
22.172
22.173 /// This class identifies an arc of the digraph. It also serves
22.174 /// as a base class of the arc iterators,
22.175 @@ -166,207 +157,214 @@
22.176 public:
22.177 /// Default constructor
22.178
22.179 - /// @warning The default constructor sets the iterator
22.180 - /// to an undefined value.
22.181 + /// Default constructor.
22.182 + /// \warning It sets the object to an undefined value.
22.183 Arc() { }
22.184 /// Copy constructor.
22.185
22.186 /// Copy constructor.
22.187 ///
22.188 Arc(const Arc&) { }
22.189 - /// Initialize the iterator to be invalid.
22.190 + /// %Invalid constructor \& conversion.
22.191
22.192 - /// Initialize the iterator to be invalid.
22.193 - ///
22.194 + /// Initializes the object to be invalid.
22.195 + /// \sa Invalid for more details.
22.196 Arc(Invalid) { }
22.197 /// Equality operator
22.198
22.199 + /// Equality operator.
22.200 + ///
22.201 /// Two iterators are equal if and only if they point to the
22.202 - /// same object or both are invalid.
22.203 + /// same object or both are \c INVALID.
22.204 bool operator==(Arc) const { return true; }
22.205 /// Inequality operator
22.206
22.207 - /// \sa operator==(Arc n)
22.208 - ///
22.209 + /// Inequality operator.
22.210 bool operator!=(Arc) const { return true; }
22.211
22.212 /// Artificial ordering operator.
22.213
22.214 - /// To allow the use of digraph descriptors as key type in std::map or
22.215 - /// similar associative container we require this.
22.216 + /// Artificial ordering operator.
22.217 ///
22.218 - /// \note This operator only have to define some strict ordering of
22.219 - /// the items; this order has nothing to do with the iteration
22.220 - /// ordering of the items.
22.221 + /// \note This operator only has to define some strict ordering of
22.222 + /// the arcs; this order has nothing to do with the iteration
22.223 + /// ordering of the arcs.
22.224 bool operator<(Arc) const { return false; }
22.225 };
22.226
22.227 - /// This iterator goes trough the outgoing arcs of a node.
22.228 + /// Iterator class for the outgoing arcs of a node.
22.229
22.230 /// This iterator goes trough the \e outgoing arcs of a certain node
22.231 /// of a digraph.
22.232 - /// Its usage is quite simple, for example you can count the number
22.233 + /// Its usage is quite simple, for example, you can count the number
22.234 /// of outgoing arcs of a node \c n
22.235 - /// in digraph \c g of type \c Digraph as follows.
22.236 + /// in a digraph \c g of type \c %Digraph as follows.
22.237 ///\code
22.238 /// int count=0;
22.239 - /// for (Digraph::OutArcIt e(g, n); e!=INVALID; ++e) ++count;
22.240 + /// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count;
22.241 ///\endcode
22.242 -
22.243 class OutArcIt : public Arc {
22.244 public:
22.245 /// Default constructor
22.246
22.247 - /// @warning The default constructor sets the iterator
22.248 - /// to an undefined value.
22.249 + /// Default constructor.
22.250 + /// \warning It sets the iterator to an undefined value.
22.251 OutArcIt() { }
22.252 /// Copy constructor.
22.253
22.254 /// Copy constructor.
22.255 ///
22.256 OutArcIt(const OutArcIt& e) : Arc(e) { }
22.257 - /// Initialize the iterator to be invalid.
22.258 + /// %Invalid constructor \& conversion.
22.259
22.260 - /// Initialize the iterator to be invalid.
22.261 + /// Initializes the iterator to be invalid.
22.262 + /// \sa Invalid for more details.
22.263 + OutArcIt(Invalid) { }
22.264 + /// Sets the iterator to the first outgoing arc.
22.265 +
22.266 + /// Sets the iterator to the first outgoing arc of the given node.
22.267 ///
22.268 - OutArcIt(Invalid) { }
22.269 - /// This constructor sets the iterator to the first outgoing arc.
22.270 + OutArcIt(const Digraph&, const Node&) { }
22.271 + /// Sets the iterator to the given arc.
22.272
22.273 - /// This constructor sets the iterator to the first outgoing arc of
22.274 - /// the node.
22.275 - OutArcIt(const Digraph&, const Node&) { }
22.276 - /// Arc -> OutArcIt conversion
22.277 -
22.278 - /// Sets the iterator to the value of the trivial iterator.
22.279 - /// This feature necessitates that each time we
22.280 - /// iterate the arc-set, the iteration order is the same.
22.281 + /// Sets the iterator to the given arc of the given digraph.
22.282 + ///
22.283 OutArcIt(const Digraph&, const Arc&) { }
22.284 - ///Next outgoing arc
22.285 + /// Next outgoing arc
22.286
22.287 /// Assign the iterator to the next
22.288 /// outgoing arc of the corresponding node.
22.289 OutArcIt& operator++() { return *this; }
22.290 };
22.291
22.292 - /// This iterator goes trough the incoming arcs of a node.
22.293 + /// Iterator class for the incoming arcs of a node.
22.294
22.295 /// This iterator goes trough the \e incoming arcs of a certain node
22.296 /// of a digraph.
22.297 - /// Its usage is quite simple, for example you can count the number
22.298 - /// of outgoing arcs of a node \c n
22.299 - /// in digraph \c g of type \c Digraph as follows.
22.300 + /// Its usage is quite simple, for example, you can count the number
22.301 + /// of incoming arcs of a node \c n
22.302 + /// in a digraph \c g of type \c %Digraph as follows.
22.303 ///\code
22.304 /// int count=0;
22.305 - /// for(Digraph::InArcIt e(g, n); e!=INVALID; ++e) ++count;
22.306 + /// for(Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count;
22.307 ///\endcode
22.308 -
22.309 class InArcIt : public Arc {
22.310 public:
22.311 /// Default constructor
22.312
22.313 - /// @warning The default constructor sets the iterator
22.314 - /// to an undefined value.
22.315 + /// Default constructor.
22.316 + /// \warning It sets the iterator to an undefined value.
22.317 InArcIt() { }
22.318 /// Copy constructor.
22.319
22.320 /// Copy constructor.
22.321 ///
22.322 InArcIt(const InArcIt& e) : Arc(e) { }
22.323 - /// Initialize the iterator to be invalid.
22.324 + /// %Invalid constructor \& conversion.
22.325
22.326 - /// Initialize the iterator to be invalid.
22.327 + /// Initializes the iterator to be invalid.
22.328 + /// \sa Invalid for more details.
22.329 + InArcIt(Invalid) { }
22.330 + /// Sets the iterator to the first incoming arc.
22.331 +
22.332 + /// Sets the iterator to the first incoming arc of the given node.
22.333 ///
22.334 - InArcIt(Invalid) { }
22.335 - /// This constructor sets the iterator to first incoming arc.
22.336 + InArcIt(const Digraph&, const Node&) { }
22.337 + /// Sets the iterator to the given arc.
22.338
22.339 - /// This constructor set the iterator to the first incoming arc of
22.340 - /// the node.
22.341 - InArcIt(const Digraph&, const Node&) { }
22.342 - /// Arc -> InArcIt conversion
22.343 -
22.344 - /// Sets the iterator to the value of the trivial iterator \c e.
22.345 - /// This feature necessitates that each time we
22.346 - /// iterate the arc-set, the iteration order is the same.
22.347 + /// Sets the iterator to the given arc of the given digraph.
22.348 + ///
22.349 InArcIt(const Digraph&, const Arc&) { }
22.350 /// Next incoming arc
22.351
22.352 - /// Assign the iterator to the next inarc of the corresponding node.
22.353 - ///
22.354 + /// Assign the iterator to the next
22.355 + /// incoming arc of the corresponding node.
22.356 InArcIt& operator++() { return *this; }
22.357 };
22.358 - /// This iterator goes through each arc.
22.359
22.360 - /// This iterator goes through each arc of a digraph.
22.361 - /// Its usage is quite simple, for example you can count the number
22.362 - /// of arcs in a digraph \c g of type \c Digraph as follows:
22.363 + /// Iterator class for the arcs.
22.364 +
22.365 + /// This iterator goes through each arc of the digraph.
22.366 + /// Its usage is quite simple, for example, you can count the number
22.367 + /// of arcs in a digraph \c g of type \c %Digraph as follows:
22.368 ///\code
22.369 /// int count=0;
22.370 - /// for(Digraph::ArcIt e(g); e!=INVALID; ++e) ++count;
22.371 + /// for(Digraph::ArcIt a(g); a!=INVALID; ++a) ++count;
22.372 ///\endcode
22.373 class ArcIt : public Arc {
22.374 public:
22.375 /// Default constructor
22.376
22.377 - /// @warning The default constructor sets the iterator
22.378 - /// to an undefined value.
22.379 + /// Default constructor.
22.380 + /// \warning It sets the iterator to an undefined value.
22.381 ArcIt() { }
22.382 /// Copy constructor.
22.383
22.384 /// Copy constructor.
22.385 ///
22.386 ArcIt(const ArcIt& e) : Arc(e) { }
22.387 - /// Initialize the iterator to be invalid.
22.388 + /// %Invalid constructor \& conversion.
22.389
22.390 - /// Initialize the iterator to be invalid.
22.391 + /// Initializes the iterator to be invalid.
22.392 + /// \sa Invalid for more details.
22.393 + ArcIt(Invalid) { }
22.394 + /// Sets the iterator to the first arc.
22.395 +
22.396 + /// Sets the iterator to the first arc of the given digraph.
22.397 ///
22.398 - ArcIt(Invalid) { }
22.399 - /// This constructor sets the iterator to the first arc.
22.400 + explicit ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); }
22.401 + /// Sets the iterator to the given arc.
22.402
22.403 - /// This constructor sets the iterator to the first arc of \c g.
22.404 - ///@param g the digraph
22.405 - ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); }
22.406 - /// Arc -> ArcIt conversion
22.407 -
22.408 - /// Sets the iterator to the value of the trivial iterator \c e.
22.409 - /// This feature necessitates that each time we
22.410 - /// iterate the arc-set, the iteration order is the same.
22.411 + /// Sets the iterator to the given arc of the given digraph.
22.412 + ///
22.413 ArcIt(const Digraph&, const Arc&) { }
22.414 - ///Next arc
22.415 + /// Next arc
22.416
22.417 /// Assign the iterator to the next arc.
22.418 + ///
22.419 ArcIt& operator++() { return *this; }
22.420 };
22.421 - ///Gives back the target node of an arc.
22.422
22.423 - ///Gives back the target node of an arc.
22.424 + /// \brief The source node of the arc.
22.425 ///
22.426 - Node target(Arc) const { return INVALID; }
22.427 - ///Gives back the source node of an arc.
22.428 -
22.429 - ///Gives back the source node of an arc.
22.430 - ///
22.431 + /// Returns the source node of the given arc.
22.432 Node source(Arc) const { return INVALID; }
22.433
22.434 - /// \brief Returns the ID of the node.
22.435 + /// \brief The target node of the arc.
22.436 + ///
22.437 + /// Returns the target node of the given arc.
22.438 + Node target(Arc) const { return INVALID; }
22.439 +
22.440 + /// \brief The ID of the node.
22.441 + ///
22.442 + /// Returns the ID of the given node.
22.443 int id(Node) const { return -1; }
22.444
22.445 - /// \brief Returns the ID of the arc.
22.446 + /// \brief The ID of the arc.
22.447 + ///
22.448 + /// Returns the ID of the given arc.
22.449 int id(Arc) const { return -1; }
22.450
22.451 - /// \brief Returns the node with the given ID.
22.452 + /// \brief The node with the given ID.
22.453 ///
22.454 - /// \pre The argument should be a valid node ID in the graph.
22.455 + /// Returns the node with the given ID.
22.456 + /// \pre The argument should be a valid node ID in the digraph.
22.457 Node nodeFromId(int) const { return INVALID; }
22.458
22.459 - /// \brief Returns the arc with the given ID.
22.460 + /// \brief The arc with the given ID.
22.461 ///
22.462 - /// \pre The argument should be a valid arc ID in the graph.
22.463 + /// Returns the arc with the given ID.
22.464 + /// \pre The argument should be a valid arc ID in the digraph.
22.465 Arc arcFromId(int) const { return INVALID; }
22.466
22.467 - /// \brief Returns an upper bound on the node IDs.
22.468 + /// \brief An upper bound on the node IDs.
22.469 + ///
22.470 + /// Returns an upper bound on the node IDs.
22.471 int maxNodeId() const { return -1; }
22.472
22.473 - /// \brief Returns an upper bound on the arc IDs.
22.474 + /// \brief An upper bound on the arc IDs.
22.475 + ///
22.476 + /// Returns an upper bound on the arc IDs.
22.477 int maxArcId() const { return -1; }
22.478
22.479 void first(Node&) const {}
22.480 @@ -392,45 +390,46 @@
22.481 // Dummy parameter.
22.482 int maxId(Arc) const { return -1; }
22.483
22.484 + /// \brief The opposite node on the arc.
22.485 + ///
22.486 + /// Returns the opposite node on the given arc.
22.487 + Node oppositeNode(Node, Arc) const { return INVALID; }
22.488 +
22.489 /// \brief The base node of the iterator.
22.490 ///
22.491 - /// Gives back the base node of the iterator.
22.492 - /// It is always the target of the pointed arc.
22.493 - Node baseNode(const InArcIt&) const { return INVALID; }
22.494 + /// Returns the base node of the given outgoing arc iterator
22.495 + /// (i.e. the source node of the corresponding arc).
22.496 + Node baseNode(OutArcIt) const { return INVALID; }
22.497
22.498 /// \brief The running node of the iterator.
22.499 ///
22.500 - /// Gives back the running node of the iterator.
22.501 - /// It is always the source of the pointed arc.
22.502 - Node runningNode(const InArcIt&) const { return INVALID; }
22.503 + /// Returns the running node of the given outgoing arc iterator
22.504 + /// (i.e. the target node of the corresponding arc).
22.505 + Node runningNode(OutArcIt) const { return INVALID; }
22.506
22.507 /// \brief The base node of the iterator.
22.508 ///
22.509 - /// Gives back the base node of the iterator.
22.510 - /// It is always the source of the pointed arc.
22.511 - Node baseNode(const OutArcIt&) const { return INVALID; }
22.512 + /// Returns the base node of the given incomming arc iterator
22.513 + /// (i.e. the target node of the corresponding arc).
22.514 + Node baseNode(InArcIt) const { return INVALID; }
22.515
22.516 /// \brief The running node of the iterator.
22.517 ///
22.518 - /// Gives back the running node of the iterator.
22.519 - /// It is always the target of the pointed arc.
22.520 - Node runningNode(const OutArcIt&) const { return INVALID; }
22.521 + /// Returns the running node of the given incomming arc iterator
22.522 + /// (i.e. the source node of the corresponding arc).
22.523 + Node runningNode(InArcIt) const { return INVALID; }
22.524
22.525 - /// \brief The opposite node on the given arc.
22.526 + /// \brief Standard graph map type for the nodes.
22.527 ///
22.528 - /// Gives back the opposite node on the given arc.
22.529 - Node oppositeNode(const Node&, const Arc&) const { return INVALID; }
22.530 -
22.531 - /// \brief Reference map of the nodes to type \c T.
22.532 - ///
22.533 - /// Reference map of the nodes to type \c T.
22.534 + /// Standard graph map type for the nodes.
22.535 + /// It conforms to the ReferenceMap concept.
22.536 template<class T>
22.537 class NodeMap : public ReferenceMap<Node, T, T&, const T&> {
22.538 public:
22.539
22.540 - ///\e
22.541 - NodeMap(const Digraph&) { }
22.542 - ///\e
22.543 + /// Constructor
22.544 + explicit NodeMap(const Digraph&) { }
22.545 + /// Constructor with given initial value
22.546 NodeMap(const Digraph&, T) { }
22.547
22.548 private:
22.549 @@ -445,17 +444,19 @@
22.550 }
22.551 };
22.552
22.553 - /// \brief Reference map of the arcs to type \c T.
22.554 + /// \brief Standard graph map type for the arcs.
22.555 ///
22.556 - /// Reference map of the arcs to type \c T.
22.557 + /// Standard graph map type for the arcs.
22.558 + /// It conforms to the ReferenceMap concept.
22.559 template<class T>
22.560 class ArcMap : public ReferenceMap<Arc, T, T&, const T&> {
22.561 public:
22.562
22.563 - ///\e
22.564 - ArcMap(const Digraph&) { }
22.565 - ///\e
22.566 + /// Constructor
22.567 + explicit ArcMap(const Digraph&) { }
22.568 + /// Constructor with given initial value
22.569 ArcMap(const Digraph&, T) { }
22.570 +
22.571 private:
22.572 ///Copy constructor
22.573 ArcMap(const ArcMap& em) :
23.1 --- a/lemon/concepts/graph.h Sun Oct 04 10:15:32 2009 +0200
23.2 +++ b/lemon/concepts/graph.h Wed Dec 09 11:14:06 2009 +0100
23.3 @@ -18,12 +18,14 @@
23.4
23.5 ///\ingroup graph_concepts
23.6 ///\file
23.7 -///\brief The concept of Undirected Graphs.
23.8 +///\brief The concept of undirected graphs.
23.9
23.10 #ifndef LEMON_CONCEPTS_GRAPH_H
23.11 #define LEMON_CONCEPTS_GRAPH_H
23.12
23.13 #include <lemon/concepts/graph_components.h>
23.14 +#include <lemon/concepts/maps.h>
23.15 +#include <lemon/concept_check.h>
23.16 #include <lemon/core.h>
23.17
23.18 namespace lemon {
23.19 @@ -31,63 +33,74 @@
23.20
23.21 /// \ingroup graph_concepts
23.22 ///
23.23 - /// \brief Class describing the concept of Undirected Graphs.
23.24 + /// \brief Class describing the concept of undirected graphs.
23.25 ///
23.26 - /// This class describes the common interface of all Undirected
23.27 - /// Graphs.
23.28 + /// This class describes the common interface of all undirected
23.29 + /// graphs.
23.30 ///
23.31 - /// As all concept describing classes it provides only interface
23.32 - /// without any sensible implementation. So any algorithm for
23.33 - /// undirected graph should compile with this class, but it will not
23.34 + /// Like all concept classes, it only provides an interface
23.35 + /// without any sensible implementation. So any general algorithm for
23.36 + /// undirected graphs should compile with this class, but it will not
23.37 /// run properly, of course.
23.38 + /// An actual graph implementation like \ref ListGraph or
23.39 + /// \ref SmartGraph may have additional functionality.
23.40 ///
23.41 - /// The LEMON undirected graphs also fulfill the concept of
23.42 - /// directed graphs (\ref lemon::concepts::Digraph "Digraph
23.43 - /// Concept"). Each edges can be seen as two opposite
23.44 - /// directed arc and consequently the undirected graph can be
23.45 - /// seen as the direceted graph of these directed arcs. The
23.46 - /// Graph has the Edge inner class for the edges and
23.47 - /// the Arc type for the directed arcs. The Arc type is
23.48 - /// convertible to Edge or inherited from it so from a directed
23.49 - /// arc we can get the represented edge.
23.50 + /// The undirected graphs also fulfill the concept of \ref Digraph
23.51 + /// "directed graphs", since each edge can also be regarded as two
23.52 + /// oppositely directed arcs.
23.53 + /// Undirected graphs provide an Edge type for the undirected edges and
23.54 + /// an Arc type for the directed arcs. The Arc type is convertible to
23.55 + /// Edge or inherited from it, i.e. the corresponding edge can be
23.56 + /// obtained from an arc.
23.57 + /// EdgeIt and EdgeMap classes can be used for the edges, while ArcIt
23.58 + /// and ArcMap classes can be used for the arcs (just like in digraphs).
23.59 + /// Both InArcIt and OutArcIt iterates on the same edges but with
23.60 + /// opposite direction. IncEdgeIt also iterates on the same edges
23.61 + /// as OutArcIt and InArcIt, but it is not convertible to Arc,
23.62 + /// only to Edge.
23.63 ///
23.64 - /// In the sense of the LEMON each edge has a default
23.65 - /// direction (it should be in every computer implementation,
23.66 - /// because the order of edge's nodes defines an
23.67 - /// orientation). With the default orientation we can define that
23.68 - /// the directed arc is forward or backward directed. With the \c
23.69 - /// direction() and \c direct() function we can get the direction
23.70 - /// of the directed arc and we can direct an edge.
23.71 + /// In LEMON, each undirected edge has an inherent orientation.
23.72 + /// Thus it can defined if an arc is forward or backward oriented in
23.73 + /// an undirected graph with respect to this default oriantation of
23.74 + /// the represented edge.
23.75 + /// With the direction() and direct() functions the direction
23.76 + /// of an arc can be obtained and set, respectively.
23.77 ///
23.78 - /// The EdgeIt is an iterator for the edges. We can use
23.79 - /// the EdgeMap to map values for the edges. The InArcIt and
23.80 - /// OutArcIt iterates on the same edges but with opposite
23.81 - /// direction. The IncEdgeIt iterates also on the same edges
23.82 - /// as the OutArcIt and InArcIt but it is not convertible to Arc just
23.83 - /// to Edge.
23.84 + /// Only nodes and edges can be added to or removed from an undirected
23.85 + /// graph and the corresponding arcs are added or removed automatically.
23.86 + ///
23.87 + /// \sa Digraph
23.88 class Graph {
23.89 + private:
23.90 + /// Graphs are \e not copy constructible. Use DigraphCopy instead.
23.91 + Graph(const Graph&) {}
23.92 + /// \brief Assignment of a graph to another one is \e not allowed.
23.93 + /// Use DigraphCopy instead.
23.94 + void operator=(const Graph&) {}
23.95 +
23.96 public:
23.97 - /// \brief The undirected graph should be tagged by the
23.98 - /// UndirectedTag.
23.99 + /// Default constructor.
23.100 + Graph() {}
23.101 +
23.102 + /// \brief Undirected graphs should be tagged with \c UndirectedTag.
23.103 ///
23.104 - /// The undirected graph should be tagged by the UndirectedTag. This
23.105 - /// tag helps the enable_if technics to make compile time
23.106 + /// Undirected graphs should be tagged with \c UndirectedTag.
23.107 + ///
23.108 + /// This tag helps the \c enable_if technics to make compile time
23.109 /// specializations for undirected graphs.
23.110 typedef True UndirectedTag;
23.111
23.112 - /// \brief The base type of node iterators,
23.113 - /// or in other words, the trivial node iterator.
23.114 - ///
23.115 - /// This is the base type of each node iterator,
23.116 - /// thus each kind of node iterator converts to this.
23.117 - /// More precisely each kind of node iterator should be inherited
23.118 - /// from the trivial node iterator.
23.119 + /// The node type of the graph
23.120 +
23.121 + /// This class identifies a node of the graph. It also serves
23.122 + /// as a base class of the node iterators,
23.123 + /// thus they convert to this type.
23.124 class Node {
23.125 public:
23.126 /// Default constructor
23.127
23.128 - /// @warning The default constructor sets the iterator
23.129 - /// to an undefined value.
23.130 + /// Default constructor.
23.131 + /// \warning It sets the object to an undefined value.
23.132 Node() { }
23.133 /// Copy constructor.
23.134
23.135 @@ -95,40 +108,40 @@
23.136 ///
23.137 Node(const Node&) { }
23.138
23.139 - /// Invalid constructor \& conversion.
23.140 + /// %Invalid constructor \& conversion.
23.141
23.142 - /// This constructor initializes the iterator to be invalid.
23.143 + /// Initializes the object to be invalid.
23.144 /// \sa Invalid for more details.
23.145 Node(Invalid) { }
23.146 /// Equality operator
23.147
23.148 + /// Equality operator.
23.149 + ///
23.150 /// Two iterators are equal if and only if they point to the
23.151 - /// same object or both are invalid.
23.152 + /// same object or both are \c INVALID.
23.153 bool operator==(Node) const { return true; }
23.154
23.155 /// Inequality operator
23.156
23.157 - /// \sa operator==(Node n)
23.158 - ///
23.159 + /// Inequality operator.
23.160 bool operator!=(Node) const { return true; }
23.161
23.162 /// Artificial ordering operator.
23.163
23.164 - /// To allow the use of graph descriptors as key type in std::map or
23.165 - /// similar associative container we require this.
23.166 + /// Artificial ordering operator.
23.167 ///
23.168 - /// \note This operator only have to define some strict ordering of
23.169 + /// \note This operator only has to define some strict ordering of
23.170 /// the items; this order has nothing to do with the iteration
23.171 /// ordering of the items.
23.172 bool operator<(Node) const { return false; }
23.173
23.174 };
23.175
23.176 - /// This iterator goes through each node.
23.177 + /// Iterator class for the nodes.
23.178
23.179 - /// This iterator goes through each node.
23.180 - /// Its usage is quite simple, for example you can count the number
23.181 - /// of nodes in graph \c g of type \c Graph like this:
23.182 + /// This iterator goes through each node of the graph.
23.183 + /// Its usage is quite simple, for example, you can count the number
23.184 + /// of nodes in a graph \c g of type \c %Graph like this:
23.185 ///\code
23.186 /// int count=0;
23.187 /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
23.188 @@ -137,30 +150,28 @@
23.189 public:
23.190 /// Default constructor
23.191
23.192 - /// @warning The default constructor sets the iterator
23.193 - /// to an undefined value.
23.194 + /// Default constructor.
23.195 + /// \warning It sets the iterator to an undefined value.
23.196 NodeIt() { }
23.197 /// Copy constructor.
23.198
23.199 /// Copy constructor.
23.200 ///
23.201 NodeIt(const NodeIt& n) : Node(n) { }
23.202 - /// Invalid constructor \& conversion.
23.203 + /// %Invalid constructor \& conversion.
23.204
23.205 - /// Initialize the iterator to be invalid.
23.206 + /// Initializes the iterator to be invalid.
23.207 /// \sa Invalid for more details.
23.208 NodeIt(Invalid) { }
23.209 /// Sets the iterator to the first node.
23.210
23.211 - /// Sets the iterator to the first node of \c g.
23.212 + /// Sets the iterator to the first node of the given digraph.
23.213 ///
23.214 - NodeIt(const Graph&) { }
23.215 - /// Node -> NodeIt conversion.
23.216 + explicit NodeIt(const Graph&) { }
23.217 + /// Sets the iterator to the given node.
23.218
23.219 - /// Sets the iterator to the node of \c the graph pointed by
23.220 - /// the trivial iterator.
23.221 - /// This feature necessitates that each time we
23.222 - /// iterate the arc-set, the iteration order is the same.
23.223 + /// Sets the iterator to the given node of the given digraph.
23.224 + ///
23.225 NodeIt(const Graph&, const Node&) { }
23.226 /// Next node.
23.227
23.228 @@ -170,54 +181,55 @@
23.229 };
23.230
23.231
23.232 - /// The base type of the edge iterators.
23.233 + /// The edge type of the graph
23.234
23.235 - /// The base type of the edge iterators.
23.236 - ///
23.237 + /// This class identifies an edge of the graph. It also serves
23.238 + /// as a base class of the edge iterators,
23.239 + /// thus they will convert to this type.
23.240 class Edge {
23.241 public:
23.242 /// Default constructor
23.243
23.244 - /// @warning The default constructor sets the iterator
23.245 - /// to an undefined value.
23.246 + /// Default constructor.
23.247 + /// \warning It sets the object to an undefined value.
23.248 Edge() { }
23.249 /// Copy constructor.
23.250
23.251 /// Copy constructor.
23.252 ///
23.253 Edge(const Edge&) { }
23.254 - /// Initialize the iterator to be invalid.
23.255 + /// %Invalid constructor \& conversion.
23.256
23.257 - /// Initialize the iterator to be invalid.
23.258 - ///
23.259 + /// Initializes the object to be invalid.
23.260 + /// \sa Invalid for more details.
23.261 Edge(Invalid) { }
23.262 /// Equality operator
23.263
23.264 + /// Equality operator.
23.265 + ///
23.266 /// Two iterators are equal if and only if they point to the
23.267 - /// same object or both are invalid.
23.268 + /// same object or both are \c INVALID.
23.269 bool operator==(Edge) const { return true; }
23.270 /// Inequality operator
23.271
23.272 - /// \sa operator==(Edge n)
23.273 - ///
23.274 + /// Inequality operator.
23.275 bool operator!=(Edge) const { return true; }
23.276
23.277 /// Artificial ordering operator.
23.278
23.279 - /// To allow the use of graph descriptors as key type in std::map or
23.280 - /// similar associative container we require this.
23.281 + /// Artificial ordering operator.
23.282 ///
23.283 - /// \note This operator only have to define some strict ordering of
23.284 - /// the items; this order has nothing to do with the iteration
23.285 - /// ordering of the items.
23.286 + /// \note This operator only has to define some strict ordering of
23.287 + /// the edges; this order has nothing to do with the iteration
23.288 + /// ordering of the edges.
23.289 bool operator<(Edge) const { return false; }
23.290 };
23.291
23.292 - /// This iterator goes through each edge.
23.293 + /// Iterator class for the edges.
23.294
23.295 - /// This iterator goes through each edge of a graph.
23.296 - /// Its usage is quite simple, for example you can count the number
23.297 - /// of edges in a graph \c g of type \c Graph as follows:
23.298 + /// This iterator goes through each edge of the graph.
23.299 + /// Its usage is quite simple, for example, you can count the number
23.300 + /// of edges in a graph \c g of type \c %Graph as follows:
23.301 ///\code
23.302 /// int count=0;
23.303 /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
23.304 @@ -226,290 +238,285 @@
23.305 public:
23.306 /// Default constructor
23.307
23.308 - /// @warning The default constructor sets the iterator
23.309 - /// to an undefined value.
23.310 + /// Default constructor.
23.311 + /// \warning It sets the iterator to an undefined value.
23.312 EdgeIt() { }
23.313 /// Copy constructor.
23.314
23.315 /// Copy constructor.
23.316 ///
23.317 EdgeIt(const EdgeIt& e) : Edge(e) { }
23.318 - /// Initialize the iterator to be invalid.
23.319 + /// %Invalid constructor \& conversion.
23.320
23.321 - /// Initialize the iterator to be invalid.
23.322 + /// Initializes the iterator to be invalid.
23.323 + /// \sa Invalid for more details.
23.324 + EdgeIt(Invalid) { }
23.325 + /// Sets the iterator to the first edge.
23.326 +
23.327 + /// Sets the iterator to the first edge of the given graph.
23.328 ///
23.329 - EdgeIt(Invalid) { }
23.330 - /// This constructor sets the iterator to the first edge.
23.331 + explicit EdgeIt(const Graph&) { }
23.332 + /// Sets the iterator to the given edge.
23.333
23.334 - /// This constructor sets the iterator to the first edge.
23.335 - EdgeIt(const Graph&) { }
23.336 - /// Edge -> EdgeIt conversion
23.337 -
23.338 - /// Sets the iterator to the value of the trivial iterator.
23.339 - /// This feature necessitates that each time we
23.340 - /// iterate the edge-set, the iteration order is the
23.341 - /// same.
23.342 + /// Sets the iterator to the given edge of the given graph.
23.343 + ///
23.344 EdgeIt(const Graph&, const Edge&) { }
23.345 /// Next edge
23.346
23.347 /// Assign the iterator to the next edge.
23.348 + ///
23.349 EdgeIt& operator++() { return *this; }
23.350 };
23.351
23.352 - /// \brief This iterator goes trough the incident undirected
23.353 - /// arcs of a node.
23.354 - ///
23.355 - /// This iterator goes trough the incident edges
23.356 - /// of a certain node of a graph. You should assume that the
23.357 - /// loop arcs will be iterated twice.
23.358 - ///
23.359 - /// Its usage is quite simple, for example you can compute the
23.360 - /// degree (i.e. count the number of incident arcs of a node \c n
23.361 - /// in graph \c g of type \c Graph as follows.
23.362 + /// Iterator class for the incident edges of a node.
23.363 +
23.364 + /// This iterator goes trough the incident undirected edges
23.365 + /// of a certain node of a graph.
23.366 + /// Its usage is quite simple, for example, you can compute the
23.367 + /// degree (i.e. the number of incident edges) of a node \c n
23.368 + /// in a graph \c g of type \c %Graph as follows.
23.369 ///
23.370 ///\code
23.371 /// int count=0;
23.372 /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count;
23.373 ///\endcode
23.374 + ///
23.375 + /// \warning Loop edges will be iterated twice.
23.376 class IncEdgeIt : public Edge {
23.377 public:
23.378 /// Default constructor
23.379
23.380 - /// @warning The default constructor sets the iterator
23.381 - /// to an undefined value.
23.382 + /// Default constructor.
23.383 + /// \warning It sets the iterator to an undefined value.
23.384 IncEdgeIt() { }
23.385 /// Copy constructor.
23.386
23.387 /// Copy constructor.
23.388 ///
23.389 IncEdgeIt(const IncEdgeIt& e) : Edge(e) { }
23.390 - /// Initialize the iterator to be invalid.
23.391 + /// %Invalid constructor \& conversion.
23.392
23.393 - /// Initialize the iterator to be invalid.
23.394 + /// Initializes the iterator to be invalid.
23.395 + /// \sa Invalid for more details.
23.396 + IncEdgeIt(Invalid) { }
23.397 + /// Sets the iterator to the first incident edge.
23.398 +
23.399 + /// Sets the iterator to the first incident edge of the given node.
23.400 ///
23.401 - IncEdgeIt(Invalid) { }
23.402 - /// This constructor sets the iterator to first incident arc.
23.403 + IncEdgeIt(const Graph&, const Node&) { }
23.404 + /// Sets the iterator to the given edge.
23.405
23.406 - /// This constructor set the iterator to the first incident arc of
23.407 - /// the node.
23.408 - IncEdgeIt(const Graph&, const Node&) { }
23.409 - /// Edge -> IncEdgeIt conversion
23.410 + /// Sets the iterator to the given edge of the given graph.
23.411 + ///
23.412 + IncEdgeIt(const Graph&, const Edge&) { }
23.413 + /// Next incident edge
23.414
23.415 - /// Sets the iterator to the value of the trivial iterator \c e.
23.416 - /// This feature necessitates that each time we
23.417 - /// iterate the arc-set, the iteration order is the same.
23.418 - IncEdgeIt(const Graph&, const Edge&) { }
23.419 - /// Next incident arc
23.420 -
23.421 - /// Assign the iterator to the next incident arc
23.422 + /// Assign the iterator to the next incident edge
23.423 /// of the corresponding node.
23.424 IncEdgeIt& operator++() { return *this; }
23.425 };
23.426
23.427 - /// The directed arc type.
23.428 + /// The arc type of the graph
23.429
23.430 - /// The directed arc type. It can be converted to the
23.431 - /// edge or it should be inherited from the undirected
23.432 - /// edge.
23.433 + /// This class identifies a directed arc of the graph. It also serves
23.434 + /// as a base class of the arc iterators,
23.435 + /// thus they will convert to this type.
23.436 class Arc {
23.437 public:
23.438 /// Default constructor
23.439
23.440 - /// @warning The default constructor sets the iterator
23.441 - /// to an undefined value.
23.442 + /// Default constructor.
23.443 + /// \warning It sets the object to an undefined value.
23.444 Arc() { }
23.445 /// Copy constructor.
23.446
23.447 /// Copy constructor.
23.448 ///
23.449 Arc(const Arc&) { }
23.450 - /// Initialize the iterator to be invalid.
23.451 + /// %Invalid constructor \& conversion.
23.452
23.453 - /// Initialize the iterator to be invalid.
23.454 - ///
23.455 + /// Initializes the object to be invalid.
23.456 + /// \sa Invalid for more details.
23.457 Arc(Invalid) { }
23.458 /// Equality operator
23.459
23.460 + /// Equality operator.
23.461 + ///
23.462 /// Two iterators are equal if and only if they point to the
23.463 - /// same object or both are invalid.
23.464 + /// same object or both are \c INVALID.
23.465 bool operator==(Arc) const { return true; }
23.466 /// Inequality operator
23.467
23.468 - /// \sa operator==(Arc n)
23.469 - ///
23.470 + /// Inequality operator.
23.471 bool operator!=(Arc) const { return true; }
23.472
23.473 /// Artificial ordering operator.
23.474
23.475 - /// To allow the use of graph descriptors as key type in std::map or
23.476 - /// similar associative container we require this.
23.477 + /// Artificial ordering operator.
23.478 ///
23.479 - /// \note This operator only have to define some strict ordering of
23.480 - /// the items; this order has nothing to do with the iteration
23.481 - /// ordering of the items.
23.482 + /// \note This operator only has to define some strict ordering of
23.483 + /// the arcs; this order has nothing to do with the iteration
23.484 + /// ordering of the arcs.
23.485 bool operator<(Arc) const { return false; }
23.486
23.487 - /// Converison to Edge
23.488 + /// Converison to \c Edge
23.489 +
23.490 + /// Converison to \c Edge.
23.491 + ///
23.492 operator Edge() const { return Edge(); }
23.493 };
23.494 - /// This iterator goes through each directed arc.
23.495
23.496 - /// This iterator goes through each arc of a graph.
23.497 - /// Its usage is quite simple, for example you can count the number
23.498 - /// of arcs in a graph \c g of type \c Graph as follows:
23.499 + /// Iterator class for the arcs.
23.500 +
23.501 + /// This iterator goes through each directed arc of the graph.
23.502 + /// Its usage is quite simple, for example, you can count the number
23.503 + /// of arcs in a graph \c g of type \c %Graph as follows:
23.504 ///\code
23.505 /// int count=0;
23.506 - /// for(Graph::ArcIt e(g); e!=INVALID; ++e) ++count;
23.507 + /// for(Graph::ArcIt a(g); a!=INVALID; ++a) ++count;
23.508 ///\endcode
23.509 class ArcIt : public Arc {
23.510 public:
23.511 /// Default constructor
23.512
23.513 - /// @warning The default constructor sets the iterator
23.514 - /// to an undefined value.
23.515 + /// Default constructor.
23.516 + /// \warning It sets the iterator to an undefined value.
23.517 ArcIt() { }
23.518 /// Copy constructor.
23.519
23.520 /// Copy constructor.
23.521 ///
23.522 ArcIt(const ArcIt& e) : Arc(e) { }
23.523 - /// Initialize the iterator to be invalid.
23.524 + /// %Invalid constructor \& conversion.
23.525
23.526 - /// Initialize the iterator to be invalid.
23.527 + /// Initializes the iterator to be invalid.
23.528 + /// \sa Invalid for more details.
23.529 + ArcIt(Invalid) { }
23.530 + /// Sets the iterator to the first arc.
23.531 +
23.532 + /// Sets the iterator to the first arc of the given graph.
23.533 ///
23.534 - ArcIt(Invalid) { }
23.535 - /// This constructor sets the iterator to the first arc.
23.536 + explicit ArcIt(const Graph &g) { ignore_unused_variable_warning(g); }
23.537 + /// Sets the iterator to the given arc.
23.538
23.539 - /// This constructor sets the iterator to the first arc of \c g.
23.540 - ///@param g the graph
23.541 - ArcIt(const Graph &g) { ignore_unused_variable_warning(g); }
23.542 - /// Arc -> ArcIt conversion
23.543 -
23.544 - /// Sets the iterator to the value of the trivial iterator \c e.
23.545 - /// This feature necessitates that each time we
23.546 - /// iterate the arc-set, the iteration order is the same.
23.547 + /// Sets the iterator to the given arc of the given graph.
23.548 + ///
23.549 ArcIt(const Graph&, const Arc&) { }
23.550 - ///Next arc
23.551 + /// Next arc
23.552
23.553 /// Assign the iterator to the next arc.
23.554 + ///
23.555 ArcIt& operator++() { return *this; }
23.556 };
23.557
23.558 - /// This iterator goes trough the outgoing directed arcs of a node.
23.559 + /// Iterator class for the outgoing arcs of a node.
23.560
23.561 - /// This iterator goes trough the \e outgoing arcs of a certain node
23.562 - /// of a graph.
23.563 - /// Its usage is quite simple, for example you can count the number
23.564 + /// This iterator goes trough the \e outgoing directed arcs of a
23.565 + /// certain node of a graph.
23.566 + /// Its usage is quite simple, for example, you can count the number
23.567 /// of outgoing arcs of a node \c n
23.568 - /// in graph \c g of type \c Graph as follows.
23.569 + /// in a graph \c g of type \c %Graph as follows.
23.570 ///\code
23.571 /// int count=0;
23.572 - /// for (Graph::OutArcIt e(g, n); e!=INVALID; ++e) ++count;
23.573 + /// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count;
23.574 ///\endcode
23.575 -
23.576 class OutArcIt : public Arc {
23.577 public:
23.578 /// Default constructor
23.579
23.580 - /// @warning The default constructor sets the iterator
23.581 - /// to an undefined value.
23.582 + /// Default constructor.
23.583 + /// \warning It sets the iterator to an undefined value.
23.584 OutArcIt() { }
23.585 /// Copy constructor.
23.586
23.587 /// Copy constructor.
23.588 ///
23.589 OutArcIt(const OutArcIt& e) : Arc(e) { }
23.590 - /// Initialize the iterator to be invalid.
23.591 + /// %Invalid constructor \& conversion.
23.592
23.593 - /// Initialize the iterator to be invalid.
23.594 + /// Initializes the iterator to be invalid.
23.595 + /// \sa Invalid for more details.
23.596 + OutArcIt(Invalid) { }
23.597 + /// Sets the iterator to the first outgoing arc.
23.598 +
23.599 + /// Sets the iterator to the first outgoing arc of the given node.
23.600 ///
23.601 - OutArcIt(Invalid) { }
23.602 - /// This constructor sets the iterator to the first outgoing arc.
23.603 -
23.604 - /// This constructor sets the iterator to the first outgoing arc of
23.605 - /// the node.
23.606 - ///@param n the node
23.607 - ///@param g the graph
23.608 OutArcIt(const Graph& n, const Node& g) {
23.609 ignore_unused_variable_warning(n);
23.610 ignore_unused_variable_warning(g);
23.611 }
23.612 - /// Arc -> OutArcIt conversion
23.613 + /// Sets the iterator to the given arc.
23.614
23.615 - /// Sets the iterator to the value of the trivial iterator.
23.616 - /// This feature necessitates that each time we
23.617 - /// iterate the arc-set, the iteration order is the same.
23.618 + /// Sets the iterator to the given arc of the given graph.
23.619 + ///
23.620 OutArcIt(const Graph&, const Arc&) { }
23.621 - ///Next outgoing arc
23.622 + /// Next outgoing arc
23.623
23.624 /// Assign the iterator to the next
23.625 /// outgoing arc of the corresponding node.
23.626 OutArcIt& operator++() { return *this; }
23.627 };
23.628
23.629 - /// This iterator goes trough the incoming directed arcs of a node.
23.630 + /// Iterator class for the incoming arcs of a node.
23.631
23.632 - /// This iterator goes trough the \e incoming arcs of a certain node
23.633 - /// of a graph.
23.634 - /// Its usage is quite simple, for example you can count the number
23.635 - /// of outgoing arcs of a node \c n
23.636 - /// in graph \c g of type \c Graph as follows.
23.637 + /// This iterator goes trough the \e incoming directed arcs of a
23.638 + /// certain node of a graph.
23.639 + /// Its usage is quite simple, for example, you can count the number
23.640 + /// of incoming arcs of a node \c n
23.641 + /// in a graph \c g of type \c %Graph as follows.
23.642 ///\code
23.643 /// int count=0;
23.644 - /// for(Graph::InArcIt e(g, n); e!=INVALID; ++e) ++count;
23.645 + /// for (Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count;
23.646 ///\endcode
23.647 -
23.648 class InArcIt : public Arc {
23.649 public:
23.650 /// Default constructor
23.651
23.652 - /// @warning The default constructor sets the iterator
23.653 - /// to an undefined value.
23.654 + /// Default constructor.
23.655 + /// \warning It sets the iterator to an undefined value.
23.656 InArcIt() { }
23.657 /// Copy constructor.
23.658
23.659 /// Copy constructor.
23.660 ///
23.661 InArcIt(const InArcIt& e) : Arc(e) { }
23.662 - /// Initialize the iterator to be invalid.
23.663 + /// %Invalid constructor \& conversion.
23.664
23.665 - /// Initialize the iterator to be invalid.
23.666 + /// Initializes the iterator to be invalid.
23.667 + /// \sa Invalid for more details.
23.668 + InArcIt(Invalid) { }
23.669 + /// Sets the iterator to the first incoming arc.
23.670 +
23.671 + /// Sets the iterator to the first incoming arc of the given node.
23.672 ///
23.673 - InArcIt(Invalid) { }
23.674 - /// This constructor sets the iterator to first incoming arc.
23.675 -
23.676 - /// This constructor set the iterator to the first incoming arc of
23.677 - /// the node.
23.678 - ///@param n the node
23.679 - ///@param g the graph
23.680 InArcIt(const Graph& g, const Node& n) {
23.681 ignore_unused_variable_warning(n);
23.682 ignore_unused_variable_warning(g);
23.683 }
23.684 - /// Arc -> InArcIt conversion
23.685 + /// Sets the iterator to the given arc.
23.686
23.687 - /// Sets the iterator to the value of the trivial iterator \c e.
23.688 - /// This feature necessitates that each time we
23.689 - /// iterate the arc-set, the iteration order is the same.
23.690 + /// Sets the iterator to the given arc of the given graph.
23.691 + ///
23.692 InArcIt(const Graph&, const Arc&) { }
23.693 /// Next incoming arc
23.694
23.695 - /// Assign the iterator to the next inarc of the corresponding node.
23.696 - ///
23.697 + /// Assign the iterator to the next
23.698 + /// incoming arc of the corresponding node.
23.699 InArcIt& operator++() { return *this; }
23.700 };
23.701
23.702 - /// \brief Reference map of the nodes to type \c T.
23.703 + /// \brief Standard graph map type for the nodes.
23.704 ///
23.705 - /// Reference map of the nodes to type \c T.
23.706 + /// Standard graph map type for the nodes.
23.707 + /// It conforms to the ReferenceMap concept.
23.708 template<class T>
23.709 class NodeMap : public ReferenceMap<Node, T, T&, const T&>
23.710 {
23.711 public:
23.712
23.713 - ///\e
23.714 - NodeMap(const Graph&) { }
23.715 - ///\e
23.716 + /// Constructor
23.717 + explicit NodeMap(const Graph&) { }
23.718 + /// Constructor with given initial value
23.719 NodeMap(const Graph&, T) { }
23.720
23.721 private:
23.722 @@ -524,18 +531,20 @@
23.723 }
23.724 };
23.725
23.726 - /// \brief Reference map of the arcs to type \c T.
23.727 + /// \brief Standard graph map type for the arcs.
23.728 ///
23.729 - /// Reference map of the arcs to type \c T.
23.730 + /// Standard graph map type for the arcs.
23.731 + /// It conforms to the ReferenceMap concept.
23.732 template<class T>
23.733 class ArcMap : public ReferenceMap<Arc, T, T&, const T&>
23.734 {
23.735 public:
23.736
23.737 - ///\e
23.738 - ArcMap(const Graph&) { }
23.739 - ///\e
23.740 + /// Constructor
23.741 + explicit ArcMap(const Graph&) { }
23.742 + /// Constructor with given initial value
23.743 ArcMap(const Graph&, T) { }
23.744 +
23.745 private:
23.746 ///Copy constructor
23.747 ArcMap(const ArcMap& em) :
23.748 @@ -548,18 +557,20 @@
23.749 }
23.750 };
23.751
23.752 - /// Reference map of the edges to type \c T.
23.753 -
23.754 - /// Reference map of the edges to type \c T.
23.755 + /// \brief Standard graph map type for the edges.
23.756 + ///
23.757 + /// Standard graph map type for the edges.
23.758 + /// It conforms to the ReferenceMap concept.
23.759 template<class T>
23.760 class EdgeMap : public ReferenceMap<Edge, T, T&, const T&>
23.761 {
23.762 public:
23.763
23.764 - ///\e
23.765 - EdgeMap(const Graph&) { }
23.766 - ///\e
23.767 + /// Constructor
23.768 + explicit EdgeMap(const Graph&) { }
23.769 + /// Constructor with given initial value
23.770 EdgeMap(const Graph&, T) { }
23.771 +
23.772 private:
23.773 ///Copy constructor
23.774 EdgeMap(const EdgeMap& em) :
23.775 @@ -572,107 +583,124 @@
23.776 }
23.777 };
23.778
23.779 - /// \brief Direct the given edge.
23.780 + /// \brief The first node of the edge.
23.781 ///
23.782 - /// Direct the given edge. The returned arc source
23.783 - /// will be the given node.
23.784 - Arc direct(const Edge&, const Node&) const {
23.785 - return INVALID;
23.786 - }
23.787 -
23.788 - /// \brief Direct the given edge.
23.789 + /// Returns the first node of the given edge.
23.790 ///
23.791 - /// Direct the given edge. The returned arc
23.792 - /// represents the given edge and the direction comes
23.793 - /// from the bool parameter. The source of the edge and
23.794 - /// the directed arc is the same when the given bool is true.
23.795 - Arc direct(const Edge&, bool) const {
23.796 - return INVALID;
23.797 - }
23.798 -
23.799 - /// \brief Returns true if the arc has default orientation.
23.800 - ///
23.801 - /// Returns whether the given directed arc is same orientation as
23.802 - /// the corresponding edge's default orientation.
23.803 - bool direction(Arc) const { return true; }
23.804 -
23.805 - /// \brief Returns the opposite directed arc.
23.806 - ///
23.807 - /// Returns the opposite directed arc.
23.808 - Arc oppositeArc(Arc) const { return INVALID; }
23.809 -
23.810 - /// \brief Opposite node on an arc
23.811 - ///
23.812 - /// \return The opposite of the given node on the given edge.
23.813 - Node oppositeNode(Node, Edge) const { return INVALID; }
23.814 -
23.815 - /// \brief First node of the edge.
23.816 - ///
23.817 - /// \return The first node of the given edge.
23.818 - ///
23.819 - /// Naturally edges don't have direction and thus
23.820 - /// don't have source and target node. However we use \c u() and \c v()
23.821 - /// methods to query the two nodes of the arc. The direction of the
23.822 - /// arc which arises this way is called the inherent direction of the
23.823 - /// edge, and is used to define the "default" direction
23.824 - /// of the directed versions of the arcs.
23.825 + /// Edges don't have source and target nodes, however, methods
23.826 + /// u() and v() are used to query the two end-nodes of an edge.
23.827 + /// The orientation of an edge that arises this way is called
23.828 + /// the inherent direction, it is used to define the default
23.829 + /// direction for the corresponding arcs.
23.830 /// \sa v()
23.831 /// \sa direction()
23.832 Node u(Edge) const { return INVALID; }
23.833
23.834 - /// \brief Second node of the edge.
23.835 + /// \brief The second node of the edge.
23.836 ///
23.837 - /// \return The second node of the given edge.
23.838 + /// Returns the second node of the given edge.
23.839 ///
23.840 - /// Naturally edges don't have direction and thus
23.841 - /// don't have source and target node. However we use \c u() and \c v()
23.842 - /// methods to query the two nodes of the arc. The direction of the
23.843 - /// arc which arises this way is called the inherent direction of the
23.844 - /// edge, and is used to define the "default" direction
23.845 - /// of the directed versions of the arcs.
23.846 + /// Edges don't have source and target nodes, however, methods
23.847 + /// u() and v() are used to query the two end-nodes of an edge.
23.848 + /// The orientation of an edge that arises this way is called
23.849 + /// the inherent direction, it is used to define the default
23.850 + /// direction for the corresponding arcs.
23.851 /// \sa u()
23.852 /// \sa direction()
23.853 Node v(Edge) const { return INVALID; }
23.854
23.855 - /// \brief Source node of the directed arc.
23.856 + /// \brief The source node of the arc.
23.857 + ///
23.858 + /// Returns the source node of the given arc.
23.859 Node source(Arc) const { return INVALID; }
23.860
23.861 - /// \brief Target node of the directed arc.
23.862 + /// \brief The target node of the arc.
23.863 + ///
23.864 + /// Returns the target node of the given arc.
23.865 Node target(Arc) const { return INVALID; }
23.866
23.867 - /// \brief Returns the id of the node.
23.868 + /// \brief The ID of the node.
23.869 + ///
23.870 + /// Returns the ID of the given node.
23.871 int id(Node) const { return -1; }
23.872
23.873 - /// \brief Returns the id of the edge.
23.874 + /// \brief The ID of the edge.
23.875 + ///
23.876 + /// Returns the ID of the given edge.
23.877 int id(Edge) const { return -1; }
23.878
23.879 - /// \brief Returns the id of the arc.
23.880 + /// \brief The ID of the arc.
23.881 + ///
23.882 + /// Returns the ID of the given arc.
23.883 int id(Arc) const { return -1; }
23.884
23.885 - /// \brief Returns the node with the given id.
23.886 + /// \brief The node with the given ID.
23.887 ///
23.888 - /// \pre The argument should be a valid node id in the graph.
23.889 + /// Returns the node with the given ID.
23.890 + /// \pre The argument should be a valid node ID in the graph.
23.891 Node nodeFromId(int) const { return INVALID; }
23.892
23.893 - /// \brief Returns the edge with the given id.
23.894 + /// \brief The edge with the given ID.
23.895 ///
23.896 - /// \pre The argument should be a valid edge id in the graph.
23.897 + /// Returns the edge with the given ID.
23.898 + /// \pre The argument should be a valid edge ID in the graph.
23.899 Edge edgeFromId(int) const { return INVALID; }
23.900
23.901 - /// \brief Returns the arc with the given id.
23.902 + /// \brief The arc with the given ID.
23.903 ///
23.904 - /// \pre The argument should be a valid arc id in the graph.
23.905 + /// Returns the arc with the given ID.
23.906 + /// \pre The argument should be a valid arc ID in the graph.
23.907 Arc arcFromId(int) const { return INVALID; }
23.908
23.909 - /// \brief Returns an upper bound on the node IDs.
23.910 + /// \brief An upper bound on the node IDs.
23.911 + ///
23.912 + /// Returns an upper bound on the node IDs.
23.913 int maxNodeId() const { return -1; }
23.914
23.915 - /// \brief Returns an upper bound on the edge IDs.
23.916 + /// \brief An upper bound on the edge IDs.
23.917 + ///
23.918 + /// Returns an upper bound on the edge IDs.
23.919 int maxEdgeId() const { return -1; }
23.920
23.921 - /// \brief Returns an upper bound on the arc IDs.
23.922 + /// \brief An upper bound on the arc IDs.
23.923 + ///
23.924 + /// Returns an upper bound on the arc IDs.
23.925 int maxArcId() const { return -1; }
23.926
23.927 + /// \brief The direction of the arc.
23.928 + ///
23.929 + /// Returns \c true if the direction of the given arc is the same as
23.930 + /// the inherent orientation of the represented edge.
23.931 + bool direction(Arc) const { return true; }
23.932 +
23.933 + /// \brief Direct the edge.
23.934 + ///
23.935 + /// Direct the given edge. The returned arc
23.936 + /// represents the given edge and its direction comes
23.937 + /// from the bool parameter. If it is \c true, then the direction
23.938 + /// of the arc is the same as the inherent orientation of the edge.
23.939 + Arc direct(Edge, bool) const {
23.940 + return INVALID;
23.941 + }
23.942 +
23.943 + /// \brief Direct the edge.
23.944 + ///
23.945 + /// Direct the given edge. The returned arc represents the given
23.946 + /// edge and its source node is the given node.
23.947 + Arc direct(Edge, Node) const {
23.948 + return INVALID;
23.949 + }
23.950 +
23.951 + /// \brief The oppositely directed arc.
23.952 + ///
23.953 + /// Returns the oppositely directed arc representing the same edge.
23.954 + Arc oppositeArc(Arc) const { return INVALID; }
23.955 +
23.956 + /// \brief The opposite node on the edge.
23.957 + ///
23.958 + /// Returns the opposite node on the given edge.
23.959 + Node oppositeNode(Node, Edge) const { return INVALID; }
23.960 +
23.961 void first(Node&) const {}
23.962 void next(Node&) const {}
23.963
23.964 @@ -705,47 +733,39 @@
23.965 // Dummy parameter.
23.966 int maxId(Arc) const { return -1; }
23.967
23.968 - /// \brief Base node of the iterator
23.969 + /// \brief The base node of the iterator.
23.970 ///
23.971 - /// Returns the base node (the source in this case) of the iterator
23.972 - Node baseNode(OutArcIt e) const {
23.973 - return source(e);
23.974 - }
23.975 - /// \brief Running node of the iterator
23.976 + /// Returns the base node of the given incident edge iterator.
23.977 + Node baseNode(IncEdgeIt) const { return INVALID; }
23.978 +
23.979 + /// \brief The running node of the iterator.
23.980 ///
23.981 - /// Returns the running node (the target in this case) of the
23.982 - /// iterator
23.983 - Node runningNode(OutArcIt e) const {
23.984 - return target(e);
23.985 - }
23.986 + /// Returns the running node of the given incident edge iterator.
23.987 + Node runningNode(IncEdgeIt) const { return INVALID; }
23.988
23.989 - /// \brief Base node of the iterator
23.990 + /// \brief The base node of the iterator.
23.991 ///
23.992 - /// Returns the base node (the target in this case) of the iterator
23.993 - Node baseNode(InArcIt e) const {
23.994 - return target(e);
23.995 - }
23.996 - /// \brief Running node of the iterator
23.997 + /// Returns the base node of the given outgoing arc iterator
23.998 + /// (i.e. the source node of the corresponding arc).
23.999 + Node baseNode(OutArcIt) const { return INVALID; }
23.1000 +
23.1001 + /// \brief The running node of the iterator.
23.1002 ///
23.1003 - /// Returns the running node (the source in this case) of the
23.1004 - /// iterator
23.1005 - Node runningNode(InArcIt e) const {
23.1006 - return source(e);
23.1007 - }
23.1008 + /// Returns the running node of the given outgoing arc iterator
23.1009 + /// (i.e. the target node of the corresponding arc).
23.1010 + Node runningNode(OutArcIt) const { return INVALID; }
23.1011
23.1012 - /// \brief Base node of the iterator
23.1013 + /// \brief The base node of the iterator.
23.1014 ///
23.1015 - /// Returns the base node of the iterator
23.1016 - Node baseNode(IncEdgeIt) const {
23.1017 - return INVALID;
23.1018 - }
23.1019 + /// Returns the base node of the given incomming arc iterator
23.1020 + /// (i.e. the target node of the corresponding arc).
23.1021 + Node baseNode(InArcIt) const { return INVALID; }
23.1022
23.1023 - /// \brief Running node of the iterator
23.1024 + /// \brief The running node of the iterator.
23.1025 ///
23.1026 - /// Returns the running node of the iterator
23.1027 - Node runningNode(IncEdgeIt) const {
23.1028 - return INVALID;
23.1029 - }
23.1030 + /// Returns the running node of the given incomming arc iterator
23.1031 + /// (i.e. the source node of the corresponding arc).
23.1032 + Node runningNode(InArcIt) const { return INVALID; }
23.1033
23.1034 template <typename _Graph>
23.1035 struct Constraints {
24.1 --- a/lemon/concepts/graph_components.h Sun Oct 04 10:15:32 2009 +0200
24.2 +++ b/lemon/concepts/graph_components.h Wed Dec 09 11:14:06 2009 +0100
24.3 @@ -18,7 +18,7 @@
24.4
24.5 ///\ingroup graph_concepts
24.6 ///\file
24.7 -///\brief The concept of graph components.
24.8 +///\brief The concepts of graph components.
24.9
24.10 #ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H
24.11 #define LEMON_CONCEPTS_GRAPH_COMPONENTS_H
24.12 @@ -92,7 +92,7 @@
24.13 /// It makes possible to use graph item types as key types in
24.14 /// associative containers (e.g. \c std::map).
24.15 ///
24.16 - /// \note This operator only have to define some strict ordering of
24.17 + /// \note This operator only has to define some strict ordering of
24.18 /// the items; this order has nothing to do with the iteration
24.19 /// ordering of the items.
24.20 bool operator<(const GraphItem&) const { return false; }
25.1 --- a/lemon/concepts/maps.h Sun Oct 04 10:15:32 2009 +0200
25.2 +++ b/lemon/concepts/maps.h Wed Dec 09 11:14:06 2009 +0100
25.3 @@ -182,7 +182,8 @@
25.4
25.5 template<typename _ReferenceMap>
25.6 struct Constraints {
25.7 - void constraints() {
25.8 + typename enable_if<typename _ReferenceMap::ReferenceMapTag, void>::type
25.9 + constraints() {
25.10 checkConcept<ReadWriteMap<K, T>, _ReferenceMap >();
25.11 ref = m[key];
25.12 m[key] = val;
26.1 --- a/lemon/concepts/path.h Sun Oct 04 10:15:32 2009 +0200
26.2 +++ b/lemon/concepts/path.h Wed Dec 09 11:14:06 2009 +0100
26.3 @@ -18,7 +18,7 @@
26.4
26.5 ///\ingroup concept
26.6 ///\file
26.7 -///\brief Classes for representing paths in digraphs.
26.8 +///\brief The concept of paths
26.9 ///
26.10
26.11 #ifndef LEMON_CONCEPTS_PATH_H
26.12 @@ -38,13 +38,22 @@
26.13 ///
26.14 /// A skeleton structure for representing directed paths in a
26.15 /// digraph.
26.16 + /// In a sense, a path can be treated as a list of arcs.
26.17 + /// LEMON path types just store this list. As a consequence, they cannot
26.18 + /// enumerate the nodes on the path directly and a zero length path
26.19 + /// cannot store its source node.
26.20 + ///
26.21 + /// The arcs of a path should be stored in the order of their directions,
26.22 + /// i.e. the target node of each arc should be the same as the source
26.23 + /// node of the next arc. This consistency could be checked using
26.24 + /// \ref checkPath().
26.25 + /// The source and target nodes of a (consistent) path can be obtained
26.26 + /// using \ref pathSource() and \ref pathTarget().
26.27 + ///
26.28 + /// A path can be constructed from another path of any type using the
26.29 + /// copy constructor or the assignment operator.
26.30 + ///
26.31 /// \tparam GR The digraph type in which the path is.
26.32 - ///
26.33 - /// In a sense, the path can be treated as a list of arcs. The
26.34 - /// lemon path type stores just this list. As a consequence it
26.35 - /// cannot enumerate the nodes in the path and the zero length
26.36 - /// paths cannot store the source.
26.37 - ///
26.38 template <typename GR>
26.39 class Path {
26.40 public:
26.41 @@ -59,18 +68,18 @@
26.42 /// \brief Default constructor
26.43 Path() {}
26.44
26.45 - /// \brief Template constructor
26.46 + /// \brief Template copy constructor
26.47 template <typename CPath>
26.48 Path(const CPath& cpath) {}
26.49
26.50 - /// \brief Template assigment
26.51 + /// \brief Template assigment operator
26.52 template <typename CPath>
26.53 Path& operator=(const CPath& cpath) {
26.54 ignore_unused_variable_warning(cpath);
26.55 return *this;
26.56 }
26.57
26.58 - /// Length of the path ie. the number of arcs in the path.
26.59 + /// Length of the path, i.e. the number of arcs on the path.
26.60 int length() const { return 0;}
26.61
26.62 /// Returns whether the path is empty.
26.63 @@ -79,19 +88,19 @@
26.64 /// Resets the path to an empty path.
26.65 void clear() {}
26.66
26.67 - /// \brief LEMON style iterator for path arcs
26.68 + /// \brief LEMON style iterator for enumerating the arcs of a path.
26.69 ///
26.70 - /// This class is used to iterate on the arcs of the paths.
26.71 + /// LEMON style iterator class for enumerating the arcs of a path.
26.72 class ArcIt {
26.73 public:
26.74 /// Default constructor
26.75 ArcIt() {}
26.76 /// Invalid constructor
26.77 ArcIt(Invalid) {}
26.78 - /// Constructor for first arc
26.79 + /// Sets the iterator to the first arc of the given path
26.80 ArcIt(const Path &) {}
26.81
26.82 - /// Conversion to Arc
26.83 + /// Conversion to \c Arc
26.84 operator Arc() const { return INVALID; }
26.85
26.86 /// Next arc
26.87 @@ -192,24 +201,18 @@
26.88 /// \brief A skeleton structure for path dumpers.
26.89 ///
26.90 /// A skeleton structure for path dumpers. The path dumpers are
26.91 - /// the generalization of the paths. The path dumpers can
26.92 - /// enumerate the arcs of the path wheter in forward or in
26.93 - /// backward order. In most time these classes are not used
26.94 - /// directly rather it used to assign a dumped class to a real
26.95 - /// path type.
26.96 + /// the generalization of the paths, they can enumerate the arcs
26.97 + /// of the path either in forward or in backward order.
26.98 + /// These classes are typically not used directly, they are rather
26.99 + /// used to be assigned to a real path type.
26.100 ///
26.101 /// The main purpose of this concept is that the shortest path
26.102 - /// algorithms can enumerate easily the arcs in reverse order.
26.103 - /// If we would like to give back a real path from these
26.104 - /// algorithms then we should create a temporarly path object. In
26.105 - /// LEMON such algorithms gives back a path dumper what can
26.106 - /// assigned to a real path and the dumpers can be implemented as
26.107 + /// algorithms can enumerate the arcs easily in reverse order.
26.108 + /// In LEMON, such algorithms give back a (reverse) path dumper that
26.109 + /// can be assigned to a real path. The dumpers can be implemented as
26.110 /// an adaptor class to the predecessor map.
26.111 ///
26.112 /// \tparam GR The digraph type in which the path is.
26.113 - ///
26.114 - /// The paths can be constructed from any path type by a
26.115 - /// template constructor or a template assignment operator.
26.116 template <typename GR>
26.117 class PathDumper {
26.118 public:
26.119 @@ -219,7 +222,7 @@
26.120 /// Arc type of the underlying digraph.
26.121 typedef typename Digraph::Arc Arc;
26.122
26.123 - /// Length of the path ie. the number of arcs in the path.
26.124 + /// Length of the path, i.e. the number of arcs on the path.
26.125 int length() const { return 0;}
26.126
26.127 /// Returns whether the path is empty.
26.128 @@ -227,25 +230,24 @@
26.129
26.130 /// \brief Forward or reverse dumping
26.131 ///
26.132 - /// If the RevPathTag is defined and true then reverse dumping
26.133 - /// is provided in the path dumper. In this case instead of the
26.134 - /// ArcIt the RevArcIt iterator should be implemented in the
26.135 - /// dumper.
26.136 + /// If this tag is defined to be \c True, then reverse dumping
26.137 + /// is provided in the path dumper. In this case, \c RevArcIt
26.138 + /// iterator should be implemented instead of \c ArcIt iterator.
26.139 typedef False RevPathTag;
26.140
26.141 - /// \brief LEMON style iterator for path arcs
26.142 + /// \brief LEMON style iterator for enumerating the arcs of a path.
26.143 ///
26.144 - /// This class is used to iterate on the arcs of the paths.
26.145 + /// LEMON style iterator class for enumerating the arcs of a path.
26.146 class ArcIt {
26.147 public:
26.148 /// Default constructor
26.149 ArcIt() {}
26.150 /// Invalid constructor
26.151 ArcIt(Invalid) {}
26.152 - /// Constructor for first arc
26.153 + /// Sets the iterator to the first arc of the given path
26.154 ArcIt(const PathDumper&) {}
26.155
26.156 - /// Conversion to Arc
26.157 + /// Conversion to \c Arc
26.158 operator Arc() const { return INVALID; }
26.159
26.160 /// Next arc
26.161 @@ -260,20 +262,21 @@
26.162
26.163 };
26.164
26.165 - /// \brief LEMON style iterator for path arcs
26.166 + /// \brief LEMON style iterator for enumerating the arcs of a path
26.167 + /// in reverse direction.
26.168 ///
26.169 - /// This class is used to iterate on the arcs of the paths in
26.170 - /// reverse direction.
26.171 + /// LEMON style iterator class for enumerating the arcs of a path
26.172 + /// in reverse direction.
26.173 class RevArcIt {
26.174 public:
26.175 /// Default constructor
26.176 RevArcIt() {}
26.177 /// Invalid constructor
26.178 RevArcIt(Invalid) {}
26.179 - /// Constructor for first arc
26.180 + /// Sets the iterator to the last arc of the given path
26.181 RevArcIt(const PathDumper &) {}
26.182
26.183 - /// Conversion to Arc
26.184 + /// Conversion to \c Arc
26.185 operator Arc() const { return INVALID; }
26.186
26.187 /// Next arc
27.1 --- a/lemon/counter.h Sun Oct 04 10:15:32 2009 +0200
27.2 +++ b/lemon/counter.h Wed Dec 09 11:14:06 2009 +0100
27.3 @@ -212,7 +212,7 @@
27.4
27.5 /// 'Do nothing' version of Counter.
27.6
27.7 - /// This class can be used in the same way as \ref Counter however it
27.8 + /// This class can be used in the same way as \ref Counter, but it
27.9 /// does not count at all and does not print report on destruction.
27.10 ///
27.11 /// Replacing a \ref Counter with a \ref NoCounter makes it possible
28.1 --- a/lemon/cplex.cc Sun Oct 04 10:15:32 2009 +0200
28.2 +++ b/lemon/cplex.cc Wed Dec 09 11:14:06 2009 +0100
28.3 @@ -111,6 +111,39 @@
28.4 return i;
28.5 }
28.6
28.7 + int CplexBase::_addRow(Value lb, ExprIterator b,
28.8 + ExprIterator e, Value ub) {
28.9 + int i = CPXgetnumrows(cplexEnv(), _prob);
28.10 + if (lb == -INF) {
28.11 + const char s = 'L';
28.12 + CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0);
28.13 + } else if (ub == INF) {
28.14 + const char s = 'G';
28.15 + CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
28.16 + } else if (lb == ub){
28.17 + const char s = 'E';
28.18 + CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
28.19 + } else {
28.20 + const char s = 'R';
28.21 + double len = ub - lb;
28.22 + CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, &len, 0);
28.23 + }
28.24 +
28.25 + std::vector<int> indices;
28.26 + std::vector<int> rowlist;
28.27 + std::vector<Value> values;
28.28 +
28.29 + for(ExprIterator it=b; it!=e; ++it) {
28.30 + indices.push_back(it->first);
28.31 + values.push_back(it->second);
28.32 + rowlist.push_back(i);
28.33 + }
28.34 +
28.35 + CPXchgcoeflist(cplexEnv(), _prob, values.size(),
28.36 + &rowlist.front(), &indices.front(), &values.front());
28.37 +
28.38 + return i;
28.39 + }
28.40
28.41 void CplexBase::_eraseCol(int i) {
28.42 CPXdelcols(cplexEnv(), _prob, i, i);
29.1 --- a/lemon/cplex.h Sun Oct 04 10:15:32 2009 +0200
29.2 +++ b/lemon/cplex.h Wed Dec 09 11:14:06 2009 +0100
29.3 @@ -93,6 +93,7 @@
29.4
29.5 virtual int _addCol();
29.6 virtual int _addRow();
29.7 + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
29.8
29.9 virtual void _eraseCol(int i);
29.10 virtual void _eraseRow(int i);
30.1 --- a/lemon/dfs.h Sun Oct 04 10:15:32 2009 +0200
30.2 +++ b/lemon/dfs.h Wed Dec 09 11:14:06 2009 +0100
30.3 @@ -47,7 +47,7 @@
30.4 ///
30.5 ///The type of the map that stores the predecessor
30.6 ///arcs of the %DFS paths.
30.7 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
30.8 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
30.9 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
30.10 ///Instantiates a \c PredMap.
30.11
30.12 @@ -62,7 +62,8 @@
30.13 ///The type of the map that indicates which nodes are processed.
30.14
30.15 ///The type of the map that indicates which nodes are processed.
30.16 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
30.17 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
30.18 + ///By default, it is a NullMap.
30.19 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
30.20 ///Instantiates a \c ProcessedMap.
30.21
30.22 @@ -81,7 +82,7 @@
30.23 ///The type of the map that indicates which nodes are reached.
30.24
30.25 ///The type of the map that indicates which nodes are reached.
30.26 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
30.27 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
30.28 typedef typename Digraph::template NodeMap<bool> ReachedMap;
30.29 ///Instantiates a \c ReachedMap.
30.30
30.31 @@ -96,7 +97,7 @@
30.32 ///The type of the map that stores the distances of the nodes.
30.33
30.34 ///The type of the map that stores the distances of the nodes.
30.35 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
30.36 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
30.37 typedef typename Digraph::template NodeMap<int> DistMap;
30.38 ///Instantiates a \c DistMap.
30.39
30.40 @@ -224,7 +225,7 @@
30.41 ///
30.42 ///\ref named-templ-param "Named parameter" for setting
30.43 ///\c PredMap type.
30.44 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
30.45 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
30.46 template <class T>
30.47 struct SetPredMap : public Dfs<Digraph, SetPredMapTraits<T> > {
30.48 typedef Dfs<Digraph, SetPredMapTraits<T> > Create;
30.49 @@ -244,7 +245,7 @@
30.50 ///
30.51 ///\ref named-templ-param "Named parameter" for setting
30.52 ///\c DistMap type.
30.53 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
30.54 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
30.55 template <class T>
30.56 struct SetDistMap : public Dfs< Digraph, SetDistMapTraits<T> > {
30.57 typedef Dfs<Digraph, SetDistMapTraits<T> > Create;
30.58 @@ -264,7 +265,7 @@
30.59 ///
30.60 ///\ref named-templ-param "Named parameter" for setting
30.61 ///\c ReachedMap type.
30.62 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
30.63 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
30.64 template <class T>
30.65 struct SetReachedMap : public Dfs< Digraph, SetReachedMapTraits<T> > {
30.66 typedef Dfs< Digraph, SetReachedMapTraits<T> > Create;
30.67 @@ -284,7 +285,7 @@
30.68 ///
30.69 ///\ref named-templ-param "Named parameter" for setting
30.70 ///\c ProcessedMap type.
30.71 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
30.72 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
30.73 template <class T>
30.74 struct SetProcessedMap : public Dfs< Digraph, SetProcessedMapTraits<T> > {
30.75 typedef Dfs< Digraph, SetProcessedMapTraits<T> > Create;
30.76 @@ -411,8 +412,8 @@
30.77 ///\name Execution Control
30.78 ///The simplest way to execute the DFS algorithm is to use one of the
30.79 ///member functions called \ref run(Node) "run()".\n
30.80 - ///If you need more control on the execution, first you have to call
30.81 - ///\ref init(), then you can add a source node with \ref addSource()
30.82 + ///If you need better control on the execution, you have to call
30.83 + ///\ref init() first, then you can add a source node with \ref addSource()
30.84 ///and perform the actual computation with \ref start().
30.85 ///This procedure can be repeated if there are nodes that have not
30.86 ///been reached.
30.87 @@ -632,12 +633,8 @@
30.88
30.89 ///Runs the algorithm to visit all nodes in the digraph.
30.90
30.91 - ///This method runs the %DFS algorithm in order to compute the
30.92 - ///%DFS path to each node.
30.93 - ///
30.94 - ///The algorithm computes
30.95 - ///- the %DFS tree (forest),
30.96 - ///- the distance of each node from the root(s) in the %DFS tree.
30.97 + ///This method runs the %DFS algorithm in order to visit all nodes
30.98 + ///in the digraph.
30.99 ///
30.100 ///\note <tt>d.run()</tt> is just a shortcut of the following code.
30.101 ///\code
30.102 @@ -669,9 +666,9 @@
30.103
30.104 ///@{
30.105
30.106 - ///The DFS path to a node.
30.107 + ///The DFS path to the given node.
30.108
30.109 - ///Returns the DFS path to a node.
30.110 + ///Returns the DFS path to the given node from the root(s).
30.111 ///
30.112 ///\warning \c t should be reached from the root(s).
30.113 ///
30.114 @@ -679,9 +676,9 @@
30.115 ///must be called before using this function.
30.116 Path path(Node t) const { return Path(*G, *_pred, t); }
30.117
30.118 - ///The distance of a node from the root(s).
30.119 + ///The distance of the given node from the root(s).
30.120
30.121 - ///Returns the distance of a node from the root(s).
30.122 + ///Returns the distance of the given node from the root(s).
30.123 ///
30.124 ///\warning If node \c v is not reached from the root(s), then
30.125 ///the return value of this function is undefined.
30.126 @@ -690,7 +687,7 @@
30.127 ///must be called before using this function.
30.128 int dist(Node v) const { return (*_dist)[v]; }
30.129
30.130 - ///Returns the 'previous arc' of the %DFS tree for a node.
30.131 + ///Returns the 'previous arc' of the %DFS tree for the given node.
30.132
30.133 ///This function returns the 'previous arc' of the %DFS tree for the
30.134 ///node \c v, i.e. it returns the last arc of a %DFS path from a
30.135 @@ -698,21 +695,21 @@
30.136 ///root(s) or if \c v is a root.
30.137 ///
30.138 ///The %DFS tree used here is equal to the %DFS tree used in
30.139 - ///\ref predNode().
30.140 + ///\ref predNode() and \ref predMap().
30.141 ///
30.142 ///\pre Either \ref run(Node) "run()" or \ref init()
30.143 ///must be called before using this function.
30.144 Arc predArc(Node v) const { return (*_pred)[v];}
30.145
30.146 - ///Returns the 'previous node' of the %DFS tree.
30.147 + ///Returns the 'previous node' of the %DFS tree for the given node.
30.148
30.149 ///This function returns the 'previous node' of the %DFS
30.150 ///tree for the node \c v, i.e. it returns the last but one node
30.151 - ///from a %DFS path from a root to \c v. It is \c INVALID
30.152 + ///of a %DFS path from a root to \c v. It is \c INVALID
30.153 ///if \c v is not reached from the root(s) or if \c v is a root.
30.154 ///
30.155 ///The %DFS tree used here is equal to the %DFS tree used in
30.156 - ///\ref predArc().
30.157 + ///\ref predArc() and \ref predMap().
30.158 ///
30.159 ///\pre Either \ref run(Node) "run()" or \ref init()
30.160 ///must be called before using this function.
30.161 @@ -733,13 +730,13 @@
30.162 ///predecessor arcs.
30.163 ///
30.164 ///Returns a const reference to the node map that stores the predecessor
30.165 - ///arcs, which form the DFS tree.
30.166 + ///arcs, which form the DFS tree (forest).
30.167 ///
30.168 ///\pre Either \ref run(Node) "run()" or \ref init()
30.169 ///must be called before using this function.
30.170 const PredMap &predMap() const { return *_pred;}
30.171
30.172 - ///Checks if a node is reached from the root(s).
30.173 + ///Checks if the given node. node is reached from the root(s).
30.174
30.175 ///Returns \c true if \c v is reached from the root(s).
30.176 ///
30.177 @@ -765,7 +762,7 @@
30.178 ///
30.179 ///The type of the map that stores the predecessor
30.180 ///arcs of the %DFS paths.
30.181 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
30.182 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
30.183 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
30.184 ///Instantiates a PredMap.
30.185
30.186 @@ -780,8 +777,8 @@
30.187 ///The type of the map that indicates which nodes are processed.
30.188
30.189 ///The type of the map that indicates which nodes are processed.
30.190 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
30.191 - ///By default it is a NullMap.
30.192 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
30.193 + ///By default, it is a NullMap.
30.194 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
30.195 ///Instantiates a ProcessedMap.
30.196
30.197 @@ -800,7 +797,7 @@
30.198 ///The type of the map that indicates which nodes are reached.
30.199
30.200 ///The type of the map that indicates which nodes are reached.
30.201 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
30.202 + ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
30.203 typedef typename Digraph::template NodeMap<bool> ReachedMap;
30.204 ///Instantiates a ReachedMap.
30.205
30.206 @@ -815,7 +812,7 @@
30.207 ///The type of the map that stores the distances of the nodes.
30.208
30.209 ///The type of the map that stores the distances of the nodes.
30.210 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
30.211 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
30.212 typedef typename Digraph::template NodeMap<int> DistMap;
30.213 ///Instantiates a DistMap.
30.214
30.215 @@ -830,18 +827,14 @@
30.216 ///The type of the DFS paths.
30.217
30.218 ///The type of the DFS paths.
30.219 - ///It must meet the \ref concepts::Path "Path" concept.
30.220 + ///It must conform to the \ref concepts::Path "Path" concept.
30.221 typedef lemon::Path<Digraph> Path;
30.222 };
30.223
30.224 /// Default traits class used by DfsWizard
30.225
30.226 - /// To make it easier to use Dfs algorithm
30.227 - /// we have created a wizard class.
30.228 - /// This \ref DfsWizard class needs default traits,
30.229 - /// as well as the \ref Dfs class.
30.230 - /// The \ref DfsWizardBase is a class to be the default traits of the
30.231 - /// \ref DfsWizard class.
30.232 + /// Default traits class used by DfsWizard.
30.233 + /// \tparam GR The type of the digraph.
30.234 template<class GR>
30.235 class DfsWizardBase : public DfsWizardDefaultTraits<GR>
30.236 {
30.237 @@ -869,7 +862,7 @@
30.238 public:
30.239 /// Constructor.
30.240
30.241 - /// This constructor does not require parameters, therefore it initiates
30.242 + /// This constructor does not require parameters, it initiates
30.243 /// all of the attributes to \c 0.
30.244 DfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
30.245 _dist(0), _path(0), _di(0) {}
30.246 @@ -899,7 +892,6 @@
30.247 {
30.248 typedef TR Base;
30.249
30.250 - ///The type of the digraph the algorithm runs on.
30.251 typedef typename TR::Digraph Digraph;
30.252
30.253 typedef typename Digraph::Node Node;
30.254 @@ -907,16 +899,10 @@
30.255 typedef typename Digraph::Arc Arc;
30.256 typedef typename Digraph::OutArcIt OutArcIt;
30.257
30.258 - ///\brief The type of the map that stores the predecessor
30.259 - ///arcs of the DFS paths.
30.260 typedef typename TR::PredMap PredMap;
30.261 - ///\brief The type of the map that stores the distances of the nodes.
30.262 typedef typename TR::DistMap DistMap;
30.263 - ///\brief The type of the map that indicates which nodes are reached.
30.264 typedef typename TR::ReachedMap ReachedMap;
30.265 - ///\brief The type of the map that indicates which nodes are processed.
30.266 typedef typename TR::ProcessedMap ProcessedMap;
30.267 - ///The type of the DFS paths
30.268 typedef typename TR::Path Path;
30.269
30.270 public:
30.271 @@ -986,8 +972,8 @@
30.272
30.273 ///Runs DFS algorithm to visit all nodes in the digraph.
30.274
30.275 - ///This method runs DFS algorithm in order to compute
30.276 - ///the DFS path to each node.
30.277 + ///This method runs DFS algorithm in order to visit all nodes
30.278 + ///in the digraph.
30.279 void run()
30.280 {
30.281 run(INVALID);
30.282 @@ -999,11 +985,12 @@
30.283 static PredMap *createPredMap(const Digraph &) { return 0; };
30.284 SetPredMapBase(const TR &b) : TR(b) {}
30.285 };
30.286 - ///\brief \ref named-func-param "Named parameter"
30.287 - ///for setting PredMap object.
30.288 +
30.289 + ///\brief \ref named-templ-param "Named parameter" for setting
30.290 + ///the predecessor map.
30.291 ///
30.292 - ///\ref named-func-param "Named parameter"
30.293 - ///for setting PredMap object.
30.294 + ///\ref named-templ-param "Named parameter" function for setting
30.295 + ///the map that stores the predecessor arcs of the nodes.
30.296 template<class T>
30.297 DfsWizard<SetPredMapBase<T> > predMap(const T &t)
30.298 {
30.299 @@ -1017,11 +1004,12 @@
30.300 static ReachedMap *createReachedMap(const Digraph &) { return 0; };
30.301 SetReachedMapBase(const TR &b) : TR(b) {}
30.302 };
30.303 - ///\brief \ref named-func-param "Named parameter"
30.304 - ///for setting ReachedMap object.
30.305 +
30.306 + ///\brief \ref named-templ-param "Named parameter" for setting
30.307 + ///the reached map.
30.308 ///
30.309 - /// \ref named-func-param "Named parameter"
30.310 - ///for setting ReachedMap object.
30.311 + ///\ref named-templ-param "Named parameter" function for setting
30.312 + ///the map that indicates which nodes are reached.
30.313 template<class T>
30.314 DfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
30.315 {
30.316 @@ -1035,11 +1023,13 @@
30.317 static DistMap *createDistMap(const Digraph &) { return 0; };
30.318 SetDistMapBase(const TR &b) : TR(b) {}
30.319 };
30.320 - ///\brief \ref named-func-param "Named parameter"
30.321 - ///for setting DistMap object.
30.322 +
30.323 + ///\brief \ref named-templ-param "Named parameter" for setting
30.324 + ///the distance map.
30.325 ///
30.326 - /// \ref named-func-param "Named parameter"
30.327 - ///for setting DistMap object.
30.328 + ///\ref named-templ-param "Named parameter" function for setting
30.329 + ///the map that stores the distances of the nodes calculated
30.330 + ///by the algorithm.
30.331 template<class T>
30.332 DfsWizard<SetDistMapBase<T> > distMap(const T &t)
30.333 {
30.334 @@ -1053,11 +1043,12 @@
30.335 static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
30.336 SetProcessedMapBase(const TR &b) : TR(b) {}
30.337 };
30.338 - ///\brief \ref named-func-param "Named parameter"
30.339 - ///for setting ProcessedMap object.
30.340 +
30.341 + ///\brief \ref named-func-param "Named parameter" for setting
30.342 + ///the processed map.
30.343 ///
30.344 - /// \ref named-func-param "Named parameter"
30.345 - ///for setting ProcessedMap object.
30.346 + ///\ref named-templ-param "Named parameter" function for setting
30.347 + ///the map that indicates which nodes are processed.
30.348 template<class T>
30.349 DfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
30.350 {
30.351 @@ -1208,7 +1199,7 @@
30.352 /// \brief The type of the map that indicates which nodes are reached.
30.353 ///
30.354 /// The type of the map that indicates which nodes are reached.
30.355 - /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
30.356 + /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
30.357 typedef typename Digraph::template NodeMap<bool> ReachedMap;
30.358
30.359 /// \brief Instantiates a ReachedMap.
30.360 @@ -1369,8 +1360,8 @@
30.361 /// \name Execution Control
30.362 /// The simplest way to execute the DFS algorithm is to use one of the
30.363 /// member functions called \ref run(Node) "run()".\n
30.364 - /// If you need more control on the execution, first you have to call
30.365 - /// \ref init(), then you can add a source node with \ref addSource()
30.366 + /// If you need better control on the execution, you have to call
30.367 + /// \ref init() first, then you can add a source node with \ref addSource()
30.368 /// and perform the actual computation with \ref start().
30.369 /// This procedure can be repeated if there are nodes that have not
30.370 /// been reached.
30.371 @@ -1583,12 +1574,8 @@
30.372
30.373 /// \brief Runs the algorithm to visit all nodes in the digraph.
30.374
30.375 - /// This method runs the %DFS algorithm in order to
30.376 - /// compute the %DFS path to each node.
30.377 - ///
30.378 - /// The algorithm computes
30.379 - /// - the %DFS tree (forest),
30.380 - /// - the distance of each node from the root(s) in the %DFS tree.
30.381 + /// This method runs the %DFS algorithm in order to visit all nodes
30.382 + /// in the digraph.
30.383 ///
30.384 /// \note <tt>d.run()</tt> is just a shortcut of the following code.
30.385 ///\code
30.386 @@ -1620,7 +1607,7 @@
30.387
30.388 ///@{
30.389
30.390 - /// \brief Checks if a node is reached from the root(s).
30.391 + /// \brief Checks if the given node is reached from the root(s).
30.392 ///
30.393 /// Returns \c true if \c v is reached from the root(s).
30.394 ///
31.1 --- a/lemon/dijkstra.h Sun Oct 04 10:15:32 2009 +0200
31.2 +++ b/lemon/dijkstra.h Wed Dec 09 11:14:06 2009 +0100
31.3 @@ -70,9 +70,9 @@
31.4 ///The type of the map that stores the arc lengths.
31.5
31.6 ///The type of the map that stores the arc lengths.
31.7 - ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
31.8 + ///It must conform to the \ref concepts::ReadMap "ReadMap" concept.
31.9 typedef LEN LengthMap;
31.10 - ///The type of the length of the arcs.
31.11 + ///The type of the arc lengths.
31.12 typedef typename LEN::Value Value;
31.13
31.14 /// Operation traits for %Dijkstra algorithm.
31.15 @@ -116,7 +116,7 @@
31.16 ///
31.17 ///The type of the map that stores the predecessor
31.18 ///arcs of the shortest paths.
31.19 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
31.20 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
31.21 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
31.22 ///Instantiates a \c PredMap.
31.23
31.24 @@ -131,8 +131,8 @@
31.25 ///The type of the map that indicates which nodes are processed.
31.26
31.27 ///The type of the map that indicates which nodes are processed.
31.28 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
31.29 - ///By default it is a NullMap.
31.30 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
31.31 + ///By default, it is a NullMap.
31.32 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
31.33 ///Instantiates a \c ProcessedMap.
31.34
31.35 @@ -151,7 +151,7 @@
31.36 ///The type of the map that stores the distances of the nodes.
31.37
31.38 ///The type of the map that stores the distances of the nodes.
31.39 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
31.40 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
31.41 typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap;
31.42 ///Instantiates a \c DistMap.
31.43
31.44 @@ -169,6 +169,10 @@
31.45 /// \ingroup shortest_path
31.46 ///This class provides an efficient implementation of the %Dijkstra algorithm.
31.47 ///
31.48 + ///The %Dijkstra algorithm solves the single-source shortest path problem
31.49 + ///when all arc lengths are non-negative. If there are negative lengths,
31.50 + ///the BellmanFord algorithm should be used instead.
31.51 + ///
31.52 ///The arc lengths are passed to the algorithm using a
31.53 ///\ref concepts::ReadMap "ReadMap",
31.54 ///so it is easy to change it to any kind of length.
31.55 @@ -201,8 +205,8 @@
31.56 ///The type of the digraph the algorithm runs on.
31.57 typedef typename TR::Digraph Digraph;
31.58
31.59 - ///The type of the length of the arcs.
31.60 - typedef typename TR::LengthMap::Value Value;
31.61 + ///The type of the arc lengths.
31.62 + typedef typename TR::Value Value;
31.63 ///The type of the map that stores the arc lengths.
31.64 typedef typename TR::LengthMap LengthMap;
31.65 ///\brief The type of the map that stores the predecessor arcs of the
31.66 @@ -304,7 +308,7 @@
31.67 ///
31.68 ///\ref named-templ-param "Named parameter" for setting
31.69 ///\c PredMap type.
31.70 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
31.71 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
31.72 template <class T>
31.73 struct SetPredMap
31.74 : public Dijkstra< Digraph, LengthMap, SetPredMapTraits<T> > {
31.75 @@ -325,7 +329,7 @@
31.76 ///
31.77 ///\ref named-templ-param "Named parameter" for setting
31.78 ///\c DistMap type.
31.79 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
31.80 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
31.81 template <class T>
31.82 struct SetDistMap
31.83 : public Dijkstra< Digraph, LengthMap, SetDistMapTraits<T> > {
31.84 @@ -346,7 +350,7 @@
31.85 ///
31.86 ///\ref named-templ-param "Named parameter" for setting
31.87 ///\c ProcessedMap type.
31.88 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
31.89 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
31.90 template <class T>
31.91 struct SetProcessedMap
31.92 : public Dijkstra< Digraph, LengthMap, SetProcessedMapTraits<T> > {
31.93 @@ -422,7 +426,7 @@
31.94 ///automatically created by the algorithm (i.e. the digraph should be
31.95 ///passed to the constructor of the cross reference and the cross
31.96 ///reference should be passed to the constructor of the heap).
31.97 - ///However external heap and cross reference objects could also be
31.98 + ///However, external heap and cross reference objects could also be
31.99 ///passed to the algorithm using the \ref heap() function before
31.100 ///calling \ref run(Node) "run()" or \ref init().
31.101 ///\sa SetHeap
31.102 @@ -443,6 +447,7 @@
31.103 ///
31.104 ///\ref named-templ-param "Named parameter" for setting
31.105 ///\c OperationTraits type.
31.106 + /// For more information, see \ref DijkstraDefaultOperationTraits.
31.107 template <class T>
31.108 struct SetOperationTraits
31.109 : public Dijkstra<Digraph, LengthMap, SetOperationTraitsTraits<T> > {
31.110 @@ -584,8 +589,8 @@
31.111 ///\name Execution Control
31.112 ///The simplest way to execute the %Dijkstra algorithm is to use
31.113 ///one of the member functions called \ref run(Node) "run()".\n
31.114 - ///If you need more control on the execution, first you have to call
31.115 - ///\ref init(), then you can add several source nodes with
31.116 + ///If you need better control on the execution, you have to call
31.117 + ///\ref init() first, then you can add several source nodes with
31.118 ///\ref addSource(). Finally the actual path computation can be
31.119 ///performed with one of the \ref start() functions.
31.120
31.121 @@ -801,14 +806,14 @@
31.122 ///\name Query Functions
31.123 ///The results of the %Dijkstra algorithm can be obtained using these
31.124 ///functions.\n
31.125 - ///Either \ref run(Node) "run()" or \ref start() should be called
31.126 + ///Either \ref run(Node) "run()" or \ref init() should be called
31.127 ///before using them.
31.128
31.129 ///@{
31.130
31.131 - ///The shortest path to a node.
31.132 + ///The shortest path to the given node.
31.133
31.134 - ///Returns the shortest path to a node.
31.135 + ///Returns the shortest path to the given node from the root(s).
31.136 ///
31.137 ///\warning \c t should be reached from the root(s).
31.138 ///
31.139 @@ -816,9 +821,9 @@
31.140 ///must be called before using this function.
31.141 Path path(Node t) const { return Path(*G, *_pred, t); }
31.142
31.143 - ///The distance of a node from the root(s).
31.144 + ///The distance of the given node from the root(s).
31.145
31.146 - ///Returns the distance of a node from the root(s).
31.147 + ///Returns the distance of the given node from the root(s).
31.148 ///
31.149 ///\warning If node \c v is not reached from the root(s), then
31.150 ///the return value of this function is undefined.
31.151 @@ -827,29 +832,31 @@
31.152 ///must be called before using this function.
31.153 Value dist(Node v) const { return (*_dist)[v]; }
31.154
31.155 - ///Returns the 'previous arc' of the shortest path tree for a node.
31.156 -
31.157 + ///\brief Returns the 'previous arc' of the shortest path tree for
31.158 + ///the given node.
31.159 + ///
31.160 ///This function returns the 'previous arc' of the shortest path
31.161 ///tree for the node \c v, i.e. it returns the last arc of a
31.162 ///shortest path from a root to \c v. It is \c INVALID if \c v
31.163 ///is not reached from the root(s) or if \c v is a root.
31.164 ///
31.165 ///The shortest path tree used here is equal to the shortest path
31.166 - ///tree used in \ref predNode().
31.167 + ///tree used in \ref predNode() and \ref predMap().
31.168 ///
31.169 ///\pre Either \ref run(Node) "run()" or \ref init()
31.170 ///must be called before using this function.
31.171 Arc predArc(Node v) const { return (*_pred)[v]; }
31.172
31.173 - ///Returns the 'previous node' of the shortest path tree for a node.
31.174 -
31.175 + ///\brief Returns the 'previous node' of the shortest path tree for
31.176 + ///the given node.
31.177 + ///
31.178 ///This function returns the 'previous node' of the shortest path
31.179 ///tree for the node \c v, i.e. it returns the last but one node
31.180 - ///from a shortest path from a root to \c v. It is \c INVALID
31.181 + ///of a shortest path from a root to \c v. It is \c INVALID
31.182 ///if \c v is not reached from the root(s) or if \c v is a root.
31.183 ///
31.184 ///The shortest path tree used here is equal to the shortest path
31.185 - ///tree used in \ref predArc().
31.186 + ///tree used in \ref predArc() and \ref predMap().
31.187 ///
31.188 ///\pre Either \ref run(Node) "run()" or \ref init()
31.189 ///must be called before using this function.
31.190 @@ -870,13 +877,13 @@
31.191 ///predecessor arcs.
31.192 ///
31.193 ///Returns a const reference to the node map that stores the predecessor
31.194 - ///arcs, which form the shortest path tree.
31.195 + ///arcs, which form the shortest path tree (forest).
31.196 ///
31.197 ///\pre Either \ref run(Node) "run()" or \ref init()
31.198 ///must be called before using this function.
31.199 const PredMap &predMap() const { return *_pred;}
31.200
31.201 - ///Checks if a node is reached from the root(s).
31.202 + ///Checks if the given node is reached from the root(s).
31.203
31.204 ///Returns \c true if \c v is reached from the root(s).
31.205 ///
31.206 @@ -895,9 +902,9 @@
31.207 bool processed(Node v) const { return (*_heap_cross_ref)[v] ==
31.208 Heap::POST_HEAP; }
31.209
31.210 - ///The current distance of a node from the root(s).
31.211 + ///The current distance of the given node from the root(s).
31.212
31.213 - ///Returns the current distance of a node from the root(s).
31.214 + ///Returns the current distance of the given node from the root(s).
31.215 ///It may be decreased in the following processes.
31.216 ///
31.217 ///\pre Either \ref run(Node) "run()" or \ref init()
31.218 @@ -924,9 +931,9 @@
31.219 ///The type of the map that stores the arc lengths.
31.220
31.221 ///The type of the map that stores the arc lengths.
31.222 - ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
31.223 + ///It must conform to the \ref concepts::ReadMap "ReadMap" concept.
31.224 typedef LEN LengthMap;
31.225 - ///The type of the length of the arcs.
31.226 + ///The type of the arc lengths.
31.227 typedef typename LEN::Value Value;
31.228
31.229 /// Operation traits for Dijkstra algorithm.
31.230 @@ -973,7 +980,7 @@
31.231 ///
31.232 ///The type of the map that stores the predecessor
31.233 ///arcs of the shortest paths.
31.234 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
31.235 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
31.236 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
31.237 ///Instantiates a PredMap.
31.238
31.239 @@ -988,8 +995,8 @@
31.240 ///The type of the map that indicates which nodes are processed.
31.241
31.242 ///The type of the map that indicates which nodes are processed.
31.243 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
31.244 - ///By default it is a NullMap.
31.245 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
31.246 + ///By default, it is a NullMap.
31.247 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
31.248 ///Instantiates a ProcessedMap.
31.249
31.250 @@ -1008,7 +1015,7 @@
31.251 ///The type of the map that stores the distances of the nodes.
31.252
31.253 ///The type of the map that stores the distances of the nodes.
31.254 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
31.255 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
31.256 typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap;
31.257 ///Instantiates a DistMap.
31.258
31.259 @@ -1023,18 +1030,15 @@
31.260 ///The type of the shortest paths.
31.261
31.262 ///The type of the shortest paths.
31.263 - ///It must meet the \ref concepts::Path "Path" concept.
31.264 + ///It must conform to the \ref concepts::Path "Path" concept.
31.265 typedef lemon::Path<Digraph> Path;
31.266 };
31.267
31.268 /// Default traits class used by DijkstraWizard
31.269
31.270 - /// To make it easier to use Dijkstra algorithm
31.271 - /// we have created a wizard class.
31.272 - /// This \ref DijkstraWizard class needs default traits,
31.273 - /// as well as the \ref Dijkstra class.
31.274 - /// The \ref DijkstraWizardBase is a class to be the default traits of the
31.275 - /// \ref DijkstraWizard class.
31.276 + /// Default traits class used by DijkstraWizard.
31.277 + /// \tparam GR The type of the digraph.
31.278 + /// \tparam LEN The type of the length map.
31.279 template<typename GR, typename LEN>
31.280 class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LEN>
31.281 {
31.282 @@ -1093,7 +1097,6 @@
31.283 {
31.284 typedef TR Base;
31.285
31.286 - ///The type of the digraph the algorithm runs on.
31.287 typedef typename TR::Digraph Digraph;
31.288
31.289 typedef typename Digraph::Node Node;
31.290 @@ -1101,20 +1104,12 @@
31.291 typedef typename Digraph::Arc Arc;
31.292 typedef typename Digraph::OutArcIt OutArcIt;
31.293
31.294 - ///The type of the map that stores the arc lengths.
31.295 typedef typename TR::LengthMap LengthMap;
31.296 - ///The type of the length of the arcs.
31.297 typedef typename LengthMap::Value Value;
31.298 - ///\brief The type of the map that stores the predecessor
31.299 - ///arcs of the shortest paths.
31.300 typedef typename TR::PredMap PredMap;
31.301 - ///The type of the map that stores the distances of the nodes.
31.302 typedef typename TR::DistMap DistMap;
31.303 - ///The type of the map that indicates which nodes are processed.
31.304 typedef typename TR::ProcessedMap ProcessedMap;
31.305 - ///The type of the shortest paths
31.306 typedef typename TR::Path Path;
31.307 - ///The heap type used by the dijkstra algorithm.
31.308 typedef typename TR::Heap Heap;
31.309
31.310 public:
31.311 @@ -1186,11 +1181,12 @@
31.312 static PredMap *createPredMap(const Digraph &) { return 0; };
31.313 SetPredMapBase(const TR &b) : TR(b) {}
31.314 };
31.315 - ///\brief \ref named-func-param "Named parameter"
31.316 - ///for setting PredMap object.
31.317 +
31.318 + ///\brief \ref named-templ-param "Named parameter" for setting
31.319 + ///the predecessor map.
31.320 ///
31.321 - ///\ref named-func-param "Named parameter"
31.322 - ///for setting PredMap object.
31.323 + ///\ref named-templ-param "Named parameter" function for setting
31.324 + ///the map that stores the predecessor arcs of the nodes.
31.325 template<class T>
31.326 DijkstraWizard<SetPredMapBase<T> > predMap(const T &t)
31.327 {
31.328 @@ -1204,11 +1200,13 @@
31.329 static DistMap *createDistMap(const Digraph &) { return 0; };
31.330 SetDistMapBase(const TR &b) : TR(b) {}
31.331 };
31.332 - ///\brief \ref named-func-param "Named parameter"
31.333 - ///for setting DistMap object.
31.334 +
31.335 + ///\brief \ref named-templ-param "Named parameter" for setting
31.336 + ///the distance map.
31.337 ///
31.338 - ///\ref named-func-param "Named parameter"
31.339 - ///for setting DistMap object.
31.340 + ///\ref named-templ-param "Named parameter" function for setting
31.341 + ///the map that stores the distances of the nodes calculated
31.342 + ///by the algorithm.
31.343 template<class T>
31.344 DijkstraWizard<SetDistMapBase<T> > distMap(const T &t)
31.345 {
31.346 @@ -1222,11 +1220,12 @@
31.347 static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
31.348 SetProcessedMapBase(const TR &b) : TR(b) {}
31.349 };
31.350 - ///\brief \ref named-func-param "Named parameter"
31.351 - ///for setting ProcessedMap object.
31.352 +
31.353 + ///\brief \ref named-func-param "Named parameter" for setting
31.354 + ///the processed map.
31.355 ///
31.356 - /// \ref named-func-param "Named parameter"
31.357 - ///for setting ProcessedMap object.
31.358 + ///\ref named-templ-param "Named parameter" function for setting
31.359 + ///the map that indicates which nodes are processed.
31.360 template<class T>
31.361 DijkstraWizard<SetProcessedMapBase<T> > processedMap(const T &t)
31.362 {
31.363 @@ -1239,6 +1238,7 @@
31.364 typedef T Path;
31.365 SetPathBase(const TR &b) : TR(b) {}
31.366 };
31.367 +
31.368 ///\brief \ref named-func-param "Named parameter"
31.369 ///for getting the shortest path to the target node.
31.370 ///
32.1 --- a/lemon/dim2.h Sun Oct 04 10:15:32 2009 +0200
32.2 +++ b/lemon/dim2.h Wed Dec 09 11:14:06 2009 +0100
32.3 @@ -21,16 +21,9 @@
32.4
32.5 #include <iostream>
32.6
32.7 -///\ingroup misc
32.8 +///\ingroup geomdat
32.9 ///\file
32.10 ///\brief A simple two dimensional vector and a bounding box implementation
32.11 -///
32.12 -/// The class \ref lemon::dim2::Point "dim2::Point" implements
32.13 -/// a two dimensional vector with the usual operations.
32.14 -///
32.15 -/// The class \ref lemon::dim2::Box "dim2::Box" can be used to determine
32.16 -/// the rectangular bounding box of a set of
32.17 -/// \ref lemon::dim2::Point "dim2::Point"'s.
32.18
32.19 namespace lemon {
32.20
32.21 @@ -40,7 +33,7 @@
32.22 ///tools for handling two dimensional coordinates
32.23 namespace dim2 {
32.24
32.25 - /// \addtogroup misc
32.26 + /// \addtogroup geomdat
32.27 /// @{
32.28
32.29 /// Two dimensional vector (plain vector)
33.1 --- a/lemon/edge_set.h Sun Oct 04 10:15:32 2009 +0200
33.2 +++ b/lemon/edge_set.h Wed Dec 09 11:14:06 2009 +0100
33.3 @@ -255,13 +255,14 @@
33.4 /// that node can be removed from the underlying graph, in this case
33.5 /// all arcs incident to the given node is erased from the arc set.
33.6 ///
33.7 + /// This class fully conforms to the \ref concepts::Digraph
33.8 + /// "Digraph" concept.
33.9 + /// It provides only linear time counting for nodes and arcs.
33.10 + ///
33.11 /// \param GR The type of the graph which shares its node set with
33.12 /// this class. Its interface must conform to the
33.13 /// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph"
33.14 /// concept.
33.15 - ///
33.16 - /// This class fully conforms to the \ref concepts::Digraph
33.17 - /// "Digraph" concept.
33.18 template <typename GR>
33.19 class ListArcSet : public ArcSetExtender<ListArcSetBase<GR> > {
33.20 typedef ArcSetExtender<ListArcSetBase<GR> > Parent;
33.21 @@ -685,13 +686,14 @@
33.22 /// be removed from the underlying graph, in this case all edges
33.23 /// incident to the given node is erased from the arc set.
33.24 ///
33.25 + /// This class fully conforms to the \ref concepts::Graph "Graph"
33.26 + /// concept.
33.27 + /// It provides only linear time counting for nodes, edges and arcs.
33.28 + ///
33.29 /// \param GR The type of the graph which shares its node set
33.30 /// with this class. Its interface must conform to the
33.31 /// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph"
33.32 /// concept.
33.33 - ///
33.34 - /// This class fully conforms to the \ref concepts::Graph "Graph"
33.35 - /// concept.
33.36 template <typename GR>
33.37 class ListEdgeSet : public EdgeSetExtender<ListEdgeSetBase<GR> > {
33.38 typedef EdgeSetExtender<ListEdgeSetBase<GR> > Parent;
33.39 @@ -867,7 +869,7 @@
33.40 arc.id = arcs.size() - 1;
33.41 }
33.42
33.43 - void next(Arc& arc) const {
33.44 + static void next(Arc& arc) {
33.45 --arc.id;
33.46 }
33.47
33.48 @@ -954,13 +956,14 @@
33.49 /// single-linked lists for enumerate outgoing and incoming
33.50 /// arcs. Therefore the arcs cannot be erased from the arc sets.
33.51 ///
33.52 + /// This class fully conforms to the \ref concepts::Digraph "Digraph"
33.53 + /// concept.
33.54 + /// It provides only linear time counting for nodes and arcs.
33.55 + ///
33.56 /// \warning If a node is erased from the underlying graph and this
33.57 /// node is the source or target of one arc in the arc set, then
33.58 /// the arc set is invalidated, and it cannot be used anymore. The
33.59 /// validity can be checked with the \c valid() member function.
33.60 - ///
33.61 - /// This class fully conforms to the \ref concepts::Digraph
33.62 - /// "Digraph" concept.
33.63 template <typename GR>
33.64 class SmartArcSet : public ArcSetExtender<SmartArcSetBase<GR> > {
33.65 typedef ArcSetExtender<SmartArcSetBase<GR> > Parent;
33.66 @@ -1173,7 +1176,7 @@
33.67 arc.id = arcs.size() - 1;
33.68 }
33.69
33.70 - void next(Arc& arc) const {
33.71 + static void next(Arc& arc) {
33.72 --arc.id;
33.73 }
33.74
33.75 @@ -1181,7 +1184,7 @@
33.76 arc.id = arcs.size() / 2 - 1;
33.77 }
33.78
33.79 - void next(Edge& arc) const {
33.80 + static void next(Edge& arc) {
33.81 --arc.id;
33.82 }
33.83
33.84 @@ -1304,13 +1307,14 @@
33.85 /// single-linked lists for enumerate incident edges. Therefore the
33.86 /// edges cannot be erased from the edge sets.
33.87 ///
33.88 + /// This class fully conforms to the \ref concepts::Graph "Graph"
33.89 + /// concept.
33.90 + /// It provides only linear time counting for nodes, edges and arcs.
33.91 + ///
33.92 /// \warning If a node is erased from the underlying graph and this
33.93 /// node is incident to one edge in the edge set, then the edge set
33.94 /// is invalidated, and it cannot be used anymore. The validity can
33.95 /// be checked with the \c valid() member function.
33.96 - ///
33.97 - /// This class fully conforms to the \ref concepts::Graph
33.98 - /// "Graph" concept.
33.99 template <typename GR>
33.100 class SmartEdgeSet : public EdgeSetExtender<SmartEdgeSetBase<GR> > {
33.101 typedef EdgeSetExtender<SmartEdgeSetBase<GR> > Parent;
34.1 --- a/lemon/full_graph.h Sun Oct 04 10:15:32 2009 +0200
34.2 +++ b/lemon/full_graph.h Wed Dec 09 11:14:06 2009 +0100
34.3 @@ -24,7 +24,7 @@
34.4
34.5 ///\ingroup graphs
34.6 ///\file
34.7 -///\brief FullGraph and FullDigraph classes.
34.8 +///\brief FullDigraph and FullGraph classes.
34.9
34.10 namespace lemon {
34.11
34.12 @@ -51,7 +51,7 @@
34.13 typedef True ArcNumTag;
34.14
34.15 Node operator()(int ix) const { return Node(ix); }
34.16 - int index(const Node& node) const { return node._id; }
34.17 + static int index(const Node& node) { return node._id; }
34.18
34.19 Arc arc(const Node& s, const Node& t) const {
34.20 return Arc(s._id * _node_num + t._id);
34.21 @@ -148,24 +148,28 @@
34.22
34.23 /// \ingroup graphs
34.24 ///
34.25 - /// \brief A full digraph class.
34.26 + /// \brief A directed full graph class.
34.27 ///
34.28 - /// This is a simple and fast directed full graph implementation.
34.29 - /// From each node go arcs to each node (including the source node),
34.30 - /// therefore the number of the arcs in the digraph is the square of
34.31 - /// the node number. This digraph type is completely static, so you
34.32 - /// can neither add nor delete either arcs or nodes, and it needs
34.33 - /// constant space in memory.
34.34 + /// FullDigraph is a simple and fast implmenetation of directed full
34.35 + /// (complete) graphs. It contains an arc from each node to each node
34.36 + /// (including a loop for each node), therefore the number of arcs
34.37 + /// is the square of the number of nodes.
34.38 + /// This class is completely static and it needs constant memory space.
34.39 + /// Thus you can neither add nor delete nodes or arcs, however
34.40 + /// the structure can be resized using resize().
34.41 ///
34.42 - /// This class fully conforms to the \ref concepts::Digraph
34.43 - /// "Digraph concept".
34.44 + /// This type fully conforms to the \ref concepts::Digraph "Digraph concept".
34.45 + /// Most of its member functions and nested classes are documented
34.46 + /// only in the concept class.
34.47 ///
34.48 - /// The \c FullDigraph and \c FullGraph classes are very similar,
34.49 + /// This class provides constant time counting for nodes and arcs.
34.50 + ///
34.51 + /// \note FullDigraph and FullGraph classes are very similar,
34.52 /// but there are two differences. While this class conforms only
34.53 - /// to the \ref concepts::Digraph "Digraph" concept, the \c FullGraph
34.54 - /// class conforms to the \ref concepts::Graph "Graph" concept,
34.55 - /// moreover \c FullGraph does not contain a loop arc for each
34.56 - /// node as \c FullDigraph does.
34.57 + /// to the \ref concepts::Digraph "Digraph" concept, FullGraph
34.58 + /// conforms to the \ref concepts::Graph "Graph" concept,
34.59 + /// moreover FullGraph does not contain a loop for each
34.60 + /// node as this class does.
34.61 ///
34.62 /// \sa FullGraph
34.63 class FullDigraph : public ExtendedFullDigraphBase {
34.64 @@ -173,7 +177,9 @@
34.65
34.66 public:
34.67
34.68 - /// \brief Constructor
34.69 + /// \brief Default constructor.
34.70 + ///
34.71 + /// Default constructor. The number of nodes and arcs will be zero.
34.72 FullDigraph() { construct(0); }
34.73
34.74 /// \brief Constructor
34.75 @@ -184,8 +190,8 @@
34.76
34.77 /// \brief Resizes the digraph
34.78 ///
34.79 - /// Resizes the digraph. The function will fully destroy and
34.80 - /// rebuild the digraph. This cause that the maps of the digraph will
34.81 + /// This function resizes the digraph. It fully destroys and
34.82 + /// rebuilds the structure, therefore the maps of the digraph will be
34.83 /// reallocated automatically and the previous values will be lost.
34.84 void resize(int n) {
34.85 Parent::notifier(Arc()).clear();
34.86 @@ -197,24 +203,26 @@
34.87
34.88 /// \brief Returns the node with the given index.
34.89 ///
34.90 - /// Returns the node with the given index. Since it is a static
34.91 - /// digraph its nodes can be indexed with integers from the range
34.92 - /// <tt>[0..nodeNum()-1]</tt>.
34.93 + /// Returns the node with the given index. Since this structure is
34.94 + /// completely static, the nodes can be indexed with integers from
34.95 + /// the range <tt>[0..nodeNum()-1]</tt>.
34.96 + /// The index of a node is the same as its ID.
34.97 /// \sa index()
34.98 Node operator()(int ix) const { return Parent::operator()(ix); }
34.99
34.100 /// \brief Returns the index of the given node.
34.101 ///
34.102 - /// Returns the index of the given node. Since it is a static
34.103 - /// digraph its nodes can be indexed with integers from the range
34.104 - /// <tt>[0..nodeNum()-1]</tt>.
34.105 - /// \sa operator()
34.106 - int index(const Node& node) const { return Parent::index(node); }
34.107 + /// Returns the index of the given node. Since this structure is
34.108 + /// completely static, the nodes can be indexed with integers from
34.109 + /// the range <tt>[0..nodeNum()-1]</tt>.
34.110 + /// The index of a node is the same as its ID.
34.111 + /// \sa operator()()
34.112 + static int index(const Node& node) { return Parent::index(node); }
34.113
34.114 /// \brief Returns the arc connecting the given nodes.
34.115 ///
34.116 /// Returns the arc connecting the given nodes.
34.117 - Arc arc(const Node& u, const Node& v) const {
34.118 + Arc arc(Node u, Node v) const {
34.119 return Parent::arc(u, v);
34.120 }
34.121
34.122 @@ -283,7 +291,7 @@
34.123 public:
34.124
34.125 Node operator()(int ix) const { return Node(ix); }
34.126 - int index(const Node& node) const { return node._id; }
34.127 + static int index(const Node& node) { return node._id; }
34.128
34.129 Edge edge(const Node& u, const Node& v) const {
34.130 if (u._id < v._id) {
34.131 @@ -520,21 +528,25 @@
34.132 ///
34.133 /// \brief An undirected full graph class.
34.134 ///
34.135 - /// This is a simple and fast undirected full graph
34.136 - /// implementation. From each node go edge to each other node,
34.137 - /// therefore the number of edges in the graph is \f$n(n-1)/2\f$.
34.138 - /// This graph type is completely static, so you can neither
34.139 - /// add nor delete either edges or nodes, and it needs constant
34.140 - /// space in memory.
34.141 + /// FullGraph is a simple and fast implmenetation of undirected full
34.142 + /// (complete) graphs. It contains an edge between every distinct pair
34.143 + /// of nodes, therefore the number of edges is <tt>n(n-1)/2</tt>.
34.144 + /// This class is completely static and it needs constant memory space.
34.145 + /// Thus you can neither add nor delete nodes or edges, however
34.146 + /// the structure can be resized using resize().
34.147 ///
34.148 - /// This class fully conforms to the \ref concepts::Graph "Graph concept".
34.149 + /// This type fully conforms to the \ref concepts::Graph "Graph concept".
34.150 + /// Most of its member functions and nested classes are documented
34.151 + /// only in the concept class.
34.152 ///
34.153 - /// The \c FullGraph and \c FullDigraph classes are very similar,
34.154 - /// but there are two differences. While the \c FullDigraph class
34.155 + /// This class provides constant time counting for nodes, edges and arcs.
34.156 + ///
34.157 + /// \note FullDigraph and FullGraph classes are very similar,
34.158 + /// but there are two differences. While FullDigraph
34.159 /// conforms only to the \ref concepts::Digraph "Digraph" concept,
34.160 /// this class conforms to the \ref concepts::Graph "Graph" concept,
34.161 - /// moreover \c FullGraph does not contain a loop arc for each
34.162 - /// node as \c FullDigraph does.
34.163 + /// moreover this class does not contain a loop for each
34.164 + /// node as FullDigraph does.
34.165 ///
34.166 /// \sa FullDigraph
34.167 class FullGraph : public ExtendedFullGraphBase {
34.168 @@ -542,7 +554,9 @@
34.169
34.170 public:
34.171
34.172 - /// \brief Constructor
34.173 + /// \brief Default constructor.
34.174 + ///
34.175 + /// Default constructor. The number of nodes and edges will be zero.
34.176 FullGraph() { construct(0); }
34.177
34.178 /// \brief Constructor
34.179 @@ -553,8 +567,8 @@
34.180
34.181 /// \brief Resizes the graph
34.182 ///
34.183 - /// Resizes the graph. The function will fully destroy and
34.184 - /// rebuild the graph. This cause that the maps of the graph will
34.185 + /// This function resizes the graph. It fully destroys and
34.186 + /// rebuilds the structure, therefore the maps of the graph will be
34.187 /// reallocated automatically and the previous values will be lost.
34.188 void resize(int n) {
34.189 Parent::notifier(Arc()).clear();
34.190 @@ -568,31 +582,33 @@
34.191
34.192 /// \brief Returns the node with the given index.
34.193 ///
34.194 - /// Returns the node with the given index. Since it is a static
34.195 - /// graph its nodes can be indexed with integers from the range
34.196 - /// <tt>[0..nodeNum()-1]</tt>.
34.197 + /// Returns the node with the given index. Since this structure is
34.198 + /// completely static, the nodes can be indexed with integers from
34.199 + /// the range <tt>[0..nodeNum()-1]</tt>.
34.200 + /// The index of a node is the same as its ID.
34.201 /// \sa index()
34.202 Node operator()(int ix) const { return Parent::operator()(ix); }
34.203
34.204 /// \brief Returns the index of the given node.
34.205 ///
34.206 - /// Returns the index of the given node. Since it is a static
34.207 - /// graph its nodes can be indexed with integers from the range
34.208 - /// <tt>[0..nodeNum()-1]</tt>.
34.209 - /// \sa operator()
34.210 - int index(const Node& node) const { return Parent::index(node); }
34.211 + /// Returns the index of the given node. Since this structure is
34.212 + /// completely static, the nodes can be indexed with integers from
34.213 + /// the range <tt>[0..nodeNum()-1]</tt>.
34.214 + /// The index of a node is the same as its ID.
34.215 + /// \sa operator()()
34.216 + static int index(const Node& node) { return Parent::index(node); }
34.217
34.218 /// \brief Returns the arc connecting the given nodes.
34.219 ///
34.220 /// Returns the arc connecting the given nodes.
34.221 - Arc arc(const Node& s, const Node& t) const {
34.222 + Arc arc(Node s, Node t) const {
34.223 return Parent::arc(s, t);
34.224 }
34.225
34.226 - /// \brief Returns the edge connects the given nodes.
34.227 + /// \brief Returns the edge connecting the given nodes.
34.228 ///
34.229 - /// Returns the edge connects the given nodes.
34.230 - Edge edge(const Node& u, const Node& v) const {
34.231 + /// Returns the edge connecting the given nodes.
34.232 + Edge edge(Node u, Node v) const {
34.233 return Parent::edge(u, v);
34.234 }
34.235
35.1 --- a/lemon/glpk.cc Sun Oct 04 10:15:32 2009 +0200
35.2 +++ b/lemon/glpk.cc Wed Dec 09 11:14:06 2009 +0100
35.3 @@ -59,6 +59,42 @@
35.4 return i;
35.5 }
35.6
35.7 + int GlpkBase::_addRow(Value lo, ExprIterator b,
35.8 + ExprIterator e, Value up) {
35.9 + int i = glp_add_rows(lp, 1);
35.10 +
35.11 + if (lo == -INF) {
35.12 + if (up == INF) {
35.13 + glp_set_row_bnds(lp, i, GLP_FR, lo, up);
35.14 + } else {
35.15 + glp_set_row_bnds(lp, i, GLP_UP, lo, up);
35.16 + }
35.17 + } else {
35.18 + if (up == INF) {
35.19 + glp_set_row_bnds(lp, i, GLP_LO, lo, up);
35.20 + } else if (lo != up) {
35.21 + glp_set_row_bnds(lp, i, GLP_DB, lo, up);
35.22 + } else {
35.23 + glp_set_row_bnds(lp, i, GLP_FX, lo, up);
35.24 + }
35.25 + }
35.26 +
35.27 + std::vector<int> indexes;
35.28 + std::vector<Value> values;
35.29 +
35.30 + indexes.push_back(0);
35.31 + values.push_back(0);
35.32 +
35.33 + for(ExprIterator it = b; it != e; ++it) {
35.34 + indexes.push_back(it->first);
35.35 + values.push_back(it->second);
35.36 + }
35.37 +
35.38 + glp_set_mat_row(lp, i, values.size() - 1,
35.39 + &indexes.front(), &values.front());
35.40 + return i;
35.41 + }
35.42 +
35.43 void GlpkBase::_eraseCol(int i) {
35.44 int ca[2];
35.45 ca[1] = i;
36.1 --- a/lemon/glpk.h Sun Oct 04 10:15:32 2009 +0200
36.2 +++ b/lemon/glpk.h Wed Dec 09 11:14:06 2009 +0100
36.3 @@ -54,6 +54,7 @@
36.4
36.5 virtual int _addCol();
36.6 virtual int _addRow();
36.7 + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
36.8
36.9 virtual void _eraseCol(int i);
36.10 virtual void _eraseRow(int i);
37.1 --- a/lemon/gomory_hu.h Sun Oct 04 10:15:32 2009 +0200
37.2 +++ b/lemon/gomory_hu.h Wed Dec 09 11:14:06 2009 +0100
37.3 @@ -294,11 +294,9 @@
37.4 ///
37.5 /// \pre \ref run() must be called before using this function.
37.6 template <typename CutMap>
37.7 - Value minCutMap(const Node& s, ///<
37.8 + Value minCutMap(const Node& s,
37.9 const Node& t,
37.10 - ///<
37.11 CutMap& cutMap
37.12 - ///<
37.13 ) const {
37.14 Node sn = s, tn = t;
37.15 bool s_root=false;
37.16 @@ -359,10 +357,10 @@
37.17 /// This example counts the nodes in the minimum cut separating \c s from
37.18 /// \c t.
37.19 /// \code
37.20 - /// GomoruHu<Graph> gom(g, capacities);
37.21 + /// GomoryHu<Graph> gom(g, capacities);
37.22 /// gom.run();
37.23 /// int cnt=0;
37.24 - /// for(GomoruHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt;
37.25 + /// for(GomoryHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt;
37.26 /// \endcode
37.27 class MinCutNodeIt
37.28 {
37.29 @@ -394,7 +392,7 @@
37.30 /// MinCutNodeIt(gomory, t, s, false);
37.31 /// \endcode
37.32 /// does not necessarily give the same set of nodes.
37.33 - /// However it is ensured that
37.34 + /// However, it is ensured that
37.35 /// \code
37.36 /// MinCutNodeIt(gomory, s, t, true);
37.37 /// \endcode
37.38 @@ -456,10 +454,10 @@
37.39 /// This example computes the value of the minimum cut separating \c s from
37.40 /// \c t.
37.41 /// \code
37.42 - /// GomoruHu<Graph> gom(g, capacities);
37.43 + /// GomoryHu<Graph> gom(g, capacities);
37.44 /// gom.run();
37.45 /// int value=0;
37.46 - /// for(GomoruHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e)
37.47 + /// for(GomoryHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e)
37.48 /// value+=capacities[e];
37.49 /// \endcode
37.50 /// The result will be the same as the value returned by
38.1 --- a/lemon/graph_to_eps.h Sun Oct 04 10:15:32 2009 +0200
38.2 +++ b/lemon/graph_to_eps.h Wed Dec 09 11:14:06 2009 +0100
38.3 @@ -142,7 +142,7 @@
38.4 ///Constructor
38.5 ///\param gr Reference to the graph to be printed.
38.6 ///\param ost Reference to the output stream.
38.7 - ///By default it is <tt>std::cout</tt>.
38.8 + ///By default, it is <tt>std::cout</tt>.
38.9 ///\param pros If it is \c true, then the \c ostream referenced by \c os
38.10 ///will be explicitly deallocated by the destructor.
38.11 DefaultGraphToEpsTraits(const GR &gr, std::ostream& ost = std::cout,
38.12 @@ -512,7 +512,7 @@
38.13
38.14 ///Turn on/off pre-scaling
38.15
38.16 - ///By default graphToEps() rescales the whole image in order to avoid
38.17 + ///By default, graphToEps() rescales the whole image in order to avoid
38.18 ///very big or very small bounding boxes.
38.19 ///
38.20 ///This (p)rescaling can be turned off with this function.
38.21 @@ -1114,7 +1114,7 @@
38.22 ///Generates an EPS file from a graph.
38.23 ///\param g Reference to the graph to be printed.
38.24 ///\param os Reference to the output stream.
38.25 -///By default it is <tt>std::cout</tt>.
38.26 +///By default, it is <tt>std::cout</tt>.
38.27 ///
38.28 ///This function also has a lot of
38.29 ///\ref named-templ-func-param "named parameters",
38.30 @@ -1126,7 +1126,7 @@
38.31 /// .arcWidthScale(.4).run();
38.32 ///\endcode
38.33 ///
38.34 -///For more detailed examples see the \ref graph_to_eps_demo.cc demo file.
38.35 +///For more detailed examples, see the \ref graph_to_eps_demo.cc demo file.
38.36 ///
38.37 ///\warning Don't forget to put the \ref GraphToEps::run() "run()"
38.38 ///to the end of the parameter list.
39.1 --- a/lemon/grid_graph.h Sun Oct 04 10:15:32 2009 +0200
39.2 +++ b/lemon/grid_graph.h Wed Dec 09 11:14:06 2009 +0100
39.3 @@ -470,18 +470,22 @@
39.4 ///
39.5 /// \brief Grid graph class
39.6 ///
39.7 - /// This class implements a special graph type. The nodes of the
39.8 - /// graph can be indexed by two integer \c (i,j) value where \c i is
39.9 - /// in the \c [0..width()-1] range and j is in the \c
39.10 - /// [0..height()-1] range. Two nodes are connected in the graph if
39.11 - /// the indexes differ exactly on one position and exactly one is
39.12 - /// the difference. The nodes of the graph can be indexed by position
39.13 - /// with the \c operator()() function. The positions of the nodes can be
39.14 - /// get with \c pos(), \c col() and \c row() members. The outgoing
39.15 + /// GridGraph implements a special graph type. The nodes of the
39.16 + /// graph can be indexed by two integer values \c (i,j) where \c i is
39.17 + /// in the range <tt>[0..width()-1]</tt> and j is in the range
39.18 + /// <tt>[0..height()-1]</tt>. Two nodes are connected in the graph if
39.19 + /// the indices differ exactly on one position and the difference is
39.20 + /// also exactly one. The nodes of the graph can be obtained by position
39.21 + /// using the \c operator()() function and the indices of the nodes can
39.22 + /// be obtained using \c pos(), \c col() and \c row() members. The outgoing
39.23 /// arcs can be retrieved with the \c right(), \c up(), \c left()
39.24 /// and \c down() functions, where the bottom-left corner is the
39.25 /// origin.
39.26 ///
39.27 + /// This class is completely static and it needs constant memory space.
39.28 + /// Thus you can neither add nor delete nodes or edges, however
39.29 + /// the structure can be resized using resize().
39.30 + ///
39.31 /// \image html grid_graph.png
39.32 /// \image latex grid_graph.eps "Grid graph" width=\textwidth
39.33 ///
39.34 @@ -496,16 +500,21 @@
39.35 /// }
39.36 ///\endcode
39.37 ///
39.38 - /// This graph type fully conforms to the \ref concepts::Graph
39.39 - /// "Graph concept".
39.40 + /// This type fully conforms to the \ref concepts::Graph "Graph concept".
39.41 + /// Most of its member functions and nested classes are documented
39.42 + /// only in the concept class.
39.43 + ///
39.44 + /// This class provides constant time counting for nodes, edges and arcs.
39.45 class GridGraph : public ExtendedGridGraphBase {
39.46 typedef ExtendedGridGraphBase Parent;
39.47
39.48 public:
39.49
39.50 - /// \brief Map to get the indices of the nodes as dim2::Point<int>.
39.51 + /// \brief Map to get the indices of the nodes as \ref dim2::Point
39.52 + /// "dim2::Point<int>".
39.53 ///
39.54 - /// Map to get the indices of the nodes as dim2::Point<int>.
39.55 + /// Map to get the indices of the nodes as \ref dim2::Point
39.56 + /// "dim2::Point<int>".
39.57 class IndexMap {
39.58 public:
39.59 /// \brief The key type of the map
39.60 @@ -514,13 +523,9 @@
39.61 typedef dim2::Point<int> Value;
39.62
39.63 /// \brief Constructor
39.64 - ///
39.65 - /// Constructor
39.66 IndexMap(const GridGraph& graph) : _graph(graph) {}
39.67
39.68 /// \brief The subscript operator
39.69 - ///
39.70 - /// The subscript operator.
39.71 Value operator[](Key key) const {
39.72 return _graph.pos(key);
39.73 }
39.74 @@ -540,13 +545,9 @@
39.75 typedef int Value;
39.76
39.77 /// \brief Constructor
39.78 - ///
39.79 - /// Constructor
39.80 ColMap(const GridGraph& graph) : _graph(graph) {}
39.81
39.82 /// \brief The subscript operator
39.83 - ///
39.84 - /// The subscript operator.
39.85 Value operator[](Key key) const {
39.86 return _graph.col(key);
39.87 }
39.88 @@ -566,13 +567,9 @@
39.89 typedef int Value;
39.90
39.91 /// \brief Constructor
39.92 - ///
39.93 - /// Constructor
39.94 RowMap(const GridGraph& graph) : _graph(graph) {}
39.95
39.96 /// \brief The subscript operator
39.97 - ///
39.98 - /// The subscript operator.
39.99 Value operator[](Key key) const {
39.100 return _graph.row(key);
39.101 }
39.102 @@ -583,15 +580,14 @@
39.103
39.104 /// \brief Constructor
39.105 ///
39.106 - /// Construct a grid graph with given size.
39.107 + /// Construct a grid graph with the given size.
39.108 GridGraph(int width, int height) { construct(width, height); }
39.109
39.110 - /// \brief Resize the graph
39.111 + /// \brief Resizes the graph
39.112 ///
39.113 - /// Resize the graph. The function will fully destroy and rebuild
39.114 - /// the graph. This cause that the maps of the graph will
39.115 - /// reallocated automatically and the previous values will be
39.116 - /// lost.
39.117 + /// This function resizes the graph. It fully destroys and
39.118 + /// rebuilds the structure, therefore the maps of the graph will be
39.119 + /// reallocated automatically and the previous values will be lost.
39.120 void resize(int width, int height) {
39.121 Parent::notifier(Arc()).clear();
39.122 Parent::notifier(Edge()).clear();
39.123 @@ -609,42 +605,42 @@
39.124 return Parent::operator()(i, j);
39.125 }
39.126
39.127 - /// \brief Gives back the column index of the node.
39.128 + /// \brief The column index of the node.
39.129 ///
39.130 /// Gives back the column index of the node.
39.131 int col(Node n) const {
39.132 return Parent::col(n);
39.133 }
39.134
39.135 - /// \brief Gives back the row index of the node.
39.136 + /// \brief The row index of the node.
39.137 ///
39.138 /// Gives back the row index of the node.
39.139 int row(Node n) const {
39.140 return Parent::row(n);
39.141 }
39.142
39.143 - /// \brief Gives back the position of the node.
39.144 + /// \brief The position of the node.
39.145 ///
39.146 /// Gives back the position of the node, ie. the <tt>(col,row)</tt> pair.
39.147 dim2::Point<int> pos(Node n) const {
39.148 return Parent::pos(n);
39.149 }
39.150
39.151 - /// \brief Gives back the number of the columns.
39.152 + /// \brief The number of the columns.
39.153 ///
39.154 /// Gives back the number of the columns.
39.155 int width() const {
39.156 return Parent::width();
39.157 }
39.158
39.159 - /// \brief Gives back the number of the rows.
39.160 + /// \brief The number of the rows.
39.161 ///
39.162 /// Gives back the number of the rows.
39.163 int height() const {
39.164 return Parent::height();
39.165 }
39.166
39.167 - /// \brief Gives back the arc goes right from the node.
39.168 + /// \brief The arc goes right from the node.
39.169 ///
39.170 /// Gives back the arc goes right from the node. If there is not
39.171 /// outgoing arc then it gives back INVALID.
39.172 @@ -652,7 +648,7 @@
39.173 return Parent::right(n);
39.174 }
39.175
39.176 - /// \brief Gives back the arc goes left from the node.
39.177 + /// \brief The arc goes left from the node.
39.178 ///
39.179 /// Gives back the arc goes left from the node. If there is not
39.180 /// outgoing arc then it gives back INVALID.
39.181 @@ -660,7 +656,7 @@
39.182 return Parent::left(n);
39.183 }
39.184
39.185 - /// \brief Gives back the arc goes up from the node.
39.186 + /// \brief The arc goes up from the node.
39.187 ///
39.188 /// Gives back the arc goes up from the node. If there is not
39.189 /// outgoing arc then it gives back INVALID.
39.190 @@ -668,7 +664,7 @@
39.191 return Parent::up(n);
39.192 }
39.193
39.194 - /// \brief Gives back the arc goes down from the node.
39.195 + /// \brief The arc goes down from the node.
39.196 ///
39.197 /// Gives back the arc goes down from the node. If there is not
39.198 /// outgoing arc then it gives back INVALID.
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
40.2 +++ b/lemon/hartmann_orlin.h Wed Dec 09 11:14:06 2009 +0100
40.3 @@ -0,0 +1,642 @@
40.4 +/* -*- C++ -*-
40.5 + *
40.6 + * This file is a part of LEMON, a generic C++ optimization library
40.7 + *
40.8 + * Copyright (C) 2003-2008
40.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
40.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
40.11 + *
40.12 + * Permission to use, modify and distribute this software is granted
40.13 + * provided that this copyright notice appears in all copies. For
40.14 + * precise terms see the accompanying LICENSE file.
40.15 + *
40.16 + * This software is provided "AS IS" with no warranty of any kind,
40.17 + * express or implied, and with no claim as to its suitability for any
40.18 + * purpose.
40.19 + *
40.20 + */
40.21 +
40.22 +#ifndef LEMON_HARTMANN_ORLIN_H
40.23 +#define LEMON_HARTMANN_ORLIN_H
40.24 +
40.25 +/// \ingroup min_mean_cycle
40.26 +///
40.27 +/// \file
40.28 +/// \brief Hartmann-Orlin's algorithm for finding a minimum mean cycle.
40.29 +
40.30 +#include <vector>
40.31 +#include <limits>
40.32 +#include <lemon/core.h>
40.33 +#include <lemon/path.h>
40.34 +#include <lemon/tolerance.h>
40.35 +#include <lemon/connectivity.h>
40.36 +
40.37 +namespace lemon {
40.38 +
40.39 + /// \brief Default traits class of HartmannOrlin algorithm.
40.40 + ///
40.41 + /// Default traits class of HartmannOrlin algorithm.
40.42 + /// \tparam GR The type of the digraph.
40.43 + /// \tparam LEN The type of the length map.
40.44 + /// It must conform to the \ref concepts::Rea_data "Rea_data" concept.
40.45 +#ifdef DOXYGEN
40.46 + template <typename GR, typename LEN>
40.47 +#else
40.48 + template <typename GR, typename LEN,
40.49 + bool integer = std::numeric_limits<typename LEN::Value>::is_integer>
40.50 +#endif
40.51 + struct HartmannOrlinDefaultTraits
40.52 + {
40.53 + /// The type of the digraph
40.54 + typedef GR Digraph;
40.55 + /// The type of the length map
40.56 + typedef LEN LengthMap;
40.57 + /// The type of the arc lengths
40.58 + typedef typename LengthMap::Value Value;
40.59 +
40.60 + /// \brief The large value type used for internal computations
40.61 + ///
40.62 + /// The large value type used for internal computations.
40.63 + /// It is \c long \c long if the \c Value type is integer,
40.64 + /// otherwise it is \c double.
40.65 + /// \c Value must be convertible to \c LargeValue.
40.66 + typedef double LargeValue;
40.67 +
40.68 + /// The tolerance type used for internal computations
40.69 + typedef lemon::Tolerance<LargeValue> Tolerance;
40.70 +
40.71 + /// \brief The path type of the found cycles
40.72 + ///
40.73 + /// The path type of the found cycles.
40.74 + /// It must conform to the \ref lemon::concepts::Path "Path" concept
40.75 + /// and it must have an \c addFront() function.
40.76 + typedef lemon::Path<Digraph> Path;
40.77 + };
40.78 +
40.79 + // Default traits class for integer value types
40.80 + template <typename GR, typename LEN>
40.81 + struct HartmannOrlinDefaultTraits<GR, LEN, true>
40.82 + {
40.83 + typedef GR Digraph;
40.84 + typedef LEN LengthMap;
40.85 + typedef typename LengthMap::Value Value;
40.86 +#ifdef LEMON_HAVE_LONG_LONG
40.87 + typedef long long LargeValue;
40.88 +#else
40.89 + typedef long LargeValue;
40.90 +#endif
40.91 + typedef lemon::Tolerance<LargeValue> Tolerance;
40.92 + typedef lemon::Path<Digraph> Path;
40.93 + };
40.94 +
40.95 +
40.96 + /// \addtogroup min_mean_cycle
40.97 + /// @{
40.98 +
40.99 + /// \brief Implementation of the Hartmann-Orlin algorithm for finding
40.100 + /// a minimum mean cycle.
40.101 + ///
40.102 + /// This class implements the Hartmann-Orlin algorithm for finding
40.103 + /// a directed cycle of minimum mean length (cost) in a digraph
40.104 + /// \ref amo93networkflows, \ref dasdan98minmeancycle.
40.105 + /// It is an improved version of \ref Karp "Karp"'s original algorithm,
40.106 + /// it applies an efficient early termination scheme.
40.107 + /// It runs in time O(ne) and uses space O(n<sup>2</sup>+e).
40.108 + ///
40.109 + /// \tparam GR The type of the digraph the algorithm runs on.
40.110 + /// \tparam LEN The type of the length map. The default
40.111 + /// map type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
40.112 +#ifdef DOXYGEN
40.113 + template <typename GR, typename LEN, typename TR>
40.114 +#else
40.115 + template < typename GR,
40.116 + typename LEN = typename GR::template ArcMap<int>,
40.117 + typename TR = HartmannOrlinDefaultTraits<GR, LEN> >
40.118 +#endif
40.119 + class HartmannOrlin
40.120 + {
40.121 + public:
40.122 +
40.123 + /// The type of the digraph
40.124 + typedef typename TR::Digraph Digraph;
40.125 + /// The type of the length map
40.126 + typedef typename TR::LengthMap LengthMap;
40.127 + /// The type of the arc lengths
40.128 + typedef typename TR::Value Value;
40.129 +
40.130 + /// \brief The large value type
40.131 + ///
40.132 + /// The large value type used for internal computations.
40.133 + /// Using the \ref HartmannOrlinDefaultTraits "default traits class",
40.134 + /// it is \c long \c long if the \c Value type is integer,
40.135 + /// otherwise it is \c double.
40.136 + typedef typename TR::LargeValue LargeValue;
40.137 +
40.138 + /// The tolerance type
40.139 + typedef typename TR::Tolerance Tolerance;
40.140 +
40.141 + /// \brief The path type of the found cycles
40.142 + ///
40.143 + /// The path type of the found cycles.
40.144 + /// Using the \ref HartmannOrlinDefaultTraits "default traits class",
40.145 + /// it is \ref lemon::Path "Path<Digraph>".
40.146 + typedef typename TR::Path Path;
40.147 +
40.148 + /// The \ref HartmannOrlinDefaultTraits "traits class" of the algorithm
40.149 + typedef TR Traits;
40.150 +
40.151 + private:
40.152 +
40.153 + TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
40.154 +
40.155 + // Data sturcture for path data
40.156 + struct PathData
40.157 + {
40.158 + LargeValue dist;
40.159 + Arc pred;
40.160 + PathData(LargeValue d, Arc p = INVALID) :
40.161 + dist(d), pred(p) {}
40.162 + };
40.163 +
40.164 + typedef typename Digraph::template NodeMap<std::vector<PathData> >
40.165 + PathDataNodeMap;
40.166 +
40.167 + private:
40.168 +
40.169 + // The digraph the algorithm runs on
40.170 + const Digraph &_gr;
40.171 + // The length of the arcs
40.172 + const LengthMap &_length;
40.173 +
40.174 + // Data for storing the strongly connected components
40.175 + int _comp_num;
40.176 + typename Digraph::template NodeMap<int> _comp;
40.177 + std::vector<std::vector<Node> > _comp_nodes;
40.178 + std::vector<Node>* _nodes;
40.179 + typename Digraph::template NodeMap<std::vector<Arc> > _out_arcs;
40.180 +
40.181 + // Data for the found cycles
40.182 + bool _curr_found, _best_found;
40.183 + LargeValue _curr_length, _best_length;
40.184 + int _curr_size, _best_size;
40.185 + Node _curr_node, _best_node;
40.186 + int _curr_level, _best_level;
40.187 +
40.188 + Path *_cycle_path;
40.189 + bool _local_path;
40.190 +
40.191 + // Node map for storing path data
40.192 + PathDataNodeMap _data;
40.193 + // The processed nodes in the last round
40.194 + std::vector<Node> _process;
40.195 +
40.196 + Tolerance _tolerance;
40.197 +
40.198 + // Infinite constant
40.199 + const LargeValue INF;
40.200 +
40.201 + public:
40.202 +
40.203 + /// \name Named Template Parameters
40.204 + /// @{
40.205 +
40.206 + template <typename T>
40.207 + struct SetLargeValueTraits : public Traits {
40.208 + typedef T LargeValue;
40.209 + typedef lemon::Tolerance<T> Tolerance;
40.210 + };
40.211 +
40.212 + /// \brief \ref named-templ-param "Named parameter" for setting
40.213 + /// \c LargeValue type.
40.214 + ///
40.215 + /// \ref named-templ-param "Named parameter" for setting \c LargeValue
40.216 + /// type. It is used for internal computations in the algorithm.
40.217 + template <typename T>
40.218 + struct SetLargeValue
40.219 + : public HartmannOrlin<GR, LEN, SetLargeValueTraits<T> > {
40.220 + typedef HartmannOrlin<GR, LEN, SetLargeValueTraits<T> > Create;
40.221 + };
40.222 +
40.223 + template <typename T>
40.224 + struct SetPathTraits : public Traits {
40.225 + typedef T Path;
40.226 + };
40.227 +
40.228 + /// \brief \ref named-templ-param "Named parameter" for setting
40.229 + /// \c %Path type.
40.230 + ///
40.231 + /// \ref named-templ-param "Named parameter" for setting the \c %Path
40.232 + /// type of the found cycles.
40.233 + /// It must conform to the \ref lemon::concepts::Path "Path" concept
40.234 + /// and it must have an \c addFront() function.
40.235 + template <typename T>
40.236 + struct SetPath
40.237 + : public HartmannOrlin<GR, LEN, SetPathTraits<T> > {
40.238 + typedef HartmannOrlin<GR, LEN, SetPathTraits<T> > Create;
40.239 + };
40.240 +
40.241 + /// @}
40.242 +
40.243 + public:
40.244 +
40.245 + /// \brief Constructor.
40.246 + ///
40.247 + /// The constructor of the class.
40.248 + ///
40.249 + /// \param digraph The digraph the algorithm runs on.
40.250 + /// \param length The lengths (costs) of the arcs.
40.251 + HartmannOrlin( const Digraph &digraph,
40.252 + const LengthMap &length ) :
40.253 + _gr(digraph), _length(length), _comp(digraph), _out_arcs(digraph),
40.254 + _best_found(false), _best_length(0), _best_size(1),
40.255 + _cycle_path(NULL), _local_path(false), _data(digraph),
40.256 + INF(std::numeric_limits<LargeValue>::has_infinity ?
40.257 + std::numeric_limits<LargeValue>::infinity() :
40.258 + std::numeric_limits<LargeValue>::max())
40.259 + {}
40.260 +
40.261 + /// Destructor.
40.262 + ~HartmannOrlin() {
40.263 + if (_local_path) delete _cycle_path;
40.264 + }
40.265 +
40.266 + /// \brief Set the path structure for storing the found cycle.
40.267 + ///
40.268 + /// This function sets an external path structure for storing the
40.269 + /// found cycle.
40.270 + ///
40.271 + /// If you don't call this function before calling \ref run() or
40.272 + /// \ref findMinMean(), it will allocate a local \ref Path "path"
40.273 + /// structure. The destuctor deallocates this automatically
40.274 + /// allocated object, of course.
40.275 + ///
40.276 + /// \note The algorithm calls only the \ref lemon::Path::addFront()
40.277 + /// "addFront()" function of the given path structure.
40.278 + ///
40.279 + /// \return <tt>(*this)</tt>
40.280 + HartmannOrlin& cycle(Path &path) {
40.281 + if (_local_path) {
40.282 + delete _cycle_path;
40.283 + _local_path = false;
40.284 + }
40.285 + _cycle_path = &path;
40.286 + return *this;
40.287 + }
40.288 +
40.289 + /// \brief Set the tolerance used by the algorithm.
40.290 + ///
40.291 + /// This function sets the tolerance object used by the algorithm.
40.292 + ///
40.293 + /// \return <tt>(*this)</tt>
40.294 + HartmannOrlin& tolerance(const Tolerance& tolerance) {
40.295 + _tolerance = tolerance;
40.296 + return *this;
40.297 + }
40.298 +
40.299 + /// \brief Return a const reference to the tolerance.
40.300 + ///
40.301 + /// This function returns a const reference to the tolerance object
40.302 + /// used by the algorithm.
40.303 + const Tolerance& tolerance() const {
40.304 + return _tolerance;
40.305 + }
40.306 +
40.307 + /// \name Execution control
40.308 + /// The simplest way to execute the algorithm is to call the \ref run()
40.309 + /// function.\n
40.310 + /// If you only need the minimum mean length, you may call
40.311 + /// \ref findMinMean().
40.312 +
40.313 + /// @{
40.314 +
40.315 + /// \brief Run the algorithm.
40.316 + ///
40.317 + /// This function runs the algorithm.
40.318 + /// It can be called more than once (e.g. if the underlying digraph
40.319 + /// and/or the arc lengths have been modified).
40.320 + ///
40.321 + /// \return \c true if a directed cycle exists in the digraph.
40.322 + ///
40.323 + /// \note <tt>mmc.run()</tt> is just a shortcut of the following code.
40.324 + /// \code
40.325 + /// return mmc.findMinMean() && mmc.findCycle();
40.326 + /// \endcode
40.327 + bool run() {
40.328 + return findMinMean() && findCycle();
40.329 + }
40.330 +
40.331 + /// \brief Find the minimum cycle mean.
40.332 + ///
40.333 + /// This function finds the minimum mean length of the directed
40.334 + /// cycles in the digraph.
40.335 + ///
40.336 + /// \return \c true if a directed cycle exists in the digraph.
40.337 + bool findMinMean() {
40.338 + // Initialization and find strongly connected components
40.339 + init();
40.340 + findComponents();
40.341 +
40.342 + // Find the minimum cycle mean in the components
40.343 + for (int comp = 0; comp < _comp_num; ++comp) {
40.344 + if (!initComponent(comp)) continue;
40.345 + processRounds();
40.346 +
40.347 + // Update the best cycle (global minimum mean cycle)
40.348 + if ( _curr_found && (!_best_found ||
40.349 + _curr_length * _best_size < _best_length * _curr_size) ) {
40.350 + _best_found = true;
40.351 + _best_length = _curr_length;
40.352 + _best_size = _curr_size;
40.353 + _best_node = _curr_node;
40.354 + _best_level = _curr_level;
40.355 + }
40.356 + }
40.357 + return _best_found;
40.358 + }
40.359 +
40.360 + /// \brief Find a minimum mean directed cycle.
40.361 + ///
40.362 + /// This function finds a directed cycle of minimum mean length
40.363 + /// in the digraph using the data computed by findMinMean().
40.364 + ///
40.365 + /// \return \c true if a directed cycle exists in the digraph.
40.366 + ///
40.367 + /// \pre \ref findMinMean() must be called before using this function.
40.368 + bool findCycle() {
40.369 + if (!_best_found) return false;
40.370 + IntNodeMap reached(_gr, -1);
40.371 + int r = _best_level + 1;
40.372 + Node u = _best_node;
40.373 + while (reached[u] < 0) {
40.374 + reached[u] = --r;
40.375 + u = _gr.source(_data[u][r].pred);
40.376 + }
40.377 + r = reached[u];
40.378 + Arc e = _data[u][r].pred;
40.379 + _cycle_path->addFront(e);
40.380 + _best_length = _length[e];
40.381 + _best_size = 1;
40.382 + Node v;
40.383 + while ((v = _gr.source(e)) != u) {
40.384 + e = _data[v][--r].pred;
40.385 + _cycle_path->addFront(e);
40.386 + _best_length += _length[e];
40.387 + ++_best_size;
40.388 + }
40.389 + return true;
40.390 + }
40.391 +
40.392 + /// @}
40.393 +
40.394 + /// \name Query Functions
40.395 + /// The results of the algorithm can be obtained using these
40.396 + /// functions.\n
40.397 + /// The algorithm should be executed before using them.
40.398 +
40.399 + /// @{
40.400 +
40.401 + /// \brief Return the total length of the found cycle.
40.402 + ///
40.403 + /// This function returns the total length of the found cycle.
40.404 + ///
40.405 + /// \pre \ref run() or \ref findMinMean() must be called before
40.406 + /// using this function.
40.407 + LargeValue cycleLength() const {
40.408 + return _best_length;
40.409 + }
40.410 +
40.411 + /// \brief Return the number of arcs on the found cycle.
40.412 + ///
40.413 + /// This function returns the number of arcs on the found cycle.
40.414 + ///
40.415 + /// \pre \ref run() or \ref findMinMean() must be called before
40.416 + /// using this function.
40.417 + int cycleArcNum() const {
40.418 + return _best_size;
40.419 + }
40.420 +
40.421 + /// \brief Return the mean length of the found cycle.
40.422 + ///
40.423 + /// This function returns the mean length of the found cycle.
40.424 + ///
40.425 + /// \note <tt>alg.cycleMean()</tt> is just a shortcut of the
40.426 + /// following code.
40.427 + /// \code
40.428 + /// return static_cast<double>(alg.cycleLength()) / alg.cycleArcNum();
40.429 + /// \endcode
40.430 + ///
40.431 + /// \pre \ref run() or \ref findMinMean() must be called before
40.432 + /// using this function.
40.433 + double cycleMean() const {
40.434 + return static_cast<double>(_best_length) / _best_size;
40.435 + }
40.436 +
40.437 + /// \brief Return the found cycle.
40.438 + ///
40.439 + /// This function returns a const reference to the path structure
40.440 + /// storing the found cycle.
40.441 + ///
40.442 + /// \pre \ref run() or \ref findCycle() must be called before using
40.443 + /// this function.
40.444 + const Path& cycle() const {
40.445 + return *_cycle_path;
40.446 + }
40.447 +
40.448 + ///@}
40.449 +
40.450 + private:
40.451 +
40.452 + // Initialization
40.453 + void init() {
40.454 + if (!_cycle_path) {
40.455 + _local_path = true;
40.456 + _cycle_path = new Path;
40.457 + }
40.458 + _cycle_path->clear();
40.459 + _best_found = false;
40.460 + _best_length = 0;
40.461 + _best_size = 1;
40.462 + _cycle_path->clear();
40.463 + for (NodeIt u(_gr); u != INVALID; ++u)
40.464 + _data[u].clear();
40.465 + }
40.466 +
40.467 + // Find strongly connected components and initialize _comp_nodes
40.468 + // and _out_arcs
40.469 + void findComponents() {
40.470 + _comp_num = stronglyConnectedComponents(_gr, _comp);
40.471 + _comp_nodes.resize(_comp_num);
40.472 + if (_comp_num == 1) {
40.473 + _comp_nodes[0].clear();
40.474 + for (NodeIt n(_gr); n != INVALID; ++n) {
40.475 + _comp_nodes[0].push_back(n);
40.476 + _out_arcs[n].clear();
40.477 + for (OutArcIt a(_gr, n); a != INVALID; ++a) {
40.478 + _out_arcs[n].push_back(a);
40.479 + }
40.480 + }
40.481 + } else {
40.482 + for (int i = 0; i < _comp_num; ++i)
40.483 + _comp_nodes[i].clear();
40.484 + for (NodeIt n(_gr); n != INVALID; ++n) {
40.485 + int k = _comp[n];
40.486 + _comp_nodes[k].push_back(n);
40.487 + _out_arcs[n].clear();
40.488 + for (OutArcIt a(_gr, n); a != INVALID; ++a) {
40.489 + if (_comp[_gr.target(a)] == k) _out_arcs[n].push_back(a);
40.490 + }
40.491 + }
40.492 + }
40.493 + }
40.494 +
40.495 + // Initialize path data for the current component
40.496 + bool initComponent(int comp) {
40.497 + _nodes = &(_comp_nodes[comp]);
40.498 + int n = _nodes->size();
40.499 + if (n < 1 || (n == 1 && _out_arcs[(*_nodes)[0]].size() == 0)) {
40.500 + return false;
40.501 + }
40.502 + for (int i = 0; i < n; ++i) {
40.503 + _data[(*_nodes)[i]].resize(n + 1, PathData(INF));
40.504 + }
40.505 + return true;
40.506 + }
40.507 +
40.508 + // Process all rounds of computing path data for the current component.
40.509 + // _data[v][k] is the length of a shortest directed walk from the root
40.510 + // node to node v containing exactly k arcs.
40.511 + void processRounds() {
40.512 + Node start = (*_nodes)[0];
40.513 + _data[start][0] = PathData(0);
40.514 + _process.clear();
40.515 + _process.push_back(start);
40.516 +
40.517 + int k, n = _nodes->size();
40.518 + int next_check = 4;
40.519 + bool terminate = false;
40.520 + for (k = 1; k <= n && int(_process.size()) < n && !terminate; ++k) {
40.521 + processNextBuildRound(k);
40.522 + if (k == next_check || k == n) {
40.523 + terminate = checkTermination(k);
40.524 + next_check = next_check * 3 / 2;
40.525 + }
40.526 + }
40.527 + for ( ; k <= n && !terminate; ++k) {
40.528 + processNextFullRound(k);
40.529 + if (k == next_check || k == n) {
40.530 + terminate = checkTermination(k);
40.531 + next_check = next_check * 3 / 2;
40.532 + }
40.533 + }
40.534 + }
40.535 +
40.536 + // Process one round and rebuild _process
40.537 + void processNextBuildRound(int k) {
40.538 + std::vector<Node> next;
40.539 + Node u, v;
40.540 + Arc e;
40.541 + LargeValue d;
40.542 + for (int i = 0; i < int(_process.size()); ++i) {
40.543 + u = _process[i];
40.544 + for (int j = 0; j < int(_out_arcs[u].size()); ++j) {
40.545 + e = _out_arcs[u][j];
40.546 + v = _gr.target(e);
40.547 + d = _data[u][k-1].dist + _length[e];
40.548 + if (_tolerance.less(d, _data[v][k].dist)) {
40.549 + if (_data[v][k].dist == INF) next.push_back(v);
40.550 + _data[v][k] = PathData(d, e);
40.551 + }
40.552 + }
40.553 + }
40.554 + _process.swap(next);
40.555 + }
40.556 +
40.557 + // Process one round using _nodes instead of _process
40.558 + void processNextFullRound(int k) {
40.559 + Node u, v;
40.560 + Arc e;
40.561 + LargeValue d;
40.562 + for (int i = 0; i < int(_nodes->size()); ++i) {
40.563 + u = (*_nodes)[i];
40.564 + for (int j = 0; j < int(_out_arcs[u].size()); ++j) {
40.565 + e = _out_arcs[u][j];
40.566 + v = _gr.target(e);
40.567 + d = _data[u][k-1].dist + _length[e];
40.568 + if (_tolerance.less(d, _data[v][k].dist)) {
40.569 + _data[v][k] = PathData(d, e);
40.570 + }
40.571 + }
40.572 + }
40.573 + }
40.574 +
40.575 + // Check early termination
40.576 + bool checkTermination(int k) {
40.577 + typedef std::pair<int, int> Pair;
40.578 + typename GR::template NodeMap<Pair> level(_gr, Pair(-1, 0));
40.579 + typename GR::template NodeMap<LargeValue> pi(_gr);
40.580 + int n = _nodes->size();
40.581 + LargeValue length;
40.582 + int size;
40.583 + Node u;
40.584 +
40.585 + // Search for cycles that are already found
40.586 + _curr_found = false;
40.587 + for (int i = 0; i < n; ++i) {
40.588 + u = (*_nodes)[i];
40.589 + if (_data[u][k].dist == INF) continue;
40.590 + for (int j = k; j >= 0; --j) {
40.591 + if (level[u].first == i && level[u].second > 0) {
40.592 + // A cycle is found
40.593 + length = _data[u][level[u].second].dist - _data[u][j].dist;
40.594 + size = level[u].second - j;
40.595 + if (!_curr_found || length * _curr_size < _curr_length * size) {
40.596 + _curr_length = length;
40.597 + _curr_size = size;
40.598 + _curr_node = u;
40.599 + _curr_level = level[u].second;
40.600 + _curr_found = true;
40.601 + }
40.602 + }
40.603 + level[u] = Pair(i, j);
40.604 + if (j != 0) {
40.605 + u = _gr.source(_data[u][j].pred);
40.606 + }
40.607 + }
40.608 + }
40.609 +
40.610 + // If at least one cycle is found, check the optimality condition
40.611 + LargeValue d;
40.612 + if (_curr_found && k < n) {
40.613 + // Find node potentials
40.614 + for (int i = 0; i < n; ++i) {
40.615 + u = (*_nodes)[i];
40.616 + pi[u] = INF;
40.617 + for (int j = 0; j <= k; ++j) {
40.618 + if (_data[u][j].dist < INF) {
40.619 + d = _data[u][j].dist * _curr_size - j * _curr_length;
40.620 + if (_tolerance.less(d, pi[u])) pi[u] = d;
40.621 + }
40.622 + }
40.623 + }
40.624 +
40.625 + // Check the optimality condition for all arcs
40.626 + bool done = true;
40.627 + for (ArcIt a(_gr); a != INVALID; ++a) {
40.628 + if (_tolerance.less(_length[a] * _curr_size - _curr_length,
40.629 + pi[_gr.target(a)] - pi[_gr.source(a)]) ) {
40.630 + done = false;
40.631 + break;
40.632 + }
40.633 + }
40.634 + return done;
40.635 + }
40.636 + return (k == n);
40.637 + }
40.638 +
40.639 + }; //class HartmannOrlin
40.640 +
40.641 + ///@}
40.642 +
40.643 +} //namespace lemon
40.644 +
40.645 +#endif //LEMON_HARTMANN_ORLIN_H
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
41.2 +++ b/lemon/howard.h Wed Dec 09 11:14:06 2009 +0100
41.3 @@ -0,0 +1,597 @@
41.4 +/* -*- C++ -*-
41.5 + *
41.6 + * This file is a part of LEMON, a generic C++ optimization library
41.7 + *
41.8 + * Copyright (C) 2003-2008
41.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
41.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
41.11 + *
41.12 + * Permission to use, modify and distribute this software is granted
41.13 + * provided that this copyright notice appears in all copies. For
41.14 + * precise terms see the accompanying LICENSE file.
41.15 + *
41.16 + * This software is provided "AS IS" with no warranty of any kind,
41.17 + * express or implied, and with no claim as to its suitability for any
41.18 + * purpose.
41.19 + *
41.20 + */
41.21 +
41.22 +#ifndef LEMON_HOWARD_H
41.23 +#define LEMON_HOWARD_H
41.24 +
41.25 +/// \ingroup min_mean_cycle
41.26 +///
41.27 +/// \file
41.28 +/// \brief Howard's algorithm for finding a minimum mean cycle.
41.29 +
41.30 +#include <vector>
41.31 +#include <limits>
41.32 +#include <lemon/core.h>
41.33 +#include <lemon/path.h>
41.34 +#include <lemon/tolerance.h>
41.35 +#include <lemon/connectivity.h>
41.36 +
41.37 +namespace lemon {
41.38 +
41.39 + /// \brief Default traits class of Howard class.
41.40 + ///
41.41 + /// Default traits class of Howard class.
41.42 + /// \tparam GR The type of the digraph.
41.43 + /// \tparam LEN The type of the length map.
41.44 + /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
41.45 +#ifdef DOXYGEN
41.46 + template <typename GR, typename LEN>
41.47 +#else
41.48 + template <typename GR, typename LEN,
41.49 + bool integer = std::numeric_limits<typename LEN::Value>::is_integer>
41.50 +#endif
41.51 + struct HowardDefaultTraits
41.52 + {
41.53 + /// The type of the digraph
41.54 + typedef GR Digraph;
41.55 + /// The type of the length map
41.56 + typedef LEN LengthMap;
41.57 + /// The type of the arc lengths
41.58 + typedef typename LengthMap::Value Value;
41.59 +
41.60 + /// \brief The large value type used for internal computations
41.61 + ///
41.62 + /// The large value type used for internal computations.
41.63 + /// It is \c long \c long if the \c Value type is integer,
41.64 + /// otherwise it is \c double.
41.65 + /// \c Value must be convertible to \c LargeValue.
41.66 + typedef double LargeValue;
41.67 +
41.68 + /// The tolerance type used for internal computations
41.69 + typedef lemon::Tolerance<LargeValue> Tolerance;
41.70 +
41.71 + /// \brief The path type of the found cycles
41.72 + ///
41.73 + /// The path type of the found cycles.
41.74 + /// It must conform to the \ref lemon::concepts::Path "Path" concept
41.75 + /// and it must have an \c addBack() function.
41.76 + typedef lemon::Path<Digraph> Path;
41.77 + };
41.78 +
41.79 + // Default traits class for integer value types
41.80 + template <typename GR, typename LEN>
41.81 + struct HowardDefaultTraits<GR, LEN, true>
41.82 + {
41.83 + typedef GR Digraph;
41.84 + typedef LEN LengthMap;
41.85 + typedef typename LengthMap::Value Value;
41.86 +#ifdef LEMON_HAVE_LONG_LONG
41.87 + typedef long long LargeValue;
41.88 +#else
41.89 + typedef long LargeValue;
41.90 +#endif
41.91 + typedef lemon::Tolerance<LargeValue> Tolerance;
41.92 + typedef lemon::Path<Digraph> Path;
41.93 + };
41.94 +
41.95 +
41.96 + /// \addtogroup min_mean_cycle
41.97 + /// @{
41.98 +
41.99 + /// \brief Implementation of Howard's algorithm for finding a minimum
41.100 + /// mean cycle.
41.101 + ///
41.102 + /// This class implements Howard's policy iteration algorithm for finding
41.103 + /// a directed cycle of minimum mean length (cost) in a digraph
41.104 + /// \ref amo93networkflows, \ref dasdan98minmeancycle.
41.105 + /// This class provides the most efficient algorithm for the
41.106 + /// minimum mean cycle problem, though the best known theoretical
41.107 + /// bound on its running time is exponential.
41.108 + ///
41.109 + /// \tparam GR The type of the digraph the algorithm runs on.
41.110 + /// \tparam LEN The type of the length map. The default
41.111 + /// map type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
41.112 +#ifdef DOXYGEN
41.113 + template <typename GR, typename LEN, typename TR>
41.114 +#else
41.115 + template < typename GR,
41.116 + typename LEN = typename GR::template ArcMap<int>,
41.117 + typename TR = HowardDefaultTraits<GR, LEN> >
41.118 +#endif
41.119 + class Howard
41.120 + {
41.121 + public:
41.122 +
41.123 + /// The type of the digraph
41.124 + typedef typename TR::Digraph Digraph;
41.125 + /// The type of the length map
41.126 + typedef typename TR::LengthMap LengthMap;
41.127 + /// The type of the arc lengths
41.128 + typedef typename TR::Value Value;
41.129 +
41.130 + /// \brief The large value type
41.131 + ///
41.132 + /// The large value type used for internal computations.
41.133 + /// Using the \ref HowardDefaultTraits "default traits class",
41.134 + /// it is \c long \c long if the \c Value type is integer,
41.135 + /// otherwise it is \c double.
41.136 + typedef typename TR::LargeValue LargeValue;
41.137 +
41.138 + /// The tolerance type
41.139 + typedef typename TR::Tolerance Tolerance;
41.140 +
41.141 + /// \brief The path type of the found cycles
41.142 + ///
41.143 + /// The path type of the found cycles.
41.144 + /// Using the \ref HowardDefaultTraits "default traits class",
41.145 + /// it is \ref lemon::Path "Path<Digraph>".
41.146 + typedef typename TR::Path Path;
41.147 +
41.148 + /// The \ref HowardDefaultTraits "traits class" of the algorithm
41.149 + typedef TR Traits;
41.150 +
41.151 + private:
41.152 +
41.153 + TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
41.154 +
41.155 + // The digraph the algorithm runs on
41.156 + const Digraph &_gr;
41.157 + // The length of the arcs
41.158 + const LengthMap &_length;
41.159 +
41.160 + // Data for the found cycles
41.161 + bool _curr_found, _best_found;
41.162 + LargeValue _curr_length, _best_length;
41.163 + int _curr_size, _best_size;
41.164 + Node _curr_node, _best_node;
41.165 +
41.166 + Path *_cycle_path;
41.167 + bool _local_path;
41.168 +
41.169 + // Internal data used by the algorithm
41.170 + typename Digraph::template NodeMap<Arc> _policy;
41.171 + typename Digraph::template NodeMap<bool> _reached;
41.172 + typename Digraph::template NodeMap<int> _level;
41.173 + typename Digraph::template NodeMap<LargeValue> _dist;
41.174 +
41.175 + // Data for storing the strongly connected components
41.176 + int _comp_num;
41.177 + typename Digraph::template NodeMap<int> _comp;
41.178 + std::vector<std::vector<Node> > _comp_nodes;
41.179 + std::vector<Node>* _nodes;
41.180 + typename Digraph::template NodeMap<std::vector<Arc> > _in_arcs;
41.181 +
41.182 + // Queue used for BFS search
41.183 + std::vector<Node> _queue;
41.184 + int _qfront, _qback;
41.185 +
41.186 + Tolerance _tolerance;
41.187 +
41.188 + // Infinite constant
41.189 + const LargeValue INF;
41.190 +
41.191 + public:
41.192 +
41.193 + /// \name Named Template Parameters
41.194 + /// @{
41.195 +
41.196 + template <typename T>
41.197 + struct SetLargeValueTraits : public Traits {
41.198 + typedef T LargeValue;
41.199 + typedef lemon::Tolerance<T> Tolerance;
41.200 + };
41.201 +
41.202 + /// \brief \ref named-templ-param "Named parameter" for setting
41.203 + /// \c LargeValue type.
41.204 + ///
41.205 + /// \ref named-templ-param "Named parameter" for setting \c LargeValue
41.206 + /// type. It is used for internal computations in the algorithm.
41.207 + template <typename T>
41.208 + struct SetLargeValue
41.209 + : public Howard<GR, LEN, SetLargeValueTraits<T> > {
41.210 + typedef Howard<GR, LEN, SetLargeValueTraits<T> > Create;
41.211 + };
41.212 +
41.213 + template <typename T>
41.214 + struct SetPathTraits : public Traits {
41.215 + typedef T Path;
41.216 + };
41.217 +
41.218 + /// \brief \ref named-templ-param "Named parameter" for setting
41.219 + /// \c %Path type.
41.220 + ///
41.221 + /// \ref named-templ-param "Named parameter" for setting the \c %Path
41.222 + /// type of the found cycles.
41.223 + /// It must conform to the \ref lemon::concepts::Path "Path" concept
41.224 + /// and it must have an \c addBack() function.
41.225 + template <typename T>
41.226 + struct SetPath
41.227 + : public Howard<GR, LEN, SetPathTraits<T> > {
41.228 + typedef Howard<GR, LEN, SetPathTraits<T> > Create;
41.229 + };
41.230 +
41.231 + /// @}
41.232 +
41.233 + public:
41.234 +
41.235 + /// \brief Constructor.
41.236 + ///
41.237 + /// The constructor of the class.
41.238 + ///
41.239 + /// \param digraph The digraph the algorithm runs on.
41.240 + /// \param length The lengths (costs) of the arcs.
41.241 + Howard( const Digraph &digraph,
41.242 + const LengthMap &length ) :
41.243 + _gr(digraph), _length(length), _best_found(false),
41.244 + _best_length(0), _best_size(1), _cycle_path(NULL), _local_path(false),
41.245 + _policy(digraph), _reached(digraph), _level(digraph), _dist(digraph),
41.246 + _comp(digraph), _in_arcs(digraph),
41.247 + INF(std::numeric_limits<LargeValue>::has_infinity ?
41.248 + std::numeric_limits<LargeValue>::infinity() :
41.249 + std::numeric_limits<LargeValue>::max())
41.250 + {}
41.251 +
41.252 + /// Destructor.
41.253 + ~Howard() {
41.254 + if (_local_path) delete _cycle_path;
41.255 + }
41.256 +
41.257 + /// \brief Set the path structure for storing the found cycle.
41.258 + ///
41.259 + /// This function sets an external path structure for storing the
41.260 + /// found cycle.
41.261 + ///
41.262 + /// If you don't call this function before calling \ref run() or
41.263 + /// \ref findMinMean(), it will allocate a local \ref Path "path"
41.264 + /// structure. The destuctor deallocates this automatically
41.265 + /// allocated object, of course.
41.266 + ///
41.267 + /// \note The algorithm calls only the \ref lemon::Path::addBack()
41.268 + /// "addBack()" function of the given path structure.
41.269 + ///
41.270 + /// \return <tt>(*this)</tt>
41.271 + Howard& cycle(Path &path) {
41.272 + if (_local_path) {
41.273 + delete _cycle_path;
41.274 + _local_path = false;
41.275 + }
41.276 + _cycle_path = &path;
41.277 + return *this;
41.278 + }
41.279 +
41.280 + /// \brief Set the tolerance used by the algorithm.
41.281 + ///
41.282 + /// This function sets the tolerance object used by the algorithm.
41.283 + ///
41.284 + /// \return <tt>(*this)</tt>
41.285 + Howard& tolerance(const Tolerance& tolerance) {
41.286 + _tolerance = tolerance;
41.287 + return *this;
41.288 + }
41.289 +
41.290 + /// \brief Return a const reference to the tolerance.
41.291 + ///
41.292 + /// This function returns a const reference to the tolerance object
41.293 + /// used by the algorithm.
41.294 + const Tolerance& tolerance() const {
41.295 + return _tolerance;
41.296 + }
41.297 +
41.298 + /// \name Execution control
41.299 + /// The simplest way to execute the algorithm is to call the \ref run()
41.300 + /// function.\n
41.301 + /// If you only need the minimum mean length, you may call
41.302 + /// \ref findMinMean().
41.303 +
41.304 + /// @{
41.305 +
41.306 + /// \brief Run the algorithm.
41.307 + ///
41.308 + /// This function runs the algorithm.
41.309 + /// It can be called more than once (e.g. if the underlying digraph
41.310 + /// and/or the arc lengths have been modified).
41.311 + ///
41.312 + /// \return \c true if a directed cycle exists in the digraph.
41.313 + ///
41.314 + /// \note <tt>mmc.run()</tt> is just a shortcut of the following code.
41.315 + /// \code
41.316 + /// return mmc.findMinMean() && mmc.findCycle();
41.317 + /// \endcode
41.318 + bool run() {
41.319 + return findMinMean() && findCycle();
41.320 + }
41.321 +
41.322 + /// \brief Find the minimum cycle mean.
41.323 + ///
41.324 + /// This function finds the minimum mean length of the directed
41.325 + /// cycles in the digraph.
41.326 + ///
41.327 + /// \return \c true if a directed cycle exists in the digraph.
41.328 + bool findMinMean() {
41.329 + // Initialize and find strongly connected components
41.330 + init();
41.331 + findComponents();
41.332 +
41.333 + // Find the minimum cycle mean in the components
41.334 + for (int comp = 0; comp < _comp_num; ++comp) {
41.335 + // Find the minimum mean cycle in the current component
41.336 + if (!buildPolicyGraph(comp)) continue;
41.337 + while (true) {
41.338 + findPolicyCycle();
41.339 + if (!computeNodeDistances()) break;
41.340 + }
41.341 + // Update the best cycle (global minimum mean cycle)
41.342 + if ( _curr_found && (!_best_found ||
41.343 + _curr_length * _best_size < _best_length * _curr_size) ) {
41.344 + _best_found = true;
41.345 + _best_length = _curr_length;
41.346 + _best_size = _curr_size;
41.347 + _best_node = _curr_node;
41.348 + }
41.349 + }
41.350 + return _best_found;
41.351 + }
41.352 +
41.353 + /// \brief Find a minimum mean directed cycle.
41.354 + ///
41.355 + /// This function finds a directed cycle of minimum mean length
41.356 + /// in the digraph using the data computed by findMinMean().
41.357 + ///
41.358 + /// \return \c true if a directed cycle exists in the digraph.
41.359 + ///
41.360 + /// \pre \ref findMinMean() must be called before using this function.
41.361 + bool findCycle() {
41.362 + if (!_best_found) return false;
41.363 + _cycle_path->addBack(_policy[_best_node]);
41.364 + for ( Node v = _best_node;
41.365 + (v = _gr.target(_policy[v])) != _best_node; ) {
41.366 + _cycle_path->addBack(_policy[v]);
41.367 + }
41.368 + return true;
41.369 + }
41.370 +
41.371 + /// @}
41.372 +
41.373 + /// \name Query Functions
41.374 + /// The results of the algorithm can be obtained using these
41.375 + /// functions.\n
41.376 + /// The algorithm should be executed before using them.
41.377 +
41.378 + /// @{
41.379 +
41.380 + /// \brief Return the total length of the found cycle.
41.381 + ///
41.382 + /// This function returns the total length of the found cycle.
41.383 + ///
41.384 + /// \pre \ref run() or \ref findMinMean() must be called before
41.385 + /// using this function.
41.386 + LargeValue cycleLength() const {
41.387 + return _best_length;
41.388 + }
41.389 +
41.390 + /// \brief Return the number of arcs on the found cycle.
41.391 + ///
41.392 + /// This function returns the number of arcs on the found cycle.
41.393 + ///
41.394 + /// \pre \ref run() or \ref findMinMean() must be called before
41.395 + /// using this function.
41.396 + int cycleArcNum() const {
41.397 + return _best_size;
41.398 + }
41.399 +
41.400 + /// \brief Return the mean length of the found cycle.
41.401 + ///
41.402 + /// This function returns the mean length of the found cycle.
41.403 + ///
41.404 + /// \note <tt>alg.cycleMean()</tt> is just a shortcut of the
41.405 + /// following code.
41.406 + /// \code
41.407 + /// return static_cast<double>(alg.cycleLength()) / alg.cycleArcNum();
41.408 + /// \endcode
41.409 + ///
41.410 + /// \pre \ref run() or \ref findMinMean() must be called before
41.411 + /// using this function.
41.412 + double cycleMean() const {
41.413 + return static_cast<double>(_best_length) / _best_size;
41.414 + }
41.415 +
41.416 + /// \brief Return the found cycle.
41.417 + ///
41.418 + /// This function returns a const reference to the path structure
41.419 + /// storing the found cycle.
41.420 + ///
41.421 + /// \pre \ref run() or \ref findCycle() must be called before using
41.422 + /// this function.
41.423 + const Path& cycle() const {
41.424 + return *_cycle_path;
41.425 + }
41.426 +
41.427 + ///@}
41.428 +
41.429 + private:
41.430 +
41.431 + // Initialize
41.432 + void init() {
41.433 + if (!_cycle_path) {
41.434 + _local_path = true;
41.435 + _cycle_path = new Path;
41.436 + }
41.437 + _queue.resize(countNodes(_gr));
41.438 + _best_found = false;
41.439 + _best_length = 0;
41.440 + _best_size = 1;
41.441 + _cycle_path->clear();
41.442 + }
41.443 +
41.444 + // Find strongly connected components and initialize _comp_nodes
41.445 + // and _in_arcs
41.446 + void findComponents() {
41.447 + _comp_num = stronglyConnectedComponents(_gr, _comp);
41.448 + _comp_nodes.resize(_comp_num);
41.449 + if (_comp_num == 1) {
41.450 + _comp_nodes[0].clear();
41.451 + for (NodeIt n(_gr); n != INVALID; ++n) {
41.452 + _comp_nodes[0].push_back(n);
41.453 + _in_arcs[n].clear();
41.454 + for (InArcIt a(_gr, n); a != INVALID; ++a) {
41.455 + _in_arcs[n].push_back(a);
41.456 + }
41.457 + }
41.458 + } else {
41.459 + for (int i = 0; i < _comp_num; ++i)
41.460 + _comp_nodes[i].clear();
41.461 + for (NodeIt n(_gr); n != INVALID; ++n) {
41.462 + int k = _comp[n];
41.463 + _comp_nodes[k].push_back(n);
41.464 + _in_arcs[n].clear();
41.465 + for (InArcIt a(_gr, n); a != INVALID; ++a) {
41.466 + if (_comp[_gr.source(a)] == k) _in_arcs[n].push_back(a);
41.467 + }
41.468 + }
41.469 + }
41.470 + }
41.471 +
41.472 + // Build the policy graph in the given strongly connected component
41.473 + // (the out-degree of every node is 1)
41.474 + bool buildPolicyGraph(int comp) {
41.475 + _nodes = &(_comp_nodes[comp]);
41.476 + if (_nodes->size() < 1 ||
41.477 + (_nodes->size() == 1 && _in_arcs[(*_nodes)[0]].size() == 0)) {
41.478 + return false;
41.479 + }
41.480 + for (int i = 0; i < int(_nodes->size()); ++i) {
41.481 + _dist[(*_nodes)[i]] = INF;
41.482 + }
41.483 + Node u, v;
41.484 + Arc e;
41.485 + for (int i = 0; i < int(_nodes->size()); ++i) {
41.486 + v = (*_nodes)[i];
41.487 + for (int j = 0; j < int(_in_arcs[v].size()); ++j) {
41.488 + e = _in_arcs[v][j];
41.489 + u = _gr.source(e);
41.490 + if (_length[e] < _dist[u]) {
41.491 + _dist[u] = _length[e];
41.492 + _policy[u] = e;
41.493 + }
41.494 + }
41.495 + }
41.496 + return true;
41.497 + }
41.498 +
41.499 + // Find the minimum mean cycle in the policy graph
41.500 + void findPolicyCycle() {
41.501 + for (int i = 0; i < int(_nodes->size()); ++i) {
41.502 + _level[(*_nodes)[i]] = -1;
41.503 + }
41.504 + LargeValue clength;
41.505 + int csize;
41.506 + Node u, v;
41.507 + _curr_found = false;
41.508 + for (int i = 0; i < int(_nodes->size()); ++i) {
41.509 + u = (*_nodes)[i];
41.510 + if (_level[u] >= 0) continue;
41.511 + for (; _level[u] < 0; u = _gr.target(_policy[u])) {
41.512 + _level[u] = i;
41.513 + }
41.514 + if (_level[u] == i) {
41.515 + // A cycle is found
41.516 + clength = _length[_policy[u]];
41.517 + csize = 1;
41.518 + for (v = u; (v = _gr.target(_policy[v])) != u; ) {
41.519 + clength += _length[_policy[v]];
41.520 + ++csize;
41.521 + }
41.522 + if ( !_curr_found ||
41.523 + (clength * _curr_size < _curr_length * csize) ) {
41.524 + _curr_found = true;
41.525 + _curr_length = clength;
41.526 + _curr_size = csize;
41.527 + _curr_node = u;
41.528 + }
41.529 + }
41.530 + }
41.531 + }
41.532 +
41.533 + // Contract the policy graph and compute node distances
41.534 + bool computeNodeDistances() {
41.535 + // Find the component of the main cycle and compute node distances
41.536 + // using reverse BFS
41.537 + for (int i = 0; i < int(_nodes->size()); ++i) {
41.538 + _reached[(*_nodes)[i]] = false;
41.539 + }
41.540 + _qfront = _qback = 0;
41.541 + _queue[0] = _curr_node;
41.542 + _reached[_curr_node] = true;
41.543 + _dist[_curr_node] = 0;
41.544 + Node u, v;
41.545 + Arc e;
41.546 + while (_qfront <= _qback) {
41.547 + v = _queue[_qfront++];
41.548 + for (int j = 0; j < int(_in_arcs[v].size()); ++j) {
41.549 + e = _in_arcs[v][j];
41.550 + u = _gr.source(e);
41.551 + if (_policy[u] == e && !_reached[u]) {
41.552 + _reached[u] = true;
41.553 + _dist[u] = _dist[v] + _length[e] * _curr_size - _curr_length;
41.554 + _queue[++_qback] = u;
41.555 + }
41.556 + }
41.557 + }
41.558 +
41.559 + // Connect all other nodes to this component and compute node
41.560 + // distances using reverse BFS
41.561 + _qfront = 0;
41.562 + while (_qback < int(_nodes->size())-1) {
41.563 + v = _queue[_qfront++];
41.564 + for (int j = 0; j < int(_in_arcs[v].size()); ++j) {
41.565 + e = _in_arcs[v][j];
41.566 + u = _gr.source(e);
41.567 + if (!_reached[u]) {
41.568 + _reached[u] = true;
41.569 + _policy[u] = e;
41.570 + _dist[u] = _dist[v] + _length[e] * _curr_size - _curr_length;
41.571 + _queue[++_qback] = u;
41.572 + }
41.573 + }
41.574 + }
41.575 +
41.576 + // Improve node distances
41.577 + bool improved = false;
41.578 + for (int i = 0; i < int(_nodes->size()); ++i) {
41.579 + v = (*_nodes)[i];
41.580 + for (int j = 0; j < int(_in_arcs[v].size()); ++j) {
41.581 + e = _in_arcs[v][j];
41.582 + u = _gr.source(e);
41.583 + LargeValue delta = _dist[v] + _length[e] * _curr_size - _curr_length;
41.584 + if (_tolerance.less(delta, _dist[u])) {
41.585 + _dist[u] = delta;
41.586 + _policy[u] = e;
41.587 + improved = true;
41.588 + }
41.589 + }
41.590 + }
41.591 + return improved;
41.592 + }
41.593 +
41.594 + }; //class Howard
41.595 +
41.596 + ///@}
41.597 +
41.598 +} //namespace lemon
41.599 +
41.600 +#endif //LEMON_HOWARD_H
42.1 --- a/lemon/hypercube_graph.h Sun Oct 04 10:15:32 2009 +0200
42.2 +++ b/lemon/hypercube_graph.h Wed Dec 09 11:14:06 2009 +0100
42.3 @@ -262,7 +262,7 @@
42.4 return arc._id >> _dim;
42.5 }
42.6
42.7 - int index(Node node) const {
42.8 + static int index(Node node) {
42.9 return node._id;
42.10 }
42.11
42.12 @@ -282,17 +282,23 @@
42.13 ///
42.14 /// \brief Hypercube graph class
42.15 ///
42.16 - /// This class implements a special graph type. The nodes of the graph
42.17 - /// are indiced with integers with at most \c dim binary digits.
42.18 + /// HypercubeGraph implements a special graph type. The nodes of the
42.19 + /// graph are indexed with integers having at most \c dim binary digits.
42.20 /// Two nodes are connected in the graph if and only if their indices
42.21 /// differ only on one position in the binary form.
42.22 + /// This class is completely static and it needs constant memory space.
42.23 + /// Thus you can neither add nor delete nodes or edges, however,
42.24 + /// the structure can be resized using resize().
42.25 + ///
42.26 + /// This type fully conforms to the \ref concepts::Graph "Graph concept".
42.27 + /// Most of its member functions and nested classes are documented
42.28 + /// only in the concept class.
42.29 + ///
42.30 + /// This class provides constant time counting for nodes, edges and arcs.
42.31 ///
42.32 /// \note The type of the indices is chosen to \c int for efficiency
42.33 /// reasons. Thus the maximum dimension of this implementation is 26
42.34 /// (assuming that the size of \c int is 32 bit).
42.35 - ///
42.36 - /// This graph type fully conforms to the \ref concepts::Graph
42.37 - /// "Graph concept".
42.38 class HypercubeGraph : public ExtendedHypercubeGraphBase {
42.39 typedef ExtendedHypercubeGraphBase Parent;
42.40
42.41 @@ -303,6 +309,21 @@
42.42 /// Constructs a hypercube graph with \c dim dimensions.
42.43 HypercubeGraph(int dim) { construct(dim); }
42.44
42.45 + /// \brief Resizes the graph
42.46 + ///
42.47 + /// This function resizes the graph. It fully destroys and
42.48 + /// rebuilds the structure, therefore the maps of the graph will be
42.49 + /// reallocated automatically and the previous values will be lost.
42.50 + void resize(int dim) {
42.51 + Parent::notifier(Arc()).clear();
42.52 + Parent::notifier(Edge()).clear();
42.53 + Parent::notifier(Node()).clear();
42.54 + construct(dim);
42.55 + Parent::notifier(Node()).build();
42.56 + Parent::notifier(Edge()).build();
42.57 + Parent::notifier(Arc()).build();
42.58 + }
42.59 +
42.60 /// \brief The number of dimensions.
42.61 ///
42.62 /// Gives back the number of dimensions.
42.63 @@ -320,7 +341,7 @@
42.64 /// \brief The dimension id of an edge.
42.65 ///
42.66 /// Gives back the dimension id of the given edge.
42.67 - /// It is in the [0..dim-1] range.
42.68 + /// It is in the range <tt>[0..dim-1]</tt>.
42.69 int dimension(Edge edge) const {
42.70 return Parent::dimension(edge);
42.71 }
42.72 @@ -328,7 +349,7 @@
42.73 /// \brief The dimension id of an arc.
42.74 ///
42.75 /// Gives back the dimension id of the given arc.
42.76 - /// It is in the [0..dim-1] range.
42.77 + /// It is in the range <tt>[0..dim-1]</tt>.
42.78 int dimension(Arc arc) const {
42.79 return Parent::dimension(arc);
42.80 }
42.81 @@ -337,7 +358,7 @@
42.82 ///
42.83 /// Gives back the index of the given node.
42.84 /// The lower bits of the integer describes the node.
42.85 - int index(Node node) const {
42.86 + static int index(Node node) {
42.87 return Parent::index(node);
42.88 }
42.89
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
43.2 +++ b/lemon/karp.h Wed Dec 09 11:14:06 2009 +0100
43.3 @@ -0,0 +1,582 @@
43.4 +/* -*- C++ -*-
43.5 + *
43.6 + * This file is a part of LEMON, a generic C++ optimization library
43.7 + *
43.8 + * Copyright (C) 2003-2008
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_KARP_H
43.23 +#define LEMON_KARP_H
43.24 +
43.25 +/// \ingroup min_mean_cycle
43.26 +///
43.27 +/// \file
43.28 +/// \brief Karp's algorithm for finding a minimum mean cycle.
43.29 +
43.30 +#include <vector>
43.31 +#include <limits>
43.32 +#include <lemon/core.h>
43.33 +#include <lemon/path.h>
43.34 +#include <lemon/tolerance.h>
43.35 +#include <lemon/connectivity.h>
43.36 +
43.37 +namespace lemon {
43.38 +
43.39 + /// \brief Default traits class of Karp algorithm.
43.40 + ///
43.41 + /// Default traits class of Karp algorithm.
43.42 + /// \tparam GR The type of the digraph.
43.43 + /// \tparam LEN The type of the length map.
43.44 + /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
43.45 +#ifdef DOXYGEN
43.46 + template <typename GR, typename LEN>
43.47 +#else
43.48 + template <typename GR, typename LEN,
43.49 + bool integer = std::numeric_limits<typename LEN::Value>::is_integer>
43.50 +#endif
43.51 + struct KarpDefaultTraits
43.52 + {
43.53 + /// The type of the digraph
43.54 + typedef GR Digraph;
43.55 + /// The type of the length map
43.56 + typedef LEN LengthMap;
43.57 + /// The type of the arc lengths
43.58 + typedef typename LengthMap::Value Value;
43.59 +
43.60 + /// \brief The large value type used for internal computations
43.61 + ///
43.62 + /// The large value type used for internal computations.
43.63 + /// It is \c long \c long if the \c Value type is integer,
43.64 + /// otherwise it is \c double.
43.65 + /// \c Value must be convertible to \c LargeValue.
43.66 + typedef double LargeValue;
43.67 +
43.68 + /// The tolerance type used for internal computations
43.69 + typedef lemon::Tolerance<LargeValue> Tolerance;
43.70 +
43.71 + /// \brief The path type of the found cycles
43.72 + ///
43.73 + /// The path type of the found cycles.
43.74 + /// It must conform to the \ref lemon::concepts::Path "Path" concept
43.75 + /// and it must have an \c addFront() function.
43.76 + typedef lemon::Path<Digraph> Path;
43.77 + };
43.78 +
43.79 + // Default traits class for integer value types
43.80 + template <typename GR, typename LEN>
43.81 + struct KarpDefaultTraits<GR, LEN, true>
43.82 + {
43.83 + typedef GR Digraph;
43.84 + typedef LEN LengthMap;
43.85 + typedef typename LengthMap::Value Value;
43.86 +#ifdef LEMON_HAVE_LONG_LONG
43.87 + typedef long long LargeValue;
43.88 +#else
43.89 + typedef long LargeValue;
43.90 +#endif
43.91 + typedef lemon::Tolerance<LargeValue> Tolerance;
43.92 + typedef lemon::Path<Digraph> Path;
43.93 + };
43.94 +
43.95 +
43.96 + /// \addtogroup min_mean_cycle
43.97 + /// @{
43.98 +
43.99 + /// \brief Implementation of Karp's algorithm for finding a minimum
43.100 + /// mean cycle.
43.101 + ///
43.102 + /// This class implements Karp's algorithm for finding a directed
43.103 + /// cycle of minimum mean length (cost) in a digraph
43.104 + /// \ref amo93networkflows, \ref dasdan98minmeancycle.
43.105 + /// It runs in time O(ne) and uses space O(n<sup>2</sup>+e).
43.106 + ///
43.107 + /// \tparam GR The type of the digraph the algorithm runs on.
43.108 + /// \tparam LEN The type of the length map. The default
43.109 + /// map type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
43.110 +#ifdef DOXYGEN
43.111 + template <typename GR, typename LEN, typename TR>
43.112 +#else
43.113 + template < typename GR,
43.114 + typename LEN = typename GR::template ArcMap<int>,
43.115 + typename TR = KarpDefaultTraits<GR, LEN> >
43.116 +#endif
43.117 + class Karp
43.118 + {
43.119 + public:
43.120 +
43.121 + /// The type of the digraph
43.122 + typedef typename TR::Digraph Digraph;
43.123 + /// The type of the length map
43.124 + typedef typename TR::LengthMap LengthMap;
43.125 + /// The type of the arc lengths
43.126 + typedef typename TR::Value Value;
43.127 +
43.128 + /// \brief The large value type
43.129 + ///
43.130 + /// The large value type used for internal computations.
43.131 + /// Using the \ref KarpDefaultTraits "default traits class",
43.132 + /// it is \c long \c long if the \c Value type is integer,
43.133 + /// otherwise it is \c double.
43.134 + typedef typename TR::LargeValue LargeValue;
43.135 +
43.136 + /// The tolerance type
43.137 + typedef typename TR::Tolerance Tolerance;
43.138 +
43.139 + /// \brief The path type of the found cycles
43.140 + ///
43.141 + /// The path type of the found cycles.
43.142 + /// Using the \ref KarpDefaultTraits "default traits class",
43.143 + /// it is \ref lemon::Path "Path<Digraph>".
43.144 + typedef typename TR::Path Path;
43.145 +
43.146 + /// The \ref KarpDefaultTraits "traits class" of the algorithm
43.147 + typedef TR Traits;
43.148 +
43.149 + private:
43.150 +
43.151 + TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
43.152 +
43.153 + // Data sturcture for path data
43.154 + struct PathData
43.155 + {
43.156 + LargeValue dist;
43.157 + Arc pred;
43.158 + PathData(LargeValue d, Arc p = INVALID) :
43.159 + dist(d), pred(p) {}
43.160 + };
43.161 +
43.162 + typedef typename Digraph::template NodeMap<std::vector<PathData> >
43.163 + PathDataNodeMap;
43.164 +
43.165 + private:
43.166 +
43.167 + // The digraph the algorithm runs on
43.168 + const Digraph &_gr;
43.169 + // The length of the arcs
43.170 + const LengthMap &_length;
43.171 +
43.172 + // Data for storing the strongly connected components
43.173 + int _comp_num;
43.174 + typename Digraph::template NodeMap<int> _comp;
43.175 + std::vector<std::vector<Node> > _comp_nodes;
43.176 + std::vector<Node>* _nodes;
43.177 + typename Digraph::template NodeMap<std::vector<Arc> > _out_arcs;
43.178 +
43.179 + // Data for the found cycle
43.180 + LargeValue _cycle_length;
43.181 + int _cycle_size;
43.182 + Node _cycle_node;
43.183 +
43.184 + Path *_cycle_path;
43.185 + bool _local_path;
43.186 +
43.187 + // Node map for storing path data
43.188 + PathDataNodeMap _data;
43.189 + // The processed nodes in the last round
43.190 + std::vector<Node> _process;
43.191 +
43.192 + Tolerance _tolerance;
43.193 +
43.194 + // Infinite constant
43.195 + const LargeValue INF;
43.196 +
43.197 + public:
43.198 +
43.199 + /// \name Named Template Parameters
43.200 + /// @{
43.201 +
43.202 + template <typename T>
43.203 + struct SetLargeValueTraits : public Traits {
43.204 + typedef T LargeValue;
43.205 + typedef lemon::Tolerance<T> Tolerance;
43.206 + };
43.207 +
43.208 + /// \brief \ref named-templ-param "Named parameter" for setting
43.209 + /// \c LargeValue type.
43.210 + ///
43.211 + /// \ref named-templ-param "Named parameter" for setting \c LargeValue
43.212 + /// type. It is used for internal computations in the algorithm.
43.213 + template <typename T>
43.214 + struct SetLargeValue
43.215 + : public Karp<GR, LEN, SetLargeValueTraits<T> > {
43.216 + typedef Karp<GR, LEN, SetLargeValueTraits<T> > Create;
43.217 + };
43.218 +
43.219 + template <typename T>
43.220 + struct SetPathTraits : public Traits {
43.221 + typedef T Path;
43.222 + };
43.223 +
43.224 + /// \brief \ref named-templ-param "Named parameter" for setting
43.225 + /// \c %Path type.
43.226 + ///
43.227 + /// \ref named-templ-param "Named parameter" for setting the \c %Path
43.228 + /// type of the found cycles.
43.229 + /// It must conform to the \ref lemon::concepts::Path "Path" concept
43.230 + /// and it must have an \c addFront() function.
43.231 + template <typename T>
43.232 + struct SetPath
43.233 + : public Karp<GR, LEN, SetPathTraits<T> > {
43.234 + typedef Karp<GR, LEN, SetPathTraits<T> > Create;
43.235 + };
43.236 +
43.237 + /// @}
43.238 +
43.239 + public:
43.240 +
43.241 + /// \brief Constructor.
43.242 + ///
43.243 + /// The constructor of the class.
43.244 + ///
43.245 + /// \param digraph The digraph the algorithm runs on.
43.246 + /// \param length The lengths (costs) of the arcs.
43.247 + Karp( const Digraph &digraph,
43.248 + const LengthMap &length ) :
43.249 + _gr(digraph), _length(length), _comp(digraph), _out_arcs(digraph),
43.250 + _cycle_length(0), _cycle_size(1), _cycle_node(INVALID),
43.251 + _cycle_path(NULL), _local_path(false), _data(digraph),
43.252 + INF(std::numeric_limits<LargeValue>::has_infinity ?
43.253 + std::numeric_limits<LargeValue>::infinity() :
43.254 + std::numeric_limits<LargeValue>::max())
43.255 + {}
43.256 +
43.257 + /// Destructor.
43.258 + ~Karp() {
43.259 + if (_local_path) delete _cycle_path;
43.260 + }
43.261 +
43.262 + /// \brief Set the path structure for storing the found cycle.
43.263 + ///
43.264 + /// This function sets an external path structure for storing the
43.265 + /// found cycle.
43.266 + ///
43.267 + /// If you don't call this function before calling \ref run() or
43.268 + /// \ref findMinMean(), it will allocate a local \ref Path "path"
43.269 + /// structure. The destuctor deallocates this automatically
43.270 + /// allocated object, of course.
43.271 + ///
43.272 + /// \note The algorithm calls only the \ref lemon::Path::addFront()
43.273 + /// "addFront()" function of the given path structure.
43.274 + ///
43.275 + /// \return <tt>(*this)</tt>
43.276 + Karp& cycle(Path &path) {
43.277 + if (_local_path) {
43.278 + delete _cycle_path;
43.279 + _local_path = false;
43.280 + }
43.281 + _cycle_path = &path;
43.282 + return *this;
43.283 + }
43.284 +
43.285 + /// \brief Set the tolerance used by the algorithm.
43.286 + ///
43.287 + /// This function sets the tolerance object used by the algorithm.
43.288 + ///
43.289 + /// \return <tt>(*this)</tt>
43.290 + Karp& tolerance(const Tolerance& tolerance) {
43.291 + _tolerance = tolerance;
43.292 + return *this;
43.293 + }
43.294 +
43.295 + /// \brief Return a const reference to the tolerance.
43.296 + ///
43.297 + /// This function returns a const reference to the tolerance object
43.298 + /// used by the algorithm.
43.299 + const Tolerance& tolerance() const {
43.300 + return _tolerance;
43.301 + }
43.302 +
43.303 + /// \name Execution control
43.304 + /// The simplest way to execute the algorithm is to call the \ref run()
43.305 + /// function.\n
43.306 + /// If you only need the minimum mean length, you may call
43.307 + /// \ref findMinMean().
43.308 +
43.309 + /// @{
43.310 +
43.311 + /// \brief Run the algorithm.
43.312 + ///
43.313 + /// This function runs the algorithm.
43.314 + /// It can be called more than once (e.g. if the underlying digraph
43.315 + /// and/or the arc lengths have been modified).
43.316 + ///
43.317 + /// \return \c true if a directed cycle exists in the digraph.
43.318 + ///
43.319 + /// \note <tt>mmc.run()</tt> is just a shortcut of the following code.
43.320 + /// \code
43.321 + /// return mmc.findMinMean() && mmc.findCycle();
43.322 + /// \endcode
43.323 + bool run() {
43.324 + return findMinMean() && findCycle();
43.325 + }
43.326 +
43.327 + /// \brief Find the minimum cycle mean.
43.328 + ///
43.329 + /// This function finds the minimum mean length of the directed
43.330 + /// cycles in the digraph.
43.331 + ///
43.332 + /// \return \c true if a directed cycle exists in the digraph.
43.333 + bool findMinMean() {
43.334 + // Initialization and find strongly connected components
43.335 + init();
43.336 + findComponents();
43.337 +
43.338 + // Find the minimum cycle mean in the components
43.339 + for (int comp = 0; comp < _comp_num; ++comp) {
43.340 + if (!initComponent(comp)) continue;
43.341 + processRounds();
43.342 + updateMinMean();
43.343 + }
43.344 + return (_cycle_node != INVALID);
43.345 + }
43.346 +
43.347 + /// \brief Find a minimum mean directed cycle.
43.348 + ///
43.349 + /// This function finds a directed cycle of minimum mean length
43.350 + /// in the digraph using the data computed by findMinMean().
43.351 + ///
43.352 + /// \return \c true if a directed cycle exists in the digraph.
43.353 + ///
43.354 + /// \pre \ref findMinMean() must be called before using this function.
43.355 + bool findCycle() {
43.356 + if (_cycle_node == INVALID) return false;
43.357 + IntNodeMap reached(_gr, -1);
43.358 + int r = _data[_cycle_node].size();
43.359 + Node u = _cycle_node;
43.360 + while (reached[u] < 0) {
43.361 + reached[u] = --r;
43.362 + u = _gr.source(_data[u][r].pred);
43.363 + }
43.364 + r = reached[u];
43.365 + Arc e = _data[u][r].pred;
43.366 + _cycle_path->addFront(e);
43.367 + _cycle_length = _length[e];
43.368 + _cycle_size = 1;
43.369 + Node v;
43.370 + while ((v = _gr.source(e)) != u) {
43.371 + e = _data[v][--r].pred;
43.372 + _cycle_path->addFront(e);
43.373 + _cycle_length += _length[e];
43.374 + ++_cycle_size;
43.375 + }
43.376 + return true;
43.377 + }
43.378 +
43.379 + /// @}
43.380 +
43.381 + /// \name Query Functions
43.382 + /// The results of the algorithm can be obtained using these
43.383 + /// functions.\n
43.384 + /// The algorithm should be executed before using them.
43.385 +
43.386 + /// @{
43.387 +
43.388 + /// \brief Return the total length of the found cycle.
43.389 + ///
43.390 + /// This function returns the total length of the found cycle.
43.391 + ///
43.392 + /// \pre \ref run() or \ref findMinMean() must be called before
43.393 + /// using this function.
43.394 + LargeValue cycleLength() const {
43.395 + return _cycle_length;
43.396 + }
43.397 +
43.398 + /// \brief Return the number of arcs on the found cycle.
43.399 + ///
43.400 + /// This function returns the number of arcs on the found cycle.
43.401 + ///
43.402 + /// \pre \ref run() or \ref findMinMean() must be called before
43.403 + /// using this function.
43.404 + int cycleArcNum() const {
43.405 + return _cycle_size;
43.406 + }
43.407 +
43.408 + /// \brief Return the mean length of the found cycle.
43.409 + ///
43.410 + /// This function returns the mean length of the found cycle.
43.411 + ///
43.412 + /// \note <tt>alg.cycleMean()</tt> is just a shortcut of the
43.413 + /// following code.
43.414 + /// \code
43.415 + /// return static_cast<double>(alg.cycleLength()) / alg.cycleArcNum();
43.416 + /// \endcode
43.417 + ///
43.418 + /// \pre \ref run() or \ref findMinMean() must be called before
43.419 + /// using this function.
43.420 + double cycleMean() const {
43.421 + return static_cast<double>(_cycle_length) / _cycle_size;
43.422 + }
43.423 +
43.424 + /// \brief Return the found cycle.
43.425 + ///
43.426 + /// This function returns a const reference to the path structure
43.427 + /// storing the found cycle.
43.428 + ///
43.429 + /// \pre \ref run() or \ref findCycle() must be called before using
43.430 + /// this function.
43.431 + const Path& cycle() const {
43.432 + return *_cycle_path;
43.433 + }
43.434 +
43.435 + ///@}
43.436 +
43.437 + private:
43.438 +
43.439 + // Initialization
43.440 + void init() {
43.441 + if (!_cycle_path) {
43.442 + _local_path = true;
43.443 + _cycle_path = new Path;
43.444 + }
43.445 + _cycle_path->clear();
43.446 + _cycle_length = 0;
43.447 + _cycle_size = 1;
43.448 + _cycle_node = INVALID;
43.449 + for (NodeIt u(_gr); u != INVALID; ++u)
43.450 + _data[u].clear();
43.451 + }
43.452 +
43.453 + // Find strongly connected components and initialize _comp_nodes
43.454 + // and _out_arcs
43.455 + void findComponents() {
43.456 + _comp_num = stronglyConnectedComponents(_gr, _comp);
43.457 + _comp_nodes.resize(_comp_num);
43.458 + if (_comp_num == 1) {
43.459 + _comp_nodes[0].clear();
43.460 + for (NodeIt n(_gr); n != INVALID; ++n) {
43.461 + _comp_nodes[0].push_back(n);
43.462 + _out_arcs[n].clear();
43.463 + for (OutArcIt a(_gr, n); a != INVALID; ++a) {
43.464 + _out_arcs[n].push_back(a);
43.465 + }
43.466 + }
43.467 + } else {
43.468 + for (int i = 0; i < _comp_num; ++i)
43.469 + _comp_nodes[i].clear();
43.470 + for (NodeIt n(_gr); n != INVALID; ++n) {
43.471 + int k = _comp[n];
43.472 + _comp_nodes[k].push_back(n);
43.473 + _out_arcs[n].clear();
43.474 + for (OutArcIt a(_gr, n); a != INVALID; ++a) {
43.475 + if (_comp[_gr.target(a)] == k) _out_arcs[n].push_back(a);
43.476 + }
43.477 + }
43.478 + }
43.479 + }
43.480 +
43.481 + // Initialize path data for the current component
43.482 + bool initComponent(int comp) {
43.483 + _nodes = &(_comp_nodes[comp]);
43.484 + int n = _nodes->size();
43.485 + if (n < 1 || (n == 1 && _out_arcs[(*_nodes)[0]].size() == 0)) {
43.486 + return false;
43.487 + }
43.488 + for (int i = 0; i < n; ++i) {
43.489 + _data[(*_nodes)[i]].resize(n + 1, PathData(INF));
43.490 + }
43.491 + return true;
43.492 + }
43.493 +
43.494 + // Process all rounds of computing path data for the current component.
43.495 + // _data[v][k] is the length of a shortest directed walk from the root
43.496 + // node to node v containing exactly k arcs.
43.497 + void processRounds() {
43.498 + Node start = (*_nodes)[0];
43.499 + _data[start][0] = PathData(0);
43.500 + _process.clear();
43.501 + _process.push_back(start);
43.502 +
43.503 + int k, n = _nodes->size();
43.504 + for (k = 1; k <= n && int(_process.size()) < n; ++k) {
43.505 + processNextBuildRound(k);
43.506 + }
43.507 + for ( ; k <= n; ++k) {
43.508 + processNextFullRound(k);
43.509 + }
43.510 + }
43.511 +
43.512 + // Process one round and rebuild _process
43.513 + void processNextBuildRound(int k) {
43.514 + std::vector<Node> next;
43.515 + Node u, v;
43.516 + Arc e;
43.517 + LargeValue d;
43.518 + for (int i = 0; i < int(_process.size()); ++i) {
43.519 + u = _process[i];
43.520 + for (int j = 0; j < int(_out_arcs[u].size()); ++j) {
43.521 + e = _out_arcs[u][j];
43.522 + v = _gr.target(e);
43.523 + d = _data[u][k-1].dist + _length[e];
43.524 + if (_tolerance.less(d, _data[v][k].dist)) {
43.525 + if (_data[v][k].dist == INF) next.push_back(v);
43.526 + _data[v][k] = PathData(d, e);
43.527 + }
43.528 + }
43.529 + }
43.530 + _process.swap(next);
43.531 + }
43.532 +
43.533 + // Process one round using _nodes instead of _process
43.534 + void processNextFullRound(int k) {
43.535 + Node u, v;
43.536 + Arc e;
43.537 + LargeValue d;
43.538 + for (int i = 0; i < int(_nodes->size()); ++i) {
43.539 + u = (*_nodes)[i];
43.540 + for (int j = 0; j < int(_out_arcs[u].size()); ++j) {
43.541 + e = _out_arcs[u][j];
43.542 + v = _gr.target(e);
43.543 + d = _data[u][k-1].dist + _length[e];
43.544 + if (_tolerance.less(d, _data[v][k].dist)) {
43.545 + _data[v][k] = PathData(d, e);
43.546 + }
43.547 + }
43.548 + }
43.549 + }
43.550 +
43.551 + // Update the minimum cycle mean
43.552 + void updateMinMean() {
43.553 + int n = _nodes->size();
43.554 + for (int i = 0; i < n; ++i) {
43.555 + Node u = (*_nodes)[i];
43.556 + if (_data[u][n].dist == INF) continue;
43.557 + LargeValue length, max_length = 0;
43.558 + int size, max_size = 1;
43.559 + bool found_curr = false;
43.560 + for (int k = 0; k < n; ++k) {
43.561 + if (_data[u][k].dist == INF) continue;
43.562 + length = _data[u][n].dist - _data[u][k].dist;
43.563 + size = n - k;
43.564 + if (!found_curr || length * max_size > max_length * size) {
43.565 + found_curr = true;
43.566 + max_length = length;
43.567 + max_size = size;
43.568 + }
43.569 + }
43.570 + if ( found_curr && (_cycle_node == INVALID ||
43.571 + max_length * _cycle_size < _cycle_length * max_size) ) {
43.572 + _cycle_length = max_length;
43.573 + _cycle_size = max_size;
43.574 + _cycle_node = u;
43.575 + }
43.576 + }
43.577 + }
43.578 +
43.579 + }; //class Karp
43.580 +
43.581 + ///@}
43.582 +
43.583 +} //namespace lemon
43.584 +
43.585 +#endif //LEMON_KARP_H
44.1 --- a/lemon/lgf_reader.h Sun Oct 04 10:15:32 2009 +0200
44.2 +++ b/lemon/lgf_reader.h Wed Dec 09 11:14:06 2009 +0100
44.3 @@ -427,7 +427,7 @@
44.4 /// run();
44.5 ///\endcode
44.6 ///
44.7 - /// By default the reader uses the first section in the file of the
44.8 + /// By default, the reader uses the first section in the file of the
44.9 /// proper type. If a section has an optional name, then it can be
44.10 /// selected for reading by giving an optional name parameter to the
44.11 /// \c nodes(), \c arcs() or \c attributes() functions.
44.12 @@ -2221,7 +2221,7 @@
44.13 /// and the comment lines are filtered out, and the leading
44.14 /// whitespaces are trimmed from each processed string.
44.15 ///
44.16 - /// For example let's see a section, which contain several
44.17 + /// For example, let's see a section, which contain several
44.18 /// integers, which should be inserted into a vector.
44.19 ///\code
44.20 /// @numbers
45.1 --- a/lemon/list_graph.h Sun Oct 04 10:15:32 2009 +0200
45.2 +++ b/lemon/list_graph.h Wed Dec 09 11:14:06 2009 +0100
45.3 @@ -21,7 +21,7 @@
45.4
45.5 ///\ingroup graphs
45.6 ///\file
45.7 -///\brief ListDigraph, ListGraph classes.
45.8 +///\brief ListDigraph and ListGraph classes.
45.9
45.10 #include <lemon/core.h>
45.11 #include <lemon/error.h>
45.12 @@ -32,6 +32,8 @@
45.13
45.14 namespace lemon {
45.15
45.16 + class ListDigraph;
45.17 +
45.18 class ListDigraphBase {
45.19
45.20 protected:
45.21 @@ -62,6 +64,7 @@
45.22
45.23 class Node {
45.24 friend class ListDigraphBase;
45.25 + friend class ListDigraph;
45.26 protected:
45.27
45.28 int id;
45.29 @@ -77,6 +80,7 @@
45.30
45.31 class Arc {
45.32 friend class ListDigraphBase;
45.33 + friend class ListDigraph;
45.34 protected:
45.35
45.36 int id;
45.37 @@ -116,20 +120,20 @@
45.38 void first(Arc& arc) const {
45.39 int n;
45.40 for(n = first_node;
45.41 - n!=-1 && nodes[n].first_in == -1;
45.42 + n != -1 && nodes[n].first_out == -1;
45.43 n = nodes[n].next) {}
45.44 - arc.id = (n == -1) ? -1 : nodes[n].first_in;
45.45 + arc.id = (n == -1) ? -1 : nodes[n].first_out;
45.46 }
45.47
45.48 void next(Arc& arc) const {
45.49 - if (arcs[arc.id].next_in != -1) {
45.50 - arc.id = arcs[arc.id].next_in;
45.51 + if (arcs[arc.id].next_out != -1) {
45.52 + arc.id = arcs[arc.id].next_out;
45.53 } else {
45.54 int n;
45.55 - for(n = nodes[arcs[arc.id].target].next;
45.56 - n!=-1 && nodes[n].first_in == -1;
45.57 + for(n = nodes[arcs[arc.id].source].next;
45.58 + n != -1 && nodes[n].first_out == -1;
45.59 n = nodes[n].next) {}
45.60 - arc.id = (n == -1) ? -1 : nodes[n].first_in;
45.61 + arc.id = (n == -1) ? -1 : nodes[n].first_out;
45.62 }
45.63 }
45.64
45.65 @@ -311,31 +315,27 @@
45.66
45.67 ///A general directed graph structure.
45.68
45.69 - ///\ref ListDigraph is a simple and fast <em>directed graph</em>
45.70 - ///implementation based on static linked lists that are stored in
45.71 + ///\ref ListDigraph is a versatile and fast directed graph
45.72 + ///implementation based on linked lists that are stored in
45.73 ///\c std::vector structures.
45.74 ///
45.75 - ///It conforms to the \ref concepts::Digraph "Digraph concept" and it
45.76 - ///also provides several useful additional functionalities.
45.77 - ///Most of the member functions and nested classes are documented
45.78 + ///This type fully conforms to the \ref concepts::Digraph "Digraph concept"
45.79 + ///and it also provides several useful additional functionalities.
45.80 + ///Most of its member functions and nested classes are documented
45.81 ///only in the concept class.
45.82 ///
45.83 + ///This class provides only linear time counting for nodes and arcs.
45.84 + ///
45.85 ///\sa concepts::Digraph
45.86 -
45.87 + ///\sa ListGraph
45.88 class ListDigraph : public ExtendedListDigraphBase {
45.89 typedef ExtendedListDigraphBase Parent;
45.90
45.91 private:
45.92 - ///ListDigraph is \e not copy constructible. Use copyDigraph() instead.
45.93 -
45.94 - ///ListDigraph is \e not copy constructible. Use copyDigraph() instead.
45.95 - ///
45.96 + /// Digraphs are \e not copy constructible. Use DigraphCopy instead.
45.97 ListDigraph(const ListDigraph &) :ExtendedListDigraphBase() {};
45.98 - ///\brief Assignment of ListDigraph to another one is \e not allowed.
45.99 - ///Use copyDigraph() instead.
45.100 -
45.101 - ///Assignment of ListDigraph to another one is \e not allowed.
45.102 - ///Use copyDigraph() instead.
45.103 + /// \brief Assignment of a digraph to another one is \e not allowed.
45.104 + /// Use DigraphCopy instead.
45.105 void operator=(const ListDigraph &) {}
45.106 public:
45.107
45.108 @@ -347,71 +347,72 @@
45.109
45.110 ///Add a new node to the digraph.
45.111
45.112 - ///Add a new node to the digraph.
45.113 + ///This function adds a new node to the digraph.
45.114 ///\return The new node.
45.115 Node addNode() { return Parent::addNode(); }
45.116
45.117 ///Add a new arc to the digraph.
45.118
45.119 - ///Add a new arc to the digraph with source node \c s
45.120 + ///This function adds a new arc to the digraph with source node \c s
45.121 ///and target node \c t.
45.122 ///\return The new arc.
45.123 - Arc addArc(const Node& s, const Node& t) {
45.124 + Arc addArc(Node s, Node t) {
45.125 return Parent::addArc(s, t);
45.126 }
45.127
45.128 ///\brief Erase a node from the digraph.
45.129 ///
45.130 - ///Erase a node from the digraph.
45.131 + ///This function erases the given node along with its outgoing and
45.132 + ///incoming arcs from the digraph.
45.133 ///
45.134 - void erase(const Node& n) { Parent::erase(n); }
45.135 + ///\note All iterators referencing the removed node or the connected
45.136 + ///arcs are invalidated, of course.
45.137 + void erase(Node n) { Parent::erase(n); }
45.138
45.139 ///\brief Erase an arc from the digraph.
45.140 ///
45.141 - ///Erase an arc from the digraph.
45.142 + ///This function erases the given arc from the digraph.
45.143 ///
45.144 - void erase(const Arc& a) { Parent::erase(a); }
45.145 + ///\note All iterators referencing the removed arc are invalidated,
45.146 + ///of course.
45.147 + void erase(Arc a) { Parent::erase(a); }
45.148
45.149 /// Node validity check
45.150
45.151 - /// This function gives back true if the given node is valid,
45.152 - /// ie. it is a real node of the graph.
45.153 + /// This function gives back \c true if the given node is valid,
45.154 + /// i.e. it is a real node of the digraph.
45.155 ///
45.156 - /// \warning A Node pointing to a removed item
45.157 - /// could become valid again later if new nodes are
45.158 - /// added to the graph.
45.159 + /// \warning A removed node could become valid again if new nodes are
45.160 + /// added to the digraph.
45.161 bool valid(Node n) const { return Parent::valid(n); }
45.162
45.163 /// Arc validity check
45.164
45.165 - /// This function gives back true if the given arc is valid,
45.166 - /// ie. it is a real arc of the graph.
45.167 + /// This function gives back \c true if the given arc is valid,
45.168 + /// i.e. it is a real arc of the digraph.
45.169 ///
45.170 - /// \warning An Arc pointing to a removed item
45.171 - /// could become valid again later if new nodes are
45.172 - /// added to the graph.
45.173 + /// \warning A removed arc could become valid again if new arcs are
45.174 + /// added to the digraph.
45.175 bool valid(Arc a) const { return Parent::valid(a); }
45.176
45.177 - /// Change the target of \c a to \c n
45.178 + /// Change the target node of an arc
45.179
45.180 - /// Change the target of \c a to \c n
45.181 + /// This function changes the target node of the given arc \c a to \c n.
45.182 ///
45.183 - ///\note The <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s referencing
45.184 - ///the changed arc remain valid. However <tt>InArcIt</tt>s are
45.185 - ///invalidated.
45.186 + ///\note \c ArcIt and \c OutArcIt iterators referencing the changed
45.187 + ///arc remain valid, but \c InArcIt iterators are invalidated.
45.188 ///
45.189 ///\warning This functionality cannot be used together with the Snapshot
45.190 ///feature.
45.191 void changeTarget(Arc a, Node n) {
45.192 Parent::changeTarget(a,n);
45.193 }
45.194 - /// Change the source of \c a to \c n
45.195 + /// Change the source node of an arc
45.196
45.197 - /// Change the source of \c a to \c n
45.198 + /// This function changes the source node of the given arc \c a to \c n.
45.199 ///
45.200 - ///\note The <tt>InArcIt</tt>s referencing the changed arc remain
45.201 - ///valid. However the <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s are
45.202 - ///invalidated.
45.203 + ///\note \c InArcIt iterators referencing the changed arc remain
45.204 + ///valid, but \c ArcIt and \c OutArcIt iterators are invalidated.
45.205 ///
45.206 ///\warning This functionality cannot be used together with the Snapshot
45.207 ///feature.
45.208 @@ -419,94 +420,76 @@
45.209 Parent::changeSource(a,n);
45.210 }
45.211
45.212 - /// Invert the direction of an arc.
45.213 + /// Reverse the direction of an arc.
45.214
45.215 - ///\note The <tt>ArcIt</tt>s referencing the changed arc remain
45.216 - ///valid. However <tt>OutArcIt</tt>s and <tt>InArcIt</tt>s are
45.217 - ///invalidated.
45.218 + /// This function reverses the direction of the given arc.
45.219 + ///\note \c ArcIt, \c OutArcIt and \c InArcIt iterators referencing
45.220 + ///the changed arc are invalidated.
45.221 ///
45.222 ///\warning This functionality cannot be used together with the Snapshot
45.223 ///feature.
45.224 - void reverseArc(Arc e) {
45.225 - Node t=target(e);
45.226 - changeTarget(e,source(e));
45.227 - changeSource(e,t);
45.228 + void reverseArc(Arc a) {
45.229 + Node t=target(a);
45.230 + changeTarget(a,source(a));
45.231 + changeSource(a,t);
45.232 }
45.233
45.234 - /// Reserve memory for nodes.
45.235 -
45.236 - /// Using this function it is possible to avoid the superfluous memory
45.237 - /// allocation: if you know that the digraph you want to build will
45.238 - /// be very large (e.g. it will contain millions of nodes and/or arcs)
45.239 - /// then it is worth reserving space for this amount before starting
45.240 - /// to build the digraph.
45.241 - /// \sa reserveArc
45.242 - void reserveNode(int n) { nodes.reserve(n); };
45.243 -
45.244 - /// Reserve memory for arcs.
45.245 -
45.246 - /// Using this function it is possible to avoid the superfluous memory
45.247 - /// allocation: if you know that the digraph you want to build will
45.248 - /// be very large (e.g. it will contain millions of nodes and/or arcs)
45.249 - /// then it is worth reserving space for this amount before starting
45.250 - /// to build the digraph.
45.251 - /// \sa reserveNode
45.252 - void reserveArc(int m) { arcs.reserve(m); };
45.253 -
45.254 ///Contract two nodes.
45.255
45.256 - ///This function contracts two nodes.
45.257 - ///Node \p b will be removed but instead of deleting
45.258 - ///incident arcs, they will be joined to \p a.
45.259 - ///The last parameter \p r controls whether to remove loops. \c true
45.260 - ///means that loops will be removed.
45.261 + ///This function contracts the given two nodes.
45.262 + ///Node \c v is removed, but instead of deleting its
45.263 + ///incident arcs, they are joined to node \c u.
45.264 + ///If the last parameter \c r is \c true (this is the default value),
45.265 + ///then the newly created loops are removed.
45.266 ///
45.267 - ///\note The <tt>ArcIt</tt>s referencing a moved arc remain
45.268 - ///valid. However <tt>InArcIt</tt>s and <tt>OutArcIt</tt>s
45.269 - ///may be invalidated.
45.270 + ///\note The moved arcs are joined to node \c u using changeSource()
45.271 + ///or changeTarget(), thus \c ArcIt and \c OutArcIt iterators are
45.272 + ///invalidated for the outgoing arcs of node \c v and \c InArcIt
45.273 + ///iterators are invalidated for the incomming arcs of \c v.
45.274 + ///Moreover all iterators referencing node \c v or the removed
45.275 + ///loops are also invalidated. Other iterators remain valid.
45.276 ///
45.277 ///\warning This functionality cannot be used together with the Snapshot
45.278 ///feature.
45.279 - void contract(Node a, Node b, bool r = true)
45.280 + void contract(Node u, Node v, bool r = true)
45.281 {
45.282 - for(OutArcIt e(*this,b);e!=INVALID;) {
45.283 + for(OutArcIt e(*this,v);e!=INVALID;) {
45.284 OutArcIt f=e;
45.285 ++f;
45.286 - if(r && target(e)==a) erase(e);
45.287 - else changeSource(e,a);
45.288 + if(r && target(e)==u) erase(e);
45.289 + else changeSource(e,u);
45.290 e=f;
45.291 }
45.292 - for(InArcIt e(*this,b);e!=INVALID;) {
45.293 + for(InArcIt e(*this,v);e!=INVALID;) {
45.294 InArcIt f=e;
45.295 ++f;
45.296 - if(r && source(e)==a) erase(e);
45.297 - else changeTarget(e,a);
45.298 + if(r && source(e)==u) erase(e);
45.299 + else changeTarget(e,u);
45.300 e=f;
45.301 }
45.302 - erase(b);
45.303 + erase(v);
45.304 }
45.305
45.306 ///Split a node.
45.307
45.308 - ///This function splits a node. First a new node is added to the digraph,
45.309 - ///then the source of each outgoing arc of \c n is moved to this new node.
45.310 - ///If \c connect is \c true (this is the default value), then a new arc
45.311 - ///from \c n to the newly created node is also added.
45.312 + ///This function splits the given node. First, a new node is added
45.313 + ///to the digraph, then the source of each outgoing arc of node \c n
45.314 + ///is moved to this new node.
45.315 + ///If the second parameter \c connect is \c true (this is the default
45.316 + ///value), then a new arc from node \c n to the newly created node
45.317 + ///is also added.
45.318 ///\return The newly created node.
45.319 ///
45.320 - ///\note The <tt>ArcIt</tt>s referencing a moved arc remain
45.321 - ///valid. However <tt>InArcIt</tt>s and <tt>OutArcIt</tt>s may
45.322 - ///be invalidated.
45.323 + ///\note All iterators remain valid.
45.324 ///
45.325 - ///\warning This functionality cannot be used in conjunction with the
45.326 + ///\warning This functionality cannot be used together with the
45.327 ///Snapshot feature.
45.328 Node split(Node n, bool connect = true) {
45.329 Node b = addNode();
45.330 - for(OutArcIt e(*this,n);e!=INVALID;) {
45.331 - OutArcIt f=e;
45.332 - ++f;
45.333 - changeSource(e,b);
45.334 - e=f;
45.335 + nodes[b.id].first_out=nodes[n.id].first_out;
45.336 + nodes[n.id].first_out=-1;
45.337 + for(int i=nodes[b.id].first_out; i!=-1; i=arcs[i].next_out) {
45.338 + arcs[i].source=b.id;
45.339 }
45.340 if (connect) addArc(n,b);
45.341 return b;
45.342 @@ -514,21 +497,53 @@
45.343
45.344 ///Split an arc.
45.345
45.346 - ///This function splits an arc. First a new node \c b is added to
45.347 - ///the digraph, then the original arc is re-targeted to \c
45.348 - ///b. Finally an arc from \c b to the original target is added.
45.349 + ///This function splits the given arc. First, a new node \c v is
45.350 + ///added to the digraph, then the target node of the original arc
45.351 + ///is set to \c v. Finally, an arc from \c v to the original target
45.352 + ///is added.
45.353 + ///\return The newly created node.
45.354 ///
45.355 - ///\return The newly created node.
45.356 + ///\note \c InArcIt iterators referencing the original arc are
45.357 + ///invalidated. Other iterators remain valid.
45.358 ///
45.359 ///\warning This functionality cannot be used together with the
45.360 ///Snapshot feature.
45.361 - Node split(Arc e) {
45.362 - Node b = addNode();
45.363 - addArc(b,target(e));
45.364 - changeTarget(e,b);
45.365 - return b;
45.366 + Node split(Arc a) {
45.367 + Node v = addNode();
45.368 + addArc(v,target(a));
45.369 + changeTarget(a,v);
45.370 + return v;
45.371 }
45.372
45.373 + ///Clear the digraph.
45.374 +
45.375 + ///This function erases all nodes and arcs from the digraph.
45.376 + ///
45.377 + ///\note All iterators of the digraph are invalidated, of course.
45.378 + void clear() {
45.379 + Parent::clear();
45.380 + }
45.381 +
45.382 + /// Reserve memory for nodes.
45.383 +
45.384 + /// Using this function, it is possible to avoid superfluous memory
45.385 + /// allocation: if you know that the digraph you want to build will
45.386 + /// be large (e.g. it will contain millions of nodes and/or arcs),
45.387 + /// then it is worth reserving space for this amount before starting
45.388 + /// to build the digraph.
45.389 + /// \sa reserveArc()
45.390 + void reserveNode(int n) { nodes.reserve(n); };
45.391 +
45.392 + /// Reserve memory for arcs.
45.393 +
45.394 + /// Using this function, it is possible to avoid superfluous memory
45.395 + /// allocation: if you know that the digraph you want to build will
45.396 + /// be large (e.g. it will contain millions of nodes and/or arcs),
45.397 + /// then it is worth reserving space for this amount before starting
45.398 + /// to build the digraph.
45.399 + /// \sa reserveNode()
45.400 + void reserveArc(int m) { arcs.reserve(m); };
45.401 +
45.402 /// \brief Class to make a snapshot of the digraph and restore
45.403 /// it later.
45.404 ///
45.405 @@ -537,9 +552,15 @@
45.406 /// The newly added nodes and arcs can be removed using the
45.407 /// restore() function.
45.408 ///
45.409 - /// \warning Arc and node deletions and other modifications (e.g.
45.410 - /// contracting, splitting, reversing arcs or nodes) cannot be
45.411 + /// \note After a state is restored, you cannot restore a later state,
45.412 + /// i.e. you cannot add the removed nodes and arcs again using
45.413 + /// another Snapshot instance.
45.414 + ///
45.415 + /// \warning Node and arc deletions and other modifications (e.g.
45.416 + /// reversing, contracting, splitting arcs or nodes) cannot be
45.417 /// restored. These events invalidate the snapshot.
45.418 + /// However, the arcs and nodes that were added to the digraph after
45.419 + /// making the current snapshot can be removed without invalidating it.
45.420 class Snapshot {
45.421 protected:
45.422
45.423 @@ -709,39 +730,40 @@
45.424 /// \brief Default constructor.
45.425 ///
45.426 /// Default constructor.
45.427 - /// To actually make a snapshot you must call save().
45.428 + /// You have to call save() to actually make a snapshot.
45.429 Snapshot()
45.430 : digraph(0), node_observer_proxy(*this),
45.431 arc_observer_proxy(*this) {}
45.432
45.433 /// \brief Constructor that immediately makes a snapshot.
45.434 ///
45.435 - /// This constructor immediately makes a snapshot of the digraph.
45.436 - /// \param _digraph The digraph we make a snapshot of.
45.437 - Snapshot(ListDigraph &_digraph)
45.438 + /// This constructor immediately makes a snapshot of the given digraph.
45.439 + Snapshot(ListDigraph &gr)
45.440 : node_observer_proxy(*this),
45.441 arc_observer_proxy(*this) {
45.442 - attach(_digraph);
45.443 + attach(gr);
45.444 }
45.445
45.446 /// \brief Make a snapshot.
45.447 ///
45.448 - /// Make a snapshot of the digraph.
45.449 - ///
45.450 - /// This function can be called more than once. In case of a repeated
45.451 + /// This function makes a snapshot of the given digraph.
45.452 + /// It can be called more than once. In case of a repeated
45.453 /// call, the previous snapshot gets lost.
45.454 - /// \param _digraph The digraph we make the snapshot of.
45.455 - void save(ListDigraph &_digraph) {
45.456 + void save(ListDigraph &gr) {
45.457 if (attached()) {
45.458 detach();
45.459 clear();
45.460 }
45.461 - attach(_digraph);
45.462 + attach(gr);
45.463 }
45.464
45.465 /// \brief Undo the changes until the last snapshot.
45.466 - //
45.467 - /// Undo the changes until the last snapshot created by save().
45.468 + ///
45.469 + /// This function undos the changes until the last snapshot
45.470 + /// created by save() or Snapshot(ListDigraph&).
45.471 + ///
45.472 + /// \warning This method invalidates the snapshot, i.e. repeated
45.473 + /// restoring is not supported unless you call save() again.
45.474 void restore() {
45.475 detach();
45.476 for(std::list<Arc>::iterator it = added_arcs.begin();
45.477 @@ -755,9 +777,9 @@
45.478 clear();
45.479 }
45.480
45.481 - /// \brief Gives back true when the snapshot is valid.
45.482 + /// \brief Returns \c true if the snapshot is valid.
45.483 ///
45.484 - /// Gives back true when the snapshot is valid.
45.485 + /// This function returns \c true if the snapshot is valid.
45.486 bool valid() const {
45.487 return attached();
45.488 }
45.489 @@ -795,10 +817,6 @@
45.490
45.491 typedef ListGraphBase Graph;
45.492
45.493 - class Node;
45.494 - class Arc;
45.495 - class Edge;
45.496 -
45.497 class Node {
45.498 friend class ListGraphBase;
45.499 protected:
45.500 @@ -848,8 +866,6 @@
45.501 bool operator<(const Arc& arc) const {return id < arc.id;}
45.502 };
45.503
45.504 -
45.505 -
45.506 ListGraphBase()
45.507 : nodes(), first_node(-1),
45.508 first_free_node(-1), arcs(), first_free_arc(-1) {}
45.509 @@ -1164,31 +1180,27 @@
45.510
45.511 ///A general undirected graph structure.
45.512
45.513 - ///\ref ListGraph is a simple and fast <em>undirected graph</em>
45.514 - ///implementation based on static linked lists that are stored in
45.515 + ///\ref ListGraph is a versatile and fast undirected graph
45.516 + ///implementation based on linked lists that are stored in
45.517 ///\c std::vector structures.
45.518 ///
45.519 - ///It conforms to the \ref concepts::Graph "Graph concept" and it
45.520 - ///also provides several useful additional functionalities.
45.521 - ///Most of the member functions and nested classes are documented
45.522 + ///This type fully conforms to the \ref concepts::Graph "Graph concept"
45.523 + ///and it also provides several useful additional functionalities.
45.524 + ///Most of its member functions and nested classes are documented
45.525 ///only in the concept class.
45.526 ///
45.527 + ///This class provides only linear time counting for nodes, edges and arcs.
45.528 + ///
45.529 ///\sa concepts::Graph
45.530 -
45.531 + ///\sa ListDigraph
45.532 class ListGraph : public ExtendedListGraphBase {
45.533 typedef ExtendedListGraphBase Parent;
45.534
45.535 private:
45.536 - ///ListGraph is \e not copy constructible. Use copyGraph() instead.
45.537 -
45.538 - ///ListGraph is \e not copy constructible. Use copyGraph() instead.
45.539 - ///
45.540 + /// Graphs are \e not copy constructible. Use GraphCopy instead.
45.541 ListGraph(const ListGraph &) :ExtendedListGraphBase() {};
45.542 - ///\brief Assignment of ListGraph to another one is \e not allowed.
45.543 - ///Use copyGraph() instead.
45.544 -
45.545 - ///Assignment of ListGraph to another one is \e not allowed.
45.546 - ///Use copyGraph() instead.
45.547 + /// \brief Assignment of a graph to another one is \e not allowed.
45.548 + /// Use GraphCopy instead.
45.549 void operator=(const ListGraph &) {}
45.550 public:
45.551 /// Constructor
45.552 @@ -1201,94 +1213,102 @@
45.553
45.554 /// \brief Add a new node to the graph.
45.555 ///
45.556 - /// Add a new node to the graph.
45.557 + /// This function adds a new node to the graph.
45.558 /// \return The new node.
45.559 Node addNode() { return Parent::addNode(); }
45.560
45.561 /// \brief Add a new edge to the graph.
45.562 ///
45.563 - /// Add a new edge to the graph with source node \c s
45.564 - /// and target node \c t.
45.565 + /// This function adds a new edge to the graph between nodes
45.566 + /// \c u and \c v with inherent orientation from node \c u to
45.567 + /// node \c v.
45.568 /// \return The new edge.
45.569 - Edge addEdge(const Node& s, const Node& t) {
45.570 - return Parent::addEdge(s, t);
45.571 + Edge addEdge(Node u, Node v) {
45.572 + return Parent::addEdge(u, v);
45.573 }
45.574
45.575 - /// \brief Erase a node from the graph.
45.576 + ///\brief Erase a node from the graph.
45.577 ///
45.578 - /// Erase a node from the graph.
45.579 + /// This function erases the given node along with its incident arcs
45.580 + /// from the graph.
45.581 ///
45.582 - void erase(const Node& n) { Parent::erase(n); }
45.583 + /// \note All iterators referencing the removed node or the incident
45.584 + /// edges are invalidated, of course.
45.585 + void erase(Node n) { Parent::erase(n); }
45.586
45.587 - /// \brief Erase an edge from the graph.
45.588 + ///\brief Erase an edge from the graph.
45.589 ///
45.590 - /// Erase an edge from the graph.
45.591 + /// This function erases the given edge from the graph.
45.592 ///
45.593 - void erase(const Edge& e) { Parent::erase(e); }
45.594 + /// \note All iterators referencing the removed edge are invalidated,
45.595 + /// of course.
45.596 + void erase(Edge e) { Parent::erase(e); }
45.597 /// Node validity check
45.598
45.599 - /// This function gives back true if the given node is valid,
45.600 - /// ie. it is a real node of the graph.
45.601 + /// This function gives back \c true if the given node is valid,
45.602 + /// i.e. it is a real node of the graph.
45.603 ///
45.604 - /// \warning A Node pointing to a removed item
45.605 - /// could become valid again later if new nodes are
45.606 + /// \warning A removed node could become valid again if new nodes are
45.607 /// added to the graph.
45.608 bool valid(Node n) const { return Parent::valid(n); }
45.609 + /// Edge validity check
45.610 +
45.611 + /// This function gives back \c true if the given edge is valid,
45.612 + /// i.e. it is a real edge of the graph.
45.613 + ///
45.614 + /// \warning A removed edge could become valid again if new edges are
45.615 + /// added to the graph.
45.616 + bool valid(Edge e) const { return Parent::valid(e); }
45.617 /// Arc validity check
45.618
45.619 - /// This function gives back true if the given arc is valid,
45.620 - /// ie. it is a real arc of the graph.
45.621 + /// This function gives back \c true if the given arc is valid,
45.622 + /// i.e. it is a real arc of the graph.
45.623 ///
45.624 - /// \warning An Arc pointing to a removed item
45.625 - /// could become valid again later if new edges are
45.626 + /// \warning A removed arc could become valid again if new edges are
45.627 /// added to the graph.
45.628 bool valid(Arc a) const { return Parent::valid(a); }
45.629 - /// Edge validity check
45.630
45.631 - /// This function gives back true if the given edge is valid,
45.632 - /// ie. it is a real arc of the graph.
45.633 + /// \brief Change the first node of an edge.
45.634 ///
45.635 - /// \warning A Edge pointing to a removed item
45.636 - /// could become valid again later if new edges are
45.637 - /// added to the graph.
45.638 - bool valid(Edge e) const { return Parent::valid(e); }
45.639 - /// \brief Change the end \c u of \c e to \c n
45.640 + /// This function changes the first node of the given edge \c e to \c n.
45.641 ///
45.642 - /// This function changes the end \c u of \c e to node \c n.
45.643 - ///
45.644 - ///\note The <tt>EdgeIt</tt>s and <tt>ArcIt</tt>s referencing the
45.645 - ///changed edge are invalidated and if the changed node is the
45.646 - ///base node of an iterator then this iterator is also
45.647 - ///invalidated.
45.648 + ///\note \c EdgeIt and \c ArcIt iterators referencing the
45.649 + ///changed edge are invalidated and all other iterators whose
45.650 + ///base node is the changed node are also invalidated.
45.651 ///
45.652 ///\warning This functionality cannot be used together with the
45.653 ///Snapshot feature.
45.654 void changeU(Edge e, Node n) {
45.655 Parent::changeU(e,n);
45.656 }
45.657 - /// \brief Change the end \c v of \c e to \c n
45.658 + /// \brief Change the second node of an edge.
45.659 ///
45.660 - /// This function changes the end \c v of \c e to \c n.
45.661 + /// This function changes the second node of the given edge \c e to \c n.
45.662 ///
45.663 - ///\note The <tt>EdgeIt</tt>s referencing the changed edge remain
45.664 - ///valid, however <tt>ArcIt</tt>s and if the changed node is the
45.665 - ///base node of an iterator then this iterator is invalidated.
45.666 + ///\note \c EdgeIt iterators referencing the changed edge remain
45.667 + ///valid, but \c ArcIt iterators referencing the changed edge and
45.668 + ///all other iterators whose base node is the changed node are also
45.669 + ///invalidated.
45.670 ///
45.671 ///\warning This functionality cannot be used together with the
45.672 ///Snapshot feature.
45.673 void changeV(Edge e, Node n) {
45.674 Parent::changeV(e,n);
45.675 }
45.676 +
45.677 /// \brief Contract two nodes.
45.678 ///
45.679 - /// This function contracts two nodes.
45.680 - /// Node \p b will be removed but instead of deleting
45.681 - /// its neighboring arcs, they will be joined to \p a.
45.682 - /// The last parameter \p r controls whether to remove loops. \c true
45.683 - /// means that loops will be removed.
45.684 + /// This function contracts the given two nodes.
45.685 + /// Node \c b is removed, but instead of deleting
45.686 + /// its incident edges, they are joined to node \c a.
45.687 + /// If the last parameter \c r is \c true (this is the default value),
45.688 + /// then the newly created loops are removed.
45.689 ///
45.690 - /// \note The <tt>ArcIt</tt>s referencing a moved arc remain
45.691 - /// valid.
45.692 + /// \note The moved edges are joined to node \c a using changeU()
45.693 + /// or changeV(), thus all edge and arc iterators whose base node is
45.694 + /// \c b are invalidated.
45.695 + /// Moreover all iterators referencing node \c b or the removed
45.696 + /// loops are also invalidated. Other iterators remain valid.
45.697 ///
45.698 ///\warning This functionality cannot be used together with the
45.699 ///Snapshot feature.
45.700 @@ -1307,6 +1327,34 @@
45.701 erase(b);
45.702 }
45.703
45.704 + ///Clear the graph.
45.705 +
45.706 + ///This function erases all nodes and arcs from the graph.
45.707 + ///
45.708 + ///\note All iterators of the graph are invalidated, of course.
45.709 + void clear() {
45.710 + Parent::clear();
45.711 + }
45.712 +
45.713 + /// Reserve memory for nodes.
45.714 +
45.715 + /// Using this function, it is possible to avoid superfluous memory
45.716 + /// allocation: if you know that the graph you want to build will
45.717 + /// be large (e.g. it will contain millions of nodes and/or edges),
45.718 + /// then it is worth reserving space for this amount before starting
45.719 + /// to build the graph.
45.720 + /// \sa reserveEdge()
45.721 + void reserveNode(int n) { nodes.reserve(n); };
45.722 +
45.723 + /// Reserve memory for edges.
45.724 +
45.725 + /// Using this function, it is possible to avoid superfluous memory
45.726 + /// allocation: if you know that the graph you want to build will
45.727 + /// be large (e.g. it will contain millions of nodes and/or edges),
45.728 + /// then it is worth reserving space for this amount before starting
45.729 + /// to build the graph.
45.730 + /// \sa reserveNode()
45.731 + void reserveEdge(int m) { arcs.reserve(2 * m); };
45.732
45.733 /// \brief Class to make a snapshot of the graph and restore
45.734 /// it later.
45.735 @@ -1316,9 +1364,15 @@
45.736 /// The newly added nodes and edges can be removed
45.737 /// using the restore() function.
45.738 ///
45.739 - /// \warning Edge and node deletions and other modifications
45.740 - /// (e.g. changing nodes of edges, contracting nodes) cannot be
45.741 - /// restored. These events invalidate the snapshot.
45.742 + /// \note After a state is restored, you cannot restore a later state,
45.743 + /// i.e. you cannot add the removed nodes and edges again using
45.744 + /// another Snapshot instance.
45.745 + ///
45.746 + /// \warning Node and edge deletions and other modifications
45.747 + /// (e.g. changing the end-nodes of edges or contracting nodes)
45.748 + /// cannot be restored. These events invalidate the snapshot.
45.749 + /// However, the edges and nodes that were added to the graph after
45.750 + /// making the current snapshot can be removed without invalidating it.
45.751 class Snapshot {
45.752 protected:
45.753
45.754 @@ -1488,39 +1542,40 @@
45.755 /// \brief Default constructor.
45.756 ///
45.757 /// Default constructor.
45.758 - /// To actually make a snapshot you must call save().
45.759 + /// You have to call save() to actually make a snapshot.
45.760 Snapshot()
45.761 : graph(0), node_observer_proxy(*this),
45.762 edge_observer_proxy(*this) {}
45.763
45.764 /// \brief Constructor that immediately makes a snapshot.
45.765 ///
45.766 - /// This constructor immediately makes a snapshot of the graph.
45.767 - /// \param _graph The graph we make a snapshot of.
45.768 - Snapshot(ListGraph &_graph)
45.769 + /// This constructor immediately makes a snapshot of the given graph.
45.770 + Snapshot(ListGraph &gr)
45.771 : node_observer_proxy(*this),
45.772 edge_observer_proxy(*this) {
45.773 - attach(_graph);
45.774 + attach(gr);
45.775 }
45.776
45.777 /// \brief Make a snapshot.
45.778 ///
45.779 - /// Make a snapshot of the graph.
45.780 - ///
45.781 - /// This function can be called more than once. In case of a repeated
45.782 + /// This function makes a snapshot of the given graph.
45.783 + /// It can be called more than once. In case of a repeated
45.784 /// call, the previous snapshot gets lost.
45.785 - /// \param _graph The graph we make the snapshot of.
45.786 - void save(ListGraph &_graph) {
45.787 + void save(ListGraph &gr) {
45.788 if (attached()) {
45.789 detach();
45.790 clear();
45.791 }
45.792 - attach(_graph);
45.793 + attach(gr);
45.794 }
45.795
45.796 /// \brief Undo the changes until the last snapshot.
45.797 - //
45.798 - /// Undo the changes until the last snapshot created by save().
45.799 + ///
45.800 + /// This function undos the changes until the last snapshot
45.801 + /// created by save() or Snapshot(ListGraph&).
45.802 + ///
45.803 + /// \warning This method invalidates the snapshot, i.e. repeated
45.804 + /// restoring is not supported unless you call save() again.
45.805 void restore() {
45.806 detach();
45.807 for(std::list<Edge>::iterator it = added_edges.begin();
45.808 @@ -1534,9 +1589,9 @@
45.809 clear();
45.810 }
45.811
45.812 - /// \brief Gives back true when the snapshot is valid.
45.813 + /// \brief Returns \c true if the snapshot is valid.
45.814 ///
45.815 - /// Gives back true when the snapshot is valid.
45.816 + /// This function returns \c true if the snapshot is valid.
45.817 bool valid() const {
45.818 return attached();
45.819 }
46.1 --- a/lemon/lp_base.h Sun Oct 04 10:15:32 2009 +0200
46.2 +++ b/lemon/lp_base.h Wed Dec 09 11:14:06 2009 +0100
46.3 @@ -146,7 +146,7 @@
46.4
46.5 ///Iterator for iterate over the columns of an LP problem
46.6
46.7 - /// Its usage is quite simple, for example you can count the number
46.8 + /// Its usage is quite simple, for example, you can count the number
46.9 /// of columns in an LP \c lp:
46.10 ///\code
46.11 /// int count=0;
46.12 @@ -241,7 +241,7 @@
46.13
46.14 ///Iterator for iterate over the rows of an LP problem
46.15
46.16 - /// Its usage is quite simple, for example you can count the number
46.17 + /// Its usage is quite simple, for example, you can count the number
46.18 /// of rows in an LP \c lp:
46.19 ///\code
46.20 /// int count=0;
46.21 @@ -943,6 +943,14 @@
46.22 virtual int _addCol() = 0;
46.23 virtual int _addRow() = 0;
46.24
46.25 + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
46.26 + int row = _addRow();
46.27 + _setRowCoeffs(row, b, e);
46.28 + _setRowLowerBound(row, l);
46.29 + _setRowUpperBound(row, u);
46.30 + return row;
46.31 + }
46.32 +
46.33 virtual void _eraseCol(int col) = 0;
46.34 virtual void _eraseRow(int row) = 0;
46.35
46.36 @@ -1207,8 +1215,10 @@
46.37 ///\param u is the upper bound (\ref INF means no bound)
46.38 ///\return The created row.
46.39 Row addRow(Value l,const Expr &e, Value u) {
46.40 - Row r=addRow();
46.41 - row(r,l,e,u);
46.42 + Row r;
46.43 + e.simplify();
46.44 + r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), cols),
46.45 + ExprIterator(e.comps.end(), cols), u - *e));
46.46 return r;
46.47 }
46.48
46.49 @@ -1217,8 +1227,12 @@
46.50 ///\param c is a linear expression (see \ref Constr)
46.51 ///\return The created row.
46.52 Row addRow(const Constr &c) {
46.53 - Row r=addRow();
46.54 - row(r,c);
46.55 + Row r;
46.56 + c.expr().simplify();
46.57 + r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound():-INF,
46.58 + ExprIterator(c.expr().comps.begin(), cols),
46.59 + ExprIterator(c.expr().comps.end(), cols),
46.60 + c.upperBounded()?c.upperBound():INF));
46.61 return r;
46.62 }
46.63 ///Erase a column (i.e a variable) from the LP
47.1 --- a/lemon/lp_skeleton.cc Sun Oct 04 10:15:32 2009 +0200
47.2 +++ b/lemon/lp_skeleton.cc Wed Dec 09 11:14:06 2009 +0100
47.3 @@ -32,6 +32,11 @@
47.4 return ++row_num;
47.5 }
47.6
47.7 + int SkeletonSolverBase::_addRow(Value, ExprIterator, ExprIterator, Value)
47.8 + {
47.9 + return ++row_num;
47.10 + }
47.11 +
47.12 void SkeletonSolverBase::_eraseCol(int) {}
47.13 void SkeletonSolverBase::_eraseRow(int) {}
47.14
48.1 --- a/lemon/lp_skeleton.h Sun Oct 04 10:15:32 2009 +0200
48.2 +++ b/lemon/lp_skeleton.h Wed Dec 09 11:14:06 2009 +0100
48.3 @@ -45,6 +45,8 @@
48.4 /// \e
48.5 virtual int _addRow();
48.6 /// \e
48.7 + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
48.8 + /// \e
48.9 virtual void _eraseCol(int i);
48.10 /// \e
48.11 virtual void _eraseRow(int i);
49.1 --- a/lemon/maps.h Sun Oct 04 10:15:32 2009 +0200
49.2 +++ b/lemon/maps.h Wed Dec 09 11:14:06 2009 +0100
49.3 @@ -56,7 +56,7 @@
49.4 /// its type definitions, or if you have to provide a writable map,
49.5 /// but data written to it is not required (i.e. it will be sent to
49.6 /// <tt>/dev/null</tt>).
49.7 - /// It conforms the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
49.8 + /// It conforms to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
49.9 ///
49.10 /// \sa ConstMap
49.11 template<typename K, typename V>
49.12 @@ -89,7 +89,7 @@
49.13 /// value to each key.
49.14 ///
49.15 /// In other aspects it is equivalent to \c NullMap.
49.16 - /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
49.17 + /// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap"
49.18 /// concept, but it absorbs the data written to it.
49.19 ///
49.20 /// The simplest way of using this map is through the constMap()
49.21 @@ -158,7 +158,7 @@
49.22 /// value to each key.
49.23 ///
49.24 /// In other aspects it is equivalent to \c NullMap.
49.25 - /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
49.26 + /// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap"
49.27 /// concept, but it absorbs the data written to it.
49.28 ///
49.29 /// The simplest way of using this map is through the constMap()
49.30 @@ -230,10 +230,10 @@
49.31 ///
49.32 /// This map is essentially a wrapper for \c std::vector. It assigns
49.33 /// values to integer keys from the range <tt>[0..size-1]</tt>.
49.34 - /// It can be used with some data structures, for example
49.35 - /// \c UnionFind, \c BinHeap, when the used items are small
49.36 - /// integers. This map conforms the \ref concepts::ReferenceMap
49.37 - /// "ReferenceMap" concept.
49.38 + /// It can be used together with some data structures, e.g.
49.39 + /// heap types and \c UnionFind, when the used items are small
49.40 + /// integers. This map conforms to the \ref concepts::ReferenceMap
49.41 + /// "ReferenceMap" concept.
49.42 ///
49.43 /// The simplest way of using this map is through the rangeMap()
49.44 /// function.
49.45 @@ -340,7 +340,7 @@
49.46 /// that you can specify a default value for the keys that are not
49.47 /// stored actually. This value can be different from the default
49.48 /// contructed value (i.e. \c %Value()).
49.49 - /// This type conforms the \ref concepts::ReferenceMap "ReferenceMap"
49.50 + /// This type conforms to the \ref concepts::ReferenceMap "ReferenceMap"
49.51 /// concept.
49.52 ///
49.53 /// This map is useful if a default value should be assigned to most of
49.54 @@ -348,9 +348,9 @@
49.55 /// keys (i.e. the map is "sparse").
49.56 /// The name of this type also refers to this important usage.
49.57 ///
49.58 - /// Apart form that this map can be used in many other cases since it
49.59 + /// Apart form that, this map can be used in many other cases since it
49.60 /// is based on \c std::map, which is a general associative container.
49.61 - /// However keep in mind that it is usually not as efficient as other
49.62 + /// However, keep in mind that it is usually not as efficient as other
49.63 /// maps.
49.64 ///
49.65 /// The simplest way of using this map is through the sparseMap()
49.66 @@ -706,7 +706,7 @@
49.67 /// "readable map" to another type using the default conversion.
49.68 /// The \c Key type of it is inherited from \c M and the \c Value
49.69 /// type is \c V.
49.70 - /// This type conforms the \ref concepts::ReadMap "ReadMap" concept.
49.71 + /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
49.72 ///
49.73 /// The simplest way of using this map is through the convertMap()
49.74 /// function.
49.75 @@ -1785,22 +1785,22 @@
49.76 ///
49.77 /// The most important usage of it is storing certain nodes or arcs
49.78 /// that were marked \c true by an algorithm.
49.79 - /// For example it makes easier to store the nodes in the processing
49.80 + /// For example, it makes easier to store the nodes in the processing
49.81 /// order of Dfs algorithm, as the following examples show.
49.82 /// \code
49.83 /// std::vector<Node> v;
49.84 - /// dfs(g,s).processedMap(loggerBoolMap(std::back_inserter(v))).run();
49.85 + /// dfs(g).processedMap(loggerBoolMap(std::back_inserter(v))).run(s);
49.86 /// \endcode
49.87 /// \code
49.88 /// std::vector<Node> v(countNodes(g));
49.89 - /// dfs(g,s).processedMap(loggerBoolMap(v.begin())).run();
49.90 + /// dfs(g).processedMap(loggerBoolMap(v.begin())).run(s);
49.91 /// \endcode
49.92 ///
49.93 /// \note The container of the iterator must contain enough space
49.94 /// for the elements or the iterator should be an inserter iterator.
49.95 ///
49.96 /// \note LoggerBoolMap is just \ref concepts::WriteMap "writable", so
49.97 - /// it cannot be used when a readable map is needed, for example as
49.98 + /// it cannot be used when a readable map is needed, for example, as
49.99 /// \c ReachedMap for \c Bfs, \c Dfs and \c Dijkstra algorithms.
49.100 ///
49.101 /// \relates LoggerBoolMap
49.102 @@ -1825,7 +1825,7 @@
49.103 /// Using this map you get access (i.e. can read) the inner id values of
49.104 /// the items stored in the graph, which is returned by the \c id()
49.105 /// function of the graph. This map can be inverted with its member
49.106 - /// class \c InverseMap or with the \c operator() member.
49.107 + /// class \c InverseMap or with the \c operator()() member.
49.108 ///
49.109 /// \tparam GR The graph type.
49.110 /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
49.111 @@ -1865,9 +1865,11 @@
49.112
49.113 public:
49.114
49.115 - /// \brief This class represents the inverse of its owner (IdMap).
49.116 + /// \brief The inverse map type of IdMap.
49.117 ///
49.118 - /// This class represents the inverse of its owner (IdMap).
49.119 + /// The inverse map type of IdMap. The subscript operator gives back
49.120 + /// an item by its id.
49.121 + /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
49.122 /// \see inverse()
49.123 class InverseMap {
49.124 public:
49.125 @@ -1882,9 +1884,9 @@
49.126 /// Constructor for creating an id-to-item map.
49.127 explicit InverseMap(const IdMap& map) : _graph(map._graph) {}
49.128
49.129 - /// \brief Gives back the given item from its id.
49.130 + /// \brief Gives back an item by its id.
49.131 ///
49.132 - /// Gives back the given item from its id.
49.133 + /// Gives back an item by its id.
49.134 Item operator[](int id) const { return _graph->fromId(id, Item());}
49.135
49.136 private:
49.137 @@ -1897,14 +1899,31 @@
49.138 InverseMap inverse() const { return InverseMap(*_graph);}
49.139 };
49.140
49.141 + /// \brief Returns an \c IdMap class.
49.142 + ///
49.143 + /// This function just returns an \c IdMap class.
49.144 + /// \relates IdMap
49.145 + template <typename K, typename GR>
49.146 + inline IdMap<GR, K> idMap(const GR& graph) {
49.147 + return IdMap<GR, K>(graph);
49.148 + }
49.149
49.150 /// \brief General cross reference graph map type.
49.151
49.152 /// This class provides simple invertable graph maps.
49.153 /// It wraps a standard graph map (\c NodeMap, \c ArcMap or \c EdgeMap)
49.154 /// and if a key is set to a new value, then stores it in the inverse map.
49.155 - /// The values of the map can be accessed
49.156 - /// with stl compatible forward iterator.
49.157 + /// The graph items can be accessed by their values either using
49.158 + /// \c InverseMap or \c operator()(), and the values of the map can be
49.159 + /// accessed with an STL compatible forward iterator (\c ValueIt).
49.160 + ///
49.161 + /// This map is intended to be used when all associated values are
49.162 + /// different (the map is actually invertable) or there are only a few
49.163 + /// items with the same value.
49.164 + /// Otherwise consider to use \c IterableValueMap, which is more
49.165 + /// suitable and more efficient for such cases. It provides iterators
49.166 + /// to traverse the items with the same associated value, but
49.167 + /// it does not have \c InverseMap.
49.168 ///
49.169 /// This type is not reference map, so it cannot be modified with
49.170 /// the subscript operator.
49.171 @@ -1945,56 +1964,66 @@
49.172
49.173 /// \brief Forward iterator for values.
49.174 ///
49.175 - /// This iterator is an stl compatible forward
49.176 + /// This iterator is an STL compatible forward
49.177 /// iterator on the values of the map. The values can
49.178 /// be accessed in the <tt>[beginValue, endValue)</tt> range.
49.179 /// They are considered with multiplicity, so each value is
49.180 /// traversed for each item it is assigned to.
49.181 - class ValueIterator
49.182 + class ValueIt
49.183 : public std::iterator<std::forward_iterator_tag, Value> {
49.184 friend class CrossRefMap;
49.185 private:
49.186 - ValueIterator(typename Container::const_iterator _it)
49.187 + ValueIt(typename Container::const_iterator _it)
49.188 : it(_it) {}
49.189 public:
49.190
49.191 - ValueIterator() {}
49.192 -
49.193 - ValueIterator& operator++() { ++it; return *this; }
49.194 - ValueIterator operator++(int) {
49.195 - ValueIterator tmp(*this);
49.196 + /// Constructor
49.197 + ValueIt() {}
49.198 +
49.199 + /// \e
49.200 + ValueIt& operator++() { ++it; return *this; }
49.201 + /// \e
49.202 + ValueIt operator++(int) {
49.203 + ValueIt tmp(*this);
49.204 operator++();
49.205 return tmp;
49.206 }
49.207
49.208 + /// \e
49.209 const Value& operator*() const { return it->first; }
49.210 + /// \e
49.211 const Value* operator->() const { return &(it->first); }
49.212
49.213 - bool operator==(ValueIterator jt) const { return it == jt.it; }
49.214 - bool operator!=(ValueIterator jt) const { return it != jt.it; }
49.215 + /// \e
49.216 + bool operator==(ValueIt jt) const { return it == jt.it; }
49.217 + /// \e
49.218 + bool operator!=(ValueIt jt) const { return it != jt.it; }
49.219
49.220 private:
49.221 typename Container::const_iterator it;
49.222 };
49.223 +
49.224 + /// Alias for \c ValueIt
49.225 + typedef ValueIt ValueIterator;
49.226
49.227 /// \brief Returns an iterator to the first value.
49.228 ///
49.229 - /// Returns an stl compatible iterator to the
49.230 + /// Returns an STL compatible iterator to the
49.231 /// first value of the map. The values of the
49.232 /// map can be accessed in the <tt>[beginValue, endValue)</tt>
49.233 /// range.
49.234 - ValueIterator beginValue() const {
49.235 - return ValueIterator(_inv_map.begin());
49.236 + ValueIt beginValue() const {
49.237 + return ValueIt(_inv_map.begin());
49.238 }
49.239
49.240 /// \brief Returns an iterator after the last value.
49.241 ///
49.242 - /// Returns an stl compatible iterator after the
49.243 + /// Returns an STL compatible iterator after the
49.244 /// last value of the map. The values of the
49.245 /// map can be accessed in the <tt>[beginValue, endValue)</tt>
49.246 /// range.
49.247 - ValueIterator endValue() const {
49.248 - return ValueIterator(_inv_map.end());
49.249 + ValueIt endValue() const {
49.250 + return ValueIt(_inv_map.end());
49.251 }
49.252
49.253 /// \brief Sets the value associated with the given key.
49.254 @@ -2032,6 +2061,14 @@
49.255 typename Container::const_iterator it = _inv_map.find(val);
49.256 return it != _inv_map.end() ? it->second : INVALID;
49.257 }
49.258 +
49.259 + /// \brief Returns the number of items with the given value.
49.260 + ///
49.261 + /// This function returns the number of items with the given value
49.262 + /// associated with it.
49.263 + int count(const Value &val) const {
49.264 + return _inv_map.count(val);
49.265 + }
49.266
49.267 protected:
49.268
49.269 @@ -2082,10 +2119,12 @@
49.270
49.271 public:
49.272
49.273 - /// \brief The inverse map type.
49.274 + /// \brief The inverse map type of CrossRefMap.
49.275 ///
49.276 - /// The inverse of this map. The subscript operator of the map
49.277 - /// gives back the item that was last assigned to the value.
49.278 + /// The inverse map type of CrossRefMap. The subscript operator gives
49.279 + /// back an item by its value.
49.280 + /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
49.281 + /// \see inverse()
49.282 class InverseMap {
49.283 public:
49.284 /// \brief Constructor
49.285 @@ -2112,20 +2151,20 @@
49.286 const CrossRefMap& _inverted;
49.287 };
49.288
49.289 - /// \brief It gives back the read-only inverse map.
49.290 + /// \brief Gives back the inverse of the map.
49.291 ///
49.292 - /// It gives back the read-only inverse map.
49.293 + /// Gives back the inverse of the CrossRefMap.
49.294 InverseMap inverse() const {
49.295 return InverseMap(*this);
49.296 }
49.297
49.298 };
49.299
49.300 - /// \brief Provides continuous and unique ID for the
49.301 + /// \brief Provides continuous and unique id for the
49.302 /// items of a graph.
49.303 ///
49.304 /// RangeIdMap provides a unique and continuous
49.305 - /// ID for each item of a given type (\c Node, \c Arc or
49.306 + /// id for each item of a given type (\c Node, \c Arc or
49.307 /// \c Edge) in a graph. This id is
49.308 /// - \b unique: different items get different ids,
49.309 /// - \b continuous: the range of the ids is the set of integers
49.310 @@ -2136,7 +2175,7 @@
49.311 /// Thus this id is not (necessarily) the same as what can get using
49.312 /// the \c id() function of the graph or \ref IdMap.
49.313 /// This map can be inverted with its member class \c InverseMap,
49.314 - /// or with the \c operator() member.
49.315 + /// or with the \c operator()() member.
49.316 ///
49.317 /// \tparam GR The graph type.
49.318 /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
49.319 @@ -2264,16 +2303,16 @@
49.320 _inv_map[pi] = q;
49.321 }
49.322
49.323 - /// \brief Gives back the \e RangeId of the item
49.324 + /// \brief Gives back the \e range \e id of the item
49.325 ///
49.326 - /// Gives back the \e RangeId of the item.
49.327 + /// Gives back the \e range \e id of the item.
49.328 int operator[](const Item& item) const {
49.329 return Map::operator[](item);
49.330 }
49.331
49.332 - /// \brief Gives back the item belonging to a \e RangeId
49.333 + /// \brief Gives back the item belonging to a \e range \e id
49.334 ///
49.335 - /// Gives back the item belonging to a \e RangeId.
49.336 + /// Gives back the item belonging to the given \e range \e id.
49.337 Item operator()(int id) const {
49.338 return _inv_map[id];
49.339 }
49.340 @@ -2287,7 +2326,9 @@
49.341
49.342 /// \brief The inverse map type of RangeIdMap.
49.343 ///
49.344 - /// The inverse map type of RangeIdMap.
49.345 + /// The inverse map type of RangeIdMap. The subscript operator gives
49.346 + /// back an item by its \e range \e id.
49.347 + /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
49.348 class InverseMap {
49.349 public:
49.350 /// \brief Constructor
49.351 @@ -2305,7 +2346,7 @@
49.352 /// \brief Subscript operator.
49.353 ///
49.354 /// Subscript operator. It gives back the item
49.355 - /// that the descriptor currently belongs to.
49.356 + /// that the given \e range \e id currently belongs to.
49.357 Value operator[](const Key& key) const {
49.358 return _inverted(key);
49.359 }
49.360 @@ -2323,18 +2364,27 @@
49.361
49.362 /// \brief Gives back the inverse of the map.
49.363 ///
49.364 - /// Gives back the inverse of the map.
49.365 + /// Gives back the inverse of the RangeIdMap.
49.366 const InverseMap inverse() const {
49.367 return InverseMap(*this);
49.368 }
49.369 };
49.370
49.371 + /// \brief Returns a \c RangeIdMap class.
49.372 + ///
49.373 + /// This function just returns an \c RangeIdMap class.
49.374 + /// \relates RangeIdMap
49.375 + template <typename K, typename GR>
49.376 + inline RangeIdMap<GR, K> rangeIdMap(const GR& graph) {
49.377 + return RangeIdMap<GR, K>(graph);
49.378 + }
49.379 +
49.380 /// \brief Dynamic iterable \c bool map.
49.381 ///
49.382 /// This class provides a special graph map type which can store a
49.383 /// \c bool value for graph items (\c Node, \c Arc or \c Edge).
49.384 /// For both \c true and \c false values it is possible to iterate on
49.385 - /// the keys.
49.386 + /// the keys mapped to the value.
49.387 ///
49.388 /// This type is a reference map, so it can be modified with the
49.389 /// subscript operator.
49.390 @@ -2703,6 +2753,11 @@
49.391 /// For each non-negative value it is possible to iterate on the keys
49.392 /// mapped to the value.
49.393 ///
49.394 + /// This map is intended to be used with small integer values, for which
49.395 + /// it is efficient, and supports iteration only for non-negative values.
49.396 + /// If you need large values and/or iteration for negative integers,
49.397 + /// consider to use \ref IterableValueMap instead.
49.398 + ///
49.399 /// This type is a reference map, so it can be modified with the
49.400 /// subscript operator.
49.401 ///
49.402 @@ -2984,15 +3039,17 @@
49.403
49.404 /// \brief Dynamic iterable map for comparable values.
49.405 ///
49.406 - /// This class provides a special graph map type which can store an
49.407 + /// This class provides a special graph map type which can store a
49.408 /// comparable value for graph items (\c Node, \c Arc or \c Edge).
49.409 /// For each value it is possible to iterate on the keys mapped to
49.410 - /// the value.
49.411 + /// the value (\c ItemIt), and the values of the map can be accessed
49.412 + /// with an STL compatible forward iterator (\c ValueIt).
49.413 + /// The map stores a linked list for each value, which contains
49.414 + /// the items mapped to the value, and the used values are stored
49.415 + /// in balanced binary tree (\c std::map).
49.416 ///
49.417 - /// The map stores for each value a linked list with
49.418 - /// the items which mapped to the value, and the values are stored
49.419 - /// in balanced binary tree. The values of the map can be accessed
49.420 - /// with stl compatible forward iterator.
49.421 + /// \ref IterableBoolMap and \ref IterableIntMap are similar classes
49.422 + /// specialized for \c bool and \c int values, respectively.
49.423 ///
49.424 /// This type is not reference map, so it cannot be modified with
49.425 /// the subscript operator.
49.426 @@ -3071,31 +3128,38 @@
49.427
49.428 /// \brief Forward iterator for values.
49.429 ///
49.430 - /// This iterator is an stl compatible forward
49.431 + /// This iterator is an STL compatible forward
49.432 /// iterator on the values of the map. The values can
49.433 /// be accessed in the <tt>[beginValue, endValue)</tt> range.
49.434 - class ValueIterator
49.435 + class ValueIt
49.436 : public std::iterator<std::forward_iterator_tag, Value> {
49.437 friend class IterableValueMap;
49.438 private:
49.439 - ValueIterator(typename std::map<Value, Key>::const_iterator _it)
49.440 + ValueIt(typename std::map<Value, Key>::const_iterator _it)
49.441 : it(_it) {}
49.442 public:
49.443
49.444 - ValueIterator() {}
49.445 -
49.446 - ValueIterator& operator++() { ++it; return *this; }
49.447 - ValueIterator operator++(int) {
49.448 - ValueIterator tmp(*this);
49.449 + /// Constructor
49.450 + ValueIt() {}
49.451 +
49.452 + /// \e
49.453 + ValueIt& operator++() { ++it; return *this; }
49.454 + /// \e
49.455 + ValueIt operator++(int) {
49.456 + ValueIt tmp(*this);
49.457 operator++();
49.458 return tmp;
49.459 }
49.460
49.461 + /// \e
49.462 const Value& operator*() const { return it->first; }
49.463 + /// \e
49.464 const Value* operator->() const { return &(it->first); }
49.465
49.466 - bool operator==(ValueIterator jt) const { return it == jt.it; }
49.467 - bool operator!=(ValueIterator jt) const { return it != jt.it; }
49.468 + /// \e
49.469 + bool operator==(ValueIt jt) const { return it == jt.it; }
49.470 + /// \e
49.471 + bool operator!=(ValueIt jt) const { return it != jt.it; }
49.472
49.473 private:
49.474 typename std::map<Value, Key>::const_iterator it;
49.475 @@ -3103,22 +3167,22 @@
49.476
49.477 /// \brief Returns an iterator to the first value.
49.478 ///
49.479 - /// Returns an stl compatible iterator to the
49.480 + /// Returns an STL compatible iterator to the
49.481 /// first value of the map. The values of the
49.482 /// map can be accessed in the <tt>[beginValue, endValue)</tt>
49.483 /// range.
49.484 - ValueIterator beginValue() const {
49.485 - return ValueIterator(_first.begin());
49.486 + ValueIt beginValue() const {
49.487 + return ValueIt(_first.begin());
49.488 }
49.489
49.490 /// \brief Returns an iterator after the last value.
49.491 ///
49.492 - /// Returns an stl compatible iterator after the
49.493 + /// Returns an STL compatible iterator after the
49.494 /// last value of the map. The values of the
49.495 /// map can be accessed in the <tt>[beginValue, endValue)</tt>
49.496 /// range.
49.497 - ValueIterator endValue() const {
49.498 - return ValueIterator(_first.end());
49.499 + ValueIt endValue() const {
49.500 + return ValueIt(_first.end());
49.501 }
49.502
49.503 /// \brief Set operation of the map.
49.504 @@ -3236,9 +3300,9 @@
49.505 class SourceMap {
49.506 public:
49.507
49.508 - ///\e
49.509 + /// The key type (the \c Arc type of the digraph).
49.510 typedef typename GR::Arc Key;
49.511 - ///\e
49.512 + /// The value type (the \c Node type of the digraph).
49.513 typedef typename GR::Node Value;
49.514
49.515 /// \brief Constructor
49.516 @@ -3277,9 +3341,9 @@
49.517 class TargetMap {
49.518 public:
49.519
49.520 - ///\e
49.521 + /// The key type (the \c Arc type of the digraph).
49.522 typedef typename GR::Arc Key;
49.523 - ///\e
49.524 + /// The value type (the \c Node type of the digraph).
49.525 typedef typename GR::Node Value;
49.526
49.527 /// \brief Constructor
49.528 @@ -3319,8 +3383,10 @@
49.529 class ForwardMap {
49.530 public:
49.531
49.532 + /// The key type (the \c Edge type of the digraph).
49.533 + typedef typename GR::Edge Key;
49.534 + /// The value type (the \c Arc type of the digraph).
49.535 typedef typename GR::Arc Value;
49.536 - typedef typename GR::Edge Key;
49.537
49.538 /// \brief Constructor
49.539 ///
49.540 @@ -3359,8 +3425,10 @@
49.541 class BackwardMap {
49.542 public:
49.543
49.544 + /// The key type (the \c Edge type of the digraph).
49.545 + typedef typename GR::Edge Key;
49.546 + /// The value type (the \c Arc type of the digraph).
49.547 typedef typename GR::Arc Value;
49.548 - typedef typename GR::Edge Key;
49.549
49.550 /// \brief Constructor
49.551 ///
49.552 @@ -3398,7 +3466,7 @@
49.553 /// \warning Besides \c addNode() and \c addArc(), a digraph structure
49.554 /// may provide alternative ways to modify the digraph.
49.555 /// The correct behavior of InDegMap is not guarantied if these additional
49.556 - /// features are used. For example the functions
49.557 + /// features are used. For example, the functions
49.558 /// \ref ListDigraph::changeSource() "changeSource()",
49.559 /// \ref ListDigraph::changeTarget() "changeTarget()" and
49.560 /// \ref ListDigraph::reverseArc() "reverseArc()"
49.561 @@ -3528,7 +3596,7 @@
49.562 /// \warning Besides \c addNode() and \c addArc(), a digraph structure
49.563 /// may provide alternative ways to modify the digraph.
49.564 /// The correct behavior of OutDegMap is not guarantied if these additional
49.565 - /// features are used. For example the functions
49.566 + /// features are used. For example, the functions
49.567 /// \ref ListDigraph::changeSource() "changeSource()",
49.568 /// \ref ListDigraph::changeTarget() "changeTarget()" and
49.569 /// \ref ListDigraph::reverseArc() "reverseArc()"
49.570 @@ -3696,6 +3764,293 @@
49.571 return PotentialDifferenceMap<GR, POT>(gr, potential);
49.572 }
49.573
49.574 +
49.575 + /// \brief Copy the values of a graph map to another map.
49.576 + ///
49.577 + /// This function copies the values of a graph map to another graph map.
49.578 + /// \c To::Key must be equal or convertible to \c From::Key and
49.579 + /// \c From::Value must be equal or convertible to \c To::Value.
49.580 + ///
49.581 + /// For example, an edge map of \c int value type can be copied to
49.582 + /// an arc map of \c double value type in an undirected graph, but
49.583 + /// an arc map cannot be copied to an edge map.
49.584 + /// Note that even a \ref ConstMap can be copied to a standard graph map,
49.585 + /// but \ref mapFill() can also be used for this purpose.
49.586 + ///
49.587 + /// \param gr The graph for which the maps are defined.
49.588 + /// \param from The map from which the values have to be copied.
49.589 + /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
49.590 + /// \param to The map to which the values have to be copied.
49.591 + /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
49.592 + template <typename GR, typename From, typename To>
49.593 + void mapCopy(const GR& gr, const From& from, To& to) {
49.594 + typedef typename To::Key Item;
49.595 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
49.596 +
49.597 + for (ItemIt it(gr); it != INVALID; ++it) {
49.598 + to.set(it, from[it]);
49.599 + }
49.600 + }
49.601 +
49.602 + /// \brief Compare two graph maps.