Changeset 2443:14abfa02bf42 in lemon-0.x for lemon/bfs.h
- Timestamp:
- 05/11/07 18:02:53 (17 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3280
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bfs.h
r2438 r2443 516 516 517 517 ///Processes the next node. And checks that at least one of 518 ///reached node has true value in the \c nm node map. If one node518 ///reached node has true value in the \c nm node map. If one node 519 519 ///with true value is reachable from the processed node then the 520 ///reached parameter will be set true. The reached parameter 521 ///should be initially false. 522 /// 523 ///\param nm The nodemaps of possible targets. 524 ///\retval reach Indicates that one of the target nodes is reached. 520 ///rnode parameter will be set to the first of such nodes. 521 /// 522 ///\param nm The node map of possible targets. 523 ///\retval rnode The reached target node. 525 524 ///\return The processed node. 526 525 /// 527 526 ///\warning The queue must not be empty! 528 527 template<class NM> 529 Node processNextNode(const NM& nm, bool& reach)528 Node processNextNode(const NM& nm, Node& rnode) 530 529 { 531 530 if(_queue_tail==_queue_next_dist) { … … 542 541 _pred->set(m,e); 543 542 _dist->set(m,_curr_dist); 544 reach = reach || nm[m];543 if (nm[m] && rnode == INVALID) rnode = m; 545 544 } 546 545 return n; … … 567 566 568 567 ///Returns the number of the nodes to be processed in the queue. 569 ///570 568 int queueSize() { return _queue_head-_queue_tail; } 571 569 … … 583 581 ///- The shortest path tree. 584 582 ///- The distance of each node from the root(s). 585 ///586 583 void start() 587 584 { … … 602 599 ///- The shortest path to \c dest. 603 600 ///- The distance of \c dest from the root(s). 604 ///605 601 void start(Node dest) 606 602 { … … 617 613 /// 618 614 ///\param nm must be a bool (or convertible) node map. The 619 ///algorithm will stop when it reache da node \c v with615 ///algorithm will stop when it reaches a node \c v with 620 616 /// <tt>nm[v]</tt> true. 621 ///\todo query the reached target 617 /// 618 ///\return The reached node \c v with <tt>nm[v]<\tt> true or 619 ///\c INVALID if no such node was found. 622 620 template<class NM> 623 void start(const NM &nm) 624 { 625 bool reach = false; 626 while ( !emptyQueue() && !reach ) processNextNode(nm, reach); 621 Node start(const NM &nm) 622 { 623 Node rnode = INVALID; 624 while ( !emptyQueue() && rnode == INVALID ) { 625 processNextNode(nm, rnode); 626 } 627 return rnode; 627 628 } 628 629 … … 1434 1435 /// 1435 1436 /// Processes the next node. And checks that at least one of 1436 /// reached node has true value in the \c nm node map. If one node1437 /// reached node has true value in the \c nm node map. If one node 1437 1438 /// with true value is reachable from the processed node then the 1438 /// reached parameter will be set true. The reached parameter 1439 /// should be initially false. 1440 /// 1441 /// \param nm The nodemaps of possible targets. 1442 /// \retval reached Indicates that one of the target nodes is reached. 1439 /// rnode parameter will be set to the first of such nodes. 1440 /// 1441 /// \param nm The node map of possible targets. 1442 /// \retval rnode The reached target node. 1443 1443 /// \return The processed node. 1444 1444 /// 1445 1445 /// \warning The queue must not be empty! 1446 1446 template <typename NM> 1447 Node processNextNode(const NM& nm, bool& reach) {1447 Node processNextNode(const NM& nm, Node& rnode) { 1448 1448 Node n = _list[++_list_front]; 1449 1449 _visitor->process(n); … … 1456 1456 _reached->set(m, true); 1457 1457 _list[++_list_back] = m; 1458 reach = reach || nm[m];1458 if (nm[m] && rnode == INVALID) rnode = m; 1459 1459 } else { 1460 1460 _visitor->examine(e); … … 1515 1515 /// 1516 1516 ///\param nm must be a bool (or convertible) node map. The 1517 ///algorithm will stop when it reache da node \c v with1517 ///algorithm will stop when it reaches a node \c v with 1518 1518 /// <tt>nm[v]</tt> true. 1519 /// 1520 ///\return The reached node \c v with <tt>nm[v]<\tt> true or 1521 ///\c INVALID if no such node was found. 1519 1522 template <typename NM> 1520 void start(const NM &nm) { 1521 bool reach = false; 1522 while ( !emptyQueue() && !reach ) processNextNode(nm, reach); 1523 Node start(const NM &nm) { 1524 Node rnode = INVALID; 1525 while ( !emptyQueue() && rnode == INVALID ) { 1526 processNextNode(nm, rnode); 1527 } 1528 return rnode; 1523 1529 } 1524 1530
Note: See TracChangeset
for help on using the changeset viewer.