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.
49.603 + ///
49.604 + /// This function compares the values of two graph maps. It returns
49.605 + /// \c true if the maps assign the same value for all items in the graph.
49.606 + /// The \c Key type of the maps (\c Node, \c Arc or \c Edge) must be equal
49.607 + /// and their \c Value types must be comparable using \c %operator==().
49.608 + ///
49.609 + /// \param gr The graph for which the maps are defined.
49.610 + /// \param map1 The first map.
49.611 + /// \param map2 The second map.
49.612 + template <typename GR, typename Map1, typename Map2>
49.613 + bool mapCompare(const GR& gr, const Map1& map1, const Map2& map2) {
49.614 + typedef typename Map2::Key Item;
49.615 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
49.616 +
49.617 + for (ItemIt it(gr); it != INVALID; ++it) {
49.618 + if (!(map1[it] == map2[it])) return false;
49.619 + }
49.620 + return true;
49.621 + }
49.622 +
49.623 + /// \brief Return an item having minimum value of a graph map.
49.624 + ///
49.625 + /// This function returns an item (\c Node, \c Arc or \c Edge) having
49.626 + /// minimum value of the given graph map.
49.627 + /// If the item set is empty, it returns \c INVALID.
49.628 + ///
49.629 + /// \param gr The graph for which the map is defined.
49.630 + /// \param map The graph map.
49.631 + template <typename GR, typename Map>
49.632 + typename Map::Key mapMin(const GR& gr, const Map& map) {
49.633 + return mapMin(gr, map, std::less<typename Map::Value>());
49.634 + }
49.635 +
49.636 + /// \brief Return an item having minimum value of a graph map.
49.637 + ///
49.638 + /// This function returns an item (\c Node, \c Arc or \c Edge) having
49.639 + /// minimum value of the given graph map.
49.640 + /// If the item set is empty, it returns \c INVALID.
49.641 + ///
49.642 + /// \param gr The graph for which the map is defined.
49.643 + /// \param map The graph map.
49.644 + /// \param comp Comparison function object.
49.645 + template <typename GR, typename Map, typename Comp>
49.646 + typename Map::Key mapMin(const GR& gr, const Map& map, const Comp& comp) {
49.647 + typedef typename Map::Key Item;
49.648 + typedef typename Map::Value Value;
49.649 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
49.650 +
49.651 + ItemIt min_item(gr);
49.652 + if (min_item == INVALID) return INVALID;
49.653 + Value min = map[min_item];
49.654 + for (ItemIt it(gr); it != INVALID; ++it) {
49.655 + if (comp(map[it], min)) {
49.656 + min = map[it];
49.657 + min_item = it;
49.658 + }
49.659 + }
49.660 + return min_item;
49.661 + }
49.662 +
49.663 + /// \brief Return an item having maximum value of a graph map.
49.664 + ///
49.665 + /// This function returns an item (\c Node, \c Arc or \c Edge) having
49.666 + /// maximum value of the given graph map.
49.667 + /// If the item set is empty, it returns \c INVALID.
49.668 + ///
49.669 + /// \param gr The graph for which the map is defined.
49.670 + /// \param map The graph map.
49.671 + template <typename GR, typename Map>
49.672 + typename Map::Key mapMax(const GR& gr, const Map& map) {
49.673 + return mapMax(gr, map, std::less<typename Map::Value>());
49.674 + }
49.675 +
49.676 + /// \brief Return an item having maximum value of a graph map.
49.677 + ///
49.678 + /// This function returns an item (\c Node, \c Arc or \c Edge) having
49.679 + /// maximum value of the given graph map.
49.680 + /// If the item set is empty, it returns \c INVALID.
49.681 + ///
49.682 + /// \param gr The graph for which the map is defined.
49.683 + /// \param map The graph map.
49.684 + /// \param comp Comparison function object.
49.685 + template <typename GR, typename Map, typename Comp>
49.686 + typename Map::Key mapMax(const GR& gr, const Map& map, const Comp& comp) {
49.687 + typedef typename Map::Key Item;
49.688 + typedef typename Map::Value Value;
49.689 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
49.690 +
49.691 + ItemIt max_item(gr);
49.692 + if (max_item == INVALID) return INVALID;
49.693 + Value max = map[max_item];
49.694 + for (ItemIt it(gr); it != INVALID; ++it) {
49.695 + if (comp(max, map[it])) {
49.696 + max = map[it];
49.697 + max_item = it;
49.698 + }
49.699 + }
49.700 + return max_item;
49.701 + }
49.702 +
49.703 + /// \brief Return the minimum value of a graph map.
49.704 + ///
49.705 + /// This function returns the minimum value of the given graph map.
49.706 + /// The corresponding item set of the graph must not be empty.
49.707 + ///
49.708 + /// \param gr The graph for which the map is defined.
49.709 + /// \param map The graph map.
49.710 + template <typename GR, typename Map>
49.711 + typename Map::Value mapMinValue(const GR& gr, const Map& map) {
49.712 + return map[mapMin(gr, map, std::less<typename Map::Value>())];
49.713 + }
49.714 +
49.715 + /// \brief Return the minimum value of a graph map.
49.716 + ///
49.717 + /// This function returns the minimum value of the given graph map.
49.718 + /// The corresponding item set of the graph must not be empty.
49.719 + ///
49.720 + /// \param gr The graph for which the map is defined.
49.721 + /// \param map The graph map.
49.722 + /// \param comp Comparison function object.
49.723 + template <typename GR, typename Map, typename Comp>
49.724 + typename Map::Value
49.725 + mapMinValue(const GR& gr, const Map& map, const Comp& comp) {
49.726 + return map[mapMin(gr, map, comp)];
49.727 + }
49.728 +
49.729 + /// \brief Return the maximum value of a graph map.
49.730 + ///
49.731 + /// This function returns the maximum value of the given graph map.
49.732 + /// The corresponding item set of the graph must not be empty.
49.733 + ///
49.734 + /// \param gr The graph for which the map is defined.
49.735 + /// \param map The graph map.
49.736 + template <typename GR, typename Map>
49.737 + typename Map::Value mapMaxValue(const GR& gr, const Map& map) {
49.738 + return map[mapMax(gr, map, std::less<typename Map::Value>())];
49.739 + }
49.740 +
49.741 + /// \brief Return the maximum value of a graph map.
49.742 + ///
49.743 + /// This function returns the maximum value of the given graph map.
49.744 + /// The corresponding item set of the graph must not be empty.
49.745 + ///
49.746 + /// \param gr The graph for which the map is defined.
49.747 + /// \param map The graph map.
49.748 + /// \param comp Comparison function object.
49.749 + template <typename GR, typename Map, typename Comp>
49.750 + typename Map::Value
49.751 + mapMaxValue(const GR& gr, const Map& map, const Comp& comp) {
49.752 + return map[mapMax(gr, map, comp)];
49.753 + }
49.754 +
49.755 + /// \brief Return an item having a specified value in a graph map.
49.756 + ///
49.757 + /// This function returns an item (\c Node, \c Arc or \c Edge) having
49.758 + /// the specified assigned value in the given graph map.
49.759 + /// If no such item exists, it returns \c INVALID.
49.760 + ///
49.761 + /// \param gr The graph for which the map is defined.
49.762 + /// \param map The graph map.
49.763 + /// \param val The value that have to be found.
49.764 + template <typename GR, typename Map>
49.765 + typename Map::Key
49.766 + mapFind(const GR& gr, const Map& map, const typename Map::Value& val) {
49.767 + typedef typename Map::Key Item;
49.768 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
49.769 +
49.770 + for (ItemIt it(gr); it != INVALID; ++it) {
49.771 + if (map[it] == val) return it;
49.772 + }
49.773 + return INVALID;
49.774 + }
49.775 +
49.776 + /// \brief Return an item having value for which a certain predicate is
49.777 + /// true in a graph map.
49.778 + ///
49.779 + /// This function returns an item (\c Node, \c Arc or \c Edge) having
49.780 + /// such assigned value for which the specified predicate is true
49.781 + /// in the given graph map.
49.782 + /// If no such item exists, it returns \c INVALID.
49.783 + ///
49.784 + /// \param gr The graph for which the map is defined.
49.785 + /// \param map The graph map.
49.786 + /// \param pred The predicate function object.
49.787 + template <typename GR, typename Map, typename Pred>
49.788 + typename Map::Key
49.789 + mapFindIf(const GR& gr, const Map& map, const Pred& pred) {
49.790 + typedef typename Map::Key Item;
49.791 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
49.792 +
49.793 + for (ItemIt it(gr); it != INVALID; ++it) {
49.794 + if (pred(map[it])) return it;
49.795 + }
49.796 + return INVALID;
49.797 + }
49.798 +
49.799 + /// \brief Return the number of items having a specified value in a
49.800 + /// graph map.
49.801 + ///
49.802 + /// This function returns the number of items (\c Node, \c Arc or \c Edge)
49.803 + /// having the specified assigned value in the given graph map.
49.804 + ///
49.805 + /// \param gr The graph for which the map is defined.
49.806 + /// \param map The graph map.
49.807 + /// \param val The value that have to be counted.
49.808 + template <typename GR, typename Map>
49.809 + int mapCount(const GR& gr, const Map& map, const typename Map::Value& val) {
49.810 + typedef typename Map::Key Item;
49.811 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
49.812 +
49.813 + int cnt = 0;
49.814 + for (ItemIt it(gr); it != INVALID; ++it) {
49.815 + if (map[it] == val) ++cnt;
49.816 + }
49.817 + return cnt;
49.818 + }
49.819 +
49.820 + /// \brief Return the number of items having values for which a certain
49.821 + /// predicate is true in a graph map.
49.822 + ///
49.823 + /// This function returns the number of items (\c Node, \c Arc or \c Edge)
49.824 + /// having such assigned values for which the specified predicate is true
49.825 + /// in the given graph map.
49.826 + ///
49.827 + /// \param gr The graph for which the map is defined.
49.828 + /// \param map The graph map.
49.829 + /// \param pred The predicate function object.
49.830 + template <typename GR, typename Map, typename Pred>
49.831 + int mapCountIf(const GR& gr, const Map& map, const Pred& pred) {
49.832 + typedef typename Map::Key Item;
49.833 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
49.834 +
49.835 + int cnt = 0;
49.836 + for (ItemIt it(gr); it != INVALID; ++it) {
49.837 + if (pred(map[it])) ++cnt;
49.838 + }
49.839 + return cnt;
49.840 + }
49.841 +
49.842 + /// \brief Fill a graph map with a certain value.
49.843 + ///
49.844 + /// This function sets the specified value for all items (\c Node,
49.845 + /// \c Arc or \c Edge) in the given graph map.
49.846 + ///
49.847 + /// \param gr The graph for which the map is defined.
49.848 + /// \param map The graph map. It must conform to the
49.849 + /// \ref concepts::WriteMap "WriteMap" concept.
49.850 + /// \param val The value.
49.851 + template <typename GR, typename Map>
49.852 + void mapFill(const GR& gr, Map& map, const typename Map::Value& val) {
49.853 + typedef typename Map::Key Item;
49.854 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
49.855 +
49.856 + for (ItemIt it(gr); it != INVALID; ++it) {
49.857 + map.set(it, val);
49.858 + }
49.859 + }
49.860 +
49.861 /// @}
49.862 }
49.863
50.1 --- a/lemon/min_cost_arborescence.h Sun Oct 04 10:15:32 2009 +0200
50.2 +++ b/lemon/min_cost_arborescence.h Wed Dec 09 11:14:06 2009 +0100
50.3 @@ -488,8 +488,8 @@
50.4 /// \name Execution Control
50.5 /// The simplest way to execute the algorithm is to use
50.6 /// one of the member functions called \c run(...). \n
50.7 - /// If you need more control on the execution,
50.8 - /// first you must call \ref init(), then you can add several
50.9 + /// If you need better control on the execution,
50.10 + /// you have to call \ref init() first, then you can add several
50.11 /// source nodes with \ref addSource().
50.12 /// Finally \ref start() will perform the arborescence
50.13 /// computation.
51.1 --- a/lemon/network_simplex.h Sun Oct 04 10:15:32 2009 +0200
51.2 +++ b/lemon/network_simplex.h Wed Dec 09 11:14:06 2009 +0100
51.3 @@ -40,7 +40,9 @@
51.4 /// for finding a \ref min_cost_flow "minimum cost flow".
51.5 ///
51.6 /// \ref NetworkSimplex implements the primal Network Simplex algorithm
51.7 - /// for finding a \ref min_cost_flow "minimum cost flow".
51.8 + /// for finding a \ref min_cost_flow "minimum cost flow"
51.9 + /// \ref amo93networkflows, \ref dantzig63linearprog,
51.10 + /// \ref kellyoneill91netsimplex.
51.11 /// This algorithm is a specialized version of the linear programming
51.12 /// simplex method directly for the minimum cost flow problem.
51.13 /// It is one of the most efficient solution methods.
51.14 @@ -48,7 +50,7 @@
51.15 /// In general this class is the fastest implementation available
51.16 /// in LEMON for the minimum cost flow problem.
51.17 /// Moreover it supports both directions of the supply/demand inequality
51.18 - /// constraints. For more information see \ref SupplyType.
51.19 + /// constraints. For more information, see \ref SupplyType.
51.20 ///
51.21 /// Most of the parameters of the problem (except for the digraph)
51.22 /// can be given using separate functions, and the algorithm can be
51.23 @@ -57,16 +59,16 @@
51.24 ///
51.25 /// \tparam GR The digraph type the algorithm runs on.
51.26 /// \tparam V The value type used for flow amounts, capacity bounds
51.27 - /// and supply values in the algorithm. By default it is \c int.
51.28 + /// and supply values in the algorithm. By default, it is \c int.
51.29 /// \tparam C The value type used for costs and potentials in the
51.30 - /// algorithm. By default it is the same as \c V.
51.31 + /// algorithm. By default, it is the same as \c V.
51.32 ///
51.33 /// \warning Both value types must be signed and all input data must
51.34 /// be integer.
51.35 ///
51.36 /// \note %NetworkSimplex provides five different pivot rule
51.37 /// implementations, from which the most efficient one is used
51.38 - /// by default. For more information see \ref PivotRule.
51.39 + /// by default. For more information, see \ref PivotRule.
51.40 template <typename GR, typename V = int, typename C = V>
51.41 class NetworkSimplex
51.42 {
51.43 @@ -122,35 +124,35 @@
51.44 /// \ref NetworkSimplex provides five different pivot rule
51.45 /// implementations that significantly affect the running time
51.46 /// of the algorithm.
51.47 - /// By default \ref BLOCK_SEARCH "Block Search" is used, which
51.48 + /// By default, \ref BLOCK_SEARCH "Block Search" is used, which
51.49 /// proved to be the most efficient and the most robust on various
51.50 /// test inputs according to our benchmark tests.
51.51 - /// However another pivot rule can be selected using the \ref run()
51.52 + /// However, another pivot rule can be selected using the \ref run()
51.53 /// function with the proper parameter.
51.54 enum PivotRule {
51.55
51.56 - /// The First Eligible pivot rule.
51.57 + /// The \e First \e Eligible pivot rule.
51.58 /// The next eligible arc is selected in a wraparound fashion
51.59 /// in every iteration.
51.60 FIRST_ELIGIBLE,
51.61
51.62 - /// The Best Eligible pivot rule.
51.63 + /// The \e Best \e Eligible pivot rule.
51.64 /// The best eligible arc is selected in every iteration.
51.65 BEST_ELIGIBLE,
51.66
51.67 - /// The Block Search pivot rule.
51.68 + /// The \e Block \e Search pivot rule.
51.69 /// A specified number of arcs are examined in every iteration
51.70 /// in a wraparound fashion and the best eligible arc is selected
51.71 /// from this block.
51.72 BLOCK_SEARCH,
51.73
51.74 - /// The Candidate List pivot rule.
51.75 + /// The \e Candidate \e List pivot rule.
51.76 /// In a major iteration a candidate list is built from eligible arcs
51.77 /// in a wraparound fashion and in the following minor iterations
51.78 /// the best eligible arc is selected from this list.
51.79 CANDIDATE_LIST,
51.80
51.81 - /// The Altering Candidate List pivot rule.
51.82 + /// The \e Altering \e Candidate \e List pivot rule.
51.83 /// It is a modified version of the Candidate List method.
51.84 /// It keeps only the several best eligible arcs from the former
51.85 /// candidate list and extends this list in every iteration.
51.86 @@ -161,8 +163,6 @@
51.87
51.88 TEMPLATE_DIGRAPH_TYPEDEFS(GR);
51.89
51.90 - typedef std::vector<Arc> ArcVector;
51.91 - typedef std::vector<Node> NodeVector;
51.92 typedef std::vector<int> IntVector;
51.93 typedef std::vector<bool> BoolVector;
51.94 typedef std::vector<Value> ValueVector;
51.95 @@ -364,33 +364,32 @@
51.96 bool findEnteringArc() {
51.97 Cost c, min = 0;
51.98 int cnt = _block_size;
51.99 - int e, min_arc = _next_arc;
51.100 + int e;
51.101 for (e = _next_arc; e < _search_arc_num; ++e) {
51.102 c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
51.103 if (c < min) {
51.104 min = c;
51.105 - min_arc = e;
51.106 + _in_arc = e;
51.107 }
51.108 if (--cnt == 0) {
51.109 - if (min < 0) break;
51.110 + if (min < 0) goto search_end;
51.111 cnt = _block_size;
51.112 }
51.113 }
51.114 - if (min == 0 || cnt > 0) {
51.115 - for (e = 0; e < _next_arc; ++e) {
51.116 - c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
51.117 - if (c < min) {
51.118 - min = c;
51.119 - min_arc = e;
51.120 - }
51.121 - if (--cnt == 0) {
51.122 - if (min < 0) break;
51.123 - cnt = _block_size;
51.124 - }
51.125 + for (e = 0; e < _next_arc; ++e) {
51.126 + c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
51.127 + if (c < min) {
51.128 + min = c;
51.129 + _in_arc = e;
51.130 + }
51.131 + if (--cnt == 0) {
51.132 + if (min < 0) goto search_end;
51.133 + cnt = _block_size;
51.134 }
51.135 }
51.136 if (min >= 0) return false;
51.137 - _in_arc = min_arc;
51.138 +
51.139 + search_end:
51.140 _next_arc = e;
51.141 return true;
51.142 }
51.143 @@ -428,7 +427,7 @@
51.144 _next_arc(0)
51.145 {
51.146 // The main parameters of the pivot rule
51.147 - const double LIST_LENGTH_FACTOR = 1.0;
51.148 + const double LIST_LENGTH_FACTOR = 0.25;
51.149 const int MIN_LIST_LENGTH = 10;
51.150 const double MINOR_LIMIT_FACTOR = 0.1;
51.151 const int MIN_MINOR_LIMIT = 3;
51.152 @@ -445,7 +444,7 @@
51.153 /// Find next entering arc
51.154 bool findEnteringArc() {
51.155 Cost min, c;
51.156 - int e, min_arc = _next_arc;
51.157 + int e;
51.158 if (_curr_length > 0 && _minor_count < _minor_limit) {
51.159 // Minor iteration: select the best eligible arc from the
51.160 // current candidate list
51.161 @@ -456,16 +455,13 @@
51.162 c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
51.163 if (c < min) {
51.164 min = c;
51.165 - min_arc = e;
51.166 + _in_arc = e;
51.167 }
51.168 - if (c >= 0) {
51.169 + else if (c >= 0) {
51.170 _candidates[i--] = _candidates[--_curr_length];
51.171 }
51.172 }
51.173 - if (min < 0) {
51.174 - _in_arc = min_arc;
51.175 - return true;
51.176 - }
51.177 + if (min < 0) return true;
51.178 }
51.179
51.180 // Major iteration: build a new candidate list
51.181 @@ -477,27 +473,26 @@
51.182 _candidates[_curr_length++] = e;
51.183 if (c < min) {
51.184 min = c;
51.185 - min_arc = e;
51.186 + _in_arc = e;
51.187 }
51.188 - if (_curr_length == _list_length) break;
51.189 + if (_curr_length == _list_length) goto search_end;
51.190 }
51.191 }
51.192 - if (_curr_length < _list_length) {
51.193 - for (e = 0; e < _next_arc; ++e) {
51.194 - c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
51.195 - if (c < 0) {
51.196 - _candidates[_curr_length++] = e;
51.197 - if (c < min) {
51.198 - min = c;
51.199 - min_arc = e;
51.200 - }
51.201 - if (_curr_length == _list_length) break;
51.202 + for (e = 0; e < _next_arc; ++e) {
51.203 + c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
51.204 + if (c < 0) {
51.205 + _candidates[_curr_length++] = e;
51.206 + if (c < min) {
51.207 + min = c;
51.208 + _in_arc = e;
51.209 }
51.210 + if (_curr_length == _list_length) goto search_end;
51.211 }
51.212 }
51.213 if (_curr_length == 0) return false;
51.214 +
51.215 + search_end:
51.216 _minor_count = 1;
51.217 - _in_arc = min_arc;
51.218 _next_arc = e;
51.219 return true;
51.220 }
51.221 @@ -549,7 +544,7 @@
51.222 _next_arc(0), _cand_cost(ns._search_arc_num), _sort_func(_cand_cost)
51.223 {
51.224 // The main parameters of the pivot rule
51.225 - const double BLOCK_SIZE_FACTOR = 1.5;
51.226 + const double BLOCK_SIZE_FACTOR = 1.0;
51.227 const int MIN_BLOCK_SIZE = 10;
51.228 const double HEAD_LENGTH_FACTOR = 0.1;
51.229 const int MIN_HEAD_LENGTH = 3;
51.230 @@ -578,39 +573,35 @@
51.231
51.232 // Extend the list
51.233 int cnt = _block_size;
51.234 - int last_arc = 0;
51.235 int limit = _head_length;
51.236
51.237 - for (int e = _next_arc; e < _search_arc_num; ++e) {
51.238 + for (e = _next_arc; e < _search_arc_num; ++e) {
51.239 _cand_cost[e] = _state[e] *
51.240 (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
51.241 if (_cand_cost[e] < 0) {
51.242 _candidates[_curr_length++] = e;
51.243 - last_arc = e;
51.244 }
51.245 if (--cnt == 0) {
51.246 - if (_curr_length > limit) break;
51.247 + if (_curr_length > limit) goto search_end;
51.248 limit = 0;
51.249 cnt = _block_size;
51.250 }
51.251 }
51.252 - if (_curr_length <= limit) {
51.253 - for (int e = 0; e < _next_arc; ++e) {
51.254 - _cand_cost[e] = _state[e] *
51.255 - (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
51.256 - if (_cand_cost[e] < 0) {
51.257 - _candidates[_curr_length++] = e;
51.258 - last_arc = e;
51.259 - }
51.260 - if (--cnt == 0) {
51.261 - if (_curr_length > limit) break;
51.262 - limit = 0;
51.263 - cnt = _block_size;
51.264 - }
51.265 + for (e = 0; e < _next_arc; ++e) {
51.266 + _cand_cost[e] = _state[e] *
51.267 + (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
51.268 + if (_cand_cost[e] < 0) {
51.269 + _candidates[_curr_length++] = e;
51.270 + }
51.271 + if (--cnt == 0) {
51.272 + if (_curr_length > limit) goto search_end;
51.273 + limit = 0;
51.274 + cnt = _block_size;
51.275 }
51.276 }
51.277 if (_curr_length == 0) return false;
51.278 - _next_arc = last_arc + 1;
51.279 +
51.280 + search_end:
51.281
51.282 // Make heap of the candidate list (approximating a partial sort)
51.283 make_heap( _candidates.begin(), _candidates.begin() + _curr_length,
51.284 @@ -618,6 +609,7 @@
51.285
51.286 // Pop the first element of the heap
51.287 _in_arc = _candidates[0];
51.288 + _next_arc = e;
51.289 pop_heap( _candidates.begin(), _candidates.begin() + _curr_length,
51.290 _sort_func );
51.291 _curr_length = std::min(_head_length, _curr_length - 1);
51.292 @@ -633,7 +625,11 @@
51.293 /// The constructor of the class.
51.294 ///
51.295 /// \param graph The digraph the algorithm runs on.
51.296 - NetworkSimplex(const GR& graph) :
51.297 + /// \param arc_mixing Indicate if the arcs have to be stored in a
51.298 + /// mixed order in the internal data structure.
51.299 + /// In special cases, it could lead to better overall performance,
51.300 + /// but it is usually slower. Therefore it is disabled by default.
51.301 + NetworkSimplex(const GR& graph, bool arc_mixing = false) :
51.302 _graph(graph), _node_id(graph), _arc_id(graph),
51.303 INF(std::numeric_limits<Value>::has_infinity ?
51.304 std::numeric_limits<Value>::infinity() :
51.305 @@ -671,31 +667,33 @@
51.306 _last_succ.resize(all_node_num);
51.307 _state.resize(max_arc_num);
51.308
51.309 - // Copy the graph (store the arcs in a mixed order)
51.310 + // Copy the graph
51.311 int i = 0;
51.312 for (NodeIt n(_graph); n != INVALID; ++n, ++i) {
51.313 _node_id[n] = i;
51.314 }
51.315 - int k = std::max(int(std::sqrt(double(_arc_num))), 10);
51.316 - i = 0;
51.317 - for (ArcIt a(_graph); a != INVALID; ++a) {
51.318 - _arc_id[a] = i;
51.319 - _source[i] = _node_id[_graph.source(a)];
51.320 - _target[i] = _node_id[_graph.target(a)];
51.321 - if ((i += k) >= _arc_num) i = (i % k) + 1;
51.322 + if (arc_mixing) {
51.323 + // Store the arcs in a mixed order
51.324 + int k = std::max(int(std::sqrt(double(_arc_num))), 10);
51.325 + int i = 0, j = 0;
51.326 + for (ArcIt a(_graph); a != INVALID; ++a) {
51.327 + _arc_id[a] = i;
51.328 + _source[i] = _node_id[_graph.source(a)];
51.329 + _target[i] = _node_id[_graph.target(a)];
51.330 + if ((i += k) >= _arc_num) i = ++j;
51.331 + }
51.332 + } else {
51.333 + // Store the arcs in the original order
51.334 + int i = 0;
51.335 + for (ArcIt a(_graph); a != INVALID; ++a, ++i) {
51.336 + _arc_id[a] = i;
51.337 + _source[i] = _node_id[_graph.source(a)];
51.338 + _target[i] = _node_id[_graph.target(a)];
51.339 + }
51.340 }
51.341
51.342 - // Initialize maps
51.343 - for (int i = 0; i != _node_num; ++i) {
51.344 - _supply[i] = 0;
51.345 - }
51.346 - for (int i = 0; i != _arc_num; ++i) {
51.347 - _lower[i] = 0;
51.348 - _upper[i] = INF;
51.349 - _cost[i] = 1;
51.350 - }
51.351 - _have_lower = false;
51.352 - _stype = GEQ;
51.353 + // Reset parameters
51.354 + reset();
51.355 }
51.356
51.357 /// \name Parameters
51.358 @@ -768,7 +766,6 @@
51.359 /// This function sets the supply values of the nodes.
51.360 /// If neither this function nor \ref stSupply() is used before
51.361 /// calling \ref run(), the supply of each node will be set to zero.
51.362 - /// (It makes sense only if non-zero lower bounds are given.)
51.363 ///
51.364 /// \param map A node map storing the supply values.
51.365 /// Its \c Value type must be convertible to the \c Value type
51.366 @@ -789,7 +786,6 @@
51.367 /// and the required flow value.
51.368 /// If neither this function nor \ref supplyMap() is used before
51.369 /// calling \ref run(), the supply of each node will be set to zero.
51.370 - /// (It makes sense only if non-zero lower bounds are given.)
51.371 ///
51.372 /// Using this function has the same effect as using \ref supplyMap()
51.373 /// with such a map in which \c k is assigned to \c s, \c -k is
51.374 @@ -816,7 +812,7 @@
51.375 /// If it is not used before calling \ref run(), the \ref GEQ supply
51.376 /// type will be used.
51.377 ///
51.378 - /// For more information see \ref SupplyType.
51.379 + /// For more information, see \ref SupplyType.
51.380 ///
51.381 /// \return <tt>(*this)</tt>
51.382 NetworkSimplex& supplyType(SupplyType supply_type) {
51.383 @@ -848,11 +844,11 @@
51.384 /// that have been given are kept for the next call, unless
51.385 /// \ref reset() is called, thus only the modified parameters
51.386 /// have to be set again. See \ref reset() for examples.
51.387 - /// However the underlying digraph must not be modified after this
51.388 + /// However, the underlying digraph must not be modified after this
51.389 /// class have been constructed, since it copies and extends the graph.
51.390 ///
51.391 /// \param pivot_rule The pivot rule that will be used during the
51.392 - /// algorithm. For more information see \ref PivotRule.
51.393 + /// algorithm. For more information, see \ref PivotRule.
51.394 ///
51.395 /// \return \c INFEASIBLE if no feasible flow exists,
51.396 /// \n \c OPTIMAL if the problem has optimal solution
51.397 @@ -877,7 +873,7 @@
51.398 /// It is useful for multiple run() calls. If this function is not
51.399 /// used, all the parameters given before are kept for the next
51.400 /// \ref run() call.
51.401 - /// However the underlying digraph must not be modified after this
51.402 + /// However, the underlying digraph must not be modified after this
51.403 /// class have been constructed, since it copies and extends the graph.
51.404 ///
51.405 /// For example,
52.1 --- a/lemon/path.h Sun Oct 04 10:15:32 2009 +0200
52.2 +++ b/lemon/path.h Wed Dec 09 11:14:06 2009 +0100
52.3 @@ -70,7 +70,7 @@
52.4 /// It simply makes a copy of the given path.
52.5 template <typename CPath>
52.6 Path(const CPath& cpath) {
52.7 - copyPath(*this, cpath);
52.8 + pathCopy(cpath, *this);
52.9 }
52.10
52.11 /// \brief Template copy assignment
52.12 @@ -78,7 +78,7 @@
52.13 /// This operator makes a copy of a path of any other type.
52.14 template <typename CPath>
52.15 Path& operator=(const CPath& cpath) {
52.16 - copyPath(*this, cpath);
52.17 + pathCopy(cpath, *this);
52.18 return *this;
52.19 }
52.20
52.21 @@ -258,7 +258,7 @@
52.22 /// makes a copy of the given path.
52.23 template <typename CPath>
52.24 SimplePath(const CPath& cpath) {
52.25 - copyPath(*this, cpath);
52.26 + pathCopy(cpath, *this);
52.27 }
52.28
52.29 /// \brief Template copy assignment
52.30 @@ -267,7 +267,7 @@
52.31 /// makes a copy of the given path.
52.32 template <typename CPath>
52.33 SimplePath& operator=(const CPath& cpath) {
52.34 - copyPath(*this, cpath);
52.35 + pathCopy(cpath, *this);
52.36 return *this;
52.37 }
52.38
52.39 @@ -437,7 +437,7 @@
52.40 /// makes a copy of the given path.
52.41 template <typename CPath>
52.42 ListPath(const CPath& cpath) : first(0), last(0) {
52.43 - copyPath(*this, cpath);
52.44 + pathCopy(cpath, *this);
52.45 }
52.46
52.47 /// \brief Destructor of the path
52.48 @@ -453,7 +453,7 @@
52.49 /// makes a copy of the given path.
52.50 template <typename CPath>
52.51 ListPath& operator=(const CPath& cpath) {
52.52 - copyPath(*this, cpath);
52.53 + pathCopy(cpath, *this);
52.54 return *this;
52.55 }
52.56
52.57 @@ -763,7 +763,7 @@
52.58 /// This path can be initialized from any other path type.
52.59 template <typename CPath>
52.60 StaticPath(const CPath& cpath) : arcs(0) {
52.61 - copyPath(*this, cpath);
52.62 + pathCopy(cpath, *this);
52.63 }
52.64
52.65 /// \brief Destructor of the path
52.66 @@ -779,7 +779,7 @@
52.67 /// makes a copy of the given path.
52.68 template <typename CPath>
52.69 StaticPath& operator=(const CPath& cpath) {
52.70 - copyPath(*this, cpath);
52.71 + pathCopy(cpath, *this);
52.72 return *this;
52.73 }
52.74
52.75 @@ -928,57 +928,57 @@
52.76 static const bool value = true;
52.77 };
52.78
52.79 - template <typename Target, typename Source,
52.80 - bool buildEnable = BuildTagIndicator<Target>::value>
52.81 + template <typename From, typename To,
52.82 + bool buildEnable = BuildTagIndicator<To>::value>
52.83 struct PathCopySelectorForward {
52.84 - static void copy(Target& target, const Source& source) {
52.85 - target.clear();
52.86 - for (typename Source::ArcIt it(source); it != INVALID; ++it) {
52.87 - target.addBack(it);
52.88 + static void copy(const From& from, To& to) {
52.89 + to.clear();
52.90 + for (typename From::ArcIt it(from); it != INVALID; ++it) {
52.91 + to.addBack(it);
52.92 }
52.93 }
52.94 };
52.95
52.96 - template <typename Target, typename Source>
52.97 - struct PathCopySelectorForward<Target, Source, true> {
52.98 - static void copy(Target& target, const Source& source) {
52.99 - target.clear();
52.100 - target.build(source);
52.101 + template <typename From, typename To>
52.102 + struct PathCopySelectorForward<From, To, true> {
52.103 + static void copy(const From& from, To& to) {
52.104 + to.clear();
52.105 + to.build(from);
52.106 }
52.107 };
52.108
52.109 - template <typename Target, typename Source,
52.110 - bool buildEnable = BuildTagIndicator<Target>::value>
52.111 + template <typename From, typename To,
52.112 + bool buildEnable = BuildTagIndicator<To>::value>
52.113 struct PathCopySelectorBackward {
52.114 - static void copy(Target& target, const Source& source) {
52.115 - target.clear();
52.116 - for (typename Source::RevArcIt it(source); it != INVALID; ++it) {
52.117 - target.addFront(it);
52.118 + static void copy(const From& from, To& to) {
52.119 + to.clear();
52.120 + for (typename From::RevArcIt it(from); it != INVALID; ++it) {
52.121 + to.addFront(it);
52.122 }
52.123 }
52.124 };
52.125
52.126 - template <typename Target, typename Source>
52.127 - struct PathCopySelectorBackward<Target, Source, true> {
52.128 - static void copy(Target& target, const Source& source) {
52.129 - target.clear();
52.130 - target.buildRev(source);
52.131 + template <typename From, typename To>
52.132 + struct PathCopySelectorBackward<From, To, true> {
52.133 + static void copy(const From& from, To& to) {
52.134 + to.clear();
52.135 + to.buildRev(from);
52.136 }
52.137 };
52.138
52.139
52.140 - template <typename Target, typename Source,
52.141 - bool revEnable = RevPathTagIndicator<Source>::value>
52.142 + template <typename From, typename To,
52.143 + bool revEnable = RevPathTagIndicator<From>::value>
52.144 struct PathCopySelector {
52.145 - static void copy(Target& target, const Source& source) {
52.146 - PathCopySelectorForward<Target, Source>::copy(target, source);
52.147 + static void copy(const From& from, To& to) {
52.148 + PathCopySelectorForward<From, To>::copy(from, to);
52.149 }
52.150 };
52.151
52.152 - template <typename Target, typename Source>
52.153 - struct PathCopySelector<Target, Source, true> {
52.154 - static void copy(Target& target, const Source& source) {
52.155 - PathCopySelectorBackward<Target, Source>::copy(target, source);
52.156 + template <typename From, typename To>
52.157 + struct PathCopySelector<From, To, true> {
52.158 + static void copy(const From& from, To& to) {
52.159 + PathCopySelectorBackward<From, To>::copy(from, to);
52.160 }
52.161 };
52.162
52.163 @@ -987,11 +987,19 @@
52.164
52.165 /// \brief Make a copy of a path.
52.166 ///
52.167 - /// This function makes a copy of a path.
52.168 - template <typename Target, typename Source>
52.169 - void copyPath(Target& target, const Source& source) {
52.170 - checkConcept<concepts::PathDumper<typename Source::Digraph>, Source>();
52.171 - _path_bits::PathCopySelector<Target, Source>::copy(target, source);
52.172 + /// This function makes a copy of a path.
52.173 + template <typename From, typename To>
52.174 + void pathCopy(const From& from, To& to) {
52.175 + checkConcept<concepts::PathDumper<typename From::Digraph>, From>();
52.176 + _path_bits::PathCopySelector<From, To>::copy(from, to);
52.177 + }
52.178 +
52.179 + /// \brief Deprecated version of \ref pathCopy().
52.180 + ///
52.181 + /// Deprecated version of \ref pathCopy() (only for reverse compatibility).
52.182 + template <typename To, typename From>
52.183 + void copyPath(To& to, const From& from) {
52.184 + pathCopy(from, to);
52.185 }
52.186
52.187 /// \brief Check the consistency of a path.
52.188 @@ -1015,18 +1023,20 @@
52.189
52.190 /// \brief The source of a path
52.191 ///
52.192 - /// This function returns the source of the given path.
52.193 + /// This function returns the source node of the given path.
52.194 + /// If the path is empty, then it returns \c INVALID.
52.195 template <typename Digraph, typename Path>
52.196 typename Digraph::Node pathSource(const Digraph& digraph, const Path& path) {
52.197 - return digraph.source(path.front());
52.198 + return path.empty() ? INVALID : digraph.source(path.front());
52.199 }
52.200
52.201 /// \brief The target of a path
52.202 ///
52.203 - /// This function returns the target of the given path.
52.204 + /// This function returns the target node of the given path.
52.205 + /// If the path is empty, then it returns \c INVALID.
52.206 template <typename Digraph, typename Path>
52.207 typename Digraph::Node pathTarget(const Digraph& digraph, const Path& path) {
52.208 - return digraph.target(path.back());
52.209 + return path.empty() ? INVALID : digraph.target(path.back());
52.210 }
52.211
52.212 /// \brief Class which helps to iterate through the nodes of a path
53.1 --- a/lemon/preflow.h Sun Oct 04 10:15:32 2009 +0200
53.2 +++ b/lemon/preflow.h Wed Dec 09 11:14:06 2009 +0100
53.3 @@ -52,7 +52,11 @@
53.4 ///
53.5 /// The type of the map that stores the flow values.
53.6 /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
53.7 +#ifdef DOXYGEN
53.8 + typedef GR::ArcMap<Value> FlowMap;
53.9 +#else
53.10 typedef typename Digraph::template ArcMap<Value> FlowMap;
53.11 +#endif
53.12
53.13 /// \brief Instantiates a FlowMap.
53.14 ///
53.15 @@ -67,9 +71,12 @@
53.16 ///
53.17 /// The elevator type used by Preflow algorithm.
53.18 ///
53.19 - /// \sa Elevator
53.20 - /// \sa LinkedElevator
53.21 - typedef LinkedElevator<Digraph, typename Digraph::Node> Elevator;
53.22 + /// \sa Elevator, LinkedElevator
53.23 +#ifdef DOXYGEN
53.24 + typedef lemon::Elevator<GR, GR::Node> Elevator;
53.25 +#else
53.26 + typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator;
53.27 +#endif
53.28
53.29 /// \brief Instantiates an Elevator.
53.30 ///
53.31 @@ -95,7 +102,8 @@
53.32 ///
53.33 /// This class provides an implementation of Goldberg-Tarjan's \e preflow
53.34 /// \e push-relabel algorithm producing a \ref max_flow
53.35 - /// "flow of maximum value" in a digraph.
53.36 + /// "flow of maximum value" in a digraph \ref clrs01algorithms,
53.37 + /// \ref amo93networkflows, \ref goldberg88newapproach.
53.38 /// The preflow algorithms are the fastest known maximum
53.39 /// flow algorithms. The current implementation uses a mixture of the
53.40 /// \e "highest label" and the \e "bound decrease" heuristics.
53.41 @@ -257,7 +265,7 @@
53.42 /// The Elevator should have standard constructor interface to be
53.43 /// able to automatically created by the algorithm (i.e. the
53.44 /// digraph and the maximum level should be passed to it).
53.45 - /// However an external elevator object could also be passed to the
53.46 + /// However, an external elevator object could also be passed to the
53.47 /// algorithm with the \ref elevator(Elevator&) "elevator()" function
53.48 /// before calling \ref run() or \ref init().
53.49 /// \sa SetElevator
53.50 @@ -391,8 +399,8 @@
53.51 /// \name Execution Control
53.52 /// The simplest way to execute the preflow algorithm is to use
53.53 /// \ref run() or \ref runMinCut().\n
53.54 - /// If you need more control on the initial solution or the execution,
53.55 - /// first you have to call one of the \ref init() functions, then
53.56 + /// If you need better control on the initial solution or the execution,
53.57 + /// you have to call one of the \ref init() functions first, then
53.58 /// \ref startFirstPhase() and if you need it \ref startSecondPhase().
53.59
53.60 ///@{
54.1 --- a/lemon/smart_graph.h Sun Oct 04 10:15:32 2009 +0200
54.2 +++ b/lemon/smart_graph.h Wed Dec 09 11:14:06 2009 +0100
54.3 @@ -32,10 +32,7 @@
54.4 namespace lemon {
54.5
54.6 class SmartDigraph;
54.7 - ///Base of SmartDigraph
54.8
54.9 - ///Base of SmartDigraph
54.10 - ///
54.11 class SmartDigraphBase {
54.12 protected:
54.13
54.14 @@ -187,28 +184,28 @@
54.15 ///
54.16 ///\brief A smart directed graph class.
54.17 ///
54.18 - ///This is a simple and fast digraph implementation.
54.19 - ///It is also quite memory efficient, but at the price
54.20 - ///that <b> it does support only limited (only stack-like)
54.21 - ///node and arc deletions</b>.
54.22 - ///It fully conforms to the \ref concepts::Digraph "Digraph concept".
54.23 + ///\ref SmartDigraph is a simple and fast digraph implementation.
54.24 + ///It is also quite memory efficient but at the price
54.25 + ///that it does not support node and arc deletion
54.26 + ///(except for the Snapshot feature).
54.27 ///
54.28 - ///\sa concepts::Digraph.
54.29 + ///This type fully conforms to the \ref concepts::Digraph "Digraph concept"
54.30 + ///and it also provides some additional functionalities.
54.31 + ///Most of its member functions and nested classes are documented
54.32 + ///only in the concept class.
54.33 + ///
54.34 + ///This class provides constant time counting for nodes and arcs.
54.35 + ///
54.36 + ///\sa concepts::Digraph
54.37 + ///\sa SmartGraph
54.38 class SmartDigraph : public ExtendedSmartDigraphBase {
54.39 typedef ExtendedSmartDigraphBase Parent;
54.40
54.41 private:
54.42 -
54.43 - ///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead.
54.44 -
54.45 - ///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead.
54.46 - ///
54.47 + /// Digraphs are \e not copy constructible. Use DigraphCopy instead.
54.48 SmartDigraph(const SmartDigraph &) : ExtendedSmartDigraphBase() {};
54.49 - ///\brief Assignment of SmartDigraph to another one is \e not allowed.
54.50 - ///Use DigraphCopy() instead.
54.51 -
54.52 - ///Assignment of SmartDigraph to another one is \e not allowed.
54.53 - ///Use DigraphCopy() instead.
54.54 + /// \brief Assignment of a digraph to another one is \e not allowed.
54.55 + /// Use DigraphCopy instead.
54.56 void operator=(const SmartDigraph &) {}
54.57
54.58 public:
54.59 @@ -221,79 +218,49 @@
54.60
54.61 ///Add a new node to the digraph.
54.62
54.63 - /// Add a new node to the digraph.
54.64 - /// \return The new node.
54.65 + ///This function adds a new node to the digraph.
54.66 + ///\return The new node.
54.67 Node addNode() { return Parent::addNode(); }
54.68
54.69 ///Add a new arc to the digraph.
54.70
54.71 - ///Add a new arc to the digraph with source node \c s
54.72 + ///This function adds a new arc to the digraph with source node \c s
54.73 ///and target node \c t.
54.74 ///\return The new arc.
54.75 - Arc addArc(const Node& s, const Node& t) {
54.76 + Arc addArc(Node s, Node t) {
54.77 return Parent::addArc(s, t);
54.78 }
54.79
54.80 - /// \brief Using this it is possible to avoid the superfluous memory
54.81 - /// allocation.
54.82 -
54.83 - /// Using this it is possible to avoid the superfluous memory
54.84 - /// allocation: if you know that the digraph you want to build will
54.85 - /// be very large (e.g. it will contain millions of nodes and/or arcs)
54.86 - /// then it is worth reserving space for this amount before starting
54.87 - /// to build the digraph.
54.88 - /// \sa reserveArc
54.89 - void reserveNode(int n) { nodes.reserve(n); };
54.90 -
54.91 - /// \brief Using this it is possible to avoid the superfluous memory
54.92 - /// allocation.
54.93 -
54.94 - /// Using this it is possible to avoid the superfluous memory
54.95 - /// allocation: if you know that the digraph you want to build will
54.96 - /// be very large (e.g. it will contain millions of nodes and/or arcs)
54.97 - /// then it is worth reserving space for this amount before starting
54.98 - /// to build the digraph.
54.99 - /// \sa reserveNode
54.100 - void reserveArc(int m) { arcs.reserve(m); };
54.101 -
54.102 /// \brief Node validity check
54.103 ///
54.104 - /// This function gives back true if the given node is valid,
54.105 - /// ie. it is a real node of the graph.
54.106 + /// This function gives back \c true if the given node is valid,
54.107 + /// i.e. it is a real node of the digraph.
54.108 ///
54.109 /// \warning A removed node (using Snapshot) could become valid again
54.110 - /// when new nodes are added to the graph.
54.111 + /// if new nodes are added to the digraph.
54.112 bool valid(Node n) const { return Parent::valid(n); }
54.113
54.114 /// \brief Arc validity check
54.115 ///
54.116 - /// This function gives back true if the given arc is valid,
54.117 - /// ie. it is a real arc of the graph.
54.118 + /// This function gives back \c true if the given arc is valid,
54.119 + /// i.e. it is a real arc of the digraph.
54.120 ///
54.121 /// \warning A removed arc (using Snapshot) could become valid again
54.122 - /// when new arcs are added to the graph.
54.123 + /// if new arcs are added to the graph.
54.124 bool valid(Arc a) const { return Parent::valid(a); }
54.125
54.126 - ///Clear the digraph.
54.127 -
54.128 - ///Erase all the nodes and arcs from the digraph.
54.129 - ///
54.130 - void clear() {
54.131 - Parent::clear();
54.132 - }
54.133 -
54.134 ///Split a node.
54.135
54.136 - ///This function splits a node. First a new node is added to the digraph,
54.137 - ///then the source of each outgoing arc of \c n is moved to this new node.
54.138 - ///If \c connect is \c true (this is the default value), then a new arc
54.139 - ///from \c n to the newly created node is also added.
54.140 + ///This function splits the given node. First, a new node is added
54.141 + ///to the digraph, then the source of each outgoing arc of node \c n
54.142 + ///is moved to this new node.
54.143 + ///If the second parameter \c connect is \c true (this is the default
54.144 + ///value), then a new arc from node \c n to the newly created node
54.145 + ///is also added.
54.146 ///\return The newly created node.
54.147 ///
54.148 - ///\note The <tt>Arc</tt>s
54.149 - ///referencing a moved arc remain
54.150 - ///valid. However <tt>InArc</tt>'s and <tt>OutArc</tt>'s
54.151 - ///may be invalidated.
54.152 + ///\note All iterators remain valid.
54.153 + ///
54.154 ///\warning This functionality cannot be used together with the Snapshot
54.155 ///feature.
54.156 Node split(Node n, bool connect = true)
54.157 @@ -308,6 +275,34 @@
54.158 return b;
54.159 }
54.160
54.161 + ///Clear the digraph.
54.162 +
54.163 + ///This function erases all nodes and arcs from the digraph.
54.164 + ///
54.165 + void clear() {
54.166 + Parent::clear();
54.167 + }
54.168 +
54.169 + /// Reserve memory for nodes.
54.170 +
54.171 + /// Using this function, it is possible to avoid superfluous memory
54.172 + /// allocation: if you know that the digraph you want to build will
54.173 + /// be large (e.g. it will contain millions of nodes and/or arcs),
54.174 + /// then it is worth reserving space for this amount before starting
54.175 + /// to build the digraph.
54.176 + /// \sa reserveArc()
54.177 + void reserveNode(int n) { nodes.reserve(n); };
54.178 +
54.179 + /// Reserve memory for arcs.
54.180 +
54.181 + /// Using this function, it is possible to avoid superfluous memory
54.182 + /// allocation: if you know that the digraph you want to build will
54.183 + /// be large (e.g. it will contain millions of nodes and/or arcs),
54.184 + /// then it is worth reserving space for this amount before starting
54.185 + /// to build the digraph.
54.186 + /// \sa reserveNode()
54.187 + void reserveArc(int m) { arcs.reserve(m); };
54.188 +
54.189 public:
54.190
54.191 class Snapshot;
54.192 @@ -332,20 +327,23 @@
54.193
54.194 public:
54.195
54.196 - ///Class to make a snapshot of the digraph and to restrore to it later.
54.197 + ///Class to make a snapshot of the digraph and to restore it later.
54.198
54.199 - ///Class to make a snapshot of the digraph and to restrore to it later.
54.200 + ///Class to make a snapshot of the digraph and to restore it later.
54.201 ///
54.202 ///The newly added nodes and arcs can be removed using the
54.203 - ///restore() function.
54.204 - ///\note After you restore a state, you cannot restore
54.205 - ///a later state, in other word you cannot add again the arcs deleted
54.206 - ///by restore() using another one Snapshot instance.
54.207 + ///restore() function. This is the only way for deleting nodes and/or
54.208 + ///arcs from a SmartDigraph structure.
54.209 ///
54.210 - ///\warning If you do not use correctly the snapshot that can cause
54.211 - ///either broken program, invalid state of the digraph, valid but
54.212 - ///not the restored digraph or no change. Because the runtime performance
54.213 - ///the validity of the snapshot is not stored.
54.214 + ///\note After a state is restored, you cannot restore a later state,
54.215 + ///i.e. you cannot add the removed nodes and arcs again using
54.216 + ///another Snapshot instance.
54.217 + ///
54.218 + ///\warning Node splitting cannot be restored.
54.219 + ///\warning The validity of the snapshot is not stored due to
54.220 + ///performance reasons. If you do not use the snapshot correctly,
54.221 + ///it can cause broken program, invalid or not restored state of
54.222 + ///the digraph or no change.
54.223 class Snapshot
54.224 {
54.225 SmartDigraph *_graph;
54.226 @@ -357,39 +355,32 @@
54.227 ///Default constructor.
54.228
54.229 ///Default constructor.
54.230 - ///To actually make a snapshot you must call save().
54.231 - ///
54.232 + ///You have to call save() to actually make a snapshot.
54.233 Snapshot() : _graph(0) {}
54.234 ///Constructor that immediately makes a snapshot
54.235
54.236 - ///This constructor immediately makes a snapshot of the digraph.
54.237 - ///\param graph The digraph we make a snapshot of.
54.238 - Snapshot(SmartDigraph &graph) : _graph(&graph) {
54.239 + ///This constructor immediately makes a snapshot of the given digraph.
54.240 + ///
54.241 + Snapshot(SmartDigraph &gr) : _graph(&gr) {
54.242 node_num=_graph->nodes.size();
54.243 arc_num=_graph->arcs.size();
54.244 }
54.245
54.246 ///Make a snapshot.
54.247
54.248 - ///Make a snapshot of the digraph.
54.249 - ///
54.250 - ///This function can be called more than once. In case of a repeated
54.251 + ///This function makes a snapshot of the given digraph.
54.252 + ///It can be called more than once. In case of a repeated
54.253 ///call, the previous snapshot gets lost.
54.254 - ///\param graph The digraph we make the snapshot of.
54.255 - void save(SmartDigraph &graph)
54.256 - {
54.257 - _graph=&graph;
54.258 + void save(SmartDigraph &gr) {
54.259 + _graph=&gr;
54.260 node_num=_graph->nodes.size();
54.261 arc_num=_graph->arcs.size();
54.262 }
54.263
54.264 ///Undo the changes until a snapshot.
54.265
54.266 - ///Undo the changes until a snapshot created by save().
54.267 - ///
54.268 - ///\note After you restored a state, you cannot restore
54.269 - ///a later state, in other word you cannot add again the arcs deleted
54.270 - ///by restore().
54.271 + ///This function undos the changes until the last snapshot
54.272 + ///created by save() or Snapshot(SmartDigraph&).
54.273 void restore()
54.274 {
54.275 _graph->restoreSnapshot(*this);
54.276 @@ -508,7 +499,7 @@
54.277 node._id = nodes.size() - 1;
54.278 }
54.279
54.280 - void next(Node& node) const {
54.281 + static void next(Node& node) {
54.282 --node._id;
54.283 }
54.284
54.285 @@ -516,7 +507,7 @@
54.286 arc._id = arcs.size() - 1;
54.287 }
54.288
54.289 - void next(Arc& arc) const {
54.290 + static void next(Arc& arc) {
54.291 --arc._id;
54.292 }
54.293
54.294 @@ -524,7 +515,7 @@
54.295 arc._id = arcs.size() / 2 - 1;
54.296 }
54.297
54.298 - void next(Edge& arc) const {
54.299 + static void next(Edge& arc) {
54.300 --arc._id;
54.301 }
54.302
54.303 @@ -621,29 +612,28 @@
54.304 ///
54.305 /// \brief A smart undirected graph class.
54.306 ///
54.307 - /// This is a simple and fast graph implementation.
54.308 - /// It is also quite memory efficient, but at the price
54.309 - /// that <b> it does support only limited (only stack-like)
54.310 - /// node and arc deletions</b>.
54.311 - /// It fully conforms to the \ref concepts::Graph "Graph concept".
54.312 + /// \ref SmartGraph is a simple and fast graph implementation.
54.313 + /// It is also quite memory efficient but at the price
54.314 + /// that it does not support node and edge deletion
54.315 + /// (except for the Snapshot feature).
54.316 ///
54.317 - /// \sa concepts::Graph.
54.318 + /// This type fully conforms to the \ref concepts::Graph "Graph concept"
54.319 + /// and it also provides some additional functionalities.
54.320 + /// Most of its member functions and nested classes are documented
54.321 + /// only in the concept class.
54.322 + ///
54.323 + /// This class provides constant time counting for nodes, edges and arcs.
54.324 + ///
54.325 + /// \sa concepts::Graph
54.326 + /// \sa SmartDigraph
54.327 class SmartGraph : public ExtendedSmartGraphBase {
54.328 typedef ExtendedSmartGraphBase Parent;
54.329
54.330 private:
54.331 -
54.332 - ///SmartGraph is \e not copy constructible. Use GraphCopy() instead.
54.333 -
54.334 - ///SmartGraph is \e not copy constructible. Use GraphCopy() instead.
54.335 - ///
54.336 + /// Graphs are \e not copy constructible. Use GraphCopy instead.
54.337 SmartGraph(const SmartGraph &) : ExtendedSmartGraphBase() {};
54.338 -
54.339 - ///\brief Assignment of SmartGraph to another one is \e not allowed.
54.340 - ///Use GraphCopy() instead.
54.341 -
54.342 - ///Assignment of SmartGraph to another one is \e not allowed.
54.343 - ///Use GraphCopy() instead.
54.344 + /// \brief Assignment of a graph to another one is \e not allowed.
54.345 + /// Use GraphCopy instead.
54.346 void operator=(const SmartGraph &) {}
54.347
54.348 public:
54.349 @@ -654,56 +644,77 @@
54.350 ///
54.351 SmartGraph() {}
54.352
54.353 - ///Add a new node to the graph.
54.354 -
54.355 - /// Add a new node to the graph.
54.356 + /// \brief Add a new node to the graph.
54.357 + ///
54.358 + /// This function adds a new node to the graph.
54.359 /// \return The new node.
54.360 Node addNode() { return Parent::addNode(); }
54.361
54.362 - ///Add a new edge to the graph.
54.363 -
54.364 - ///Add a new edge to the graph with node \c s
54.365 - ///and \c t.
54.366 - ///\return The new edge.
54.367 - Edge addEdge(const Node& s, const Node& t) {
54.368 - return Parent::addEdge(s, t);
54.369 + /// \brief Add a new edge to the graph.
54.370 + ///
54.371 + /// This function adds a new edge to the graph between nodes
54.372 + /// \c u and \c v with inherent orientation from node \c u to
54.373 + /// node \c v.
54.374 + /// \return The new edge.
54.375 + Edge addEdge(Node u, Node v) {
54.376 + return Parent::addEdge(u, v);
54.377 }
54.378
54.379 /// \brief Node validity check
54.380 ///
54.381 - /// This function gives back true if the given node is valid,
54.382 - /// ie. it is a real node of the graph.
54.383 + /// This function gives back \c true if the given node is valid,
54.384 + /// i.e. it is a real node of the graph.
54.385 ///
54.386 /// \warning A removed node (using Snapshot) could become valid again
54.387 - /// when new nodes are added to the graph.
54.388 + /// if new nodes are added to the graph.
54.389 bool valid(Node n) const { return Parent::valid(n); }
54.390
54.391 + /// \brief Edge validity check
54.392 + ///
54.393 + /// This function gives back \c true if the given edge is valid,
54.394 + /// i.e. it is a real edge of the graph.
54.395 + ///
54.396 + /// \warning A removed edge (using Snapshot) could become valid again
54.397 + /// if new edges are added to the graph.
54.398 + bool valid(Edge e) const { return Parent::valid(e); }
54.399 +
54.400 /// \brief Arc validity check
54.401 ///
54.402 - /// This function gives back true if the given arc is valid,
54.403 - /// ie. it is a real arc of the graph.
54.404 + /// This function gives back \c true if the given arc is valid,
54.405 + /// i.e. it is a real arc of the graph.
54.406 ///
54.407 /// \warning A removed arc (using Snapshot) could become valid again
54.408 - /// when new edges are added to the graph.
54.409 + /// if new edges are added to the graph.
54.410 bool valid(Arc a) const { return Parent::valid(a); }
54.411
54.412 - /// \brief Edge validity check
54.413 - ///
54.414 - /// This function gives back true if the given edge is valid,
54.415 - /// ie. it is a real edge of the graph.
54.416 - ///
54.417 - /// \warning A removed edge (using Snapshot) could become valid again
54.418 - /// when new edges are added to the graph.
54.419 - bool valid(Edge e) const { return Parent::valid(e); }
54.420 -
54.421 ///Clear the graph.
54.422
54.423 - ///Erase all the nodes and edges from the graph.
54.424 + ///This function erases all nodes and arcs from the graph.
54.425 ///
54.426 void clear() {
54.427 Parent::clear();
54.428 }
54.429
54.430 + /// Reserve memory for nodes.
54.431 +
54.432 + /// Using this function, it is possible to avoid superfluous memory
54.433 + /// allocation: if you know that the graph you want to build will
54.434 + /// be large (e.g. it will contain millions of nodes and/or edges),
54.435 + /// then it is worth reserving space for this amount before starting
54.436 + /// to build the graph.
54.437 + /// \sa reserveEdge()
54.438 + void reserveNode(int n) { nodes.reserve(n); };
54.439 +
54.440 + /// Reserve memory for edges.
54.441 +
54.442 + /// Using this function, it is possible to avoid superfluous memory
54.443 + /// allocation: if you know that the graph you want to build will
54.444 + /// be large (e.g. it will contain millions of nodes and/or edges),
54.445 + /// then it is worth reserving space for this amount before starting
54.446 + /// to build the graph.
54.447 + /// \sa reserveNode()
54.448 + void reserveEdge(int m) { arcs.reserve(2 * m); };
54.449 +
54.450 public:
54.451
54.452 class Snapshot;
54.453 @@ -742,21 +753,22 @@
54.454
54.455 public:
54.456
54.457 - ///Class to make a snapshot of the digraph and to restrore to it later.
54.458 + ///Class to make a snapshot of the graph and to restore it later.
54.459
54.460 - ///Class to make a snapshot of the digraph and to restrore to it later.
54.461 + ///Class to make a snapshot of the graph and to restore it later.
54.462 ///
54.463 - ///The newly added nodes and arcs can be removed using the
54.464 - ///restore() function.
54.465 + ///The newly added nodes and edges can be removed using the
54.466 + ///restore() function. This is the only way for deleting nodes and/or
54.467 + ///edges from a SmartGraph structure.
54.468 ///
54.469 - ///\note After you restore a state, you cannot restore
54.470 - ///a later state, in other word you cannot add again the arcs deleted
54.471 - ///by restore() using another one Snapshot instance.
54.472 + ///\note After a state is restored, you cannot restore a later state,
54.473 + ///i.e. you cannot add the removed nodes and edges again using
54.474 + ///another Snapshot instance.
54.475 ///
54.476 - ///\warning If you do not use correctly the snapshot that can cause
54.477 - ///either broken program, invalid state of the digraph, valid but
54.478 - ///not the restored digraph or no change. Because the runtime performance
54.479 - ///the validity of the snapshot is not stored.
54.480 + ///\warning The validity of the snapshot is not stored due to
54.481 + ///performance reasons. If you do not use the snapshot correctly,
54.482 + ///it can cause broken program, invalid or not restored state of
54.483 + ///the graph or no change.
54.484 class Snapshot
54.485 {
54.486 SmartGraph *_graph;
54.487 @@ -768,36 +780,30 @@
54.488 ///Default constructor.
54.489
54.490 ///Default constructor.
54.491 - ///To actually make a snapshot you must call save().
54.492 - ///
54.493 + ///You have to call save() to actually make a snapshot.
54.494 Snapshot() : _graph(0) {}
54.495 ///Constructor that immediately makes a snapshot
54.496
54.497 - ///This constructor immediately makes a snapshot of the digraph.
54.498 - ///\param graph The digraph we make a snapshot of.
54.499 - Snapshot(SmartGraph &graph) {
54.500 - graph.saveSnapshot(*this);
54.501 + /// This constructor immediately makes a snapshot of the given graph.
54.502 + ///
54.503 + Snapshot(SmartGraph &gr) {
54.504 + gr.saveSnapshot(*this);
54.505 }
54.506
54.507 ///Make a snapshot.
54.508
54.509 - ///Make a snapshot of the graph.
54.510 - ///
54.511 - ///This function can be called more than once. In case of a repeated
54.512 + ///This function makes a snapshot of the given graph.
54.513 + ///It can be called more than once. In case of a repeated
54.514 ///call, the previous snapshot gets lost.
54.515 - ///\param graph The digraph we make the snapshot of.
54.516 - void save(SmartGraph &graph)
54.517 + void save(SmartGraph &gr)
54.518 {
54.519 - graph.saveSnapshot(*this);
54.520 + gr.saveSnapshot(*this);
54.521 }
54.522
54.523 - ///Undo the changes until a snapshot.
54.524 + ///Undo the changes until the last snapshot.
54.525
54.526 - ///Undo the changes until a snapshot created by save().
54.527 - ///
54.528 - ///\note After you restored a state, you cannot restore
54.529 - ///a later state, in other word you cannot add again the arcs deleted
54.530 - ///by restore().
54.531 + ///This function undos the changes until the last snapshot
54.532 + ///created by save() or Snapshot(SmartGraph&).
54.533 void restore()
54.534 {
54.535 _graph->restoreSnapshot(*this);
55.1 --- a/lemon/soplex.cc Sun Oct 04 10:15:32 2009 +0200
55.2 +++ b/lemon/soplex.cc Wed Dec 09 11:14:06 2009 +0100
55.3 @@ -91,6 +91,19 @@
55.4 return soplex->nRows() - 1;
55.5 }
55.6
55.7 + int SoplexLp::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
55.8 + soplex::DSVector v;
55.9 + for (ExprIterator it = b; it != e; ++it) {
55.10 + v.add(it->first, it->second);
55.11 + }
55.12 + soplex::LPRow r(l, v, u);
55.13 + soplex->addRow(r);
55.14 +
55.15 + _row_names.push_back(std::string());
55.16 +
55.17 + return soplex->nRows() - 1;
55.18 + }
55.19 +
55.20
55.21 void SoplexLp::_eraseCol(int i) {
55.22 soplex->removeCol(i);
56.1 --- a/lemon/soplex.h Sun Oct 04 10:15:32 2009 +0200
56.2 +++ b/lemon/soplex.h Wed Dec 09 11:14:06 2009 +0100
56.3 @@ -84,6 +84,7 @@
56.4
56.5 virtual int _addCol();
56.6 virtual int _addRow();
56.7 + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
56.8
56.9 virtual void _eraseCol(int i);
56.10 virtual void _eraseRow(int i);
57.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
57.2 +++ b/lemon/static_graph.h Wed Dec 09 11:14:06 2009 +0100
57.3 @@ -0,0 +1,476 @@
57.4 +/* -*- C++ -*-
57.5 + *
57.6 + * This file is a part of LEMON, a generic C++ optimization library
57.7 + *
57.8 + * Copyright (C) 2003-2008
57.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
57.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
57.11 + *
57.12 + * Permission to use, modify and distribute this software is granted
57.13 + * provided that this copyright notice appears in all copies. For
57.14 + * precise terms see the accompanying LICENSE file.
57.15 + *
57.16 + * This software is provided "AS IS" with no warranty of any kind,
57.17 + * express or implied, and with no claim as to its suitability for any
57.18 + * purpose.
57.19 + *
57.20 + */
57.21 +
57.22 +#ifndef LEMON_STATIC_GRAPH_H
57.23 +#define LEMON_STATIC_GRAPH_H
57.24 +
57.25 +///\ingroup graphs
57.26 +///\file
57.27 +///\brief StaticDigraph class.
57.28 +
57.29 +#include <lemon/core.h>
57.30 +#include <lemon/bits/graph_extender.h>
57.31 +
57.32 +namespace lemon {
57.33 +
57.34 + class StaticDigraphBase {
57.35 + public:
57.36 +
57.37 + StaticDigraphBase()
57.38 + : built(false), node_num(0), arc_num(0),
57.39 + node_first_out(NULL), node_first_in(NULL),
57.40 + arc_source(NULL), arc_target(NULL),
57.41 + arc_next_in(NULL), arc_next_out(NULL) {}
57.42 +
57.43 + ~StaticDigraphBase() {
57.44 + if (built) {
57.45 + delete[] node_first_out;
57.46 + delete[] node_first_in;
57.47 + delete[] arc_source;
57.48 + delete[] arc_target;
57.49 + delete[] arc_next_out;
57.50 + delete[] arc_next_in;
57.51 + }
57.52 + }
57.53 +
57.54 + class Node {
57.55 + friend class StaticDigraphBase;
57.56 + protected:
57.57 + int id;
57.58 + Node(int _id) : id(_id) {}
57.59 + public:
57.60 + Node() {}
57.61 + Node (Invalid) : id(-1) {}
57.62 + bool operator==(const Node& node) const { return id == node.id; }
57.63 + bool operator!=(const Node& node) const { return id != node.id; }
57.64 + bool operator<(const Node& node) const { return id < node.id; }
57.65 + };
57.66 +
57.67 + class Arc {
57.68 + friend class StaticDigraphBase;
57.69 + protected:
57.70 + int id;
57.71 + Arc(int _id) : id(_id) {}
57.72 + public:
57.73 + Arc() { }
57.74 + Arc (Invalid) : id(-1) {}
57.75 + bool operator==(const Arc& arc) const { return id == arc.id; }
57.76 + bool operator!=(const Arc& arc) const { return id != arc.id; }
57.77 + bool operator<(const Arc& arc) const { return id < arc.id; }
57.78 + };
57.79 +
57.80 + Node source(const Arc& e) const { return Node(arc_source[e.id]); }
57.81 + Node target(const Arc& e) const { return Node(arc_target[e.id]); }
57.82 +
57.83 + void first(Node& n) const { n.id = node_num - 1; }
57.84 + static void next(Node& n) { --n.id; }
57.85 +
57.86 + void first(Arc& e) const { e.id = arc_num - 1; }
57.87 + static void next(Arc& e) { --e.id; }
57.88 +
57.89 + void firstOut(Arc& e, const Node& n) const {
57.90 + e.id = node_first_out[n.id] != node_first_out[n.id + 1] ?
57.91 + node_first_out[n.id] : -1;
57.92 + }
57.93 + void nextOut(Arc& e) const { e.id = arc_next_out[e.id]; }
57.94 +
57.95 + void firstIn(Arc& e, const Node& n) const { e.id = node_first_in[n.id]; }
57.96 + void nextIn(Arc& e) const { e.id = arc_next_in[e.id]; }
57.97 +
57.98 + static int id(const Node& n) { return n.id; }
57.99 + static Node nodeFromId(int id) { return Node(id); }
57.100 + int maxNodeId() const { return node_num - 1; }
57.101 +
57.102 + static int id(const Arc& e) { return e.id; }
57.103 + static Arc arcFromId(int id) { return Arc(id); }
57.104 + int maxArcId() const { return arc_num - 1; }
57.105 +
57.106 + typedef True NodeNumTag;
57.107 + typedef True ArcNumTag;
57.108 +
57.109 + int nodeNum() const { return node_num; }
57.110 + int arcNum() const { return arc_num; }
57.111 +
57.112 + private:
57.113 +
57.114 + template <typename Digraph, typename NodeRefMap>
57.115 + class ArcLess {
57.116 + public:
57.117 + typedef typename Digraph::Arc Arc;
57.118 +
57.119 + ArcLess(const Digraph &_graph, const NodeRefMap& _nodeRef)
57.120 + : digraph(_graph), nodeRef(_nodeRef) {}
57.121 +
57.122 + bool operator()(const Arc& left, const Arc& right) const {
57.123 + return nodeRef[digraph.target(left)] < nodeRef[digraph.target(right)];
57.124 + }
57.125 + private:
57.126 + const Digraph& digraph;
57.127 + const NodeRefMap& nodeRef;
57.128 + };
57.129 +
57.130 + public:
57.131 +
57.132 + typedef True BuildTag;
57.133 +
57.134 + void clear() {
57.135 + if (built) {
57.136 + delete[] node_first_out;
57.137 + delete[] node_first_in;
57.138 + delete[] arc_source;
57.139 + delete[] arc_target;
57.140 + delete[] arc_next_out;
57.141 + delete[] arc_next_in;
57.142 + }
57.143 + built = false;
57.144 + node_num = 0;
57.145 + arc_num = 0;
57.146 + }
57.147 +
57.148 + template <typename Digraph, typename NodeRefMap, typename ArcRefMap>
57.149 + void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) {
57.150 + typedef typename Digraph::Node GNode;
57.151 + typedef typename Digraph::Arc GArc;
57.152 +
57.153 + built = true;
57.154 +
57.155 + node_num = countNodes(digraph);
57.156 + arc_num = countArcs(digraph);
57.157 +
57.158 + node_first_out = new int[node_num + 1];
57.159 + node_first_in = new int[node_num];
57.160 +
57.161 + arc_source = new int[arc_num];
57.162 + arc_target = new int[arc_num];
57.163 + arc_next_out = new int[arc_num];
57.164 + arc_next_in = new int[arc_num];
57.165 +
57.166 + int node_index = 0;
57.167 + for (typename Digraph::NodeIt n(digraph); n != INVALID; ++n) {
57.168 + nodeRef[n] = Node(node_index);
57.169 + node_first_in[node_index] = -1;
57.170 + ++node_index;
57.171 + }
57.172 +
57.173 + ArcLess<Digraph, NodeRefMap> arcLess(digraph, nodeRef);
57.174 +
57.175 + int arc_index = 0;
57.176 + for (typename Digraph::NodeIt n(digraph); n != INVALID; ++n) {
57.177 + int source = nodeRef[n].id;
57.178 + std::vector<GArc> arcs;
57.179 + for (typename Digraph::OutArcIt e(digraph, n); e != INVALID; ++e) {
57.180 + arcs.push_back(e);
57.181 + }
57.182 + if (!arcs.empty()) {
57.183 + node_first_out[source] = arc_index;
57.184 + std::sort(arcs.begin(), arcs.end(), arcLess);
57.185 + for (typename std::vector<GArc>::iterator it = arcs.begin();
57.186 + it != arcs.end(); ++it) {
57.187 + int target = nodeRef[digraph.target(*it)].id;
57.188 + arcRef[*it] = Arc(arc_index);
57.189 + arc_source[arc_index] = source;
57.190 + arc_target[arc_index] = target;
57.191 + arc_next_in[arc_index] = node_first_in[target];
57.192 + node_first_in[target] = arc_index;
57.193 + arc_next_out[arc_index] = arc_index + 1;
57.194 + ++arc_index;
57.195 + }
57.196 + arc_next_out[arc_index - 1] = -1;
57.197 + } else {
57.198 + node_first_out[source] = arc_index;
57.199 + }
57.200 + }
57.201 + node_first_out[node_num] = arc_num;
57.202 + }
57.203 +
57.204 + template <typename ArcListIterator>
57.205 + void build(int n, ArcListIterator first, ArcListIterator last) {
57.206 + built = true;
57.207 +
57.208 + node_num = n;
57.209 + arc_num = std::distance(first, last);
57.210 +
57.211 + node_first_out = new int[node_num + 1];
57.212 + node_first_in = new int[node_num];
57.213 +
57.214 + arc_source = new int[arc_num];
57.215 + arc_target = new int[arc_num];
57.216 + arc_next_out = new int[arc_num];
57.217 + arc_next_in = new int[arc_num];
57.218 +
57.219 + for (int i = 0; i != node_num; ++i) {
57.220 + node_first_in[i] = -1;
57.221 + }
57.222 +
57.223 + int arc_index = 0;
57.224 + for (int i = 0; i != node_num; ++i) {
57.225 + node_first_out[i] = arc_index;
57.226 + for ( ; first != last && (*first).first == i; ++first) {
57.227 + int j = (*first).second;
57.228 + LEMON_ASSERT(j >= 0 && j < node_num,
57.229 + "Wrong arc list for StaticDigraph::build()");
57.230 + arc_source[arc_index] = i;
57.231 + arc_target[arc_index] = j;
57.232 + arc_next_in[arc_index] = node_first_in[j];
57.233 + node_first_in[j] = arc_index;
57.234 + arc_next_out[arc_index] = arc_index + 1;
57.235 + ++arc_index;
57.236 + }
57.237 + if (arc_index > node_first_out[i])
57.238 + arc_next_out[arc_index - 1] = -1;
57.239 + }
57.240 + LEMON_ASSERT(first == last,
57.241 + "Wrong arc list for StaticDigraph::build()");
57.242 + node_first_out[node_num] = arc_num;
57.243 + }
57.244 +
57.245 + protected:
57.246 +
57.247 + void fastFirstOut(Arc& e, const Node& n) const {
57.248 + e.id = node_first_out[n.id];
57.249 + }
57.250 +
57.251 + static void fastNextOut(Arc& e) {
57.252 + ++e.id;
57.253 + }
57.254 + void fastLastOut(Arc& e, const Node& n) const {
57.255 + e.id = node_first_out[n.id + 1];
57.256 + }
57.257 +
57.258 + protected:
57.259 + bool built;
57.260 + int node_num;
57.261 + int arc_num;
57.262 + int *node_first_out;
57.263 + int *node_first_in;
57.264 + int *arc_source;
57.265 + int *arc_target;
57.266 + int *arc_next_in;
57.267 + int *arc_next_out;
57.268 + };
57.269 +
57.270 + typedef DigraphExtender<StaticDigraphBase> ExtendedStaticDigraphBase;
57.271 +
57.272 +
57.273 + /// \ingroup graphs
57.274 + ///
57.275 + /// \brief A static directed graph class.
57.276 + ///
57.277 + /// \ref StaticDigraph is a highly efficient digraph implementation,
57.278 + /// but it is fully static.
57.279 + /// It stores only two \c int values for each node and only four \c int
57.280 + /// values for each arc. Moreover it provides faster item iteration than
57.281 + /// \ref ListDigraph and \ref SmartDigraph, especially using \c OutArcIt
57.282 + /// iterators, since its arcs are stored in an appropriate order.
57.283 + /// However it only provides build() and clear() functions and does not
57.284 + /// support any other modification of the digraph.
57.285 + ///
57.286 + /// Since this digraph structure is completely static, its nodes and arcs
57.287 + /// can be indexed with integers from the ranges <tt>[0..nodeNum()-1]</tt>
57.288 + /// and <tt>[0..arcNum()-1]</tt>, respectively.
57.289 + /// The index of an item is the same as its ID, it can be obtained
57.290 + /// using the corresponding \ref index() or \ref concepts::Digraph::id()
57.291 + /// "id()" function. A node or arc with a certain index can be obtained
57.292 + /// using node() or arc().
57.293 + ///
57.294 + /// This type fully conforms to the \ref concepts::Digraph "Digraph concept".
57.295 + /// Most of its member functions and nested classes are documented
57.296 + /// only in the concept class.
57.297 + ///
57.298 + /// This class provides constant time counting for nodes and arcs.
57.299 + ///
57.300 + /// \sa concepts::Digraph
57.301 + class StaticDigraph : public ExtendedStaticDigraphBase {
57.302 + public:
57.303 +
57.304 + typedef ExtendedStaticDigraphBase Parent;
57.305 +
57.306 + public:
57.307 +
57.308 + /// \brief Constructor
57.309 + ///
57.310 + /// Default constructor.
57.311 + StaticDigraph() : Parent() {}
57.312 +
57.313 + /// \brief The node with the given index.
57.314 + ///
57.315 + /// This function returns the node with the given index.
57.316 + /// \sa index()
57.317 + static Node node(int ix) { return Parent::nodeFromId(ix); }
57.318 +
57.319 + /// \brief The arc with the given index.
57.320 + ///
57.321 + /// This function returns the arc with the given index.
57.322 + /// \sa index()
57.323 + static Arc arc(int ix) { return Parent::arcFromId(ix); }
57.324 +
57.325 + /// \brief The index of the given node.
57.326 + ///
57.327 + /// This function returns the index of the the given node.
57.328 + /// \sa node()
57.329 + static int index(Node node) { return Parent::id(node); }
57.330 +
57.331 + /// \brief The index of the given arc.
57.332 + ///
57.333 + /// This function returns the index of the the given arc.
57.334 + /// \sa arc()
57.335 + static int index(Arc arc) { return Parent::id(arc); }
57.336 +
57.337 + /// \brief Number of nodes.
57.338 + ///
57.339 + /// This function returns the number of nodes.
57.340 + int nodeNum() const { return node_num; }
57.341 +
57.342 + /// \brief Number of arcs.
57.343 + ///
57.344 + /// This function returns the number of arcs.
57.345 + int arcNum() const { return arc_num; }
57.346 +
57.347 + /// \brief Build the digraph copying another digraph.
57.348 + ///
57.349 + /// This function builds the digraph copying another digraph of any
57.350 + /// kind. It can be called more than once, but in such case, the whole
57.351 + /// structure and all maps will be cleared and rebuilt.
57.352 + ///
57.353 + /// This method also makes possible to copy a digraph to a StaticDigraph
57.354 + /// structure using \ref DigraphCopy.
57.355 + ///
57.356 + /// \param digraph An existing digraph to be copied.
57.357 + /// \param nodeRef The node references will be copied into this map.
57.358 + /// Its key type must be \c Digraph::Node and its value type must be
57.359 + /// \c StaticDigraph::Node.
57.360 + /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap"
57.361 + /// concept.
57.362 + /// \param arcRef The arc references will be copied into this map.
57.363 + /// Its key type must be \c Digraph::Arc and its value type must be
57.364 + /// \c StaticDigraph::Arc.
57.365 + /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
57.366 + ///
57.367 + /// \note If you do not need the arc references, then you could use
57.368 + /// \ref NullMap for the last parameter. However the node references
57.369 + /// are required by the function itself, thus they must be readable
57.370 + /// from the map.
57.371 + template <typename Digraph, typename NodeRefMap, typename ArcRefMap>
57.372 + void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) {
57.373 + if (built) Parent::clear();
57.374 + Parent::build(digraph, nodeRef, arcRef);
57.375 + }
57.376 +
57.377 + /// \brief Build the digraph from an arc list.
57.378 + ///
57.379 + /// This function builds the digraph from the given arc list.
57.380 + /// It can be called more than once, but in such case, the whole
57.381 + /// structure and all maps will be cleared and rebuilt.
57.382 + ///
57.383 + /// The list of the arcs must be given in the range <tt>[begin, end)</tt>
57.384 + /// specified by STL compatible itartors whose \c value_type must be
57.385 + /// <tt>std::pair<int,int></tt>.
57.386 + /// Each arc must be specified by a pair of integer indices
57.387 + /// from the range <tt>[0..n-1]</tt>. <i>The pairs must be in a
57.388 + /// non-decreasing order with respect to their first values.</i>
57.389 + /// If the k-th pair in the list is <tt>(i,j)</tt>, then
57.390 + /// <tt>arc(k-1)</tt> will connect <tt>node(i)</tt> to <tt>node(j)</tt>.
57.391 + ///
57.392 + /// \param n The number of nodes.
57.393 + /// \param begin An iterator pointing to the beginning of the arc list.
57.394 + /// \param end An iterator pointing to the end of the arc list.
57.395 + ///
57.396 + /// For example, a simple digraph can be constructed like this.
57.397 + /// \code
57.398 + /// std::vector<std::pair<int,int> > arcs;
57.399 + /// arcs.push_back(std::make_pair(0,1));
57.400 + /// arcs.push_back(std::make_pair(0,2));
57.401 + /// arcs.push_back(std::make_pair(1,3));
57.402 + /// arcs.push_back(std::make_pair(1,2));
57.403 + /// arcs.push_back(std::make_pair(3,0));
57.404 + /// StaticDigraph gr;
57.405 + /// gr.build(4, arcs.begin(), arcs.end());
57.406 + /// \endcode
57.407 + template <typename ArcListIterator>
57.408 + void build(int n, ArcListIterator begin, ArcListIterator end) {
57.409 + if (built) Parent::clear();
57.410 + StaticDigraphBase::build(n, begin, end);
57.411 + notifier(Node()).build();
57.412 + notifier(Arc()).build();
57.413 + }
57.414 +
57.415 + /// \brief Clear the digraph.
57.416 + ///
57.417 + /// This function erases all nodes and arcs from the digraph.
57.418 + void clear() {
57.419 + Parent::clear();
57.420 + }
57.421 +
57.422 + protected:
57.423 +
57.424 + using Parent::fastFirstOut;
57.425 + using Parent::fastNextOut;
57.426 + using Parent::fastLastOut;
57.427 +
57.428 + public:
57.429 +
57.430 + class OutArcIt : public Arc {
57.431 + public:
57.432 +
57.433 + OutArcIt() { }
57.434 +
57.435 + OutArcIt(Invalid i) : Arc(i) { }
57.436 +
57.437 + OutArcIt(const StaticDigraph& digraph, const Node& node) {
57.438 + digraph.fastFirstOut(*this, node);
57.439 + digraph.fastLastOut(last, node);
57.440 + if (last == *this) *this = INVALID;
57.441 + }
57.442 +
57.443 + OutArcIt(const StaticDigraph& digraph, const Arc& arc) : Arc(arc) {
57.444 + if (arc != INVALID) {
57.445 + digraph.fastLastOut(last, digraph.source(arc));
57.446 + }
57.447 + }
57.448 +
57.449 + OutArcIt& operator++() {
57.450 + StaticDigraph::fastNextOut(*this);
57.451 + if (last == *this) *this = INVALID;
57.452 + return *this;
57.453 + }
57.454 +
57.455 + private:
57.456 + Arc last;
57.457 + };
57.458 +
57.459 + Node baseNode(const OutArcIt &arc) const {
57.460 + return Parent::source(static_cast<const Arc&>(arc));
57.461 + }
57.462 +
57.463 + Node runningNode(const OutArcIt &arc) const {
57.464 + return Parent::target(static_cast<const Arc&>(arc));
57.465 + }
57.466 +
57.467 + Node baseNode(const InArcIt &arc) const {
57.468 + return Parent::target(static_cast<const Arc&>(arc));
57.469 + }
57.470 +
57.471 + Node runningNode(const InArcIt &arc) const {
57.472 + return Parent::source(static_cast<const Arc&>(arc));
57.473 + }
57.474 +
57.475 + };
57.476 +
57.477 +}
57.478 +
57.479 +#endif
58.1 --- a/lemon/time_measure.h Sun Oct 04 10:15:32 2009 +0200
58.2 +++ b/lemon/time_measure.h Wed Dec 09 11:14:06 2009 +0100
58.3 @@ -375,7 +375,7 @@
58.4
58.5 ///This function returns the number of stop() exections that is
58.6 ///necessary to really stop the timer.
58.7 - ///For example the timer
58.8 + ///For example, the timer
58.9 ///is running if and only if the return value is \c true
58.10 ///(i.e. greater than
58.11 ///zero).
59.1 --- a/lemon/unionfind.h Sun Oct 04 10:15:32 2009 +0200
59.2 +++ b/lemon/unionfind.h Wed Dec 09 11:14:06 2009 +0100
59.3 @@ -43,7 +43,7 @@
59.4 /// the find operation uses path compression.
59.5 /// This is a very simple but efficient implementation, providing
59.6 /// only four methods: join (union), find, insert and size.
59.7 - /// For more features see the \ref UnionFindEnum class.
59.8 + /// For more features, see the \ref UnionFindEnum class.
59.9 ///
59.10 /// It is primarily used in Kruskal algorithm for finding minimal
59.11 /// cost spanning tree in a graph.
60.1 --- a/m4/lx_check_coin.m4 Sun Oct 04 10:15:32 2009 +0200
60.2 +++ b/m4/lx_check_coin.m4 Wed Dec 09 11:14:06 2009 +0100
60.3 @@ -88,7 +88,7 @@
60.4 elif test x"$with_coin" != x"yes"; then
60.5 CBC_LDFLAGS="-L$with_coin/lib"
60.6 fi
60.7 - CBC_LIBS="-lOsi -lCbc -lOsiCbc -lCbcSolver -lClp -lOsiClp -lCoinUtils -lVol -lOsiVol -lCgl -lm -llapack -lblas"
60.8 + CBC_LIBS="-lOsi -lCbc -lCbcSolver -lClp -lOsiClp -lCoinUtils -lVol -lOsiVol -lCgl -lm -llapack -lblas"
60.9
60.10 lx_save_cxxflags="$CXXFLAGS"
60.11 lx_save_ldflags="$LDFLAGS"
61.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
61.2 +++ b/scripts/Makefile.am Wed Dec 09 11:14:06 2009 +0100
61.3 @@ -0,0 +1,7 @@
61.4 +EXTRA_DIST += \
61.5 + scripts/bib2dox.py \
61.6 + scripts/bootstrap.sh \
61.7 + scripts/chg-len.py \
61.8 + scripts/mk-release.sh \
61.9 + scripts/unify-sources.sh \
61.10 + scripts/valgrind-wrapper.sh
62.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
62.2 +++ b/scripts/bib2dox.py Wed Dec 09 11:14:06 2009 +0100
62.3 @@ -0,0 +1,811 @@
62.4 +#!/usr/bin/env /usr/local/Python/bin/python2.1
62.5 +"""
62.6 + BibTeX to Doxygen converter
62.7 + Usage: python bib2dox.py bibfile.bib > bibfile.dox
62.8 +
62.9 + This code is the modification of the BibTeX to XML converter
62.10 + by Vidar Bronken Gundersen et al. See the original copyright notices below.
62.11 +
62.12 + **********************************************************************
62.13 +
62.14 + Decoder for bibliographic data, BibTeX
62.15 + Usage: python bibtex2xml.py bibfile.bib > bibfile.xml
62.16 +
62.17 + v.8
62.18 + (c)2002-06-23 Vidar Bronken Gundersen
62.19 + http://bibtexml.sf.net/
62.20 + Reuse approved as long as this notification is kept.
62.21 + Licence: GPL.
62.22 +
62.23 + Contributions/thanks to:
62.24 + Egon Willighagen, http://sf.net/projects/jreferences/
62.25 + Richard Mahoney (for providing a test case)
62.26 +
62.27 + Editted by Sara Sprenkle to be more robust and handle more bibtex features.
62.28 + (c) 2003-01-15
62.29 +
62.30 + 1. Changed bibtex: tags to bibxml: tags.
62.31 + 2. Use xmlns:bibxml="http://bibtexml.sf.net/"
62.32 + 3. Allow spaces between @type and first {
62.33 + 4. "author" fields with multiple authors split by " and "
62.34 + are put in separate xml "bibxml:author" tags.
62.35 + 5. Option for Titles: words are capitalized
62.36 + only if first letter in title or capitalized inside braces
62.37 + 6. Removes braces from within field values
62.38 + 7. Ignores comments in bibtex file (including @comment{ or % )
62.39 + 8. Replaces some special latex tags, e.g., replaces ~ with ' '
62.40 + 9. Handles bibtex @string abbreviations
62.41 + --> includes bibtex's default abbreviations for months
62.42 + --> does concatenation of abbr # " more " and " more " # abbr
62.43 + 10. Handles @type( ... ) or @type{ ... }
62.44 + 11. The keywords field is split on , or ; and put into separate xml
62.45 + "bibxml:keywords" tags
62.46 + 12. Ignores @preamble
62.47 +
62.48 + Known Limitations
62.49 + 1. Does not transform Latex encoding like math mode and special
62.50 + latex symbols.
62.51 + 2. Does not parse author fields into first and last names.
62.52 + E.g., It does not do anything special to an author whose name is
62.53 + in the form LAST_NAME, FIRST_NAME
62.54 + In "author" tag, will show up as
62.55 + <bibxml:author>LAST_NAME, FIRST_NAME</bibxml:author>
62.56 + 3. Does not handle "crossref" fields other than to print
62.57 + <bibxml:crossref>...</bibxml:crossref>
62.58 + 4. Does not inform user of the input's format errors. You just won't
62.59 + be able to transform the file later with XSL
62.60 +
62.61 + You will have to manually edit the XML output if you need to handle
62.62 + these (and unknown) limitations.
62.63 +
62.64 +"""
62.65 +
62.66 +import string, re
62.67 +
62.68 +# set of valid name characters
62.69 +valid_name_chars = '[\w\-:]'
62.70 +
62.71 +#
62.72 +# define global regular expression variables
62.73 +#
62.74 +author_rex = re.compile('\s+and\s+')
62.75 +rembraces_rex = re.compile('[{}]')
62.76 +capitalize_rex = re.compile('({[^}]*})')
62.77 +
62.78 +# used by bibtexkeywords(data)
62.79 +keywords_rex = re.compile('[,;]')
62.80 +
62.81 +# used by concat_line(line)
62.82 +concatsplit_rex = re.compile('\s*#\s*')
62.83 +
62.84 +# split on {, }, or " in verify_out_of_braces
62.85 +delimiter_rex = re.compile('([{}"])',re.I)
62.86 +
62.87 +field_rex = re.compile('\s*(\w*)\s*=\s*(.*)')
62.88 +data_rex = re.compile('\s*(\w*)\s*=\s*([^,]*),?')
62.89 +
62.90 +url_rex = re.compile('\\\url\{([^}]*)\}')
62.91 +
62.92 +#
62.93 +# styles for html formatting
62.94 +#
62.95 +divstyle = 'margin-top: -4ex; margin-left: 8em;'
62.96 +
62.97 +#
62.98 +# return the string parameter without braces
62.99 +#
62.100 +def transformurls(str):
62.101 + return url_rex.sub(r'<a href="\1">\1</a>', str)
62.102 +
62.103 +#
62.104 +# return the string parameter without braces
62.105 +#
62.106 +def removebraces(str):
62.107 + return rembraces_rex.sub('', str)
62.108 +
62.109 +#
62.110 +# latex-specific replacements
62.111 +# (do this after braces were removed)
62.112 +#
62.113 +def latexreplacements(line):
62.114 + line = string.replace(line, '~', ' ')
62.115 + line = string.replace(line, '\\\'a', 'á')
62.116 + line = string.replace(line, '\\"a', 'ä')
62.117 + line = string.replace(line, '\\\'e', 'é')
62.118 + line = string.replace(line, '\\"e', 'ë')
62.119 + line = string.replace(line, '\\\'i', 'í')
62.120 + line = string.replace(line, '\\"i', 'ï')
62.121 + line = string.replace(line, '\\\'o', 'ó')
62.122 + line = string.replace(line, '\\"o', 'ö')
62.123 + line = string.replace(line, '\\\'u', 'ú')
62.124 + line = string.replace(line, '\\"u', 'ü')
62.125 + line = string.replace(line, '\\H o', 'õ')
62.126 + line = string.replace(line, '\\H u', 'ü') # ũ does not exist
62.127 + line = string.replace(line, '\\\'A', 'Á')
62.128 + line = string.replace(line, '\\"A', 'Ä')
62.129 + line = string.replace(line, '\\\'E', 'É')
62.130 + line = string.replace(line, '\\"E', 'Ë')
62.131 + line = string.replace(line, '\\\'I', 'Í')
62.132 + line = string.replace(line, '\\"I', 'Ï')
62.133 + line = string.replace(line, '\\\'O', 'Ó')
62.134 + line = string.replace(line, '\\"O', 'Ö')
62.135 + line = string.replace(line, '\\\'U', 'Ú')
62.136 + line = string.replace(line, '\\"U', 'Ü')
62.137 + line = string.replace(line, '\\H O', 'Õ')
62.138 + line = string.replace(line, '\\H U', 'Ü') # Ũ does not exist
62.139 +
62.140 + return line
62.141 +
62.142 +#
62.143 +# copy characters form a string decoding html expressions (&xyz;)
62.144 +#
62.145 +def copychars(str, ifrom, count):
62.146 + result = ''
62.147 + i = ifrom
62.148 + c = 0
62.149 + html_spec = False
62.150 + while (i < len(str)) and (c < count):
62.151 + if str[i] == '&':
62.152 + html_spec = True;
62.153 + if i+1 < len(str):
62.154 + result += str[i+1]
62.155 + c += 1
62.156 + i += 2
62.157 + else:
62.158 + if not html_spec:
62.159 + if ((str[i] >= 'A') and (str[i] <= 'Z')) or \
62.160 + ((str[i] >= 'a') and (str[i] <= 'z')):
62.161 + result += str[i]
62.162 + c += 1
62.163 + elif str[i] == ';':
62.164 + html_spec = False;
62.165 + i += 1
62.166 +
62.167 + return result
62.168 +
62.169 +
62.170 +#
62.171 +# Handle a list of authors (separated by 'and').
62.172 +# It gives back an array of the follwing values:
62.173 +# - num: the number of authors,
62.174 +# - list: the list of the author names,
62.175 +# - text: the bibtex text (separated by commas and/or 'and')
62.176 +# - abbrev: abbreviation that can be used for indicate the
62.177 +# bibliography entries
62.178 +#
62.179 +def bibtexauthor(data):
62.180 + result = {}
62.181 + bibtex = ''
62.182 + result['list'] = author_rex.split(data)
62.183 + result['num'] = len(result['list'])
62.184 + for i, author in enumerate(result['list']):
62.185 + # general transformations
62.186 + author = latexreplacements(removebraces(author.strip()))
62.187 + # transform "Xyz, A. B." to "A. B. Xyz"
62.188 + pos = author.find(',')
62.189 + if pos != -1:
62.190 + author = author[pos+1:].strip() + ' ' + author[:pos].strip()
62.191 + result['list'][i] = author
62.192 + bibtex += author + '#'
62.193 + bibtex = bibtex[:-1]
62.194 + if result['num'] > 1:
62.195 + ix = bibtex.rfind('#')
62.196 + if result['num'] == 2:
62.197 + bibtex = bibtex[:ix] + ' and ' + bibtex[ix+1:]
62.198 + else:
62.199 + bibtex = bibtex[:ix] + ', and ' + bibtex[ix+1:]
62.200 + bibtex = bibtex.replace('#', ', ')
62.201 + result['text'] = bibtex
62.202 +
62.203 + result['abbrev'] = ''
62.204 + for author in result['list']:
62.205 + pos = author.rfind(' ') + 1
62.206 + count = 1
62.207 + if result['num'] == 1:
62.208 + count = 3
62.209 + result['abbrev'] += copychars(author, pos, count)
62.210 +
62.211 + return result
62.212 +
62.213 +
62.214 +#
62.215 +# data = title string
62.216 +# @return the capitalized title (first letter is capitalized), rest are capitalized
62.217 +# only if capitalized inside braces
62.218 +#
62.219 +def capitalizetitle(data):
62.220 + title_list = capitalize_rex.split(data)
62.221 + title = ''
62.222 + count = 0
62.223 + for phrase in title_list:
62.224 + check = string.lstrip(phrase)
62.225 +
62.226 + # keep phrase's capitalization the same
62.227 + if check.find('{') == 0:
62.228 + title += removebraces(phrase)
62.229 + else:
62.230 + # first word --> capitalize first letter (after spaces)
62.231 + if count == 0:
62.232 + title += check.capitalize()
62.233 + else:
62.234 + title += phrase.lower()
62.235 + count = count + 1
62.236 +
62.237 + return title
62.238 +
62.239 +
62.240 +#
62.241 +# @return the bibtex for the title
62.242 +# @param data --> title string
62.243 +# braces are removed from title
62.244 +#
62.245 +def bibtextitle(data, entrytype):
62.246 + if entrytype in ('book', 'inbook'):
62.247 + title = removebraces(data.strip())
62.248 + else:
62.249 + title = removebraces(capitalizetitle(data.strip()))
62.250 + bibtex = title
62.251 + return bibtex
62.252 +
62.253 +
62.254 +#
62.255 +# function to compare entry lists
62.256 +#
62.257 +def entry_cmp(x, y):
62.258 + return cmp(x[0], y[0])
62.259 +
62.260 +
62.261 +#
62.262 +# print the XML for the transformed "filecont_source"
62.263 +#
62.264 +def bibtexdecoder(filecont_source):
62.265 + filecont = []
62.266 + file = []
62.267 +
62.268 + # want @<alphanumeric chars><spaces>{<spaces><any chars>,
62.269 + pubtype_rex = re.compile('@(\w*)\s*{\s*(.*),')
62.270 + endtype_rex = re.compile('}\s*$')
62.271 + endtag_rex = re.compile('^\s*}\s*$')
62.272 +
62.273 + bracefield_rex = re.compile('\s*(\w*)\s*=\s*(.*)')
62.274 + bracedata_rex = re.compile('\s*(\w*)\s*=\s*{(.*)},?')
62.275 +
62.276 + quotefield_rex = re.compile('\s*(\w*)\s*=\s*(.*)')
62.277 + quotedata_rex = re.compile('\s*(\w*)\s*=\s*"(.*)",?')
62.278 +
62.279 + for line in filecont_source:
62.280 + line = line[:-1]
62.281 +
62.282 + # encode character entities
62.283 + line = string.replace(line, '&', '&')
62.284 + line = string.replace(line, '<', '<')
62.285 + line = string.replace(line, '>', '>')
62.286 +
62.287 + # start entry: publication type (store for later use)
62.288 + if pubtype_rex.match(line):
62.289 + # want @<alphanumeric chars><spaces>{<spaces><any chars>,
62.290 + entrycont = {}
62.291 + entry = []
62.292 + entrytype = pubtype_rex.sub('\g<1>',line)
62.293 + entrytype = string.lower(entrytype)
62.294 + entryid = pubtype_rex.sub('\g<2>', line)
62.295 +
62.296 + # end entry if just a }
62.297 + elif endtype_rex.match(line):
62.298 + # generate doxygen code for the entry
62.299 +
62.300 + # enty type related formattings
62.301 + if entrytype in ('book', 'inbook'):
62.302 + entrycont['title'] = '<em>' + entrycont['title'] + '</em>'
62.303 + if not entrycont.has_key('author'):
62.304 + entrycont['author'] = entrycont['editor']
62.305 + entrycont['author']['text'] += ', editors'
62.306 + elif entrytype == 'article':
62.307 + entrycont['journal'] = '<em>' + entrycont['journal'] + '</em>'
62.308 + elif entrytype in ('inproceedings', 'incollection', 'conference'):
62.309 + entrycont['booktitle'] = '<em>' + entrycont['booktitle'] + '</em>'
62.310 + elif entrytype == 'techreport':
62.311 + if not entrycont.has_key('type'):
62.312 + entrycont['type'] = 'Technical report'
62.313 + elif entrytype == 'mastersthesis':
62.314 + entrycont['type'] = 'Master\'s thesis'
62.315 + elif entrytype == 'phdthesis':
62.316 + entrycont['type'] = 'PhD thesis'
62.317 +
62.318 + for eline in entrycont:
62.319 + if eline != '':
62.320 + eline = latexreplacements(eline)
62.321 +
62.322 + if entrycont.has_key('pages') and (entrycont['pages'] != ''):
62.323 + entrycont['pages'] = string.replace(entrycont['pages'], '--', '-')
62.324 +
62.325 + if entrycont.has_key('author') and (entrycont['author'] != ''):
62.326 + entry.append(entrycont['author']['text'] + '.')
62.327 + if entrycont.has_key('title') and (entrycont['title'] != ''):
62.328 + entry.append(entrycont['title'] + '.')
62.329 + if entrycont.has_key('journal') and (entrycont['journal'] != ''):
62.330 + entry.append(entrycont['journal'] + ',')
62.331 + if entrycont.has_key('booktitle') and (entrycont['booktitle'] != ''):
62.332 + entry.append('In ' + entrycont['booktitle'] + ',')
62.333 + if entrycont.has_key('type') and (entrycont['type'] != ''):
62.334 + eline = entrycont['type']
62.335 + if entrycont.has_key('number') and (entrycont['number'] != ''):
62.336 + eline += ' ' + entrycont['number']
62.337 + eline += ','
62.338 + entry.append(eline)
62.339 + if entrycont.has_key('institution') and (entrycont['institution'] != ''):
62.340 + entry.append(entrycont['institution'] + ',')
62.341 + if entrycont.has_key('publisher') and (entrycont['publisher'] != ''):
62.342 + entry.append(entrycont['publisher'] + ',')
62.343 + if entrycont.has_key('school') and (entrycont['school'] != ''):
62.344 + entry.append(entrycont['school'] + ',')
62.345 + if entrycont.has_key('address') and (entrycont['address'] != ''):
62.346 + entry.append(entrycont['address'] + ',')
62.347 + if entrycont.has_key('edition') and (entrycont['edition'] != ''):
62.348 + entry.append(entrycont['edition'] + ' edition,')
62.349 + if entrycont.has_key('howpublished') and (entrycont['howpublished'] != ''):
62.350 + entry.append(entrycont['howpublished'] + ',')
62.351 + if entrycont.has_key('volume') and (entrycont['volume'] != ''):
62.352 + eline = entrycont['volume'];
62.353 + if entrycont.has_key('number') and (entrycont['number'] != ''):
62.354 + eline += '(' + entrycont['number'] + ')'
62.355 + if entrycont.has_key('pages') and (entrycont['pages'] != ''):
62.356 + eline += ':' + entrycont['pages']
62.357 + eline += ','
62.358 + entry.append(eline)
62.359 + else:
62.360 + if entrycont.has_key('pages') and (entrycont['pages'] != ''):
62.361 + entry.append('pages ' + entrycont['pages'] + ',')
62.362 + if entrycont.has_key('year') and (entrycont['year'] != ''):
62.363 + if entrycont.has_key('month') and (entrycont['month'] != ''):
62.364 + entry.append(entrycont['month'] + ' ' + entrycont['year'] + '.')
62.365 + else:
62.366 + entry.append(entrycont['year'] + '.')
62.367 + if entrycont.has_key('note') and (entrycont['note'] != ''):
62.368 + entry.append(entrycont['note'] + '.')
62.369 + if entrycont.has_key('url') and (entrycont['url'] != ''):
62.370 + entry.append(entrycont['url'] + '.')
62.371 +
62.372 + # generate keys for sorting and for the output
62.373 + sortkey = ''
62.374 + bibkey = ''
62.375 + if entrycont.has_key('author'):
62.376 + for author in entrycont['author']['list']:
62.377 + sortkey += copychars(author, author.rfind(' ')+1, len(author))
62.378 + bibkey = entrycont['author']['abbrev']
62.379 + else:
62.380 + bibkey = 'x'
62.381 + if entrycont.has_key('year'):
62.382 + sortkey += entrycont['year']
62.383 + bibkey += entrycont['year'][-2:]
62.384 + if entrycont.has_key('title'):
62.385 + sortkey += entrycont['title']
62.386 + if entrycont.has_key('key'):
62.387 + sortkey = entrycont['key'] + sortkey
62.388 + bibkey = entrycont['key']
62.389 + entry.insert(0, sortkey)
62.390 + entry.insert(1, bibkey)
62.391 + entry.insert(2, entryid)
62.392 +
62.393 + # add the entry to the file contents
62.394 + filecont.append(entry)
62.395 +
62.396 + else:
62.397 + # field, publication info
62.398 + field = ''
62.399 + data = ''
62.400 +
62.401 + # field = {data} entries
62.402 + if bracedata_rex.match(line):
62.403 + field = bracefield_rex.sub('\g<1>', line)
62.404 + field = string.lower(field)
62.405 + data = bracedata_rex.sub('\g<2>', line)
62.406 +
62.407 + # field = "data" entries
62.408 + elif quotedata_rex.match(line):
62.409 + field = quotefield_rex.sub('\g<1>', line)
62.410 + field = string.lower(field)
62.411 + data = quotedata_rex.sub('\g<2>', line)
62.412 +
62.413 + # field = data entries
62.414 + elif data_rex.match(line):
62.415 + field = field_rex.sub('\g<1>', line)
62.416 + field = string.lower(field)
62.417 + data = data_rex.sub('\g<2>', line)
62.418 +
62.419 + if field == 'url':
62.420 + data = '\\url{' + data.strip() + '}'
62.421 +
62.422 + if field in ('author', 'editor'):
62.423 + entrycont[field] = bibtexauthor(data)
62.424 + line = ''
62.425 + elif field == 'title':
62.426 + line = bibtextitle(data, entrytype)
62.427 + elif field != '':
62.428 + line = removebraces(transformurls(data.strip()))
62.429 +
62.430 + if line != '':
62.431 + line = latexreplacements(line)
62.432 + entrycont[field] = line
62.433 +
62.434 +
62.435 + # sort entries
62.436 + filecont.sort(entry_cmp)
62.437 +
62.438 + # count the bibtex keys
62.439 + keytable = {}
62.440 + counttable = {}
62.441 + for entry in filecont:
62.442 + bibkey = entry[1]
62.443 + if not keytable.has_key(bibkey):
62.444 + keytable[bibkey] = 1
62.445 + else:
62.446 + keytable[bibkey] += 1
62.447 +
62.448 + for bibkey in keytable.keys():
62.449 + counttable[bibkey] = 0
62.450 +
62.451 + # generate output
62.452 + for entry in filecont:
62.453 + # generate output key form the bibtex key
62.454 + bibkey = entry[1]
62.455 + entryid = entry[2]
62.456 + if keytable[bibkey] == 1:
62.457 + outkey = bibkey
62.458 + else:
62.459 + outkey = bibkey + chr(97 + counttable[bibkey])
62.460 + counttable[bibkey] += 1
62.461 +
62.462 + # append the entry code to the output
62.463 + file.append('\\section ' + entryid + ' [' + outkey + ']')
62.464 + file.append('<div style="' + divstyle + '">')
62.465 + for line in entry[3:]:
62.466 + file.append(line)
62.467 + file.append('</div>')
62.468 + file.append('')
62.469 +
62.470 + return file
62.471 +
62.472 +
62.473 +#
62.474 +# return 1 iff abbr is in line but not inside braces or quotes
62.475 +# assumes that abbr appears only once on the line (out of braces and quotes)
62.476 +#
62.477 +def verify_out_of_braces(line, abbr):
62.478 +
62.479 + phrase_split = delimiter_rex.split(line)
62.480 +
62.481 + abbr_rex = re.compile( '\\b' + abbr + '\\b', re.I)
62.482 +
62.483 + open_brace = 0
62.484 + open_quote = 0
62.485 +
62.486 + for phrase in phrase_split:
62.487 + if phrase == "{":
62.488 + open_brace = open_brace + 1
62.489 + elif phrase == "}":
62.490 + open_brace = open_brace - 1
62.491 + elif phrase == '"':
62.492 + if open_quote == 1:
62.493 + open_quote = 0
62.494 + else:
62.495 + open_quote = 1
62.496 + elif abbr_rex.search(phrase):
62.497 + if open_brace == 0 and open_quote == 0:
62.498 + return 1
62.499 +
62.500 + return 0
62.501 +
62.502 +
62.503 +#
62.504 +# a line in the form phrase1 # phrase2 # ... # phrasen
62.505 +# is returned as phrase1 phrase2 ... phrasen
62.506 +# with the correct punctuation
62.507 +# Bug: Doesn't always work with multiple abbreviations plugged in
62.508 +#
62.509 +def concat_line(line):
62.510 + # only look at part after equals
62.511 + field = field_rex.sub('\g<1>',line)
62.512 + rest = field_rex.sub('\g<2>',line)
62.513 +
62.514 + concat_line = field + ' ='
62.515 +
62.516 + pound_split = concatsplit_rex.split(rest)
62.517 +
62.518 + phrase_count = 0
62.519 + length = len(pound_split)
62.520 +
62.521 + for phrase in pound_split:
62.522 + phrase = phrase.strip()
62.523 + if phrase_count != 0:
62.524 + if phrase.startswith('"') or phrase.startswith('{'):
62.525 + phrase = phrase[1:]
62.526 + elif phrase.startswith('"'):
62.527 + phrase = phrase.replace('"','{',1)
62.528 +
62.529 + if phrase_count != length-1:
62.530 + if phrase.endswith('"') or phrase.endswith('}'):
62.531 + phrase = phrase[:-1]
62.532 + else:
62.533 + if phrase.endswith('"'):
62.534 + phrase = phrase[:-1]
62.535 + phrase = phrase + "}"
62.536 + elif phrase.endswith('",'):
62.537 + phrase = phrase[:-2]
62.538 + phrase = phrase + "},"
62.539 +
62.540 + # if phrase did have \#, add the \# back
62.541 + if phrase.endswith('\\'):
62.542 + phrase = phrase + "#"
62.543 + concat_line = concat_line + ' ' + phrase
62.544 +
62.545 + phrase_count = phrase_count + 1
62.546 +
62.547 + return concat_line
62.548 +
62.549 +
62.550 +#
62.551 +# substitute abbreviations into filecont
62.552 +# @param filecont_source - string of data from file
62.553 +#
62.554 +def bibtex_replace_abbreviations(filecont_source):
62.555 + filecont = filecont_source.splitlines()
62.556 +
62.557 + # These are defined in bibtex, so we'll define them too
62.558 + abbr_list = ['jan','feb','mar','apr','may','jun',
62.559 + 'jul','aug','sep','oct','nov','dec']
62.560 + value_list = ['January','February','March','April',
62.561 + 'May','June','July','August','September',
62.562 + 'October','November','December']
62.563 +
62.564 + abbr_rex = []
62.565 + total_abbr_count = 0
62.566 +
62.567 + front = '\\b'
62.568 + back = '(,?)\\b'
62.569 +
62.570 + for x in abbr_list:
62.571 + abbr_rex.append( re.compile( front + abbr_list[total_abbr_count] + back, re.I ) )
62.572 + total_abbr_count = total_abbr_count + 1
62.573 +
62.574 +
62.575 + abbrdef_rex = re.compile('\s*@string\s*{\s*('+ valid_name_chars +'*)\s*=(.*)',
62.576 + re.I)
62.577 +
62.578 + comment_rex = re.compile('@comment\s*{',re.I)
62.579 + preamble_rex = re.compile('@preamble\s*{',re.I)
62.580 +
62.581 + waiting_for_end_string = 0
62.582 + i = 0
62.583 + filecont2 = ''
62.584 +
62.585 + for line in filecont:
62.586 + if line == ' ' or line == '':
62.587 + continue
62.588 +
62.589 + if waiting_for_end_string:
62.590 + if re.search('}',line):
62.591 + waiting_for_end_string = 0
62.592 + continue
62.593 +
62.594 + if abbrdef_rex.search(line):
62.595 + abbr = abbrdef_rex.sub('\g<1>', line)
62.596 +
62.597 + if abbr_list.count(abbr) == 0:
62.598 + val = abbrdef_rex.sub('\g<2>', line)
62.599 + abbr_list.append(abbr)
62.600 + value_list.append(string.strip(val))
62.601 + abbr_rex.append( re.compile( front + abbr_list[total_abbr_count] + back, re.I ) )
62.602 + total_abbr_count = total_abbr_count + 1
62.603 + waiting_for_end_string = 1
62.604 + continue
62.605 +
62.606 + if comment_rex.search(line):
62.607 + waiting_for_end_string = 1
62.608 + continue
62.609 +
62.610 + if preamble_rex.search(line):
62.611 + waiting_for_end_string = 1
62.612 + continue
62.613 +
62.614 +
62.615 + # replace subsequent abbreviations with the value
62.616 + abbr_count = 0
62.617 +
62.618 + for x in abbr_list:
62.619 +
62.620 + if abbr_rex[abbr_count].search(line):
62.621 + if verify_out_of_braces(line,abbr_list[abbr_count]) == 1:
62.622 + line = abbr_rex[abbr_count].sub( value_list[abbr_count] + '\g<1>', line)
62.623 + # Check for # concatenations
62.624 + if concatsplit_rex.search(line):
62.625 + line = concat_line(line)
62.626 + abbr_count = abbr_count + 1
62.627 +
62.628 +
62.629 + filecont2 = filecont2 + line + '\n'
62.630 + i = i+1
62.631 +
62.632 +
62.633 + # Do one final pass over file
62.634 +
62.635 + # make sure that didn't end up with {" or }" after the substitution
62.636 + filecont2 = filecont2.replace('{"','{{')
62.637 + filecont2 = filecont2.replace('"}','}}')
62.638 +
62.639 + afterquotevalue_rex = re.compile('"\s*,\s*')
62.640 + afterbrace_rex = re.compile('"\s*}')
62.641 + afterbracevalue_rex = re.compile('(=\s*{[^=]*)},\s*')
62.642 +
62.643 + # add new lines to data that changed because of abbreviation substitutions
62.644 + filecont2 = afterquotevalue_rex.sub('",\n', filecont2)
62.645 + filecont2 = afterbrace_rex.sub('"\n}', filecont2)
62.646 + filecont2 = afterbracevalue_rex.sub('\g<1>},\n', filecont2)
62.647 +
62.648 + return filecont2
62.649 +
62.650 +#
62.651 +# convert @type( ... ) to @type{ ... }
62.652 +#
62.653 +def no_outer_parens(filecont):
62.654 +
62.655 + # do checking for open parens
62.656 + # will convert to braces
62.657 + paren_split = re.split('([(){}])',filecont)
62.658 +
62.659 + open_paren_count = 0
62.660 + open_type = 0
62.661 + look_next = 0
62.662 +
62.663 + # rebuild filecont
62.664 + filecont = ''
62.665 +
62.666 + at_rex = re.compile('@\w*')
62.667 +
62.668 + for phrase in paren_split:
62.669 + if look_next == 1:
62.670 + if phrase == '(':
62.671 + phrase = '{'
62.672 + open_paren_count = open_paren_count + 1
62.673 + else:
62.674 + open_type = 0
62.675 + look_next = 0
62.676 +
62.677 + if phrase == '(':
62.678 + open_paren_count = open_paren_count + 1
62.679 +
62.680 + elif phrase == ')':
62.681 + open_paren_count = open_paren_count - 1
62.682 + if open_type == 1 and open_paren_count == 0:
62.683 + phrase = '}'
62.684 + open_type = 0
62.685 +
62.686 + elif at_rex.search( phrase ):
62.687 + open_type = 1
62.688 + look_next = 1
62.689 +
62.690 + filecont = filecont + phrase
62.691 +
62.692 + return filecont
62.693 +
62.694 +
62.695 +#
62.696 +# make all whitespace into just one space
62.697 +# format the bibtex file into a usable form.
62.698 +#
62.699 +def bibtexwasher(filecont_source):
62.700 +
62.701 + space_rex = re.compile('\s+')
62.702 + comment_rex = re.compile('\s*%')
62.703 +
62.704 + filecont = []
62.705 +
62.706 + # remove trailing and excessive whitespace
62.707 + # ignore comments
62.708 + for line in filecont_source:
62.709 + line = string.strip(line)
62.710 + line = space_rex.sub(' ', line)
62.711 + # ignore comments
62.712 + if not comment_rex.match(line) and line != '':
62.713 + filecont.append(' '+ line)
62.714 +
62.715 + filecont = string.join(filecont, '')
62.716 +
62.717 + # the file is in one long string
62.718 +
62.719 + filecont = no_outer_parens(filecont)
62.720 +
62.721 + #
62.722 + # split lines according to preferred syntax scheme
62.723 + #
62.724 + filecont = re.sub('(=\s*{[^=]*)},', '\g<1>},\n', filecont)
62.725 +
62.726 + # add new lines after commas that are after values
62.727 + filecont = re.sub('"\s*,', '",\n', filecont)
62.728 + filecont = re.sub('=\s*([\w\d]+)\s*,', '= \g<1>,\n', filecont)
62.729 + filecont = re.sub('(@\w*)\s*({(\s*)[^,\s]*)\s*,',
62.730 + '\n\n\g<1>\g<2>,\n', filecont)
62.731 +
62.732 + # add new lines after }
62.733 + filecont = re.sub('"\s*}','"\n}\n', filecont)
62.734 + filecont = re.sub('}\s*,','},\n', filecont)
62.735 +
62.736 +
62.737 + filecont = re.sub('@(\w*)', '\n@\g<1>', filecont)
62.738 +
62.739 + # character encoding, reserved latex characters
62.740 + filecont = re.sub('{\\\&}', '&', filecont)
62.741 + filecont = re.sub('\\\&', '&', filecont)
62.742 +
62.743 + # do checking for open braces to get format correct
62.744 + open_brace_count = 0
62.745 + brace_split = re.split('([{}])',filecont)
62.746 +
62.747 + # rebuild filecont
62.748 + filecont = ''
62.749 +
62.750 + for phrase in brace_split:
62.751 + if phrase == '{':
62.752 + open_brace_count = open_brace_count + 1
62.753 + elif phrase == '}':
62.754 + open_brace_count = open_brace_count - 1
62.755 + if open_brace_count == 0:
62.756 + filecont = filecont + '\n'
62.757 +
62.758 + filecont = filecont + phrase
62.759 +
62.760 + filecont2 = bibtex_replace_abbreviations(filecont)
62.761 +
62.762 + # gather
62.763 + filecont = filecont2.splitlines()
62.764 + i=0
62.765 + j=0 # count the number of blank lines
62.766 + for line in filecont:
62.767 + # ignore blank lines
62.768 + if line == '' or line == ' ':
62.769 + j = j+1
62.770 + continue
62.771 + filecont[i] = line + '\n'
62.772 + i = i+1
62.773 +
62.774 + # get rid of the extra stuff at the end of the array
62.775 + # (The extra stuff are duplicates that are in the array because
62.776 + # blank lines were removed.)
62.777 + length = len( filecont)
62.778 + filecont[length-j:length] = []
62.779 +
62.780 + return filecont
62.781 +
62.782 +
62.783 +def filehandler(filepath):
62.784 + try:
62.785 + fd = open(filepath, 'r')
62.786 + filecont_source = fd.readlines()
62.787 + fd.close()
62.788 + except:
62.789 + print 'Could not open file:', filepath
62.790 + washeddata = bibtexwasher(filecont_source)
62.791 + outdata = bibtexdecoder(washeddata)
62.792 + print '/**'
62.793 + print '\page references References'
62.794 + print
62.795 + for line in outdata:
62.796 + print line
62.797 + print '*/'
62.798 +
62.799 +
62.800 +# main program
62.801 +
62.802 +def main():
62.803 + import sys
62.804 + if sys.argv[1:]:
62.805 + filepath = sys.argv[1]
62.806 + else:
62.807 + print "No input file"
62.808 + sys.exit()
62.809 + filehandler(filepath)
62.810 +
62.811 +if __name__ == "__main__": main()
62.812 +
62.813 +
62.814 +# end python script
63.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
63.2 +++ b/scripts/bootstrap.sh Wed Dec 09 11:14:06 2009 +0100
63.3 @@ -0,0 +1,142 @@
63.4 +#!/bin/bash
63.5 +#
63.6 +# This file is a part of LEMON, a generic C++ optimization library.
63.7 +#
63.8 +# Copyright (C) 2003-2009
63.9 +# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
63.10 +# (Egervary Research Group on Combinatorial Optimization, EGRES).
63.11 +#
63.12 +# Permission to use, modify and distribute this software is granted
63.13 +# provided that this copyright notice appears in all copies. For
63.14 +# precise terms see the accompanying LICENSE file.
63.15 +#
63.16 +# This software is provided "AS IS" with no warranty of any kind,
63.17 +# express or implied, and with no claim as to its suitability for any
63.18 +# purpose.
63.19 +
63.20 +
63.21 +if [ ! -f ~/.lemon-bootstrap ]; then
63.22 + echo 'Create ~/.lemon-bootstrap'.
63.23 + cat >~/.lemon-bootstrap <<EOF
63.24 +#
63.25 +# Default settings for bootstraping the LEMON source code repository
63.26 +#
63.27 +EOF
63.28 +fi
63.29 +
63.30 +source ~/.lemon-bootstrap
63.31 +if [ -f ../../../.lemon-bootstrap ]; then source ../../../.lemon-bootstrap; fi
63.32 +if [ -f ../../.lemon-bootstrap ]; then source ../../.lemon-bootstrap; fi
63.33 +if [ -f ../.lemon-bootstrap ]; then source ../.lemon-bootstrap; fi
63.34 +if [ -f ./.lemon-bootstrap ]; then source ./.lemon-bootstrap; fi
63.35 +
63.36 +
63.37 +function augment_config() {
63.38 + if [ "x${!1}" == "x" ]; then
63.39 + eval $1=$2
63.40 + echo Add "'$1'" to '~/.lemon-bootstrap'.
63.41 + echo >>~/.lemon-bootstrap
63.42 + echo $3 >>~/.lemon-bootstrap
63.43 + echo $1=$2 >>~/.lemon-bootstrap
63.44 + fi
63.45 +}
63.46 +
63.47 +augment_config LEMON_INSTALL_PREFIX /usr/local \
63.48 + "# LEMON installation prefix"
63.49 +
63.50 +augment_config COIN_OR_PREFIX /usr/local/coin-or \
63.51 + "# COIN-OR installation root prefix (used for CLP/CBC)"
63.52 +
63.53 +augment_config SOPLEX_PREFIX /usr/local/soplex \
63.54 + "# Soplex build prefix"
63.55 +
63.56 +
63.57 +function ask() {
63.58 +echo -n "$1 [$2]? "
63.59 +read _an
63.60 +if [ "x$_an" == "x" ]; then
63.61 + ret="$2"
63.62 +else
63.63 + ret=$_an
63.64 +fi
63.65 +}
63.66 +
63.67 +function yesorno() {
63.68 + ret='rossz'
63.69 + while [ "$ret" != "y" -a "$ret" != "n" -a "$ret" != "yes" -a "$ret" != "no" ]; do
63.70 + ask "$1" "$2"
63.71 + done
63.72 + if [ "$ret" != "y" -a "$ret" != "yes" ]; then
63.73 + return 1
63.74 + else
63.75 + return 0
63.76 + fi
63.77 +}
63.78 +
63.79 +if yesorno "External build" "n"
63.80 +then
63.81 + CONFIGURE_PATH=".."
63.82 +else
63.83 + CONFIGURE_PATH="."
63.84 + if yesorno "Autoreconf" "y"
63.85 + then
63.86 + AUTORE=yes
63.87 + else
63.88 + AUTORE=no
63.89 + fi
63.90 +fi
63.91 +
63.92 +if yesorno "Optimize" "n"
63.93 +then
63.94 + opt_flags=' -O2'
63.95 +else
63.96 + opt_flags=''
63.97 +fi
63.98 +
63.99 +if yesorno "Stop on warning" "y"
63.100 +then
63.101 + werror_flags=' -Werror'
63.102 +else
63.103 + werror_flags=''
63.104 +fi
63.105 +
63.106 +cxx_flags="CXXFLAGS=-ggdb$opt_flags$werror_flags"
63.107 +
63.108 +if yesorno "Check with valgrind" "n"
63.109 +then
63.110 + valgrind_flags=' --enable-valgrind'
63.111 +else
63.112 + valgrind_flags=''
63.113 +fi
63.114 +
63.115 +if [ -f ${COIN_OR_PREFIX}/include/coin/config_coinutils.h ]; then
63.116 + if yesorno "Use COIN-OR (CBC/CLP)" "n"
63.117 + then
63.118 + coin_flag="--with-coin=$COIN_OR_PREFIX"
63.119 + else
63.120 + coin_flag=""
63.121 + fi
63.122 +else
63.123 + coin_flag=""
63.124 +fi
63.125 +
63.126 +if [ -f ${SOPLEX_PREFIX}/src/soplex.h ]; then
63.127 + if yesorno "Use Soplex" "n"
63.128 + then
63.129 + soplex_flag="--with-soplex=$SOPLEX_PREFIX"
63.130 + else
63.131 + soplex_flag=""
63.132 + fi
63.133 +else
63.134 + soplex_flag=""
63.135 +fi
63.136 +
63.137 +if [ "x$AUTORE" == "xyes" ]; then
63.138 + autoreconf -vif;
63.139 +fi
63.140 +${CONFIGURE_PATH}/configure --prefix=$LEMON_INSTALL_PREFIX \
63.141 +$valgrind_flags \
63.142 +"$cxx_flags" \
63.143 +$coin_flag \
63.144 +$soplex_flag \
63.145 +$*
64.1 --- a/scripts/chg-len.py Sun Oct 04 10:15:32 2009 +0200
64.2 +++ b/scripts/chg-len.py Wed Dec 09 11:14:06 2009 +0100
64.3 @@ -1,4 +1,18 @@
64.4 #! /usr/bin/env python
64.5 +#
64.6 +# This file is a part of LEMON, a generic C++ optimization library.
64.7 +#
64.8 +# Copyright (C) 2003-2009
64.9 +# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
64.10 +# (Egervary Research Group on Combinatorial Optimization, EGRES).
64.11 +#
64.12 +# Permission to use, modify and distribute this software is granted
64.13 +# provided that this copyright notice appears in all copies. For
64.14 +# precise terms see the accompanying LICENSE file.
64.15 +#
64.16 +# This software is provided "AS IS" with no warranty of any kind,
64.17 +# express or implied, and with no claim as to its suitability for any
64.18 +# purpose.
64.19
64.20 import sys
64.21
65.1 --- a/scripts/mk-release.sh Sun Oct 04 10:15:32 2009 +0200
65.2 +++ b/scripts/mk-release.sh Wed Dec 09 11:14:06 2009 +0100
65.3 @@ -1,4 +1,18 @@
65.4 #!/bin/bash
65.5 +#
65.6 +# This file is a part of LEMON, a generic C++ optimization library.
65.7 +#
65.8 +# Copyright (C) 2003-2009
65.9 +# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
65.10 +# (Egervary Research Group on Combinatorial Optimization, EGRES).
65.11 +#
65.12 +# Permission to use, modify and distribute this software is granted
65.13 +# provided that this copyright notice appears in all copies. For
65.14 +# precise terms see the accompanying LICENSE file.
65.15 +#
65.16 +# This software is provided "AS IS" with no warranty of any kind,
65.17 +# express or implied, and with no claim as to its suitability for any
65.18 +# purpose.
65.19
65.20 set -e
65.21
66.1 --- a/scripts/unify-sources.sh Sun Oct 04 10:15:32 2009 +0200
66.2 +++ b/scripts/unify-sources.sh Wed Dec 09 11:14:06 2009 +0100
66.3 @@ -1,4 +1,18 @@
66.4 #!/bin/bash
66.5 +#
66.6 +# This file is a part of LEMON, a generic C++ optimization library.
66.7 +#
66.8 +# Copyright (C) 2003-2009
66.9 +# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
66.10 +# (Egervary Research Group on Combinatorial Optimization, EGRES).
66.11 +#
66.12 +# Permission to use, modify and distribute this software is granted
66.13 +# provided that this copyright notice appears in all copies. For
66.14 +# precise terms see the accompanying LICENSE file.
66.15 +#
66.16 +# This software is provided "AS IS" with no warranty of any kind,
66.17 +# express or implied, and with no claim as to its suitability for any
66.18 +# purpose.
66.19
66.20 YEAR=`date +%Y`
66.21 HGROOT=`hg root`
67.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
67.2 +++ b/scripts/valgrind-wrapper.sh Wed Dec 09 11:14:06 2009 +0100
67.3 @@ -0,0 +1,22 @@
67.4 +#!/bin/sh
67.5 +
67.6 +# Run in valgrind, with leak checking enabled
67.7 +
67.8 +valgrind -q --leak-check=full "$@" 2> .valgrind-log
67.9 +
67.10 +# Save the test result
67.11 +
67.12 +result="$?"
67.13 +
67.14 +# Valgrind should generate no error messages
67.15 +
67.16 +log_contents="`cat .valgrind-log`"
67.17 +
67.18 +if [ "$log_contents" != "" ]; then
67.19 + cat .valgrind-log >&2
67.20 + result=1
67.21 +fi
67.22 +
67.23 +rm -f .valgrind-log
67.24 +
67.25 +exit $result
68.1 --- a/test/CMakeLists.txt Sun Oct 04 10:15:32 2009 +0200
68.2 +++ b/test/CMakeLists.txt Wed Dec 09 11:14:06 2009 +0100
68.3 @@ -32,6 +32,7 @@
68.4 matching_test
68.5 min_cost_arborescence_test
68.6 min_cost_flow_test
68.7 + min_mean_cycle_test
68.8 path_test
68.9 planarity_test
68.10 preflow_test
69.1 --- a/test/Makefile.am Sun Oct 04 10:15:32 2009 +0200
69.2 +++ b/test/Makefile.am Wed Dec 09 11:14:06 2009 +0100
69.3 @@ -1,3 +1,7 @@
69.4 +if USE_VALGRIND
69.5 +TESTS_ENVIRONMENT=$(top_srcdir)/scripts/valgrind-wrapper.sh
69.6 +endif
69.7 +
69.8 EXTRA_DIST += \
69.9 test/CMakeLists.txt
69.10
69.11 @@ -30,6 +34,7 @@
69.12 test/matching_test \
69.13 test/min_cost_arborescence_test \
69.14 test/min_cost_flow_test \
69.15 + test/min_mean_cycle_test \
69.16 test/path_test \
69.17 test/planarity_test \
69.18 test/preflow_test \
69.19 @@ -79,6 +84,7 @@
69.20 test_matching_test_SOURCES = test/matching_test.cc
69.21 test_min_cost_arborescence_test_SOURCES = test/min_cost_arborescence_test.cc
69.22 test_min_cost_flow_test_SOURCES = test/min_cost_flow_test.cc
69.23 +test_min_mean_cycle_test_SOURCES = test/min_mean_cycle_test.cc
69.24 test_path_test_SOURCES = test/path_test.cc
69.25 test_planarity_test_SOURCES = test/planarity_test.cc
69.26 test_preflow_test_SOURCES = test/preflow_test.cc
70.1 --- a/test/adaptors_test.cc Sun Oct 04 10:15:32 2009 +0200
70.2 +++ b/test/adaptors_test.cc Wed Dec 09 11:14:06 2009 +0100
70.3 @@ -1371,51 +1371,43 @@
70.4 GridGraph::Node n4 = graph(1,1);
70.5
70.6 GridGraph::EdgeMap<bool> dir_map(graph);
70.7 - dir_map[graph.right(n1)] = graph.u(graph.right(n1)) == n1;
70.8 - dir_map[graph.up(n1)] = graph.u(graph.up(n1)) != n1;
70.9 - dir_map[graph.left(n4)] = graph.u(graph.left(n4)) != n4;
70.10 - dir_map[graph.down(n4)] = graph.u(graph.down(n4)) != n4;
70.11 + dir_map[graph.right(n1)] = graph.u(graph.right(n1)) != n1;
70.12 + dir_map[graph.up(n1)] = graph.u(graph.up(n1)) == n1;
70.13 + dir_map[graph.left(n4)] = graph.u(graph.left(n4)) == n4;
70.14 + dir_map[graph.down(n4)] = graph.u(graph.down(n4)) == n4;
70.15
70.16 // Apply several adaptors on the grid graph
70.17 - typedef SplitNodes< ReverseDigraph< const Orienter<
70.18 - const GridGraph, GridGraph::EdgeMap<bool> > > >
70.19 - RevSplitGridGraph;
70.20 - typedef ReverseDigraph<const RevSplitGridGraph> SplitGridGraph;
70.21 + typedef SplitNodes<Orienter< const GridGraph, GridGraph::EdgeMap<bool> > >
70.22 + SplitGridGraph;
70.23 typedef Undirector<const SplitGridGraph> USplitGridGraph;
70.24 - typedef Undirector<const USplitGridGraph> UUSplitGridGraph;
70.25 - checkConcept<concepts::Digraph, RevSplitGridGraph>();
70.26 checkConcept<concepts::Digraph, SplitGridGraph>();
70.27 checkConcept<concepts::Graph, USplitGridGraph>();
70.28 - checkConcept<concepts::Graph, UUSplitGridGraph>();
70.29
70.30 - RevSplitGridGraph rev_adaptor =
70.31 - splitNodes(reverseDigraph(orienter(graph, dir_map)));
70.32 - SplitGridGraph adaptor = reverseDigraph(rev_adaptor);
70.33 + SplitGridGraph adaptor = splitNodes(orienter(graph, dir_map));
70.34 USplitGridGraph uadaptor = undirector(adaptor);
70.35 - UUSplitGridGraph uuadaptor = undirector(uadaptor);
70.36
70.37 // Check adaptor
70.38 checkGraphNodeList(adaptor, 8);
70.39 checkGraphArcList(adaptor, 8);
70.40 checkGraphConArcList(adaptor, 8);
70.41
70.42 - checkGraphOutArcList(adaptor, rev_adaptor.inNode(n1), 1);
70.43 - checkGraphOutArcList(adaptor, rev_adaptor.outNode(n1), 1);
70.44 - checkGraphOutArcList(adaptor, rev_adaptor.inNode(n2), 2);
70.45 - checkGraphOutArcList(adaptor, rev_adaptor.outNode(n2), 1);
70.46 - checkGraphOutArcList(adaptor, rev_adaptor.inNode(n3), 1);
70.47 - checkGraphOutArcList(adaptor, rev_adaptor.outNode(n3), 1);
70.48 - checkGraphOutArcList(adaptor, rev_adaptor.inNode(n4), 0);
70.49 - checkGraphOutArcList(adaptor, rev_adaptor.outNode(n4), 1);
70.50 + checkGraphOutArcList(adaptor, adaptor.inNode(n1), 1);
70.51 + checkGraphOutArcList(adaptor, adaptor.outNode(n1), 1);
70.52 + checkGraphOutArcList(adaptor, adaptor.inNode(n2), 1);
70.53 + checkGraphOutArcList(adaptor, adaptor.outNode(n2), 0);
70.54 + checkGraphOutArcList(adaptor, adaptor.inNode(n3), 1);
70.55 + checkGraphOutArcList(adaptor, adaptor.outNode(n3), 1);
70.56 + checkGraphOutArcList(adaptor, adaptor.inNode(n4), 1);
70.57 + checkGraphOutArcList(adaptor, adaptor.outNode(n4), 2);
70.58
70.59 - checkGraphInArcList(adaptor, rev_adaptor.inNode(n1), 1);
70.60 - checkGraphInArcList(adaptor, rev_adaptor.outNode(n1), 1);
70.61 - checkGraphInArcList(adaptor, rev_adaptor.inNode(n2), 1);
70.62 - checkGraphInArcList(adaptor, rev_adaptor.outNode(n2), 0);
70.63 - checkGraphInArcList(adaptor, rev_adaptor.inNode(n3), 1);
70.64 - checkGraphInArcList(adaptor, rev_adaptor.outNode(n3), 1);
70.65 - checkGraphInArcList(adaptor, rev_adaptor.inNode(n4), 1);
70.66 - checkGraphInArcList(adaptor, rev_adaptor.outNode(n4), 2);
70.67 + checkGraphInArcList(adaptor, adaptor.inNode(n1), 1);
70.68 + checkGraphInArcList(adaptor, adaptor.outNode(n1), 1);
70.69 + checkGraphInArcList(adaptor, adaptor.inNode(n2), 2);
70.70 + checkGraphInArcList(adaptor, adaptor.outNode(n2), 1);
70.71 + checkGraphInArcList(adaptor, adaptor.inNode(n3), 1);
70.72 + checkGraphInArcList(adaptor, adaptor.outNode(n3), 1);
70.73 + checkGraphInArcList(adaptor, adaptor.inNode(n4), 0);
70.74 + checkGraphInArcList(adaptor, adaptor.outNode(n4), 1);
70.75
70.76 checkNodeIds(adaptor);
70.77 checkArcIds(adaptor);
70.78 @@ -1438,29 +1430,14 @@
70.79 checkGraphEdgeMap(uadaptor);
70.80 checkGraphArcMap(uadaptor);
70.81
70.82 - checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n1), 2);
70.83 - checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n1), 2);
70.84 - checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n2), 3);
70.85 - checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n2), 1);
70.86 - checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n3), 2);
70.87 - checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n3), 2);
70.88 - checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n4), 1);
70.89 - checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n4), 3);
70.90 -
70.91 - // Check uuadaptor
70.92 - checkGraphNodeList(uuadaptor, 8);
70.93 - checkGraphEdgeList(uuadaptor, 16);
70.94 - checkGraphArcList(uuadaptor, 32);
70.95 - checkGraphConEdgeList(uuadaptor, 16);
70.96 - checkGraphConArcList(uuadaptor, 32);
70.97 -
70.98 - checkNodeIds(uuadaptor);
70.99 - checkEdgeIds(uuadaptor);
70.100 - checkArcIds(uuadaptor);
70.101 -
70.102 - checkGraphNodeMap(uuadaptor);
70.103 - checkGraphEdgeMap(uuadaptor);
70.104 - checkGraphArcMap(uuadaptor);
70.105 + checkGraphIncEdgeArcLists(uadaptor, adaptor.inNode(n1), 2);
70.106 + checkGraphIncEdgeArcLists(uadaptor, adaptor.outNode(n1), 2);
70.107 + checkGraphIncEdgeArcLists(uadaptor, adaptor.inNode(n2), 3);
70.108 + checkGraphIncEdgeArcLists(uadaptor, adaptor.outNode(n2), 1);
70.109 + checkGraphIncEdgeArcLists(uadaptor, adaptor.inNode(n3), 2);
70.110 + checkGraphIncEdgeArcLists(uadaptor, adaptor.outNode(n3), 2);
70.111 + checkGraphIncEdgeArcLists(uadaptor, adaptor.inNode(n4), 1);
70.112 + checkGraphIncEdgeArcLists(uadaptor, adaptor.outNode(n4), 3);
70.113 }
70.114
70.115 int main(int, const char **) {
71.1 --- a/test/bellman_ford_test.cc Sun Oct 04 10:15:32 2009 +0200
71.2 +++ b/test/bellman_ford_test.cc Wed Dec 09 11:14:06 2009 +0100
71.3 @@ -65,7 +65,7 @@
71.4 Node s, t, n;
71.5 Arc e;
71.6 Value l;
71.7 - int k;
71.8 + int k=3;
71.9 bool b;
71.10 BF::DistMap d(gr);
71.11 BF::PredMap p(gr);
71.12 @@ -96,6 +96,7 @@
71.13 d = const_bf_test.distMap();
71.14 p = const_bf_test.predMap();
71.15 pp = const_bf_test.path(t);
71.16 + pp = const_bf_test.negativeCycle();
71.17
71.18 for (BF::ActiveIt it(const_bf_test); it != INVALID; ++it) {}
71.19 }
71.20 @@ -132,6 +133,7 @@
71.21 s = bf_test.predNode(t);
71.22 b = bf_test.reached(t);
71.23 pp = bf_test.path(t);
71.24 + pp = bf_test.negativeCycle();
71.25 }
71.26 }
71.27
72.1 --- a/test/digraph_test.cc Sun Oct 04 10:15:32 2009 +0200
72.2 +++ b/test/digraph_test.cc Wed Dec 09 11:14:06 2009 +0100
72.3 @@ -19,6 +19,7 @@
72.4 #include <lemon/concepts/digraph.h>
72.5 #include <lemon/list_graph.h>
72.6 #include <lemon/smart_graph.h>
72.7 +#include <lemon/static_graph.h>
72.8 #include <lemon/full_graph.h>
72.9
72.10 #include "test_tools.h"
72.11 @@ -35,6 +36,9 @@
72.12 checkGraphNodeList(G, 0);
72.13 checkGraphArcList(G, 0);
72.14
72.15 + G.reserveNode(3);
72.16 + G.reserveArc(4);
72.17 +
72.18 Node
72.19 n1 = G.addNode(),
72.20 n2 = G.addNode(),
72.21 @@ -283,6 +287,14 @@
72.22 G.addArc(G.addNode(), G.addNode());
72.23
72.24 snapshot.restore();
72.25 + snapshot.save(G);
72.26 +
72.27 + checkGraphNodeList(G, 4);
72.28 + checkGraphArcList(G, 4);
72.29 +
72.30 + G.addArc(G.addNode(), G.addNode());
72.31 +
72.32 + snapshot.restore();
72.33
72.34 checkGraphNodeList(G, 4);
72.35 checkGraphArcList(G, 4);
72.36 @@ -317,6 +329,10 @@
72.37 checkConcept<ExtendableDigraphComponent<>, SmartDigraph>();
72.38 checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
72.39 }
72.40 + { // Checking StaticDigraph
72.41 + checkConcept<Digraph, StaticDigraph>();
72.42 + checkConcept<ClearableDigraphComponent<>, StaticDigraph>();
72.43 + }
72.44 { // Checking FullDigraph
72.45 checkConcept<Digraph, FullDigraph>();
72.46 }
72.47 @@ -372,10 +388,122 @@
72.48 check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
72.49 }
72.50
72.51 +void checkStaticDigraph() {
72.52 + SmartDigraph g;
72.53 + SmartDigraph::NodeMap<StaticDigraph::Node> nref(g);
72.54 + SmartDigraph::ArcMap<StaticDigraph::Arc> aref(g);
72.55 +
72.56 + StaticDigraph G;
72.57 +
72.58 + checkGraphNodeList(G, 0);
72.59 + checkGraphArcList(G, 0);
72.60 +
72.61 + G.build(g, nref, aref);
72.62 +
72.63 + checkGraphNodeList(G, 0);
72.64 + checkGraphArcList(G, 0);
72.65 +
72.66 + SmartDigraph::Node
72.67 + n1 = g.addNode(),
72.68 + n2 = g.addNode(),
72.69 + n3 = g.addNode();
72.70 +
72.71 + G.build(g, nref, aref);
72.72 +
72.73 + checkGraphNodeList(G, 3);
72.74 + checkGraphArcList(G, 0);
72.75 +
72.76 + SmartDigraph::Arc a1 = g.addArc(n1, n2);
72.77 +
72.78 + G.build(g, nref, aref);
72.79 +
72.80 + check(G.source(aref[a1]) == nref[n1] && G.target(aref[a1]) == nref[n2],
72.81 + "Wrong arc or wrong references");
72.82 + checkGraphNodeList(G, 3);
72.83 + checkGraphArcList(G, 1);
72.84 +
72.85 + checkGraphOutArcList(G, nref[n1], 1);
72.86 + checkGraphOutArcList(G, nref[n2], 0);
72.87 + checkGraphOutArcList(G, nref[n3], 0);
72.88 +
72.89 + checkGraphInArcList(G, nref[n1], 0);
72.90 + checkGraphInArcList(G, nref[n2], 1);
72.91 + checkGraphInArcList(G, nref[n3], 0);
72.92 +
72.93 + checkGraphConArcList(G, 1);
72.94 +
72.95 + SmartDigraph::Arc
72.96 + a2 = g.addArc(n2, n1),
72.97 + a3 = g.addArc(n2, n3),
72.98 + a4 = g.addArc(n2, n3);
72.99 +
72.100 + digraphCopy(g, G).nodeRef(nref).run();
72.101 +
72.102 + checkGraphNodeList(G, 3);
72.103 + checkGraphArcList(G, 4);
72.104 +
72.105 + checkGraphOutArcList(G, nref[n1], 1);
72.106 + checkGraphOutArcList(G, nref[n2], 3);
72.107 + checkGraphOutArcList(G, nref[n3], 0);
72.108 +
72.109 + checkGraphInArcList(G, nref[n1], 1);
72.110 + checkGraphInArcList(G, nref[n2], 1);
72.111 + checkGraphInArcList(G, nref[n3], 2);
72.112 +
72.113 + checkGraphConArcList(G, 4);
72.114 +
72.115 + std::vector<std::pair<int,int> > arcs;
72.116 + arcs.push_back(std::make_pair(0,1));
72.117 + arcs.push_back(std::make_pair(0,2));
72.118 + arcs.push_back(std::make_pair(1,3));
72.119 + arcs.push_back(std::make_pair(1,2));
72.120 + arcs.push_back(std::make_pair(3,0));
72.121 + arcs.push_back(std::make_pair(3,3));
72.122 + arcs.push_back(std::make_pair(4,2));
72.123 + arcs.push_back(std::make_pair(4,3));
72.124 + arcs.push_back(std::make_pair(4,1));
72.125 +
72.126 + G.build(6, arcs.begin(), arcs.end());
72.127 +
72.128 + checkGraphNodeList(G, 6);
72.129 + checkGraphArcList(G, 9);
72.130 +
72.131 + checkGraphOutArcList(G, G.node(0), 2);
72.132 + checkGraphOutArcList(G, G.node(1), 2);
72.133 + checkGraphOutArcList(G, G.node(2), 0);
72.134 + checkGraphOutArcList(G, G.node(3), 2);
72.135 + checkGraphOutArcList(G, G.node(4), 3);
72.136 + checkGraphOutArcList(G, G.node(5), 0);
72.137 +
72.138 + checkGraphInArcList(G, G.node(0), 1);
72.139 + checkGraphInArcList(G, G.node(1), 2);
72.140 + checkGraphInArcList(G, G.node(2), 3);
72.141 + checkGraphInArcList(G, G.node(3), 3);
72.142 + checkGraphInArcList(G, G.node(4), 0);
72.143 + checkGraphInArcList(G, G.node(5), 0);
72.144 +
72.145 + checkGraphConArcList(G, 9);
72.146 +
72.147 + checkNodeIds(G);
72.148 + checkArcIds(G);
72.149 + checkGraphNodeMap(G);
72.150 + checkGraphArcMap(G);
72.151 +
72.152 + int n = G.nodeNum();
72.153 + int m = G.arcNum();
72.154 + check(G.index(G.node(n-1)) == n-1, "Wrong index.");
72.155 + check(G.index(G.arc(m-1)) == m-1, "Wrong index.");
72.156 +}
72.157 +
72.158 void checkFullDigraph(int num) {
72.159 typedef FullDigraph Digraph;
72.160 DIGRAPH_TYPEDEFS(Digraph);
72.161 +
72.162 Digraph G(num);
72.163 + check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
72.164 +
72.165 + G.resize(num);
72.166 + check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
72.167
72.168 checkGraphNodeList(G, num);
72.169 checkGraphArcList(G, num * num);
72.170 @@ -419,6 +547,9 @@
72.171 checkDigraphSnapshot<SmartDigraph>();
72.172 checkDigraphValidity<SmartDigraph>();
72.173 }
72.174 + { // Checking StaticDigraph
72.175 + checkStaticDigraph();
72.176 + }
72.177 { // Checking FullDigraph
72.178 checkFullDigraph(8);
72.179 }
73.1 --- a/test/graph_test.cc Sun Oct 04 10:15:32 2009 +0200
73.2 +++ b/test/graph_test.cc Wed Dec 09 11:14:06 2009 +0100
73.3 @@ -38,6 +38,9 @@
73.4 checkGraphEdgeList(G, 0);
73.5 checkGraphArcList(G, 0);
73.6
73.7 + G.reserveNode(3);
73.8 + G.reserveEdge(3);
73.9 +
73.10 Node
73.11 n1 = G.addNode(),
73.12 n2 = G.addNode(),
73.13 @@ -256,6 +259,15 @@
73.14 G.addEdge(G.addNode(), G.addNode());
73.15
73.16 snapshot.restore();
73.17 + snapshot.save(G);
73.18 +
73.19 + checkGraphNodeList(G, 4);
73.20 + checkGraphEdgeList(G, 3);
73.21 + checkGraphArcList(G, 6);
73.22 +
73.23 + G.addEdge(G.addNode(), G.addNode());
73.24 +
73.25 + snapshot.restore();
73.26
73.27 checkGraphNodeList(G, 4);
73.28 checkGraphEdgeList(G, 3);
73.29 @@ -267,6 +279,13 @@
73.30 GRAPH_TYPEDEFS(Graph);
73.31
73.32 Graph G(num);
73.33 + check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
73.34 + "Wrong size");
73.35 +
73.36 + G.resize(num);
73.37 + check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
73.38 + "Wrong size");
73.39 +
73.40 checkGraphNodeList(G, num);
73.41 checkGraphEdgeList(G, num * (num - 1) / 2);
73.42
73.43 @@ -411,6 +430,10 @@
73.44 check(G.width() == width, "Wrong column number");
73.45 check(G.height() == height, "Wrong row number");
73.46
73.47 + G.resize(width, height);
73.48 + check(G.width() == width, "Wrong column number");
73.49 + check(G.height() == height, "Wrong row number");
73.50 +
73.51 for (int i = 0; i < width; ++i) {
73.52 for (int j = 0; j < height; ++j) {
73.53 check(G.col(G(i, j)) == i, "Wrong column");
73.54 @@ -486,6 +509,11 @@
73.55 GRAPH_TYPEDEFS(HypercubeGraph);
73.56
73.57 HypercubeGraph G(dim);
73.58 + check(G.dimension() == dim, "Wrong dimension");
73.59 +
73.60 + G.resize(dim);
73.61 + check(G.dimension() == dim, "Wrong dimension");
73.62 +
73.63 checkGraphNodeList(G, 1 << dim);
73.64 checkGraphEdgeList(G, dim * (1 << (dim-1)));
73.65 checkGraphArcList(G, dim * (1 << dim));
74.1 --- a/test/maps_test.cc Sun Oct 04 10:15:32 2009 +0200
74.2 +++ b/test/maps_test.cc Wed Dec 09 11:14:06 2009 +0100
74.3 @@ -22,7 +22,11 @@
74.4 #include <lemon/concept_check.h>
74.5 #include <lemon/concepts/maps.h>
74.6 #include <lemon/maps.h>
74.7 +#include <lemon/list_graph.h>
74.8 #include <lemon/smart_graph.h>
74.9 +#include <lemon/adaptors.h>
74.10 +#include <lemon/dfs.h>
74.11 +#include <algorithm>
74.12
74.13 #include "test_tools.h"
74.14
74.15 @@ -34,9 +38,22 @@
74.16 struct B {};
74.17
74.18 class C {
74.19 - int x;
74.20 + int _x;
74.21 public:
74.22 - C(int _x) : x(_x) {}
74.23 + C(int x) : _x(x) {}
74.24 + int get() const { return _x; }
74.25 +};
74.26 +inline bool operator<(C c1, C c2) { return c1.get() < c2.get(); }
74.27 +inline bool operator==(C c1, C c2) { return c1.get() == c2.get(); }
74.28 +
74.29 +C createC(int x) { return C(x); }
74.30 +
74.31 +template <typename T>
74.32 +class Less {
74.33 + T _t;
74.34 +public:
74.35 + Less(T t): _t(t) {}
74.36 + bool operator()(const T& t) const { return t < _t; }
74.37 };
74.38
74.39 class F {
74.40 @@ -53,6 +70,14 @@
74.41
74.42 int binc(int a, B) { return a+1; }
74.43
74.44 +template <typename T>
74.45 +class Sum {
74.46 + T& _sum;
74.47 +public:
74.48 + Sum(T& sum) : _sum(sum) {}
74.49 + void operator()(const T& t) { _sum += t; }
74.50 +};
74.51 +
74.52 typedef ReadMap<A, double> DoubleMap;
74.53 typedef ReadWriteMap<A, double> DoubleWriteMap;
74.54 typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap;
74.55 @@ -329,6 +354,10 @@
74.56 // LoggerBoolMap
74.57 {
74.58 typedef std::vector<int> vec;
74.59 + checkConcept<WriteMap<int, bool>, LoggerBoolMap<vec::iterator> >();
74.60 + checkConcept<WriteMap<int, bool>,
74.61 + LoggerBoolMap<std::back_insert_iterator<vec> > >();
74.62 +
74.63 vec v1;
74.64 vec v2(10);
74.65 LoggerBoolMap<std::back_insert_iterator<vec> >
74.66 @@ -348,6 +377,223 @@
74.67 for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
74.68 it != map2.end(); ++it )
74.69 check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
74.70 +
74.71 + typedef ListDigraph Graph;
74.72 + DIGRAPH_TYPEDEFS(Graph);
74.73 + Graph gr;
74.74 +
74.75 + Node n0 = gr.addNode();
74.76 + Node n1 = gr.addNode();
74.77 + Node n2 = gr.addNode();
74.78 + Node n3 = gr.addNode();
74.79 +
74.80 + gr.addArc(n3, n0);
74.81 + gr.addArc(n3, n2);
74.82 + gr.addArc(n0, n2);
74.83 + gr.addArc(n2, n1);
74.84 + gr.addArc(n0, n1);
74.85 +
74.86 + {
74.87 + std::vector<Node> v;
74.88 + dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run();
74.89 +
74.90 + check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
74.91 + "Something is wrong with LoggerBoolMap");
74.92 + }
74.93 + {
74.94 + std::vector<Node> v(countNodes(gr));
74.95 + dfs(gr).processedMap(loggerBoolMap(v.begin())).run();
74.96 +
74.97 + check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
74.98 + "Something is wrong with LoggerBoolMap");
74.99 + }
74.100 + }
74.101 +
74.102 + // IdMap, RangeIdMap
74.103 + {
74.104 + typedef ListDigraph Graph;
74.105 + DIGRAPH_TYPEDEFS(Graph);
74.106 +
74.107 + checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >();
74.108 + checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >();
74.109 + checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >();
74.110 + checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >();
74.111 +
74.112 + Graph gr;
74.113 + IdMap<Graph, Node> nmap(gr);
74.114 + IdMap<Graph, Arc> amap(gr);
74.115 + RangeIdMap<Graph, Node> nrmap(gr);
74.116 + RangeIdMap<Graph, Arc> armap(gr);
74.117 +
74.118 + Node n0 = gr.addNode();
74.119 + Node n1 = gr.addNode();
74.120 + Node n2 = gr.addNode();
74.121 +
74.122 + Arc a0 = gr.addArc(n0, n1);
74.123 + Arc a1 = gr.addArc(n0, n2);
74.124 + Arc a2 = gr.addArc(n2, n1);
74.125 + Arc a3 = gr.addArc(n2, n0);
74.126 +
74.127 + check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap");
74.128 + check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap");
74.129 + check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap");
74.130 +
74.131 + check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap");
74.132 + check(amap[a1] == gr.id(a1) && amap(gr.id(a1)) == a1, "Wrong IdMap");
74.133 + check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap");
74.134 + check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap");
74.135 +
74.136 + check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap");
74.137 + check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap");
74.138 +
74.139 + check(nrmap.size() == 3 && armap.size() == 4,
74.140 + "Wrong RangeIdMap::size()");
74.141 +
74.142 + check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
74.143 + check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
74.144 + check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
74.145 +
74.146 + check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
74.147 + check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
74.148 + check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
74.149 + check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
74.150 +
74.151 + check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
74.152 + check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
74.153 +
74.154 + gr.erase(n1);
74.155 +
74.156 + if (nrmap[n0] == 1) nrmap.swap(n0, n2);
74.157 + nrmap.swap(n2, n0);
74.158 + if (armap[a1] == 1) armap.swap(a1, a3);
74.159 + armap.swap(a3, a1);
74.160 +
74.161 + check(nrmap.size() == 2 && armap.size() == 2,
74.162 + "Wrong RangeIdMap::size()");
74.163 +
74.164 + check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
74.165 + check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
74.166 +
74.167 + check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
74.168 + check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
74.169 +
74.170 + check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
74.171 + check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
74.172 + }
74.173 +
74.174 + // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
74.175 + {
74.176 + typedef ListGraph Graph;
74.177 + GRAPH_TYPEDEFS(Graph);
74.178 +
74.179 + checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
74.180 + checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
74.181 + checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
74.182 + checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
74.183 + checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
74.184 + checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >();
74.185 +
74.186 + Graph gr;
74.187 + Node n0 = gr.addNode();
74.188 + Node n1 = gr.addNode();
74.189 + Node n2 = gr.addNode();
74.190 +
74.191 + gr.addEdge(n0,n1);
74.192 + gr.addEdge(n1,n2);
74.193 + gr.addEdge(n0,n2);
74.194 + gr.addEdge(n2,n1);
74.195 + gr.addEdge(n1,n2);
74.196 + gr.addEdge(n0,n1);
74.197 +
74.198 + for (EdgeIt e(gr); e != INVALID; ++e) {
74.199 + check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
74.200 + check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
74.201 + }
74.202 +
74.203 + check(mapCompare(gr,
74.204 + sourceMap(orienter(gr, constMap<Edge, bool>(true))),
74.205 + targetMap(orienter(gr, constMap<Edge, bool>(false)))),
74.206 + "Wrong SourceMap or TargetMap");
74.207 +
74.208 + typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
74.209 + Digraph dgr(gr, constMap<Edge, bool>(true));
74.210 + OutDegMap<Digraph> odm(dgr);
74.211 + InDegMap<Digraph> idm(dgr);
74.212 +
74.213 + check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
74.214 + check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
74.215 +
74.216 + gr.addEdge(n2, n0);
74.217 +
74.218 + check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
74.219 + check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
74.220 + }
74.221 +
74.222 + // CrossRefMap
74.223 + {
74.224 + typedef ListDigraph Graph;
74.225 + DIGRAPH_TYPEDEFS(Graph);
74.226 +
74.227 + checkConcept<ReadWriteMap<Node, int>,
74.228 + CrossRefMap<Graph, Node, int> >();
74.229 + checkConcept<ReadWriteMap<Node, bool>,
74.230 + CrossRefMap<Graph, Node, bool> >();
74.231 + checkConcept<ReadWriteMap<Node, double>,
74.232 + CrossRefMap<Graph, Node, double> >();
74.233 +
74.234 + Graph gr;
74.235 + typedef CrossRefMap<Graph, Node, char> CRMap;
74.236 + CRMap map(gr);
74.237 +
74.238 + Node n0 = gr.addNode();
74.239 + Node n1 = gr.addNode();
74.240 + Node n2 = gr.addNode();
74.241 +
74.242 + map.set(n0, 'A');
74.243 + map.set(n1, 'B');
74.244 + map.set(n2, 'C');
74.245 +
74.246 + check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
74.247 + "Wrong CrossRefMap");
74.248 + check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
74.249 + "Wrong CrossRefMap");
74.250 + check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
74.251 + "Wrong CrossRefMap");
74.252 + check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
74.253 + "Wrong CrossRefMap::count()");
74.254 +
74.255 + CRMap::ValueIt it = map.beginValue();
74.256 + check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
74.257 + it == map.endValue(), "Wrong value iterator");
74.258 +
74.259 + map.set(n2, 'A');
74.260 +
74.261 + check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
74.262 + "Wrong CrossRefMap");
74.263 + check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
74.264 + check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
74.265 + check(map('C') == INVALID && map.inverse()['C'] == INVALID,
74.266 + "Wrong CrossRefMap");
74.267 + check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
74.268 + "Wrong CrossRefMap::count()");
74.269 +
74.270 + it = map.beginValue();
74.271 + check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' &&
74.272 + it == map.endValue(), "Wrong value iterator");
74.273 +
74.274 + map.set(n0, 'C');
74.275 +
74.276 + check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
74.277 + "Wrong CrossRefMap");
74.278 + check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
74.279 + check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
74.280 + check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
74.281 + check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
74.282 + "Wrong CrossRefMap::count()");
74.283 +
74.284 + it = map.beginValue();
74.285 + check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
74.286 + it == map.endValue(), "Wrong value iterator");
74.287 }
74.288
74.289 // CrossRefMap
74.290 @@ -546,10 +792,10 @@
74.291 check(static_cast<Item>(it) == INVALID, "Wrong value");
74.292 }
74.293
74.294 - for (Ivm::ValueIterator vit = map1.beginValue();
74.295 + for (Ivm::ValueIt vit = map1.beginValue();
74.296 vit != map1.endValue(); ++vit) {
74.297 check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit,
74.298 - "Wrong ValueIterator");
74.299 + "Wrong ValueIt");
74.300 }
74.301
74.302 for (int i = 0; i < num; ++i) {
74.303 @@ -571,5 +817,183 @@
74.304 check(n == num, "Wrong number");
74.305
74.306 }
74.307 +
74.308 + // Graph map utilities:
74.309 + // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
74.310 + // mapFind(), mapFindIf(), mapCount(), mapCountIf()
74.311 + // mapCopy(), mapCompare(), mapFill()
74.312 + {
74.313 + DIGRAPH_TYPEDEFS(SmartDigraph);
74.314 +
74.315 + SmartDigraph g;
74.316 + Node n1 = g.addNode();
74.317 + Node n2 = g.addNode();
74.318 + Node n3 = g.addNode();
74.319 +
74.320 + SmartDigraph::NodeMap<int> map1(g);
74.321 + SmartDigraph::ArcMap<char> map2(g);
74.322 + ConstMap<Node, A> cmap1 = A();
74.323 + ConstMap<Arc, C> cmap2 = C(0);
74.324 +
74.325 + map1[n1] = 10;
74.326 + map1[n2] = 5;
74.327 + map1[n3] = 12;
74.328 +
74.329 + // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
74.330 + check(mapMin(g, map1) == n2, "Wrong mapMin()");
74.331 + check(mapMax(g, map1) == n3, "Wrong mapMax()");
74.332 + check(mapMin(g, map1, std::greater<int>()) == n3, "Wrong mapMin()");
74.333 + check(mapMax(g, map1, std::greater<int>()) == n2, "Wrong mapMax()");
74.334 + check(mapMinValue(g, map1) == 5, "Wrong mapMinValue()");
74.335 + check(mapMaxValue(g, map1) == 12, "Wrong mapMaxValue()");
74.336 +
74.337 + check(mapMin(g, map2) == INVALID, "Wrong mapMin()");
74.338 + check(mapMax(g, map2) == INVALID, "Wrong mapMax()");
74.339 +
74.340 + check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()");
74.341 + check(mapMax(g, cmap2) == INVALID, "Wrong mapMax()");
74.342 +
74.343 + Arc a1 = g.addArc(n1, n2);
74.344 + Arc a2 = g.addArc(n1, n3);
74.345 + Arc a3 = g.addArc(n2, n3);
74.346 + Arc a4 = g.addArc(n3, n1);
74.347 +
74.348 + map2[a1] = 'b';
74.349 + map2[a2] = 'a';
74.350 + map2[a3] = 'b';
74.351 + map2[a4] = 'c';
74.352 +
74.353 + // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
74.354 + check(mapMin(g, map2) == a2, "Wrong mapMin()");
74.355 + check(mapMax(g, map2) == a4, "Wrong mapMax()");
74.356 + check(mapMin(g, map2, std::greater<int>()) == a4, "Wrong mapMin()");
74.357 + check(mapMax(g, map2, std::greater<int>()) == a2, "Wrong mapMax()");
74.358 + check(mapMinValue(g, map2, std::greater<int>()) == 'c',
74.359 + "Wrong mapMinValue()");
74.360 + check(mapMaxValue(g, map2, std::greater<int>()) == 'a',
74.361 + "Wrong mapMaxValue()");
74.362 +
74.363 + check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()");
74.364 + check(mapMax(g, cmap2) != INVALID, "Wrong mapMax()");
74.365 + check(mapMaxValue(g, cmap2) == C(0), "Wrong mapMaxValue()");
74.366 +
74.367 + check(mapMin(g, composeMap(functorToMap(&createC), map2)) == a2,
74.368 + "Wrong mapMin()");
74.369 + check(mapMax(g, composeMap(functorToMap(&createC), map2)) == a4,
74.370 + "Wrong mapMax()");
74.371 + check(mapMinValue(g, composeMap(functorToMap(&createC), map2)) == C('a'),
74.372 + "Wrong mapMinValue()");
74.373 + check(mapMaxValue(g, composeMap(functorToMap(&createC), map2)) == C('c'),
74.374 + "Wrong mapMaxValue()");
74.375 +
74.376 + // mapFind(), mapFindIf()
74.377 + check(mapFind(g, map1, 5) == n2, "Wrong mapFind()");
74.378 + check(mapFind(g, map1, 6) == INVALID, "Wrong mapFind()");
74.379 + check(mapFind(g, map2, 'a') == a2, "Wrong mapFind()");
74.380 + check(mapFind(g, map2, 'e') == INVALID, "Wrong mapFind()");
74.381 + check(mapFind(g, cmap2, C(0)) == ArcIt(g), "Wrong mapFind()");
74.382 + check(mapFind(g, cmap2, C(1)) == INVALID, "Wrong mapFind()");
74.383 +
74.384 + check(mapFindIf(g, map1, Less<int>(7)) == n2,
74.385 + "Wrong mapFindIf()");
74.386 + check(mapFindIf(g, map1, Less<int>(5)) == INVALID,
74.387 + "Wrong mapFindIf()");
74.388 + check(mapFindIf(g, map2, Less<char>('d')) == ArcIt(g),
74.389 + "Wrong mapFindIf()");
74.390 + check(mapFindIf(g, map2, Less<char>('a')) == INVALID,
74.391 + "Wrong mapFindIf()");
74.392 +
74.393 + // mapCount(), mapCountIf()
74.394 + check(mapCount(g, map1, 5) == 1, "Wrong mapCount()");
74.395 + check(mapCount(g, map1, 6) == 0, "Wrong mapCount()");
74.396 + check(mapCount(g, map2, 'a') == 1, "Wrong mapCount()");
74.397 + check(mapCount(g, map2, 'b') == 2, "Wrong mapCount()");
74.398 + check(mapCount(g, map2, 'e') == 0, "Wrong mapCount()");
74.399 + check(mapCount(g, cmap2, C(0)) == 4, "Wrong mapCount()");
74.400 + check(mapCount(g, cmap2, C(1)) == 0, "Wrong mapCount()");
74.401 +
74.402 + check(mapCountIf(g, map1, Less<int>(11)) == 2,
74.403 + "Wrong mapCountIf()");
74.404 + check(mapCountIf(g, map1, Less<int>(13)) == 3,
74.405 + "Wrong mapCountIf()");
74.406 + check(mapCountIf(g, map1, Less<int>(5)) == 0,
74.407 + "Wrong mapCountIf()");
74.408 + check(mapCountIf(g, map2, Less<char>('d')) == 4,
74.409 + "Wrong mapCountIf()");
74.410 + check(mapCountIf(g, map2, Less<char>('c')) == 3,
74.411 + "Wrong mapCountIf()");
74.412 + check(mapCountIf(g, map2, Less<char>('a')) == 0,
74.413 + "Wrong mapCountIf()");
74.414 +
74.415 + // MapIt, ConstMapIt
74.416 +/*
74.417 +These tests can be used after applying bugfix #330
74.418 + typedef SmartDigraph::NodeMap<int>::MapIt MapIt;
74.419 + typedef SmartDigraph::NodeMap<int>::ConstMapIt ConstMapIt;
74.420 + check(*std::min_element(MapIt(map1), MapIt(INVALID)) == 5,
74.421 + "Wrong NodeMap<>::MapIt");
74.422 + check(*std::max_element(ConstMapIt(map1), ConstMapIt(INVALID)) == 12,
74.423 + "Wrong NodeMap<>::MapIt");
74.424 +
74.425 + int sum = 0;
74.426 + std::for_each(MapIt(map1), MapIt(INVALID), Sum<int>(sum));
74.427 + check(sum == 27, "Wrong NodeMap<>::MapIt");
74.428 + std::for_each(ConstMapIt(map1), ConstMapIt(INVALID), Sum<int>(sum));
74.429 + check(sum == 54, "Wrong NodeMap<>::ConstMapIt");
74.430 +*/
74.431 +
74.432 + // mapCopy(), mapCompare(), mapFill()
74.433 + check(mapCompare(g, map1, map1), "Wrong mapCompare()");
74.434 + check(mapCompare(g, cmap2, cmap2), "Wrong mapCompare()");
74.435 + check(mapCompare(g, map1, shiftMap(map1, 0)), "Wrong mapCompare()");
74.436 + check(mapCompare(g, map2, scaleMap(map2, 1)), "Wrong mapCompare()");
74.437 + check(!mapCompare(g, map1, shiftMap(map1, 1)), "Wrong mapCompare()");
74.438 +
74.439 + SmartDigraph::NodeMap<int> map3(g, 0);
74.440 + SmartDigraph::ArcMap<char> map4(g, 'a');
74.441 +
74.442 + check(!mapCompare(g, map1, map3), "Wrong mapCompare()");
74.443 + check(!mapCompare(g, map2, map4), "Wrong mapCompare()");
74.444 +
74.445 + mapCopy(g, map1, map3);
74.446 + mapCopy(g, map2, map4);
74.447 +
74.448 + check(mapCompare(g, map1, map3), "Wrong mapCompare() or mapCopy()");
74.449 + check(mapCompare(g, map2, map4), "Wrong mapCompare() or mapCopy()");
74.450 +
74.451 + Undirector<SmartDigraph> ug(g);
74.452 + Undirector<SmartDigraph>::EdgeMap<char> umap1(ug, 'x');
74.453 + Undirector<SmartDigraph>::ArcMap<double> umap2(ug, 3.14);
74.454 +
74.455 + check(!mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
74.456 + check(!mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
74.457 + check(!mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
74.458 + check(!mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
74.459 +
74.460 + mapCopy(g, map2, umap1);
74.461 +
74.462 + check(mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
74.463 + check(mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
74.464 + check(mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
74.465 + check(mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
74.466 +
74.467 + mapCopy(g, map2, umap1);
74.468 + mapCopy(g, umap1, map2);
74.469 + mapCopy(ug, map2, umap1);
74.470 + mapCopy(ug, umap1, map2);
74.471 +
74.472 + check(!mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
74.473 + mapCopy(ug, umap1, umap2);
74.474 + check(mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
74.475 +
74.476 + check(!mapCompare(g, map1, constMap<Node>(2)), "Wrong mapCompare()");
74.477 + mapFill(g, map1, 2);
74.478 + check(mapCompare(g, constMap<Node>(2), map1), "Wrong mapFill()");
74.479 +
74.480 + check(!mapCompare(g, map2, constMap<Arc>('z')), "Wrong mapCompare()");
74.481 + mapCopy(g, constMap<Arc>('z'), map2);
74.482 + check(mapCompare(g, constMap<Arc>('z'), map2), "Wrong mapCopy()");
74.483 + }
74.484 +
74.485 return 0;
74.486 }
75.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
75.2 +++ b/test/min_mean_cycle_test.cc Wed Dec 09 11:14:06 2009 +0100
75.3 @@ -0,0 +1,216 @@
75.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
75.5 + *
75.6 + * This file is a part of LEMON, a generic C++ optimization library.
75.7 + *
75.8 + * Copyright (C) 2003-2009
75.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
75.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
75.11 + *
75.12 + * Permission to use, modify and distribute this software is granted
75.13 + * provided that this copyright notice appears in all copies. For
75.14 + * precise terms see the accompanying LICENSE file.
75.15 + *
75.16 + * This software is provided "AS IS" with no warranty of any kind,
75.17 + * express or implied, and with no claim as to its suitability for any
75.18 + * purpose.
75.19 + *
75.20 + */
75.21 +
75.22 +#include <iostream>
75.23 +#include <sstream>
75.24 +
75.25 +#include <lemon/smart_graph.h>
75.26 +#include <lemon/lgf_reader.h>
75.27 +#include <lemon/path.h>
75.28 +#include <lemon/concepts/digraph.h>
75.29 +#include <lemon/concept_check.h>
75.30 +
75.31 +#include <lemon/karp.h>
75.32 +#include <lemon/hartmann_orlin.h>
75.33 +#include <lemon/howard.h>
75.34 +
75.35 +#include "test_tools.h"
75.36 +
75.37 +using namespace lemon;
75.38 +
75.39 +char test_lgf[] =
75.40 + "@nodes\n"
75.41 + "label\n"
75.42 + "1\n"
75.43 + "2\n"
75.44 + "3\n"
75.45 + "4\n"
75.46 + "5\n"
75.47 + "6\n"
75.48 + "7\n"
75.49 + "@arcs\n"
75.50 + " len1 len2 len3 len4 c1 c2 c3 c4\n"
75.51 + "1 2 1 1 1 1 0 0 0 0\n"
75.52 + "2 4 5 5 5 5 1 0 0 0\n"
75.53 + "2 3 8 8 8 8 0 0 0 0\n"
75.54 + "3 2 -2 0 0 0 1 0 0 0\n"
75.55 + "3 4 4 4 4 4 0 0 0 0\n"
75.56 + "3 7 -4 -4 -4 -4 0 0 0 0\n"
75.57 + "4 1 2 2 2 2 0 0 0 0\n"
75.58 + "4 3 3 3 3 3 1 0 0 0\n"
75.59 + "4 4 3 3 0 0 0 0 1 0\n"
75.60 + "5 2 4 4 4 4 0 0 0 0\n"
75.61 + "5 6 3 3 3 3 0 1 0 0\n"
75.62 + "6 5 2 2 2 2 0 1 0 0\n"
75.63 + "6 4 -1 -1 -1 -1 0 0 0 0\n"
75.64 + "6 7 1 1 1 1 0 0 0 0\n"
75.65 + "7 7 4 4 4 -1 0 0 0 1\n";
75.66 +
75.67 +
75.68 +// Check the interface of an MMC algorithm
75.69 +template <typename GR, typename Value>
75.70 +struct MmcClassConcept
75.71 +{
75.72 + template <typename MMC>
75.73 + struct Constraints {
75.74 + void constraints() {
75.75 + const Constraints& me = *this;
75.76 +
75.77 + typedef typename MMC
75.78 + ::template SetPath<ListPath<GR> >
75.79 + ::template SetLargeValue<Value>
75.80 + ::Create MmcAlg;
75.81 + MmcAlg mmc(me.g, me.length);
75.82 + const MmcAlg& const_mmc = mmc;
75.83 +
75.84 + typename MmcAlg::Tolerance tol = const_mmc.tolerance();
75.85 + mmc.tolerance(tol);
75.86 +
75.87 + b = mmc.cycle(p).run();
75.88 + b = mmc.findMinMean();
75.89 + b = mmc.findCycle();
75.90 +
75.91 + v = const_mmc.cycleLength();
75.92 + i = const_mmc.cycleArcNum();
75.93 + d = const_mmc.cycleMean();
75.94 + p = const_mmc.cycle();
75.95 + }
75.96 +
75.97 + typedef concepts::ReadMap<typename GR::Arc, Value> LM;
75.98 +
75.99 + GR g;
75.100 + LM length;
75.101 + ListPath<GR> p;
75.102 + Value v;
75.103 + int i;
75.104 + double d;
75.105 + bool b;
75.106 + };
75.107 +};
75.108 +
75.109 +// Perform a test with the given parameters
75.110 +template <typename MMC>
75.111 +void checkMmcAlg(const SmartDigraph& gr,
75.112 + const SmartDigraph::ArcMap<int>& lm,
75.113 + const SmartDigraph::ArcMap<int>& cm,
75.114 + int length, int size) {
75.115 + MMC alg(gr, lm);
75.116 + alg.findMinMean();
75.117 + check(alg.cycleMean() == static_cast<double>(length) / size,
75.118 + "Wrong cycle mean");
75.119 + alg.findCycle();
75.120 + check(alg.cycleLength() == length && alg.cycleArcNum() == size,
75.121 + "Wrong path");
75.122 + SmartDigraph::ArcMap<int> cycle(gr, 0);
75.123 + for (typename MMC::Path::ArcIt a(alg.cycle()); a != INVALID; ++a) {
75.124 + ++cycle[a];
75.125 + }
75.126 + for (SmartDigraph::ArcIt a(gr); a != INVALID; ++a) {
75.127 + check(cm[a] == cycle[a], "Wrong path");
75.128 + }
75.129 +}
75.130 +
75.131 +// Class for comparing types
75.132 +template <typename T1, typename T2>
75.133 +struct IsSameType {
75.134 + static const int result = 0;
75.135 +};
75.136 +
75.137 +template <typename T>
75.138 +struct IsSameType<T,T> {
75.139 + static const int result = 1;
75.140 +};
75.141 +
75.142 +
75.143 +int main() {
75.144 + #ifdef LEMON_HAVE_LONG_LONG
75.145 + typedef long long long_int;
75.146 + #else
75.147 + typedef long long_int;
75.148 + #endif
75.149 +
75.150 + // Check the interface
75.151 + {
75.152 + typedef concepts::Digraph GR;
75.153 +
75.154 + // Karp
75.155 + checkConcept< MmcClassConcept<GR, int>,
75.156 + Karp<GR, concepts::ReadMap<GR::Arc, int> > >();
75.157 + checkConcept< MmcClassConcept<GR, float>,
75.158 + Karp<GR, concepts::ReadMap<GR::Arc, float> > >();
75.159 +
75.160 + // HartmannOrlin
75.161 + checkConcept< MmcClassConcept<GR, int>,
75.162 + HartmannOrlin<GR, concepts::ReadMap<GR::Arc, int> > >();
75.163 + checkConcept< MmcClassConcept<GR, float>,
75.164 + HartmannOrlin<GR, concepts::ReadMap<GR::Arc, float> > >();
75.165 +
75.166 + // Howard
75.167 + checkConcept< MmcClassConcept<GR, int>,
75.168 + Howard<GR, concepts::ReadMap<GR::Arc, int> > >();
75.169 + checkConcept< MmcClassConcept<GR, float>,
75.170 + Howard<GR, concepts::ReadMap<GR::Arc, float> > >();
75.171 +
75.172 + if (IsSameType<Howard<GR, concepts::ReadMap<GR::Arc, int> >::LargeValue,
75.173 + long_int>::result == 0) check(false, "Wrong LargeValue type");
75.174 + if (IsSameType<Howard<GR, concepts::ReadMap<GR::Arc, float> >::LargeValue,
75.175 + double>::result == 0) check(false, "Wrong LargeValue type");
75.176 + }
75.177 +
75.178 + // Run various tests
75.179 + {
75.180 + typedef SmartDigraph GR;
75.181 + DIGRAPH_TYPEDEFS(GR);
75.182 +
75.183 + GR gr;
75.184 + IntArcMap l1(gr), l2(gr), l3(gr), l4(gr);
75.185 + IntArcMap c1(gr), c2(gr), c3(gr), c4(gr);
75.186 +
75.187 + std::istringstream input(test_lgf);
75.188 + digraphReader(gr, input).
75.189 + arcMap("len1", l1).
75.190 + arcMap("len2", l2).
75.191 + arcMap("len3", l3).
75.192 + arcMap("len4", l4).
75.193 + arcMap("c1", c1).
75.194 + arcMap("c2", c2).
75.195 + arcMap("c3", c3).
75.196 + arcMap("c4", c4).
75.197 + run();
75.198 +
75.199 + // Karp
75.200 + checkMmcAlg<Karp<GR, IntArcMap> >(gr, l1, c1, 6, 3);
75.201 + checkMmcAlg<Karp<GR, IntArcMap> >(gr, l2, c2, 5, 2);
75.202 + checkMmcAlg<Karp<GR, IntArcMap> >(gr, l3, c3, 0, 1);
75.203 + checkMmcAlg<Karp<GR, IntArcMap> >(gr, l4, c4, -1, 1);
75.204 +
75.205 + // HartmannOrlin
75.206 + checkMmcAlg<HartmannOrlin<GR, IntArcMap> >(gr, l1, c1, 6, 3);
75.207 + checkMmcAlg<HartmannOrlin<GR, IntArcMap> >(gr, l2, c2, 5, 2);
75.208 + checkMmcAlg<HartmannOrlin<GR, IntArcMap> >(gr, l3, c3, 0, 1);
75.209 + checkMmcAlg<HartmannOrlin<GR, IntArcMap> >(gr, l4, c4, -1, 1);
75.210 +
75.211 + // Howard
75.212 + checkMmcAlg<Howard<GR, IntArcMap> >(gr, l1, c1, 6, 3);
75.213 + checkMmcAlg<Howard<GR, IntArcMap> >(gr, l2, c2, 5, 2);
75.214 + checkMmcAlg<Howard<GR, IntArcMap> >(gr, l3, c3, 0, 1);
75.215 + checkMmcAlg<Howard<GR, IntArcMap> >(gr, l4, c4, -1, 1);
75.216 + }
75.217 +
75.218 + return 0;
75.219 +}
76.1 --- a/test/mip_test.cc Sun Oct 04 10:15:32 2009 +0200
76.2 +++ b/test/mip_test.cc Wed Dec 09 11:14:06 2009 +0100
76.3 @@ -50,7 +50,8 @@
76.4
76.5 if (stat == MipSolver::OPTIMAL) {
76.6 std::ostringstream sbuf;
76.7 - buf << "Wrong optimal value: the right optimum is " << exp_opt;
76.8 + sbuf << "Wrong optimal value ("<< mip.solValue()
76.9 + <<" instead of " << exp_opt << ")";
76.10 check(std::abs(mip.solValue()-exp_opt) < 1e-3, sbuf.str());
76.11 //+ecvt(exp_opt,2)
76.12 }
77.1 --- a/test/test_tools.h Sun Oct 04 10:15:32 2009 +0200
77.2 +++ b/test/test_tools.h Wed Dec 09 11:14:06 2009 +0100
77.3 @@ -37,10 +37,14 @@
77.4 ///\code check(0==1,"This is obviously false.");\endcode will
77.5 ///print something like this (and then exits).
77.6 ///\verbatim file_name.cc:123: error: This is obviously false. \endverbatim
77.7 -#define check(rc, msg) \
77.8 - if(!(rc)) { \
77.9 - std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
77.10 - abort(); \
77.11 - } else { } \
77.12 +#define check(rc, msg) \
77.13 + { \
77.14 + if(!(rc)) { \
77.15 + std::cerr << __FILE__ ":" << __LINE__ << ": error: " \
77.16 + << msg << std::endl; \
77.17 + abort(); \
77.18 + } else { } \
77.19 + } \
77.20 +
77.21
77.22 #endif