Modified start() function in Dfs and Dijkstra classes to give back reached
authordeba
Mon, 07 May 2007 08:49:57 +0000
changeset 24393f1c7a6c33cd
parent 2438 718479989797
child 2440 c9218405595b
Modified start() function in Dfs and Dijkstra classes to give back reached
edge/node.

Patch from Peter Kovacs
lemon/dfs.h
lemon/dijkstra.h
     1.1 --- a/lemon/dfs.h	Mon May 07 08:48:40 2007 +0000
     1.2 +++ b/lemon/dfs.h	Mon May 07 08:49:57 2007 +0000
     1.3 @@ -564,14 +564,19 @@
     1.4      ///with addSource() before using this function.
     1.5      ///
     1.6      ///\param em must be a bool (or convertible) edge map. The algorithm
     1.7 -    ///will stop when it reaches an edge \c e with \code em[e]==true \endcode.
     1.8 +    ///will stop when it reaches an edge \c e with <tt>em[e]==true<\tt>.
     1.9      ///
    1.10 -    ///\warning Contrary to \ref Dfs and \ref Dijkstra, \c em is an edge map,
    1.11 +    ///\return The reached edge \c e with <tt>em[e]==true<\tt> or
    1.12 +    ///\c INVALID if no such edge was found.
    1.13 +    ///
    1.14 +    ///\warning Contrary to \ref Bfs and \ref Dijkstra, \c em is an edge map,
    1.15      ///not a node map.
    1.16      template<class EM>
    1.17 -    void start(const EM &em)
    1.18 +    Edge start(const EM &em)
    1.19      {
    1.20 -      while ( !emptyQueue() && !em[_stack[_stack_head]] ) processNextEdge();
    1.21 +      while ( !emptyQueue() && !em[_stack[_stack_head]] )
    1.22 +        processNextEdge();
    1.23 +      return emptyQueue() ? INVALID : _stack[_stack_head];
    1.24      }
    1.25  
    1.26      ///Runs %DFS algorithm to visit all nodes in the graph.
    1.27 @@ -1441,7 +1446,7 @@
    1.28      /// \pre init() must be called and at least one node should be added
    1.29      /// with addSource() before using this function.
    1.30      void start(Node dest) {
    1.31 -      while ( !emptyQueue() && _graph->target(_stack[_stack_head]) != dest) 
    1.32 +      while ( !emptyQueue() && _graph->target(_stack[_stack_head]) != dest ) 
    1.33  	processNextEdge();
    1.34      }
    1.35      
    1.36 @@ -1453,13 +1458,18 @@
    1.37      /// with addSource() before using this function.
    1.38      ///
    1.39      /// \param em must be a bool (or convertible) edge map. The algorithm
    1.40 -    /// will stop when it reaches an edge \c e with \code nm[e]==true \endcode.
    1.41 +    /// will stop when it reaches an edge \c e with <tt>em[e]==true<\tt>.
    1.42      ///
    1.43 -    /// \warning Contrary to \ref Dfs and \ref Dijkstra, \c em is an edge map,
    1.44 +    ///\return The reached edge \c e with <tt>em[e]==true<\tt> or
    1.45 +    ///\c INVALID if no such edge was found.
    1.46 +    ///
    1.47 +    /// \warning Contrary to \ref Bfs and \ref Dijkstra, \c em is an edge map,
    1.48      /// not a node map.
    1.49      template <typename EM>
    1.50 -    void start(const EM &em) {
    1.51 -      while (!emptyQueue() && !em[_stack[_stack_head]]) processNextEdge();
    1.52 +    Edge start(const EM &em) {
    1.53 +      while ( !emptyQueue() && !em[_stack[_stack_head]] )
    1.54 +        processNextEdge();
    1.55 +      return emptyQueue() ? INVALID : _stack[_stack_head];
    1.56      }
    1.57  
    1.58      /// \brief Runs %DFSVisit algorithm from node \c s.
     2.1 --- a/lemon/dijkstra.h	Mon May 07 08:48:40 2007 +0000
     2.2 +++ b/lemon/dijkstra.h	Mon May 07 08:49:57 2007 +0000
     2.3 @@ -601,7 +601,7 @@
     2.4      /// is empty.
     2.5      Node nextNode()
     2.6      { 
     2.7 -      return _heap->empty()?_heap->top():INVALID;
     2.8 +      return !_heap->empty()?_heap->top():INVALID;
     2.9      }
    2.10   
    2.11      ///\brief Returns \c false if there are nodes
    2.12 @@ -664,11 +664,16 @@
    2.13      ///
    2.14      ///\param nm must be a bool (or convertible) node map. The algorithm
    2.15      ///will stop when it reaches a node \c v with <tt>nm[v]==true</tt>.
    2.16 +    ///
    2.17 +    ///\return The reached node \c v with <tt>nm[v]==true<\tt> or
    2.18 +    ///\c INVALID if no such node was found.
    2.19      template<class NodeBoolMap>
    2.20 -    void start(const NodeBoolMap &nm)
    2.21 +    Node start(const NodeBoolMap &nm)
    2.22      {
    2.23        while ( !_heap->empty() && !nm[_heap->top()] ) processNextNode();
    2.24 -      if ( !_heap->empty() ) finalizeNodeData(_heap->top(),_heap->prio());
    2.25 +      if ( _heap->empty() ) return INVALID;
    2.26 +      finalizeNodeData(_heap->top(),_heap->prio());
    2.27 +      return _heap->top();
    2.28      }
    2.29      
    2.30      ///Runs %Dijkstra algorithm from node \c s.