Merge #302
authorAlpar Juttner <alpar@cs.elte.hu>
Sat, 26 Sep 2009 07:08:10 +0200
changeset 7733fc2a801c39e
parent 772 11404088d1a5
parent 766 ba79e8d64448
child 778 0977046c60d2
Merge #302
lemon/maps.h
test/maps_test.cc
     1.1 --- a/doc/groups.dox	Fri Sep 25 12:24:16 2009 +0200
     1.2 +++ b/doc/groups.dox	Sat Sep 26 07:08:10 2009 +0200
     1.3 @@ -226,14 +226,6 @@
     1.4  */
     1.5  
     1.6  /**
     1.7 -@defgroup matrices Matrices
     1.8 -@ingroup datas
     1.9 -\brief Two dimensional data storages implemented in LEMON.
    1.10 -
    1.11 -This group contains two dimensional data storages implemented in LEMON.
    1.12 -*/
    1.13 -
    1.14 -/**
    1.15  @defgroup paths Path Structures
    1.16  @ingroup datas
    1.17  \brief %Path structures implemented in LEMON.
    1.18 @@ -246,7 +238,36 @@
    1.19  efficient to have e.g. the Dijkstra algorithm to store its result in
    1.20  any kind of path structure.
    1.21  
    1.22 -\sa lemon::concepts::Path
    1.23 +\sa \ref concepts::Path "Path concept"
    1.24 +*/
    1.25 +
    1.26 +/**
    1.27 +@defgroup heaps Heap Structures
    1.28 +@ingroup datas
    1.29 +\brief %Heap structures implemented in LEMON.
    1.30 +
    1.31 +This group contains the heap structures implemented in LEMON.
    1.32 +
    1.33 +LEMON provides several heap classes. They are efficient implementations
    1.34 +of the abstract data type \e priority \e queue. They store items with
    1.35 +specified values called \e priorities in such a way that finding and
    1.36 +removing the item with minimum priority are efficient.
    1.37 +The basic operations are adding and erasing items, changing the priority
    1.38 +of an item, etc.
    1.39 +
    1.40 +Heaps are crucial in several algorithms, such as Dijkstra and Prim.
    1.41 +The heap implementations have the same interface, thus any of them can be
    1.42 +used easily in such algorithms.
    1.43 +
    1.44 +\sa \ref concepts::Heap "Heap concept"
    1.45 +*/
    1.46 +
    1.47 +/**
    1.48 +@defgroup matrices Matrices
    1.49 +@ingroup datas
    1.50 +\brief Two dimensional data storages implemented in LEMON.
    1.51 +
    1.52 +This group contains two dimensional data storages implemented in LEMON.
    1.53  */
    1.54  
    1.55  /**
    1.56 @@ -259,6 +280,28 @@
    1.57  */
    1.58  
    1.59  /**
    1.60 +@defgroup geomdat Geometric Data Structures
    1.61 +@ingroup auxdat
    1.62 +\brief Geometric data structures implemented in LEMON.
    1.63 +
    1.64 +This group contains geometric data structures implemented in LEMON.
    1.65 +
    1.66 + - \ref lemon::dim2::Point "dim2::Point" implements a two dimensional
    1.67 +   vector with the usual operations.
    1.68 + - \ref lemon::dim2::Box "dim2::Box" can be used to determine the
    1.69 +   rectangular bounding box of a set of \ref lemon::dim2::Point
    1.70 +   "dim2::Point"'s.
    1.71 +*/
    1.72 +
    1.73 +/**
    1.74 +@defgroup matrices Matrices
    1.75 +@ingroup auxdat
    1.76 +\brief Two dimensional data storages implemented in LEMON.
    1.77 +
    1.78 +This group contains two dimensional data storages implemented in LEMON.
    1.79 +*/
    1.80 +
    1.81 +/**
    1.82  @defgroup algs Algorithms
    1.83  \brief This group contains the several algorithms
    1.84  implemented in LEMON.
    1.85 @@ -298,6 +341,15 @@
    1.86  */
    1.87  
    1.88  /**
    1.89 +@defgroup spantree Minimum Spanning Tree Algorithms
    1.90 +@ingroup algs
    1.91 +\brief Algorithms for finding minimum cost spanning trees and arborescences.
    1.92 +
    1.93 +This group contains the algorithms for finding minimum cost spanning
    1.94 +trees and arborescences.
    1.95 +*/
    1.96 +
    1.97 +/**
    1.98  @defgroup max_flow Maximum Flow Algorithms
    1.99  @ingroup algs
   1.100  \brief Algorithms for finding maximum flows.
   1.101 @@ -375,7 +427,7 @@
   1.102  cut is the \f$X\f$ solution of the next optimization problem:
   1.103  
   1.104  \f[ \min_{X \subset V, X\not\in \{\emptyset, V\}}
   1.105 -    \sum_{uv\in A, u\in X, v\not\in X}cap(uv) \f]
   1.106 +    \sum_{uv\in A: u\in X, v\not\in X}cap(uv) \f]
   1.107  
   1.108  LEMON contains several algorithms related to minimum cut problems:
   1.109  
   1.110 @@ -391,30 +443,6 @@
   1.111  */
   1.112  
   1.113  /**
   1.114 -@defgroup graph_properties Connectivity and Other Graph Properties
   1.115 -@ingroup algs
   1.116 -\brief Algorithms for discovering the graph properties
   1.117 -
   1.118 -This group contains the algorithms for discovering the graph properties
   1.119 -like connectivity, bipartiteness, euler property, simplicity etc.
   1.120 -
   1.121 -\image html edge_biconnected_components.png
   1.122 -\image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth
   1.123 -*/
   1.124 -
   1.125 -/**
   1.126 -@defgroup planar Planarity Embedding and Drawing
   1.127 -@ingroup algs
   1.128 -\brief Algorithms for planarity checking, embedding and drawing
   1.129 -
   1.130 -This group contains the algorithms for planarity checking,
   1.131 -embedding and drawing.
   1.132 -
   1.133 -\image html planar.png
   1.134 -\image latex planar.eps "Plane graph" width=\textwidth
   1.135 -*/
   1.136 -
   1.137 -/**
   1.138  @defgroup matching Matching Algorithms
   1.139  @ingroup algs
   1.140  \brief Algorithms for finding matchings in graphs and bipartite graphs.
   1.141 @@ -455,12 +483,36 @@
   1.142  */
   1.143  
   1.144  /**
   1.145 -@defgroup spantree Minimum Spanning Tree Algorithms
   1.146 +@defgroup graph_properties Connectivity and Other Graph Properties
   1.147  @ingroup algs
   1.148 -\brief Algorithms for finding minimum cost spanning trees and arborescences.
   1.149 +\brief Algorithms for discovering the graph properties
   1.150  
   1.151 -This group contains the algorithms for finding minimum cost spanning
   1.152 -trees and arborescences.
   1.153 +This group contains the algorithms for discovering the graph properties
   1.154 +like connectivity, bipartiteness, euler property, simplicity etc.
   1.155 +
   1.156 +\image html connected_components.png
   1.157 +\image latex connected_components.eps "Connected components" width=\textwidth
   1.158 +*/
   1.159 +
   1.160 +/**
   1.161 +@defgroup planar Planarity Embedding and Drawing
   1.162 +@ingroup algs
   1.163 +\brief Algorithms for planarity checking, embedding and drawing
   1.164 +
   1.165 +This group contains the algorithms for planarity checking,
   1.166 +embedding and drawing.
   1.167 +
   1.168 +\image html planar.png
   1.169 +\image latex planar.eps "Plane graph" width=\textwidth
   1.170 +*/
   1.171 +
   1.172 +/**
   1.173 +@defgroup approx Approximation Algorithms
   1.174 +@ingroup algs
   1.175 +\brief Approximation algorithms.
   1.176 +
   1.177 +This group contains the approximation and heuristic algorithms
   1.178 +implemented in LEMON.
   1.179  */
   1.180  
   1.181  /**
   1.182 @@ -473,15 +525,6 @@
   1.183  */
   1.184  
   1.185  /**
   1.186 -@defgroup approx Approximation Algorithms
   1.187 -@ingroup algs
   1.188 -\brief Approximation algorithms.
   1.189 -
   1.190 -This group contains the approximation and heuristic algorithms
   1.191 -implemented in LEMON.
   1.192 -*/
   1.193 -
   1.194 -/**
   1.195  @defgroup gen_opt_group General Optimization Tools
   1.196  \brief This group contains some general optimization frameworks
   1.197  implemented in LEMON.
   1.198 @@ -587,7 +630,7 @@
   1.199  */
   1.200  
   1.201  /**
   1.202 -@defgroup dimacs_group DIMACS format
   1.203 +@defgroup dimacs_group DIMACS Format
   1.204  @ingroup io_group
   1.205  \brief Read and write files in DIMACS format
   1.206  
   1.207 @@ -649,6 +692,15 @@
   1.208  */
   1.209  
   1.210  /**
   1.211 +@defgroup tools Standalone Utility Applications
   1.212 +
   1.213 +Some utility applications are listed here.
   1.214 +
   1.215 +The standard compilation procedure (<tt>./configure;make</tt>) will compile
   1.216 +them, as well.
   1.217 +*/
   1.218 +
   1.219 +/**
   1.220  \anchor demoprograms
   1.221  
   1.222  @defgroup demos Demo Programs
   1.223 @@ -660,13 +712,4 @@
   1.224  <tt>make check</tt> commands.
   1.225  */
   1.226  
   1.227 -/**
   1.228 -@defgroup tools Standalone Utility Applications
   1.229 -
   1.230 -Some utility applications are listed here.
   1.231 -
   1.232 -The standard compilation procedure (<tt>./configure;make</tt>) will compile
   1.233 -them, as well.
   1.234 -*/
   1.235 -
   1.236  }
     2.1 --- a/lemon/Makefile.am	Fri Sep 25 12:24:16 2009 +0200
     2.2 +++ b/lemon/Makefile.am	Sat Sep 26 07:08:10 2009 +0200
     2.3 @@ -57,8 +57,10 @@
     2.4  	lemon/adaptors.h \
     2.5  	lemon/arg_parser.h \
     2.6  	lemon/assert.h \
     2.7 +	lemon/bellman_ford.h \
     2.8  	lemon/bfs.h \
     2.9  	lemon/bin_heap.h \
    2.10 +	lemon/binom_heap.h \
    2.11  	lemon/bucket_heap.h \
    2.12  	lemon/cbc.h \
    2.13  	lemon/circulation.h \
    2.14 @@ -78,12 +80,14 @@
    2.15  	lemon/error.h \
    2.16  	lemon/euler.h \
    2.17  	lemon/fib_heap.h \
    2.18 +	lemon/fourary_heap.h \
    2.19  	lemon/full_graph.h \
    2.20  	lemon/glpk.h \
    2.21  	lemon/gomory_hu.h \
    2.22  	lemon/graph_to_eps.h \
    2.23  	lemon/grid_graph.h \
    2.24  	lemon/hypercube_graph.h \
    2.25 +	lemon/kary_heap.h \
    2.26  	lemon/kruskal.h \
    2.27  	lemon/hao_orlin.h \
    2.28  	lemon/lgf_reader.h \
    2.29 @@ -92,13 +96,13 @@
    2.30  	lemon/lp.h \
    2.31  	lemon/lp_base.h \
    2.32  	lemon/lp_skeleton.h \
    2.33 -	lemon/list_graph.h \
    2.34  	lemon/maps.h \
    2.35  	lemon/matching.h \
    2.36  	lemon/math.h \
    2.37  	lemon/min_cost_arborescence.h \
    2.38  	lemon/nauty_reader.h \
    2.39  	lemon/network_simplex.h \
    2.40 +	lemon/pairing_heap.h \
    2.41  	lemon/path.h \
    2.42  	lemon/preflow.h \
    2.43  	lemon/radix_heap.h \
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/lemon/bellman_ford.h	Sat Sep 26 07:08:10 2009 +0200
     3.3 @@ -0,0 +1,1100 @@
     3.4 +/* -*- C++ -*-
     3.5 + *
     3.6 + * This file is a part of LEMON, a generic C++ optimization library
     3.7 + *
     3.8 + * Copyright (C) 2003-2008
     3.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    3.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    3.11 + *
    3.12 + * Permission to use, modify and distribute this software is granted
    3.13 + * provided that this copyright notice appears in all copies. For
    3.14 + * precise terms see the accompanying LICENSE file.
    3.15 + *
    3.16 + * This software is provided "AS IS" with no warranty of any kind,
    3.17 + * express or implied, and with no claim as to its suitability for any
    3.18 + * purpose.
    3.19 + *
    3.20 + */
    3.21 +
    3.22 +#ifndef LEMON_BELLMAN_FORD_H
    3.23 +#define LEMON_BELLMAN_FORD_H
    3.24 +
    3.25 +/// \ingroup shortest_path
    3.26 +/// \file
    3.27 +/// \brief Bellman-Ford algorithm.
    3.28 +
    3.29 +#include <lemon/bits/path_dump.h>
    3.30 +#include <lemon/core.h>
    3.31 +#include <lemon/error.h>
    3.32 +#include <lemon/maps.h>
    3.33 +#include <lemon/path.h>
    3.34 +
    3.35 +#include <limits>
    3.36 +
    3.37 +namespace lemon {
    3.38 +
    3.39 +  /// \brief Default OperationTraits for the BellmanFord algorithm class.
    3.40 +  ///  
    3.41 +  /// This operation traits class defines all computational operations
    3.42 +  /// and constants that are used in the Bellman-Ford algorithm.
    3.43 +  /// The default implementation is based on the \c numeric_limits class.
    3.44 +  /// If the numeric type does not have infinity value, then the maximum
    3.45 +  /// value is used as extremal infinity value.
    3.46 +  template <
    3.47 +    typename V, 
    3.48 +    bool has_inf = std::numeric_limits<V>::has_infinity>
    3.49 +  struct BellmanFordDefaultOperationTraits {
    3.50 +    /// \e
    3.51 +    typedef V Value;
    3.52 +    /// \brief Gives back the zero value of the type.
    3.53 +    static Value zero() {
    3.54 +      return static_cast<Value>(0);
    3.55 +    }
    3.56 +    /// \brief Gives back the positive infinity value of the type.
    3.57 +    static Value infinity() {
    3.58 +      return std::numeric_limits<Value>::infinity();
    3.59 +    }
    3.60 +    /// \brief Gives back the sum of the given two elements.
    3.61 +    static Value plus(const Value& left, const Value& right) {
    3.62 +      return left + right;
    3.63 +    }
    3.64 +    /// \brief Gives back \c true only if the first value is less than
    3.65 +    /// the second.
    3.66 +    static bool less(const Value& left, const Value& right) {
    3.67 +      return left < right;
    3.68 +    }
    3.69 +  };
    3.70 +
    3.71 +  template <typename V>
    3.72 +  struct BellmanFordDefaultOperationTraits<V, false> {
    3.73 +    typedef V Value;
    3.74 +    static Value zero() {
    3.75 +      return static_cast<Value>(0);
    3.76 +    }
    3.77 +    static Value infinity() {
    3.78 +      return std::numeric_limits<Value>::max();
    3.79 +    }
    3.80 +    static Value plus(const Value& left, const Value& right) {
    3.81 +      if (left == infinity() || right == infinity()) return infinity();
    3.82 +      return left + right;
    3.83 +    }
    3.84 +    static bool less(const Value& left, const Value& right) {
    3.85 +      return left < right;
    3.86 +    }
    3.87 +  };
    3.88 +  
    3.89 +  /// \brief Default traits class of BellmanFord class.
    3.90 +  ///
    3.91 +  /// Default traits class of BellmanFord class.
    3.92 +  /// \param GR The type of the digraph.
    3.93 +  /// \param LEN The type of the length map.
    3.94 +  template<typename GR, typename LEN>
    3.95 +  struct BellmanFordDefaultTraits {
    3.96 +    /// The type of the digraph the algorithm runs on. 
    3.97 +    typedef GR Digraph;
    3.98 +
    3.99 +    /// \brief The type of the map that stores the arc lengths.
   3.100 +    ///
   3.101 +    /// The type of the map that stores the arc lengths.
   3.102 +    /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
   3.103 +    typedef LEN LengthMap;
   3.104 +
   3.105 +    /// The type of the arc lengths.
   3.106 +    typedef typename LEN::Value Value;
   3.107 +
   3.108 +    /// \brief Operation traits for Bellman-Ford algorithm.
   3.109 +    ///
   3.110 +    /// It defines the used operations and the infinity value for the
   3.111 +    /// given \c Value type.
   3.112 +    /// \see BellmanFordDefaultOperationTraits
   3.113 +    typedef BellmanFordDefaultOperationTraits<Value> OperationTraits;
   3.114 + 
   3.115 +    /// \brief The type of the map that stores the last arcs of the 
   3.116 +    /// shortest paths.
   3.117 +    /// 
   3.118 +    /// The type of the map that stores the last
   3.119 +    /// arcs of the shortest paths.
   3.120 +    /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   3.121 +    typedef typename GR::template NodeMap<typename GR::Arc> PredMap;
   3.122 +
   3.123 +    /// \brief Instantiates a \c PredMap.
   3.124 +    /// 
   3.125 +    /// This function instantiates a \ref PredMap. 
   3.126 +    /// \param g is the digraph to which we would like to define the
   3.127 +    /// \ref PredMap.
   3.128 +    static PredMap *createPredMap(const GR& g) {
   3.129 +      return new PredMap(g);
   3.130 +    }
   3.131 +
   3.132 +    /// \brief The type of the map that stores the distances of the nodes.
   3.133 +    ///
   3.134 +    /// The type of the map that stores the distances of the nodes.
   3.135 +    /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   3.136 +    typedef typename GR::template NodeMap<typename LEN::Value> DistMap;
   3.137 +
   3.138 +    /// \brief Instantiates a \c DistMap.
   3.139 +    ///
   3.140 +    /// This function instantiates a \ref DistMap. 
   3.141 +    /// \param g is the digraph to which we would like to define the 
   3.142 +    /// \ref DistMap.
   3.143 +    static DistMap *createDistMap(const GR& g) {
   3.144 +      return new DistMap(g);
   3.145 +    }
   3.146 +
   3.147 +  };
   3.148 +  
   3.149 +  /// \brief %BellmanFord algorithm class.
   3.150 +  ///
   3.151 +  /// \ingroup shortest_path
   3.152 +  /// This class provides an efficient implementation of the Bellman-Ford 
   3.153 +  /// algorithm. The maximum time complexity of the algorithm is
   3.154 +  /// <tt>O(ne)</tt>.
   3.155 +  ///
   3.156 +  /// The Bellman-Ford algorithm solves the single-source shortest path
   3.157 +  /// problem when the arcs can have negative lengths, but the digraph
   3.158 +  /// should not contain directed cycles with negative total length.
   3.159 +  /// If all arc costs are non-negative, consider to use the Dijkstra
   3.160 +  /// algorithm instead, since it is more efficient.
   3.161 +  ///
   3.162 +  /// The arc lengths are passed to the algorithm using a
   3.163 +  /// \ref concepts::ReadMap "ReadMap", so it is easy to change it to any 
   3.164 +  /// kind of length. The type of the length values is determined by the
   3.165 +  /// \ref concepts::ReadMap::Value "Value" type of the length map.
   3.166 +  ///
   3.167 +  /// There is also a \ref bellmanFord() "function-type interface" for the
   3.168 +  /// Bellman-Ford algorithm, which is convenient in the simplier cases and
   3.169 +  /// it can be used easier.
   3.170 +  ///
   3.171 +  /// \tparam GR The type of the digraph the algorithm runs on.
   3.172 +  /// The default type is \ref ListDigraph.
   3.173 +  /// \tparam LEN A \ref concepts::ReadMap "readable" arc map that specifies
   3.174 +  /// the lengths of the arcs. The default map type is
   3.175 +  /// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
   3.176 +#ifdef DOXYGEN
   3.177 +  template <typename GR, typename LEN, typename TR>
   3.178 +#else
   3.179 +  template <typename GR=ListDigraph,
   3.180 +            typename LEN=typename GR::template ArcMap<int>,
   3.181 +            typename TR=BellmanFordDefaultTraits<GR,LEN> >
   3.182 +#endif
   3.183 +  class BellmanFord {
   3.184 +  public:
   3.185 +
   3.186 +    ///The type of the underlying digraph.
   3.187 +    typedef typename TR::Digraph Digraph;
   3.188 +    
   3.189 +    /// \brief The type of the arc lengths.
   3.190 +    typedef typename TR::LengthMap::Value Value;
   3.191 +    /// \brief The type of the map that stores the arc lengths.
   3.192 +    typedef typename TR::LengthMap LengthMap;
   3.193 +    /// \brief The type of the map that stores the last
   3.194 +    /// arcs of the shortest paths.
   3.195 +    typedef typename TR::PredMap PredMap;
   3.196 +    /// \brief The type of the map that stores the distances of the nodes.
   3.197 +    typedef typename TR::DistMap DistMap;
   3.198 +    /// The type of the paths.
   3.199 +    typedef PredMapPath<Digraph, PredMap> Path;
   3.200 +    ///\brief The \ref BellmanFordDefaultOperationTraits
   3.201 +    /// "operation traits class" of the algorithm.
   3.202 +    typedef typename TR::OperationTraits OperationTraits;
   3.203 +
   3.204 +    ///The \ref BellmanFordDefaultTraits "traits class" of the algorithm.
   3.205 +    typedef TR Traits;
   3.206 +
   3.207 +  private:
   3.208 +
   3.209 +    typedef typename Digraph::Node Node;
   3.210 +    typedef typename Digraph::NodeIt NodeIt;
   3.211 +    typedef typename Digraph::Arc Arc;
   3.212 +    typedef typename Digraph::OutArcIt OutArcIt;
   3.213 +
   3.214 +    // Pointer to the underlying digraph.
   3.215 +    const Digraph *_gr;
   3.216 +    // Pointer to the length map
   3.217 +    const LengthMap *_length;
   3.218 +    // Pointer to the map of predecessors arcs.
   3.219 +    PredMap *_pred;
   3.220 +    // Indicates if _pred is locally allocated (true) or not.
   3.221 +    bool _local_pred;
   3.222 +    // Pointer to the map of distances.
   3.223 +    DistMap *_dist;
   3.224 +    // Indicates if _dist is locally allocated (true) or not.
   3.225 +    bool _local_dist;
   3.226 +
   3.227 +    typedef typename Digraph::template NodeMap<bool> MaskMap;
   3.228 +    MaskMap *_mask;
   3.229 +
   3.230 +    std::vector<Node> _process;
   3.231 +
   3.232 +    // Creates the maps if necessary.
   3.233 +    void create_maps() {
   3.234 +      if(!_pred) {
   3.235 +	_local_pred = true;
   3.236 +	_pred = Traits::createPredMap(*_gr);
   3.237 +      }
   3.238 +      if(!_dist) {
   3.239 +	_local_dist = true;
   3.240 +	_dist = Traits::createDistMap(*_gr);
   3.241 +      }
   3.242 +      _mask = new MaskMap(*_gr, false);
   3.243 +    }
   3.244 +    
   3.245 +  public :
   3.246 + 
   3.247 +    typedef BellmanFord Create;
   3.248 +
   3.249 +    /// \name Named Template Parameters
   3.250 +
   3.251 +    ///@{
   3.252 +
   3.253 +    template <class T>
   3.254 +    struct SetPredMapTraits : public Traits {
   3.255 +      typedef T PredMap;
   3.256 +      static PredMap *createPredMap(const Digraph&) {
   3.257 +        LEMON_ASSERT(false, "PredMap is not initialized");
   3.258 +        return 0; // ignore warnings
   3.259 +      }
   3.260 +    };
   3.261 +
   3.262 +    /// \brief \ref named-templ-param "Named parameter" for setting
   3.263 +    /// \c PredMap type.
   3.264 +    ///
   3.265 +    /// \ref named-templ-param "Named parameter" for setting
   3.266 +    /// \c PredMap type.
   3.267 +    /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   3.268 +    template <class T>
   3.269 +    struct SetPredMap 
   3.270 +      : public BellmanFord< Digraph, LengthMap, SetPredMapTraits<T> > {
   3.271 +      typedef BellmanFord< Digraph, LengthMap, SetPredMapTraits<T> > Create;
   3.272 +    };
   3.273 +    
   3.274 +    template <class T>
   3.275 +    struct SetDistMapTraits : public Traits {
   3.276 +      typedef T DistMap;
   3.277 +      static DistMap *createDistMap(const Digraph&) {
   3.278 +        LEMON_ASSERT(false, "DistMap is not initialized");
   3.279 +        return 0; // ignore warnings
   3.280 +      }
   3.281 +    };
   3.282 +
   3.283 +    /// \brief \ref named-templ-param "Named parameter" for setting
   3.284 +    /// \c DistMap type.
   3.285 +    ///
   3.286 +    /// \ref named-templ-param "Named parameter" for setting
   3.287 +    /// \c DistMap type.
   3.288 +    /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   3.289 +    template <class T>
   3.290 +    struct SetDistMap 
   3.291 +      : public BellmanFord< Digraph, LengthMap, SetDistMapTraits<T> > {
   3.292 +      typedef BellmanFord< Digraph, LengthMap, SetDistMapTraits<T> > Create;
   3.293 +    };
   3.294 +
   3.295 +    template <class T>
   3.296 +    struct SetOperationTraitsTraits : public Traits {
   3.297 +      typedef T OperationTraits;
   3.298 +    };
   3.299 +    
   3.300 +    /// \brief \ref named-templ-param "Named parameter" for setting 
   3.301 +    /// \c OperationTraits type.
   3.302 +    ///
   3.303 +    /// \ref named-templ-param "Named parameter" for setting
   3.304 +    /// \c OperationTraits type.
   3.305 +    /// For more information see \ref BellmanFordDefaultOperationTraits.
   3.306 +    template <class T>
   3.307 +    struct SetOperationTraits
   3.308 +      : public BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> > {
   3.309 +      typedef BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> >
   3.310 +      Create;
   3.311 +    };
   3.312 +    
   3.313 +    ///@}
   3.314 +
   3.315 +  protected:
   3.316 +    
   3.317 +    BellmanFord() {}
   3.318 +
   3.319 +  public:      
   3.320 +    
   3.321 +    /// \brief Constructor.
   3.322 +    ///
   3.323 +    /// Constructor.
   3.324 +    /// \param g The digraph the algorithm runs on.
   3.325 +    /// \param length The length map used by the algorithm.
   3.326 +    BellmanFord(const Digraph& g, const LengthMap& length) :
   3.327 +      _gr(&g), _length(&length),
   3.328 +      _pred(0), _local_pred(false),
   3.329 +      _dist(0), _local_dist(false), _mask(0) {}
   3.330 +    
   3.331 +    ///Destructor.
   3.332 +    ~BellmanFord() {
   3.333 +      if(_local_pred) delete _pred;
   3.334 +      if(_local_dist) delete _dist;
   3.335 +      if(_mask) delete _mask;
   3.336 +    }
   3.337 +
   3.338 +    /// \brief Sets the length map.
   3.339 +    ///
   3.340 +    /// Sets the length map.
   3.341 +    /// \return <tt>(*this)</tt>
   3.342 +    BellmanFord &lengthMap(const LengthMap &map) {
   3.343 +      _length = &map;
   3.344 +      return *this;
   3.345 +    }
   3.346 +
   3.347 +    /// \brief Sets the map that stores the predecessor arcs.
   3.348 +    ///
   3.349 +    /// Sets the map that stores the predecessor arcs.
   3.350 +    /// If you don't use this function before calling \ref run()
   3.351 +    /// or \ref init(), an instance will be allocated automatically.
   3.352 +    /// The destructor deallocates this automatically allocated map,
   3.353 +    /// of course.
   3.354 +    /// \return <tt>(*this)</tt>
   3.355 +    BellmanFord &predMap(PredMap &map) {
   3.356 +      if(_local_pred) {
   3.357 +	delete _pred;
   3.358 +	_local_pred=false;
   3.359 +      }
   3.360 +      _pred = &map;
   3.361 +      return *this;
   3.362 +    }
   3.363 +
   3.364 +    /// \brief Sets the map that stores the distances of the nodes.
   3.365 +    ///
   3.366 +    /// Sets the map that stores the distances of the nodes calculated
   3.367 +    /// by the algorithm.
   3.368 +    /// If you don't use this function before calling \ref run()
   3.369 +    /// or \ref init(), an instance will be allocated automatically.
   3.370 +    /// The destructor deallocates this automatically allocated map,
   3.371 +    /// of course.
   3.372 +    /// \return <tt>(*this)</tt>
   3.373 +    BellmanFord &distMap(DistMap &map) {
   3.374 +      if(_local_dist) {
   3.375 +	delete _dist;
   3.376 +	_local_dist=false;
   3.377 +      }
   3.378 +      _dist = &map;
   3.379 +      return *this;
   3.380 +    }
   3.381 +
   3.382 +    /// \name Execution Control
   3.383 +    /// The simplest way to execute the Bellman-Ford algorithm is to use
   3.384 +    /// one of the member functions called \ref run().\n
   3.385 +    /// If you need better control on the execution, you have to call
   3.386 +    /// \ref init() first, then you can add several source nodes
   3.387 +    /// with \ref addSource(). Finally the actual path computation can be
   3.388 +    /// performed with \ref start(), \ref checkedStart() or
   3.389 +    /// \ref limitedStart().
   3.390 +
   3.391 +    ///@{
   3.392 +
   3.393 +    /// \brief Initializes the internal data structures.
   3.394 +    /// 
   3.395 +    /// Initializes the internal data structures. The optional parameter
   3.396 +    /// is the initial distance of each node.
   3.397 +    void init(const Value value = OperationTraits::infinity()) {
   3.398 +      create_maps();
   3.399 +      for (NodeIt it(*_gr); it != INVALID; ++it) {
   3.400 +	_pred->set(it, INVALID);
   3.401 +	_dist->set(it, value);
   3.402 +      }
   3.403 +      _process.clear();
   3.404 +      if (OperationTraits::less(value, OperationTraits::infinity())) {
   3.405 +	for (NodeIt it(*_gr); it != INVALID; ++it) {
   3.406 +	  _process.push_back(it);
   3.407 +	  _mask->set(it, true);
   3.408 +	}
   3.409 +      }
   3.410 +    }
   3.411 +    
   3.412 +    /// \brief Adds a new source node.
   3.413 +    ///
   3.414 +    /// This function adds a new source node. The optional second parameter
   3.415 +    /// is the initial distance of the node.
   3.416 +    void addSource(Node source, Value dst = OperationTraits::zero()) {
   3.417 +      _dist->set(source, dst);
   3.418 +      if (!(*_mask)[source]) {
   3.419 +	_process.push_back(source);
   3.420 +	_mask->set(source, true);
   3.421 +      }
   3.422 +    }
   3.423 +
   3.424 +    /// \brief Executes one round from the Bellman-Ford algorithm.
   3.425 +    ///
   3.426 +    /// If the algoritm calculated the distances in the previous round
   3.427 +    /// exactly for the paths of at most \c k arcs, then this function
   3.428 +    /// will calculate the distances exactly for the paths of at most
   3.429 +    /// <tt>k+1</tt> arcs. Performing \c k iterations using this function
   3.430 +    /// calculates the shortest path distances exactly for the paths
   3.431 +    /// consisting of at most \c k arcs.
   3.432 +    ///
   3.433 +    /// \warning The paths with limited arc number cannot be retrieved
   3.434 +    /// easily with \ref path() or \ref predArc() functions. If you also
   3.435 +    /// need the shortest paths and not only the distances, you should
   3.436 +    /// store the \ref predMap() "predecessor map" after each iteration
   3.437 +    /// and build the path manually.
   3.438 +    ///
   3.439 +    /// \return \c true when the algorithm have not found more shorter
   3.440 +    /// paths.
   3.441 +    ///
   3.442 +    /// \see ActiveIt
   3.443 +    bool processNextRound() {
   3.444 +      for (int i = 0; i < int(_process.size()); ++i) {
   3.445 +	_mask->set(_process[i], false);
   3.446 +      }
   3.447 +      std::vector<Node> nextProcess;
   3.448 +      std::vector<Value> values(_process.size());
   3.449 +      for (int i = 0; i < int(_process.size()); ++i) {
   3.450 +	values[i] = (*_dist)[_process[i]];
   3.451 +      }
   3.452 +      for (int i = 0; i < int(_process.size()); ++i) {
   3.453 +	for (OutArcIt it(*_gr, _process[i]); it != INVALID; ++it) {
   3.454 +	  Node target = _gr->target(it);
   3.455 +	  Value relaxed = OperationTraits::plus(values[i], (*_length)[it]);
   3.456 +	  if (OperationTraits::less(relaxed, (*_dist)[target])) {
   3.457 +	    _pred->set(target, it);
   3.458 +	    _dist->set(target, relaxed);
   3.459 +	    if (!(*_mask)[target]) {
   3.460 +	      _mask->set(target, true);
   3.461 +	      nextProcess.push_back(target);
   3.462 +	    }
   3.463 +	  }	  
   3.464 +	}
   3.465 +      }
   3.466 +      _process.swap(nextProcess);
   3.467 +      return _process.empty();
   3.468 +    }
   3.469 +
   3.470 +    /// \brief Executes one weak round from the Bellman-Ford algorithm.
   3.471 +    ///
   3.472 +    /// If the algorithm calculated the distances in the previous round
   3.473 +    /// at least for the paths of at most \c k arcs, then this function
   3.474 +    /// will calculate the distances at least for the paths of at most
   3.475 +    /// <tt>k+1</tt> arcs.
   3.476 +    /// This function does not make it possible to calculate the shortest
   3.477 +    /// path distances exactly for paths consisting of at most \c k arcs,
   3.478 +    /// this is why it is called weak round.
   3.479 +    ///
   3.480 +    /// \return \c true when the algorithm have not found more shorter
   3.481 +    /// paths.
   3.482 +    ///
   3.483 +    /// \see ActiveIt
   3.484 +    bool processNextWeakRound() {
   3.485 +      for (int i = 0; i < int(_process.size()); ++i) {
   3.486 +	_mask->set(_process[i], false);
   3.487 +      }
   3.488 +      std::vector<Node> nextProcess;
   3.489 +      for (int i = 0; i < int(_process.size()); ++i) {
   3.490 +	for (OutArcIt it(*_gr, _process[i]); it != INVALID; ++it) {
   3.491 +	  Node target = _gr->target(it);
   3.492 +	  Value relaxed = 
   3.493 +	    OperationTraits::plus((*_dist)[_process[i]], (*_length)[it]);
   3.494 +	  if (OperationTraits::less(relaxed, (*_dist)[target])) {
   3.495 +	    _pred->set(target, it);
   3.496 +	    _dist->set(target, relaxed);
   3.497 +	    if (!(*_mask)[target]) {
   3.498 +	      _mask->set(target, true);
   3.499 +	      nextProcess.push_back(target);
   3.500 +	    }
   3.501 +	  }	  
   3.502 +	}
   3.503 +      }
   3.504 +      _process.swap(nextProcess);
   3.505 +      return _process.empty();
   3.506 +    }
   3.507 +
   3.508 +    /// \brief Executes the algorithm.
   3.509 +    ///
   3.510 +    /// Executes the algorithm.
   3.511 +    ///
   3.512 +    /// This method runs the Bellman-Ford algorithm from the root node(s)
   3.513 +    /// in order to compute the shortest path to each node.
   3.514 +    ///
   3.515 +    /// The algorithm computes
   3.516 +    /// - the shortest path tree (forest),
   3.517 +    /// - the distance of each node from the root(s).
   3.518 +    ///
   3.519 +    /// \pre init() must be called and at least one root node should be
   3.520 +    /// added with addSource() before using this function.
   3.521 +    void start() {
   3.522 +      int num = countNodes(*_gr) - 1;
   3.523 +      for (int i = 0; i < num; ++i) {
   3.524 +	if (processNextWeakRound()) break;
   3.525 +      }
   3.526 +    }
   3.527 +
   3.528 +    /// \brief Executes the algorithm and checks the negative cycles.
   3.529 +    ///
   3.530 +    /// Executes the algorithm and checks the negative cycles.
   3.531 +    ///
   3.532 +    /// This method runs the Bellman-Ford algorithm from the root node(s)
   3.533 +    /// in order to compute the shortest path to each node and also checks
   3.534 +    /// if the digraph contains cycles with negative total length.
   3.535 +    ///
   3.536 +    /// The algorithm computes 
   3.537 +    /// - the shortest path tree (forest),
   3.538 +    /// - the distance of each node from the root(s).
   3.539 +    /// 
   3.540 +    /// \return \c false if there is a negative cycle in the digraph.
   3.541 +    ///
   3.542 +    /// \pre init() must be called and at least one root node should be
   3.543 +    /// added with addSource() before using this function. 
   3.544 +    bool checkedStart() {
   3.545 +      int num = countNodes(*_gr);
   3.546 +      for (int i = 0; i < num; ++i) {
   3.547 +	if (processNextWeakRound()) return true;
   3.548 +      }
   3.549 +      return _process.empty();
   3.550 +    }
   3.551 +
   3.552 +    /// \brief Executes the algorithm with arc number limit.
   3.553 +    ///
   3.554 +    /// Executes the algorithm with arc number limit.
   3.555 +    ///
   3.556 +    /// This method runs the Bellman-Ford algorithm from the root node(s)
   3.557 +    /// in order to compute the shortest path distance for each node
   3.558 +    /// using only the paths consisting of at most \c num arcs.
   3.559 +    ///
   3.560 +    /// The algorithm computes
   3.561 +    /// - the limited distance of each node from the root(s),
   3.562 +    /// - the predecessor arc for each node.
   3.563 +    ///
   3.564 +    /// \warning The paths with limited arc number cannot be retrieved
   3.565 +    /// easily with \ref path() or \ref predArc() functions. If you also
   3.566 +    /// need the shortest paths and not only the distances, you should
   3.567 +    /// store the \ref predMap() "predecessor map" after each iteration
   3.568 +    /// and build the path manually.
   3.569 +    ///
   3.570 +    /// \pre init() must be called and at least one root node should be
   3.571 +    /// added with addSource() before using this function. 
   3.572 +    void limitedStart(int num) {
   3.573 +      for (int i = 0; i < num; ++i) {
   3.574 +	if (processNextRound()) break;
   3.575 +      }
   3.576 +    }
   3.577 +    
   3.578 +    /// \brief Runs the algorithm from the given root node.
   3.579 +    ///    
   3.580 +    /// This method runs the Bellman-Ford algorithm from the given root
   3.581 +    /// node \c s in order to compute the shortest path to each node.
   3.582 +    ///
   3.583 +    /// The algorithm computes
   3.584 +    /// - the shortest path tree (forest),
   3.585 +    /// - the distance of each node from the root(s).
   3.586 +    ///
   3.587 +    /// \note bf.run(s) is just a shortcut of the following code.
   3.588 +    /// \code
   3.589 +    ///   bf.init();
   3.590 +    ///   bf.addSource(s);
   3.591 +    ///   bf.start();
   3.592 +    /// \endcode
   3.593 +    void run(Node s) {
   3.594 +      init();
   3.595 +      addSource(s);
   3.596 +      start();
   3.597 +    }
   3.598 +    
   3.599 +    /// \brief Runs the algorithm from the given root node with arc
   3.600 +    /// number limit.
   3.601 +    ///    
   3.602 +    /// This method runs the Bellman-Ford algorithm from the given root
   3.603 +    /// node \c s in order to compute the shortest path distance for each
   3.604 +    /// node using only the paths consisting of at most \c num arcs.
   3.605 +    ///
   3.606 +    /// The algorithm computes
   3.607 +    /// - the limited distance of each node from the root(s),
   3.608 +    /// - the predecessor arc for each node.
   3.609 +    ///
   3.610 +    /// \warning The paths with limited arc number cannot be retrieved
   3.611 +    /// easily with \ref path() or \ref predArc() functions. If you also
   3.612 +    /// need the shortest paths and not only the distances, you should
   3.613 +    /// store the \ref predMap() "predecessor map" after each iteration
   3.614 +    /// and build the path manually.
   3.615 +    ///
   3.616 +    /// \note bf.run(s, num) is just a shortcut of the following code.
   3.617 +    /// \code
   3.618 +    ///   bf.init();
   3.619 +    ///   bf.addSource(s);
   3.620 +    ///   bf.limitedStart(num);
   3.621 +    /// \endcode
   3.622 +    void run(Node s, int num) {
   3.623 +      init();
   3.624 +      addSource(s);
   3.625 +      limitedStart(num);
   3.626 +    }
   3.627 +    
   3.628 +    ///@}
   3.629 +
   3.630 +    /// \brief LEMON iterator for getting the active nodes.
   3.631 +    ///
   3.632 +    /// This class provides a common style LEMON iterator that traverses
   3.633 +    /// the active nodes of the Bellman-Ford algorithm after the last
   3.634 +    /// phase. These nodes should be checked in the next phase to
   3.635 +    /// find augmenting arcs outgoing from them.
   3.636 +    class ActiveIt {
   3.637 +    public:
   3.638 +
   3.639 +      /// \brief Constructor.
   3.640 +      ///
   3.641 +      /// Constructor for getting the active nodes of the given BellmanFord
   3.642 +      /// instance. 
   3.643 +      ActiveIt(const BellmanFord& algorithm) : _algorithm(&algorithm)
   3.644 +      {
   3.645 +        _index = _algorithm->_process.size() - 1;
   3.646 +      }
   3.647 +
   3.648 +      /// \brief Invalid constructor.
   3.649 +      ///
   3.650 +      /// Invalid constructor.
   3.651 +      ActiveIt(Invalid) : _algorithm(0), _index(-1) {}
   3.652 +
   3.653 +      /// \brief Conversion to \c Node.
   3.654 +      ///
   3.655 +      /// Conversion to \c Node.
   3.656 +      operator Node() const { 
   3.657 +        return _index >= 0 ? _algorithm->_process[_index] : INVALID;
   3.658 +      }
   3.659 +
   3.660 +      /// \brief Increment operator.
   3.661 +      ///
   3.662 +      /// Increment operator.
   3.663 +      ActiveIt& operator++() {
   3.664 +        --_index;
   3.665 +        return *this; 
   3.666 +      }
   3.667 +
   3.668 +      bool operator==(const ActiveIt& it) const { 
   3.669 +        return static_cast<Node>(*this) == static_cast<Node>(it); 
   3.670 +      }
   3.671 +      bool operator!=(const ActiveIt& it) const { 
   3.672 +        return static_cast<Node>(*this) != static_cast<Node>(it); 
   3.673 +      }
   3.674 +      bool operator<(const ActiveIt& it) const { 
   3.675 +        return static_cast<Node>(*this) < static_cast<Node>(it); 
   3.676 +      }
   3.677 +      
   3.678 +    private:
   3.679 +      const BellmanFord* _algorithm;
   3.680 +      int _index;
   3.681 +    };
   3.682 +    
   3.683 +    /// \name Query Functions
   3.684 +    /// The result of the Bellman-Ford algorithm can be obtained using these
   3.685 +    /// functions.\n
   3.686 +    /// Either \ref run() or \ref init() should be called before using them.
   3.687 +    
   3.688 +    ///@{
   3.689 +
   3.690 +    /// \brief The shortest path to the given node.
   3.691 +    ///    
   3.692 +    /// Gives back the shortest path to the given node from the root(s).
   3.693 +    ///
   3.694 +    /// \warning \c t should be reached from the root(s).
   3.695 +    ///
   3.696 +    /// \pre Either \ref run() or \ref init() must be called before
   3.697 +    /// using this function.
   3.698 +    Path path(Node t) const
   3.699 +    {
   3.700 +      return Path(*_gr, *_pred, t);
   3.701 +    }
   3.702 +	  
   3.703 +    /// \brief The distance of the given node from the root(s).
   3.704 +    ///
   3.705 +    /// Returns the distance of the given node from the root(s).
   3.706 +    ///
   3.707 +    /// \warning If node \c v is not reached from the root(s), then
   3.708 +    /// the return value of this function is undefined.
   3.709 +    ///
   3.710 +    /// \pre Either \ref run() or \ref init() must be called before
   3.711 +    /// using this function.
   3.712 +    Value dist(Node v) const { return (*_dist)[v]; }
   3.713 +
   3.714 +    /// \brief Returns the 'previous arc' of the shortest path tree for
   3.715 +    /// the given node.
   3.716 +    ///
   3.717 +    /// This function returns the 'previous arc' of the shortest path
   3.718 +    /// tree for node \c v, i.e. it returns the last arc of a
   3.719 +    /// shortest path from a root to \c v. It is \c INVALID if \c v
   3.720 +    /// is not reached from the root(s) or if \c v is a root.
   3.721 +    ///
   3.722 +    /// The shortest path tree used here is equal to the shortest path
   3.723 +    /// tree used in \ref predNode() and \predMap().
   3.724 +    ///
   3.725 +    /// \pre Either \ref run() or \ref init() must be called before
   3.726 +    /// using this function.
   3.727 +    Arc predArc(Node v) const { return (*_pred)[v]; }
   3.728 +
   3.729 +    /// \brief Returns the 'previous node' of the shortest path tree for
   3.730 +    /// the given node.
   3.731 +    ///
   3.732 +    /// This function returns the 'previous node' of the shortest path
   3.733 +    /// tree for node \c v, i.e. it returns the last but one node of
   3.734 +    /// a shortest path from a root to \c v. It is \c INVALID if \c v
   3.735 +    /// is not reached from the root(s) or if \c v is a root.
   3.736 +    ///
   3.737 +    /// The shortest path tree used here is equal to the shortest path
   3.738 +    /// tree used in \ref predArc() and \predMap().
   3.739 +    ///
   3.740 +    /// \pre Either \ref run() or \ref init() must be called before
   3.741 +    /// using this function.
   3.742 +    Node predNode(Node v) const { 
   3.743 +      return (*_pred)[v] == INVALID ? INVALID : _gr->source((*_pred)[v]); 
   3.744 +    }
   3.745 +    
   3.746 +    /// \brief Returns a const reference to the node map that stores the
   3.747 +    /// distances of the nodes.
   3.748 +    ///
   3.749 +    /// Returns a const reference to the node map that stores the distances
   3.750 +    /// of the nodes calculated by the algorithm.
   3.751 +    ///
   3.752 +    /// \pre Either \ref run() or \ref init() must be called before
   3.753 +    /// using this function.
   3.754 +    const DistMap &distMap() const { return *_dist;}
   3.755 + 
   3.756 +    /// \brief Returns a const reference to the node map that stores the
   3.757 +    /// predecessor arcs.
   3.758 +    ///
   3.759 +    /// Returns a const reference to the node map that stores the predecessor
   3.760 +    /// arcs, which form the shortest path tree (forest).
   3.761 +    ///
   3.762 +    /// \pre Either \ref run() or \ref init() must be called before
   3.763 +    /// using this function.
   3.764 +    const PredMap &predMap() const { return *_pred; }
   3.765 + 
   3.766 +    /// \brief Checks if a node is reached from the root(s).
   3.767 +    ///
   3.768 +    /// Returns \c true if \c v is reached from the root(s).
   3.769 +    ///
   3.770 +    /// \pre Either \ref run() or \ref init() must be called before
   3.771 +    /// using this function.
   3.772 +    bool reached(Node v) const {
   3.773 +      return (*_dist)[v] != OperationTraits::infinity();
   3.774 +    }
   3.775 +
   3.776 +    /// \brief Gives back a negative cycle.
   3.777 +    ///    
   3.778 +    /// This function gives back a directed cycle with negative total
   3.779 +    /// length if the algorithm has already found one.
   3.780 +    /// Otherwise it gives back an empty path.
   3.781 +    lemon::Path<Digraph> negativeCycle() {
   3.782 +      typename Digraph::template NodeMap<int> state(*_gr, -1);
   3.783 +      lemon::Path<Digraph> cycle;
   3.784 +      for (int i = 0; i < int(_process.size()); ++i) {
   3.785 +        if (state[_process[i]] != -1) continue;
   3.786 +        for (Node v = _process[i]; (*_pred)[v] != INVALID;
   3.787 +             v = _gr->source((*_pred)[v])) {
   3.788 +          if (state[v] == i) {
   3.789 +            cycle.addFront((*_pred)[v]);
   3.790 +            for (Node u = _gr->source((*_pred)[v]); u != v;
   3.791 +                 u = _gr->source((*_pred)[u])) {
   3.792 +              cycle.addFront((*_pred)[u]);
   3.793 +            }
   3.794 +            return cycle;
   3.795 +          }
   3.796 +          else if (state[v] >= 0) {
   3.797 +            break;
   3.798 +          }
   3.799 +          state[v] = i;
   3.800 +        }
   3.801 +      }
   3.802 +      return cycle;
   3.803 +    }
   3.804 +    
   3.805 +    ///@}
   3.806 +  };
   3.807 + 
   3.808 +  /// \brief Default traits class of bellmanFord() function.
   3.809 +  ///
   3.810 +  /// Default traits class of bellmanFord() function.
   3.811 +  /// \tparam GR The type of the digraph.
   3.812 +  /// \tparam LEN The type of the length map.
   3.813 +  template <typename GR, typename LEN>
   3.814 +  struct BellmanFordWizardDefaultTraits {
   3.815 +    /// The type of the digraph the algorithm runs on. 
   3.816 +    typedef GR Digraph;
   3.817 +
   3.818 +    /// \brief The type of the map that stores the arc lengths.
   3.819 +    ///
   3.820 +    /// The type of the map that stores the arc lengths.
   3.821 +    /// It must meet the \ref concepts::ReadMap "ReadMap" concept.
   3.822 +    typedef LEN LengthMap;
   3.823 +
   3.824 +    /// The type of the arc lengths.
   3.825 +    typedef typename LEN::Value Value;
   3.826 +
   3.827 +    /// \brief Operation traits for Bellman-Ford algorithm.
   3.828 +    ///
   3.829 +    /// It defines the used operations and the infinity value for the
   3.830 +    /// given \c Value type.
   3.831 +    /// \see BellmanFordDefaultOperationTraits
   3.832 +    typedef BellmanFordDefaultOperationTraits<Value> OperationTraits;
   3.833 +
   3.834 +    /// \brief The type of the map that stores the last
   3.835 +    /// arcs of the shortest paths.
   3.836 +    /// 
   3.837 +    /// The type of the map that stores the last arcs of the shortest paths.
   3.838 +    /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   3.839 +    typedef typename GR::template NodeMap<typename GR::Arc> PredMap;
   3.840 +
   3.841 +    /// \brief Instantiates a \c PredMap.
   3.842 +    /// 
   3.843 +    /// This function instantiates a \ref PredMap.
   3.844 +    /// \param g is the digraph to which we would like to define the
   3.845 +    /// \ref PredMap.
   3.846 +    static PredMap *createPredMap(const GR &g) {
   3.847 +      return new PredMap(g);
   3.848 +    }
   3.849 +
   3.850 +    /// \brief The type of the map that stores the distances of the nodes.
   3.851 +    ///
   3.852 +    /// The type of the map that stores the distances of the nodes.
   3.853 +    /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   3.854 +    typedef typename GR::template NodeMap<Value> DistMap;
   3.855 +
   3.856 +    /// \brief Instantiates a \c DistMap.
   3.857 +    ///
   3.858 +    /// This function instantiates a \ref DistMap. 
   3.859 +    /// \param g is the digraph to which we would like to define the
   3.860 +    /// \ref DistMap.
   3.861 +    static DistMap *createDistMap(const GR &g) {
   3.862 +      return new DistMap(g);
   3.863 +    }
   3.864 +
   3.865 +    ///The type of the shortest paths.
   3.866 +
   3.867 +    ///The type of the shortest paths.
   3.868 +    ///It must meet the \ref concepts::Path "Path" concept.
   3.869 +    typedef lemon::Path<Digraph> Path;
   3.870 +  };
   3.871 +  
   3.872 +  /// \brief Default traits class used by BellmanFordWizard.
   3.873 +  ///
   3.874 +  /// Default traits class used by BellmanFordWizard.
   3.875 +  /// \tparam GR The type of the digraph.
   3.876 +  /// \tparam LEN The type of the length map.
   3.877 +  template <typename GR, typename LEN>
   3.878 +  class BellmanFordWizardBase 
   3.879 +    : public BellmanFordWizardDefaultTraits<GR, LEN> {
   3.880 +
   3.881 +    typedef BellmanFordWizardDefaultTraits<GR, LEN> Base;
   3.882 +  protected:
   3.883 +    // Type of the nodes in the digraph.
   3.884 +    typedef typename Base::Digraph::Node Node;
   3.885 +
   3.886 +    // Pointer to the underlying digraph.
   3.887 +    void *_graph;
   3.888 +    // Pointer to the length map
   3.889 +    void *_length;
   3.890 +    // Pointer to the map of predecessors arcs.
   3.891 +    void *_pred;
   3.892 +    // Pointer to the map of distances.
   3.893 +    void *_dist;
   3.894 +    //Pointer to the shortest path to the target node.
   3.895 +    void *_path;
   3.896 +    //Pointer to the distance of the target node.
   3.897 +    void *_di;
   3.898 +
   3.899 +    public:
   3.900 +    /// Constructor.
   3.901 +    
   3.902 +    /// This constructor does not require parameters, it initiates
   3.903 +    /// all of the attributes to default values \c 0.
   3.904 +    BellmanFordWizardBase() :
   3.905 +      _graph(0), _length(0), _pred(0), _dist(0), _path(0), _di(0) {}
   3.906 +
   3.907 +    /// Constructor.
   3.908 +    
   3.909 +    /// This constructor requires two parameters,
   3.910 +    /// others are initiated to \c 0.
   3.911 +    /// \param gr The digraph the algorithm runs on.
   3.912 +    /// \param len The length map.
   3.913 +    BellmanFordWizardBase(const GR& gr, 
   3.914 +			  const LEN& len) :
   3.915 +      _graph(reinterpret_cast<void*>(const_cast<GR*>(&gr))), 
   3.916 +      _length(reinterpret_cast<void*>(const_cast<LEN*>(&len))), 
   3.917 +      _pred(0), _dist(0), _path(0), _di(0) {}
   3.918 +
   3.919 +  };
   3.920 +  
   3.921 +  /// \brief Auxiliary class for the function-type interface of the
   3.922 +  /// \ref BellmanFord "Bellman-Ford" algorithm.
   3.923 +  ///
   3.924 +  /// This auxiliary class is created to implement the
   3.925 +  /// \ref bellmanFord() "function-type interface" of the
   3.926 +  /// \ref BellmanFord "Bellman-Ford" algorithm.
   3.927 +  /// It does not have own \ref run() method, it uses the
   3.928 +  /// functions and features of the plain \ref BellmanFord.
   3.929 +  ///
   3.930 +  /// This class should only be used through the \ref bellmanFord()
   3.931 +  /// function, which makes it easier to use the algorithm.
   3.932 +  template<class TR>
   3.933 +  class BellmanFordWizard : public TR {
   3.934 +    typedef TR Base;
   3.935 +
   3.936 +    typedef typename TR::Digraph Digraph;
   3.937 +
   3.938 +    typedef typename Digraph::Node Node;
   3.939 +    typedef typename Digraph::NodeIt NodeIt;
   3.940 +    typedef typename Digraph::Arc Arc;
   3.941 +    typedef typename Digraph::OutArcIt ArcIt;
   3.942 +    
   3.943 +    typedef typename TR::LengthMap LengthMap;
   3.944 +    typedef typename LengthMap::Value Value;
   3.945 +    typedef typename TR::PredMap PredMap;
   3.946 +    typedef typename TR::DistMap DistMap;
   3.947 +    typedef typename TR::Path Path;
   3.948 +
   3.949 +  public:
   3.950 +    /// Constructor.
   3.951 +    BellmanFordWizard() : TR() {}
   3.952 +
   3.953 +    /// \brief Constructor that requires parameters.
   3.954 +    ///
   3.955 +    /// Constructor that requires parameters.
   3.956 +    /// These parameters will be the default values for the traits class.
   3.957 +    /// \param gr The digraph the algorithm runs on.
   3.958 +    /// \param len The length map.
   3.959 +    BellmanFordWizard(const Digraph& gr, const LengthMap& len) 
   3.960 +      : TR(gr, len) {}
   3.961 +
   3.962 +    /// \brief Copy constructor
   3.963 +    BellmanFordWizard(const TR &b) : TR(b) {}
   3.964 +
   3.965 +    ~BellmanFordWizard() {}
   3.966 +
   3.967 +    /// \brief Runs the Bellman-Ford algorithm from the given source node.
   3.968 +    ///    
   3.969 +    /// This method runs the Bellman-Ford algorithm from the given source
   3.970 +    /// node in order to compute the shortest path to each node.
   3.971 +    void run(Node s) {
   3.972 +      BellmanFord<Digraph,LengthMap,TR> 
   3.973 +	bf(*reinterpret_cast<const Digraph*>(Base::_graph), 
   3.974 +           *reinterpret_cast<const LengthMap*>(Base::_length));
   3.975 +      if (Base::_pred) bf.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
   3.976 +      if (Base::_dist) bf.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
   3.977 +      bf.run(s);
   3.978 +    }
   3.979 +
   3.980 +    /// \brief Runs the Bellman-Ford algorithm to find the shortest path
   3.981 +    /// between \c s and \c t.
   3.982 +    ///
   3.983 +    /// This method runs the Bellman-Ford algorithm from node \c s
   3.984 +    /// in order to compute the shortest path to node \c t.
   3.985 +    /// Actually, it computes the shortest path to each node, but using
   3.986 +    /// this function you can retrieve the distance and the shortest path
   3.987 +    /// for a single target node easier.
   3.988 +    ///
   3.989 +    /// \return \c true if \c t is reachable form \c s.
   3.990 +    bool run(Node s, Node t) {
   3.991 +      BellmanFord<Digraph,LengthMap,TR>
   3.992 +        bf(*reinterpret_cast<const Digraph*>(Base::_graph),
   3.993 +           *reinterpret_cast<const LengthMap*>(Base::_length));
   3.994 +      if (Base::_pred) bf.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
   3.995 +      if (Base::_dist) bf.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
   3.996 +      bf.run(s);
   3.997 +      if (Base::_path) *reinterpret_cast<Path*>(Base::_path) = bf.path(t);
   3.998 +      if (Base::_di) *reinterpret_cast<Value*>(Base::_di) = bf.dist(t);
   3.999 +      return bf.reached(t);
  3.1000 +    }
  3.1001 +
  3.1002 +    template<class T>
  3.1003 +    struct SetPredMapBase : public Base {
  3.1004 +      typedef T PredMap;
  3.1005 +      static PredMap *createPredMap(const Digraph &) { return 0; };
  3.1006 +      SetPredMapBase(const TR &b) : TR(b) {}
  3.1007 +    };
  3.1008 +    
  3.1009 +    /// \brief \ref named-templ-param "Named parameter" for setting
  3.1010 +    /// the predecessor map.
  3.1011 +    ///
  3.1012 +    /// \ref named-templ-param "Named parameter" for setting
  3.1013 +    /// the map that stores the predecessor arcs of the nodes.
  3.1014 +    template<class T>
  3.1015 +    BellmanFordWizard<SetPredMapBase<T> > predMap(const T &t) {
  3.1016 +      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
  3.1017 +      return BellmanFordWizard<SetPredMapBase<T> >(*this);
  3.1018 +    }
  3.1019 +    
  3.1020 +    template<class T>
  3.1021 +    struct SetDistMapBase : public Base {
  3.1022 +      typedef T DistMap;
  3.1023 +      static DistMap *createDistMap(const Digraph &) { return 0; };
  3.1024 +      SetDistMapBase(const TR &b) : TR(b) {}
  3.1025 +    };
  3.1026 +    
  3.1027 +    /// \brief \ref named-templ-param "Named parameter" for setting
  3.1028 +    /// the distance map.
  3.1029 +    ///
  3.1030 +    /// \ref named-templ-param "Named parameter" for setting
  3.1031 +    /// the map that stores the distances of the nodes calculated
  3.1032 +    /// by the algorithm.
  3.1033 +    template<class T>
  3.1034 +    BellmanFordWizard<SetDistMapBase<T> > distMap(const T &t) {
  3.1035 +      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
  3.1036 +      return BellmanFordWizard<SetDistMapBase<T> >(*this);
  3.1037 +    }
  3.1038 +
  3.1039 +    template<class T>
  3.1040 +    struct SetPathBase : public Base {
  3.1041 +      typedef T Path;
  3.1042 +      SetPathBase(const TR &b) : TR(b) {}
  3.1043 +    };
  3.1044 +
  3.1045 +    /// \brief \ref named-func-param "Named parameter" for getting
  3.1046 +    /// the shortest path to the target node.
  3.1047 +    ///
  3.1048 +    /// \ref named-func-param "Named parameter" for getting
  3.1049 +    /// the shortest path to the target node.
  3.1050 +    template<class T>
  3.1051 +    BellmanFordWizard<SetPathBase<T> > path(const T &t)
  3.1052 +    {
  3.1053 +      Base::_path=reinterpret_cast<void*>(const_cast<T*>(&t));
  3.1054 +      return BellmanFordWizard<SetPathBase<T> >(*this);
  3.1055 +    }
  3.1056 +
  3.1057 +    /// \brief \ref named-func-param "Named parameter" for getting
  3.1058 +    /// the distance of the target node.
  3.1059 +    ///
  3.1060 +    /// \ref named-func-param "Named parameter" for getting
  3.1061 +    /// the distance of the target node.
  3.1062 +    BellmanFordWizard dist(const Value &d)
  3.1063 +    {
  3.1064 +      Base::_di=reinterpret_cast<void*>(const_cast<Value*>(&d));
  3.1065 +      return *this;
  3.1066 +    }
  3.1067 +    
  3.1068 +  };
  3.1069 +  
  3.1070 +  /// \brief Function type interface for the \ref BellmanFord "Bellman-Ford"
  3.1071 +  /// algorithm.
  3.1072 +  ///
  3.1073 +  /// \ingroup shortest_path
  3.1074 +  /// Function type interface for the \ref BellmanFord "Bellman-Ford"
  3.1075 +  /// algorithm.
  3.1076 +  ///
  3.1077 +  /// This function also has several \ref named-templ-func-param 
  3.1078 +  /// "named parameters", they are declared as the members of class 
  3.1079 +  /// \ref BellmanFordWizard.
  3.1080 +  /// The following examples show how to use these parameters.
  3.1081 +  /// \code
  3.1082 +  ///   // Compute shortest path from node s to each node
  3.1083 +  ///   bellmanFord(g,length).predMap(preds).distMap(dists).run(s);
  3.1084 +  ///
  3.1085 +  ///   // Compute shortest path from s to t
  3.1086 +  ///   bool reached = bellmanFord(g,length).path(p).dist(d).run(s,t);
  3.1087 +  /// \endcode
  3.1088 +  /// \warning Don't forget to put the \ref BellmanFordWizard::run() "run()"
  3.1089 +  /// to the end of the parameter list.
  3.1090 +  /// \sa BellmanFordWizard
  3.1091 +  /// \sa BellmanFord
  3.1092 +  template<typename GR, typename LEN>
  3.1093 +  BellmanFordWizard<BellmanFordWizardBase<GR,LEN> >
  3.1094 +  bellmanFord(const GR& digraph,
  3.1095 +	      const LEN& length)
  3.1096 +  {
  3.1097 +    return BellmanFordWizard<BellmanFordWizardBase<GR,LEN> >(digraph, length);
  3.1098 +  }
  3.1099 +
  3.1100 +} //END OF NAMESPACE LEMON
  3.1101 +
  3.1102 +#endif
  3.1103 +
     4.1 --- a/lemon/bfs.h	Fri Sep 25 12:24:16 2009 +0200
     4.2 +++ b/lemon/bfs.h	Sat Sep 26 07:08:10 2009 +0200
     4.3 @@ -47,7 +47,7 @@
     4.4      ///
     4.5      ///The type of the map that stores the predecessor
     4.6      ///arcs of the shortest paths.
     4.7 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     4.8 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
     4.9      typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
    4.10      ///Instantiates a \c PredMap.
    4.11  
    4.12 @@ -62,7 +62,8 @@
    4.13      ///The type of the map that indicates which nodes are processed.
    4.14  
    4.15      ///The type of the map that indicates which nodes are processed.
    4.16 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    4.17 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    4.18 +    ///By default it is a NullMap.
    4.19      typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    4.20      ///Instantiates a \c ProcessedMap.
    4.21  
    4.22 @@ -81,7 +82,7 @@
    4.23      ///The type of the map that indicates which nodes are reached.
    4.24  
    4.25      ///The type of the map that indicates which nodes are reached.
    4.26 -    ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    4.27 +    ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    4.28      typedef typename Digraph::template NodeMap<bool> ReachedMap;
    4.29      ///Instantiates a \c ReachedMap.
    4.30  
    4.31 @@ -96,7 +97,7 @@
    4.32      ///The type of the map that stores the distances of the nodes.
    4.33  
    4.34      ///The type of the map that stores the distances of the nodes.
    4.35 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    4.36 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    4.37      typedef typename Digraph::template NodeMap<int> DistMap;
    4.38      ///Instantiates a \c DistMap.
    4.39  
    4.40 @@ -225,7 +226,7 @@
    4.41      ///
    4.42      ///\ref named-templ-param "Named parameter" for setting
    4.43      ///\c PredMap type.
    4.44 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    4.45 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    4.46      template <class T>
    4.47      struct SetPredMap : public Bfs< Digraph, SetPredMapTraits<T> > {
    4.48        typedef Bfs< Digraph, SetPredMapTraits<T> > Create;
    4.49 @@ -245,7 +246,7 @@
    4.50      ///
    4.51      ///\ref named-templ-param "Named parameter" for setting
    4.52      ///\c DistMap type.
    4.53 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    4.54 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    4.55      template <class T>
    4.56      struct SetDistMap : public Bfs< Digraph, SetDistMapTraits<T> > {
    4.57        typedef Bfs< Digraph, SetDistMapTraits<T> > Create;
    4.58 @@ -265,7 +266,7 @@
    4.59      ///
    4.60      ///\ref named-templ-param "Named parameter" for setting
    4.61      ///\c ReachedMap type.
    4.62 -    ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    4.63 +    ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    4.64      template <class T>
    4.65      struct SetReachedMap : public Bfs< Digraph, SetReachedMapTraits<T> > {
    4.66        typedef Bfs< Digraph, SetReachedMapTraits<T> > Create;
    4.67 @@ -285,7 +286,7 @@
    4.68      ///
    4.69      ///\ref named-templ-param "Named parameter" for setting
    4.70      ///\c ProcessedMap type.
    4.71 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    4.72 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    4.73      template <class T>
    4.74      struct SetProcessedMap : public Bfs< Digraph, SetProcessedMapTraits<T> > {
    4.75        typedef Bfs< Digraph, SetProcessedMapTraits<T> > Create;
    4.76 @@ -413,8 +414,8 @@
    4.77      ///\name Execution Control
    4.78      ///The simplest way to execute the BFS algorithm is to use one of the
    4.79      ///member functions called \ref run(Node) "run()".\n
    4.80 -    ///If you need more control on the execution, first you have to call
    4.81 -    ///\ref init(), then you can add several source nodes with
    4.82 +    ///If you need better control on the execution, you have to call
    4.83 +    ///\ref init() first, then you can add several source nodes with
    4.84      ///\ref addSource(). Finally the actual path computation can be
    4.85      ///performed with one of the \ref start() functions.
    4.86  
    4.87 @@ -737,9 +738,9 @@
    4.88  
    4.89      ///@{
    4.90  
    4.91 -    ///The shortest path to a node.
    4.92 +    ///The shortest path to the given node.
    4.93  
    4.94 -    ///Returns the shortest path to a node.
    4.95 +    ///Returns the shortest path to the given node from the root(s).
    4.96      ///
    4.97      ///\warning \c t should be reached from the root(s).
    4.98      ///
    4.99 @@ -747,9 +748,9 @@
   4.100      ///must be called before using this function.
   4.101      Path path(Node t) const { return Path(*G, *_pred, t); }
   4.102  
   4.103 -    ///The distance of a node from the root(s).
   4.104 +    ///The distance of the given node from the root(s).
   4.105  
   4.106 -    ///Returns the distance of a node from the root(s).
   4.107 +    ///Returns the distance of the given node from the root(s).
   4.108      ///
   4.109      ///\warning If node \c v is not reached from the root(s), then
   4.110      ///the return value of this function is undefined.
   4.111 @@ -758,29 +759,31 @@
   4.112      ///must be called before using this function.
   4.113      int dist(Node v) const { return (*_dist)[v]; }
   4.114  
   4.115 -    ///Returns the 'previous arc' of the shortest path tree for a node.
   4.116 -
   4.117 +    ///\brief Returns the 'previous arc' of the shortest path tree for
   4.118 +    ///the given node.
   4.119 +    ///
   4.120      ///This function returns the 'previous arc' of the shortest path
   4.121      ///tree for the node \c v, i.e. it returns the last arc of a
   4.122      ///shortest path from a root to \c v. It is \c INVALID if \c v
   4.123      ///is not reached from the root(s) or if \c v is a root.
   4.124      ///
   4.125      ///The shortest path tree used here is equal to the shortest path
   4.126 -    ///tree used in \ref predNode().
   4.127 +    ///tree used in \ref predNode() and \ref predMap().
   4.128      ///
   4.129      ///\pre Either \ref run(Node) "run()" or \ref init()
   4.130      ///must be called before using this function.
   4.131      Arc predArc(Node v) const { return (*_pred)[v];}
   4.132  
   4.133 -    ///Returns the 'previous node' of the shortest path tree for a node.
   4.134 -
   4.135 +    ///\brief Returns the 'previous node' of the shortest path tree for
   4.136 +    ///the given node.
   4.137 +    ///
   4.138      ///This function returns the 'previous node' of the shortest path
   4.139      ///tree for the node \c v, i.e. it returns the last but one node
   4.140 -    ///from a shortest path from a root to \c v. It is \c INVALID
   4.141 +    ///of a shortest path from a root to \c v. It is \c INVALID
   4.142      ///if \c v is not reached from the root(s) or if \c v is a root.
   4.143      ///
   4.144      ///The shortest path tree used here is equal to the shortest path
   4.145 -    ///tree used in \ref predArc().
   4.146 +    ///tree used in \ref predArc() and \ref predMap().
   4.147      ///
   4.148      ///\pre Either \ref run(Node) "run()" or \ref init()
   4.149      ///must be called before using this function.
   4.150 @@ -801,13 +804,13 @@
   4.151      ///predecessor arcs.
   4.152      ///
   4.153      ///Returns a const reference to the node map that stores the predecessor
   4.154 -    ///arcs, which form the shortest path tree.
   4.155 +    ///arcs, which form the shortest path tree (forest).
   4.156      ///
   4.157      ///\pre Either \ref run(Node) "run()" or \ref init()
   4.158      ///must be called before using this function.
   4.159      const PredMap &predMap() const { return *_pred;}
   4.160  
   4.161 -    ///Checks if a node is reached from the root(s).
   4.162 +    ///Checks if the given node is reached from the root(s).
   4.163  
   4.164      ///Returns \c true if \c v is reached from the root(s).
   4.165      ///
   4.166 @@ -833,7 +836,7 @@
   4.167      ///
   4.168      ///The type of the map that stores the predecessor
   4.169      ///arcs of the shortest paths.
   4.170 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   4.171 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   4.172      typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
   4.173      ///Instantiates a PredMap.
   4.174  
   4.175 @@ -848,7 +851,7 @@
   4.176      ///The type of the map that indicates which nodes are processed.
   4.177  
   4.178      ///The type of the map that indicates which nodes are processed.
   4.179 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   4.180 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   4.181      ///By default it is a NullMap.
   4.182      typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
   4.183      ///Instantiates a ProcessedMap.
   4.184 @@ -868,7 +871,7 @@
   4.185      ///The type of the map that indicates which nodes are reached.
   4.186  
   4.187      ///The type of the map that indicates which nodes are reached.
   4.188 -    ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   4.189 +    ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   4.190      typedef typename Digraph::template NodeMap<bool> ReachedMap;
   4.191      ///Instantiates a ReachedMap.
   4.192  
   4.193 @@ -883,7 +886,7 @@
   4.194      ///The type of the map that stores the distances of the nodes.
   4.195  
   4.196      ///The type of the map that stores the distances of the nodes.
   4.197 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   4.198 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   4.199      typedef typename Digraph::template NodeMap<int> DistMap;
   4.200      ///Instantiates a DistMap.
   4.201  
   4.202 @@ -898,18 +901,14 @@
   4.203      ///The type of the shortest paths.
   4.204  
   4.205      ///The type of the shortest paths.
   4.206 -    ///It must meet the \ref concepts::Path "Path" concept.
   4.207 +    ///It must conform to the \ref concepts::Path "Path" concept.
   4.208      typedef lemon::Path<Digraph> Path;
   4.209    };
   4.210  
   4.211    /// Default traits class used by BfsWizard
   4.212  
   4.213 -  /// To make it easier to use Bfs algorithm
   4.214 -  /// we have created a wizard class.
   4.215 -  /// This \ref BfsWizard class needs default traits,
   4.216 -  /// as well as the \ref Bfs class.
   4.217 -  /// The \ref BfsWizardBase is a class to be the default traits of the
   4.218 -  /// \ref BfsWizard class.
   4.219 +  /// Default traits class used by BfsWizard.
   4.220 +  /// \tparam GR The type of the digraph.
   4.221    template<class GR>
   4.222    class BfsWizardBase : public BfsWizardDefaultTraits<GR>
   4.223    {
   4.224 @@ -937,7 +936,7 @@
   4.225      public:
   4.226      /// Constructor.
   4.227  
   4.228 -    /// This constructor does not require parameters, therefore it initiates
   4.229 +    /// This constructor does not require parameters, it initiates
   4.230      /// all of the attributes to \c 0.
   4.231      BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
   4.232                        _dist(0), _path(0), _di(0) {}
   4.233 @@ -967,7 +966,6 @@
   4.234    {
   4.235      typedef TR Base;
   4.236  
   4.237 -    ///The type of the digraph the algorithm runs on.
   4.238      typedef typename TR::Digraph Digraph;
   4.239  
   4.240      typedef typename Digraph::Node Node;
   4.241 @@ -975,16 +973,10 @@
   4.242      typedef typename Digraph::Arc Arc;
   4.243      typedef typename Digraph::OutArcIt OutArcIt;
   4.244  
   4.245 -    ///\brief The type of the map that stores the predecessor
   4.246 -    ///arcs of the shortest paths.
   4.247      typedef typename TR::PredMap PredMap;
   4.248 -    ///\brief The type of the map that stores the distances of the nodes.
   4.249      typedef typename TR::DistMap DistMap;
   4.250 -    ///\brief The type of the map that indicates which nodes are reached.
   4.251      typedef typename TR::ReachedMap ReachedMap;
   4.252 -    ///\brief The type of the map that indicates which nodes are processed.
   4.253      typedef typename TR::ProcessedMap ProcessedMap;
   4.254 -    ///The type of the shortest paths
   4.255      typedef typename TR::Path Path;
   4.256  
   4.257    public:
   4.258 @@ -1067,11 +1059,12 @@
   4.259        static PredMap *createPredMap(const Digraph &) { return 0; };
   4.260        SetPredMapBase(const TR &b) : TR(b) {}
   4.261      };
   4.262 -    ///\brief \ref named-func-param "Named parameter"
   4.263 -    ///for setting PredMap object.
   4.264 +
   4.265 +    ///\brief \ref named-templ-param "Named parameter" for setting
   4.266 +    ///the predecessor map.
   4.267      ///
   4.268 -    ///\ref named-func-param "Named parameter"
   4.269 -    ///for setting PredMap object.
   4.270 +    ///\ref named-templ-param "Named parameter" function for setting
   4.271 +    ///the map that stores the predecessor arcs of the nodes.
   4.272      template<class T>
   4.273      BfsWizard<SetPredMapBase<T> > predMap(const T &t)
   4.274      {
   4.275 @@ -1085,11 +1078,12 @@
   4.276        static ReachedMap *createReachedMap(const Digraph &) { return 0; };
   4.277        SetReachedMapBase(const TR &b) : TR(b) {}
   4.278      };
   4.279 -    ///\brief \ref named-func-param "Named parameter"
   4.280 -    ///for setting ReachedMap object.
   4.281 +
   4.282 +    ///\brief \ref named-templ-param "Named parameter" for setting
   4.283 +    ///the reached map.
   4.284      ///
   4.285 -    /// \ref named-func-param "Named parameter"
   4.286 -    ///for setting ReachedMap object.
   4.287 +    ///\ref named-templ-param "Named parameter" function for setting
   4.288 +    ///the map that indicates which nodes are reached.
   4.289      template<class T>
   4.290      BfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
   4.291      {
   4.292 @@ -1103,11 +1097,13 @@
   4.293        static DistMap *createDistMap(const Digraph &) { return 0; };
   4.294        SetDistMapBase(const TR &b) : TR(b) {}
   4.295      };
   4.296 -    ///\brief \ref named-func-param "Named parameter"
   4.297 -    ///for setting DistMap object.
   4.298 +
   4.299 +    ///\brief \ref named-templ-param "Named parameter" for setting
   4.300 +    ///the distance map.
   4.301      ///
   4.302 -    /// \ref named-func-param "Named parameter"
   4.303 -    ///for setting DistMap object.
   4.304 +    ///\ref named-templ-param "Named parameter" function for setting
   4.305 +    ///the map that stores the distances of the nodes calculated
   4.306 +    ///by the algorithm.
   4.307      template<class T>
   4.308      BfsWizard<SetDistMapBase<T> > distMap(const T &t)
   4.309      {
   4.310 @@ -1121,11 +1117,12 @@
   4.311        static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
   4.312        SetProcessedMapBase(const TR &b) : TR(b) {}
   4.313      };
   4.314 -    ///\brief \ref named-func-param "Named parameter"
   4.315 -    ///for setting ProcessedMap object.
   4.316 +
   4.317 +    ///\brief \ref named-func-param "Named parameter" for setting
   4.318 +    ///the processed map.
   4.319      ///
   4.320 -    /// \ref named-func-param "Named parameter"
   4.321 -    ///for setting ProcessedMap object.
   4.322 +    ///\ref named-templ-param "Named parameter" function for setting
   4.323 +    ///the map that indicates which nodes are processed.
   4.324      template<class T>
   4.325      BfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
   4.326      {
   4.327 @@ -1264,7 +1261,7 @@
   4.328      /// \brief The type of the map that indicates which nodes are reached.
   4.329      ///
   4.330      /// The type of the map that indicates which nodes are reached.
   4.331 -    /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   4.332 +    /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   4.333      typedef typename Digraph::template NodeMap<bool> ReachedMap;
   4.334  
   4.335      /// \brief Instantiates a ReachedMap.
   4.336 @@ -1425,8 +1422,8 @@
   4.337      /// \name Execution Control
   4.338      /// The simplest way to execute the BFS algorithm is to use one of the
   4.339      /// member functions called \ref run(Node) "run()".\n
   4.340 -    /// If you need more control on the execution, first you have to call
   4.341 -    /// \ref init(), then you can add several source nodes with
   4.342 +    /// If you need better control on the execution, you have to call
   4.343 +    /// \ref init() first, then you can add several source nodes with
   4.344      /// \ref addSource(). Finally the actual path computation can be
   4.345      /// performed with one of the \ref start() functions.
   4.346  
   4.347 @@ -1735,7 +1732,7 @@
   4.348  
   4.349      ///@{
   4.350  
   4.351 -    /// \brief Checks if a node is reached from the root(s).
   4.352 +    /// \brief Checks if the given node is reached from the root(s).
   4.353      ///
   4.354      /// Returns \c true if \c v is reached from the root(s).
   4.355      ///
     5.1 --- a/lemon/bin_heap.h	Fri Sep 25 12:24:16 2009 +0200
     5.2 +++ b/lemon/bin_heap.h	Sat Sep 26 07:08:10 2009 +0200
     5.3 @@ -19,9 +19,9 @@
     5.4  #ifndef LEMON_BIN_HEAP_H
     5.5  #define LEMON_BIN_HEAP_H
     5.6  
     5.7 -///\ingroup auxdat
     5.8 +///\ingroup heaps
     5.9  ///\file
    5.10 -///\brief Binary Heap implementation.
    5.11 +///\brief Binary heap implementation.
    5.12  
    5.13  #include <vector>
    5.14  #include <utility>
    5.15 @@ -29,45 +29,41 @@
    5.16  
    5.17  namespace lemon {
    5.18  
    5.19 -  ///\ingroup auxdat
    5.20 +  /// \ingroup heaps
    5.21    ///
    5.22 -  ///\brief A Binary Heap implementation.
    5.23 +  /// \brief Binary heap data structure.
    5.24    ///
    5.25 -  ///This class implements the \e binary \e heap data structure.
    5.26 +  /// This class implements the \e binary \e heap data structure.
    5.27 +  /// It fully conforms to the \ref concepts::Heap "heap concept".
    5.28    ///
    5.29 -  ///A \e heap is a data structure for storing items with specified values
    5.30 -  ///called \e priorities in such a way that finding the item with minimum
    5.31 -  ///priority is efficient. \c CMP specifies the ordering of the priorities.
    5.32 -  ///In a heap one can change the priority of an item, add or erase an
    5.33 -  ///item, etc.
    5.34 -  ///
    5.35 -  ///\tparam PR Type of the priority of the items.
    5.36 -  ///\tparam IM A read and writable item map with int values, used internally
    5.37 -  ///to handle the cross references.
    5.38 -  ///\tparam CMP A functor class for the ordering of the priorities.
    5.39 -  ///The default is \c std::less<PR>.
    5.40 -  ///
    5.41 -  ///\sa FibHeap
    5.42 -  ///\sa Dijkstra
    5.43 +  /// \tparam PR Type of the priorities of the items.
    5.44 +  /// \tparam IM A read-writable item map with \c int values, used
    5.45 +  /// internally to handle the cross references.
    5.46 +  /// \tparam CMP A functor class for comparing the priorities.
    5.47 +  /// The default is \c std::less<PR>.
    5.48 +#ifdef DOXYGEN
    5.49 +  template <typename PR, typename IM, typename CMP>
    5.50 +#else
    5.51    template <typename PR, typename IM, typename CMP = std::less<PR> >
    5.52 +#endif
    5.53    class BinHeap {
    5.54 +  public:
    5.55  
    5.56 -  public:
    5.57 -    ///\e
    5.58 +    /// Type of the item-int map.
    5.59      typedef IM ItemIntMap;
    5.60 -    ///\e
    5.61 +    /// Type of the priorities.
    5.62      typedef PR Prio;
    5.63 -    ///\e
    5.64 +    /// Type of the items stored in the heap.
    5.65      typedef typename ItemIntMap::Key Item;
    5.66 -    ///\e
    5.67 +    /// Type of the item-priority pairs.
    5.68      typedef std::pair<Item,Prio> Pair;
    5.69 -    ///\e
    5.70 +    /// Functor type for comparing the priorities.
    5.71      typedef CMP Compare;
    5.72  
    5.73 -    /// \brief Type to represent the items states.
    5.74 +    /// \brief Type to represent the states of the items.
    5.75      ///
    5.76 -    /// Each Item element have a state associated to it. It may be "in heap",
    5.77 -    /// "pre heap" or "post heap". The latter two are indifferent from the
    5.78 +    /// Each item has a state associated to it. It can be "in heap",
    5.79 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
    5.80      /// heap's point of view, but may be useful to the user.
    5.81      ///
    5.82      /// The item-int map must be initialized in such way that it assigns
    5.83 @@ -84,42 +80,43 @@
    5.84      ItemIntMap &_iim;
    5.85  
    5.86    public:
    5.87 -    /// \brief The constructor.
    5.88 +
    5.89 +    /// \brief Constructor.
    5.90      ///
    5.91 -    /// The constructor.
    5.92 -    /// \param map should be given to the constructor, since it is used
    5.93 -    /// internally to handle the cross references. The value of the map
    5.94 -    /// must be \c PRE_HEAP (<tt>-1</tt>) for every item.
    5.95 +    /// Constructor.
    5.96 +    /// \param map A map that assigns \c int values to the items.
    5.97 +    /// It is used internally to handle the cross references.
    5.98 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
    5.99      explicit BinHeap(ItemIntMap &map) : _iim(map) {}
   5.100  
   5.101 -    /// \brief The constructor.
   5.102 +    /// \brief Constructor.
   5.103      ///
   5.104 -    /// The constructor.
   5.105 -    /// \param map should be given to the constructor, since it is used
   5.106 -    /// internally to handle the cross references. The value of the map
   5.107 -    /// should be PRE_HEAP (-1) for each element.
   5.108 -    ///
   5.109 -    /// \param comp The comparator function object.
   5.110 +    /// Constructor.
   5.111 +    /// \param map A map that assigns \c int values to the items.
   5.112 +    /// It is used internally to handle the cross references.
   5.113 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
   5.114 +    /// \param comp The function object used for comparing the priorities.
   5.115      BinHeap(ItemIntMap &map, const Compare &comp)
   5.116        : _iim(map), _comp(comp) {}
   5.117  
   5.118  
   5.119 -    /// The number of items stored in the heap.
   5.120 +    /// \brief The number of items stored in the heap.
   5.121      ///
   5.122 -    /// \brief Returns the number of items stored in the heap.
   5.123 +    /// This function returns the number of items stored in the heap.
   5.124      int size() const { return _data.size(); }
   5.125  
   5.126 -    /// \brief Checks if the heap stores no items.
   5.127 +    /// \brief Check if the heap is empty.
   5.128      ///
   5.129 -    /// Returns \c true if and only if the heap stores no items.
   5.130 +    /// This function returns \c true if the heap is empty.
   5.131      bool empty() const { return _data.empty(); }
   5.132  
   5.133 -    /// \brief Make empty this heap.
   5.134 +    /// \brief Make the heap empty.
   5.135      ///
   5.136 -    /// Make empty this heap. It does not change the cross reference map.
   5.137 -    /// If you want to reuse what is not surely empty you should first clear
   5.138 -    /// the heap and after that you should set the cross reference map for
   5.139 -    /// each item to \c PRE_HEAP.
   5.140 +    /// This functon makes the heap empty.
   5.141 +    /// It does not change the cross reference map. If you want to reuse
   5.142 +    /// a heap that is not surely empty, you should first clear it and
   5.143 +    /// then you should set the cross reference map to \c PRE_HEAP
   5.144 +    /// for each item.
   5.145      void clear() {
   5.146        _data.clear();
   5.147      }
   5.148 @@ -127,12 +124,12 @@
   5.149    private:
   5.150      static int parent(int i) { return (i-1)/2; }
   5.151  
   5.152 -    static int second_child(int i) { return 2*i+2; }
   5.153 +    static int secondChild(int i) { return 2*i+2; }
   5.154      bool less(const Pair &p1, const Pair &p2) const {
   5.155        return _comp(p1.second, p2.second);
   5.156      }
   5.157  
   5.158 -    int bubble_up(int hole, Pair p) {
   5.159 +    int bubbleUp(int hole, Pair p) {
   5.160        int par = parent(hole);
   5.161        while( hole>0 && less(p,_data[par]) ) {
   5.162          move(_data[par],hole);
   5.163 @@ -143,8 +140,8 @@
   5.164        return hole;
   5.165      }
   5.166  
   5.167 -    int bubble_down(int hole, Pair p, int length) {
   5.168 -      int child = second_child(hole);
   5.169 +    int bubbleDown(int hole, Pair p, int length) {
   5.170 +      int child = secondChild(hole);
   5.171        while(child < length) {
   5.172          if( less(_data[child-1], _data[child]) ) {
   5.173            --child;
   5.174 @@ -153,7 +150,7 @@
   5.175            goto ok;
   5.176          move(_data[child], hole);
   5.177          hole = child;
   5.178 -        child = second_child(hole);
   5.179 +        child = secondChild(hole);
   5.180        }
   5.181        child--;
   5.182        if( child<length && less(_data[child], p) ) {
   5.183 @@ -171,87 +168,91 @@
   5.184      }
   5.185  
   5.186    public:
   5.187 +
   5.188      /// \brief Insert a pair of item and priority into the heap.
   5.189      ///
   5.190 -    /// Adds \c p.first to the heap with priority \c p.second.
   5.191 +    /// This function inserts \c p.first to the heap with priority
   5.192 +    /// \c p.second.
   5.193      /// \param p The pair to insert.
   5.194 +    /// \pre \c p.first must not be stored in the heap.
   5.195      void push(const Pair &p) {
   5.196        int n = _data.size();
   5.197        _data.resize(n+1);
   5.198 -      bubble_up(n, p);
   5.199 +      bubbleUp(n, p);
   5.200      }
   5.201  
   5.202 -    /// \brief Insert an item into the heap with the given heap.
   5.203 +    /// \brief Insert an item into the heap with the given priority.
   5.204      ///
   5.205 -    /// Adds \c i to the heap with priority \c p.
   5.206 +    /// This function inserts the given item into the heap with the
   5.207 +    /// given priority.
   5.208      /// \param i The item to insert.
   5.209      /// \param p The priority of the item.
   5.210 +    /// \pre \e i must not be stored in the heap.
   5.211      void push(const Item &i, const Prio &p) { push(Pair(i,p)); }
   5.212  
   5.213 -    /// \brief Returns the item with minimum priority relative to \c Compare.
   5.214 +    /// \brief Return the item having minimum priority.
   5.215      ///
   5.216 -    /// This method returns the item with minimum priority relative to \c
   5.217 -    /// Compare.
   5.218 -    /// \pre The heap must be nonempty.
   5.219 +    /// This function returns the item having minimum priority.
   5.220 +    /// \pre The heap must be non-empty.
   5.221      Item top() const {
   5.222        return _data[0].first;
   5.223      }
   5.224  
   5.225 -    /// \brief Returns the minimum priority relative to \c Compare.
   5.226 +    /// \brief The minimum priority.
   5.227      ///
   5.228 -    /// It returns the minimum priority relative to \c Compare.
   5.229 -    /// \pre The heap must be nonempty.
   5.230 +    /// This function returns the minimum priority.
   5.231 +    /// \pre The heap must be non-empty.
   5.232      Prio prio() const {
   5.233        return _data[0].second;
   5.234      }
   5.235  
   5.236 -    /// \brief Deletes the item with minimum priority relative to \c Compare.
   5.237 +    /// \brief Remove the item having minimum priority.
   5.238      ///
   5.239 -    /// This method deletes the item with minimum priority relative to \c
   5.240 -    /// Compare from the heap.
   5.241 +    /// This function removes the item having minimum priority.
   5.242      /// \pre The heap must be non-empty.
   5.243      void pop() {
   5.244        int n = _data.size()-1;
   5.245        _iim.set(_data[0].first, POST_HEAP);
   5.246        if (n > 0) {
   5.247 -        bubble_down(0, _data[n], n);
   5.248 +        bubbleDown(0, _data[n], n);
   5.249        }
   5.250        _data.pop_back();
   5.251      }
   5.252  
   5.253 -    /// \brief Deletes \c i from the heap.
   5.254 +    /// \brief Remove the given item from the heap.
   5.255      ///
   5.256 -    /// This method deletes item \c i from the heap.
   5.257 -    /// \param i The item to erase.
   5.258 -    /// \pre The item should be in the heap.
   5.259 +    /// This function removes the given item from the heap if it is
   5.260 +    /// already stored.
   5.261 +    /// \param i The item to delete.
   5.262 +    /// \pre \e i must be in the heap.
   5.263      void erase(const Item &i) {
   5.264        int h = _iim[i];
   5.265        int n = _data.size()-1;
   5.266        _iim.set(_data[h].first, POST_HEAP);
   5.267        if( h < n ) {
   5.268 -        if ( bubble_up(h, _data[n]) == h) {
   5.269 -          bubble_down(h, _data[n], n);
   5.270 +        if ( bubbleUp(h, _data[n]) == h) {
   5.271 +          bubbleDown(h, _data[n], n);
   5.272          }
   5.273        }
   5.274        _data.pop_back();
   5.275      }
   5.276  
   5.277 -
   5.278 -    /// \brief Returns the priority of \c i.
   5.279 +    /// \brief The priority of the given item.
   5.280      ///
   5.281 -    /// This function returns the priority of item \c i.
   5.282 +    /// This function returns the priority of the given item.
   5.283      /// \param i The item.
   5.284 -    /// \pre \c i must be in the heap.
   5.285 +    /// \pre \e i must be in the heap.
   5.286      Prio operator[](const Item &i) const {
   5.287        int idx = _iim[i];
   5.288        return _data[idx].second;
   5.289      }
   5.290  
   5.291 -    /// \brief \c i gets to the heap with priority \c p independently
   5.292 -    /// if \c i was already there.
   5.293 +    /// \brief Set the priority of an item or insert it, if it is
   5.294 +    /// not stored in the heap.
   5.295      ///
   5.296 -    /// This method calls \ref push(\c i, \c p) if \c i is not stored
   5.297 -    /// in the heap and sets the priority of \c i to \c p otherwise.
   5.298 +    /// This method sets the priority of the given item if it is
   5.299 +    /// already stored in the heap. Otherwise it inserts the given
   5.300 +    /// item into the heap with the given priority.
   5.301      /// \param i The item.
   5.302      /// \param p The priority.
   5.303      void set(const Item &i, const Prio &p) {
   5.304 @@ -260,44 +261,42 @@
   5.305          push(i,p);
   5.306        }
   5.307        else if( _comp(p, _data[idx].second) ) {
   5.308 -        bubble_up(idx, Pair(i,p));
   5.309 +        bubbleUp(idx, Pair(i,p));
   5.310        }
   5.311        else {
   5.312 -        bubble_down(idx, Pair(i,p), _data.size());
   5.313 +        bubbleDown(idx, Pair(i,p), _data.size());
   5.314        }
   5.315      }
   5.316  
   5.317 -    /// \brief Decreases the priority of \c i to \c p.
   5.318 +    /// \brief Decrease the priority of an item to the given value.
   5.319      ///
   5.320 -    /// This method decreases the priority of item \c i to \c p.
   5.321 +    /// This function decreases the priority of an item to the given value.
   5.322      /// \param i The item.
   5.323      /// \param p The priority.
   5.324 -    /// \pre \c i must be stored in the heap with priority at least \c
   5.325 -    /// p relative to \c Compare.
   5.326 +    /// \pre \e i must be stored in the heap with priority at least \e p.
   5.327      void decrease(const Item &i, const Prio &p) {
   5.328        int idx = _iim[i];
   5.329 -      bubble_up(idx, Pair(i,p));
   5.330 +      bubbleUp(idx, Pair(i,p));
   5.331      }
   5.332  
   5.333 -    /// \brief Increases the priority of \c i to \c p.
   5.334 +    /// \brief Increase the priority of an item to the given value.
   5.335      ///
   5.336 -    /// This method sets the priority of item \c i to \c p.
   5.337 +    /// This function increases the priority of an item to the given value.
   5.338      /// \param i The item.
   5.339      /// \param p The priority.
   5.340 -    /// \pre \c i must be stored in the heap with priority at most \c
   5.341 -    /// p relative to \c Compare.
   5.342 +    /// \pre \e i must be stored in the heap with priority at most \e p.
   5.343      void increase(const Item &i, const Prio &p) {
   5.344        int idx = _iim[i];
   5.345 -      bubble_down(idx, Pair(i,p), _data.size());
   5.346 +      bubbleDown(idx, Pair(i,p), _data.size());
   5.347      }
   5.348  
   5.349 -    /// \brief Returns if \c item is in, has already been in, or has
   5.350 -    /// never been in the heap.
   5.351 +    /// \brief Return the state of an item.
   5.352      ///
   5.353 -    /// This method returns PRE_HEAP if \c item has never been in the
   5.354 -    /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
   5.355 -    /// otherwise. In the latter case it is possible that \c item will
   5.356 -    /// get back to the heap again.
   5.357 +    /// This method returns \c PRE_HEAP if the given item has never
   5.358 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
   5.359 +    /// and \c POST_HEAP otherwise.
   5.360 +    /// In the latter case it is possible that the item will get back
   5.361 +    /// to the heap again.
   5.362      /// \param i The item.
   5.363      State state(const Item &i) const {
   5.364        int s = _iim[i];
   5.365 @@ -306,11 +305,11 @@
   5.366        return State(s);
   5.367      }
   5.368  
   5.369 -    /// \brief Sets the state of the \c item in the heap.
   5.370 +    /// \brief Set the state of an item in the heap.
   5.371      ///
   5.372 -    /// Sets the state of the \c item in the heap. It can be used to
   5.373 -    /// manually clear the heap when it is important to achive the
   5.374 -    /// better time complexity.
   5.375 +    /// This function sets the state of the given item in the heap.
   5.376 +    /// It can be used to manually clear the heap when it is important
   5.377 +    /// to achive better time complexity.
   5.378      /// \param i The item.
   5.379      /// \param st The state. It should not be \c IN_HEAP.
   5.380      void state(const Item& i, State st) {
   5.381 @@ -327,12 +326,13 @@
   5.382        }
   5.383      }
   5.384  
   5.385 -    /// \brief Replaces an item in the heap.
   5.386 +    /// \brief Replace an item in the heap.
   5.387      ///
   5.388 -    /// The \c i item is replaced with \c j item. The \c i item should
   5.389 -    /// be in the heap, while the \c j should be out of the heap. The
   5.390 -    /// \c i item will out of the heap and \c j will be in the heap
   5.391 -    /// with the same prioriority as prevoiusly the \c i item.
   5.392 +    /// This function replaces item \c i with item \c j.
   5.393 +    /// Item \c i must be in the heap, while \c j must be out of the heap.
   5.394 +    /// After calling this method, item \c i will be out of the
   5.395 +    /// heap and \c j will be in the heap with the same prioriority
   5.396 +    /// as item \c i had before.
   5.397      void replace(const Item& i, const Item& j) {
   5.398        int idx = _iim[i];
   5.399        _iim.set(i, _iim[j]);
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/lemon/binom_heap.h	Sat Sep 26 07:08:10 2009 +0200
     6.3 @@ -0,0 +1,445 @@
     6.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
     6.5 + *
     6.6 + * This file is a part of LEMON, a generic C++ optimization library.
     6.7 + *
     6.8 + * Copyright (C) 2003-2009
     6.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    6.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    6.11 + *
    6.12 + * Permission to use, modify and distribute this software is granted
    6.13 + * provided that this copyright notice appears in all copies. For
    6.14 + * precise terms see the accompanying LICENSE file.
    6.15 + *
    6.16 + * This software is provided "AS IS" with no warranty of any kind,
    6.17 + * express or implied, and with no claim as to its suitability for any
    6.18 + * purpose.
    6.19 + *
    6.20 + */
    6.21 +
    6.22 +#ifndef LEMON_BINOM_HEAP_H
    6.23 +#define LEMON_BINOM_HEAP_H
    6.24 +
    6.25 +///\file
    6.26 +///\ingroup heaps
    6.27 +///\brief Binomial Heap implementation.
    6.28 +
    6.29 +#include <vector>
    6.30 +#include <utility>
    6.31 +#include <functional>
    6.32 +#include <lemon/math.h>
    6.33 +#include <lemon/counter.h>
    6.34 +
    6.35 +namespace lemon {
    6.36 +
    6.37 +  /// \ingroup heaps
    6.38 +  ///
    6.39 +  ///\brief Binomial heap data structure.
    6.40 +  ///
    6.41 +  /// This class implements the \e binomial \e heap data structure.
    6.42 +  /// It fully conforms to the \ref concepts::Heap "heap concept".
    6.43 +  ///
    6.44 +  /// The methods \ref increase() and \ref erase() are not efficient
    6.45 +  /// in a binomial heap. In case of many calls of these operations,
    6.46 +  /// it is better to use other heap structure, e.g. \ref BinHeap
    6.47 +  /// "binary heap".
    6.48 +  ///
    6.49 +  /// \tparam PR Type of the priorities of the items.
    6.50 +  /// \tparam IM A read-writable item map with \c int values, used
    6.51 +  /// internally to handle the cross references.
    6.52 +  /// \tparam CMP A functor class for comparing the priorities.
    6.53 +  /// The default is \c std::less<PR>.
    6.54 +#ifdef DOXYGEN
    6.55 +  template <typename PR, typename IM, typename CMP>
    6.56 +#else
    6.57 +  template <typename PR, typename IM, typename CMP = std::less<PR> >
    6.58 +#endif
    6.59 +  class BinomHeap {
    6.60 +  public:
    6.61 +    /// Type of the item-int map.
    6.62 +    typedef IM ItemIntMap;
    6.63 +    /// Type of the priorities.
    6.64 +    typedef PR Prio;
    6.65 +    /// Type of the items stored in the heap.
    6.66 +    typedef typename ItemIntMap::Key Item;
    6.67 +    /// Functor type for comparing the priorities.
    6.68 +    typedef CMP Compare;
    6.69 +
    6.70 +    /// \brief Type to represent the states of the items.
    6.71 +    ///
    6.72 +    /// Each item has a state associated to it. It can be "in heap",
    6.73 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
    6.74 +    /// heap's point of view, but may be useful to the user.
    6.75 +    ///
    6.76 +    /// The item-int map must be initialized in such way that it assigns
    6.77 +    /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
    6.78 +    enum State {
    6.79 +      IN_HEAP = 0,    ///< = 0.
    6.80 +      PRE_HEAP = -1,  ///< = -1.
    6.81 +      POST_HEAP = -2  ///< = -2.
    6.82 +    };
    6.83 +
    6.84 +  private:
    6.85 +    class Store;
    6.86 +
    6.87 +    std::vector<Store> _data;
    6.88 +    int _min, _head;
    6.89 +    ItemIntMap &_iim;
    6.90 +    Compare _comp;
    6.91 +    int _num_items;
    6.92 +
    6.93 +  public:
    6.94 +    /// \brief Constructor.
    6.95 +    ///
    6.96 +    /// Constructor.
    6.97 +    /// \param map A map that assigns \c int values to the items.
    6.98 +    /// It is used internally to handle the cross references.
    6.99 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
   6.100 +    explicit BinomHeap(ItemIntMap &map)
   6.101 +      : _min(0), _head(-1), _iim(map), _num_items(0) {}
   6.102 +
   6.103 +    /// \brief Constructor.
   6.104 +    ///
   6.105 +    /// Constructor.
   6.106 +    /// \param map A map that assigns \c int values to the items.
   6.107 +    /// It is used internally to handle the cross references.
   6.108 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
   6.109 +    /// \param comp The function object used for comparing the priorities.
   6.110 +    BinomHeap(ItemIntMap &map, const Compare &comp)
   6.111 +      : _min(0), _head(-1), _iim(map), _comp(comp), _num_items(0) {}
   6.112 +
   6.113 +    /// \brief The number of items stored in the heap.
   6.114 +    ///
   6.115 +    /// This function returns the number of items stored in the heap.
   6.116 +    int size() const { return _num_items; }
   6.117 +
   6.118 +    /// \brief Check if the heap is empty.
   6.119 +    ///
   6.120 +    /// This function returns \c true if the heap is empty.
   6.121 +    bool empty() const { return _num_items==0; }
   6.122 +
   6.123 +    /// \brief Make the heap empty.
   6.124 +    ///
   6.125 +    /// This functon makes the heap empty.
   6.126 +    /// It does not change the cross reference map. If you want to reuse
   6.127 +    /// a heap that is not surely empty, you should first clear it and
   6.128 +    /// then you should set the cross reference map to \c PRE_HEAP
   6.129 +    /// for each item.
   6.130 +    void clear() {
   6.131 +      _data.clear(); _min=0; _num_items=0; _head=-1;
   6.132 +    }
   6.133 +
   6.134 +    /// \brief Set the priority of an item or insert it, if it is
   6.135 +    /// not stored in the heap.
   6.136 +    ///
   6.137 +    /// This method sets the priority of the given item if it is
   6.138 +    /// already stored in the heap. Otherwise it inserts the given
   6.139 +    /// item into the heap with the given priority.
   6.140 +    /// \param item The item.
   6.141 +    /// \param value The priority.
   6.142 +    void set (const Item& item, const Prio& value) {
   6.143 +      int i=_iim[item];
   6.144 +      if ( i >= 0 && _data[i].in ) {
   6.145 +        if ( _comp(value, _data[i].prio) ) decrease(item, value);
   6.146 +        if ( _comp(_data[i].prio, value) ) increase(item, value);
   6.147 +      } else push(item, value);
   6.148 +    }
   6.149 +
   6.150 +    /// \brief Insert an item into the heap with the given priority.
   6.151 +    ///
   6.152 +    /// This function inserts the given item into the heap with the
   6.153 +    /// given priority.
   6.154 +    /// \param item The item to insert.
   6.155 +    /// \param value The priority of the item.
   6.156 +    /// \pre \e item must not be stored in the heap.
   6.157 +    void push (const Item& item, const Prio& value) {
   6.158 +      int i=_iim[item];
   6.159 +      if ( i<0 ) {
   6.160 +        int s=_data.size();
   6.161 +        _iim.set( item,s );
   6.162 +        Store st;
   6.163 +        st.name=item;
   6.164 +        st.prio=value;
   6.165 +        _data.push_back(st);
   6.166 +        i=s;
   6.167 +      }
   6.168 +      else {
   6.169 +        _data[i].parent=_data[i].right_neighbor=_data[i].child=-1;
   6.170 +        _data[i].degree=0;
   6.171 +        _data[i].in=true;
   6.172 +        _data[i].prio=value;
   6.173 +      }
   6.174 +
   6.175 +      if( 0==_num_items ) {
   6.176 +        _head=i;
   6.177 +        _min=i;
   6.178 +      } else {
   6.179 +        merge(i);
   6.180 +        if( _comp(_data[i].prio, _data[_min].prio) ) _min=i;
   6.181 +      }
   6.182 +      ++_num_items;
   6.183 +    }
   6.184 +
   6.185 +    /// \brief Return the item having minimum priority.
   6.186 +    ///
   6.187 +    /// This function returns the item having minimum priority.
   6.188 +    /// \pre The heap must be non-empty.
   6.189 +    Item top() const { return _data[_min].name; }
   6.190 +
   6.191 +    /// \brief The minimum priority.
   6.192 +    ///
   6.193 +    /// This function returns the minimum priority.
   6.194 +    /// \pre The heap must be non-empty.
   6.195 +    Prio prio() const { return _data[_min].prio; }
   6.196 +
   6.197 +    /// \brief The priority of the given item.
   6.198 +    ///
   6.199 +    /// This function returns the priority of the given item.
   6.200 +    /// \param item The item.
   6.201 +    /// \pre \e item must be in the heap.
   6.202 +    const Prio& operator[](const Item& item) const {
   6.203 +      return _data[_iim[item]].prio;
   6.204 +    }
   6.205 +
   6.206 +    /// \brief Remove the item having minimum priority.
   6.207 +    ///
   6.208 +    /// This function removes the item having minimum priority.
   6.209 +    /// \pre The heap must be non-empty.
   6.210 +    void pop() {
   6.211 +      _data[_min].in=false;
   6.212 +
   6.213 +      int head_child=-1;
   6.214 +      if ( _data[_min].child!=-1 ) {
   6.215 +        int child=_data[_min].child;
   6.216 +        int neighb;
   6.217 +        while( child!=-1 ) {
   6.218 +          neighb=_data[child].right_neighbor;
   6.219 +          _data[child].parent=-1;
   6.220 +          _data[child].right_neighbor=head_child;
   6.221 +          head_child=child;
   6.222 +          child=neighb;
   6.223 +        }
   6.224 +      }
   6.225 +
   6.226 +      if ( _data[_head].right_neighbor==-1 ) {
   6.227 +        // there was only one root
   6.228 +        _head=head_child;
   6.229 +      }
   6.230 +      else {
   6.231 +        // there were more roots
   6.232 +        if( _head!=_min )  { unlace(_min); }
   6.233 +        else { _head=_data[_head].right_neighbor; }
   6.234 +        merge(head_child);
   6.235 +      }
   6.236 +      _min=findMin();
   6.237 +      --_num_items;
   6.238 +    }
   6.239 +
   6.240 +    /// \brief Remove the given item from the heap.
   6.241 +    ///
   6.242 +    /// This function removes the given item from the heap if it is
   6.243 +    /// already stored.
   6.244 +    /// \param item The item to delete.
   6.245 +    /// \pre \e item must be in the heap.
   6.246 +    void erase (const Item& item) {
   6.247 +      int i=_iim[item];
   6.248 +      if ( i >= 0 && _data[i].in ) {
   6.249 +        decrease( item, _data[_min].prio-1 );
   6.250 +        pop();
   6.251 +      }
   6.252 +    }
   6.253 +
   6.254 +    /// \brief Decrease the priority of an item to the given value.
   6.255 +    ///
   6.256 +    /// This function decreases the priority of an item to the given value.
   6.257 +    /// \param item The item.
   6.258 +    /// \param value The priority.
   6.259 +    /// \pre \e item must be stored in the heap with priority at least \e value.
   6.260 +    void decrease (Item item, const Prio& value) {
   6.261 +      int i=_iim[item];
   6.262 +      int p=_data[i].parent;
   6.263 +      _data[i].prio=value;
   6.264 +      
   6.265 +      while( p!=-1 && _comp(value, _data[p].prio) ) {
   6.266 +        _data[i].name=_data[p].name;
   6.267 +        _data[i].prio=_data[p].prio;
   6.268 +        _data[p].name=item;
   6.269 +        _data[p].prio=value;
   6.270 +        _iim[_data[i].name]=i;
   6.271 +        i=p;
   6.272 +        p=_data[p].parent;
   6.273 +      }
   6.274 +      _iim[item]=i;
   6.275 +      if ( _comp(value, _data[_min].prio) ) _min=i;
   6.276 +    }
   6.277 +
   6.278 +    /// \brief Increase the priority of an item to the given value.
   6.279 +    ///
   6.280 +    /// This function increases the priority of an item to the given value.
   6.281 +    /// \param item The item.
   6.282 +    /// \param value The priority.
   6.283 +    /// \pre \e item must be stored in the heap with priority at most \e value.
   6.284 +    void increase (Item item, const Prio& value) {
   6.285 +      erase(item);
   6.286 +      push(item, value);
   6.287 +    }
   6.288 +
   6.289 +    /// \brief Return the state of an item.
   6.290 +    ///
   6.291 +    /// This method returns \c PRE_HEAP if the given item has never
   6.292 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
   6.293 +    /// and \c POST_HEAP otherwise.
   6.294 +    /// In the latter case it is possible that the item will get back
   6.295 +    /// to the heap again.
   6.296 +    /// \param item The item.
   6.297 +    State state(const Item &item) const {
   6.298 +      int i=_iim[item];
   6.299 +      if( i>=0 ) {
   6.300 +        if ( _data[i].in ) i=0;
   6.301 +        else i=-2;
   6.302 +      }
   6.303 +      return State(i);
   6.304 +    }
   6.305 +
   6.306 +    /// \brief Set the state of an item in the heap.
   6.307 +    ///
   6.308 +    /// This function sets the state of the given item in the heap.
   6.309 +    /// It can be used to manually clear the heap when it is important
   6.310 +    /// to achive better time complexity.
   6.311 +    /// \param i The item.
   6.312 +    /// \param st The state. It should not be \c IN_HEAP.
   6.313 +    void state(const Item& i, State st) {
   6.314 +      switch (st) {
   6.315 +      case POST_HEAP:
   6.316 +      case PRE_HEAP:
   6.317 +        if (state(i) == IN_HEAP) {
   6.318 +          erase(i);
   6.319 +        }
   6.320 +        _iim[i] = st;
   6.321 +        break;
   6.322 +      case IN_HEAP:
   6.323 +        break;
   6.324 +      }
   6.325 +    }
   6.326 +
   6.327 +  private:
   6.328 +    
   6.329 +    // Find the minimum of the roots
   6.330 +    int findMin() {
   6.331 +      if( _head!=-1 ) {
   6.332 +        int min_loc=_head, min_val=_data[_head].prio;
   6.333 +        for( int x=_data[_head].right_neighbor; x!=-1;
   6.334 +             x=_data[x].right_neighbor ) {
   6.335 +          if( _comp( _data[x].prio,min_val ) ) {
   6.336 +            min_val=_data[x].prio;
   6.337 +            min_loc=x;
   6.338 +          }
   6.339 +        }
   6.340 +        return min_loc;
   6.341 +      }
   6.342 +      else return -1;
   6.343 +    }
   6.344 +
   6.345 +    // Merge the heap with another heap starting at the given position
   6.346 +    void merge(int a) {
   6.347 +      if( _head==-1 || a==-1 ) return;
   6.348 +      if( _data[a].right_neighbor==-1 &&
   6.349 +          _data[a].degree<=_data[_head].degree ) {
   6.350 +        _data[a].right_neighbor=_head;
   6.351 +        _head=a;
   6.352 +      } else {
   6.353 +        interleave(a);
   6.354 +      }
   6.355 +      if( _data[_head].right_neighbor==-1 ) return;
   6.356 +      
   6.357 +      int x=_head;
   6.358 +      int x_prev=-1, x_next=_data[x].right_neighbor;
   6.359 +      while( x_next!=-1 ) {
   6.360 +        if( _data[x].degree!=_data[x_next].degree ||
   6.361 +            ( _data[x_next].right_neighbor!=-1 &&
   6.362 +              _data[_data[x_next].right_neighbor].degree==_data[x].degree ) ) {
   6.363 +          x_prev=x;
   6.364 +          x=x_next;
   6.365 +        }
   6.366 +        else {
   6.367 +          if( _comp(_data[x_next].prio,_data[x].prio) ) {
   6.368 +            if( x_prev==-1 ) {
   6.369 +              _head=x_next;
   6.370 +            } else {
   6.371 +              _data[x_prev].right_neighbor=x_next;
   6.372 +            }
   6.373 +            fuse(x,x_next);
   6.374 +            x=x_next;
   6.375 +          }
   6.376 +          else {
   6.377 +            _data[x].right_neighbor=_data[x_next].right_neighbor;
   6.378 +            fuse(x_next,x);
   6.379 +          }
   6.380 +        }
   6.381 +        x_next=_data[x].right_neighbor;
   6.382 +      }
   6.383 +    }
   6.384 +
   6.385 +    // Interleave the elements of the given list into the list of the roots
   6.386 +    void interleave(int a) {
   6.387 +      int p=_head, q=a;
   6.388 +      int curr=_data.size();
   6.389 +      _data.push_back(Store());
   6.390 +      
   6.391 +      while( p!=-1 || q!=-1 ) {
   6.392 +        if( q==-1 || ( p!=-1 && _data[p].degree<_data[q].degree ) ) {
   6.393 +          _data[curr].right_neighbor=p;
   6.394 +          curr=p;
   6.395 +          p=_data[p].right_neighbor;
   6.396 +        }
   6.397 +        else {
   6.398 +          _data[curr].right_neighbor=q;
   6.399 +          curr=q;
   6.400 +          q=_data[q].right_neighbor;
   6.401 +        }
   6.402 +      }
   6.403 +      
   6.404 +      _head=_data.back().right_neighbor;
   6.405 +      _data.pop_back();
   6.406 +    }
   6.407 +
   6.408 +    // Lace node a under node b
   6.409 +    void fuse(int a, int b) {
   6.410 +      _data[a].parent=b;
   6.411 +      _data[a].right_neighbor=_data[b].child;
   6.412 +      _data[b].child=a;
   6.413 +
   6.414 +      ++_data[b].degree;
   6.415 +    }
   6.416 +
   6.417 +    // Unlace node a (if it has siblings)
   6.418 +    void unlace(int a) {
   6.419 +      int neighb=_data[a].right_neighbor;
   6.420 +      int other=_head;
   6.421 +
   6.422 +      while( _data[other].right_neighbor!=a )
   6.423 +        other=_data[other].right_neighbor;
   6.424 +      _data[other].right_neighbor=neighb;
   6.425 +    }
   6.426 +
   6.427 +  private:
   6.428 +
   6.429 +    class Store {
   6.430 +      friend class BinomHeap;
   6.431 +
   6.432 +      Item name;
   6.433 +      int parent;
   6.434 +      int right_neighbor;
   6.435 +      int child;
   6.436 +      int degree;
   6.437 +      bool in;
   6.438 +      Prio prio;
   6.439 +
   6.440 +      Store() : parent(-1), right_neighbor(-1), child(-1), degree(0),
   6.441 +        in(true) {}
   6.442 +    };
   6.443 +  };
   6.444 +
   6.445 +} //namespace lemon
   6.446 +
   6.447 +#endif //LEMON_BINOM_HEAP_H
   6.448 +
     7.1 --- a/lemon/bits/edge_set_extender.h	Fri Sep 25 12:24:16 2009 +0200
     7.2 +++ b/lemon/bits/edge_set_extender.h	Sat Sep 26 07:08:10 2009 +0200
     7.3 @@ -537,7 +537,7 @@
     7.4        typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent;
     7.5  
     7.6      public:
     7.7 -      ArcMap(const Graph& _g) 
     7.8 +      explicit ArcMap(const Graph& _g) 
     7.9  	: Parent(_g) {}
    7.10        ArcMap(const Graph& _g, const _Value& _v) 
    7.11  	: Parent(_g, _v) {}
    7.12 @@ -561,7 +561,7 @@
    7.13        typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
    7.14  
    7.15      public:
    7.16 -      EdgeMap(const Graph& _g) 
    7.17 +      explicit EdgeMap(const Graph& _g) 
    7.18  	: Parent(_g) {}
    7.19  
    7.20        EdgeMap(const Graph& _g, const _Value& _v) 
     8.1 --- a/lemon/bits/graph_extender.h	Fri Sep 25 12:24:16 2009 +0200
     8.2 +++ b/lemon/bits/graph_extender.h	Sat Sep 26 07:08:10 2009 +0200
     8.3 @@ -604,7 +604,7 @@
     8.4        typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
     8.5  
     8.6      public:
     8.7 -      NodeMap(const Graph& graph)
     8.8 +      explicit NodeMap(const Graph& graph)
     8.9          : Parent(graph) {}
    8.10        NodeMap(const Graph& graph, const _Value& value)
    8.11          : Parent(graph, value) {}
    8.12 @@ -628,7 +628,7 @@
    8.13        typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent;
    8.14  
    8.15      public:
    8.16 -      ArcMap(const Graph& graph)
    8.17 +      explicit ArcMap(const Graph& graph)
    8.18          : Parent(graph) {}
    8.19        ArcMap(const Graph& graph, const _Value& value)
    8.20          : Parent(graph, value) {}
    8.21 @@ -652,7 +652,7 @@
    8.22        typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
    8.23  
    8.24      public:
    8.25 -      EdgeMap(const Graph& graph)
    8.26 +      explicit EdgeMap(const Graph& graph)
    8.27          : Parent(graph) {}
    8.28  
    8.29        EdgeMap(const Graph& graph, const _Value& value)
     9.1 --- a/lemon/bits/map_extender.h	Fri Sep 25 12:24:16 2009 +0200
     9.2 +++ b/lemon/bits/map_extender.h	Sat Sep 26 07:08:10 2009 +0200
     9.3 @@ -49,6 +49,8 @@
     9.4      typedef typename Parent::Reference Reference;
     9.5      typedef typename Parent::ConstReference ConstReference;
     9.6  
     9.7 +    typedef typename Parent::ReferenceMapTag ReferenceMapTag;
     9.8 +
     9.9      class MapIt;
    9.10      class ConstMapIt;
    9.11  
    9.12 @@ -191,6 +193,8 @@
    9.13      typedef typename Parent::Reference Reference;
    9.14      typedef typename Parent::ConstReference ConstReference;
    9.15  
    9.16 +    typedef typename Parent::ReferenceMapTag ReferenceMapTag;
    9.17 +
    9.18      class MapIt;
    9.19      class ConstMapIt;
    9.20  
    10.1 --- a/lemon/bucket_heap.h	Fri Sep 25 12:24:16 2009 +0200
    10.2 +++ b/lemon/bucket_heap.h	Sat Sep 26 07:08:10 2009 +0200
    10.3 @@ -19,9 +19,9 @@
    10.4  #ifndef LEMON_BUCKET_HEAP_H
    10.5  #define LEMON_BUCKET_HEAP_H
    10.6  
    10.7 -///\ingroup auxdat
    10.8 +///\ingroup heaps
    10.9  ///\file
   10.10 -///\brief Bucket Heap implementation.
   10.11 +///\brief Bucket heap implementation.
   10.12  
   10.13  #include <vector>
   10.14  #include <utility>
   10.15 @@ -53,35 +53,41 @@
   10.16  
   10.17    }
   10.18  
   10.19 -  /// \ingroup auxdat
   10.20 +  /// \ingroup heaps
   10.21    ///
   10.22 -  /// \brief A Bucket Heap implementation.
   10.23 +  /// \brief Bucket heap data structure.
   10.24    ///
   10.25 -  /// This class implements the \e bucket \e heap data structure. A \e heap
   10.26 -  /// is a data structure for storing items with specified values called \e
   10.27 -  /// priorities in such a way that finding the item with minimum priority is
   10.28 -  /// efficient. The bucket heap is very simple implementation, it can store
   10.29 -  /// only integer priorities and it stores for each priority in the
   10.30 -  /// \f$ [0..C) \f$ range a list of items. So it should be used only when
   10.31 -  /// the priorities are small. It is not intended to use as dijkstra heap.
   10.32 +  /// This class implements the \e bucket \e heap data structure.
   10.33 +  /// It practically conforms to the \ref concepts::Heap "heap concept",
   10.34 +  /// but it has some limitations.
   10.35    ///
   10.36 -  /// \param IM A read and write Item int map, used internally
   10.37 -  /// to handle the cross references.
   10.38 -  /// \param MIN If the given parameter is false then instead of the
   10.39 -  /// minimum value the maximum can be retrivied with the top() and
   10.40 -  /// prio() member functions.
   10.41 +  /// The bucket heap is a very simple structure. It can store only
   10.42 +  /// \c int priorities and it maintains a list of items for each priority
   10.43 +  /// in the range <tt>[0..C)</tt>. So it should only be used when the
   10.44 +  /// priorities are small. It is not intended to use as a Dijkstra heap.
   10.45 +  ///
   10.46 +  /// \tparam IM A read-writable item map with \c int values, used
   10.47 +  /// internally to handle the cross references.
   10.48 +  /// \tparam MIN Indicate if the heap is a \e min-heap or a \e max-heap.
   10.49 +  /// The default is \e min-heap. If this parameter is set to \c false,
   10.50 +  /// then the comparison is reversed, so the top(), prio() and pop()
   10.51 +  /// functions deal with the item having maximum priority instead of the
   10.52 +  /// minimum.
   10.53 +  ///
   10.54 +  /// \sa SimpleBucketHeap
   10.55    template <typename IM, bool MIN = true>
   10.56    class BucketHeap {
   10.57  
   10.58    public:
   10.59 -    /// \e
   10.60 -    typedef typename IM::Key Item;
   10.61 -    /// \e
   10.62 +
   10.63 +    /// Type of the item-int map.
   10.64 +    typedef IM ItemIntMap;
   10.65 +    /// Type of the priorities.
   10.66      typedef int Prio;
   10.67 -    /// \e
   10.68 -    typedef std::pair<Item, Prio> Pair;
   10.69 -    /// \e
   10.70 -    typedef IM ItemIntMap;
   10.71 +    /// Type of the items stored in the heap.
   10.72 +    typedef typename ItemIntMap::Key Item;
   10.73 +    /// Type of the item-priority pairs.
   10.74 +    typedef std::pair<Item,Prio> Pair;
   10.75  
   10.76    private:
   10.77  
   10.78 @@ -89,10 +95,10 @@
   10.79  
   10.80    public:
   10.81  
   10.82 -    /// \brief Type to represent the items states.
   10.83 +    /// \brief Type to represent the states of the items.
   10.84      ///
   10.85 -    /// Each Item element have a state associated to it. It may be "in heap",
   10.86 -    /// "pre heap" or "post heap". The latter two are indifferent from the
   10.87 +    /// Each item has a state associated to it. It can be "in heap",
   10.88 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
   10.89      /// heap's point of view, but may be useful to the user.
   10.90      ///
   10.91      /// The item-int map must be initialized in such way that it assigns
   10.92 @@ -104,37 +110,39 @@
   10.93      };
   10.94  
   10.95    public:
   10.96 -    /// \brief The constructor.
   10.97 +
   10.98 +    /// \brief Constructor.
   10.99      ///
  10.100 -    /// The constructor.
  10.101 -    /// \param map should be given to the constructor, since it is used
  10.102 -    /// internally to handle the cross references. The value of the map
  10.103 -    /// should be PRE_HEAP (-1) for each element.
  10.104 +    /// Constructor.
  10.105 +    /// \param map A map that assigns \c int values to the items.
  10.106 +    /// It is used internally to handle the cross references.
  10.107 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  10.108      explicit BucketHeap(ItemIntMap &map) : _iim(map), _minimum(0) {}
  10.109  
  10.110 -    /// The number of items stored in the heap.
  10.111 +    /// \brief The number of items stored in the heap.
  10.112      ///
  10.113 -    /// \brief Returns the number of items stored in the heap.
  10.114 +    /// This function returns the number of items stored in the heap.
  10.115      int size() const { return _data.size(); }
  10.116  
  10.117 -    /// \brief Checks if the heap stores no items.
  10.118 +    /// \brief Check if the heap is empty.
  10.119      ///
  10.120 -    /// Returns \c true if and only if the heap stores no items.
  10.121 +    /// This function returns \c true if the heap is empty.
  10.122      bool empty() const { return _data.empty(); }
  10.123  
  10.124 -    /// \brief Make empty this heap.
  10.125 +    /// \brief Make the heap empty.
  10.126      ///
  10.127 -    /// Make empty this heap. It does not change the cross reference
  10.128 -    /// map.  If you want to reuse a heap what is not surely empty you
  10.129 -    /// should first clear the heap and after that you should set the
  10.130 -    /// cross reference map for each item to \c PRE_HEAP.
  10.131 +    /// This functon makes the heap empty.
  10.132 +    /// It does not change the cross reference map. If you want to reuse
  10.133 +    /// a heap that is not surely empty, you should first clear it and
  10.134 +    /// then you should set the cross reference map to \c PRE_HEAP
  10.135 +    /// for each item.
  10.136      void clear() {
  10.137        _data.clear(); _first.clear(); _minimum = 0;
  10.138      }
  10.139  
  10.140    private:
  10.141  
  10.142 -    void relocate_last(int idx) {
  10.143 +    void relocateLast(int idx) {
  10.144        if (idx + 1 < int(_data.size())) {
  10.145          _data[idx] = _data.back();
  10.146          if (_data[idx].prev != -1) {
  10.147 @@ -174,19 +182,24 @@
  10.148      }
  10.149  
  10.150    public:
  10.151 +
  10.152      /// \brief Insert a pair of item and priority into the heap.
  10.153      ///
  10.154 -    /// Adds \c p.first to the heap with priority \c p.second.
  10.155 +    /// This function inserts \c p.first to the heap with priority
  10.156 +    /// \c p.second.
  10.157      /// \param p The pair to insert.
  10.158 +    /// \pre \c p.first must not be stored in the heap.
  10.159      void push(const Pair& p) {
  10.160        push(p.first, p.second);
  10.161      }
  10.162  
  10.163      /// \brief Insert an item into the heap with the given priority.
  10.164      ///
  10.165 -    /// Adds \c i to the heap with priority \c p.
  10.166 +    /// This function inserts the given item into the heap with the
  10.167 +    /// given priority.
  10.168      /// \param i The item to insert.
  10.169      /// \param p The priority of the item.
  10.170 +    /// \pre \e i must not be stored in the heap.
  10.171      void push(const Item &i, const Prio &p) {
  10.172        int idx = _data.size();
  10.173        _iim[i] = idx;
  10.174 @@ -197,10 +210,10 @@
  10.175        }
  10.176      }
  10.177  
  10.178 -    /// \brief Returns the item with minimum priority.
  10.179 +    /// \brief Return the item having minimum priority.
  10.180      ///
  10.181 -    /// This method returns the item with minimum priority.
  10.182 -    /// \pre The heap must be nonempty.
  10.183 +    /// This function returns the item having minimum priority.
  10.184 +    /// \pre The heap must be non-empty.
  10.185      Item top() const {
  10.186        while (_first[_minimum] == -1) {
  10.187          Direction::increase(_minimum);
  10.188 @@ -208,10 +221,10 @@
  10.189        return _data[_first[_minimum]].item;
  10.190      }
  10.191  
  10.192 -    /// \brief Returns the minimum priority.
  10.193 +    /// \brief The minimum priority.
  10.194      ///
  10.195 -    /// It returns the minimum priority.
  10.196 -    /// \pre The heap must be nonempty.
  10.197 +    /// This function returns the minimum priority.
  10.198 +    /// \pre The heap must be non-empty.
  10.199      Prio prio() const {
  10.200        while (_first[_minimum] == -1) {
  10.201          Direction::increase(_minimum);
  10.202 @@ -219,9 +232,9 @@
  10.203        return _minimum;
  10.204      }
  10.205  
  10.206 -    /// \brief Deletes the item with minimum priority.
  10.207 +    /// \brief Remove the item having minimum priority.
  10.208      ///
  10.209 -    /// This method deletes the item with minimum priority from the heap.
  10.210 +    /// This function removes the item having minimum priority.
  10.211      /// \pre The heap must be non-empty.
  10.212      void pop() {
  10.213        while (_first[_minimum] == -1) {
  10.214 @@ -230,37 +243,38 @@
  10.215        int idx = _first[_minimum];
  10.216        _iim[_data[idx].item] = -2;
  10.217        unlace(idx);
  10.218 -      relocate_last(idx);
  10.219 +      relocateLast(idx);
  10.220      }
  10.221  
  10.222 -    /// \brief Deletes \c i from the heap.
  10.223 +    /// \brief Remove the given item from the heap.
  10.224      ///
  10.225 -    /// This method deletes item \c i from the heap, if \c i was
  10.226 -    /// already stored in the heap.
  10.227 -    /// \param i The item to erase.
  10.228 +    /// This function removes the given item from the heap if it is
  10.229 +    /// already stored.
  10.230 +    /// \param i The item to delete.
  10.231 +    /// \pre \e i must be in the heap.
  10.232      void erase(const Item &i) {
  10.233        int idx = _iim[i];
  10.234        _iim[_data[idx].item] = -2;
  10.235        unlace(idx);
  10.236 -      relocate_last(idx);
  10.237 +      relocateLast(idx);
  10.238      }
  10.239  
  10.240 -
  10.241 -    /// \brief Returns the priority of \c i.
  10.242 +    /// \brief The priority of the given item.
  10.243      ///
  10.244 -    /// This function returns the priority of item \c i.
  10.245 -    /// \pre \c i must be in the heap.
  10.246 +    /// This function returns the priority of the given item.
  10.247      /// \param i The item.
  10.248 +    /// \pre \e i must be in the heap.
  10.249      Prio operator[](const Item &i) const {
  10.250        int idx = _iim[i];
  10.251        return _data[idx].value;
  10.252      }
  10.253  
  10.254 -    /// \brief \c i gets to the heap with priority \c p independently
  10.255 -    /// if \c i was already there.
  10.256 +    /// \brief Set the priority of an item or insert it, if it is
  10.257 +    /// not stored in the heap.
  10.258      ///
  10.259 -    /// This method calls \ref push(\c i, \c p) if \c i is not stored
  10.260 -    /// in the heap and sets the priority of \c i to \c p otherwise.
  10.261 +    /// This method sets the priority of the given item if it is
  10.262 +    /// already stored in the heap. Otherwise it inserts the given
  10.263 +    /// item into the heap with the given priority.
  10.264      /// \param i The item.
  10.265      /// \param p The priority.
  10.266      void set(const Item &i, const Prio &p) {
  10.267 @@ -274,13 +288,12 @@
  10.268        }
  10.269      }
  10.270  
  10.271 -    /// \brief Decreases the priority of \c i to \c p.
  10.272 +    /// \brief Decrease the priority of an item to the given value.
  10.273      ///
  10.274 -    /// This method decreases the priority of item \c i to \c p.
  10.275 -    /// \pre \c i must be stored in the heap with priority at least \c
  10.276 -    /// p relative to \c Compare.
  10.277 +    /// This function decreases the priority of an item to the given value.
  10.278      /// \param i The item.
  10.279      /// \param p The priority.
  10.280 +    /// \pre \e i must be stored in the heap with priority at least \e p.
  10.281      void decrease(const Item &i, const Prio &p) {
  10.282        int idx = _iim[i];
  10.283        unlace(idx);
  10.284 @@ -291,13 +304,12 @@
  10.285        lace(idx);
  10.286      }
  10.287  
  10.288 -    /// \brief Increases the priority of \c i to \c p.
  10.289 +    /// \brief Increase the priority of an item to the given value.
  10.290      ///
  10.291 -    /// This method sets the priority of item \c i to \c p.
  10.292 -    /// \pre \c i must be stored in the heap with priority at most \c
  10.293 -    /// p relative to \c Compare.
  10.294 +    /// This function increases the priority of an item to the given value.
  10.295      /// \param i The item.
  10.296      /// \param p The priority.
  10.297 +    /// \pre \e i must be stored in the heap with priority at most \e p.
  10.298      void increase(const Item &i, const Prio &p) {
  10.299        int idx = _iim[i];
  10.300        unlace(idx);
  10.301 @@ -305,13 +317,13 @@
  10.302        lace(idx);
  10.303      }
  10.304  
  10.305 -    /// \brief Returns if \c item is in, has already been in, or has
  10.306 -    /// never been in the heap.
  10.307 +    /// \brief Return the state of an item.
  10.308      ///
  10.309 -    /// This method returns PRE_HEAP if \c item has never been in the
  10.310 -    /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
  10.311 -    /// otherwise. In the latter case it is possible that \c item will
  10.312 -    /// get back to the heap again.
  10.313 +    /// This method returns \c PRE_HEAP if the given item has never
  10.314 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  10.315 +    /// and \c POST_HEAP otherwise.
  10.316 +    /// In the latter case it is possible that the item will get back
  10.317 +    /// to the heap again.
  10.318      /// \param i The item.
  10.319      State state(const Item &i) const {
  10.320        int idx = _iim[i];
  10.321 @@ -319,11 +331,11 @@
  10.322        return State(idx);
  10.323      }
  10.324  
  10.325 -    /// \brief Sets the state of the \c item in the heap.
  10.326 +    /// \brief Set the state of an item in the heap.
  10.327      ///
  10.328 -    /// Sets the state of the \c item in the heap. It can be used to
  10.329 -    /// manually clear the heap when it is important to achive the
  10.330 -    /// better time complexity.
  10.331 +    /// This function sets the state of the given item in the heap.
  10.332 +    /// It can be used to manually clear the heap when it is important
  10.333 +    /// to achive better time complexity.
  10.334      /// \param i The item.
  10.335      /// \param st The state. It should not be \c IN_HEAP.
  10.336      void state(const Item& i, State st) {
  10.337 @@ -359,33 +371,44 @@
  10.338  
  10.339    }; // class BucketHeap
  10.340  
  10.341 -  /// \ingroup auxdat
  10.342 +  /// \ingroup heaps
  10.343    ///
  10.344 -  /// \brief A Simplified Bucket Heap implementation.
  10.345 +  /// \brief Simplified bucket heap data structure.
  10.346    ///
  10.347    /// This class implements a simplified \e bucket \e heap data
  10.348 -  /// structure.  It does not provide some functionality but it faster
  10.349 -  /// and simplier data structure than the BucketHeap. The main
  10.350 -  /// difference is that the BucketHeap stores for every key a double
  10.351 -  /// linked list while this class stores just simple lists. In the
  10.352 -  /// other way it does not support erasing each elements just the
  10.353 -  /// minimal and it does not supports key increasing, decreasing.
  10.354 +  /// structure. It does not provide some functionality, but it is
  10.355 +  /// faster and simpler than BucketHeap. The main difference is
  10.356 +  /// that BucketHeap stores a doubly-linked list for each key while
  10.357 +  /// this class stores only simply-linked lists. It supports erasing
  10.358 +  /// only for the item having minimum priority and it does not support
  10.359 +  /// key increasing and decreasing.
  10.360    ///
  10.361 -  /// \param IM A read and write Item int map, used internally
  10.362 -  /// to handle the cross references.
  10.363 -  /// \param MIN If the given parameter is false then instead of the
  10.364 -  /// minimum value the maximum can be retrivied with the top() and
  10.365 -  /// prio() member functions.
  10.366 +  /// Note that this implementation does not conform to the
  10.367 +  /// \ref concepts::Heap "heap concept" due to the lack of some 
  10.368 +  /// functionality.
  10.369 +  ///
  10.370 +  /// \tparam IM A read-writable item map with \c int values, used
  10.371 +  /// internally to handle the cross references.
  10.372 +  /// \tparam MIN Indicate if the heap is a \e min-heap or a \e max-heap.
  10.373 +  /// The default is \e min-heap. If this parameter is set to \c false,
  10.374 +  /// then the comparison is reversed, so the top(), prio() and pop()
  10.375 +  /// functions deal with the item having maximum priority instead of the
  10.376 +  /// minimum.
  10.377    ///
  10.378    /// \sa BucketHeap
  10.379    template <typename IM, bool MIN = true >
  10.380    class SimpleBucketHeap {
  10.381  
  10.382    public:
  10.383 -    typedef typename IM::Key Item;
  10.384 +
  10.385 +    /// Type of the item-int map.
  10.386 +    typedef IM ItemIntMap;
  10.387 +    /// Type of the priorities.
  10.388      typedef int Prio;
  10.389 -    typedef std::pair<Item, Prio> Pair;
  10.390 -    typedef IM ItemIntMap;
  10.391 +    /// Type of the items stored in the heap.
  10.392 +    typedef typename ItemIntMap::Key Item;
  10.393 +    /// Type of the item-priority pairs.
  10.394 +    typedef std::pair<Item,Prio> Pair;
  10.395  
  10.396    private:
  10.397  
  10.398 @@ -393,10 +416,10 @@
  10.399  
  10.400    public:
  10.401  
  10.402 -    /// \brief Type to represent the items states.
  10.403 +    /// \brief Type to represent the states of the items.
  10.404      ///
  10.405 -    /// Each Item element have a state associated to it. It may be "in heap",
  10.406 -    /// "pre heap" or "post heap". The latter two are indifferent from the
  10.407 +    /// Each item has a state associated to it. It can be "in heap",
  10.408 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
  10.409      /// heap's point of view, but may be useful to the user.
  10.410      ///
  10.411      /// The item-int map must be initialized in such way that it assigns
  10.412 @@ -409,48 +432,53 @@
  10.413  
  10.414    public:
  10.415  
  10.416 -    /// \brief The constructor.
  10.417 +    /// \brief Constructor.
  10.418      ///
  10.419 -    /// The constructor.
  10.420 -    /// \param map should be given to the constructor, since it is used
  10.421 -    /// internally to handle the cross references. The value of the map
  10.422 -    /// should be PRE_HEAP (-1) for each element.
  10.423 +    /// Constructor.
  10.424 +    /// \param map A map that assigns \c int values to the items.
  10.425 +    /// It is used internally to handle the cross references.
  10.426 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  10.427      explicit SimpleBucketHeap(ItemIntMap &map)
  10.428        : _iim(map), _free(-1), _num(0), _minimum(0) {}
  10.429  
  10.430 -    /// \brief Returns the number of items stored in the heap.
  10.431 +    /// \brief The number of items stored in the heap.
  10.432      ///
  10.433 -    /// The number of items stored in the heap.
  10.434 +    /// This function returns the number of items stored in the heap.
  10.435      int size() const { return _num; }
  10.436  
  10.437 -    /// \brief Checks if the heap stores no items.
  10.438 +    /// \brief Check if the heap is empty.
  10.439      ///
  10.440 -    /// Returns \c true if and only if the heap stores no items.
  10.441 +    /// This function returns \c true if the heap is empty.
  10.442      bool empty() const { return _num == 0; }
  10.443  
  10.444 -    /// \brief Make empty this heap.
  10.445 +    /// \brief Make the heap empty.
  10.446      ///
  10.447 -    /// Make empty this heap. It does not change the cross reference
  10.448 -    /// map.  If you want to reuse a heap what is not surely empty you
  10.449 -    /// should first clear the heap and after that you should set the
  10.450 -    /// cross reference map for each item to \c PRE_HEAP.
  10.451 +    /// This functon makes the heap empty.
  10.452 +    /// It does not change the cross reference map. If you want to reuse
  10.453 +    /// a heap that is not surely empty, you should first clear it and
  10.454 +    /// then you should set the cross reference map to \c PRE_HEAP
  10.455 +    /// for each item.
  10.456      void clear() {
  10.457        _data.clear(); _first.clear(); _free = -1; _num = 0; _minimum = 0;
  10.458      }
  10.459  
  10.460      /// \brief Insert a pair of item and priority into the heap.
  10.461      ///
  10.462 -    /// Adds \c p.first to the heap with priority \c p.second.
  10.463 +    /// This function inserts \c p.first to the heap with priority
  10.464 +    /// \c p.second.
  10.465      /// \param p The pair to insert.
  10.466 +    /// \pre \c p.first must not be stored in the heap.
  10.467      void push(const Pair& p) {
  10.468        push(p.first, p.second);
  10.469      }
  10.470  
  10.471      /// \brief Insert an item into the heap with the given priority.
  10.472      ///
  10.473 -    /// Adds \c i to the heap with priority \c p.
  10.474 +    /// This function inserts the given item into the heap with the
  10.475 +    /// given priority.
  10.476      /// \param i The item to insert.
  10.477      /// \param p The priority of the item.
  10.478 +    /// \pre \e i must not be stored in the heap.
  10.479      void push(const Item &i, const Prio &p) {
  10.480        int idx;
  10.481        if (_free == -1) {
  10.482 @@ -471,10 +499,10 @@
  10.483        ++_num;
  10.484      }
  10.485  
  10.486 -    /// \brief Returns the item with minimum priority.
  10.487 +    /// \brief Return the item having minimum priority.
  10.488      ///
  10.489 -    /// This method returns the item with minimum priority.
  10.490 -    /// \pre The heap must be nonempty.
  10.491 +    /// This function returns the item having minimum priority.
  10.492 +    /// \pre The heap must be non-empty.
  10.493      Item top() const {
  10.494        while (_first[_minimum] == -1) {
  10.495          Direction::increase(_minimum);
  10.496 @@ -482,10 +510,10 @@
  10.497        return _data[_first[_minimum]].item;
  10.498      }
  10.499  
  10.500 -    /// \brief Returns the minimum priority.
  10.501 +    /// \brief The minimum priority.
  10.502      ///
  10.503 -    /// It returns the minimum priority.
  10.504 -    /// \pre The heap must be nonempty.
  10.505 +    /// This function returns the minimum priority.
  10.506 +    /// \pre The heap must be non-empty.
  10.507      Prio prio() const {
  10.508        while (_first[_minimum] == -1) {
  10.509          Direction::increase(_minimum);
  10.510 @@ -493,9 +521,9 @@
  10.511        return _minimum;
  10.512      }
  10.513  
  10.514 -    /// \brief Deletes the item with minimum priority.
  10.515 +    /// \brief Remove the item having minimum priority.
  10.516      ///
  10.517 -    /// This method deletes the item with minimum priority from the heap.
  10.518 +    /// This function removes the item having minimum priority.
  10.519      /// \pre The heap must be non-empty.
  10.520      void pop() {
  10.521        while (_first[_minimum] == -1) {
  10.522 @@ -509,16 +537,15 @@
  10.523        --_num;
  10.524      }
  10.525  
  10.526 -    /// \brief Returns the priority of \c i.
  10.527 +    /// \brief The priority of the given item.
  10.528      ///
  10.529 -    /// This function returns the priority of item \c i.
  10.530 -    /// \warning This operator is not a constant time function
  10.531 -    /// because it scans the whole data structure to find the proper
  10.532 -    /// value.
  10.533 -    /// \pre \c i must be in the heap.
  10.534 +    /// This function returns the priority of the given item.
  10.535      /// \param i The item.
  10.536 +    /// \pre \e i must be in the heap.
  10.537 +    /// \warning This operator is not a constant time function because
  10.538 +    /// it scans the whole data structure to find the proper value.
  10.539      Prio operator[](const Item &i) const {
  10.540 -      for (int k = 0; k < _first.size(); ++k) {
  10.541 +      for (int k = 0; k < int(_first.size()); ++k) {
  10.542          int idx = _first[k];
  10.543          while (idx != -1) {
  10.544            if (_data[idx].item == i) {
  10.545 @@ -530,13 +557,13 @@
  10.546        return -1;
  10.547      }
  10.548  
  10.549 -    /// \brief Returns if \c item is in, has already been in, or has
  10.550 -    /// never been in the heap.
  10.551 +    /// \brief Return the state of an item.
  10.552      ///
  10.553 -    /// This method returns PRE_HEAP if \c item has never been in the
  10.554 -    /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
  10.555 -    /// otherwise. In the latter case it is possible that \c item will
  10.556 -    /// get back to the heap again.
  10.557 +    /// This method returns \c PRE_HEAP if the given item has never
  10.558 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  10.559 +    /// and \c POST_HEAP otherwise.
  10.560 +    /// In the latter case it is possible that the item will get back
  10.561 +    /// to the heap again.
  10.562      /// \param i The item.
  10.563      State state(const Item &i) const {
  10.564        int idx = _iim[i];
    11.1 --- a/lemon/circulation.h	Fri Sep 25 12:24:16 2009 +0200
    11.2 +++ b/lemon/circulation.h	Sat Sep 26 07:08:10 2009 +0200
    11.3 @@ -72,7 +72,11 @@
    11.4      /// The type of the map that stores the flow values.
    11.5      /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap"
    11.6      /// concept.
    11.7 +#ifdef DOXYGEN
    11.8 +    typedef GR::ArcMap<Value> FlowMap;
    11.9 +#else
   11.10      typedef typename Digraph::template ArcMap<Value> FlowMap;
   11.11 +#endif
   11.12  
   11.13      /// \brief Instantiates a FlowMap.
   11.14      ///
   11.15 @@ -87,9 +91,12 @@
   11.16      ///
   11.17      /// The elevator type used by the algorithm.
   11.18      ///
   11.19 -    /// \sa Elevator
   11.20 -    /// \sa LinkedElevator
   11.21 +    /// \sa Elevator, LinkedElevator
   11.22 +#ifdef DOXYGEN
   11.23 +    typedef lemon::Elevator<GR, GR::Node> Elevator;
   11.24 +#else
   11.25      typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator;
   11.26 +#endif
   11.27  
   11.28      /// \brief Instantiates an Elevator.
   11.29      ///
   11.30 @@ -450,25 +457,27 @@
   11.31        return *_level;
   11.32      }
   11.33  
   11.34 -    /// \brief Sets the tolerance used by algorithm.
   11.35 +    /// \brief Sets the tolerance used by the algorithm.
   11.36      ///
   11.37 -    /// Sets the tolerance used by algorithm.
   11.38 -    Circulation& tolerance(const Tolerance& tolerance) const {
   11.39 +    /// Sets the tolerance object used by the algorithm.
   11.40 +    /// \return <tt>(*this)</tt>
   11.41 +    Circulation& tolerance(const Tolerance& tolerance) {
   11.42        _tol = tolerance;
   11.43        return *this;
   11.44      }
   11.45  
   11.46      /// \brief Returns a const reference to the tolerance.
   11.47      ///
   11.48 -    /// Returns a const reference to the tolerance.
   11.49 +    /// Returns a const reference to the tolerance object used by
   11.50 +    /// the algorithm.
   11.51      const Tolerance& tolerance() const {
   11.52 -      return tolerance;
   11.53 +      return _tol;
   11.54      }
   11.55  
   11.56      /// \name Execution Control
   11.57      /// The simplest way to execute the algorithm is to call \ref run().\n
   11.58 -    /// If you need more control on the initial solution or the execution,
   11.59 -    /// first you have to call one of the \ref init() functions, then
   11.60 +    /// If you need better control on the initial solution or the execution,
   11.61 +    /// you have to call one of the \ref init() functions first, then
   11.62      /// the \ref start() function.
   11.63  
   11.64      ///@{
    12.1 --- a/lemon/concepts/heap.h	Fri Sep 25 12:24:16 2009 +0200
    12.2 +++ b/lemon/concepts/heap.h	Sat Sep 26 07:08:10 2009 +0200
    12.3 @@ -16,13 +16,13 @@
    12.4   *
    12.5   */
    12.6  
    12.7 +#ifndef LEMON_CONCEPTS_HEAP_H
    12.8 +#define LEMON_CONCEPTS_HEAP_H
    12.9 +
   12.10  ///\ingroup concept
   12.11  ///\file
   12.12  ///\brief The concept of heaps.
   12.13  
   12.14 -#ifndef LEMON_CONCEPTS_HEAP_H
   12.15 -#define LEMON_CONCEPTS_HEAP_H
   12.16 -
   12.17  #include <lemon/core.h>
   12.18  #include <lemon/concept_check.h>
   12.19  
   12.20 @@ -35,21 +35,27 @@
   12.21  
   12.22      /// \brief The heap concept.
   12.23      ///
   12.24 -    /// Concept class describing the main interface of heaps. A \e heap
   12.25 -    /// is a data structure for storing items with specified values called
   12.26 -    /// \e priorities in such a way that finding the item with minimum
   12.27 -    /// priority is efficient. In a heap one can change the priority of an
   12.28 -    /// item, add or erase an item, etc.
   12.29 +    /// This concept class describes the main interface of heaps.
   12.30 +    /// The various \ref heaps "heap structures" are efficient
   12.31 +    /// implementations of the abstract data type \e priority \e queue.
   12.32 +    /// They store items with specified values called \e priorities
   12.33 +    /// in such a way that finding and removing the item with minimum
   12.34 +    /// priority are efficient. The basic operations are adding and
   12.35 +    /// erasing items, changing the priority of an item, etc.
   12.36      ///
   12.37 -    /// \tparam PR Type of the priority of the items.
   12.38 -    /// \tparam IM A read and writable item map with int values, used
   12.39 +    /// Heaps are crucial in several algorithms, such as Dijkstra and Prim.
   12.40 +    /// Any class that conforms to this concept can be used easily in such
   12.41 +    /// algorithms.
   12.42 +    ///
   12.43 +    /// \tparam PR Type of the priorities of the items.
   12.44 +    /// \tparam IM A read-writable item map with \c int values, used
   12.45      /// internally to handle the cross references.
   12.46 -    /// \tparam Comp A functor class for the ordering of the priorities.
   12.47 +    /// \tparam CMP A functor class for comparing the priorities.
   12.48      /// The default is \c std::less<PR>.
   12.49  #ifdef DOXYGEN
   12.50 -    template <typename PR, typename IM, typename Comp = std::less<PR> >
   12.51 +    template <typename PR, typename IM, typename CMP>
   12.52  #else
   12.53 -    template <typename PR, typename IM>
   12.54 +    template <typename PR, typename IM, typename CMP = std::less<PR> >
   12.55  #endif
   12.56      class Heap {
   12.57      public:
   12.58 @@ -64,109 +70,125 @@
   12.59        /// \brief Type to represent the states of the items.
   12.60        ///
   12.61        /// Each item has a state associated to it. It can be "in heap",
   12.62 -      /// "pre heap" or "post heap". The later two are indifferent
   12.63 -      /// from the point of view of the heap, but may be useful for
   12.64 -      /// the user.
   12.65 +      /// "pre-heap" or "post-heap". The latter two are indifferent from the
   12.66 +      /// heap's point of view, but may be useful to the user.
   12.67        ///
   12.68        /// The item-int map must be initialized in such way that it assigns
   12.69        /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
   12.70        enum State {
   12.71          IN_HEAP = 0,    ///< = 0. The "in heap" state constant.
   12.72 -        PRE_HEAP = -1,  ///< = -1. The "pre heap" state constant.
   12.73 -        POST_HEAP = -2  ///< = -2. The "post heap" state constant.
   12.74 +        PRE_HEAP = -1,  ///< = -1. The "pre-heap" state constant.
   12.75 +        POST_HEAP = -2  ///< = -2. The "post-heap" state constant.
   12.76        };
   12.77  
   12.78 -      /// \brief The constructor.
   12.79 +      /// \brief Constructor.
   12.80        ///
   12.81 -      /// The constructor.
   12.82 +      /// Constructor.
   12.83        /// \param map A map that assigns \c int values to keys of type
   12.84        /// \c Item. It is used internally by the heap implementations to
   12.85        /// handle the cross references. The assigned value must be
   12.86 -      /// \c PRE_HEAP (<tt>-1</tt>) for every item.
   12.87 +      /// \c PRE_HEAP (<tt>-1</tt>) for each item.
   12.88        explicit Heap(ItemIntMap &map) {}
   12.89  
   12.90 +      /// \brief Constructor.
   12.91 +      ///
   12.92 +      /// Constructor.
   12.93 +      /// \param map A map that assigns \c int values to keys of type
   12.94 +      /// \c Item. It is used internally by the heap implementations to
   12.95 +      /// handle the cross references. The assigned value must be
   12.96 +      /// \c PRE_HEAP (<tt>-1</tt>) for each item.
   12.97 +      /// \param comp The function object used for comparing the priorities.
   12.98 +      explicit Heap(ItemIntMap &map, const CMP &comp) {}
   12.99 +
  12.100        /// \brief The number of items stored in the heap.
  12.101        ///
  12.102 -      /// Returns the number of items stored in the heap.
  12.103 +      /// This function returns the number of items stored in the heap.
  12.104        int size() const { return 0; }
  12.105  
  12.106 -      /// \brief Checks if the heap is empty.
  12.107 +      /// \brief Check if the heap is empty.
  12.108        ///
  12.109 -      /// Returns \c true if the heap is empty.
  12.110 +      /// This function returns \c true if the heap is empty.
  12.111        bool empty() const { return false; }
  12.112  
  12.113 -      /// \brief Makes the heap empty.
  12.114 +      /// \brief Make the heap empty.
  12.115        ///
  12.116 -      /// Makes the heap empty.
  12.117 -      void clear();
  12.118 +      /// This functon makes the heap empty.
  12.119 +      /// It does not change the cross reference map. If you want to reuse
  12.120 +      /// a heap that is not surely empty, you should first clear it and
  12.121 +      /// then you should set the cross reference map to \c PRE_HEAP
  12.122 +      /// for each item.
  12.123 +      void clear() {}
  12.124  
  12.125 -      /// \brief Inserts an item into the heap with the given priority.
  12.126 +      /// \brief Insert an item into the heap with the given priority.
  12.127        ///
  12.128 -      /// Inserts the given item into the heap with the given priority.
  12.129 +      /// This function inserts the given item into the heap with the
  12.130 +      /// given priority.
  12.131        /// \param i The item to insert.
  12.132        /// \param p The priority of the item.
  12.133 +      /// \pre \e i must not be stored in the heap.
  12.134        void push(const Item &i, const Prio &p) {}
  12.135  
  12.136 -      /// \brief Returns the item having minimum priority.
  12.137 +      /// \brief Return the item having minimum priority.
  12.138        ///
  12.139 -      /// Returns the item having minimum priority.
  12.140 +      /// This function returns the item having minimum priority.
  12.141        /// \pre The heap must be non-empty.
  12.142        Item top() const {}
  12.143  
  12.144        /// \brief The minimum priority.
  12.145        ///
  12.146 -      /// Returns the minimum priority.
  12.147 +      /// This function returns the minimum priority.
  12.148        /// \pre The heap must be non-empty.
  12.149        Prio prio() const {}
  12.150  
  12.151 -      /// \brief Removes the item having minimum priority.
  12.152 +      /// \brief Remove the item having minimum priority.
  12.153        ///
  12.154 -      /// Removes the item having minimum priority.
  12.155 +      /// This function removes the item having minimum priority.
  12.156        /// \pre The heap must be non-empty.
  12.157        void pop() {}
  12.158  
  12.159 -      /// \brief Removes an item from the heap.
  12.160 +      /// \brief Remove the given item from the heap.
  12.161        ///
  12.162 -      /// Removes the given item from the heap if it is already stored.
  12.163 +      /// This function removes the given item from the heap if it is
  12.164 +      /// already stored.
  12.165        /// \param i The item to delete.
  12.166 +      /// \pre \e i must be in the heap.
  12.167        void erase(const Item &i) {}
  12.168  
  12.169 -      /// \brief The priority of an item.
  12.170 +      /// \brief The priority of the given item.
  12.171        ///
  12.172 -      /// Returns the priority of the given item.
  12.173 +      /// This function returns the priority of the given item.
  12.174        /// \param i The item.
  12.175 -      /// \pre \c i must be in the heap.
  12.176 +      /// \pre \e i must be in the heap.
  12.177        Prio operator[](const Item &i) const {}
  12.178  
  12.179 -      /// \brief Sets the priority of an item or inserts it, if it is
  12.180 +      /// \brief Set the priority of an item or insert it, if it is
  12.181        /// not stored in the heap.
  12.182        ///
  12.183        /// This method sets the priority of the given item if it is
  12.184 -      /// already stored in the heap.
  12.185 -      /// Otherwise it inserts the given item with the given priority.
  12.186 +      /// already stored in the heap. Otherwise it inserts the given
  12.187 +      /// item into the heap with the given priority.
  12.188        ///
  12.189        /// \param i The item.
  12.190        /// \param p The priority.
  12.191        void set(const Item &i, const Prio &p) {}
  12.192  
  12.193 -      /// \brief Decreases the priority of an item to the given value.
  12.194 +      /// \brief Decrease the priority of an item to the given value.
  12.195        ///
  12.196 -      /// Decreases the priority of an item to the given value.
  12.197 +      /// This function decreases the priority of an item to the given value.
  12.198        /// \param i The item.
  12.199        /// \param p The priority.
  12.200 -      /// \pre \c i must be stored in the heap with priority at least \c p.
  12.201 +      /// \pre \e i must be stored in the heap with priority at least \e p.
  12.202        void decrease(const Item &i, const Prio &p) {}
  12.203  
  12.204 -      /// \brief Increases the priority of an item to the given value.
  12.205 +      /// \brief Increase the priority of an item to the given value.
  12.206        ///
  12.207 -      /// Increases the priority of an item to the given value.
  12.208 +      /// This function increases the priority of an item to the given value.
  12.209        /// \param i The item.
  12.210        /// \param p The priority.
  12.211 -      /// \pre \c i must be stored in the heap with priority at most \c p.
  12.212 +      /// \pre \e i must be stored in the heap with priority at most \e p.
  12.213        void increase(const Item &i, const Prio &p) {}
  12.214  
  12.215 -      /// \brief Returns if an item is in, has already been in, or has
  12.216 -      /// never been in the heap.
  12.217 +      /// \brief Return the state of an item.
  12.218        ///
  12.219        /// This method returns \c PRE_HEAP if the given item has never
  12.220        /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  12.221 @@ -176,11 +198,11 @@
  12.222        /// \param i The item.
  12.223        State state(const Item &i) const {}
  12.224  
  12.225 -      /// \brief Sets the state of an item in the heap.
  12.226 +      /// \brief Set the state of an item in the heap.
  12.227        ///
  12.228 -      /// Sets the state of the given item in the heap. It can be used
  12.229 -      /// to manually clear the heap when it is important to achive the
  12.230 -      /// better time complexity.
  12.231 +      /// This function sets the state of the given item in the heap.
  12.232 +      /// It can be used to manually clear the heap when it is important
  12.233 +      /// to achive better time complexity.
  12.234        /// \param i The item.
  12.235        /// \param st The state. It should not be \c IN_HEAP.
  12.236        void state(const Item& i, State st) {}
    13.1 --- a/lemon/concepts/maps.h	Fri Sep 25 12:24:16 2009 +0200
    13.2 +++ b/lemon/concepts/maps.h	Sat Sep 26 07:08:10 2009 +0200
    13.3 @@ -182,7 +182,8 @@
    13.4  
    13.5        template<typename _ReferenceMap>
    13.6        struct Constraints {
    13.7 -        void constraints() {
    13.8 +        typename enable_if<typename _ReferenceMap::ReferenceMapTag, void>::type
    13.9 +        constraints() {
   13.10            checkConcept<ReadWriteMap<K, T>, _ReferenceMap >();
   13.11            ref = m[key];
   13.12            m[key] = val;
    14.1 --- a/lemon/dfs.h	Fri Sep 25 12:24:16 2009 +0200
    14.2 +++ b/lemon/dfs.h	Sat Sep 26 07:08:10 2009 +0200
    14.3 @@ -47,7 +47,7 @@
    14.4      ///
    14.5      ///The type of the map that stores the predecessor
    14.6      ///arcs of the %DFS paths.
    14.7 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    14.8 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    14.9      typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
   14.10      ///Instantiates a \c PredMap.
   14.11  
   14.12 @@ -62,7 +62,8 @@
   14.13      ///The type of the map that indicates which nodes are processed.
   14.14  
   14.15      ///The type of the map that indicates which nodes are processed.
   14.16 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   14.17 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   14.18 +    ///By default it is a NullMap.
   14.19      typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
   14.20      ///Instantiates a \c ProcessedMap.
   14.21  
   14.22 @@ -81,7 +82,7 @@
   14.23      ///The type of the map that indicates which nodes are reached.
   14.24  
   14.25      ///The type of the map that indicates which nodes are reached.
   14.26 -    ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   14.27 +    ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   14.28      typedef typename Digraph::template NodeMap<bool> ReachedMap;
   14.29      ///Instantiates a \c ReachedMap.
   14.30  
   14.31 @@ -96,7 +97,7 @@
   14.32      ///The type of the map that stores the distances of the nodes.
   14.33  
   14.34      ///The type of the map that stores the distances of the nodes.
   14.35 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   14.36 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   14.37      typedef typename Digraph::template NodeMap<int> DistMap;
   14.38      ///Instantiates a \c DistMap.
   14.39  
   14.40 @@ -224,7 +225,7 @@
   14.41      ///
   14.42      ///\ref named-templ-param "Named parameter" for setting
   14.43      ///\c PredMap type.
   14.44 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   14.45 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   14.46      template <class T>
   14.47      struct SetPredMap : public Dfs<Digraph, SetPredMapTraits<T> > {
   14.48        typedef Dfs<Digraph, SetPredMapTraits<T> > Create;
   14.49 @@ -244,7 +245,7 @@
   14.50      ///
   14.51      ///\ref named-templ-param "Named parameter" for setting
   14.52      ///\c DistMap type.
   14.53 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   14.54 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   14.55      template <class T>
   14.56      struct SetDistMap : public Dfs< Digraph, SetDistMapTraits<T> > {
   14.57        typedef Dfs<Digraph, SetDistMapTraits<T> > Create;
   14.58 @@ -264,7 +265,7 @@
   14.59      ///
   14.60      ///\ref named-templ-param "Named parameter" for setting
   14.61      ///\c ReachedMap type.
   14.62 -    ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   14.63 +    ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   14.64      template <class T>
   14.65      struct SetReachedMap : public Dfs< Digraph, SetReachedMapTraits<T> > {
   14.66        typedef Dfs< Digraph, SetReachedMapTraits<T> > Create;
   14.67 @@ -284,7 +285,7 @@
   14.68      ///
   14.69      ///\ref named-templ-param "Named parameter" for setting
   14.70      ///\c ProcessedMap type.
   14.71 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   14.72 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   14.73      template <class T>
   14.74      struct SetProcessedMap : public Dfs< Digraph, SetProcessedMapTraits<T> > {
   14.75        typedef Dfs< Digraph, SetProcessedMapTraits<T> > Create;
   14.76 @@ -411,8 +412,8 @@
   14.77      ///\name Execution Control
   14.78      ///The simplest way to execute the DFS algorithm is to use one of the
   14.79      ///member functions called \ref run(Node) "run()".\n
   14.80 -    ///If you need more control on the execution, first you have to call
   14.81 -    ///\ref init(), then you can add a source node with \ref addSource()
   14.82 +    ///If you need better control on the execution, you have to call
   14.83 +    ///\ref init() first, then you can add a source node with \ref addSource()
   14.84      ///and perform the actual computation with \ref start().
   14.85      ///This procedure can be repeated if there are nodes that have not
   14.86      ///been reached.
   14.87 @@ -669,9 +670,9 @@
   14.88  
   14.89      ///@{
   14.90  
   14.91 -    ///The DFS path to a node.
   14.92 +    ///The DFS path to the given node.
   14.93  
   14.94 -    ///Returns the DFS path to a node.
   14.95 +    ///Returns the DFS path to the given node from the root(s).
   14.96      ///
   14.97      ///\warning \c t should be reached from the root(s).
   14.98      ///
   14.99 @@ -679,9 +680,9 @@
  14.100      ///must be called before using this function.
  14.101      Path path(Node t) const { return Path(*G, *_pred, t); }
  14.102  
  14.103 -    ///The distance of a node from the root(s).
  14.104 +    ///The distance of the given node from the root(s).
  14.105  
  14.106 -    ///Returns the distance of a node from the root(s).
  14.107 +    ///Returns the distance of the given node from the root(s).
  14.108      ///
  14.109      ///\warning If node \c v is not reached from the root(s), then
  14.110      ///the return value of this function is undefined.
  14.111 @@ -690,7 +691,7 @@
  14.112      ///must be called before using this function.
  14.113      int dist(Node v) const { return (*_dist)[v]; }
  14.114  
  14.115 -    ///Returns the 'previous arc' of the %DFS tree for a node.
  14.116 +    ///Returns the 'previous arc' of the %DFS tree for the given node.
  14.117  
  14.118      ///This function returns the 'previous arc' of the %DFS tree for the
  14.119      ///node \c v, i.e. it returns the last arc of a %DFS path from a
  14.120 @@ -698,21 +699,21 @@
  14.121      ///root(s) or if \c v is a root.
  14.122      ///
  14.123      ///The %DFS tree used here is equal to the %DFS tree used in
  14.124 -    ///\ref predNode().
  14.125 +    ///\ref predNode() and \ref predMap().
  14.126      ///
  14.127      ///\pre Either \ref run(Node) "run()" or \ref init()
  14.128      ///must be called before using this function.
  14.129      Arc predArc(Node v) const { return (*_pred)[v];}
  14.130  
  14.131 -    ///Returns the 'previous node' of the %DFS tree.
  14.132 +    ///Returns the 'previous node' of the %DFS tree for the given node.
  14.133  
  14.134      ///This function returns the 'previous node' of the %DFS
  14.135      ///tree for the node \c v, i.e. it returns the last but one node
  14.136 -    ///from a %DFS path from a root to \c v. It is \c INVALID
  14.137 +    ///of a %DFS path from a root to \c v. It is \c INVALID
  14.138      ///if \c v is not reached from the root(s) or if \c v is a root.
  14.139      ///
  14.140      ///The %DFS tree used here is equal to the %DFS tree used in
  14.141 -    ///\ref predArc().
  14.142 +    ///\ref predArc() and \ref predMap().
  14.143      ///
  14.144      ///\pre Either \ref run(Node) "run()" or \ref init()
  14.145      ///must be called before using this function.
  14.146 @@ -733,13 +734,13 @@
  14.147      ///predecessor arcs.
  14.148      ///
  14.149      ///Returns a const reference to the node map that stores the predecessor
  14.150 -    ///arcs, which form the DFS tree.
  14.151 +    ///arcs, which form the DFS tree (forest).
  14.152      ///
  14.153      ///\pre Either \ref run(Node) "run()" or \ref init()
  14.154      ///must be called before using this function.
  14.155      const PredMap &predMap() const { return *_pred;}
  14.156  
  14.157 -    ///Checks if a node is reached from the root(s).
  14.158 +    ///Checks if the given node. node is reached from the root(s).
  14.159  
  14.160      ///Returns \c true if \c v is reached from the root(s).
  14.161      ///
  14.162 @@ -765,7 +766,7 @@
  14.163      ///
  14.164      ///The type of the map that stores the predecessor
  14.165      ///arcs of the %DFS paths.
  14.166 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
  14.167 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  14.168      typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
  14.169      ///Instantiates a PredMap.
  14.170  
  14.171 @@ -780,7 +781,7 @@
  14.172      ///The type of the map that indicates which nodes are processed.
  14.173  
  14.174      ///The type of the map that indicates which nodes are processed.
  14.175 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
  14.176 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  14.177      ///By default it is a NullMap.
  14.178      typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
  14.179      ///Instantiates a ProcessedMap.
  14.180 @@ -800,7 +801,7 @@
  14.181      ///The type of the map that indicates which nodes are reached.
  14.182  
  14.183      ///The type of the map that indicates which nodes are reached.
  14.184 -    ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
  14.185 +    ///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
  14.186      typedef typename Digraph::template NodeMap<bool> ReachedMap;
  14.187      ///Instantiates a ReachedMap.
  14.188  
  14.189 @@ -815,7 +816,7 @@
  14.190      ///The type of the map that stores the distances of the nodes.
  14.191  
  14.192      ///The type of the map that stores the distances of the nodes.
  14.193 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
  14.194 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  14.195      typedef typename Digraph::template NodeMap<int> DistMap;
  14.196      ///Instantiates a DistMap.
  14.197  
  14.198 @@ -830,18 +831,14 @@
  14.199      ///The type of the DFS paths.
  14.200  
  14.201      ///The type of the DFS paths.
  14.202 -    ///It must meet the \ref concepts::Path "Path" concept.
  14.203 +    ///It must conform to the \ref concepts::Path "Path" concept.
  14.204      typedef lemon::Path<Digraph> Path;
  14.205    };
  14.206  
  14.207    /// Default traits class used by DfsWizard
  14.208  
  14.209 -  /// To make it easier to use Dfs algorithm
  14.210 -  /// we have created a wizard class.
  14.211 -  /// This \ref DfsWizard class needs default traits,
  14.212 -  /// as well as the \ref Dfs class.
  14.213 -  /// The \ref DfsWizardBase is a class to be the default traits of the
  14.214 -  /// \ref DfsWizard class.
  14.215 +  /// Default traits class used by DfsWizard.
  14.216 +  /// \tparam GR The type of the digraph.
  14.217    template<class GR>
  14.218    class DfsWizardBase : public DfsWizardDefaultTraits<GR>
  14.219    {
  14.220 @@ -869,7 +866,7 @@
  14.221      public:
  14.222      /// Constructor.
  14.223  
  14.224 -    /// This constructor does not require parameters, therefore it initiates
  14.225 +    /// This constructor does not require parameters, it initiates
  14.226      /// all of the attributes to \c 0.
  14.227      DfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
  14.228                        _dist(0), _path(0), _di(0) {}
  14.229 @@ -899,7 +896,6 @@
  14.230    {
  14.231      typedef TR Base;
  14.232  
  14.233 -    ///The type of the digraph the algorithm runs on.
  14.234      typedef typename TR::Digraph Digraph;
  14.235  
  14.236      typedef typename Digraph::Node Node;
  14.237 @@ -907,16 +903,10 @@
  14.238      typedef typename Digraph::Arc Arc;
  14.239      typedef typename Digraph::OutArcIt OutArcIt;
  14.240  
  14.241 -    ///\brief The type of the map that stores the predecessor
  14.242 -    ///arcs of the DFS paths.
  14.243      typedef typename TR::PredMap PredMap;
  14.244 -    ///\brief The type of the map that stores the distances of the nodes.
  14.245      typedef typename TR::DistMap DistMap;
  14.246 -    ///\brief The type of the map that indicates which nodes are reached.
  14.247      typedef typename TR::ReachedMap ReachedMap;
  14.248 -    ///\brief The type of the map that indicates which nodes are processed.
  14.249      typedef typename TR::ProcessedMap ProcessedMap;
  14.250 -    ///The type of the DFS paths
  14.251      typedef typename TR::Path Path;
  14.252  
  14.253    public:
  14.254 @@ -999,11 +989,12 @@
  14.255        static PredMap *createPredMap(const Digraph &) { return 0; };
  14.256        SetPredMapBase(const TR &b) : TR(b) {}
  14.257      };
  14.258 -    ///\brief \ref named-func-param "Named parameter"
  14.259 -    ///for setting PredMap object.
  14.260 +
  14.261 +    ///\brief \ref named-templ-param "Named parameter" for setting
  14.262 +    ///the predecessor map.
  14.263      ///
  14.264 -    ///\ref named-func-param "Named parameter"
  14.265 -    ///for setting PredMap object.
  14.266 +    ///\ref named-templ-param "Named parameter" function for setting
  14.267 +    ///the map that stores the predecessor arcs of the nodes.
  14.268      template<class T>
  14.269      DfsWizard<SetPredMapBase<T> > predMap(const T &t)
  14.270      {
  14.271 @@ -1017,11 +1008,12 @@
  14.272        static ReachedMap *createReachedMap(const Digraph &) { return 0; };
  14.273        SetReachedMapBase(const TR &b) : TR(b) {}
  14.274      };
  14.275 -    ///\brief \ref named-func-param "Named parameter"
  14.276 -    ///for setting ReachedMap object.
  14.277 +
  14.278 +    ///\brief \ref named-templ-param "Named parameter" for setting
  14.279 +    ///the reached map.
  14.280      ///
  14.281 -    /// \ref named-func-param "Named parameter"
  14.282 -    ///for setting ReachedMap object.
  14.283 +    ///\ref named-templ-param "Named parameter" function for setting
  14.284 +    ///the map that indicates which nodes are reached.
  14.285      template<class T>
  14.286      DfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
  14.287      {
  14.288 @@ -1035,11 +1027,13 @@
  14.289        static DistMap *createDistMap(const Digraph &) { return 0; };
  14.290        SetDistMapBase(const TR &b) : TR(b) {}
  14.291      };
  14.292 -    ///\brief \ref named-func-param "Named parameter"
  14.293 -    ///for setting DistMap object.
  14.294 +
  14.295 +    ///\brief \ref named-templ-param "Named parameter" for setting
  14.296 +    ///the distance map.
  14.297      ///
  14.298 -    /// \ref named-func-param "Named parameter"
  14.299 -    ///for setting DistMap object.
  14.300 +    ///\ref named-templ-param "Named parameter" function for setting
  14.301 +    ///the map that stores the distances of the nodes calculated
  14.302 +    ///by the algorithm.
  14.303      template<class T>
  14.304      DfsWizard<SetDistMapBase<T> > distMap(const T &t)
  14.305      {
  14.306 @@ -1053,11 +1047,12 @@
  14.307        static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
  14.308        SetProcessedMapBase(const TR &b) : TR(b) {}
  14.309      };
  14.310 -    ///\brief \ref named-func-param "Named parameter"
  14.311 -    ///for setting ProcessedMap object.
  14.312 +
  14.313 +    ///\brief \ref named-func-param "Named parameter" for setting
  14.314 +    ///the processed map.
  14.315      ///
  14.316 -    /// \ref named-func-param "Named parameter"
  14.317 -    ///for setting ProcessedMap object.
  14.318 +    ///\ref named-templ-param "Named parameter" function for setting
  14.319 +    ///the map that indicates which nodes are processed.
  14.320      template<class T>
  14.321      DfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
  14.322      {
  14.323 @@ -1208,7 +1203,7 @@
  14.324      /// \brief The type of the map that indicates which nodes are reached.
  14.325      ///
  14.326      /// The type of the map that indicates which nodes are reached.
  14.327 -    /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
  14.328 +    /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
  14.329      typedef typename Digraph::template NodeMap<bool> ReachedMap;
  14.330  
  14.331      /// \brief Instantiates a ReachedMap.
  14.332 @@ -1369,8 +1364,8 @@
  14.333      /// \name Execution Control
  14.334      /// The simplest way to execute the DFS algorithm is to use one of the
  14.335      /// member functions called \ref run(Node) "run()".\n
  14.336 -    /// If you need more control on the execution, first you have to call
  14.337 -    /// \ref init(), then you can add a source node with \ref addSource()
  14.338 +    /// If you need better control on the execution, you have to call
  14.339 +    /// \ref init() first, then you can add a source node with \ref addSource()
  14.340      /// and perform the actual computation with \ref start().
  14.341      /// This procedure can be repeated if there are nodes that have not
  14.342      /// been reached.
  14.343 @@ -1620,7 +1615,7 @@
  14.344  
  14.345      ///@{
  14.346  
  14.347 -    /// \brief Checks if a node is reached from the root(s).
  14.348 +    /// \brief Checks if the given node is reached from the root(s).
  14.349      ///
  14.350      /// Returns \c true if \c v is reached from the root(s).
  14.351      ///
    15.1 --- a/lemon/dijkstra.h	Fri Sep 25 12:24:16 2009 +0200
    15.2 +++ b/lemon/dijkstra.h	Sat Sep 26 07:08:10 2009 +0200
    15.3 @@ -70,9 +70,9 @@
    15.4      ///The type of the map that stores the arc lengths.
    15.5  
    15.6      ///The type of the map that stores the arc lengths.
    15.7 -    ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
    15.8 +    ///It must conform to the \ref concepts::ReadMap "ReadMap" concept.
    15.9      typedef LEN LengthMap;
   15.10 -    ///The type of the length of the arcs.
   15.11 +    ///The type of the arc lengths.
   15.12      typedef typename LEN::Value Value;
   15.13  
   15.14      /// Operation traits for %Dijkstra algorithm.
   15.15 @@ -116,7 +116,7 @@
   15.16      ///
   15.17      ///The type of the map that stores the predecessor
   15.18      ///arcs of the shortest paths.
   15.19 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   15.20 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   15.21      typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
   15.22      ///Instantiates a \c PredMap.
   15.23  
   15.24 @@ -131,7 +131,7 @@
   15.25      ///The type of the map that indicates which nodes are processed.
   15.26  
   15.27      ///The type of the map that indicates which nodes are processed.
   15.28 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   15.29 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   15.30      ///By default it is a NullMap.
   15.31      typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
   15.32      ///Instantiates a \c ProcessedMap.
   15.33 @@ -151,7 +151,7 @@
   15.34      ///The type of the map that stores the distances of the nodes.
   15.35  
   15.36      ///The type of the map that stores the distances of the nodes.
   15.37 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   15.38 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   15.39      typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap;
   15.40      ///Instantiates a \c DistMap.
   15.41  
   15.42 @@ -169,6 +169,10 @@
   15.43    /// \ingroup shortest_path
   15.44    ///This class provides an efficient implementation of the %Dijkstra algorithm.
   15.45    ///
   15.46 +  ///The %Dijkstra algorithm solves the single-source shortest path problem
   15.47 +  ///when all arc lengths are non-negative. If there are negative lengths,
   15.48 +  ///the BellmanFord algorithm should be used instead.
   15.49 +  ///
   15.50    ///The arc lengths are passed to the algorithm using a
   15.51    ///\ref concepts::ReadMap "ReadMap",
   15.52    ///so it is easy to change it to any kind of length.
   15.53 @@ -201,7 +205,7 @@
   15.54      ///The type of the digraph the algorithm runs on.
   15.55      typedef typename TR::Digraph Digraph;
   15.56  
   15.57 -    ///The type of the length of the arcs.
   15.58 +    ///The type of the arc lengths.
   15.59      typedef typename TR::LengthMap::Value Value;
   15.60      ///The type of the map that stores the arc lengths.
   15.61      typedef typename TR::LengthMap LengthMap;
   15.62 @@ -304,7 +308,7 @@
   15.63      ///
   15.64      ///\ref named-templ-param "Named parameter" for setting
   15.65      ///\c PredMap type.
   15.66 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   15.67 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   15.68      template <class T>
   15.69      struct SetPredMap
   15.70        : public Dijkstra< Digraph, LengthMap, SetPredMapTraits<T> > {
   15.71 @@ -325,7 +329,7 @@
   15.72      ///
   15.73      ///\ref named-templ-param "Named parameter" for setting
   15.74      ///\c DistMap type.
   15.75 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   15.76 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   15.77      template <class T>
   15.78      struct SetDistMap
   15.79        : public Dijkstra< Digraph, LengthMap, SetDistMapTraits<T> > {
   15.80 @@ -346,7 +350,7 @@
   15.81      ///
   15.82      ///\ref named-templ-param "Named parameter" for setting
   15.83      ///\c ProcessedMap type.
   15.84 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   15.85 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   15.86      template <class T>
   15.87      struct SetProcessedMap
   15.88        : public Dijkstra< Digraph, LengthMap, SetProcessedMapTraits<T> > {
   15.89 @@ -443,6 +447,7 @@
   15.90      ///
   15.91      ///\ref named-templ-param "Named parameter" for setting
   15.92      ///\c OperationTraits type.
   15.93 +    /// For more information see \ref DijkstraDefaultOperationTraits.
   15.94      template <class T>
   15.95      struct SetOperationTraits
   15.96        : public Dijkstra<Digraph, LengthMap, SetOperationTraitsTraits<T> > {
   15.97 @@ -584,8 +589,8 @@
   15.98      ///\name Execution Control
   15.99      ///The simplest way to execute the %Dijkstra algorithm is to use
  15.100      ///one of the member functions called \ref run(Node) "run()".\n
  15.101 -    ///If you need more control on the execution, first you have to call
  15.102 -    ///\ref init(), then you can add several source nodes with
  15.103 +    ///If you need better control on the execution, you have to call
  15.104 +    ///\ref init() first, then you can add several source nodes with
  15.105      ///\ref addSource(). Finally the actual path computation can be
  15.106      ///performed with one of the \ref start() functions.
  15.107  
  15.108 @@ -801,14 +806,14 @@
  15.109      ///\name Query Functions
  15.110      ///The results of the %Dijkstra algorithm can be obtained using these
  15.111      ///functions.\n
  15.112 -    ///Either \ref run(Node) "run()" or \ref start() should be called
  15.113 +    ///Either \ref run(Node) "run()" or \ref init() should be called
  15.114      ///before using them.
  15.115  
  15.116      ///@{
  15.117  
  15.118 -    ///The shortest path to a node.
  15.119 +    ///The shortest path to the given node.
  15.120  
  15.121 -    ///Returns the shortest path to a node.
  15.122 +    ///Returns the shortest path to the given node from the root(s).
  15.123      ///
  15.124      ///\warning \c t should be reached from the root(s).
  15.125      ///
  15.126 @@ -816,9 +821,9 @@
  15.127      ///must be called before using this function.
  15.128      Path path(Node t) const { return Path(*G, *_pred, t); }
  15.129  
  15.130 -    ///The distance of a node from the root(s).
  15.131 +    ///The distance of the given node from the root(s).
  15.132  
  15.133 -    ///Returns the distance of a node from the root(s).
  15.134 +    ///Returns the distance of the given node from the root(s).
  15.135      ///
  15.136      ///\warning If node \c v is not reached from the root(s), then
  15.137      ///the return value of this function is undefined.
  15.138 @@ -827,29 +832,31 @@
  15.139      ///must be called before using this function.
  15.140      Value dist(Node v) const { return (*_dist)[v]; }
  15.141  
  15.142 -    ///Returns the 'previous arc' of the shortest path tree for a node.
  15.143 -
  15.144 +    ///\brief Returns the 'previous arc' of the shortest path tree for
  15.145 +    ///the given node.
  15.146 +    ///
  15.147      ///This function returns the 'previous arc' of the shortest path
  15.148      ///tree for the node \c v, i.e. it returns the last arc of a
  15.149      ///shortest path from a root to \c v. It is \c INVALID if \c v
  15.150      ///is not reached from the root(s) or if \c v is a root.
  15.151      ///
  15.152      ///The shortest path tree used here is equal to the shortest path
  15.153 -    ///tree used in \ref predNode().
  15.154 +    ///tree used in \ref predNode() and \ref predMap().
  15.155      ///
  15.156      ///\pre Either \ref run(Node) "run()" or \ref init()
  15.157      ///must be called before using this function.
  15.158      Arc predArc(Node v) const { return (*_pred)[v]; }
  15.159  
  15.160 -    ///Returns the 'previous node' of the shortest path tree for a node.
  15.161 -
  15.162 +    ///\brief Returns the 'previous node' of the shortest path tree for
  15.163 +    ///the given node.
  15.164 +    ///
  15.165      ///This function returns the 'previous node' of the shortest path
  15.166      ///tree for the node \c v, i.e. it returns the last but one node
  15.167 -    ///from a shortest path from a root to \c v. It is \c INVALID
  15.168 +    ///of a shortest path from a root to \c v. It is \c INVALID
  15.169      ///if \c v is not reached from the root(s) or if \c v is a root.
  15.170      ///
  15.171      ///The shortest path tree used here is equal to the shortest path
  15.172 -    ///tree used in \ref predArc().
  15.173 +    ///tree used in \ref predArc() and \ref predMap().
  15.174      ///
  15.175      ///\pre Either \ref run(Node) "run()" or \ref init()
  15.176      ///must be called before using this function.
  15.177 @@ -870,13 +877,13 @@
  15.178      ///predecessor arcs.
  15.179      ///
  15.180      ///Returns a const reference to the node map that stores the predecessor
  15.181 -    ///arcs, which form the shortest path tree.
  15.182 +    ///arcs, which form the shortest path tree (forest).
  15.183      ///
  15.184      ///\pre Either \ref run(Node) "run()" or \ref init()
  15.185      ///must be called before using this function.
  15.186      const PredMap &predMap() const { return *_pred;}
  15.187  
  15.188 -    ///Checks if a node is reached from the root(s).
  15.189 +    ///Checks if the given node is reached from the root(s).
  15.190  
  15.191      ///Returns \c true if \c v is reached from the root(s).
  15.192      ///
  15.193 @@ -895,9 +902,9 @@
  15.194      bool processed(Node v) const { return (*_heap_cross_ref)[v] ==
  15.195                                            Heap::POST_HEAP; }
  15.196  
  15.197 -    ///The current distance of a node from the root(s).
  15.198 +    ///The current distance of the given node from the root(s).
  15.199  
  15.200 -    ///Returns the current distance of a node from the root(s).
  15.201 +    ///Returns the current distance of the given node from the root(s).
  15.202      ///It may be decreased in the following processes.
  15.203      ///
  15.204      ///\pre Either \ref run(Node) "run()" or \ref init()
  15.205 @@ -924,9 +931,9 @@
  15.206      ///The type of the map that stores the arc lengths.
  15.207  
  15.208      ///The type of the map that stores the arc lengths.
  15.209 -    ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
  15.210 +    ///It must conform to the \ref concepts::ReadMap "ReadMap" concept.
  15.211      typedef LEN LengthMap;
  15.212 -    ///The type of the length of the arcs.
  15.213 +    ///The type of the arc lengths.
  15.214      typedef typename LEN::Value Value;
  15.215  
  15.216      /// Operation traits for Dijkstra algorithm.
  15.217 @@ -973,7 +980,7 @@
  15.218      ///
  15.219      ///The type of the map that stores the predecessor
  15.220      ///arcs of the shortest paths.
  15.221 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
  15.222 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  15.223      typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
  15.224      ///Instantiates a PredMap.
  15.225  
  15.226 @@ -988,7 +995,7 @@
  15.227      ///The type of the map that indicates which nodes are processed.
  15.228  
  15.229      ///The type of the map that indicates which nodes are processed.
  15.230 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
  15.231 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  15.232      ///By default it is a NullMap.
  15.233      typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
  15.234      ///Instantiates a ProcessedMap.
  15.235 @@ -1008,7 +1015,7 @@
  15.236      ///The type of the map that stores the distances of the nodes.
  15.237  
  15.238      ///The type of the map that stores the distances of the nodes.
  15.239 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
  15.240 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
  15.241      typedef typename Digraph::template NodeMap<typename LEN::Value> DistMap;
  15.242      ///Instantiates a DistMap.
  15.243  
  15.244 @@ -1023,18 +1030,15 @@
  15.245      ///The type of the shortest paths.
  15.246  
  15.247      ///The type of the shortest paths.
  15.248 -    ///It must meet the \ref concepts::Path "Path" concept.
  15.249 +    ///It must conform to the \ref concepts::Path "Path" concept.
  15.250      typedef lemon::Path<Digraph> Path;
  15.251    };
  15.252  
  15.253    /// Default traits class used by DijkstraWizard
  15.254  
  15.255 -  /// To make it easier to use Dijkstra algorithm
  15.256 -  /// we have created a wizard class.
  15.257 -  /// This \ref DijkstraWizard class needs default traits,
  15.258 -  /// as well as the \ref Dijkstra class.
  15.259 -  /// The \ref DijkstraWizardBase is a class to be the default traits of the
  15.260 -  /// \ref DijkstraWizard class.
  15.261 +  /// Default traits class used by DijkstraWizard.
  15.262 +  /// \tparam GR The type of the digraph.
  15.263 +  /// \tparam LEN The type of the length map.
  15.264    template<typename GR, typename LEN>
  15.265    class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LEN>
  15.266    {
  15.267 @@ -1093,7 +1097,6 @@
  15.268    {
  15.269      typedef TR Base;
  15.270  
  15.271 -    ///The type of the digraph the algorithm runs on.
  15.272      typedef typename TR::Digraph Digraph;
  15.273  
  15.274      typedef typename Digraph::Node Node;
  15.275 @@ -1101,20 +1104,12 @@
  15.276      typedef typename Digraph::Arc Arc;
  15.277      typedef typename Digraph::OutArcIt OutArcIt;
  15.278  
  15.279 -    ///The type of the map that stores the arc lengths.
  15.280      typedef typename TR::LengthMap LengthMap;
  15.281 -    ///The type of the length of the arcs.
  15.282      typedef typename LengthMap::Value Value;
  15.283 -    ///\brief The type of the map that stores the predecessor
  15.284 -    ///arcs of the shortest paths.
  15.285      typedef typename TR::PredMap PredMap;
  15.286 -    ///The type of the map that stores the distances of the nodes.
  15.287      typedef typename TR::DistMap DistMap;
  15.288 -    ///The type of the map that indicates which nodes are processed.
  15.289      typedef typename TR::ProcessedMap ProcessedMap;
  15.290 -    ///The type of the shortest paths
  15.291      typedef typename TR::Path Path;
  15.292 -    ///The heap type used by the dijkstra algorithm.
  15.293      typedef typename TR::Heap Heap;
  15.294  
  15.295    public:
  15.296 @@ -1186,11 +1181,12 @@
  15.297        static PredMap *createPredMap(const Digraph &) { return 0; };
  15.298        SetPredMapBase(const TR &b) : TR(b) {}
  15.299      };
  15.300 -    ///\brief \ref named-func-param "Named parameter"
  15.301 -    ///for setting PredMap object.
  15.302 +
  15.303 +    ///\brief \ref named-templ-param "Named parameter" for setting
  15.304 +    ///the predecessor map.
  15.305      ///
  15.306 -    ///\ref named-func-param "Named parameter"
  15.307 -    ///for setting PredMap object.
  15.308 +    ///\ref named-templ-param "Named parameter" function for setting
  15.309 +    ///the map that stores the predecessor arcs of the nodes.
  15.310      template<class T>
  15.311      DijkstraWizard<SetPredMapBase<T> > predMap(const T &t)
  15.312      {
  15.313 @@ -1204,11 +1200,13 @@
  15.314        static DistMap *createDistMap(const Digraph &) { return 0; };
  15.315        SetDistMapBase(const TR &b) : TR(b) {}
  15.316      };
  15.317 -    ///\brief \ref named-func-param "Named parameter"
  15.318 -    ///for setting DistMap object.
  15.319 +
  15.320 +    ///\brief \ref named-templ-param "Named parameter" for setting
  15.321 +    ///the distance map.
  15.322      ///
  15.323 -    ///\ref named-func-param "Named parameter"
  15.324 -    ///for setting DistMap object.
  15.325 +    ///\ref named-templ-param "Named parameter" function for setting
  15.326 +    ///the map that stores the distances of the nodes calculated
  15.327 +    ///by the algorithm.
  15.328      template<class T>
  15.329      DijkstraWizard<SetDistMapBase<T> > distMap(const T &t)
  15.330      {
  15.331 @@ -1222,11 +1220,12 @@
  15.332        static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
  15.333        SetProcessedMapBase(const TR &b) : TR(b) {}
  15.334      };
  15.335 -    ///\brief \ref named-func-param "Named parameter"
  15.336 -    ///for setting ProcessedMap object.
  15.337 +
  15.338 +    ///\brief \ref named-func-param "Named parameter" for setting
  15.339 +    ///the processed map.
  15.340      ///
  15.341 -    /// \ref named-func-param "Named parameter"
  15.342 -    ///for setting ProcessedMap object.
  15.343 +    ///\ref named-templ-param "Named parameter" function for setting
  15.344 +    ///the map that indicates which nodes are processed.
  15.345      template<class T>
  15.346      DijkstraWizard<SetProcessedMapBase<T> > processedMap(const T &t)
  15.347      {
  15.348 @@ -1239,6 +1238,7 @@
  15.349        typedef T Path;
  15.350        SetPathBase(const TR &b) : TR(b) {}
  15.351      };
  15.352 +
  15.353      ///\brief \ref named-func-param "Named parameter"
  15.354      ///for getting the shortest path to the target node.
  15.355      ///
    16.1 --- a/lemon/dim2.h	Fri Sep 25 12:24:16 2009 +0200
    16.2 +++ b/lemon/dim2.h	Sat Sep 26 07:08:10 2009 +0200
    16.3 @@ -21,16 +21,9 @@
    16.4  
    16.5  #include <iostream>
    16.6  
    16.7 -///\ingroup misc
    16.8 +///\ingroup geomdat
    16.9  ///\file
   16.10  ///\brief A simple two dimensional vector and a bounding box implementation
   16.11 -///
   16.12 -/// The class \ref lemon::dim2::Point "dim2::Point" implements
   16.13 -/// a two dimensional vector with the usual operations.
   16.14 -///
   16.15 -/// The class \ref lemon::dim2::Box "dim2::Box" can be used to determine
   16.16 -/// the rectangular bounding box of a set of
   16.17 -/// \ref lemon::dim2::Point "dim2::Point"'s.
   16.18  
   16.19  namespace lemon {
   16.20  
   16.21 @@ -40,7 +33,7 @@
   16.22    ///tools for handling two dimensional coordinates
   16.23    namespace dim2 {
   16.24  
   16.25 -  /// \addtogroup misc
   16.26 +  /// \addtogroup geomdat
   16.27    /// @{
   16.28  
   16.29    /// Two dimensional vector (plain vector)
    17.1 --- a/lemon/fib_heap.h	Fri Sep 25 12:24:16 2009 +0200
    17.2 +++ b/lemon/fib_heap.h	Sat Sep 26 07:08:10 2009 +0200
    17.3 @@ -20,53 +20,49 @@
    17.4  #define LEMON_FIB_HEAP_H
    17.5  
    17.6  ///\file
    17.7 -///\ingroup auxdat
    17.8 -///\brief Fibonacci Heap implementation.
    17.9 +///\ingroup heaps
   17.10 +///\brief Fibonacci heap implementation.
   17.11  
   17.12  #include <vector>
   17.13 +#include <utility>
   17.14  #include <functional>
   17.15  #include <lemon/math.h>
   17.16  
   17.17  namespace lemon {
   17.18  
   17.19 -  /// \ingroup auxdat
   17.20 +  /// \ingroup heaps
   17.21    ///
   17.22 -  ///\brief Fibonacci Heap.
   17.23 +  /// \brief Fibonacci heap data structure.
   17.24    ///
   17.25 -  ///This class implements the \e Fibonacci \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. \c CMP specifies the ordering of the priorities. In a heap
   17.29 -  ///one can change the priority of an item, add or erase an item, etc.
   17.30 +  /// This class implements the \e Fibonacci \e heap data structure.
   17.31 +  /// It fully conforms to the \ref concepts::Heap "heap concept".
   17.32    ///
   17.33 -  ///The methods \ref increase and \ref erase are not efficient in a Fibonacci
   17.34 -  ///heap. In case of many calls to these operations, it is better to use a
   17.35 -  ///\ref BinHeap "binary heap".
   17.36 +  /// The methods \ref increase() and \ref erase() are not efficient in a
   17.37 +  /// Fibonacci heap. In case of many calls of these operations, it is
   17.38 +  /// better to use other heap structure, e.g. \ref BinHeap "binary heap".
   17.39    ///
   17.40 -  ///\param PRIO Type of the priority of the items.
   17.41 -  ///\param IM A read and writable Item int map, used internally
   17.42 -  ///to handle the cross references.
   17.43 -  ///\param CMP A class for the ordering of the priorities. The
   17.44 -  ///default is \c std::less<PRIO>.
   17.45 -  ///
   17.46 -  ///\sa BinHeap
   17.47 -  ///\sa Dijkstra
   17.48 +  /// \tparam PR Type of the priorities of the items.
   17.49 +  /// \tparam IM A read-writable item map with \c int values, used
   17.50 +  /// internally to handle the cross references.
   17.51 +  /// \tparam CMP A functor class for comparing the priorities.
   17.52 +  /// The default is \c std::less<PR>.
   17.53  #ifdef DOXYGEN
   17.54 -  template <typename PRIO, typename IM, typename CMP>
   17.55 +  template <typename PR, typename IM, typename CMP>
   17.56  #else
   17.57 -  template <typename PRIO, typename IM, typename CMP = std::less<PRIO> >
   17.58 +  template <typename PR, typename IM, typename CMP = std::less<PR> >
   17.59  #endif
   17.60    class FibHeap {
   17.61    public:
   17.62 -    ///\e
   17.63 +
   17.64 +    /// Type of the item-int map.
   17.65      typedef IM ItemIntMap;
   17.66 -    ///\e
   17.67 -    typedef PRIO Prio;
   17.68 -    ///\e
   17.69 +    /// Type of the priorities.
   17.70 +    typedef PR Prio;
   17.71 +    /// Type of the items stored in the heap.
   17.72      typedef typename ItemIntMap::Key Item;
   17.73 -    ///\e
   17.74 +    /// Type of the item-priority pairs.
   17.75      typedef std::pair<Item,Prio> Pair;
   17.76 -    ///\e
   17.77 +    /// Functor type for comparing the priorities.
   17.78      typedef CMP Compare;
   17.79  
   17.80    private:
   17.81 @@ -80,10 +76,10 @@
   17.82  
   17.83    public:
   17.84  
   17.85 -    /// \brief Type to represent the items states.
   17.86 +    /// \brief Type to represent the states of the items.
   17.87      ///
   17.88 -    /// Each Item element have a state associated to it. It may be "in heap",
   17.89 -    /// "pre heap" or "post heap". The latter two are indifferent from the
   17.90 +    /// Each item has a state associated to it. It can be "in heap",
   17.91 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
   17.92      /// heap's point of view, but may be useful to the user.
   17.93      ///
   17.94      /// The item-int map must be initialized in such way that it assigns
   17.95 @@ -94,60 +90,54 @@
   17.96        POST_HEAP = -2  ///< = -2.
   17.97      };
   17.98  
   17.99 -    /// \brief The constructor
  17.100 +    /// \brief Constructor.
  17.101      ///
  17.102 -    /// \c map should be given to the constructor, since it is
  17.103 -    ///   used internally to handle the cross references.
  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 FibHeap(ItemIntMap &map)
  17.109        : _minimum(0), _iim(map), _num() {}
  17.110  
  17.111 -    /// \brief The constructor
  17.112 +    /// \brief Constructor.
  17.113      ///
  17.114 -    /// \c map should be given to the constructor, since it is used
  17.115 -    /// internally to handle the cross references. \c comp is an
  17.116 -    /// object for ordering of the priorities.
  17.117 +    /// Constructor.
  17.118 +    /// \param map A map that assigns \c int values to the items.
  17.119 +    /// It is used internally to handle the cross references.
  17.120 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  17.121 +    /// \param comp The function object used for comparing the priorities.
  17.122      FibHeap(ItemIntMap &map, const Compare &comp)
  17.123        : _minimum(0), _iim(map), _comp(comp), _num() {}
  17.124  
  17.125      /// \brief The number of items stored in the heap.
  17.126      ///
  17.127 -    /// Returns the number of items stored in the heap.
  17.128 +    /// This function returns the number of items stored in the heap.
  17.129      int size() const { return _num; }
  17.130  
  17.131 -    /// \brief Checks if the heap stores no items.
  17.132 +    /// \brief Check if the heap is empty.
  17.133      ///
  17.134 -    ///   Returns \c true if and only if the heap stores no items.
  17.135 +    /// This function returns \c true if the heap is empty.
  17.136      bool empty() const { return _num==0; }
  17.137  
  17.138 -    /// \brief Make empty this heap.
  17.139 +    /// \brief Make the heap empty.
  17.140      ///
  17.141 -    /// Make empty this heap. It does not change the cross reference
  17.142 -    /// map.  If you want to reuse a heap what is not surely empty you
  17.143 -    /// should first clear the heap and after that you should set the
  17.144 -    /// cross reference map for each item to \c PRE_HEAP.
  17.145 +    /// This functon makes the heap empty.
  17.146 +    /// It does not change the cross reference map. If you want to reuse
  17.147 +    /// a heap that is not surely empty, you should first clear it and
  17.148 +    /// then you should set the cross reference map to \c PRE_HEAP
  17.149 +    /// for each item.
  17.150      void clear() {
  17.151        _data.clear(); _minimum = 0; _num = 0;
  17.152      }
  17.153  
  17.154 -    /// \brief \c item gets to the heap with priority \c value independently
  17.155 -    /// if \c item was already there.
  17.156 +    /// \brief Insert an item into the heap with the given priority.
  17.157      ///
  17.158 -    /// This method calls \ref push(\c item, \c value) if \c item is not
  17.159 -    /// stored in the heap and it calls \ref decrease(\c item, \c value) or
  17.160 -    /// \ref increase(\c item, \c value) otherwise.
  17.161 -    void set (const Item& item, const Prio& value) {
  17.162 -      int i=_iim[item];
  17.163 -      if ( i >= 0 && _data[i].in ) {
  17.164 -        if ( _comp(value, _data[i].prio) ) decrease(item, value);
  17.165 -        if ( _comp(_data[i].prio, value) ) increase(item, value);
  17.166 -      } else push(item, value);
  17.167 -    }
  17.168 -
  17.169 -    /// \brief Adds \c item to the heap with priority \c value.
  17.170 -    ///
  17.171 -    /// Adds \c item to the heap with priority \c value.
  17.172 -    /// \pre \c item must not be stored in the heap.
  17.173 -    void push (const Item& item, const Prio& value) {
  17.174 +    /// This function inserts the given item into the heap with the
  17.175 +    /// given priority.
  17.176 +    /// \param item The item to insert.
  17.177 +    /// \param prio The priority of the item.
  17.178 +    /// \pre \e item must not be stored in the heap.
  17.179 +    void push (const Item& item, const Prio& prio) {
  17.180        int i=_iim[item];
  17.181        if ( i < 0 ) {
  17.182          int s=_data.size();
  17.183 @@ -168,47 +158,37 @@
  17.184          _data[i].right_neighbor=_data[_minimum].right_neighbor;
  17.185          _data[_minimum].right_neighbor=i;
  17.186          _data[i].left_neighbor=_minimum;
  17.187 -        if ( _comp( value, _data[_minimum].prio) ) _minimum=i;
  17.188 +        if ( _comp( prio, _data[_minimum].prio) ) _minimum=i;
  17.189        } else {
  17.190          _data[i].right_neighbor=_data[i].left_neighbor=i;
  17.191          _minimum=i;
  17.192        }
  17.193 -      _data[i].prio=value;
  17.194 +      _data[i].prio=prio;
  17.195        ++_num;
  17.196      }
  17.197  
  17.198 -    /// \brief Returns the item with minimum priority relative to \c Compare.
  17.199 +    /// \brief Return the item having minimum priority.
  17.200      ///
  17.201 -    /// This method returns the item with minimum priority relative to \c
  17.202 -    /// Compare.
  17.203 -    /// \pre The heap must be nonempty.
  17.204 +    /// This function returns the item having minimum priority.
  17.205 +    /// \pre The heap must be non-empty.
  17.206      Item top() const { return _data[_minimum].name; }
  17.207  
  17.208 -    /// \brief Returns the minimum priority relative to \c Compare.
  17.209 +    /// \brief The minimum priority.
  17.210      ///
  17.211 -    /// It returns the minimum priority relative to \c Compare.
  17.212 -    /// \pre The heap must be nonempty.
  17.213 -    const Prio& prio() const { return _data[_minimum].prio; }
  17.214 +    /// This function returns the minimum priority.
  17.215 +    /// \pre The heap must be non-empty.
  17.216 +    Prio prio() const { return _data[_minimum].prio; }
  17.217  
  17.218 -    /// \brief Returns the priority of \c item.
  17.219 +    /// \brief Remove the item having minimum priority.
  17.220      ///
  17.221 -    /// It returns the priority of \c item.
  17.222 -    /// \pre \c item must be in the heap.
  17.223 -    const Prio& operator[](const Item& item) const {
  17.224 -      return _data[_iim[item]].prio;
  17.225 -    }
  17.226 -
  17.227 -    /// \brief Deletes the item with minimum priority relative to \c Compare.
  17.228 -    ///
  17.229 -    /// This method deletes the item with minimum priority relative to \c
  17.230 -    /// Compare from the heap.
  17.231 +    /// This function removes the item having minimum priority.
  17.232      /// \pre The heap must be non-empty.
  17.233      void pop() {
  17.234        /*The first case is that there are only one root.*/
  17.235        if ( _data[_minimum].left_neighbor==_minimum ) {
  17.236          _data[_minimum].in=false;
  17.237          if ( _data[_minimum].degree!=0 ) {
  17.238 -          makeroot(_data[_minimum].child);
  17.239 +          makeRoot(_data[_minimum].child);
  17.240            _minimum=_data[_minimum].child;
  17.241            balance();
  17.242          }
  17.243 @@ -221,7 +201,7 @@
  17.244            int child=_data[_minimum].child;
  17.245            int last_child=_data[child].left_neighbor;
  17.246  
  17.247 -          makeroot(child);
  17.248 +          makeRoot(child);
  17.249  
  17.250            _data[left].right_neighbor=child;
  17.251            _data[child].left_neighbor=left;
  17.252 @@ -234,10 +214,12 @@
  17.253        --_num;
  17.254      }
  17.255  
  17.256 -    /// \brief Deletes \c item from the heap.
  17.257 +    /// \brief Remove the given item from the heap.
  17.258      ///
  17.259 -    /// This method deletes \c item from the heap, if \c item was already
  17.260 -    /// stored in the heap. It is quite inefficient in Fibonacci heaps.
  17.261 +    /// This function removes the given item from the heap if it is
  17.262 +    /// already stored.
  17.263 +    /// \param item The item to delete.
  17.264 +    /// \pre \e item must be in the heap.
  17.265      void erase (const Item& item) {
  17.266        int i=_iim[item];
  17.267  
  17.268 @@ -252,43 +234,68 @@
  17.269        }
  17.270      }
  17.271  
  17.272 -    /// \brief Decreases the priority of \c item to \c value.
  17.273 +    /// \brief The priority of the given item.
  17.274      ///
  17.275 -    /// This method decreases the priority of \c item to \c value.
  17.276 -    /// \pre \c item must be stored in the heap with priority at least \c
  17.277 -    ///   value relative to \c Compare.
  17.278 -    void decrease (Item item, const Prio& value) {
  17.279 +    /// This function returns the priority of the given item.
  17.280 +    /// \param item The item.
  17.281 +    /// \pre \e item must be in the heap.
  17.282 +    Prio operator[](const Item& item) const {
  17.283 +      return _data[_iim[item]].prio;
  17.284 +    }
  17.285 +
  17.286 +    /// \brief Set the priority of an item or insert it, if it is
  17.287 +    /// not stored in the heap.
  17.288 +    ///
  17.289 +    /// This method sets the priority of the given item if it is
  17.290 +    /// already stored in the heap. Otherwise it inserts the given
  17.291 +    /// item into the heap with the given priority.
  17.292 +    /// \param item The item.
  17.293 +    /// \param prio The priority.
  17.294 +    void set (const Item& item, const Prio& prio) {
  17.295        int i=_iim[item];
  17.296 -      _data[i].prio=value;
  17.297 +      if ( i >= 0 && _data[i].in ) {
  17.298 +        if ( _comp(prio, _data[i].prio) ) decrease(item, prio);
  17.299 +        if ( _comp(_data[i].prio, prio) ) increase(item, prio);
  17.300 +      } else push(item, prio);
  17.301 +    }
  17.302 +
  17.303 +    /// \brief Decrease the priority of an item to the given value.
  17.304 +    ///
  17.305 +    /// This function decreases the priority of an item to the given value.
  17.306 +    /// \param item The item.
  17.307 +    /// \param prio The priority.
  17.308 +    /// \pre \e item must be stored in the heap with priority at least \e prio.
  17.309 +    void decrease (const Item& item, const Prio& prio) {
  17.310 +      int i=_iim[item];
  17.311 +      _data[i].prio=prio;
  17.312        int p=_data[i].parent;
  17.313  
  17.314 -      if ( p!=-1 && _comp(value, _data[p].prio) ) {
  17.315 +      if ( p!=-1 && _comp(prio, _data[p].prio) ) {
  17.316          cut(i,p);
  17.317          cascade(p);
  17.318        }
  17.319 -      if ( _comp(value, _data[_minimum].prio) ) _minimum=i;
  17.320 +      if ( _comp(prio, _data[_minimum].prio) ) _minimum=i;
  17.321      }
  17.322  
  17.323 -    /// \brief Increases the priority of \c item to \c value.
  17.324 +    /// \brief Increase the priority of an item to the given value.
  17.325      ///
  17.326 -    /// This method sets the priority of \c item to \c value. Though
  17.327 -    /// there is no precondition on the priority of \c item, this
  17.328 -    /// method should be used only if it is indeed necessary to increase
  17.329 -    /// (relative to \c Compare) the priority of \c item, because this
  17.330 -    /// method is inefficient.
  17.331 -    void increase (Item item, const Prio& value) {
  17.332 +    /// This function increases the priority of an item to the given value.
  17.333 +    /// \param item The item.
  17.334 +    /// \param prio The priority.
  17.335 +    /// \pre \e item must be stored in the heap with priority at most \e prio.
  17.336 +    void increase (const Item& item, const Prio& prio) {
  17.337        erase(item);
  17.338 -      push(item, value);
  17.339 +      push(item, prio);
  17.340      }
  17.341  
  17.342 -
  17.343 -    /// \brief Returns if \c item is in, has already been in, or has never
  17.344 -    /// been in the heap.
  17.345 +    /// \brief Return the state of an item.
  17.346      ///
  17.347 -    /// This method returns PRE_HEAP if \c item has never been in the
  17.348 -    /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
  17.349 -    /// otherwise. In the latter case it is possible that \c item will
  17.350 -    /// get back to the heap again.
  17.351 +    /// This method returns \c PRE_HEAP if the given item has never
  17.352 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  17.353 +    /// and \c POST_HEAP otherwise.
  17.354 +    /// In the latter case it is possible that the item will get back
  17.355 +    /// to the heap again.
  17.356 +    /// \param item The item.
  17.357      State state(const Item &item) const {
  17.358        int i=_iim[item];
  17.359        if( i>=0 ) {
  17.360 @@ -298,11 +305,11 @@
  17.361        return State(i);
  17.362      }
  17.363  
  17.364 -    /// \brief Sets the state of the \c item in the heap.
  17.365 +    /// \brief Set the state of an item in the heap.
  17.366      ///
  17.367 -    /// Sets the state of the \c item in the heap. It can be used to
  17.368 -    /// manually clear the heap when it is important to achive the
  17.369 -    /// better time _complexity.
  17.370 +    /// This function sets the state of the given item in the heap.
  17.371 +    /// It can be used to manually clear the heap when it is important
  17.372 +    /// to achive better time complexity.
  17.373      /// \param i The item.
  17.374      /// \param st The state. It should not be \c IN_HEAP.
  17.375      void state(const Item& i, State st) {
  17.376 @@ -365,7 +372,7 @@
  17.377        } while ( s != m );
  17.378      }
  17.379  
  17.380 -    void makeroot(int c) {
  17.381 +    void makeRoot(int c) {
  17.382        int s=c;
  17.383        do {
  17.384          _data[s].parent=-1;
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/lemon/fourary_heap.h	Sat Sep 26 07:08:10 2009 +0200
    18.3 @@ -0,0 +1,342 @@
    18.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
    18.5 + *
    18.6 + * This file is a part of LEMON, a generic C++ optimization library.
    18.7 + *
    18.8 + * Copyright (C) 2003-2009
    18.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   18.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
   18.11 + *
   18.12 + * Permission to use, modify and distribute this software is granted
   18.13 + * provided that this copyright notice appears in all copies. For
   18.14 + * precise terms see the accompanying LICENSE file.
   18.15 + *
   18.16 + * This software is provided "AS IS" with no warranty of any kind,
   18.17 + * express or implied, and with no claim as to its suitability for any
   18.18 + * purpose.
   18.19 + *
   18.20 + */
   18.21 +
   18.22 +#ifndef LEMON_FOURARY_HEAP_H
   18.23 +#define LEMON_FOURARY_HEAP_H
   18.24 +
   18.25 +///\ingroup heaps
   18.26 +///\file
   18.27 +///\brief Fourary heap implementation.
   18.28 +
   18.29 +#include <vector>
   18.30 +#include <utility>
   18.31 +#include <functional>
   18.32 +
   18.33 +namespace lemon {
   18.34 +
   18.35 +  /// \ingroup heaps
   18.36 +  ///
   18.37 +  ///\brief Fourary heap data structure.
   18.38 +  ///
   18.39 +  /// This class implements the \e fourary \e heap data structure.
   18.40 +  /// It fully conforms to the \ref concepts::Heap "heap concept".
   18.41 +  ///
   18.42 +  /// The fourary heap is a specialization of the \ref KaryHeap "K-ary heap"
   18.43 +  /// for <tt>K=4</tt>. It is similar to the \ref BinHeap "binary heap",
   18.44 +  /// but its nodes have at most four children, instead of two.
   18.45 +  ///
   18.46 +  /// \tparam PR Type of the priorities of the items.
   18.47 +  /// \tparam IM A read-writable item map with \c int values, used
   18.48 +  /// internally to handle the cross references.
   18.49 +  /// \tparam CMP A functor class for comparing the priorities.
   18.50 +  /// The default is \c std::less<PR>.
   18.51 +  ///
   18.52 +  ///\sa BinHeap
   18.53 +  ///\sa KaryHeap
   18.54 +#ifdef DOXYGEN
   18.55 +  template <typename PR, typename IM, typename CMP>
   18.56 +#else
   18.57 +  template <typename PR, typename IM, typename CMP = std::less<PR> >
   18.58 +#endif
   18.59 +  class FouraryHeap {
   18.60 +  public:
   18.61 +    /// Type of the item-int map.
   18.62 +    typedef IM ItemIntMap;
   18.63 +    /// Type of the priorities.
   18.64 +    typedef PR Prio;
   18.65 +    /// Type of the items stored in the heap.
   18.66 +    typedef typename ItemIntMap::Key Item;
   18.67 +    /// Type of the item-priority pairs.
   18.68 +    typedef std::pair<Item,Prio> Pair;
   18.69 +    /// Functor type for comparing the priorities.
   18.70 +    typedef CMP Compare;
   18.71 +
   18.72 +    /// \brief Type to represent the states of the items.
   18.73 +    ///
   18.74 +    /// Each item has a state associated to it. It can be "in heap",
   18.75 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
   18.76 +    /// heap's point of view, but may be useful to the user.
   18.77 +    ///
   18.78 +    /// The item-int map must be initialized in such way that it assigns
   18.79 +    /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
   18.80 +    enum State {
   18.81 +      IN_HEAP = 0,    ///< = 0.
   18.82 +      PRE_HEAP = -1,  ///< = -1.
   18.83 +      POST_HEAP = -2  ///< = -2.
   18.84 +    };
   18.85 +
   18.86 +  private:
   18.87 +    std::vector<Pair> _data;
   18.88 +    Compare _comp;
   18.89 +    ItemIntMap &_iim;
   18.90 +
   18.91 +  public:
   18.92 +    /// \brief Constructor.
   18.93 +    ///
   18.94 +    /// Constructor.
   18.95 +    /// \param map A map that assigns \c int values to the items.
   18.96 +    /// It is used internally to handle the cross references.
   18.97 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
   18.98 +    explicit FouraryHeap(ItemIntMap &map) : _iim(map) {}
   18.99 +
  18.100 +    /// \brief Constructor.
  18.101 +    ///
  18.102 +    /// Constructor.
  18.103 +    /// \param map A map that assigns \c int values to the items.
  18.104 +    /// It is used internally to handle the cross references.
  18.105 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  18.106 +    /// \param comp The function object used for comparing the priorities.
  18.107 +    FouraryHeap(ItemIntMap &map, const Compare &comp)
  18.108 +      : _iim(map), _comp(comp) {}
  18.109 +
  18.110 +    /// \brief The number of items stored in the heap.
  18.111 +    ///
  18.112 +    /// This function returns the number of items stored in the heap.
  18.113 +    int size() const { return _data.size(); }
  18.114 +
  18.115 +    /// \brief Check if the heap is empty.
  18.116 +    ///
  18.117 +    /// This function returns \c true if the heap is empty.
  18.118 +    bool empty() const { return _data.empty(); }
  18.119 +
  18.120 +    /// \brief Make the heap empty.
  18.121 +    ///
  18.122 +    /// This functon makes the heap empty.
  18.123 +    /// It does not change the cross reference map. If you want to reuse
  18.124 +    /// a heap that is not surely empty, you should first clear it and
  18.125 +    /// then you should set the cross reference map to \c PRE_HEAP
  18.126 +    /// for each item.
  18.127 +    void clear() { _data.clear(); }
  18.128 +
  18.129 +  private:
  18.130 +    static int parent(int i) { return (i-1)/4; }
  18.131 +    static int firstChild(int i) { return 4*i+1; }
  18.132 +
  18.133 +    bool less(const Pair &p1, const Pair &p2) const {
  18.134 +      return _comp(p1.second, p2.second);
  18.135 +    }
  18.136 +
  18.137 +    void bubbleUp(int hole, Pair p) {
  18.138 +      int par = parent(hole);
  18.139 +      while( hole>0 && less(p,_data[par]) ) {
  18.140 +        move(_data[par],hole);
  18.141 +        hole = par;
  18.142 +        par = parent(hole);
  18.143 +      }
  18.144 +      move(p, hole);
  18.145 +    }
  18.146 +
  18.147 +    void bubbleDown(int hole, Pair p, int length) {
  18.148 +      if( length>1 ) {
  18.149 +        int child = firstChild(hole);
  18.150 +        while( child+3<length ) {
  18.151 +          int min=child;
  18.152 +          if( less(_data[++child], _data[min]) ) min=child;
  18.153 +          if( less(_data[++child], _data[min]) ) min=child;
  18.154 +          if( less(_data[++child], _data[min]) ) min=child;
  18.155 +          if( !less(_data[min], p) )
  18.156 +            goto ok;
  18.157 +          move(_data[min], hole);
  18.158 +          hole = min;
  18.159 +          child = firstChild(hole);
  18.160 +        }
  18.161 +        if ( child<length ) {
  18.162 +          int min = child;
  18.163 +          if( ++child<length && less(_data[child], _data[min]) ) min=child;
  18.164 +          if( ++child<length && less(_data[child], _data[min]) ) min=child;
  18.165 +          if( less(_data[min], p) ) {
  18.166 +            move(_data[min], hole);
  18.167 +            hole = min;
  18.168 +          }
  18.169 +        }
  18.170 +      }
  18.171 +    ok:
  18.172 +      move(p, hole);
  18.173 +    }
  18.174 +
  18.175 +    void move(const Pair &p, int i) {
  18.176 +      _data[i] = p;
  18.177 +      _iim.set(p.first, i);
  18.178 +    }
  18.179 +
  18.180 +  public:
  18.181 +    /// \brief Insert a pair of item and priority into the heap.
  18.182 +    ///
  18.183 +    /// This function inserts \c p.first to the heap with priority
  18.184 +    /// \c p.second.
  18.185 +    /// \param p The pair to insert.
  18.186 +    /// \pre \c p.first must not be stored in the heap.
  18.187 +    void push(const Pair &p) {
  18.188 +      int n = _data.size();
  18.189 +      _data.resize(n+1);
  18.190 +      bubbleUp(n, p);
  18.191 +    }
  18.192 +
  18.193 +    /// \brief Insert an item into the heap with the given priority.
  18.194 +    ///
  18.195 +    /// This function inserts the given item into the heap with the
  18.196 +    /// given priority.
  18.197 +    /// \param i The item to insert.
  18.198 +    /// \param p The priority of the item.
  18.199 +    /// \pre \e i must not be stored in the heap.
  18.200 +    void push(const Item &i, const Prio &p) { push(Pair(i,p)); }
  18.201 +
  18.202 +    /// \brief Return the item having minimum priority.
  18.203 +    ///
  18.204 +    /// This function returns the item having minimum priority.
  18.205 +    /// \pre The heap must be non-empty.
  18.206 +    Item top() const { return _data[0].first; }
  18.207 +
  18.208 +    /// \brief The minimum priority.
  18.209 +    ///
  18.210 +    /// This function returns the minimum priority.
  18.211 +    /// \pre The heap must be non-empty.
  18.212 +    Prio prio() const { return _data[0].second; }
  18.213 +
  18.214 +    /// \brief Remove the item having minimum priority.
  18.215 +    ///
  18.216 +    /// This function removes the item having minimum priority.
  18.217 +    /// \pre The heap must be non-empty.
  18.218 +    void pop() {
  18.219 +      int n = _data.size()-1;
  18.220 +      _iim.set(_data[0].first, POST_HEAP);
  18.221 +      if (n>0) bubbleDown(0, _data[n], n);
  18.222 +      _data.pop_back();
  18.223 +    }
  18.224 +
  18.225 +    /// \brief Remove the given item from the heap.
  18.226 +    ///
  18.227 +    /// This function removes the given item from the heap if it is
  18.228 +    /// already stored.
  18.229 +    /// \param i The item to delete.
  18.230 +    /// \pre \e i must be in the heap.
  18.231 +    void erase(const Item &i) {
  18.232 +      int h = _iim[i];
  18.233 +      int n = _data.size()-1;
  18.234 +      _iim.set(_data[h].first, POST_HEAP);
  18.235 +      if( h<n ) {
  18.236 +        if( less(_data[parent(h)], _data[n]) )
  18.237 +          bubbleDown(h, _data[n], n);
  18.238 +        else
  18.239 +          bubbleUp(h, _data[n]);
  18.240 +      }
  18.241 +      _data.pop_back();
  18.242 +    }
  18.243 +
  18.244 +    /// \brief The priority of the given item.
  18.245 +    ///
  18.246 +    /// This function returns the priority of the given item.
  18.247 +    /// \param i The item.
  18.248 +    /// \pre \e i must be in the heap.
  18.249 +    Prio operator[](const Item &i) const {
  18.250 +      int idx = _iim[i];
  18.251 +      return _data[idx].second;
  18.252 +    }
  18.253 +
  18.254 +    /// \brief Set the priority of an item or insert it, if it is
  18.255 +    /// not stored in the heap.
  18.256 +    ///
  18.257 +    /// This method sets the priority of the given item if it is
  18.258 +    /// already stored in the heap. Otherwise it inserts the given
  18.259 +    /// item into the heap with the given priority.
  18.260 +    /// \param i The item.
  18.261 +    /// \param p The priority.
  18.262 +    void set(const Item &i, const Prio &p) {
  18.263 +      int idx = _iim[i];
  18.264 +      if( idx < 0 )
  18.265 +        push(i,p);
  18.266 +      else if( _comp(p, _data[idx].second) )
  18.267 +        bubbleUp(idx, Pair(i,p));
  18.268 +      else
  18.269 +        bubbleDown(idx, Pair(i,p), _data.size());
  18.270 +    }
  18.271 +
  18.272 +    /// \brief Decrease the priority of an item to the given value.
  18.273 +    ///
  18.274 +    /// This function decreases the priority of an item to the given value.
  18.275 +    /// \param i The item.
  18.276 +    /// \param p The priority.
  18.277 +    /// \pre \e i must be stored in the heap with priority at least \e p.
  18.278 +    void decrease(const Item &i, const Prio &p) {
  18.279 +      int idx = _iim[i];
  18.280 +      bubbleUp(idx, Pair(i,p));
  18.281 +    }
  18.282 +
  18.283 +    /// \brief Increase the priority of an item to the given value.
  18.284 +    ///
  18.285 +    /// This function increases the priority of an item to the given value.
  18.286 +    /// \param i The item.
  18.287 +    /// \param p The priority.
  18.288 +    /// \pre \e i must be stored in the heap with priority at most \e p.
  18.289 +    void increase(const Item &i, const Prio &p) {
  18.290 +      int idx = _iim[i];
  18.291 +      bubbleDown(idx, Pair(i,p), _data.size());
  18.292 +    }
  18.293 +
  18.294 +    /// \brief Return the state of an item.
  18.295 +    ///
  18.296 +    /// This method returns \c PRE_HEAP if the given item has never
  18.297 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  18.298 +    /// and \c POST_HEAP otherwise.
  18.299 +    /// In the latter case it is possible that the item will get back
  18.300 +    /// to the heap again.
  18.301 +    /// \param i The item.
  18.302 +    State state(const Item &i) const {
  18.303 +      int s = _iim[i];
  18.304 +      if (s>=0) s=0;
  18.305 +      return State(s);
  18.306 +    }
  18.307 +
  18.308 +    /// \brief Set the state of an item in the heap.
  18.309 +    ///
  18.310 +    /// This function sets the state of the given item in the heap.
  18.311 +    /// It can be used to manually clear the heap when it is important
  18.312 +    /// to achive better time complexity.
  18.313 +    /// \param i The item.
  18.314 +    /// \param st The state. It should not be \c IN_HEAP.
  18.315 +    void state(const Item& i, State st) {
  18.316 +      switch (st) {
  18.317 +        case POST_HEAP:
  18.318 +        case PRE_HEAP:
  18.319 +          if (state(i) == IN_HEAP) erase(i);
  18.320 +          _iim[i] = st;
  18.321 +          break;
  18.322 +        case IN_HEAP:
  18.323 +          break;
  18.324 +      }
  18.325 +    }
  18.326 +
  18.327 +    /// \brief Replace an item in the heap.
  18.328 +    ///
  18.329 +    /// This function replaces item \c i with item \c j.
  18.330 +    /// Item \c i must be in the heap, while \c j must be out of the heap.
  18.331 +    /// After calling this method, item \c i will be out of the
  18.332 +    /// heap and \c j will be in the heap with the same prioriority
  18.333 +    /// as item \c i had before.
  18.334 +    void replace(const Item& i, const Item& j) {
  18.335 +      int idx = _iim[i];
  18.336 +      _iim.set(i, _iim[j]);
  18.337 +      _iim.set(j, idx);
  18.338 +      _data[idx].first = j;
  18.339 +    }
  18.340 +
  18.341 +  }; // class FouraryHeap
  18.342 +
  18.343 +} // namespace lemon
  18.344 +
  18.345 +#endif // LEMON_FOURARY_HEAP_H
    19.1 --- a/lemon/gomory_hu.h	Fri Sep 25 12:24:16 2009 +0200
    19.2 +++ b/lemon/gomory_hu.h	Sat Sep 26 07:08:10 2009 +0200
    19.3 @@ -359,10 +359,10 @@
    19.4      /// This example counts the nodes in the minimum cut separating \c s from
    19.5      /// \c t.
    19.6      /// \code
    19.7 -    /// GomoruHu<Graph> gom(g, capacities);
    19.8 +    /// GomoryHu<Graph> gom(g, capacities);
    19.9      /// gom.run();
   19.10      /// int cnt=0;
   19.11 -    /// for(GomoruHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt;
   19.12 +    /// for(GomoryHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt;
   19.13      /// \endcode
   19.14      class MinCutNodeIt
   19.15      {
   19.16 @@ -456,10 +456,10 @@
   19.17      /// This example computes the value of the minimum cut separating \c s from
   19.18      /// \c t.
   19.19      /// \code
   19.20 -    /// GomoruHu<Graph> gom(g, capacities);
   19.21 +    /// GomoryHu<Graph> gom(g, capacities);
   19.22      /// gom.run();
   19.23      /// int value=0;
   19.24 -    /// for(GomoruHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e)
   19.25 +    /// for(GomoryHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e)
   19.26      ///   value+=capacities[e];
   19.27      /// \endcode
   19.28      /// The result will be the same as the value returned by
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/lemon/kary_heap.h	Sat Sep 26 07:08:10 2009 +0200
    20.3 @@ -0,0 +1,352 @@
    20.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
    20.5 + *
    20.6 + * This file is a part of LEMON, a generic C++ optimization library.
    20.7 + *
    20.8 + * Copyright (C) 2003-2009
    20.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   20.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
   20.11 + *
   20.12 + * Permission to use, modify and distribute this software is granted
   20.13 + * provided that this copyright notice appears in all copies. For
   20.14 + * precise terms see the accompanying LICENSE file.
   20.15 + *
   20.16 + * This software is provided "AS IS" with no warranty of any kind,
   20.17 + * express or implied, and with no claim as to its suitability for any
   20.18 + * purpose.
   20.19 + *
   20.20 + */
   20.21 +
   20.22 +#ifndef LEMON_KARY_HEAP_H
   20.23 +#define LEMON_KARY_HEAP_H
   20.24 +
   20.25 +///\ingroup heaps
   20.26 +///\file
   20.27 +///\brief Fourary heap implementation.
   20.28 +
   20.29 +#include <vector>
   20.30 +#include <utility>
   20.31 +#include <functional>
   20.32 +
   20.33 +namespace lemon {
   20.34 +
   20.35 +  /// \ingroup heaps
   20.36 +  ///
   20.37 +  ///\brief K-ary heap data structure.
   20.38 +  ///
   20.39 +  /// This class implements the \e K-ary \e heap data structure.
   20.40 +  /// It fully conforms to the \ref concepts::Heap "heap concept".
   20.41 +  ///
   20.42 +  /// The \ref KaryHeap "K-ary heap" is a generalization of the
   20.43 +  /// \ref BinHeap "binary heap" structure, its nodes have at most
   20.44 +  /// \c K children, instead of two.
   20.45 +  /// \ref BinHeap and \ref FouraryHeap are specialized implementations
   20.46 +  /// of this structure for <tt>K=2</tt> and <tt>K=4</tt>, respectively.
   20.47 +  ///
   20.48 +  /// \tparam PR Type of the priorities of the items.
   20.49 +  /// \tparam IM A read-writable item map with \c int values, used
   20.50 +  /// internally to handle the cross references.
   20.51 +  /// \tparam K The degree of the heap, each node have at most \e K
   20.52 +  /// children. The default is 16. Powers of two are suggested to use
   20.53 +  /// so that the multiplications and divisions needed to traverse the
   20.54 +  /// nodes of the heap could be performed faster.
   20.55 +  /// \tparam CMP A functor class for comparing the priorities.
   20.56 +  /// The default is \c std::less<PR>.
   20.57 +  ///
   20.58 +  ///\sa BinHeap
   20.59 +  ///\sa FouraryHeap
   20.60 +#ifdef DOXYGEN
   20.61 +  template <typename PR, typename IM, int K, typename CMP>
   20.62 +#else
   20.63 +  template <typename PR, typename IM, int K = 16,
   20.64 +            typename CMP = std::less<PR> >
   20.65 +#endif
   20.66 +  class KaryHeap {
   20.67 +  public:
   20.68 +    /// Type of the item-int map.
   20.69 +    typedef IM ItemIntMap;
   20.70 +    /// Type of the priorities.
   20.71 +    typedef PR Prio;
   20.72 +    /// Type of the items stored in the heap.
   20.73 +    typedef typename ItemIntMap::Key Item;
   20.74 +    /// Type of the item-priority pairs.
   20.75 +    typedef std::pair<Item,Prio> Pair;
   20.76 +    /// Functor type for comparing the priorities.
   20.77 +    typedef CMP Compare;
   20.78 +
   20.79 +    /// \brief Type to represent the states of the items.
   20.80 +    ///
   20.81 +    /// Each item has a state associated to it. It can be "in heap",
   20.82 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
   20.83 +    /// heap's point of view, but may be useful to the user.
   20.84 +    ///
   20.85 +    /// The item-int map must be initialized in such way that it assigns
   20.86 +    /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
   20.87 +    enum State {
   20.88 +      IN_HEAP = 0,    ///< = 0.
   20.89 +      PRE_HEAP = -1,  ///< = -1.
   20.90 +      POST_HEAP = -2  ///< = -2.
   20.91 +    };
   20.92 +
   20.93 +  private:
   20.94 +    std::vector<Pair> _data;
   20.95 +    Compare _comp;
   20.96 +    ItemIntMap &_iim;
   20.97 +
   20.98 +  public:
   20.99 +    /// \brief Constructor.
  20.100 +    ///
  20.101 +    /// Constructor.
  20.102 +    /// \param map A map that assigns \c int values to the items.
  20.103 +    /// It is used internally to handle the cross references.
  20.104 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  20.105 +    explicit KaryHeap(ItemIntMap &map) : _iim(map) {}
  20.106 +
  20.107 +    /// \brief Constructor.
  20.108 +    ///
  20.109 +    /// Constructor.
  20.110 +    /// \param map A map that assigns \c int values to the items.
  20.111 +    /// It is used internally to handle the cross references.
  20.112 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  20.113 +    /// \param comp The function object used for comparing the priorities.
  20.114 +    KaryHeap(ItemIntMap &map, const Compare &comp)
  20.115 +      : _iim(map), _comp(comp) {}
  20.116 +
  20.117 +    /// \brief The number of items stored in the heap.
  20.118 +    ///
  20.119 +    /// This function returns the number of items stored in the heap.
  20.120 +    int size() const { return _data.size(); }
  20.121 +
  20.122 +    /// \brief Check if the heap is empty.
  20.123 +    ///
  20.124 +    /// This function returns \c true if the heap is empty.
  20.125 +    bool empty() const { return _data.empty(); }
  20.126 +
  20.127 +    /// \brief Make the heap empty.
  20.128 +    ///
  20.129 +    /// This functon makes the heap empty.
  20.130 +    /// It does not change the cross reference map. If you want to reuse
  20.131 +    /// a heap that is not surely empty, you should first clear it and
  20.132 +    /// then you should set the cross reference map to \c PRE_HEAP
  20.133 +    /// for each item.
  20.134 +    void clear() { _data.clear(); }
  20.135 +
  20.136 +  private:
  20.137 +    int parent(int i) { return (i-1)/K; }
  20.138 +    int firstChild(int i) { return K*i+1; }
  20.139 +
  20.140 +    bool less(const Pair &p1, const Pair &p2) const {
  20.141 +      return _comp(p1.second, p2.second);
  20.142 +    }
  20.143 +
  20.144 +    void bubbleUp(int hole, Pair p) {
  20.145 +      int par = parent(hole);
  20.146 +      while( hole>0 && less(p,_data[par]) ) {
  20.147 +        move(_data[par],hole);
  20.148 +        hole = par;
  20.149 +        par = parent(hole);
  20.150 +      }
  20.151 +      move(p, hole);
  20.152 +    }
  20.153 +
  20.154 +    void bubbleDown(int hole, Pair p, int length) {
  20.155 +      if( length>1 ) {
  20.156 +        int child = firstChild(hole);
  20.157 +        while( child+K<=length ) {
  20.158 +          int min=child;
  20.159 +          for (int i=1; i<K; ++i) {
  20.160 +            if( less(_data[child+i], _data[min]) )
  20.161 +              min=child+i;
  20.162 +          }
  20.163 +          if( !less(_data[min], p) )
  20.164 +            goto ok;
  20.165 +          move(_data[min], hole);
  20.166 +          hole = min;
  20.167 +          child = firstChild(hole);
  20.168 +        }
  20.169 +        if ( child<length ) {
  20.170 +          int min = child;
  20.171 +          while (++child < length) {
  20.172 +            if( less(_data[child], _data[min]) )
  20.173 +              min=child;
  20.174 +          }
  20.175 +          if( less(_data[min], p) ) {
  20.176 +            move(_data[min], hole);
  20.177 +            hole = min;
  20.178 +          }
  20.179 +        }
  20.180 +      }
  20.181 +    ok:
  20.182 +      move(p, hole);
  20.183 +    }
  20.184 +
  20.185 +    void move(const Pair &p, int i) {
  20.186 +      _data[i] = p;
  20.187 +      _iim.set(p.first, i);
  20.188 +    }
  20.189 +
  20.190 +  public:
  20.191 +    /// \brief Insert a pair of item and priority into the heap.
  20.192 +    ///
  20.193 +    /// This function inserts \c p.first to the heap with priority
  20.194 +    /// \c p.second.
  20.195 +    /// \param p The pair to insert.
  20.196 +    /// \pre \c p.first must not be stored in the heap.
  20.197 +    void push(const Pair &p) {
  20.198 +      int n = _data.size();
  20.199 +      _data.resize(n+1);
  20.200 +      bubbleUp(n, p);
  20.201 +    }
  20.202 +
  20.203 +    /// \brief Insert an item into the heap with the given priority.
  20.204 +    ///
  20.205 +    /// This function inserts the given item into the heap with the
  20.206 +    /// given priority.
  20.207 +    /// \param i The item to insert.
  20.208 +    /// \param p The priority of the item.
  20.209 +    /// \pre \e i must not be stored in the heap.
  20.210 +    void push(const Item &i, const Prio &p) { push(Pair(i,p)); }
  20.211 +
  20.212 +    /// \brief Return the item having minimum priority.
  20.213 +    ///
  20.214 +    /// This function returns the item having minimum priority.
  20.215 +    /// \pre The heap must be non-empty.
  20.216 +    Item top() const { return _data[0].first; }
  20.217 +
  20.218 +    /// \brief The minimum priority.
  20.219 +    ///
  20.220 +    /// This function returns the minimum priority.
  20.221 +    /// \pre The heap must be non-empty.
  20.222 +    Prio prio() const { return _data[0].second; }
  20.223 +
  20.224 +    /// \brief Remove the item having minimum priority.
  20.225 +    ///
  20.226 +    /// This function removes the item having minimum priority.
  20.227 +    /// \pre The heap must be non-empty.
  20.228 +    void pop() {
  20.229 +      int n = _data.size()-1;
  20.230 +      _iim.set(_data[0].first, POST_HEAP);
  20.231 +      if (n>0) bubbleDown(0, _data[n], n);
  20.232 +      _data.pop_back();
  20.233 +    }
  20.234 +
  20.235 +    /// \brief Remove the given item from the heap.
  20.236 +    ///
  20.237 +    /// This function removes the given item from the heap if it is
  20.238 +    /// already stored.
  20.239 +    /// \param i The item to delete.
  20.240 +    /// \pre \e i must be in the heap.
  20.241 +    void erase(const Item &i) {
  20.242 +      int h = _iim[i];
  20.243 +      int n = _data.size()-1;
  20.244 +      _iim.set(_data[h].first, POST_HEAP);
  20.245 +      if( h<n ) {
  20.246 +        if( less(_data[parent(h)], _data[n]) )
  20.247 +          bubbleDown(h, _data[n], n);
  20.248 +        else
  20.249 +          bubbleUp(h, _data[n]);
  20.250 +      }
  20.251 +      _data.pop_back();
  20.252 +    }
  20.253 +
  20.254 +    /// \brief The priority of the given item.
  20.255 +    ///
  20.256 +    /// This function returns the priority of the given item.
  20.257 +    /// \param i The item.
  20.258 +    /// \pre \e i must be in the heap.
  20.259 +    Prio operator[](const Item &i) const {
  20.260 +      int idx = _iim[i];
  20.261 +      return _data[idx].second;
  20.262 +    }
  20.263 +
  20.264 +    /// \brief Set the priority of an item or insert it, if it is
  20.265 +    /// not stored in the heap.
  20.266 +    ///
  20.267 +    /// This method sets the priority of the given item if it is
  20.268 +    /// already stored in the heap. Otherwise it inserts the given
  20.269 +    /// item into the heap with the given priority.
  20.270 +    /// \param i The item.
  20.271 +    /// \param p The priority.
  20.272 +    void set(const Item &i, const Prio &p) {
  20.273 +      int idx = _iim[i];
  20.274 +      if( idx<0 )
  20.275 +        push(i,p);
  20.276 +      else if( _comp(p, _data[idx].second) )
  20.277 +        bubbleUp(idx, Pair(i,p));
  20.278 +      else
  20.279 +        bubbleDown(idx, Pair(i,p), _data.size());
  20.280 +    }
  20.281 +
  20.282 +    /// \brief Decrease the priority of an item to the given value.
  20.283 +    ///
  20.284 +    /// This function decreases the priority of an item to the given value.
  20.285 +    /// \param i The item.
  20.286 +    /// \param p The priority.
  20.287 +    /// \pre \e i must be stored in the heap with priority at least \e p.
  20.288 +    void decrease(const Item &i, const Prio &p) {
  20.289 +      int idx = _iim[i];
  20.290 +      bubbleUp(idx, Pair(i,p));
  20.291 +    }
  20.292 +
  20.293 +    /// \brief Increase the priority of an item to the given value.
  20.294 +    ///
  20.295 +    /// This function increases the priority of an item to the given value.
  20.296 +    /// \param i The item.
  20.297 +    /// \param p The priority.
  20.298 +    /// \pre \e i must be stored in the heap with priority at most \e p.
  20.299 +    void increase(const Item &i, const Prio &p) {
  20.300 +      int idx = _iim[i];
  20.301 +      bubbleDown(idx, Pair(i,p), _data.size());
  20.302 +    }
  20.303 +
  20.304 +    /// \brief Return the state of an item.
  20.305 +    ///
  20.306 +    /// This method returns \c PRE_HEAP if the given item has never
  20.307 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  20.308 +    /// and \c POST_HEAP otherwise.
  20.309 +    /// In the latter case it is possible that the item will get back
  20.310 +    /// to the heap again.
  20.311 +    /// \param i The item.
  20.312 +    State state(const Item &i) const {
  20.313 +      int s = _iim[i];
  20.314 +      if (s>=0) s=0;
  20.315 +      return State(s);
  20.316 +    }
  20.317 +
  20.318 +    /// \brief Set the state of an item in the heap.
  20.319 +    ///
  20.320 +    /// This function sets the state of the given item in the heap.
  20.321 +    /// It can be used to manually clear the heap when it is important
  20.322 +    /// to achive better time complexity.
  20.323 +    /// \param i The item.
  20.324 +    /// \param st The state. It should not be \c IN_HEAP.
  20.325 +    void state(const Item& i, State st) {
  20.326 +      switch (st) {
  20.327 +        case POST_HEAP:
  20.328 +        case PRE_HEAP:
  20.329 +          if (state(i) == IN_HEAP) erase(i);
  20.330 +          _iim[i] = st;
  20.331 +          break;
  20.332 +        case IN_HEAP:
  20.333 +          break;
  20.334 +      }
  20.335 +    }
  20.336 +
  20.337 +    /// \brief Replace an item in the heap.
  20.338 +    ///
  20.339 +    /// This function replaces item \c i with item \c j.
  20.340 +    /// Item \c i must be in the heap, while \c j must be out of the heap.
  20.341 +    /// After calling this method, item \c i will be out of the
  20.342 +    /// heap and \c j will be in the heap with the same prioriority
  20.343 +    /// as item \c i had before.
  20.344 +    void replace(const Item& i, const Item& j) {
  20.345 +      int idx=_iim[i];
  20.346 +      _iim.set(i, _iim[j]);
  20.347 +      _iim.set(j, idx);
  20.348 +      _data[idx].first=j;
  20.349 +    }
  20.350 +
  20.351 +  }; // class KaryHeap
  20.352 +
  20.353 +} // namespace lemon
  20.354 +
  20.355 +#endif // LEMON_KARY_HEAP_H
    21.1 --- a/lemon/maps.h	Fri Sep 25 12:24:16 2009 +0200
    21.2 +++ b/lemon/maps.h	Sat Sep 26 07:08:10 2009 +0200
    21.3 @@ -1789,11 +1789,11 @@
    21.4    /// order of Dfs algorithm, as the following examples show.
    21.5    /// \code
    21.6    ///   std::vector<Node> v;
    21.7 -  ///   dfs(g,s).processedMap(loggerBoolMap(std::back_inserter(v))).run();
    21.8 +  ///   dfs(g).processedMap(loggerBoolMap(std::back_inserter(v))).run(s);
    21.9    /// \endcode
   21.10    /// \code
   21.11    ///   std::vector<Node> v(countNodes(g));
   21.12 -  ///   dfs(g,s).processedMap(loggerBoolMap(v.begin())).run();
   21.13 +  ///   dfs(g).processedMap(loggerBoolMap(v.begin())).run(s);
   21.14    /// \endcode
   21.15    ///
   21.16    /// \note The container of the iterator must contain enough space
    22.1 --- a/lemon/min_cost_arborescence.h	Fri Sep 25 12:24:16 2009 +0200
    22.2 +++ b/lemon/min_cost_arborescence.h	Sat Sep 26 07:08:10 2009 +0200
    22.3 @@ -488,8 +488,8 @@
    22.4      /// \name Execution Control
    22.5      /// The simplest way to execute the algorithm is to use
    22.6      /// one of the member functions called \c run(...). \n
    22.7 -    /// If you need more control on the execution,
    22.8 -    /// first you must call \ref init(), then you can add several
    22.9 +    /// If you need better control on the execution,
   22.10 +    /// you have to call \ref init() first, then you can add several
   22.11      /// source nodes with \ref addSource().
   22.12      /// Finally \ref start() will perform the arborescence
   22.13      /// computation.
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/lemon/pairing_heap.h	Sat Sep 26 07:08:10 2009 +0200
    23.3 @@ -0,0 +1,474 @@
    23.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
    23.5 + *
    23.6 + * This file is a part of LEMON, a generic C++ optimization library.
    23.7 + *
    23.8 + * Copyright (C) 2003-2009
    23.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   23.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
   23.11 + *
   23.12 + * Permission to use, modify and distribute this software is granted
   23.13 + * provided that this copyright notice appears in all copies. For
   23.14 + * precise terms see the accompanying LICENSE file.
   23.15 + *
   23.16 + * This software is provided "AS IS" with no warranty of any kind,
   23.17 + * express or implied, and with no claim as to its suitability for any
   23.18 + * purpose.
   23.19 + *
   23.20 + */
   23.21 +
   23.22 +#ifndef LEMON_PAIRING_HEAP_H
   23.23 +#define LEMON_PAIRING_HEAP_H
   23.24 +
   23.25 +///\file
   23.26 +///\ingroup heaps
   23.27 +///\brief Pairing heap implementation.
   23.28 +
   23.29 +#include <vector>
   23.30 +#include <utility>
   23.31 +#include <functional>
   23.32 +#include <lemon/math.h>
   23.33 +
   23.34 +namespace lemon {
   23.35 +
   23.36 +  /// \ingroup heaps
   23.37 +  ///
   23.38 +  ///\brief Pairing Heap.
   23.39 +  ///
   23.40 +  /// This class implements the \e pairing \e heap data structure.
   23.41 +  /// It fully conforms to the \ref concepts::Heap "heap concept".
   23.42 +  ///
   23.43 +  /// The methods \ref increase() and \ref erase() are not efficient
   23.44 +  /// in a pairing heap. In case of many calls of these operations,
   23.45 +  /// it is better to use other heap structure, e.g. \ref BinHeap
   23.46 +  /// "binary heap".
   23.47 +  ///
   23.48 +  /// \tparam PR Type of the priorities of the items.
   23.49 +  /// \tparam IM A read-writable item map with \c int values, used
   23.50 +  /// internally to handle the cross references.
   23.51 +  /// \tparam CMP A functor class for comparing the priorities.
   23.52 +  /// The default is \c std::less<PR>.
   23.53 +#ifdef DOXYGEN
   23.54 +  template <typename PR, typename IM, typename CMP>
   23.55 +#else
   23.56 +  template <typename PR, typename IM, typename CMP = std::less<PR> >
   23.57 +#endif
   23.58 +  class PairingHeap {
   23.59 +  public:
   23.60 +    /// Type of the item-int map.
   23.61 +    typedef IM ItemIntMap;
   23.62 +    /// Type of the priorities.
   23.63 +    typedef PR Prio;
   23.64 +    /// Type of the items stored in the heap.
   23.65 +    typedef typename ItemIntMap::Key Item;
   23.66 +    /// Functor type for comparing the priorities.
   23.67 +    typedef CMP Compare;
   23.68 +
   23.69 +    /// \brief Type to represent the states of the items.
   23.70 +    ///
   23.71 +    /// Each item has a state associated to it. It can be "in heap",
   23.72 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
   23.73 +    /// heap's point of view, but may be useful to the user.
   23.74 +    ///
   23.75 +    /// The item-int map must be initialized in such way that it assigns
   23.76 +    /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
   23.77 +    enum State {
   23.78 +      IN_HEAP = 0,    ///< = 0.
   23.79 +      PRE_HEAP = -1,  ///< = -1.
   23.80 +      POST_HEAP = -2  ///< = -2.
   23.81 +    };
   23.82 +
   23.83 +  private:
   23.84 +    class store;
   23.85 +
   23.86 +    std::vector<store> _data;
   23.87 +    int _min;
   23.88 +    ItemIntMap &_iim;
   23.89 +    Compare _comp;
   23.90 +    int _num_items;
   23.91 +
   23.92 +  public:
   23.93 +    /// \brief Constructor.
   23.94 +    ///
   23.95 +    /// Constructor.
   23.96 +    /// \param map A map that assigns \c int values to the items.
   23.97 +    /// It is used internally to handle the cross references.
   23.98 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
   23.99 +    explicit PairingHeap(ItemIntMap &map)
  23.100 +      : _min(0), _iim(map), _num_items(0) {}
  23.101 +
  23.102 +    /// \brief Constructor.
  23.103 +    ///
  23.104 +    /// Constructor.
  23.105 +    /// \param map A map that assigns \c int values to the items.
  23.106 +    /// It is used internally to handle the cross references.
  23.107 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  23.108 +    /// \param comp The function object used for comparing the priorities.
  23.109 +    PairingHeap(ItemIntMap &map, const Compare &comp)
  23.110 +      : _min(0), _iim(map), _comp(comp), _num_items(0) {}
  23.111 +
  23.112 +    /// \brief The number of items stored in the heap.
  23.113 +    ///
  23.114 +    /// This function returns the number of items stored in the heap.
  23.115 +    int size() const { return _num_items; }
  23.116 +
  23.117 +    /// \brief Check if the heap is empty.
  23.118 +    ///
  23.119 +    /// This function returns \c true if the heap is empty.
  23.120 +    bool empty() const { return _num_items==0; }
  23.121 +
  23.122 +    /// \brief Make the heap empty.
  23.123 +    ///
  23.124 +    /// This functon makes the heap empty.
  23.125 +    /// It does not change the cross reference map. If you want to reuse
  23.126 +    /// a heap that is not surely empty, you should first clear it and
  23.127 +    /// then you should set the cross reference map to \c PRE_HEAP
  23.128 +    /// for each item.
  23.129 +    void clear() {
  23.130 +      _data.clear();
  23.131 +      _min = 0;
  23.132 +      _num_items = 0;
  23.133 +    }
  23.134 +
  23.135 +    /// \brief Set the priority of an item or insert it, if it is
  23.136 +    /// not stored in the heap.
  23.137 +    ///
  23.138 +    /// This method sets the priority of the given item if it is
  23.139 +    /// already stored in the heap. Otherwise it inserts the given
  23.140 +    /// item into the heap with the given priority.
  23.141 +    /// \param item The item.
  23.142 +    /// \param value The priority.
  23.143 +    void set (const Item& item, const Prio& value) {
  23.144 +      int i=_iim[item];
  23.145 +      if ( i>=0 && _data[i].in ) {
  23.146 +        if ( _comp(value, _data[i].prio) ) decrease(item, value);
  23.147 +        if ( _comp(_data[i].prio, value) ) increase(item, value);
  23.148 +      } else push(item, value);
  23.149 +    }
  23.150 +
  23.151 +    /// \brief Insert an item into the heap with the given priority.
  23.152 +    ///
  23.153 +    /// This function inserts the given item into the heap with the
  23.154 +    /// given priority.
  23.155 +    /// \param item The item to insert.
  23.156 +    /// \param value The priority of the item.
  23.157 +    /// \pre \e item must not be stored in the heap.
  23.158 +    void push (const Item& item, const Prio& value) {
  23.159 +      int i=_iim[item];
  23.160 +      if( i<0 ) {
  23.161 +        int s=_data.size();
  23.162 +        _iim.set(item, s);
  23.163 +        store st;
  23.164 +        st.name=item;
  23.165 +        _data.push_back(st);
  23.166 +        i=s;
  23.167 +      } else {
  23.168 +        _data[i].parent=_data[i].child=-1;
  23.169 +        _data[i].left_child=false;
  23.170 +        _data[i].degree=0;
  23.171 +        _data[i].in=true;
  23.172 +      }
  23.173 +
  23.174 +      _data[i].prio=value;
  23.175 +
  23.176 +      if ( _num_items!=0 ) {
  23.177 +        if ( _comp( value, _data[_min].prio) ) {
  23.178 +          fuse(i,_min);
  23.179 +          _min=i;
  23.180 +        }
  23.181 +        else fuse(_min,i);
  23.182 +      }
  23.183 +      else _min=i;
  23.184 +
  23.185 +      ++_num_items;
  23.186 +    }
  23.187 +
  23.188 +    /// \brief Return the item having minimum priority.
  23.189 +    ///
  23.190 +    /// This function returns the item having minimum priority.
  23.191 +    /// \pre The heap must be non-empty.
  23.192 +    Item top() const { return _data[_min].name; }
  23.193 +
  23.194 +    /// \brief The minimum priority.
  23.195 +    ///
  23.196 +    /// This function returns the minimum priority.
  23.197 +    /// \pre The heap must be non-empty.
  23.198 +    const Prio& prio() const { return _data[_min].prio; }
  23.199 +
  23.200 +    /// \brief The priority of the given item.
  23.201 +    ///
  23.202 +    /// This function returns the priority of the given item.
  23.203 +    /// \param item The item.
  23.204 +    /// \pre \e item must be in the heap.
  23.205 +    const Prio& operator[](const Item& item) const {
  23.206 +      return _data[_iim[item]].prio;
  23.207 +    }
  23.208 +
  23.209 +    /// \brief Remove the item having minimum priority.
  23.210 +    ///
  23.211 +    /// This function removes the item having minimum priority.
  23.212 +    /// \pre The heap must be non-empty.
  23.213 +    void pop() {
  23.214 +      std::vector<int> trees;
  23.215 +      int i=0, child_right = 0;
  23.216 +      _data[_min].in=false;
  23.217 +
  23.218 +      if( -1!=_data[_min].child ) {
  23.219 +        i=_data[_min].child;
  23.220 +        trees.push_back(i);
  23.221 +        _data[i].parent = -1;
  23.222 +        _data[_min].child = -1;
  23.223 +
  23.224 +        int ch=-1;
  23.225 +        while( _data[i].child!=-1 ) {
  23.226 +          ch=_data[i].child;
  23.227 +          if( _data[ch].left_child && i==_data[ch].parent ) {
  23.228 +            break;
  23.229 +          } else {
  23.230 +            if( _data[ch].left_child ) {
  23.231 +              child_right=_data[ch].parent;
  23.232 +              _data[ch].parent = i;
  23.233 +              --_data[i].degree;
  23.234 +            }
  23.235 +            else {
  23.236 +              child_right=ch;
  23.237 +              _data[i].child=-1;
  23.238 +              _data[i].degree=0;
  23.239 +            }
  23.240 +            _data[child_right].parent = -1;
  23.241 +            trees.push_back(child_right);
  23.242 +            i = child_right;
  23.243 +          }
  23.244 +        }
  23.245 +
  23.246 +        int num_child = trees.size();
  23.247 +        int other;
  23.248 +        for( i=0; i<num_child-1; i+=2 ) {
  23.249 +          if ( !_comp(_data[trees[i]].prio, _data[trees[i+1]].prio) ) {
  23.250 +            other=trees[i];
  23.251 +            trees[i]=trees[i+1];
  23.252 +            trees[i+1]=other;
  23.253 +          }
  23.254 +          fuse( trees[i], trees[i+1] );
  23.255 +        }
  23.256 +
  23.257 +        i = (0==(num_child % 2)) ? num_child-2 : num_child-1;
  23.258 +        while(i>=2) {
  23.259 +          if ( _comp(_data[trees[i]].prio, _data[trees[i-2]].prio) ) {
  23.260 +            other=trees[i];
  23.261 +            trees[i]=trees[i-2];
  23.262 +            trees[i-2]=other;
  23.263 +          }
  23.264 +          fuse( trees[i-2], trees[i] );
  23.265 +          i-=2;
  23.266 +        }
  23.267 +        _min = trees[0];
  23.268 +      }
  23.269 +      else {
  23.270 +        _min = _data[_min].child;
  23.271 +      }
  23.272 +
  23.273 +      if (_min >= 0) _data[_min].left_child = false;
  23.274 +      --_num_items;
  23.275 +    }
  23.276 +
  23.277 +    /// \brief Remove the given item from the heap.
  23.278 +    ///
  23.279 +    /// This function removes the given item from the heap if it is
  23.280 +    /// already stored.
  23.281 +    /// \param item The item to delete.
  23.282 +    /// \pre \e item must be in the heap.
  23.283 +    void erase (const Item& item) {
  23.284 +      int i=_iim[item];
  23.285 +      if ( i>=0 && _data[i].in ) {
  23.286 +        decrease( item, _data[_min].prio-1 );
  23.287 +        pop();
  23.288 +      }
  23.289 +    }
  23.290 +
  23.291 +    /// \brief Decrease the priority of an item to the given value.
  23.292 +    ///
  23.293 +    /// This function decreases the priority of an item to the given value.
  23.294 +    /// \param item The item.
  23.295 +    /// \param value The priority.
  23.296 +    /// \pre \e item must be stored in the heap with priority at least \e value.
  23.297 +    void decrease (Item item, const Prio& value) {
  23.298 +      int i=_iim[item];
  23.299 +      _data[i].prio=value;
  23.300 +      int p=_data[i].parent;
  23.301 +
  23.302 +      if( _data[i].left_child && i!=_data[p].child ) {
  23.303 +        p=_data[p].parent;
  23.304 +      }
  23.305 +
  23.306 +      if ( p!=-1 && _comp(value,_data[p].prio) ) {
  23.307 +        cut(i,p);
  23.308 +        if ( _comp(_data[_min].prio,value) ) {
  23.309 +          fuse(_min,i);
  23.310 +        } else {
  23.311 +          fuse(i,_min);
  23.312 +          _min=i;
  23.313 +        }
  23.314 +      }
  23.315 +    }
  23.316 +
  23.317 +    /// \brief Increase the priority of an item to the given value.
  23.318 +    ///
  23.319 +    /// This function increases the priority of an item to the given value.
  23.320 +    /// \param item The item.
  23.321 +    /// \param value The priority.
  23.322 +    /// \pre \e item must be stored in the heap with priority at most \e value.
  23.323 +    void increase (Item item, const Prio& value) {
  23.324 +      erase(item);
  23.325 +      push(item,value);
  23.326 +    }
  23.327 +
  23.328 +    /// \brief Return the state of an item.
  23.329 +    ///
  23.330 +    /// This method returns \c PRE_HEAP if the given item has never
  23.331 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  23.332 +    /// and \c POST_HEAP otherwise.
  23.333 +    /// In the latter case it is possible that the item will get back
  23.334 +    /// to the heap again.
  23.335 +    /// \param item The item.
  23.336 +    State state(const Item &item) const {
  23.337 +      int i=_iim[item];
  23.338 +      if( i>=0 ) {
  23.339 +        if( _data[i].in ) i=0;
  23.340 +        else i=-2;
  23.341 +      }
  23.342 +      return State(i);
  23.343 +    }
  23.344 +
  23.345 +    /// \brief Set the state of an item in the heap.
  23.346 +    ///
  23.347 +    /// This function sets the state of the given item in the heap.
  23.348 +    /// It can be used to manually clear the heap when it is important
  23.349 +    /// to achive better time complexity.
  23.350 +    /// \param i The item.
  23.351 +    /// \param st The state. It should not be \c IN_HEAP.
  23.352 +    void state(const Item& i, State st) {
  23.353 +      switch (st) {
  23.354 +      case POST_HEAP:
  23.355 +      case PRE_HEAP:
  23.356 +        if (state(i) == IN_HEAP) erase(i);
  23.357 +        _iim[i]=st;
  23.358 +        break;
  23.359 +      case IN_HEAP:
  23.360 +        break;
  23.361 +      }
  23.362 +    }
  23.363 +
  23.364 +  private:
  23.365 +
  23.366 +    void cut(int a, int b) {
  23.367 +      int child_a;
  23.368 +      switch (_data[a].degree) {
  23.369 +        case 2:
  23.370 +          child_a = _data[_data[a].child].parent;
  23.371 +          if( _data[a].left_child ) {
  23.372 +            _data[child_a].left_child=true;
  23.373 +            _data[b].child=child_a;
  23.374 +            _data[child_a].parent=_data[a].parent;
  23.375 +          }
  23.376 +          else {
  23.377 +            _data[child_a].left_child=false;
  23.378 +            _data[child_a].parent=b;
  23.379 +            if( a!=_data[b].child )
  23.380 +              _data[_data[b].child].parent=child_a;
  23.381 +            else
  23.382 +              _data[b].child=child_a;
  23.383 +          }
  23.384 +          --_data[a].degree;
  23.385 +          _data[_data[a].child].parent=a;
  23.386 +          break;
  23.387 +
  23.388 +        case 1:
  23.389 +          child_a = _data[a].child;
  23.390 +          if( !_data[child_a].left_child ) {
  23.391 +            --_data[a].degree;
  23.392 +            if( _data[a].left_child ) {
  23.393 +              _data[child_a].left_child=true;
  23.394 +              _data[child_a].parent=_data[a].parent;
  23.395 +              _data[b].child=child_a;
  23.396 +            }
  23.397 +            else {
  23.398 +              _data[child_a].left_child=false;
  23.399 +              _data[child_a].parent=b;
  23.400 +              if( a!=_data[b].child )
  23.401 +                _data[_data[b].child].parent=child_a;
  23.402 +              else
  23.403 +                _data[b].child=child_a;
  23.404 +            }
  23.405 +            _data[a].child=-1;
  23.406 +          }
  23.407 +          else {
  23.408 +            --_data[b].degree;
  23.409 +            if( _data[a].left_child ) {
  23.410 +              _data[b].child =
  23.411 +                (1==_data[b].degree) ? _data[a].parent : -1;
  23.412 +            } else {
  23.413 +              if (1==_data[b].degree)
  23.414 +                _data[_data[b].child].parent=b;
  23.415 +              else
  23.416 +                _data[b].child=-1;
  23.417 +            }
  23.418 +          }
  23.419 +          break;
  23.420 +
  23.421 +        case 0:
  23.422 +          --_data[b].degree;
  23.423 +          if( _data[a].left_child ) {
  23.424 +            _data[b].child =
  23.425 +              (0!=_data[b].degree) ? _data[a].parent : -1;
  23.426 +          } else {
  23.427 +            if( 0!=_data[b].degree )
  23.428 +              _data[_data[b].child].parent=b;
  23.429 +            else
  23.430 +              _data[b].child=-1;
  23.431 +          }
  23.432 +          break;
  23.433 +      }
  23.434 +      _data[a].parent=-1;
  23.435 +      _data[a].left_child=false;
  23.436 +    }
  23.437 +
  23.438 +    void fuse(int a, int b) {
  23.439 +      int child_a = _data[a].child;
  23.440 +      int child_b = _data[b].child;
  23.441 +      _data[a].child=b;
  23.442 +      _data[b].parent=a;
  23.443 +      _data[b].left_child=true;
  23.444 +
  23.445 +      if( -1!=child_a ) {
  23.446 +        _data[b].child=child_a;
  23.447 +        _data[child_a].parent=b;
  23.448 +        _data[child_a].left_child=false;
  23.449 +        ++_data[b].degree;
  23.450 +
  23.451 +        if( -1!=child_b ) {
  23.452 +           _data[b].child=child_b;
  23.453 +           _data[child_b].parent=child_a;
  23.454 +        }
  23.455 +      }
  23.456 +      else { ++_data[a].degree; }
  23.457 +    }
  23.458 +
  23.459 +    class store {
  23.460 +      friend class PairingHeap;
  23.461 +
  23.462 +      Item name;
  23.463 +      int parent;
  23.464 +      int child;
  23.465 +      bool left_child;
  23.466 +      int degree;
  23.467 +      bool in;
  23.468 +      Prio prio;
  23.469 +
  23.470 +      store() : parent(-1), child(-1), left_child(false), degree(0), in(true) {}
  23.471 +    };
  23.472 +  };
  23.473 +
  23.474 +} //namespace lemon
  23.475 +
  23.476 +#endif //LEMON_PAIRING_HEAP_H
  23.477 +
    24.1 --- a/lemon/preflow.h	Fri Sep 25 12:24:16 2009 +0200
    24.2 +++ b/lemon/preflow.h	Sat Sep 26 07:08:10 2009 +0200
    24.3 @@ -52,7 +52,11 @@
    24.4      ///
    24.5      /// The type of the map that stores the flow values.
    24.6      /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    24.7 +#ifdef DOXYGEN
    24.8 +    typedef GR::ArcMap<Value> FlowMap;
    24.9 +#else
   24.10      typedef typename Digraph::template ArcMap<Value> FlowMap;
   24.11 +#endif
   24.12  
   24.13      /// \brief Instantiates a FlowMap.
   24.14      ///
   24.15 @@ -67,9 +71,12 @@
   24.16      ///
   24.17      /// The elevator type used by Preflow algorithm.
   24.18      ///
   24.19 -    /// \sa Elevator
   24.20 -    /// \sa LinkedElevator
   24.21 -    typedef LinkedElevator<Digraph, typename Digraph::Node> Elevator;
   24.22 +    /// \sa Elevator, LinkedElevator
   24.23 +#ifdef DOXYGEN
   24.24 +    typedef lemon::Elevator<GR, GR::Node> Elevator;
   24.25 +#else
   24.26 +    typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator;
   24.27 +#endif
   24.28  
   24.29      /// \brief Instantiates an Elevator.
   24.30      ///
   24.31 @@ -97,7 +104,7 @@
   24.32    /// \e push-relabel algorithm producing a \ref max_flow
   24.33    /// "flow of maximum value" in a digraph.
   24.34    /// The preflow algorithms are the fastest known maximum
   24.35 -  /// flow algorithms. The current implementation use a mixture of the
   24.36 +  /// flow algorithms. The current implementation uses a mixture of the
   24.37    /// \e "highest label" and the \e "bound decrease" heuristics.
   24.38    /// The worst case time complexity of the algorithm is \f$O(n^2\sqrt{e})\f$.
   24.39    ///
   24.40 @@ -371,26 +378,28 @@
   24.41        return *_level;
   24.42      }
   24.43  
   24.44 -    /// \brief Sets the tolerance used by algorithm.
   24.45 +    /// \brief Sets the tolerance used by the algorithm.
   24.46      ///
   24.47 -    /// Sets the tolerance used by algorithm.
   24.48 -    Preflow& tolerance(const Tolerance& tolerance) const {
   24.49 +    /// Sets the tolerance object used by the algorithm.
   24.50 +    /// \return <tt>(*this)</tt>
   24.51 +    Preflow& tolerance(const Tolerance& tolerance) {
   24.52        _tolerance = tolerance;
   24.53        return *this;
   24.54      }
   24.55  
   24.56      /// \brief Returns a const reference to the tolerance.
   24.57      ///
   24.58 -    /// Returns a const reference to the tolerance.
   24.59 +    /// Returns a const reference to the tolerance object used by
   24.60 +    /// the algorithm.
   24.61      const Tolerance& tolerance() const {
   24.62 -      return tolerance;
   24.63 +      return _tolerance;
   24.64      }
   24.65  
   24.66      /// \name Execution Control
   24.67      /// The simplest way to execute the preflow algorithm is to use
   24.68      /// \ref run() or \ref runMinCut().\n
   24.69 -    /// If you need more control on the initial solution or the execution,
   24.70 -    /// first you have to call one of the \ref init() functions, then
   24.71 +    /// If you need better control on the initial solution or the execution,
   24.72 +    /// you have to call one of the \ref init() functions first, then
   24.73      /// \ref startFirstPhase() and if you need it \ref startSecondPhase().
   24.74  
   24.75      ///@{
    25.1 --- a/lemon/radix_heap.h	Fri Sep 25 12:24:16 2009 +0200
    25.2 +++ b/lemon/radix_heap.h	Sat Sep 26 07:08:10 2009 +0200
    25.3 @@ -19,9 +19,9 @@
    25.4  #ifndef LEMON_RADIX_HEAP_H
    25.5  #define LEMON_RADIX_HEAP_H
    25.6  
    25.7 -///\ingroup auxdat
    25.8 +///\ingroup heaps
    25.9  ///\file
   25.10 -///\brief Radix Heap implementation.
   25.11 +///\brief Radix heap implementation.
   25.12  
   25.13  #include <vector>
   25.14  #include <lemon/error.h>
   25.15 @@ -29,56 +29,54 @@
   25.16  namespace lemon {
   25.17  
   25.18  
   25.19 -  /// \ingroup auxdata
   25.20 +  /// \ingroup heaps
   25.21    ///
   25.22 -  /// \brief A Radix Heap implementation.
   25.23 +  /// \brief Radix heap data structure.
   25.24    ///
   25.25 -  /// This class implements the \e radix \e heap data structure. A \e heap
   25.26 -  /// is a data structure for storing items with specified values called \e
   25.27 -  /// priorities in such a way that finding the item with minimum priority is
   25.28 -  /// efficient. This heap type can store only items with \e int priority.
   25.29 -  /// In a heap one can change the priority of an item, add or erase an
   25.30 -  /// item, but the priority cannot be decreased under the last removed
   25.31 -  /// item's priority.
   25.32 +  /// This class implements the \e radix \e heap data structure.
   25.33 +  /// It practically conforms to the \ref concepts::Heap "heap concept",
   25.34 +  /// but it has some limitations due its special implementation.
   25.35 +  /// The type of the priorities must be \c int and the priority of an
   25.36 +  /// item cannot be decreased under the priority of the last removed item.
   25.37    ///
   25.38 -  /// \param IM A read and writable Item int map, used internally
   25.39 -  /// to handle the cross references.
   25.40 -  ///
   25.41 -  /// \see BinHeap
   25.42 -  /// \see Dijkstra
   25.43 +  /// \tparam IM A read-writable item map with \c int values, used
   25.44 +  /// internally to handle the cross references.
   25.45    template <typename IM>
   25.46    class RadixHeap {
   25.47  
   25.48    public:
   25.49 -    typedef typename IM::Key Item;
   25.50 +
   25.51 +    /// Type of the item-int map.
   25.52 +    typedef IM ItemIntMap;
   25.53 +    /// Type of the priorities.
   25.54      typedef int Prio;
   25.55 -    typedef IM ItemIntMap;
   25.56 +    /// Type of the items stored in the heap.
   25.57 +    typedef typename ItemIntMap::Key Item;
   25.58  
   25.59      /// \brief Exception thrown by RadixHeap.
   25.60      ///
   25.61 -    /// This Exception is thrown when a smaller priority
   25.62 -    /// is inserted into the \e RadixHeap then the last time erased.
   25.63 +    /// This exception is thrown when an item is inserted into a
   25.64 +    /// RadixHeap with a priority smaller than the last erased one.
   25.65      /// \see RadixHeap
   25.66 -
   25.67 -    class UnderFlowPriorityError : public Exception {
   25.68 +    class PriorityUnderflowError : public Exception {
   25.69      public:
   25.70        virtual const char* what() const throw() {
   25.71 -        return "lemon::RadixHeap::UnderFlowPriorityError";
   25.72 +        return "lemon::RadixHeap::PriorityUnderflowError";
   25.73        }
   25.74      };
   25.75  
   25.76 -    /// \brief Type to represent the items states.
   25.77 +    /// \brief Type to represent the states of the items.
   25.78      ///
   25.79 -    /// Each Item element have a state associated to it. It may be "in heap",
   25.80 -    /// "pre heap" or "post heap". The latter two are indifferent from the
   25.81 +    /// Each item has a state associated to it. It can be "in heap",
   25.82 +    /// "pre-heap" or "post-heap". The latter two are indifferent from the
   25.83      /// heap's point of view, but may be useful to the user.
   25.84      ///
   25.85 -    /// The ItemIntMap \e should be initialized in such way that it maps
   25.86 -    /// PRE_HEAP (-1) to any element to be put in the heap...
   25.87 +    /// The item-int map must be initialized in such way that it assigns
   25.88 +    /// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap.
   25.89      enum State {
   25.90 -      IN_HEAP = 0,
   25.91 -      PRE_HEAP = -1,
   25.92 -      POST_HEAP = -2
   25.93 +      IN_HEAP = 0,    ///< = 0.
   25.94 +      PRE_HEAP = -1,  ///< = -1.
   25.95 +      POST_HEAP = -2  ///< = -2.
   25.96      };
   25.97  
   25.98    private:
   25.99 @@ -96,52 +94,55 @@
  25.100        RadixBox(int _min, int _size) : first(-1), min(_min), size(_size) {}
  25.101      };
  25.102  
  25.103 -    std::vector<RadixItem> data;
  25.104 -    std::vector<RadixBox> boxes;
  25.105 +    std::vector<RadixItem> _data;
  25.106 +    std::vector<RadixBox> _boxes;
  25.107  
  25.108      ItemIntMap &_iim;
  25.109  
  25.110 +  public:
  25.111  
  25.112 -  public:
  25.113 -    /// \brief The constructor.
  25.114 +    /// \brief Constructor.
  25.115      ///
  25.116 -    /// The constructor.
  25.117 -    ///
  25.118 -    /// \param map It should be given to the constructor, since it is used
  25.119 -    /// internally to handle the cross references. The value of the map
  25.120 -    /// should be PRE_HEAP (-1) for each element.
  25.121 -    ///
  25.122 -    /// \param minimal The initial minimal value of the heap.
  25.123 -    /// \param capacity It determines the initial capacity of the heap.
  25.124 -    RadixHeap(ItemIntMap &map, int minimal = 0, int capacity = 0)
  25.125 -      : _iim(map) {
  25.126 -      boxes.push_back(RadixBox(minimal, 1));
  25.127 -      boxes.push_back(RadixBox(minimal + 1, 1));
  25.128 -      while (lower(boxes.size() - 1, capacity + minimal - 1)) {
  25.129 +    /// Constructor.
  25.130 +    /// \param map A map that assigns \c int values to the items.
  25.131 +    /// It is used internally to handle the cross references.
  25.132 +    /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item.
  25.133 +    /// \param minimum The initial minimum value of the heap.
  25.134 +    /// \param capacity The initial capacity of the heap.
  25.135 +    RadixHeap(ItemIntMap &map, int minimum = 0, int capacity = 0)
  25.136 +      : _iim(map)
  25.137 +    {
  25.138 +      _boxes.push_back(RadixBox(minimum, 1));
  25.139 +      _boxes.push_back(RadixBox(minimum + 1, 1));
  25.140 +      while (lower(_boxes.size() - 1, capacity + minimum - 1)) {
  25.141          extend();
  25.142        }
  25.143      }
  25.144  
  25.145 -    /// The number of items stored in the heap.
  25.146 +    /// \brief The number of items stored in the heap.
  25.147      ///
  25.148 -    /// \brief Returns the number of items stored in the heap.
  25.149 -    int size() const { return data.size(); }
  25.150 -    /// \brief Checks if the heap stores no items.
  25.151 +    /// This function returns the number of items stored in the heap.
  25.152 +    int size() const { return _data.size(); }
  25.153 +
  25.154 +    /// \brief Check if the heap is empty.
  25.155      ///
  25.156 -    /// Returns \c true if and only if the heap stores no items.
  25.157 -    bool empty() const { return data.empty(); }
  25.158 +    /// This function returns \c true if the heap is empty.
  25.159 +    bool empty() const { return _data.empty(); }
  25.160  
  25.161 -    /// \brief Make empty this heap.
  25.162 +    /// \brief Make the heap empty.
  25.163      ///
  25.164 -    /// Make empty this heap. It does not change the cross reference
  25.165 -    /// map.  If you want to reuse a heap what is not surely empty you
  25.166 -    /// should first clear the heap and after that you should set the
  25.167 -    /// cross reference map for each item to \c PRE_HEAP.
  25.168 -    void clear(int minimal = 0, int capacity = 0) {
  25.169 -      data.clear(); boxes.clear();
  25.170 -      boxes.push_back(RadixBox(minimal, 1));
  25.171 -      boxes.push_back(RadixBox(minimal + 1, 1));
  25.172 -      while (lower(boxes.size() - 1, capacity + minimal - 1)) {
  25.173 +    /// This functon makes the heap empty.
  25.174 +    /// It does not change the cross reference map. If you want to reuse
  25.175 +    /// a heap that is not surely empty, you should first clear it and
  25.176 +    /// then you should set the cross reference map to \c PRE_HEAP
  25.177 +    /// for each item.
  25.178 +    /// \param minimum The minimum value of the heap.
  25.179 +    /// \param capacity The capacity of the heap.
  25.180 +    void clear(int minimum = 0, int capacity = 0) {
  25.181 +      _data.clear(); _boxes.clear();
  25.182 +      _boxes.push_back(RadixBox(minimum, 1));
  25.183 +      _boxes.push_back(RadixBox(minimum + 1, 1));
  25.184 +      while (lower(_boxes.size() - 1, capacity + minimum - 1)) {
  25.185          extend();
  25.186        }
  25.187      }
  25.188 @@ -149,255 +150,259 @@
  25.189    private:
  25.190  
  25.191      bool upper(int box, Prio pr) {
  25.192 -      return pr < boxes[box].min;
  25.193 +      return pr < _boxes[box].min;
  25.194      }
  25.195  
  25.196      bool lower(int box, Prio pr) {
  25.197 -      return pr >= boxes[box].min + boxes[box].size;
  25.198 +      return pr >= _boxes[box].min + _boxes[box].size;
  25.199      }
  25.200  
  25.201 -    /// \brief Remove item from the box list.
  25.202 +    // Remove item from the box list
  25.203      void remove(int index) {
  25.204 -      if (data[index].prev >= 0) {
  25.205 -        data[data[index].prev].next = data[index].next;
  25.206 +      if (_data[index].prev >= 0) {
  25.207 +        _data[_data[index].prev].next = _data[index].next;
  25.208        } else {
  25.209 -        boxes[data[index].box].first = data[index].next;
  25.210 +        _boxes[_data[index].box].first = _data[index].next;
  25.211        }
  25.212 -      if (data[index].next >= 0) {
  25.213 -        data[data[index].next].prev = data[index].prev;
  25.214 +      if (_data[index].next >= 0) {
  25.215 +        _data[_data[index].next].prev = _data[index].prev;
  25.216        }
  25.217      }
  25.218  
  25.219 -    /// \brief Insert item into the box list.
  25.220 +    // Insert item into the box list
  25.221      void insert(int box, int index) {
  25.222 -      if (boxes[box].first == -1) {
  25.223 -        boxes[box].first = index;
  25.224 -        data[index].next = data[index].prev = -1;
  25.225 +      if (_boxes[box].first == -1) {
  25.226 +        _boxes[box].first = index;
  25.227 +        _data[index].next = _data[index].prev = -1;
  25.228        } else {
  25.229 -        data[index].next = boxes[box].first;
  25.230 -        data[boxes[box].first].prev = index;
  25.231 -        data[index].prev = -1;
  25.232 -        boxes[box].first = index;
  25.233 +        _data[index].next = _boxes[box].first;
  25.234 +        _data[_boxes[box].first].prev = index;
  25.235 +        _data[index].prev = -1;
  25.236 +        _boxes[box].first = index;
  25.237        }
  25.238 -      data[index].box = box;
  25.239 +      _data[index].box = box;
  25.240      }
  25.241  
  25.242 -    /// \brief Add a new box to the box list.
  25.243 +    // Add a new box to the box list
  25.244      void extend() {
  25.245 -      int min = boxes.back().min + boxes.back().size;
  25.246 -      int bs = 2 * boxes.back().size;
  25.247 -      boxes.push_back(RadixBox(min, bs));
  25.248 +      int min = _boxes.back().min + _boxes.back().size;
  25.249 +      int bs = 2 * _boxes.back().size;
  25.250 +      _boxes.push_back(RadixBox(min, bs));
  25.251      }
  25.252  
  25.253 -    /// \brief Move an item up into the proper box.
  25.254 -    void bubble_up(int index) {
  25.255 -      if (!lower(data[index].box, data[index].prio)) return;
  25.256 +    // Move an item up into the proper box.
  25.257 +    void bubbleUp(int index) {
  25.258 +      if (!lower(_data[index].box, _data[index].prio)) return;
  25.259        remove(index);
  25.260 -      int box = findUp(data[index].box, data[index].prio);
  25.261 +      int box = findUp(_data[index].box, _data[index].prio);
  25.262        insert(box, index);
  25.263      }
  25.264  
  25.265 -    /// \brief Find up the proper box for the item with the given prio.
  25.266 +    // Find up the proper box for the item with the given priority
  25.267      int findUp(int start, int pr) {
  25.268        while (lower(start, pr)) {
  25.269 -        if (++start == int(boxes.size())) {
  25.270 +        if (++start == int(_boxes.size())) {
  25.271            extend();
  25.272          }
  25.273        }
  25.274        return start;
  25.275      }
  25.276  
  25.277 -    /// \brief Move an item down into the proper box.
  25.278 -    void bubble_down(int index) {
  25.279 -      if (!upper(data[index].box, data[index].prio)) return;
  25.280 +    // Move an item down into the proper box
  25.281 +    void bubbleDown(int index) {
  25.282 +      if (!upper(_data[index].box, _data[index].prio)) return;
  25.283        remove(index);
  25.284 -      int box = findDown(data[index].box, data[index].prio);
  25.285 +      int box = findDown(_data[index].box, _data[index].prio);
  25.286        insert(box, index);
  25.287      }
  25.288  
  25.289 -    /// \brief Find up the proper box for the item with the given prio.
  25.290 +    // Find down the proper box for the item with the given priority
  25.291      int findDown(int start, int pr) {
  25.292        while (upper(start, pr)) {
  25.293 -        if (--start < 0) throw UnderFlowPriorityError();
  25.294 +        if (--start < 0) throw PriorityUnderflowError();
  25.295        }
  25.296        return start;
  25.297      }
  25.298  
  25.299 -    /// \brief Find the first not empty box.
  25.300 +    // Find the first non-empty box
  25.301      int findFirst() {
  25.302        int first = 0;
  25.303 -      while (boxes[first].first == -1) ++first;
  25.304 +      while (_boxes[first].first == -1) ++first;
  25.305        return first;
  25.306      }
  25.307  
  25.308 -    /// \brief Gives back the minimal prio of the box.
  25.309 +    // Gives back the minimum priority of the given box
  25.310      int minValue(int box) {
  25.311 -      int min = data[boxes[box].first].prio;
  25.312 -      for (int k = boxes[box].first; k != -1; k = data[k].next) {
  25.313 -        if (data[k].prio < min) min = data[k].prio;
  25.314 +      int min = _data[_boxes[box].first].prio;
  25.315 +      for (int k = _boxes[box].first; k != -1; k = _data[k].next) {
  25.316 +        if (_data[k].prio < min) min = _data[k].prio;
  25.317        }
  25.318        return min;
  25.319      }
  25.320  
  25.321 -    /// \brief Rearrange the items of the heap and makes the
  25.322 -    /// first box not empty.
  25.323 +    // Rearrange the items of the heap and make the first box non-empty
  25.324      void moveDown() {
  25.325        int box = findFirst();
  25.326        if (box == 0) return;
  25.327        int min = minValue(box);
  25.328        for (int i = 0; i <= box; ++i) {
  25.329 -        boxes[i].min = min;
  25.330 -        min += boxes[i].size;
  25.331 +        _boxes[i].min = min;
  25.332 +        min += _boxes[i].size;
  25.333        }
  25.334 -      int curr = boxes[box].first, next;
  25.335 +      int curr = _boxes[box].first, next;
  25.336        while (curr != -1) {
  25.337 -        next = data[curr].next;
  25.338 -        bubble_down(curr);
  25.339 +        next = _data[curr].next;
  25.340 +        bubbleDown(curr);
  25.341          curr = next;
  25.342        }
  25.343      }
  25.344  
  25.345 -    void relocate_last(int index) {
  25.346 -      if (index != int(data.size()) - 1) {
  25.347 -        data[index] = data.back();
  25.348 -        if (data[index].prev != -1) {
  25.349 -          data[data[index].prev].next = index;
  25.350 +    void relocateLast(int index) {
  25.351 +      if (index != int(_data.size()) - 1) {
  25.352 +        _data[index] = _data.back();
  25.353 +        if (_data[index].prev != -1) {
  25.354 +          _data[_data[index].prev].next = index;
  25.355          } else {
  25.356 -          boxes[data[index].box].first = index;
  25.357 +          _boxes[_data[index].box].first = index;
  25.358          }
  25.359 -        if (data[index].next != -1) {
  25.360 -          data[data[index].next].prev = index;
  25.361 +        if (_data[index].next != -1) {
  25.362 +          _data[_data[index].next].prev = index;
  25.363          }
  25.364 -        _iim[data[index].item] = index;
  25.365 +        _iim[_data[index].item] = index;
  25.366        }
  25.367 -      data.pop_back();
  25.368 +      _data.pop_back();
  25.369      }
  25.370  
  25.371    public:
  25.372  
  25.373      /// \brief Insert an item into the heap with the given priority.
  25.374      ///
  25.375 -    /// Adds \c i to the heap with priority \c p.
  25.376 +    /// This function inserts the given item into the heap with the
  25.377 +    /// given priority.
  25.378      /// \param i The item to insert.
  25.379      /// \param p The priority of the item.
  25.380 +    /// \pre \e i must not be stored in the heap.
  25.381 +    /// \warning This method may throw an \c UnderFlowPriorityException.
  25.382      void push(const Item &i, const Prio &p) {
  25.383 -      int n = data.size();
  25.384 +      int n = _data.size();
  25.385        _iim.set(i, n);
  25.386 -      data.push_back(RadixItem(i, p));
  25.387 -      while (lower(boxes.size() - 1, p)) {
  25.388 +      _data.push_back(RadixItem(i, p));
  25.389 +      while (lower(_boxes.size() - 1, p)) {
  25.390          extend();
  25.391        }
  25.392 -      int box = findDown(boxes.size() - 1, p);
  25.393 +      int box = findDown(_boxes.size() - 1, p);
  25.394        insert(box, n);
  25.395      }
  25.396  
  25.397 -    /// \brief Returns the item with minimum priority.
  25.398 +    /// \brief Return the item having minimum priority.
  25.399      ///
  25.400 -    /// This method returns the item with minimum priority.
  25.401 -    /// \pre The heap must be nonempty.
  25.402 +    /// This function returns the item having minimum priority.
  25.403 +    /// \pre The heap must be non-empty.
  25.404      Item top() const {
  25.405        const_cast<RadixHeap<ItemIntMap>&>(*this).moveDown();
  25.406 -      return data[boxes[0].first].item;
  25.407 +      return _data[_boxes[0].first].item;
  25.408      }
  25.409  
  25.410 -    /// \brief Returns the minimum priority.
  25.411 +    /// \brief The minimum priority.
  25.412      ///
  25.413 -    /// It returns the minimum priority.
  25.414 -    /// \pre The heap must be nonempty.
  25.415 +    /// This function returns the minimum priority.
  25.416 +    /// \pre The heap must be non-empty.
  25.417      Prio prio() const {
  25.418        const_cast<RadixHeap<ItemIntMap>&>(*this).moveDown();
  25.419 -      return data[boxes[0].first].prio;
  25.420 +      return _data[_boxes[0].first].prio;
  25.421       }
  25.422  
  25.423 -    /// \brief Deletes the item with minimum priority.
  25.424 +    /// \brief Remove the item having minimum priority.
  25.425      ///
  25.426 -    /// This method deletes the item with minimum priority.
  25.427 +    /// This function removes the item having minimum priority.
  25.428      /// \pre The heap must be non-empty.
  25.429      void pop() {
  25.430        moveDown();
  25.431 -      int index = boxes[0].first;
  25.432 -      _iim[data[index].item] = POST_HEAP;
  25.433 +      int index = _boxes[0].first;
  25.434 +      _iim[_data[index].item] = POST_HEAP;
  25.435        remove(index);
  25.436 -      relocate_last(index);
  25.437 +      relocateLast(index);
  25.438      }
  25.439  
  25.440 -    /// \brief Deletes \c i from the heap.
  25.441 +    /// \brief Remove the given item from the heap.
  25.442      ///
  25.443 -    /// This method deletes item \c i from the heap, if \c i was
  25.444 -    /// already stored in the heap.
  25.445 -    /// \param i The item to erase.
  25.446 +    /// This function removes the given item from the heap if it is
  25.447 +    /// already stored.
  25.448 +    /// \param i The item to delete.
  25.449 +    /// \pre \e i must be in the heap.
  25.450      void erase(const Item &i) {
  25.451        int index = _iim[i];
  25.452        _iim[i] = POST_HEAP;
  25.453        remove(index);
  25.454 -      relocate_last(index);
  25.455 +      relocateLast(index);
  25.456     }
  25.457  
  25.458 -    /// \brief Returns the priority of \c i.
  25.459 +    /// \brief The priority of the given item.
  25.460      ///
  25.461 -    /// This function returns the priority of item \c i.
  25.462 -    /// \pre \c i must be in the heap.
  25.463 +    /// This function returns the priority of the given item.
  25.464      /// \param i The item.
  25.465 +    /// \pre \e i must be in the heap.
  25.466      Prio operator[](const Item &i) const {
  25.467        int idx = _iim[i];
  25.468 -      return data[idx].prio;
  25.469 +      return _data[idx].prio;
  25.470      }
  25.471  
  25.472 -    /// \brief \c i gets to the heap with priority \c p independently
  25.473 -    /// if \c i was already there.
  25.474 +    /// \brief Set the priority of an item or insert it, if it is
  25.475 +    /// not stored in the heap.
  25.476      ///
  25.477 -    /// This method calls \ref push(\c i, \c p) if \c i is not stored
  25.478 -    /// in the heap and sets the priority of \c i to \c p otherwise.
  25.479 -    /// It may throw an \e UnderFlowPriorityException.
  25.480 +    /// This method sets the priority of the given item if it is
  25.481 +    /// already stored in the heap. Otherwise it inserts the given
  25.482 +    /// item into the heap with the given priority.
  25.483      /// \param i The item.
  25.484      /// \param p The priority.
  25.485 +    /// \pre \e i must be in the heap.
  25.486 +    /// \warning This method may throw an \c UnderFlowPriorityException.
  25.487      void set(const Item &i, const Prio &p) {
  25.488        int idx = _iim[i];
  25.489        if( idx < 0 ) {
  25.490          push(i, p);
  25.491        }
  25.492 -      else if( p >= data[idx].prio ) {
  25.493 -        data[idx].prio = p;
  25.494 -        bubble_up(idx);
  25.495 +      else if( p >= _data[idx].prio ) {
  25.496 +        _data[idx].prio = p;
  25.497 +        bubbleUp(idx);
  25.498        } else {
  25.499 -        data[idx].prio = p;
  25.500 -        bubble_down(idx);
  25.501 +        _data[idx].prio = p;
  25.502 +        bubbleDown(idx);
  25.503        }
  25.504      }
  25.505  
  25.506 -
  25.507 -    /// \brief Decreases the priority of \c i to \c p.
  25.508 +    /// \brief Decrease the priority of an item to the given value.
  25.509      ///
  25.510 -    /// This method decreases the priority of item \c i to \c p.
  25.511 -    /// \pre \c i must be stored in the heap with priority at least \c p, and
  25.512 -    /// \c should be greater or equal to the last removed item's priority.
  25.513 +    /// This function decreases the priority of an item to the given value.
  25.514      /// \param i The item.
  25.515      /// \param p The priority.
  25.516 +    /// \pre \e i must be stored in the heap with priority at least \e p.
  25.517 +    /// \warning This method may throw an \c UnderFlowPriorityException.
  25.518      void decrease(const Item &i, const Prio &p) {
  25.519        int idx = _iim[i];
  25.520 -      data[idx].prio = p;
  25.521 -      bubble_down(idx);
  25.522 +      _data[idx].prio = p;
  25.523 +      bubbleDown(idx);
  25.524      }
  25.525  
  25.526 -    /// \brief Increases the priority of \c i to \c p.
  25.527 +    /// \brief Increase the priority of an item to the given value.
  25.528      ///
  25.529 -    /// This method sets the priority of item \c i to \c p.
  25.530 -    /// \pre \c i must be stored in the heap with priority at most \c p
  25.531 +    /// This function increases the priority of an item to the given value.
  25.532      /// \param i The item.
  25.533      /// \param p The priority.
  25.534 +    /// \pre \e i must be stored in the heap with priority at most \e p.
  25.535      void increase(const Item &i, const Prio &p) {
  25.536        int idx = _iim[i];
  25.537 -      data[idx].prio = p;
  25.538 -      bubble_up(idx);
  25.539 +      _data[idx].prio = p;
  25.540 +      bubbleUp(idx);
  25.541      }
  25.542  
  25.543 -    /// \brief Returns if \c item is in, has already been in, or has
  25.544 -    /// never been in the heap.
  25.545 +    /// \brief Return the state of an item.
  25.546      ///
  25.547 -    /// This method returns PRE_HEAP if \c item has never been in the
  25.548 -    /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
  25.549 -    /// otherwise. In the latter case it is possible that \c item will
  25.550 -    /// get back to the heap again.
  25.551 +    /// This method returns \c PRE_HEAP if the given item has never
  25.552 +    /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
  25.553 +    /// and \c POST_HEAP otherwise.
  25.554 +    /// In the latter case it is possible that the item will get back
  25.555 +    /// to the heap again.
  25.556      /// \param i The item.
  25.557      State state(const Item &i) const {
  25.558        int s = _iim[i];
  25.559 @@ -405,11 +410,11 @@
  25.560        return State(s);
  25.561      }
  25.562  
  25.563 -    /// \brief Sets the state of the \c item in the heap.
  25.564 +    /// \brief Set the state of an item in the heap.
  25.565      ///
  25.566 -    /// Sets the state of the \c item in the heap. It can be used to
  25.567 -    /// manually clear the heap when it is important to achive the
  25.568 -    /// better time complexity.
  25.569 +    /// This function sets the state of the given item in the heap.
  25.570 +    /// It can be used to manually clear the heap when it is important
  25.571 +    /// to achive better time complexity.
  25.572      /// \param i The item.
  25.573      /// \param st The state. It should not be \c IN_HEAP.
  25.574      void state(const Item& i, State st) {
    26.1 --- a/test/CMakeLists.txt	Fri Sep 25 12:24:16 2009 +0200
    26.2 +++ b/test/CMakeLists.txt	Sat Sep 26 07:08:10 2009 +0200
    26.3 @@ -9,6 +9,7 @@
    26.4  
    26.5  SET(TESTS
    26.6    adaptors_test
    26.7 +  bellman_ford_test
    26.8    bfs_test
    26.9    circulation_test
   26.10    connectivity_test
    27.1 --- a/test/Makefile.am	Fri Sep 25 12:24:16 2009 +0200
    27.2 +++ b/test/Makefile.am	Sat Sep 26 07:08:10 2009 +0200
    27.3 @@ -7,6 +7,7 @@
    27.4  
    27.5  check_PROGRAMS += \
    27.6  	test/adaptors_test \
    27.7 +	test/bellman_ford_test \
    27.8  	test/bfs_test \
    27.9  	test/circulation_test \
   27.10  	test/connectivity_test \
   27.11 @@ -52,6 +53,7 @@
   27.12  XFAIL_TESTS += test/test_tools_fail$(EXEEXT)
   27.13  
   27.14  test_adaptors_test_SOURCES = test/adaptors_test.cc
   27.15 +test_bellman_ford_test_SOURCES = test/bellman_ford_test.cc
   27.16  test_bfs_test_SOURCES = test/bfs_test.cc
   27.17  test_circulation_test_SOURCES = test/circulation_test.cc
   27.18  test_counter_test_SOURCES = test/counter_test.cc
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/test/bellman_ford_test.cc	Sat Sep 26 07:08:10 2009 +0200
    28.3 @@ -0,0 +1,283 @@
    28.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
    28.5 + *
    28.6 + * This file is a part of LEMON, a generic C++ optimization library.
    28.7 + *
    28.8 + * Copyright (C) 2003-2009
    28.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   28.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
   28.11 + *
   28.12 + * Permission to use, modify and distribute this software is granted
   28.13 + * provided that this copyright notice appears in all copies. For
   28.14 + * precise terms see the accompanying LICENSE file.
   28.15 + *
   28.16 + * This software is provided "AS IS" with no warranty of any kind,
   28.17 + * express or implied, and with no claim as to its suitability for any
   28.18 + * purpose.
   28.19 + *
   28.20 + */
   28.21 +
   28.22 +#include <lemon/concepts/digraph.h>
   28.23 +#include <lemon/smart_graph.h>
   28.24 +#include <lemon/list_graph.h>
   28.25 +#include <lemon/lgf_reader.h>
   28.26 +#include <lemon/bellman_ford.h>
   28.27 +#include <lemon/path.h>
   28.28 +
   28.29 +#include "graph_test.h"
   28.30 +#include "test_tools.h"
   28.31 +
   28.32 +using namespace lemon;
   28.33 +
   28.34 +char test_lgf[] =
   28.35 +  "@nodes\n"
   28.36 +  "label\n"
   28.37 +  "0\n"
   28.38 +  "1\n"
   28.39 +  "2\n"
   28.40 +  "3\n"
   28.41 +  "4\n"
   28.42 +  "@arcs\n"
   28.43 +  "    length\n"
   28.44 +  "0 1 3\n"
   28.45 +  "1 2 -3\n"
   28.46 +  "1 2 -5\n"
   28.47 +  "1 3 -2\n"
   28.48 +  "0 2 -1\n"
   28.49 +  "1 2 -4\n"
   28.50 +  "0 3 2\n"
   28.51 +  "4 2 -5\n"
   28.52 +  "2 3 1\n"
   28.53 +  "@attributes\n"
   28.54 +  "source 0\n"
   28.55 +  "target 3\n";
   28.56 +
   28.57 +
   28.58 +void checkBellmanFordCompile()
   28.59 +{
   28.60 +  typedef int Value;
   28.61 +  typedef concepts::Digraph Digraph;
   28.62 +  typedef concepts::ReadMap<Digraph::Arc,Value> LengthMap;
   28.63 +  typedef BellmanFord<Digraph, LengthMap> BF;
   28.64 +  typedef Digraph::Node Node;
   28.65 +  typedef Digraph::Arc Arc;
   28.66 +
   28.67 +  Digraph gr;
   28.68 +  Node s, t, n;
   28.69 +  Arc e;
   28.70 +  Value l;
   28.71 +  int k;
   28.72 +  bool b;
   28.73 +  BF::DistMap d(gr);
   28.74 +  BF::PredMap p(gr);
   28.75 +  LengthMap length;
   28.76 +  concepts::Path<Digraph> pp;
   28.77 +
   28.78 +  {
   28.79 +    BF bf_test(gr,length);
   28.80 +    const BF& const_bf_test = bf_test;
   28.81 +
   28.82 +    bf_test.run(s);
   28.83 +    bf_test.run(s,k);
   28.84 +
   28.85 +    bf_test.init();
   28.86 +    bf_test.addSource(s);
   28.87 +    bf_test.addSource(s, 1);
   28.88 +    b = bf_test.processNextRound();
   28.89 +    b = bf_test.processNextWeakRound();
   28.90 +
   28.91 +    bf_test.start();
   28.92 +    bf_test.checkedStart();
   28.93 +    bf_test.limitedStart(k);
   28.94 +
   28.95 +    l  = const_bf_test.dist(t);
   28.96 +    e  = const_bf_test.predArc(t);
   28.97 +    s  = const_bf_test.predNode(t);
   28.98 +    b  = const_bf_test.reached(t);
   28.99 +    d  = const_bf_test.distMap();
  28.100 +    p  = const_bf_test.predMap();
  28.101 +    pp = const_bf_test.path(t);
  28.102 +    
  28.103 +    for (BF::ActiveIt it(const_bf_test); it != INVALID; ++it) {}
  28.104 +  }
  28.105 +  {
  28.106 +    BF::SetPredMap<concepts::ReadWriteMap<Node,Arc> >
  28.107 +      ::SetDistMap<concepts::ReadWriteMap<Node,Value> >
  28.108 +      ::SetOperationTraits<BellmanFordDefaultOperationTraits<Value> >
  28.109 +      ::Create bf_test(gr,length);
  28.110 +
  28.111 +    LengthMap length_map;
  28.112 +    concepts::ReadWriteMap<Node,Arc> pred_map;
  28.113 +    concepts::ReadWriteMap<Node,Value> dist_map;
  28.114 +    
  28.115 +    bf_test
  28.116 +      .lengthMap(length_map)
  28.117 +      .predMap(pred_map)
  28.118 +      .distMap(dist_map);
  28.119 +
  28.120 +    bf_test.run(s);
  28.121 +    bf_test.run(s,k);
  28.122 +
  28.123 +    bf_test.init();
  28.124 +    bf_test.addSource(s);
  28.125 +    bf_test.addSource(s, 1);
  28.126 +    b = bf_test.processNextRound();
  28.127 +    b = bf_test.processNextWeakRound();
  28.128 +
  28.129 +    bf_test.start();
  28.130 +    bf_test.checkedStart();
  28.131 +    bf_test.limitedStart(k);
  28.132 +
  28.133 +    l  = bf_test.dist(t);
  28.134 +    e  = bf_test.predArc(t);
  28.135 +    s  = bf_test.predNode(t);
  28.136 +    b  = bf_test.reached(t);
  28.137 +    pp = bf_test.path(t);
  28.138 +  }
  28.139 +}
  28.140 +
  28.141 +void checkBellmanFordFunctionCompile()
  28.142 +{
  28.143 +  typedef int Value;
  28.144 +  typedef concepts::Digraph Digraph;
  28.145 +  typedef Digraph::Arc Arc;
  28.146 +  typedef Digraph::Node Node;
  28.147 +  typedef concepts::ReadMap<Digraph::Arc,Value> LengthMap;
  28.148 +
  28.149 +  Digraph g;
  28.150 +  bool b;
  28.151 +  bellmanFord(g,LengthMap()).run(Node());
  28.152 +  b = bellmanFord(g,LengthMap()).run(Node(),Node());
  28.153 +  bellmanFord(g,LengthMap())
  28.154 +    .predMap(concepts::ReadWriteMap<Node,Arc>())
  28.155 +    .distMap(concepts::ReadWriteMap<Node,Value>())
  28.156 +    .run(Node());
  28.157 +  b=bellmanFord(g,LengthMap())
  28.158 +    .predMap(concepts::ReadWriteMap<Node,Arc>())
  28.159 +    .distMap(concepts::ReadWriteMap<Node,Value>())
  28.160 +    .path(concepts::Path<Digraph>())
  28.161 +    .dist(Value())
  28.162 +    .run(Node(),Node());
  28.163 +}
  28.164 +
  28.165 +
  28.166 +template <typename Digraph, typename Value>
  28.167 +void checkBellmanFord() {
  28.168 +  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
  28.169 +  typedef typename Digraph::template ArcMap<Value> LengthMap;
  28.170 +
  28.171 +  Digraph gr;
  28.172 +  Node s, t;
  28.173 +  LengthMap length(gr);
  28.174 +
  28.175 +  std::istringstream input(test_lgf);
  28.176 +  digraphReader(gr, input).
  28.177 +    arcMap("length", length).
  28.178 +    node("source", s).
  28.179 +    node("target", t).
  28.180 +    run();
  28.181 +
  28.182 +  BellmanFord<Digraph, LengthMap>
  28.183 +    bf(gr, length);
  28.184 +  bf.run(s);
  28.185 +  Path<Digraph> p = bf.path(t);
  28.186 +
  28.187 +  check(bf.reached(t) && bf.dist(t) == -1, "Bellman-Ford found a wrong path.");
  28.188 +  check(p.length() == 3, "path() found a wrong path.");
  28.189 +  check(checkPath(gr, p), "path() found a wrong path.");
  28.190 +  check(pathSource(gr, p) == s, "path() found a wrong path.");
  28.191 +  check(pathTarget(gr, p) == t, "path() found a wrong path.");
  28.192 +  
  28.193 +  ListPath<Digraph> path;
  28.194 +  Value dist;
  28.195 +  bool reached = bellmanFord(gr,length).path(path).dist(dist).run(s,t);
  28.196 +
  28.197 +  check(reached && dist == -1, "Bellman-Ford found a wrong path.");
  28.198 +  check(path.length() == 3, "path() found a wrong path.");
  28.199 +  check(checkPath(gr, path), "path() found a wrong path.");
  28.200 +  check(pathSource(gr, path) == s, "path() found a wrong path.");
  28.201 +  check(pathTarget(gr, path) == t, "path() found a wrong path.");
  28.202 +
  28.203 +  for(ArcIt e(gr); e!=INVALID; ++e) {
  28.204 +    Node u=gr.source(e);
  28.205 +    Node v=gr.target(e);
  28.206 +    check(!bf.reached(u) || (bf.dist(v) - bf.dist(u) <= length[e]),
  28.207 +          "Wrong output. dist(target)-dist(source)-arc_length=" <<
  28.208 +          bf.dist(v) - bf.dist(u) - length[e]);
  28.209 +  }
  28.210 +
  28.211 +  for(NodeIt v(gr); v!=INVALID; ++v) {
  28.212 +    if (bf.reached(v)) {
  28.213 +      check(v==s || bf.predArc(v)!=INVALID, "Wrong tree.");
  28.214 +      if (bf.predArc(v)!=INVALID ) {
  28.215 +        Arc e=bf.predArc(v);
  28.216 +        Node u=gr.source(e);
  28.217 +        check(u==bf.predNode(v),"Wrong tree.");
  28.218 +        check(bf.dist(v) - bf.dist(u) == length[e],
  28.219 +              "Wrong distance! Difference: " <<
  28.220 +              bf.dist(v) - bf.dist(u) - length[e]);
  28.221 +      }
  28.222 +    }
  28.223 +  }
  28.224 +}
  28.225 +
  28.226 +void checkBellmanFordNegativeCycle() {
  28.227 +  DIGRAPH_TYPEDEFS(SmartDigraph);
  28.228 +
  28.229 +  SmartDigraph gr;
  28.230 +  IntArcMap length(gr);
  28.231 +  
  28.232 +  Node n1 = gr.addNode();
  28.233 +  Node n2 = gr.addNode();
  28.234 +  Node n3 = gr.addNode();
  28.235 +  Node n4 = gr.addNode();
  28.236 +  
  28.237 +  Arc a1 = gr.addArc(n1, n2);
  28.238 +  Arc a2 = gr.addArc(n2, n2);
  28.239 +  
  28.240 +  length[a1] = 2;
  28.241 +  length[a2] = -1;
  28.242 +  
  28.243 +  {
  28.244 +    BellmanFord<SmartDigraph, IntArcMap> bf(gr, length);
  28.245 +    bf.run(n1);
  28.246 +    StaticPath<SmartDigraph> p = bf.negativeCycle();
  28.247 +    check(p.length() == 1 && p.front() == p.back() && p.front() == a2,
  28.248 +          "Wrong negative cycle.");
  28.249 +  }
  28.250 + 
  28.251 +  length[a2] = 0;
  28.252 +  
  28.253 +  {
  28.254 +    BellmanFord<SmartDigraph, IntArcMap> bf(gr, length);
  28.255 +    bf.run(n1);
  28.256 +    check(bf.negativeCycle().empty(),
  28.257 +          "Negative cycle should not be found.");
  28.258 +  }
  28.259 +  
  28.260 +  length[gr.addArc(n1, n3)] = 5;
  28.261 +  length[gr.addArc(n4, n3)] = 1;
  28.262 +  length[gr.addArc(n2, n4)] = 2;
  28.263 +  length[gr.addArc(n3, n2)] = -4;
  28.264 +  
  28.265 +  {
  28.266 +    BellmanFord<SmartDigraph, IntArcMap> bf(gr, length);
  28.267 +    bf.init();
  28.268 +    bf.addSource(n1);
  28.269 +    for (int i = 0; i < 4; ++i) {
  28.270 +      check(bf.negativeCycle().empty(),
  28.271 +            "Negative cycle should not be found.");
  28.272 +      bf.processNextRound();
  28.273 +    }
  28.274 +    StaticPath<SmartDigraph> p = bf.negativeCycle();
  28.275 +    check(p.length() == 3, "Wrong negative cycle.");
  28.276 +    check(length[p.nth(0)] + length[p.nth(1)] + length[p.nth(2)] == -1,
  28.277 +          "Wrong negative cycle.");
  28.278 +  }
  28.279 +}
  28.280 +
  28.281 +int main() {
  28.282 +  checkBellmanFord<ListDigraph, int>();
  28.283 +  checkBellmanFord<SmartDigraph, double>();
  28.284 +  checkBellmanFordNegativeCycle();
  28.285 +  return 0;
  28.286 +}
    29.1 --- a/test/circulation_test.cc	Fri Sep 25 12:24:16 2009 +0200
    29.2 +++ b/test/circulation_test.cc	Sat Sep 26 07:08:10 2009 +0200
    29.3 @@ -87,6 +87,11 @@
    29.4      .upperMap(ucap)
    29.5      .supplyMap(supply)
    29.6      .flowMap(flow);
    29.7 +  
    29.8 +  const CirculationType::Elevator& elev = const_circ_test.elevator();
    29.9 +  circ_test.elevator(const_cast<CirculationType::Elevator&>(elev));
   29.10 +  CirculationType::Tolerance tol = const_circ_test.tolerance();
   29.11 +  circ_test.tolerance(tol);
   29.12  
   29.13    circ_test.init();
   29.14    circ_test.greedyInit();
    30.1 --- a/test/heap_test.cc	Fri Sep 25 12:24:16 2009 +0200
    30.2 +++ b/test/heap_test.cc	Sat Sep 26 07:08:10 2009 +0200
    30.3 @@ -25,14 +25,17 @@
    30.4  #include <lemon/concepts/heap.h>
    30.5  
    30.6  #include <lemon/smart_graph.h>
    30.7 -
    30.8  #include <lemon/lgf_reader.h>
    30.9  #include <lemon/dijkstra.h>
   30.10  #include <lemon/maps.h>
   30.11  
   30.12  #include <lemon/bin_heap.h>
   30.13 +#include <lemon/fourary_heap.h>
   30.14 +#include <lemon/kary_heap.h>
   30.15  #include <lemon/fib_heap.h>
   30.16 +#include <lemon/pairing_heap.h>
   30.17  #include <lemon/radix_heap.h>
   30.18 +#include <lemon/binom_heap.h>
   30.19  #include <lemon/bucket_heap.h>
   30.20  
   30.21  #include "test_tools.h"
   30.22 @@ -89,18 +92,16 @@
   30.23  template <typename Heap>
   30.24  void heapSortTest() {
   30.25    RangeMap<int> map(test_len, -1);
   30.26 -
   30.27    Heap heap(map);
   30.28  
   30.29    std::vector<int> v(test_len);
   30.30 -
   30.31    for (int i = 0; i < test_len; ++i) {
   30.32      v[i] = test_seq[i];
   30.33      heap.push(i, v[i]);
   30.34    }
   30.35    std::sort(v.begin(), v.end());
   30.36    for (int i = 0; i < test_len; ++i) {
   30.37 -    check(v[i] == heap.prio() ,"Wrong order in heap sort.");
   30.38 +    check(v[i] == heap.prio(), "Wrong order in heap sort.");
   30.39      heap.pop();
   30.40    }
   30.41  }
   30.42 @@ -112,7 +113,6 @@
   30.43    Heap heap(map);
   30.44  
   30.45    std::vector<int> v(test_len);
   30.46 -
   30.47    for (int i = 0; i < test_len; ++i) {
   30.48      v[i] = test_seq[i];
   30.49      heap.push(i, v[i]);
   30.50 @@ -123,13 +123,11 @@
   30.51    }
   30.52    std::sort(v.begin(), v.end());
   30.53    for (int i = 0; i < test_len; ++i) {
   30.54 -    check(v[i] == heap.prio() ,"Wrong order in heap increase test.");
   30.55 +    check(v[i] == heap.prio(), "Wrong order in heap increase test.");
   30.56      heap.pop();
   30.57    }
   30.58  }
   30.59  
   30.60 -
   30.61 -
   30.62  template <typename Heap>
   30.63  void dijkstraHeapTest(const Digraph& digraph, const IntArcMap& length,
   30.64                        Node source) {
   30.65 @@ -144,7 +142,7 @@
   30.66      Node t = digraph.target(a);
   30.67      if (dijkstra.reached(s)) {
   30.68        check( dijkstra.dist(t) - dijkstra.dist(s) <= length[a],
   30.69 -             "Error in a shortest path tree!");
   30.70 +             "Error in shortest path tree.");
   30.71      }
   30.72    }
   30.73  
   30.74 @@ -153,7 +151,7 @@
   30.75        Arc a = dijkstra.predArc(n);
   30.76        Node s = digraph.source(a);
   30.77        check( dijkstra.dist(n) - dijkstra.dist(s) == length[a],
   30.78 -             "Error in a shortest path tree!");
   30.79 +             "Error in shortest path tree.");
   30.80      }
   30.81    }
   30.82  
   30.83 @@ -175,6 +173,7 @@
   30.84      node("source", source).
   30.85      run();
   30.86  
   30.87 +  // BinHeap
   30.88    {
   30.89      typedef BinHeap<Prio, ItemIntMap> IntHeap;
   30.90      checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
   30.91 @@ -186,6 +185,31 @@
   30.92      dijkstraHeapTest<NodeHeap>(digraph, length, source);
   30.93    }
   30.94  
   30.95 +  // FouraryHeap
   30.96 +  {
   30.97 +    typedef FouraryHeap<Prio, ItemIntMap> IntHeap;
   30.98 +    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
   30.99 +    heapSortTest<IntHeap>();
  30.100 +    heapIncreaseTest<IntHeap>();
  30.101 +
  30.102 +    typedef FouraryHeap<Prio, IntNodeMap > NodeHeap;
  30.103 +    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
  30.104 +    dijkstraHeapTest<NodeHeap>(digraph, length, source);
  30.105 +  }
  30.106 +
  30.107 +  // KaryHeap
  30.108 +  {
  30.109 +    typedef KaryHeap<Prio, ItemIntMap> IntHeap;
  30.110 +    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
  30.111 +    heapSortTest<IntHeap>();
  30.112 +    heapIncreaseTest<IntHeap>();
  30.113 +
  30.114 +    typedef KaryHeap<Prio, IntNodeMap > NodeHeap;
  30.115 +    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
  30.116 +    dijkstraHeapTest<NodeHeap>(digraph, length, source);
  30.117 +  }
  30.118 +
  30.119 +  // FibHeap
  30.120    {
  30.121      typedef FibHeap<Prio, ItemIntMap> IntHeap;
  30.122      checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
  30.123 @@ -197,6 +221,19 @@
  30.124      dijkstraHeapTest<NodeHeap>(digraph, length, source);
  30.125    }
  30.126  
  30.127 +  // PairingHeap
  30.128 +  {
  30.129 +    typedef PairingHeap<Prio, ItemIntMap> IntHeap;
  30.130 +    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
  30.131 +    heapSortTest<IntHeap>();
  30.132 +    heapIncreaseTest<IntHeap>();
  30.133 +
  30.134 +    typedef PairingHeap<Prio, IntNodeMap > NodeHeap;
  30.135 +    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
  30.136 +    dijkstraHeapTest<NodeHeap>(digraph, length, source);
  30.137 +  }
  30.138 +
  30.139 +  // RadixHeap
  30.140    {
  30.141      typedef RadixHeap<ItemIntMap> IntHeap;
  30.142      checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
  30.143 @@ -208,6 +245,19 @@
  30.144      dijkstraHeapTest<NodeHeap>(digraph, length, source);
  30.145    }
  30.146  
  30.147 +  // BinomHeap
  30.148 +  {
  30.149 +    typedef BinomHeap<Prio, ItemIntMap> IntHeap;
  30.150 +    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
  30.151 +    heapSortTest<IntHeap>();
  30.152 +    heapIncreaseTest<IntHeap>();
  30.153 +
  30.154 +    typedef BinomHeap<Prio, IntNodeMap > NodeHeap;
  30.155 +    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
  30.156 +    dijkstraHeapTest<NodeHeap>(digraph, length, source);
  30.157 +  }
  30.158 +
  30.159 +  // BucketHeap, SimpleBucketHeap
  30.160    {
  30.161      typedef BucketHeap<ItemIntMap> IntHeap;
  30.162      checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
  30.163 @@ -217,8 +267,10 @@
  30.164      typedef BucketHeap<IntNodeMap > NodeHeap;
  30.165      checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
  30.166      dijkstraHeapTest<NodeHeap>(digraph, length, source);
  30.167 +
  30.168 +    typedef SimpleBucketHeap<ItemIntMap> SimpleIntHeap;
  30.169 +    heapSortTest<SimpleIntHeap>();
  30.170    }
  30.171  
  30.172 -
  30.173    return 0;
  30.174  }
    31.1 --- a/test/maps_test.cc	Fri Sep 25 12:24:16 2009 +0200
    31.2 +++ b/test/maps_test.cc	Sat Sep 26 07:08:10 2009 +0200
    31.3 @@ -579,6 +579,40 @@
    31.4            it == map.endValue(), "Wrong value iterator");
    31.5    }
    31.6  
    31.7 +  // CrossRefMap
    31.8 +  {
    31.9 +    typedef SmartDigraph Graph;
   31.10 +    DIGRAPH_TYPEDEFS(Graph);
   31.11 +
   31.12 +    checkConcept<ReadWriteMap<Node, int>,
   31.13 +                 CrossRefMap<Graph, Node, int> >();
   31.14 +    
   31.15 +    Graph gr;
   31.16 +    typedef CrossRefMap<Graph, Node, char> CRMap;
   31.17 +    typedef CRMap::ValueIterator ValueIt;
   31.18 +    CRMap map(gr);
   31.19 +    
   31.20 +    Node n0 = gr.addNode();
   31.21 +    Node n1 = gr.addNode();
   31.22 +    Node n2 = gr.addNode();
   31.23 +    
   31.24 +    map.set(n0, 'A');
   31.25 +    map.set(n1, 'B');
   31.26 +    map.set(n2, 'C');
   31.27 +    map.set(n2, 'A');
   31.28 +    map.set(n0, 'C');
   31.29 +
   31.30 +    check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
   31.31 +          "Wrong CrossRefMap");
   31.32 +    check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
   31.33 +    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
   31.34 +    check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
   31.35 +
   31.36 +    ValueIt it = map.beginValue();
   31.37 +    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
   31.38 +          it == map.endValue(), "Wrong value iterator");
   31.39 +  }
   31.40 +  
   31.41    // Iterable bool map
   31.42    {
   31.43      typedef SmartGraph Graph;
    32.1 --- a/test/preflow_test.cc	Fri Sep 25 12:24:16 2009 +0200
    32.2 +++ b/test/preflow_test.cc	Sat Sep 26 07:08:10 2009 +0200
    32.3 @@ -94,6 +94,11 @@
    32.4              ::Create PreflowType;
    32.5    PreflowType preflow_test(g, cap, n, n);
    32.6    const PreflowType& const_preflow_test = preflow_test;
    32.7 +  
    32.8 +  const PreflowType::Elevator& elev = const_preflow_test.elevator();
    32.9 +  preflow_test.elevator(const_cast<PreflowType::Elevator&>(elev));
   32.10 +  PreflowType::Tolerance tol = const_preflow_test.tolerance();
   32.11 +  preflow_test.tolerance(tol);
   32.12  
   32.13    preflow_test
   32.14      .capacityMap(cap)
    33.1 --- a/tools/lemon-0.x-to-1.x.sh	Fri Sep 25 12:24:16 2009 +0200
    33.2 +++ b/tools/lemon-0.x-to-1.x.sh	Sat Sep 26 07:08:10 2009 +0200
    33.3 @@ -35,10 +35,10 @@
    33.4          -e "s/IncEdgeIt/_In_cEd_geIt_label_/g"\
    33.5          -e "s/Edge\>/_Ar_c_label_/g"\
    33.6          -e "s/\<edge\>/_ar_c_label_/g"\
    33.7 -        -e "s/_edge\>/_ar_c_label_/g"\
    33.8 +        -e "s/_edge\>/__ar_c_label_/g"\
    33.9          -e "s/Edges\>/_Ar_c_label_s/g"\
   33.10          -e "s/\<edges\>/_ar_c_label_s/g"\
   33.11 -        -e "s/_edges\>/_ar_c_label_s/g"\
   33.12 +        -e "s/_edges\>/__ar_c_label_s/g"\
   33.13          -e "s/\([Ee]\)dge\([a-z]\)/_\1d_ge_label_\2/g"\
   33.14          -e "s/\([a-z]\)edge/\1_ed_ge_label_/g"\
   33.15          -e "s/Edge/_Ar_c_label_/g"\
   33.16 @@ -68,6 +68,11 @@
   33.17          -e "s/_blu_e_label_/blue/g"\
   33.18          -e "s/_GR_APH_TY_PEDE_FS_label_/GRAPH_TYPEDEFS/g"\
   33.19          -e "s/_DIGR_APH_TY_PEDE_FS_label_/DIGRAPH_TYPEDEFS/g"\
   33.20 +        -e "s/\<digraph_adaptor\.h\>/adaptors.h/g"\
   33.21 +        -e "s/\<digraph_utils\.h\>/core.h/g"\
   33.22 +        -e "s/\<digraph_reader\.h\>/lgf_reader.h/g"\
   33.23 +        -e "s/\<digraph_writer\.h\>/lgf_writer.h/g"\
   33.24 +        -e "s/\<topology\.h\>/connectivity.h/g"\
   33.25          -e "s/DigraphToEps/GraphToEps/g"\
   33.26          -e "s/digraphToEps/graphToEps/g"\
   33.27          -e "s/\<DefPredMap\>/SetPredMap/g"\