lemon/bfs.h
changeset 286 da414906fe21
parent 278 931190050520
child 287 bb40b6db0a58
     1.1 --- a/lemon/bfs.h	Tue Sep 23 18:42:49 2008 +0200
     1.2 +++ b/lemon/bfs.h	Fri Sep 26 12:40:11 2008 +0200
     1.3 @@ -607,11 +607,11 @@
     1.4      ///Executes the algorithm until the given target node is reached.
     1.5      ///
     1.6      ///This method runs the %BFS algorithm from the root node(s)
     1.7 -    ///in order to compute the shortest path to \c dest.
     1.8 +    ///in order to compute the shortest path to \c t.
     1.9      ///
    1.10      ///The algorithm computes
    1.11 -    ///- the shortest path to \c dest,
    1.12 -    ///- the distance of \c dest from the root(s).
    1.13 +    ///- the shortest path to \c t,
    1.14 +    ///- the distance of \c t from the root(s).
    1.15      ///
    1.16      ///\pre init() must be called and at least one root node should be
    1.17      ///added with addSource() before using this function.
    1.18 @@ -623,10 +623,10 @@
    1.19      ///    b.processNextNode(t, reach);
    1.20      ///  }
    1.21      ///\endcode
    1.22 -    void start(Node dest)
    1.23 +    void start(Node t)
    1.24      {
    1.25        bool reach = false;
    1.26 -      while ( !emptyQueue() && !reach ) processNextNode(dest, reach);
    1.27 +      while ( !emptyQueue() && !reach ) processNextNode(t, reach);
    1.28      }
    1.29  
    1.30      ///Executes the algorithm until a condition is met.
    1.31 @@ -664,7 +664,7 @@
    1.32        return rnode;
    1.33      }
    1.34  
    1.35 -    ///Runs the algorithm from the given node.
    1.36 +    ///Runs the algorithm from the given source node.
    1.37  
    1.38      ///This method runs the %BFS algorithm from node \c s
    1.39      ///in order to compute the shortest path to each node.
    1.40 @@ -688,10 +688,10 @@
    1.41      ///Finds the shortest path between \c s and \c t.
    1.42  
    1.43      ///This method runs the %BFS algorithm from node \c s
    1.44 -    ///in order to compute the shortest path to \c t.
    1.45 +    ///in order to compute the shortest path to node \c t
    1.46 +    ///(it stops searching when \c t is processed).
    1.47      ///
    1.48 -    ///\return The length of the shortest <tt>s</tt>--<tt>t</tt> path,
    1.49 -    ///if \c t is reachable form \c s, \c 0 otherwise.
    1.50 +    ///\return \c true if \c t is reachable form \c s.
    1.51      ///
    1.52      ///\note Apart from the return value, <tt>b.run(s,t)</tt> is just a
    1.53      ///shortcut of the following code.
    1.54 @@ -700,11 +700,11 @@
    1.55      ///  b.addSource(s);
    1.56      ///  b.start(t);
    1.57      ///\endcode
    1.58 -    int run(Node s,Node t) {
    1.59 +    bool run(Node s,Node t) {
    1.60        init();
    1.61        addSource(s);
    1.62        start(t);
    1.63 -      return reached(t) ? _curr_dist : 0;
    1.64 +      return reached(t);
    1.65      }
    1.66  
    1.67      ///Runs the algorithm to visit all nodes in the digraph.
    1.68 @@ -1621,11 +1621,11 @@
    1.69      /// Executes the algorithm until the given target node is reached.
    1.70      ///
    1.71      /// This method runs the %BFS algorithm from the root node(s)
    1.72 -    /// in order to compute the shortest path to \c dest.
    1.73 +    /// in order to compute the shortest path to \c t.
    1.74      ///
    1.75      /// The algorithm computes
    1.76 -    /// - the shortest path to \c dest,
    1.77 -    /// - the distance of \c dest from the root(s).
    1.78 +    /// - the shortest path to \c t,
    1.79 +    /// - the distance of \c t from the root(s).
    1.80      ///
    1.81      /// \pre init() must be called and at least one root node should be
    1.82      /// added with addSource() before using this function.
    1.83 @@ -1637,9 +1637,9 @@
    1.84      ///     b.processNextNode(t, reach);
    1.85      ///   }
    1.86      /// \endcode
    1.87 -    void start(Node dest) {
    1.88 +    void start(Node t) {
    1.89        bool reach = false;
    1.90 -      while ( !emptyQueue() && !reach ) processNextNode(dest, reach);
    1.91 +      while ( !emptyQueue() && !reach ) processNextNode(t, reach);
    1.92      }
    1.93  
    1.94      /// \brief Executes the algorithm until a condition is met.
    1.95 @@ -1677,7 +1677,7 @@
    1.96        return rnode;
    1.97      }
    1.98  
    1.99 -    /// \brief Runs the algorithm from the given node.
   1.100 +    /// \brief Runs the algorithm from the given source node.
   1.101      ///
   1.102      /// This method runs the %BFS algorithm from node \c s
   1.103      /// in order to compute the shortest path to each node.
   1.104 @@ -1698,6 +1698,28 @@
   1.105        start();
   1.106      }
   1.107  
   1.108 +    /// \brief Finds the shortest path between \c s and \c t.
   1.109 +    ///
   1.110 +    /// This method runs the %BFS algorithm from node \c s
   1.111 +    /// in order to compute the shortest path to node \c t
   1.112 +    /// (it stops searching when \c t is processed).
   1.113 +    ///
   1.114 +    /// \return \c true if \c t is reachable form \c s.
   1.115 +    ///
   1.116 +    /// \note Apart from the return value, <tt>b.run(s,t)</tt> is just a
   1.117 +    /// shortcut of the following code.
   1.118 +    ///\code
   1.119 +    ///   b.init();
   1.120 +    ///   b.addSource(s);
   1.121 +    ///   b.start(t);
   1.122 +    ///\endcode
   1.123 +    bool run(Node s,Node t) {
   1.124 +      init();
   1.125 +      addSource(s);
   1.126 +      start(t);
   1.127 +      return reached(t);
   1.128 +    }
   1.129 +
   1.130      /// \brief Runs the algorithm to visit all nodes in the digraph.
   1.131      ///
   1.132      /// This method runs the %BFS algorithm in order to