1.1 --- a/lemon/bfs.h Fri Aug 09 11:07:27 2013 +0200
1.2 +++ b/lemon/bfs.h Sun Aug 11 15:28:12 2013 +0200
1.3 @@ -2,7 +2,7 @@
1.4 *
1.5 * This file is a part of LEMON, a generic C++ optimization library.
1.6 *
1.7 - * Copyright (C) 2003-2009
1.8 + * Copyright (C) 2003-2010
1.9 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 *
1.12 @@ -47,7 +47,7 @@
1.13 ///
1.14 ///The type of the map that stores the predecessor
1.15 ///arcs of the shortest paths.
1.16 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
1.17 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
1.18 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
1.19 ///Instantiates a \c PredMap.
1.20
1.21 @@ -62,7 +62,8 @@
1.22 ///The type of the map that indicates which nodes are processed.
1.23
1.24 ///The type of the map that indicates which nodes are processed.
1.25 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
1.26 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
1.27 + ///By default, it is a NullMap.
1.28 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
1.29 ///Instantiates a \c ProcessedMap.
1.30
1.31 @@ -81,7 +82,8 @@
1.32 ///The type of the map that indicates which nodes are reached.
1.33
1.34 ///The type of the map that indicates which nodes are reached.
1.35 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
1.36 + ///It must conform to
1.37 + ///the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
1.38 typedef typename Digraph::template NodeMap<bool> ReachedMap;
1.39 ///Instantiates a \c ReachedMap.
1.40
1.41 @@ -96,7 +98,7 @@
1.42 ///The type of the map that stores the distances of the nodes.
1.43
1.44 ///The type of the map that stores the distances of the nodes.
1.45 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
1.46 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
1.47 typedef typename Digraph::template NodeMap<int> DistMap;
1.48 ///Instantiates a \c DistMap.
1.49
1.50 @@ -120,6 +122,11 @@
1.51 ///
1.52 ///\tparam GR The type of the digraph the algorithm runs on.
1.53 ///The default type is \ref ListDigraph.
1.54 + ///\tparam TR The traits class that defines various types used by the
1.55 + ///algorithm. By default, it is \ref BfsDefaultTraits
1.56 + ///"BfsDefaultTraits<GR>".
1.57 + ///In most cases, this parameter should not be set directly,
1.58 + ///consider to use the named template parameters instead.
1.59 #ifdef DOXYGEN
1.60 template <typename GR,
1.61 typename TR>
1.62 @@ -225,7 +232,7 @@
1.63 ///
1.64 ///\ref named-templ-param "Named parameter" for setting
1.65 ///\c PredMap type.
1.66 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
1.67 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
1.68 template <class T>
1.69 struct SetPredMap : public Bfs< Digraph, SetPredMapTraits<T> > {
1.70 typedef Bfs< Digraph, SetPredMapTraits<T> > Create;
1.71 @@ -245,7 +252,7 @@
1.72 ///
1.73 ///\ref named-templ-param "Named parameter" for setting
1.74 ///\c DistMap type.
1.75 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
1.76 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
1.77 template <class T>
1.78 struct SetDistMap : public Bfs< Digraph, SetDistMapTraits<T> > {
1.79 typedef Bfs< Digraph, SetDistMapTraits<T> > Create;
1.80 @@ -265,7 +272,8 @@
1.81 ///
1.82 ///\ref named-templ-param "Named parameter" for setting
1.83 ///\c ReachedMap type.
1.84 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
1.85 + ///It must conform to
1.86 + ///the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
1.87 template <class T>
1.88 struct SetReachedMap : public Bfs< Digraph, SetReachedMapTraits<T> > {
1.89 typedef Bfs< Digraph, SetReachedMapTraits<T> > Create;
1.90 @@ -285,7 +293,7 @@
1.91 ///
1.92 ///\ref named-templ-param "Named parameter" for setting
1.93 ///\c ProcessedMap type.
1.94 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
1.95 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
1.96 template <class T>
1.97 struct SetProcessedMap : public Bfs< Digraph, SetProcessedMapTraits<T> > {
1.98 typedef Bfs< Digraph, SetProcessedMapTraits<T> > Create;
1.99 @@ -413,8 +421,8 @@
1.100 ///\name Execution Control
1.101 ///The simplest way to execute the BFS algorithm is to use one of the
1.102 ///member functions called \ref run(Node) "run()".\n
1.103 - ///If you need more control on the execution, first you have to call
1.104 - ///\ref init(), then you can add several source nodes with
1.105 + ///If you need better control on the execution, you have to call
1.106 + ///\ref init() first, then you can add several source nodes with
1.107 ///\ref addSource(). Finally the actual path computation can be
1.108 ///performed with one of the \ref start() functions.
1.109
1.110 @@ -700,12 +708,8 @@
1.111
1.112 ///Runs the algorithm to visit all nodes in the digraph.
1.113
1.114 - ///This method runs the %BFS algorithm in order to
1.115 - ///compute the shortest path to each node.
1.116 - ///
1.117 - ///The algorithm computes
1.118 - ///- the shortest path tree (forest),
1.119 - ///- the distance of each node from the root(s).
1.120 + ///This method runs the %BFS algorithm in order to visit all nodes
1.121 + ///in the digraph.
1.122 ///
1.123 ///\note <tt>b.run(s)</tt> is just a shortcut of the following code.
1.124 ///\code
1.125 @@ -737,9 +741,9 @@
1.126
1.127 ///@{
1.128
1.129 - ///The shortest path to a node.
1.130 + ///The shortest path to the given node.
1.131
1.132 - ///Returns the shortest path to a node.
1.133 + ///Returns the shortest path to the given node from the root(s).
1.134 ///
1.135 ///\warning \c t should be reached from the root(s).
1.136 ///
1.137 @@ -747,9 +751,9 @@
1.138 ///must be called before using this function.
1.139 Path path(Node t) const { return Path(*G, *_pred, t); }
1.140
1.141 - ///The distance of a node from the root(s).
1.142 + ///The distance of the given node from the root(s).
1.143
1.144 - ///Returns the distance of a node from the root(s).
1.145 + ///Returns the distance of the given node from the root(s).
1.146 ///
1.147 ///\warning If node \c v is not reached from the root(s), then
1.148 ///the return value of this function is undefined.
1.149 @@ -758,29 +762,31 @@
1.150 ///must be called before using this function.
1.151 int dist(Node v) const { return (*_dist)[v]; }
1.152
1.153 - ///Returns the 'previous arc' of the shortest path tree for a node.
1.154 -
1.155 + ///\brief Returns the 'previous arc' of the shortest path tree for
1.156 + ///the given node.
1.157 + ///
1.158 ///This function returns the 'previous arc' of the shortest path
1.159 ///tree for the node \c v, i.e. it returns the last arc of a
1.160 ///shortest path from a root to \c v. It is \c INVALID if \c v
1.161 ///is not reached from the root(s) or if \c v is a root.
1.162 ///
1.163 ///The shortest path tree used here is equal to the shortest path
1.164 - ///tree used in \ref predNode().
1.165 + ///tree used in \ref predNode() and \ref predMap().
1.166 ///
1.167 ///\pre Either \ref run(Node) "run()" or \ref init()
1.168 ///must be called before using this function.
1.169 Arc predArc(Node v) const { return (*_pred)[v];}
1.170
1.171 - ///Returns the 'previous node' of the shortest path tree for a node.
1.172 -
1.173 + ///\brief Returns the 'previous node' of the shortest path tree for
1.174 + ///the given node.
1.175 + ///
1.176 ///This function returns the 'previous node' of the shortest path
1.177 ///tree for the node \c v, i.e. it returns the last but one node
1.178 - ///from a shortest path from a root to \c v. It is \c INVALID
1.179 + ///of a shortest path from a root to \c v. It is \c INVALID
1.180 ///if \c v is not reached from the root(s) or if \c v is a root.
1.181 ///
1.182 ///The shortest path tree used here is equal to the shortest path
1.183 - ///tree used in \ref predArc().
1.184 + ///tree used in \ref predArc() and \ref predMap().
1.185 ///
1.186 ///\pre Either \ref run(Node) "run()" or \ref init()
1.187 ///must be called before using this function.
1.188 @@ -801,13 +807,13 @@
1.189 ///predecessor arcs.
1.190 ///
1.191 ///Returns a const reference to the node map that stores the predecessor
1.192 - ///arcs, which form the shortest path tree.
1.193 + ///arcs, which form the shortest path tree (forest).
1.194 ///
1.195 ///\pre Either \ref run(Node) "run()" or \ref init()
1.196 ///must be called before using this function.
1.197 const PredMap &predMap() const { return *_pred;}
1.198
1.199 - ///Checks if a node is reached from the root(s).
1.200 + ///Checks if the given node is reached from the root(s).
1.201
1.202 ///Returns \c true if \c v is reached from the root(s).
1.203 ///
1.204 @@ -833,7 +839,7 @@
1.205 ///
1.206 ///The type of the map that stores the predecessor
1.207 ///arcs of the shortest paths.
1.208 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
1.209 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
1.210 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
1.211 ///Instantiates a PredMap.
1.212
1.213 @@ -848,8 +854,8 @@
1.214 ///The type of the map that indicates which nodes are processed.
1.215
1.216 ///The type of the map that indicates which nodes are processed.
1.217 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
1.218 - ///By default it is a NullMap.
1.219 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
1.220 + ///By default, it is a NullMap.
1.221 typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
1.222 ///Instantiates a ProcessedMap.
1.223
1.224 @@ -868,7 +874,8 @@
1.225 ///The type of the map that indicates which nodes are reached.
1.226
1.227 ///The type of the map that indicates which nodes are reached.
1.228 - ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
1.229 + ///It must conform to
1.230 + ///the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
1.231 typedef typename Digraph::template NodeMap<bool> ReachedMap;
1.232 ///Instantiates a ReachedMap.
1.233
1.234 @@ -883,7 +890,7 @@
1.235 ///The type of the map that stores the distances of the nodes.
1.236
1.237 ///The type of the map that stores the distances of the nodes.
1.238 - ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
1.239 + ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
1.240 typedef typename Digraph::template NodeMap<int> DistMap;
1.241 ///Instantiates a DistMap.
1.242
1.243 @@ -898,18 +905,14 @@
1.244 ///The type of the shortest paths.
1.245
1.246 ///The type of the shortest paths.
1.247 - ///It must meet the \ref concepts::Path "Path" concept.
1.248 + ///It must conform to the \ref concepts::Path "Path" concept.
1.249 typedef lemon::Path<Digraph> Path;
1.250 };
1.251
1.252 /// Default traits class used by BfsWizard
1.253
1.254 - /// To make it easier to use Bfs algorithm
1.255 - /// we have created a wizard class.
1.256 - /// This \ref BfsWizard class needs default traits,
1.257 - /// as well as the \ref Bfs class.
1.258 - /// The \ref BfsWizardBase is a class to be the default traits of the
1.259 - /// \ref BfsWizard class.
1.260 + /// Default traits class used by BfsWizard.
1.261 + /// \tparam GR The type of the digraph.
1.262 template<class GR>
1.263 class BfsWizardBase : public BfsWizardDefaultTraits<GR>
1.264 {
1.265 @@ -937,7 +940,7 @@
1.266 public:
1.267 /// Constructor.
1.268
1.269 - /// This constructor does not require parameters, therefore it initiates
1.270 + /// This constructor does not require parameters, it initiates
1.271 /// all of the attributes to \c 0.
1.272 BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
1.273 _dist(0), _path(0), _di(0) {}
1.274 @@ -962,12 +965,14 @@
1.275 ///
1.276 /// This class should only be used through the \ref bfs() function,
1.277 /// which makes it easier to use the algorithm.
1.278 + ///
1.279 + /// \tparam TR The traits class that defines various types used by the
1.280 + /// algorithm.
1.281 template<class TR>
1.282 class BfsWizard : public TR
1.283 {
1.284 typedef TR Base;
1.285
1.286 - ///The type of the digraph the algorithm runs on.
1.287 typedef typename TR::Digraph Digraph;
1.288
1.289 typedef typename Digraph::Node Node;
1.290 @@ -975,16 +980,10 @@
1.291 typedef typename Digraph::Arc Arc;
1.292 typedef typename Digraph::OutArcIt OutArcIt;
1.293
1.294 - ///\brief The type of the map that stores the predecessor
1.295 - ///arcs of the shortest paths.
1.296 typedef typename TR::PredMap PredMap;
1.297 - ///\brief The type of the map that stores the distances of the nodes.
1.298 typedef typename TR::DistMap DistMap;
1.299 - ///\brief The type of the map that indicates which nodes are reached.
1.300 typedef typename TR::ReachedMap ReachedMap;
1.301 - ///\brief The type of the map that indicates which nodes are processed.
1.302 typedef typename TR::ProcessedMap ProcessedMap;
1.303 - ///The type of the shortest paths
1.304 typedef typename TR::Path Path;
1.305
1.306 public:
1.307 @@ -1054,8 +1053,8 @@
1.308
1.309 ///Runs BFS algorithm to visit all nodes in the digraph.
1.310
1.311 - ///This method runs BFS algorithm in order to compute
1.312 - ///the shortest path to each node.
1.313 + ///This method runs BFS algorithm in order to visit all nodes
1.314 + ///in the digraph.
1.315 void run()
1.316 {
1.317 run(INVALID);
1.318 @@ -1067,11 +1066,12 @@
1.319 static PredMap *createPredMap(const Digraph &) { return 0; };
1.320 SetPredMapBase(const TR &b) : TR(b) {}
1.321 };
1.322 - ///\brief \ref named-func-param "Named parameter"
1.323 - ///for setting PredMap object.
1.324 +
1.325 + ///\brief \ref named-templ-param "Named parameter" for setting
1.326 + ///the predecessor map.
1.327 ///
1.328 - ///\ref named-func-param "Named parameter"
1.329 - ///for setting PredMap object.
1.330 + ///\ref named-templ-param "Named parameter" function for setting
1.331 + ///the map that stores the predecessor arcs of the nodes.
1.332 template<class T>
1.333 BfsWizard<SetPredMapBase<T> > predMap(const T &t)
1.334 {
1.335 @@ -1085,11 +1085,12 @@
1.336 static ReachedMap *createReachedMap(const Digraph &) { return 0; };
1.337 SetReachedMapBase(const TR &b) : TR(b) {}
1.338 };
1.339 - ///\brief \ref named-func-param "Named parameter"
1.340 - ///for setting ReachedMap object.
1.341 +
1.342 + ///\brief \ref named-templ-param "Named parameter" for setting
1.343 + ///the reached map.
1.344 ///
1.345 - /// \ref named-func-param "Named parameter"
1.346 - ///for setting ReachedMap object.
1.347 + ///\ref named-templ-param "Named parameter" function for setting
1.348 + ///the map that indicates which nodes are reached.
1.349 template<class T>
1.350 BfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
1.351 {
1.352 @@ -1103,11 +1104,13 @@
1.353 static DistMap *createDistMap(const Digraph &) { return 0; };
1.354 SetDistMapBase(const TR &b) : TR(b) {}
1.355 };
1.356 - ///\brief \ref named-func-param "Named parameter"
1.357 - ///for setting DistMap object.
1.358 +
1.359 + ///\brief \ref named-templ-param "Named parameter" for setting
1.360 + ///the distance map.
1.361 ///
1.362 - /// \ref named-func-param "Named parameter"
1.363 - ///for setting DistMap object.
1.364 + ///\ref named-templ-param "Named parameter" function for setting
1.365 + ///the map that stores the distances of the nodes calculated
1.366 + ///by the algorithm.
1.367 template<class T>
1.368 BfsWizard<SetDistMapBase<T> > distMap(const T &t)
1.369 {
1.370 @@ -1121,11 +1124,12 @@
1.371 static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
1.372 SetProcessedMapBase(const TR &b) : TR(b) {}
1.373 };
1.374 - ///\brief \ref named-func-param "Named parameter"
1.375 - ///for setting ProcessedMap object.
1.376 +
1.377 + ///\brief \ref named-func-param "Named parameter" for setting
1.378 + ///the processed map.
1.379 ///
1.380 - /// \ref named-func-param "Named parameter"
1.381 - ///for setting ProcessedMap object.
1.382 + ///\ref named-templ-param "Named parameter" function for setting
1.383 + ///the map that indicates which nodes are processed.
1.384 template<class T>
1.385 BfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
1.386 {
1.387 @@ -1265,7 +1269,8 @@
1.388 /// \brief The type of the map that indicates which nodes are reached.
1.389 ///
1.390 /// The type of the map that indicates which nodes are reached.
1.391 - /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
1.392 + /// It must conform to
1.393 + ///the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
1.394 typedef typename Digraph::template NodeMap<bool> ReachedMap;
1.395
1.396 /// \brief Instantiates a ReachedMap.
1.397 @@ -1303,11 +1308,11 @@
1.398 /// \ref BfsVisitor "BfsVisitor<GR>" is an empty visitor, which
1.399 /// does not observe the BFS events. If you want to observe the BFS
1.400 /// events, you should implement your own visitor class.
1.401 - /// \tparam TR Traits class to set various data types used by the
1.402 - /// algorithm. The default traits class is
1.403 - /// \ref BfsVisitDefaultTraits "BfsVisitDefaultTraits<GR>".
1.404 - /// See \ref BfsVisitDefaultTraits for the documentation of
1.405 - /// a BFS visit traits class.
1.406 + /// \tparam TR The traits class that defines various types used by the
1.407 + /// algorithm. By default, it is \ref BfsVisitDefaultTraits
1.408 + /// "BfsVisitDefaultTraits<GR>".
1.409 + /// In most cases, this parameter should not be set directly,
1.410 + /// consider to use the named template parameters instead.
1.411 #ifdef DOXYGEN
1.412 template <typename GR, typename VS, typename TR>
1.413 #else
1.414 @@ -1426,8 +1431,8 @@
1.415 /// \name Execution Control
1.416 /// The simplest way to execute the BFS algorithm is to use one of the
1.417 /// member functions called \ref run(Node) "run()".\n
1.418 - /// If you need more control on the execution, first you have to call
1.419 - /// \ref init(), then you can add several source nodes with
1.420 + /// If you need better control on the execution, you have to call
1.421 + /// \ref init() first, then you can add several source nodes with
1.422 /// \ref addSource(). Finally the actual path computation can be
1.423 /// performed with one of the \ref start() functions.
1.424
1.425 @@ -1699,12 +1704,8 @@
1.426
1.427 /// \brief Runs the algorithm to visit all nodes in the digraph.
1.428 ///
1.429 - /// This method runs the %BFS algorithm in order to
1.430 - /// compute the shortest path to each node.
1.431 - ///
1.432 - /// The algorithm computes
1.433 - /// - the shortest path tree (forest),
1.434 - /// - the distance of each node from the root(s).
1.435 + /// This method runs the %BFS algorithm in order to visit all nodes
1.436 + /// in the digraph.
1.437 ///
1.438 /// \note <tt>b.run(s)</tt> is just a shortcut of the following code.
1.439 ///\code
1.440 @@ -1736,7 +1737,7 @@
1.441
1.442 ///@{
1.443
1.444 - /// \brief Checks if a node is reached from the root(s).
1.445 + /// \brief Checks if the given node is reached from the root(s).
1.446 ///
1.447 /// Returns \c true if \c v is reached from the root(s).
1.448 ///