COIN-OR::LEMON - Graph Library

Changeset 2439:3f1c7a6c33cd in lemon-0.x


Ignore:
Timestamp:
05/07/07 10:49:57 (17 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3276
Message:

Modified start() function in Dfs and Dijkstra classes to give back reached
edge/node.

Patch from Peter Kovacs

Location:
lemon
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lemon/dfs.h

    r2391 r2439  
    565565    ///
    566566    ///\param em must be a bool (or convertible) edge map. The algorithm
    567     ///will stop when it reaches an edge \c e with \code em[e]==true \endcode.
    568     ///
    569     ///\warning Contrary to \ref Dfs and \ref Dijkstra, \c em is an edge map,
     567    ///will stop when it reaches an edge \c e with <tt>em[e]==true<\tt>.
     568    ///
     569    ///\return The reached edge \c e with <tt>em[e]==true<\tt> or
     570    ///\c INVALID if no such edge was found.
     571    ///
     572    ///\warning Contrary to \ref Bfs and \ref Dijkstra, \c em is an edge map,
    570573    ///not a node map.
    571574    template<class EM>
    572     void start(const EM &em)
    573     {
    574       while ( !emptyQueue() && !em[_stack[_stack_head]] ) processNextEdge();
     575    Edge start(const EM &em)
     576    {
     577      while ( !emptyQueue() && !em[_stack[_stack_head]] )
     578        processNextEdge();
     579      return emptyQueue() ? INVALID : _stack[_stack_head];
    575580    }
    576581
     
    14421447    /// with addSource() before using this function.
    14431448    void start(Node dest) {
    1444       while ( !emptyQueue() && _graph->target(_stack[_stack_head]) != dest)
     1449      while ( !emptyQueue() && _graph->target(_stack[_stack_head]) != dest )
    14451450        processNextEdge();
    14461451    }
     
    14541459    ///
    14551460    /// \param em must be a bool (or convertible) edge map. The algorithm
    1456     /// will stop when it reaches an edge \c e with \code nm[e]==true \endcode.
    1457     ///
    1458     /// \warning Contrary to \ref Dfs and \ref Dijkstra, \c em is an edge map,
     1461    /// will stop when it reaches an edge \c e with <tt>em[e]==true<\tt>.
     1462    ///
     1463    ///\return The reached edge \c e with <tt>em[e]==true<\tt> or
     1464    ///\c INVALID if no such edge was found.
     1465    ///
     1466    /// \warning Contrary to \ref Bfs and \ref Dijkstra, \c em is an edge map,
    14591467    /// not a node map.
    14601468    template <typename EM>
    1461     void start(const EM &em) {
    1462       while (!emptyQueue() && !em[_stack[_stack_head]]) processNextEdge();
     1469    Edge start(const EM &em) {
     1470      while ( !emptyQueue() && !em[_stack[_stack_head]] )
     1471        processNextEdge();
     1472      return emptyQueue() ? INVALID : _stack[_stack_head];
    14631473    }
    14641474
  • lemon/dijkstra.h

    r2391 r2439  
    602602    Node nextNode()
    603603    {
    604       return _heap->empty()?_heap->top():INVALID;
     604      return !_heap->empty()?_heap->top():INVALID;
    605605    }
    606606 
     
    665665    ///\param nm must be a bool (or convertible) node map. The algorithm
    666666    ///will stop when it reaches a node \c v with <tt>nm[v]==true</tt>.
     667    ///
     668    ///\return The reached node \c v with <tt>nm[v]==true<\tt> or
     669    ///\c INVALID if no such node was found.
    667670    template<class NodeBoolMap>
    668     void start(const NodeBoolMap &nm)
     671    Node start(const NodeBoolMap &nm)
    669672    {
    670673      while ( !_heap->empty() && !nm[_heap->top()] ) processNextNode();
    671       if ( !_heap->empty() ) finalizeNodeData(_heap->top(),_heap->prio());
     674      if ( _heap->empty() ) return INVALID;
     675      finalizeNodeData(_heap->top(),_heap->prio());
     676      return _heap->top();
    672677    }
    673678   
Note: See TracChangeset for help on using the changeset viewer.