# HG changeset patch # User deba # Date 1178527797 0 # Node ID 3f1c7a6c33cd294b2191f0654da2ade1f841691b # Parent 718479989797e9eaed6990ee60f695dcb641cdbe Modified start() function in Dfs and Dijkstra classes to give back reached edge/node. Patch from Peter Kovacs diff -r 718479989797 -r 3f1c7a6c33cd lemon/dfs.h --- a/lemon/dfs.h Mon May 07 08:48:40 2007 +0000 +++ b/lemon/dfs.h Mon May 07 08:49:57 2007 +0000 @@ -564,14 +564,19 @@ ///with addSource() before using this function. /// ///\param em must be a bool (or convertible) edge map. The algorithm - ///will stop when it reaches an edge \c e with \code em[e]==true \endcode. + ///will stop when it reaches an edge \c e with em[e]==true<\tt>. /// - ///\warning Contrary to \ref Dfs and \ref Dijkstra, \c em is an edge map, + ///\return The reached edge \c e with em[e]==true<\tt> or + ///\c INVALID if no such edge was found. + /// + ///\warning Contrary to \ref Bfs and \ref Dijkstra, \c em is an edge map, ///not a node map. template - void start(const EM &em) + Edge start(const EM &em) { - while ( !emptyQueue() && !em[_stack[_stack_head]] ) processNextEdge(); + while ( !emptyQueue() && !em[_stack[_stack_head]] ) + processNextEdge(); + return emptyQueue() ? INVALID : _stack[_stack_head]; } ///Runs %DFS algorithm to visit all nodes in the graph. @@ -1441,7 +1446,7 @@ /// \pre init() must be called and at least one node should be added /// with addSource() before using this function. void start(Node dest) { - while ( !emptyQueue() && _graph->target(_stack[_stack_head]) != dest) + while ( !emptyQueue() && _graph->target(_stack[_stack_head]) != dest ) processNextEdge(); } @@ -1453,13 +1458,18 @@ /// with addSource() before using this function. /// /// \param em must be a bool (or convertible) edge map. The algorithm - /// will stop when it reaches an edge \c e with \code nm[e]==true \endcode. + /// will stop when it reaches an edge \c e with em[e]==true<\tt>. /// - /// \warning Contrary to \ref Dfs and \ref Dijkstra, \c em is an edge map, + ///\return The reached edge \c e with em[e]==true<\tt> or + ///\c INVALID if no such edge was found. + /// + /// \warning Contrary to \ref Bfs and \ref Dijkstra, \c em is an edge map, /// not a node map. template - void start(const EM &em) { - while (!emptyQueue() && !em[_stack[_stack_head]]) processNextEdge(); + Edge start(const EM &em) { + while ( !emptyQueue() && !em[_stack[_stack_head]] ) + processNextEdge(); + return emptyQueue() ? INVALID : _stack[_stack_head]; } /// \brief Runs %DFSVisit algorithm from node \c s. diff -r 718479989797 -r 3f1c7a6c33cd lemon/dijkstra.h --- a/lemon/dijkstra.h Mon May 07 08:48:40 2007 +0000 +++ b/lemon/dijkstra.h Mon May 07 08:49:57 2007 +0000 @@ -601,7 +601,7 @@ /// is empty. Node nextNode() { - return _heap->empty()?_heap->top():INVALID; + return !_heap->empty()?_heap->top():INVALID; } ///\brief Returns \c false if there are nodes @@ -664,11 +664,16 @@ /// ///\param nm must be a bool (or convertible) node map. The algorithm ///will stop when it reaches a node \c v with nm[v]==true. + /// + ///\return The reached node \c v with nm[v]==true<\tt> or + ///\c INVALID if no such node was found. template - void start(const NodeBoolMap &nm) + Node start(const NodeBoolMap &nm) { while ( !_heap->empty() && !nm[_heap->top()] ) processNextNode(); - if ( !_heap->empty() ) finalizeNodeData(_heap->top(),_heap->prio()); + if ( _heap->empty() ) return INVALID; + finalizeNodeData(_heap->top(),_heap->prio()); + return _heap->top(); } ///Runs %Dijkstra algorithm from node \c s.