lemon/dfs.h
changeset 942 2b6bffe0e7e8
parent 937 17e36e175725
parent 877 141f9c0db4a3
child 944 02c93d1f00d7
child 964 7fdaa05a69a1
     1.1 --- a/lemon/dfs.h	Tue Dec 20 17:44:38 2011 +0100
     1.2 +++ b/lemon/dfs.h	Tue Dec 20 18:15:14 2011 +0100
     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 %DFS 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 DfsDefaultTraits
    1.56 +  ///"DfsDefaultTraits<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 @@ -224,7 +231,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 Dfs<Digraph, SetPredMapTraits<T> > {
    1.70        typedef Dfs<Digraph, SetPredMapTraits<T> > Create;
    1.71 @@ -244,7 +251,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 Dfs< Digraph, SetDistMapTraits<T> > {
    1.79        typedef Dfs<Digraph, SetDistMapTraits<T> > Create;
    1.80 @@ -264,7 +271,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 Dfs< Digraph, SetReachedMapTraits<T> > {
    1.89        typedef Dfs< Digraph, SetReachedMapTraits<T> > Create;
    1.90 @@ -284,7 +292,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 Dfs< Digraph, SetProcessedMapTraits<T> > {
    1.98        typedef Dfs< Digraph, SetProcessedMapTraits<T> > Create;
    1.99 @@ -411,8 +419,8 @@
   1.100      ///\name Execution Control
   1.101      ///The simplest way to execute the DFS 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 a source node with \ref addSource()
   1.105 +    ///If you need better control on the execution, you have to call
   1.106 +    ///\ref init() first, then you can add a source node with \ref addSource()
   1.107      ///and perform the actual computation with \ref start().
   1.108      ///This procedure can be repeated if there are nodes that have not
   1.109      ///been reached.
   1.110 @@ -632,12 +640,8 @@
   1.111  
   1.112      ///Runs the algorithm to visit all nodes in the digraph.
   1.113  
   1.114 -    ///This method runs the %DFS algorithm in order to compute the
   1.115 -    ///%DFS path to each node.
   1.116 -    ///
   1.117 -    ///The algorithm computes
   1.118 -    ///- the %DFS tree (forest),
   1.119 -    ///- the distance of each node from the root(s) in the %DFS tree.
   1.120 +    ///This method runs the %DFS algorithm in order to visit all nodes
   1.121 +    ///in the digraph.
   1.122      ///
   1.123      ///\note <tt>d.run()</tt> is just a shortcut of the following code.
   1.124      ///\code
   1.125 @@ -669,9 +673,9 @@
   1.126  
   1.127      ///@{
   1.128  
   1.129 -    ///The DFS path to a node.
   1.130 +    ///The DFS path to the given node.
   1.131  
   1.132 -    ///Returns the DFS path to a node.
   1.133 +    ///Returns the DFS 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 @@ -679,9 +683,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 @@ -690,7 +694,7 @@
   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 %DFS tree for a node.
   1.154 +    ///Returns the 'previous arc' of the %DFS tree for the given node.
   1.155  
   1.156      ///This function returns the 'previous arc' of the %DFS tree for the
   1.157      ///node \c v, i.e. it returns the last arc of a %DFS path from a
   1.158 @@ -698,21 +702,21 @@
   1.159      ///root(s) or if \c v is a root.
   1.160      ///
   1.161      ///The %DFS tree used here is equal to the %DFS tree used in
   1.162 -    ///\ref predNode().
   1.163 +    ///\ref predNode() and \ref predMap().
   1.164      ///
   1.165      ///\pre Either \ref run(Node) "run()" or \ref init()
   1.166      ///must be called before using this function.
   1.167      Arc predArc(Node v) const { return (*_pred)[v];}
   1.168  
   1.169 -    ///Returns the 'previous node' of the %DFS tree.
   1.170 +    ///Returns the 'previous node' of the %DFS tree for the given node.
   1.171  
   1.172      ///This function returns the 'previous node' of the %DFS
   1.173      ///tree for the node \c v, i.e. it returns the last but one node
   1.174 -    ///from a %DFS path from a root to \c v. It is \c INVALID
   1.175 +    ///of a %DFS path from a root to \c v. It is \c INVALID
   1.176      ///if \c v is not reached from the root(s) or if \c v is a root.
   1.177      ///
   1.178      ///The %DFS tree used here is equal to the %DFS tree used in
   1.179 -    ///\ref predArc().
   1.180 +    ///\ref predArc() and \ref predMap().
   1.181      ///
   1.182      ///\pre Either \ref run(Node) "run()" or \ref init()
   1.183      ///must be called before using this function.
   1.184 @@ -733,13 +737,13 @@
   1.185      ///predecessor arcs.
   1.186      ///
   1.187      ///Returns a const reference to the node map that stores the predecessor
   1.188 -    ///arcs, which form the DFS tree.
   1.189 +    ///arcs, which form the DFS tree (forest).
   1.190      ///
   1.191      ///\pre Either \ref run(Node) "run()" or \ref init()
   1.192      ///must be called before using this function.
   1.193      const PredMap &predMap() const { return *_pred;}
   1.194  
   1.195 -    ///Checks if a node is reached from the root(s).
   1.196 +    ///Checks if the given node. node is reached from the root(s).
   1.197  
   1.198      ///Returns \c true if \c v is reached from the root(s).
   1.199      ///
   1.200 @@ -765,7 +769,7 @@
   1.201      ///
   1.202      ///The type of the map that stores the predecessor
   1.203      ///arcs of the %DFS paths.
   1.204 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   1.205 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   1.206      typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
   1.207      ///Instantiates a PredMap.
   1.208  
   1.209 @@ -780,8 +784,8 @@
   1.210      ///The type of the map that indicates which nodes are processed.
   1.211  
   1.212      ///The type of the map that indicates which nodes are processed.
   1.213 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   1.214 -    ///By default it is a NullMap.
   1.215 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   1.216 +    ///By default, it is a NullMap.
   1.217      typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
   1.218      ///Instantiates a ProcessedMap.
   1.219  
   1.220 @@ -800,7 +804,8 @@
   1.221      ///The type of the map that indicates which nodes are reached.
   1.222  
   1.223      ///The type of the map that indicates which nodes are reached.
   1.224 -    ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   1.225 +    ///It must conform to
   1.226 +    ///the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   1.227      typedef typename Digraph::template NodeMap<bool> ReachedMap;
   1.228      ///Instantiates a ReachedMap.
   1.229  
   1.230 @@ -815,7 +820,7 @@
   1.231      ///The type of the map that stores the distances of the nodes.
   1.232  
   1.233      ///The type of the map that stores the distances of the nodes.
   1.234 -    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
   1.235 +    ///It must conform to the \ref concepts::WriteMap "WriteMap" concept.
   1.236      typedef typename Digraph::template NodeMap<int> DistMap;
   1.237      ///Instantiates a DistMap.
   1.238  
   1.239 @@ -830,18 +835,14 @@
   1.240      ///The type of the DFS paths.
   1.241  
   1.242      ///The type of the DFS paths.
   1.243 -    ///It must meet the \ref concepts::Path "Path" concept.
   1.244 +    ///It must conform to the \ref concepts::Path "Path" concept.
   1.245      typedef lemon::Path<Digraph> Path;
   1.246    };
   1.247  
   1.248    /// Default traits class used by DfsWizard
   1.249  
   1.250 -  /// To make it easier to use Dfs algorithm
   1.251 -  /// we have created a wizard class.
   1.252 -  /// This \ref DfsWizard class needs default traits,
   1.253 -  /// as well as the \ref Dfs class.
   1.254 -  /// The \ref DfsWizardBase is a class to be the default traits of the
   1.255 -  /// \ref DfsWizard class.
   1.256 +  /// Default traits class used by DfsWizard.
   1.257 +  /// \tparam GR The type of the digraph.
   1.258    template<class GR>
   1.259    class DfsWizardBase : public DfsWizardDefaultTraits<GR>
   1.260    {
   1.261 @@ -869,7 +870,7 @@
   1.262      public:
   1.263      /// Constructor.
   1.264  
   1.265 -    /// This constructor does not require parameters, therefore it initiates
   1.266 +    /// This constructor does not require parameters, it initiates
   1.267      /// all of the attributes to \c 0.
   1.268      DfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
   1.269                        _dist(0), _path(0), _di(0) {}
   1.270 @@ -894,12 +895,14 @@
   1.271    ///
   1.272    /// This class should only be used through the \ref dfs() function,
   1.273    /// which makes it easier to use the algorithm.
   1.274 +  ///
   1.275 +  /// \tparam TR The traits class that defines various types used by the
   1.276 +  /// algorithm.
   1.277    template<class TR>
   1.278    class DfsWizard : public TR
   1.279    {
   1.280      typedef TR Base;
   1.281  
   1.282 -    ///The type of the digraph the algorithm runs on.
   1.283      typedef typename TR::Digraph Digraph;
   1.284  
   1.285      typedef typename Digraph::Node Node;
   1.286 @@ -907,16 +910,10 @@
   1.287      typedef typename Digraph::Arc Arc;
   1.288      typedef typename Digraph::OutArcIt OutArcIt;
   1.289  
   1.290 -    ///\brief The type of the map that stores the predecessor
   1.291 -    ///arcs of the DFS paths.
   1.292      typedef typename TR::PredMap PredMap;
   1.293 -    ///\brief The type of the map that stores the distances of the nodes.
   1.294      typedef typename TR::DistMap DistMap;
   1.295 -    ///\brief The type of the map that indicates which nodes are reached.
   1.296      typedef typename TR::ReachedMap ReachedMap;
   1.297 -    ///\brief The type of the map that indicates which nodes are processed.
   1.298      typedef typename TR::ProcessedMap ProcessedMap;
   1.299 -    ///The type of the DFS paths
   1.300      typedef typename TR::Path Path;
   1.301  
   1.302    public:
   1.303 @@ -986,8 +983,8 @@
   1.304  
   1.305      ///Runs DFS algorithm to visit all nodes in the digraph.
   1.306  
   1.307 -    ///This method runs DFS algorithm in order to compute
   1.308 -    ///the DFS path to each node.
   1.309 +    ///This method runs DFS algorithm in order to visit all nodes
   1.310 +    ///in the digraph.
   1.311      void run()
   1.312      {
   1.313        run(INVALID);
   1.314 @@ -999,11 +996,12 @@
   1.315        static PredMap *createPredMap(const Digraph &) { return 0; };
   1.316        SetPredMapBase(const TR &b) : TR(b) {}
   1.317      };
   1.318 -    ///\brief \ref named-func-param "Named parameter"
   1.319 -    ///for setting PredMap object.
   1.320 +
   1.321 +    ///\brief \ref named-templ-param "Named parameter" for setting
   1.322 +    ///the predecessor map.
   1.323      ///
   1.324 -    ///\ref named-func-param "Named parameter"
   1.325 -    ///for setting PredMap object.
   1.326 +    ///\ref named-templ-param "Named parameter" function for setting
   1.327 +    ///the map that stores the predecessor arcs of the nodes.
   1.328      template<class T>
   1.329      DfsWizard<SetPredMapBase<T> > predMap(const T &t)
   1.330      {
   1.331 @@ -1017,11 +1015,12 @@
   1.332        static ReachedMap *createReachedMap(const Digraph &) { return 0; };
   1.333        SetReachedMapBase(const TR &b) : TR(b) {}
   1.334      };
   1.335 -    ///\brief \ref named-func-param "Named parameter"
   1.336 -    ///for setting ReachedMap object.
   1.337 +
   1.338 +    ///\brief \ref named-templ-param "Named parameter" for setting
   1.339 +    ///the reached map.
   1.340      ///
   1.341 -    /// \ref named-func-param "Named parameter"
   1.342 -    ///for setting ReachedMap object.
   1.343 +    ///\ref named-templ-param "Named parameter" function for setting
   1.344 +    ///the map that indicates which nodes are reached.
   1.345      template<class T>
   1.346      DfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
   1.347      {
   1.348 @@ -1035,11 +1034,13 @@
   1.349        static DistMap *createDistMap(const Digraph &) { return 0; };
   1.350        SetDistMapBase(const TR &b) : TR(b) {}
   1.351      };
   1.352 -    ///\brief \ref named-func-param "Named parameter"
   1.353 -    ///for setting DistMap object.
   1.354 +
   1.355 +    ///\brief \ref named-templ-param "Named parameter" for setting
   1.356 +    ///the distance map.
   1.357      ///
   1.358 -    /// \ref named-func-param "Named parameter"
   1.359 -    ///for setting DistMap object.
   1.360 +    ///\ref named-templ-param "Named parameter" function for setting
   1.361 +    ///the map that stores the distances of the nodes calculated
   1.362 +    ///by the algorithm.
   1.363      template<class T>
   1.364      DfsWizard<SetDistMapBase<T> > distMap(const T &t)
   1.365      {
   1.366 @@ -1053,11 +1054,12 @@
   1.367        static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
   1.368        SetProcessedMapBase(const TR &b) : TR(b) {}
   1.369      };
   1.370 -    ///\brief \ref named-func-param "Named parameter"
   1.371 -    ///for setting ProcessedMap object.
   1.372 +
   1.373 +    ///\brief \ref named-func-param "Named parameter" for setting
   1.374 +    ///the processed map.
   1.375      ///
   1.376 -    /// \ref named-func-param "Named parameter"
   1.377 -    ///for setting ProcessedMap object.
   1.378 +    ///\ref named-templ-param "Named parameter" function for setting
   1.379 +    ///the map that indicates which nodes are processed.
   1.380      template<class T>
   1.381      DfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
   1.382      {
   1.383 @@ -1208,7 +1210,8 @@
   1.384      /// \brief The type of the map that indicates which nodes are reached.
   1.385      ///
   1.386      /// The type of the map that indicates which nodes are reached.
   1.387 -    /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   1.388 +    /// It must conform to the
   1.389 +    /// \ref concepts::ReadWriteMap "ReadWriteMap" concept.
   1.390      typedef typename Digraph::template NodeMap<bool> ReachedMap;
   1.391  
   1.392      /// \brief Instantiates a ReachedMap.
   1.393 @@ -1246,11 +1249,11 @@
   1.394    /// \ref DfsVisitor "DfsVisitor<GR>" is an empty visitor, which
   1.395    /// does not observe the DFS events. If you want to observe the DFS
   1.396    /// events, you should implement your own visitor class.
   1.397 -  /// \tparam TR Traits class to set various data types used by the
   1.398 -  /// algorithm. The default traits class is
   1.399 -  /// \ref DfsVisitDefaultTraits "DfsVisitDefaultTraits<GR>".
   1.400 -  /// See \ref DfsVisitDefaultTraits for the documentation of
   1.401 -  /// a DFS visit traits class.
   1.402 +  /// \tparam TR The traits class that defines various types used by the
   1.403 +  /// algorithm. By default, it is \ref DfsVisitDefaultTraits
   1.404 +  /// "DfsVisitDefaultTraits<GR>".
   1.405 +  /// In most cases, this parameter should not be set directly,
   1.406 +  /// consider to use the named template parameters instead.
   1.407  #ifdef DOXYGEN
   1.408    template <typename GR, typename VS, typename TR>
   1.409  #else
   1.410 @@ -1369,8 +1372,8 @@
   1.411      /// \name Execution Control
   1.412      /// The simplest way to execute the DFS algorithm is to use one of the
   1.413      /// member functions called \ref run(Node) "run()".\n
   1.414 -    /// If you need more control on the execution, first you have to call
   1.415 -    /// \ref init(), then you can add a source node with \ref addSource()
   1.416 +    /// If you need better control on the execution, you have to call
   1.417 +    /// \ref init() first, then you can add a source node with \ref addSource()
   1.418      /// and perform the actual computation with \ref start().
   1.419      /// This procedure can be repeated if there are nodes that have not
   1.420      /// been reached.
   1.421 @@ -1583,12 +1586,8 @@
   1.422  
   1.423      /// \brief Runs the algorithm to visit all nodes in the digraph.
   1.424  
   1.425 -    /// This method runs the %DFS algorithm in order to
   1.426 -    /// compute the %DFS path to each node.
   1.427 -    ///
   1.428 -    /// The algorithm computes
   1.429 -    /// - the %DFS tree (forest),
   1.430 -    /// - the distance of each node from the root(s) in the %DFS tree.
   1.431 +    /// This method runs the %DFS algorithm in order to visit all nodes
   1.432 +    /// in the digraph.
   1.433      ///
   1.434      /// \note <tt>d.run()</tt> is just a shortcut of the following code.
   1.435      ///\code
   1.436 @@ -1620,7 +1619,7 @@
   1.437  
   1.438      ///@{
   1.439  
   1.440 -    /// \brief Checks if a node is reached from the root(s).
   1.441 +    /// \brief Checks if the given node is reached from the root(s).
   1.442      ///
   1.443      /// Returns \c true if \c v is reached from the root(s).
   1.444      ///