Merge #68 (Port static graph implementation)
authorAlpar Juttner <alpar@cs.elte.hu>
Thu, 05 Nov 2009 10:23:16 +0100 (2009-11-05)
changeset 780580af8cf2f6a
parent 779 c160bf9f18ef
parent 772 f964a00b9068
child 782 ceb2756dea2a
Merge #68 (Port static graph implementation)
lemon/Makefile.am
lemon/full_graph.h
lemon/hypercube_graph.h
lemon/smart_graph.h
test/digraph_test.cc
     1.1 --- a/CMakeLists.txt	Thu Nov 05 10:01:02 2009 +0100
     1.2 +++ b/CMakeLists.txt	Thu Nov 05 10:23:16 2009 +0100
     1.3 @@ -35,6 +35,8 @@
     1.4  CHECK_TYPE_SIZE("long long" LONG_LONG)
     1.5  SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
     1.6  
     1.7 +INCLUDE(FindPythonInterp)
     1.8 +
     1.9  ENABLE_TESTING()
    1.10  
    1.11  ADD_SUBDIRECTORY(lemon)
     2.1 --- a/Makefile.am	Thu Nov 05 10:01:02 2009 +0100
     2.2 +++ b/Makefile.am	Thu Nov 05 10:23:16 2009 +0100
     2.3 @@ -17,6 +17,7 @@
     2.4  	cmake/FindCPLEX.cmake \
     2.5  	cmake/FindGLPK.cmake \
     2.6  	cmake/FindCOIN.cmake \
     2.7 +	cmake/LEMONConfig.cmake.in \
     2.8  	cmake/version.cmake.in \
     2.9  	cmake/version.cmake \
    2.10  	cmake/nsis/lemon.ico \
     3.1 --- a/configure.ac	Thu Nov 05 10:01:02 2009 +0100
     3.2 +++ b/configure.ac	Thu Nov 05 10:23:16 2009 +0100
     3.3 @@ -41,6 +41,7 @@
     3.4  AC_PROG_LIBTOOL
     3.5  
     3.6  AC_CHECK_PROG([doxygen_found],[doxygen],[yes],[no])
     3.7 +AC_CHECK_PROG([python_found],[python],[yes],[no])
     3.8  AC_CHECK_PROG([gs_found],[gs],[yes],[no])
     3.9  
    3.10  dnl Detect Intel compiler.
     4.1 --- a/doc/CMakeLists.txt	Thu Nov 05 10:01:02 2009 +0100
     4.2 +++ b/doc/CMakeLists.txt	Thu Nov 05 10:23:16 2009 +0100
     4.3 @@ -9,7 +9,7 @@
     4.4    @ONLY
     4.5  )
     4.6  
     4.7 -IF(DOXYGEN_EXECUTABLE AND GHOSTSCRIPT_EXECUTABLE)
     4.8 +IF(DOXYGEN_EXECUTABLE AND PYTHONINTERP_FOUND AND GHOSTSCRIPT_EXECUTABLE)
     4.9    FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/)
    4.10    SET(GHOSTSCRIPT_OPTIONS -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha)
    4.11    ADD_CUSTOM_TARGET(html
    4.12 @@ -28,6 +28,7 @@
    4.13      COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_4.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_4.eps
    4.14      COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/strongly_connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/strongly_connected_components.eps
    4.15      COMMAND ${CMAKE_COMMAND} -E remove_directory html
    4.16 +    COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/bib2dox.py ${CMAKE_CURRENT_SOURCE_DIR}/references.bib >references.dox
    4.17      COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile
    4.18      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    4.19    )
     5.1 --- a/doc/Doxyfile.in	Thu Nov 05 10:01:02 2009 +0100
     5.2 +++ b/doc/Doxyfile.in	Thu Nov 05 10:23:16 2009 +0100
     5.3 @@ -1,4 +1,4 @@
     5.4 -# Doxyfile 1.5.7.1
     5.5 +# Doxyfile 1.5.9
     5.6  
     5.7  #---------------------------------------------------------------------------
     5.8  # Project related configuration options
     5.9 @@ -21,7 +21,6 @@
    5.10  JAVADOC_AUTOBRIEF      = NO
    5.11  QT_AUTOBRIEF           = NO
    5.12  MULTILINE_CPP_IS_BRIEF = NO
    5.13 -DETAILS_AT_TOP         = YES
    5.14  INHERIT_DOCS           = NO
    5.15  SEPARATE_MEMBER_PAGES  = NO
    5.16  TAB_SIZE               = 8
    5.17 @@ -91,7 +90,8 @@
    5.18                           "@abs_top_srcdir@/lemon/concepts" \
    5.19                           "@abs_top_srcdir@/demo" \
    5.20                           "@abs_top_srcdir@/tools" \
    5.21 -                         "@abs_top_srcdir@/test/test_tools.h"
    5.22 +                         "@abs_top_srcdir@/test/test_tools.h" \
    5.23 +                         "@abs_top_builddir@/doc/references.dox"
    5.24  INPUT_ENCODING         = UTF-8
    5.25  FILE_PATTERNS          = *.h \
    5.26                           *.cc \
    5.27 @@ -223,7 +223,7 @@
    5.28  EXPAND_AS_DEFINED      = 
    5.29  SKIP_FUNCTION_MACROS   = YES
    5.30  #---------------------------------------------------------------------------
    5.31 -# Configuration::additions related to external references   
    5.32 +# Options related to the search engine   
    5.33  #---------------------------------------------------------------------------
    5.34  TAGFILES               = "@abs_top_srcdir@/doc/libstdc++.tag = http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/  "
    5.35  GENERATE_TAGFILE       = html/lemon.tag
     6.1 --- a/doc/Makefile.am	Thu Nov 05 10:01:02 2009 +0100
     6.2 +++ b/doc/Makefile.am	Thu Nov 05 10:23:16 2009 +0100
     6.3 @@ -66,7 +66,19 @@
     6.4  	  exit 1; \
     6.5  	fi
     6.6  
     6.7 -html-local: $(DOC_PNG_IMAGES)
     6.8 +references.dox: doc/references.bib
     6.9 +	if test ${python_found} = yes; then \
    6.10 +	  cd doc; \
    6.11 +	  python @abs_top_srcdir@/scripts/bib2dox.py @abs_top_builddir@/$< >$@; \
    6.12 +	  cd ..; \
    6.13 +	else \
    6.14 +	  echo; \
    6.15 +	  echo "Python not found."; \
    6.16 +	  echo; \
    6.17 +	  exit 1; \
    6.18 +	fi
    6.19 +
    6.20 +html-local: $(DOC_PNG_IMAGES) references.dox
    6.21  	if test ${doxygen_found} = yes; then \
    6.22  	  cd doc; \
    6.23  	  doxygen Doxyfile; \
     7.1 --- a/doc/groups.dox	Thu Nov 05 10:01:02 2009 +0100
     7.2 +++ b/doc/groups.dox	Thu Nov 05 10:23:16 2009 +0100
     7.3 @@ -226,14 +226,6 @@
     7.4  */
     7.5  
     7.6  /**
     7.7 -@defgroup matrices Matrices
     7.8 -@ingroup datas
     7.9 -\brief Two dimensional data storages implemented in LEMON.
    7.10 -
    7.11 -This group contains two dimensional data storages implemented in LEMON.
    7.12 -*/
    7.13 -
    7.14 -/**
    7.15  @defgroup paths Path Structures
    7.16  @ingroup datas
    7.17  \brief %Path structures implemented in LEMON.
    7.18 @@ -246,7 +238,36 @@
    7.19  efficient to have e.g. the Dijkstra algorithm to store its result in
    7.20  any kind of path structure.
    7.21  
    7.22 -\sa lemon::concepts::Path
    7.23 +\sa \ref concepts::Path "Path concept"
    7.24 +*/
    7.25 +
    7.26 +/**
    7.27 +@defgroup heaps Heap Structures
    7.28 +@ingroup datas
    7.29 +\brief %Heap structures implemented in LEMON.
    7.30 +
    7.31 +This group contains the heap structures implemented in LEMON.
    7.32 +
    7.33 +LEMON provides several heap classes. They are efficient implementations
    7.34 +of the abstract data type \e priority \e queue. They store items with
    7.35 +specified values called \e priorities in such a way that finding and
    7.36 +removing the item with minimum priority are efficient.
    7.37 +The basic operations are adding and erasing items, changing the priority
    7.38 +of an item, etc.
    7.39 +
    7.40 +Heaps are crucial in several algorithms, such as Dijkstra and Prim.
    7.41 +The heap implementations have the same interface, thus any of them can be
    7.42 +used easily in such algorithms.
    7.43 +
    7.44 +\sa \ref concepts::Heap "Heap concept"
    7.45 +*/
    7.46 +
    7.47 +/**
    7.48 +@defgroup matrices Matrices
    7.49 +@ingroup datas
    7.50 +\brief Two dimensional data storages implemented in LEMON.
    7.51 +
    7.52 +This group contains two dimensional data storages implemented in LEMON.
    7.53  */
    7.54  
    7.55  /**
    7.56 @@ -259,6 +280,28 @@
    7.57  */
    7.58  
    7.59  /**
    7.60 +@defgroup geomdat Geometric Data Structures
    7.61 +@ingroup auxdat
    7.62 +\brief Geometric data structures implemented in LEMON.
    7.63 +
    7.64 +This group contains geometric data structures implemented in LEMON.
    7.65 +
    7.66 + - \ref lemon::dim2::Point "dim2::Point" implements a two dimensional
    7.67 +   vector with the usual operations.
    7.68 + - \ref lemon::dim2::Box "dim2::Box" can be used to determine the
    7.69 +   rectangular bounding box of a set of \ref lemon::dim2::Point
    7.70 +   "dim2::Point"'s.
    7.71 +*/
    7.72 +
    7.73 +/**
    7.74 +@defgroup matrices Matrices
    7.75 +@ingroup auxdat
    7.76 +\brief Two dimensional data storages implemented in LEMON.
    7.77 +
    7.78 +This group contains two dimensional data storages implemented in LEMON.
    7.79 +*/
    7.80 +
    7.81 +/**
    7.82  @defgroup algs Algorithms
    7.83  \brief This group contains the several algorithms
    7.84  implemented in LEMON.
    7.85 @@ -273,7 +316,8 @@
    7.86  \brief Common graph search algorithms.
    7.87  
    7.88  This group contains the common graph search algorithms, namely
    7.89 -\e breadth-first \e search (BFS) and \e depth-first \e search (DFS).
    7.90 +\e breadth-first \e search (BFS) and \e depth-first \e search (DFS)
    7.91 +\ref clrs01algorithms.
    7.92  */
    7.93  
    7.94  /**
    7.95 @@ -281,7 +325,8 @@
    7.96  @ingroup algs
    7.97  \brief Algorithms for finding shortest paths.
    7.98  
    7.99 -This group contains the algorithms for finding shortest paths in digraphs.
   7.100 +This group contains the algorithms for finding shortest paths in digraphs
   7.101 +\ref clrs01algorithms.
   7.102  
   7.103   - \ref Dijkstra algorithm for finding shortest paths from a source node
   7.104     when all arc lengths are non-negative.
   7.105 @@ -298,12 +343,21 @@
   7.106  */
   7.107  
   7.108  /**
   7.109 +@defgroup spantree Minimum Spanning Tree Algorithms
   7.110 +@ingroup algs
   7.111 +\brief Algorithms for finding minimum cost spanning trees and arborescences.
   7.112 +
   7.113 +This group contains the algorithms for finding minimum cost spanning
   7.114 +trees and arborescences \ref clrs01algorithms.
   7.115 +*/
   7.116 +
   7.117 +/**
   7.118  @defgroup max_flow Maximum Flow Algorithms
   7.119  @ingroup algs
   7.120  \brief Algorithms for finding maximum flows.
   7.121  
   7.122  This group contains the algorithms for finding maximum flows and
   7.123 -feasible circulations.
   7.124 +feasible circulations \ref clrs01algorithms, \ref amo93networkflows.
   7.125  
   7.126  The \e maximum \e flow \e problem is to find a flow of maximum value between
   7.127  a single source and a single target. Formally, there is a \f$G=(V,A)\f$
   7.128 @@ -318,12 +372,16 @@
   7.129  \f[ 0 \leq f(uv) \leq cap(uv) \quad \forall uv\in A \f]
   7.130  
   7.131  LEMON contains several algorithms for solving maximum flow problems:
   7.132 -- \ref EdmondsKarp Edmonds-Karp algorithm.
   7.133 -- \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm.
   7.134 -- \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees.
   7.135 -- \ref GoldbergTarjan Preflow push-relabel algorithm with dynamic trees.
   7.136 +- \ref EdmondsKarp Edmonds-Karp algorithm
   7.137 +  \ref edmondskarp72theoretical.
   7.138 +- \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm
   7.139 +  \ref goldberg88newapproach.
   7.140 +- \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees
   7.141 +  \ref dinic70algorithm, \ref sleator83dynamic.
   7.142 +- \ref GoldbergTarjan !Preflow push-relabel algorithm with dynamic trees
   7.143 +  \ref goldberg88newapproach, \ref sleator83dynamic.
   7.144  
   7.145 -In most cases the \ref Preflow "Preflow" algorithm provides the
   7.146 +In most cases the \ref Preflow algorithm provides the
   7.147  fastest method for computing a maximum flow. All implementations
   7.148  also provide functions to query the minimum cut, which is the dual
   7.149  problem of maximum flow.
   7.150 @@ -341,18 +399,22 @@
   7.151  \brief Algorithms for finding minimum cost flows and circulations.
   7.152  
   7.153  This group contains the algorithms for finding minimum cost flows and
   7.154 -circulations. For more information about this problem and its dual
   7.155 -solution see \ref min_cost_flow "Minimum Cost Flow Problem".
   7.156 +circulations \ref amo93networkflows. For more information about this
   7.157 +problem and its dual solution, see \ref min_cost_flow
   7.158 +"Minimum Cost Flow Problem".
   7.159  
   7.160  LEMON contains several algorithms for this problem.
   7.161   - \ref NetworkSimplex Primal Network Simplex algorithm with various
   7.162 -   pivot strategies.
   7.163 +   pivot strategies \ref dantzig63linearprog, \ref kellyoneill91netsimplex.
   7.164   - \ref CostScaling Push-Relabel and Augment-Relabel algorithms based on
   7.165 -   cost scaling.
   7.166 +   cost scaling \ref goldberg90approximation, \ref goldberg97efficient,
   7.167 +   \ref bunnagel98efficient.
   7.168   - \ref CapacityScaling Successive Shortest %Path algorithm with optional
   7.169 -   capacity scaling.
   7.170 - - \ref CancelAndTighten The Cancel and Tighten algorithm.
   7.171 - - \ref CycleCanceling Cycle-Canceling algorithms.
   7.172 +   capacity scaling \ref edmondskarp72theoretical.
   7.173 + - \ref CancelAndTighten The Cancel and Tighten algorithm
   7.174 +   \ref goldberg89cyclecanceling.
   7.175 + - \ref CycleCanceling Cycle-Canceling algorithms
   7.176 +   \ref klein67primal, \ref goldberg89cyclecanceling.
   7.177  
   7.178  In general NetworkSimplex is the most efficient implementation,
   7.179  but in special cases other algorithms could be faster.
   7.180 @@ -375,7 +437,7 @@
   7.181  cut is the \f$X\f$ solution of the next optimization problem:
   7.182  
   7.183  \f[ \min_{X \subset V, X\not\in \{\emptyset, V\}}
   7.184 -    \sum_{uv\in A, u\in X, v\not\in X}cap(uv) \f]
   7.185 +    \sum_{uv\in A: u\in X, v\not\in X}cap(uv) \f]
   7.186  
   7.187  LEMON contains several algorithms related to minimum cut problems:
   7.188  
   7.189 @@ -391,27 +453,40 @@
   7.190  */
   7.191  
   7.192  /**
   7.193 -@defgroup graph_properties Connectivity and Other Graph Properties
   7.194 +@defgroup min_mean_cycle Minimum Mean Cycle Algorithms
   7.195  @ingroup algs
   7.196 -\brief Algorithms for discovering the graph properties
   7.197 +\brief Algorithms for finding minimum mean cycles.
   7.198  
   7.199 -This group contains the algorithms for discovering the graph properties
   7.200 -like connectivity, bipartiteness, euler property, simplicity etc.
   7.201 +This group contains the algorithms for finding minimum mean cycles
   7.202 +\ref clrs01algorithms, \ref amo93networkflows.
   7.203  
   7.204 -\image html edge_biconnected_components.png
   7.205 -\image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth
   7.206 -*/
   7.207 +The \e minimum \e mean \e cycle \e problem is to find a directed cycle
   7.208 +of minimum mean length (cost) in a digraph.
   7.209 +The mean length of a cycle is the average length of its arcs, i.e. the
   7.210 +ratio between the total length of the cycle and the number of arcs on it.
   7.211  
   7.212 -/**
   7.213 -@defgroup planar Planarity Embedding and Drawing
   7.214 -@ingroup algs
   7.215 -\brief Algorithms for planarity checking, embedding and drawing
   7.216 +This problem has an important connection to \e conservative \e length
   7.217 +\e functions, too. A length function on the arcs of a digraph is called
   7.218 +conservative if and only if there is no directed cycle of negative total
   7.219 +length. For an arbitrary length function, the negative of the minimum
   7.220 +cycle mean is the smallest \f$\epsilon\f$ value so that increasing the
   7.221 +arc lengths uniformly by \f$\epsilon\f$ results in a conservative length
   7.222 +function.
   7.223  
   7.224 -This group contains the algorithms for planarity checking,
   7.225 -embedding and drawing.
   7.226 +LEMON contains three algorithms for solving the minimum mean cycle problem:
   7.227 +- \ref Karp "Karp"'s original algorithm \ref amo93networkflows,
   7.228 +  \ref dasdan98minmeancycle.
   7.229 +- \ref HartmannOrlin "Hartmann-Orlin"'s algorithm, which is an improved
   7.230 +  version of Karp's algorithm \ref dasdan98minmeancycle.
   7.231 +- \ref Howard "Howard"'s policy iteration algorithm
   7.232 +  \ref dasdan98minmeancycle.
   7.233  
   7.234 -\image html planar.png
   7.235 -\image latex planar.eps "Plane graph" width=\textwidth
   7.236 +In practice, the Howard algorithm proved to be by far the most efficient
   7.237 +one, though the best known theoretical bound on its running time is
   7.238 +exponential.
   7.239 +Both Karp and HartmannOrlin algorithms run in time O(ne) and use space
   7.240 +O(n<sup>2</sup>+e), but the latter one is typically faster due to the
   7.241 +applied early termination scheme.
   7.242  */
   7.243  
   7.244  /**
   7.245 @@ -455,12 +530,36 @@
   7.246  */
   7.247  
   7.248  /**
   7.249 -@defgroup spantree Minimum Spanning Tree Algorithms
   7.250 +@defgroup graph_properties Connectivity and Other Graph Properties
   7.251  @ingroup algs
   7.252 -\brief Algorithms for finding minimum cost spanning trees and arborescences.
   7.253 +\brief Algorithms for discovering the graph properties
   7.254  
   7.255 -This group contains the algorithms for finding minimum cost spanning
   7.256 -trees and arborescences.
   7.257 +This group contains the algorithms for discovering the graph properties
   7.258 +like connectivity, bipartiteness, euler property, simplicity etc.
   7.259 +
   7.260 +\image html connected_components.png
   7.261 +\image latex connected_components.eps "Connected components" width=\textwidth
   7.262 +*/
   7.263 +
   7.264 +/**
   7.265 +@defgroup planar Planarity Embedding and Drawing
   7.266 +@ingroup algs
   7.267 +\brief Algorithms for planarity checking, embedding and drawing
   7.268 +
   7.269 +This group contains the algorithms for planarity checking,
   7.270 +embedding and drawing.
   7.271 +
   7.272 +\image html planar.png
   7.273 +\image latex planar.eps "Plane graph" width=\textwidth
   7.274 +*/
   7.275 +
   7.276 +/**
   7.277 +@defgroup approx Approximation Algorithms
   7.278 +@ingroup algs
   7.279 +\brief Approximation algorithms.
   7.280 +
   7.281 +This group contains the approximation and heuristic algorithms
   7.282 +implemented in LEMON.
   7.283  */
   7.284  
   7.285  /**
   7.286 @@ -473,15 +572,6 @@
   7.287  */
   7.288  
   7.289  /**
   7.290 -@defgroup approx Approximation Algorithms
   7.291 -@ingroup algs
   7.292 -\brief Approximation algorithms.
   7.293 -
   7.294 -This group contains the approximation and heuristic algorithms
   7.295 -implemented in LEMON.
   7.296 -*/
   7.297 -
   7.298 -/**
   7.299  @defgroup gen_opt_group General Optimization Tools
   7.300  \brief This group contains some general optimization frameworks
   7.301  implemented in LEMON.
   7.302 @@ -491,13 +581,16 @@
   7.303  */
   7.304  
   7.305  /**
   7.306 -@defgroup lp_group Lp and Mip Solvers
   7.307 +@defgroup lp_group LP and MIP Solvers
   7.308  @ingroup gen_opt_group
   7.309 -\brief Lp and Mip solver interfaces for LEMON.
   7.310 +\brief LP and MIP solver interfaces for LEMON.
   7.311  
   7.312 -This group contains Lp and Mip solver interfaces for LEMON. The
   7.313 -various LP solvers could be used in the same manner with this
   7.314 -interface.
   7.315 +This group contains LP and MIP solver interfaces for LEMON.
   7.316 +Various LP solvers could be used in the same manner with this
   7.317 +high-level interface.
   7.318 +
   7.319 +The currently supported solvers are \ref glpk, \ref clp, \ref cbc,
   7.320 +\ref cplex, \ref soplex.
   7.321  */
   7.322  
   7.323  /**
   7.324 @@ -587,7 +680,7 @@
   7.325  */
   7.326  
   7.327  /**
   7.328 -@defgroup dimacs_group DIMACS format
   7.329 +@defgroup dimacs_group DIMACS Format
   7.330  @ingroup io_group
   7.331  \brief Read and write files in DIMACS format
   7.332  
   7.333 @@ -636,8 +729,8 @@
   7.334  @ingroup concept
   7.335  \brief Skeleton and concept checking classes for graph structures
   7.336  
   7.337 -This group contains the skeletons and concept checking classes of LEMON's
   7.338 -graph structures and helper classes used to implement these.
   7.339 +This group contains the skeletons and concept checking classes of
   7.340 +graph structures.
   7.341  */
   7.342  
   7.343  /**
   7.344 @@ -649,6 +742,15 @@
   7.345  */
   7.346  
   7.347  /**
   7.348 +@defgroup tools Standalone Utility Applications
   7.349 +
   7.350 +Some utility applications are listed here.
   7.351 +
   7.352 +The standard compilation procedure (<tt>./configure;make</tt>) will compile
   7.353 +them, as well.
   7.354 +*/
   7.355 +
   7.356 +/**
   7.357  \anchor demoprograms
   7.358  
   7.359  @defgroup demos Demo Programs
   7.360 @@ -660,13 +762,4 @@
   7.361  <tt>make check</tt> commands.
   7.362  */
   7.363  
   7.364 -/**
   7.365 -@defgroup tools Standalone Utility Applications
   7.366 -
   7.367 -Some utility applications are listed here.
   7.368 -
   7.369 -The standard compilation procedure (<tt>./configure;make</tt>) will compile
   7.370 -them, as well.
   7.371 -*/
   7.372 -
   7.373  }
     8.1 --- a/doc/mainpage.dox	Thu Nov 05 10:01:02 2009 +0100
     8.2 +++ b/doc/mainpage.dox	Thu Nov 05 10:23:16 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&nbsp;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&aacute;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&ouml;tv&ouml;s Lor&aacute;nd University,
    8.33 +Budapest</a>, Hungary.
    8.34 +LEMON is also a member of the <a href="http://www.coin-or.org/">COIN-OR</a>
    8.35 +initiative \ref coinor.
    8.36 +
    8.37 +\section howtoread How to Read the Documentation
    8.38  
    8.39  If you would like to get to know the library, see
    8.40  <a class="el" href="http://lemon.cs.elte.hu/pub/tutorial/">LEMON Tutorial</a>.
     9.1 --- a/doc/min_cost_flow.dox	Thu Nov 05 10:01:02 2009 +0100
     9.2 +++ b/doc/min_cost_flow.dox	Thu Nov 05 10:23:16 2009 +0100
     9.3 @@ -26,7 +26,7 @@
     9.4  The \e minimum \e cost \e flow \e problem is to find a feasible flow of
     9.5  minimum total cost from a set of supply nodes to a set of demand nodes
     9.6  in a network with capacity constraints (lower and upper bounds)
     9.7 -and arc costs.
     9.8 +and arc costs \ref amo93networkflows.
     9.9  
    9.10  Formally, let \f$G=(V,A)\f$ be a digraph, \f$lower: A\rightarrow\mathbf{R}\f$,
    9.11  \f$upper: A\rightarrow\mathbf{R}\cup\{+\infty\}\f$ denote the lower and
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/doc/references.bib	Thu Nov 05 10:23:16 2009 +0100
    10.3 @@ -0,0 +1,301 @@
    10.4 +%%%%% Defining LEMON %%%%%
    10.5 +
    10.6 +@misc{lemon,
    10.7 +  key =          {LEMON},
    10.8 +  title =        {{LEMON} -- {L}ibrary for {E}fficient {M}odeling and
    10.9 +                  {O}ptimization in {N}etworks},
   10.10 +  howpublished = {\url{http://lemon.cs.elte.hu/}},
   10.11 +  year =         2009
   10.12 +}
   10.13 +
   10.14 +@misc{egres,
   10.15 +  key =          {EGRES},
   10.16 +  title =        {{EGRES} -- {E}gerv{\'a}ry {R}esearch {G}roup on
   10.17 +                  {C}ombinatorial {O}ptimization},
   10.18 +  url =          {http://www.cs.elte.hu/egres/}
   10.19 +}
   10.20 +
   10.21 +@misc{coinor,
   10.22 +  key =          {COIN-OR},
   10.23 +  title =        {{COIN-OR} -- {C}omputational {I}nfrastructure for
   10.24 +                  {O}perations {R}esearch},
   10.25 +  url =          {http://www.coin-or.org/}
   10.26 +}
   10.27 +
   10.28 +
   10.29 +%%%%% Other libraries %%%%%%
   10.30 +
   10.31 +@misc{boost,
   10.32 +  key =          {Boost},
   10.33 +  title =        {{B}oost {C++} {L}ibraries},
   10.34 +  url =          {http://www.boost.org/}
   10.35 +}
   10.36 +
   10.37 +@book{bglbook,
   10.38 +  author =       {Jeremy G. Siek and Lee-Quan Lee and Andrew
   10.39 +                  Lumsdaine},
   10.40 +  title =        {The Boost Graph Library: User Guide and Reference
   10.41 +                  Manual},
   10.42 +  publisher =    {Addison-Wesley},
   10.43 +  year =         2002
   10.44 +}
   10.45 +
   10.46 +@misc{leda,
   10.47 +  key =          {LEDA},
   10.48 +  title =        {{LEDA} -- {L}ibrary of {E}fficient {D}ata {T}ypes and
   10.49 +                  {A}lgorithms},
   10.50 +  url =          {http://www.algorithmic-solutions.com/}
   10.51 +}
   10.52 +
   10.53 +@book{ledabook,
   10.54 +  author =       {Kurt Mehlhorn and Stefan N{\"a}her},
   10.55 +  title =        {{LEDA}: {A} platform for combinatorial and geometric
   10.56 +                  computing},
   10.57 +  isbn =         {0-521-56329-1},
   10.58 +  publisher =    {Cambridge University Press},
   10.59 +  address =      {New York, NY, USA},
   10.60 +  year =         1999
   10.61 +}
   10.62 +
   10.63 +
   10.64 +%%%%% Tools that LEMON depends on %%%%%
   10.65 +
   10.66 +@misc{cmake,
   10.67 +  key =          {CMake},
   10.68 +  title =        {{CMake} -- {C}ross {P}latform {M}ake},
   10.69 +  url =          {http://www.cmake.org/}
   10.70 +}
   10.71 +
   10.72 +@misc{doxygen,
   10.73 +  key =          {Doxygen},
   10.74 +  title =        {{Doxygen} -- {S}ource code documentation generator
   10.75 +                  tool},
   10.76 +  url =          {http://www.doxygen.org/}
   10.77 +}
   10.78 +
   10.79 +
   10.80 +%%%%% LP/MIP libraries %%%%%
   10.81 +
   10.82 +@misc{glpk,
   10.83 +  key =          {GLPK},
   10.84 +  title =        {{GLPK} -- {GNU} {L}inear {P}rogramming {K}it},
   10.85 +  url =          {http://www.gnu.org/software/glpk/}
   10.86 +}
   10.87 +
   10.88 +@misc{clp,
   10.89 +  key =          {Clp},
   10.90 +  title =        {{Clp} -- {Coin-Or} {L}inear {P}rogramming},
   10.91 +  url =          {http://projects.coin-or.org/Clp/}
   10.92 +}
   10.93 +
   10.94 +@misc{cbc,
   10.95 +  key =          {Cbc},
   10.96 +  title =        {{Cbc} -- {Coin-Or} {B}ranch and {C}ut},
   10.97 +  url =          {http://projects.coin-or.org/Cbc/}
   10.98 +}
   10.99 +
  10.100 +@misc{cplex,
  10.101 +  key =          {CPLEX},
  10.102 +  title =        {{ILOG} {CPLEX}},
  10.103 +  url =          {http://www.ilog.com/}
  10.104 +}
  10.105 +
  10.106 +@misc{soplex,
  10.107 +  key =          {SoPlex},
  10.108 +  title =        {{SoPlex} -- {T}he {S}equential {O}bject-{O}riented
  10.109 +                  {S}implex},
  10.110 +  url =          {http://soplex.zib.de/}
  10.111 +}
  10.112 +
  10.113 +
  10.114 +%%%%% General books %%%%%
  10.115 +
  10.116 +@book{amo93networkflows,
  10.117 +  author =       {Ravindra K. Ahuja and Thomas L. Magnanti and James
  10.118 +                  B. Orlin},
  10.119 +  title =        {Network Flows: Theory, Algorithms, and Applications},
  10.120 +  publisher =    {Prentice-Hall, Inc.},
  10.121 +  year =         1993,
  10.122 +  month =        feb,
  10.123 +  isbn =         {978-0136175490}
  10.124 +}
  10.125 +
  10.126 +@book{schrijver03combinatorial,
  10.127 +  author =       {Alexander Schrijver},
  10.128 +  title =        {Combinatorial Optimization: Polyhedra and Efficiency},
  10.129 +  publisher =    {Springer-Verlag},
  10.130 +  year =         2003,
  10.131 +  isbn =         {978-3540443896}
  10.132 +}
  10.133 +
  10.134 +@book{clrs01algorithms,
  10.135 +  author =       {Thomas H. Cormen and Charles E. Leiserson and Ronald
  10.136 +                  L. Rivest and Clifford Stein},
  10.137 +  title =        {Introduction to Algorithms},
  10.138 +  publisher =    {The MIT Press},
  10.139 +  year =         2001,
  10.140 +  edition =      {2nd}
  10.141 +}
  10.142 +
  10.143 +@book{stroustrup00cpp,
  10.144 +  author =       {Bjarne Stroustrup},
  10.145 +  title =        {The C++ Programming Language},
  10.146 +  edition =      {3rd},
  10.147 +  publisher =    {Addison-Wesley Professional},
  10.148 +  isbn =         0201700735,
  10.149 +  month =        {February},
  10.150 +  year =         2000
  10.151 +}
  10.152 +
  10.153 +
  10.154 +%%%%% Maximum flow algorithms %%%%%
  10.155 +
  10.156 +@article{edmondskarp72theoretical,
  10.157 +  author =       {Jack Edmonds and Richard M. Karp},
  10.158 +  title =        {Theoretical improvements in algorithmic efficiency
  10.159 +                  for network flow problems},
  10.160 +  journal =      {Journal of the ACM},
  10.161 +  year =         1972,
  10.162 +  volume =       19,
  10.163 +  number =       2,
  10.164 +  pages =        {248-264}
  10.165 +}
  10.166 +
  10.167 +@article{goldberg88newapproach,
  10.168 +  author =       {Andrew V. Goldberg and Robert E. Tarjan},
  10.169 +  title =        {A new approach to the maximum flow problem},
  10.170 +  journal =      {Journal of the ACM},
  10.171 +  year =         1988,
  10.172 +  volume =       35,
  10.173 +  number =       4,
  10.174 +  pages =        {921-940}
  10.175 +}
  10.176 +
  10.177 +@article{dinic70algorithm,
  10.178 +  author =       {E. A. Dinic},
  10.179 +  title =        {Algorithm for solution of a problem of maximum flow
  10.180 +                  in a network with power estimation},
  10.181 +  journal =      {Soviet Math. Doklady},
  10.182 +  year =         1970,
  10.183 +  volume =       11,
  10.184 +  pages =        {1277-1280}
  10.185 +}
  10.186 +
  10.187 +@article{goldberg08partial,
  10.188 +  author =       {Andrew V. Goldberg},
  10.189 +  title =        {The Partial Augment-Relabel Algorithm for the
  10.190 +                  Maximum Flow Problem},
  10.191 +  journal =      {16th Annual European Symposium on Algorithms},
  10.192 +  year =         2008,
  10.193 +  pages =        {466-477}
  10.194 +}
  10.195 +
  10.196 +@article{sleator83dynamic,
  10.197 +  author =       {Daniel D. Sleator and Robert E. Tarjan},
  10.198 +  title =        {A data structure for dynamic trees},
  10.199 +  journal =      {Journal of Computer and System Sciences},
  10.200 +  year =         1983,
  10.201 +  volume =       26,
  10.202 +  number =       3,
  10.203 +  pages =        {362-391}
  10.204 +}
  10.205 +
  10.206 +
  10.207 +%%%%% Minimum mean cycle algorithms %%%%%
  10.208 +
  10.209 +@article{karp78characterization,
  10.210 +  author =       {Richard M. Karp},
  10.211 +  title =        {A characterization of the minimum cycle mean in a
  10.212 +                  digraph},
  10.213 +  journal =      {Discrete Math.},
  10.214 +  year =         1978,
  10.215 +  volume =       23,
  10.216 +  pages =        {309-311}
  10.217 +}
  10.218 +
  10.219 +@article{dasdan98minmeancycle,
  10.220 +  author =       {Ali Dasdan and Rajesh K. Gupta},
  10.221 +  title =        {Faster Maximum and Minimum Mean Cycle Alogrithms for
  10.222 +                  System Performance Analysis},
  10.223 +  journal =      {IEEE Transactions on Computer-Aided Design of
  10.224 +                  Integrated Circuits and Systems},
  10.225 +  year =         1998,
  10.226 +  volume =       17,
  10.227 +  number =       10,
  10.228 +  pages =        {889-899}
  10.229 +}
  10.230 +
  10.231 +
  10.232 +%%%%% Minimum cost flow algorithms %%%%%
  10.233 +
  10.234 +@article{klein67primal,
  10.235 +  author =       {Morton Klein},
  10.236 +  title =        {A primal method for minimal cost flows with
  10.237 +                  applications to the assignment and transportation
  10.238 +                  problems},
  10.239 +  journal =      {Management Science},
  10.240 +  year =         1967,
  10.241 +  volume =       14,
  10.242 +  pages =        {205-220}
  10.243 +}
  10.244 +
  10.245 +@article{goldberg89cyclecanceling,
  10.246 +  author =       {Andrew V. Goldberg and Robert E. Tarjan},
  10.247 +  title =        {Finding minimum-cost circulations by canceling
  10.248 +                  negative cycles},
  10.249 +  journal =      {Journal of the ACM},
  10.250 +  year =         1989,
  10.251 +  volume =       36,
  10.252 +  number =       4,
  10.253 +  pages =        {873-886}
  10.254 +}
  10.255 +
  10.256 +@article{goldberg90approximation,
  10.257 +  author =       {Andrew V. Goldberg and Robert E. Tarjan},
  10.258 +  title =        {Finding Minimum-Cost Circulations by Successive
  10.259 +                  Approximation},
  10.260 +  journal =      {Mathematics of Operations Research},
  10.261 +  year =         1990,
  10.262 +  volume =       15,
  10.263 +  number =       3,
  10.264 +  pages =        {430-466}
  10.265 +}
  10.266 +
  10.267 +@article{goldberg97efficient,
  10.268 +  author =       {Andrew V. Goldberg},
  10.269 +  title =        {An Efficient Implementation of a Scaling
  10.270 +                  Minimum-Cost Flow Algorithm},
  10.271 +  journal =      {Journal of Algorithms},
  10.272 +  year =         1997,
  10.273 +  volume =       22,
  10.274 +  number =       1,
  10.275 +  pages =        {1-29}
  10.276 +}
  10.277 +
  10.278 +@article{bunnagel98efficient,
  10.279 +  author =       {Ursula B{\"u}nnagel and Bernhard Korte and Jens
  10.280 +                  Vygen},
  10.281 +  title =        {Efficient implementation of the {G}oldberg-{T}arjan
  10.282 +                  minimum-cost flow algorithm},
  10.283 +  journal =      {Optimization Methods and Software},
  10.284 +  year =         1998,
  10.285 +  volume =       10,
  10.286 +  pages =        {157-174}
  10.287 +}
  10.288 +
  10.289 +@book{dantzig63linearprog,
  10.290 +  author =       {George B. Dantzig},
  10.291 +  title =        {Linear Programming and Extensions},
  10.292 +  publisher =    {Princeton University Press},
  10.293 +  year =         1963
  10.294 +}
  10.295 +
  10.296 +@mastersthesis{kellyoneill91netsimplex,
  10.297 +  author =       {Damian J. Kelly and Garrett M. O'Neill},
  10.298 +  title =        {The Minimum Cost Flow Problem and The Network
  10.299 +                  Simplex Method},
  10.300 +  school =       {University College},
  10.301 +  address =      {Dublin, Ireland},
  10.302 +  year =         1991,
  10.303 +  month =        sep,
  10.304 +}
    11.1 --- a/lemon/Makefile.am	Thu Nov 05 10:01:02 2009 +0100
    11.2 +++ b/lemon/Makefile.am	Thu Nov 05 10:23:16 2009 +0100
    11.3 @@ -57,8 +57,10 @@
    11.4  	lemon/adaptors.h \
    11.5  	lemon/arg_parser.h \
    11.6  	lemon/assert.h \
    11.7 +	lemon/bellman_ford.h \
    11.8  	lemon/bfs.h \
    11.9  	lemon/bin_heap.h \
   11.10 +	lemon/binom_heap.h \
   11.11  	lemon/bucket_heap.h \
   11.12  	lemon/cbc.h \
   11.13  	lemon/circulation.h \
   11.14 @@ -78,12 +80,17 @@
   11.15  	lemon/error.h \
   11.16  	lemon/euler.h \
   11.17  	lemon/fib_heap.h \
   11.18 +	lemon/fourary_heap.h \
   11.19  	lemon/full_graph.h \
   11.20  	lemon/glpk.h \
   11.21  	lemon/gomory_hu.h \
   11.22  	lemon/graph_to_eps.h \
   11.23  	lemon/grid_graph.h \
   11.24 +	lemon/hartmann_orlin.h \
   11.25 +	lemon/howard.h \
   11.26  	lemon/hypercube_graph.h \
   11.27 +	lemon/karp.h \
   11.28 +	lemon/kary_heap.h \
   11.29  	lemon/kruskal.h \
   11.30  	lemon/hao_orlin.h \
   11.31  	lemon/lgf_reader.h \
   11.32 @@ -98,6 +105,7 @@
   11.33  	lemon/min_cost_arborescence.h \
   11.34  	lemon/nauty_reader.h \
   11.35  	lemon/network_simplex.h \
   11.36 +	lemon/pairing_heap.h \
   11.37  	lemon/path.h \
   11.38  	lemon/preflow.h \
   11.39  	lemon/radix_heap.h \
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/lemon/bellman_ford.h	Thu Nov 05 10:23:16 2009 +0100
    12.3 @@ -0,0 +1,1100 @@
    12.4 +/* -*- C++ -*-
    12.5 + *
    12.6 + * This file is a part of LEMON, a generic C++ optimization library
    12.7 + *
    12.8 + * Copyright (C) 2003-2008
    12.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   12.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
   12.11 + *
   12.12 + * Permission to use, modify and distribute this software is granted
   12.13 + * provided that this copyright notice appears in all copies. For
   12.14 + * precise terms see the accompanying LICENSE file.
   12.15 + *
   12.16 + * This software is provided "AS IS" with no warranty of any kind,
   12.17 + * express or implied, and with no claim as to its suitability for any
   12.18 + * purpose.
   12.19 + *
   12.20 + */
   12.21 +
   12.22 +#ifndef LEMON_BELLMAN_FORD_H
   12.23 +#define LEMON_BELLMAN_FORD_H
   12.24 +
   12.25 +/// \ingroup shortest_path
   12.26 +/// \file
   12.27 +/// \brief Bellman-Ford algorithm.
   12.28 +
   12.29 +#include <lemon/bits/path_dump.h>
   12.30 +#include <lemon/core.h>
   12.31 +#include <lemon/error.h>
   12.32 +#include <lemon/maps.h>
   12.33 +#include <lemon/path.h>
   12.34 +
   12.35 +#include <limits>
   12.36 +
   12.37 +namespace lemon {
   12.38 +
   12.39 +  /// \brief Default OperationTraits for the BellmanFord algorithm class.
   12.40 +  ///  
   12.41 +  /// This operation traits class defines all computational operations
   12.42 +  /// and constants that are used in the Bellman-Ford algorithm.
   12.43 +  /// The default implementation is based on the \c numeric_limits class.
   12.44 +  /// If the numeric type does not have infinity value, then the maximum
   12.45 +  /// value is used as extremal infinity value.
   12.46 +  template <
   12.47 +    typename V, 
   12.48 +    bool has_inf = std::numeric_limits<V>::has_infinity>
   12.49 +  struct BellmanFordDefaultOperationTraits {
   12.50 +    /// \e
   12.51 +    typedef V Value;
   12.52 +    /// \brief Gives back the zero value of the type.
   12.53 +    static Value zero() {
   12.54 +      return static_cast<Value>(0);
   12.55 +    }
   12.56 +    /// \brief Gives back the positive infinity value of the type.
   12.57 +    static Value infinity() {
   12.58 +      return std::numeric_limits<Value>::infinity();
   12.59 +    }
   12.60 +    /// \brief Gives back the sum of the given two elements.
   12.61 +    static Value plus(const Value& left, const Value& right) {
   12.62 +      return left + right;
   12.63 +    }
   12.64 +    /// \brief Gives back \c true only if the first value is less than
   12.65 +    /// the second.
   12.66 +    static bool less(const Value& left, const Value& right) {
   12.67 +      return left < right;
   12.68 +    }
   12.69 +  };
   12.70 +
   12.71 +  template <typename V>
   12.72 +  struct BellmanFordDefaultOperationTraits<V, false> {
   12.73 +    typedef V Value;
   12.74 +    static Value zero() {
   12.75 +      return static_cast<Value>(0);
   12.76 +    }
   12.77 +    static Value infinity() {
   12.78 +      return std::numeric_limits<Value>::max();
   12.79 +    }
   12.80 +    static Value plus(const Value& left, const Value& right) {
   12.81 +      if (left == infinity() || right == infinity()) return infinity();
   12.82 +      return left + right;
   12.83 +    }
   12.84 +    static bool less(const Value& left, const Value& right) {
   12.85 +      return left < right;
   12.86 +    }
   12.87 +  };
   12.88 +  
   12.89 +  /// \brief Default traits class of BellmanFord class.
   12.90 +  ///
   12.91 +  /// Default traits class of BellmanFord class.
   12.92 +  /// \param GR The type of the digraph.
   12.93 +  /// \param LEN The type of the length map.
   12.94 +  template<typename GR, typename LEN>
   12.95 +  struct BellmanFordDefaultTraits {
   12.96 +    /// The type of the digraph the algorithm runs on. 
   12.97 +    typedef GR Digraph;
   12.98 +
   12.99 +    /// \brief The type of the map that stores the arc lengths.
  12.100 +    ///
  12.101 +    /// The type of the map that stores the arc lengths.
  12.102 +    /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
  12.103 +    typedef LEN LengthMap;
  12.104 +
  12.105 +    /// The type of the arc lengths.
  12.106 +    typedef typename LEN::Value Value;
  12.107 +
  12.108 +    /// \brief Operation traits for Bellman-Ford algorithm.
  12.109 +    ///
  12.110 +    /// It defines the used operations and the infinity value for the
  12.111 +    /// given \c Value type.
  12.112 +    /// \see BellmanFordDefaultOperationTraits
  12.113 +    typedef BellmanFordDefaultOperationTraits<Value> OperationTraits;
  12.114 + 
  12.115 +    /// \brief The type of the map that stores the last arcs of the 
  12.116 +    /// shortest paths.
  12.117 +    /// 
  12.118 +    /// The type of the map that stores the last
  12.119 +    /// arcs of the shortest paths.
  12.120 +    /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  12.121 +    typedef typename GR::template NodeMap<typename GR::Arc> PredMap;
  12.122 +
  12.123 +    /// \brief Instantiates a \c PredMap.
  12.124 +    /// 
  12.125 +    /// This function instantiates a \ref PredMap. 
  12.126 +    /// \param g is the digraph to which we would like to define the
  12.127 +    /// \ref PredMap.
  12.128 +    static PredMap *createPredMap(const GR& g) {
  12.129 +      return new PredMap(g);
  12.130 +    }
  12.131 +
  12.132 +    /// \brief The type of the map that stores the distances of the nodes.
  12.133 +    ///
  12.134 +    /// The type of the map that stores the distances of the nodes.
  12.135 +    /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  12.136 +    typedef typename GR::template NodeMap<typename LEN::Value> DistMap;
  12.137 +
  12.138 +    /// \brief Instantiates a \c DistMap.
  12.139 +    ///
  12.140 +    /// This function instantiates a \ref DistMap. 
  12.141 +    /// \param g is the digraph to which we would like to define the 
  12.142 +    /// \ref DistMap.
  12.143 +    static DistMap *createDistMap(const GR& g) {
  12.144 +      return new DistMap(g);
  12.145 +    }
  12.146 +
  12.147 +  };
  12.148 +  
  12.149 +  /// \brief %BellmanFord algorithm class.
  12.150 +  ///
  12.151 +  /// \ingroup shortest_path
  12.152 +  /// This class provides an efficient implementation of the Bellman-Ford 
  12.153 +  /// algorithm. The maximum time complexity of the algorithm is
  12.154 +  /// <tt>O(ne)</tt>.
  12.155 +  ///
  12.156 +  /// The Bellman-Ford algorithm solves the single-source shortest path
  12.157 +  /// problem when the arcs can have negative lengths, but the digraph
  12.158 +  /// should not contain directed cycles with negative total length.
  12.159 +  /// If all arc costs are non-negative, consider to use the Dijkstra
  12.160 +  /// algorithm instead, since it is more efficient.
  12.161 +  ///
  12.162 +  /// The arc lengths are passed to the algorithm using a
  12.163 +  /// \ref concepts::ReadMap "ReadMap", so it is easy to change it to any 
  12.164 +  /// kind of length. The type of the length values is determined by the
  12.165 +  /// \ref concepts::ReadMap::Value "Value" type of the length map.
  12.166 +  ///
  12.167 +  /// There is also a \ref bellmanFord() "function-type interface" for the
  12.168 +  /// Bellman-Ford algorithm, which is convenient in the simplier cases and
  12.169 +  /// it can be used easier.
  12.170 +  ///
  12.171 +  /// \tparam GR The type of the digraph the algorithm runs on.
  12.172 +  /// The default type is \ref ListDigraph.
  12.173 +  /// \tparam LEN A \ref concepts::ReadMap "readable" arc map that specifies
  12.174 +  /// the lengths of the arcs. The default map type is
  12.175 +  /// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
  12.176 +#ifdef DOXYGEN
  12.177 +  template <typename GR, typename LEN, typename TR>
  12.178 +#else
  12.179 +  template <typename GR=ListDigraph,
  12.180 +            typename LEN=typename GR::template ArcMap<int>,
  12.181 +            typename TR=BellmanFordDefaultTraits<GR,LEN> >
  12.182 +#endif
  12.183 +  class BellmanFord {
  12.184 +  public:
  12.185 +
  12.186 +    ///The type of the underlying digraph.
  12.187 +    typedef typename TR::Digraph Digraph;
  12.188 +    
  12.189 +    /// \brief The type of the arc lengths.
  12.190 +    typedef typename TR::LengthMap::Value Value;
  12.191 +    /// \brief The type of the map that stores the arc lengths.
  12.192 +    typedef typename TR::LengthMap LengthMap;
  12.193 +    /// \brief The type of the map that stores the last
  12.194 +    /// arcs of the shortest paths.
  12.195 +    typedef typename TR::PredMap PredMap;
  12.196 +    /// \brief The type of the map that stores the distances of the nodes.
  12.197 +    typedef typename TR::DistMap DistMap;
  12.198 +    /// The type of the paths.
  12.199 +    typedef PredMapPath<Digraph, PredMap> Path;
  12.200 +    ///\brief The \ref BellmanFordDefaultOperationTraits
  12.201 +    /// "operation traits class" of the algorithm.
  12.202 +    typedef typename TR::OperationTraits OperationTraits;
  12.203 +
  12.204 +    ///The \ref BellmanFordDefaultTraits "traits class" of the algorithm.
  12.205 +    typedef TR Traits;
  12.206 +
  12.207 +  private:
  12.208 +
  12.209 +    typedef typename Digraph::Node Node;
  12.210 +    typedef typename Digraph::NodeIt NodeIt;
  12.211 +    typedef typename Digraph::Arc Arc;
  12.212 +    typedef typename Digraph::OutArcIt OutArcIt;
  12.213 +
  12.214 +    // Pointer to the underlying digraph.
  12.215 +    const Digraph *_gr;
  12.216 +    // Pointer to the length map
  12.217 +    const LengthMap *_length;
  12.218 +    // Pointer to the map of predecessors arcs.
  12.219 +    PredMap *_pred;
  12.220 +    // Indicates if _pred is locally allocated (true) or not.
  12.221 +    bool _local_pred;
  12.222 +    // Pointer to the map of distances.
  12.223 +    DistMap *_dist;
  12.224 +    // Indicates if _dist is locally allocated (true) or not.
  12.225 +    bool _local_dist;
  12.226 +
  12.227 +    typedef typename Digraph::template NodeMap<bool> MaskMap;
  12.228 +    MaskMap *_mask;
  12.229 +
  12.230 +    std::vector<Node> _process;
  12.231 +
  12.232 +    // Creates the maps if necessary.
  12.233 +    void create_maps() {
  12.234 +      if(!_pred) {
  12.235 +	_local_pred = true;
  12.236 +	_pred = Traits::createPredMap(*_gr);
  12.237 +      }
  12.238 +      if(!_dist) {
  12.239 +	_local_dist = true;
  12.240 +	_dist = Traits::createDistMap(*_gr);
  12.241 +      }
  12.242 +      _mask = new MaskMap(*_gr, false);
  12.243 +    }
  12.244 +    
  12.245 +  public :
  12.246 + 
  12.247 +    typedef BellmanFord Create;
  12.248 +
  12.249 +    /// \name Named Template Parameters
  12.250 +
  12.251 +    ///@{
  12.252 +
  12.253 +    template <class T>
  12.254 +    struct SetPredMapTraits : public Traits {
  12.255 +      typedef T PredMap;
  12.256 +      static PredMap *createPredMap(const Digraph&) {
  12.257 +        LEMON_ASSERT(false, "PredMap is not initialized");
  12.258 +        return 0; // ignore warnings
  12.259 +      }
  12.260 +    };
  12.261 +
  12.262 +    /// \brief \ref named-templ-param "Named parameter" for setting
  12.263 +    /// \c PredMap type.
  12.264 +    ///
  12.265 +    /// \ref named-templ-param "Named parameter" for setting
  12.266 +    /// \c PredMap type.
  12.267 +    /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  12.268 +    template <class T>
  12.269 +    struct SetPredMap 
  12.270 +      : public BellmanFord< Digraph, LengthMap, SetPredMapTraits<T> > {
  12.271 +      typedef BellmanFord< Digraph, LengthMap, SetPredMapTraits<T> > Create;
  12.272 +    };
  12.273 +    
  12.274 +    template <class T>
  12.275 +    struct SetDistMapTraits : public Traits {
  12.276 +      typedef T DistMap;
  12.277 +      static DistMap *createDistMap(const Digraph&) {
  12.278 +        LEMON_ASSERT(false, "DistMap is not initialized");
  12.279 +        return 0; // ignore warnings
  12.280 +      }
  12.281 +    };
  12.282 +
  12.283 +    /// \brief \ref named-templ-param "Named parameter" for setting
  12.284 +    /// \c DistMap type.
  12.285 +    ///
  12.286 +    /// \ref named-templ-param "Named parameter" for setting
  12.287 +    /// \c DistMap type.
  12.288 +    /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  12.289 +    template <class T>
  12.290 +    struct SetDistMap 
  12.291 +      : public BellmanFord< Digraph, LengthMap, SetDistMapTraits<T> > {
  12.292 +      typedef BellmanFord< Digraph, LengthMap, SetDistMapTraits<T> > Create;
  12.293 +    };
  12.294 +
  12.295 +    template <class T>
  12.296 +    struct SetOperationTraitsTraits : public Traits {
  12.297 +      typedef T OperationTraits;
  12.298 +    };
  12.299 +    
  12.300 +    /// \brief \ref named-templ-param "Named parameter" for setting 
  12.301 +    /// \c OperationTraits type.
  12.302 +    ///
  12.303 +    /// \ref named-templ-param "Named parameter" for setting
  12.304 +    /// \c OperationTraits type.
  12.305 +    /// For more information see \ref BellmanFordDefaultOperationTraits.
  12.306 +    template <class T>
  12.307 +    struct SetOperationTraits
  12.308 +      : public BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> > {
  12.309 +      typedef BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> >
  12.310 +      Create;
  12.311 +    };
  12.312 +    
  12.313 +    ///@}
  12.314 +
  12.315 +  protected:
  12.316 +    
  12.317 +    BellmanFord() {}
  12.318 +
  12.319 +  public:      
  12.320 +    
  12.321 +    /// \brief Constructor.
  12.322 +    ///
  12.323 +    /// Constructor.
  12.324 +    /// \param g The digraph the algorithm runs on.
  12.325 +    /// \param length The length map used by the algorithm.
  12.326 +    BellmanFord(const Digraph& g, const LengthMap& length) :
  12.327 +      _gr(&g), _length(&length),
  12.328 +      _pred(0), _local_pred(false),
  12.329 +      _dist(0), _local_dist(false), _mask(0) {}
  12.330 +    
  12.331 +    ///Destructor.
  12.332 +    ~BellmanFord() {
  12.333 +      if(_local_pred) delete _pred;
  12.334 +      if(_local_dist) delete _dist;
  12.335 +      if(_mask) delete _mask;
  12.336 +    }
  12.337 +
  12.338 +    /// \brief Sets the length map.
  12.339 +    ///
  12.340 +    /// Sets the length map.
  12.341 +    /// \return <tt>(*this)</tt>
  12.342 +    BellmanFord &lengthMap(const LengthMap &map) {
  12.343 +      _length = &map;
  12.344 +      return *this;
  12.345 +    }
  12.346 +
  12.347 +    /// \brief Sets the map that stores the predecessor arcs.
  12.348 +    ///
  12.349 +    /// Sets the map that stores the predecessor arcs.
  12.350 +    /// If you don't use this function before calling \ref run()
  12.351 +    /// or \ref init(), an instance will be allocated automatically.
  12.352 +    /// The destructor deallocates this automatically allocated map,
  12.353 +    /// of course.
  12.354 +    /// \return <tt>(*this)</tt>
  12.355 +    BellmanFord &predMap(PredMap &map) {
  12.356 +      if(_local_pred) {
  12.357 +	delete _pred;
  12.358 +	_local_pred=false;
  12.359 +      }
  12.360 +      _pred = &map;
  12.361 +      return *this;
  12.362 +    }
  12.363 +
  12.364 +    /// \brief Sets the map that stores the distances of the nodes.
  12.365 +    ///
  12.366 +    /// Sets the map that stores the distances of the nodes calculated
  12.367 +    /// by the algorithm.
  12.368 +    /// If you don't use this function before calling \ref run()
  12.369 +    /// or \ref init(), an instance will be allocated automatically.
  12.370 +    /// The destructor deallocates this automatically allocated map,
  12.371 +    /// of course.
  12.372 +    /// \return <tt>(*this)</tt>
  12.373 +    BellmanFord &distMap(DistMap &map) {
  12.374 +      if(_local_dist) {
  12.375 +	delete _dist;
  12.376 +	_local_dist=false;
  12.377 +      }
  12.378 +      _dist = &map;
  12.379 +      return *this;
  12.380 +    }
  12.381 +
  12.382 +    /// \name Execution Control
  12.383 +    /// The simplest way to execute the Bellman-Ford algorithm is to use
  12.384 +    /// one of the member functions called \ref run().\n
  12.385 +    /// If you need better control on the execution, you have to call
  12.386 +    /// \ref init() first, then you can add several source nodes
  12.387 +    /// with \ref addSource(). Finally the actual path computation can be
  12.388 +    /// performed with \ref start(), \ref checkedStart() or
  12.389 +    /// \ref limitedStart().
  12.390 +
  12.391 +    ///@{
  12.392 +
  12.393 +    /// \brief Initializes the internal data structures.
  12.394 +    /// 
  12.395 +    /// Initializes the internal data structures. The optional parameter
  12.396 +    /// is the initial distance of each node.
  12.397 +    void init(const Value value = OperationTraits::infinity()) {
  12.398 +      create_maps();
  12.399 +      for (NodeIt it(*_gr); it != INVALID; ++it) {
  12.400 +	_pred->set(it, INVALID);
  12.401 +	_dist->set(it, value);
  12.402 +      }
  12.403 +      _process.clear();
  12.404 +      if (OperationTraits::less(value, OperationTraits::infinity())) {
  12.405 +	for (NodeIt it(*_gr); it != INVALID; ++it) {
  12.406 +	  _process.push_back(it);
  12.407 +	  _mask->set(it, true);
  12.408 +	}
  12.409 +      }
  12.410 +    }
  12.411 +    
  12.412 +    /// \brief Adds a new source node.
  12.413 +    ///
  12.414 +    /// This function adds a new source node. The optional second parameter
  12.415 +    /// is the initial distance of the node.
  12.416 +    void addSource(Node source, Value dst = OperationTraits::zero()) {
  12.417 +      _dist->set(source, dst);
  12.418 +      if (!(*_mask)[source]) {
  12.419 +	_process.push_back(source);
  12.420 +	_mask->set(source, true);
  12.421 +      }
  12.422 +    }
  12.423 +
  12.424 +    /// \brief Executes one round from the Bellman-Ford algorithm.
  12.425 +    ///
  12.426 +    /// If the algoritm calculated the distances in the previous round
  12.427 +    /// exactly for the paths of at most \c k arcs, then this function
  12.428 +    /// will calculate the distances exactly for the paths of at most
  12.429 +    /// <tt>k+1</tt> arcs. Performing \c k iterations using this function
  12.430 +    /// calculates the shortest path distances exactly for the paths
  12.431 +    /// consisting of at most \c k arcs.
  12.432 +    ///
  12.433 +    /// \warning The paths with limited arc number cannot be retrieved
  12.434 +    /// easily with \ref path() or \ref predArc() functions. If you also
  12.435 +    /// need the shortest paths and not only the distances, you should
  12.436 +    /// store the \ref predMap() "predecessor map" after each iteration
  12.437 +    /// and build the path manually.
  12.438 +    ///
  12.439 +    /// \return \c true when the algorithm have not found more shorter
  12.440 +    /// paths.
  12.441 +    ///
  12.442 +    /// \see ActiveIt
  12.443 +    bool processNextRound() {
  12.444 +      for (int i = 0; i < int(_process.size()); ++i) {
  12.445 +	_mask->set(_process[i], false);
  12.446 +      }
  12.447 +      std::vector<Node> nextProcess;
  12.448 +      std::vector<Value> values(_process.size());
  12.449 +      for (int i = 0; i < int(_process.size()); ++i) {
  12.450 +	values[i] = (*_dist)[_process[i]];
  12.451 +      }
  12.452 +      for (int i = 0; i < int(_process.size()); ++i) {
  12.453 +	for (OutArcIt it(*_gr, _process[i]); it != INVALID; ++it) {
  12.454 +	  Node target = _gr->target(it);
  12.455 +	  Value relaxed = OperationTraits::plus(values[i], (*_length)[it]);
  12.456 +	  if (OperationTraits::less(relaxed, (*_dist)[target])) {
  12.457 +	    _pred->set(target, it);
  12.458 +	    _dist->set(target, relaxed);
  12.459 +	    if (!(*_mask)[target]) {
  12.460 +	      _mask->set(target, true);
  12.461 +	      nextProcess.push_back(target);
  12.462 +	    }
  12.463 +	  }	  
  12.464 +	}
  12.465 +      }
  12.466 +      _process.swap(nextProcess);
  12.467 +      return _process.empty();
  12.468 +    }
  12.469 +
  12.470 +    /// \brief Executes one weak round from the Bellman-Ford algorithm.
  12.471 +    ///
  12.472 +    /// If the algorithm calculated the distances in the previous round
  12.473 +    /// at least for the paths of at most \c k arcs, then this function
  12.474 +    /// will calculate the distances at least for the paths of at most
  12.475 +    /// <tt>k+1</tt> arcs.
  12.476 +    /// This function does not make it possible to calculate the shortest
  12.477 +    /// path distances exactly for paths consisting of at most \c k arcs,
  12.478 +    /// this is why it is called weak round.
  12.479 +    ///
  12.480 +    /// \return \c true when the algorithm have not found more shorter
  12.481 +    /// paths.
  12.482 +    ///
  12.483 +    /// \see ActiveIt
  12.484 +    bool processNextWeakRound() {
  12.485 +      for (int i = 0; i < int(_process.size()); ++i) {
  12.486 +	_mask->set(_process[i], false);
  12.487 +      }
  12.488 +      std::vector<Node> nextProcess;
  12.489 +      for (int i = 0; i < int(_process.size()); ++i) {
  12.490 +	for (OutArcIt it(*_gr, _process[i]); it != INVALID; ++it) {
  12.491 +	  Node target = _gr->target(it);
  12.492 +	  Value relaxed = 
  12.493 +	    OperationTraits::plus((*_dist)[_process[i]], (*_length)[it]);
  12.494 +	  if (OperationTraits::less(relaxed, (*_dist)[target])) {
  12.495 +	    _pred->set(target, it);
  12.496 +	    _dist->set(target, relaxed);
  12.497 +	    if (!(*_mask)[target]) {
  12.498 +	      _mask->set(target, true);
  12.499 +	      nextProcess.push_back(target);
  12.500 +	    }
  12.501 +	  }	  
  12.502 +	}
  12.503 +      }
  12.504 +      _process.swap(nextProcess);
  12.505 +      return _process.empty();
  12.506 +    }
  12.507 +
  12.508 +    /// \brief Executes the algorithm.
  12.509 +    ///
  12.510 +    /// Executes the algorithm.
  12.511 +    ///
  12.512 +    /// This method runs the Bellman-Ford algorithm from the root node(s)
  12.513 +    /// in order to compute the shortest path to each node.
  12.514 +    ///
  12.515 +    /// The algorithm computes
  12.516 +    /// - the shortest path tree (forest),
  12.517 +    /// - the distance of each node from the root(s).
  12.518 +    ///
  12.519 +    /// \pre init() must be called and at least one root node should be
  12.520 +    /// added with addSource() before using this function.
  12.521 +    void start() {
  12.522 +      int num = countNodes(*_gr) - 1;
  12.523 +      for (int i = 0; i < num; ++i) {
  12.524 +	if (processNextWeakRound()) break;
  12.525 +      }
  12.526 +    }
  12.527 +
  12.528 +    /// \brief Executes the algorithm and checks the negative cycles.
  12.529 +    ///
  12.530 +    /// Executes the algorithm and checks the negative cycles.
  12.531 +    ///
  12.532 +    /// This method runs the Bellman-Ford algorithm from the root node(s)
  12.533 +    /// in order to compute the shortest path to each node and also checks
  12.534 +    /// if the digraph contains cycles with negative total length.
  12.535 +    ///
  12.536 +    /// The algorithm computes 
  12.537 +    /// - the shortest path tree (forest),
  12.538 +    /// - the distance of each node from the root(s).
  12.539 +    /// 
  12.540 +    /// \return \c false if there is a negative cycle in the digraph.
  12.541 +    ///
  12.542 +    /// \pre init() must be called and at least one root node should be
  12.543 +    /// added with addSource() before using this function. 
  12.544 +    bool checkedStart() {
  12.545 +      int num = countNodes(*_gr);
  12.546 +      for (int i = 0; i < num; ++i) {
  12.547 +	if (processNextWeakRound()) return true;
  12.548 +      }
  12.549 +      return _process.empty();
  12.550 +    }
  12.551 +
  12.552 +    /// \brief Executes the algorithm with arc number limit.
  12.553 +    ///
  12.554 +    /// Executes the algorithm with arc number limit.
  12.555 +    ///
  12.556 +    /// This method runs the Bellman-Ford algorithm from the root node(s)
  12.557 +    /// in order to compute the shortest path distance for each node
  12.558 +    /// using only the paths consisting of at most \c num arcs.
  12.559 +    ///
  12.560 +    /// The algorithm computes
  12.561 +    /// - the limited distance of each node from the root(s),
  12.562 +    /// - the predecessor arc for each node.
  12.563 +    ///
  12.564 +    /// \warning The paths with limited arc number cannot be retrieved
  12.565 +    /// easily with \ref path() or \ref predArc() functions. If you also
  12.566 +    /// need the shortest paths and not only the distances, you should
  12.567 +    /// store the \ref predMap() "predecessor map" after each iteration
  12.568 +    /// and build the path manually.
  12.569 +    ///
  12.570 +    /// \pre init() must be called and at least one root node should be
  12.571 +    /// added with addSource() before using this function. 
  12.572 +    void limitedStart(int num) {
  12.573 +      for (int i = 0; i < num; ++i) {
  12.574 +	if (processNextRound()) break;
  12.575 +      }
  12.576 +    }
  12.577 +    
  12.578 +    /// \brief Runs the algorithm from the given root node.
  12.579 +    ///    
  12.580 +    /// This method runs the Bellman-Ford algorithm from the given root
  12.581 +    /// node \c s in order to compute the shortest path to each node.
  12.582 +    ///
  12.583 +    /// The algorithm computes
  12.584 +    /// - the shortest path tree (forest),
  12.585 +    /// - the distance of each node from the root(s).
  12.586 +    ///
  12.587 +    /// \note bf.run(s) is just a shortcut of the following code.
  12.588 +    /// \code
  12.589 +    ///   bf.init();
  12.590 +    ///   bf.addSource(s);
  12.591 +    ///   bf.start();
  12.592 +    /// \endcode
  12.593 +    void run(Node s) {
  12.594 +      init();
  12.595 +      addSource(s);
  12.596 +      start();
  12.597 +    }
  12.598 +    
  12.599 +    /// \brief Runs the algorithm from the given root node with arc
  12.600 +    /// number limit.
  12.601 +    ///    
  12.602 +    /// This method runs the Bellman-Ford algorithm from the given root
  12.603 +    /// node \c s in order to compute the shortest path distance for each
  12.604 +    /// node using only the paths consisting of at most \c num arcs.
  12.605 +    ///
  12.606 +    /// The algorithm computes
  12.607 +    /// - the limited distance of each node from the root(s),
  12.608 +    /// - the predecessor arc for each node.
  12.609 +    ///
  12.610 +    /// \warning The paths with limited arc number cannot be retrieved
  12.611 +    /// easily with \ref path() or \ref predArc() functions. If you also
  12.612 +    /// need the shortest paths and not only the distances, you should
  12.613 +    /// store the \ref predMap() "predecessor map" after each iteration
  12.614 +    /// and build the path manually.
  12.615 +    ///
  12.616 +    /// \note bf.run(s, num) is just a shortcut of the following code.
  12.617 +    /// \code
  12.618 +    ///   bf.init();
  12.619 +    ///   bf.addSource(s);
  12.620 +    ///   bf.limitedStart(num);
  12.621 +    /// \endcode
  12.622 +    void run(Node s, int num) {
  12.623 +      init();
  12.624 +      addSource(s);
  12.625 +      limitedStart(num);
  12.626 +    }
  12.627 +    
  12.628 +    ///@}
  12.629 +
  12.630 +    /// \brief LEMON iterator for getting the active nodes.
  12.631 +    ///
  12.632 +    /// This class provides a common style LEMON iterator that traverses
  12.633 +    /// the active nodes of the Bellman-Ford algorithm after the last
  12.634 +    /// phase. These nodes should be checked in the next phase to
  12.635 +    /// find augmenting arcs outgoing from them.
  12.636 +    class ActiveIt {
  12.637 +    public:
  12.638 +
  12.639 +      /// \brief Constructor.
  12.640 +      ///
  12.641 +      /// Constructor for getting the active nodes of the given BellmanFord
  12.642 +      /// instance. 
  12.643 +      ActiveIt(const BellmanFord& algorithm) : _algorithm(&algorithm)
  12.644 +      {
  12.645 +        _index = _algorithm->_process.size() - 1;
  12.646 +      }
  12.647 +
  12.648 +      /// \brief Invalid constructor.
  12.649 +      ///
  12.650 +      /// Invalid constructor.
  12.651 +      ActiveIt(Invalid) : _algorithm(0), _index(-1) {}
  12.652 +
  12.653 +      /// \brief Conversion to \c Node.
  12.654 +      ///
  12.655 +      /// Conversion to \c Node.
  12.656 +      operator Node() const { 
  12.657 +        return _index >= 0 ? _algorithm->_process[_index] : INVALID;
  12.658 +      }
  12.659 +
  12.660 +      /// \brief Increment operator.
  12.661 +      ///
  12.662 +      /// Increment operator.
  12.663 +      ActiveIt& operator++() {
  12.664 +        --_index;
  12.665 +        return *this; 
  12.666 +      }
  12.667 +
  12.668 +      bool operator==(const ActiveIt& it) const { 
  12.669 +        return static_cast<Node>(*this) == static_cast<Node>(it); 
  12.670 +      }
  12.671 +      bool operator!=(const ActiveIt& it) const { 
  12.672 +        return static_cast<Node>(*this) != static_cast<Node>(it); 
  12.673 +      }
  12.674 +      bool operator<(const ActiveIt& it) const { 
  12.675 +        return static_cast<Node>(*this) < static_cast<Node>(it); 
  12.676 +      }
  12.677 +      
  12.678 +    private:
  12.679 +      const BellmanFord* _algorithm;
  12.680 +      int _index;
  12.681 +    };
  12.682 +    
  12.683 +    /// \name Query Functions
  12.684 +    /// The result of the Bellman-Ford algorithm can be obtained using these
  12.685 +    /// functions.\n
  12.686 +    /// Either \ref run() or \ref init() should be called before using them.
  12.687 +    
  12.688 +    ///@{
  12.689 +
  12.690 +    /// \brief The shortest path to the given node.
  12.691 +    ///    
  12.692 +    /// Gives back the shortest path to the given node from the root(s).
  12.693 +    ///
  12.694 +    /// \warning \c t should be reached from the root(s).
  12.695 +    ///
  12.696 +    /// \pre Either \ref run() or \ref init() must be called before
  12.697 +    /// using this function.
  12.698 +    Path path(Node t) const
  12.699 +    {
  12.700 +      return Path(*_gr, *_pred, t);
  12.701 +    }
  12.702 +	  
  12.703 +    /// \brief The distance of the given node from the root(s).
  12.704 +    ///
  12.705 +    /// Returns the distance of the given node from the root(s).
  12.706 +    ///
  12.707 +    /// \warning If node \c v is not reached from the root(s), then
  12.708 +    /// the return value of this function is undefined.
  12.709 +    ///
  12.710 +    /// \pre Either \ref run() or \ref init() must be called before
  12.711 +    /// using this function.
  12.712 +    Value dist(Node v) const { return (*_dist)[v]; }
  12.713 +
  12.714 +    /// \brief Returns the 'previous arc' of the shortest path tree for
  12.715 +    /// the given node.
  12.716 +    ///
  12.717 +    /// This function returns the 'previous arc' of the shortest path
  12.718 +    /// tree for node \c v, i.e. it returns the last arc of a
  12.719 +    /// shortest path from a root to \c v. It is \c INVALID if \c v
  12.720 +    /// is not reached from the root(s) or if \c v is a root.
  12.721 +    ///
  12.722 +    /// The shortest path tree used here is equal to the shortest path
  12.723 +    /// tree used in \ref predNode() and \predMap().
  12.724 +    ///
  12.725 +    /// \pre Either \ref run() or \ref init() must be called before
  12.726 +    /// using this function.
  12.727 +    Arc predArc(Node v) const { return (*_pred)[v]; }
  12.728 +
  12.729 +    /// \brief Returns the 'previous node' of the shortest path tree for
  12.730 +    /// the given node.
  12.731 +    ///
  12.732 +    /// This function returns the 'previous node' of the shortest path
  12.733 +    /// tree for node \c v, i.e. it returns the last but one node of
  12.734 +    /// a shortest path from a root to \c v. It is \c INVALID if \c v
  12.735 +    /// is not reached from the root(s) or if \c v is a root.
  12.736 +    ///
  12.737 +    /// The shortest path tree used here is equal to the shortest path
  12.738 +    /// tree used in \ref predArc() and \predMap().
  12.739 +    ///
  12.740 +    /// \pre Either \ref run() or \ref init() must be called before
  12.741 +    /// using this function.
  12.742 +    Node predNode(Node v) const { 
  12.743 +      return (*_pred)[v] == INVALID ? INVALID : _gr->source((*_pred)[v]); 
  12.744 +    }
  12.745 +    
  12.746 +    /// \brief Returns a const reference to the node map that stores the
  12.747 +    /// distances of the nodes.
  12.748 +    ///
  12.749 +    /// Returns a const reference to the node map that stores the distances
  12.750 +    /// of the nodes calculated by the algorithm.
  12.751 +    ///
  12.752 +    /// \pre Either \ref run() or \ref init() must be called before
  12.753 +    /// using this function.
  12.754 +    const DistMap &distMap() const { return *_dist;}
  12.755 + 
  12.756 +    /// \brief Returns a const reference to the node map that stores the
  12.757 +    /// predecessor arcs.
  12.758 +    ///
  12.759 +    /// Returns a const reference to the node map that stores the predecessor
  12.760 +    /// arcs, which form the shortest path tree (forest).
  12.761 +    ///
  12.762 +    /// \pre Either \ref run() or \ref init() must be called before
  12.763 +    /// using this function.
  12.764 +    const PredMap &predMap() const { return *_pred; }
  12.765 + 
  12.766 +    /// \brief Checks if a node is reached from the root(s).
  12.767 +    ///
  12.768 +    /// Returns \c true if \c v is reached from the root(s).
  12.769 +    ///
  12.770 +    /// \pre Either \ref run() or \ref init() must be called before
  12.771 +    /// using this function.
  12.772 +    bool reached(Node v) const {
  12.773 +      return (*_dist)[v] != OperationTraits::infinity();
  12.774 +    }
  12.775 +
  12.776 +    /// \brief Gives back a negative cycle.
  12.777 +    ///    
  12.778 +    /// This function gives back a directed cycle with negative total
  12.779 +    /// length if the algorithm has already found one.
  12.780 +    /// Otherwise it gives back an empty path.
  12.781 +    lemon::Path<Digraph> negativeCycle() {
  12.782 +      typename Digraph::template NodeMap<int> state(*_gr, -1);
  12.783 +      lemon::Path<Digraph> cycle;
  12.784 +      for (int i = 0; i < int(_process.size()); ++i) {
  12.785 +        if (state[_process[i]] != -1) continue;
  12.786 +        for (Node v = _process[i]; (*_pred)[v] != INVALID;
  12.787 +             v = _gr->source((*_pred)[v])) {
  12.788 +          if (state[v] == i) {
  12.789 +            cycle.addFront((*_pred)[v]);
  12.790 +            for (Node u = _gr->source((*_pred)[v]); u != v;
  12.791 +                 u = _gr->source((*_pred)[u])) {
  12.792 +              cycle.addFront((*_pred)[u]);
  12.793 +            }
  12.794 +            return cycle;
  12.795 +          }
  12.796 +          else if (state[v] >= 0) {
  12.797 +            break;
  12.798 +          }
  12.799 +          state[v] = i;
  12.800 +        }
  12.801 +      }
  12.802 +      return cycle;
  12.803 +    }
  12.804 +    
  12.805 +    ///@}
  12.806 +  };
  12.807 + 
  12.808 +  /// \brief Default traits class of bellmanFord() function.
  12.809 +  ///
  12.810 +  /// Default traits class of bellmanFord() function.
  12.811 +  /// \tparam GR The type of the digraph.
  12.812 +  /// \tparam LEN The type of the length map.
  12.813 +  template <typename GR, typename LEN>
  12.814 +  struct BellmanFordWizardDefaultTraits {
  12.815 +    /// The type of the digraph the algorithm runs on. 
  12.816 +    typedef GR Digraph;
  12.817 +
  12.818 +    /// \brief The type of the map that stores the arc lengths.
  12.819 +    ///
  12.820 +    /// The type of the map that stores the arc lengths.
  12.821 +    /// It must meet the \ref concepts::ReadMap "ReadMap" concept.
  12.822 +    typedef LEN LengthMap;
  12.823 +
  12.824 +    /// The type of the arc lengths.
  12.825 +    typedef typename LEN::Value Value;
  12.826 +
  12.827 +    /// \brief Operation traits for Bellman-Ford algorithm.
  12.828 +    ///
  12.829 +    /// It defines the used operations and the infinity value for the
  12.830 +    /// given \c Value type.
  12.831 +    /// \see BellmanFordDefaultOperationTraits
  12.832 +    typedef BellmanFordDefaultOperationTraits<Value> OperationTraits;
  12.833 +
  12.834 +    /// \brief The type of the map that stores the last
  12.835 +    /// arcs of the shortest paths.
  12.836 +    /// 
  12.837 +    /// The type of the map that stores the last arcs of the shortest paths.
  12.838 +    /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  12.839 +    typedef typename GR::template NodeMap<typename GR::Arc> PredMap;
  12.840 +
  12.841 +    /// \brief Instantiates a \c PredMap.
  12.842 +    /// 
  12.843 +    /// This function instantiates a \ref PredMap.
  12.844 +    /// \param g is the digraph to which we would like to define the
  12.845 +    /// \ref PredMap.
  12.846 +    static PredMap *createPredMap(const GR &g) {
  12.847 +      return new PredMap(g);
  12.848 +    }
  12.849 +
  12.850 +    /// \brief The type of the map that stores the distances of the nodes.
  12.851 +    ///
  12.852 +    /// The type of the map that stores the distances of the nodes.
  12.853 +    /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  12.854 +    typedef typename GR::template NodeMap<Value> DistMap;
  12.855 +
  12.856 +    /// \brief Instantiates a \c DistMap.
  12.857 +    ///
  12.858 +    /// This function instantiates a \ref DistMap. 
  12.859 +    /// \param g is the digraph to which we would like to define the
  12.860 +    /// \ref DistMap.
  12.861 +    static DistMap *createDistMap(const GR &g) {
  12.862 +      return new DistMap(g);
  12.863 +    }
  12.864 +
  12.865 +    ///The type of the shortest paths.
  12.866 +
  12.867 +    ///The type of the shortest paths.
  12.868 +    ///It must meet the \ref concepts::Path "Path" concept.
  12.869 +    typedef lemon::Path<Digraph> Path;
  12.870 +  };
  12.871 +  
  12.872 +  /// \brief Default traits class used by BellmanFordWizard.
  12.873 +  ///
  12.874 +  /// Default traits class used by BellmanFordWizard.
  12.875 +  /// \tparam GR The type of the digraph.
  12.876 +  /// \tparam LEN The type of the length map.
  12.877 +  template <typename GR, typename LEN>
  12.878 +  class BellmanFordWizardBase 
  12.879 +    : public BellmanFordWizardDefaultTraits<GR, LEN> {
  12.880 +
  12.881 +    typedef BellmanFordWizardDefaultTraits<GR, LEN> Base;
  12.882 +  protected:
  12.883 +    // Type of the nodes in the digraph.
  12.884 +    typedef typename Base::Digraph::Node Node;
  12.885 +
  12.886 +    // Pointer to the underlying digraph.
  12.887 +    void *_graph;
  12.888 +    // Pointer to the length map
  12.889 +    void *_length;
  12.890 +    // Pointer to the map of predecessors arcs.
  12.891 +    void *_pred;
  12.892 +    // Pointer to the map of distances.
  12.893 +    void *_dist;
  12.894 +    //Pointer to the shortest path to the target node.
  12.895 +    void *_path;
  12.896 +    //Pointer to the distance of the target node.
  12.897 +    void *_di;
  12.898 +
  12.899 +    public:
  12.900 +    /// Constructor.
  12.901 +    
  12.902 +    /// This constructor does not require parameters, it initiates
  12.903 +    /// all of the attributes to default values \c 0.
  12.904 +    BellmanFordWizardBase() :
  12.905 +      _graph(0), _length(0), _pred(0), _dist(0), _path(0), _di(0) {}
  12.906 +
  12.907 +    /// Constructor.
  12.908 +    
  12.909 +    /// This constructor requires two parameters,
  12.910 +    /// others are initiated to \c 0.
  12.911 +    /// \param gr The digraph the algorithm runs on.
  12.912 +    /// \param len The length map.
  12.913 +    BellmanFordWizardBase(const GR& gr, 
  12.914 +			  const LEN& len) :
  12.915 +      _graph(reinterpret_cast<void*>(const_cast<GR*>(&gr))), 
  12.916 +      _length(reinterpret_cast<void*>(const_cast<LEN*>(&len))), 
  12.917 +      _pred(0), _dist(0), _path(0), _di(0) {}
  12.918 +
  12.919 +  };
  12.920 +  
  12.921 +  /// \brief Auxiliary class for the function-type interface of the
  12.922 +  /// \ref BellmanFord "Bellman-Ford" algorithm.
  12.923 +  ///
  12.924 +  /// This auxiliary class is created to implement the
  12.925 +  /// \ref bellmanFord() "function-type interface" of the
  12.926 +  /// \ref BellmanFord "Bellman-Ford" algorithm.
  12.927 +  /// It does not have own \ref run() method, it uses the
  12.928 +  /// functions and features of the plain \ref BellmanFord.
  12.929 +  ///
  12.930 +  /// This class should only be used through the \ref bellmanFord()
  12.931 +  /// function, which makes it easier to use the algorithm.
  12.932 +  template<class TR>
  12.933 +  class BellmanFordWizard : public TR {
  12.934 +    typedef TR Base;
  12.935 +
  12.936 +    typedef typename TR::Digraph Digraph;
  12.937 +
  12.938 +    typedef typename Digraph::Node Node;
  12.939 +    typedef typename Digraph::NodeIt NodeIt;
  12.940 +    typedef typename Digraph::Arc Arc;
  12.941 +    typedef typename Digraph::OutArcIt ArcIt;
  12.942 +    
  12.943 +    typedef typename TR::LengthMap LengthMap;
  12.944 +    typedef typename LengthMap::Value Value;
  12.945 +    typedef typename TR::PredMap PredMap;
  12.946 +    typedef typename TR::DistMap DistMap;
  12.947 +    typedef typename TR::Path Path;
  12.948 +
  12.949 +  public:
  12.950 +    /// Constructor.
  12.951 +    BellmanFordWizard() : TR() {}
  12.952 +
  12.953 +    /// \brief Constructor that requires parameters.
  12.954 +    ///
  12.955 +    /// Constructor that requires parameters.
  12.956 +    /// These parameters will be the default values for the traits class.
  12.957 +    /// \param gr The digraph the algorithm runs on.
  12.958 +    /// \param len The length map.
  12.959 +    BellmanFordWizard(const Digraph& gr, const LengthMap& len) 
  12.960 +      : TR(gr, len) {}
  12.961 +
  12.962 +    /// \brief Copy constructor
  12.963 +    BellmanFordWizard(const TR &b) : TR(b) {}
  12.964 +
  12.965 +    ~BellmanFordWizard() {}
  12.966 +
  12.967 +    /// \brief Runs the Bellman-Ford algorithm from the given source node.
  12.968 +    ///    
  12.969 +    /// This method runs the Bellman-Ford algorithm from the given source
  12.970 +    /// node in order to compute the shortest path to each node.
  12.971 +    void run(Node s) {
  12.972 +      BellmanFord<Digraph,LengthMap,TR> 
  12.973 +	bf(*reinterpret_cast<const Digraph*>(Base::_graph), 
  12.974 +           *reinterpret_cast<const LengthMap*>(Base::_length));
  12.975 +      if (Base::_pred) bf.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
  12.976 +      if (Base::_dist) bf.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
  12.977 +      bf.run(s);
  12.978 +    }
  12.979 +
  12.980 +    /// \brief Runs the Bellman-Ford algorithm to find the shortest path
  12.981 +    /// between \c s and \c t.
  12.982 +    ///
  12.983 +    /// This method runs the Bellman-Ford algorithm from node \c s
  12.984 +    /// in order to compute the shortest path to node \c t.
  12.985 +    /// Actually, it computes the shortest path to each node, but using
  12.986 +    /// this function you can retrieve the distance and the shortest path
  12.987 +    /// for a single target node easier.
  12.988 +    ///
  12.989 +    /// \return \c true if \c t is reachable form \c s.
  12.990 +    bool run(Node s, Node t) {
  12.991 +      BellmanFord<Digraph,LengthMap,TR>
  12.992 +        bf(*reinterpret_cast<const Digraph*>(Base::_graph),
  12.993 +           *reinterpret_cast<const LengthMap*>(Base::_length));
  12.994 +      if (Base::_pred) bf.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
  12.995 +      if (Base::_dist) bf.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
  12.996 +      bf.run(s);
  12.997 +      if (Base::_path) *reinterpret_cast<Path*>(Base::_path) = bf.path(t);
  12.998 +      if (Base::_di) *reinterpret_cast<Value*>(Base::_di) = bf.dist(t);
  12.999 +      return bf.reached(t);
 12.1000 +    }
 12.1001 +
 12.1002 +    template<class T>
 12.1003 +    struct SetPredMapBase : public Base {
 12.1004 +      typedef T PredMap;
 12.1005 +      static PredMap *createPredMap(const Digraph &) { return 0; };
 12.1006 +      SetPredMapBase(const TR &b) : TR(b) {}
 12.1007 +    };
 12.1008 +    
 12.1009 +    /// \brief \ref named-templ-param "Named parameter" for setting
 12.1010 +    /// the predecessor map.
 12.1011 +    ///
 12.1012 +    /// \ref named-templ-param "Named parameter" for setting
 12.1013 +    /// the map that stores the predecessor arcs of the nodes.
 12.1014 +    template<class T>
 12.1015 +    BellmanFordWizard<SetPredMapBase<T> > predMap(const T &t) {
 12.1016 +      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
 12.1017 +      return BellmanFordWizard<SetPredMapBase<T> >(*this);
 12.1018 +    }
 12.1019 +    
 12.1020 +    template<class T>
 12.1021 +    struct SetDistMapBase : public Base {
 12.1022 +      typedef T DistMap;
 12.1023 +      static DistMap *createDistMap(const Digraph &) { return 0; };
 12.1024 +      SetDistMapBase(const TR &b) : TR(b) {}
 12.1025 +    };
 12.1026 +    
 12.1027 +    /// \brief \ref named-templ-param "Named parameter" for setting
 12.1028 +    /// the distance map.
 12.1029 +    ///
 12.1030 +    /// \ref named-templ-param "Named parameter" for setting
 12.1031 +    /// the map that stores the distances of the nodes calculated
 12.1032 +    /// by the algorithm.
 12.1033 +    template<class T>
 12.1034 +    BellmanFordWizard<SetDistMapBase<T> > distMap(const T &t) {
 12.1035 +      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
 12.1036 +      return BellmanFordWizard<SetDistMapBase<T> >(*this);
 12.1037 +    }
 12.1038 +
 12.1039 +    template<class T>
 12.1040 +    struct SetPathBase : public Base {
 12.1041 +      typedef T Path;
 12.1042 +      SetPathBase(const TR &b) : TR(b) {}
 12.1043 +    };
 12.1044 +
 12.1045 +    /// \brief \ref named-func-param "Named parameter" for getting
 12.1046 +    /// the shortest path to the target node.
 12.1047 +    ///
 12.1048 +    /// \ref named-func-param "Named parameter" for getting
 12.1049 +    /// the shortest path to the target node.
 12.1050 +    template<class T>
 12.1051 +    BellmanFordWizard<SetPathBase<T> > path(const T &t)
 12.1052 +    {
 12.1053 +      Base::_path=reinterpret_cast<void*>(const_cast<T*>(&t));
 12.1054 +      return BellmanFordWizard<SetPathBase<T> >(*this);
 12.1055 +    }
 12.1056 +
 12.1057 +    /// \brief \ref named-func-param "Named parameter" for getting
 12.1058 +    /// the distance of the target node.
 12.1059 +    ///
 12.1060 +    /// \ref named-func-param "Named parameter" for getting
 12.1061 +    /// the distance of the target node.
 12.1062 +    BellmanFordWizard dist(const Value &d)
 12.1063 +    {
 12.1064 +      Base::_di=reinterpret_cast<void*>(const_cast<Value*>(&d));
 12.1065 +      return *this;
 12.1066 +    }
 12.1067 +    
 12.1068 +  };
 12.1069 +  
 12.1070 +  /// \brief Function type interface for the \ref BellmanFord "Bellman-Ford"
 12.1071 +  /// algorithm.
 12.1072 +  ///
 12.1073 +  /// \ingroup shortest_path
 12.1074 +  /// Function type interface for the \ref BellmanFord "Bellman-Ford"
 12.1075 +  /// algorithm.
 12.1076 +  ///
 12.1077 +  /// This function also has several \ref named-templ-func-param 
 12.1078 +  /// "named parameters", they are declared as the members of class 
 12.1079 +  /// \ref BellmanFordWizard.
 12.1080 +  /// The following examples show how to use these parameters.
 12.1081 +  /// \code
 12.1082 +  ///   // Compute shortest path from node s to each node
 12.1083 +  ///   bellmanFord(g,length).predMap(preds).distMap(dists).run(s);
 12.1084 +  ///
 12.1085 +  ///   // Compute shortest path from s to t
 12.1086 +  ///   bool reached = bellmanFord(g,length).path(p).dist(d).run(s,t);
 12.1087 +  /// \endcode
 12.1088 +  /// \warning Don't forget to put the \ref BellmanFordWizard::run() "run()"
 12.1089 +  /// to the end of the parameter list.
 12.1090 +  /// \sa BellmanFordWizard
 12.1091 +  /// \sa BellmanFord
 12.1092 +  template<typename GR, typename LEN>
 12.1093 +  BellmanFordWizard<BellmanFordWizardBase<GR,LEN> >
 12.1094 +  bellmanFord(const GR& digraph,
 12.1095 +	      const LEN& length)
 12.1096 +  {
 12.1097 +    return BellmanFordWizard<BellmanFordWizardBase<GR,LEN> >(digraph, length);
 12.1098 +  }
 12.1099 +
 12.1100 +} //END OF NAMESPACE LEMON
 12.1101 +
 12.1102 +#endif
 12.1103 +
    13.1 --- a/lemon/bfs.h	Thu Nov 05 10:01:02 2009 +0100
    13.2 +++ b/lemon/bfs.h	Thu Nov 05 10:23:16 2009 +0100
    13.3 @@ -47,7 +47,7 @@
    13.4      ///
    13.5      ///The type of the map that stores the predecessor
    13.6      ///arcs of the shortest paths.
    13.7 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    13.8 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    13.9      typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
   13.10      ///Instantiates a \c PredMap.
   13.11  
   13.12 @@ -62,7 +62,8 @@
   13.13      ///The type of the map that indicates which nodes are processed.
   13.14  
   13.15      ///The type of the map that indicates which nodes are processed.
   13.16 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   13.17 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   13.18 +    ///By default it is a NullMap.
   13.19      typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
   13.20      ///Instantiates a \c ProcessedMap.
   13.21  
   13.22 @@ -81,7 +82,7 @@
   13.23      ///The type of the map that indicates which nodes are reached.
   13.24  
   13.25      ///The type of the map that indicates which nodes are reached.
   13.26 -    ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   13.27 +    ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   13.28      typedef typename Digraph::template NodeMap<bool> ReachedMap;
   13.29      ///Instantiates a \c ReachedMap.
   13.30  
   13.31 @@ -96,7 +97,7 @@
   13.32      ///The type of the map that stores the distances of the nodes.
   13.33  
   13.34      ///The type of the map that stores the distances of the nodes.
   13.35 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   13.36 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   13.37      typedef typename Digraph::template NodeMap<int> DistMap;
   13.38      ///Instantiates a \c DistMap.
   13.39  
   13.40 @@ -225,7 +226,7 @@
   13.41      ///
   13.42      ///\ref named-templ-param "Named parameter" for setting
   13.43      ///\c PredMap type.
   13.44 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   13.45 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   13.46      template <class T>
   13.47      struct SetPredMap : public Bfs< Digraph, SetPredMapTraits<T> > {
   13.48        typedef Bfs< Digraph, SetPredMapTraits<T> > Create;
   13.49 @@ -245,7 +246,7 @@
   13.50      ///
   13.51      ///\ref named-templ-param "Named parameter" for setting
   13.52      ///\c DistMap type.
   13.53 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   13.54 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   13.55      template <class T>
   13.56      struct SetDistMap : public Bfs< Digraph, SetDistMapTraits<T> > {
   13.57        typedef Bfs< Digraph, SetDistMapTraits<T> > Create;
   13.58 @@ -265,7 +266,7 @@
   13.59      ///
   13.60      ///\ref named-templ-param "Named parameter" for setting
   13.61      ///\c ReachedMap type.
   13.62 -    ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   13.63 +    ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   13.64      template <class T>
   13.65      struct SetReachedMap : public Bfs< Digraph, SetReachedMapTraits<T> > {
   13.66        typedef Bfs< Digraph, SetReachedMapTraits<T> > Create;
   13.67 @@ -285,7 +286,7 @@
   13.68      ///
   13.69      ///\ref named-templ-param "Named parameter" for setting
   13.70      ///\c ProcessedMap type.
   13.71 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   13.72 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   13.73      template <class T>
   13.74      struct SetProcessedMap : public Bfs< Digraph, SetProcessedMapTraits<T> > {
   13.75        typedef Bfs< Digraph, SetProcessedMapTraits<T> > Create;
   13.76 @@ -413,8 +414,8 @@
   13.77      ///\name Execution Control
   13.78      ///The simplest way to execute the BFS algorithm is to use one of the
   13.79      ///member functions called \ref run(Node) "run()".\n
   13.80 -    ///If you need more control on the execution, first you have to call
   13.81 -    ///\ref init(), then you can add several source nodes with
   13.82 +    ///If you need better control on the execution, you have to call
   13.83 +    ///\ref init() first, then you can add several source nodes with
   13.84      ///\ref addSource(). Finally the actual path computation can be
   13.85      ///performed with one of the \ref start() functions.
   13.86  
   13.87 @@ -737,9 +738,9 @@
   13.88  
   13.89      ///@{
   13.90  
   13.91 -    ///The shortest path to a node.
   13.92 +    ///The shortest path to the given node.
   13.93  
   13.94 -    ///Returns the shortest path to a node.
   13.95 +    ///Returns the shortest path to the given node from the root(s).
   13.96      ///
   13.97      ///\warning \c t should be reached from the root(s).
   13.98      ///
   13.99 @@ -747,9 +748,9 @@
  13.100      ///must be called before using this function.
  13.101      Path path(Node t) const { return Path(*G, *_pred, t); }
  13.102  
  13.103 -    ///The distance of a node from the root(s).
  13.104 +    ///The distance of the given node from the root(s).
  13.105  
  13.106 -    ///Returns the distance of a node from the root(s).
  13.107 +    ///Returns the distance of the given node from the root(s).
  13.108      ///
  13.109      ///\warning If node \c v is not reached from the root(s), then
  13.110      ///the return value of this function is undefined.
  13.111 @@ -758,29 +759,31 @@
  13.112      ///must be called before using this function.
  13.113      int dist(Node v) const { return (*_dist)[v]; }
  13.114  
  13.115 -    ///Returns the 'previous arc' of the shortest path tree for a node.
  13.116 -
  13.117 +    ///\brief Returns the 'previous arc' of the shortest path tree for
  13.118 +    ///the given node.
  13.119 +    ///
  13.120      ///This function returns the 'previous arc' of the shortest path
  13.121      ///tree for the node \c v, i.e. it returns the last arc of a
  13.122      ///shortest path from a root to \c v. It is \c INVALID if \c v
  13.123      ///is not reached from the root(s) or if \c v is a root.
  13.124      ///
  13.125      ///The shortest path tree used here is equal to the shortest path
  13.126 -    ///tree used in \ref predNode().
  13.127 +    ///tree used in \ref predNode() and \ref predMap().
  13.128      ///
  13.129      ///\pre Either \ref run(Node) "run()" or \ref init()
  13.130      ///must be called before using this function.
  13.131      Arc predArc(Node v) const { return (*_pred)[v];}
  13.132  
  13.133 -    ///Returns the 'previous node' of the shortest path tree for a node.
  13.134 -
  13.135 +    ///\brief Returns the 'previous node' of the shortest path tree for
  13.136 +    ///the given node.
  13.137 +    ///
  13.138      ///This function returns the 'previous node' of the shortest path
  13.139      ///tree for the node \c v, i.e. it returns the last but one node
  13.140 -    ///from a shortest path from a root to \c v. It is \c INVALID
  13.141 +    ///of a shortest path from a root to \c v. It is \c INVALID
  13.142      ///if \c v is not reached from the root(s) or if \c v is a root.
  13.143      ///
  13.144      ///The shortest path tree used here is equal to the shortest path
  13.145 -    ///tree used in \ref predArc().
  13.146 +    ///tree used in \ref predArc() and \ref predMap().
  13.147      ///
  13.148      ///\pre Either \ref run(Node) "run()" or \ref init()
  13.149      ///must be called before using this function.
  13.150 @@ -801,13 +804,13 @@
  13.151      ///predecessor arcs.
  13.152      ///
  13.153      ///Returns a const reference to the node map that stores the predecessor
  13.154 -    ///arcs, which form the shortest path tree.
  13.155 +    ///arcs, which form the shortest path tree (forest).
  13.156      ///
  13.157      ///\pre Either \ref run(Node) "run()" or \ref init()
  13.158      ///must be called before using this function.
  13.159      const PredMap &predMap() const { return *_pred;}
  13.160  
  13.161 -    ///Checks if a node is reached from the root(s).
  13.162 +    ///Checks if the given node is reached from the root(s).
  13.163  
  13.164      ///Returns \c true if \c v is reached from the root(s).
  13.165      ///
  13.166 @@ -833,7 +836,7 @@
  13.167      ///
  13.168      ///The type of the map that stores the predecessor
  13.169      ///arcs of the shortest paths.
  13.170 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
  13.171 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  13.172      typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
  13.173      ///Instantiates a PredMap.
  13.174  
  13.175 @@ -848,7 +851,7 @@
  13.176      ///The type of the map that indicates which nodes are processed.
  13.177  
  13.178      ///The type of the map that indicates which nodes are processed.
  13.179 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
  13.180 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  13.181      ///By default it is a NullMap.
  13.182      typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
  13.183      ///Instantiates a ProcessedMap.
  13.184 @@ -868,7 +871,7 @@
  13.185      ///The type of the map that indicates which nodes are reached.
  13.186  
  13.187      ///The type of the map that indicates which nodes are reached.
  13.188 -    ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
  13.189 +    ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
  13.190      typedef typename Digraph::template NodeMap<bool> ReachedMap;
  13.191      ///Instantiates a ReachedMap.
  13.192  
  13.193 @@ -883,7 +886,7 @@
  13.194      ///The type of the map that stores the distances of the nodes.
  13.195  
  13.196      ///The type of the map that stores the distances of the nodes.
  13.197 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
  13.198 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  13.199      typedef typename Digraph::template NodeMap<int> DistMap;
  13.200      ///Instantiates a DistMap.
  13.201  
  13.202 @@ -898,18 +901,14 @@
  13.203      ///The type of the shortest paths.
  13.204  
  13.205      ///The type of the shortest paths.
  13.206 -    ///It must meet the \ref concepts::Path "Path" concept.
  13.207 +    ///It must conform to the \ref concepts::Path "Path" concept.
  13.208      typedef lemon::Path<Digraph> Path;
  13.209    };
  13.210  
  13.211    /// Default traits class used by BfsWizard
  13.212  
  13.213 -  /// To make it easier to use Bfs algorithm
  13.214 -  /// we have created a wizard class.
  13.215 -  /// This \ref BfsWizard class needs default traits,
  13.216 -  /// as well as the \ref Bfs class.
  13.217 -  /// The \ref BfsWizardBase is a class to be the default traits of the
  13.218 -  /// \ref BfsWizard class.
  13.219 +  /// Default traits class used by BfsWizard.
  13.220 +  /// \tparam GR The type of the digraph.
  13.221    template<class GR>
  13.222    class BfsWizardBase : public BfsWizardDefaultTraits<GR>
  13.223    {
  13.224 @@ -937,7 +936,7 @@
  13.225      public:
  13.226      /// Constructor.
  13.227  
  13.228 -    /// This constructor does not require parameters, therefore it initiates
  13.229 +    /// This constructor does not require parameters, it initiates
  13.230      /// all of the attributes to \c 0.
  13.231      BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
  13.232                        _dist(0), _path(0), _di(0) {}
  13.233 @@ -967,7 +966,6 @@
  13.234    {
  13.235      typedef TR Base;
  13.236  
  13.237 -    ///The type of the digraph the algorithm runs on.
  13.238      typedef typename TR::Digraph Digraph;
  13.239  
  13.240      typedef typename Digraph::Node Node;
  13.241 @@ -975,16 +973,10 @@
  13.242      typedef typename Digraph::Arc Arc;
  13.243      typedef typename Digraph::OutArcIt OutArcIt;
  13.244  
  13.245 -    ///\brief The type of the map that stores the predecessor
  13.246 -    ///arcs of the shortest paths.
  13.247      typedef typename TR::PredMap PredMap;
  13.248 -    ///\brief The type of the map that stores the distances of the nodes.
  13.249      typedef typename TR::DistMap DistMap;
  13.250 -    ///\brief The type of the map that indicates which nodes are reached.
  13.251      typedef typename TR::ReachedMap ReachedMap;
  13.252 -    ///\brief The type of the map that indicates which nodes are processed.
  13.253      typedef typename TR::ProcessedMap ProcessedMap;
  13.254 -    ///The type of the shortest paths
  13.255      typedef typename TR::Path Path;
  13.256  
  13.257    public:
  13.258 @@ -1067,11 +1059,12 @@
  13.259        static PredMap *createPredMap(const Digraph &) { return 0; };
  13.260        SetPredMapBase(const TR &b) : TR(b) {}
  13.261      };
  13.262 -    ///\brief \ref named-func-param "Named parameter"
  13.263 -    ///for setting PredMap object.
  13.264 +
  13.265 +    ///\brief \ref named-templ-param "Named parameter" for setting
  13.266 +    ///the predecessor map.
  13.267      ///
  13.268 -    ///\ref named-func-param "Named parameter"
  13.269 -    ///for setting PredMap object.
  13.270 +    ///\ref named-templ-param "Named parameter" function for setting
  13.271 +    ///the map that stores the predecessor arcs of the nodes.
  13.272      template<class T>
  13.273      BfsWizard<SetPredMapBase<T> > predMap(const T &t)
  13.274      {
  13.275 @@ -1085,11 +1078,12 @@
  13.276        static ReachedMap *createReachedMap(const Digraph &) { return 0; };
  13.277        SetReachedMapBase(const TR &b) : TR(b) {}
  13.278      };
  13.279 -    ///\brief \ref named-func-param "Named parameter"
  13.280 -    ///for setting ReachedMap object.
  13.281 +
  13.282 +    ///\brief \ref named-templ-param "Named parameter" for setting
  13.283 +    ///the reached map.
  13.284      ///
  13.285 -    /// \ref named-func-param "Named parameter"
  13.286 -    ///for setting ReachedMap object.
  13.287 +    ///\ref named-templ-param "Named parameter" function for setting
  13.288 +    ///the map that indicates which nodes are reached.
  13.289      template<class T>
  13.290      BfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
  13.291      {
  13.292 @@ -1103,11 +1097,13 @@
  13.293        static DistMap *createDistMap(const Digraph &) { return 0; };
  13.294        SetDistMapBase(const TR &b) : TR(b) {}
  13.295      };
  13.296 -    ///\brief \ref named-func-param "Named parameter"
  13.297 -    ///for setting DistMap object.
  13.298 +
  13.299 +    ///\brief \ref named-templ-param "Named parameter" for setting
  13.300 +    ///the distance map.
  13.301      ///
  13.302 -    /// \ref named-func-param "Named parameter"
  13.303 -    ///for setting DistMap object.
  13.304 +    ///\ref named-templ-param "Named parameter" function for setting
  13.305 +    ///the map that stores the distances of the nodes calculated
  13.306 +    ///by the algorithm.
  13.307      template<class T>
  13.308      BfsWizard<SetDistMapBase<T> > distMap(const T &t)
  13.309      {
  13.310 @@ -1121,11 +1117,12 @@
  13.311        static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
  13.312        SetProcessedMapBase(const TR &b) : TR(b) {}
  13.313      };
  13.314 -    ///\brief \ref named-func-param "Named parameter"
  13.315 -    ///for setting ProcessedMap object.
  13.316 +
  13.317 +    ///\brief \ref named-func-param "Named parameter" for setting
  13.318 +    ///the processed map.
  13.319      ///
  13.320 -    /// \ref named-func-param "Named parameter"
  13.321 -    ///for setting ProcessedMap object.
  13.322 +    ///\ref named-templ-param "Named parameter" function for setting
  13.323 +    ///the map that indicates which nodes are processed.
  13.324      template<class T>
  13.325      BfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
  13.326      {
  13.327 @@ -1264,7 +1261,7 @@
  13.328      /// \brief The type of the map that indicates which nodes are reached.
  13.329      ///
  13.330      /// The type of the map that indicates which nodes are reached.
  13.331 -    /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
  13.332 +    /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
  13.333      typedef typename Digraph::template NodeMap<bool> ReachedMap;
  13.334  
  13.335      /// \brief Instantiates a ReachedMap.
  13.336 @@ -1425,8 +1422,8 @@
  13.337      /// \name Execution Control
  13.338      /// The simplest way to execute the BFS algorithm is to use one of the
  13.339      /// member functions called \ref run(Node) "run()".\n
  13.340 -    /// If you need more control on the execution, first you have to call
  13.341 -    /// \ref init(), then you can add several source nodes with
  13.342 +    /// If you need better control on the execution, you have to call
  13.343 +    /// \ref init() first, then you can add several source nodes with
  13.344      /// \ref addSource(). Finally the actual path computation can be
  13.345      /// performed with one of the \ref start() functions.
  13.346  
  13.347 @@ -1735,7 +1732,7 @@
  13.348  
  13.349      ///@{
  13.350  
  13.351 -    /// \brief Checks if a node is reached from the root(s).
  13.352 +    /// \brief Checks if the given node is reached from the root(s).
  13.353      ///
  13.354      /// Returns \c true if \c v is reached from the root(s).
  13.355      ///
    14.1 --- a/lemon/bin_heap.h	Thu Nov 05 10:01:02 2009 +0100
    14.2 +++ b/lemon/bin_heap.h	Thu Nov 05 10:23:16 2009 +0100
    14.3 @@ -19,9 +19,9 @@
    14.4  #ifndef LEMON_BIN_HEAP_H
    14.5  #define LEMON_BIN_HEAP_H
    14.6  
    14.7 -///\ingroup auxdat
    14.8 +///\ingroup heaps
    14.9  ///\file
   14.10 -///\brief Binary Heap implementation.
   14.11 +///\brief Binary heap implementation.
   14.12  
   14.13  #include <vector>
   14.14  #include <utility>
   14.15 @@ -29,45 +29,41 @@
   14.16  
   14.17  namespace lemon {
   14.18  
   14.19 -  ///\ingroup auxdat
   14.20 +  /// \ingroup heaps
   14.21    ///
   14.22 -  ///\brief A Binary Heap implementation.
   14.23 +  /// \brief Binary heap data structure.
   14.24    ///
   14.25 -  ///This class implements the \e binary \e heap data structure.
   14.26 +  /// This class implements the \e binary \e heap data structure.
   14.27 +  /// It fully conforms to the \ref concepts::Heap "heap concept".
   14.28    ///
   14.29 -  ///A \e heap is a data structure for storing items with specified values
   14.30 -  ///called \e priorities in such a way that finding the item with minimum
   14.31 -  ///priority is efficient. \c CMP specifies the ordering of the priorities.
   14.32 -  ///In a heap one can change the priority of an item, add or erase an
   14.33 -  ///item, etc.
   14.34 -  ///
   14.35 -  ///\tparam PR Type of the priority of the items.
   14.36 -  ///\tparam IM A read and writable item map with int values, used internally
   14.37 -  ///to handle the cross references.
   14.38 -  ///\tparam CMP A functor class for the ordering of the priorities.
   14.39 -  ///The default is \c std::less<PR>.
   14.40 -  ///
   14.41 -  ///\sa FibHeap
   14.42 -  ///\sa Dijkstra
   14.43 +  /// \tparam PR Type of the priorities of the items.
   14.44 +  /// \tparam IM A read-writable item map with \c int values, used
   14.45 +  /// internally to handle the cross references.
   14.46 +  /// \tparam CMP A functor class for comparing the priorities.
   14.47 +  /// The default is \c std::less<PR>.
   14.48 +#ifdef DOXYGEN
   14.49 +  template <typename PR, typename IM, typename CMP>
   14.50 +#else
   14.51    template <typename PR, typename IM, typename CMP = std::less<PR> >
   14.52 +#endif
   14.53    class BinHeap {
   14.54 +  public:
   14.55  
   14.56 -  public:
   14.57 -    ///\e
   14.58 +    /// Type of the item-int map.
   14.59      typedef IM ItemIntMap;
   14.60 -    ///\e
   14.61 +    /// Type of the priorities.
   14.62      typedef PR Prio;
   14.63 -    ///\e
   14.64 +    /// Type of the items stored in the heap.
   14.65      typedef typename ItemIntMap::Key Item;
   14.66 -    ///\e
   14.67 +    /// Type of the item-priority pairs.
   14.68      typedef std::pair<Item,Prio> Pair;
   14.69 -    ///\e
   14.70 +    /// Functor type for comparing the priorities.
   14.71      typedef CMP Compare;
   14.72  
   14.73 -    /// \brief Type to represent the items states.
   14.74 +    /// \brief Type to represent the states of the items.
   14.75      ///
   14.76 -    /// Each Item element have a state associated to it. It may be "in heap",
   14.77 -    /// "pre heap" or "post heap". The latter two are indifferent from the
   14.78 +    /// Each item has a state associated to it. It can be "in heap",
   14.79 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
   14.80      /// heap's point of view, but may be useful to the user.
   14.81      ///
   14.82      /// The item-int map must be initialized in such way that it assigns
   14.83 @@ -84,42 +80,43 @@
   14.84      ItemIntMap &_iim;
   14.85  
   14.86    public:
   14.87 -    /// \brief The constructor.
   14.88 +
   14.89 +    /// \brief Constructor.
   14.90      ///
   14.91 -    /// The constructor.
   14.92 -    /// \param map should be given to the constructor, since it is used
   14.93 -    /// internally to handle the cross references. The value of the map
   14.94 -    /// must be \c PRE_HEAP (<tt>-1</tt>) for every item.
   14.95 +    /// Constructor.
   14.96 +    /// \param map A map that assigns \c int values to the items.
   14.97 +    /// It is used internally to handle the cross references.
   14.98 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
   14.99      explicit BinHeap(ItemIntMap &map) : _iim(map) {}
  14.100  
  14.101 -    /// \brief The constructor.
  14.102 +    /// \brief Constructor.
  14.103      ///
  14.104 -    /// The constructor.
  14.105 -    /// \param map should be given to the constructor, since it is used
  14.106 -    /// internally to handle the cross references. The value of the map
  14.107 -    /// should be PRE_HEAP (-1) for each element.
  14.108 -    ///
  14.109 -    /// \param comp The comparator function object.
  14.110 +    /// Constructor.
  14.111 +    /// \param map A map that assigns \c int values to the items.
  14.112 +    /// It is used internally to handle the cross references.
  14.113 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  14.114 +    /// \param comp The function object used for comparing the priorities.
  14.115      BinHeap(ItemIntMap &map, const Compare &comp)
  14.116        : _iim(map), _comp(comp) {}
  14.117  
  14.118  
  14.119 -    /// The number of items stored in the heap.
  14.120 +    /// \brief The number of items stored in the heap.
  14.121      ///
  14.122 -    /// \brief Returns the number of items stored in the heap.
  14.123 +    /// This function returns the number of items stored in the heap.
  14.124      int size() const { return _data.size(); }
  14.125  
  14.126 -    /// \brief Checks if the heap stores no items.
  14.127 +    /// \brief Check if the heap is empty.
  14.128      ///
  14.129 -    /// Returns \c true if and only if the heap stores no items.
  14.130 +    /// This function returns \c true if the heap is empty.
  14.131      bool empty() const { return _data.empty(); }
  14.132  
  14.133 -    /// \brief Make empty this heap.
  14.134 +    /// \brief Make the heap empty.
  14.135      ///
  14.136 -    /// Make empty this heap. It does not change the cross reference map.
  14.137 -    /// If you want to reuse what is not surely empty you should first clear
  14.138 -    /// the heap and after that you should set the cross reference map for
  14.139 -    /// each item to \c PRE_HEAP.
  14.140 +    /// This functon makes the heap empty.
  14.141 +    /// It does not change the cross reference map. If you want to reuse
  14.142 +    /// a heap that is not surely empty, you should first clear it and
  14.143 +    /// then you should set the cross reference map to \c PRE_HEAP
  14.144 +    /// for each item.
  14.145      void clear() {
  14.146        _data.clear();
  14.147      }
  14.148 @@ -127,12 +124,12 @@
  14.149    private:
  14.150      static int parent(int i) { return (i-1)/2; }
  14.151  
  14.152 -    static int second_child(int i) { return 2*i+2; }
  14.153 +    static int secondChild(int i) { return 2*i+2; }
  14.154      bool less(const Pair &p1, const Pair &p2) const {
  14.155        return _comp(p1.second, p2.second);
  14.156      }
  14.157  
  14.158 -    int bubble_up(int hole, Pair p) {
  14.159 +    int bubbleUp(int hole, Pair p) {
  14.160        int par = parent(hole);
  14.161        while( hole>0 && less(p,_data[par]) ) {
  14.162          move(_data[par],hole);
  14.163 @@ -143,8 +140,8 @@
  14.164        return hole;
  14.165      }
  14.166  
  14.167 -    int bubble_down(int hole, Pair p, int length) {
  14.168 -      int child = second_child(hole);
  14.169 +    int bubbleDown(int hole, Pair p, int length) {
  14.170 +      int child = secondChild(hole);
  14.171        while(child < length) {
  14.172          if( less(_data[child-1], _data[child]) ) {
  14.173            --child;
  14.174 @@ -153,7 +150,7 @@
  14.175            goto ok;
  14.176          move(_data[child], hole);
  14.177          hole = child;
  14.178 -        child = second_child(hole);
  14.179 +        child = secondChild(hole);
  14.180        }
  14.181        child--;
  14.182        if( child<length && less(_data[child], p) ) {
  14.183 @@ -171,87 +168,91 @@
  14.184      }
  14.185  
  14.186    public:
  14.187 +
  14.188      /// \brief Insert a pair of item and priority into the heap.
  14.189      ///
  14.190 -    /// Adds \c p.first to the heap with priority \c p.second.
  14.191 +    /// This function inserts \c p.first to the heap with priority
  14.192 +    /// \c p.second.
  14.193      /// \param p The pair to insert.
  14.194 +    /// \pre \c p.first must not be stored in the heap.
  14.195      void push(const Pair &p) {
  14.196        int n = _data.size();
  14.197        _data.resize(n+1);
  14.198 -      bubble_up(n, p);
  14.199 +      bubbleUp(n, p);
  14.200      }
  14.201  
  14.202 -    /// \brief Insert an item into the heap with the given heap.
  14.203 +    /// \brief Insert an item into the heap with the given priority.
  14.204      ///
  14.205 -    /// Adds \c i to the heap with priority \c p.
  14.206 +    /// This function inserts the given item into the heap with the
  14.207 +    /// given priority.
  14.208      /// \param i The item to insert.
  14.209      /// \param p The priority of the item.
  14.210 +    /// \pre \e i must not be stored in the heap.
  14.211      void push(const Item &i, const Prio &p) { push(Pair(i,p)); }
  14.212  
  14.213 -    /// \brief Returns the item with minimum priority relative to \c Compare.
  14.214 +    /// \brief Return the item having minimum priority.
  14.215      ///
  14.216 -    /// This method returns the item with minimum priority relative to \c
  14.217 -    /// Compare.
  14.218 -    /// \pre The heap must be nonempty.
  14.219 +    /// This function returns the item having minimum priority.
  14.220 +    /// \pre The heap must be non-empty.
  14.221      Item top() const {
  14.222        return _data[0].first;
  14.223      }
  14.224  
  14.225 -    /// \brief Returns the minimum priority relative to \c Compare.
  14.226 +    /// \brief The minimum priority.
  14.227      ///
  14.228 -    /// It returns the minimum priority relative to \c Compare.
  14.229 -    /// \pre The heap must be nonempty.
  14.230 +    /// This function returns the minimum priority.
  14.231 +    /// \pre The heap must be non-empty.
  14.232      Prio prio() const {
  14.233        return _data[0].second;
  14.234      }
  14.235  
  14.236 -    /// \brief Deletes the item with minimum priority relative to \c Compare.
  14.237 +    /// \brief Remove the item having minimum priority.
  14.238      ///
  14.239 -    /// This method deletes the item with minimum priority relative to \c
  14.240 -    /// Compare from the heap.
  14.241 +    /// This function removes the item having minimum priority.
  14.242      /// \pre The heap must be non-empty.
  14.243      void pop() {
  14.244        int n = _data.size()-1;
  14.245        _iim.set(_data[0].first, POST_HEAP);
  14.246        if (n > 0) {
  14.247 -        bubble_down(0, _data[n], n);
  14.248 +        bubbleDown(0, _data[n], n);
  14.249        }
  14.250        _data.pop_back();
  14.251      }
  14.252  
  14.253 -    /// \brief Deletes \c i from the heap.
  14.254 +    /// \brief Remove the given item from the heap.
  14.255      ///
  14.256 -    /// This method deletes item \c i from the heap.
  14.257 -    /// \param i The item to erase.
  14.258 -    /// \pre The item should be in the heap.
  14.259 +    /// This function removes the given item from the heap if it is
  14.260 +    /// already stored.
  14.261 +    /// \param i The item to delete.
  14.262 +    /// \pre \e i must be in the heap.
  14.263      void erase(const Item &i) {
  14.264        int h = _iim[i];
  14.265        int n = _data.size()-1;
  14.266        _iim.set(_data[h].first, POST_HEAP);
  14.267        if( h < n ) {
  14.268 -        if ( bubble_up(h, _data[n]) == h) {
  14.269 -          bubble_down(h, _data[n], n);
  14.270 +        if ( bubbleUp(h, _data[n]) == h) {
  14.271 +          bubbleDown(h, _data[n], n);
  14.272          }
  14.273        }
  14.274        _data.pop_back();
  14.275      }
  14.276  
  14.277 -
  14.278 -    /// \brief Returns the priority of \c i.
  14.279 +    /// \brief The priority of the given item.
  14.280      ///
  14.281 -    /// This function returns the priority of item \c i.
  14.282 +    /// This function returns the priority of the given item.
  14.283      /// \param i The item.
  14.284 -    /// \pre \c i must be in the heap.
  14.285 +    /// \pre \e i must be in the heap.
  14.286      Prio operator[](const Item &i) const {
  14.287        int idx = _iim[i];
  14.288        return _data[idx].second;
  14.289      }
  14.290  
  14.291 -    /// \brief \c i gets to the heap with priority \c p independently
  14.292 -    /// if \c i was already there.
  14.293 +    /// \brief Set the priority of an item or insert it, if it is
  14.294 +    /// not stored in the heap.
  14.295      ///
  14.296 -    /// This method calls \ref push(\c i, \c p) if \c i is not stored
  14.297 -    /// in the heap and sets the priority of \c i to \c p otherwise.
  14.298 +    /// This method sets the priority of the given item if it is
  14.299 +    /// already stored in the heap. Otherwise it inserts the given
  14.300 +    /// item into the heap with the given priority.
  14.301      /// \param i The item.
  14.302      /// \param p The priority.
  14.303      void set(const Item &i, const Prio &p) {
  14.304 @@ -260,44 +261,42 @@
  14.305          push(i,p);
  14.306        }
  14.307        else if( _comp(p, _data[idx].second) ) {
  14.308 -        bubble_up(idx, Pair(i,p));
  14.309 +        bubbleUp(idx, Pair(i,p));
  14.310        }
  14.311        else {
  14.312 -        bubble_down(idx, Pair(i,p), _data.size());
  14.313 +        bubbleDown(idx, Pair(i,p), _data.size());
  14.314        }
  14.315      }
  14.316  
  14.317 -    /// \brief Decreases the priority of \c i to \c p.
  14.318 +    /// \brief Decrease the priority of an item to the given value.
  14.319      ///
  14.320 -    /// This method decreases the priority of item \c i to \c p.
  14.321 +    /// This function decreases the priority of an item to the given value.
  14.322      /// \param i The item.
  14.323      /// \param p The priority.
  14.324 -    /// \pre \c i must be stored in the heap with priority at least \c
  14.325 -    /// p relative to \c Compare.
  14.326 +    /// \pre \e i must be stored in the heap with priority at least \e p.
  14.327      void decrease(const Item &i, const Prio &p) {
  14.328        int idx = _iim[i];
  14.329 -      bubble_up(idx, Pair(i,p));
  14.330 +      bubbleUp(idx, Pair(i,p));
  14.331      }
  14.332  
  14.333 -    /// \brief Increases the priority of \c i to \c p.
  14.334 +    /// \brief Increase the priority of an item to the given value.
  14.335      ///
  14.336 -    /// This method sets the priority of item \c i to \c p.
  14.337 +    /// This function increases the priority of an item to the given value.
  14.338      /// \param i The item.
  14.339      /// \param p The priority.
  14.340 -    /// \pre \c i must be stored in the heap with priority at most \c
  14.341 -    /// p relative to \c Compare.
  14.342 +    /// \pre \e i must be stored in the heap with priority at most \e p.
  14.343      void increase(const Item &i, const Prio &p) {
  14.344        int idx = _iim[i];
  14.345 -      bubble_down(idx, Pair(i,p), _data.size());
  14.346 +      bubbleDown(idx, Pair(i,p), _data.size());
  14.347      }
  14.348  
  14.349 -    /// \brief Returns if \c item is in, has already been in, or has
  14.350 -    /// never been in the heap.
  14.351 +    /// \brief Return the state of an item.
  14.352      ///
  14.353 -    /// This method returns PRE_HEAP if \c item has never been in the
  14.354 -    /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
  14.355 -    /// otherwise. In the latter case it is possible that \c item will
  14.356 -    /// get back to the heap again.
  14.357 +    /// This method returns \c PRE_HEAP if the given item has never
  14.358 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  14.359 +    /// and \c POST_HEAP otherwise.
  14.360 +    /// In the latter case it is possible that the item will get back
  14.361 +    /// to the heap again.
  14.362      /// \param i The item.
  14.363      State state(const Item &i) const {
  14.364        int s = _iim[i];
  14.365 @@ -306,11 +305,11 @@
  14.366        return State(s);
  14.367      }
  14.368  
  14.369 -    /// \brief Sets the state of the \c item in the heap.
  14.370 +    /// \brief Set the state of an item in the heap.
  14.371      ///
  14.372 -    /// Sets the state of the \c item in the heap. It can be used to
  14.373 -    /// manually clear the heap when it is important to achive the
  14.374 -    /// better time complexity.
  14.375 +    /// This function sets the state of the given item in the heap.
  14.376 +    /// It can be used to manually clear the heap when it is important
  14.377 +    /// to achive better time complexity.
  14.378      /// \param i The item.
  14.379      /// \param st The state. It should not be \c IN_HEAP.
  14.380      void state(const Item& i, State st) {
  14.381 @@ -327,12 +326,13 @@
  14.382        }
  14.383      }
  14.384  
  14.385 -    /// \brief Replaces an item in the heap.
  14.386 +    /// \brief Replace an item in the heap.
  14.387      ///
  14.388 -    /// The \c i item is replaced with \c j item. The \c i item should
  14.389 -    /// be in the heap, while the \c j should be out of the heap. The
  14.390 -    /// \c i item will out of the heap and \c j will be in the heap
  14.391 -    /// with the same prioriority as prevoiusly the \c i item.
  14.392 +    /// This function replaces item \c i with item \c j.
  14.393 +    /// Item \c i must be in the heap, while \c j must be out of the heap.
  14.394 +    /// After calling this method, item \c i will be out of the
  14.395 +    /// heap and \c j will be in the heap with the same prioriority
  14.396 +    /// as item \c i had before.
  14.397      void replace(const Item& i, const Item& j) {
  14.398        int idx = _iim[i];
  14.399        _iim.set(i, _iim[j]);
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/lemon/binom_heap.h	Thu Nov 05 10:23:16 2009 +0100
    15.3 @@ -0,0 +1,445 @@
    15.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
    15.5 + *
    15.6 + * This file is a part of LEMON, a generic C++ optimization library.
    15.7 + *
    15.8 + * Copyright (C) 2003-2009
    15.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   15.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
   15.11 + *
   15.12 + * Permission to use, modify and distribute this software is granted
   15.13 + * provided that this copyright notice appears in all copies. For
   15.14 + * precise terms see the accompanying LICENSE file.
   15.15 + *
   15.16 + * This software is provided "AS IS" with no warranty of any kind,
   15.17 + * express or implied, and with no claim as to its suitability for any
   15.18 + * purpose.
   15.19 + *
   15.20 + */
   15.21 +
   15.22 +#ifndef LEMON_BINOM_HEAP_H
   15.23 +#define LEMON_BINOM_HEAP_H
   15.24 +
   15.25 +///\file
   15.26 +///\ingroup heaps
   15.27 +///\brief Binomial Heap implementation.
   15.28 +
   15.29 +#include <vector>
   15.30 +#include <utility>
   15.31 +#include <functional>
   15.32 +#include <lemon/math.h>
   15.33 +#include <lemon/counter.h>
   15.34 +
   15.35 +namespace lemon {
   15.36 +
   15.37 +  /// \ingroup heaps
   15.38 +  ///
   15.39 +  ///\brief Binomial heap data structure.
   15.40 +  ///
   15.41 +  /// This class implements the \e binomial \e heap data structure.
   15.42 +  /// It fully conforms to the \ref concepts::Heap "heap concept".
   15.43 +  ///
   15.44 +  /// The methods \ref increase() and \ref erase() are not efficient
   15.45 +  /// in a binomial heap. In case of many calls of these operations,
   15.46 +  /// it is better to use other heap structure, e.g. \ref BinHeap
   15.47 +  /// "binary heap".
   15.48 +  ///
   15.49 +  /// \tparam PR Type of the priorities of the items.
   15.50 +  /// \tparam IM A read-writable item map with \c int values, used
   15.51 +  /// internally to handle the cross references.
   15.52 +  /// \tparam CMP A functor class for comparing the priorities.
   15.53 +  /// The default is \c std::less<PR>.
   15.54 +#ifdef DOXYGEN
   15.55 +  template <typename PR, typename IM, typename CMP>
   15.56 +#else
   15.57 +  template <typename PR, typename IM, typename CMP = std::less<PR> >
   15.58 +#endif
   15.59 +  class BinomHeap {
   15.60 +  public:
   15.61 +    /// Type of the item-int map.
   15.62 +    typedef IM ItemIntMap;
   15.63 +    /// Type of the priorities.
   15.64 +    typedef PR Prio;
   15.65 +    /// Type of the items stored in the heap.
   15.66 +    typedef typename ItemIntMap::Key Item;
   15.67 +    /// Functor type for comparing the priorities.
   15.68 +    typedef CMP Compare;
   15.69 +
   15.70 +    /// \brief Type to represent the states of the items.
   15.71 +    ///
   15.72 +    /// Each item has a state associated to it. It can be "in heap",
   15.73 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
   15.74 +    /// heap's point of view, but may be useful to the user.
   15.75 +    ///
   15.76 +    /// The item-int map must be initialized in such way that it assigns
   15.77 +    /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
   15.78 +    enum State {
   15.79 +      IN_HEAP = 0,    ///< = 0.
   15.80 +      PRE_HEAP = -1,  ///< = -1.
   15.81 +      POST_HEAP = -2  ///< = -2.
   15.82 +    };
   15.83 +
   15.84 +  private:
   15.85 +    class Store;
   15.86 +
   15.87 +    std::vector<Store> _data;
   15.88 +    int _min, _head;
   15.89 +    ItemIntMap &_iim;
   15.90 +    Compare _comp;
   15.91 +    int _num_items;
   15.92 +
   15.93 +  public:
   15.94 +    /// \brief Constructor.
   15.95 +    ///
   15.96 +    /// Constructor.
   15.97 +    /// \param map A map that assigns \c int values to the items.
   15.98 +    /// It is used internally to handle the cross references.
   15.99 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  15.100 +    explicit BinomHeap(ItemIntMap &map)
  15.101 +      : _min(0), _head(-1), _iim(map), _num_items(0) {}
  15.102 +
  15.103 +    /// \brief Constructor.
  15.104 +    ///
  15.105 +    /// Constructor.
  15.106 +    /// \param map A map that assigns \c int values to the items.
  15.107 +    /// It is used internally to handle the cross references.
  15.108 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  15.109 +    /// \param comp The function object used for comparing the priorities.
  15.110 +    BinomHeap(ItemIntMap &map, const Compare &comp)
  15.111 +      : _min(0), _head(-1), _iim(map), _comp(comp), _num_items(0) {}
  15.112 +
  15.113 +    /// \brief The number of items stored in the heap.
  15.114 +    ///
  15.115 +    /// This function returns the number of items stored in the heap.
  15.116 +    int size() const { return _num_items; }
  15.117 +
  15.118 +    /// \brief Check if the heap is empty.
  15.119 +    ///
  15.120 +    /// This function returns \c true if the heap is empty.
  15.121 +    bool empty() const { return _num_items==0; }
  15.122 +
  15.123 +    /// \brief Make the heap empty.
  15.124 +    ///
  15.125 +    /// This functon makes the heap empty.
  15.126 +    /// It does not change the cross reference map. If you want to reuse
  15.127 +    /// a heap that is not surely empty, you should first clear it and
  15.128 +    /// then you should set the cross reference map to \c PRE_HEAP
  15.129 +    /// for each item.
  15.130 +    void clear() {
  15.131 +      _data.clear(); _min=0; _num_items=0; _head=-1;
  15.132 +    }
  15.133 +
  15.134 +    /// \brief Set the priority of an item or insert it, if it is
  15.135 +    /// not stored in the heap.
  15.136 +    ///
  15.137 +    /// This method sets the priority of the given item if it is
  15.138 +    /// already stored in the heap. Otherwise it inserts the given
  15.139 +    /// item into the heap with the given priority.
  15.140 +    /// \param item The item.
  15.141 +    /// \param value The priority.
  15.142 +    void set (const Item& item, const Prio& value) {
  15.143 +      int i=_iim[item];
  15.144 +      if ( i >= 0 && _data[i].in ) {
  15.145 +        if ( _comp(value, _data[i].prio) ) decrease(item, value);
  15.146 +        if ( _comp(_data[i].prio, value) ) increase(item, value);
  15.147 +      } else push(item, value);
  15.148 +    }
  15.149 +
  15.150 +    /// \brief Insert an item into the heap with the given priority.
  15.151 +    ///
  15.152 +    /// This function inserts the given item into the heap with the
  15.153 +    /// given priority.
  15.154 +    /// \param item The item to insert.
  15.155 +    /// \param value The priority of the item.
  15.156 +    /// \pre \e item must not be stored in the heap.
  15.157 +    void push (const Item& item, const Prio& value) {
  15.158 +      int i=_iim[item];
  15.159 +      if ( i<0 ) {
  15.160 +        int s=_data.size();
  15.161 +        _iim.set( item,s );
  15.162 +        Store st;
  15.163 +        st.name=item;
  15.164 +        st.prio=value;
  15.165 +        _data.push_back(st);
  15.166 +        i=s;
  15.167 +      }
  15.168 +      else {
  15.169 +        _data[i].parent=_data[i].right_neighbor=_data[i].child=-1;
  15.170 +        _data[i].degree=0;
  15.171 +        _data[i].in=true;
  15.172 +        _data[i].prio=value;
  15.173 +      }
  15.174 +
  15.175 +      if( 0==_num_items ) {
  15.176 +        _head=i;
  15.177 +        _min=i;
  15.178 +      } else {
  15.179 +        merge(i);
  15.180 +        if( _comp(_data[i].prio, _data[_min].prio) ) _min=i;
  15.181 +      }
  15.182 +      ++_num_items;
  15.183 +    }
  15.184 +
  15.185 +    /// \brief Return the item having minimum priority.
  15.186 +    ///
  15.187 +    /// This function returns the item having minimum priority.
  15.188 +    /// \pre The heap must be non-empty.
  15.189 +    Item top() const { return _data[_min].name; }
  15.190 +
  15.191 +    /// \brief The minimum priority.
  15.192 +    ///
  15.193 +    /// This function returns the minimum priority.
  15.194 +    /// \pre The heap must be non-empty.
  15.195 +    Prio prio() const { return _data[_min].prio; }
  15.196 +
  15.197 +    /// \brief The priority of the given item.
  15.198 +    ///
  15.199 +    /// This function returns the priority of the given item.
  15.200 +    /// \param item The item.
  15.201 +    /// \pre \e item must be in the heap.
  15.202 +    const Prio& operator[](const Item& item) const {
  15.203 +      return _data[_iim[item]].prio;
  15.204 +    }
  15.205 +
  15.206 +    /// \brief Remove the item having minimum priority.
  15.207 +    ///
  15.208 +    /// This function removes the item having minimum priority.
  15.209 +    /// \pre The heap must be non-empty.
  15.210 +    void pop() {
  15.211 +      _data[_min].in=false;
  15.212 +
  15.213 +      int head_child=-1;
  15.214 +      if ( _data[_min].child!=-1 ) {
  15.215 +        int child=_data[_min].child;
  15.216 +        int neighb;
  15.217 +        while( child!=-1 ) {
  15.218 +          neighb=_data[child].right_neighbor;
  15.219 +          _data[child].parent=-1;
  15.220 +          _data[child].right_neighbor=head_child;
  15.221 +          head_child=child;
  15.222 +          child=neighb;
  15.223 +        }
  15.224 +      }
  15.225 +
  15.226 +      if ( _data[_head].right_neighbor==-1 ) {
  15.227 +        // there was only one root
  15.228 +        _head=head_child;
  15.229 +      }
  15.230 +      else {
  15.231 +        // there were more roots
  15.232 +        if( _head!=_min )  { unlace(_min); }
  15.233 +        else { _head=_data[_head].right_neighbor; }
  15.234 +        merge(head_child);
  15.235 +      }
  15.236 +      _min=findMin();
  15.237 +      --_num_items;
  15.238 +    }
  15.239 +
  15.240 +    /// \brief Remove the given item from the heap.
  15.241 +    ///
  15.242 +    /// This function removes the given item from the heap if it is
  15.243 +    /// already stored.
  15.244 +    /// \param item The item to delete.
  15.245 +    /// \pre \e item must be in the heap.
  15.246 +    void erase (const Item& item) {
  15.247 +      int i=_iim[item];
  15.248 +      if ( i >= 0 && _data[i].in ) {
  15.249 +        decrease( item, _data[_min].prio-1 );
  15.250 +        pop();
  15.251 +      }
  15.252 +    }
  15.253 +
  15.254 +    /// \brief Decrease the priority of an item to the given value.
  15.255 +    ///
  15.256 +    /// This function decreases the priority of an item to the given value.
  15.257 +    /// \param item The item.
  15.258 +    /// \param value The priority.
  15.259 +    /// \pre \e item must be stored in the heap with priority at least \e value.
  15.260 +    void decrease (Item item, const Prio& value) {
  15.261 +      int i=_iim[item];
  15.262 +      int p=_data[i].parent;
  15.263 +      _data[i].prio=value;
  15.264 +      
  15.265 +      while( p!=-1 && _comp(value, _data[p].prio) ) {
  15.266 +        _data[i].name=_data[p].name;
  15.267 +        _data[i].prio=_data[p].prio;
  15.268 +        _data[p].name=item;
  15.269 +        _data[p].prio=value;
  15.270 +        _iim[_data[i].name]=i;
  15.271 +        i=p;
  15.272 +        p=_data[p].parent;
  15.273 +      }
  15.274 +      _iim[item]=i;
  15.275 +      if ( _comp(value, _data[_min].prio) ) _min=i;
  15.276 +    }
  15.277 +
  15.278 +    /// \brief Increase the priority of an item to the given value.
  15.279 +    ///
  15.280 +    /// This function increases the priority of an item to the given value.
  15.281 +    /// \param item The item.
  15.282 +    /// \param value The priority.
  15.283 +    /// \pre \e item must be stored in the heap with priority at most \e value.
  15.284 +    void increase (Item item, const Prio& value) {
  15.285 +      erase(item);
  15.286 +      push(item, value);
  15.287 +    }
  15.288 +
  15.289 +    /// \brief Return the state of an item.
  15.290 +    ///
  15.291 +    /// This method returns \c PRE_HEAP if the given item has never
  15.292 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  15.293 +    /// and \c POST_HEAP otherwise.
  15.294 +    /// In the latter case it is possible that the item will get back
  15.295 +    /// to the heap again.
  15.296 +    /// \param item The item.
  15.297 +    State state(const Item &item) const {
  15.298 +      int i=_iim[item];
  15.299 +      if( i>=0 ) {
  15.300 +        if ( _data[i].in ) i=0;
  15.301 +        else i=-2;
  15.302 +      }
  15.303 +      return State(i);
  15.304 +    }
  15.305 +
  15.306 +    /// \brief Set the state of an item in the heap.
  15.307 +    ///
  15.308 +    /// This function sets the state of the given item in the heap.
  15.309 +    /// It can be used to manually clear the heap when it is important
  15.310 +    /// to achive better time complexity.
  15.311 +    /// \param i The item.
  15.312 +    /// \param st The state. It should not be \c IN_HEAP.
  15.313 +    void state(const Item& i, State st) {
  15.314 +      switch (st) {
  15.315 +      case POST_HEAP:
  15.316 +      case PRE_HEAP:
  15.317 +        if (state(i) == IN_HEAP) {
  15.318 +          erase(i);
  15.319 +        }
  15.320 +        _iim[i] = st;
  15.321 +        break;
  15.322 +      case IN_HEAP:
  15.323 +        break;
  15.324 +      }
  15.325 +    }
  15.326 +
  15.327 +  private:
  15.328 +    
  15.329 +    // Find the minimum of the roots
  15.330 +    int findMin() {
  15.331 +      if( _head!=-1 ) {
  15.332 +        int min_loc=_head, min_val=_data[_head].prio;
  15.333 +        for( int x=_data[_head].right_neighbor; x!=-1;
  15.334 +             x=_data[x].right_neighbor ) {
  15.335 +          if( _comp( _data[x].prio,min_val ) ) {
  15.336 +            min_val=_data[x].prio;
  15.337 +            min_loc=x;
  15.338 +          }
  15.339 +        }
  15.340 +        return min_loc;
  15.341 +      }
  15.342 +      else return -1;
  15.343 +    }
  15.344 +
  15.345 +    // Merge the heap with another heap starting at the given position
  15.346 +    void merge(int a) {
  15.347 +      if( _head==-1 || a==-1 ) return;
  15.348 +      if( _data[a].right_neighbor==-1 &&
  15.349 +          _data[a].degree<=_data[_head].degree ) {
  15.350 +        _data[a].right_neighbor=_head;
  15.351 +        _head=a;
  15.352 +      } else {
  15.353 +        interleave(a);
  15.354 +      }
  15.355 +      if( _data[_head].right_neighbor==-1 ) return;
  15.356 +      
  15.357 +      int x=_head;
  15.358 +      int x_prev=-1, x_next=_data[x].right_neighbor;
  15.359 +      while( x_next!=-1 ) {
  15.360 +        if( _data[x].degree!=_data[x_next].degree ||
  15.361 +            ( _data[x_next].right_neighbor!=-1 &&
  15.362 +              _data[_data[x_next].right_neighbor].degree==_data[x].degree ) ) {
  15.363 +          x_prev=x;
  15.364 +          x=x_next;
  15.365 +        }
  15.366 +        else {
  15.367 +          if( _comp(_data[x_next].prio,_data[x].prio) ) {
  15.368 +            if( x_prev==-1 ) {
  15.369 +              _head=x_next;
  15.370 +            } else {
  15.371 +              _data[x_prev].right_neighbor=x_next;
  15.372 +            }
  15.373 +            fuse(x,x_next);
  15.374 +            x=x_next;
  15.375 +          }
  15.376 +          else {
  15.377 +            _data[x].right_neighbor=_data[x_next].right_neighbor;
  15.378 +            fuse(x_next,x);
  15.379 +          }
  15.380 +        }
  15.381 +        x_next=_data[x].right_neighbor;
  15.382 +      }
  15.383 +    }
  15.384 +
  15.385 +    // Interleave the elements of the given list into the list of the roots
  15.386 +    void interleave(int a) {
  15.387 +      int p=_head, q=a;
  15.388 +      int curr=_data.size();
  15.389 +      _data.push_back(Store());
  15.390 +      
  15.391 +      while( p!=-1 || q!=-1 ) {
  15.392 +        if( q==-1 || ( p!=-1 && _data[p].degree<_data[q].degree ) ) {
  15.393 +          _data[curr].right_neighbor=p;
  15.394 +          curr=p;
  15.395 +          p=_data[p].right_neighbor;
  15.396 +        }
  15.397 +        else {
  15.398 +          _data[curr].right_neighbor=q;
  15.399 +          curr=q;
  15.400 +          q=_data[q].right_neighbor;
  15.401 +        }
  15.402 +      }
  15.403 +      
  15.404 +      _head=_data.back().right_neighbor;
  15.405 +      _data.pop_back();
  15.406 +    }
  15.407 +
  15.408 +    // Lace node a under node b
  15.409 +    void fuse(int a, int b) {
  15.410 +      _data[a].parent=b;
  15.411 +      _data[a].right_neighbor=_data[b].child;
  15.412 +      _data[b].child=a;
  15.413 +
  15.414 +      ++_data[b].degree;
  15.415 +    }
  15.416 +
  15.417 +    // Unlace node a (if it has siblings)
  15.418 +    void unlace(int a) {
  15.419 +      int neighb=_data[a].right_neighbor;
  15.420 +      int other=_head;
  15.421 +
  15.422 +      while( _data[other].right_neighbor!=a )
  15.423 +        other=_data[other].right_neighbor;
  15.424 +      _data[other].right_neighbor=neighb;
  15.425 +    }
  15.426 +
  15.427 +  private:
  15.428 +
  15.429 +    class Store {
  15.430 +      friend class BinomHeap;
  15.431 +
  15.432 +      Item name;
  15.433 +      int parent;
  15.434 +      int right_neighbor;
  15.435 +      int child;
  15.436 +      int degree;
  15.437 +      bool in;
  15.438 +      Prio prio;
  15.439 +
  15.440 +      Store() : parent(-1), right_neighbor(-1), child(-1), degree(0),
  15.441 +        in(true) {}
  15.442 +    };
  15.443 +  };
  15.444 +
  15.445 +} //namespace lemon
  15.446 +
  15.447 +#endif //LEMON_BINOM_HEAP_H
  15.448 +
    16.1 --- a/lemon/bits/map_extender.h	Thu Nov 05 10:01:02 2009 +0100
    16.2 +++ b/lemon/bits/map_extender.h	Thu Nov 05 10:23:16 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/bucket_heap.h	Thu Nov 05 10:01:02 2009 +0100
    17.2 +++ b/lemon/bucket_heap.h	Thu Nov 05 10:23:16 2009 +0100
    17.3 @@ -19,9 +19,9 @@
    17.4  #ifndef LEMON_BUCKET_HEAP_H
    17.5  #define LEMON_BUCKET_HEAP_H
    17.6  
    17.7 -///\ingroup auxdat
    17.8 +///\ingroup heaps
    17.9  ///\file
   17.10 -///\brief Bucket Heap implementation.
   17.11 +///\brief Bucket heap implementation.
   17.12  
   17.13  #include <vector>
   17.14  #include <utility>
   17.15 @@ -53,35 +53,41 @@
   17.16  
   17.17    }
   17.18  
   17.19 -  /// \ingroup auxdat
   17.20 +  /// \ingroup heaps
   17.21    ///
   17.22 -  /// \brief A Bucket Heap implementation.
   17.23 +  /// \brief Bucket heap data structure.
   17.24    ///
   17.25 -  /// This class implements the \e bucket \e heap data structure. A \e heap
   17.26 -  /// is a data structure for storing items with specified values called \e
   17.27 -  /// priorities in such a way that finding the item with minimum priority is
   17.28 -  /// efficient. The bucket heap is very simple implementation, it can store
   17.29 -  /// only integer priorities and it stores for each priority in the
   17.30 -  /// \f$ [0..C) \f$ range a list of items. So it should be used only when
   17.31 -  /// the priorities are small. It is not intended to use as dijkstra heap.
   17.32 +  /// This class implements the \e bucket \e heap data structure.
   17.33 +  /// It practically conforms to the \ref concepts::Heap "heap concept",
   17.34 +  /// but it has some limitations.
   17.35    ///
   17.36 -  /// \param IM A read and write Item int map, used internally
   17.37 -  /// to handle the cross references.
   17.38 -  /// \param MIN If the given parameter is false then instead of the
   17.39 -  /// minimum value the maximum can be retrivied with the top() and
   17.40 -  /// prio() member functions.
   17.41 +  /// The bucket heap is a very simple structure. It can store only
   17.42 +  /// \c int priorities and it maintains a list of items for each priority
   17.43 +  /// in the range <tt>[0..C)</tt>. So it should only be used when the
   17.44 +  /// priorities are small. It is not intended to use as a Dijkstra heap.
   17.45 +  ///
   17.46 +  /// \tparam IM A read-writable item map with \c int values, used
   17.47 +  /// internally to handle the cross references.
   17.48 +  /// \tparam MIN Indicate if the heap is a \e min-heap or a \e max-heap.
   17.49 +  /// The default is \e min-heap. If this parameter is set to \c false,
   17.50 +  /// then the comparison is reversed, so the top(), prio() and pop()
   17.51 +  /// functions deal with the item having maximum priority instead of the
   17.52 +  /// minimum.
   17.53 +  ///
   17.54 +  /// \sa SimpleBucketHeap
   17.55    template <typename IM, bool MIN = true>
   17.56    class BucketHeap {
   17.57  
   17.58    public:
   17.59 -    /// \e
   17.60 -    typedef typename IM::Key Item;
   17.61 -    /// \e
   17.62 +
   17.63 +    /// Type of the item-int map.
   17.64 +    typedef IM ItemIntMap;
   17.65 +    /// Type of the priorities.
   17.66      typedef int Prio;
   17.67 -    /// \e
   17.68 -    typedef std::pair<Item, Prio> Pair;
   17.69 -    /// \e
   17.70 -    typedef IM ItemIntMap;
   17.71 +    /// Type of the items stored in the heap.
   17.72 +    typedef typename ItemIntMap::Key Item;
   17.73 +    /// Type of the item-priority pairs.
   17.74 +    typedef std::pair<Item,Prio> Pair;
   17.75  
   17.76    private:
   17.77  
   17.78 @@ -89,10 +95,10 @@
   17.79  
   17.80    public:
   17.81  
   17.82 -    /// \brief Type to represent the items states.
   17.83 +    /// \brief Type to represent the states of the items.
   17.84      ///
   17.85 -    /// Each Item element have a state associated to it. It may be "in heap",
   17.86 -    /// "pre heap" or "post heap". The latter two are indifferent from the
   17.87 +    /// Each item has a state associated to it. It can be "in heap",
   17.88 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
   17.89      /// heap's point of view, but may be useful to the user.
   17.90      ///
   17.91      /// The item-int map must be initialized in such way that it assigns
   17.92 @@ -104,37 +110,39 @@
   17.93      };
   17.94  
   17.95    public:
   17.96 -    /// \brief The constructor.
   17.97 +
   17.98 +    /// \brief Constructor.
   17.99      ///
  17.100 -    /// The constructor.
  17.101 -    /// \param map should be given to the constructor, since it is used
  17.102 -    /// internally to handle the cross references. The value of the map
  17.103 -    /// should be PRE_HEAP (-1) for each element.
  17.104 +    /// Constructor.
  17.105 +    /// \param map A map that assigns \c int values to the items.
  17.106 +    /// It is used internally to handle the cross references.
  17.107 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  17.108      explicit BucketHeap(ItemIntMap &map) : _iim(map), _minimum(0) {}
  17.109  
  17.110 -    /// The number of items stored in the heap.
  17.111 +    /// \brief The number of items stored in the heap.
  17.112      ///
  17.113 -    /// \brief Returns the number of items stored in the heap.
  17.114 +    /// This function returns the number of items stored in the heap.
  17.115      int size() const { return _data.size(); }
  17.116  
  17.117 -    /// \brief Checks if the heap stores no items.
  17.118 +    /// \brief Check if the heap is empty.
  17.119      ///
  17.120 -    /// Returns \c true if and only if the heap stores no items.
  17.121 +    /// This function returns \c true if the heap is empty.
  17.122      bool empty() const { return _data.empty(); }
  17.123  
  17.124 -    /// \brief Make empty this heap.
  17.125 +    /// \brief Make the heap empty.
  17.126      ///
  17.127 -    /// Make empty this heap. It does not change the cross reference
  17.128 -    /// map.  If you want to reuse a heap what is not surely empty you
  17.129 -    /// should first clear the heap and after that you should set the
  17.130 -    /// cross reference map for each item to \c PRE_HEAP.
  17.131 +    /// This functon makes the heap empty.
  17.132 +    /// It does not change the cross reference map. If you want to reuse
  17.133 +    /// a heap that is not surely empty, you should first clear it and
  17.134 +    /// then you should set the cross reference map to \c PRE_HEAP
  17.135 +    /// for each item.
  17.136      void clear() {
  17.137        _data.clear(); _first.clear(); _minimum = 0;
  17.138      }
  17.139  
  17.140    private:
  17.141  
  17.142 -    void relocate_last(int idx) {
  17.143 +    void relocateLast(int idx) {
  17.144        if (idx + 1 < int(_data.size())) {
  17.145          _data[idx] = _data.back();
  17.146          if (_data[idx].prev != -1) {
  17.147 @@ -174,19 +182,24 @@
  17.148      }
  17.149  
  17.150    public:
  17.151 +
  17.152      /// \brief Insert a pair of item and priority into the heap.
  17.153      ///
  17.154 -    /// Adds \c p.first to the heap with priority \c p.second.
  17.155 +    /// This function inserts \c p.first to the heap with priority
  17.156 +    /// \c p.second.
  17.157      /// \param p The pair to insert.
  17.158 +    /// \pre \c p.first must not be stored in the heap.
  17.159      void push(const Pair& p) {
  17.160        push(p.first, p.second);
  17.161      }
  17.162  
  17.163      /// \brief Insert an item into the heap with the given priority.
  17.164      ///
  17.165 -    /// Adds \c i to the heap with priority \c p.
  17.166 +    /// This function inserts the given item into the heap with the
  17.167 +    /// given priority.
  17.168      /// \param i The item to insert.
  17.169      /// \param p The priority of the item.
  17.170 +    /// \pre \e i must not be stored in the heap.
  17.171      void push(const Item &i, const Prio &p) {
  17.172        int idx = _data.size();
  17.173        _iim[i] = idx;
  17.174 @@ -197,10 +210,10 @@
  17.175        }
  17.176      }
  17.177  
  17.178 -    /// \brief Returns the item with minimum priority.
  17.179 +    /// \brief Return the item having minimum priority.
  17.180      ///
  17.181 -    /// This method returns the item with minimum priority.
  17.182 -    /// \pre The heap must be nonempty.
  17.183 +    /// This function returns the item having minimum priority.
  17.184 +    /// \pre The heap must be non-empty.
  17.185      Item top() const {
  17.186        while (_first[_minimum] == -1) {
  17.187          Direction::increase(_minimum);
  17.188 @@ -208,10 +221,10 @@
  17.189        return _data[_first[_minimum]].item;
  17.190      }
  17.191  
  17.192 -    /// \brief Returns the minimum priority.
  17.193 +    /// \brief The minimum priority.
  17.194      ///
  17.195 -    /// It returns the minimum priority.
  17.196 -    /// \pre The heap must be nonempty.
  17.197 +    /// This function returns the minimum priority.
  17.198 +    /// \pre The heap must be non-empty.
  17.199      Prio prio() const {
  17.200        while (_first[_minimum] == -1) {
  17.201          Direction::increase(_minimum);
  17.202 @@ -219,9 +232,9 @@
  17.203        return _minimum;
  17.204      }
  17.205  
  17.206 -    /// \brief Deletes the item with minimum priority.
  17.207 +    /// \brief Remove the item having minimum priority.
  17.208      ///
  17.209 -    /// This method deletes the item with minimum priority from the heap.
  17.210 +    /// This function removes the item having minimum priority.
  17.211      /// \pre The heap must be non-empty.
  17.212      void pop() {
  17.213        while (_first[_minimum] == -1) {
  17.214 @@ -230,37 +243,38 @@
  17.215        int idx = _first[_minimum];
  17.216        _iim[_data[idx].item] = -2;
  17.217        unlace(idx);
  17.218 -      relocate_last(idx);
  17.219 +      relocateLast(idx);
  17.220      }
  17.221  
  17.222 -    /// \brief Deletes \c i from the heap.
  17.223 +    /// \brief Remove the given item from the heap.
  17.224      ///
  17.225 -    /// This method deletes item \c i from the heap, if \c i was
  17.226 -    /// already stored in the heap.
  17.227 -    /// \param i The item to erase.
  17.228 +    /// This function removes the given item from the heap if it is
  17.229 +    /// already stored.
  17.230 +    /// \param i The item to delete.
  17.231 +    /// \pre \e i must be in the heap.
  17.232      void erase(const Item &i) {
  17.233        int idx = _iim[i];
  17.234        _iim[_data[idx].item] = -2;
  17.235        unlace(idx);
  17.236 -      relocate_last(idx);
  17.237 +      relocateLast(idx);
  17.238      }
  17.239  
  17.240 -
  17.241 -    /// \brief Returns the priority of \c i.
  17.242 +    /// \brief The priority of the given item.
  17.243      ///
  17.244 -    /// This function returns the priority of item \c i.
  17.245 -    /// \pre \c i must be in the heap.
  17.246 +    /// This function returns the priority of the given item.
  17.247      /// \param i The item.
  17.248 +    /// \pre \e i must be in the heap.
  17.249      Prio operator[](const Item &i) const {
  17.250        int idx = _iim[i];
  17.251        return _data[idx].value;
  17.252      }
  17.253  
  17.254 -    /// \brief \c i gets to the heap with priority \c p independently
  17.255 -    /// if \c i was already there.
  17.256 +    /// \brief Set the priority of an item or insert it, if it is
  17.257 +    /// not stored in the heap.
  17.258      ///
  17.259 -    /// This method calls \ref push(\c i, \c p) if \c i is not stored
  17.260 -    /// in the heap and sets the priority of \c i to \c p otherwise.
  17.261 +    /// This method sets the priority of the given item if it is
  17.262 +    /// already stored in the heap. Otherwise it inserts the given
  17.263 +    /// item into the heap with the given priority.
  17.264      /// \param i The item.
  17.265      /// \param p The priority.
  17.266      void set(const Item &i, const Prio &p) {
  17.267 @@ -274,13 +288,12 @@
  17.268        }
  17.269      }
  17.270  
  17.271 -    /// \brief Decreases the priority of \c i to \c p.
  17.272 +    /// \brief Decrease the priority of an item to the given value.
  17.273      ///
  17.274 -    /// This method decreases the priority of item \c i to \c p.
  17.275 -    /// \pre \c i must be stored in the heap with priority at least \c
  17.276 -    /// p relative to \c Compare.
  17.277 +    /// This function decreases the priority of an item to the given value.
  17.278      /// \param i The item.
  17.279      /// \param p The priority.
  17.280 +    /// \pre \e i must be stored in the heap with priority at least \e p.
  17.281      void decrease(const Item &i, const Prio &p) {
  17.282        int idx = _iim[i];
  17.283        unlace(idx);
  17.284 @@ -291,13 +304,12 @@
  17.285        lace(idx);
  17.286      }
  17.287  
  17.288 -    /// \brief Increases the priority of \c i to \c p.
  17.289 +    /// \brief Increase the priority of an item to the given value.
  17.290      ///
  17.291 -    /// This method sets the priority of item \c i to \c p.
  17.292 -    /// \pre \c i must be stored in the heap with priority at most \c
  17.293 -    /// p relative to \c Compare.
  17.294 +    /// This function increases the priority of an item to the given value.
  17.295      /// \param i The item.
  17.296      /// \param p The priority.
  17.297 +    /// \pre \e i must be stored in the heap with priority at most \e p.
  17.298      void increase(const Item &i, const Prio &p) {
  17.299        int idx = _iim[i];
  17.300        unlace(idx);
  17.301 @@ -305,13 +317,13 @@
  17.302        lace(idx);
  17.303      }
  17.304  
  17.305 -    /// \brief Returns if \c item is in, has already been in, or has
  17.306 -    /// never been in the heap.
  17.307 +    /// \brief Return the state of an item.
  17.308      ///
  17.309 -    /// This method returns PRE_HEAP if \c item has never been in the
  17.310 -    /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
  17.311 -    /// otherwise. In the latter case it is possible that \c item will
  17.312 -    /// get back to the heap again.
  17.313 +    /// This method returns \c PRE_HEAP if the given item has never
  17.314 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  17.315 +    /// and \c POST_HEAP otherwise.
  17.316 +    /// In the latter case it is possible that the item will get back
  17.317 +    /// to the heap again.
  17.318      /// \param i The item.
  17.319      State state(const Item &i) const {
  17.320        int idx = _iim[i];
  17.321 @@ -319,11 +331,11 @@
  17.322        return State(idx);
  17.323      }
  17.324  
  17.325 -    /// \brief Sets the state of the \c item in the heap.
  17.326 +    /// \brief Set the state of an item in the heap.
  17.327      ///
  17.328 -    /// Sets the state of the \c item in the heap. It can be used to
  17.329 -    /// manually clear the heap when it is important to achive the
  17.330 -    /// better time complexity.
  17.331 +    /// This function sets the state of the given item in the heap.
  17.332 +    /// It can be used to manually clear the heap when it is important
  17.333 +    /// to achive better time complexity.
  17.334      /// \param i The item.
  17.335      /// \param st The state. It should not be \c IN_HEAP.
  17.336      void state(const Item& i, State st) {
  17.337 @@ -359,33 +371,44 @@
  17.338  
  17.339    }; // class BucketHeap
  17.340  
  17.341 -  /// \ingroup auxdat
  17.342 +  /// \ingroup heaps
  17.343    ///
  17.344 -  /// \brief A Simplified Bucket Heap implementation.
  17.345 +  /// \brief Simplified bucket heap data structure.
  17.346    ///
  17.347    /// This class implements a simplified \e bucket \e heap data
  17.348 -  /// structure.  It does not provide some functionality but it faster
  17.349 -  /// and simplier data structure than the BucketHeap. The main
  17.350 -  /// difference is that the BucketHeap stores for every key a double
  17.351 -  /// linked list while this class stores just simple lists. In the
  17.352 -  /// other way it does not support erasing each elements just the
  17.353 -  /// minimal and it does not supports key increasing, decreasing.
  17.354 +  /// structure. It does not provide some functionality, but it is
  17.355 +  /// faster and simpler than BucketHeap. The main difference is
  17.356 +  /// that BucketHeap stores a doubly-linked list for each key while
  17.357 +  /// this class stores only simply-linked lists. It supports erasing
  17.358 +  /// only for the item having minimum priority and it does not support
  17.359 +  /// key increasing and decreasing.
  17.360    ///
  17.361 -  /// \param IM A read and write Item int map, used internally
  17.362 -  /// to handle the cross references.
  17.363 -  /// \param MIN If the given parameter is false then instead of the
  17.364 -  /// minimum value the maximum can be retrivied with the top() and
  17.365 -  /// prio() member functions.
  17.366 +  /// Note that this implementation does not conform to the
  17.367 +  /// \ref concepts::Heap "heap concept" due to the lack of some 
  17.368 +  /// functionality.
  17.369 +  ///
  17.370 +  /// \tparam IM A read-writable item map with \c int values, used
  17.371 +  /// internally to handle the cross references.
  17.372 +  /// \tparam MIN Indicate if the heap is a \e min-heap or a \e max-heap.
  17.373 +  /// The default is \e min-heap. If this parameter is set to \c false,
  17.374 +  /// then the comparison is reversed, so the top(), prio() and pop()
  17.375 +  /// functions deal with the item having maximum priority instead of the
  17.376 +  /// minimum.
  17.377    ///
  17.378    /// \sa BucketHeap
  17.379    template <typename IM, bool MIN = true >
  17.380    class SimpleBucketHeap {
  17.381  
  17.382    public:
  17.383 -    typedef typename IM::Key Item;
  17.384 +
  17.385 +    /// Type of the item-int map.
  17.386 +    typedef IM ItemIntMap;
  17.387 +    /// Type of the priorities.
  17.388      typedef int Prio;
  17.389 -    typedef std::pair<Item, Prio> Pair;
  17.390 -    typedef IM ItemIntMap;
  17.391 +    /// Type of the items stored in the heap.
  17.392 +    typedef typename ItemIntMap::Key Item;
  17.393 +    /// Type of the item-priority pairs.
  17.394 +    typedef std::pair<Item,Prio> Pair;
  17.395  
  17.396    private:
  17.397  
  17.398 @@ -393,10 +416,10 @@
  17.399  
  17.400    public:
  17.401  
  17.402 -    /// \brief Type to represent the items states.
  17.403 +    /// \brief Type to represent the states of the items.
  17.404      ///
  17.405 -    /// Each Item element have a state associated to it. It may be "in heap",
  17.406 -    /// "pre heap" or "post heap". The latter two are indifferent from the
  17.407 +    /// Each item has a state associated to it. It can be "in heap",
  17.408 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
  17.409      /// heap's point of view, but may be useful to the user.
  17.410      ///
  17.411      /// The item-int map must be initialized in such way that it assigns
  17.412 @@ -409,48 +432,53 @@
  17.413  
  17.414    public:
  17.415  
  17.416 -    /// \brief The constructor.
  17.417 +    /// \brief Constructor.
  17.418      ///
  17.419 -    /// The constructor.
  17.420 -    /// \param map should be given to the constructor, since it is used
  17.421 -    /// internally to handle the cross references. The value of the map
  17.422 -    /// should be PRE_HEAP (-1) for each element.
  17.423 +    /// Constructor.
  17.424 +    /// \param map A map that assigns \c int values to the items.
  17.425 +    /// It is used internally to handle the cross references.
  17.426 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  17.427      explicit SimpleBucketHeap(ItemIntMap &map)
  17.428        : _iim(map), _free(-1), _num(0), _minimum(0) {}
  17.429  
  17.430 -    /// \brief Returns the number of items stored in the heap.
  17.431 +    /// \brief The number of items stored in the heap.
  17.432      ///
  17.433 -    /// The number of items stored in the heap.
  17.434 +    /// This function returns the number of items stored in the heap.
  17.435      int size() const { return _num; }
  17.436  
  17.437 -    /// \brief Checks if the heap stores no items.
  17.438 +    /// \brief Check if the heap is empty.
  17.439      ///
  17.440 -    /// Returns \c true if and only if the heap stores no items.
  17.441 +    /// This function returns \c true if the heap is empty.
  17.442      bool empty() const { return _num == 0; }
  17.443  
  17.444 -    /// \brief Make empty this heap.
  17.445 +    /// \brief Make the heap empty.
  17.446      ///
  17.447 -    /// Make empty this heap. It does not change the cross reference
  17.448 -    /// map.  If you want to reuse a heap what is not surely empty you
  17.449 -    /// should first clear the heap and after that you should set the
  17.450 -    /// cross reference map for each item to \c PRE_HEAP.
  17.451 +    /// This functon makes the heap empty.
  17.452 +    /// It does not change the cross reference map. If you want to reuse
  17.453 +    /// a heap that is not surely empty, you should first clear it and
  17.454 +    /// then you should set the cross reference map to \c PRE_HEAP
  17.455 +    /// for each item.
  17.456      void clear() {
  17.457        _data.clear(); _first.clear(); _free = -1; _num = 0; _minimum = 0;
  17.458      }
  17.459  
  17.460      /// \brief Insert a pair of item and priority into the heap.
  17.461      ///
  17.462 -    /// Adds \c p.first to the heap with priority \c p.second.
  17.463 +    /// This function inserts \c p.first to the heap with priority
  17.464 +    /// \c p.second.
  17.465      /// \param p The pair to insert.
  17.466 +    /// \pre \c p.first must not be stored in the heap.
  17.467      void push(const Pair& p) {
  17.468        push(p.first, p.second);
  17.469      }
  17.470  
  17.471      /// \brief Insert an item into the heap with the given priority.
  17.472      ///
  17.473 -    /// Adds \c i to the heap with priority \c p.
  17.474 +    /// This function inserts the given item into the heap with the
  17.475 +    /// given priority.
  17.476      /// \param i The item to insert.
  17.477      /// \param p The priority of the item.
  17.478 +    /// \pre \e i must not be stored in the heap.
  17.479      void push(const Item &i, const Prio &p) {
  17.480        int idx;
  17.481        if (_free == -1) {
  17.482 @@ -471,10 +499,10 @@
  17.483        ++_num;
  17.484      }
  17.485  
  17.486 -    /// \brief Returns the item with minimum priority.
  17.487 +    /// \brief Return the item having minimum priority.
  17.488      ///
  17.489 -    /// This method returns the item with minimum priority.
  17.490 -    /// \pre The heap must be nonempty.
  17.491 +    /// This function returns the item having minimum priority.
  17.492 +    /// \pre The heap must be non-empty.
  17.493      Item top() const {
  17.494        while (_first[_minimum] == -1) {
  17.495          Direction::increase(_minimum);
  17.496 @@ -482,10 +510,10 @@
  17.497        return _data[_first[_minimum]].item;
  17.498      }
  17.499  
  17.500 -    /// \brief Returns the minimum priority.
  17.501 +    /// \brief The minimum priority.
  17.502      ///
  17.503 -    /// It returns the minimum priority.
  17.504 -    /// \pre The heap must be nonempty.
  17.505 +    /// This function returns the minimum priority.
  17.506 +    /// \pre The heap must be non-empty.
  17.507      Prio prio() const {
  17.508        while (_first[_minimum] == -1) {
  17.509          Direction::increase(_minimum);
  17.510 @@ -493,9 +521,9 @@
  17.511        return _minimum;
  17.512      }
  17.513  
  17.514 -    /// \brief Deletes the item with minimum priority.
  17.515 +    /// \brief Remove the item having minimum priority.
  17.516      ///
  17.517 -    /// This method deletes the item with minimum priority from the heap.
  17.518 +    /// This function removes the item having minimum priority.
  17.519      /// \pre The heap must be non-empty.
  17.520      void pop() {
  17.521        while (_first[_minimum] == -1) {
  17.522 @@ -509,16 +537,15 @@
  17.523        --_num;
  17.524      }
  17.525  
  17.526 -    /// \brief Returns the priority of \c i.
  17.527 +    /// \brief The priority of the given item.
  17.528      ///
  17.529 -    /// This function returns the priority of item \c i.
  17.530 -    /// \warning This operator is not a constant time function
  17.531 -    /// because it scans the whole data structure to find the proper
  17.532 -    /// value.
  17.533 -    /// \pre \c i must be in the heap.
  17.534 +    /// This function returns the priority of the given item.
  17.535      /// \param i The item.
  17.536 +    /// \pre \e i must be in the heap.
  17.537 +    /// \warning This operator is not a constant time function because
  17.538 +    /// it scans the whole data structure to find the proper value.
  17.539      Prio operator[](const Item &i) const {
  17.540 -      for (int k = 0; k < _first.size(); ++k) {
  17.541 +      for (int k = 0; k < int(_first.size()); ++k) {
  17.542          int idx = _first[k];
  17.543          while (idx != -1) {
  17.544            if (_data[idx].item == i) {
  17.545 @@ -530,13 +557,13 @@
  17.546        return -1;
  17.547      }
  17.548  
  17.549 -    /// \brief Returns if \c item is in, has already been in, or has
  17.550 -    /// never been in the heap.
  17.551 +    /// \brief Return the state of an item.
  17.552      ///
  17.553 -    /// This method returns PRE_HEAP if \c item has never been in the
  17.554 -    /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
  17.555 -    /// otherwise. In the latter case it is possible that \c item will
  17.556 -    /// get back to the heap again.
  17.557 +    /// This method returns \c PRE_HEAP if the given item has never
  17.558 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  17.559 +    /// and \c POST_HEAP otherwise.
  17.560 +    /// In the latter case it is possible that the item will get back
  17.561 +    /// to the heap again.
  17.562      /// \param i The item.
  17.563      State state(const Item &i) const {
  17.564        int idx = _iim[i];
    18.1 --- a/lemon/cbc.cc	Thu Nov 05 10:01:02 2009 +0100
    18.2 +++ b/lemon/cbc.cc	Thu Nov 05 10:23:16 2009 +0100
    18.3 @@ -94,6 +94,18 @@
    18.4      return _prob->numberRows() - 1;
    18.5    }
    18.6  
    18.7 +  int CbcMip::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
    18.8 +    std::vector<int> indexes;
    18.9 +    std::vector<Value> values;
   18.10 +
   18.11 +    for(ExprIterator it = b; it != e; ++it) {
   18.12 +      indexes.push_back(it->first);
   18.13 +      values.push_back(it->second);
   18.14 +    }
   18.15 +
   18.16 +    _prob->addRow(values.size(), &indexes.front(), &values.front(), l, u);
   18.17 +    return _prob->numberRows() - 1;
   18.18 +  }
   18.19  
   18.20    void CbcMip::_eraseCol(int i) {
   18.21      _prob->deleteColumn(i);
    19.1 --- a/lemon/cbc.h	Thu Nov 05 10:01:02 2009 +0100
    19.2 +++ b/lemon/cbc.h	Thu Nov 05 10:23:16 2009 +0100
    19.3 @@ -62,6 +62,7 @@
    19.4  
    19.5      virtual int _addCol();
    19.6      virtual int _addRow();
    19.7 +    virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
    19.8  
    19.9      virtual void _eraseCol(int i);
   19.10      virtual void _eraseRow(int i);
    20.1 --- a/lemon/circulation.h	Thu Nov 05 10:01:02 2009 +0100
    20.2 +++ b/lemon/circulation.h	Thu Nov 05 10:23:16 2009 +0100
    20.3 @@ -72,7 +72,11 @@
    20.4      /// The type of the map that stores the flow values.
    20.5      /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap"
    20.6      /// concept.
    20.7 +#ifdef DOXYGEN
    20.8 +    typedef GR::ArcMap<Value> FlowMap;
    20.9 +#else
   20.10      typedef typename Digraph::template ArcMap<Value> FlowMap;
   20.11 +#endif
   20.12  
   20.13      /// \brief Instantiates a FlowMap.
   20.14      ///
   20.15 @@ -87,9 +91,12 @@
   20.16      ///
   20.17      /// The elevator type used by the algorithm.
   20.18      ///
   20.19 -    /// \sa Elevator
   20.20 -    /// \sa LinkedElevator
   20.21 +    /// \sa Elevator, LinkedElevator
   20.22 +#ifdef DOXYGEN
   20.23 +    typedef lemon::Elevator<GR, GR::Node> Elevator;
   20.24 +#else
   20.25      typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator;
   20.26 +#endif
   20.27  
   20.28      /// \brief Instantiates an Elevator.
   20.29      ///
   20.30 @@ -450,25 +457,27 @@
   20.31        return *_level;
   20.32      }
   20.33  
   20.34 -    /// \brief Sets the tolerance used by algorithm.
   20.35 +    /// \brief Sets the tolerance used by the algorithm.
   20.36      ///
   20.37 -    /// Sets the tolerance used by algorithm.
   20.38 -    Circulation& tolerance(const Tolerance& tolerance) const {
   20.39 +    /// Sets the tolerance object used by the algorithm.
   20.40 +    /// \return <tt>(*this)</tt>
   20.41 +    Circulation& tolerance(const Tolerance& tolerance) {
   20.42        _tol = tolerance;
   20.43        return *this;
   20.44      }
   20.45  
   20.46      /// \brief Returns a const reference to the tolerance.
   20.47      ///
   20.48 -    /// Returns a const reference to the tolerance.
   20.49 +    /// Returns a const reference to the tolerance object used by
   20.50 +    /// the algorithm.
   20.51      const Tolerance& tolerance() const {
   20.52 -      return tolerance;
   20.53 +      return _tol;
   20.54      }
   20.55  
   20.56      /// \name Execution Control
   20.57      /// The simplest way to execute the algorithm is to call \ref run().\n
   20.58 -    /// If you need more control on the initial solution or the execution,
   20.59 -    /// first you have to call one of the \ref init() functions, then
   20.60 +    /// If you need better control on the initial solution or the execution,
   20.61 +    /// you have to call one of the \ref init() functions first, then
   20.62      /// the \ref start() function.
   20.63  
   20.64      ///@{
    21.1 --- a/lemon/clp.cc	Thu Nov 05 10:01:02 2009 +0100
    21.2 +++ b/lemon/clp.cc	Thu Nov 05 10:23:16 2009 +0100
    21.3 @@ -78,6 +78,19 @@
    21.4      return _prob->numberRows() - 1;
    21.5    }
    21.6  
    21.7 +  int ClpLp::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
    21.8 +    std::vector<int> indexes;
    21.9 +    std::vector<Value> values;
   21.10 +
   21.11 +    for(ExprIterator it = b; it != e; ++it) {
   21.12 +      indexes.push_back(it->first);
   21.13 +      values.push_back(it->second);
   21.14 +    }
   21.15 +
   21.16 +    _prob->addRow(values.size(), &indexes.front(), &values.front(), l, u);
   21.17 +    return _prob->numberRows() - 1;
   21.18 +  }
   21.19 +
   21.20  
   21.21    void ClpLp::_eraseCol(int c) {
   21.22      _col_names_ref.erase(_prob->getColumnName(c));
    22.1 --- a/lemon/clp.h	Thu Nov 05 10:01:02 2009 +0100
    22.2 +++ b/lemon/clp.h	Thu Nov 05 10:23:16 2009 +0100
    22.3 @@ -75,6 +75,7 @@
    22.4  
    22.5      virtual int _addCol();
    22.6      virtual int _addRow();
    22.7 +    virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
    22.8  
    22.9      virtual void _eraseCol(int i);
   22.10      virtual void _eraseRow(int i);
    23.1 --- a/lemon/concepts/digraph.h	Thu Nov 05 10:01:02 2009 +0100
    23.2 +++ b/lemon/concepts/digraph.h	Thu Nov 05 10:23:16 2009 +0100
    23.3 @@ -35,46 +35,40 @@
    23.4      ///
    23.5      /// \brief Class describing the concept of directed graphs.
    23.6      ///
    23.7 -    /// This class describes the \ref concept "concept" of the
    23.8 -    /// immutable directed digraphs.
    23.9 +    /// This class describes the common interface of all directed
   23.10 +    /// graphs (digraphs).
   23.11      ///
   23.12 -    /// Note that actual digraph implementation like @ref ListDigraph or
   23.13 -    /// @ref SmartDigraph may have several additional functionality.
   23.14 +    /// Like all concept classes, it only provides an interface
   23.15 +    /// without any sensible implementation. So any general algorithm for
   23.16 +    /// directed graphs should compile with this class, but it will not
   23.17 +    /// run properly, of course.
   23.18 +    /// An actual digraph implementation like \ref ListDigraph or
   23.19 +    /// \ref SmartDigraph may have additional functionality.
   23.20      ///
   23.21 -    /// \sa concept
   23.22 +    /// \sa Graph
   23.23      class Digraph {
   23.24      private:
   23.25 -      ///Digraphs are \e not copy constructible. Use DigraphCopy() instead.
   23.26 +      /// Diraphs are \e not copy constructible. Use DigraphCopy instead.
   23.27 +      Digraph(const Digraph &) {}
   23.28 +      /// \brief Assignment of a digraph to another one is \e not allowed.
   23.29 +      /// Use DigraphCopy instead.
   23.30 +      void operator=(const Digraph &) {}
   23.31  
   23.32 -      ///Digraphs are \e not copy constructible. Use DigraphCopy() instead.
   23.33 -      ///
   23.34 -      Digraph(const Digraph &) {};
   23.35 -      ///\brief Assignment of \ref Digraph "Digraph"s to another ones are
   23.36 -      ///\e not allowed. Use DigraphCopy() instead.
   23.37 +    public:
   23.38 +      /// Default constructor.
   23.39 +      Digraph() { }
   23.40  
   23.41 -      ///Assignment of \ref Digraph "Digraph"s to another ones are
   23.42 -      ///\e not allowed.  Use DigraphCopy() instead.
   23.43 -
   23.44 -      void operator=(const Digraph &) {}
   23.45 -    public:
   23.46 -      ///\e
   23.47 -
   23.48 -      /// Defalult constructor.
   23.49 -
   23.50 -      /// Defalult constructor.
   23.51 -      ///
   23.52 -      Digraph() { }
   23.53 -      /// Class for identifying a node of the digraph
   23.54 +      /// The node type of the digraph
   23.55  
   23.56        /// This class identifies a node of the digraph. It also serves
   23.57        /// as a base class of the node iterators,
   23.58 -      /// thus they will convert to this type.
   23.59 +      /// thus they convert to this type.
   23.60        class Node {
   23.61        public:
   23.62          /// Default constructor
   23.63  
   23.64 -        /// @warning The default constructor sets the iterator
   23.65 -        /// to an undefined value.
   23.66 +        /// Default constructor.
   23.67 +        /// \warning It sets the object to an undefined value.
   23.68          Node() { }
   23.69          /// Copy constructor.
   23.70  
   23.71 @@ -82,40 +76,39 @@
   23.72          ///
   23.73          Node(const Node&) { }
   23.74  
   23.75 -        /// Invalid constructor \& conversion.
   23.76 +        /// %Invalid constructor \& conversion.
   23.77  
   23.78 -        /// This constructor initializes the iterator to be invalid.
   23.79 +        /// Initializes the object to be invalid.
   23.80          /// \sa Invalid for more details.
   23.81          Node(Invalid) { }
   23.82          /// Equality operator
   23.83  
   23.84 +        /// Equality operator.
   23.85 +        ///
   23.86          /// Two iterators are equal if and only if they point to the
   23.87 -        /// same object or both are invalid.
   23.88 +        /// same object or both are \c INVALID.
   23.89          bool operator==(Node) const { return true; }
   23.90  
   23.91          /// Inequality operator
   23.92  
   23.93 -        /// \sa operator==(Node n)
   23.94 -        ///
   23.95 +        /// Inequality operator.
   23.96          bool operator!=(Node) const { return true; }
   23.97  
   23.98          /// Artificial ordering operator.
   23.99  
  23.100 -        /// To allow the use of digraph descriptors as key type in std::map or
  23.101 -        /// similar associative container we require this.
  23.102 +        /// Artificial ordering operator.
  23.103          ///
  23.104 -        /// \note This operator only have to define some strict ordering of
  23.105 -        /// the items; this order has nothing to do with the iteration
  23.106 -        /// ordering of the items.
  23.107 +        /// \note This operator only has to define some strict ordering of
  23.108 +        /// the nodes; this order has nothing to do with the iteration
  23.109 +        /// ordering of the nodes.
  23.110          bool operator<(Node) const { return false; }
  23.111 -
  23.112        };
  23.113  
  23.114 -      /// This iterator goes through each node.
  23.115 +      /// Iterator class for the nodes.
  23.116  
  23.117 -      /// This iterator goes through each node.
  23.118 +      /// This iterator goes through each node of the digraph.
  23.119        /// Its usage is quite simple, for example you can count the number
  23.120 -      /// of nodes in digraph \c g of type \c Digraph like this:
  23.121 +      /// of nodes in a digraph \c g of type \c %Digraph like this:
  23.122        ///\code
  23.123        /// int count=0;
  23.124        /// for (Digraph::NodeIt n(g); n!=INVALID; ++n) ++count;
  23.125 @@ -124,30 +117,28 @@
  23.126        public:
  23.127          /// Default constructor
  23.128  
  23.129 -        /// @warning The default constructor sets the iterator
  23.130 -        /// to an undefined value.
  23.131 +        /// Default constructor.
  23.132 +        /// \warning It sets the iterator to an undefined value.
  23.133          NodeIt() { }
  23.134          /// Copy constructor.
  23.135  
  23.136          /// Copy constructor.
  23.137          ///
  23.138          NodeIt(const NodeIt& n) : Node(n) { }
  23.139 -        /// Invalid constructor \& conversion.
  23.140 +        /// %Invalid constructor \& conversion.
  23.141  
  23.142 -        /// Initialize the iterator to be invalid.
  23.143 +        /// Initializes the iterator to be invalid.
  23.144          /// \sa Invalid for more details.
  23.145          NodeIt(Invalid) { }
  23.146          /// Sets the iterator to the first node.
  23.147  
  23.148 -        /// Sets the iterator to the first node of \c g.
  23.149 +        /// Sets the iterator to the first node of the given digraph.
  23.150          ///
  23.151 -        NodeIt(const Digraph&) { }
  23.152 -        /// Node -> NodeIt conversion.
  23.153 +        explicit NodeIt(const Digraph&) { }
  23.154 +        /// Sets the iterator to the given node.
  23.155  
  23.156 -        /// Sets the iterator to the node of \c the digraph pointed by
  23.157 -        /// the trivial iterator.
  23.158 -        /// This feature necessitates that each time we
  23.159 -        /// iterate the arc-set, the iteration order is the same.
  23.160 +        /// Sets the iterator to the given node of the given digraph.
  23.161 +        ///
  23.162          NodeIt(const Digraph&, const Node&) { }
  23.163          /// Next node.
  23.164  
  23.165 @@ -157,7 +148,7 @@
  23.166        };
  23.167  
  23.168  
  23.169 -      /// Class for identifying an arc of the digraph
  23.170 +      /// The arc type of the digraph
  23.171  
  23.172        /// This class identifies an arc of the digraph. It also serves
  23.173        /// as a base class of the arc iterators,
  23.174 @@ -166,207 +157,214 @@
  23.175        public:
  23.176          /// Default constructor
  23.177  
  23.178 -        /// @warning The default constructor sets the iterator
  23.179 -        /// to an undefined value.
  23.180 +        /// Default constructor.
  23.181 +        /// \warning It sets the object to an undefined value.
  23.182          Arc() { }
  23.183          /// Copy constructor.
  23.184  
  23.185          /// Copy constructor.
  23.186          ///
  23.187          Arc(const Arc&) { }
  23.188 -        /// Initialize the iterator to be invalid.
  23.189 +        /// %Invalid constructor \& conversion.
  23.190  
  23.191 -        /// Initialize the iterator to be invalid.
  23.192 -        ///
  23.193 +        /// Initializes the object to be invalid.
  23.194 +        /// \sa Invalid for more details.
  23.195          Arc(Invalid) { }
  23.196          /// Equality operator
  23.197  
  23.198 +        /// Equality operator.
  23.199 +        ///
  23.200          /// Two iterators are equal if and only if they point to the
  23.201 -        /// same object or both are invalid.
  23.202 +        /// same object or both are \c INVALID.
  23.203          bool operator==(Arc) const { return true; }
  23.204          /// Inequality operator
  23.205  
  23.206 -        /// \sa operator==(Arc n)
  23.207 -        ///
  23.208 +        /// Inequality operator.
  23.209          bool operator!=(Arc) const { return true; }
  23.210  
  23.211          /// Artificial ordering operator.
  23.212  
  23.213 -        /// To allow the use of digraph descriptors as key type in std::map or
  23.214 -        /// similar associative container we require this.
  23.215 +        /// Artificial ordering operator.
  23.216          ///
  23.217 -        /// \note This operator only have to define some strict ordering of
  23.218 -        /// the items; this order has nothing to do with the iteration
  23.219 -        /// ordering of the items.
  23.220 +        /// \note This operator only has to define some strict ordering of
  23.221 +        /// the arcs; this order has nothing to do with the iteration
  23.222 +        /// ordering of the arcs.
  23.223          bool operator<(Arc) const { return false; }
  23.224        };
  23.225  
  23.226 -      /// This iterator goes trough the outgoing arcs of a node.
  23.227 +      /// Iterator class for the outgoing arcs of a node.
  23.228  
  23.229        /// This iterator goes trough the \e outgoing arcs of a certain node
  23.230        /// of a digraph.
  23.231        /// Its usage is quite simple, for example you can count the number
  23.232        /// of outgoing arcs of a node \c n
  23.233 -      /// in digraph \c g of type \c Digraph as follows.
  23.234 +      /// in a digraph \c g of type \c %Digraph as follows.
  23.235        ///\code
  23.236        /// int count=0;
  23.237 -      /// for (Digraph::OutArcIt e(g, n); e!=INVALID; ++e) ++count;
  23.238 +      /// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count;
  23.239        ///\endcode
  23.240 -
  23.241        class OutArcIt : public Arc {
  23.242        public:
  23.243          /// Default constructor
  23.244  
  23.245 -        /// @warning The default constructor sets the iterator
  23.246 -        /// to an undefined value.
  23.247 +        /// Default constructor.
  23.248 +        /// \warning It sets the iterator to an undefined value.
  23.249          OutArcIt() { }
  23.250          /// Copy constructor.
  23.251  
  23.252          /// Copy constructor.
  23.253          ///
  23.254          OutArcIt(const OutArcIt& e) : Arc(e) { }
  23.255 -        /// Initialize the iterator to be invalid.
  23.256 +        /// %Invalid constructor \& conversion.
  23.257  
  23.258 -        /// Initialize the iterator to be invalid.
  23.259 +        /// Initializes the iterator to be invalid.
  23.260 +        /// \sa Invalid for more details.
  23.261 +        OutArcIt(Invalid) { }
  23.262 +        /// Sets the iterator to the first outgoing arc.
  23.263 +
  23.264 +        /// Sets the iterator to the first outgoing arc of the given node.
  23.265          ///
  23.266 -        OutArcIt(Invalid) { }
  23.267 -        /// This constructor sets the iterator to the first outgoing arc.
  23.268 +        OutArcIt(const Digraph&, const Node&) { }
  23.269 +        /// Sets the iterator to the given arc.
  23.270  
  23.271 -        /// This constructor sets the iterator to the first outgoing arc of
  23.272 -        /// the node.
  23.273 -        OutArcIt(const Digraph&, const Node&) { }
  23.274 -        /// Arc -> OutArcIt conversion
  23.275 -
  23.276 -        /// Sets the iterator to the value of the trivial iterator.
  23.277 -        /// This feature necessitates that each time we
  23.278 -        /// iterate the arc-set, the iteration order is the same.
  23.279 +        /// Sets the iterator to the given arc of the given digraph.
  23.280 +        ///
  23.281          OutArcIt(const Digraph&, const Arc&) { }
  23.282 -        ///Next outgoing arc
  23.283 +        /// Next outgoing arc
  23.284  
  23.285          /// Assign the iterator to the next
  23.286          /// outgoing arc of the corresponding node.
  23.287          OutArcIt& operator++() { return *this; }
  23.288        };
  23.289  
  23.290 -      /// This iterator goes trough the incoming arcs of a node.
  23.291 +      /// Iterator class for the incoming arcs of a node.
  23.292  
  23.293        /// This iterator goes trough the \e incoming arcs of a certain node
  23.294        /// of a digraph.
  23.295        /// Its usage is quite simple, for example you can count the number
  23.296 -      /// of outgoing arcs of a node \c n
  23.297 -      /// in digraph \c g of type \c Digraph as follows.
  23.298 +      /// of incoming arcs of a node \c n
  23.299 +      /// in a digraph \c g of type \c %Digraph as follows.
  23.300        ///\code
  23.301        /// int count=0;
  23.302 -      /// for(Digraph::InArcIt e(g, n); e!=INVALID; ++e) ++count;
  23.303 +      /// for(Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count;
  23.304        ///\endcode
  23.305 -
  23.306        class InArcIt : public Arc {
  23.307        public:
  23.308          /// Default constructor
  23.309  
  23.310 -        /// @warning The default constructor sets the iterator
  23.311 -        /// to an undefined value.
  23.312 +        /// Default constructor.
  23.313 +        /// \warning It sets the iterator to an undefined value.
  23.314          InArcIt() { }
  23.315          /// Copy constructor.
  23.316  
  23.317          /// Copy constructor.
  23.318          ///
  23.319          InArcIt(const InArcIt& e) : Arc(e) { }
  23.320 -        /// Initialize the iterator to be invalid.
  23.321 +        /// %Invalid constructor \& conversion.
  23.322  
  23.323 -        /// Initialize the iterator to be invalid.
  23.324 +        /// Initializes the iterator to be invalid.
  23.325 +        /// \sa Invalid for more details.
  23.326 +        InArcIt(Invalid) { }
  23.327 +        /// Sets the iterator to the first incoming arc.
  23.328 +
  23.329 +        /// Sets the iterator to the first incoming arc of the given node.
  23.330          ///
  23.331 -        InArcIt(Invalid) { }
  23.332 -        /// This constructor sets the iterator to first incoming arc.
  23.333 +        InArcIt(const Digraph&, const Node&) { }
  23.334 +        /// Sets the iterator to the given arc.
  23.335  
  23.336 -        /// This constructor set the iterator to the first incoming arc of
  23.337 -        /// the node.
  23.338 -        InArcIt(const Digraph&, const Node&) { }
  23.339 -        /// Arc -> InArcIt conversion
  23.340 -
  23.341 -        /// Sets the iterator to the value of the trivial iterator \c e.
  23.342 -        /// This feature necessitates that each time we
  23.343 -        /// iterate the arc-set, the iteration order is the same.
  23.344 +        /// Sets the iterator to the given arc of the given digraph.
  23.345 +        ///
  23.346          InArcIt(const Digraph&, const Arc&) { }
  23.347          /// Next incoming arc
  23.348  
  23.349 -        /// Assign the iterator to the next inarc of the corresponding node.
  23.350 -        ///
  23.351 +        /// Assign the iterator to the next
  23.352 +        /// incoming arc of the corresponding node.
  23.353          InArcIt& operator++() { return *this; }
  23.354        };
  23.355 -      /// This iterator goes through each arc.
  23.356  
  23.357 -      /// This iterator goes through each arc of a digraph.
  23.358 +      /// Iterator class for the arcs.
  23.359 +
  23.360 +      /// This iterator goes through each arc of the digraph.
  23.361        /// Its usage is quite simple, for example you can count the number
  23.362 -      /// of arcs in a digraph \c g of type \c Digraph as follows:
  23.363 +      /// of arcs in a digraph \c g of type \c %Digraph as follows:
  23.364        ///\code
  23.365        /// int count=0;
  23.366 -      /// for(Digraph::ArcIt e(g); e!=INVALID; ++e) ++count;
  23.367 +      /// for(Digraph::ArcIt a(g); a!=INVALID; ++a) ++count;
  23.368        ///\endcode
  23.369        class ArcIt : public Arc {
  23.370        public:
  23.371          /// Default constructor
  23.372  
  23.373 -        /// @warning The default constructor sets the iterator
  23.374 -        /// to an undefined value.
  23.375 +        /// Default constructor.
  23.376 +        /// \warning It sets the iterator to an undefined value.
  23.377          ArcIt() { }
  23.378          /// Copy constructor.
  23.379  
  23.380          /// Copy constructor.
  23.381          ///
  23.382          ArcIt(const ArcIt& e) : Arc(e) { }
  23.383 -        /// Initialize the iterator to be invalid.
  23.384 +        /// %Invalid constructor \& conversion.
  23.385  
  23.386 -        /// Initialize the iterator to be invalid.
  23.387 +        /// Initializes the iterator to be invalid.
  23.388 +        /// \sa Invalid for more details.
  23.389 +        ArcIt(Invalid) { }
  23.390 +        /// Sets the iterator to the first arc.
  23.391 +
  23.392 +        /// Sets the iterator to the first arc of the given digraph.
  23.393          ///
  23.394 -        ArcIt(Invalid) { }
  23.395 -        /// This constructor sets the iterator to the first arc.
  23.396 +        explicit ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); }
  23.397 +        /// Sets the iterator to the given arc.
  23.398  
  23.399 -        /// This constructor sets the iterator to the first arc of \c g.
  23.400 -        ///@param g the digraph
  23.401 -        ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); }
  23.402 -        /// Arc -> ArcIt conversion
  23.403 -
  23.404 -        /// Sets the iterator to the value of the trivial iterator \c e.
  23.405 -        /// This feature necessitates that each time we
  23.406 -        /// iterate the arc-set, the iteration order is the same.
  23.407 +        /// Sets the iterator to the given arc of the given digraph.
  23.408 +        ///
  23.409          ArcIt(const Digraph&, const Arc&) { }
  23.410 -        ///Next arc
  23.411 +        /// Next arc
  23.412  
  23.413          /// Assign the iterator to the next arc.
  23.414 +        ///
  23.415          ArcIt& operator++() { return *this; }
  23.416        };
  23.417 -      ///Gives back the target node of an arc.
  23.418  
  23.419 -      ///Gives back the target node of an arc.
  23.420 +      /// \brief The source node of the arc.
  23.421        ///
  23.422 -      Node target(Arc) const { return INVALID; }
  23.423 -      ///Gives back the source node of an arc.
  23.424 -
  23.425 -      ///Gives back the source node of an arc.
  23.426 -      ///
  23.427 +      /// Returns the source node of the given arc.
  23.428        Node source(Arc) const { return INVALID; }
  23.429  
  23.430 -      /// \brief Returns the ID of the node.
  23.431 +      /// \brief The target node of the arc.
  23.432 +      ///
  23.433 +      /// Returns the target node of the given arc.
  23.434 +      Node target(Arc) const { return INVALID; }
  23.435 +
  23.436 +      /// \brief The ID of the node.
  23.437 +      ///
  23.438 +      /// Returns the ID of the given node.
  23.439        int id(Node) const { return -1; }
  23.440  
  23.441 -      /// \brief Returns the ID of the arc.
  23.442 +      /// \brief The ID of the arc.
  23.443 +      ///
  23.444 +      /// Returns the ID of the given arc.
  23.445        int id(Arc) const { return -1; }
  23.446  
  23.447 -      /// \brief Returns the node with the given ID.
  23.448 +      /// \brief The node with the given ID.
  23.449        ///
  23.450 -      /// \pre The argument should be a valid node ID in the graph.
  23.451 +      /// Returns the node with the given ID.
  23.452 +      /// \pre The argument should be a valid node ID in the digraph.
  23.453        Node nodeFromId(int) const { return INVALID; }
  23.454  
  23.455 -      /// \brief Returns the arc with the given ID.
  23.456 +      /// \brief The arc with the given ID.
  23.457        ///
  23.458 -      /// \pre The argument should be a valid arc ID in the graph.
  23.459 +      /// Returns the arc with the given ID.
  23.460 +      /// \pre The argument should be a valid arc ID in the digraph.
  23.461        Arc arcFromId(int) const { return INVALID; }
  23.462  
  23.463 -      /// \brief Returns an upper bound on the node IDs.
  23.464 +      /// \brief An upper bound on the node IDs.
  23.465 +      ///
  23.466 +      /// Returns an upper bound on the node IDs.
  23.467        int maxNodeId() const { return -1; }
  23.468  
  23.469 -      /// \brief Returns an upper bound on the arc IDs.
  23.470 +      /// \brief An upper bound on the arc IDs.
  23.471 +      ///
  23.472 +      /// Returns an upper bound on the arc IDs.
  23.473        int maxArcId() const { return -1; }
  23.474  
  23.475        void first(Node&) const {}
  23.476 @@ -392,45 +390,46 @@
  23.477        // Dummy parameter.
  23.478        int maxId(Arc) const { return -1; }
  23.479  
  23.480 +      /// \brief The opposite node on the arc.
  23.481 +      ///
  23.482 +      /// Returns the opposite node on the given arc.
  23.483 +      Node oppositeNode(Node, Arc) const { return INVALID; }
  23.484 +
  23.485        /// \brief The base node of the iterator.
  23.486        ///
  23.487 -      /// Gives back the base node of the iterator.
  23.488 -      /// It is always the target of the pointed arc.
  23.489 -      Node baseNode(const InArcIt&) const { return INVALID; }
  23.490 +      /// Returns the base node of the given outgoing arc iterator
  23.491 +      /// (i.e. the source node of the corresponding arc).
  23.492 +      Node baseNode(OutArcIt) const { return INVALID; }
  23.493  
  23.494        /// \brief The running node of the iterator.
  23.495        ///
  23.496 -      /// Gives back the running node of the iterator.
  23.497 -      /// It is always the source of the pointed arc.
  23.498 -      Node runningNode(const InArcIt&) const { return INVALID; }
  23.499 +      /// Returns the running node of the given outgoing arc iterator
  23.500 +      /// (i.e. the target node of the corresponding arc).
  23.501 +      Node runningNode(OutArcIt) const { return INVALID; }
  23.502  
  23.503        /// \brief The base node of the iterator.
  23.504        ///
  23.505 -      /// Gives back the base node of the iterator.
  23.506 -      /// It is always the source of the pointed arc.
  23.507 -      Node baseNode(const OutArcIt&) const { return INVALID; }
  23.508 +      /// Returns the base node of the given incomming arc iterator
  23.509 +      /// (i.e. the target node of the corresponding arc).
  23.510 +      Node baseNode(InArcIt) const { return INVALID; }
  23.511  
  23.512        /// \brief The running node of the iterator.
  23.513        ///
  23.514 -      /// Gives back the running node of the iterator.
  23.515 -      /// It is always the target of the pointed arc.
  23.516 -      Node runningNode(const OutArcIt&) const { return INVALID; }
  23.517 +      /// Returns the running node of the given incomming arc iterator
  23.518 +      /// (i.e. the source node of the corresponding arc).
  23.519 +      Node runningNode(InArcIt) const { return INVALID; }
  23.520  
  23.521 -      /// \brief The opposite node on the given arc.
  23.522 +      /// \brief Standard graph map type for the nodes.
  23.523        ///
  23.524 -      /// Gives back the opposite node on the given arc.
  23.525 -      Node oppositeNode(const Node&, const Arc&) const { return INVALID; }
  23.526 -
  23.527 -      /// \brief Reference map of the nodes to type \c T.
  23.528 -      ///
  23.529 -      /// Reference map of the nodes to type \c T.
  23.530 +      /// Standard graph map type for the nodes.
  23.531 +      /// It conforms to the ReferenceMap concept.
  23.532        template<class T>
  23.533        class NodeMap : public ReferenceMap<Node, T, T&, const T&> {
  23.534        public:
  23.535  
  23.536 -        ///\e
  23.537 -        NodeMap(const Digraph&) { }
  23.538 -        ///\e
  23.539 +        /// Constructor
  23.540 +        explicit NodeMap(const Digraph&) { }
  23.541 +        /// Constructor with given initial value
  23.542          NodeMap(const Digraph&, T) { }
  23.543  
  23.544        private:
  23.545 @@ -445,17 +444,19 @@
  23.546          }
  23.547        };
  23.548  
  23.549 -      /// \brief Reference map of the arcs to type \c T.
  23.550 +      /// \brief Standard graph map type for the arcs.
  23.551        ///
  23.552 -      /// Reference map of the arcs to type \c T.
  23.553 +      /// Standard graph map type for the arcs.
  23.554 +      /// It conforms to the ReferenceMap concept.
  23.555        template<class T>
  23.556        class ArcMap : public ReferenceMap<Arc, T, T&, const T&> {
  23.557        public:
  23.558  
  23.559 -        ///\e
  23.560 -        ArcMap(const Digraph&) { }
  23.561 -        ///\e
  23.562 +        /// Constructor
  23.563 +        explicit ArcMap(const Digraph&) { }
  23.564 +        /// Constructor with given initial value
  23.565          ArcMap(const Digraph&, T) { }
  23.566 +
  23.567        private:
  23.568          ///Copy constructor
  23.569          ArcMap(const ArcMap& em) :
    24.1 --- a/lemon/concepts/graph.h	Thu Nov 05 10:01:02 2009 +0100
    24.2 +++ b/lemon/concepts/graph.h	Thu Nov 05 10:23:16 2009 +0100
    24.3 @@ -18,12 +18,14 @@
    24.4  
    24.5  ///\ingroup graph_concepts
    24.6  ///\file
    24.7 -///\brief The concept of Undirected Graphs.
    24.8 +///\brief The concept of undirected graphs.
    24.9  
   24.10  #ifndef LEMON_CONCEPTS_GRAPH_H
   24.11  #define LEMON_CONCEPTS_GRAPH_H
   24.12  
   24.13  #include <lemon/concepts/graph_components.h>
   24.14 +#include <lemon/concepts/maps.h>
   24.15 +#include <lemon/concept_check.h>
   24.16  #include <lemon/core.h>
   24.17  
   24.18  namespace lemon {
   24.19 @@ -31,63 +33,74 @@
   24.20  
   24.21      /// \ingroup graph_concepts
   24.22      ///
   24.23 -    /// \brief Class describing the concept of Undirected Graphs.
   24.24 +    /// \brief Class describing the concept of undirected graphs.
   24.25      ///
   24.26 -    /// This class describes the common interface of all Undirected
   24.27 -    /// Graphs.
   24.28 +    /// This class describes the common interface of all undirected
   24.29 +    /// graphs.
   24.30      ///
   24.31 -    /// As all concept describing classes it provides only interface
   24.32 -    /// without any sensible implementation. So any algorithm for
   24.33 -    /// undirected graph should compile with this class, but it will not
   24.34 +    /// Like all concept classes, it only provides an interface
   24.35 +    /// without any sensible implementation. So any general algorithm for
   24.36 +    /// undirected graphs should compile with this class, but it will not
   24.37      /// run properly, of course.
   24.38 +    /// An actual graph implementation like \ref ListGraph or
   24.39 +    /// \ref SmartGraph may have additional functionality.    
   24.40      ///
   24.41 -    /// The LEMON undirected graphs also fulfill the concept of
   24.42 -    /// directed graphs (\ref lemon::concepts::Digraph "Digraph
   24.43 -    /// Concept"). Each edges can be seen as two opposite
   24.44 -    /// directed arc and consequently the undirected graph can be
   24.45 -    /// seen as the direceted graph of these directed arcs. The
   24.46 -    /// Graph has the Edge inner class for the edges and
   24.47 -    /// the Arc type for the directed arcs. The Arc type is
   24.48 -    /// convertible to Edge or inherited from it so from a directed
   24.49 -    /// arc we can get the represented edge.
   24.50 +    /// The undirected graphs also fulfill the concept of \ref Digraph
   24.51 +    /// "directed graphs", since each edge can also be regarded as two
   24.52 +    /// oppositely directed arcs.
   24.53 +    /// Undirected graphs provide an Edge type for the undirected edges and
   24.54 +    /// an Arc type for the directed arcs. The Arc type is convertible to
   24.55 +    /// Edge or inherited from it, i.e. the corresponding edge can be
   24.56 +    /// obtained from an arc.
   24.57 +    /// EdgeIt and EdgeMap classes can be used for the edges, while ArcIt
   24.58 +    /// and ArcMap classes can be used for the arcs (just like in digraphs).
   24.59 +    /// Both InArcIt and OutArcIt iterates on the same edges but with
   24.60 +    /// opposite direction. IncEdgeIt also iterates on the same edges
   24.61 +    /// as OutArcIt and InArcIt, but it is not convertible to Arc,
   24.62 +    /// only to Edge.
   24.63      ///
   24.64 -    /// In the sense of the LEMON each edge has a default
   24.65 -    /// direction (it should be in every computer implementation,
   24.66 -    /// because the order of edge's nodes defines an
   24.67 -    /// orientation). With the default orientation we can define that
   24.68 -    /// the directed arc is forward or backward directed. With the \c
   24.69 -    /// direction() and \c direct() function we can get the direction
   24.70 -    /// of the directed arc and we can direct an edge.
   24.71 +    /// In LEMON, each undirected edge has an inherent orientation.
   24.72 +    /// Thus it can defined if an arc is forward or backward oriented in
   24.73 +    /// an undirected graph with respect to this default oriantation of
   24.74 +    /// the represented edge.
   24.75 +    /// With the direction() and direct() functions the direction
   24.76 +    /// of an arc can be obtained and set, respectively.
   24.77      ///
   24.78 -    /// The EdgeIt is an iterator for the edges. We can use
   24.79 -    /// the EdgeMap to map values for the edges. The InArcIt and
   24.80 -    /// OutArcIt iterates on the same edges but with opposite
   24.81 -    /// direction. The IncEdgeIt iterates also on the same edges
   24.82 -    /// as the OutArcIt and InArcIt but it is not convertible to Arc just
   24.83 -    /// to Edge.
   24.84 +    /// Only nodes and edges can be added to or removed from an undirected
   24.85 +    /// graph and the corresponding arcs are added or removed automatically.
   24.86 +    ///
   24.87 +    /// \sa Digraph
   24.88      class Graph {
   24.89 +    private:
   24.90 +      /// Graphs are \e not copy constructible. Use DigraphCopy instead.
   24.91 +      Graph(const Graph&) {}
   24.92 +      /// \brief Assignment of a graph to another one is \e not allowed.
   24.93 +      /// Use DigraphCopy instead.
   24.94 +      void operator=(const Graph&) {}
   24.95 +
   24.96      public:
   24.97 -      /// \brief The undirected graph should be tagged by the
   24.98 -      /// UndirectedTag.
   24.99 +      /// Default constructor.
  24.100 +      Graph() {}
  24.101 +
  24.102 +      /// \brief Undirected graphs should be tagged with \c UndirectedTag.
  24.103        ///
  24.104 -      /// The undirected graph should be tagged by the UndirectedTag. This
  24.105 -      /// tag helps the enable_if technics to make compile time
  24.106 +      /// Undirected graphs should be tagged with \c UndirectedTag.
  24.107 +      /// 
  24.108 +      /// This tag helps the \c enable_if technics to make compile time
  24.109        /// specializations for undirected graphs.
  24.110        typedef True UndirectedTag;
  24.111  
  24.112 -      /// \brief The base type of node iterators,
  24.113 -      /// or in other words, the trivial node iterator.
  24.114 -      ///
  24.115 -      /// This is the base type of each node iterator,
  24.116 -      /// thus each kind of node iterator converts to this.
  24.117 -      /// More precisely each kind of node iterator should be inherited
  24.118 -      /// from the trivial node iterator.
  24.119 +      /// The node type of the graph
  24.120 +
  24.121 +      /// This class identifies a node of the graph. It also serves
  24.122 +      /// as a base class of the node iterators,
  24.123 +      /// thus they convert to this type.
  24.124        class Node {
  24.125        public:
  24.126          /// Default constructor
  24.127  
  24.128 -        /// @warning The default constructor sets the iterator
  24.129 -        /// to an undefined value.
  24.130 +        /// Default constructor.
  24.131 +        /// \warning It sets the object to an undefined value.
  24.132          Node() { }
  24.133          /// Copy constructor.
  24.134  
  24.135 @@ -95,40 +108,40 @@
  24.136          ///
  24.137          Node(const Node&) { }
  24.138  
  24.139 -        /// Invalid constructor \& conversion.
  24.140 +        /// %Invalid constructor \& conversion.
  24.141  
  24.142 -        /// This constructor initializes the iterator to be invalid.
  24.143 +        /// Initializes the object to be invalid.
  24.144          /// \sa Invalid for more details.
  24.145          Node(Invalid) { }
  24.146          /// Equality operator
  24.147  
  24.148 +        /// Equality operator.
  24.149 +        ///
  24.150          /// Two iterators are equal if and only if they point to the
  24.151 -        /// same object or both are invalid.
  24.152 +        /// same object or both are \c INVALID.
  24.153          bool operator==(Node) const { return true; }
  24.154  
  24.155          /// Inequality operator
  24.156  
  24.157 -        /// \sa operator==(Node n)
  24.158 -        ///
  24.159 +        /// Inequality operator.
  24.160          bool operator!=(Node) const { return true; }
  24.161  
  24.162          /// Artificial ordering operator.
  24.163  
  24.164 -        /// To allow the use of graph descriptors as key type in std::map or
  24.165 -        /// similar associative container we require this.
  24.166 +        /// Artificial ordering operator.
  24.167          ///
  24.168 -        /// \note This operator only have to define some strict ordering of
  24.169 +        /// \note This operator only has to define some strict ordering of
  24.170          /// the items; this order has nothing to do with the iteration
  24.171          /// ordering of the items.
  24.172          bool operator<(Node) const { return false; }
  24.173  
  24.174        };
  24.175  
  24.176 -      /// This iterator goes through each node.
  24.177 +      /// Iterator class for the nodes.
  24.178  
  24.179 -      /// This iterator goes through each node.
  24.180 +      /// This iterator goes through each node of the graph.
  24.181        /// Its usage is quite simple, for example you can count the number
  24.182 -      /// of nodes in graph \c g of type \c Graph like this:
  24.183 +      /// of nodes in a graph \c g of type \c %Graph like this:
  24.184        ///\code
  24.185        /// int count=0;
  24.186        /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
  24.187 @@ -137,30 +150,28 @@
  24.188        public:
  24.189          /// Default constructor
  24.190  
  24.191 -        /// @warning The default constructor sets the iterator
  24.192 -        /// to an undefined value.
  24.193 +        /// Default constructor.
  24.194 +        /// \warning It sets the iterator to an undefined value.
  24.195          NodeIt() { }
  24.196          /// Copy constructor.
  24.197  
  24.198          /// Copy constructor.
  24.199          ///
  24.200          NodeIt(const NodeIt& n) : Node(n) { }
  24.201 -        /// Invalid constructor \& conversion.
  24.202 +        /// %Invalid constructor \& conversion.
  24.203  
  24.204 -        /// Initialize the iterator to be invalid.
  24.205 +        /// Initializes the iterator to be invalid.
  24.206          /// \sa Invalid for more details.
  24.207          NodeIt(Invalid) { }
  24.208          /// Sets the iterator to the first node.
  24.209  
  24.210 -        /// Sets the iterator to the first node of \c g.
  24.211 +        /// Sets the iterator to the first node of the given digraph.
  24.212          ///
  24.213 -        NodeIt(const Graph&) { }
  24.214 -        /// Node -> NodeIt conversion.
  24.215 +        explicit NodeIt(const Graph&) { }
  24.216 +        /// Sets the iterator to the given node.
  24.217  
  24.218 -        /// Sets the iterator to the node of \c the graph pointed by
  24.219 -        /// the trivial iterator.
  24.220 -        /// This feature necessitates that each time we
  24.221 -        /// iterate the arc-set, the iteration order is the same.
  24.222 +        /// Sets the iterator to the given node of the given digraph.
  24.223 +        ///
  24.224          NodeIt(const Graph&, const Node&) { }
  24.225          /// Next node.
  24.226  
  24.227 @@ -170,54 +181,55 @@
  24.228        };
  24.229  
  24.230  
  24.231 -      /// The base type of the edge iterators.
  24.232 +      /// The edge type of the graph
  24.233  
  24.234 -      /// The base type of the edge iterators.
  24.235 -      ///
  24.236 +      /// This class identifies an edge of the graph. It also serves
  24.237 +      /// as a base class of the edge iterators,
  24.238 +      /// thus they will convert to this type.
  24.239        class Edge {
  24.240        public:
  24.241          /// Default constructor
  24.242  
  24.243 -        /// @warning The default constructor sets the iterator
  24.244 -        /// to an undefined value.
  24.245 +        /// Default constructor.
  24.246 +        /// \warning It sets the object to an undefined value.
  24.247          Edge() { }
  24.248          /// Copy constructor.
  24.249  
  24.250          /// Copy constructor.
  24.251          ///
  24.252          Edge(const Edge&) { }
  24.253 -        /// Initialize the iterator to be invalid.
  24.254 +        /// %Invalid constructor \& conversion.
  24.255  
  24.256 -        /// Initialize the iterator to be invalid.
  24.257 -        ///
  24.258 +        /// Initializes the object to be invalid.
  24.259 +        /// \sa Invalid for more details.
  24.260          Edge(Invalid) { }
  24.261          /// Equality operator
  24.262  
  24.263 +        /// Equality operator.
  24.264 +        ///
  24.265          /// Two iterators are equal if and only if they point to the
  24.266 -        /// same object or both are invalid.
  24.267 +        /// same object or both are \c INVALID.
  24.268          bool operator==(Edge) const { return true; }
  24.269          /// Inequality operator
  24.270  
  24.271 -        /// \sa operator==(Edge n)
  24.272 -        ///
  24.273 +        /// Inequality operator.
  24.274          bool operator!=(Edge) const { return true; }
  24.275  
  24.276          /// Artificial ordering operator.
  24.277  
  24.278 -        /// To allow the use of graph descriptors as key type in std::map or
  24.279 -        /// similar associative container we require this.
  24.280 +        /// Artificial ordering operator.
  24.281          ///
  24.282 -        /// \note This operator only have to define some strict ordering of
  24.283 -        /// the items; this order has nothing to do with the iteration
  24.284 -        /// ordering of the items.
  24.285 +        /// \note This operator only has to define some strict ordering of
  24.286 +        /// the edges; this order has nothing to do with the iteration
  24.287 +        /// ordering of the edges.
  24.288          bool operator<(Edge) const { return false; }
  24.289        };
  24.290  
  24.291 -      /// This iterator goes through each edge.
  24.292 +      /// Iterator class for the edges.
  24.293  
  24.294 -      /// This iterator goes through each edge of a graph.
  24.295 +      /// This iterator goes through each edge of the graph.
  24.296        /// Its usage is quite simple, for example you can count the number
  24.297 -      /// of edges in a graph \c g of type \c Graph as follows:
  24.298 +      /// of edges in a graph \c g of type \c %Graph as follows:
  24.299        ///\code
  24.300        /// int count=0;
  24.301        /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
  24.302 @@ -226,290 +238,285 @@
  24.303        public:
  24.304          /// Default constructor
  24.305  
  24.306 -        /// @warning The default constructor sets the iterator
  24.307 -        /// to an undefined value.
  24.308 +        /// Default constructor.
  24.309 +        /// \warning It sets the iterator to an undefined value.
  24.310          EdgeIt() { }
  24.311          /// Copy constructor.
  24.312  
  24.313          /// Copy constructor.
  24.314          ///
  24.315          EdgeIt(const EdgeIt& e) : Edge(e) { }
  24.316 -        /// Initialize the iterator to be invalid.
  24.317 +        /// %Invalid constructor \& conversion.
  24.318  
  24.319 -        /// Initialize the iterator to be invalid.
  24.320 +        /// Initializes the iterator to be invalid.
  24.321 +        /// \sa Invalid for more details.
  24.322 +        EdgeIt(Invalid) { }
  24.323 +        /// Sets the iterator to the first edge.
  24.324 +
  24.325 +        /// Sets the iterator to the first edge of the given graph.
  24.326          ///
  24.327 -        EdgeIt(Invalid) { }
  24.328 -        /// This constructor sets the iterator to the first edge.
  24.329 +        explicit EdgeIt(const Graph&) { }
  24.330 +        /// Sets the iterator to the given edge.
  24.331  
  24.332 -        /// This constructor sets the iterator to the first edge.
  24.333 -        EdgeIt(const Graph&) { }
  24.334 -        /// Edge -> EdgeIt conversion
  24.335 -
  24.336 -        /// Sets the iterator to the value of the trivial iterator.
  24.337 -        /// This feature necessitates that each time we
  24.338 -        /// iterate the edge-set, the iteration order is the
  24.339 -        /// same.
  24.340 +        /// Sets the iterator to the given edge of the given graph.
  24.341 +        ///
  24.342          EdgeIt(const Graph&, const Edge&) { }
  24.343          /// Next edge
  24.344  
  24.345          /// Assign the iterator to the next edge.
  24.346 +        ///
  24.347          EdgeIt& operator++() { return *this; }
  24.348        };
  24.349  
  24.350 -      /// \brief This iterator goes trough the incident undirected
  24.351 -      /// arcs of a node.
  24.352 -      ///
  24.353 -      /// This iterator goes trough the incident edges
  24.354 -      /// of a certain node of a graph. You should assume that the
  24.355 -      /// loop arcs will be iterated twice.
  24.356 -      ///
  24.357 +      /// Iterator class for the incident edges of a node.
  24.358 +
  24.359 +      /// This iterator goes trough the incident undirected edges
  24.360 +      /// of a certain node of a graph.
  24.361        /// Its usage is quite simple, for example you can compute the
  24.362 -      /// degree (i.e. count the number of incident arcs of a node \c n
  24.363 -      /// in graph \c g of type \c Graph as follows.
  24.364 +      /// degree (i.e. the number of incident edges) of a node \c n
  24.365 +      /// in a graph \c g of type \c %Graph as follows.
  24.366        ///
  24.367        ///\code
  24.368        /// int count=0;
  24.369        /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count;
  24.370        ///\endcode
  24.371 +      ///
  24.372 +      /// \warning Loop edges will be iterated twice.
  24.373        class IncEdgeIt : public Edge {
  24.374        public:
  24.375          /// Default constructor
  24.376  
  24.377 -        /// @warning The default constructor sets the iterator
  24.378 -        /// to an undefined value.
  24.379 +        /// Default constructor.
  24.380 +        /// \warning It sets the iterator to an undefined value.
  24.381          IncEdgeIt() { }
  24.382          /// Copy constructor.
  24.383  
  24.384          /// Copy constructor.
  24.385          ///
  24.386          IncEdgeIt(const IncEdgeIt& e) : Edge(e) { }
  24.387 -        /// Initialize the iterator to be invalid.
  24.388 +        /// %Invalid constructor \& conversion.
  24.389  
  24.390 -        /// Initialize the iterator to be invalid.
  24.391 +        /// Initializes the iterator to be invalid.
  24.392 +        /// \sa Invalid for more details.
  24.393 +        IncEdgeIt(Invalid) { }
  24.394 +        /// Sets the iterator to the first incident edge.
  24.395 +
  24.396 +        /// Sets the iterator to the first incident edge of the given node.
  24.397          ///
  24.398 -        IncEdgeIt(Invalid) { }
  24.399 -        /// This constructor sets the iterator to first incident arc.
  24.400 +        IncEdgeIt(const Graph&, const Node&) { }
  24.401 +        /// Sets the iterator to the given edge.
  24.402  
  24.403 -        /// This constructor set the iterator to the first incident arc of
  24.404 -        /// the node.
  24.405 -        IncEdgeIt(const Graph&, const Node&) { }
  24.406 -        /// Edge -> IncEdgeIt conversion
  24.407 +        /// Sets the iterator to the given edge of the given graph.
  24.408 +        ///
  24.409 +        IncEdgeIt(const Graph&, const Edge&) { }
  24.410 +        /// Next incident edge
  24.411  
  24.412 -        /// Sets the iterator to the value of the trivial iterator \c e.
  24.413 -        /// This feature necessitates that each time we
  24.414 -        /// iterate the arc-set, the iteration order is the same.
  24.415 -        IncEdgeIt(const Graph&, const Edge&) { }
  24.416 -        /// Next incident arc
  24.417 -
  24.418 -        /// Assign the iterator to the next incident arc
  24.419 +        /// Assign the iterator to the next incident edge
  24.420          /// of the corresponding node.
  24.421          IncEdgeIt& operator++() { return *this; }
  24.422        };
  24.423  
  24.424 -      /// The directed arc type.
  24.425 +      /// The arc type of the graph
  24.426  
  24.427 -      /// The directed arc type. It can be converted to the
  24.428 -      /// edge or it should be inherited from the undirected
  24.429 -      /// edge.
  24.430 +      /// This class identifies a directed arc of the graph. It also serves
  24.431 +      /// as a base class of the arc iterators,
  24.432 +      /// thus they will convert to this type.
  24.433        class Arc {
  24.434        public:
  24.435          /// Default constructor
  24.436  
  24.437 -        /// @warning The default constructor sets the iterator
  24.438 -        /// to an undefined value.
  24.439 +        /// Default constructor.
  24.440 +        /// \warning It sets the object to an undefined value.
  24.441          Arc() { }
  24.442          /// Copy constructor.
  24.443  
  24.444          /// Copy constructor.
  24.445          ///
  24.446          Arc(const Arc&) { }
  24.447 -        /// Initialize the iterator to be invalid.
  24.448 +        /// %Invalid constructor \& conversion.
  24.449  
  24.450 -        /// Initialize the iterator to be invalid.
  24.451 -        ///
  24.452 +        /// Initializes the object to be invalid.
  24.453 +        /// \sa Invalid for more details.
  24.454          Arc(Invalid) { }
  24.455          /// Equality operator
  24.456  
  24.457 +        /// Equality operator.
  24.458 +        ///
  24.459          /// Two iterators are equal if and only if they point to the
  24.460 -        /// same object or both are invalid.
  24.461 +        /// same object or both are \c INVALID.
  24.462          bool operator==(Arc) const { return true; }
  24.463          /// Inequality operator
  24.464  
  24.465 -        /// \sa operator==(Arc n)
  24.466 -        ///
  24.467 +        /// Inequality operator.
  24.468          bool operator!=(Arc) const { return true; }
  24.469  
  24.470          /// Artificial ordering operator.
  24.471  
  24.472 -        /// To allow the use of graph descriptors as key type in std::map or
  24.473 -        /// similar associative container we require this.
  24.474 +        /// Artificial ordering operator.
  24.475          ///
  24.476 -        /// \note This operator only have to define some strict ordering of
  24.477 -        /// the items; this order has nothing to do with the iteration
  24.478 -        /// ordering of the items.
  24.479 +        /// \note This operator only has to define some strict ordering of
  24.480 +        /// the arcs; this order has nothing to do with the iteration
  24.481 +        /// ordering of the arcs.
  24.482          bool operator<(Arc) const { return false; }
  24.483  
  24.484 -        /// Converison to Edge
  24.485 +        /// Converison to \c Edge
  24.486 +        
  24.487 +        /// Converison to \c Edge.
  24.488 +        ///
  24.489          operator Edge() const { return Edge(); }
  24.490        };
  24.491 -      /// This iterator goes through each directed arc.
  24.492  
  24.493 -      /// This iterator goes through each arc of a graph.
  24.494 +      /// Iterator class for the arcs.
  24.495 +
  24.496 +      /// This iterator goes through each directed arc of the graph.
  24.497        /// Its usage is quite simple, for example you can count the number
  24.498 -      /// of arcs in a graph \c g of type \c Graph as follows:
  24.499 +      /// of arcs in a graph \c g of type \c %Graph as follows:
  24.500        ///\code
  24.501        /// int count=0;
  24.502 -      /// for(Graph::ArcIt e(g); e!=INVALID; ++e) ++count;
  24.503 +      /// for(Graph::ArcIt a(g); a!=INVALID; ++a) ++count;
  24.504        ///\endcode
  24.505        class ArcIt : public Arc {
  24.506        public:
  24.507          /// Default constructor
  24.508  
  24.509 -        /// @warning The default constructor sets the iterator
  24.510 -        /// to an undefined value.
  24.511 +        /// Default constructor.
  24.512 +        /// \warning It sets the iterator to an undefined value.
  24.513          ArcIt() { }
  24.514          /// Copy constructor.
  24.515  
  24.516          /// Copy constructor.
  24.517          ///
  24.518          ArcIt(const ArcIt& e) : Arc(e) { }
  24.519 -        /// Initialize the iterator to be invalid.
  24.520 +        /// %Invalid constructor \& conversion.
  24.521  
  24.522 -        /// Initialize the iterator to be invalid.
  24.523 +        /// Initializes the iterator to be invalid.
  24.524 +        /// \sa Invalid for more details.
  24.525 +        ArcIt(Invalid) { }
  24.526 +        /// Sets the iterator to the first arc.
  24.527 +
  24.528 +        /// Sets the iterator to the first arc of the given graph.
  24.529          ///
  24.530 -        ArcIt(Invalid) { }
  24.531 -        /// This constructor sets the iterator to the first arc.
  24.532 +        explicit ArcIt(const Graph &g) { ignore_unused_variable_warning(g); }
  24.533 +        /// Sets the iterator to the given arc.
  24.534  
  24.535 -        /// This constructor sets the iterator to the first arc of \c g.
  24.536 -        ///@param g the graph
  24.537 -        ArcIt(const Graph &g) { ignore_unused_variable_warning(g); }
  24.538 -        /// Arc -> ArcIt conversion
  24.539 -
  24.540 -        /// Sets the iterator to the value of the trivial iterator \c e.
  24.541 -        /// This feature necessitates that each time we
  24.542 -        /// iterate the arc-set, the iteration order is the same.
  24.543 +        /// Sets the iterator to the given arc of the given graph.
  24.544 +        ///
  24.545          ArcIt(const Graph&, const Arc&) { }
  24.546 -        ///Next arc
  24.547 +        /// Next arc
  24.548  
  24.549          /// Assign the iterator to the next arc.
  24.550 +        ///
  24.551          ArcIt& operator++() { return *this; }
  24.552        };
  24.553  
  24.554 -      /// This iterator goes trough the outgoing directed arcs of a node.
  24.555 +      /// Iterator class for the outgoing arcs of a node.
  24.556  
  24.557 -      /// This iterator goes trough the \e outgoing arcs of a certain node
  24.558 -      /// of a graph.
  24.559 +      /// This iterator goes trough the \e outgoing directed arcs of a
  24.560 +      /// certain node of a graph.
  24.561        /// Its usage is quite simple, for example you can count the number
  24.562        /// of outgoing arcs of a node \c n
  24.563 -      /// in graph \c g of type \c Graph as follows.
  24.564 +      /// in a graph \c g of type \c %Graph as follows.
  24.565        ///\code
  24.566        /// int count=0;
  24.567 -      /// for (Graph::OutArcIt e(g, n); e!=INVALID; ++e) ++count;
  24.568 +      /// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count;
  24.569        ///\endcode
  24.570 -
  24.571        class OutArcIt : public Arc {
  24.572        public:
  24.573          /// Default constructor
  24.574  
  24.575 -        /// @warning The default constructor sets the iterator
  24.576 -        /// to an undefined value.
  24.577 +        /// Default constructor.
  24.578 +        /// \warning It sets the iterator to an undefined value.
  24.579          OutArcIt() { }
  24.580          /// Copy constructor.
  24.581  
  24.582          /// Copy constructor.
  24.583          ///
  24.584          OutArcIt(const OutArcIt& e) : Arc(e) { }
  24.585 -        /// Initialize the iterator to be invalid.
  24.586 +        /// %Invalid constructor \& conversion.
  24.587  
  24.588 -        /// Initialize the iterator to be invalid.
  24.589 +        /// Initializes the iterator to be invalid.
  24.590 +        /// \sa Invalid for more details.
  24.591 +        OutArcIt(Invalid) { }
  24.592 +        /// Sets the iterator to the first outgoing arc.
  24.593 +
  24.594 +        /// Sets the iterator to the first outgoing arc of the given node.
  24.595          ///
  24.596 -        OutArcIt(Invalid) { }
  24.597 -        /// This constructor sets the iterator to the first outgoing arc.
  24.598 -
  24.599 -        /// This constructor sets the iterator to the first outgoing arc of
  24.600 -        /// the node.
  24.601 -        ///@param n the node
  24.602 -        ///@param g the graph
  24.603          OutArcIt(const Graph& n, const Node& g) {
  24.604            ignore_unused_variable_warning(n);
  24.605            ignore_unused_variable_warning(g);
  24.606          }
  24.607 -        /// Arc -> OutArcIt conversion
  24.608 +        /// Sets the iterator to the given arc.
  24.609  
  24.610 -        /// Sets the iterator to the value of the trivial iterator.
  24.611 -        /// This feature necessitates that each time we
  24.612 -        /// iterate the arc-set, the iteration order is the same.
  24.613 +        /// Sets the iterator to the given arc of the given graph.
  24.614 +        ///
  24.615          OutArcIt(const Graph&, const Arc&) { }
  24.616 -        ///Next outgoing arc
  24.617 +        /// Next outgoing arc
  24.618  
  24.619          /// Assign the iterator to the next
  24.620          /// outgoing arc of the corresponding node.
  24.621          OutArcIt& operator++() { return *this; }
  24.622        };
  24.623  
  24.624 -      /// This iterator goes trough the incoming directed arcs of a node.
  24.625 +      /// Iterator class for the incoming arcs of a node.
  24.626  
  24.627 -      /// This iterator goes trough the \e incoming arcs of a certain node
  24.628 -      /// of a graph.
  24.629 +      /// This iterator goes trough the \e incoming directed arcs of a
  24.630 +      /// certain node of a graph.
  24.631        /// Its usage is quite simple, for example you can count the number
  24.632 -      /// of outgoing arcs of a node \c n
  24.633 -      /// in graph \c g of type \c Graph as follows.
  24.634 +      /// of incoming arcs of a node \c n
  24.635 +      /// in a graph \c g of type \c %Graph as follows.
  24.636        ///\code
  24.637        /// int count=0;
  24.638 -      /// for(Graph::InArcIt e(g, n); e!=INVALID; ++e) ++count;
  24.639 +      /// for (Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count;
  24.640        ///\endcode
  24.641 -
  24.642        class InArcIt : public Arc {
  24.643        public:
  24.644          /// Default constructor
  24.645  
  24.646 -        /// @warning The default constructor sets the iterator
  24.647 -        /// to an undefined value.
  24.648 +        /// Default constructor.
  24.649 +        /// \warning It sets the iterator to an undefined value.
  24.650          InArcIt() { }
  24.651          /// Copy constructor.
  24.652  
  24.653          /// Copy constructor.
  24.654          ///
  24.655          InArcIt(const InArcIt& e) : Arc(e) { }
  24.656 -        /// Initialize the iterator to be invalid.
  24.657 +        /// %Invalid constructor \& conversion.
  24.658  
  24.659 -        /// Initialize the iterator to be invalid.
  24.660 +        /// Initializes the iterator to be invalid.
  24.661 +        /// \sa Invalid for more details.
  24.662 +        InArcIt(Invalid) { }
  24.663 +        /// Sets the iterator to the first incoming arc.
  24.664 +
  24.665 +        /// Sets the iterator to the first incoming arc of the given node.
  24.666          ///
  24.667 -        InArcIt(Invalid) { }
  24.668 -        /// This constructor sets the iterator to first incoming arc.
  24.669 -
  24.670 -        /// This constructor set the iterator to the first incoming arc of
  24.671 -        /// the node.
  24.672 -        ///@param n the node
  24.673 -        ///@param g the graph
  24.674          InArcIt(const Graph& g, const Node& n) {
  24.675            ignore_unused_variable_warning(n);
  24.676            ignore_unused_variable_warning(g);
  24.677          }
  24.678 -        /// Arc -> InArcIt conversion
  24.679 +        /// Sets the iterator to the given arc.
  24.680  
  24.681 -        /// Sets the iterator to the value of the trivial iterator \c e.
  24.682 -        /// This feature necessitates that each time we
  24.683 -        /// iterate the arc-set, the iteration order is the same.
  24.684 +        /// Sets the iterator to the given arc of the given graph.
  24.685 +        ///
  24.686          InArcIt(const Graph&, const Arc&) { }
  24.687          /// Next incoming arc
  24.688  
  24.689 -        /// Assign the iterator to the next inarc of the corresponding node.
  24.690 -        ///
  24.691 +        /// Assign the iterator to the next
  24.692 +        /// incoming arc of the corresponding node.
  24.693          InArcIt& operator++() { return *this; }
  24.694        };
  24.695  
  24.696 -      /// \brief Reference map of the nodes to type \c T.
  24.697 +      /// \brief Standard graph map type for the nodes.
  24.698        ///
  24.699 -      /// Reference map of the nodes to type \c T.
  24.700 +      /// Standard graph map type for the nodes.
  24.701 +      /// It conforms to the ReferenceMap concept.
  24.702        template<class T>
  24.703        class NodeMap : public ReferenceMap<Node, T, T&, const T&>
  24.704        {
  24.705        public:
  24.706  
  24.707 -        ///\e
  24.708 -        NodeMap(const Graph&) { }
  24.709 -        ///\e
  24.710 +        /// Constructor
  24.711 +        explicit NodeMap(const Graph&) { }
  24.712 +        /// Constructor with given initial value
  24.713          NodeMap(const Graph&, T) { }
  24.714  
  24.715        private:
  24.716 @@ -524,18 +531,20 @@
  24.717          }
  24.718        };
  24.719  
  24.720 -      /// \brief Reference map of the arcs to type \c T.
  24.721 +      /// \brief Standard graph map type for the arcs.
  24.722        ///
  24.723 -      /// Reference map of the arcs to type \c T.
  24.724 +      /// Standard graph map type for the arcs.
  24.725 +      /// It conforms to the ReferenceMap concept.
  24.726        template<class T>
  24.727        class ArcMap : public ReferenceMap<Arc, T, T&, const T&>
  24.728        {
  24.729        public:
  24.730  
  24.731 -        ///\e
  24.732 -        ArcMap(const Graph&) { }
  24.733 -        ///\e
  24.734 +        /// Constructor
  24.735 +        explicit ArcMap(const Graph&) { }
  24.736 +        /// Constructor with given initial value
  24.737          ArcMap(const Graph&, T) { }
  24.738 +
  24.739        private:
  24.740          ///Copy constructor
  24.741          ArcMap(const ArcMap& em) :
  24.742 @@ -548,18 +557,20 @@
  24.743          }
  24.744        };
  24.745  
  24.746 -      /// Reference map of the edges to type \c T.
  24.747 -
  24.748 -      /// Reference map of the edges to type \c T.
  24.749 +      /// \brief Standard graph map type for the edges.
  24.750 +      ///
  24.751 +      /// Standard graph map type for the edges.
  24.752 +      /// It conforms to the ReferenceMap concept.
  24.753        template<class T>
  24.754        class EdgeMap : public ReferenceMap<Edge, T, T&, const T&>
  24.755        {
  24.756        public:
  24.757  
  24.758 -        ///\e
  24.759 -        EdgeMap(const Graph&) { }
  24.760 -        ///\e
  24.761 +        /// Constructor
  24.762 +        explicit EdgeMap(const Graph&) { }
  24.763 +        /// Constructor with given initial value
  24.764          EdgeMap(const Graph&, T) { }
  24.765 +
  24.766        private:
  24.767          ///Copy constructor
  24.768          EdgeMap(const EdgeMap& em) :
  24.769 @@ -572,107 +583,124 @@
  24.770          }
  24.771        };
  24.772  
  24.773 -      /// \brief Direct the given edge.
  24.774 +      /// \brief The first node of the edge.
  24.775        ///
  24.776 -      /// Direct the given edge. The returned arc source
  24.777 -      /// will be the given node.
  24.778 -      Arc direct(const Edge&, const Node&) const {
  24.779 -        return INVALID;
  24.780 -      }
  24.781 -
  24.782 -      /// \brief Direct the given edge.
  24.783 +      /// Returns the first node of the given edge.
  24.784        ///
  24.785 -      /// Direct the given edge. The returned arc
  24.786 -      /// represents the given edge and the direction comes
  24.787 -      /// from the bool parameter. The source of the edge and
  24.788 -      /// the directed arc is the same when the given bool is true.
  24.789 -      Arc direct(const Edge&, bool) const {
  24.790 -        return INVALID;
  24.791 -      }
  24.792 -
  24.793 -      /// \brief Returns true if the arc has default orientation.
  24.794 -      ///
  24.795 -      /// Returns whether the given directed arc is same orientation as
  24.796 -      /// the corresponding edge's default orientation.
  24.797 -      bool direction(Arc) const { return true; }
  24.798 -
  24.799 -      /// \brief Returns the opposite directed arc.
  24.800 -      ///
  24.801 -      /// Returns the opposite directed arc.
  24.802 -      Arc oppositeArc(Arc) const { return INVALID; }
  24.803 -
  24.804 -      /// \brief Opposite node on an arc
  24.805 -      ///
  24.806 -      /// \return The opposite of the given node on the given edge.
  24.807 -      Node oppositeNode(Node, Edge) const { return INVALID; }
  24.808 -
  24.809 -      /// \brief First node of the edge.
  24.810 -      ///
  24.811 -      /// \return The first node of the given edge.
  24.812 -      ///
  24.813 -      /// Naturally edges don't have direction and thus
  24.814 -      /// don't have source and target node. However we use \c u() and \c v()
  24.815 -      /// methods to query the two nodes of the arc. The direction of the
  24.816 -      /// arc which arises this way is called the inherent direction of the
  24.817 -      /// edge, and is used to define the "default" direction
  24.818 -      /// of the directed versions of the arcs.
  24.819 +      /// Edges don't have source and target nodes, however methods
  24.820 +      /// u() and v() are used to query the two end-nodes of an edge.
  24.821 +      /// The orientation of an edge that arises this way is called
  24.822 +      /// the inherent direction, it is used to define the default
  24.823 +      /// direction for the corresponding arcs.
  24.824        /// \sa v()
  24.825        /// \sa direction()
  24.826        Node u(Edge) const { return INVALID; }
  24.827  
  24.828 -      /// \brief Second node of the edge.
  24.829 +      /// \brief The second node of the edge.
  24.830        ///
  24.831 -      /// \return The second node of the given edge.
  24.832 +      /// Returns the second node of the given edge.
  24.833        ///
  24.834 -      /// Naturally edges don't have direction and thus
  24.835 -      /// don't have source and target node. However we use \c u() and \c v()
  24.836 -      /// methods to query the two nodes of the arc. The direction of the
  24.837 -      /// arc which arises this way is called the inherent direction of the
  24.838 -      /// edge, and is used to define the "default" direction
  24.839 -      /// of the directed versions of the arcs.
  24.840 +      /// Edges don't have source and target nodes, however methods
  24.841 +      /// u() and v() are used to query the two end-nodes of an edge.
  24.842 +      /// The orientation of an edge that arises this way is called
  24.843 +      /// the inherent direction, it is used to define the default
  24.844 +      /// direction for the corresponding arcs.
  24.845        /// \sa u()
  24.846        /// \sa direction()
  24.847        Node v(Edge) const { return INVALID; }
  24.848  
  24.849 -      /// \brief Source node of the directed arc.
  24.850 +      /// \brief The source node of the arc.
  24.851 +      ///
  24.852 +      /// Returns the source node of the given arc.
  24.853        Node source(Arc) const { return INVALID; }
  24.854  
  24.855 -      /// \brief Target node of the directed arc.
  24.856 +      /// \brief The target node of the arc.
  24.857 +      ///
  24.858 +      /// Returns the target node of the given arc.
  24.859        Node target(Arc) const { return INVALID; }
  24.860  
  24.861 -      /// \brief Returns the id of the node.
  24.862 +      /// \brief The ID of the node.
  24.863 +      ///
  24.864 +      /// Returns the ID of the given node.
  24.865        int id(Node) const { return -1; }
  24.866  
  24.867 -      /// \brief Returns the id of the edge.
  24.868 +      /// \brief The ID of the edge.
  24.869 +      ///
  24.870 +      /// Returns the ID of the given edge.
  24.871        int id(Edge) const { return -1; }
  24.872  
  24.873 -      /// \brief Returns the id of the arc.
  24.874 +      /// \brief The ID of the arc.
  24.875 +      ///
  24.876 +      /// Returns the ID of the given arc.
  24.877        int id(Arc) const { return -1; }
  24.878  
  24.879 -      /// \brief Returns the node with the given id.
  24.880 +      /// \brief The node with the given ID.
  24.881        ///
  24.882 -      /// \pre The argument should be a valid node id in the graph.
  24.883 +      /// Returns the node with the given ID.
  24.884 +      /// \pre The argument should be a valid node ID in the graph.
  24.885        Node nodeFromId(int) const { return INVALID; }
  24.886  
  24.887 -      /// \brief Returns the edge with the given id.
  24.888 +      /// \brief The edge with the given ID.
  24.889        ///
  24.890 -      /// \pre The argument should be a valid edge id in the graph.
  24.891 +      /// Returns the edge with the given ID.
  24.892 +      /// \pre The argument should be a valid edge ID in the graph.
  24.893        Edge edgeFromId(int) const { return INVALID; }
  24.894  
  24.895 -      /// \brief Returns the arc with the given id.
  24.896 +      /// \brief The arc with the given ID.
  24.897        ///
  24.898 -      /// \pre The argument should be a valid arc id in the graph.
  24.899 +      /// Returns the arc with the given ID.
  24.900 +      /// \pre The argument should be a valid arc ID in the graph.
  24.901        Arc arcFromId(int) const { return INVALID; }
  24.902  
  24.903 -      /// \brief Returns an upper bound on the node IDs.
  24.904 +      /// \brief An upper bound on the node IDs.
  24.905 +      ///
  24.906 +      /// Returns an upper bound on the node IDs.
  24.907        int maxNodeId() const { return -1; }
  24.908  
  24.909 -      /// \brief Returns an upper bound on the edge IDs.
  24.910 +      /// \brief An upper bound on the edge IDs.
  24.911 +      ///
  24.912 +      /// Returns an upper bound on the edge IDs.
  24.913        int maxEdgeId() const { return -1; }
  24.914  
  24.915 -      /// \brief Returns an upper bound on the arc IDs.
  24.916 +      /// \brief An upper bound on the arc IDs.
  24.917 +      ///
  24.918 +      /// Returns an upper bound on the arc IDs.
  24.919        int maxArcId() const { return -1; }
  24.920  
  24.921 +      /// \brief The direction of the arc.
  24.922 +      ///
  24.923 +      /// Returns \c true if the direction of the given arc is the same as
  24.924 +      /// the inherent orientation of the represented edge.
  24.925 +      bool direction(Arc) const { return true; }
  24.926 +
  24.927 +      /// \brief Direct the edge.
  24.928 +      ///
  24.929 +      /// Direct the given edge. The returned arc
  24.930 +      /// represents the given edge and its direction comes
  24.931 +      /// from the bool parameter. If it is \c true, then the direction
  24.932 +      /// of the arc is the same as the inherent orientation of the edge.
  24.933 +      Arc direct(Edge, bool) const {
  24.934 +        return INVALID;
  24.935 +      }
  24.936 +
  24.937 +      /// \brief Direct the edge.
  24.938 +      ///
  24.939 +      /// Direct the given edge. The returned arc represents the given
  24.940 +      /// edge and its source node is the given node.
  24.941 +      Arc direct(Edge, Node) const {
  24.942 +        return INVALID;
  24.943 +      }
  24.944 +
  24.945 +      /// \brief The oppositely directed arc.
  24.946 +      ///
  24.947 +      /// Returns the oppositely directed arc representing the same edge.
  24.948 +      Arc oppositeArc(Arc) const { return INVALID; }
  24.949 +
  24.950 +      /// \brief The opposite node on the edge.
  24.951 +      ///
  24.952 +      /// Returns the opposite node on the given edge.
  24.953 +      Node oppositeNode(Node, Edge) const { return INVALID; }
  24.954 +
  24.955        void first(Node&) const {}
  24.956        void next(Node&) const {}
  24.957  
  24.958 @@ -705,47 +733,39 @@
  24.959        // Dummy parameter.
  24.960        int maxId(Arc) const { return -1; }
  24.961  
  24.962 -      /// \brief Base node of the iterator
  24.963 +      /// \brief The base node of the iterator.
  24.964        ///
  24.965 -      /// Returns the base node (the source in this case) of the iterator
  24.966 -      Node baseNode(OutArcIt e) const {
  24.967 -        return source(e);
  24.968 -      }
  24.969 -      /// \brief Running node of the iterator
  24.970 +      /// Returns the base node of the given incident edge iterator.
  24.971 +      Node baseNode(IncEdgeIt) const { return INVALID; }
  24.972 +
  24.973 +      /// \brief The running node of the iterator.
  24.974        ///
  24.975 -      /// Returns the running node (the target in this case) of the
  24.976 -      /// iterator
  24.977 -      Node runningNode(OutArcIt e) const {
  24.978 -        return target(e);
  24.979 -      }
  24.980 +      /// Returns the running node of the given incident edge iterator.
  24.981 +      Node runningNode(IncEdgeIt) const { return INVALID; }
  24.982  
  24.983 -      /// \brief Base node of the iterator
  24.984 +      /// \brief The base node of the iterator.
  24.985        ///
  24.986 -      /// Returns the base node (the target in this case) of the iterator
  24.987 -      Node baseNode(InArcIt e) const {
  24.988 -        return target(e);
  24.989 -      }
  24.990 -      /// \brief Running node of the iterator
  24.991 +      /// Returns the base node of the given outgoing arc iterator
  24.992 +      /// (i.e. the source node of the corresponding arc).
  24.993 +      Node baseNode(OutArcIt) const { return INVALID; }
  24.994 +
  24.995 +      /// \brief The running node of the iterator.
  24.996        ///
  24.997 -      /// Returns the running node (the source in this case) of the
  24.998 -      /// iterator
  24.999 -      Node runningNode(InArcIt e) const {
 24.1000 -        return source(e);
 24.1001 -      }
 24.1002 +      /// Returns the running node of the given outgoing arc iterator
 24.1003 +      /// (i.e. the target node of the corresponding arc).
 24.1004 +      Node runningNode(OutArcIt) const { return INVALID; }
 24.1005  
 24.1006 -      /// \brief Base node of the iterator
 24.1007 +      /// \brief The base node of the iterator.
 24.1008        ///
 24.1009 -      /// Returns the base node of the iterator
 24.1010 -      Node baseNode(IncEdgeIt) const {
 24.1011 -        return INVALID;
 24.1012 -      }
 24.1013 +      /// Returns the base node of the given incomming arc iterator
 24.1014 +      /// (i.e. the target node of the corresponding arc).
 24.1015 +      Node baseNode(InArcIt) const { return INVALID; }
 24.1016  
 24.1017 -      /// \brief Running node of the iterator
 24.1018 +      /// \brief The running node of the iterator.
 24.1019        ///
 24.1020 -      /// Returns the running node of the iterator
 24.1021 -      Node runningNode(IncEdgeIt) const {
 24.1022 -        return INVALID;
 24.1023 -      }
 24.1024 +      /// Returns the running node of the given incomming arc iterator
 24.1025 +      /// (i.e. the source node of the corresponding arc).
 24.1026 +      Node runningNode(InArcIt) const { return INVALID; }
 24.1027  
 24.1028        template <typename _Graph>
 24.1029        struct Constraints {
    25.1 --- a/lemon/concepts/graph_components.h	Thu Nov 05 10:01:02 2009 +0100
    25.2 +++ b/lemon/concepts/graph_components.h	Thu Nov 05 10:23:16 2009 +0100
    25.3 @@ -92,7 +92,7 @@
    25.4        /// It makes possible to use graph item types as key types in 
    25.5        /// associative containers (e.g. \c std::map).
    25.6        ///
    25.7 -      /// \note This operator only have to define some strict ordering of
    25.8 +      /// \note This operator only has to define some strict ordering of
    25.9        /// the items; this order has nothing to do with the iteration
   25.10        /// ordering of the items.
   25.11        bool operator<(const GraphItem&) const { return false; }
    26.1 --- a/lemon/concepts/heap.h	Thu Nov 05 10:01:02 2009 +0100
    26.2 +++ b/lemon/concepts/heap.h	Thu Nov 05 10:23:16 2009 +0100
    26.3 @@ -16,13 +16,13 @@
    26.4   *
    26.5   */
    26.6  
    26.7 +#ifndef LEMON_CONCEPTS_HEAP_H
    26.8 +#define LEMON_CONCEPTS_HEAP_H
    26.9 +
   26.10  ///\ingroup concept
   26.11  ///\file
   26.12  ///\brief The concept of heaps.
   26.13  
   26.14 -#ifndef LEMON_CONCEPTS_HEAP_H
   26.15 -#define LEMON_CONCEPTS_HEAP_H
   26.16 -
   26.17  #include <lemon/core.h>
   26.18  #include <lemon/concept_check.h>
   26.19  
   26.20 @@ -35,21 +35,27 @@
   26.21  
   26.22      /// \brief The heap concept.
   26.23      ///
   26.24 -    /// Concept class describing the main interface of heaps. A \e heap
   26.25 -    /// is a data structure for storing items with specified values called
   26.26 -    /// \e priorities in such a way that finding the item with minimum
   26.27 -    /// priority is efficient. In a heap one can change the priority of an
   26.28 -    /// item, add or erase an item, etc.
   26.29 +    /// This concept class describes the main interface of heaps.
   26.30 +    /// The various \ref heaps "heap structures" are efficient
   26.31 +    /// implementations of the abstract data type \e priority \e queue.
   26.32 +    /// They store items with specified values called \e priorities
   26.33 +    /// in such a way that finding and removing the item with minimum
   26.34 +    /// priority are efficient. The basic operations are adding and
   26.35 +    /// erasing items, changing the priority of an item, etc.
   26.36      ///
   26.37 -    /// \tparam PR Type of the priority of the items.
   26.38 -    /// \tparam IM A read and writable item map with int values, used
   26.39 +    /// Heaps are crucial in several algorithms, such as Dijkstra and Prim.
   26.40 +    /// Any class that conforms to this concept can be used easily in such
   26.41 +    /// algorithms.
   26.42 +    ///
   26.43 +    /// \tparam PR Type of the priorities of the items.
   26.44 +    /// \tparam IM A read-writable item map with \c int values, used
   26.45      /// internally to handle the cross references.
   26.46 -    /// \tparam Comp A functor class for the ordering of the priorities.
   26.47 +    /// \tparam CMP A functor class for comparing the priorities.
   26.48      /// The default is \c std::less<PR>.
   26.49  #ifdef DOXYGEN
   26.50 -    template <typename PR, typename IM, typename Comp = std::less<PR> >
   26.51 +    template <typename PR, typename IM, typename CMP>
   26.52  #else
   26.53 -    template <typename PR, typename IM>
   26.54 +    template <typename PR, typename IM, typename CMP = std::less<PR> >
   26.55  #endif
   26.56      class Heap {
   26.57      public:
   26.58 @@ -64,109 +70,125 @@
   26.59        /// \brief Type to represent the states of the items.
   26.60        ///
   26.61        /// Each item has a state associated to it. It can be "in heap",
   26.62 -      /// "pre heap" or "post heap". The later two are indifferent
   26.63 -      /// from the point of view of the heap, but may be useful for
   26.64 -      /// the user.
   26.65 +      /// "pre-heap" or "post-heap". The latter two are indifferent from the
   26.66 +      /// heap's point of view, but may be useful to the user.
   26.67        ///
   26.68        /// The item-int map must be initialized in such way that it assigns
   26.69        /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
   26.70        enum State {
   26.71          IN_HEAP = 0,    ///< = 0. The "in heap" state constant.
   26.72 -        PRE_HEAP = -1,  ///< = -1. The "pre heap" state constant.
   26.73 -        POST_HEAP = -2  ///< = -2. The "post heap" state constant.
   26.74 +        PRE_HEAP = -1,  ///< = -1. The "pre-heap" state constant.
   26.75 +        POST_HEAP = -2  ///< = -2. The "post-heap" state constant.
   26.76        };
   26.77  
   26.78 -      /// \brief The constructor.
   26.79 +      /// \brief Constructor.
   26.80        ///
   26.81 -      /// The constructor.
   26.82 +      /// Constructor.
   26.83        /// \param map A map that assigns \c int values to keys of type
   26.84        /// \c Item. It is used internally by the heap implementations to
   26.85        /// handle the cross references. The assigned value must be
   26.86 -      /// \c PRE_HEAP (<tt>-1</tt>) for every item.
   26.87 +      /// \c PRE_HEAP (<tt>-1</tt>) for each item.
   26.88        explicit Heap(ItemIntMap &map) {}
   26.89  
   26.90 +      /// \brief Constructor.
   26.91 +      ///
   26.92 +      /// Constructor.
   26.93 +      /// \param map A map that assigns \c int values to keys of type
   26.94 +      /// \c Item. It is used internally by the heap implementations to
   26.95 +      /// handle the cross references. The assigned value must be
   26.96 +      /// \c PRE_HEAP (<tt>-1</tt>) for each item.
   26.97 +      /// \param comp The function object used for comparing the priorities.
   26.98 +      explicit Heap(ItemIntMap &map, const CMP &comp) {}
   26.99 +
  26.100        /// \brief The number of items stored in the heap.
  26.101        ///
  26.102 -      /// Returns the number of items stored in the heap.
  26.103 +      /// This function returns the number of items stored in the heap.
  26.104        int size() const { return 0; }
  26.105  
  26.106 -      /// \brief Checks if the heap is empty.
  26.107 +      /// \brief Check if the heap is empty.
  26.108        ///
  26.109 -      /// Returns \c true if the heap is empty.
  26.110 +      /// This function returns \c true if the heap is empty.
  26.111        bool empty() const { return false; }
  26.112  
  26.113 -      /// \brief Makes the heap empty.
  26.114 +      /// \brief Make the heap empty.
  26.115        ///
  26.116 -      /// Makes the heap empty.
  26.117 -      void clear();
  26.118 +      /// This functon makes the heap empty.
  26.119 +      /// It does not change the cross reference map. If you want to reuse
  26.120 +      /// a heap that is not surely empty, you should first clear it and
  26.121 +      /// then you should set the cross reference map to \c PRE_HEAP
  26.122 +      /// for each item.
  26.123 +      void clear() {}
  26.124  
  26.125 -      /// \brief Inserts an item into the heap with the given priority.
  26.126 +      /// \brief Insert an item into the heap with the given priority.
  26.127        ///
  26.128 -      /// Inserts the given item into the heap with the given priority.
  26.129 +      /// This function inserts the given item into the heap with the
  26.130 +      /// given priority.
  26.131        /// \param i The item to insert.
  26.132        /// \param p The priority of the item.
  26.133 +      /// \pre \e i must not be stored in the heap.
  26.134        void push(const Item &i, const Prio &p) {}
  26.135  
  26.136 -      /// \brief Returns the item having minimum priority.
  26.137 +      /// \brief Return the item having minimum priority.
  26.138        ///
  26.139 -      /// Returns the item having minimum priority.
  26.140 +      /// This function returns the item having minimum priority.
  26.141        /// \pre The heap must be non-empty.
  26.142        Item top() const {}
  26.143  
  26.144        /// \brief The minimum priority.
  26.145        ///
  26.146 -      /// Returns the minimum priority.
  26.147 +      /// This function returns the minimum priority.
  26.148        /// \pre The heap must be non-empty.
  26.149        Prio prio() const {}
  26.150  
  26.151 -      /// \brief Removes the item having minimum priority.
  26.152 +      /// \brief Remove the item having minimum priority.
  26.153        ///
  26.154 -      /// Removes the item having minimum priority.
  26.155 +      /// This function removes the item having minimum priority.
  26.156        /// \pre The heap must be non-empty.
  26.157        void pop() {}
  26.158  
  26.159 -      /// \brief Removes an item from the heap.
  26.160 +      /// \brief Remove the given item from the heap.
  26.161        ///
  26.162 -      /// Removes the given item from the heap if it is already stored.
  26.163 +      /// This function removes the given item from the heap if it is
  26.164 +      /// already stored.
  26.165        /// \param i The item to delete.
  26.166 +      /// \pre \e i must be in the heap.
  26.167        void erase(const Item &i) {}
  26.168  
  26.169 -      /// \brief The priority of an item.
  26.170 +      /// \brief The priority of the given item.
  26.171        ///
  26.172 -      /// Returns the priority of the given item.
  26.173 +      /// This function returns the priority of the given item.
  26.174        /// \param i The item.
  26.175 -      /// \pre \c i must be in the heap.
  26.176 +      /// \pre \e i must be in the heap.
  26.177        Prio operator[](const Item &i) const {}
  26.178  
  26.179 -      /// \brief Sets the priority of an item or inserts it, if it is
  26.180 +      /// \brief Set the priority of an item or insert it, if it is
  26.181        /// not stored in the heap.
  26.182        ///
  26.183        /// This method sets the priority of the given item if it is
  26.184 -      /// already stored in the heap.
  26.185 -      /// Otherwise it inserts the given item with the given priority.
  26.186 +      /// already stored in the heap. Otherwise it inserts the given
  26.187 +      /// item into the heap with the given priority.
  26.188        ///
  26.189        /// \param i The item.
  26.190        /// \param p The priority.
  26.191        void set(const Item &i, const Prio &p) {}
  26.192  
  26.193 -      /// \brief Decreases the priority of an item to the given value.
  26.194 +      /// \brief Decrease the priority of an item to the given value.
  26.195        ///
  26.196 -      /// Decreases the priority of an item to the given value.
  26.197 +      /// This function decreases the priority of an item to the given value.
  26.198        /// \param i The item.
  26.199        /// \param p The priority.
  26.200 -      /// \pre \c i must be stored in the heap with priority at least \c p.
  26.201 +      /// \pre \e i must be stored in the heap with priority at least \e p.
  26.202        void decrease(const Item &i, const Prio &p) {}
  26.203  
  26.204 -      /// \brief Increases the priority of an item to the given value.
  26.205 +      /// \brief Increase the priority of an item to the given value.
  26.206        ///
  26.207 -      /// Increases the priority of an item to the given value.
  26.208 +      /// This function increases the priority of an item to the given value.
  26.209        /// \param i The item.
  26.210        /// \param p The priority.
  26.211 -      /// \pre \c i must be stored in the heap with priority at most \c p.
  26.212 +      /// \pre \e i must be stored in the heap with priority at most \e p.
  26.213        void increase(const Item &i, const Prio &p) {}
  26.214  
  26.215 -      /// \brief Returns if an item is in, has already been in, or has
  26.216 -      /// never been in the heap.
  26.217 +      /// \brief Return the state of an item.
  26.218        ///
  26.219        /// This method returns \c PRE_HEAP if the given item has never
  26.220        /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  26.221 @@ -176,11 +198,11 @@
  26.222        /// \param i The item.
  26.223        State state(const Item &i) const {}
  26.224  
  26.225 -      /// \brief Sets the state of an item in the heap.
  26.226 +      /// \brief Set the state of an item in the heap.
  26.227        ///
  26.228 -      /// Sets the state of the given item in the heap. It can be used
  26.229 -      /// to manually clear the heap when it is important to achive the
  26.230 -      /// better time complexity.
  26.231 +      /// This function sets the state of the given item in the heap.
  26.232 +      /// It can be used to manually clear the heap when it is important
  26.233 +      /// to achive better time complexity.
  26.234        /// \param i The item.
  26.235        /// \param st The state. It should not be \c IN_HEAP.
  26.236        void state(const Item& i, State st) {}
    27.1 --- a/lemon/concepts/maps.h	Thu Nov 05 10:01:02 2009 +0100
    27.2 +++ b/lemon/concepts/maps.h	Thu Nov 05 10:23:16 2009 +0100
    27.3 @@ -182,7 +182,8 @@
    27.4  
    27.5        template<typename _ReferenceMap>
    27.6        struct Constraints {
    27.7 -        void constraints() {
    27.8 +        typename enable_if<typename _ReferenceMap::ReferenceMapTag, void>::type
    27.9 +        constraints() {
   27.10            checkConcept<ReadWriteMap<K, T>, _ReferenceMap >();
   27.11            ref = m[key];
   27.12            m[key] = val;
    28.1 --- a/lemon/cplex.cc	Thu Nov 05 10:01:02 2009 +0100
    28.2 +++ b/lemon/cplex.cc	Thu Nov 05 10:23:16 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	Thu Nov 05 10:01:02 2009 +0100
    29.2 +++ b/lemon/cplex.h	Thu Nov 05 10:23:16 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	Thu Nov 05 10:01:02 2009 +0100
    30.2 +++ b/lemon/dfs.h	Thu Nov 05 10:23:16 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 @@ -669,9 +670,9 @@
   30.88  
   30.89      ///@{
   30.90  
   30.91 -    ///The DFS path to a node.
   30.92 +    ///The DFS path to the given node.
   30.93  
   30.94 -    ///Returns the DFS path to a node.
   30.95 +    ///Returns the DFS path to the given node from the root(s).
   30.96      ///
   30.97      ///\warning \c t should be reached from the root(s).
   30.98      ///
   30.99 @@ -679,9 +680,9 @@
  30.100      ///must be called before using this function.
  30.101      Path path(Node t) const { return Path(*G, *_pred, t); }
  30.102  
  30.103 -    ///The distance of a node from the root(s).
  30.104 +    ///The distance of the given node from the root(s).
  30.105  
  30.106 -    ///Returns the distance of a node from the root(s).
  30.107 +    ///Returns the distance of the given node from the root(s).
  30.108      ///
  30.109      ///\warning If node \c v is not reached from the root(s), then
  30.110      ///the return value of this function is undefined.
  30.111 @@ -690,7 +691,7 @@
  30.112      ///must be called before using this function.
  30.113      int dist(Node v) const { return (*_dist)[v]; }
  30.114  
  30.115 -    ///Returns the 'previous arc' of the %DFS tree for a node.
  30.116 +    ///Returns the 'previous arc' of the %DFS tree for the given node.
  30.117  
  30.118      ///This function returns the 'previous arc' of the %DFS tree for the
  30.119      ///node \c v, i.e. it returns the last arc of a %DFS path from a
  30.120 @@ -698,21 +699,21 @@
  30.121      ///root(s) or if \c v is a root.
  30.122      ///
  30.123      ///The %DFS tree used here is equal to the %DFS tree used in
  30.124 -    ///\ref predNode().
  30.125 +    ///\ref predNode() and \ref predMap().
  30.126      ///
  30.127      ///\pre Either \ref run(Node) "run()" or \ref init()
  30.128      ///must be called before using this function.
  30.129      Arc predArc(Node v) const { return (*_pred)[v];}
  30.130  
  30.131 -    ///Returns the 'previous node' of the %DFS tree.
  30.132 +    ///Returns the 'previous node' of the %DFS tree for the given node.
  30.133  
  30.134      ///This function returns the 'previous node' of the %DFS
  30.135      ///tree for the node \c v, i.e. it returns the last but one node
  30.136 -    ///from a %DFS path from a root to \c v. It is \c INVALID
  30.137 +    ///of a %DFS path from a root to \c v. It is \c INVALID
  30.138      ///if \c v is not reached from the root(s) or if \c v is a root.
  30.139      ///
  30.140      ///The %DFS tree used here is equal to the %DFS tree used in
  30.141 -    ///\ref predArc().
  30.142 +    ///\ref predArc() and \ref predMap().
  30.143      ///
  30.144      ///\pre Either \ref run(Node) "run()" or \ref init()
  30.145      ///must be called before using this function.
  30.146 @@ -733,13 +734,13 @@
  30.147      ///predecessor arcs.
  30.148      ///
  30.149      ///Returns a const reference to the node map that stores the predecessor
  30.150 -    ///arcs, which form the DFS tree.
  30.151 +    ///arcs, which form the DFS tree (forest).
  30.152      ///
  30.153      ///\pre Either \ref run(Node) "run()" or \ref init()
  30.154      ///must be called before using this function.
  30.155      const PredMap &predMap() const { return *_pred;}
  30.156  
  30.157 -    ///Checks if a node is reached from the root(s).
  30.158 +    ///Checks if the given node. node is reached from the root(s).
  30.159  
  30.160      ///Returns \c true if \c v is reached from the root(s).
  30.161      ///
  30.162 @@ -765,7 +766,7 @@
  30.163      ///
  30.164      ///The type of the map that stores the predecessor
  30.165      ///arcs of the %DFS paths.
  30.166 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
  30.167 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  30.168      typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
  30.169      ///Instantiates a PredMap.
  30.170  
  30.171 @@ -780,7 +781,7 @@
  30.172      ///The type of the map that indicates which nodes are processed.
  30.173  
  30.174      ///The type of the map that indicates which nodes are processed.
  30.175 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
  30.176 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  30.177      ///By default it is a NullMap.
  30.178      typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
  30.179      ///Instantiates a ProcessedMap.
  30.180 @@ -800,7 +801,7 @@
  30.181      ///The type of the map that indicates which nodes are reached.
  30.182  
  30.183      ///The type of the map that indicates which nodes are reached.
  30.184 -    ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
  30.185 +    ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
  30.186      typedef typename Digraph::template NodeMap<bool> ReachedMap;
  30.187      ///Instantiates a ReachedMap.
  30.188  
  30.189 @@ -815,7 +816,7 @@
  30.190      ///The type of the map that stores the distances of the nodes.
  30.191  
  30.192      ///The type of the map that stores the distances of the nodes.
  30.193 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
  30.194 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  30.195      typedef typename Digraph::template NodeMap<int> DistMap;
  30.196      ///Instantiates a DistMap.
  30.197  
  30.198 @@ -830,18 +831,14 @@
  30.199      ///The type of the DFS paths.
  30.200  
  30.201      ///The type of the DFS paths.
  30.202 -    ///It must meet the \ref concepts::Path "Path" concept.
  30.203 +    ///It must conform to the \ref concepts::Path "Path" concept.
  30.204      typedef lemon::Path<Digraph> Path;
  30.205    };
  30.206  
  30.207    /// Default traits class used by DfsWizard
  30.208  
  30.209 -  /// To make it easier to use Dfs algorithm
  30.210 -  /// we have created a wizard class.
  30.211 -  /// This \ref DfsWizard class needs default traits,
  30.212 -  /// as well as the \ref Dfs class.
  30.213 -  /// The \ref DfsWizardBase is a class to be the default traits of the
  30.214 -  /// \ref DfsWizard class.
  30.215 +  /// Default traits class used by DfsWizard.
  30.216 +  /// \tparam GR The type of the digraph.
  30.217    template<class GR>
  30.218    class DfsWizardBase : public DfsWizardDefaultTraits<GR>
  30.219    {
  30.220 @@ -869,7 +866,7 @@
  30.221      public:
  30.222      /// Constructor.
  30.223  
  30.224 -    /// This constructor does not require parameters, therefore it initiates
  30.225 +    /// This constructor does not require parameters, it initiates
  30.226      /// all of the attributes to \c 0.
  30.227      DfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
  30.228                        _dist(0), _path(0), _di(0) {}
  30.229 @@ -899,7 +896,6 @@
  30.230    {
  30.231      typedef TR Base;
  30.232  
  30.233 -    ///The type of the digraph the algorithm runs on.
  30.234      typedef typename TR::Digraph Digraph;
  30.235  
  30.236      typedef typename Digraph::Node Node;
  30.237 @@ -907,16 +903,10 @@
  30.238      typedef typename Digraph::Arc Arc;
  30.239      typedef typename Digraph::OutArcIt OutArcIt;
  30.240  
  30.241 -    ///\brief The type of the map that stores the predecessor
  30.242 -    ///arcs of the DFS paths.
  30.243      typedef typename TR::PredMap PredMap;
  30.244 -    ///\brief The type of the map that stores the distances of the nodes.
  30.245      typedef typename TR::DistMap DistMap;
  30.246 -    ///\brief The type of the map that indicates which nodes are reached.
  30.247      typedef typename TR::ReachedMap ReachedMap;
  30.248 -    ///\brief The type of the map that indicates which nodes are processed.
  30.249      typedef typename TR::ProcessedMap ProcessedMap;
  30.250 -    ///The type of the DFS paths
  30.251      typedef typename TR::Path Path;
  30.252  
  30.253    public:
  30.254 @@ -999,11 +989,12 @@
  30.255        static PredMap *createPredMap(const Digraph &) { return 0; };
  30.256        SetPredMapBase(const TR &b) : TR(b) {}
  30.257      };
  30.258 -    ///\brief \ref named-func-param "Named parameter"
  30.259 -    ///for setting PredMap object.
  30.260 +
  30.261 +    ///\brief \ref named-templ-param "Named parameter" for setting
  30.262 +    ///the predecessor map.
  30.263      ///
  30.264 -    ///\ref named-func-param "Named parameter"
  30.265 -    ///for setting PredMap object.
  30.266 +    ///\ref named-templ-param "Named parameter" function for setting
  30.267 +    ///the map that stores the predecessor arcs of the nodes.
  30.268      template<class T>
  30.269      DfsWizard<SetPredMapBase<T> > predMap(const T &t)
  30.270      {
  30.271 @@ -1017,11 +1008,12 @@
  30.272        static ReachedMap *createReachedMap(const Digraph &) { return 0; };
  30.273        SetReachedMapBase(const TR &b) : TR(b) {}
  30.274      };
  30.275 -    ///\brief \ref named-func-param "Named parameter"
  30.276 -    ///for setting ReachedMap object.
  30.277 +
  30.278 +    ///\brief \ref named-templ-param "Named parameter" for setting
  30.279 +    ///the reached map.
  30.280      ///
  30.281 -    /// \ref named-func-param "Named parameter"
  30.282 -    ///for setting ReachedMap object.
  30.283 +    ///\ref named-templ-param "Named parameter" function for setting
  30.284 +    ///the map that indicates which nodes are reached.
  30.285      template<class T>
  30.286      DfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
  30.287      {
  30.288 @@ -1035,11 +1027,13 @@
  30.289        static DistMap *createDistMap(const Digraph &) { return 0; };
  30.290        SetDistMapBase(const TR &b) : TR(b) {}
  30.291      };
  30.292 -    ///\brief \ref named-func-param "Named parameter"
  30.293 -    ///for setting DistMap object.
  30.294 +
  30.295 +    ///\brief \ref named-templ-param "Named parameter" for setting
  30.296 +    ///the distance map.
  30.297      ///
  30.298 -    /// \ref named-func-param "Named parameter"
  30.299 -    ///for setting DistMap object.
  30.300 +    ///\ref named-templ-param "Named parameter" function for setting
  30.301 +    ///the map that stores the distances of the nodes calculated
  30.302 +    ///by the algorithm.
  30.303      template<class T>
  30.304      DfsWizard<SetDistMapBase<T> > distMap(const T &t)
  30.305      {
  30.306 @@ -1053,11 +1047,12 @@
  30.307        static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
  30.308        SetProcessedMapBase(const TR &b) : TR(b) {}
  30.309      };
  30.310 -    ///\brief \ref named-func-param "Named parameter"
  30.311 -    ///for setting ProcessedMap object.
  30.312 +
  30.313 +    ///\brief \ref named-func-param "Named parameter" for setting
  30.314 +    ///the processed map.
  30.315      ///
  30.316 -    /// \ref named-func-param "Named parameter"
  30.317 -    ///for setting ProcessedMap object.
  30.318 +    ///\ref named-templ-param "Named parameter" function for setting
  30.319 +    ///the map that indicates which nodes are processed.
  30.320      template<class T>
  30.321      DfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
  30.322      {
  30.323 @@ -1208,7 +1203,7 @@
  30.324      /// \brief The type of the map that indicates which nodes are reached.
  30.325      ///
  30.326      /// The type of the map that indicates which nodes are reached.
  30.327 -    /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
  30.328 +    /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
  30.329      typedef typename Digraph::template NodeMap<bool> ReachedMap;
  30.330  
  30.331      /// \brief Instantiates a ReachedMap.
  30.332 @@ -1369,8 +1364,8 @@
  30.333      /// \name Execution Control
  30.334      /// The simplest way to execute the DFS algorithm is to use one of the
  30.335      /// member functions called \ref run(Node) "run()".\n
  30.336 -    /// If you need more control on the execution, first you have to call
  30.337 -    /// \ref init(), then you can add a source node with \ref addSource()
  30.338 +    /// If you need better control on the execution, you have to call
  30.339 +    /// \ref init() first, then you can add a source node with \ref addSource()
  30.340      /// and perform the actual computation with \ref start().
  30.341      /// This procedure can be repeated if there are nodes that have not
  30.342      /// been reached.
  30.343 @@ -1620,7 +1615,7 @@
  30.344  
  30.345      ///@{
  30.346  
  30.347 -    /// \brief Checks if a node is reached from the root(s).
  30.348 +    /// \brief Checks if the given node is reached from the root(s).
  30.349      ///
  30.350      /// Returns \c true if \c v is reached from the root(s).
  30.351      ///
    31.1 --- a/lemon/dijkstra.h	Thu Nov 05 10:01:02 2009 +0100
    31.2 +++ b/lemon/dijkstra.h	Thu Nov 05 10:23:16 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,7 +131,7 @@
   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 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   31.30      ///By default it is a NullMap.
   31.31      typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
   31.32      ///Instantiates a \c ProcessedMap.
   31.33 @@ -151,7 +151,7 @@
   31.34      ///The type of the map that stores the distances of the nodes.
   31.35  
   31.36      ///The type of the map that stores the distances of the nodes.
   31.37 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   31.38 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   31.39      typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap;
   31.40      ///Instantiates a \c DistMap.
   31.41  
   31.42 @@ -169,6 +169,10 @@
   31.43    /// \ingroup shortest_path
   31.44    ///This class provides an efficient implementation of the %Dijkstra algorithm.
   31.45    ///
   31.46 +  ///The %Dijkstra algorithm solves the single-source shortest path problem
   31.47 +  ///when all arc lengths are non-negative. If there are negative lengths,
   31.48 +  ///the BellmanFord algorithm should be used instead.
   31.49 +  ///
   31.50    ///The arc lengths are passed to the algorithm using a
   31.51    ///\ref concepts::ReadMap "ReadMap",
   31.52    ///so it is easy to change it to any kind of length.
   31.53 @@ -201,7 +205,7 @@
   31.54      ///The type of the digraph the algorithm runs on.
   31.55      typedef typename TR::Digraph Digraph;
   31.56  
   31.57 -    ///The type of the length of the arcs.
   31.58 +    ///The type of the arc lengths.
   31.59      typedef typename TR::LengthMap::Value Value;
   31.60      ///The type of the map that stores the arc lengths.
   31.61      typedef typename TR::LengthMap LengthMap;
   31.62 @@ -304,7 +308,7 @@
   31.63      ///
   31.64      ///\ref named-templ-param "Named parameter" for setting
   31.65      ///\c PredMap type.
   31.66 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   31.67 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   31.68      template <class T>
   31.69      struct SetPredMap
   31.70        : public Dijkstra< Digraph, LengthMap, SetPredMapTraits<T> > {
   31.71 @@ -325,7 +329,7 @@
   31.72      ///
   31.73      ///\ref named-templ-param "Named parameter" for setting
   31.74      ///\c DistMap type.
   31.75 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   31.76 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   31.77      template <class T>
   31.78      struct SetDistMap
   31.79        : public Dijkstra< Digraph, LengthMap, SetDistMapTraits<T> > {
   31.80 @@ -346,7 +350,7 @@
   31.81      ///
   31.82      ///\ref named-templ-param "Named parameter" for setting
   31.83      ///\c ProcessedMap type.
   31.84 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   31.85 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   31.86      template <class T>
   31.87      struct SetProcessedMap
   31.88        : public Dijkstra< Digraph, LengthMap, SetProcessedMapTraits<T> > {
   31.89 @@ -443,6 +447,7 @@
   31.90      ///
   31.91      ///\ref named-templ-param "Named parameter" for setting
   31.92      ///\c OperationTraits type.
   31.93 +    /// For more information see \ref DijkstraDefaultOperationTraits.
   31.94      template <class T>
   31.95      struct SetOperationTraits
   31.96        : public Dijkstra<Digraph, LengthMap, SetOperationTraitsTraits<T> > {
   31.97 @@ -584,8 +589,8 @@
   31.98      ///\name Execution Control
   31.99      ///The simplest way to execute the %Dijkstra algorithm is to use
  31.100      ///one of the member functions called \ref run(Node) "run()".\n
  31.101 -    ///If you need more control on the execution, first you have to call
  31.102 -    ///\ref init(), then you can add several source nodes with
  31.103 +    ///If you need better control on the execution, you have to call
  31.104 +    ///\ref init() first, then you can add several source nodes with
  31.105      ///\ref addSource(). Finally the actual path computation can be
  31.106      ///performed with one of the \ref start() functions.
  31.107  
  31.108 @@ -801,14 +806,14 @@
  31.109      ///\name Query Functions
  31.110      ///The results of the %Dijkstra algorithm can be obtained using these
  31.111      ///functions.\n
  31.112 -    ///Either \ref run(Node) "run()" or \ref start() should be called
  31.113 +    ///Either \ref run(Node) "run()" or \ref init() should be called
  31.114      ///before using them.
  31.115  
  31.116      ///@{
  31.117  
  31.118 -    ///The shortest path to a node.
  31.119 +    ///The shortest path to the given node.
  31.120  
  31.121 -    ///Returns the shortest path to a node.
  31.122 +    ///Returns the shortest path to the given node from the root(s).
  31.123      ///
  31.124      ///\warning \c t should be reached from the root(s).
  31.125      ///
  31.126 @@ -816,9 +821,9 @@
  31.127      ///must be called before using this function.
  31.128      Path path(Node t) const { return Path(*G, *_pred, t); }
  31.129  
  31.130 -    ///The distance of a node from the root(s).
  31.131 +    ///The distance of the given node from the root(s).
  31.132  
  31.133 -    ///Returns the distance of a node from the root(s).
  31.134 +    ///Returns the distance of the given node from the root(s).
  31.135      ///
  31.136      ///\warning If node \c v is not reached from the root(s), then
  31.137      ///the return value of this function is undefined.
  31.138 @@ -827,29 +832,31 @@
  31.139      ///must be called before using this function.
  31.140      Value dist(Node v) const { return (*_dist)[v]; }
  31.141  
  31.142 -    ///Returns the 'previous arc' of the shortest path tree for a node.
  31.143 -
  31.144 +    ///\brief Returns the 'previous arc' of the shortest path tree for
  31.145 +    ///the given node.
  31.146 +    ///
  31.147      ///This function returns the 'previous arc' of the shortest path
  31.148      ///tree for the node \c v, i.e. it returns the last arc of a
  31.149      ///shortest path from a root to \c v. It is \c INVALID if \c v
  31.150      ///is not reached from the root(s) or if \c v is a root.
  31.151      ///
  31.152      ///The shortest path tree used here is equal to the shortest path
  31.153 -    ///tree used in \ref predNode().
  31.154 +    ///tree used in \ref predNode() and \ref predMap().
  31.155      ///
  31.156      ///\pre Either \ref run(Node) "run()" or \ref init()
  31.157      ///must be called before using this function.
  31.158      Arc predArc(Node v) const { return (*_pred)[v]; }
  31.159  
  31.160 -    ///Returns the 'previous node' of the shortest path tree for a node.
  31.161 -
  31.162 +    ///\brief Returns the 'previous node' of the shortest path tree for
  31.163 +    ///the given node.
  31.164 +    ///
  31.165      ///This function returns the 'previous node' of the shortest path
  31.166      ///tree for the node \c v, i.e. it returns the last but one node
  31.167 -    ///from a shortest path from a root to \c v. It is \c INVALID
  31.168 +    ///of a shortest path from a root to \c v. It is \c INVALID
  31.169      ///if \c v is not reached from the root(s) or if \c v is a root.
  31.170      ///
  31.171      ///The shortest path tree used here is equal to the shortest path
  31.172 -    ///tree used in \ref predArc().
  31.173 +    ///tree used in \ref predArc() and \ref predMap().
  31.174      ///
  31.175      ///\pre Either \ref run(Node) "run()" or \ref init()
  31.176      ///must be called before using this function.
  31.177 @@ -870,13 +877,13 @@
  31.178      ///predecessor arcs.
  31.179      ///
  31.180      ///Returns a const reference to the node map that stores the predecessor
  31.181 -    ///arcs, which form the shortest path tree.
  31.182 +    ///arcs, which form the shortest path tree (forest).
  31.183      ///
  31.184      ///\pre Either \ref run(Node) "run()" or \ref init()
  31.185      ///must be called before using this function.
  31.186      const PredMap &predMap() const { return *_pred;}
  31.187  
  31.188 -    ///Checks if a node is reached from the root(s).
  31.189 +    ///Checks if the given node is reached from the root(s).
  31.190  
  31.191      ///Returns \c true if \c v is reached from the root(s).
  31.192      ///
  31.193 @@ -895,9 +902,9 @@
  31.194      bool processed(Node v) const { return (*_heap_cross_ref)[v] ==
  31.195                                            Heap::POST_HEAP; }
  31.196  
  31.197 -    ///The current distance of a node from the root(s).
  31.198 +    ///The current distance of the given node from the root(s).
  31.199  
  31.200 -    ///Returns the current distance of a node from the root(s).
  31.201 +    ///Returns the current distance of the given node from the root(s).
  31.202      ///It may be decreased in the following processes.
  31.203      ///
  31.204      ///\pre Either \ref run(Node) "run()" or \ref init()
  31.205 @@ -924,9 +931,9 @@
  31.206      ///The type of the map that stores the arc lengths.
  31.207  
  31.208      ///The type of the map that stores the arc lengths.
  31.209 -    ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
  31.210 +    ///It must conform to the \ref concepts::ReadMap "ReadMap" concept.
  31.211      typedef LEN LengthMap;
  31.212 -    ///The type of the length of the arcs.
  31.213 +    ///The type of the arc lengths.
  31.214      typedef typename LEN::Value Value;
  31.215  
  31.216      /// Operation traits for Dijkstra algorithm.
  31.217 @@ -973,7 +980,7 @@
  31.218      ///
  31.219      ///The type of the map that stores the predecessor
  31.220      ///arcs of the shortest paths.
  31.221 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
  31.222 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  31.223      typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
  31.224      ///Instantiates a PredMap.
  31.225  
  31.226 @@ -988,7 +995,7 @@
  31.227      ///The type of the map that indicates which nodes are processed.
  31.228  
  31.229      ///The type of the map that indicates which nodes are processed.
  31.230 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
  31.231 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  31.232      ///By default it is a NullMap.
  31.233      typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
  31.234      ///Instantiates a ProcessedMap.
  31.235 @@ -1008,7 +1015,7 @@
  31.236      ///The type of the map that stores the distances of the nodes.
  31.237  
  31.238      ///The type of the map that stores the distances of the nodes.
  31.239 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
  31.240 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  31.241      typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap;
  31.242      ///Instantiates a DistMap.
  31.243  
  31.244 @@ -1023,18 +1030,15 @@
  31.245      ///The type of the shortest paths.
  31.246  
  31.247      ///The type of the shortest paths.
  31.248 -    ///It must meet the \ref concepts::Path "Path" concept.
  31.249 +    ///It must conform to the \ref concepts::Path "Path" concept.
  31.250      typedef lemon::Path<Digraph> Path;
  31.251    };
  31.252  
  31.253    /// Default traits class used by DijkstraWizard
  31.254  
  31.255 -  /// To make it easier to use Dijkstra algorithm
  31.256 -  /// we have created a wizard class.
  31.257 -  /// This \ref DijkstraWizard class needs default traits,
  31.258 -  /// as well as the \ref Dijkstra class.
  31.259 -  /// The \ref DijkstraWizardBase is a class to be the default traits of the
  31.260 -  /// \ref DijkstraWizard class.
  31.261 +  /// Default traits class used by DijkstraWizard.
  31.262 +  /// \tparam GR The type of the digraph.
  31.263 +  /// \tparam LEN The type of the length map.
  31.264    template<typename GR, typename LEN>
  31.265    class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LEN>
  31.266    {
  31.267 @@ -1093,7 +1097,6 @@
  31.268    {
  31.269      typedef TR Base;
  31.270  
  31.271 -    ///The type of the digraph the algorithm runs on.
  31.272      typedef typename TR::Digraph Digraph;
  31.273  
  31.274      typedef typename Digraph::Node Node;
  31.275 @@ -1101,20 +1104,12 @@
  31.276      typedef typename Digraph::Arc Arc;
  31.277      typedef typename Digraph::OutArcIt OutArcIt;
  31.278  
  31.279 -    ///The type of the map that stores the arc lengths.
  31.280      typedef typename TR::LengthMap LengthMap;
  31.281 -    ///The type of the length of the arcs.
  31.282      typedef typename LengthMap::Value Value;
  31.283 -    ///\brief The type of the map that stores the predecessor
  31.284 -    ///arcs of the shortest paths.
  31.285      typedef typename TR::PredMap PredMap;
  31.286 -    ///The type of the map that stores the distances of the nodes.
  31.287      typedef typename TR::DistMap DistMap;
  31.288 -    ///The type of the map that indicates which nodes are processed.
  31.289      typedef typename TR::ProcessedMap ProcessedMap;
  31.290 -    ///The type of the shortest paths
  31.291      typedef typename TR::Path Path;
  31.292 -    ///The heap type used by the dijkstra algorithm.
  31.293      typedef typename TR::Heap Heap;
  31.294  
  31.295    public:
  31.296 @@ -1186,11 +1181,12 @@
  31.297        static PredMap *createPredMap(const Digraph &) { return 0; };
  31.298        SetPredMapBase(const TR &b) : TR(b) {}
  31.299      };
  31.300 -    ///\brief \ref named-func-param "Named parameter"
  31.301 -    ///for setting PredMap object.
  31.302 +
  31.303 +    ///\brief \ref named-templ-param "Named parameter" for setting
  31.304 +    ///the predecessor map.
  31.305      ///
  31.306 -    ///\ref named-func-param "Named parameter"
  31.307 -    ///for setting PredMap object.
  31.308 +    ///\ref named-templ-param "Named parameter" function for setting
  31.309 +    ///the map that stores the predecessor arcs of the nodes.
  31.310      template<class T>
  31.311      DijkstraWizard<SetPredMapBase<T> > predMap(const T &t)
  31.312      {
  31.313 @@ -1204,11 +1200,13 @@
  31.314        static DistMap *createDistMap(const Digraph &) { return 0; };
  31.315        SetDistMapBase(const TR &b) : TR(b) {}
  31.316      };
  31.317 -    ///\brief \ref named-func-param "Named parameter"
  31.318 -    ///for setting DistMap object.
  31.319 +
  31.320 +    ///\brief \ref named-templ-param "Named parameter" for setting
  31.321 +    ///the distance map.
  31.322      ///
  31.323 -    ///\ref named-func-param "Named parameter"
  31.324 -    ///for setting DistMap object.
  31.325 +    ///\ref named-templ-param "Named parameter" function for setting
  31.326 +    ///the map that stores the distances of the nodes calculated
  31.327 +    ///by the algorithm.
  31.328      template<class T>
  31.329      DijkstraWizard<SetDistMapBase<T> > distMap(const T &t)
  31.330      {
  31.331 @@ -1222,11 +1220,12 @@
  31.332        static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
  31.333        SetProcessedMapBase(const TR &b) : TR(b) {}
  31.334      };
  31.335 -    ///\brief \ref named-func-param "Named parameter"
  31.336 -    ///for setting ProcessedMap object.
  31.337 +
  31.338 +    ///\brief \ref named-func-param "Named parameter" for setting
  31.339 +    ///the processed map.
  31.340      ///
  31.341 -    /// \ref named-func-param "Named parameter"
  31.342 -    ///for setting ProcessedMap object.
  31.343 +    ///\ref named-templ-param "Named parameter" function for setting
  31.344 +    ///the map that indicates which nodes are processed.
  31.345      template<class T>
  31.346      DijkstraWizard<SetProcessedMapBase<T> > processedMap(const T &t)
  31.347      {
  31.348 @@ -1239,6 +1238,7 @@
  31.349        typedef T Path;
  31.350        SetPathBase(const TR &b) : TR(b) {}
  31.351      };
  31.352 +
  31.353      ///\brief \ref named-func-param "Named parameter"
  31.354      ///for getting the shortest path to the target node.
  31.355      ///
    32.1 --- a/lemon/dim2.h	Thu Nov 05 10:01:02 2009 +0100
    32.2 +++ b/lemon/dim2.h	Thu Nov 05 10:23:16 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/fib_heap.h	Thu Nov 05 10:01:02 2009 +0100
    33.2 +++ b/lemon/fib_heap.h	Thu Nov 05 10:23:16 2009 +0100
    33.3 @@ -20,53 +20,49 @@
    33.4  #define LEMON_FIB_HEAP_H
    33.5  
    33.6  ///\file
    33.7 -///\ingroup auxdat
    33.8 -///\brief Fibonacci Heap implementation.
    33.9 +///\ingroup heaps
   33.10 +///\brief Fibonacci heap implementation.
   33.11  
   33.12  #include <vector>
   33.13 +#include <utility>
   33.14  #include <functional>
   33.15  #include <lemon/math.h>
   33.16  
   33.17  namespace lemon {
   33.18  
   33.19 -  /// \ingroup auxdat
   33.20 +  /// \ingroup heaps
   33.21    ///
   33.22 -  ///\brief Fibonacci Heap.
   33.23 +  /// \brief Fibonacci heap data structure.
   33.24    ///
   33.25 -  ///This class implements the \e Fibonacci \e heap data structure. A \e heap
   33.26 -  ///is a data structure for storing items with specified values called \e
   33.27 -  ///priorities in such a way that finding the item with minimum priority is
   33.28 -  ///efficient. \c CMP specifies the ordering of the priorities. In a heap
   33.29 -  ///one can change the priority of an item, add or erase an item, etc.
   33.30 +  /// This class implements the \e Fibonacci \e heap data structure.
   33.31 +  /// It fully conforms to the \ref concepts::Heap "heap concept".
   33.32    ///
   33.33 -  ///The methods \ref increase and \ref erase are not efficient in a Fibonacci
   33.34 -  ///heap. In case of many calls to these operations, it is better to use a
   33.35 -  ///\ref BinHeap "binary heap".
   33.36 +  /// The methods \ref increase() and \ref erase() are not efficient in a
   33.37 +  /// Fibonacci heap. In case of many calls of these operations, it is
   33.38 +  /// better to use other heap structure, e.g. \ref BinHeap "binary heap".
   33.39    ///
   33.40 -  ///\param PRIO Type of the priority of the items.
   33.41 -  ///\param IM A read and writable Item int map, used internally
   33.42 -  ///to handle the cross references.
   33.43 -  ///\param CMP A class for the ordering of the priorities. The
   33.44 -  ///default is \c std::less<PRIO>.
   33.45 -  ///
   33.46 -  ///\sa BinHeap
   33.47 -  ///\sa Dijkstra
   33.48 +  /// \tparam PR Type of the priorities of the items.
   33.49 +  /// \tparam IM A read-writable item map with \c int values, used
   33.50 +  /// internally to handle the cross references.
   33.51 +  /// \tparam CMP A functor class for comparing the priorities.
   33.52 +  /// The default is \c std::less<PR>.
   33.53  #ifdef DOXYGEN
   33.54 -  template <typename PRIO, typename IM, typename CMP>
   33.55 +  template <typename PR, typename IM, typename CMP>
   33.56  #else
   33.57 -  template <typename PRIO, typename IM, typename CMP = std::less<PRIO> >
   33.58 +  template <typename PR, typename IM, typename CMP = std::less<PR> >
   33.59  #endif
   33.60    class FibHeap {
   33.61    public:
   33.62 -    ///\e
   33.63 +
   33.64 +    /// Type of the item-int map.
   33.65      typedef IM ItemIntMap;
   33.66 -    ///\e
   33.67 -    typedef PRIO Prio;
   33.68 -    ///\e
   33.69 +    /// Type of the priorities.
   33.70 +    typedef PR Prio;
   33.71 +    /// Type of the items stored in the heap.
   33.72      typedef typename ItemIntMap::Key Item;
   33.73 -    ///\e
   33.74 +    /// Type of the item-priority pairs.
   33.75      typedef std::pair<Item,Prio> Pair;
   33.76 -    ///\e
   33.77 +    /// Functor type for comparing the priorities.
   33.78      typedef CMP Compare;
   33.79  
   33.80    private:
   33.81 @@ -80,10 +76,10 @@
   33.82  
   33.83    public:
   33.84  
   33.85 -    /// \brief Type to represent the items states.
   33.86 +    /// \brief Type to represent the states of the items.
   33.87      ///
   33.88 -    /// Each Item element have a state associated to it. It may be "in heap",
   33.89 -    /// "pre heap" or "post heap". The latter two are indifferent from the
   33.90 +    /// Each item has a state associated to it. It can be "in heap",
   33.91 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
   33.92      /// heap's point of view, but may be useful to the user.
   33.93      ///
   33.94      /// The item-int map must be initialized in such way that it assigns
   33.95 @@ -94,60 +90,54 @@
   33.96        POST_HEAP = -2  ///< = -2.
   33.97      };
   33.98  
   33.99 -    /// \brief The constructor
  33.100 +    /// \brief Constructor.
  33.101      ///
  33.102 -    /// \c map should be given to the constructor, since it is
  33.103 -    ///   used internally to handle the cross references.
  33.104 +    /// Constructor.
  33.105 +    /// \param map A map that assigns \c int values to the items.
  33.106 +    /// It is used internally to handle the cross references.
  33.107 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  33.108      explicit FibHeap(ItemIntMap &map)
  33.109        : _minimum(0), _iim(map), _num() {}
  33.110  
  33.111 -    /// \brief The constructor
  33.112 +    /// \brief Constructor.
  33.113      ///
  33.114 -    /// \c map should be given to the constructor, since it is used
  33.115 -    /// internally to handle the cross references. \c comp is an
  33.116 -    /// object for ordering of the priorities.
  33.117 +    /// Constructor.
  33.118 +    /// \param map A map that assigns \c int values to the items.
  33.119 +    /// It is used internally to handle the cross references.
  33.120 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  33.121 +    /// \param comp The function object used for comparing the priorities.
  33.122      FibHeap(ItemIntMap &map, const Compare &comp)
  33.123        : _minimum(0), _iim(map), _comp(comp), _num() {}
  33.124  
  33.125      /// \brief The number of items stored in the heap.
  33.126      ///
  33.127 -    /// Returns the number of items stored in the heap.
  33.128 +    /// This function returns the number of items stored in the heap.
  33.129      int size() const { return _num; }
  33.130  
  33.131 -    /// \brief Checks if the heap stores no items.
  33.132 +    /// \brief Check if the heap is empty.
  33.133      ///
  33.134 -    ///   Returns \c true if and only if the heap stores no items.
  33.135 +    /// This function returns \c true if the heap is empty.
  33.136      bool empty() const { return _num==0; }
  33.137  
  33.138 -    /// \brief Make empty this heap.
  33.139 +    /// \brief Make the heap empty.
  33.140      ///
  33.141 -    /// Make empty this heap. It does not change the cross reference
  33.142 -    /// map.  If you want to reuse a heap what is not surely empty you
  33.143 -    /// should first clear the heap and after that you should set the
  33.144 -    /// cross reference map for each item to \c PRE_HEAP.
  33.145 +    /// This functon makes the heap empty.
  33.146 +    /// It does not change the cross reference map. If you want to reuse
  33.147 +    /// a heap that is not surely empty, you should first clear it and
  33.148 +    /// then you should set the cross reference map to \c PRE_HEAP
  33.149 +    /// for each item.
  33.150      void clear() {
  33.151        _data.clear(); _minimum = 0; _num = 0;
  33.152      }
  33.153  
  33.154 -    /// \brief \c item gets to the heap with priority \c value independently
  33.155 -    /// if \c item was already there.
  33.156 +    /// \brief Insert an item into the heap with the given priority.
  33.157      ///
  33.158 -    /// This method calls \ref push(\c item, \c value) if \c item is not
  33.159 -    /// stored in the heap and it calls \ref decrease(\c item, \c value) or
  33.160 -    /// \ref increase(\c item, \c value) otherwise.
  33.161 -    void set (const Item& item, const Prio& value) {
  33.162 -      int i=_iim[item];
  33.163 -      if ( i >= 0 && _data[i].in ) {
  33.164 -        if ( _comp(value, _data[i].prio) ) decrease(item, value);
  33.165 -        if ( _comp(_data[i].prio, value) ) increase(item, value);
  33.166 -      } else push(item, value);
  33.167 -    }
  33.168 -
  33.169 -    /// \brief Adds \c item to the heap with priority \c value.
  33.170 -    ///
  33.171 -    /// Adds \c item to the heap with priority \c value.
  33.172 -    /// \pre \c item must not be stored in the heap.
  33.173 -    void push (const Item& item, const Prio& value) {
  33.174 +    /// This function inserts the given item into the heap with the
  33.175 +    /// given priority.
  33.176 +    /// \param item The item to insert.
  33.177 +    /// \param prio The priority of the item.
  33.178 +    /// \pre \e item must not be stored in the heap.
  33.179 +    void push (const Item& item, const Prio& prio) {
  33.180        int i=_iim[item];
  33.181        if ( i < 0 ) {
  33.182          int s=_data.size();
  33.183 @@ -168,47 +158,37 @@
  33.184          _data[i].right_neighbor=_data[_minimum].right_neighbor;
  33.185          _data[_minimum].right_neighbor=i;
  33.186          _data[i].left_neighbor=_minimum;
  33.187 -        if ( _comp( value, _data[_minimum].prio) ) _minimum=i;
  33.188 +        if ( _comp( prio, _data[_minimum].prio) ) _minimum=i;
  33.189        } else {
  33.190          _data[i].right_neighbor=_data[i].left_neighbor=i;
  33.191          _minimum=i;
  33.192        }
  33.193 -      _data[i].prio=value;
  33.194 +      _data[i].prio=prio;
  33.195        ++_num;
  33.196      }
  33.197  
  33.198 -    /// \brief Returns the item with minimum priority relative to \c Compare.
  33.199 +    /// \brief Return the item having minimum priority.
  33.200      ///
  33.201 -    /// This method returns the item with minimum priority relative to \c
  33.202 -    /// Compare.
  33.203 -    /// \pre The heap must be nonempty.
  33.204 +    /// This function returns the item having minimum priority.
  33.205 +    /// \pre The heap must be non-empty.
  33.206      Item top() const { return _data[_minimum].name; }
  33.207  
  33.208 -    /// \brief Returns the minimum priority relative to \c Compare.
  33.209 +    /// \brief The minimum priority.
  33.210      ///
  33.211 -    /// It returns the minimum priority relative to \c Compare.
  33.212 -    /// \pre The heap must be nonempty.
  33.213 -    const Prio& prio() const { return _data[_minimum].prio; }
  33.214 +    /// This function returns the minimum priority.
  33.215 +    /// \pre The heap must be non-empty.
  33.216 +    Prio prio() const { return _data[_minimum].prio; }
  33.217  
  33.218 -    /// \brief Returns the priority of \c item.
  33.219 +    /// \brief Remove the item having minimum priority.
  33.220      ///
  33.221 -    /// It returns the priority of \c item.
  33.222 -    /// \pre \c item must be in the heap.
  33.223 -    const Prio& operator[](const Item& item) const {
  33.224 -      return _data[_iim[item]].prio;
  33.225 -    }
  33.226 -
  33.227 -    /// \brief Deletes the item with minimum priority relative to \c Compare.
  33.228 -    ///
  33.229 -    /// This method deletes the item with minimum priority relative to \c
  33.230 -    /// Compare from the heap.
  33.231 +    /// This function removes the item having minimum priority.
  33.232      /// \pre The heap must be non-empty.
  33.233      void pop() {
  33.234        /*The first case is that there are only one root.*/
  33.235        if ( _data[_minimum].left_neighbor==_minimum ) {
  33.236          _data[_minimum].in=false;
  33.237          if ( _data[_minimum].degree!=0 ) {
  33.238 -          makeroot(_data[_minimum].child);
  33.239 +          makeRoot(_data[_minimum].child);
  33.240            _minimum=_data[_minimum].child;
  33.241            balance();
  33.242          }
  33.243 @@ -221,7 +201,7 @@
  33.244            int child=_data[_minimum].child;
  33.245            int last_child=_data[child].left_neighbor;
  33.246  
  33.247 -          makeroot(child);
  33.248 +          makeRoot(child);
  33.249  
  33.250            _data[left].right_neighbor=child;
  33.251            _data[child].left_neighbor=left;
  33.252 @@ -234,10 +214,12 @@
  33.253        --_num;
  33.254      }
  33.255  
  33.256 -    /// \brief Deletes \c item from the heap.
  33.257 +    /// \brief Remove the given item from the heap.
  33.258      ///
  33.259 -    /// This method deletes \c item from the heap, if \c item was already
  33.260 -    /// stored in the heap. It is quite inefficient in Fibonacci heaps.
  33.261 +    /// This function removes the given item from the heap if it is
  33.262 +    /// already stored.
  33.263 +    /// \param item The item to delete.
  33.264 +    /// \pre \e item must be in the heap.
  33.265      void erase (const Item& item) {
  33.266        int i=_iim[item];
  33.267  
  33.268 @@ -252,43 +234,68 @@
  33.269        }
  33.270      }
  33.271  
  33.272 -    /// \brief Decreases the priority of \c item to \c value.
  33.273 +    /// \brief The priority of the given item.
  33.274      ///
  33.275 -    /// This method decreases the priority of \c item to \c value.
  33.276 -    /// \pre \c item must be stored in the heap with priority at least \c
  33.277 -    ///   value relative to \c Compare.
  33.278 -    void decrease (Item item, const Prio& value) {
  33.279 +    /// This function returns the priority of the given item.
  33.280 +    /// \param item The item.
  33.281 +    /// \pre \e item must be in the heap.
  33.282 +    Prio operator[](const Item& item) const {
  33.283 +      return _data[_iim[item]].prio;
  33.284 +    }
  33.285 +
  33.286 +    /// \brief Set the priority of an item or insert it, if it is
  33.287 +    /// not stored in the heap.
  33.288 +    ///
  33.289 +    /// This method sets the priority of the given item if it is
  33.290 +    /// already stored in the heap. Otherwise it inserts the given
  33.291 +    /// item into the heap with the given priority.
  33.292 +    /// \param item The item.
  33.293 +    /// \param prio The priority.
  33.294 +    void set (const Item& item, const Prio& prio) {
  33.295        int i=_iim[item];
  33.296 -      _data[i].prio=value;
  33.297 +      if ( i >= 0 && _data[i].in ) {
  33.298 +        if ( _comp(prio, _data[i].prio) ) decrease(item, prio);
  33.299 +        if ( _comp(_data[i].prio, prio) ) increase(item, prio);
  33.300 +      } else push(item, prio);
  33.301 +    }
  33.302 +
  33.303 +    /// \brief Decrease the priority of an item to the given value.
  33.304 +    ///
  33.305 +    /// This function decreases the priority of an item to the given value.
  33.306 +    /// \param item The item.
  33.307 +    /// \param prio The priority.
  33.308 +    /// \pre \e item must be stored in the heap with priority at least \e prio.
  33.309 +    void decrease (const Item& item, const Prio& prio) {
  33.310 +      int i=_iim[item];
  33.311 +      _data[i].prio=prio;
  33.312        int p=_data[i].parent;
  33.313  
  33.314 -      if ( p!=-1 && _comp(value, _data[p].prio) ) {
  33.315 +      if ( p!=-1 && _comp(prio, _data[p].prio) ) {
  33.316          cut(i,p);
  33.317          cascade(p);
  33.318        }
  33.319 -      if ( _comp(value, _data[_minimum].prio) ) _minimum=i;
  33.320 +      if ( _comp(prio, _data[_minimum].prio) ) _minimum=i;
  33.321      }
  33.322  
  33.323 -    /// \brief Increases the priority of \c item to \c value.
  33.324 +    /// \brief Increase the priority of an item to the given value.
  33.325      ///
  33.326 -    /// This method sets the priority of \c item to \c value. Though
  33.327 -    /// there is no precondition on the priority of \c item, this
  33.328 -    /// method should be used only if it is indeed necessary to increase
  33.329 -    /// (relative to \c Compare) the priority of \c item, because this
  33.330 -    /// method is inefficient.
  33.331 -    void increase (Item item, const Prio& value) {
  33.332 +    /// This function increases the priority of an item to the given value.
  33.333 +    /// \param item The item.
  33.334 +    /// \param prio The priority.
  33.335 +    /// \pre \e item must be stored in the heap with priority at most \e prio.
  33.336 +    void increase (const Item& item, const Prio& prio) {
  33.337        erase(item);
  33.338 -      push(item, value);
  33.339 +      push(item, prio);
  33.340      }
  33.341  
  33.342 -
  33.343 -    /// \brief Returns if \c item is in, has already been in, or has never
  33.344 -    /// been in the heap.
  33.345 +    /// \brief Return the state of an item.
  33.346      ///
  33.347 -    /// This method returns PRE_HEAP if \c item has never been in the
  33.348 -    /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
  33.349 -    /// otherwise. In the latter case it is possible that \c item will
  33.350 -    /// get back to the heap again.
  33.351 +    /// This method returns \c PRE_HEAP if the given item has never
  33.352 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  33.353 +    /// and \c POST_HEAP otherwise.
  33.354 +    /// In the latter case it is possible that the item will get back
  33.355 +    /// to the heap again.
  33.356 +    /// \param item The item.
  33.357      State state(const Item &item) const {
  33.358        int i=_iim[item];
  33.359        if( i>=0 ) {
  33.360 @@ -298,11 +305,11 @@
  33.361        return State(i);
  33.362      }
  33.363  
  33.364 -    /// \brief Sets the state of the \c item in the heap.
  33.365 +    /// \brief Set the state of an item in the heap.
  33.366      ///
  33.367 -    /// Sets the state of the \c item in the heap. It can be used to
  33.368 -    /// manually clear the heap when it is important to achive the
  33.369 -    /// better time _complexity.
  33.370 +    /// This function sets the state of the given item in the heap.
  33.371 +    /// It can be used to manually clear the heap when it is important
  33.372 +    /// to achive better time complexity.
  33.373      /// \param i The item.
  33.374      /// \param st The state. It should not be \c IN_HEAP.
  33.375      void state(const Item& i, State st) {
  33.376 @@ -365,7 +372,7 @@
  33.377        } while ( s != m );
  33.378      }
  33.379  
  33.380 -    void makeroot(int c) {
  33.381 +    void makeRoot(int c) {
  33.382        int s=c;
  33.383        do {
  33.384          _data[s].parent=-1;
    34.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.2 +++ b/lemon/fourary_heap.h	Thu Nov 05 10:23:16 2009 +0100
    34.3 @@ -0,0 +1,342 @@
    34.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
    34.5 + *
    34.6 + * This file is a part of LEMON, a generic C++ optimization library.
    34.7 + *
    34.8 + * Copyright (C) 2003-2009
    34.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   34.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
   34.11 + *
   34.12 + * Permission to use, modify and distribute this software is granted
   34.13 + * provided that this copyright notice appears in all copies. For
   34.14 + * precise terms see the accompanying LICENSE file.
   34.15 + *
   34.16 + * This software is provided "AS IS" with no warranty of any kind,
   34.17 + * express or implied, and with no claim as to its suitability for any
   34.18 + * purpose.
   34.19 + *
   34.20 + */
   34.21 +
   34.22 +#ifndef LEMON_FOURARY_HEAP_H
   34.23 +#define LEMON_FOURARY_HEAP_H
   34.24 +
   34.25 +///\ingroup heaps
   34.26 +///\file
   34.27 +///\brief Fourary heap implementation.
   34.28 +
   34.29 +#include <vector>
   34.30 +#include <utility>
   34.31 +#include <functional>
   34.32 +
   34.33 +namespace lemon {
   34.34 +
   34.35 +  /// \ingroup heaps
   34.36 +  ///
   34.37 +  ///\brief Fourary heap data structure.
   34.38 +  ///
   34.39 +  /// This class implements the \e fourary \e heap data structure.
   34.40 +  /// It fully conforms to the \ref concepts::Heap "heap concept".
   34.41 +  ///
   34.42 +  /// The fourary heap is a specialization of the \ref KaryHeap "K-ary heap"
   34.43 +  /// for <tt>K=4</tt>. It is similar to the \ref BinHeap "binary heap",
   34.44 +  /// but its nodes have at most four children, instead of two.
   34.45 +  ///
   34.46 +  /// \tparam PR Type of the priorities of the items.
   34.47 +  /// \tparam IM A read-writable item map with \c int values, used
   34.48 +  /// internally to handle the cross references.
   34.49 +  /// \tparam CMP A functor class for comparing the priorities.
   34.50 +  /// The default is \c std::less<PR>.
   34.51 +  ///
   34.52 +  ///\sa BinHeap
   34.53 +  ///\sa KaryHeap
   34.54 +#ifdef DOXYGEN
   34.55 +  template <typename PR, typename IM, typename CMP>
   34.56 +#else
   34.57 +  template <typename PR, typename IM, typename CMP = std::less<PR> >
   34.58 +#endif
   34.59 +  class FouraryHeap {
   34.60 +  public:
   34.61 +    /// Type of the item-int map.
   34.62 +    typedef IM ItemIntMap;
   34.63 +    /// Type of the priorities.
   34.64 +    typedef PR Prio;
   34.65 +    /// Type of the items stored in the heap.
   34.66 +    typedef typename ItemIntMap::Key Item;
   34.67 +    /// Type of the item-priority pairs.
   34.68 +    typedef std::pair<Item,Prio> Pair;
   34.69 +    /// Functor type for comparing the priorities.
   34.70 +    typedef CMP Compare;
   34.71 +
   34.72 +    /// \brief Type to represent the states of the items.
   34.73 +    ///
   34.74 +    /// Each item has a state associated to it. It can be "in heap",
   34.75 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
   34.76 +    /// heap's point of view, but may be useful to the user.
   34.77 +    ///
   34.78 +    /// The item-int map must be initialized in such way that it assigns
   34.79 +    /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
   34.80 +    enum State {
   34.81 +      IN_HEAP = 0,    ///< = 0.
   34.82 +      PRE_HEAP = -1,  ///< = -1.
   34.83 +      POST_HEAP = -2  ///< = -2.
   34.84 +    };
   34.85 +
   34.86 +  private:
   34.87 +    std::vector<Pair> _data;
   34.88 +    Compare _comp;
   34.89 +    ItemIntMap &_iim;
   34.90 +
   34.91 +  public:
   34.92 +    /// \brief Constructor.
   34.93 +    ///
   34.94 +    /// Constructor.
   34.95 +    /// \param map A map that assigns \c int values to the items.
   34.96 +    /// It is used internally to handle the cross references.
   34.97 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
   34.98 +    explicit FouraryHeap(ItemIntMap &map) : _iim(map) {}
   34.99 +
  34.100 +    /// \brief Constructor.
  34.101 +    ///
  34.102 +    /// Constructor.
  34.103 +    /// \param map A map that assigns \c int values to the items.
  34.104 +    /// It is used internally to handle the cross references.
  34.105 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  34.106 +    /// \param comp The function object used for comparing the priorities.
  34.107 +    FouraryHeap(ItemIntMap &map, const Compare &comp)
  34.108 +      : _iim(map), _comp(comp) {}
  34.109 +
  34.110 +    /// \brief The number of items stored in the heap.
  34.111 +    ///
  34.112 +    /// This function returns the number of items stored in the heap.
  34.113 +    int size() const { return _data.size(); }
  34.114 +
  34.115 +    /// \brief Check if the heap is empty.
  34.116 +    ///
  34.117 +    /// This function returns \c true if the heap is empty.
  34.118 +    bool empty() const { return _data.empty(); }
  34.119 +
  34.120 +    /// \brief Make the heap empty.
  34.121 +    ///
  34.122 +    /// This functon makes the heap empty.
  34.123 +    /// It does not change the cross reference map. If you want to reuse
  34.124 +    /// a heap that is not surely empty, you should first clear it and
  34.125 +    /// then you should set the cross reference map to \c PRE_HEAP
  34.126 +    /// for each item.
  34.127 +    void clear() { _data.clear(); }
  34.128 +
  34.129 +  private:
  34.130 +    static int parent(int i) { return (i-1)/4; }
  34.131 +    static int firstChild(int i) { return 4*i+1; }
  34.132 +
  34.133 +    bool less(const Pair &p1, const Pair &p2) const {
  34.134 +      return _comp(p1.second, p2.second);
  34.135 +    }
  34.136 +
  34.137 +    void bubbleUp(int hole, Pair p) {
  34.138 +      int par = parent(hole);
  34.139 +      while( hole>0 && less(p,_data[par]) ) {
  34.140 +        move(_data[par],hole);
  34.141 +        hole = par;
  34.142 +        par = parent(hole);
  34.143 +      }
  34.144 +      move(p, hole);
  34.145 +    }
  34.146 +
  34.147 +    void bubbleDown(int hole, Pair p, int length) {
  34.148 +      if( length>1 ) {
  34.149 +        int child = firstChild(hole);
  34.150 +        while( child+3<length ) {
  34.151 +          int min=child;
  34.152 +          if( less(_data[++child], _data[min]) ) min=child;
  34.153 +          if( less(_data[++child], _data[min]) ) min=child;
  34.154 +          if( less(_data[++child], _data[min]) ) min=child;
  34.155 +          if( !less(_data[min], p) )
  34.156 +            goto ok;
  34.157 +          move(_data[min], hole);
  34.158 +          hole = min;
  34.159 +          child = firstChild(hole);
  34.160 +        }
  34.161 +        if ( child<length ) {
  34.162 +          int min = child;
  34.163 +          if( ++child<length && less(_data[child], _data[min]) ) min=child;
  34.164 +          if( ++child<length && less(_data[child], _data[min]) ) min=child;
  34.165 +          if( less(_data[min], p) ) {
  34.166 +            move(_data[min], hole);
  34.167 +            hole = min;
  34.168 +          }
  34.169 +        }
  34.170 +      }
  34.171 +    ok:
  34.172 +      move(p, hole);
  34.173 +    }
  34.174 +
  34.175 +    void move(const Pair &p, int i) {
  34.176 +      _data[i] = p;
  34.177 +      _iim.set(p.first, i);
  34.178 +    }
  34.179 +
  34.180 +  public:
  34.181 +    /// \brief Insert a pair of item and priority into the heap.
  34.182 +    ///
  34.183 +    /// This function inserts \c p.first to the heap with priority
  34.184 +    /// \c p.second.
  34.185 +    /// \param p The pair to insert.
  34.186 +    /// \pre \c p.first must not be stored in the heap.
  34.187 +    void push(const Pair &p) {
  34.188 +      int n = _data.size();
  34.189 +      _data.resize(n+1);
  34.190 +      bubbleUp(n, p);
  34.191 +    }
  34.192 +
  34.193 +    /// \brief Insert an item into the heap with the given priority.
  34.194 +    ///
  34.195 +    /// This function inserts the given item into the heap with the
  34.196 +    /// given priority.
  34.197 +    /// \param i The item to insert.
  34.198 +    /// \param p The priority of the item.
  34.199 +    /// \pre \e i must not be stored in the heap.
  34.200 +    void push(const Item &i, const Prio &p) { push(Pair(i,p)); }
  34.201 +
  34.202 +    /// \brief Return the item having minimum priority.
  34.203 +    ///
  34.204 +    /// This function returns the item having minimum priority.
  34.205 +    /// \pre The heap must be non-empty.
  34.206 +    Item top() const { return _data[0].first; }
  34.207 +
  34.208 +    /// \brief The minimum priority.
  34.209 +    ///
  34.210 +    /// This function returns the minimum priority.
  34.211 +    /// \pre The heap must be non-empty.
  34.212 +    Prio prio() const { return _data[0].second; }
  34.213 +
  34.214 +    /// \brief Remove the item having minimum priority.
  34.215 +    ///
  34.216 +    /// This function removes the item having minimum priority.
  34.217 +    /// \pre The heap must be non-empty.
  34.218 +    void pop() {
  34.219 +      int n = _data.size()-1;
  34.220 +      _iim.set(_data[0].first, POST_HEAP);
  34.221 +      if (n>0) bubbleDown(0, _data[n], n);
  34.222 +      _data.pop_back();
  34.223 +    }
  34.224 +
  34.225 +    /// \brief Remove the given item from the heap.
  34.226 +    ///
  34.227 +    /// This function removes the given item from the heap if it is
  34.228 +    /// already stored.
  34.229 +    /// \param i The item to delete.
  34.230 +    /// \pre \e i must be in the heap.
  34.231 +    void erase(const Item &i) {
  34.232 +      int h = _iim[i];
  34.233 +      int n = _data.size()-1;
  34.234 +      _iim.set(_data[h].first, POST_HEAP);
  34.235 +      if( h<n ) {
  34.236 +        if( less(_data[parent(h)], _data[n]) )
  34.237 +          bubbleDown(h, _data[n], n);
  34.238 +        else
  34.239 +          bubbleUp(h, _data[n]);
  34.240 +      }
  34.241 +      _data.pop_back();
  34.242 +    }
  34.243 +
  34.244 +    /// \brief The priority of the given item.
  34.245 +    ///
  34.246 +    /// This function returns the priority of the given item.
  34.247 +    /// \param i The item.
  34.248 +    /// \pre \e i must be in the heap.
  34.249 +    Prio operator[](const Item &i) const {
  34.250 +      int idx = _iim[i];
  34.251 +      return _data[idx].second;
  34.252 +    }
  34.253 +
  34.254 +    /// \brief Set the priority of an item or insert it, if it is
  34.255 +    /// not stored in the heap.
  34.256 +    ///
  34.257 +    /// This method sets the priority of the given item if it is
  34.258 +    /// already stored in the heap. Otherwise it inserts the given
  34.259 +    /// item into the heap with the given priority.
  34.260 +    /// \param i The item.
  34.261 +    /// \param p The priority.
  34.262 +    void set(const Item &i, const Prio &p) {
  34.263 +      int idx = _iim[i];
  34.264 +      if( idx < 0 )
  34.265 +        push(i,p);
  34.266 +      else if( _comp(p, _data[idx].second) )
  34.267 +        bubbleUp(idx, Pair(i,p));
  34.268 +      else
  34.269 +        bubbleDown(idx, Pair(i,p), _data.size());
  34.270 +    }
  34.271 +
  34.272 +    /// \brief Decrease the priority of an item to the given value.
  34.273 +    ///
  34.274 +    /// This function decreases the priority of an item to the given value.
  34.275 +    /// \param i The item.
  34.276 +    /// \param p The priority.
  34.277 +    /// \pre \e i must be stored in the heap with priority at least \e p.
  34.278 +    void decrease(const Item &i, const Prio &p) {
  34.279 +      int idx = _iim[i];
  34.280 +      bubbleUp(idx, Pair(i,p));
  34.281 +    }
  34.282 +
  34.283 +    /// \brief Increase the priority of an item to the given value.
  34.284 +    ///
  34.285 +    /// This function increases the priority of an item to the given value.
  34.286 +    /// \param i The item.
  34.287 +    /// \param p The priority.
  34.288 +    /// \pre \e i must be stored in the heap with priority at most \e p.
  34.289 +    void increase(const Item &i, const Prio &p) {
  34.290 +      int idx = _iim[i];
  34.291 +      bubbleDown(idx, Pair(i,p), _data.size());
  34.292 +    }
  34.293 +
  34.294 +    /// \brief Return the state of an item.
  34.295 +    ///
  34.296 +    /// This method returns \c PRE_HEAP if the given item has never
  34.297 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  34.298 +    /// and \c POST_HEAP otherwise.
  34.299 +    /// In the latter case it is possible that the item will get back
  34.300 +    /// to the heap again.
  34.301 +    /// \param i The item.
  34.302 +    State state(const Item &i) const {
  34.303 +      int s = _iim[i];
  34.304 +      if (s>=0) s=0;
  34.305 +      return State(s);
  34.306 +    }
  34.307 +
  34.308 +    /// \brief Set the state of an item in the heap.
  34.309 +    ///
  34.310 +    /// This function sets the state of the given item in the heap.
  34.311 +    /// It can be used to manually clear the heap when it is important
  34.312 +    /// to achive better time complexity.
  34.313 +    /// \param i The item.
  34.314 +    /// \param st The state. It should not be \c IN_HEAP.
  34.315 +    void state(const Item& i, State st) {
  34.316 +      switch (st) {
  34.317 +        case POST_HEAP:
  34.318 +        case PRE_HEAP:
  34.319 +          if (state(i) == IN_HEAP) erase(i);
  34.320 +          _iim[i] = st;
  34.321 +          break;
  34.322 +        case IN_HEAP:
  34.323 +          break;
  34.324 +      }
  34.325 +    }
  34.326 +
  34.327 +    /// \brief Replace an item in the heap.
  34.328 +    ///
  34.329 +    /// This function replaces item \c i with item \c j.
  34.330 +    /// Item \c i must be in the heap, while \c j must be out of the heap.
  34.331 +    /// After calling this method, item \c i will be out of the
  34.332 +    /// heap and \c j will be in the heap with the same prioriority
  34.333 +    /// as item \c i had before.
  34.334 +    void replace(const Item& i, const Item& j) {
  34.335 +      int idx = _iim[i];
  34.336 +      _iim.set(i, _iim[j]);
  34.337 +      _iim.set(j, idx);
  34.338 +      _data[idx].first = j;
  34.339 +    }
  34.340 +
  34.341 +  }; // class FouraryHeap
  34.342 +
  34.343 +} // namespace lemon
  34.344 +
  34.345 +#endif // LEMON_FOURARY_HEAP_H
    35.1 --- a/lemon/full_graph.h	Thu Nov 05 10:01:02 2009 +0100
    35.2 +++ b/lemon/full_graph.h	Thu Nov 05 10:23:16 2009 +0100
    35.3 @@ -24,7 +24,7 @@
    35.4  
    35.5  ///\ingroup graphs
    35.6  ///\file
    35.7 -///\brief FullGraph and FullDigraph classes.
    35.8 +///\brief FullDigraph and FullGraph classes.
    35.9  
   35.10  namespace lemon {
   35.11  
   35.12 @@ -148,24 +148,26 @@
   35.13  
   35.14    /// \ingroup graphs
   35.15    ///
   35.16 -  /// \brief A full digraph class.
   35.17 +  /// \brief A directed full graph class.
   35.18    ///
   35.19 -  /// This is a simple and fast directed full graph implementation.
   35.20 -  /// From each node go arcs to each node (including the source node),
   35.21 -  /// therefore the number of the arcs in the digraph is the square of
   35.22 -  /// the node number. This digraph type is completely static, so you
   35.23 -  /// can neither add nor delete either arcs or nodes, and it needs
   35.24 -  /// constant space in memory.
   35.25 +  /// FullDigraph is a simple and fast implmenetation of directed full
   35.26 +  /// (complete) graphs. It contains an arc from each node to each node
   35.27 +  /// (including a loop for each node), therefore the number of arcs
   35.28 +  /// is the square of the number of nodes.
   35.29 +  /// This class is completely static and it needs constant memory space.
   35.30 +  /// Thus you can neither add nor delete nodes or arcs, however
   35.31 +  /// the structure can be resized using resize().
   35.32    ///
   35.33 -  /// This class fully conforms to the \ref concepts::Digraph
   35.34 -  /// "Digraph concept".
   35.35 +  /// This type fully conforms to the \ref concepts::Digraph "Digraph concept".
   35.36 +  /// Most of its member functions and nested classes are documented
   35.37 +  /// only in the concept class.
   35.38    ///
   35.39 -  /// The \c FullDigraph and \c FullGraph classes are very similar,
   35.40 +  /// \note FullDigraph and FullGraph classes are very similar,
   35.41    /// but there are two differences. While this class conforms only
   35.42 -  /// to the \ref concepts::Digraph "Digraph" concept, the \c FullGraph
   35.43 -  /// class conforms to the \ref concepts::Graph "Graph" concept,
   35.44 -  /// moreover \c FullGraph does not contain a loop arc for each
   35.45 -  /// node as \c FullDigraph does.
   35.46 +  /// to the \ref concepts::Digraph "Digraph" concept, FullGraph
   35.47 +  /// conforms to the \ref concepts::Graph "Graph" concept,
   35.48 +  /// moreover FullGraph does not contain a loop for each
   35.49 +  /// node as this class does.
   35.50    ///
   35.51    /// \sa FullGraph
   35.52    class FullDigraph : public ExtendedFullDigraphBase {
   35.53 @@ -173,7 +175,9 @@
   35.54  
   35.55    public:
   35.56  
   35.57 -    /// \brief Constructor
   35.58 +    /// \brief Default constructor.
   35.59 +    ///
   35.60 +    /// Default constructor. The number of nodes and arcs will be zero.
   35.61      FullDigraph() { construct(0); }
   35.62  
   35.63      /// \brief Constructor
   35.64 @@ -184,8 +188,8 @@
   35.65  
   35.66      /// \brief Resizes the digraph
   35.67      ///
   35.68 -    /// Resizes the digraph. The function will fully destroy and
   35.69 -    /// rebuild the digraph. This cause that the maps of the digraph will
   35.70 +    /// This function resizes the digraph. It fully destroys and
   35.71 +    /// rebuilds the structure, therefore the maps of the digraph will be
   35.72      /// reallocated automatically and the previous values will be lost.
   35.73      void resize(int n) {
   35.74        Parent::notifier(Arc()).clear();
   35.75 @@ -197,24 +201,24 @@
   35.76  
   35.77      /// \brief Returns the node with the given index.
   35.78      ///
   35.79 -    /// Returns the node with the given index. Since it is a static
   35.80 -    /// digraph its nodes can be indexed with integers from the range
   35.81 -    /// <tt>[0..nodeNum()-1]</tt>.
   35.82 +    /// Returns the node with the given index. Since this structure is 
   35.83 +    /// completely static, the nodes can be indexed with integers from
   35.84 +    /// the range <tt>[0..nodeNum()-1]</tt>.
   35.85      /// \sa index()
   35.86      Node operator()(int ix) const { return Parent::operator()(ix); }
   35.87  
   35.88      /// \brief Returns the index of the given node.
   35.89      ///
   35.90 -    /// Returns the index of the given node. Since it is a static
   35.91 -    /// digraph its nodes can be indexed with integers from the range
   35.92 -    /// <tt>[0..nodeNum()-1]</tt>.
   35.93 -    /// \sa operator()
   35.94 +    /// Returns the index of the given node. Since this structure is 
   35.95 +    /// completely static, the nodes can be indexed with integers from
   35.96 +    /// the range <tt>[0..nodeNum()-1]</tt>.
   35.97 +    /// \sa operator()()
   35.98      static int index(const Node& node) { return Parent::index(node); }
   35.99  
  35.100      /// \brief Returns the arc connecting the given nodes.
  35.101      ///
  35.102      /// Returns the arc connecting the given nodes.
  35.103 -    Arc arc(const Node& u, const Node& v) const {
  35.104 +    Arc arc(Node u, Node v) const {
  35.105        return Parent::arc(u, v);
  35.106      }
  35.107  
  35.108 @@ -520,21 +524,23 @@
  35.109    ///
  35.110    /// \brief An undirected full graph class.
  35.111    ///
  35.112 -  /// This is a simple and fast undirected full graph
  35.113 -  /// implementation. From each node go edge to each other node,
  35.114 -  /// therefore the number of edges in the graph is \f$n(n-1)/2\f$.
  35.115 -  /// This graph type is completely static, so you can neither
  35.116 -  /// add nor delete either edges or nodes, and it needs constant
  35.117 -  /// space in memory.
  35.118 +  /// FullGraph is a simple and fast implmenetation of undirected full
  35.119 +  /// (complete) graphs. It contains an edge between every distinct pair
  35.120 +  /// of nodes, therefore the number of edges is <tt>n(n-1)/2</tt>.
  35.121 +  /// This class is completely static and it needs constant memory space.
  35.122 +  /// Thus you can neither add nor delete nodes or edges, however
  35.123 +  /// the structure can be resized using resize().
  35.124    ///
  35.125 -  /// This class fully conforms to the \ref concepts::Graph "Graph concept".
  35.126 +  /// This type fully conforms to the \ref concepts::Graph "Graph concept".
  35.127 +  /// Most of its member functions and nested classes are documented
  35.128 +  /// only in the concept class.
  35.129    ///
  35.130 -  /// The \c FullGraph and \c FullDigraph classes are very similar,
  35.131 -  /// but there are two differences. While the \c FullDigraph class
  35.132 +  /// \note FullDigraph and FullGraph classes are very similar,
  35.133 +  /// but there are two differences. While FullDigraph
  35.134    /// conforms only to the \ref concepts::Digraph "Digraph" concept,
  35.135    /// this class conforms to the \ref concepts::Graph "Graph" concept,
  35.136 -  /// moreover \c FullGraph does not contain a loop arc for each
  35.137 -  /// node as \c FullDigraph does.
  35.138 +  /// moreover this class does not contain a loop for each
  35.139 +  /// node as FullDigraph does.
  35.140    ///
  35.141    /// \sa FullDigraph
  35.142    class FullGraph : public ExtendedFullGraphBase {
  35.143 @@ -542,7 +548,9 @@
  35.144  
  35.145    public:
  35.146  
  35.147 -    /// \brief Constructor
  35.148 +    /// \brief Default constructor.
  35.149 +    ///
  35.150 +    /// Default constructor. The number of nodes and edges will be zero.
  35.151      FullGraph() { construct(0); }
  35.152  
  35.153      /// \brief Constructor
  35.154 @@ -553,8 +561,8 @@
  35.155  
  35.156      /// \brief Resizes the graph
  35.157      ///
  35.158 -    /// Resizes the graph. The function will fully destroy and
  35.159 -    /// rebuild the graph. This cause that the maps of the graph will
  35.160 +    /// This function resizes the graph. It fully destroys and
  35.161 +    /// rebuilds the structure, therefore the maps of the graph will be
  35.162      /// reallocated automatically and the previous values will be lost.
  35.163      void resize(int n) {
  35.164        Parent::notifier(Arc()).clear();
  35.165 @@ -568,31 +576,31 @@
  35.166  
  35.167      /// \brief Returns the node with the given index.
  35.168      ///
  35.169 -    /// Returns the node with the given index. Since it is a static
  35.170 -    /// graph its nodes can be indexed with integers from the range
  35.171 -    /// <tt>[0..nodeNum()-1]</tt>.
  35.172 +    /// Returns the node with the given index. Since this structure is 
  35.173 +    /// completely static, the nodes can be indexed with integers from
  35.174 +    /// the range <tt>[0..nodeNum()-1]</tt>.
  35.175      /// \sa index()
  35.176      Node operator()(int ix) const { return Parent::operator()(ix); }
  35.177  
  35.178      /// \brief Returns the index of the given node.
  35.179      ///
  35.180 -    /// Returns the index of the given node. Since it is a static
  35.181 -    /// graph its nodes can be indexed with integers from the range
  35.182 -    /// <tt>[0..nodeNum()-1]</tt>.
  35.183 -    /// \sa operator()
  35.184 +    /// Returns the index of the given node. Since this structure is 
  35.185 +    /// completely static, the nodes can be indexed with integers from
  35.186 +    /// the range <tt>[0..nodeNum()-1]</tt>.
  35.187 +    /// \sa operator()()
  35.188      static int index(const Node& node) { return Parent::index(node); }
  35.189  
  35.190      /// \brief Returns the arc connecting the given nodes.
  35.191      ///
  35.192      /// Returns the arc connecting the given nodes.
  35.193 -    Arc arc(const Node& s, const Node& t) const {
  35.194 +    Arc arc(Node s, Node t) const {
  35.195        return Parent::arc(s, t);
  35.196      }
  35.197  
  35.198 -    /// \brief Returns the edge connects the given nodes.
  35.199 +    /// \brief Returns the edge connecting the given nodes.
  35.200      ///
  35.201 -    /// Returns the edge connects the given nodes.
  35.202 -    Edge edge(const Node& u, const Node& v) const {
  35.203 +    /// Returns the edge connecting the given nodes.
  35.204 +    Edge edge(Node u, Node v) const {
  35.205        return Parent::edge(u, v);
  35.206      }
  35.207  
    36.1 --- a/lemon/glpk.cc	Thu Nov 05 10:01:02 2009 +0100
    36.2 +++ b/lemon/glpk.cc	Thu Nov 05 10:23:16 2009 +0100
    36.3 @@ -59,6 +59,42 @@
    36.4      return i;
    36.5    }
    36.6  
    36.7 +  int GlpkBase::_addRow(Value lo, ExprIterator b, 
    36.8 +                        ExprIterator e, Value up) {
    36.9 +    int i = glp_add_rows(lp, 1);
   36.10 +
   36.11 +    if (lo == -INF) {
   36.12 +      if (up == INF) {
   36.13 +        glp_set_row_bnds(lp, i, GLP_FR, lo, up);
   36.14 +      } else {
   36.15 +        glp_set_row_bnds(lp, i, GLP_UP, lo, up);
   36.16 +      }    
   36.17 +    } else {
   36.18 +      if (up == INF) {
   36.19 +        glp_set_row_bnds(lp, i, GLP_LO, lo, up);
   36.20 +      } else if (lo != up) {        
   36.21 +        glp_set_row_bnds(lp, i, GLP_DB, lo, up);
   36.22 +      } else {
   36.23 +        glp_set_row_bnds(lp, i, GLP_FX, lo, up);
   36.24 +      }
   36.25 +    }
   36.26 +
   36.27 +    std::vector<int> indexes;
   36.28 +    std::vector<Value> values;
   36.29 +
   36.30 +    indexes.push_back(0);
   36.31 +    values.push_back(0);
   36.32 +
   36.33 +    for(ExprIterator it = b; it != e; ++it) {
   36.34 +      indexes.push_back(it->first);
   36.35 +      values.push_back(it->second);
   36.36 +    }
   36.37 +
   36.38 +    glp_set_mat_row(lp, i, values.size() - 1,
   36.39 +                    &indexes.front(), &values.front());
   36.40 +    return i;
   36.41 +  }
   36.42 +
   36.43    void GlpkBase::_eraseCol(int i) {
   36.44      int ca[2];
   36.45      ca[1] = i;
    37.1 --- a/lemon/glpk.h	Thu Nov 05 10:01:02 2009 +0100
    37.2 +++ b/lemon/glpk.h	Thu Nov 05 10:23:16 2009 +0100
    37.3 @@ -54,6 +54,7 @@
    37.4  
    37.5      virtual int _addCol();
    37.6      virtual int _addRow();
    37.7 +    virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
    37.8  
    37.9      virtual void _eraseCol(int i);
   37.10      virtual void _eraseRow(int i);
    38.1 --- a/lemon/gomory_hu.h	Thu Nov 05 10:01:02 2009 +0100
    38.2 +++ b/lemon/gomory_hu.h	Thu Nov 05 10:23:16 2009 +0100
    38.3 @@ -359,10 +359,10 @@
    38.4      /// This example counts the nodes in the minimum cut separating \c s from
    38.5      /// \c t.
    38.6      /// \code
    38.7 -    /// GomoruHu<Graph> gom(g, capacities);
    38.8 +    /// GomoryHu<Graph> gom(g, capacities);
    38.9      /// gom.run();
   38.10      /// int cnt=0;
   38.11 -    /// for(GomoruHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt;
   38.12 +    /// for(GomoryHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt;
   38.13      /// \endcode
   38.14      class MinCutNodeIt
   38.15      {
   38.16 @@ -456,10 +456,10 @@
   38.17      /// This example computes the value of the minimum cut separating \c s from
   38.18      /// \c t.
   38.19      /// \code
   38.20 -    /// GomoruHu<Graph> gom(g, capacities);
   38.21 +    /// GomoryHu<Graph> gom(g, capacities);
   38.22      /// gom.run();
   38.23      /// int value=0;
   38.24 -    /// for(GomoruHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e)
   38.25 +    /// for(GomoryHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e)
   38.26      ///   value+=capacities[e];
   38.27      /// \endcode
   38.28      /// The result will be the same as the value returned by
    39.1 --- a/lemon/grid_graph.h	Thu Nov 05 10:01:02 2009 +0100
    39.2 +++ b/lemon/grid_graph.h	Thu Nov 05 10:23:16 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,19 @@
   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    class GridGraph : public ExtendedGridGraphBase {
   39.44      typedef ExtendedGridGraphBase Parent;
   39.45  
   39.46    public:
   39.47  
   39.48 -    /// \brief Map to get the indices of the nodes as dim2::Point<int>.
   39.49 +    /// \brief Map to get the indices of the nodes as \ref dim2::Point
   39.50 +    /// "dim2::Point<int>".
   39.51      ///
   39.52 -    /// Map to get the indices of the nodes as dim2::Point<int>.
   39.53 +    /// Map to get the indices of the nodes as \ref dim2::Point
   39.54 +    /// "dim2::Point<int>".
   39.55      class IndexMap {
   39.56      public:
   39.57        /// \brief The key type of the map
   39.58 @@ -514,13 +521,9 @@
   39.59        typedef dim2::Point<int> Value;
   39.60  
   39.61        /// \brief Constructor
   39.62 -      ///
   39.63 -      /// Constructor
   39.64        IndexMap(const GridGraph& graph) : _graph(graph) {}
   39.65  
   39.66        /// \brief The subscript operator
   39.67 -      ///
   39.68 -      /// The subscript operator.
   39.69        Value operator[](Key key) const {
   39.70          return _graph.pos(key);
   39.71        }
   39.72 @@ -540,13 +543,9 @@
   39.73        typedef int Value;
   39.74  
   39.75        /// \brief Constructor
   39.76 -      ///
   39.77 -      /// Constructor
   39.78        ColMap(const GridGraph& graph) : _graph(graph) {}
   39.79  
   39.80        /// \brief The subscript operator
   39.81 -      ///
   39.82 -      /// The subscript operator.
   39.83        Value operator[](Key key) const {
   39.84          return _graph.col(key);
   39.85        }
   39.86 @@ -566,13 +565,9 @@
   39.87        typedef int Value;
   39.88  
   39.89        /// \brief Constructor
   39.90 -      ///
   39.91 -      /// Constructor
   39.92        RowMap(const GridGraph& graph) : _graph(graph) {}
   39.93  
   39.94        /// \brief The subscript operator
   39.95 -      ///
   39.96 -      /// The subscript operator.
   39.97        Value operator[](Key key) const {
   39.98          return _graph.row(key);
   39.99        }
  39.100 @@ -583,15 +578,14 @@
  39.101  
  39.102      /// \brief Constructor
  39.103      ///
  39.104 -    /// Construct a grid graph with given size.
  39.105 +    /// Construct a grid graph with the given size.
  39.106      GridGraph(int width, int height) { construct(width, height); }
  39.107  
  39.108 -    /// \brief Resize the graph
  39.109 +    /// \brief Resizes the graph
  39.110      ///
  39.111 -    /// Resize the graph. The function will fully destroy and rebuild
  39.112 -    /// the graph.  This cause that the maps of the graph will
  39.113 -    /// reallocated automatically and the previous values will be
  39.114 -    /// lost.
  39.115 +    /// This function resizes the graph. It fully destroys and
  39.116 +    /// rebuilds the structure, therefore the maps of the graph will be
  39.117 +    /// reallocated automatically and the previous values will be lost.
  39.118      void resize(int width, int height) {
  39.119        Parent::notifier(Arc()).clear();
  39.120        Parent::notifier(Edge()).clear();
  39.121 @@ -609,42 +603,42 @@
  39.122        return Parent::operator()(i, j);
  39.123      }
  39.124  
  39.125 -    /// \brief Gives back the column index of the node.
  39.126 +    /// \brief The column index of the node.
  39.127      ///
  39.128      /// Gives back the column index of the node.
  39.129      int col(Node n) const {
  39.130        return Parent::col(n);
  39.131      }
  39.132  
  39.133 -    /// \brief Gives back the row index of the node.
  39.134 +    /// \brief The row index of the node.
  39.135      ///
  39.136      /// Gives back the row index of the node.
  39.137      int row(Node n) const {
  39.138        return Parent::row(n);
  39.139      }
  39.140  
  39.141 -    /// \brief Gives back the position of the node.
  39.142 +    /// \brief The position of the node.
  39.143      ///
  39.144      /// Gives back the position of the node, ie. the <tt>(col,row)</tt> pair.
  39.145      dim2::Point<int> pos(Node n) const {
  39.146        return Parent::pos(n);
  39.147      }
  39.148  
  39.149 -    /// \brief Gives back the number of the columns.
  39.150 +    /// \brief The number of the columns.
  39.151      ///
  39.152      /// Gives back the number of the columns.
  39.153      int width() const {
  39.154        return Parent::width();
  39.155      }
  39.156  
  39.157 -    /// \brief Gives back the number of the rows.
  39.158 +    /// \brief The number of the rows.
  39.159      ///
  39.160      /// Gives back the number of the rows.
  39.161      int height() const {
  39.162        return Parent::height();
  39.163      }
  39.164  
  39.165 -    /// \brief Gives back the arc goes right from the node.
  39.166 +    /// \brief The arc goes right from the node.
  39.167      ///
  39.168      /// Gives back the arc goes right from the node. If there is not
  39.169      /// outgoing arc then it gives back INVALID.
  39.170 @@ -652,7 +646,7 @@
  39.171        return Parent::right(n);
  39.172      }
  39.173  
  39.174 -    /// \brief Gives back the arc goes left from the node.
  39.175 +    /// \brief The arc goes left from the node.
  39.176      ///
  39.177      /// Gives back the arc goes left from the node. If there is not
  39.178      /// outgoing arc then it gives back INVALID.
  39.179 @@ -660,7 +654,7 @@
  39.180        return Parent::left(n);
  39.181      }
  39.182  
  39.183 -    /// \brief Gives back the arc goes up from the node.
  39.184 +    /// \brief The arc goes up from the node.
  39.185      ///
  39.186      /// Gives back the arc goes up from the node. If there is not
  39.187      /// outgoing arc then it gives back INVALID.
  39.188 @@ -668,7 +662,7 @@
  39.189        return Parent::up(n);
  39.190      }
  39.191  
  39.192 -    /// \brief Gives back the arc goes down from the node.
  39.193 +    /// \brief The arc goes down from the node.
  39.194      ///
  39.195      /// Gives back the arc goes down from the node. If there is not
  39.196      /// 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	Thu Nov 05 10:23:16 2009 +0100
    40.3 @@ -0,0 +1,640 @@
    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 +          u = _gr.source(_data[u][j].pred);
  40.605 +        }
  40.606 +      }
  40.607 +
  40.608 +      // If at least one cycle is found, check the optimality condition
  40.609 +      LargeValue d;
  40.610 +      if (_curr_found && k < n) {
  40.611 +        // Find node potentials
  40.612 +        for (int i = 0; i < n; ++i) {
  40.613 +          u = (*_nodes)[i];
  40.614 +          pi[u] = INF;
  40.615 +          for (int j = 0; j <= k; ++j) {
  40.616 +            if (_data[u][j].dist < INF) {
  40.617 +              d = _data[u][j].dist * _curr_size - j * _curr_length;
  40.618 +              if (_tolerance.less(d, pi[u])) pi[u] = d;
  40.619 +            }
  40.620 +          }
  40.621 +        }
  40.622 +
  40.623 +        // Check the optimality condition for all arcs
  40.624 +        bool done = true;
  40.625 +        for (ArcIt a(_gr); a != INVALID; ++a) {
  40.626 +          if (_tolerance.less(_length[a] * _curr_size - _curr_length,
  40.627 +                              pi[_gr.target(a)] - pi[_gr.source(a)]) ) {
  40.628 +            done = false;
  40.629 +            break;
  40.630 +          }
  40.631 +        }
  40.632 +        return done;
  40.633 +      }
  40.634 +      return (k == n);
  40.635 +    }
  40.636 +
  40.637 +  }; //class HartmannOrlin
  40.638 +
  40.639 +  ///@}
  40.640 +
  40.641 +} //namespace lemon
  40.642 +
  40.643 +#endif //LEMON_HARTMANN_ORLIN_H
    41.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.2 +++ b/lemon/howard.h	Thu Nov 05 10:23:16 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	Thu Nov 05 10:01:02 2009 +0100
    42.2 +++ b/lemon/hypercube_graph.h	Thu Nov 05 10:23:16 2009 +0100
    42.3 @@ -282,17 +282,21 @@
    42.4    ///
    42.5    /// \brief Hypercube graph class
    42.6    ///
    42.7 -  /// This class implements a special graph type. The nodes of the graph
    42.8 -  /// are indiced with integers with at most \c dim binary digits.
    42.9 +  /// HypercubeGraph implements a special graph type. The nodes of the
   42.10 +  /// graph are indexed with integers having at most \c dim binary digits.
   42.11    /// Two nodes are connected in the graph if and only if their indices
   42.12    /// differ only on one position in the binary form.
   42.13 +  /// This class is completely static and it needs constant memory space.
   42.14 +  /// Thus you can neither add nor delete nodes or edges, however 
   42.15 +  /// the structure can be resized using resize().
   42.16 +  ///
   42.17 +  /// This type fully conforms to the \ref concepts::Graph "Graph concept".
   42.18 +  /// Most of its member functions and nested classes are documented
   42.19 +  /// only in the concept class.
   42.20    ///
   42.21    /// \note The type of the indices is chosen to \c int for efficiency
   42.22    /// reasons. Thus the maximum dimension of this implementation is 26
   42.23    /// (assuming that the size of \c int is 32 bit).
   42.24 -  ///
   42.25 -  /// This graph type fully conforms to the \ref concepts::Graph
   42.26 -  /// "Graph concept".
   42.27    class HypercubeGraph : public ExtendedHypercubeGraphBase {
   42.28      typedef ExtendedHypercubeGraphBase Parent;
   42.29  
   42.30 @@ -303,6 +307,21 @@
   42.31      /// Constructs a hypercube graph with \c dim dimensions.
   42.32      HypercubeGraph(int dim) { construct(dim); }
   42.33  
   42.34 +    /// \brief Resizes the graph
   42.35 +    ///
   42.36 +    /// This function resizes the graph. It fully destroys and
   42.37 +    /// rebuilds the structure, therefore the maps of the graph will be
   42.38 +    /// reallocated automatically and the previous values will be lost.
   42.39 +    void resize(int dim) {
   42.40 +      Parent::notifier(Arc()).clear();
   42.41 +      Parent::notifier(Edge()).clear();
   42.42 +      Parent::notifier(Node()).clear();
   42.43 +      construct(dim);
   42.44 +      Parent::notifier(Node()).build();
   42.45 +      Parent::notifier(Edge()).build();
   42.46 +      Parent::notifier(Arc()).build();
   42.47 +    }
   42.48 +
   42.49      /// \brief The number of dimensions.
   42.50      ///
   42.51      /// Gives back the number of dimensions.
   42.52 @@ -320,7 +339,7 @@
   42.53      /// \brief The dimension id of an edge.
   42.54      ///
   42.55      /// Gives back the dimension id of the given edge.
   42.56 -    /// It is in the [0..dim-1] range.
   42.57 +    /// It is in the range <tt>[0..dim-1]</tt>.
   42.58      int dimension(Edge edge) const {
   42.59        return Parent::dimension(edge);
   42.60      }
   42.61 @@ -328,7 +347,7 @@
   42.62      /// \brief The dimension id of an arc.
   42.63      ///
   42.64      /// Gives back the dimension id of the given arc.
   42.65 -    /// It is in the [0..dim-1] range.
   42.66 +    /// It is in the range <tt>[0..dim-1]</tt>.
   42.67      int dimension(Arc arc) const {
   42.68        return Parent::dimension(arc);
   42.69      }
    43.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.2 +++ b/lemon/karp.h	Thu Nov 05 10:23:16 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 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.2 +++ b/lemon/kary_heap.h	Thu Nov 05 10:23:16 2009 +0100
    44.3 @@ -0,0 +1,352 @@
    44.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
    44.5 + *
    44.6 + * This file is a part of LEMON, a generic C++ optimization library.
    44.7 + *
    44.8 + * Copyright (C) 2003-2009
    44.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   44.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
   44.11 + *
   44.12 + * Permission to use, modify and distribute this software is granted
   44.13 + * provided that this copyright notice appears in all copies. For
   44.14 + * precise terms see the accompanying LICENSE file.
   44.15 + *
   44.16 + * This software is provided "AS IS" with no warranty of any kind,
   44.17 + * express or implied, and with no claim as to its suitability for any
   44.18 + * purpose.
   44.19 + *
   44.20 + */
   44.21 +
   44.22 +#ifndef LEMON_KARY_HEAP_H
   44.23 +#define LEMON_KARY_HEAP_H
   44.24 +
   44.25 +///\ingroup heaps
   44.26 +///\file
   44.27 +///\brief Fourary heap implementation.
   44.28 +
   44.29 +#include <vector>
   44.30 +#include <utility>
   44.31 +#include <functional>
   44.32 +
   44.33 +namespace lemon {
   44.34 +
   44.35 +  /// \ingroup heaps
   44.36 +  ///
   44.37 +  ///\brief K-ary heap data structure.
   44.38 +  ///
   44.39 +  /// This class implements the \e K-ary \e heap data structure.
   44.40 +  /// It fully conforms to the \ref concepts::Heap "heap concept".
   44.41 +  ///
   44.42 +  /// The \ref KaryHeap "K-ary heap" is a generalization of the
   44.43 +  /// \ref BinHeap "binary heap" structure, its nodes have at most
   44.44 +  /// \c K children, instead of two.
   44.45 +  /// \ref BinHeap and \ref FouraryHeap are specialized implementations
   44.46 +  /// of this structure for <tt>K=2</tt> and <tt>K=4</tt>, respectively.
   44.47 +  ///
   44.48 +  /// \tparam PR Type of the priorities of the items.
   44.49 +  /// \tparam IM A read-writable item map with \c int values, used
   44.50 +  /// internally to handle the cross references.
   44.51 +  /// \tparam K The degree of the heap, each node have at most \e K
   44.52 +  /// children. The default is 16. Powers of two are suggested to use
   44.53 +  /// so that the multiplications and divisions needed to traverse the
   44.54 +  /// nodes of the heap could be performed faster.
   44.55 +  /// \tparam CMP A functor class for comparing the priorities.
   44.56 +  /// The default is \c std::less<PR>.
   44.57 +  ///
   44.58 +  ///\sa BinHeap
   44.59 +  ///\sa FouraryHeap
   44.60 +#ifdef DOXYGEN
   44.61 +  template <typename PR, typename IM, int K, typename CMP>
   44.62 +#else
   44.63 +  template <typename PR, typename IM, int K = 16,
   44.64 +            typename CMP = std::less<PR> >
   44.65 +#endif
   44.66 +  class KaryHeap {
   44.67 +  public:
   44.68 +    /// Type of the item-int map.
   44.69 +    typedef IM ItemIntMap;
   44.70 +    /// Type of the priorities.
   44.71 +    typedef PR Prio;
   44.72 +    /// Type of the items stored in the heap.
   44.73 +    typedef typename ItemIntMap::Key Item;
   44.74 +    /// Type of the item-priority pairs.
   44.75 +    typedef std::pair<Item,Prio> Pair;
   44.76 +    /// Functor type for comparing the priorities.
   44.77 +    typedef CMP Compare;
   44.78 +
   44.79 +    /// \brief Type to represent the states of the items.
   44.80 +    ///
   44.81 +    /// Each item has a state associated to it. It can be "in heap",
   44.82 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
   44.83 +    /// heap's point of view, but may be useful to the user.
   44.84 +    ///
   44.85 +    /// The item-int map must be initialized in such way that it assigns
   44.86 +    /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
   44.87 +    enum State {
   44.88 +      IN_HEAP = 0,    ///< = 0.
   44.89 +      PRE_HEAP = -1,  ///< = -1.
   44.90 +      POST_HEAP = -2  ///< = -2.
   44.91 +    };
   44.92 +
   44.93 +  private:
   44.94 +    std::vector<Pair> _data;
   44.95 +    Compare _comp;
   44.96 +    ItemIntMap &_iim;
   44.97 +
   44.98 +  public:
   44.99 +    /// \brief Constructor.
  44.100 +    ///
  44.101 +    /// Constructor.
  44.102 +    /// \param map A map that assigns \c int values to the items.
  44.103 +    /// It is used internally to handle the cross references.
  44.104 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  44.105 +    explicit KaryHeap(ItemIntMap &map) : _iim(map) {}
  44.106 +
  44.107 +    /// \brief Constructor.
  44.108 +    ///
  44.109 +    /// Constructor.
  44.110 +    /// \param map A map that assigns \c int values to the items.
  44.111 +    /// It is used internally to handle the cross references.
  44.112 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  44.113 +    /// \param comp The function object used for comparing the priorities.
  44.114 +    KaryHeap(ItemIntMap &map, const Compare &comp)
  44.115 +      : _iim(map), _comp(comp) {}
  44.116 +
  44.117 +    /// \brief The number of items stored in the heap.
  44.118 +    ///
  44.119 +    /// This function returns the number of items stored in the heap.
  44.120 +    int size() const { return _data.size(); }
  44.121 +
  44.122 +    /// \brief Check if the heap is empty.
  44.123 +    ///
  44.124 +    /// This function returns \c true if the heap is empty.
  44.125 +    bool empty() const { return _data.empty(); }
  44.126 +
  44.127 +    /// \brief Make the heap empty.
  44.128 +    ///
  44.129 +    /// This functon makes the heap empty.
  44.130 +    /// It does not change the cross reference map. If you want to reuse
  44.131 +    /// a heap that is not surely empty, you should first clear it and
  44.132 +    /// then you should set the cross reference map to \c PRE_HEAP
  44.133 +    /// for each item.
  44.134 +    void clear() { _data.clear(); }
  44.135 +
  44.136 +  private:
  44.137 +    int parent(int i) { return (i-1)/K; }
  44.138 +    int firstChild(int i) { return K*i+1; }
  44.139 +
  44.140 +    bool less(const Pair &p1, const Pair &p2) const {
  44.141 +      return _comp(p1.second, p2.second);
  44.142 +    }
  44.143 +
  44.144 +    void bubbleUp(int hole, Pair p) {
  44.145 +      int par = parent(hole);
  44.146 +      while( hole>0 && less(p,_data[par]) ) {
  44.147 +        move(_data[par],hole);
  44.148 +        hole = par;
  44.149 +        par = parent(hole);
  44.150 +      }
  44.151 +      move(p, hole);
  44.152 +    }
  44.153 +
  44.154 +    void bubbleDown(int hole, Pair p, int length) {
  44.155 +      if( length>1 ) {
  44.156 +        int child = firstChild(hole);
  44.157 +        while( child+K<=length ) {
  44.158 +          int min=child;
  44.159 +          for (int i=1; i<K; ++i) {
  44.160 +            if( less(_data[child+i], _data[min]) )
  44.161 +              min=child+i;
  44.162 +          }
  44.163 +          if( !less(_data[min], p) )
  44.164 +            goto ok;
  44.165 +          move(_data[min], hole);
  44.166 +          hole = min;
  44.167 +          child = firstChild(hole);
  44.168 +        }
  44.169 +        if ( child<length ) {
  44.170 +          int min = child;
  44.171 +          while (++child < length) {
  44.172 +            if( less(_data[child], _data[min]) )
  44.173 +              min=child;
  44.174 +          }
  44.175 +          if( less(_data[min], p) ) {
  44.176 +            move(_data[min], hole);
  44.177 +            hole = min;
  44.178 +          }
  44.179 +        }
  44.180 +      }
  44.181 +    ok:
  44.182 +      move(p, hole);
  44.183 +    }
  44.184 +
  44.185 +    void move(const Pair &p, int i) {
  44.186 +      _data[i] = p;
  44.187 +      _iim.set(p.first, i);
  44.188 +    }
  44.189 +
  44.190 +  public:
  44.191 +    /// \brief Insert a pair of item and priority into the heap.
  44.192 +    ///
  44.193 +    /// This function inserts \c p.first to the heap with priority
  44.194 +    /// \c p.second.
  44.195 +    /// \param p The pair to insert.
  44.196 +    /// \pre \c p.first must not be stored in the heap.
  44.197 +    void push(const Pair &p) {
  44.198 +      int n = _data.size();
  44.199 +      _data.resize(n+1);
  44.200 +      bubbleUp(n, p);
  44.201 +    }
  44.202 +
  44.203 +    /// \brief Insert an item into the heap with the given priority.
  44.204 +    ///
  44.205 +    /// This function inserts the given item into the heap with the
  44.206 +    /// given priority.
  44.207 +    /// \param i The item to insert.
  44.208 +    /// \param p The priority of the item.
  44.209 +    /// \pre \e i must not be stored in the heap.
  44.210 +    void push(const Item &i, const Prio &p) { push(Pair(i,p)); }
  44.211 +
  44.212 +    /// \brief Return the item having minimum priority.
  44.213 +    ///
  44.214 +    /// This function returns the item having minimum priority.
  44.215 +    /// \pre The heap must be non-empty.
  44.216 +    Item top() const { return _data[0].first; }
  44.217 +
  44.218 +    /// \brief The minimum priority.
  44.219 +    ///
  44.220 +    /// This function returns the minimum priority.
  44.221 +    /// \pre The heap must be non-empty.
  44.222 +    Prio prio() const { return _data[0].second; }
  44.223 +
  44.224 +    /// \brief Remove the item having minimum priority.
  44.225 +    ///
  44.226 +    /// This function removes the item having minimum priority.
  44.227 +    /// \pre The heap must be non-empty.
  44.228 +    void pop() {
  44.229 +      int n = _data.size()-1;
  44.230 +      _iim.set(_data[0].first, POST_HEAP);
  44.231 +      if (n>0) bubbleDown(0, _data[n], n);
  44.232 +      _data.pop_back();
  44.233 +    }
  44.234 +
  44.235 +    /// \brief Remove the given item from the heap.
  44.236 +    ///
  44.237 +    /// This function removes the given item from the heap if it is
  44.238 +    /// already stored.
  44.239 +    /// \param i The item to delete.
  44.240 +    /// \pre \e i must be in the heap.
  44.241 +    void erase(const Item &i) {
  44.242 +      int h = _iim[i];
  44.243 +      int n = _data.size()-1;
  44.244 +      _iim.set(_data[h].first, POST_HEAP);
  44.245 +      if( h<n ) {
  44.246 +        if( less(_data[parent(h)], _data[n]) )
  44.247 +          bubbleDown(h, _data[n], n);
  44.248 +        else
  44.249 +          bubbleUp(h, _data[n]);
  44.250 +      }
  44.251 +      _data.pop_back();
  44.252 +    }
  44.253 +
  44.254 +    /// \brief The priority of the given item.
  44.255 +    ///
  44.256 +    /// This function returns the priority of the given item.
  44.257 +    /// \param i The item.
  44.258 +    /// \pre \e i must be in the heap.
  44.259 +    Prio operator[](const Item &i) const {
  44.260 +      int idx = _iim[i];
  44.261 +      return _data[idx].second;
  44.262 +    }
  44.263 +
  44.264 +    /// \brief Set the priority of an item or insert it, if it is
  44.265 +    /// not stored in the heap.
  44.266 +    ///
  44.267 +    /// This method sets the priority of the given item if it is
  44.268 +    /// already stored in the heap. Otherwise it inserts the given
  44.269 +    /// item into the heap with the given priority.
  44.270 +    /// \param i The item.
  44.271 +    /// \param p The priority.
  44.272 +    void set(const Item &i, const Prio &p) {
  44.273 +      int idx = _iim[i];
  44.274 +      if( idx<0 )
  44.275 +        push(i,p);
  44.276 +      else if( _comp(p, _data[idx].second) )
  44.277 +        bubbleUp(idx, Pair(i,p));
  44.278 +      else
  44.279 +        bubbleDown(idx, Pair(i,p), _data.size());
  44.280 +    }
  44.281 +
  44.282 +    /// \brief Decrease the priority of an item to the given value.
  44.283 +    ///
  44.284 +    /// This function decreases the priority of an item to the given value.
  44.285 +    /// \param i The item.
  44.286 +    /// \param p The priority.
  44.287 +    /// \pre \e i must be stored in the heap with priority at least \e p.
  44.288 +    void decrease(const Item &i, const Prio &p) {
  44.289 +      int idx = _iim[i];
  44.290 +      bubbleUp(idx, Pair(i,p));
  44.291 +    }
  44.292 +
  44.293 +    /// \brief Increase the priority of an item to the given value.
  44.294 +    ///
  44.295 +    /// This function increases the priority of an item to the given value.
  44.296 +    /// \param i The item.
  44.297 +    /// \param p The priority.
  44.298 +    /// \pre \e i must be stored in the heap with priority at most \e p.
  44.299 +    void increase(const Item &i, const Prio &p) {
  44.300 +      int idx = _iim[i];
  44.301 +      bubbleDown(idx, Pair(i,p), _data.size());
  44.302 +    }
  44.303 +
  44.304 +    /// \brief Return the state of an item.
  44.305 +    ///
  44.306 +    /// This method returns \c PRE_HEAP if the given item has never
  44.307 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  44.308 +    /// and \c POST_HEAP otherwise.
  44.309 +    /// In the latter case it is possible that the item will get back
  44.310 +    /// to the heap again.
  44.311 +    /// \param i The item.
  44.312 +    State state(const Item &i) const {
  44.313 +      int s = _iim[i];
  44.314 +      if (s>=0) s=0;
  44.315 +      return State(s);
  44.316 +    }
  44.317 +
  44.318 +    /// \brief Set the state of an item in the heap.
  44.319 +    ///
  44.320 +    /// This function sets the state of the given item in the heap.
  44.321 +    /// It can be used to manually clear the heap when it is important
  44.322 +    /// to achive better time complexity.
  44.323 +    /// \param i The item.
  44.324 +    /// \param st The state. It should not be \c IN_HEAP.
  44.325 +    void state(const Item& i, State st) {
  44.326 +      switch (st) {
  44.327 +        case POST_HEAP:
  44.328 +        case PRE_HEAP:
  44.329 +          if (state(i) == IN_HEAP) erase(i);
  44.330 +          _iim[i] = st;
  44.331 +          break;
  44.332 +        case IN_HEAP:
  44.333 +          break;
  44.334 +      }
  44.335 +    }
  44.336 +
  44.337 +    /// \brief Replace an item in the heap.
  44.338 +    ///
  44.339 +    /// This function replaces item \c i with item \c j.
  44.340 +    /// Item \c i must be in the heap, while \c j must be out of the heap.
  44.341 +    /// After calling this method, item \c i will be out of the
  44.342 +    /// heap and \c j will be in the heap with the same prioriority
  44.343 +    /// as item \c i had before.
  44.344 +    void replace(const Item& i, const Item& j) {
  44.345 +      int idx=_iim[i];
  44.346 +      _iim.set(i, _iim[j]);
  44.347 +      _iim.set(j, idx);
  44.348 +      _data[idx].first=j;
  44.349 +    }
  44.350 +
  44.351 +  }; // class KaryHeap
  44.352 +
  44.353 +} // namespace lemon
  44.354 +
  44.355 +#endif // LEMON_KARY_HEAP_H
    45.1 --- a/lemon/list_graph.h	Thu Nov 05 10:01:02 2009 +0100
    45.2 +++ b/lemon/list_graph.h	Thu Nov 05 10:23:16 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,25 @@
   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    ///\sa concepts::Digraph
   45.84 -
   45.85 +  ///\sa ListGraph
   45.86    class ListDigraph : public ExtendedListDigraphBase {
   45.87      typedef ExtendedListDigraphBase Parent;
   45.88  
   45.89    private:
   45.90 -    ///ListDigraph is \e not copy constructible. Use copyDigraph() instead.
   45.91 -
   45.92 -    ///ListDigraph is \e not copy constructible. Use copyDigraph() instead.
   45.93 -    ///
   45.94 +    /// Digraphs are \e not copy constructible. Use DigraphCopy instead.
   45.95      ListDigraph(const ListDigraph &) :ExtendedListDigraphBase() {};
   45.96 -    ///\brief Assignment of ListDigraph to another one is \e not allowed.
   45.97 -    ///Use copyDigraph() instead.
   45.98 -
   45.99 -    ///Assignment of ListDigraph to another one is \e not allowed.
  45.100 -    ///Use copyDigraph() instead.
  45.101 +    /// \brief Assignment of a digraph to another one is \e not allowed.
  45.102 +    /// Use DigraphCopy instead.
  45.103      void operator=(const ListDigraph &) {}
  45.104    public:
  45.105  
  45.106 @@ -347,71 +345,65 @@
  45.107  
  45.108      ///Add a new node to the digraph.
  45.109  
  45.110 -    ///Add a new node to the digraph.
  45.111 +    ///This function adds a new node to the digraph.
  45.112      ///\return The new node.
  45.113      Node addNode() { return Parent::addNode(); }
  45.114  
  45.115      ///Add a new arc to the digraph.
  45.116  
  45.117 -    ///Add a new arc to the digraph with source node \c s
  45.118 +    ///This function adds a new arc to the digraph with source node \c s
  45.119      ///and target node \c t.
  45.120      ///\return The new arc.
  45.121 -    Arc addArc(const Node& s, const Node& t) {
  45.122 +    Arc addArc(Node s, Node t) {
  45.123        return Parent::addArc(s, t);
  45.124      }
  45.125  
  45.126      ///\brief Erase a node from the digraph.
  45.127      ///
  45.128 -    ///Erase a node from the digraph.
  45.129 -    ///
  45.130 -    void erase(const Node& n) { Parent::erase(n); }
  45.131 +    ///This function erases the given node from the digraph.
  45.132 +    void erase(Node n) { Parent::erase(n); }
  45.133  
  45.134      ///\brief Erase an arc from the digraph.
  45.135      ///
  45.136 -    ///Erase an arc from the digraph.
  45.137 -    ///
  45.138 -    void erase(const Arc& a) { Parent::erase(a); }
  45.139 +    ///This function erases the given arc from the digraph.
  45.140 +    void erase(Arc a) { Parent::erase(a); }
  45.141  
  45.142      /// Node validity check
  45.143  
  45.144 -    /// This function gives back true if the given node is valid,
  45.145 -    /// ie. it is a real node of the graph.
  45.146 +    /// This function gives back \c true if the given node is valid,
  45.147 +    /// i.e. it is a real node of the digraph.
  45.148      ///
  45.149 -    /// \warning A Node pointing to a removed item
  45.150 -    /// could become valid again later if new nodes are
  45.151 -    /// added to the graph.
  45.152 +    /// \warning A removed node could become valid again if new nodes are
  45.153 +    /// added to the digraph.
  45.154      bool valid(Node n) const { return Parent::valid(n); }
  45.155  
  45.156      /// Arc validity check
  45.157  
  45.158 -    /// This function gives back true if the given arc is valid,
  45.159 -    /// ie. it is a real arc of the graph.
  45.160 +    /// This function gives back \c true if the given arc is valid,
  45.161 +    /// i.e. it is a real arc of the digraph.
  45.162      ///
  45.163 -    /// \warning An Arc pointing to a removed item
  45.164 -    /// could become valid again later if new nodes are
  45.165 -    /// added to the graph.
  45.166 +    /// \warning A removed arc could become valid again if new arcs are
  45.167 +    /// added to the digraph.
  45.168      bool valid(Arc a) const { return Parent::valid(a); }
  45.169  
  45.170 -    /// Change the target of \c a to \c n
  45.171 +    /// Change the target node of an arc
  45.172  
  45.173 -    /// Change the target of \c a to \c n
  45.174 +    /// This function changes the target node of the given arc \c a to \c n.
  45.175      ///
  45.176 -    ///\note The <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s referencing
  45.177 -    ///the changed arc remain valid. However <tt>InArcIt</tt>s are
  45.178 -    ///invalidated.
  45.179 +    ///\note \c ArcIt and \c OutArcIt iterators referencing the changed
  45.180 +    ///arc remain valid, however \c InArcIt iterators are invalidated.
  45.181      ///
  45.182      ///\warning This functionality cannot be used together with the Snapshot
  45.183      ///feature.
  45.184      void changeTarget(Arc a, Node n) {
  45.185        Parent::changeTarget(a,n);
  45.186      }
  45.187 -    /// Change the source of \c a to \c n
  45.188 +    /// Change the source node of an arc
  45.189  
  45.190 -    /// Change the source of \c a to \c n
  45.191 +    /// This function changes the source node of the given arc \c a to \c n.
  45.192      ///
  45.193 -    ///\note The <tt>InArcIt</tt>s referencing the changed arc remain
  45.194 -    ///valid. However the <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s are
  45.195 -    ///invalidated.
  45.196 +    ///\note \c InArcIt iterators referencing the changed arc remain
  45.197 +    ///valid, however \c ArcIt and \c OutArcIt iterators are invalidated.
  45.198      ///
  45.199      ///\warning This functionality cannot be used together with the Snapshot
  45.200      ///feature.
  45.201 @@ -419,94 +411,76 @@
  45.202        Parent::changeSource(a,n);
  45.203      }
  45.204  
  45.205 -    /// Invert the direction of an arc.
  45.206 +    /// Reverse the direction of an arc.
  45.207  
  45.208 -    ///\note The <tt>ArcIt</tt>s referencing the changed arc remain
  45.209 -    ///valid. However <tt>OutArcIt</tt>s and <tt>InArcIt</tt>s are
  45.210 -    ///invalidated.
  45.211 +    /// This function reverses the direction of the given arc.
  45.212 +    ///\note \c ArcIt, \c OutArcIt and \c InArcIt iterators referencing
  45.213 +    ///the changed arc are invalidated.
  45.214      ///
  45.215      ///\warning This functionality cannot be used together with the Snapshot
  45.216      ///feature.
  45.217 -    void reverseArc(Arc e) {
  45.218 -      Node t=target(e);
  45.219 -      changeTarget(e,source(e));
  45.220 -      changeSource(e,t);
  45.221 +    void reverseArc(Arc a) {
  45.222 +      Node t=target(a);
  45.223 +      changeTarget(a,source(a));
  45.224 +      changeSource(a,t);
  45.225      }
  45.226  
  45.227 -    /// Reserve memory for nodes.
  45.228 -
  45.229 -    /// Using this function it is possible to avoid the superfluous memory
  45.230 -    /// allocation: if you know that the digraph you want to build will
  45.231 -    /// be very large (e.g. it will contain millions of nodes and/or arcs)
  45.232 -    /// then it is worth reserving space for this amount before starting
  45.233 -    /// to build the digraph.
  45.234 -    /// \sa reserveArc
  45.235 -    void reserveNode(int n) { nodes.reserve(n); };
  45.236 -
  45.237 -    /// Reserve memory for arcs.
  45.238 -
  45.239 -    /// Using this function it is possible to avoid the superfluous memory
  45.240 -    /// allocation: if you know that the digraph you want to build will
  45.241 -    /// be very large (e.g. it will contain millions of nodes and/or arcs)
  45.242 -    /// then it is worth reserving space for this amount before starting
  45.243 -    /// to build the digraph.
  45.244 -    /// \sa reserveNode
  45.245 -    void reserveArc(int m) { arcs.reserve(m); };
  45.246 -
  45.247      ///Contract two nodes.
  45.248  
  45.249 -    ///This function contracts two nodes.
  45.250 -    ///Node \p b will be removed but instead of deleting
  45.251 -    ///incident arcs, they will be joined to \p a.
  45.252 -    ///The last parameter \p r controls whether to remove loops. \c true
  45.253 -    ///means that loops will be removed.
  45.254 +    ///This function contracts the given two nodes.
  45.255 +    ///Node \c v is removed, but instead of deleting its
  45.256 +    ///incident arcs, they are joined to node \c u.
  45.257 +    ///If the last parameter \c r is \c true (this is the default value),
  45.258 +    ///then the newly created loops are removed.
  45.259      ///
  45.260 -    ///\note The <tt>ArcIt</tt>s referencing a moved arc remain
  45.261 -    ///valid. However <tt>InArcIt</tt>s and <tt>OutArcIt</tt>s
  45.262 -    ///may be invalidated.
  45.263 +    ///\note The moved arcs are joined to node \c u using changeSource()
  45.264 +    ///or changeTarget(), thus \c ArcIt and \c OutArcIt iterators are
  45.265 +    ///invalidated for the outgoing arcs of node \c v and \c InArcIt
  45.266 +    ///iterators are invalidated for the incomming arcs of \c v.
  45.267 +    ///Moreover all iterators referencing node \c v or the removed 
  45.268 +    ///loops are also invalidated. Other iterators remain valid.
  45.269      ///
  45.270      ///\warning This functionality cannot be used together with the Snapshot
  45.271      ///feature.
  45.272 -    void contract(Node a, Node b, bool r = true)
  45.273 +    void contract(Node u, Node v, bool r = true)
  45.274      {
  45.275 -      for(OutArcIt e(*this,b);e!=INVALID;) {
  45.276 +      for(OutArcIt e(*this,v);e!=INVALID;) {
  45.277          OutArcIt f=e;
  45.278          ++f;
  45.279 -        if(r && target(e)==a) erase(e);
  45.280 -        else changeSource(e,a);
  45.281 +        if(r && target(e)==u) erase(e);
  45.282 +        else changeSource(e,u);
  45.283          e=f;
  45.284        }
  45.285 -      for(InArcIt e(*this,b);e!=INVALID;) {
  45.286 +      for(InArcIt e(*this,v);e!=INVALID;) {
  45.287          InArcIt f=e;
  45.288          ++f;
  45.289 -        if(r && source(e)==a) erase(e);
  45.290 -        else changeTarget(e,a);
  45.291 +        if(r && source(e)==u) erase(e);
  45.292 +        else changeTarget(e,u);
  45.293          e=f;
  45.294        }
  45.295 -      erase(b);
  45.296 +      erase(v);
  45.297      }
  45.298  
  45.299      ///Split a node.
  45.300  
  45.301 -    ///This function splits a node. First a new node is added to the digraph,
  45.302 -    ///then the source of each outgoing arc of \c n is moved to this new node.
  45.303 -    ///If \c connect is \c true (this is the default value), then a new arc
  45.304 -    ///from \c n to the newly created node is also added.
  45.305 +    ///This function splits the given node. First, a new node is added
  45.306 +    ///to the digraph, then the source of each outgoing arc of node \c n
  45.307 +    ///is moved to this new node.
  45.308 +    ///If the second parameter \c connect is \c true (this is the default
  45.309 +    ///value), then a new arc from node \c n to the newly created node
  45.310 +    ///is also added.
  45.311      ///\return The newly created node.
  45.312      ///
  45.313 -    ///\note The <tt>ArcIt</tt>s referencing a moved arc remain
  45.314 -    ///valid. However <tt>InArcIt</tt>s and <tt>OutArcIt</tt>s may
  45.315 -    ///be invalidated.
  45.316 +    ///\note All iterators remain valid.
  45.317      ///
  45.318 -    ///\warning This functionality cannot be used in conjunction with the
  45.319 +    ///\warning This functionality cannot be used together with the
  45.320      ///Snapshot feature.
  45.321      Node split(Node n, bool connect = true) {
  45.322        Node b = addNode();
  45.323 -      for(OutArcIt e(*this,n);e!=INVALID;) {
  45.324 -        OutArcIt f=e;
  45.325 -        ++f;
  45.326 -        changeSource(e,b);
  45.327 -        e=f;
  45.328 +      nodes[b.id].first_out=nodes[n.id].first_out;
  45.329 +      nodes[n.id].first_out=-1;
  45.330 +      for(int i=nodes[b.id].first_out; i!=-1; i=arcs[i].next_out) {
  45.331 +        arcs[i].source=b.id;
  45.332        }
  45.333        if (connect) addArc(n,b);
  45.334        return b;
  45.335 @@ -514,21 +488,52 @@
  45.336  
  45.337      ///Split an arc.
  45.338  
  45.339 -    ///This function splits an arc. First a new node \c b is added to
  45.340 -    ///the digraph, then the original arc is re-targeted to \c
  45.341 -    ///b. Finally an arc from \c b to the original target is added.
  45.342 +    ///This function splits the given arc. First, a new node \c v is
  45.343 +    ///added to the digraph, then the target node of the original arc
  45.344 +    ///is set to \c v. Finally, an arc from \c v to the original target
  45.345 +    ///is added.
  45.346 +    ///\return The newly created node.
  45.347      ///
  45.348 -    ///\return The newly created node.
  45.349 +    ///\note \c InArcIt iterators referencing the original arc are
  45.350 +    ///invalidated. Other iterators remain valid.
  45.351      ///
  45.352      ///\warning This functionality cannot be used together with the
  45.353      ///Snapshot feature.
  45.354 -    Node split(Arc e) {
  45.355 -      Node b = addNode();
  45.356 -      addArc(b,target(e));
  45.357 -      changeTarget(e,b);
  45.358 -      return b;
  45.359 +    Node split(Arc a) {
  45.360 +      Node v = addNode();
  45.361 +      addArc(v,target(a));
  45.362 +      changeTarget(a,v);
  45.363 +      return v;
  45.364      }
  45.365  
  45.366 +    ///Clear the digraph.
  45.367 +
  45.368 +    ///This function erases all nodes and arcs from the digraph.
  45.369 +    ///
  45.370 +    void clear() {
  45.371 +      Parent::clear();
  45.372 +    }
  45.373 +
  45.374 +    /// Reserve memory for nodes.
  45.375 +
  45.376 +    /// Using this function, it is possible to avoid superfluous memory
  45.377 +    /// allocation: if you know that the digraph you want to build will
  45.378 +    /// be large (e.g. it will contain millions of nodes and/or arcs),
  45.379 +    /// then it is worth reserving space for this amount before starting
  45.380 +    /// to build the digraph.
  45.381 +    /// \sa reserveArc()
  45.382 +    void reserveNode(int n) { nodes.reserve(n); };
  45.383 +
  45.384 +    /// Reserve memory for arcs.
  45.385 +
  45.386 +    /// Using this function, it is possible to avoid superfluous memory
  45.387 +    /// allocation: if you know that the digraph you want to build will
  45.388 +    /// be large (e.g. it will contain millions of nodes and/or arcs),
  45.389 +    /// then it is worth reserving space for this amount before starting
  45.390 +    /// to build the digraph.
  45.391 +    /// \sa reserveNode()
  45.392 +    void reserveArc(int m) { arcs.reserve(m); };
  45.393 +
  45.394      /// \brief Class to make a snapshot of the digraph and restore
  45.395      /// it later.
  45.396      ///
  45.397 @@ -537,9 +542,15 @@
  45.398      /// The newly added nodes and arcs can be removed using the
  45.399      /// restore() function.
  45.400      ///
  45.401 -    /// \warning Arc and node deletions and other modifications (e.g.
  45.402 -    /// contracting, splitting, reversing arcs or nodes) cannot be
  45.403 +    /// \note After a state is restored, you cannot restore a later state, 
  45.404 +    /// i.e. you cannot add the removed nodes and arcs again using
  45.405 +    /// another Snapshot instance.
  45.406 +    ///
  45.407 +    /// \warning Node and arc deletions and other modifications (e.g.
  45.408 +    /// reversing, contracting, splitting arcs or nodes) cannot be
  45.409      /// restored. These events invalidate the snapshot.
  45.410 +    /// However the arcs and nodes that were added to the digraph after
  45.411 +    /// making the current snapshot can be removed without invalidating it.
  45.412      class Snapshot {
  45.413      protected:
  45.414  
  45.415 @@ -709,39 +720,40 @@
  45.416        /// \brief Default constructor.
  45.417        ///
  45.418        /// Default constructor.
  45.419 -      /// To actually make a snapshot you must call save().
  45.420 +      /// You have to call save() to actually make a snapshot.
  45.421        Snapshot()
  45.422          : digraph(0), node_observer_proxy(*this),
  45.423            arc_observer_proxy(*this) {}
  45.424  
  45.425        /// \brief Constructor that immediately makes a snapshot.
  45.426        ///
  45.427 -      /// This constructor immediately makes a snapshot of the digraph.
  45.428 -      /// \param _digraph The digraph we make a snapshot of.
  45.429 -      Snapshot(ListDigraph &_digraph)
  45.430 +      /// This constructor immediately makes a snapshot of the given digraph.
  45.431 +      Snapshot(ListDigraph &gr)
  45.432          : node_observer_proxy(*this),
  45.433            arc_observer_proxy(*this) {
  45.434 -        attach(_digraph);
  45.435 +        attach(gr);
  45.436        }
  45.437  
  45.438        /// \brief Make a snapshot.
  45.439        ///
  45.440 -      /// Make a snapshot of the digraph.
  45.441 -      ///
  45.442 -      /// This function can be called more than once. In case of a repeated
  45.443 +      /// This function makes a snapshot of the given digraph.
  45.444 +      /// It can be called more than once. In case of a repeated
  45.445        /// call, the previous snapshot gets lost.
  45.446 -      /// \param _digraph The digraph we make the snapshot of.
  45.447 -      void save(ListDigraph &_digraph) {
  45.448 +      void save(ListDigraph &gr) {
  45.449          if (attached()) {
  45.450            detach();
  45.451            clear();
  45.452          }
  45.453 -        attach(_digraph);
  45.454 +        attach(gr);
  45.455        }
  45.456  
  45.457        /// \brief Undo the changes until the last snapshot.
  45.458 -      //
  45.459 -      /// Undo the changes until the last snapshot created by save().
  45.460 +      ///
  45.461 +      /// This function undos the changes until the last snapshot
  45.462 +      /// created by save() or Snapshot(ListDigraph&).
  45.463 +      ///
  45.464 +      /// \warning This method invalidates the snapshot, i.e. repeated
  45.465 +      /// restoring is not supported unless you call save() again.
  45.466        void restore() {
  45.467          detach();
  45.468          for(std::list<Arc>::iterator it = added_arcs.begin();
  45.469 @@ -755,9 +767,9 @@
  45.470          clear();
  45.471        }
  45.472  
  45.473 -      /// \brief Gives back true when the snapshot is valid.
  45.474 +      /// \brief Returns \c true if the snapshot is valid.
  45.475        ///
  45.476 -      /// Gives back true when the snapshot is valid.
  45.477 +      /// This function returns \c true if the snapshot is valid.
  45.478        bool valid() const {
  45.479          return attached();
  45.480        }
  45.481 @@ -795,10 +807,6 @@
  45.482  
  45.483      typedef ListGraphBase Graph;
  45.484  
  45.485 -    class Node;
  45.486 -    class Arc;
  45.487 -    class Edge;
  45.488 -
  45.489      class Node {
  45.490        friend class ListGraphBase;
  45.491      protected:
  45.492 @@ -848,8 +856,6 @@
  45.493        bool operator<(const Arc& arc) const {return id < arc.id;}
  45.494      };
  45.495  
  45.496 -
  45.497 -
  45.498      ListGraphBase()
  45.499        : nodes(), first_node(-1),
  45.500          first_free_node(-1), arcs(), first_free_arc(-1) {}
  45.501 @@ -1164,31 +1170,25 @@
  45.502  
  45.503    ///A general undirected graph structure.
  45.504  
  45.505 -  ///\ref ListGraph is a simple and fast <em>undirected graph</em>
  45.506 -  ///implementation based on static linked lists that are stored in
  45.507 +  ///\ref ListGraph is a versatile and fast undirected graph
  45.508 +  ///implementation based on linked lists that are stored in
  45.509    ///\c std::vector structures.
  45.510    ///
  45.511 -  ///It conforms to the \ref concepts::Graph "Graph concept" and it
  45.512 -  ///also provides several useful additional functionalities.
  45.513 -  ///Most of the member functions and nested classes are documented
  45.514 +  ///This type fully conforms to the \ref concepts::Graph "Graph concept"
  45.515 +  ///and it also provides several useful additional functionalities.
  45.516 +  ///Most of its member functions and nested classes are documented
  45.517    ///only in the concept class.
  45.518    ///
  45.519    ///\sa concepts::Graph
  45.520 -
  45.521 +  ///\sa ListDigraph
  45.522    class ListGraph : public ExtendedListGraphBase {
  45.523      typedef ExtendedListGraphBase Parent;
  45.524  
  45.525    private:
  45.526 -    ///ListGraph is \e not copy constructible. Use copyGraph() instead.
  45.527 -
  45.528 -    ///ListGraph is \e not copy constructible. Use copyGraph() instead.
  45.529 -    ///
  45.530 +    /// Graphs are \e not copy constructible. Use GraphCopy instead.
  45.531      ListGraph(const ListGraph &) :ExtendedListGraphBase()  {};
  45.532 -    ///\brief Assignment of ListGraph to another one is \e not allowed.
  45.533 -    ///Use copyGraph() instead.
  45.534 -
  45.535 -    ///Assignment of ListGraph to another one is \e not allowed.
  45.536 -    ///Use copyGraph() instead.
  45.537 +    /// \brief Assignment of a graph to another one is \e not allowed.
  45.538 +    /// Use GraphCopy instead.
  45.539      void operator=(const ListGraph &) {}
  45.540    public:
  45.541      /// Constructor
  45.542 @@ -1201,94 +1201,95 @@
  45.543  
  45.544      /// \brief Add a new node to the graph.
  45.545      ///
  45.546 -    /// Add a new node to the graph.
  45.547 +    /// This function adds a new node to the graph.
  45.548      /// \return The new node.
  45.549      Node addNode() { return Parent::addNode(); }
  45.550  
  45.551      /// \brief Add a new edge to the graph.
  45.552      ///
  45.553 -    /// Add a new edge to the graph with source node \c s
  45.554 -    /// and target node \c t.
  45.555 +    /// This function adds a new edge to the graph between nodes
  45.556 +    /// \c u and \c v with inherent orientation from node \c u to
  45.557 +    /// node \c v.
  45.558      /// \return The new edge.
  45.559 -    Edge addEdge(const Node& s, const Node& t) {
  45.560 -      return Parent::addEdge(s, t);
  45.561 +    Edge addEdge(Node u, Node v) {
  45.562 +      return Parent::addEdge(u, v);
  45.563      }
  45.564  
  45.565 -    /// \brief Erase a node from the graph.
  45.566 +    ///\brief Erase a node from the graph.
  45.567      ///
  45.568 -    /// Erase a node from the graph.
  45.569 +    /// This function erases the given node from the graph.
  45.570 +    void erase(Node n) { Parent::erase(n); }
  45.571 +
  45.572 +    ///\brief Erase an edge from the graph.
  45.573      ///
  45.574 -    void erase(const Node& n) { Parent::erase(n); }
  45.575 -
  45.576 -    /// \brief Erase an edge from the graph.
  45.577 -    ///
  45.578 -    /// Erase an edge from the graph.
  45.579 -    ///
  45.580 -    void erase(const Edge& e) { Parent::erase(e); }
  45.581 +    /// This function erases the given edge from the graph.
  45.582 +    void erase(Edge e) { Parent::erase(e); }
  45.583      /// Node validity check
  45.584  
  45.585 -    /// This function gives back true if the given node is valid,
  45.586 -    /// ie. it is a real node of the graph.
  45.587 +    /// This function gives back \c true if the given node is valid,
  45.588 +    /// i.e. it is a real node of the graph.
  45.589      ///
  45.590 -    /// \warning A Node pointing to a removed item
  45.591 -    /// could become valid again later if new nodes are
  45.592 +    /// \warning A removed node could become valid again if new nodes are
  45.593      /// added to the graph.
  45.594      bool valid(Node n) const { return Parent::valid(n); }
  45.595 +    /// Edge validity check
  45.596 +
  45.597 +    /// This function gives back \c true if the given edge is valid,
  45.598 +    /// i.e. it is a real edge of the graph.
  45.599 +    ///
  45.600 +    /// \warning A removed edge could become valid again if new edges are
  45.601 +    /// added to the graph.
  45.602 +    bool valid(Edge e) const { return Parent::valid(e); }
  45.603      /// Arc validity check
  45.604  
  45.605 -    /// This function gives back true if the given arc is valid,
  45.606 -    /// ie. it is a real arc of the graph.
  45.607 +    /// This function gives back \c true if the given arc is valid,
  45.608 +    /// i.e. it is a real arc of the graph.
  45.609      ///
  45.610 -    /// \warning An Arc pointing to a removed item
  45.611 -    /// could become valid again later if new edges are
  45.612 +    /// \warning A removed arc could become valid again if new edges are
  45.613      /// added to the graph.
  45.614      bool valid(Arc a) const { return Parent::valid(a); }
  45.615 -    /// Edge validity check
  45.616  
  45.617 -    /// This function gives back true if the given edge is valid,
  45.618 -    /// ie. it is a real arc of the graph.
  45.619 +    /// \brief Change the first node of an edge.
  45.620      ///
  45.621 -    /// \warning A Edge pointing to a removed item
  45.622 -    /// could become valid again later if new edges are
  45.623 -    /// added to the graph.
  45.624 -    bool valid(Edge e) const { return Parent::valid(e); }
  45.625 -    /// \brief Change the end \c u of \c e to \c n
  45.626 +    /// This function changes the first node of the given edge \c e to \c n.
  45.627      ///
  45.628 -    /// This function changes the end \c u of \c e to node \c n.
  45.629 -    ///
  45.630 -    ///\note The <tt>EdgeIt</tt>s and <tt>ArcIt</tt>s referencing the
  45.631 -    ///changed edge are invalidated and if the changed node is the
  45.632 -    ///base node of an iterator then this iterator is also
  45.633 -    ///invalidated.
  45.634 +    ///\note \c EdgeIt and \c ArcIt iterators referencing the
  45.635 +    ///changed edge are invalidated and all other iterators whose
  45.636 +    ///base node is the changed node are also invalidated.
  45.637      ///
  45.638      ///\warning This functionality cannot be used together with the
  45.639      ///Snapshot feature.
  45.640      void changeU(Edge e, Node n) {
  45.641        Parent::changeU(e,n);
  45.642      }
  45.643 -    /// \brief Change the end \c v of \c e to \c n
  45.644 +    /// \brief Change the second node of an edge.
  45.645      ///
  45.646 -    /// This function changes the end \c v of \c e to \c n.
  45.647 +    /// This function changes the second node of the given edge \c e to \c n.
  45.648      ///
  45.649 -    ///\note The <tt>EdgeIt</tt>s referencing the changed edge remain
  45.650 -    ///valid, however <tt>ArcIt</tt>s and if the changed node is the
  45.651 -    ///base node of an iterator then this iterator is invalidated.
  45.652 +    ///\note \c EdgeIt iterators referencing the changed edge remain
  45.653 +    ///valid, however \c ArcIt iterators referencing the changed edge and
  45.654 +    ///all other iterators whose base node is the changed node are also
  45.655 +    ///invalidated.
  45.656      ///
  45.657      ///\warning This functionality cannot be used together with the
  45.658      ///Snapshot feature.
  45.659      void changeV(Edge e, Node n) {
  45.660        Parent::changeV(e,n);
  45.661      }
  45.662 +
  45.663      /// \brief Contract two nodes.
  45.664      ///
  45.665 -    /// This function contracts two nodes.
  45.666 -    /// Node \p b will be removed but instead of deleting
  45.667 -    /// its neighboring arcs, they will be joined to \p a.
  45.668 -    /// The last parameter \p r controls whether to remove loops. \c true
  45.669 -    /// means that loops will be removed.
  45.670 +    /// This function contracts the given two nodes.
  45.671 +    /// Node \c b is removed, but instead of deleting
  45.672 +    /// its incident edges, they are joined to node \c a.
  45.673 +    /// If the last parameter \c r is \c true (this is the default value),
  45.674 +    /// then the newly created loops are removed.
  45.675      ///
  45.676 -    /// \note The <tt>ArcIt</tt>s referencing a moved arc remain
  45.677 -    /// valid.
  45.678 +    /// \note The moved edges are joined to node \c a using changeU()
  45.679 +    /// or changeV(), thus all edge and arc iterators whose base node is
  45.680 +    /// \c b are invalidated.
  45.681 +    /// Moreover all iterators referencing node \c b or the removed 
  45.682 +    /// loops are also invalidated. Other iterators remain valid.
  45.683      ///
  45.684      ///\warning This functionality cannot be used together with the
  45.685      ///Snapshot feature.
  45.686 @@ -1307,6 +1308,33 @@
  45.687        erase(b);
  45.688      }
  45.689  
  45.690 +    ///Clear the graph.
  45.691 +
  45.692 +    ///This function erases all nodes and arcs from the graph.
  45.693 +    ///
  45.694 +    void clear() {
  45.695 +      Parent::clear();
  45.696 +    }
  45.697 +
  45.698 +    /// Reserve memory for nodes.
  45.699 +
  45.700 +    /// Using this function, it is possible to avoid superfluous memory
  45.701 +    /// allocation: if you know that the graph you want to build will
  45.702 +    /// be large (e.g. it will contain millions of nodes and/or edges),
  45.703 +    /// then it is worth reserving space for this amount before starting
  45.704 +    /// to build the graph.
  45.705 +    /// \sa reserveEdge()
  45.706 +    void reserveNode(int n) { nodes.reserve(n); };
  45.707 +
  45.708 +    /// Reserve memory for edges.
  45.709 +
  45.710 +    /// Using this function, it is possible to avoid superfluous memory
  45.711 +    /// allocation: if you know that the graph you want to build will
  45.712 +    /// be large (e.g. it will contain millions of nodes and/or edges),
  45.713 +    /// then it is worth reserving space for this amount before starting
  45.714 +    /// to build the graph.
  45.715 +    /// \sa reserveNode()
  45.716 +    void reserveEdge(int m) { arcs.reserve(2 * m); };
  45.717  
  45.718      /// \brief Class to make a snapshot of the graph and restore
  45.719      /// it later.
  45.720 @@ -1316,9 +1344,15 @@
  45.721      /// The newly added nodes and edges can be removed
  45.722      /// using the restore() function.
  45.723      ///
  45.724 -    /// \warning Edge and node deletions and other modifications
  45.725 -    /// (e.g. changing nodes of edges, contracting nodes) cannot be
  45.726 -    /// restored. These events invalidate the snapshot.
  45.727 +    /// \note After a state is restored, you cannot restore a later state, 
  45.728 +    /// i.e. you cannot add the removed nodes and edges again using
  45.729 +    /// another Snapshot instance.
  45.730 +    ///
  45.731 +    /// \warning Node and edge deletions and other modifications
  45.732 +    /// (e.g. changing the end-nodes of edges or contracting nodes)
  45.733 +    /// cannot be restored. These events invalidate the snapshot.
  45.734 +    /// However the edges and nodes that were added to the graph after
  45.735 +    /// making the current snapshot can be removed without invalidating it.
  45.736      class Snapshot {
  45.737      protected:
  45.738  
  45.739 @@ -1488,39 +1522,40 @@
  45.740        /// \brief Default constructor.
  45.741        ///
  45.742        /// Default constructor.
  45.743 -      /// To actually make a snapshot you must call save().
  45.744 +      /// You have to call save() to actually make a snapshot.
  45.745        Snapshot()
  45.746          : graph(0), node_observer_proxy(*this),
  45.747            edge_observer_proxy(*this) {}
  45.748  
  45.749        /// \brief Constructor that immediately makes a snapshot.
  45.750        ///
  45.751 -      /// This constructor immediately makes a snapshot of the graph.
  45.752 -      /// \param _graph The graph we make a snapshot of.
  45.753 -      Snapshot(ListGraph &_graph)
  45.754 +      /// This constructor immediately makes a snapshot of the given graph.
  45.755 +      Snapshot(ListGraph &gr)
  45.756          : node_observer_proxy(*this),
  45.757            edge_observer_proxy(*this) {
  45.758 -        attach(_graph);
  45.759 +        attach(gr);
  45.760        }
  45.761  
  45.762        /// \brief Make a snapshot.
  45.763        ///
  45.764 -      /// Make a snapshot of the graph.
  45.765 -      ///
  45.766 -      /// This function can be called more than once. In case of a repeated
  45.767 +      /// This function makes a snapshot of the given graph.
  45.768 +      /// It can be called more than once. In case of a repeated
  45.769        /// call, the previous snapshot gets lost.
  45.770 -      /// \param _graph The graph we make the snapshot of.
  45.771 -      void save(ListGraph &_graph) {
  45.772 +      void save(ListGraph &gr) {
  45.773          if (attached()) {
  45.774            detach();
  45.775            clear();
  45.776          }
  45.777 -        attach(_graph);
  45.778 +        attach(gr);
  45.779        }
  45.780  
  45.781        /// \brief Undo the changes until the last snapshot.
  45.782 -      //
  45.783 -      /// Undo the changes until the last snapshot created by save().
  45.784 +      ///
  45.785 +      /// This function undos the changes until the last snapshot
  45.786 +      /// created by save() or Snapshot(ListGraph&).
  45.787 +      ///
  45.788 +      /// \warning This method invalidates the snapshot, i.e. repeated
  45.789 +      /// restoring is not supported unless you call save() again.
  45.790        void restore() {
  45.791          detach();
  45.792          for(std::list<Edge>::iterator it = added_edges.begin();
  45.793 @@ -1534,9 +1569,9 @@
  45.794          clear();
  45.795        }
  45.796  
  45.797 -      /// \brief Gives back true when the snapshot is valid.
  45.798 +      /// \brief Returns \c true if the snapshot is valid.
  45.799        ///
  45.800 -      /// Gives back true when the snapshot is valid.
  45.801 +      /// This function returns \c true if the snapshot is valid.
  45.802        bool valid() const {
  45.803          return attached();
  45.804        }
    46.1 --- a/lemon/lp_base.h	Thu Nov 05 10:01:02 2009 +0100
    46.2 +++ b/lemon/lp_base.h	Thu Nov 05 10:23:16 2009 +0100
    46.3 @@ -943,6 +943,14 @@
    46.4      virtual int _addCol() = 0;
    46.5      virtual int _addRow() = 0;
    46.6  
    46.7 +    virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
    46.8 +      int row = _addRow();
    46.9 +      _setRowCoeffs(row, b, e);
   46.10 +      _setRowLowerBound(row, l);
   46.11 +      _setRowUpperBound(row, u);
   46.12 +      return row;
   46.13 +    }
   46.14 +
   46.15      virtual void _eraseCol(int col) = 0;
   46.16      virtual void _eraseRow(int row) = 0;
   46.17  
   46.18 @@ -1207,8 +1215,10 @@
   46.19      ///\param u is the upper bound (\ref INF means no bound)
   46.20      ///\return The created row.
   46.21      Row addRow(Value l,const Expr &e, Value u) {
   46.22 -      Row r=addRow();
   46.23 -      row(r,l,e,u);
   46.24 +      Row r;
   46.25 +      e.simplify();
   46.26 +      r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), cols),
   46.27 +                                ExprIterator(e.comps.end(), cols), u - *e));
   46.28        return r;
   46.29      }
   46.30  
   46.31 @@ -1217,8 +1227,12 @@
   46.32      ///\param c is a linear expression (see \ref Constr)
   46.33      ///\return The created row.
   46.34      Row addRow(const Constr &c) {
   46.35 -      Row r=addRow();
   46.36 -      row(r,c);
   46.37 +      Row r;
   46.38 +      c.expr().simplify();
   46.39 +      r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound():-INF, 
   46.40 +                                ExprIterator(c.expr().comps.begin(), cols),
   46.41 +                                ExprIterator(c.expr().comps.end(), cols),
   46.42 +                                c.upperBounded()?c.upperBound():INF));
   46.43        return r;
   46.44      }
   46.45      ///Erase a column (i.e a variable) from the LP
    47.1 --- a/lemon/lp_skeleton.cc	Thu Nov 05 10:01:02 2009 +0100
    47.2 +++ b/lemon/lp_skeleton.cc	Thu Nov 05 10:23:16 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	Thu Nov 05 10:01:02 2009 +0100
    48.2 +++ b/lemon/lp_skeleton.h	Thu Nov 05 10:23:16 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	Thu Nov 05 10:01:02 2009 +0100
    49.2 +++ b/lemon/maps.h	Thu Nov 05 10:23:16 2009 +0100
    49.3 @@ -22,6 +22,7 @@
    49.4  #include <iterator>
    49.5  #include <functional>
    49.6  #include <vector>
    49.7 +#include <map>
    49.8  
    49.9  #include <lemon/core.h>
   49.10  
   49.11 @@ -29,8 +30,6 @@
   49.12  ///\ingroup maps
   49.13  ///\brief Miscellaneous property maps
   49.14  
   49.15 -#include <map>
   49.16 -
   49.17  namespace lemon {
   49.18  
   49.19    /// \addtogroup maps
   49.20 @@ -57,7 +56,7 @@
   49.21    /// its type definitions, or if you have to provide a writable map,
   49.22    /// but data written to it is not required (i.e. it will be sent to
   49.23    /// <tt>/dev/null</tt>).
   49.24 -  /// It conforms the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   49.25 +  /// It conforms to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   49.26    ///
   49.27    /// \sa ConstMap
   49.28    template<typename K, typename V>
   49.29 @@ -90,7 +89,7 @@
   49.30    /// value to each key.
   49.31    ///
   49.32    /// In other aspects it is equivalent to \c NullMap.
   49.33 -  /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
   49.34 +  /// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap"
   49.35    /// concept, but it absorbs the data written to it.
   49.36    ///
   49.37    /// The simplest way of using this map is through the constMap()
   49.38 @@ -159,7 +158,7 @@
   49.39    /// value to each key.
   49.40    ///
   49.41    /// In other aspects it is equivalent to \c NullMap.
   49.42 -  /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
   49.43 +  /// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap"
   49.44    /// concept, but it absorbs the data written to it.
   49.45    ///
   49.46    /// The simplest way of using this map is through the constMap()
   49.47 @@ -233,7 +232,7 @@
   49.48    /// values to integer keys from the range <tt>[0..size-1]</tt>.
   49.49    /// It can be used with some data structures, for example
   49.50    /// \c UnionFind, \c BinHeap, when the used items are small
   49.51 -  /// integers. This map conforms the \ref concepts::ReferenceMap
   49.52 +  /// integers. This map conforms to the \ref concepts::ReferenceMap
   49.53    /// "ReferenceMap" concept.
   49.54    ///
   49.55    /// The simplest way of using this map is through the rangeMap()
   49.56 @@ -341,7 +340,7 @@
   49.57    /// that you can specify a default value for the keys that are not
   49.58    /// stored actually. This value can be different from the default
   49.59    /// contructed value (i.e. \c %Value()).
   49.60 -  /// This type conforms the \ref concepts::ReferenceMap "ReferenceMap"
   49.61 +  /// This type conforms to the \ref concepts::ReferenceMap "ReferenceMap"
   49.62    /// concept.
   49.63    ///
   49.64    /// This map is useful if a default value should be assigned to most of
   49.65 @@ -707,7 +706,7 @@
   49.66    /// "readable map" to another type using the default conversion.
   49.67    /// The \c Key type of it is inherited from \c M and the \c Value
   49.68    /// type is \c V.
   49.69 -  /// This type conforms the \ref concepts::ReadMap "ReadMap" concept.
   49.70 +  /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
   49.71    ///
   49.72    /// The simplest way of using this map is through the convertMap()
   49.73    /// function.
   49.74 @@ -1790,11 +1789,11 @@
   49.75    /// order of Dfs algorithm, as the following examples show.
   49.76    /// \code
   49.77    ///   std::vector<Node> v;
   49.78 -  ///   dfs(g,s).processedMap(loggerBoolMap(std::back_inserter(v))).run();
   49.79 +  ///   dfs(g).processedMap(loggerBoolMap(std::back_inserter(v))).run(s);
   49.80    /// \endcode
   49.81    /// \code
   49.82    ///   std::vector<Node> v(countNodes(g));
   49.83 -  ///   dfs(g,s).processedMap(loggerBoolMap(v.begin())).run();
   49.84 +  ///   dfs(g).processedMap(loggerBoolMap(v.begin())).run(s);
   49.85    /// \endcode
   49.86    ///
   49.87    /// \note The container of the iterator must contain enough space
   49.88 @@ -1818,7 +1817,7 @@
   49.89    /// \brief Provides an immutable and unique id for each item in a graph.
   49.90    ///
   49.91    /// IdMap provides a unique and immutable id for each item of the
   49.92 -  /// same type (\c Node, \c Arc or \c Edge) in a graph. This id is 
   49.93 +  /// same type (\c Node, \c Arc or \c Edge) in a graph. This id is
   49.94    ///  - \b unique: different items get different ids,
   49.95    ///  - \b immutable: the id of an item does not change (even if you
   49.96    ///    delete other nodes).
   49.97 @@ -1826,7 +1825,7 @@
   49.98    /// Using this map you get access (i.e. can read) the inner id values of
   49.99    /// the items stored in the graph, which is returned by the \c id()
  49.100    /// function of the graph. This map can be inverted with its member
  49.101 -  /// class \c InverseMap or with the \c operator() member.
  49.102 +  /// class \c InverseMap or with the \c operator()() member.
  49.103    ///
  49.104    /// \tparam GR The graph type.
  49.105    /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
  49.106 @@ -1866,9 +1865,11 @@
  49.107  
  49.108    public:
  49.109  
  49.110 -    /// \brief This class represents the inverse of its owner (IdMap).
  49.111 +    /// \brief The inverse map type of IdMap.
  49.112      ///
  49.113 -    /// This class represents the inverse of its owner (IdMap).
  49.114 +    /// The inverse map type of IdMap. The subscript operator gives back
  49.115 +    /// an item by its id.
  49.116 +    /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
  49.117      /// \see inverse()
  49.118      class InverseMap {
  49.119      public:
  49.120 @@ -1883,9 +1884,9 @@
  49.121        /// Constructor for creating an id-to-item map.
  49.122        explicit InverseMap(const IdMap& map) : _graph(map._graph) {}
  49.123  
  49.124 -      /// \brief Gives back the given item from its id.
  49.125 +      /// \brief Gives back an item by its id.
  49.126        ///
  49.127 -      /// Gives back the given item from its id.
  49.128 +      /// Gives back an item by its id.
  49.129        Item operator[](int id) const { return _graph->fromId(id, Item());}
  49.130  
  49.131      private:
  49.132 @@ -1898,14 +1899,31 @@
  49.133      InverseMap inverse() const { return InverseMap(*_graph);}
  49.134    };
  49.135  
  49.136 +  /// \brief Returns an \c IdMap class.
  49.137 +  ///
  49.138 +  /// This function just returns an \c IdMap class.
  49.139 +  /// \relates IdMap
  49.140 +  template <typename K, typename GR>
  49.141 +  inline IdMap<GR, K> idMap(const GR& graph) {
  49.142 +    return IdMap<GR, K>(graph);
  49.143 +  }
  49.144  
  49.145    /// \brief General cross reference graph map type.
  49.146  
  49.147    /// This class provides simple invertable graph maps.
  49.148    /// It wraps a standard graph map (\c NodeMap, \c ArcMap or \c EdgeMap)
  49.149    /// and if a key is set to a new value, then stores it in the inverse map.
  49.150 -  /// The values of the map can be accessed
  49.151 -  /// with stl compatible forward iterator.
  49.152 +  /// The graph items can be accessed by their values either using
  49.153 +  /// \c InverseMap or \c operator()(), and the values of the map can be
  49.154 +  /// accessed with an STL compatible forward iterator (\c ValueIt).
  49.155 +  /// 
  49.156 +  /// This map is intended to be used when all associated values are
  49.157 +  /// different (the map is actually invertable) or there are only a few
  49.158 +  /// items with the same value.
  49.159 +  /// Otherwise consider to use \c IterableValueMap, which is more 
  49.160 +  /// suitable and more efficient for such cases. It provides iterators
  49.161 +  /// to traverse the items with the same associated value, however
  49.162 +  /// it does not have \c InverseMap.
  49.163    ///
  49.164    /// This type is not reference map, so it cannot be modified with
  49.165    /// the subscript operator.
  49.166 @@ -1946,56 +1964,66 @@
  49.167  
  49.168      /// \brief Forward iterator for values.
  49.169      ///
  49.170 -    /// This iterator is an stl compatible forward
  49.171 +    /// This iterator is an STL compatible forward
  49.172      /// iterator on the values of the map. The values can
  49.173      /// be accessed in the <tt>[beginValue, endValue)</tt> range.
  49.174      /// They are considered with multiplicity, so each value is
  49.175      /// traversed for each item it is assigned to.
  49.176 -    class ValueIterator
  49.177 +    class ValueIt
  49.178        : public std::iterator<std::forward_iterator_tag, Value> {
  49.179        friend class CrossRefMap;
  49.180      private:
  49.181 -      ValueIterator(typename Container::const_iterator _it)
  49.182 +      ValueIt(typename Container::const_iterator _it)
  49.183          : it(_it) {}
  49.184      public:
  49.185  
  49.186 -      ValueIterator() {}
  49.187 -
  49.188 -      ValueIterator& operator++() { ++it; return *this; }
  49.189 -      ValueIterator operator++(int) {
  49.190 -        ValueIterator tmp(*this);
  49.191 +      /// Constructor
  49.192 +      ValueIt() {}
  49.193 +
  49.194 +      /// \e
  49.195 +      ValueIt& operator++() { ++it; return *this; }
  49.196 +      /// \e
  49.197 +      ValueIt operator++(int) {
  49.198 +        ValueIt tmp(*this);
  49.199          operator++();
  49.200          return tmp;
  49.201        }
  49.202  
  49.203 +      /// \e
  49.204        const Value& operator*() const { return it->first; }
  49.205 +      /// \e
  49.206        const Value* operator->() const { return &(it->first); }
  49.207  
  49.208 -      bool operator==(ValueIterator jt) const { return it == jt.it; }
  49.209 -      bool operator!=(ValueIterator jt) const { return it != jt.it; }
  49.210 +      /// \e
  49.211 +      bool operator==(ValueIt jt) const { return it == jt.it; }
  49.212 +      /// \e
  49.213 +      bool operator!=(ValueIt jt) const { return it != jt.it; }
  49.214  
  49.215      private:
  49.216        typename Container::const_iterator it;
  49.217      };
  49.218 +    
  49.219 +    /// Alias for \c ValueIt
  49.220 +    typedef ValueIt ValueIterator;
  49.221  
  49.222      /// \brief Returns an iterator to the first value.
  49.223      ///
  49.224 -    /// Returns an stl compatible iterator to the
  49.225 +    /// Returns an STL compatible iterator to the
  49.226      /// first value of the map. The values of the
  49.227      /// map can be accessed in the <tt>[beginValue, endValue)</tt>
  49.228      /// range.
  49.229 -    ValueIterator beginValue() const {
  49.230 -      return ValueIterator(_inv_map.begin());
  49.231 +    ValueIt beginValue() const {
  49.232 +      return ValueIt(_inv_map.begin());
  49.233      }
  49.234  
  49.235      /// \brief Returns an iterator after the last value.
  49.236      ///
  49.237 -    /// Returns an stl compatible iterator after the
  49.238 +    /// Returns an STL compatible iterator after the
  49.239      /// last value of the map. The values of the
  49.240      /// map can be accessed in the <tt>[beginValue, endValue)</tt>
  49.241      /// range.
  49.242 -    ValueIterator endValue() const {
  49.243 -      return ValueIterator(_inv_map.end());
  49.244 +    ValueIt endValue() const {
  49.245 +      return ValueIt(_inv_map.end());
  49.246      }
  49.247  
  49.248      /// \brief Sets the value associated with the given key.
  49.249 @@ -2033,6 +2061,14 @@
  49.250        typename Container::const_iterator it = _inv_map.find(val);
  49.251        return it != _inv_map.end() ? it->second : INVALID;
  49.252      }
  49.253 +    
  49.254 +    /// \brief Returns the number of items with the given value.
  49.255 +    ///
  49.256 +    /// This function returns the number of items with the given value
  49.257 +    /// associated with it.
  49.258 +    int count(const Value &val) const {
  49.259 +      return _inv_map.count(val);
  49.260 +    }
  49.261  
  49.262    protected:
  49.263  
  49.264 @@ -2083,10 +2119,12 @@
  49.265  
  49.266    public:
  49.267  
  49.268 -    /// \brief The inverse map type.
  49.269 +    /// \brief The inverse map type of CrossRefMap.
  49.270      ///
  49.271 -    /// The inverse of this map. The subscript operator of the map
  49.272 -    /// gives back the item that was last assigned to the value.
  49.273 +    /// The inverse map type of CrossRefMap. The subscript operator gives
  49.274 +    /// back an item by its value.
  49.275 +    /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
  49.276 +    /// \see inverse()
  49.277      class InverseMap {
  49.278      public:
  49.279        /// \brief Constructor
  49.280 @@ -2113,20 +2151,20 @@
  49.281        const CrossRefMap& _inverted;
  49.282      };
  49.283  
  49.284 -    /// \brief It gives back the read-only inverse map.
  49.285 +    /// \brief Gives back the inverse of the map.
  49.286      ///
  49.287 -    /// It gives back the read-only inverse map.
  49.288 +    /// Gives back the inverse of the CrossRefMap.
  49.289      InverseMap inverse() const {
  49.290        return InverseMap(*this);
  49.291      }
  49.292  
  49.293    };
  49.294  
  49.295 -  /// \brief Provides continuous and unique ID for the
  49.296 +  /// \brief Provides continuous and unique id for the
  49.297    /// items of a graph.
  49.298    ///
  49.299    /// RangeIdMap provides a unique and continuous
  49.300 -  /// ID for each item of a given type (\c Node, \c Arc or
  49.301 +  /// id for each item of a given type (\c Node, \c Arc or
  49.302    /// \c Edge) in a graph. This id is
  49.303    ///  - \b unique: different items get different ids,
  49.304    ///  - \b continuous: the range of the ids is the set of integers
  49.305 @@ -2137,7 +2175,7 @@
  49.306    /// Thus this id is not (necessarily) the same as what can get using
  49.307    /// the \c id() function of the graph or \ref IdMap.
  49.308    /// This map can be inverted with its member class \c InverseMap,
  49.309 -  /// or with the \c operator() member.
  49.310 +  /// or with the \c operator()() member.
  49.311    ///
  49.312    /// \tparam GR The graph type.
  49.313    /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
  49.314 @@ -2265,16 +2303,16 @@
  49.315        _inv_map[pi] = q;
  49.316      }
  49.317  
  49.318 -    /// \brief Gives back the \e RangeId of the item
  49.319 +    /// \brief Gives back the \e range \e id of the item
  49.320      ///
  49.321 -    /// Gives back the \e RangeId of the item.
  49.322 +    /// Gives back the \e range \e id of the item.
  49.323      int operator[](const Item& item) const {
  49.324        return Map::operator[](item);
  49.325      }
  49.326  
  49.327 -    /// \brief Gives back the item belonging to a \e RangeId
  49.328 -    /// 
  49.329 -    /// Gives back the item belonging to a \e RangeId.
  49.330 +    /// \brief Gives back the item belonging to a \e range \e id
  49.331 +    ///
  49.332 +    /// Gives back the item belonging to the given \e range \e id.
  49.333      Item operator()(int id) const {
  49.334        return _inv_map[id];
  49.335      }
  49.336 @@ -2288,7 +2326,9 @@
  49.337  
  49.338      /// \brief The inverse map type of RangeIdMap.
  49.339      ///
  49.340 -    /// The inverse map type of RangeIdMap.
  49.341 +    /// The inverse map type of RangeIdMap. The subscript operator gives
  49.342 +    /// back an item by its \e range \e id.
  49.343 +    /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
  49.344      class InverseMap {
  49.345      public:
  49.346        /// \brief Constructor
  49.347 @@ -2306,7 +2346,7 @@
  49.348        /// \brief Subscript operator.
  49.349        ///
  49.350        /// Subscript operator. It gives back the item
  49.351 -      /// that the descriptor currently belongs to.
  49.352 +      /// that the given \e range \e id currently belongs to.
  49.353        Value operator[](const Key& key) const {
  49.354          return _inverted(key);
  49.355        }
  49.356 @@ -2324,12 +2364,932 @@
  49.357  
  49.358      /// \brief Gives back the inverse of the map.
  49.359      ///
  49.360 -    /// Gives back the inverse of the map.
  49.361 +    /// Gives back the inverse of the RangeIdMap.
  49.362      const InverseMap inverse() const {
  49.363        return InverseMap(*this);
  49.364      }
  49.365    };
  49.366  
  49.367 +  /// \brief Returns a \c RangeIdMap class.
  49.368 +  ///
  49.369 +  /// This function just returns an \c RangeIdMap class.
  49.370 +  /// \relates RangeIdMap
  49.371 +  template <typename K, typename GR>
  49.372 +  inline RangeIdMap<GR, K> rangeIdMap(const GR& graph) {
  49.373 +    return RangeIdMap<GR, K>(graph);
  49.374 +  }
  49.375 +  
  49.376 +  /// \brief Dynamic iterable \c bool map.
  49.377 +  ///
  49.378 +  /// This class provides a special graph map type which can store a
  49.379 +  /// \c bool value for graph items (\c Node, \c Arc or \c Edge).
  49.380 +  /// For both \c true and \c false values it is possible to iterate on
  49.381 +  /// the keys mapped to the value.
  49.382 +  ///
  49.383 +  /// This type is a reference map, so it can be modified with the
  49.384 +  /// subscript operator.
  49.385 +  ///
  49.386 +  /// \tparam GR The graph type.
  49.387 +  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
  49.388 +  /// \c GR::Edge).
  49.389 +  ///
  49.390 +  /// \see IterableIntMap, IterableValueMap
  49.391 +  /// \see CrossRefMap
  49.392 +  template <typename GR, typename K>
  49.393 +  class IterableBoolMap
  49.394 +    : protected ItemSetTraits<GR, K>::template Map<int>::Type {
  49.395 +  private:
  49.396 +    typedef GR Graph;
  49.397 +
  49.398 +    typedef typename ItemSetTraits<GR, K>::ItemIt KeyIt;
  49.399 +    typedef typename ItemSetTraits<GR, K>::template Map<int>::Type Parent;
  49.400 +
  49.401 +    std::vector<K> _array;
  49.402 +    int _sep;
  49.403 +
  49.404 +  public:
  49.405 +
  49.406 +    /// Indicates that the map is reference map.
  49.407 +    typedef True ReferenceMapTag;
  49.408 +
  49.409 +    /// The key type
  49.410 +    typedef K Key;
  49.411 +    /// The value type
  49.412 +    typedef bool Value;
  49.413 +    /// The const reference type.
  49.414 +    typedef const Value& ConstReference;
  49.415 +
  49.416 +  private:
  49.417 +
  49.418 +    int position(const Key& key) const {
  49.419 +      return Parent::operator[](key);
  49.420 +    }
  49.421 +
  49.422 +  public:
  49.423 +
  49.424 +    /// \brief Reference to the value of the map.
  49.425 +    ///
  49.426 +    /// This class is similar to the \c bool type. It can be converted to
  49.427 +    /// \c bool and it provides the same operators.
  49.428 +    class Reference {
  49.429 +      friend class IterableBoolMap;
  49.430 +    private:
  49.431 +      Reference(IterableBoolMap& map, const Key& key)
  49.432 +        : _key(key), _map(map) {}
  49.433 +    public:
  49.434 +
  49.435 +      Reference& operator=(const Reference& value) {
  49.436 +        _map.set(_key, static_cast<bool>(value));
  49.437 +         return *this;
  49.438 +      }
  49.439 +
  49.440 +      operator bool() const {
  49.441 +        return static_cast<const IterableBoolMap&>(_map)[_key];
  49.442 +      }
  49.443 +
  49.444 +      Reference& operator=(bool value) {
  49.445 +        _map.set(_key, value);
  49.446 +        return *this;
  49.447 +      }
  49.448 +      Reference& operator&=(bool value) {
  49.449 +        _map.set(_key, _map[_key] & value);
  49.450 +        return *this;
  49.451 +      }
  49.452 +      Reference& operator|=(bool value) {
  49.453 +        _map.set(_key, _map[_key] | value);
  49.454 +        return *this;
  49.455 +      }
  49.456 +      Reference& operator^=(bool value) {
  49.457 +        _map.set(_key, _map[_key] ^ value);
  49.458 +        return *this;
  49.459 +      }
  49.460 +    private:
  49.461 +      Key _key;
  49.462 +      IterableBoolMap& _map;
  49.463 +    };
  49.464 +
  49.465 +    /// \brief Constructor of the map with a default value.
  49.466 +    ///
  49.467 +    /// Constructor of the map with a default value.
  49.468 +    explicit IterableBoolMap(const Graph& graph, bool def = false)
  49.469 +      : Parent(graph) {
  49.470 +      typename Parent::Notifier* nf = Parent::notifier();
  49.471 +      Key it;
  49.472 +      for (nf->first(it); it != INVALID; nf->next(it)) {
  49.473 +        Parent::set(it, _array.size());
  49.474 +        _array.push_back(it);
  49.475 +      }
  49.476 +      _sep = (def ? _array.size() : 0);
  49.477 +    }
  49.478 +
  49.479 +    /// \brief Const subscript operator of the map.
  49.480 +    ///
  49.481 +    /// Const subscript operator of the map.
  49.482 +    bool operator[](const Key& key) const {
  49.483 +      return position(key) < _sep;
  49.484 +    }
  49.485 +
  49.486 +    /// \brief Subscript operator of the map.
  49.487 +    ///
  49.488 +    /// Subscript operator of the map.
  49.489 +    Reference operator[](const Key& key) {
  49.490 +      return Reference(*this, key);
  49.491 +    }
  49.492 +
  49.493 +    /// \brief Set operation of the map.
  49.494 +    ///
  49.495 +    /// Set operation of the map.
  49.496 +    void set(const Key& key, bool value) {
  49.497 +      int pos = position(key);
  49.498 +      if (value) {
  49.499 +        if (pos < _sep) return;
  49.500 +        Key tmp = _array[_sep];
  49.501 +        _array[_sep] = key;
  49.502 +        Parent::set(key, _sep);
  49.503 +        _array[pos] = tmp;
  49.504 +        Parent::set(tmp, pos);
  49.505 +        ++_sep;
  49.506 +      } else {
  49.507 +        if (pos >= _sep) return;
  49.508 +        --_sep;
  49.509 +        Key tmp = _array[_sep];
  49.510 +        _array[_sep] = key;
  49.511 +        Parent::set(key, _sep);
  49.512 +        _array[pos] = tmp;
  49.513 +        Parent::set(tmp, pos);
  49.514 +      }
  49.515 +    }
  49.516 +
  49.517 +    /// \brief Set all items.
  49.518 +    ///
  49.519 +    /// Set all items in the map.
  49.520 +    /// \note Constant time operation.
  49.521 +    void setAll(bool value) {
  49.522 +      _sep = (value ? _array.size() : 0);
  49.523 +    }
  49.524 +
  49.525 +    /// \brief Returns the number of the keys mapped to \c true.
  49.526 +    ///
  49.527 +    /// Returns the number of the keys mapped to \c true.
  49.528 +    int trueNum() const {
  49.529 +      return _sep;
  49.530 +    }
  49.531 +
  49.532 +    /// \brief Returns the number of the keys mapped to \c false.
  49.533 +    ///
  49.534 +    /// Returns the number of the keys mapped to \c false.
  49.535 +    int falseNum() const {
  49.536 +      return _array.size() - _sep;
  49.537 +    }
  49.538 +
  49.539 +    /// \brief Iterator for the keys mapped to \c true.
  49.540 +    ///
  49.541 +    /// Iterator for the keys mapped to \c true. It works
  49.542 +    /// like a graph item iterator, it can be converted to
  49.543 +    /// the key type of the map, incremented with \c ++ operator, and
  49.544 +    /// if the iterator leaves the last valid key, it will be equal to
  49.545 +    /// \c INVALID.
  49.546 +    class TrueIt : public Key {
  49.547 +    public:
  49.548 +      typedef Key Parent;
  49.549 +
  49.550 +      /// \brief Creates an iterator.
  49.551 +      ///
  49.552 +      /// Creates an iterator. It iterates on the
  49.553 +      /// keys mapped to \c true.
  49.554 +      /// \param map The IterableBoolMap.
  49.555 +      explicit TrueIt(const IterableBoolMap& map)
  49.556 +        : Parent(map._sep > 0 ? map._array[map._sep - 1] : INVALID),
  49.557 +          _map(&map) {}
  49.558 +
  49.559 +      /// \brief Invalid constructor \& conversion.
  49.560 +      ///
  49.561 +      /// This constructor initializes the iterator to be invalid.
  49.562 +      /// \sa Invalid for more details.
  49.563 +      TrueIt(Invalid) : Parent(INVALID), _map(0) {}
  49.564 +
  49.565 +      /// \brief Increment operator.
  49.566 +      ///
  49.567 +      /// Increment operator.
  49.568 +      TrueIt& operator++() {
  49.569 +        int pos = _map->position(*this);
  49.570 +        Parent::operator=(pos > 0 ? _map->_array[pos - 1] : INVALID);
  49.571 +        return *this;
  49.572 +      }
  49.573 +
  49.574 +    private:
  49.575 +      const IterableBoolMap* _map;
  49.576 +    };
  49.577 +
  49.578 +    /// \brief Iterator for the keys mapped to \c false.
  49.579 +    ///
  49.580 +    /// Iterator for the keys mapped to \c false. It works
  49.581 +    /// like a graph item iterator, it can be converted to
  49.582 +    /// the key type of the map, incremented with \c ++ operator, and
  49.583 +    /// if the iterator leaves the last valid key, it will be equal to
  49.584 +    /// \c INVALID.
  49.585 +    class FalseIt : public Key {
  49.586 +    public:
  49.587 +      typedef Key Parent;
  49.588 +
  49.589 +      /// \brief Creates an iterator.
  49.590 +      ///
  49.591 +      /// Creates an iterator. It iterates on the
  49.592 +      /// keys mapped to \c false.
  49.593 +      /// \param map The IterableBoolMap.
  49.594 +      explicit FalseIt(const IterableBoolMap& map)
  49.595 +        : Parent(map._sep < int(map._array.size()) ?
  49.596 +                 map._array.back() : INVALID), _map(&map) {}
  49.597 +
  49.598 +      /// \brief Invalid constructor \& conversion.
  49.599 +      ///
  49.600 +      /// This constructor initializes the iterator to be invalid.
  49.601 +      /// \sa Invalid for more details.
  49.602 +      FalseIt(Invalid) : Parent(INVALID), _map(0) {}
  49.603 +
  49.604 +      /// \brief Increment operator.
  49.605 +      ///
  49.606 +      /// Increment operator.
  49.607 +      FalseIt& operator++() {
  49.608 +        int pos = _map->position(*this);
  49.609 +        Parent::operator=(pos > _map->_sep ? _map->_array[pos - 1] : INVALID);
  49.610 +        return *this;
  49.611 +      }
  49.612 +
  49.613 +    private:
  49.614 +      const IterableBoolMap* _map;
  49.615 +    };
  49.616 +
  49.617 +    /// \brief Iterator for the keys mapped to a given value.
  49.618 +    ///
  49.619 +    /// Iterator for the keys mapped to a given value. It works
  49.620 +    /// like a graph item iterator, it can be converted to
  49.621 +    /// the key type of the map, incremented with \c ++ operator, and
  49.622 +    /// if the iterator leaves the last valid key, it will be equal to
  49.623 +    /// \c INVALID.
  49.624 +    class ItemIt : public Key {
  49.625 +    public:
  49.626 +      typedef Key Parent;
  49.627 +
  49.628 +      /// \brief Creates an iterator with a value.
  49.629 +      ///
  49.630 +      /// Creates an iterator with a value. It iterates on the
  49.631 +      /// keys mapped to the given value.
  49.632 +      /// \param map The IterableBoolMap.
  49.633 +      /// \param value The value.
  49.634 +      ItemIt(const IterableBoolMap& map, bool value)
  49.635 +        : Parent(value ? 
  49.636 +                 (map._sep > 0 ?
  49.637 +                  map._array[map._sep - 1] : INVALID) :
  49.638 +                 (map._sep < int(map._array.size()) ?
  49.639 +                  map._array.back() : INVALID)), _map(&map) {}
  49.640 +
  49.641 +      /// \brief Invalid constructor \& conversion.
  49.642 +      ///
  49.643 +      /// This constructor initializes the iterator to be invalid.
  49.644 +      /// \sa Invalid for more details.
  49.645 +      ItemIt(Invalid) : Parent(INVALID), _map(0) {}
  49.646 +
  49.647 +      /// \brief Increment operator.
  49.648 +      ///
  49.649 +      /// Increment operator.
  49.650 +      ItemIt& operator++() {
  49.651 +        int pos = _map->position(*this);
  49.652 +        int _sep = pos >= _map->_sep ? _map->_sep : 0;
  49.653 +        Parent::operator=(pos > _sep ? _map->_array[pos - 1] : INVALID);
  49.654 +        return *this;
  49.655 +      }
  49.656 +
  49.657 +    private:
  49.658 +      const IterableBoolMap* _map;
  49.659 +    };
  49.660 +
  49.661 +  protected:
  49.662 +
  49.663 +    virtual void add(const Key& key) {
  49.664 +      Parent::add(key);
  49.665 +      Parent::set(key, _array.size());
  49.666 +      _array.push_back(key);
  49.667 +    }
  49.668 +
  49.669 +    virtual void add(const std::vector<Key>& keys) {
  49.670 +      Parent::add(keys);
  49.671 +      for (int i = 0; i < int(keys.size()); ++i) {
  49.672 +        Parent::set(keys[i], _array.size());
  49.673 +        _array.push_back(keys[i]);
  49.674 +      }
  49.675 +    }
  49.676 +
  49.677 +    virtual void erase(const Key& key) {
  49.678 +      int pos = position(key);
  49.679 +      if (pos < _sep) {
  49.680 +        --_sep;
  49.681 +        Parent::set(_array[_sep], pos);
  49.682 +        _array[pos] = _array[_sep];
  49.683 +        Parent::set(_array.back(), _sep);
  49.684 +        _array[_sep] = _array.back();
  49.685 +        _array.pop_back();
  49.686 +      } else {
  49.687 +        Parent::set(_array.back(), pos);
  49.688 +        _array[pos] = _array.back();
  49.689 +        _array.pop_back();
  49.690 +      }
  49.691 +      Parent::erase(key);
  49.692 +    }
  49.693 +
  49.694 +    virtual void erase(const std::vector<Key>& keys) {
  49.695 +      for (int i = 0; i < int(keys.size()); ++i) {
  49.696 +        int pos = position(keys[i]);
  49.697 +        if (pos < _sep) {
  49.698 +          --_sep;
  49.699 +          Parent::set(_array[_sep], pos);
  49.700 +          _array[pos] = _array[_sep];
  49.701 +          Parent::set(_array.back(), _sep);
  49.702 +          _array[_sep] = _array.back();
  49.703 +          _array.pop_back();
  49.704 +        } else {
  49.705 +          Parent::set(_array.back(), pos);
  49.706 +          _array[pos] = _array.back();
  49.707 +          _array.pop_back();
  49.708 +        }
  49.709 +      }
  49.710 +      Parent::erase(keys);
  49.711 +    }
  49.712 +
  49.713 +    virtual void build() {
  49.714 +      Parent::build();
  49.715 +      typename Parent::Notifier* nf = Parent::notifier();
  49.716 +      Key it;
  49.717 +      for (nf->first(it); it != INVALID; nf->next(it)) {
  49.718 +        Parent::set(it, _array.size());
  49.719 +        _array.push_back(it);
  49.720 +      }
  49.721 +      _sep = 0;
  49.722 +    }
  49.723 +
  49.724 +    virtual void clear() {
  49.725 +      _array.clear();
  49.726 +      _sep = 0;
  49.727 +      Parent::clear();
  49.728 +    }
  49.729 +
  49.730 +  };
  49.731 +
  49.732 +
  49.733 +  namespace _maps_bits {
  49.734 +    template <typename Item>
  49.735 +    struct IterableIntMapNode {
  49.736 +      IterableIntMapNode() : value(-1) {}
  49.737 +      IterableIntMapNode(int _value) : value(_value) {}
  49.738 +      Item prev, next;
  49.739 +      int value;
  49.740 +    };
  49.741 +  }
  49.742 +
  49.743 +  /// \brief Dynamic iterable integer map.
  49.744 +  ///
  49.745 +  /// This class provides a special graph map type which can store an
  49.746 +  /// integer value for graph items (\c Node, \c Arc or \c Edge).
  49.747 +  /// For each non-negative value it is possible to iterate on the keys
  49.748 +  /// mapped to the value.
  49.749 +  ///
  49.750 +  /// This map is intended to be used with small integer values, for which
  49.751 +  /// it is efficient, and supports iteration only for non-negative values.
  49.752 +  /// If you need large values and/or iteration for negative integers,
  49.753 +  /// consider to use \ref IterableValueMap instead.
  49.754 +  ///
  49.755 +  /// This type is a reference map, so it can be modified with the
  49.756 +  /// subscript operator.
  49.757 +  ///
  49.758 +  /// \note The size of the data structure depends on the largest
  49.759 +  /// value in the map.
  49.760 +  ///
  49.761 +  /// \tparam GR The graph type.
  49.762 +  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
  49.763 +  /// \c GR::Edge).
  49.764 +  ///
  49.765 +  /// \see IterableBoolMap, IterableValueMap
  49.766 +  /// \see CrossRefMap
  49.767 +  template <typename GR, typename K>
  49.768 +  class IterableIntMap
  49.769 +    : protected ItemSetTraits<GR, K>::
  49.770 +        template Map<_maps_bits::IterableIntMapNode<K> >::Type {
  49.771 +  public:
  49.772 +    typedef typename ItemSetTraits<GR, K>::
  49.773 +      template Map<_maps_bits::IterableIntMapNode<K> >::Type Parent;
  49.774 +
  49.775 +    /// The key type
  49.776 +    typedef K Key;
  49.777 +    /// The value type
  49.778 +    typedef int Value;
  49.779 +    /// The graph type
  49.780 +    typedef GR Graph;
  49.781 +
  49.782 +    /// \brief Constructor of the map.
  49.783 +    ///
  49.784 +    /// Constructor of the map. It sets all values to -1.
  49.785 +    explicit IterableIntMap(const Graph& graph)
  49.786 +      : Parent(graph) {}
  49.787 +
  49.788 +    /// \brief Constructor of the map with a given value.
  49.789 +    ///
  49.790 +    /// Constructor of the map with a given value.
  49.791 +    explicit IterableIntMap(const Graph& graph, int value)
  49.792 +      : Parent(graph, _maps_bits::IterableIntMapNode<K>(value)) {
  49.793 +      if (value >= 0) {
  49.794 +        for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
  49.795 +          lace(it);
  49.796 +        }
  49.797 +      }
  49.798 +    }
  49.799 +
  49.800 +  private:
  49.801 +
  49.802 +    void unlace(const Key& key) {
  49.803 +      typename Parent::Value& node = Parent::operator[](key);
  49.804 +      if (node.value < 0) return;
  49.805 +      if (node.prev != INVALID) {
  49.806 +        Parent::operator[](node.prev).next = node.next;
  49.807 +      } else {
  49.808 +        _first[node.value] = node.next;
  49.809 +      }
  49.810 +      if (node.next != INVALID) {
  49.811 +        Parent::operator[](node.next).prev = node.prev;
  49.812 +      }
  49.813 +      while (!_first.empty() && _first.back() == INVALID) {
  49.814 +        _first.pop_back();
  49.815 +      }
  49.816 +    }
  49.817 +
  49.818 +    void lace(const Key& key) {
  49.819 +      typename Parent::Value& node = Parent::operator[](key);
  49.820 +      if (node.value < 0) return;
  49.821 +      if (node.value >= int(_first.size())) {
  49.822 +        _first.resize(node.value + 1, INVALID);
  49.823 +      }
  49.824 +      node.prev = INVALID;
  49.825 +      node.next = _first[node.value];
  49.826 +      if (node.next != INVALID) {
  49.827 +        Parent::operator[](node.next).prev = key;
  49.828 +      }
  49.829 +      _first[node.value] = key;
  49.830 +    }
  49.831 +
  49.832 +  public:
  49.833 +
  49.834 +    /// Indicates that the map is reference map.
  49.835 +    typedef True ReferenceMapTag;
  49.836 +
  49.837 +    /// \brief Reference to the value of the map.
  49.838 +    ///
  49.839 +    /// This class is similar to the \c int type. It can
  49.840 +    /// be converted to \c int and it has the same operators.
  49.841 +    class Reference {
  49.842 +      friend class IterableIntMap;
  49.843 +    private:
  49.844 +      Reference(IterableIntMap& map, const Key& key)
  49.845 +        : _key(key), _map(map) {}
  49.846 +    public:
  49.847 +
  49.848 +      Reference& operator=(const Reference& value) {
  49.849 +        _map.set(_key, static_cast<const int&>(value));
  49.850 +         return *this;
  49.851 +      }
  49.852 +
  49.853 +      operator const int&() const {
  49.854 +        return static_cast<const IterableIntMap&>(_map)[_key];
  49.855 +      }
  49.856 +
  49.857 +      Reference& operator=(int value) {
  49.858 +        _map.set(_key, value);
  49.859 +        return *this;
  49.860 +      }
  49.861 +      Reference& operator++() {
  49.862 +        _map.set(_key, _map[_key] + 1);
  49.863 +        return *this;
  49.864 +      }
  49.865 +      int operator++(int) {
  49.866 +        int value = _map[_key];
  49.867 +        _map.set(_key, value + 1);
  49.868 +        return value;
  49.869 +      }
  49.870 +      Reference& operator--() {
  49.871 +        _map.set(_key, _map[_key] - 1);
  49.872 +        return *this;
  49.873 +      }
  49.874 +      int operator--(int) {
  49.875 +        int value = _map[_key];
  49.876 +        _map.set(_key, value - 1);
  49.877 +        return value;
  49.878 +      }
  49.879 +      Reference& operator+=(int value) {
  49.880 +        _map.set(_key, _map[_key] + value);
  49.881 +        return *this;
  49.882 +      }
  49.883 +      Reference& operator-=(int value) {
  49.884 +        _map.set(_key, _map[_key] - value);
  49.885 +        return *this;
  49.886 +      }
  49.887 +      Reference& operator*=(int value) {
  49.888 +        _map.set(_key, _map[_key] * value);
  49.889 +        return *this;
  49.890 +      }
  49.891 +      Reference& operator/=(int value) {
  49.892 +        _map.set(_key, _map[_key] / value);
  49.893 +        return *this;
  49.894 +      }
  49.895 +      Reference& operator%=(int value) {
  49.896 +        _map.set(_key, _map[_key] % value);
  49.897 +        return *this;
  49.898 +      }
  49.899 +      Reference& operator&=(int value) {
  49.900 +        _map.set(_key, _map[_key] & value);
  49.901 +        return *this;
  49.902 +      }
  49.903 +      Reference& operator|=(int value) {
  49.904 +        _map.set(_key, _map[_key] | value);
  49.905 +        return *this;
  49.906 +      }
  49.907 +      Reference& operator^=(int value) {
  49.908 +        _map.set(_key, _map[_key] ^ value);
  49.909 +        return *this;
  49.910 +      }
  49.911 +      Reference& operator<<=(int value) {
  49.912 +        _map.set(_key, _map[_key] << value);
  49.913 +        return *this;
  49.914 +      }
  49.915 +      Reference& operator>>=(int value) {
  49.916 +        _map.set(_key, _map[_key] >> value);
  49.917 +        return *this;
  49.918 +      }
  49.919 +
  49.920 +    private:
  49.921 +      Key _key;
  49.922 +      IterableIntMap& _map;
  49.923 +    };
  49.924 +
  49.925 +    /// The const reference type.
  49.926 +    typedef const Value& ConstReference;
  49.927 +
  49.928 +    /// \brief Gives back the maximal value plus one.
  49.929 +    ///
  49.930 +    /// Gives back the maximal value plus one.
  49.931 +    int size() const {
  49.932 +      return _first.size();
  49.933 +    }
  49.934 +
  49.935 +    /// \brief Set operation of the map.
  49.936 +    ///
  49.937 +    /// Set operation of the map.
  49.938 +    void set(const Key& key, const Value& value) {
  49.939 +      unlace(key);
  49.940 +      Parent::operator[](key).value = value;
  49.941 +      lace(key);
  49.942 +    }
  49.943 +
  49.944 +    /// \brief Const subscript operator of the map.
  49.945 +    ///
  49.946 +    /// Const subscript operator of the map.
  49.947 +    const Value& operator[](const Key& key) const {
  49.948 +      return Parent::operator[](key).value;
  49.949 +    }
  49.950 +
  49.951 +    /// \brief Subscript operator of the map.
  49.952 +    ///
  49.953 +    /// Subscript operator of the map.
  49.954 +    Reference operator[](const Key& key) {
  49.955 +      return Reference(*this, key);
  49.956 +    }
  49.957 +
  49.958 +    /// \brief Iterator for the keys with the same value.
  49.959 +    ///
  49.960 +    /// Iterator for the keys with the same value. It works
  49.961 +    /// like a graph item iterator, it can be converted to
  49.962 +    /// the item type of the map, incremented with \c ++ operator, and
  49.963 +    /// if the iterator leaves the last valid item, it will be equal to
  49.964 +    /// \c INVALID.
  49.965 +    class ItemIt : public Key {
  49.966 +    public:
  49.967 +      typedef Key Parent;
  49.968 +
  49.969 +      /// \brief Invalid constructor \& conversion.
  49.970 +      ///
  49.971 +      /// This constructor initializes the iterator to be invalid.
  49.972 +      /// \sa Invalid for more details.
  49.973 +      ItemIt(Invalid) : Parent(INVALID), _map(0) {}
  49.974 +
  49.975 +      /// \brief Creates an iterator with a value.
  49.976 +      ///
  49.977 +      /// Creates an iterator with a value. It iterates on the
  49.978 +      /// keys mapped to the given value.
  49.979 +      /// \param map The IterableIntMap.
  49.980 +      /// \param value The value.
  49.981 +      ItemIt(const IterableIntMap& map, int value) : _map(&map) {
  49.982 +        if (value < 0 || value >= int(_map->_first.size())) {
  49.983 +          Parent::operator=(INVALID);
  49.984 +        } else {
  49.985 +          Parent::operator=(_map->_first[value]);
  49.986 +        }
  49.987 +      }
  49.988 +
  49.989 +      /// \brief Increment operator.
  49.990 +      ///
  49.991 +      /// Increment operator.
  49.992 +      ItemIt& operator++() {
  49.993 +        Parent::operator=(_map->IterableIntMap::Parent::
  49.994 +                          operator[](static_cast<Parent&>(*this)).next);
  49.995 +        return *this;
  49.996 +      }
  49.997 +
  49.998 +    private:
  49.999 +      const IterableIntMap* _map;
 49.1000 +    };
 49.1001 +
 49.1002 +  protected:
 49.1003 +
 49.1004 +    virtual void erase(const Key& key) {
 49.1005 +      unlace(key);
 49.1006 +      Parent::erase(key);
 49.1007 +    }
 49.1008 +
 49.1009 +    virtual void erase(const std::vector<Key>& keys) {
 49.1010 +      for (int i = 0; i < int(keys.size()); ++i) {
 49.1011 +        unlace(keys[i]);
 49.1012 +      }
 49.1013 +      Parent::erase(keys);
 49.1014 +    }
 49.1015 +
 49.1016 +    virtual void clear() {
 49.1017 +      _first.clear();
 49.1018 +      Parent::clear();
 49.1019 +    }
 49.1020 +
 49.1021 +  private:
 49.1022 +    std::vector<Key> _first;
 49.1023 +  };
 49.1024 +
 49.1025 +  namespace _maps_bits {
 49.1026 +    template <typename Item, typename Value>
 49.1027 +    struct IterableValueMapNode {
 49.1028 +      IterableValueMapNode(Value _value = Value()) : value(_value) {}
 49.1029 +      Item prev, next;
 49.1030 +      Value value;
 49.1031 +    };
 49.1032 +  }
 49.1033 +
 49.1034 +  /// \brief Dynamic iterable map for comparable values.
 49.1035 +  ///
 49.1036 +  /// This class provides a special graph map type which can store a
 49.1037 +  /// comparable value for graph items (\c Node, \c Arc or \c Edge).
 49.1038 +  /// For each value it is possible to iterate on the keys mapped to
 49.1039 +  /// the value (\c ItemIt), and the values of the map can be accessed
 49.1040 +  /// with an STL compatible forward iterator (\c ValueIt).
 49.1041 +  /// The map stores a linked list for each value, which contains
 49.1042 +  /// the items mapped to the value, and the used values are stored
 49.1043 +  /// in balanced binary tree (\c std::map).
 49.1044 +  ///
 49.1045 +  /// \ref IterableBoolMap and \ref IterableIntMap are similar classes
 49.1046 +  /// specialized for \c bool and \c int values, respectively.
 49.1047 +  ///
 49.1048 +  /// This type is not reference map, so it cannot be modified with
 49.1049 +  /// the subscript operator.
 49.1050 +  ///
 49.1051 +  /// \tparam GR The graph type.
 49.1052 +  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
 49.1053 +  /// \c GR::Edge).
 49.1054 +  /// \tparam V The value type of the map. It can be any comparable
 49.1055 +  /// value type.
 49.1056 +  ///
 49.1057 +  /// \see IterableBoolMap, IterableIntMap
 49.1058 +  /// \see CrossRefMap
 49.1059 +  template <typename GR, typename K, typename V>
 49.1060 +  class IterableValueMap
 49.1061 +    : protected ItemSetTraits<GR, K>::
 49.1062 +        template Map<_maps_bits::IterableValueMapNode<K, V> >::Type {
 49.1063 +  public:
 49.1064 +    typedef typename ItemSetTraits<GR, K>::
 49.1065 +      template Map<_maps_bits::IterableValueMapNode<K, V> >::Type Parent;
 49.1066 +
 49.1067 +    /// The key type
 49.1068 +    typedef K Key;
 49.1069 +    /// The value type
 49.1070 +    typedef V Value;
 49.1071 +    /// The graph type
 49.1072 +    typedef GR Graph;
 49.1073 +
 49.1074 +  public:
 49.1075 +
 49.1076 +    /// \brief Constructor of the map with a given value.
 49.1077 +    ///
 49.1078 +    /// Constructor of the map with a given value.
 49.1079 +    explicit IterableValueMap(const Graph& graph,
 49.1080 +                              const Value& value = Value())
 49.1081 +      : Parent(graph, _maps_bits::IterableValueMapNode<K, V>(value)) {
 49.1082 +      for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
 49.1083 +        lace(it);
 49.1084 +      }
 49.1085 +    }
 49.1086 +
 49.1087 +  protected:
 49.1088 +
 49.1089 +    void unlace(const Key& key) {
 49.1090 +      typename Parent::Value& node = Parent::operator[](key);
 49.1091 +      if (node.prev != INVALID) {
 49.1092 +        Parent::operator[](node.prev).next = node.next;
 49.1093 +      } else {
 49.1094 +        if (node.next != INVALID) {
 49.1095 +          _first[node.value] = node.next;
 49.1096 +        } else {
 49.1097 +          _first.erase(node.value);
 49.1098 +        }
 49.1099 +      }
 49.1100 +      if (node.next != INVALID) {
 49.1101 +        Parent::operator[](node.next).prev = node.prev;
 49.1102 +      }
 49.1103 +    }
 49.1104 +
 49.1105 +    void lace(const Key& key) {
 49.1106 +      typename Parent::Value& node = Parent::operator[](key);
 49.1107 +      typename std::map<Value, Key>::iterator it = _first.find(node.value);
 49.1108 +      if (it == _first.end()) {
 49.1109 +        node.prev = node.next = INVALID;
 49.1110 +        _first.insert(std::make_pair(node.value, key));
 49.1111 +      } else {
 49.1112 +        node.prev = INVALID;
 49.1113 +        node.next = it->second;
 49.1114 +        if (node.next != INVALID) {
 49.1115 +          Parent::operator[](node.next).prev = key;
 49.1116 +        }
 49.1117 +        it->second = key;
 49.1118 +      }
 49.1119 +    }
 49.1120 +
 49.1121 +  public:
 49.1122 +
 49.1123 +    /// \brief Forward iterator for values.
 49.1124 +    ///
 49.1125 +    /// This iterator is an STL compatible forward
 49.1126 +    /// iterator on the values of the map. The values can
 49.1127 +    /// be accessed in the <tt>[beginValue, endValue)</tt> range.
 49.1128 +    class ValueIt
 49.1129 +      : public std::iterator<std::forward_iterator_tag, Value> {
 49.1130 +      friend class IterableValueMap;
 49.1131 +    private:
 49.1132 +      ValueIt(typename std::map<Value, Key>::const_iterator _it)
 49.1133 +        : it(_it) {}
 49.1134 +    public:
 49.1135 +
 49.1136 +      /// Constructor
 49.1137 +      ValueIt() {}
 49.1138 +
 49.1139 +      /// \e
 49.1140 +      ValueIt& operator++() { ++it; return *this; }
 49.1141 +      /// \e
 49.1142 +      ValueIt operator++(int) {
 49.1143 +        ValueIt tmp(*this);
 49.1144 +        operator++();
 49.1145 +        return tmp;
 49.1146 +      }
 49.1147 +
 49.1148 +      /// \e
 49.1149 +      const Value& operator*() const { return it->first; }
 49.1150 +      /// \e
 49.1151 +      const Value* operator->() const { return &(it->first); }
 49.1152 +
 49.1153 +      /// \e
 49.1154 +      bool operator==(ValueIt jt) const { return it == jt.it; }
 49.1155 +      /// \e
 49.1156 +      bool operator!=(ValueIt jt) const { return it != jt.it; }
 49.1157 +
 49.1158 +    private:
 49.1159 +      typename std::map<Value, Key>::const_iterator it;
 49.1160 +    };
 49.1161 +
 49.1162 +    /// \brief Returns an iterator to the first value.
 49.1163 +    ///
 49.1164 +    /// Returns an STL compatible iterator to the
 49.1165 +    /// first value of the map. The values of the
 49.1166 +    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
 49.1167 +    /// range.
 49.1168 +    ValueIt beginValue() const {
 49.1169 +      return ValueIt(_first.begin());
 49.1170 +    }
 49.1171 +
 49.1172 +    /// \brief Returns an iterator after the last value.
 49.1173 +    ///
 49.1174 +    /// Returns an STL compatible iterator after the
 49.1175 +    /// last value of the map. The values of the
 49.1176 +    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
 49.1177 +    /// range.
 49.1178 +    ValueIt endValue() const {
 49.1179 +      return ValueIt(_first.end());
 49.1180 +    }
 49.1181 +
 49.1182 +    /// \brief Set operation of the map.
 49.1183 +    ///
 49.1184 +    /// Set operation of the map.
 49.1185 +    void set(const Key& key, const Value& value) {
 49.1186 +      unlace(key);
 49.1187 +      Parent::operator[](key).value = value;
 49.1188 +      lace(key);
 49.1189 +    }
 49.1190 +
 49.1191 +    /// \brief Const subscript operator of the map.
 49.1192 +    ///
 49.1193 +    /// Const subscript operator of the map.
 49.1194 +    const Value& operator[](const Key& key) const {
 49.1195 +      return Parent::operator[](key).value;
 49.1196 +    }
 49.1197 +
 49.1198 +    /// \brief Iterator for the keys with the same value.
 49.1199 +    ///
 49.1200 +    /// Iterator for the keys with the same value. It works
 49.1201 +    /// like a graph item iterator, it can be converted to
 49.1202 +    /// the item type of the map, incremented with \c ++ operator, and
 49.1203 +    /// if the iterator leaves the last valid item, it will be equal to
 49.1204 +    /// \c INVALID.
 49.1205 +    class ItemIt : public Key {
 49.1206 +    public:
 49.1207 +      typedef Key Parent;
 49.1208 +
 49.1209 +      /// \brief Invalid constructor \& conversion.
 49.1210 +      ///
 49.1211 +      /// This constructor initializes the iterator to be invalid.
 49.1212 +      /// \sa Invalid for more details.
 49.1213 +      ItemIt(Invalid) : Parent(INVALID), _map(0) {}
 49.1214 +
 49.1215 +      /// \brief Creates an iterator with a value.
 49.1216 +      ///
 49.1217 +      /// Creates an iterator with a value. It iterates on the
 49.1218 +      /// keys which have the given value.
 49.1219 +      /// \param map The IterableValueMap
 49.1220 +      /// \param value The value
 49.1221 +      ItemIt(const IterableValueMap& map, const Value& value) : _map(&map) {
 49.1222 +        typename std::map<Value, Key>::const_iterator it =
 49.1223 +          map._first.find(value);
 49.1224 +        if (it == map._first.end()) {
 49.1225 +          Parent::operator=(INVALID);
 49.1226 +        } else {
 49.1227 +          Parent::operator=(it->second);
 49.1228 +        }
 49.1229 +      }
 49.1230 +
 49.1231 +      /// \brief Increment operator.
 49.1232 +      ///
 49.1233 +      /// Increment Operator.
 49.1234 +      ItemIt& operator++() {
 49.1235 +        Parent::operator=(_map->IterableValueMap::Parent::
 49.1236 +                          operator[](static_cast<Parent&>(*this)).next);
 49.1237 +        return *this;
 49.1238 +      }
 49.1239 +
 49.1240 +
 49.1241 +    private:
 49.1242 +      const IterableValueMap* _map;
 49.1243 +    };
 49.1244 +
 49.1245 +  protected:
 49.1246 +
 49.1247 +    virtual void add(const Key& key) {
 49.1248 +      Parent::add(key);
 49.1249 +      unlace(key);
 49.1250 +    }
 49.1251 +
 49.1252 +    virtual void add(const std::vector<Key>& keys) {
 49.1253 +      Parent::add(keys);
 49.1254 +      for (int i = 0; i < int(keys.size()); ++i) {
 49.1255 +        lace(keys[i]);
 49.1256 +      }
 49.1257 +    }
 49.1258 +
 49.1259 +    virtual void erase(const Key& key) {
 49.1260 +      unlace(key);
 49.1261 +      Parent::erase(key);
 49.1262 +    }
 49.1263 +
 49.1264 +    virtual void erase(const std::vector<Key>& keys) {
 49.1265 +      for (int i = 0; i < int(keys.size()); ++i) {
 49.1266 +        unlace(keys[i]);
 49.1267 +      }
 49.1268 +      Parent::erase(keys);
 49.1269 +    }
 49.1270 +
 49.1271 +    virtual void build() {
 49.1272 +      Parent::build();
 49.1273 +      for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
 49.1274 +        lace(it);
 49.1275 +      }
 49.1276 +    }
 49.1277 +
 49.1278 +    virtual void clear() {
 49.1279 +      _first.clear();
 49.1280 +      Parent::clear();
 49.1281 +    }
 49.1282 +
 49.1283 +  private:
 49.1284 +    std::map<Value, Key> _first;
 49.1285 +  };
 49.1286 +
 49.1287    /// \brief Map of the source nodes of arcs in a digraph.
 49.1288    ///
 49.1289    /// SourceMap provides access for the source node of each arc in a digraph,
 49.1290 @@ -2340,9 +3300,9 @@
 49.1291    class SourceMap {
 49.1292    public:
 49.1293  
 49.1294 -    ///\e
 49.1295 +    /// The key type (the \c Arc type of the digraph).
 49.1296      typedef typename GR::Arc Key;
 49.1297 -    ///\e
 49.1298 +    /// The value type (the \c Node type of the digraph).
 49.1299      typedef typename GR::Node Value;
 49.1300  
 49.1301      /// \brief Constructor
 49.1302 @@ -2381,9 +3341,9 @@
 49.1303    class TargetMap {
 49.1304    public:
 49.1305  
 49.1306 -    ///\e
 49.1307 +    /// The key type (the \c Arc type of the digraph).
 49.1308      typedef typename GR::Arc Key;
 49.1309 -    ///\e
 49.1310 +    /// The value type (the \c Node type of the digraph).
 49.1311      typedef typename GR::Node Value;
 49.1312  
 49.1313      /// \brief Constructor
 49.1314 @@ -2423,8 +3383,10 @@
 49.1315    class ForwardMap {
 49.1316    public:
 49.1317  
 49.1318 +    /// The key type (the \c Edge type of the digraph).
 49.1319 +    typedef typename GR::Edge Key;
 49.1320 +    /// The value type (the \c Arc type of the digraph).
 49.1321      typedef typename GR::Arc Value;
 49.1322 -    typedef typename GR::Edge Key;
 49.1323  
 49.1324      /// \brief Constructor
 49.1325      ///
 49.1326 @@ -2463,8 +3425,10 @@
 49.1327    class BackwardMap {
 49.1328    public:
 49.1329  
 49.1330 +    /// The key type (the \c Edge type of the digraph).
 49.1331 +    typedef typename GR::Edge Key;
 49.1332 +    /// The value type (the \c Arc type of the digraph).
 49.1333      typedef typename GR::Arc Value;
 49.1334 -    typedef typename GR::Edge Key;
 49.1335  
 49.1336      /// \brief Constructor
 49.1337      ///
 49.1338 @@ -2499,7 +3463,7 @@
 49.1339    /// in constant time. On the other hand, the values are updated automatically
 49.1340    /// whenever the digraph changes.
 49.1341    ///
 49.1342 -  /// \warning Besides \c addNode() and \c addArc(), a digraph structure 
 49.1343 +  /// \warning Besides \c addNode() and \c addArc(), a digraph structure
 49.1344    /// may provide alternative ways to modify the digraph.
 49.1345    /// The correct behavior of InDegMap is not guarantied if these additional
 49.1346    /// features are used. For example the functions
 49.1347 @@ -2515,7 +3479,7 @@
 49.1348        ::ItemNotifier::ObserverBase {
 49.1349  
 49.1350    public:
 49.1351 -    
 49.1352 +
 49.1353      /// The graph type of InDegMap
 49.1354      typedef GR Graph;
 49.1355      typedef GR Digraph;
 49.1356 @@ -2629,7 +3593,7 @@
 49.1357    /// in constant time. On the other hand, the values are updated automatically
 49.1358    /// whenever the digraph changes.
 49.1359    ///
 49.1360 -  /// \warning Besides \c addNode() and \c addArc(), a digraph structure 
 49.1361 +  /// \warning Besides \c addNode() and \c addArc(), a digraph structure
 49.1362    /// may provide alternative ways to modify the digraph.
 49.1363    /// The correct behavior of OutDegMap is not guarantied if these additional
 49.1364    /// features are used. For example the functions
    50.1 --- a/lemon/min_cost_arborescence.h	Thu Nov 05 10:01:02 2009 +0100
    50.2 +++ b/lemon/min_cost_arborescence.h	Thu Nov 05 10:23:16 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	Thu Nov 05 10:01:02 2009 +0100
    51.2 +++ b/lemon/network_simplex.h	Thu Nov 05 10:23:16 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 @@ -161,8 +163,6 @@
   51.15  
   51.16      TEMPLATE_DIGRAPH_TYPEDEFS(GR);
   51.17  
   51.18 -    typedef std::vector<Arc> ArcVector;
   51.19 -    typedef std::vector<Node> NodeVector;
   51.20      typedef std::vector<int> IntVector;
   51.21      typedef std::vector<bool> BoolVector;
   51.22      typedef std::vector<Value> ValueVector;
   51.23 @@ -364,33 +364,32 @@
   51.24        bool findEnteringArc() {
   51.25          Cost c, min = 0;
   51.26          int cnt = _block_size;
   51.27 -        int e, min_arc = _next_arc;
   51.28 +        int e;
   51.29          for (e = _next_arc; e < _search_arc_num; ++e) {
   51.30            c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
   51.31            if (c < min) {
   51.32              min = c;
   51.33 -            min_arc = e;
   51.34 +            _in_arc = e;
   51.35            }
   51.36            if (--cnt == 0) {
   51.37 -            if (min < 0) break;
   51.38 +            if (min < 0) goto search_end;
   51.39              cnt = _block_size;
   51.40            }
   51.41          }
   51.42 -        if (min == 0 || cnt > 0) {
   51.43 -          for (e = 0; e < _next_arc; ++e) {
   51.44 -            c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
   51.45 -            if (c < min) {
   51.46 -              min = c;
   51.47 -              min_arc = e;
   51.48 -            }
   51.49 -            if (--cnt == 0) {
   51.50 -              if (min < 0) break;
   51.51 -              cnt = _block_size;
   51.52 -            }
   51.53 +        for (e = 0; e < _next_arc; ++e) {
   51.54 +          c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
   51.55 +          if (c < min) {
   51.56 +            min = c;
   51.57 +            _in_arc = e;
   51.58 +          }
   51.59 +          if (--cnt == 0) {
   51.60 +            if (min < 0) goto search_end;
   51.61 +            cnt = _block_size;
   51.62            }
   51.63          }
   51.64          if (min >= 0) return false;
   51.65 -        _in_arc = min_arc;
   51.66 +
   51.67 +      search_end:
   51.68          _next_arc = e;
   51.69          return true;
   51.70        }
   51.71 @@ -428,7 +427,7 @@
   51.72          _next_arc(0)
   51.73        {
   51.74          // The main parameters of the pivot rule
   51.75 -        const double LIST_LENGTH_FACTOR = 1.0;
   51.76 +        const double LIST_LENGTH_FACTOR = 0.25;
   51.77          const int MIN_LIST_LENGTH = 10;
   51.78          const double MINOR_LIMIT_FACTOR = 0.1;
   51.79          const int MIN_MINOR_LIMIT = 3;
   51.80 @@ -445,7 +444,7 @@
   51.81        /// Find next entering arc
   51.82        bool findEnteringArc() {
   51.83          Cost min, c;
   51.84 -        int e, min_arc = _next_arc;
   51.85 +        int e;
   51.86          if (_curr_length > 0 && _minor_count < _minor_limit) {
   51.87            // Minor iteration: select the best eligible arc from the
   51.88            // current candidate list
   51.89 @@ -456,16 +455,13 @@
   51.90              c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
   51.91              if (c < min) {
   51.92                min = c;
   51.93 -              min_arc = e;
   51.94 +              _in_arc = e;
   51.95              }
   51.96 -            if (c >= 0) {
   51.97 +            else if (c >= 0) {
   51.98                _candidates[i--] = _candidates[--_curr_length];
   51.99              }
  51.100            }
  51.101 -          if (min < 0) {
  51.102 -            _in_arc = min_arc;
  51.103 -            return true;
  51.104 -          }
  51.105 +          if (min < 0) return true;
  51.106          }
  51.107  
  51.108          // Major iteration: build a new candidate list
  51.109 @@ -477,27 +473,26 @@
  51.110              _candidates[_curr_length++] = e;
  51.111              if (c < min) {
  51.112                min = c;
  51.113 -              min_arc = e;
  51.114 +              _in_arc = e;
  51.115              }
  51.116 -            if (_curr_length == _list_length) break;
  51.117 +            if (_curr_length == _list_length) goto search_end;
  51.118            }
  51.119          }
  51.120 -        if (_curr_length < _list_length) {
  51.121 -          for (e = 0; e < _next_arc; ++e) {
  51.122 -            c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
  51.123 -            if (c < 0) {
  51.124 -              _candidates[_curr_length++] = e;
  51.125 -              if (c < min) {
  51.126 -                min = c;
  51.127 -                min_arc = e;
  51.128 -              }
  51.129 -              if (_curr_length == _list_length) break;
  51.130 +        for (e = 0; e < _next_arc; ++e) {
  51.131 +          c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
  51.132 +          if (c < 0) {
  51.133 +            _candidates[_curr_length++] = e;
  51.134 +            if (c < min) {
  51.135 +              min = c;
  51.136 +              _in_arc = e;
  51.137              }
  51.138 +            if (_curr_length == _list_length) goto search_end;
  51.139            }
  51.140          }
  51.141          if (_curr_length == 0) return false;
  51.142 +      
  51.143 +      search_end:        
  51.144          _minor_count = 1;
  51.145 -        _in_arc = min_arc;
  51.146          _next_arc = e;
  51.147          return true;
  51.148        }
  51.149 @@ -549,7 +544,7 @@
  51.150          _next_arc(0), _cand_cost(ns._search_arc_num), _sort_func(_cand_cost)
  51.151        {
  51.152          // The main parameters of the pivot rule
  51.153 -        const double BLOCK_SIZE_FACTOR = 1.5;
  51.154 +        const double BLOCK_SIZE_FACTOR = 1.0;
  51.155          const int MIN_BLOCK_SIZE = 10;
  51.156          const double HEAD_LENGTH_FACTOR = 0.1;
  51.157          const int MIN_HEAD_LENGTH = 3;
  51.158 @@ -578,39 +573,35 @@
  51.159  
  51.160          // Extend the list
  51.161          int cnt = _block_size;
  51.162 -        int last_arc = 0;
  51.163          int limit = _head_length;
  51.164  
  51.165 -        for (int e = _next_arc; e < _search_arc_num; ++e) {
  51.166 +        for (e = _next_arc; e < _search_arc_num; ++e) {
  51.167            _cand_cost[e] = _state[e] *
  51.168              (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
  51.169            if (_cand_cost[e] < 0) {
  51.170              _candidates[_curr_length++] = e;
  51.171 -            last_arc = e;
  51.172            }
  51.173            if (--cnt == 0) {
  51.174 -            if (_curr_length > limit) break;
  51.175 +            if (_curr_length > limit) goto search_end;
  51.176              limit = 0;
  51.177              cnt = _block_size;
  51.178            }
  51.179          }
  51.180 -        if (_curr_length <= limit) {
  51.181 -          for (int e = 0; e < _next_arc; ++e) {
  51.182 -            _cand_cost[e] = _state[e] *
  51.183 -              (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
  51.184 -            if (_cand_cost[e] < 0) {
  51.185 -              _candidates[_curr_length++] = e;
  51.186 -              last_arc = e;
  51.187 -            }
  51.188 -            if (--cnt == 0) {
  51.189 -              if (_curr_length > limit) break;
  51.190 -              limit = 0;
  51.191 -              cnt = _block_size;
  51.192 -            }
  51.193 +        for (e = 0; e < _next_arc; ++e) {
  51.194 +          _cand_cost[e] = _state[e] *
  51.195 +            (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
  51.196 +          if (_cand_cost[e] < 0) {
  51.197 +            _candidates[_curr_length++] = e;
  51.198 +          }
  51.199 +          if (--cnt == 0) {
  51.200 +            if (_curr_length > limit) goto search_end;
  51.201 +            limit = 0;
  51.202 +            cnt = _block_size;
  51.203            }
  51.204          }
  51.205          if (_curr_length == 0) return false;
  51.206 -        _next_arc = last_arc + 1;
  51.207 +        
  51.208 +      search_end:
  51.209  
  51.210          // Make heap of the candidate list (approximating a partial sort)
  51.211          make_heap( _candidates.begin(), _candidates.begin() + _curr_length,
  51.212 @@ -618,6 +609,7 @@
  51.213  
  51.214          // Pop the first element of the heap
  51.215          _in_arc = _candidates[0];
  51.216 +        _next_arc = e;
  51.217          pop_heap( _candidates.begin(), _candidates.begin() + _curr_length,
  51.218                    _sort_func );
  51.219          _curr_length = std::min(_head_length, _curr_length - 1);
  51.220 @@ -633,7 +625,11 @@
  51.221      /// The constructor of the class.
  51.222      ///
  51.223      /// \param graph The digraph the algorithm runs on.
  51.224 -    NetworkSimplex(const GR& graph) :
  51.225 +    /// \param arc_mixing Indicate if the arcs have to be stored in a
  51.226 +    /// mixed order in the internal data structure. 
  51.227 +    /// In special cases, it could lead to better overall performance,
  51.228 +    /// but it is usually slower. Therefore it is disabled by default.
  51.229 +    NetworkSimplex(const GR& graph, bool arc_mixing = false) :
  51.230        _graph(graph), _node_id(graph), _arc_id(graph),
  51.231        INF(std::numeric_limits<Value>::has_infinity ?
  51.232            std::numeric_limits<Value>::infinity() :
  51.233 @@ -671,31 +667,33 @@
  51.234        _last_succ.resize(all_node_num);
  51.235        _state.resize(max_arc_num);
  51.236  
  51.237 -      // Copy the graph (store the arcs in a mixed order)
  51.238 +      // Copy the graph
  51.239        int i = 0;
  51.240        for (NodeIt n(_graph); n != INVALID; ++n, ++i) {
  51.241          _node_id[n] = i;
  51.242        }
  51.243 -      int k = std::max(int(std::sqrt(double(_arc_num))), 10);
  51.244 -      i = 0;
  51.245 -      for (ArcIt a(_graph); a != INVALID; ++a) {
  51.246 -        _arc_id[a] = i;
  51.247 -        _source[i] = _node_id[_graph.source(a)];
  51.248 -        _target[i] = _node_id[_graph.target(a)];
  51.249 -        if ((i += k) >= _arc_num) i = (i % k) + 1;
  51.250 +      if (arc_mixing) {
  51.251 +        // Store the arcs in a mixed order
  51.252 +        int k = std::max(int(std::sqrt(double(_arc_num))), 10);
  51.253 +        int i = 0, j = 0;
  51.254 +        for (ArcIt a(_graph); a != INVALID; ++a) {
  51.255 +          _arc_id[a] = i;
  51.256 +          _source[i] = _node_id[_graph.source(a)];
  51.257 +          _target[i] = _node_id[_graph.target(a)];
  51.258 +          if ((i += k) >= _arc_num) i = ++j;
  51.259 +        }
  51.260 +      } else {
  51.261 +        // Store the arcs in the original order
  51.262 +        int i = 0;
  51.263 +        for (ArcIt a(_graph); a != INVALID; ++a, ++i) {
  51.264 +          _arc_id[a] = i;
  51.265 +          _source[i] = _node_id[_graph.source(a)];
  51.266 +          _target[i] = _node_id[_graph.target(a)];
  51.267 +        }
  51.268        }
  51.269        
  51.270 -      // Initialize maps
  51.271 -      for (int i = 0; i != _node_num; ++i) {
  51.272 -        _supply[i] = 0;
  51.273 -      }
  51.274 -      for (int i = 0; i != _arc_num; ++i) {
  51.275 -        _lower[i] = 0;
  51.276 -        _upper[i] = INF;
  51.277 -        _cost[i] = 1;
  51.278 -      }
  51.279 -      _have_lower = false;
  51.280 -      _stype = GEQ;
  51.281 +      // Reset parameters
  51.282 +      reset();
  51.283      }
  51.284  
  51.285      /// \name Parameters
  51.286 @@ -768,7 +766,6 @@
  51.287      /// This function sets the supply values of the nodes.
  51.288      /// If neither this function nor \ref stSupply() is used before
  51.289      /// calling \ref run(), the supply of each node will be set to zero.
  51.290 -    /// (It makes sense only if non-zero lower bounds are given.)
  51.291      ///
  51.292      /// \param map A node map storing the supply values.
  51.293      /// Its \c Value type must be convertible to the \c Value type
  51.294 @@ -789,7 +786,6 @@
  51.295      /// and the required flow value.
  51.296      /// If neither this function nor \ref supplyMap() is used before
  51.297      /// calling \ref run(), the supply of each node will be set to zero.
  51.298 -    /// (It makes sense only if non-zero lower bounds are given.)
  51.299      ///
  51.300      /// Using this function has the same effect as using \ref supplyMap()
  51.301      /// with such a map in which \c k is assigned to \c s, \c -k is
    52.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.2 +++ b/lemon/pairing_heap.h	Thu Nov 05 10:23:16 2009 +0100
    52.3 @@ -0,0 +1,474 @@
    52.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
    52.5 + *
    52.6 + * This file is a part of LEMON, a generic C++ optimization library.
    52.7 + *
    52.8 + * Copyright (C) 2003-2009
    52.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   52.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
   52.11 + *
   52.12 + * Permission to use, modify and distribute this software is granted
   52.13 + * provided that this copyright notice appears in all copies. For
   52.14 + * precise terms see the accompanying LICENSE file.
   52.15 + *
   52.16 + * This software is provided "AS IS" with no warranty of any kind,
   52.17 + * express or implied, and with no claim as to its suitability for any
   52.18 + * purpose.
   52.19 + *
   52.20 + */
   52.21 +
   52.22 +#ifndef LEMON_PAIRING_HEAP_H
   52.23 +#define LEMON_PAIRING_HEAP_H
   52.24 +
   52.25 +///\file
   52.26 +///\ingroup heaps
   52.27 +///\brief Pairing heap implementation.
   52.28 +
   52.29 +#include <vector>
   52.30 +#include <utility>
   52.31 +#include <functional>
   52.32 +#include <lemon/math.h>
   52.33 +
   52.34 +namespace lemon {
   52.35 +
   52.36 +  /// \ingroup heaps
   52.37 +  ///
   52.38 +  ///\brief Pairing Heap.
   52.39 +  ///
   52.40 +  /// This class implements the \e pairing \e heap data structure.
   52.41 +  /// It fully conforms to the \ref concepts::Heap "heap concept".
   52.42 +  ///
   52.43 +  /// The methods \ref increase() and \ref erase() are not efficient
   52.44 +  /// in a pairing heap. In case of many calls of these operations,
   52.45 +  /// it is better to use other heap structure, e.g. \ref BinHeap
   52.46 +  /// "binary heap".
   52.47 +  ///
   52.48 +  /// \tparam PR Type of the priorities of the items.
   52.49 +  /// \tparam IM A read-writable item map with \c int values, used
   52.50 +  /// internally to handle the cross references.
   52.51 +  /// \tparam CMP A functor class for comparing the priorities.
   52.52 +  /// The default is \c std::less<PR>.
   52.53 +#ifdef DOXYGEN
   52.54 +  template <typename PR, typename IM, typename CMP>
   52.55 +#else
   52.56 +  template <typename PR, typename IM, typename CMP = std::less<PR> >
   52.57 +#endif
   52.58 +  class PairingHeap {
   52.59 +  public:
   52.60 +    /// Type of the item-int map.
   52.61 +    typedef IM ItemIntMap;
   52.62 +    /// Type of the priorities.
   52.63 +    typedef PR Prio;
   52.64 +    /// Type of the items stored in the heap.
   52.65 +    typedef typename ItemIntMap::Key Item;
   52.66 +    /// Functor type for comparing the priorities.
   52.67 +    typedef CMP Compare;
   52.68 +
   52.69 +    /// \brief Type to represent the states of the items.
   52.70 +    ///
   52.71 +    /// Each item has a state associated to it. It can be "in heap",
   52.72 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
   52.73 +    /// heap's point of view, but may be useful to the user.
   52.74 +    ///
   52.75 +    /// The item-int map must be initialized in such way that it assigns
   52.76 +    /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
   52.77 +    enum State {
   52.78 +      IN_HEAP = 0,    ///< = 0.
   52.79 +      PRE_HEAP = -1,  ///< = -1.
   52.80 +      POST_HEAP = -2  ///< = -2.
   52.81 +    };
   52.82 +
   52.83 +  private:
   52.84 +    class store;
   52.85 +
   52.86 +    std::vector<store> _data;
   52.87 +    int _min;
   52.88 +    ItemIntMap &_iim;
   52.89 +    Compare _comp;
   52.90 +    int _num_items;
   52.91 +
   52.92 +  public:
   52.93 +    /// \brief Constructor.
   52.94 +    ///
   52.95 +    /// Constructor.
   52.96 +    /// \param map A map that assigns \c int values to the items.
   52.97 +    /// It is used internally to handle the cross references.
   52.98 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
   52.99 +    explicit PairingHeap(ItemIntMap &map)
  52.100 +      : _min(0), _iim(map), _num_items(0) {}
  52.101 +
  52.102 +    /// \brief Constructor.
  52.103 +    ///
  52.104 +    /// Constructor.
  52.105 +    /// \param map A map that assigns \c int values to the items.
  52.106 +    /// It is used internally to handle the cross references.
  52.107 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  52.108 +    /// \param comp The function object used for comparing the priorities.
  52.109 +    PairingHeap(ItemIntMap &map, const Compare &comp)
  52.110 +      : _min(0), _iim(map), _comp(comp), _num_items(0) {}
  52.111 +
  52.112 +    /// \brief The number of items stored in the heap.
  52.113 +    ///
  52.114 +    /// This function returns the number of items stored in the heap.
  52.115 +    int size() const { return _num_items; }
  52.116 +
  52.117 +    /// \brief Check if the heap is empty.
  52.118 +    ///
  52.119 +    /// This function returns \c true if the heap is empty.
  52.120 +    bool empty() const { return _num_items==0; }
  52.121 +
  52.122 +    /// \brief Make the heap empty.
  52.123 +    ///
  52.124 +    /// This functon makes the heap empty.
  52.125 +    /// It does not change the cross reference map. If you want to reuse
  52.126 +    /// a heap that is not surely empty, you should first clear it and
  52.127 +    /// then you should set the cross reference map to \c PRE_HEAP
  52.128 +    /// for each item.
  52.129 +    void clear() {
  52.130 +      _data.clear();
  52.131 +      _min = 0;
  52.132 +      _num_items = 0;
  52.133 +    }
  52.134 +
  52.135 +    /// \brief Set the priority of an item or insert it, if it is
  52.136 +    /// not stored in the heap.
  52.137 +    ///
  52.138 +    /// This method sets the priority of the given item if it is
  52.139 +    /// already stored in the heap. Otherwise it inserts the given
  52.140 +    /// item into the heap with the given priority.
  52.141 +    /// \param item The item.
  52.142 +    /// \param value The priority.
  52.143 +    void set (const Item& item, const Prio& value) {
  52.144 +      int i=_iim[item];
  52.145 +      if ( i>=0 && _data[i].in ) {
  52.146 +        if ( _comp(value, _data[i].prio) ) decrease(item, value);
  52.147 +        if ( _comp(_data[i].prio, value) ) increase(item, value);
  52.148 +      } else push(item, value);
  52.149 +    }
  52.150 +
  52.151 +    /// \brief Insert an item into the heap with the given priority.
  52.152 +    ///
  52.153 +    /// This function inserts the given item into the heap with the
  52.154 +    /// given priority.
  52.155 +    /// \param item The item to insert.
  52.156 +    /// \param value The priority of the item.
  52.157 +    /// \pre \e item must not be stored in the heap.
  52.158 +    void push (const Item& item, const Prio& value) {
  52.159 +      int i=_iim[item];
  52.160 +      if( i<0 ) {
  52.161 +        int s=_data.size();
  52.162 +        _iim.set(item, s);
  52.163 +        store st;
  52.164 +        st.name=item;
  52.165 +        _data.push_back(st);
  52.166 +        i=s;
  52.167 +      } else {
  52.168 +        _data[i].parent=_data[i].child=-1;
  52.169 +        _data[i].left_child=false;
  52.170 +        _data[i].degree=0;
  52.171 +        _data[i].in=true;
  52.172 +      }
  52.173 +
  52.174 +      _data[i].prio=value;
  52.175 +
  52.176 +      if ( _num_items!=0 ) {
  52.177 +        if ( _comp( value, _data[_min].prio) ) {
  52.178 +          fuse(i,_min);
  52.179 +          _min=i;
  52.180 +        }
  52.181 +        else fuse(_min,i);
  52.182 +      }
  52.183 +      else _min=i;
  52.184 +
  52.185 +      ++_num_items;
  52.186 +    }
  52.187 +
  52.188 +    /// \brief Return the item having minimum priority.
  52.189 +    ///
  52.190 +    /// This function returns the item having minimum priority.
  52.191 +    /// \pre The heap must be non-empty.
  52.192 +    Item top() const { return _data[_min].name; }
  52.193 +
  52.194 +    /// \brief The minimum priority.
  52.195 +    ///
  52.196 +    /// This function returns the minimum priority.
  52.197 +    /// \pre The heap must be non-empty.
  52.198 +    const Prio& prio() const { return _data[_min].prio; }
  52.199 +
  52.200 +    /// \brief The priority of the given item.
  52.201 +    ///
  52.202 +    /// This function returns the priority of the given item.
  52.203 +    /// \param item The item.
  52.204 +    /// \pre \e item must be in the heap.
  52.205 +    const Prio& operator[](const Item& item) const {
  52.206 +      return _data[_iim[item]].prio;
  52.207 +    }
  52.208 +
  52.209 +    /// \brief Remove the item having minimum priority.
  52.210 +    ///
  52.211 +    /// This function removes the item having minimum priority.
  52.212 +    /// \pre The heap must be non-empty.
  52.213 +    void pop() {
  52.214 +      std::vector<int> trees;
  52.215 +      int i=0, child_right = 0;
  52.216 +      _data[_min].in=false;
  52.217 +
  52.218 +      if( -1!=_data[_min].child ) {
  52.219 +        i=_data[_min].child;
  52.220 +        trees.push_back(i);
  52.221 +        _data[i].parent = -1;
  52.222 +        _data[_min].child = -1;
  52.223 +
  52.224 +        int ch=-1;
  52.225 +        while( _data[i].child!=-1 ) {
  52.226 +          ch=_data[i].child;
  52.227 +          if( _data[ch].left_child && i==_data[ch].parent ) {
  52.228 +            break;
  52.229 +          } else {
  52.230 +            if( _data[ch].left_child ) {
  52.231 +              child_right=_data[ch].parent;
  52.232 +              _data[ch].parent = i;
  52.233 +              --_data[i].degree;
  52.234 +            }
  52.235 +            else {
  52.236 +              child_right=ch;
  52.237 +              _data[i].child=-1;
  52.238 +              _data[i].degree=0;
  52.239 +            }
  52.240 +            _data[child_right].parent = -1;
  52.241 +            trees.push_back(child_right);
  52.242 +            i = child_right;
  52.243 +          }
  52.244 +        }
  52.245 +
  52.246 +        int num_child = trees.size();
  52.247 +        int other;
  52.248 +        for( i=0; i<num_child-1; i+=2 ) {
  52.249 +          if ( !_comp(_data[trees[i]].prio, _data[trees[i+1]].prio) ) {
  52.250 +            other=trees[i];
  52.251 +            trees[i]=trees[i+1];
  52.252 +            trees[i+1]=other;
  52.253 +          }
  52.254 +          fuse( trees[i], trees[i+1] );
  52.255 +        }
  52.256 +
  52.257 +        i = (0==(num_child % 2)) ? num_child-2 : num_child-1;
  52.258 +        while(i>=2) {
  52.259 +          if ( _comp(_data[trees[i]].prio, _data[trees[i-2]].prio) ) {
  52.260 +            other=trees[i];
  52.261 +            trees[i]=trees[i-2];
  52.262 +            trees[i-2]=other;
  52.263 +          }
  52.264 +          fuse( trees[i-2], trees[i] );
  52.265 +          i-=2;
  52.266 +        }
  52.267 +        _min = trees[0];
  52.268 +      }
  52.269 +      else {
  52.270 +        _min = _data[_min].child;
  52.271 +      }
  52.272 +
  52.273 +      if (_min >= 0) _data[_min].left_child = false;
  52.274 +      --_num_items;
  52.275 +    }
  52.276 +
  52.277 +    /// \brief Remove the given item from the heap.
  52.278 +    ///
  52.279 +    /// This function removes the given item from the heap if it is
  52.280 +    /// already stored.
  52.281 +    /// \param item The item to delete.
  52.282 +    /// \pre \e item must be in the heap.
  52.283 +    void erase (const Item& item) {
  52.284 +      int i=_iim[item];
  52.285 +      if ( i>=0 && _data[i].in ) {
  52.286 +        decrease( item, _data[_min].prio-1 );
  52.287 +        pop();
  52.288 +      }
  52.289 +    }
  52.290 +
  52.291 +    /// \brief Decrease the priority of an item to the given value.
  52.292 +    ///
  52.293 +    /// This function decreases the priority of an item to the given value.
  52.294 +    /// \param item The item.
  52.295 +    /// \param value The priority.
  52.296 +    /// \pre \e item must be stored in the heap with priority at least \e value.
  52.297 +    void decrease (Item item, const Prio& value) {
  52.298 +      int i=_iim[item];
  52.299 +      _data[i].prio=value;
  52.300 +      int p=_data[i].parent;
  52.301 +
  52.302 +      if( _data[i].left_child && i!=_data[p].child ) {
  52.303 +        p=_data[p].parent;
  52.304 +      }
  52.305 +
  52.306 +      if ( p!=-1 && _comp(value,_data[p].prio) ) {
  52.307 +        cut(i,p);
  52.308 +        if ( _comp(_data[_min].prio,value) ) {
  52.309 +          fuse(_min,i);
  52.310 +        } else {
  52.311 +          fuse(i,_min);
  52.312 +          _min=i;
  52.313 +        }
  52.314 +      }
  52.315 +    }
  52.316 +
  52.317 +    /// \brief Increase the priority of an item to the given value.
  52.318 +    ///
  52.319 +    /// This function increases the priority of an item to the given value.
  52.320 +    /// \param item The item.
  52.321 +    /// \param value The priority.
  52.322 +    /// \pre \e item must be stored in the heap with priority at most \e value.
  52.323 +    void increase (Item item, const Prio& value) {
  52.324 +      erase(item);
  52.325 +      push(item,value);
  52.326 +    }
  52.327 +
  52.328 +    /// \brief Return the state of an item.
  52.329 +    ///
  52.330 +    /// This method returns \c PRE_HEAP if the given item has never
  52.331 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  52.332 +    /// and \c POST_HEAP otherwise.
  52.333 +    /// In the latter case it is possible that the item will get back
  52.334 +    /// to the heap again.
  52.335 +    /// \param item The item.
  52.336 +    State state(const Item &item) const {
  52.337 +      int i=_iim[item];
  52.338 +      if( i>=0 ) {
  52.339 +        if( _data[i].in ) i=0;
  52.340 +        else i=-2;
  52.341 +      }
  52.342 +      return State(i);
  52.343 +    }
  52.344 +
  52.345 +    /// \brief Set the state of an item in the heap.
  52.346 +    ///
  52.347 +    /// This function sets the state of the given item in the heap.
  52.348 +    /// It can be used to manually clear the heap when it is important
  52.349 +    /// to achive better time complexity.
  52.350 +    /// \param i The item.
  52.351 +    /// \param st The state. It should not be \c IN_HEAP.
  52.352 +    void state(const Item& i, State st) {
  52.353 +      switch (st) {
  52.354 +      case POST_HEAP:
  52.355 +      case PRE_HEAP:
  52.356 +        if (state(i) == IN_HEAP) erase(i);
  52.357 +        _iim[i]=st;
  52.358 +        break;
  52.359 +      case IN_HEAP:
  52.360 +        break;
  52.361 +      }
  52.362 +    }
  52.363 +
  52.364 +  private:
  52.365 +
  52.366 +    void cut(int a, int b) {
  52.367 +      int child_a;
  52.368 +      switch (_data[a].degree) {
  52.369 +        case 2:
  52.370 +          child_a = _data[_data[a].child].parent;
  52.371 +          if( _data[a].left_child ) {
  52.372 +            _data[child_a].left_child=true;
  52.373 +            _data[b].child=child_a;
  52.374 +            _data[child_a].parent=_data[a].parent;
  52.375 +          }
  52.376 +          else {
  52.377 +            _data[child_a].left_child=false;
  52.378 +            _data[child_a].parent=b;
  52.379 +            if( a!=_data[b].child )
  52.380 +              _data[_data[b].child].parent=child_a;
  52.381 +            else
  52.382 +              _data[b].child=child_a;
  52.383 +          }
  52.384 +          --_data[a].degree;
  52.385 +          _data[_data[a].child].parent=a;
  52.386 +          break;
  52.387 +
  52.388 +        case 1:
  52.389 +          child_a = _data[a].child;
  52.390 +          if( !_data[child_a].left_child ) {
  52.391 +            --_data[a].degree;
  52.392 +            if( _data[a].left_child ) {
  52.393 +              _data[child_a].left_child=true;
  52.394 +              _data[child_a].parent=_data[a].parent;
  52.395 +              _data[b].child=child_a;
  52.396 +            }
  52.397 +            else {
  52.398 +              _data[child_a].left_child=false;
  52.399 +              _data[child_a].parent=b;
  52.400 +              if( a!=_data[b].child )
  52.401 +                _data[_data[b].child].parent=child_a;
  52.402 +              else
  52.403 +                _data[b].child=child_a;
  52.404 +            }
  52.405 +            _data[a].child=-1;
  52.406 +          }
  52.407 +          else {
  52.408 +            --_data[b].degree;
  52.409 +            if( _data[a].left_child ) {
  52.410 +              _data[b].child =
  52.411 +                (1==_data[b].degree) ? _data[a].parent : -1;
  52.412 +            } else {
  52.413 +              if (1==_data[b].degree)
  52.414 +                _data[_data[b].child].parent=b;
  52.415 +              else
  52.416 +                _data[b].child=-1;
  52.417 +            }
  52.418 +          }
  52.419 +          break;
  52.420 +
  52.421 +        case 0:
  52.422 +          --_data[b].degree;
  52.423 +          if( _data[a].left_child ) {
  52.424 +            _data[b].child =
  52.425 +              (0!=_data[b].degree) ? _data[a].parent : -1;
  52.426 +          } else {
  52.427 +            if( 0!=_data[b].degree )
  52.428 +              _data[_data[b].child].parent=b;
  52.429 +            else
  52.430 +              _data[b].child=-1;
  52.431 +          }
  52.432 +          break;
  52.433 +      }
  52.434 +      _data[a].parent=-1;
  52.435 +      _data[a].left_child=false;
  52.436 +    }
  52.437 +
  52.438 +    void fuse(int a, int b) {
  52.439 +      int child_a = _data[a].child;
  52.440 +      int child_b = _data[b].child;
  52.441 +      _data[a].child=b;
  52.442 +      _data[b].parent=a;
  52.443 +      _data[b].left_child=true;
  52.444 +
  52.445 +      if( -1!=child_a ) {
  52.446 +        _data[b].child=child_a;
  52.447 +        _data[child_a].parent=b;
  52.448 +        _data[child_a].left_child=false;
  52.449 +        ++_data[b].degree;
  52.450 +
  52.451 +        if( -1!=child_b ) {
  52.452 +           _data[b].child=child_b;
  52.453 +           _data[child_b].parent=child_a;
  52.454 +        }
  52.455 +      }
  52.456 +      else { ++_data[a].degree; }
  52.457 +    }
  52.458 +
  52.459 +    class store {
  52.460 +      friend class PairingHeap;
  52.461 +
  52.462 +      Item name;
  52.463 +      int parent;
  52.464 +      int child;
  52.465 +      bool left_child;
  52.466 +      int degree;
  52.467 +      bool in;
  52.468 +      Prio prio;
  52.469 +
  52.470 +      store() : parent(-1), child(-1), left_child(false), degree(0), in(true) {}
  52.471 +    };
  52.472 +  };
  52.473 +
  52.474 +} //namespace lemon
  52.475 +
  52.476 +#endif //LEMON_PAIRING_HEAP_H
  52.477 +
    53.1 --- a/lemon/path.h	Thu Nov 05 10:01:02 2009 +0100
    53.2 +++ b/lemon/path.h	Thu Nov 05 10:23:16 2009 +0100
    53.3 @@ -1015,18 +1015,20 @@
    53.4  
    53.5    /// \brief The source of a path
    53.6    ///
    53.7 -  /// This function returns the source of the given path.
    53.8 +  /// This function returns the source node of the given path.
    53.9 +  /// If the path is empty, then it returns \c INVALID.
   53.10    template <typename Digraph, typename Path>
   53.11    typename Digraph::Node pathSource(const Digraph& digraph, const Path& path) {
   53.12 -    return digraph.source(path.front());
   53.13 +    return path.empty() ? INVALID : digraph.source(path.front());
   53.14    }
   53.15  
   53.16    /// \brief The target of a path
   53.17    ///
   53.18 -  /// This function returns the target of the given path.
   53.19 +  /// This function returns the target node of the given path.
   53.20 +  /// If the path is empty, then it returns \c INVALID.
   53.21    template <typename Digraph, typename Path>
   53.22    typename Digraph::Node pathTarget(const Digraph& digraph, const Path& path) {
   53.23 -    return digraph.target(path.back());
   53.24 +    return path.empty() ? INVALID : digraph.target(path.back());
   53.25    }
   53.26  
   53.27    /// \brief Class which helps to iterate through the nodes of a path
    54.1 --- a/lemon/preflow.h	Thu Nov 05 10:01:02 2009 +0100
    54.2 +++ b/lemon/preflow.h	Thu Nov 05 10:23:16 2009 +0100
    54.3 @@ -52,7 +52,11 @@
    54.4      ///
    54.5      /// The type of the map that stores the flow values.
    54.6      /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    54.7 +#ifdef DOXYGEN
    54.8 +    typedef GR::ArcMap<Value> FlowMap;
    54.9 +#else
   54.10      typedef typename Digraph::template ArcMap<Value> FlowMap;
   54.11 +#endif
   54.12  
   54.13      /// \brief Instantiates a FlowMap.
   54.14      ///
   54.15 @@ -67,9 +71,12 @@
   54.16      ///
   54.17      /// The elevator type used by Preflow algorithm.
   54.18      ///
   54.19 -    /// \sa Elevator
   54.20 -    /// \sa LinkedElevator
   54.21 -    typedef LinkedElevator<Digraph, typename Digraph::Node> Elevator;
   54.22 +    /// \sa Elevator, LinkedElevator
   54.23 +#ifdef DOXYGEN
   54.24 +    typedef lemon::Elevator<GR, GR::Node> Elevator;
   54.25 +#else
   54.26 +    typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator;
   54.27 +#endif
   54.28  
   54.29      /// \brief Instantiates an Elevator.
   54.30      ///
   54.31 @@ -95,9 +102,10 @@
   54.32    ///
   54.33    /// This class provides an implementation of Goldberg-Tarjan's \e preflow
   54.34    /// \e push-relabel algorithm producing a \ref max_flow
   54.35 -  /// "flow of maximum value" in a digraph.
   54.36 +  /// "flow of maximum value" in a digraph \ref clrs01algorithms,
   54.37 +  /// \ref amo93networkflows, \ref goldberg88newapproach.
   54.38    /// The preflow algorithms are the fastest known maximum
   54.39 -  /// flow algorithms. The current implementation use a mixture of the
   54.40 +  /// flow algorithms. The current implementation uses a mixture of the
   54.41    /// \e "highest label" and the \e "bound decrease" heuristics.
   54.42    /// The worst case time complexity of the algorithm is \f$O(n^2\sqrt{e})\f$.
   54.43    ///
   54.44 @@ -371,26 +379,28 @@
   54.45        return *_level;
   54.46      }
   54.47  
   54.48 -    /// \brief Sets the tolerance used by algorithm.
   54.49 +    /// \brief Sets the tolerance used by the algorithm.
   54.50      ///
   54.51 -    /// Sets the tolerance used by algorithm.
   54.52 -    Preflow& tolerance(const Tolerance& tolerance) const {
   54.53 +    /// Sets the tolerance object used by the algorithm.
   54.54 +    /// \return <tt>(*this)</tt>
   54.55 +    Preflow& tolerance(const Tolerance& tolerance) {
   54.56        _tolerance = tolerance;
   54.57        return *this;
   54.58      }
   54.59  
   54.60      /// \brief Returns a const reference to the tolerance.
   54.61      ///
   54.62 -    /// Returns a const reference to the tolerance.
   54.63 +    /// Returns a const reference to the tolerance object used by
   54.64 +    /// the algorithm.
   54.65      const Tolerance& tolerance() const {
   54.66 -      return tolerance;
   54.67 +      return _tolerance;
   54.68      }
   54.69  
   54.70      /// \name Execution Control
   54.71      /// The simplest way to execute the preflow algorithm is to use
   54.72      /// \ref run() or \ref runMinCut().\n
   54.73 -    /// If you need more control on the initial solution or the execution,
   54.74 -    /// first you have to call one of the \ref init() functions, then
   54.75 +    /// If you need better control on the initial solution or the execution,
   54.76 +    /// you have to call one of the \ref init() functions first, then
   54.77      /// \ref startFirstPhase() and if you need it \ref startSecondPhase().
   54.78  
   54.79      ///@{
    55.1 --- a/lemon/radix_heap.h	Thu Nov 05 10:01:02 2009 +0100
    55.2 +++ b/lemon/radix_heap.h	Thu Nov 05 10:23:16 2009 +0100
    55.3 @@ -19,9 +19,9 @@
    55.4  #ifndef LEMON_RADIX_HEAP_H
    55.5  #define LEMON_RADIX_HEAP_H
    55.6  
    55.7 -///\ingroup auxdat
    55.8 +///\ingroup heaps
    55.9  ///\file
   55.10 -///\brief Radix Heap implementation.
   55.11 +///\brief Radix heap implementation.
   55.12  
   55.13  #include <vector>
   55.14  #include <lemon/error.h>
   55.15 @@ -29,56 +29,54 @@
   55.16  namespace lemon {
   55.17  
   55.18  
   55.19 -  /// \ingroup auxdata
   55.20 +  /// \ingroup heaps
   55.21    ///
   55.22 -  /// \brief A Radix Heap implementation.
   55.23 +  /// \brief Radix heap data structure.
   55.24    ///
   55.25 -  /// This class implements the \e radix \e heap data structure. A \e heap
   55.26 -  /// is a data structure for storing items with specified values called \e
   55.27 -  /// priorities in such a way that finding the item with minimum priority is
   55.28 -  /// efficient. This heap type can store only items with \e int priority.
   55.29 -  /// In a heap one can change the priority of an item, add or erase an
   55.30 -  /// item, but the priority cannot be decreased under the last removed
   55.31 -  /// item's priority.
   55.32 +  /// This class implements the \e radix \e heap data structure.
   55.33 +  /// It practically conforms to the \ref concepts::Heap "heap concept",
   55.34 +  /// but it has some limitations due its special implementation.
   55.35 +  /// The type of the priorities must be \c int and the priority of an
   55.36 +  /// item cannot be decreased under the priority of the last removed item.
   55.37    ///
   55.38 -  /// \param IM A read and writable Item int map, used internally
   55.39 -  /// to handle the cross references.
   55.40 -  ///
   55.41 -  /// \see BinHeap
   55.42 -  /// \see Dijkstra
   55.43 +  /// \tparam IM A read-writable item map with \c int values, used
   55.44 +  /// internally to handle the cross references.
   55.45    template <typename IM>
   55.46    class RadixHeap {
   55.47  
   55.48    public:
   55.49 -    typedef typename IM::Key Item;
   55.50 +
   55.51 +    /// Type of the item-int map.
   55.52 +    typedef IM ItemIntMap;
   55.53 +    /// Type of the priorities.
   55.54      typedef int Prio;
   55.55 -    typedef IM ItemIntMap;
   55.56 +    /// Type of the items stored in the heap.
   55.57 +    typedef typename ItemIntMap::Key Item;
   55.58  
   55.59      /// \brief Exception thrown by RadixHeap.
   55.60      ///
   55.61 -    /// This Exception is thrown when a smaller priority
   55.62 -    /// is inserted into the \e RadixHeap then the last time erased.
   55.63 +    /// This exception is thrown when an item is inserted into a
   55.64 +    /// RadixHeap with a priority smaller than the last erased one.
   55.65      /// \see RadixHeap
   55.66 -
   55.67 -    class UnderFlowPriorityError : public Exception {
   55.68 +    class PriorityUnderflowError : public Exception {
   55.69      public:
   55.70        virtual const char* what() const throw() {
   55.71 -        return "lemon::RadixHeap::UnderFlowPriorityError";
   55.72 +        return "lemon::RadixHeap::PriorityUnderflowError";
   55.73        }
   55.74      };
   55.75  
   55.76 -    /// \brief Type to represent the items states.
   55.77 +    /// \brief Type to represent the states of the items.
   55.78      ///
   55.79 -    /// Each Item element have a state associated to it. It may be "in heap",
   55.80 -    /// "pre heap" or "post heap". The latter two are indifferent from the
   55.81 +    /// Each item has a state associated to it. It can be "in heap",
   55.82 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
   55.83      /// heap's point of view, but may be useful to the user.
   55.84      ///
   55.85 -    /// The ItemIntMap \e should be initialized in such way that it maps
   55.86 -    /// PRE_HEAP (-1) to any element to be put in the heap...
   55.87 +    /// The item-int map must be initialized in such way that it assigns
   55.88 +    /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
   55.89      enum State {
   55.90 -      IN_HEAP = 0,
   55.91 -      PRE_HEAP = -1,
   55.92 -      POST_HEAP = -2
   55.93 +      IN_HEAP = 0,    ///< = 0.
   55.94 +      PRE_HEAP = -1,  ///< = -1.
   55.95 +      POST_HEAP = -2  ///< = -2.
   55.96      };
   55.97  
   55.98    private:
   55.99 @@ -96,52 +94,55 @@
  55.100        RadixBox(int _min, int _size) : first(-1), min(_min), size(_size) {}
  55.101      };
  55.102  
  55.103 -    std::vector<RadixItem> data;
  55.104 -    std::vector<RadixBox> boxes;
  55.105 +    std::vector<RadixItem> _data;
  55.106 +    std::vector<RadixBox> _boxes;
  55.107  
  55.108      ItemIntMap &_iim;
  55.109  
  55.110 +  public:
  55.111  
  55.112 -  public:
  55.113 -    /// \brief The constructor.
  55.114 +    /// \brief Constructor.
  55.115      ///
  55.116 -    /// The constructor.
  55.117 -    ///
  55.118 -    /// \param map It should be given to the constructor, since it is used
  55.119 -    /// internally to handle the cross references. The value of the map
  55.120 -    /// should be PRE_HEAP (-1) for each element.
  55.121 -    ///
  55.122 -    /// \param minimal The initial minimal value of the heap.
  55.123 -    /// \param capacity It determines the initial capacity of the heap.
  55.124 -    RadixHeap(ItemIntMap &map, int minimal = 0, int capacity = 0)
  55.125 -      : _iim(map) {
  55.126 -      boxes.push_back(RadixBox(minimal, 1));
  55.127 -      boxes.push_back(RadixBox(minimal + 1, 1));
  55.128 -      while (lower(boxes.size() - 1, capacity + minimal - 1)) {
  55.129 +    /// Constructor.
  55.130 +    /// \param map A map that assigns \c int values to the items.
  55.131 +    /// It is used internally to handle the cross references.
  55.132 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  55.133 +    /// \param minimum The initial minimum value of the heap.
  55.134 +    /// \param capacity The initial capacity of the heap.
  55.135 +    RadixHeap(ItemIntMap &map, int minimum = 0, int capacity = 0)
  55.136 +      : _iim(map)
  55.137 +    {
  55.138 +      _boxes.push_back(RadixBox(minimum, 1));
  55.139 +      _boxes.push_back(RadixBox(minimum + 1, 1));
  55.140 +      while (lower(_boxes.size() - 1, capacity + minimum - 1)) {
  55.141          extend();
  55.142        }
  55.143      }
  55.144  
  55.145 -    /// The number of items stored in the heap.
  55.146 +    /// \brief The number of items stored in the heap.
  55.147      ///
  55.148 -    /// \brief Returns the number of items stored in the heap.
  55.149 -    int size() const { return data.size(); }
  55.150 -    /// \brief Checks if the heap stores no items.
  55.151 +    /// This function returns the number of items stored in the heap.
  55.152 +    int size() const { return _data.size(); }
  55.153 +
  55.154 +    /// \brief Check if the heap is empty.
  55.155      ///
  55.156 -    /// Returns \c true if and only if the heap stores no items.
  55.157 -    bool empty() const { return data.empty(); }
  55.158 +    /// This function returns \c true if the heap is empty.
  55.159 +    bool empty() const { return _data.empty(); }
  55.160  
  55.161 -    /// \brief Make empty this heap.
  55.162 +    /// \brief Make the heap empty.
  55.163      ///
  55.164 -    /// Make empty this heap. It does not change the cross reference
  55.165 -    /// map.  If you want to reuse a heap what is not surely empty you
  55.166 -    /// should first clear the heap and after that you should set the
  55.167 -    /// cross reference map for each item to \c PRE_HEAP.
  55.168 -    void clear(int minimal = 0, int capacity = 0) {
  55.169 -      data.clear(); boxes.clear();
  55.170 -      boxes.push_back(RadixBox(minimal, 1));
  55.171 -      boxes.push_back(RadixBox(minimal + 1, 1));
  55.172 -      while (lower(boxes.size() - 1, capacity + minimal - 1)) {
  55.173 +    /// This functon makes the heap empty.
  55.174 +    /// It does not change the cross reference map. If you want to reuse
  55.175 +    /// a heap that is not surely empty, you should first clear it and
  55.176 +    /// then you should set the cross reference map to \c PRE_HEAP
  55.177 +    /// for each item.
  55.178 +    /// \param minimum The minimum value of the heap.
  55.179 +    /// \param capacity The capacity of the heap.
  55.180 +    void clear(int minimum = 0, int capacity = 0) {
  55.181 +      _data.clear(); _boxes.clear();
  55.182 +      _boxes.push_back(RadixBox(minimum, 1));
  55.183 +      _boxes.push_back(RadixBox(minimum + 1, 1));
  55.184 +      while (lower(_boxes.size() - 1, capacity + minimum - 1)) {
  55.185          extend();
  55.186        }
  55.187      }
  55.188 @@ -149,255 +150,259 @@
  55.189    private:
  55.190  
  55.191      bool upper(int box, Prio pr) {
  55.192 -      return pr < boxes[box].min;
  55.193 +      return pr < _boxes[box].min;
  55.194      }
  55.195  
  55.196      bool lower(int box, Prio pr) {
  55.197 -      return pr >= boxes[box].min + boxes[box].size;
  55.198 +      return pr >= _boxes[box].min + _boxes[box].size;
  55.199      }
  55.200  
  55.201 -    /// \brief Remove item from the box list.
  55.202 +    // Remove item from the box list
  55.203      void remove(int index) {
  55.204 -      if (data[index].prev >= 0) {
  55.205 -        data[data[index].prev].next = data[index].next;
  55.206 +      if (_data[index].prev >= 0) {
  55.207 +        _data[_data[index].prev].next = _data[index].next;
  55.208        } else {
  55.209 -        boxes[data[index].box].first = data[index].next;
  55.210 +        _boxes[_data[index].box].first = _data[index].next;
  55.211        }
  55.212 -      if (data[index].next >= 0) {
  55.213 -        data[data[index].next].prev = data[index].prev;
  55.214 +      if (_data[index].next >= 0) {
  55.215 +        _data[_data[index].next].prev = _data[index].prev;
  55.216        }
  55.217      }
  55.218  
  55.219 -    /// \brief Insert item into the box list.
  55.220 +    // Insert item into the box list
  55.221      void insert(int box, int index) {
  55.222 -      if (boxes[box].first == -1) {
  55.223 -        boxes[box].first = index;
  55.224 -        data[index].next = data[index].prev = -1;
  55.225 +      if (_boxes[box].first == -1) {
  55.226 +        _boxes[box].first = index;
  55.227 +        _data[index].next = _data[index].prev = -1;
  55.228        } else {
  55.229 -        data[index].next = boxes[box].first;
  55.230 -        data[boxes[box].first].prev = index;
  55.231 -        data[index].prev = -1;
  55.232 -        boxes[box].first = index;
  55.233 +        _data[index].next = _boxes[box].first;
  55.234 +        _data[_boxes[box].first].prev = index;
  55.235 +        _data[index].prev = -1;
  55.236 +        _boxes[box].first = index;
  55.237        }
  55.238 -      data[index].box = box;
  55.239 +      _data[index].box = box;
  55.240      }
  55.241  
  55.242 -    /// \brief Add a new box to the box list.
  55.243 +    // Add a new box to the box list
  55.244      void extend() {
  55.245 -      int min = boxes.back().min + boxes.back().size;
  55.246 -      int bs = 2 * boxes.back().size;
  55.247 -      boxes.push_back(RadixBox(min, bs));
  55.248 +      int min = _boxes.back().min + _boxes.back().size;
  55.249 +      int bs = 2 * _boxes.back().size;
  55.250 +      _boxes.push_back(RadixBox(min, bs));
  55.251      }
  55.252  
  55.253 -    /// \brief Move an item up into the proper box.
  55.254 -    void bubble_up(int index) {
  55.255 -      if (!lower(data[index].box, data[index].prio)) return;
  55.256 +    // Move an item up into the proper box.
  55.257 +    void bubbleUp(int index) {
  55.258 +      if (!lower(_data[index].box, _data[index].prio)) return;
  55.259        remove(index);
  55.260 -      int box = findUp(data[index].box, data[index].prio);
  55.261 +      int box = findUp(_data[index].box, _data[index].prio);
  55.262        insert(box, index);
  55.263      }
  55.264  
  55.265 -    /// \brief Find up the proper box for the item with the given prio.
  55.266 +    // Find up the proper box for the item with the given priority
  55.267      int findUp(int start, int pr) {
  55.268        while (lower(start, pr)) {
  55.269 -        if (++start == int(boxes.size())) {
  55.270 +        if (++start == int(_boxes.size())) {
  55.271            extend();
  55.272          }
  55.273        }
  55.274        return start;
  55.275      }
  55.276  
  55.277 -    /// \brief Move an item down into the proper box.
  55.278 -    void bubble_down(int index) {
  55.279 -      if (!upper(data[index].box, data[index].prio)) return;
  55.280 +    // Move an item down into the proper box
  55.281 +    void bubbleDown(int index) {
  55.282 +      if (!upper(_data[index].box, _data[index].prio)) return;
  55.283        remove(index);
  55.284 -      int box = findDown(data[index].box, data[index].prio);
  55.285 +      int box = findDown(_data[index].box, _data[index].prio);
  55.286        insert(box, index);
  55.287      }
  55.288  
  55.289 -    /// \brief Find up the proper box for the item with the given prio.
  55.290 +    // Find down the proper box for the item with the given priority
  55.291      int findDown(int start, int pr) {
  55.292        while (upper(start, pr)) {
  55.293 -        if (--start < 0) throw UnderFlowPriorityError();
  55.294 +        if (--start < 0) throw PriorityUnderflowError();
  55.295        }
  55.296        return start;
  55.297      }
  55.298  
  55.299 -    /// \brief Find the first not empty box.
  55.300 +    // Find the first non-empty box
  55.301      int findFirst() {
  55.302        int first = 0;
  55.303 -      while (boxes[first].first == -1) ++first;
  55.304 +      while (_boxes[first].first == -1) ++first;
  55.305        return first;
  55.306      }
  55.307  
  55.308 -    /// \brief Gives back the minimal prio of the box.
  55.309 +    // Gives back the minimum priority of the given box
  55.310      int minValue(int box) {
  55.311 -      int min = data[boxes[box].first].prio;
  55.312 -      for (int k = boxes[box].first; k != -1; k = data[k].next) {
  55.313 -        if (data[k].prio < min) min = data[k].prio;
  55.314 +      int min = _data[_boxes[box].first].prio;
  55.315 +      for (int k = _boxes[box].first; k != -1; k = _data[k].next) {
  55.316 +        if (_data[k].prio < min) min = _data[k].prio;
  55.317        }
  55.318        return min;
  55.319      }
  55.320  
  55.321 -    /// \brief Rearrange the items of the heap and makes the
  55.322 -    /// first box not empty.
  55.323 +    // Rearrange the items of the heap and make the first box non-empty
  55.324      void moveDown() {
  55.325        int box = findFirst();
  55.326        if (box == 0) return;
  55.327        int min = minValue(box);
  55.328        for (int i = 0; i <= box; ++i) {
  55.329 -        boxes[i].min = min;
  55.330 -        min += boxes[i].size;
  55.331 +        _boxes[i].min = min;
  55.332 +        min += _boxes[i].size;
  55.333        }
  55.334 -      int curr = boxes[box].first, next;
  55.335 +      int curr = _boxes[box].first, next;
  55.336        while (curr != -1) {
  55.337 -        next = data[curr].next;
  55.338 -        bubble_down(curr);
  55.339 +        next = _data[curr].next;
  55.340 +        bubbleDown(curr);
  55.341          curr = next;
  55.342        }
  55.343      }
  55.344  
  55.345 -    void relocate_last(int index) {
  55.346 -      if (index != int(data.size()) - 1) {
  55.347 -        data[index] = data.back();
  55.348 -        if (data[index].prev != -1) {
  55.349 -          data[data[index].prev].next = index;
  55.350 +    void relocateLast(int index) {
  55.351 +      if (index != int(_data.size()) - 1) {
  55.352 +        _data[index] = _data.back();
  55.353 +        if (_data[index].prev != -1) {
  55.354 +          _data[_data[index].prev].next = index;
  55.355          } else {
  55.356 -          boxes[data[index].box].first = index;
  55.357 +          _boxes[_data[index].box].first = index;
  55.358          }
  55.359 -        if (data[index].next != -1) {
  55.360 -          data[data[index].next].prev = index;
  55.361 +        if (_data[index].next != -1) {
  55.362 +          _data[_data[index].next].prev = index;
  55.363          }
  55.364 -        _iim[data[index].item] = index;
  55.365 +        _iim[_data[index].item] = index;
  55.366        }
  55.367 -      data.pop_back();
  55.368 +      _data.pop_back();
  55.369      }
  55.370  
  55.371    public:
  55.372  
  55.373      /// \brief Insert an item into the heap with the given priority.
  55.374      ///
  55.375 -    /// Adds \c i to the heap with priority \c p.
  55.376 +    /// This function inserts the given item into the heap with the
  55.377 +    /// given priority.
  55.378      /// \param i The item to insert.
  55.379      /// \param p The priority of the item.
  55.380 +    /// \pre \e i must not be stored in the heap.
  55.381 +    /// \warning This method may throw an \c UnderFlowPriorityException.
  55.382      void push(const Item &i, const Prio &p) {
  55.383 -      int n = data.size();
  55.384 +      int n = _data.size();
  55.385        _iim.set(i, n);
  55.386 -      data.push_back(RadixItem(i, p));
  55.387 -      while (lower(boxes.size() - 1, p)) {
  55.388 +      _data.push_back(RadixItem(i, p));
  55.389 +      while (lower(_boxes.size() - 1, p)) {
  55.390          extend();
  55.391        }
  55.392 -      int box = findDown(boxes.size() - 1, p);
  55.393 +      int box = findDown(_boxes.size() - 1, p);
  55.394        insert(box, n);
  55.395      }
  55.396  
  55.397 -    /// \brief Returns the item with minimum priority.
  55.398 +    /// \brief Return the item having minimum priority.
  55.399      ///
  55.400 -    /// This method returns the item with minimum priority.
  55.401 -    /// \pre The heap must be nonempty.
  55.402 +    /// This function returns the item having minimum priority.
  55.403 +    /// \pre The heap must be non-empty.
  55.404      Item top() const {
  55.405        const_cast<RadixHeap<ItemIntMap>&>(*this).moveDown();
  55.406 -      return data[boxes[0].first].item;
  55.407 +      return _data[_boxes[0].first].item;
  55.408      }
  55.409  
  55.410 -    /// \brief Returns the minimum priority.
  55.411 +    /// \brief The minimum priority.
  55.412      ///
  55.413 -    /// It returns the minimum priority.
  55.414 -    /// \pre The heap must be nonempty.
  55.415 +    /// This function returns the minimum priority.
  55.416 +    /// \pre The heap must be non-empty.
  55.417      Prio prio() const {
  55.418        const_cast<RadixHeap<ItemIntMap>&>(*this).moveDown();
  55.419 -      return data[boxes[0].first].prio;
  55.420 +      return _data[_boxes[0].first].prio;
  55.421       }
  55.422  
  55.423 -    /// \brief Deletes the item with minimum priority.
  55.424 +    /// \brief Remove the item having minimum priority.
  55.425      ///
  55.426 -    /// This method deletes the item with minimum priority.
  55.427 +    /// This function removes the item having minimum priority.
  55.428      /// \pre The heap must be non-empty.
  55.429      void pop() {
  55.430        moveDown();
  55.431 -      int index = boxes[0].first;
  55.432 -      _iim[data[index].item] = POST_HEAP;
  55.433 +      int index = _boxes[0].first;
  55.434 +      _iim[_data[index].item] = POST_HEAP;
  55.435        remove(index);
  55.436 -      relocate_last(index);
  55.437 +      relocateLast(index);
  55.438      }
  55.439  
  55.440 -    /// \brief Deletes \c i from the heap.
  55.441 +    /// \brief Remove the given item from the heap.
  55.442      ///
  55.443 -    /// This method deletes item \c i from the heap, if \c i was
  55.444 -    /// already stored in the heap.
  55.445 -    /// \param i The item to erase.
  55.446 +    /// This function removes the given item from the heap if it is
  55.447 +    /// already stored.
  55.448 +    /// \param i The item to delete.
  55.449 +    /// \pre \e i must be in the heap.
  55.450      void erase(const Item &i) {
  55.451        int index = _iim[i];
  55.452        _iim[i] = POST_HEAP;
  55.453        remove(index);
  55.454 -      relocate_last(index);
  55.455 +      relocateLast(index);
  55.456     }
  55.457  
  55.458 -    /// \brief Returns the priority of \c i.
  55.459 +    /// \brief The priority of the given item.
  55.460      ///
  55.461 -    /// This function returns the priority of item \c i.
  55.462 -    /// \pre \c i must be in the heap.
  55.463 +    /// This function returns the priority of the given item.
  55.464      /// \param i The item.
  55.465 +    /// \pre \e i must be in the heap.
  55.466      Prio operator[](const Item &i) const {
  55.467        int idx = _iim[i];
  55.468 -      return data[idx].prio;
  55.469 +      return _data[idx].prio;
  55.470      }
  55.471  
  55.472 -    /// \brief \c i gets to the heap with priority \c p independently
  55.473 -    /// if \c i was already there.
  55.474 +    /// \brief Set the priority of an item or insert it, if it is
  55.475 +    /// not stored in the heap.
  55.476      ///
  55.477 -    /// This method calls \ref push(\c i, \c p) if \c i is not stored
  55.478 -    /// in the heap and sets the priority of \c i to \c p otherwise.
  55.479 -    /// It may throw an \e UnderFlowPriorityException.
  55.480 +    /// This method sets the priority of the given item if it is
  55.481 +    /// already stored in the heap. Otherwise it inserts the given
  55.482 +    /// item into the heap with the given priority.
  55.483      /// \param i The item.
  55.484      /// \param p The priority.
  55.485 +    /// \pre \e i must be in the heap.
  55.486 +    /// \warning This method may throw an \c UnderFlowPriorityException.
  55.487      void set(const Item &i, const Prio &p) {
  55.488        int idx = _iim[i];
  55.489        if( idx < 0 ) {
  55.490          push(i, p);
  55.491        }
  55.492 -      else if( p >= data[idx].prio ) {
  55.493 -        data[idx].prio = p;
  55.494 -        bubble_up(idx);
  55.495 +      else if( p >= _data[idx].prio ) {
  55.496 +        _data[idx].prio = p;
  55.497 +        bubbleUp(idx);
  55.498        } else {
  55.499 -        data[idx].prio = p;
  55.500 -        bubble_down(idx);
  55.501 +        _data[idx].prio = p;
  55.502 +        bubbleDown(idx);
  55.503        }
  55.504      }
  55.505  
  55.506 -
  55.507 -    /// \brief Decreases the priority of \c i to \c p.
  55.508 +    /// \brief Decrease the priority of an item to the given value.
  55.509      ///
  55.510 -    /// This method decreases the priority of item \c i to \c p.
  55.511 -    /// \pre \c i must be stored in the heap with priority at least \c p, and
  55.512 -    /// \c should be greater or equal to the last removed item's priority.
  55.513 +    /// This function decreases the priority of an item to the given value.
  55.514      /// \param i The item.
  55.515      /// \param p The priority.
  55.516 +    /// \pre \e i must be stored in the heap with priority at least \e p.
  55.517 +    /// \warning This method may throw an \c UnderFlowPriorityException.
  55.518      void decrease(const Item &i, const Prio &p) {
  55.519        int idx = _iim[i];
  55.520 -      data[idx].prio = p;
  55.521 -      bubble_down(idx);
  55.522 +      _data[idx].prio = p;
  55.523 +      bubbleDown(idx);
  55.524      }
  55.525  
  55.526 -    /// \brief Increases the priority of \c i to \c p.
  55.527 +    /// \brief Increase the priority of an item to the given value.
  55.528      ///
  55.529 -    /// This method sets the priority of item \c i to \c p.
  55.530 -    /// \pre \c i must be stored in the heap with priority at most \c p
  55.531 +    /// This function increases the priority of an item to the given value.
  55.532      /// \param i The item.
  55.533      /// \param p The priority.
  55.534 +    /// \pre \e i must be stored in the heap with priority at most \e p.
  55.535      void increase(const Item &i, const Prio &p) {
  55.536        int idx = _iim[i];
  55.537 -      data[idx].prio = p;
  55.538 -      bubble_up(idx);
  55.539 +      _data[idx].prio = p;
  55.540 +      bubbleUp(idx);
  55.541      }
  55.542  
  55.543 -    /// \brief Returns if \c item is in, has already been in, or has
  55.544 -    /// never been in the heap.
  55.545 +    /// \brief Return the state of an item.
  55.546      ///
  55.547 -    /// This method returns PRE_HEAP if \c item has never been in the
  55.548 -    /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
  55.549 -    /// otherwise. In the latter case it is possible that \c item will
  55.550 -    /// get back to the heap again.
  55.551 +    /// This method returns \c PRE_HEAP if the given item has never
  55.552 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  55.553 +    /// and \c POST_HEAP otherwise.
  55.554 +    /// In the latter case it is possible that the item will get back
  55.555 +    /// to the heap again.
  55.556      /// \param i The item.
  55.557      State state(const Item &i) const {
  55.558        int s = _iim[i];
  55.559 @@ -405,11 +410,11 @@
  55.560        return State(s);
  55.561      }
  55.562  
  55.563 -    /// \brief Sets the state of the \c item in the heap.
  55.564 +    /// \brief Set the state of an item in the heap.
  55.565      ///
  55.566 -    /// Sets the state of the \c item in the heap. It can be used to
  55.567 -    /// manually clear the heap when it is important to achive the
  55.568 -    /// better time complexity.
  55.569 +    /// This function sets the state of the given item in the heap.
  55.570 +    /// It can be used to manually clear the heap when it is important
  55.571 +    /// to achive better time complexity.
  55.572      /// \param i The item.
  55.573      /// \param st The state. It should not be \c IN_HEAP.
  55.574      void state(const Item& i, State st) {
    56.1 --- a/lemon/smart_graph.h	Thu Nov 05 10:01:02 2009 +0100
    56.2 +++ b/lemon/smart_graph.h	Thu Nov 05 10:23:16 2009 +0100
    56.3 @@ -32,10 +32,7 @@
    56.4  namespace lemon {
    56.5  
    56.6    class SmartDigraph;
    56.7 -  ///Base of SmartDigraph
    56.8  
    56.9 -  ///Base of SmartDigraph
   56.10 -  ///
   56.11    class SmartDigraphBase {
   56.12    protected:
   56.13  
   56.14 @@ -187,28 +184,26 @@
   56.15    ///
   56.16    ///\brief A smart directed graph class.
   56.17    ///
   56.18 -  ///This is a simple and fast digraph implementation.
   56.19 -  ///It is also quite memory efficient, but at the price
   56.20 -  ///that <b> it does support only limited (only stack-like)
   56.21 -  ///node and arc deletions</b>.
   56.22 -  ///It fully conforms to the \ref concepts::Digraph "Digraph concept".
   56.23 +  ///\ref SmartDigraph is a simple and fast digraph implementation.
   56.24 +  ///It is also quite memory efficient but at the price
   56.25 +  ///that it does not support node and arc deletion 
   56.26 +  ///(except for the Snapshot feature).
   56.27    ///
   56.28 -  ///\sa concepts::Digraph.
   56.29 +  ///This type fully conforms to the \ref concepts::Digraph "Digraph concept"
   56.30 +  ///and it also provides some additional functionalities.
   56.31 +  ///Most of its member functions and nested classes are documented
   56.32 +  ///only in the concept class.
   56.33 +  ///
   56.34 +  ///\sa concepts::Digraph
   56.35 +  ///\sa SmartGraph
   56.36    class SmartDigraph : public ExtendedSmartDigraphBase {
   56.37      typedef ExtendedSmartDigraphBase Parent;
   56.38  
   56.39    private:
   56.40 -
   56.41 -    ///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead.
   56.42 -
   56.43 -    ///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead.
   56.44 -    ///
   56.45 +    /// Digraphs are \e not copy constructible. Use DigraphCopy instead.
   56.46      SmartDigraph(const SmartDigraph &) : ExtendedSmartDigraphBase() {};
   56.47 -    ///\brief Assignment of SmartDigraph to another one is \e not allowed.
   56.48 -    ///Use DigraphCopy() instead.
   56.49 -
   56.50 -    ///Assignment of SmartDigraph to another one is \e not allowed.
   56.51 -    ///Use DigraphCopy() instead.
   56.52 +    /// \brief Assignment of a digraph to another one is \e not allowed.
   56.53 +    /// Use DigraphCopy instead.
   56.54      void operator=(const SmartDigraph &) {}
   56.55  
   56.56    public:
   56.57 @@ -221,79 +216,49 @@
   56.58  
   56.59      ///Add a new node to the digraph.
   56.60  
   56.61 -    /// Add a new node to the digraph.
   56.62 -    /// \return The new node.
   56.63 +    ///This function adds a new node to the digraph.
   56.64 +    ///\return The new node.
   56.65      Node addNode() { return Parent::addNode(); }
   56.66  
   56.67      ///Add a new arc to the digraph.
   56.68  
   56.69 -    ///Add a new arc to the digraph with source node \c s
   56.70 +    ///This function adds a new arc to the digraph with source node \c s
   56.71      ///and target node \c t.
   56.72      ///\return The new arc.
   56.73 -    Arc addArc(const Node& s, const Node& t) {
   56.74 +    Arc addArc(Node s, Node t) {
   56.75        return Parent::addArc(s, t);
   56.76      }
   56.77  
   56.78 -    /// \brief Using this it is possible to avoid the superfluous memory
   56.79 -    /// allocation.
   56.80 -
   56.81 -    /// Using this it is possible to avoid the superfluous memory
   56.82 -    /// allocation: if you know that the digraph you want to build will
   56.83 -    /// be very large (e.g. it will contain millions of nodes and/or arcs)
   56.84 -    /// then it is worth reserving space for this amount before starting
   56.85 -    /// to build the digraph.
   56.86 -    /// \sa reserveArc
   56.87 -    void reserveNode(int n) { nodes.reserve(n); };
   56.88 -
   56.89 -    /// \brief Using this it is possible to avoid the superfluous memory
   56.90 -    /// allocation.
   56.91 -
   56.92 -    /// Using this it is possible to avoid the superfluous memory
   56.93 -    /// allocation: if you know that the digraph you want to build will
   56.94 -    /// be very large (e.g. it will contain millions of nodes and/or arcs)
   56.95 -    /// then it is worth reserving space for this amount before starting
   56.96 -    /// to build the digraph.
   56.97 -    /// \sa reserveNode
   56.98 -    void reserveArc(int m) { arcs.reserve(m); };
   56.99 -
  56.100      /// \brief Node validity check
  56.101      ///
  56.102 -    /// This function gives back true if the given node is valid,
  56.103 -    /// ie. it is a real node of the graph.
  56.104 +    /// This function gives back \c true if the given node is valid,
  56.105 +    /// i.e. it is a real node of the digraph.
  56.106      ///
  56.107      /// \warning A removed node (using Snapshot) could become valid again
  56.108 -    /// when new nodes are added to the graph.
  56.109 +    /// if new nodes are added to the digraph.
  56.110      bool valid(Node n) const { return Parent::valid(n); }
  56.111  
  56.112      /// \brief Arc validity check
  56.113      ///
  56.114 -    /// This function gives back true if the given arc is valid,
  56.115 -    /// ie. it is a real arc of the graph.
  56.116 +    /// This function gives back \c true if the given arc is valid,
  56.117 +    /// i.e. it is a real arc of the digraph.
  56.118      ///
  56.119      /// \warning A removed arc (using Snapshot) could become valid again
  56.120 -    /// when new arcs are added to the graph.
  56.121 +    /// if new arcs are added to the graph.
  56.122      bool valid(Arc a) const { return Parent::valid(a); }
  56.123  
  56.124 -    ///Clear the digraph.
  56.125 -
  56.126 -    ///Erase all the nodes and arcs from the digraph.
  56.127 -    ///
  56.128 -    void clear() {
  56.129 -      Parent::clear();
  56.130 -    }
  56.131 -
  56.132      ///Split a node.
  56.133  
  56.134 -    ///This function splits a node. First a new node is added to the digraph,
  56.135 -    ///then the source of each outgoing arc of \c n is moved to this new node.
  56.136 -    ///If \c connect is \c true (this is the default value), then a new arc
  56.137 -    ///from \c n to the newly created node is also added.
  56.138 +    ///This function splits the given node. First, a new node is added
  56.139 +    ///to the digraph, then the source of each outgoing arc of node \c n
  56.140 +    ///is moved to this new node.
  56.141 +    ///If the second parameter \c connect is \c true (this is the default
  56.142 +    ///value), then a new arc from node \c n to the newly created node
  56.143 +    ///is also added.
  56.144      ///\return The newly created node.
  56.145      ///
  56.146 -    ///\note The <tt>Arc</tt>s
  56.147 -    ///referencing a moved arc remain
  56.148 -    ///valid. However <tt>InArc</tt>'s and <tt>OutArc</tt>'s
  56.149 -    ///may be invalidated.
  56.150 +    ///\note All iterators remain valid.
  56.151 +    ///
  56.152      ///\warning This functionality cannot be used together with the Snapshot
  56.153      ///feature.
  56.154      Node split(Node n, bool connect = true)
  56.155 @@ -308,6 +273,34 @@
  56.156        return b;
  56.157      }
  56.158  
  56.159 +    ///Clear the digraph.
  56.160 +
  56.161 +    ///This function erases all nodes and arcs from the digraph.
  56.162 +    ///
  56.163 +    void clear() {
  56.164 +      Parent::clear();
  56.165 +    }
  56.166 +
  56.167 +    /// Reserve memory for nodes.
  56.168 +
  56.169 +    /// Using this function, it is possible to avoid superfluous memory
  56.170 +    /// allocation: if you know that the digraph you want to build will
  56.171 +    /// be large (e.g. it will contain millions of nodes and/or arcs),
  56.172 +    /// then it is worth reserving space for this amount before starting
  56.173 +    /// to build the digraph.
  56.174 +    /// \sa reserveArc()
  56.175 +    void reserveNode(int n) { nodes.reserve(n); };
  56.176 +
  56.177 +    /// Reserve memory for arcs.
  56.178 +
  56.179 +    /// Using this function, it is possible to avoid superfluous memory
  56.180 +    /// allocation: if you know that the digraph you want to build will
  56.181 +    /// be large (e.g. it will contain millions of nodes and/or arcs),
  56.182 +    /// then it is worth reserving space for this amount before starting
  56.183 +    /// to build the digraph.
  56.184 +    /// \sa reserveNode()
  56.185 +    void reserveArc(int m) { arcs.reserve(m); };
  56.186 +
  56.187    public:
  56.188  
  56.189      class Snapshot;
  56.190 @@ -332,20 +325,23 @@
  56.191  
  56.192    public:
  56.193  
  56.194 -    ///Class to make a snapshot of the digraph and to restrore to it later.
  56.195 +    ///Class to make a snapshot of the digraph and to restore it later.
  56.196  
  56.197 -    ///Class to make a snapshot of the digraph and to restrore to it later.
  56.198 +    ///Class to make a snapshot of the digraph and to restore it later.
  56.199      ///
  56.200      ///The newly added nodes and arcs can be removed using the
  56.201 -    ///restore() function.
  56.202 -    ///\note After you restore a state, you cannot restore
  56.203 -    ///a later state, in other word you cannot add again the arcs deleted
  56.204 -    ///by restore() using another one Snapshot instance.
  56.205 +    ///restore() function. This is the only way for deleting nodes and/or
  56.206 +    ///arcs from a SmartDigraph structure.
  56.207      ///
  56.208 -    ///\warning If you do not use correctly the snapshot that can cause
  56.209 -    ///either broken program, invalid state of the digraph, valid but
  56.210 -    ///not the restored digraph or no change. Because the runtime performance
  56.211 -    ///the validity of the snapshot is not stored.
  56.212 +    ///\note After a state is restored, you cannot restore a later state, 
  56.213 +    ///i.e. you cannot add the removed nodes and arcs again using
  56.214 +    ///another Snapshot instance.
  56.215 +    ///
  56.216 +    ///\warning Node splitting cannot be restored.
  56.217 +    ///\warning The validity of the snapshot is not stored due to
  56.218 +    ///performance reasons. If you do not use the snapshot correctly,
  56.219 +    ///it can cause broken program, invalid or not restored state of
  56.220 +    ///the digraph or no change.
  56.221      class Snapshot
  56.222      {
  56.223        SmartDigraph *_graph;
  56.224 @@ -357,39 +353,32 @@
  56.225        ///Default constructor.
  56.226  
  56.227        ///Default constructor.
  56.228 -      ///To actually make a snapshot you must call save().
  56.229 -      ///
  56.230 +      ///You have to call save() to actually make a snapshot.
  56.231        Snapshot() : _graph(0) {}
  56.232        ///Constructor that immediately makes a snapshot
  56.233  
  56.234 -      ///This constructor immediately makes a snapshot of the digraph.
  56.235 -      ///\param graph The digraph we make a snapshot of.
  56.236 -      Snapshot(SmartDigraph &graph) : _graph(&graph) {
  56.237 +      ///This constructor immediately makes a snapshot of the given digraph.
  56.238 +      ///
  56.239 +      Snapshot(SmartDigraph &gr) : _graph(&gr) {
  56.240          node_num=_graph->nodes.size();
  56.241          arc_num=_graph->arcs.size();
  56.242        }
  56.243  
  56.244        ///Make a snapshot.
  56.245  
  56.246 -      ///Make a snapshot of the digraph.
  56.247 -      ///
  56.248 -      ///This function can be called more than once. In case of a repeated
  56.249 +      ///This function makes a snapshot of the given digraph.
  56.250 +      ///It can be called more than once. In case of a repeated
  56.251        ///call, the previous snapshot gets lost.
  56.252 -      ///\param graph The digraph we make the snapshot of.
  56.253 -      void save(SmartDigraph &graph)
  56.254 -      {
  56.255 -        _graph=&graph;
  56.256 +      void save(SmartDigraph &gr) {
  56.257 +        _graph=&gr;
  56.258          node_num=_graph->nodes.size();
  56.259          arc_num=_graph->arcs.size();
  56.260        }
  56.261  
  56.262        ///Undo the changes until a snapshot.
  56.263  
  56.264 -      ///Undo the changes until a snapshot created by save().
  56.265 -      ///
  56.266 -      ///\note After you restored a state, you cannot restore
  56.267 -      ///a later state, in other word you cannot add again the arcs deleted
  56.268 -      ///by restore().
  56.269 +      ///This function undos the changes until the last snapshot
  56.270 +      ///created by save() or Snapshot(SmartDigraph&).
  56.271        void restore()
  56.272        {
  56.273          _graph->restoreSnapshot(*this);
  56.274 @@ -621,29 +610,26 @@
  56.275    ///
  56.276    /// \brief A smart undirected graph class.
  56.277    ///
  56.278 -  /// This is a simple and fast graph implementation.
  56.279 -  /// It is also quite memory efficient, but at the price
  56.280 -  /// that <b> it does support only limited (only stack-like)
  56.281 -  /// node and arc deletions</b>.
  56.282 -  /// It fully conforms to the \ref concepts::Graph "Graph concept".
  56.283 +  /// \ref SmartGraph is a simple and fast graph implementation.
  56.284 +  /// It is also quite memory efficient but at the price
  56.285 +  /// that it does not support node and edge deletion 
  56.286 +  /// (except for the Snapshot feature).
  56.287    ///
  56.288 -  /// \sa concepts::Graph.
  56.289 +  /// This type fully conforms to the \ref concepts::Graph "Graph concept"
  56.290 +  /// and it also provides some additional functionalities.
  56.291 +  /// Most of its member functions and nested classes are documented
  56.292 +  /// only in the concept class.
  56.293 +  ///
  56.294 +  /// \sa concepts::Graph
  56.295 +  /// \sa SmartDigraph
  56.296    class SmartGraph : public ExtendedSmartGraphBase {
  56.297      typedef ExtendedSmartGraphBase Parent;
  56.298  
  56.299    private:
  56.300 -
  56.301 -    ///SmartGraph is \e not copy constructible. Use GraphCopy() instead.
  56.302 -
  56.303 -    ///SmartGraph is \e not copy constructible. Use GraphCopy() instead.
  56.304 -    ///
  56.305 +    /// Graphs are \e not copy constructible. Use GraphCopy instead.
  56.306      SmartGraph(const SmartGraph &) : ExtendedSmartGraphBase() {};
  56.307 -
  56.308 -    ///\brief Assignment of SmartGraph to another one is \e not allowed.
  56.309 -    ///Use GraphCopy() instead.
  56.310 -
  56.311 -    ///Assignment of SmartGraph to another one is \e not allowed.
  56.312 -    ///Use GraphCopy() instead.
  56.313 +    /// \brief Assignment of a graph to another one is \e not allowed.
  56.314 +    /// Use GraphCopy instead.
  56.315      void operator=(const SmartGraph &) {}
  56.316  
  56.317    public:
  56.318 @@ -654,56 +640,77 @@
  56.319      ///
  56.320      SmartGraph() {}
  56.321  
  56.322 -    ///Add a new node to the graph.
  56.323 -
  56.324 -    /// Add a new node to the graph.
  56.325 +    /// \brief Add a new node to the graph.
  56.326 +    ///
  56.327 +    /// This function adds a new node to the graph.
  56.328      /// \return The new node.
  56.329      Node addNode() { return Parent::addNode(); }
  56.330  
  56.331 -    ///Add a new edge to the graph.
  56.332 -
  56.333 -    ///Add a new edge to the graph with node \c s
  56.334 -    ///and \c t.
  56.335 -    ///\return The new edge.
  56.336 -    Edge addEdge(const Node& s, const Node& t) {
  56.337 -      return Parent::addEdge(s, t);
  56.338 +    /// \brief Add a new edge to the graph.
  56.339 +    ///
  56.340 +    /// This function adds a new edge to the graph between nodes
  56.341 +    /// \c u and \c v with inherent orientation from node \c u to
  56.342 +    /// node \c v.
  56.343 +    /// \return The new edge.
  56.344 +    Edge addEdge(Node u, Node v) {
  56.345 +      return Parent::addEdge(u, v);
  56.346      }
  56.347  
  56.348      /// \brief Node validity check
  56.349      ///
  56.350 -    /// This function gives back true if the given node is valid,
  56.351 -    /// ie. it is a real node of the graph.
  56.352 +    /// This function gives back \c true if the given node is valid,
  56.353 +    /// i.e. it is a real node of the graph.
  56.354      ///
  56.355      /// \warning A removed node (using Snapshot) could become valid again
  56.356 -    /// when new nodes are added to the graph.
  56.357 +    /// if new nodes are added to the graph.
  56.358      bool valid(Node n) const { return Parent::valid(n); }
  56.359  
  56.360 +    /// \brief Edge validity check
  56.361 +    ///
  56.362 +    /// This function gives back \c true if the given edge is valid,
  56.363 +    /// i.e. it is a real edge of the graph.
  56.364 +    ///
  56.365 +    /// \warning A removed edge (using Snapshot) could become valid again
  56.366 +    /// if new edges are added to the graph.
  56.367 +    bool valid(Edge e) const { return Parent::valid(e); }
  56.368 +
  56.369      /// \brief Arc validity check
  56.370      ///
  56.371 -    /// This function gives back true if the given arc is valid,
  56.372 -    /// ie. it is a real arc of the graph.
  56.373 +    /// This function gives back \c true if the given arc is valid,
  56.374 +    /// i.e. it is a real arc of the graph.
  56.375      ///
  56.376      /// \warning A removed arc (using Snapshot) could become valid again
  56.377 -    /// when new edges are added to the graph.
  56.378 +    /// if new edges are added to the graph.
  56.379      bool valid(Arc a) const { return Parent::valid(a); }
  56.380  
  56.381 -    /// \brief Edge validity check
  56.382 -    ///
  56.383 -    /// This function gives back true if the given edge is valid,
  56.384 -    /// ie. it is a real edge of the graph.
  56.385 -    ///
  56.386 -    /// \warning A removed edge (using Snapshot) could become valid again
  56.387 -    /// when new edges are added to the graph.
  56.388 -    bool valid(Edge e) const { return Parent::valid(e); }
  56.389 -
  56.390      ///Clear the graph.
  56.391  
  56.392 -    ///Erase all the nodes and edges from the graph.
  56.393 +    ///This function erases all nodes and arcs from the graph.
  56.394      ///
  56.395      void clear() {
  56.396        Parent::clear();
  56.397      }
  56.398  
  56.399 +    /// Reserve memory for nodes.
  56.400 +
  56.401 +    /// Using this function, it is possible to avoid superfluous memory
  56.402 +    /// allocation: if you know that the graph you want to build will
  56.403 +    /// be large (e.g. it will contain millions of nodes and/or edges),
  56.404 +    /// then it is worth reserving space for this amount before starting
  56.405 +    /// to build the graph.
  56.406 +    /// \sa reserveEdge()
  56.407 +    void reserveNode(int n) { nodes.reserve(n); };
  56.408 +
  56.409 +    /// Reserve memory for edges.
  56.410 +
  56.411 +    /// Using this function, it is possible to avoid superfluous memory
  56.412 +    /// allocation: if you know that the graph you want to build will
  56.413 +    /// be large (e.g. it will contain millions of nodes and/or edges),
  56.414 +    /// then it is worth reserving space for this amount before starting
  56.415 +    /// to build the graph.
  56.416 +    /// \sa reserveNode()
  56.417 +    void reserveEdge(int m) { arcs.reserve(2 * m); };
  56.418 +
  56.419    public:
  56.420  
  56.421      class Snapshot;
  56.422 @@ -742,21 +749,22 @@
  56.423  
  56.424    public:
  56.425  
  56.426 -    ///Class to make a snapshot of the digraph and to restrore to it later.
  56.427 +    ///Class to make a snapshot of the graph and to restore it later.
  56.428  
  56.429 -    ///Class to make a snapshot of the digraph and to restrore to it later.
  56.430 +    ///Class to make a snapshot of the graph and to restore it later.
  56.431      ///
  56.432 -    ///The newly added nodes and arcs can be removed using the
  56.433 -    ///restore() function.
  56.434 +    ///The newly added nodes and edges can be removed using the
  56.435 +    ///restore() function. This is the only way for deleting nodes and/or
  56.436 +    ///edges from a SmartGraph structure.
  56.437      ///
  56.438 -    ///\note After you restore a state, you cannot restore
  56.439 -    ///a later state, in other word you cannot add again the arcs deleted
  56.440 -    ///by restore() using another one Snapshot instance.
  56.441 +    ///\note After a state is restored, you cannot restore a later state, 
  56.442 +    ///i.e. you cannot add the removed nodes and edges again using
  56.443 +    ///another Snapshot instance.
  56.444      ///
  56.445 -    ///\warning If you do not use correctly the snapshot that can cause
  56.446 -    ///either broken program, invalid state of the digraph, valid but
  56.447 -    ///not the restored digraph or no change. Because the runtime performance
  56.448 -    ///the validity of the snapshot is not stored.
  56.449 +    ///\warning The validity of the snapshot is not stored due to
  56.450 +    ///performance reasons. If you do not use the snapshot correctly,
  56.451 +    ///it can cause broken program, invalid or not restored state of
  56.452 +    ///the graph or no change.
  56.453      class Snapshot
  56.454      {
  56.455        SmartGraph *_graph;
  56.456 @@ -768,36 +776,30 @@
  56.457        ///Default constructor.
  56.458  
  56.459        ///Default constructor.
  56.460 -      ///To actually make a snapshot you must call save().
  56.461 -      ///
  56.462 +      ///You have to call save() to actually make a snapshot.
  56.463        Snapshot() : _graph(0) {}
  56.464        ///Constructor that immediately makes a snapshot
  56.465  
  56.466 -      ///This constructor immediately makes a snapshot of the digraph.
  56.467 -      ///\param graph The digraph we make a snapshot of.
  56.468 -      Snapshot(SmartGraph &graph) {
  56.469 -        graph.saveSnapshot(*this);
  56.470 +      /// This constructor immediately makes a snapshot of the given graph.
  56.471 +      ///
  56.472 +      Snapshot(SmartGraph &gr) {
  56.473 +        gr.saveSnapshot(*this);
  56.474        }
  56.475  
  56.476        ///Make a snapshot.
  56.477  
  56.478 -      ///Make a snapshot of the graph.
  56.479 -      ///
  56.480 -      ///This function can be called more than once. In case of a repeated
  56.481 +      ///This function makes a snapshot of the given graph.
  56.482 +      ///It can be called more than once. In case of a repeated
  56.483        ///call, the previous snapshot gets lost.
  56.484 -      ///\param graph The digraph we make the snapshot of.
  56.485 -      void save(SmartGraph &graph)
  56.486 +      void save(SmartGraph &gr)
  56.487        {
  56.488 -        graph.saveSnapshot(*this);
  56.489 +        gr.saveSnapshot(*this);
  56.490        }
  56.491  
  56.492 -      ///Undo the changes until a snapshot.
  56.493 +      ///Undo the changes until the last snapshot.
  56.494  
  56.495 -      ///Undo the changes until a snapshot created by save().
  56.496 -      ///
  56.497 -      ///\note After you restored a state, you cannot restore
  56.498 -      ///a later state, in other word you cannot add again the arcs deleted
  56.499 -      ///by restore().
  56.500 +      ///This function undos the changes until the last snapshot
  56.501 +      ///created by save() or Snapshot(SmartGraph&).
  56.502        void restore()
  56.503        {
  56.504          _graph->restoreSnapshot(*this);
    57.1 --- a/lemon/soplex.cc	Thu Nov 05 10:01:02 2009 +0100
    57.2 +++ b/lemon/soplex.cc	Thu Nov 05 10:23:16 2009 +0100
    57.3 @@ -91,6 +91,19 @@
    57.4      return soplex->nRows() - 1;
    57.5    }
    57.6  
    57.7 +  int SoplexLp::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
    57.8 +    soplex::DSVector v;
    57.9 +    for (ExprIterator it = b; it != e; ++it) {
   57.10 +      v.add(it->first, it->second);
   57.11 +    }
   57.12 +    soplex::LPRow r(l, v, u);
   57.13 +    soplex->addRow(r);
   57.14 +
   57.15 +    _row_names.push_back(std::string());
   57.16 +
   57.17 +    return soplex->nRows() - 1;
   57.18 +  }
   57.19 +
   57.20  
   57.21    void SoplexLp::_eraseCol(int i) {
   57.22      soplex->removeCol(i);
    58.1 --- a/lemon/soplex.h	Thu Nov 05 10:01:02 2009 +0100
    58.2 +++ b/lemon/soplex.h	Thu Nov 05 10:23:16 2009 +0100
    58.3 @@ -84,6 +84,7 @@
    58.4  
    58.5      virtual int _addCol();
    58.6      virtual int _addRow();
    58.7 +    virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
    58.8  
    58.9      virtual void _eraseCol(int i);
   58.10      virtual void _eraseRow(int i);
    59.1 --- a/m4/lx_check_coin.m4	Thu Nov 05 10:01:02 2009 +0100
    59.2 +++ b/m4/lx_check_coin.m4	Thu Nov 05 10:23:16 2009 +0100
    59.3 @@ -88,7 +88,7 @@
    59.4        elif test x"$with_coin" != x"yes"; then
    59.5          CBC_LDFLAGS="-L$with_coin/lib"
    59.6        fi
    59.7 -      CBC_LIBS="-lOsi -lCbc -lOsiCbc -lCbcSolver -lClp -lOsiClp -lCoinUtils -lVol -lOsiVol -lCgl -lm -llapack -lblas"
    59.8 +      CBC_LIBS="-lOsi -lCbc -lCbcSolver -lClp -lOsiClp -lCoinUtils -lVol -lOsiVol -lCgl -lm -llapack -lblas"
    59.9  
   59.10        lx_save_cxxflags="$CXXFLAGS"
   59.11        lx_save_ldflags="$LDFLAGS"
    60.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    60.2 +++ b/scripts/bib2dox.py	Thu Nov 05 10:23:16 2009 +0100
    60.3 @@ -0,0 +1,811 @@
    60.4 +#!/usr/bin/env /usr/local/Python/bin/python2.1
    60.5 +"""
    60.6 +  BibTeX to Doxygen converter
    60.7 +  Usage: python bib2dox.py bibfile.bib > bibfile.dox
    60.8 +
    60.9 +  This code is the modification of the BibTeX to XML converter
   60.10 +  by Vidar Bronken Gundersen et al. See the original copyright notices below. 
   60.11 +
   60.12 +  **********************************************************************
   60.13 +
   60.14 +  Decoder for bibliographic data, BibTeX
   60.15 +  Usage: python bibtex2xml.py bibfile.bib > bibfile.xml
   60.16 +
   60.17 +  v.8
   60.18 +  (c)2002-06-23 Vidar Bronken Gundersen
   60.19 +  http://bibtexml.sf.net/
   60.20 +  Reuse approved as long as this notification is kept.
   60.21 +  Licence: GPL.
   60.22 +
   60.23 +  Contributions/thanks to:
   60.24 +  Egon Willighagen, http://sf.net/projects/jreferences/
   60.25 +  Richard Mahoney (for providing a test case)
   60.26 +
   60.27 +  Editted by Sara Sprenkle to be more robust and handle more bibtex features.
   60.28 +  (c) 2003-01-15
   60.29 +
   60.30 +  1.  Changed bibtex: tags to bibxml: tags.
   60.31 +  2.  Use xmlns:bibxml="http://bibtexml.sf.net/"
   60.32 +  3.  Allow spaces between @type and first {
   60.33 +  4.  "author" fields with multiple authors split by " and "
   60.34 +      are put in separate xml "bibxml:author" tags.
   60.35 +  5.  Option for Titles: words are capitalized
   60.36 +      only if first letter in title or capitalized inside braces
   60.37 +  6.  Removes braces from within field values
   60.38 +  7.  Ignores comments in bibtex file (including @comment{ or % )
   60.39 +  8.  Replaces some special latex tags, e.g., replaces ~ with '&#160;'
   60.40 +  9.  Handles bibtex @string abbreviations
   60.41 +        --> includes bibtex's default abbreviations for months
   60.42 +        --> does concatenation of abbr # " more " and " more " # abbr
   60.43 +  10. Handles @type( ... ) or @type{ ... }
   60.44 +  11. The keywords field is split on , or ; and put into separate xml
   60.45 +      "bibxml:keywords" tags
   60.46 +  12. Ignores @preamble
   60.47 +
   60.48 +  Known Limitations
   60.49 +  1.  Does not transform Latex encoding like math mode and special
   60.50 +      latex symbols.
   60.51 +  2.  Does not parse author fields into first and last names.
   60.52 +      E.g., It does not do anything special to an author whose name is
   60.53 +      in the form LAST_NAME, FIRST_NAME
   60.54 +      In "author" tag, will show up as
   60.55 +      <bibxml:author>LAST_NAME, FIRST_NAME</bibxml:author>
   60.56 +  3.  Does not handle "crossref" fields other than to print
   60.57 +      <bibxml:crossref>...</bibxml:crossref>
   60.58 +  4.  Does not inform user of the input's format errors.  You just won't
   60.59 +      be able to transform the file later with XSL
   60.60 +
   60.61 +  You will have to manually edit the XML output if you need to handle
   60.62 +  these (and unknown) limitations.
   60.63 +
   60.64 +"""
   60.65 +
   60.66 +import string, re
   60.67 +
   60.68 +# set of valid name characters
   60.69 +valid_name_chars = '[\w\-:]'
   60.70 +
   60.71 +#
   60.72 +# define global regular expression variables
   60.73 +#
   60.74 +author_rex = re.compile('\s+and\s+')
   60.75 +rembraces_rex = re.compile('[{}]')
   60.76 +capitalize_rex = re.compile('({[^}]*})')
   60.77 +
   60.78 +# used by bibtexkeywords(data)
   60.79 +keywords_rex = re.compile('[,;]')
   60.80 +
   60.81 +# used by concat_line(line)
   60.82 +concatsplit_rex = re.compile('\s*#\s*')
   60.83 +
   60.84 +# split on {, }, or " in verify_out_of_braces
   60.85 +delimiter_rex = re.compile('([{}"])',re.I)
   60.86 +
   60.87 +field_rex = re.compile('\s*(\w*)\s*=\s*(.*)')
   60.88 +data_rex = re.compile('\s*(\w*)\s*=\s*([^,]*),?')
   60.89 +
   60.90 +url_rex = re.compile('\\\url\{([^}]*)\}')
   60.91 +
   60.92 +#
   60.93 +# styles for html formatting
   60.94 +#
   60.95 +divstyle = 'margin-top: -4ex; margin-left: 8em;'
   60.96 +
   60.97 +#
   60.98 +# return the string parameter without braces
   60.99 +#
  60.100 +def transformurls(str):
  60.101 +    return url_rex.sub(r'<a href="\1">\1</a>', str)
  60.102 +
  60.103 +#
  60.104 +# return the string parameter without braces
  60.105 +#
  60.106 +def removebraces(str):
  60.107 +    return rembraces_rex.sub('', str)
  60.108 +
  60.109 +#
  60.110 +# latex-specific replacements
  60.111 +# (do this after braces were removed)
  60.112 +#
  60.113 +def latexreplacements(line):
  60.114 +    line = string.replace(line, '~', '&nbsp;')
  60.115 +    line = string.replace(line, '\\\'a', '&aacute;')
  60.116 +    line = string.replace(line, '\\"a', '&auml;')
  60.117 +    line = string.replace(line, '\\\'e', '&eacute;')
  60.118 +    line = string.replace(line, '\\"e', '&euml;')
  60.119 +    line = string.replace(line, '\\\'i', '&iacute;')
  60.120 +    line = string.replace(line, '\\"i', '&iuml;')
  60.121 +    line = string.replace(line, '\\\'o', '&oacute;')
  60.122 +    line = string.replace(line, '\\"o', '&ouml;')
  60.123 +    line = string.replace(line, '\\\'u', '&uacute;')
  60.124 +    line = string.replace(line, '\\"u', '&uuml;')
  60.125 +    line = string.replace(line, '\\H o', '&otilde;')
  60.126 +    line = string.replace(line, '\\H u', '&uuml;')   # &utilde; does not exist
  60.127 +    line = string.replace(line, '\\\'A', '&Aacute;')
  60.128 +    line = string.replace(line, '\\"A', '&Auml;')
  60.129 +    line = string.replace(line, '\\\'E', '&Eacute;')
  60.130 +    line = string.replace(line, '\\"E', '&Euml;')
  60.131 +    line = string.replace(line, '\\\'I', '&Iacute;')
  60.132 +    line = string.replace(line, '\\"I', '&Iuml;')
  60.133 +    line = string.replace(line, '\\\'O', '&Oacute;')
  60.134 +    line = string.replace(line, '\\"O', '&Ouml;')
  60.135 +    line = string.replace(line, '\\\'U', '&Uacute;')
  60.136 +    line = string.replace(line, '\\"U', '&Uuml;')
  60.137 +    line = string.replace(line, '\\H O', '&Otilde;')
  60.138 +    line = string.replace(line, '\\H U', '&Uuml;')   # &Utilde; does not exist
  60.139 +
  60.140 +    return line
  60.141 +
  60.142 +#
  60.143 +# copy characters form a string decoding html expressions (&xyz;)
  60.144 +#
  60.145 +def copychars(str, ifrom, count):
  60.146 +    result = ''
  60.147 +    i = ifrom
  60.148 +    c = 0
  60.149 +    html_spec = False
  60.150 +    while (i < len(str)) and (c < count):
  60.151 +        if str[i] == '&':
  60.152 +            html_spec = True;
  60.153 +            if i+1 < len(str):
  60.154 +                result += str[i+1]
  60.155 +            c += 1
  60.156 +            i += 2
  60.157 +        else:
  60.158 +            if not html_spec:
  60.159 +                if ((str[i] >= 'A') and (str[i] <= 'Z')) or \
  60.160 +                   ((str[i] >= 'a') and (str[i] <= 'z')):
  60.161 +                    result += str[i]
  60.162 +                    c += 1
  60.163 +            elif str[i] == ';':
  60.164 +                html_spec = False;
  60.165 +            i += 1
  60.166 +    
  60.167 +    return result
  60.168 +
  60.169 +
  60.170 +# 
  60.171 +# Handle a list of authors (separated by 'and').
  60.172 +# It gives back an array of the follwing values:
  60.173 +#  - num: the number of authors,
  60.174 +#  - list: the list of the author names,
  60.175 +#  - text: the bibtex text (separated by commas and/or 'and')
  60.176 +#  - abbrev: abbreviation that can be used for indicate the
  60.177 +#    bibliography entries
  60.178 +#
  60.179 +def bibtexauthor(data):
  60.180 +    result = {}
  60.181 +    bibtex = ''
  60.182 +    result['list'] = author_rex.split(data)
  60.183 +    result['num'] = len(result['list'])
  60.184 +    for i, author in enumerate(result['list']):
  60.185 +        # general transformations
  60.186 +        author = latexreplacements(removebraces(author.strip()))
  60.187 +        # transform "Xyz, A. B." to "A. B. Xyz"
  60.188 +        pos = author.find(',')
  60.189 +        if pos != -1:
  60.190 +            author = author[pos+1:].strip() + ' ' + author[:pos].strip()
  60.191 +        result['list'][i] = author
  60.192 +        bibtex += author + '#'
  60.193 +    bibtex = bibtex[:-1]
  60.194 +    if result['num'] > 1:
  60.195 +        ix = bibtex.rfind('#')
  60.196 +        if result['num'] == 2:
  60.197 +            bibtex = bibtex[:ix] + ' and ' + bibtex[ix+1:]
  60.198 +        else:
  60.199 +            bibtex = bibtex[:ix] + ', and ' + bibtex[ix+1:]
  60.200 +    bibtex = bibtex.replace('#', ', ')
  60.201 +    result['text'] = bibtex
  60.202 +    
  60.203 +    result['abbrev'] = ''
  60.204 +    for author in result['list']:
  60.205 +        pos = author.rfind(' ') + 1
  60.206 +        count = 1
  60.207 +        if result['num'] == 1:
  60.208 +            count = 3
  60.209 +        result['abbrev'] += copychars(author, pos, count)
  60.210 +
  60.211 +    return result
  60.212 +
  60.213 +
  60.214 +#
  60.215 +# data = title string
  60.216 +# @return the capitalized title (first letter is capitalized), rest are capitalized
  60.217 +# only if capitalized inside braces
  60.218 +#
  60.219 +def capitalizetitle(data):
  60.220 +    title_list = capitalize_rex.split(data)
  60.221 +    title = ''
  60.222 +    count = 0
  60.223 +    for phrase in title_list:
  60.224 +         check = string.lstrip(phrase)
  60.225 +
  60.226 +         # keep phrase's capitalization the same
  60.227 +         if check.find('{') == 0:
  60.228 +              title += removebraces(phrase)
  60.229 +         else:
  60.230 +         # first word --> capitalize first letter (after spaces)
  60.231 +              if count == 0:
  60.232 +                  title += check.capitalize()
  60.233 +              else:
  60.234 +                  title += phrase.lower()
  60.235 +         count = count + 1
  60.236 +
  60.237 +    return title
  60.238 +
  60.239 +
  60.240 +#
  60.241 +# @return the bibtex for the title
  60.242 +# @param data --> title string
  60.243 +# braces are removed from title
  60.244 +#
  60.245 +def bibtextitle(data, entrytype):
  60.246 +    if entrytype in ('book', 'inbook'):
  60.247 +        title = removebraces(data.strip())
  60.248 +    else:
  60.249 +        title = removebraces(capitalizetitle(data.strip()))
  60.250 +    bibtex = title
  60.251 +    return bibtex
  60.252 +
  60.253 +
  60.254 +#
  60.255 +# function to compare entry lists
  60.256 +#
  60.257 +def entry_cmp(x, y):
  60.258 +    return cmp(x[0], y[0])
  60.259 +
  60.260 +
  60.261 +#
  60.262 +# print the XML for the transformed "filecont_source"
  60.263 +#
  60.264 +def bibtexdecoder(filecont_source):
  60.265 +    filecont = []
  60.266 +    file = []
  60.267 +    
  60.268 +    # want @<alphanumeric chars><spaces>{<spaces><any chars>,
  60.269 +    pubtype_rex = re.compile('@(\w*)\s*{\s*(.*),')
  60.270 +    endtype_rex = re.compile('}\s*$')
  60.271 +    endtag_rex = re.compile('^\s*}\s*$')
  60.272 +
  60.273 +    bracefield_rex = re.compile('\s*(\w*)\s*=\s*(.*)')
  60.274 +    bracedata_rex = re.compile('\s*(\w*)\s*=\s*{(.*)},?')
  60.275 +
  60.276 +    quotefield_rex = re.compile('\s*(\w*)\s*=\s*(.*)')
  60.277 +    quotedata_rex = re.compile('\s*(\w*)\s*=\s*"(.*)",?')
  60.278 +
  60.279 +    for line in filecont_source:
  60.280 +        line = line[:-1]
  60.281 +
  60.282 +        # encode character entities
  60.283 +        line = string.replace(line, '&', '&amp;')
  60.284 +        line = string.replace(line, '<', '&lt;')
  60.285 +        line = string.replace(line, '>', '&gt;')
  60.286 +
  60.287 +        # start entry: publication type (store for later use)
  60.288 +        if pubtype_rex.match(line):
  60.289 +        # want @<alphanumeric chars><spaces>{<spaces><any chars>,
  60.290 +            entrycont = {}
  60.291 +            entry = []
  60.292 +            entrytype = pubtype_rex.sub('\g<1>',line)
  60.293 +            entrytype = string.lower(entrytype)
  60.294 +            entryid   = pubtype_rex.sub('\g<2>', line)
  60.295 +
  60.296 +        # end entry if just a }
  60.297 +        elif endtype_rex.match(line):
  60.298 +            # generate doxygen code for the entry
  60.299 +
  60.300 +            # enty type related formattings
  60.301 +            if entrytype in ('book', 'inbook'):
  60.302 +                entrycont['title'] = '<em>' + entrycont['title'] + '</em>'
  60.303 +                if not entrycont.has_key('author'):
  60.304 +                    entrycont['author'] = entrycont['editor']
  60.305 +                    entrycont['author']['text'] += ', editors'
  60.306 +            elif entrytype == 'article':
  60.307 +                entrycont['journal'] = '<em>' + entrycont['journal'] + '</em>'
  60.308 +            elif entrytype in ('inproceedings', 'incollection', 'conference'):
  60.309 +                entrycont['booktitle'] = '<em>' + entrycont['booktitle'] + '</em>'
  60.310 +            elif entrytype == 'techreport':
  60.311 +                if not entrycont.has_key('type'):
  60.312 +                    entrycont['type'] = 'Technical report'
  60.313 +            elif entrytype == 'mastersthesis':
  60.314 +                entrycont['type'] = 'Master\'s thesis'
  60.315 +            elif entrytype == 'phdthesis':
  60.316 +                entrycont['type'] = 'PhD thesis'
  60.317 +
  60.318 +            for eline in entrycont:
  60.319 +                if eline != '':
  60.320 +                    eline = latexreplacements(eline)
  60.321 +
  60.322 +            if entrycont.has_key('pages') and (entrycont['pages'] != ''):
  60.323 +                entrycont['pages'] = string.replace(entrycont['pages'], '--', '-')
  60.324 +
  60.325 +            if entrycont.has_key('author') and (entrycont['author'] != ''):
  60.326 +                entry.append(entrycont['author']['text'] + '.')
  60.327 +            if entrycont.has_key('title') and (entrycont['title'] != ''):
  60.328 +                entry.append(entrycont['title'] + '.')
  60.329 +            if entrycont.has_key('journal') and (entrycont['journal'] != ''):
  60.330 +                entry.append(entrycont['journal'] + ',')
  60.331 +            if entrycont.has_key('booktitle') and (entrycont['booktitle'] != ''):
  60.332 +                entry.append('In ' + entrycont['booktitle'] + ',')
  60.333 +            if entrycont.has_key('type') and (entrycont['type'] != ''):
  60.334 +                eline = entrycont['type']
  60.335 +                if entrycont.has_key('number') and (entrycont['number'] != ''):
  60.336 +                    eline += ' ' + entrycont['number']
  60.337 +                eline += ','
  60.338 +                entry.append(eline)
  60.339 +            if entrycont.has_key('institution') and (entrycont['institution'] != ''):
  60.340 +                entry.append(entrycont['institution'] + ',')
  60.341 +            if entrycont.has_key('publisher') and (entrycont['publisher'] != ''):
  60.342 +                entry.append(entrycont['publisher'] + ',')
  60.343 +            if entrycont.has_key('school') and (entrycont['school'] != ''):
  60.344 +                entry.append(entrycont['school'] + ',')
  60.345 +            if entrycont.has_key('address') and (entrycont['address'] != ''):
  60.346 +                entry.append(entrycont['address'] + ',')
  60.347 +            if entrycont.has_key('edition') and (entrycont['edition'] != ''):
  60.348 +                entry.append(entrycont['edition'] + ' edition,')
  60.349 +            if entrycont.has_key('howpublished') and (entrycont['howpublished'] != ''):
  60.350 +                entry.append(entrycont['howpublished'] + ',')
  60.351 +            if entrycont.has_key('volume') and (entrycont['volume'] != ''):
  60.352 +                eline = entrycont['volume'];
  60.353 +                if entrycont.has_key('number') and (entrycont['number'] != ''):
  60.354 +                    eline += '(' + entrycont['number'] + ')'
  60.355 +                if entrycont.has_key('pages') and (entrycont['pages'] != ''):
  60.356 +                    eline += ':' + entrycont['pages']
  60.357 +                eline += ','
  60.358 +                entry.append(eline)
  60.359 +            else:
  60.360 +                if entrycont.has_key('pages') and (entrycont['pages'] != ''):
  60.361 +                    entry.append('pages ' + entrycont['pages'] + ',')
  60.362 +            if entrycont.has_key('year') and (entrycont['year'] != ''):
  60.363 +                if entrycont.has_key('month') and (entrycont['month'] != ''):
  60.364 +                    entry.append(entrycont['month'] + ' ' + entrycont['year'] + '.')
  60.365 +                else:
  60.366 +                    entry.append(entrycont['year'] + '.')
  60.367 +            if entrycont.has_key('note') and (entrycont['note'] != ''):
  60.368 +                entry.append(entrycont['note'] + '.')
  60.369 +            if entrycont.has_key('url') and (entrycont['url'] != ''):
  60.370 +                entry.append(entrycont['url'] + '.')
  60.371 +
  60.372 +            # generate keys for sorting and for the output
  60.373 +            sortkey = ''
  60.374 +            bibkey = ''
  60.375 +            if entrycont.has_key('author'):
  60.376 +                for author in entrycont['author']['list']:
  60.377 +                    sortkey += copychars(author, author.rfind(' ')+1, len(author))
  60.378 +                bibkey = entrycont['author']['abbrev']
  60.379 +            else:
  60.380 +                bibkey = 'x'
  60.381 +            if entrycont.has_key('year'):
  60.382 +                sortkey += entrycont['year']
  60.383 +                bibkey += entrycont['year'][-2:]
  60.384 +            if entrycont.has_key('title'):
  60.385 +                sortkey += entrycont['title']
  60.386 +            if entrycont.has_key('key'):
  60.387 +                sortkey = entrycont['key'] + sortkey
  60.388 +                bibkey = entrycont['key']
  60.389 +            entry.insert(0, sortkey)
  60.390 +            entry.insert(1, bibkey)
  60.391 +            entry.insert(2, entryid)
  60.392 +           
  60.393 +            # add the entry to the file contents
  60.394 +            filecont.append(entry)
  60.395 +
  60.396 +        else:
  60.397 +            # field, publication info
  60.398 +            field = ''
  60.399 +            data = ''
  60.400 +            
  60.401 +            # field = {data} entries
  60.402 +            if bracedata_rex.match(line):
  60.403 +                field = bracefield_rex.sub('\g<1>', line)
  60.404 +                field = string.lower(field)
  60.405 +                data =  bracedata_rex.sub('\g<2>', line)
  60.406 +
  60.407 +            # field = "data" entries
  60.408 +            elif quotedata_rex.match(line):
  60.409 +                field = quotefield_rex.sub('\g<1>', line)
  60.410 +                field = string.lower(field)
  60.411 +                data =  quotedata_rex.sub('\g<2>', line)
  60.412 +
  60.413 +            # field = data entries
  60.414 +            elif data_rex.match(line):
  60.415 +                field = field_rex.sub('\g<1>', line)
  60.416 +                field = string.lower(field)
  60.417 +                data =  data_rex.sub('\g<2>', line)
  60.418 +
  60.419 +            if field == 'url':
  60.420 +                data = '\\url{' + data.strip() + '}'
  60.421 +            
  60.422 +            if field in ('author', 'editor'):
  60.423 +                entrycont[field] = bibtexauthor(data)
  60.424 +                line = ''
  60.425 +            elif field == 'title':
  60.426 +                line = bibtextitle(data, entrytype)
  60.427 +            elif field != '':
  60.428 +                line = removebraces(transformurls(data.strip()))
  60.429 +
  60.430 +            if line != '':
  60.431 +                line = latexreplacements(line)
  60.432 +                entrycont[field] = line
  60.433 +
  60.434 +
  60.435 +    # sort entries
  60.436 +    filecont.sort(entry_cmp)
  60.437 +    
  60.438 +    # count the bibtex keys
  60.439 +    keytable = {}
  60.440 +    counttable = {}
  60.441 +    for entry in filecont:
  60.442 +        bibkey = entry[1]
  60.443 +        if not keytable.has_key(bibkey):
  60.444 +            keytable[bibkey] = 1
  60.445 +        else:
  60.446 +            keytable[bibkey] += 1
  60.447 +
  60.448 +    for bibkey in keytable.keys():
  60.449 +        counttable[bibkey] = 0
  60.450 +    
  60.451 +    # generate output
  60.452 +    for entry in filecont:
  60.453 +        # generate output key form the bibtex key
  60.454 +        bibkey = entry[1]
  60.455 +        entryid = entry[2]
  60.456 +        if keytable[bibkey] == 1:
  60.457 +            outkey = bibkey
  60.458 +        else:
  60.459 +            outkey = bibkey + chr(97 + counttable[bibkey])
  60.460 +        counttable[bibkey] += 1
  60.461 +        
  60.462 +        # append the entry code to the output
  60.463 +        file.append('\\section ' + entryid + ' [' + outkey + ']')
  60.464 +        file.append('<div style="' + divstyle + '">')
  60.465 +        for line in entry[3:]:
  60.466 +            file.append(line)
  60.467 +        file.append('</div>')
  60.468 +        file.append('')
  60.469 +
  60.470 +    return file
  60.471 +
  60.472 +
  60.473 +#
  60.474 +# return 1 iff abbr is in line but not inside braces or quotes
  60.475 +# assumes that abbr appears only once on the line (out of braces and quotes)
  60.476 +#
  60.477 +def verify_out_of_braces(line, abbr):
  60.478 +
  60.479 +    phrase_split = delimiter_rex.split(line)
  60.480 +
  60.481 +    abbr_rex = re.compile( '\\b' + abbr + '\\b', re.I)
  60.482 +
  60.483 +    open_brace = 0
  60.484 +    open_quote = 0
  60.485 +
  60.486 +    for phrase in phrase_split:
  60.487 +        if phrase == "{":
  60.488 +            open_brace = open_brace + 1
  60.489 +        elif phrase == "}":
  60.490 +            open_brace = open_brace - 1
  60.491 +        elif phrase == '"':
  60.492 +            if open_quote == 1:
  60.493 +                open_quote = 0
  60.494 +            else:
  60.495 +                open_quote = 1
  60.496 +        elif abbr_rex.search(phrase):
  60.497 +            if open_brace == 0 and open_quote == 0:
  60.498 +                return 1
  60.499 +
  60.500 +    return 0
  60.501 +
  60.502 +
  60.503 +#
  60.504 +# a line in the form phrase1 # phrase2 # ... # phrasen
  60.505 +# is returned as phrase1 phrase2 ... phrasen
  60.506 +# with the correct punctuation
  60.507 +# Bug: Doesn't always work with multiple abbreviations plugged in
  60.508 +#
  60.509 +def concat_line(line):
  60.510 +    # only look at part after equals
  60.511 +    field = field_rex.sub('\g<1>',line)
  60.512 +    rest = field_rex.sub('\g<2>',line)
  60.513 +
  60.514 +    concat_line = field + ' ='
  60.515 +
  60.516 +    pound_split = concatsplit_rex.split(rest)
  60.517 +
  60.518 +    phrase_count = 0
  60.519 +    length = len(pound_split)
  60.520 +
  60.521 +    for phrase in pound_split:
  60.522 +        phrase = phrase.strip()
  60.523 +        if phrase_count != 0:
  60.524 +            if phrase.startswith('"') or phrase.startswith('{'):
  60.525 +                phrase = phrase[1:]
  60.526 +        elif phrase.startswith('"'):
  60.527 +            phrase = phrase.replace('"','{',1)
  60.528 +
  60.529 +        if phrase_count != length-1:
  60.530 +            if phrase.endswith('"') or phrase.endswith('}'):
  60.531 +                phrase = phrase[:-1]
  60.532 +        else:
  60.533 +            if phrase.endswith('"'):
  60.534 +                phrase = phrase[:-1]
  60.535 +                phrase = phrase + "}"
  60.536 +            elif phrase.endswith('",'):
  60.537 +                phrase = phrase[:-2]
  60.538 +                phrase = phrase + "},"
  60.539 +
  60.540 +        # if phrase did have \#, add the \# back
  60.541 +        if phrase.endswith('\\'):
  60.542 +            phrase = phrase + "#"
  60.543 +        concat_line = concat_line + ' ' + phrase
  60.544 +
  60.545 +        phrase_count = phrase_count + 1
  60.546 +
  60.547 +    return concat_line
  60.548 +
  60.549 +
  60.550 +#
  60.551 +# substitute abbreviations into filecont
  60.552 +# @param filecont_source - string of data from file
  60.553 +#
  60.554 +def bibtex_replace_abbreviations(filecont_source):
  60.555 +    filecont = filecont_source.splitlines()
  60.556 +
  60.557 +    #  These are defined in bibtex, so we'll define them too
  60.558 +    abbr_list = ['jan','feb','mar','apr','may','jun',
  60.559 +                 'jul','aug','sep','oct','nov','dec']
  60.560 +    value_list = ['January','February','March','April',
  60.561 +                  'May','June','July','August','September',
  60.562 +                  'October','November','December']
  60.563 +
  60.564 +    abbr_rex = []
  60.565 +    total_abbr_count = 0
  60.566 +
  60.567 +    front = '\\b'
  60.568 +    back = '(,?)\\b'
  60.569 +
  60.570 +    for x in abbr_list:
  60.571 +        abbr_rex.append( re.compile( front + abbr_list[total_abbr_count] + back, re.I ) )
  60.572 +        total_abbr_count = total_abbr_count + 1
  60.573 +
  60.574 +
  60.575 +    abbrdef_rex = re.compile('\s*@string\s*{\s*('+ valid_name_chars +'*)\s*=(.*)',
  60.576 +                             re.I)
  60.577 +
  60.578 +    comment_rex = re.compile('@comment\s*{',re.I)
  60.579 +    preamble_rex = re.compile('@preamble\s*{',re.I)
  60.580 +
  60.581 +    waiting_for_end_string = 0
  60.582 +    i = 0
  60.583 +    filecont2 = ''
  60.584 +
  60.585 +    for line in filecont:
  60.586 +        if line == ' ' or line == '':
  60.587 +            continue
  60.588 +
  60.589 +        if waiting_for_end_string:
  60.590 +            if re.search('}',line):
  60.591 +                waiting_for_end_string = 0
  60.592 +                continue
  60.593 +
  60.594 +        if abbrdef_rex.search(line):
  60.595 +            abbr = abbrdef_rex.sub('\g<1>', line)
  60.596 +
  60.597 +            if abbr_list.count(abbr) == 0:
  60.598 +                val = abbrdef_rex.sub('\g<2>', line)
  60.599 +                abbr_list.append(abbr)
  60.600 +                value_list.append(string.strip(val))
  60.601 +                abbr_rex.append( re.compile( front + abbr_list[total_abbr_count] + back, re.I ) )
  60.602 +                total_abbr_count = total_abbr_count + 1
  60.603 +            waiting_for_end_string = 1
  60.604 +            continue
  60.605 +
  60.606 +        if comment_rex.search(line):
  60.607 +            waiting_for_end_string = 1
  60.608 +            continue
  60.609 +
  60.610 +        if preamble_rex.search(line):
  60.611 +            waiting_for_end_string = 1
  60.612 +            continue
  60.613 +
  60.614 +
  60.615 +        # replace subsequent abbreviations with the value
  60.616 +        abbr_count = 0
  60.617 +
  60.618 +        for x in abbr_list:
  60.619 +
  60.620 +            if abbr_rex[abbr_count].search(line):
  60.621 +                if verify_out_of_braces(line,abbr_list[abbr_count]) == 1:
  60.622 +                    line = abbr_rex[abbr_count].sub( value_list[abbr_count] + '\g<1>', line)
  60.623 +                # Check for # concatenations
  60.624 +                if concatsplit_rex.search(line):
  60.625 +                    line = concat_line(line)
  60.626 +            abbr_count = abbr_count + 1
  60.627 +
  60.628 +
  60.629 +        filecont2 = filecont2 + line + '\n'
  60.630 +        i = i+1
  60.631 +
  60.632 +
  60.633 +    # Do one final pass over file
  60.634 +
  60.635 +    # make sure that didn't end up with {" or }" after the substitution
  60.636 +    filecont2 = filecont2.replace('{"','{{')
  60.637 +    filecont2 = filecont2.replace('"}','}}')
  60.638 +
  60.639 +    afterquotevalue_rex = re.compile('"\s*,\s*')
  60.640 +    afterbrace_rex = re.compile('"\s*}')
  60.641 +    afterbracevalue_rex = re.compile('(=\s*{[^=]*)},\s*')
  60.642 +
  60.643 +    # add new lines to data that changed because of abbreviation substitutions
  60.644 +    filecont2 = afterquotevalue_rex.sub('",\n', filecont2)
  60.645 +    filecont2 = afterbrace_rex.sub('"\n}', filecont2)
  60.646 +    filecont2 = afterbracevalue_rex.sub('\g<1>},\n', filecont2)
  60.647 +
  60.648 +    return filecont2
  60.649 +
  60.650 +#
  60.651 +# convert @type( ... ) to @type{ ... }
  60.652 +#
  60.653 +def no_outer_parens(filecont):
  60.654 +
  60.655 +    # do checking for open parens
  60.656 +    # will convert to braces
  60.657 +    paren_split = re.split('([(){}])',filecont)
  60.658 +
  60.659 +    open_paren_count = 0
  60.660 +    open_type = 0
  60.661 +    look_next = 0
  60.662 +
  60.663 +    # rebuild filecont
  60.664 +    filecont = ''
  60.665 +
  60.666 +    at_rex = re.compile('@\w*')
  60.667 +
  60.668 +    for phrase in paren_split:
  60.669 +        if look_next == 1:
  60.670 +            if phrase == '(':
  60.671 +                phrase = '{'
  60.672 +                open_paren_count = open_paren_count + 1
  60.673 +            else:
  60.674 +                open_type = 0
  60.675 +            look_next = 0
  60.676 +
  60.677 +        if phrase == '(':
  60.678 +            open_paren_count = open_paren_count + 1
  60.679 +
  60.680 +        elif phrase == ')':
  60.681 +            open_paren_count = open_paren_count - 1
  60.682 +            if open_type == 1 and open_paren_count == 0:
  60.683 +                phrase = '}'
  60.684 +                open_type = 0
  60.685 +
  60.686 +        elif at_rex.search( phrase ):
  60.687 +            open_type = 1
  60.688 +            look_next = 1
  60.689 +
  60.690 +        filecont = filecont + phrase
  60.691 +
  60.692 +    return filecont
  60.693 +
  60.694 +
  60.695 +#
  60.696 +# make all whitespace into just one space
  60.697 +# format the bibtex file into a usable form.
  60.698 +#
  60.699 +def bibtexwasher(filecont_source):
  60.700 +
  60.701 +    space_rex = re.compile('\s+')
  60.702 +    comment_rex = re.compile('\s*%')
  60.703 +
  60.704 +    filecont = []
  60.705 +
  60.706 +    # remove trailing and excessive whitespace
  60.707 +    # ignore comments
  60.708 +    for line in filecont_source:
  60.709 +        line = string.strip(line)
  60.710 +        line = space_rex.sub(' ', line)
  60.711 +        # ignore comments
  60.712 +        if not comment_rex.match(line) and line != '':
  60.713 +            filecont.append(' '+ line)
  60.714 +
  60.715 +    filecont = string.join(filecont, '')
  60.716 +
  60.717 +    # the file is in one long string
  60.718 +
  60.719 +    filecont = no_outer_parens(filecont)
  60.720 +
  60.721 +    #
  60.722 +    # split lines according to preferred syntax scheme
  60.723 +    #
  60.724 +    filecont = re.sub('(=\s*{[^=]*)},', '\g<1>},\n', filecont)
  60.725 +
  60.726 +    # add new lines after commas that are after values
  60.727 +    filecont = re.sub('"\s*,', '",\n', filecont)
  60.728 +    filecont = re.sub('=\s*([\w\d]+)\s*,', '= \g<1>,\n', filecont)
  60.729 +    filecont = re.sub('(@\w*)\s*({(\s*)[^,\s]*)\s*,',
  60.730 +                          '\n\n\g<1>\g<2>,\n', filecont)
  60.731 +
  60.732 +    # add new lines after }
  60.733 +    filecont = re.sub('"\s*}','"\n}\n', filecont)
  60.734 +    filecont = re.sub('}\s*,','},\n', filecont)
  60.735 +
  60.736 +
  60.737 +    filecont = re.sub('@(\w*)', '\n@\g<1>', filecont)
  60.738 +
  60.739 +    # character encoding, reserved latex characters
  60.740 +    filecont = re.sub('{\\\&}', '&', filecont)
  60.741 +    filecont = re.sub('\\\&', '&', filecont)
  60.742 +
  60.743 +    # do checking for open braces to get format correct
  60.744 +    open_brace_count = 0
  60.745 +    brace_split = re.split('([{}])',filecont)
  60.746 +
  60.747 +    # rebuild filecont
  60.748 +    filecont = ''
  60.749 +
  60.750 +    for phrase in brace_split:
  60.751 +        if phrase == '{':
  60.752 +            open_brace_count = open_brace_count + 1
  60.753 +        elif phrase == '}':
  60.754 +            open_brace_count = open_brace_count - 1
  60.755 +            if open_brace_count == 0:
  60.756 +                filecont = filecont + '\n'
  60.757 +
  60.758 +        filecont = filecont + phrase
  60.759 +
  60.760 +    filecont2 = bibtex_replace_abbreviations(filecont)
  60.761 +
  60.762 +    # gather
  60.763 +    filecont = filecont2.splitlines()
  60.764 +    i=0
  60.765 +    j=0         # count the number of blank lines
  60.766 +    for line in filecont:
  60.767 +        # ignore blank lines
  60.768 +        if line == '' or line == ' ':
  60.769 +            j = j+1
  60.770 +            continue
  60.771 +        filecont[i] = line + '\n'
  60.772 +        i = i+1
  60.773 +
  60.774 +    # get rid of the extra stuff at the end of the array
  60.775 +    # (The extra stuff are duplicates that are in the array because
  60.776 +    # blank lines were removed.)
  60.777 +    length = len( filecont)
  60.778 +    filecont[length-j:length] = []
  60.779 +
  60.780 +    return filecont
  60.781 +
  60.782 +
  60.783 +def filehandler(filepath):
  60.784 +    try:
  60.785 +        fd = open(filepath, 'r')
  60.786 +        filecont_source = fd.readlines()
  60.787 +        fd.close()
  60.788 +    except:
  60.789 +        print 'Could not open file:', filepath
  60.790 +    washeddata = bibtexwasher(filecont_source)
  60.791 +    outdata = bibtexdecoder(washeddata)
  60.792 +    print '/**'
  60.793 +    print '\page references References'
  60.794 +    print
  60.795 +    for line in outdata:
  60.796 +        print line
  60.797 +    print '*/'
  60.798 +
  60.799 +
  60.800 +# main program
  60.801 +
  60.802 +def main():
  60.803 +    import sys
  60.804 +    if sys.argv[1:]:
  60.805 +        filepath = sys.argv[1]
  60.806 +    else:
  60.807 +        print "No input file"
  60.808 +        sys.exit()
  60.809 +    filehandler(filepath)
  60.810 +
  60.811 +if __name__ == "__main__": main()
  60.812 +
  60.813 +
  60.814 +# end python script
    61.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    61.2 +++ b/scripts/bootstrap.sh	Thu Nov 05 10:23:16 2009 +0100
    61.3 @@ -0,0 +1,134 @@
    61.4 +#!/bin/bash
    61.5 +#
    61.6 +# This file is a part of LEMON, a generic C++ optimization library.
    61.7 +#
    61.8 +# Copyright (C) 2003-2009
    61.9 +# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   61.10 +# (Egervary Research Group on Combinatorial Optimization, EGRES).
   61.11 +#
   61.12 +# Permission to use, modify and distribute this software is granted
   61.13 +# provided that this copyright notice appears in all copies. For
   61.14 +# precise terms see the accompanying LICENSE file.
   61.15 +#
   61.16 +# This software is provided "AS IS" with no warranty of any kind,
   61.17 +# express or implied, and with no claim as to its suitability for any
   61.18 +# purpose.
   61.19 +
   61.20 +
   61.21 +if [ ! -f ~/.lemon-bootstrap ]; then
   61.22 +    echo 'Create ~/.lemon-bootstrap'.
   61.23 +    cat >~/.lemon-bootstrap <<EOF
   61.24 +#
   61.25 +# Default settings for bootstraping the LEMON source code repository
   61.26 +#
   61.27 +EOF
   61.28 +fi
   61.29 +
   61.30 +source ~/.lemon-bootstrap
   61.31 +if [ -f ../../../.lemon-bootstrap ]; then source ../../../.lemon-bootstrap; fi
   61.32 +if [ -f ../../.lemon-bootstrap ]; then source ../../.lemon-bootstrap; fi
   61.33 +if [ -f ../.lemon-bootstrap ]; then source ../.lemon-bootstrap; fi
   61.34 +if [ -f ./.lemon-bootstrap ]; then source ./.lemon-bootstrap; fi
   61.35 +
   61.36 +
   61.37 +function augment_config() { 
   61.38 +    if [ "x${!1}" == "x" ]; then
   61.39 +        eval $1=$2
   61.40 +        echo Add "'$1'" to '~/.lemon-bootstrap'.
   61.41 +        echo >>~/.lemon-bootstrap
   61.42 +        echo $3 >>~/.lemon-bootstrap
   61.43 +        echo $1=$2 >>~/.lemon-bootstrap
   61.44 +    fi
   61.45 +}
   61.46 +
   61.47 +augment_config LEMON_INSTALL_PREFIX /usr/local \
   61.48 +    "# LEMON installation prefix"
   61.49 +
   61.50 +augment_config COIN_OR_PREFIX /usr/local/coin-or \
   61.51 +    "# COIN-OR installation root prefix (used for CLP/CBC)"
   61.52 +
   61.53 +augment_config SOPLEX_PREFIX /usr/local/soplex \
   61.54 +    "# Soplex build prefix"
   61.55 +
   61.56 +
   61.57 +function ask() {
   61.58 +echo -n "$1 [$2]? "
   61.59 +read _an
   61.60 +if [ "x$_an" == "x" ]; then
   61.61 +    ret="$2"
   61.62 +else
   61.63 +    ret=$_an
   61.64 +fi
   61.65 +}
   61.66 +
   61.67 +function yesorno() {
   61.68 +    ret='rossz'
   61.69 +    while [ "$ret" != "y" -a "$ret" != "n" -a "$ret" != "yes" -a "$ret" != "no" ]; do
   61.70 +        ask "$1" "$2"
   61.71 +    done
   61.72 +    if [ "$ret" != "y" -a "$ret" != "yes" ]; then
   61.73 +        return 1
   61.74 +    else
   61.75 +        return 0
   61.76 +    fi
   61.77 +}
   61.78 +
   61.79 +if yesorno "External build" "n"
   61.80 +then
   61.81 +    CONFIGURE_PATH=".."
   61.82 +else
   61.83 +    CONFIGURE_PATH="."
   61.84 +    if yesorno "Autoreconf" "y"
   61.85 +    then
   61.86 +        AUTORE=yes
   61.87 +    else
   61.88 +        AUTORE=no
   61.89 +    fi
   61.90 +fi
   61.91 +
   61.92 +if yesorno "Optimize" "n" 
   61.93 +then
   61.94 +    opt_flags=' -O2'
   61.95 +else
   61.96 +    opt_flags=''
   61.97 +fi
   61.98 +
   61.99 +if yesorno "Stop on warning" "y" 
  61.100 +then
  61.101 +    werror_flags=' -Werror'
  61.102 +else
  61.103 +    werror_flags=''
  61.104 +fi
  61.105 +
  61.106 +cxx_flags="CXXFLAGS=-ggdb$opt_flags$werror_flags"
  61.107 +
  61.108 +if [ -f ${COIN_OR_PREFIX}/include/coin/config_coinutils.h ]; then
  61.109 +    if yesorno "Use COIN-OR (CBC/CLP)" "n"
  61.110 +    then
  61.111 +        coin_flag="--with-coin=$COIN_OR_PREFIX"
  61.112 +    else
  61.113 +        coin_flag=""
  61.114 +    fi
  61.115 +else
  61.116 +    coin_flag=""        
  61.117 +fi
  61.118 +
  61.119 +if [ -f ${SOPLEX_PREFIX}/src/soplex.h ]; then
  61.120 +    if yesorno "Use Soplex" "n"
  61.121 +    then
  61.122 +        soplex_flag="--with-soplex=$SOPLEX_PREFIX"
  61.123 +    else
  61.124 +        soplex_flag=""
  61.125 +    fi
  61.126 +else
  61.127 +    soplex_flag=""
  61.128 +fi
  61.129 +
  61.130 +if [ "x$AUTORE" == "xyes" ]; then
  61.131 +    autoreconf -vif;
  61.132 +fi
  61.133 +${CONFIGURE_PATH}/configure --prefix=$LEMON_INSTALL_PREFIX \
  61.134 +"$cxx_flags" \
  61.135 +$coin_flag \
  61.136 +$soplex_flag \
  61.137 +$*
    62.1 --- a/scripts/chg-len.py	Thu Nov 05 10:01:02 2009 +0100
    62.2 +++ b/scripts/chg-len.py	Thu Nov 05 10:23:16 2009 +0100
    62.3 @@ -1,4 +1,18 @@
    62.4  #! /usr/bin/env python
    62.5 +#
    62.6 +# This file is a part of LEMON, a generic C++ optimization library.
    62.7 +#
    62.8 +# Copyright (C) 2003-2009
    62.9 +# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   62.10 +# (Egervary Research Group on Combinatorial Optimization, EGRES).
   62.11 +#
   62.12 +# Permission to use, modify and distribute this software is granted
   62.13 +# provided that this copyright notice appears in all copies. For
   62.14 +# precise terms see the accompanying LICENSE file.
   62.15 +#
   62.16 +# This software is provided "AS IS" with no warranty of any kind,
   62.17 +# express or implied, and with no claim as to its suitability for any
   62.18 +# purpose.
   62.19  
   62.20  import sys
   62.21  
    63.1 --- a/scripts/mk-release.sh	Thu Nov 05 10:01:02 2009 +0100
    63.2 +++ b/scripts/mk-release.sh	Thu Nov 05 10:23:16 2009 +0100
    63.3 @@ -1,4 +1,18 @@
    63.4  #!/bin/bash
    63.5 +#
    63.6 +# This file is a part of LEMON, a generic C++ optimization library.
    63.7 +#
    63.8 +# Copyright (C) 2003-2009
    63.9 +# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   63.10 +# (Egervary Research Group on Combinatorial Optimization, EGRES).
   63.11 +#
   63.12 +# Permission to use, modify and distribute this software is granted
   63.13 +# provided that this copyright notice appears in all copies. For
   63.14 +# precise terms see the accompanying LICENSE file.
   63.15 +#
   63.16 +# This software is provided "AS IS" with no warranty of any kind,
   63.17 +# express or implied, and with no claim as to its suitability for any
   63.18 +# purpose.
   63.19  
   63.20  set -e
   63.21  
    64.1 --- a/scripts/unify-sources.sh	Thu Nov 05 10:01:02 2009 +0100
    64.2 +++ b/scripts/unify-sources.sh	Thu Nov 05 10:23:16 2009 +0100
    64.3 @@ -1,4 +1,18 @@
    64.4  #!/bin/bash
    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  YEAR=`date +%Y`
   64.21  HGROOT=`hg root`
    65.1 --- a/test/CMakeLists.txt	Thu Nov 05 10:01:02 2009 +0100
    65.2 +++ b/test/CMakeLists.txt	Thu Nov 05 10:23:16 2009 +0100
    65.3 @@ -9,6 +9,7 @@
    65.4  
    65.5  SET(TESTS
    65.6    adaptors_test
    65.7 +  bellman_ford_test
    65.8    bfs_test
    65.9    circulation_test
   65.10    connectivity_test
   65.11 @@ -31,6 +32,7 @@
   65.12    matching_test
   65.13    min_cost_arborescence_test
   65.14    min_cost_flow_test
   65.15 +  min_mean_cycle_test
   65.16    path_test
   65.17    preflow_test
   65.18    radix_sort_test
    66.1 --- a/test/Makefile.am	Thu Nov 05 10:01:02 2009 +0100
    66.2 +++ b/test/Makefile.am	Thu Nov 05 10:23:16 2009 +0100
    66.3 @@ -7,6 +7,7 @@
    66.4  
    66.5  check_PROGRAMS += \
    66.6  	test/adaptors_test \
    66.7 +	test/bellman_ford_test \
    66.8  	test/bfs_test \
    66.9  	test/circulation_test \
   66.10  	test/connectivity_test \
   66.11 @@ -29,6 +30,7 @@
   66.12  	test/matching_test \
   66.13  	test/min_cost_arborescence_test \
   66.14  	test/min_cost_flow_test \
   66.15 +	test/min_mean_cycle_test \
   66.16  	test/path_test \
   66.17  	test/preflow_test \
   66.18  	test/radix_sort_test \
   66.19 @@ -52,6 +54,7 @@
   66.20  XFAIL_TESTS += test/test_tools_fail$(EXEEXT)
   66.21  
   66.22  test_adaptors_test_SOURCES = test/adaptors_test.cc
   66.23 +test_bellman_ford_test_SOURCES = test/bellman_ford_test.cc
   66.24  test_bfs_test_SOURCES = test/bfs_test.cc
   66.25  test_circulation_test_SOURCES = test/circulation_test.cc
   66.26  test_counter_test_SOURCES = test/counter_test.cc
   66.27 @@ -76,6 +79,7 @@
   66.28  test_matching_test_SOURCES = test/matching_test.cc
   66.29  test_min_cost_arborescence_test_SOURCES = test/min_cost_arborescence_test.cc
   66.30  test_min_cost_flow_test_SOURCES = test/min_cost_flow_test.cc
   66.31 +test_min_mean_cycle_test_SOURCES = test/min_mean_cycle_test.cc
   66.32  test_path_test_SOURCES = test/path_test.cc
   66.33  test_preflow_test_SOURCES = test/preflow_test.cc
   66.34  test_radix_sort_test_SOURCES = test/radix_sort_test.cc
    67.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    67.2 +++ b/test/bellman_ford_test.cc	Thu Nov 05 10:23:16 2009 +0100
    67.3 @@ -0,0 +1,283 @@
    67.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
    67.5 + *
    67.6 + * This file is a part of LEMON, a generic C++ optimization library.
    67.7 + *
    67.8 + * Copyright (C) 2003-2009
    67.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   67.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
   67.11 + *
   67.12 + * Permission to use, modify and distribute this software is granted
   67.13 + * provided that this copyright notice appears in all copies. For
   67.14 + * precise terms see the accompanying LICENSE file.
   67.15 + *
   67.16 + * This software is provided "AS IS" with no warranty of any kind,
   67.17 + * express or implied, and with no claim as to its suitability for any
   67.18 + * purpose.
   67.19 + *
   67.20 + */
   67.21 +
   67.22 +#include <lemon/concepts/digraph.h>
   67.23 +#include <lemon/smart_graph.h>
   67.24 +#include <lemon/list_graph.h>
   67.25 +#include <lemon/lgf_reader.h>
   67.26 +#include <lemon/bellman_ford.h>
   67.27 +#include <lemon/path.h>
   67.28 +
   67.29 +#include "graph_test.h"
   67.30 +#include "test_tools.h"
   67.31 +
   67.32 +using namespace lemon;
   67.33 +
   67.34 +char test_lgf[] =
   67.35 +  "@nodes\n"
   67.36 +  "label\n"
   67.37 +  "0\n"
   67.38 +  "1\n"
   67.39 +  "2\n"
   67.40 +  "3\n"
   67.41 +  "4\n"
   67.42 +  "@arcs\n"
   67.43 +  "    length\n"
   67.44 +  "0 1 3\n"
   67.45 +  "1 2 -3\n"
   67.46 +  "1 2 -5\n"
   67.47 +  "1 3 -2\n"
   67.48 +  "0 2 -1\n"
   67.49 +  "1 2 -4\n"
   67.50 +  "0 3 2\n"
   67.51 +  "4 2 -5\n"
   67.52 +  "2 3 1\n"
   67.53 +  "@attributes\n"
   67.54 +  "source 0\n"
   67.55 +  "target 3\n";
   67.56 +
   67.57 +
   67.58 +void checkBellmanFordCompile()
   67.59 +{
   67.60 +  typedef int Value;
   67.61 +  typedef concepts::Digraph Digraph;
   67.62 +  typedef concepts::ReadMap<Digraph::Arc,Value> LengthMap;
   67.63 +  typedef BellmanFord<Digraph, LengthMap> BF;
   67.64 +  typedef Digraph::Node Node;
   67.65 +  typedef Digraph::Arc Arc;
   67.66 +
   67.67 +  Digraph gr;
   67.68 +  Node s, t, n;
   67.69 +  Arc e;
   67.70 +  Value l;
   67.71 +  int k;
   67.72 +  bool b;
   67.73 +  BF::DistMap d(gr);
   67.74 +  BF::PredMap p(gr);
   67.75 +  LengthMap length;
   67.76 +  concepts::Path<Digraph> pp;
   67.77 +
   67.78 +  {
   67.79 +    BF bf_test(gr,length);
   67.80 +    const BF& const_bf_test = bf_test;
   67.81 +
   67.82 +    bf_test.run(s);
   67.83 +    bf_test.run(s,k);
   67.84 +
   67.85 +    bf_test.init();
   67.86 +    bf_test.addSource(s);
   67.87 +    bf_test.addSource(s, 1);
   67.88 +    b = bf_test.processNextRound();
   67.89 +    b = bf_test.processNextWeakRound();
   67.90 +
   67.91 +    bf_test.start();
   67.92 +    bf_test.checkedStart();
   67.93 +    bf_test.limitedStart(k);
   67.94 +
   67.95 +    l  = const_bf_test.dist(t);
   67.96 +    e  = const_bf_test.predArc(t);
   67.97 +    s  = const_bf_test.predNode(t);
   67.98 +    b  = const_bf_test.reached(t);
   67.99 +    d  = const_bf_test.distMap();
  67.100 +    p  = const_bf_test.predMap();
  67.101 +    pp = const_bf_test.path(t);
  67.102 +    
  67.103 +    for (BF::ActiveIt it(const_bf_test); it != INVALID; ++it) {}
  67.104 +  }
  67.105 +  {
  67.106 +    BF::SetPredMap<concepts::ReadWriteMap<Node,Arc> >
  67.107 +      ::SetDistMap<concepts::ReadWriteMap<Node,Value> >
  67.108 +      ::SetOperationTraits<BellmanFordDefaultOperationTraits<Value> >
  67.109 +      ::Create bf_test(gr,length);
  67.110 +
  67.111 +    LengthMap length_map;
  67.112 +    concepts::ReadWriteMap<Node,Arc> pred_map;
  67.113 +    concepts::ReadWriteMap<Node,Value> dist_map;
  67.114 +    
  67.115 +    bf_test
  67.116 +      .lengthMap(length_map)
  67.117 +      .predMap(pred_map)
  67.118 +      .distMap(dist_map);
  67.119 +
  67.120 +    bf_test.run(s);
  67.121 +    bf_test.run(s,k);
  67.122 +
  67.123 +    bf_test.init();
  67.124 +    bf_test.addSource(s);
  67.125 +    bf_test.addSource(s, 1);
  67.126 +    b = bf_test.processNextRound();
  67.127 +    b = bf_test.processNextWeakRound();
  67.128 +
  67.129 +    bf_test.start();
  67.130 +    bf_test.checkedStart();
  67.131 +    bf_test.limitedStart(k);
  67.132 +
  67.133 +    l  = bf_test.dist(t);
  67.134 +    e  = bf_test.predArc(t);
  67.135 +    s  = bf_test.predNode(t);
  67.136 +    b  = bf_test.reached(t);
  67.137 +    pp = bf_test.path(t);
  67.138 +  }
  67.139 +}
  67.140 +
  67.141 +void checkBellmanFordFunctionCompile()
  67.142 +{
  67.143 +  typedef int Value;
  67.144 +  typedef concepts::Digraph Digraph;
  67.145 +  typedef Digraph::Arc Arc;
  67.146 +  typedef Digraph::Node Node;
  67.147 +  typedef concepts::ReadMap<Digraph::Arc,Value> LengthMap;
  67.148 +
  67.149 +  Digraph g;
  67.150 +  bool b;
  67.151 +  bellmanFord(g,LengthMap()).run(Node());
  67.152 +  b = bellmanFord(g,LengthMap()).run(Node(),Node());
  67.153 +  bellmanFord(g,LengthMap())
  67.154 +    .predMap(concepts::ReadWriteMap<Node,Arc>())
  67.155 +    .distMap(concepts::ReadWriteMap<Node,Value>())
  67.156 +    .run(Node());
  67.157 +  b=bellmanFord(g,LengthMap())
  67.158 +    .predMap(concepts::ReadWriteMap<Node,Arc>())
  67.159 +    .distMap(concepts::ReadWriteMap<Node,Value>())
  67.160 +    .path(concepts::Path<Digraph>())
  67.161 +    .dist(Value())
  67.162 +    .run(Node(),Node());
  67.163 +}
  67.164 +
  67.165 +
  67.166 +template <typename Digraph, typename Value>
  67.167 +void checkBellmanFord() {
  67.168 +  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
  67.169 +  typedef typename Digraph::template ArcMap<Value> LengthMap;
  67.170 +
  67.171 +  Digraph gr;
  67.172 +  Node s, t;
  67.173 +  LengthMap length(gr);
  67.174 +
  67.175 +  std::istringstream input(test_lgf);
  67.176 +  digraphReader(gr, input).
  67.177 +    arcMap("length", length).
  67.178 +    node("source", s).
  67.179 +    node("target", t).
  67.180 +    run();
  67.181 +
  67.182 +  BellmanFord<Digraph, LengthMap>
  67.183 +    bf(gr, length);
  67.184 +  bf.run(s);
  67.185 +  Path<Digraph> p = bf.path(t);
  67.186 +
  67.187 +  check(bf.reached(t) && bf.dist(t) == -1, "Bellman-Ford found a wrong path.");
  67.188 +  check(p.length() == 3, "path() found a wrong path.");
  67.189 +  check(checkPath(gr, p), "path() found a wrong path.");
  67.190 +  check(pathSource(gr, p) == s, "path() found a wrong path.");
  67.191 +  check(pathTarget(gr, p) == t, "path() found a wrong path.");
  67.192 +  
  67.193 +  ListPath<Digraph> path;
  67.194 +  Value dist;
  67.195 +  bool reached = bellmanFord(gr,length).path(path).dist(dist).run(s,t);
  67.196 +
  67.197 +  check(reached && dist == -1, "Bellman-Ford found a wrong path.");
  67.198 +  check(path.length() == 3, "path() found a wrong path.");
  67.199 +  check(checkPath(gr, path), "path() found a wrong path.");
  67.200 +  check(pathSource(gr, path) == s, "path() found a wrong path.");
  67.201 +  check(pathTarget(gr, path) == t, "path() found a wrong path.");
  67.202 +
  67.203 +  for(ArcIt e(gr); e!=INVALID; ++e) {
  67.204 +    Node u=gr.source(e);
  67.205 +    Node v=gr.target(e);
  67.206 +    check(!bf.reached(u) || (bf.dist(v) - bf.dist(u) <= length[e]),
  67.207 +          "Wrong output. dist(target)-dist(source)-arc_length=" <<
  67.208 +          bf.dist(v) - bf.dist(u) - length[e]);
  67.209 +  }
  67.210 +
  67.211 +  for(NodeIt v(gr); v!=INVALID; ++v) {
  67.212 +    if (bf.reached(v)) {
  67.213 +      check(v==s || bf.predArc(v)!=INVALID, "Wrong tree.");
  67.214 +      if (bf.predArc(v)!=INVALID ) {
  67.215 +        Arc e=bf.predArc(v);
  67.216 +        Node u=gr.source(e);
  67.217 +        check(u==bf.predNode(v),"Wrong tree.");
  67.218 +        check(bf.dist(v) - bf.dist(u) == length[e],
  67.219 +              "Wrong distance! Difference: " <<
  67.220 +              bf.dist(v) - bf.dist(u) - length[e]);
  67.221 +      }
  67.222 +    }
  67.223 +  }
  67.224 +}
  67.225 +
  67.226 +void checkBellmanFordNegativeCycle() {
  67.227 +  DIGRAPH_TYPEDEFS(SmartDigraph);
  67.228 +
  67.229 +  SmartDigraph gr;
  67.230 +  IntArcMap length(gr);
  67.231 +  
  67.232 +  Node n1 = gr.addNode();
  67.233 +  Node n2 = gr.addNode();
  67.234 +  Node n3 = gr.addNode();
  67.235 +  Node n4 = gr.addNode();
  67.236 +  
  67.237 +  Arc a1 = gr.addArc(n1, n2);
  67.238 +  Arc a2 = gr.addArc(n2, n2);
  67.239 +  
  67.240 +  length[a1] = 2;
  67.241 +  length[a2] = -1;
  67.242 +  
  67.243 +  {
  67.244 +    BellmanFord<SmartDigraph, IntArcMap> bf(gr, length);
  67.245 +    bf.run(n1);
  67.246 +    StaticPath<SmartDigraph> p = bf.negativeCycle();
  67.247 +    check(p.length() == 1 && p.front() == p.back() && p.front() == a2,
  67.248 +          "Wrong negative cycle.");
  67.249 +  }
  67.250 + 
  67.251 +  length[a2] = 0;
  67.252 +  
  67.253 +  {
  67.254 +    BellmanFord<SmartDigraph, IntArcMap> bf(gr, length);
  67.255 +    bf.run(n1);
  67.256 +    check(bf.negativeCycle().empty(),
  67.257 +          "Negative cycle should not be found.");
  67.258 +  }
  67.259 +  
  67.260 +  length[gr.addArc(n1, n3)] = 5;
  67.261 +  length[gr.addArc(n4, n3)] = 1;
  67.262 +  length[gr.addArc(n2, n4)] = 2;
  67.263 +  length[gr.addArc(n3, n2)] = -4;
  67.264 +  
  67.265 +  {
  67.266 +    BellmanFord<SmartDigraph, IntArcMap> bf(gr, length);
  67.267 +    bf.init();
  67.268 +    bf.addSource(n1);
  67.269 +    for (int i = 0; i < 4; ++i) {
  67.270 +      check(bf.negativeCycle().empty(),
  67.271 +            "Negative cycle should not be found.");
  67.272 +      bf.processNextRound();
  67.273 +    }
  67.274 +    StaticPath<SmartDigraph> p = bf.negativeCycle();
  67.275 +    check(p.length() == 3, "Wrong negative cycle.");
  67.276 +    check(length[p.nth(0)] + length[p.nth(1)] + length[p.nth(2)] == -1,
  67.277 +          "Wrong negative cycle.");
  67.278 +  }
  67.279 +}
  67.280 +
  67.281 +int main() {
  67.282 +  checkBellmanFord<ListDigraph, int>();
  67.283 +  checkBellmanFord<SmartDigraph, double>();
  67.284 +  checkBellmanFordNegativeCycle();
  67.285 +  return 0;
  67.286 +}
    68.1 --- a/test/circulation_test.cc	Thu Nov 05 10:01:02 2009 +0100
    68.2 +++ b/test/circulation_test.cc	Thu Nov 05 10:23:16 2009 +0100
    68.3 @@ -87,6 +87,11 @@
    68.4      .upperMap(ucap)
    68.5      .supplyMap(supply)
    68.6      .flowMap(flow);
    68.7 +  
    68.8 +  const CirculationType::Elevator& elev = const_circ_test.elevator();
    68.9 +  circ_test.elevator(const_cast<CirculationType::Elevator&>(elev));
   68.10 +  CirculationType::Tolerance tol = const_circ_test.tolerance();
   68.11 +  circ_test.tolerance(tol);
   68.12  
   68.13    circ_test.init();
   68.14    circ_test.greedyInit();
    69.1 --- a/test/digraph_test.cc	Thu Nov 05 10:01:02 2009 +0100
    69.2 +++ b/test/digraph_test.cc	Thu Nov 05 10:23:16 2009 +0100
    69.3 @@ -36,6 +36,9 @@
    69.4    checkGraphNodeList(G, 0);
    69.5    checkGraphArcList(G, 0);
    69.6  
    69.7 +  G.reserveNode(3);
    69.8 +  G.reserveArc(4);
    69.9 +
   69.10    Node
   69.11      n1 = G.addNode(),
   69.12      n2 = G.addNode(),
   69.13 @@ -284,6 +287,14 @@
   69.14    G.addArc(G.addNode(), G.addNode());
   69.15  
   69.16    snapshot.restore();
   69.17 +  snapshot.save(G);
   69.18 +
   69.19 +  checkGraphNodeList(G, 4);
   69.20 +  checkGraphArcList(G, 4);
   69.21 +
   69.22 +  G.addArc(G.addNode(), G.addNode());
   69.23 +
   69.24 +  snapshot.restore();
   69.25  
   69.26    checkGraphNodeList(G, 4);
   69.27    checkGraphArcList(G, 4);
   69.28 @@ -487,7 +498,12 @@
   69.29  void checkFullDigraph(int num) {
   69.30    typedef FullDigraph Digraph;
   69.31    DIGRAPH_TYPEDEFS(Digraph);
   69.32 +
   69.33    Digraph G(num);
   69.34 +  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
   69.35 +
   69.36 +  G.resize(num);
   69.37 +  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
   69.38  
   69.39    checkGraphNodeList(G, num);
   69.40    checkGraphArcList(G, num * num);
    70.1 --- a/test/graph_test.cc	Thu Nov 05 10:01:02 2009 +0100
    70.2 +++ b/test/graph_test.cc	Thu Nov 05 10:23:16 2009 +0100
    70.3 @@ -38,6 +38,9 @@
    70.4    checkGraphEdgeList(G, 0);
    70.5    checkGraphArcList(G, 0);
    70.6  
    70.7 +  G.reserveNode(3);
    70.8 +  G.reserveEdge(3);
    70.9 +
   70.10    Node
   70.11      n1 = G.addNode(),
   70.12      n2 = G.addNode(),
   70.13 @@ -256,6 +259,15 @@
   70.14    G.addEdge(G.addNode(), G.addNode());
   70.15  
   70.16    snapshot.restore();
   70.17 +  snapshot.save(G);
   70.18 +
   70.19 +  checkGraphNodeList(G, 4);
   70.20 +  checkGraphEdgeList(G, 3);
   70.21 +  checkGraphArcList(G, 6);
   70.22 +  
   70.23 +  G.addEdge(G.addNode(), G.addNode());
   70.24 +
   70.25 +  snapshot.restore();
   70.26  
   70.27    checkGraphNodeList(G, 4);
   70.28    checkGraphEdgeList(G, 3);
   70.29 @@ -267,6 +279,13 @@
   70.30    GRAPH_TYPEDEFS(Graph);
   70.31  
   70.32    Graph G(num);
   70.33 +  check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
   70.34 +        "Wrong size");
   70.35 +
   70.36 +  G.resize(num);
   70.37 +  check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
   70.38 +        "Wrong size");
   70.39 +
   70.40    checkGraphNodeList(G, num);
   70.41    checkGraphEdgeList(G, num * (num - 1) / 2);
   70.42  
   70.43 @@ -411,6 +430,10 @@
   70.44    check(G.width() == width, "Wrong column number");
   70.45    check(G.height() == height, "Wrong row number");
   70.46  
   70.47 +  G.resize(width, height);
   70.48 +  check(G.width() == width, "Wrong column number");
   70.49 +  check(G.height() == height, "Wrong row number");
   70.50 +
   70.51    for (int i = 0; i < width; ++i) {
   70.52      for (int j = 0; j < height; ++j) {
   70.53        check(G.col(G(i, j)) == i, "Wrong column");
   70.54 @@ -486,6 +509,11 @@
   70.55    GRAPH_TYPEDEFS(HypercubeGraph);
   70.56  
   70.57    HypercubeGraph G(dim);
   70.58 +  check(G.dimension() == dim, "Wrong dimension");
   70.59 +
   70.60 +  G.resize(dim);
   70.61 +  check(G.dimension() == dim, "Wrong dimension");
   70.62 +  
   70.63    checkGraphNodeList(G, 1 << dim);
   70.64    checkGraphEdgeList(G, dim * (1 << (dim-1)));
   70.65    checkGraphArcList(G, dim * (1 << dim));
    71.1 --- a/test/heap_test.cc	Thu Nov 05 10:01:02 2009 +0100
    71.2 +++ b/test/heap_test.cc	Thu Nov 05 10:23:16 2009 +0100
    71.3 @@ -25,14 +25,17 @@
    71.4  #include <lemon/concepts/heap.h>
    71.5  
    71.6  #include <lemon/smart_graph.h>
    71.7 -
    71.8  #include <lemon/lgf_reader.h>
    71.9  #include <lemon/dijkstra.h>
   71.10  #include <lemon/maps.h>
   71.11  
   71.12  #include <lemon/bin_heap.h>
   71.13 +#include <lemon/fourary_heap.h>
   71.14 +#include <lemon/kary_heap.h>
   71.15  #include <lemon/fib_heap.h>
   71.16 +#include <lemon/pairing_heap.h>
   71.17  #include <lemon/radix_heap.h>
   71.18 +#include <lemon/binom_heap.h>
   71.19  #include <lemon/bucket_heap.h>
   71.20  
   71.21  #include "test_tools.h"
   71.22 @@ -89,18 +92,16 @@
   71.23  template <typename Heap>
   71.24  void heapSortTest() {
   71.25    RangeMap<int> map(test_len, -1);
   71.26 -
   71.27    Heap heap(map);
   71.28  
   71.29    std::vector<int> v(test_len);
   71.30 -
   71.31    for (int i = 0; i < test_len; ++i) {
   71.32      v[i] = test_seq[i];
   71.33      heap.push(i, v[i]);
   71.34    }
   71.35    std::sort(v.begin(), v.end());
   71.36    for (int i = 0; i < test_len; ++i) {
   71.37 -    check(v[i] == heap.prio() ,"Wrong order in heap sort.");
   71.38 +    check(v[i] == heap.prio(), "Wrong order in heap sort.");
   71.39      heap.pop();
   71.40    }
   71.41  }
   71.42 @@ -112,7 +113,6 @@
   71.43    Heap heap(map);
   71.44  
   71.45    std::vector<int> v(test_len);
   71.46 -
   71.47    for (int i = 0; i < test_len; ++i) {
   71.48      v[i] = test_seq[i];
   71.49      heap.push(i, v[i]);
   71.50 @@ -123,13 +123,11 @@
   71.51    }
   71.52    std::sort(v.begin(), v.end());
   71.53    for (int i = 0; i < test_len; ++i) {
   71.54 -    check(v[i] == heap.prio() ,"Wrong order in heap increase test.");
   71.55 +    check(v[i] == heap.prio(), "Wrong order in heap increase test.");
   71.56      heap.pop();
   71.57    }
   71.58  }
   71.59  
   71.60 -
   71.61 -
   71.62  template <typename Heap>
   71.63  void dijkstraHeapTest(const Digraph& digraph, const IntArcMap& length,
   71.64                        Node source) {
   71.65 @@ -144,7 +142,7 @@
   71.66      Node t = digraph.target(a);
   71.67      if (dijkstra.reached(s)) {
   71.68        check( dijkstra.dist(t) - dijkstra.dist(s) <= length[a],
   71.69 -             "Error in a shortest path tree!");
   71.70 +             "Error in shortest path tree.");
   71.71      }
   71.72    }
   71.73  
   71.74 @@ -153,7 +151,7 @@
   71.75        Arc a = dijkstra.predArc(n);
   71.76        Node s = digraph.source(a);
   71.77        check( dijkstra.dist(n) - dijkstra.dist(s) == length[a],
   71.78 -             "Error in a shortest path tree!");
   71.79 +             "Error in shortest path tree.");
   71.80      }
   71.81    }
   71.82  
   71.83 @@ -175,6 +173,7 @@
   71.84      node("source", source).
   71.85      run();
   71.86  
   71.87 +  // BinHeap
   71.88    {
   71.89      typedef BinHeap<Prio, ItemIntMap> IntHeap;
   71.90      checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
   71.91 @@ -186,6 +185,31 @@
   71.92      dijkstraHeapTest<NodeHeap>(digraph, length, source);
   71.93    }
   71.94  
   71.95 +  // FouraryHeap
   71.96 +  {
   71.97 +    typedef FouraryHeap<Prio, ItemIntMap> IntHeap;
   71.98 +    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
   71.99 +    heapSortTest<IntHeap>();
  71.100 +    heapIncreaseTest<IntHeap>();
  71.101 +
  71.102 +    typedef FouraryHeap<Prio, IntNodeMap > NodeHeap;
  71.103 +    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
  71.104 +    dijkstraHeapTest<NodeHeap>(digraph, length, source);
  71.105 +  }
  71.106 +
  71.107 +  // KaryHeap
  71.108 +  {
  71.109 +    typedef KaryHeap<Prio, ItemIntMap> IntHeap;
  71.110 +    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
  71.111 +    heapSortTest<IntHeap>();
  71.112 +    heapIncreaseTest<IntHeap>();
  71.113 +
  71.114 +    typedef KaryHeap<Prio, IntNodeMap > NodeHeap;
  71.115 +    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
  71.116 +    dijkstraHeapTest<NodeHeap>(digraph, length, source);
  71.117 +  }
  71.118 +
  71.119 +  // FibHeap
  71.120    {
  71.121      typedef FibHeap<Prio, ItemIntMap> IntHeap;
  71.122      checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
  71.123 @@ -197,6 +221,19 @@
  71.124      dijkstraHeapTest<NodeHeap>(digraph, length, source);
  71.125    }
  71.126  
  71.127 +  // PairingHeap
  71.128 +  {
  71.129 +    typedef PairingHeap<Prio, ItemIntMap> IntHeap;
  71.130 +    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
  71.131 +    heapSortTest<IntHeap>();
  71.132 +    heapIncreaseTest<IntHeap>();
  71.133 +
  71.134 +    typedef PairingHeap<Prio, IntNodeMap > NodeHeap;
  71.135 +    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
  71.136 +    dijkstraHeapTest<NodeHeap>(digraph, length, source);
  71.137 +  }
  71.138 +
  71.139 +  // RadixHeap
  71.140    {
  71.141      typedef RadixHeap<ItemIntMap> IntHeap;
  71.142      checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
  71.143 @@ -208,6 +245,19 @@
  71.144      dijkstraHeapTest<NodeHeap>(digraph, length, source);
  71.145    }
  71.146  
  71.147 +  // BinomHeap
  71.148 +  {
  71.149 +    typedef BinomHeap<Prio, ItemIntMap> IntHeap;
  71.150 +    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
  71.151 +    heapSortTest<IntHeap>();
  71.152 +    heapIncreaseTest<IntHeap>();
  71.153 +
  71.154 +    typedef BinomHeap<Prio, IntNodeMap > NodeHeap;
  71.155 +    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
  71.156 +    dijkstraHeapTest<NodeHeap>(digraph, length, source);
  71.157 +  }
  71.158 +
  71.159 +  // BucketHeap, SimpleBucketHeap
  71.160    {
  71.161      typedef BucketHeap<ItemIntMap> IntHeap;
  71.162      checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
  71.163 @@ -217,8 +267,10 @@
  71.164      typedef BucketHeap<IntNodeMap > NodeHeap;
  71.165      checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
  71.166      dijkstraHeapTest<NodeHeap>(digraph, length, source);
  71.167 +
  71.168 +    typedef SimpleBucketHeap<ItemIntMap> SimpleIntHeap;
  71.169 +    heapSortTest<SimpleIntHeap>();
  71.170    }
  71.171  
  71.172 -
  71.173    return 0;
  71.174  }
    72.1 --- a/test/maps_test.cc	Thu Nov 05 10:01:02 2009 +0100
    72.2 +++ b/test/maps_test.cc	Thu Nov 05 10:23:16 2009 +0100
    72.3 @@ -23,6 +23,9 @@
    72.4  #include <lemon/concepts/maps.h>
    72.5  #include <lemon/maps.h>
    72.6  #include <lemon/list_graph.h>
    72.7 +#include <lemon/smart_graph.h>
    72.8 +#include <lemon/adaptors.h>
    72.9 +#include <lemon/dfs.h>
   72.10  
   72.11  #include "test_tools.h"
   72.12  
   72.13 @@ -61,6 +64,12 @@
   72.14  typedef ReadWriteMap<A, bool> BoolWriteMap;
   72.15  typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap;
   72.16  
   72.17 +template<typename Map1, typename Map2, typename ItemIt>
   72.18 +void compareMap(const Map1& map1, const Map2& map2, ItemIt it) {
   72.19 +  for (; it != INVALID; ++it)
   72.20 +    check(map1[it] == map2[it], "The maps are not equal");
   72.21 +}
   72.22 +
   72.23  int main()
   72.24  {
   72.25    // Map concepts
   72.26 @@ -329,6 +338,10 @@
   72.27    // LoggerBoolMap
   72.28    {
   72.29      typedef std::vector<int> vec;
   72.30 +    checkConcept<WriteMap<int, bool>, LoggerBoolMap<vec::iterator> >();
   72.31 +    checkConcept<WriteMap<int, bool>,
   72.32 +                 LoggerBoolMap<std::back_insert_iterator<vec> > >();
   72.33 +
   72.34      vec v1;
   72.35      vec v2(10);
   72.36      LoggerBoolMap<std::back_insert_iterator<vec> >
   72.37 @@ -348,6 +361,155 @@
   72.38      for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
   72.39            it != map2.end(); ++it )
   72.40        check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
   72.41 +    
   72.42 +    typedef ListDigraph Graph;
   72.43 +    DIGRAPH_TYPEDEFS(Graph);
   72.44 +    Graph gr;
   72.45 +
   72.46 +    Node n0 = gr.addNode();
   72.47 +    Node n1 = gr.addNode();
   72.48 +    Node n2 = gr.addNode();
   72.49 +    Node n3 = gr.addNode();
   72.50 +    
   72.51 +    gr.addArc(n3, n0);
   72.52 +    gr.addArc(n3, n2);
   72.53 +    gr.addArc(n0, n2);
   72.54 +    gr.addArc(n2, n1);
   72.55 +    gr.addArc(n0, n1);
   72.56 +    
   72.57 +    {
   72.58 +      std::vector<Node> v;
   72.59 +      dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run();
   72.60 +
   72.61 +      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
   72.62 +            "Something is wrong with LoggerBoolMap");
   72.63 +    }
   72.64 +    {
   72.65 +      std::vector<Node> v(countNodes(gr));
   72.66 +      dfs(gr).processedMap(loggerBoolMap(v.begin())).run();
   72.67 +      
   72.68 +      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
   72.69 +            "Something is wrong with LoggerBoolMap");
   72.70 +    }
   72.71 +  }
   72.72 +  
   72.73 +  // IdMap, RangeIdMap
   72.74 +  {
   72.75 +    typedef ListDigraph Graph;
   72.76 +    DIGRAPH_TYPEDEFS(Graph);
   72.77 +
   72.78 +    checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >();
   72.79 +    checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >();
   72.80 +    checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >();
   72.81 +    checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >();
   72.82 +    
   72.83 +    Graph gr;
   72.84 +    IdMap<Graph, Node> nmap(gr);
   72.85 +    IdMap<Graph, Arc> amap(gr);
   72.86 +    RangeIdMap<Graph, Node> nrmap(gr);
   72.87 +    RangeIdMap<Graph, Arc> armap(gr);
   72.88 +    
   72.89 +    Node n0 = gr.addNode();
   72.90 +    Node n1 = gr.addNode();
   72.91 +    Node n2 = gr.addNode();
   72.92 +    
   72.93 +    Arc a0 = gr.addArc(n0, n1);
   72.94 +    Arc a1 = gr.addArc(n0, n2);
   72.95 +    Arc a2 = gr.addArc(n2, n1);
   72.96 +    Arc a3 = gr.addArc(n2, n0);
   72.97 +    
   72.98 +    check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap");
   72.99 +    check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap");
  72.100 +    check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap");
  72.101 +
  72.102 +    check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap");
  72.103 +    check(amap[a1] == gr.id(a1) && amap(gr.id(a1)) == a1, "Wrong IdMap");
  72.104 +    check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap");
  72.105 +    check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap");
  72.106 +
  72.107 +    check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap");
  72.108 +    check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap");
  72.109 +    
  72.110 +    check(nrmap.size() == 3 && armap.size() == 4,
  72.111 +          "Wrong RangeIdMap::size()");
  72.112 +
  72.113 +    check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
  72.114 +    check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
  72.115 +    check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
  72.116 +    
  72.117 +    check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
  72.118 +    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
  72.119 +    check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
  72.120 +    check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
  72.121 +
  72.122 +    check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
  72.123 +    check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
  72.124 +    
  72.125 +    gr.erase(n1);
  72.126 +    
  72.127 +    if (nrmap[n0] == 1) nrmap.swap(n0, n2);
  72.128 +    nrmap.swap(n2, n0);
  72.129 +    if (armap[a1] == 1) armap.swap(a1, a3);
  72.130 +    armap.swap(a3, a1);
  72.131 +    
  72.132 +    check(nrmap.size() == 2 && armap.size() == 2,
  72.133 +          "Wrong RangeIdMap::size()");
  72.134 +
  72.135 +    check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
  72.136 +    check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
  72.137 +    
  72.138 +    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
  72.139 +    check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
  72.140 +
  72.141 +    check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
  72.142 +    check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
  72.143 +  }
  72.144 +  
  72.145 +  // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
  72.146 +  {
  72.147 +    typedef ListGraph Graph;
  72.148 +    GRAPH_TYPEDEFS(Graph);
  72.149 +    
  72.150 +    checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
  72.151 +    checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
  72.152 +    checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
  72.153 +    checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
  72.154 +    checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
  72.155 +    checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >();
  72.156 +
  72.157 +    Graph gr;
  72.158 +    Node n0 = gr.addNode();
  72.159 +    Node n1 = gr.addNode();
  72.160 +    Node n2 = gr.addNode();
  72.161 +    
  72.162 +    gr.addEdge(n0,n1);
  72.163 +    gr.addEdge(n1,n2);
  72.164 +    gr.addEdge(n0,n2);
  72.165 +    gr.addEdge(n2,n1);
  72.166 +    gr.addEdge(n1,n2);
  72.167 +    gr.addEdge(n0,n1);
  72.168 +    
  72.169 +    for (EdgeIt e(gr); e != INVALID; ++e) {
  72.170 +      check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
  72.171 +      check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
  72.172 +    }
  72.173 +    
  72.174 +    compareMap(sourceMap(orienter(gr, constMap<Edge, bool>(true))),
  72.175 +               targetMap(orienter(gr, constMap<Edge, bool>(false))),
  72.176 +               EdgeIt(gr));
  72.177 +
  72.178 +    typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
  72.179 +    Digraph dgr(gr, constMap<Edge, bool>(true));
  72.180 +    OutDegMap<Digraph> odm(dgr);
  72.181 +    InDegMap<Digraph> idm(dgr);
  72.182 +    
  72.183 +    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
  72.184 +    check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
  72.185 +   
  72.186 +    gr.addEdge(n2, n0);
  72.187 +
  72.188 +    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
  72.189 +    check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
  72.190    }
  72.191    
  72.192    // CrossRefMap
  72.193 @@ -357,6 +519,73 @@
  72.194  
  72.195      checkConcept<ReadWriteMap<Node, int>,
  72.196                   CrossRefMap<Graph, Node, int> >();
  72.197 +    checkConcept<ReadWriteMap<Node, bool>,
  72.198 +                 CrossRefMap<Graph, Node, bool> >();
  72.199 +    checkConcept<ReadWriteMap<Node, double>,
  72.200 +                 CrossRefMap<Graph, Node, double> >();
  72.201 +    
  72.202 +    Graph gr;
  72.203 +    typedef CrossRefMap<Graph, Node, char> CRMap;
  72.204 +    CRMap map(gr);
  72.205 +    
  72.206 +    Node n0 = gr.addNode();
  72.207 +    Node n1 = gr.addNode();
  72.208 +    Node n2 = gr.addNode();
  72.209 +    
  72.210 +    map.set(n0, 'A');
  72.211 +    map.set(n1, 'B');
  72.212 +    map.set(n2, 'C');
  72.213 +    
  72.214 +    check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
  72.215 +          "Wrong CrossRefMap");
  72.216 +    check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
  72.217 +          "Wrong CrossRefMap");
  72.218 +    check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
  72.219 +          "Wrong CrossRefMap");
  72.220 +    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
  72.221 +          "Wrong CrossRefMap::count()");
  72.222 +    
  72.223 +    CRMap::ValueIt it = map.beginValue();
  72.224 +    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
  72.225 +          it == map.endValue(), "Wrong value iterator");
  72.226 +    
  72.227 +    map.set(n2, 'A');
  72.228 +
  72.229 +    check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
  72.230 +          "Wrong CrossRefMap");
  72.231 +    check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
  72.232 +    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
  72.233 +    check(map('C') == INVALID && map.inverse()['C'] == INVALID,
  72.234 +          "Wrong CrossRefMap");
  72.235 +    check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
  72.236 +          "Wrong CrossRefMap::count()");
  72.237 +
  72.238 +    it = map.beginValue();
  72.239 +    check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' &&
  72.240 +          it == map.endValue(), "Wrong value iterator");
  72.241 +
  72.242 +    map.set(n0, 'C');
  72.243 +
  72.244 +    check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
  72.245 +          "Wrong CrossRefMap");
  72.246 +    check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
  72.247 +    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
  72.248 +    check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
  72.249 +    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
  72.250 +          "Wrong CrossRefMap::count()");
  72.251 +
  72.252 +    it = map.beginValue();
  72.253 +    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
  72.254 +          it == map.endValue(), "Wrong value iterator");
  72.255 +  }
  72.256 +
  72.257 +  // CrossRefMap
  72.258 +  {
  72.259 +    typedef SmartDigraph Graph;
  72.260 +    DIGRAPH_TYPEDEFS(Graph);
  72.261 +
  72.262 +    checkConcept<ReadWriteMap<Node, int>,
  72.263 +                 CrossRefMap<Graph, Node, int> >();
  72.264      
  72.265      Graph gr;
  72.266      typedef CrossRefMap<Graph, Node, char> CRMap;
  72.267 @@ -383,6 +612,193 @@
  72.268      check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
  72.269            it == map.endValue(), "Wrong value iterator");
  72.270    }
  72.271 +  
  72.272 +  // Iterable bool map
  72.273 +  {
  72.274 +    typedef SmartGraph Graph;
  72.275 +    typedef SmartGraph::Node Item;
  72.276  
  72.277 +    typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm;
  72.278 +    checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>();
  72.279 +
  72.280 +    const int num = 10;
  72.281 +    Graph g;
  72.282 +    std::vector<Item> items;
  72.283 +    for (int i = 0; i < num; ++i) {
  72.284 +      items.push_back(g.addNode());
  72.285 +    }
  72.286 +
  72.287 +    Ibm map1(g, true);
  72.288 +    int n = 0;
  72.289 +    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
  72.290 +      check(map1[static_cast<Item>(it)], "Wrong TrueIt");
  72.291 +      ++n;
  72.292 +    }
  72.293 +    check(n == num, "Wrong number");
  72.294 +
  72.295 +    n = 0;
  72.296 +    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
  72.297 +        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
  72.298 +        ++n;
  72.299 +    }
  72.300 +    check(n == num, "Wrong number");
  72.301 +    check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt");
  72.302 +    check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false");
  72.303 +
  72.304 +    map1[items[5]] = true;
  72.305 +
  72.306 +    n = 0;
  72.307 +    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
  72.308 +        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
  72.309 +        ++n;
  72.310 +    }
  72.311 +    check(n == num, "Wrong number");
  72.312 +
  72.313 +    map1[items[num / 2]] = false;
  72.314 +    check(map1[items[num / 2]] == false, "Wrong map value");
  72.315 +
  72.316 +    n = 0;
  72.317 +    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
  72.318 +        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
  72.319 +        ++n;
  72.320 +    }
  72.321 +    check(n == num - 1, "Wrong number");
  72.322 +
  72.323 +    n = 0;
  72.324 +    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
  72.325 +        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
  72.326 +        ++n;
  72.327 +    }
  72.328 +    check(n == 1, "Wrong number");
  72.329 +
  72.330 +    map1[items[0]] = false;
  72.331 +    check(map1[items[0]] == false, "Wrong map value");
  72.332 +
  72.333 +    map1[items[num - 1]] = false;
  72.334 +    check(map1[items[num - 1]] == false, "Wrong map value");
  72.335 +
  72.336 +    n = 0;
  72.337 +    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
  72.338 +        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
  72.339 +        ++n;
  72.340 +    }
  72.341 +    check(n == num - 3, "Wrong number");
  72.342 +    check(map1.trueNum() == num - 3, "Wrong number");
  72.343 +
  72.344 +    n = 0;
  72.345 +    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
  72.346 +        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
  72.347 +        ++n;
  72.348 +    }
  72.349 +    check(n == 3, "Wrong number");
  72.350 +    check(map1.falseNum() == 3, "Wrong number");
  72.351 +  }
  72.352 +
  72.353 +  // Iterable int map
  72.354 +  {
  72.355 +    typedef SmartGraph Graph;
  72.356 +    typedef SmartGraph::Node Item;
  72.357 +    typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim;
  72.358 +
  72.359 +    checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>();
  72.360 +
  72.361 +    const int num = 10;
  72.362 +    Graph g;
  72.363 +    std::vector<Item> items;
  72.364 +    for (int i = 0; i < num; ++i) {
  72.365 +      items.push_back(g.addNode());
  72.366 +    }
  72.367 +
  72.368 +    Iim map1(g);
  72.369 +    check(map1.size() == 0, "Wrong size");
  72.370 +
  72.371 +    for (int i = 0; i < num; ++i) {
  72.372 +      map1[items[i]] = i;
  72.373 +    }
  72.374 +    check(map1.size() == num, "Wrong size");
  72.375 +
  72.376 +    for (int i = 0; i < num; ++i) {
  72.377 +      Iim::ItemIt it(map1, i);
  72.378 +      check(static_cast<Item>(it) == items[i], "Wrong value");
  72.379 +      ++it;
  72.380 +      check(static_cast<Item>(it) == INVALID, "Wrong value");
  72.381 +    }
  72.382 +
  72.383 +    for (int i = 0; i < num; ++i) {
  72.384 +      map1[items[i]] = i % 2;
  72.385 +    }
  72.386 +    check(map1.size() == 2, "Wrong size");
  72.387 +
  72.388 +    int n = 0;
  72.389 +    for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) {
  72.390 +      check(map1[static_cast<Item>(it)] == 0, "Wrong value");
  72.391 +      ++n;
  72.392 +    }
  72.393 +    check(n == (num + 1) / 2, "Wrong number");
  72.394 +
  72.395 +    for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) {
  72.396 +      check(map1[static_cast<Item>(it)] == 1, "Wrong value");
  72.397 +      ++n;
  72.398 +    }
  72.399 +    check(n == num, "Wrong number");
  72.400 +
  72.401 +  }
  72.402 +
  72.403 +  // Iterable value map
  72.404 +  {
  72.405 +    typedef SmartGraph Graph;
  72.406 +    typedef SmartGraph::Node Item;
  72.407 +    typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm;
  72.408 +
  72.409 +    checkConcept<ReadWriteMap<Item, double>, Ivm>();
  72.410 +
  72.411 +    const int num = 10;
  72.412 +    Graph g;
  72.413 +    std::vector<Item> items;
  72.414 +    for (int i = 0; i < num; ++i) {
  72.415 +      items.push_back(g.addNode());
  72.416 +    }
  72.417 +
  72.418 +    Ivm map1(g, 0.0);
  72.419 +    check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size");
  72.420 +    check(*map1.beginValue() == 0.0, "Wrong value");
  72.421 +
  72.422 +    for (int i = 0; i < num; ++i) {
  72.423 +      map1.set(items[i], static_cast<double>(i));
  72.424 +    }
  72.425 +    check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size");
  72.426 +
  72.427 +    for (int i = 0; i < num; ++i) {
  72.428 +      Ivm::ItemIt it(map1, static_cast<double>(i));
  72.429 +      check(static_cast<Item>(it) == items[i], "Wrong value");
  72.430 +      ++it;
  72.431 +      check(static_cast<Item>(it) == INVALID, "Wrong value");
  72.432 +    }
  72.433 +
  72.434 +    for (Ivm::ValueIt vit = map1.beginValue();
  72.435 +         vit != map1.endValue(); ++vit) {
  72.436 +      check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit,
  72.437 +            "Wrong ValueIt");
  72.438 +    }
  72.439 +
  72.440 +    for (int i = 0; i < num; ++i) {
  72.441 +      map1.set(items[i], static_cast<double>(i % 2));
  72.442 +    }
  72.443 +    check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size");
  72.444 +
  72.445 +    int n = 0;
  72.446 +    for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) {
  72.447 +      check(map1[static_cast<Item>(it)] == 0.0, "Wrong value");
  72.448 +      ++n;
  72.449 +    }
  72.450 +    check(n == (num + 1) / 2, "Wrong number");
  72.451 +
  72.452 +    for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) {
  72.453 +      check(map1[static_cast<Item>(it)] == 1.0, "Wrong value");
  72.454 +      ++n;
  72.455 +    }
  72.456 +    check(n == num, "Wrong number");
  72.457 +
  72.458 +  }
  72.459    return 0;
  72.460  }
    73.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    73.2 +++ b/test/min_mean_cycle_test.cc	Thu Nov 05 10:23:16 2009 +0100
    73.3 @@ -0,0 +1,216 @@
    73.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
    73.5 + *
    73.6 + * This file is a part of LEMON, a generic C++ optimization library.
    73.7 + *
    73.8 + * Copyright (C) 2003-2009
    73.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   73.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
   73.11 + *
   73.12 + * Permission to use, modify and distribute this software is granted
   73.13 + * provided that this copyright notice appears in all copies. For
   73.14 + * precise terms see the accompanying LICENSE file.
   73.15 + *
   73.16 + * This software is provided "AS IS" with no warranty of any kind,
   73.17 + * express or implied, and with no claim as to its suitability for any
   73.18 + * purpose.
   73.19 + *
   73.20 + */
   73.21 +
   73.22 +#include <iostream>
   73.23 +#include <sstream>
   73.24 +
   73.25 +#include <lemon/smart_graph.h>
   73.26 +#include <lemon/lgf_reader.h>
   73.27 +#include <lemon/path.h>
   73.28 +#include <lemon/concepts/digraph.h>
   73.29 +#include <lemon/concept_check.h>
   73.30 +
   73.31 +#include <lemon/karp.h>
   73.32 +#include <lemon/hartmann_orlin.h>
   73.33 +#include <lemon/howard.h>
   73.34 +
   73.35 +#include "test_tools.h"
   73.36 +
   73.37 +using namespace lemon;
   73.38 +
   73.39 +char test_lgf[] =
   73.40 +  "@nodes\n"
   73.41 +  "label\n"
   73.42 +  "1\n"
   73.43 +  "2\n"
   73.44 +  "3\n"
   73.45 +  "4\n"
   73.46 +  "5\n"
   73.47 +  "6\n"
   73.48 +  "7\n"
   73.49 +  "@arcs\n"
   73.50 +  "    len1 len2 len3 len4  c1 c2 c3 c4\n"
   73.51 +  "1 2    1    1    1    1   0  0  0  0\n"
   73.52 +  "2 4    5    5    5    5   1  0  0  0\n"
   73.53 +  "2 3    8    8    8    8   0  0  0  0\n"
   73.54 +  "3 2   -2    0    0    0   1  0  0  0\n"
   73.55 +  "3 4    4    4    4    4   0  0  0  0\n"
   73.56 +  "3 7   -4   -4   -4   -4   0  0  0  0\n"
   73.57 +  "4 1    2    2    2    2   0  0  0  0\n"
   73.58 +  "4 3    3    3    3    3   1  0  0  0\n"
   73.59 +  "4 4    3    3    0    0   0  0  1  0\n"
   73.60 +  "5 2    4    4    4    4   0  0  0  0\n"
   73.61 +  "5 6    3    3    3    3   0  1  0  0\n"
   73.62 +  "6 5    2    2    2    2   0  1  0  0\n"
   73.63 +  "6 4   -1   -1   -1   -1   0  0  0  0\n"
   73.64 +  "6 7    1    1    1    1   0  0  0  0\n"
   73.65 +  "7 7    4    4    4   -1   0  0  0  1\n";
   73.66 +
   73.67 +                        
   73.68 +// Check the interface of an MMC algorithm
   73.69 +template <typename GR, typename Value>
   73.70 +struct MmcClassConcept
   73.71 +{
   73.72 +  template <typename MMC>
   73.73 +  struct Constraints {
   73.74 +    void constraints() {
   73.75 +      const Constraints& me = *this;
   73.76 +
   73.77 +      typedef typename MMC
   73.78 +        ::template SetPath<ListPath<GR> >
   73.79 +        ::template SetLargeValue<Value>
   73.80 +        ::Create MmcAlg;
   73.81 +      MmcAlg mmc(me.g, me.length);
   73.82 +      const MmcAlg& const_mmc = mmc;
   73.83 +      
   73.84 +      typename MmcAlg::Tolerance tol = const_mmc.tolerance();
   73.85 +      mmc.tolerance(tol);
   73.86 +      
   73.87 +      b = mmc.cycle(p).run();
   73.88 +      b = mmc.findMinMean();
   73.89 +      b = mmc.findCycle();
   73.90 +
   73.91 +      v = const_mmc.cycleLength();
   73.92 +      i = const_mmc.cycleArcNum();
   73.93 +      d = const_mmc.cycleMean();
   73.94 +      p = const_mmc.cycle();
   73.95 +    }
   73.96 +
   73.97 +    typedef concepts::ReadMap<typename GR::Arc, Value> LM;
   73.98 +  
   73.99 +    GR g;
  73.100 +    LM length;
  73.101 +    ListPath<GR> p;
  73.102 +    Value v;
  73.103 +    int i;
  73.104 +    double d;
  73.105 +    bool b;
  73.106 +  };
  73.107 +};
  73.108 +
  73.109 +// Perform a test with the given parameters
  73.110 +template <typename MMC>
  73.111 +void checkMmcAlg(const SmartDigraph& gr,
  73.112 +                 const SmartDigraph::ArcMap<int>& lm,
  73.113 +                 const SmartDigraph::ArcMap<int>& cm,
  73.114 +                 int length, int size) {
  73.115 +  MMC alg(gr, lm);
  73.116 +  alg.findMinMean();
  73.117 +  check(alg.cycleMean() == static_cast<double>(length) / size,
  73.118 +        "Wrong cycle mean");
  73.119 +  alg.findCycle();
  73.120 +  check(alg.cycleLength() == length && alg.cycleArcNum() == size,
  73.121 +        "Wrong path");
  73.122 +  SmartDigraph::ArcMap<int> cycle(gr, 0);
  73.123 +  for (typename MMC::Path::ArcIt a(alg.cycle()); a != INVALID; ++a) {
  73.124 +    ++cycle[a];
  73.125 +  }
  73.126 +  for (SmartDigraph::ArcIt a(gr); a != INVALID; ++a) {
  73.127 +    check(cm[a] == cycle[a], "Wrong path");
  73.128 +  }
  73.129 +}
  73.130 +
  73.131 +// Class for comparing types
  73.132 +template <typename T1, typename T2>
  73.133 +struct IsSameType {
  73.134 +  static const int result = 0;
  73.135 +};
  73.136 +
  73.137 +template <typename T>
  73.138 +struct IsSameType<T,T> {
  73.139 +  static const int result = 1;
  73.140 +};
  73.141 +
  73.142 +
  73.143 +int main() {
  73.144 +  #ifdef LEMON_HAVE_LONG_LONG
  73.145 +    typedef long long long_int;
  73.146 +  #else
  73.147 +    typedef long long_int;
  73.148 +  #endif
  73.149 +
  73.150 +  // Check the interface
  73.151 +  {
  73.152 +    typedef concepts::Digraph GR;
  73.153 +
  73.154 +    // Karp
  73.155 +    checkConcept< MmcClassConcept<GR, int>,
  73.156 +                  Karp<GR, concepts::ReadMap<GR::Arc, int> > >();
  73.157 +    checkConcept< MmcClassConcept<GR, float>,
  73.158 +                  Karp<GR, concepts::ReadMap<GR::Arc, float> > >();
  73.159 +    
  73.160 +    // HartmannOrlin
  73.161 +    checkConcept< MmcClassConcept<GR, int>,
  73.162 +                  HartmannOrlin<GR, concepts::ReadMap<GR::Arc, int> > >();
  73.163 +    checkConcept< MmcClassConcept<GR, float>,
  73.164 +                  HartmannOrlin<GR, concepts::ReadMap<GR::Arc, float> > >();
  73.165 +    
  73.166 +    // Howard
  73.167 +    checkConcept< MmcClassConcept<GR, int>,
  73.168 +                  Howard<GR, concepts::ReadMap<GR::Arc, int> > >();
  73.169 +    checkConcept< MmcClassConcept<GR, float>,
  73.170 +                  Howard<GR, concepts::ReadMap<GR::Arc, float> > >();
  73.171 +
  73.172 +    if (IsSameType<Howard<GR, concepts::ReadMap<GR::Arc, int> >::LargeValue,
  73.173 +          long_int>::result == 0) check(false, "Wrong LargeValue type");
  73.174 +    if (IsSameType<Howard<GR, concepts::ReadMap<GR::Arc, float> >::LargeValue,
  73.175 +          double>::result == 0) check(false, "Wrong LargeValue type");
  73.176 +  }
  73.177 +
  73.178 +  // Run various tests
  73.179 +  {
  73.180 +    typedef SmartDigraph GR;
  73.181 +    DIGRAPH_TYPEDEFS(GR);
  73.182 +    
  73.183 +    GR gr;
  73.184 +    IntArcMap l1(gr), l2(gr), l3(gr), l4(gr);
  73.185 +    IntArcMap c1(gr), c2(gr), c3(gr), c4(gr);
  73.186 +    
  73.187 +    std::istringstream input(test_lgf);
  73.188 +    digraphReader(gr, input).
  73.189 +      arcMap("len1", l1).
  73.190 +      arcMap("len2", l2).
  73.191 +      arcMap("len3", l3).
  73.192 +      arcMap("len4", l4).
  73.193 +      arcMap("c1", c1).
  73.194 +      arcMap("c2", c2).
  73.195 +      arcMap("c3", c3).
  73.196 +      arcMap("c4", c4).
  73.197 +      run();
  73.198 +
  73.199 +    // Karp
  73.200 +    checkMmcAlg<Karp<GR, IntArcMap> >(gr, l1, c1,  6, 3);
  73.201 +    checkMmcAlg<Karp<GR, IntArcMap> >(gr, l2, c2,  5, 2);
  73.202 +    checkMmcAlg<Karp<GR, IntArcMap> >(gr, l3, c3,  0, 1);
  73.203 +    checkMmcAlg<Karp<GR, IntArcMap> >(gr, l4, c4, -1, 1);
  73.204 +
  73.205 +    // HartmannOrlin
  73.206 +    checkMmcAlg<HartmannOrlin<GR, IntArcMap> >(gr, l1, c1,  6, 3);
  73.207 +    checkMmcAlg<HartmannOrlin<GR, IntArcMap> >(gr, l2, c2,  5, 2);
  73.208 +    checkMmcAlg<HartmannOrlin<GR, IntArcMap> >(gr, l3, c3,  0, 1);
  73.209 +    checkMmcAlg<HartmannOrlin<GR, IntArcMap> >(gr, l4, c4, -1, 1);
  73.210 +
  73.211 +    // Howard
  73.212 +    checkMmcAlg<Howard<GR, IntArcMap> >(gr, l1, c1,  6, 3);
  73.213 +    checkMmcAlg<Howard<GR, IntArcMap> >(gr, l2, c2,  5, 2);
  73.214 +    checkMmcAlg<Howard<GR, IntArcMap> >(gr, l3, c3,  0, 1);
  73.215 +    checkMmcAlg<Howard<GR, IntArcMap> >(gr, l4, c4, -1, 1);
  73.216 +  }
  73.217 +
  73.218 +  return 0;
  73.219 +}
    74.1 --- a/test/mip_test.cc	Thu Nov 05 10:01:02 2009 +0100
    74.2 +++ b/test/mip_test.cc	Thu Nov 05 10:23:16 2009 +0100
    74.3 @@ -50,7 +50,8 @@
    74.4  
    74.5    if (stat ==  MipSolver::OPTIMAL) {
    74.6      std::ostringstream sbuf;
    74.7 -    buf << "Wrong optimal value: the right optimum is " << exp_opt;
    74.8 +    sbuf << "Wrong optimal value ("<< mip.solValue()
    74.9 +         <<" instead of " << exp_opt << ")";
   74.10      check(std::abs(mip.solValue()-exp_opt) < 1e-3, sbuf.str());
   74.11      //+ecvt(exp_opt,2)
   74.12    }
    75.1 --- a/test/preflow_test.cc	Thu Nov 05 10:01:02 2009 +0100
    75.2 +++ b/test/preflow_test.cc	Thu Nov 05 10:23:16 2009 +0100
    75.3 @@ -94,6 +94,11 @@
    75.4              ::Create PreflowType;
    75.5    PreflowType preflow_test(g, cap, n, n);
    75.6    const PreflowType& const_preflow_test = preflow_test;
    75.7 +  
    75.8 +  const PreflowType::Elevator& elev = const_preflow_test.elevator();
    75.9 +  preflow_test.elevator(const_cast<PreflowType::Elevator&>(elev));
   75.10 +  PreflowType::Tolerance tol = const_preflow_test.tolerance();
   75.11 +  preflow_test.tolerance(tol);
   75.12  
   75.13    preflow_test
   75.14      .capacityMap(cap)
    76.1 --- a/test/test_tools.h	Thu Nov 05 10:01:02 2009 +0100
    76.2 +++ b/test/test_tools.h	Thu Nov 05 10:23:16 2009 +0100
    76.3 @@ -37,10 +37,14 @@
    76.4  ///\code check(0==1,"This is obviously false.");\endcode will
    76.5  ///print something like this (and then exits).
    76.6  ///\verbatim file_name.cc:123: error: This is obviously false. \endverbatim
    76.7 -#define check(rc, msg) \
    76.8 -  if(!(rc)) { \
    76.9 -    std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
   76.10 -    abort(); \
   76.11 -  } else { } \
   76.12 +#define check(rc, msg)                                                  \
   76.13 +  {                                                                     \
   76.14 +    if(!(rc)) {                                                         \
   76.15 +      std::cerr << __FILE__ ":" << __LINE__ << ": error: "              \
   76.16 +                << msg << std::endl;                                    \
   76.17 +      abort();                                                          \
   76.18 +    } else { }                                                          \
   76.19 +  }                                                                     \
   76.20 +    
   76.21  
   76.22  #endif
    77.1 --- a/tools/lemon-0.x-to-1.x.sh	Thu Nov 05 10:01:02 2009 +0100
    77.2 +++ b/tools/lemon-0.x-to-1.x.sh	Thu Nov 05 10:23:16 2009 +0100
    77.3 @@ -35,10 +35,10 @@
    77.4          -e "s/IncEdgeIt/_In_cEd_geIt_label_/g"\
    77.5          -e "s/Edge\>/_Ar_c_label_/g"\
    77.6          -e "s/\<edge\>/_ar_c_label_/g"\
    77.7 -        -e "s/_edge\>/_ar_c_label_/g"\
    77.8 +        -e "s/_edge\>/__ar_c_label_/g"\
    77.9          -e "s/Edges\>/_Ar_c_label_s/g"\
   77.10          -e "s/\<edges\>/_ar_c_label_s/g"\
   77.11 -        -e "s/_edges\>/_ar_c_label_s/g"\
   77.12 +        -e "s/_edges\>/__ar_c_label_s/g"\
   77.13          -e "s/\([Ee]\)dge\([a-z]\)/_\1d_ge_label_\2/g"\
   77.14          -e "s/\([a-z]\)edge/\1_ed_ge_label_/g"\
   77.15          -e "s/Edge/_Ar_c_label_/g"\
   77.16 @@ -68,6 +68,11 @@
   77.17          -e "s/_blu_e_label_/blue/g"\
   77.18          -e "s/_GR_APH_TY_PEDE_FS_label_/GRAPH_TYPEDEFS/g"\
   77.19          -e "s/_DIGR_APH_TY_PEDE_FS_label_/DIGRAPH_TYPEDEFS/g"\
   77.20 +        -e "s/\<digraph_adaptor\.h\>/adaptors.h/g"\
   77.21 +        -e "s/\<digraph_utils\.h\>/core.h/g"\
   77.22 +        -e "s/\<digraph_reader\.h\>/lgf_reader.h/g"\
   77.23 +        -e "s/\<digraph_writer\.h\>/lgf_writer.h/g"\
   77.24 +        -e "s/\<topology\.h\>/connectivity.h/g"\
   77.25          -e "s/DigraphToEps/GraphToEps/g"\
   77.26          -e "s/digraphToEps/graphToEps/g"\
   77.27          -e "s/\<DefPredMap\>/SetPredMap/g"\