0
4
0
... | ... |
@@ -1712,41 +1712,41 @@ |
1712 | 1712 |
/// if (!b.reached(n)) { |
1713 | 1713 |
/// b.addSource(n); |
1714 | 1714 |
/// b.start(); |
1715 | 1715 |
/// } |
1716 | 1716 |
/// } |
1717 | 1717 |
///\endcode |
1718 | 1718 |
void run() { |
1719 | 1719 |
init(); |
1720 | 1720 |
for (NodeIt it(*_digraph); it != INVALID; ++it) { |
1721 | 1721 |
if (!reached(it)) { |
1722 | 1722 |
addSource(it); |
1723 | 1723 |
start(); |
1724 | 1724 |
} |
1725 | 1725 |
} |
1726 | 1726 |
} |
1727 | 1727 |
|
1728 | 1728 |
///@} |
1729 | 1729 |
|
1730 | 1730 |
/// \name Query Functions |
1731 | 1731 |
/// The results of the BFS algorithm can be obtained using these |
1732 | 1732 |
/// functions.\n |
1733 | 1733 |
/// Either \ref run(Node) "run()" or \ref start() should be called |
1734 | 1734 |
/// before using them. |
1735 | 1735 |
|
1736 | 1736 |
///@{ |
1737 | 1737 |
|
1738 | 1738 |
/// \brief Checks if a node is reached from the root(s). |
1739 | 1739 |
/// |
1740 | 1740 |
/// Returns \c true if \c v is reached from the root(s). |
1741 | 1741 |
/// |
1742 | 1742 |
/// \pre Either \ref run(Node) "run()" or \ref init() |
1743 | 1743 |
/// must be called before using this function. |
1744 |
bool reached(Node v) { return (*_reached)[v]; } |
|
1744 |
bool reached(Node v) const { return (*_reached)[v]; } |
|
1745 | 1745 |
|
1746 | 1746 |
///@} |
1747 | 1747 |
|
1748 | 1748 |
}; |
1749 | 1749 |
|
1750 | 1750 |
} //END OF NAMESPACE LEMON |
1751 | 1751 |
|
1752 | 1752 |
#endif |
... | ... |
@@ -390,65 +390,65 @@ |
390 | 390 |
Circulation& flowMap(FlowMap& map) { |
391 | 391 |
if (_local_flow) { |
392 | 392 |
delete _flow; |
393 | 393 |
_local_flow = false; |
394 | 394 |
} |
395 | 395 |
_flow = ↦ |
396 | 396 |
return *this; |
397 | 397 |
} |
398 | 398 |
|
399 | 399 |
/// \brief Sets the elevator used by algorithm. |
400 | 400 |
/// |
401 | 401 |
/// Sets the elevator used by algorithm. |
402 | 402 |
/// If you don't use this function before calling \ref run() or |
403 | 403 |
/// \ref init(), an instance will be allocated automatically. |
404 | 404 |
/// The destructor deallocates this automatically allocated elevator, |
405 | 405 |
/// of course. |
406 | 406 |
/// \return <tt>(*this)</tt> |
407 | 407 |
Circulation& elevator(Elevator& elevator) { |
408 | 408 |
if (_local_level) { |
409 | 409 |
delete _level; |
410 | 410 |
_local_level = false; |
411 | 411 |
} |
412 | 412 |
_level = &elevator; |
413 | 413 |
return *this; |
414 | 414 |
} |
415 | 415 |
|
416 | 416 |
/// \brief Returns a const reference to the elevator. |
417 | 417 |
/// |
418 | 418 |
/// Returns a const reference to the elevator. |
419 | 419 |
/// |
420 | 420 |
/// \pre Either \ref run() or \ref init() must be called before |
421 | 421 |
/// using this function. |
422 |
const Elevator& elevator() { |
|
422 |
const Elevator& elevator() const { |
|
423 | 423 |
return *_level; |
424 | 424 |
} |
425 | 425 |
|
426 | 426 |
/// \brief Sets the tolerance used by algorithm. |
427 | 427 |
/// |
428 | 428 |
/// Sets the tolerance used by algorithm. |
429 | 429 |
Circulation& tolerance(const Tolerance& tolerance) const { |
430 | 430 |
_tol = tolerance; |
431 | 431 |
return *this; |
432 | 432 |
} |
433 | 433 |
|
434 | 434 |
/// \brief Returns a const reference to the tolerance. |
435 | 435 |
/// |
436 | 436 |
/// Returns a const reference to the tolerance. |
437 | 437 |
const Tolerance& tolerance() const { |
438 | 438 |
return tolerance; |
439 | 439 |
} |
440 | 440 |
|
441 | 441 |
/// \name Execution Control |
442 | 442 |
/// The simplest way to execute the algorithm is to call \ref run().\n |
443 | 443 |
/// If you need more control on the initial solution or the execution, |
444 | 444 |
/// first you have to call one of the \ref init() functions, then |
445 | 445 |
/// the \ref start() function. |
446 | 446 |
|
447 | 447 |
///@{ |
448 | 448 |
|
449 | 449 |
/// Initializes the internal data structures. |
450 | 450 |
|
451 | 451 |
/// Initializes the internal data structures and sets all flow values |
452 | 452 |
/// to the lower bound. |
453 | 453 |
void init() |
454 | 454 |
{ |
... | ... |
@@ -615,141 +615,141 @@ |
615 | 615 |
/// \endcode |
616 | 616 |
bool run() { |
617 | 617 |
greedyInit(); |
618 | 618 |
return start(); |
619 | 619 |
} |
620 | 620 |
|
621 | 621 |
/// @} |
622 | 622 |
|
623 | 623 |
/// \name Query Functions |
624 | 624 |
/// The results of the circulation algorithm can be obtained using |
625 | 625 |
/// these functions.\n |
626 | 626 |
/// Either \ref run() or \ref start() should be called before |
627 | 627 |
/// using them. |
628 | 628 |
|
629 | 629 |
///@{ |
630 | 630 |
|
631 | 631 |
/// \brief Returns the flow on the given arc. |
632 | 632 |
/// |
633 | 633 |
/// Returns the flow on the given arc. |
634 | 634 |
/// |
635 | 635 |
/// \pre Either \ref run() or \ref init() must be called before |
636 | 636 |
/// using this function. |
637 | 637 |
Value flow(const Arc& arc) const { |
638 | 638 |
return (*_flow)[arc]; |
639 | 639 |
} |
640 | 640 |
|
641 | 641 |
/// \brief Returns a const reference to the flow map. |
642 | 642 |
/// |
643 | 643 |
/// Returns a const reference to the arc map storing the found flow. |
644 | 644 |
/// |
645 | 645 |
/// \pre Either \ref run() or \ref init() must be called before |
646 | 646 |
/// using this function. |
647 |
const FlowMap& flowMap() { |
|
647 |
const FlowMap& flowMap() const { |
|
648 | 648 |
return *_flow; |
649 | 649 |
} |
650 | 650 |
|
651 | 651 |
/** |
652 | 652 |
\brief Returns \c true if the given node is in a barrier. |
653 | 653 |
|
654 | 654 |
Barrier is a set \e B of nodes for which |
655 | 655 |
|
656 | 656 |
\f[ \sum_{a\in\delta_{out}(B)} upper(a) - |
657 | 657 |
\sum_{a\in\delta_{in}(B)} lower(a) < \sum_{v\in B}delta(v) \f] |
658 | 658 |
|
659 | 659 |
holds. The existence of a set with this property prooves that a |
660 | 660 |
feasible circualtion cannot exist. |
661 | 661 |
|
662 | 662 |
This function returns \c true if the given node is in the found |
663 | 663 |
barrier. If a feasible circulation is found, the function |
664 | 664 |
gives back \c false for every node. |
665 | 665 |
|
666 | 666 |
\pre Either \ref run() or \ref init() must be called before |
667 | 667 |
using this function. |
668 | 668 |
|
669 | 669 |
\sa barrierMap() |
670 | 670 |
\sa checkBarrier() |
671 | 671 |
*/ |
672 |
bool barrier(const Node& node) |
|
672 |
bool barrier(const Node& node) const |
|
673 | 673 |
{ |
674 | 674 |
return (*_level)[node] >= _el; |
675 | 675 |
} |
676 | 676 |
|
677 | 677 |
/// \brief Gives back a barrier. |
678 | 678 |
/// |
679 | 679 |
/// This function sets \c bar to the characteristic vector of the |
680 | 680 |
/// found barrier. \c bar should be a \ref concepts::WriteMap "writable" |
681 | 681 |
/// node map with \c bool (or convertible) value type. |
682 | 682 |
/// |
683 | 683 |
/// If a feasible circulation is found, the function gives back an |
684 | 684 |
/// empty set, so \c bar[v] will be \c false for all nodes \c v. |
685 | 685 |
/// |
686 | 686 |
/// \note This function calls \ref barrier() for each node, |
687 | 687 |
/// so it runs in \f$O(n)\f$ time. |
688 | 688 |
/// |
689 | 689 |
/// \pre Either \ref run() or \ref init() must be called before |
690 | 690 |
/// using this function. |
691 | 691 |
/// |
692 | 692 |
/// \sa barrier() |
693 | 693 |
/// \sa checkBarrier() |
694 | 694 |
template<class BarrierMap> |
695 |
void barrierMap(BarrierMap &bar) |
|
695 |
void barrierMap(BarrierMap &bar) const |
|
696 | 696 |
{ |
697 | 697 |
for(NodeIt n(_g);n!=INVALID;++n) |
698 | 698 |
bar.set(n, (*_level)[n] >= _el); |
699 | 699 |
} |
700 | 700 |
|
701 | 701 |
/// @} |
702 | 702 |
|
703 | 703 |
/// \name Checker Functions |
704 | 704 |
/// The feasibility of the results can be checked using |
705 | 705 |
/// these functions.\n |
706 | 706 |
/// Either \ref run() or \ref start() should be called before |
707 | 707 |
/// using them. |
708 | 708 |
|
709 | 709 |
///@{ |
710 | 710 |
|
711 | 711 |
///Check if the found flow is a feasible circulation |
712 | 712 |
|
713 | 713 |
///Check if the found flow is a feasible circulation, |
714 | 714 |
/// |
715 |
bool checkFlow() { |
|
715 |
bool checkFlow() const { |
|
716 | 716 |
for(ArcIt e(_g);e!=INVALID;++e) |
717 | 717 |
if((*_flow)[e]<(*_lo)[e]||(*_flow)[e]>(*_up)[e]) return false; |
718 | 718 |
for(NodeIt n(_g);n!=INVALID;++n) |
719 | 719 |
{ |
720 | 720 |
Value dif=-(*_delta)[n]; |
721 | 721 |
for(InArcIt e(_g,n);e!=INVALID;++e) dif-=(*_flow)[e]; |
722 | 722 |
for(OutArcIt e(_g,n);e!=INVALID;++e) dif+=(*_flow)[e]; |
723 | 723 |
if(_tol.negative(dif)) return false; |
724 | 724 |
} |
725 | 725 |
return true; |
726 | 726 |
} |
727 | 727 |
|
728 | 728 |
///Check whether or not the last execution provides a barrier |
729 | 729 |
|
730 | 730 |
///Check whether or not the last execution provides a barrier. |
731 | 731 |
///\sa barrier() |
732 | 732 |
///\sa barrierMap() |
733 |
bool checkBarrier() |
|
733 |
bool checkBarrier() const |
|
734 | 734 |
{ |
735 | 735 |
Value delta=0; |
736 | 736 |
for(NodeIt n(_g);n!=INVALID;++n) |
737 | 737 |
if(barrier(n)) |
738 | 738 |
delta-=(*_delta)[n]; |
739 | 739 |
for(ArcIt e(_g);e!=INVALID;++e) |
740 | 740 |
{ |
741 | 741 |
Node s=_g.source(e); |
742 | 742 |
Node t=_g.target(e); |
743 | 743 |
if(barrier(s)&&!barrier(t)) delta+=(*_up)[e]; |
744 | 744 |
else if(barrier(t)&&!barrier(s)) delta-=(*_lo)[e]; |
745 | 745 |
} |
746 | 746 |
return _tol.negative(delta); |
747 | 747 |
} |
748 | 748 |
|
749 | 749 |
/// @} |
750 | 750 |
|
751 | 751 |
}; |
752 | 752 |
|
753 | 753 |
} |
754 | 754 |
|
755 | 755 |
#endif |
... | ... |
@@ -1596,41 +1596,41 @@ |
1596 | 1596 |
/// if (!d.reached(n)) { |
1597 | 1597 |
/// d.addSource(n); |
1598 | 1598 |
/// d.start(); |
1599 | 1599 |
/// } |
1600 | 1600 |
/// } |
1601 | 1601 |
///\endcode |
1602 | 1602 |
void run() { |
1603 | 1603 |
init(); |
1604 | 1604 |
for (NodeIt it(*_digraph); it != INVALID; ++it) { |
1605 | 1605 |
if (!reached(it)) { |
1606 | 1606 |
addSource(it); |
1607 | 1607 |
start(); |
1608 | 1608 |
} |
1609 | 1609 |
} |
1610 | 1610 |
} |
1611 | 1611 |
|
1612 | 1612 |
///@} |
1613 | 1613 |
|
1614 | 1614 |
/// \name Query Functions |
1615 | 1615 |
/// The results of the DFS algorithm can be obtained using these |
1616 | 1616 |
/// functions.\n |
1617 | 1617 |
/// Either \ref run(Node) "run()" or \ref start() should be called |
1618 | 1618 |
/// before using them. |
1619 | 1619 |
|
1620 | 1620 |
///@{ |
1621 | 1621 |
|
1622 | 1622 |
/// \brief Checks if a node is reached from the root(s). |
1623 | 1623 |
/// |
1624 | 1624 |
/// Returns \c true if \c v is reached from the root(s). |
1625 | 1625 |
/// |
1626 | 1626 |
/// \pre Either \ref run(Node) "run()" or \ref init() |
1627 | 1627 |
/// must be called before using this function. |
1628 |
bool reached(Node v) { return (*_reached)[v]; } |
|
1628 |
bool reached(Node v) const { return (*_reached)[v]; } |
|
1629 | 1629 |
|
1630 | 1630 |
///@} |
1631 | 1631 |
|
1632 | 1632 |
}; |
1633 | 1633 |
|
1634 | 1634 |
} //END OF NAMESPACE LEMON |
1635 | 1635 |
|
1636 | 1636 |
#endif |
... | ... |
@@ -337,65 +337,65 @@ |
337 | 337 |
/// \brief Sets the target node. |
338 | 338 |
/// |
339 | 339 |
/// Sets the target node. |
340 | 340 |
/// \return <tt>(*this)</tt> |
341 | 341 |
Preflow& target(const Node& node) { |
342 | 342 |
_target = node; |
343 | 343 |
return *this; |
344 | 344 |
} |
345 | 345 |
|
346 | 346 |
/// \brief Sets the elevator used by algorithm. |
347 | 347 |
/// |
348 | 348 |
/// Sets the elevator used by algorithm. |
349 | 349 |
/// If you don't use this function before calling \ref run() or |
350 | 350 |
/// \ref init(), an instance will be allocated automatically. |
351 | 351 |
/// The destructor deallocates this automatically allocated elevator, |
352 | 352 |
/// of course. |
353 | 353 |
/// \return <tt>(*this)</tt> |
354 | 354 |
Preflow& elevator(Elevator& elevator) { |
355 | 355 |
if (_local_level) { |
356 | 356 |
delete _level; |
357 | 357 |
_local_level = false; |
358 | 358 |
} |
359 | 359 |
_level = &elevator; |
360 | 360 |
return *this; |
361 | 361 |
} |
362 | 362 |
|
363 | 363 |
/// \brief Returns a const reference to the elevator. |
364 | 364 |
/// |
365 | 365 |
/// Returns a const reference to the elevator. |
366 | 366 |
/// |
367 | 367 |
/// \pre Either \ref run() or \ref init() must be called before |
368 | 368 |
/// using this function. |
369 |
const Elevator& elevator() { |
|
369 |
const Elevator& elevator() const { |
|
370 | 370 |
return *_level; |
371 | 371 |
} |
372 | 372 |
|
373 | 373 |
/// \brief Sets the tolerance used by algorithm. |
374 | 374 |
/// |
375 | 375 |
/// Sets the tolerance used by algorithm. |
376 | 376 |
Preflow& tolerance(const Tolerance& tolerance) const { |
377 | 377 |
_tolerance = tolerance; |
378 | 378 |
return *this; |
379 | 379 |
} |
380 | 380 |
|
381 | 381 |
/// \brief Returns a const reference to the tolerance. |
382 | 382 |
/// |
383 | 383 |
/// Returns a const reference to the tolerance. |
384 | 384 |
const Tolerance& tolerance() const { |
385 | 385 |
return tolerance; |
386 | 386 |
} |
387 | 387 |
|
388 | 388 |
/// \name Execution Control |
389 | 389 |
/// The simplest way to execute the preflow algorithm is to use |
390 | 390 |
/// \ref run() or \ref runMinCut().\n |
391 | 391 |
/// If you need more control on the initial solution or the execution, |
392 | 392 |
/// first you have to call one of the \ref init() functions, then |
393 | 393 |
/// \ref startFirstPhase() and if you need it \ref startSecondPhase(). |
394 | 394 |
|
395 | 395 |
///@{ |
396 | 396 |
|
397 | 397 |
/// \brief Initializes the internal data structures. |
398 | 398 |
/// |
399 | 399 |
/// Initializes the internal data structures and sets the initial |
400 | 400 |
/// flow to zero on each arc. |
401 | 401 |
void init() { |
... | ... |
@@ -889,65 +889,65 @@ |
889 | 889 |
///@{ |
890 | 890 |
|
891 | 891 |
/// \brief Returns the value of the maximum flow. |
892 | 892 |
/// |
893 | 893 |
/// Returns the value of the maximum flow by returning the excess |
894 | 894 |
/// of the target node. This value equals to the value of |
895 | 895 |
/// the maximum flow already after the first phase of the algorithm. |
896 | 896 |
/// |
897 | 897 |
/// \pre Either \ref run() or \ref init() must be called before |
898 | 898 |
/// using this function. |
899 | 899 |
Value flowValue() const { |
900 | 900 |
return (*_excess)[_target]; |
901 | 901 |
} |
902 | 902 |
|
903 | 903 |
/// \brief Returns the flow on the given arc. |
904 | 904 |
/// |
905 | 905 |
/// Returns the flow on the given arc. This method can |
906 | 906 |
/// be called after the second phase of the algorithm. |
907 | 907 |
/// |
908 | 908 |
/// \pre Either \ref run() or \ref init() must be called before |
909 | 909 |
/// using this function. |
910 | 910 |
Value flow(const Arc& arc) const { |
911 | 911 |
return (*_flow)[arc]; |
912 | 912 |
} |
913 | 913 |
|
914 | 914 |
/// \brief Returns a const reference to the flow map. |
915 | 915 |
/// |
916 | 916 |
/// Returns a const reference to the arc map storing the found flow. |
917 | 917 |
/// This method can be called after the second phase of the algorithm. |
918 | 918 |
/// |
919 | 919 |
/// \pre Either \ref run() or \ref init() must be called before |
920 | 920 |
/// using this function. |
921 |
const FlowMap& flowMap() { |
|
921 |
const FlowMap& flowMap() const { |
|
922 | 922 |
return *_flow; |
923 | 923 |
} |
924 | 924 |
|
925 | 925 |
/// \brief Returns \c true when the node is on the source side of the |
926 | 926 |
/// minimum cut. |
927 | 927 |
/// |
928 | 928 |
/// Returns true when the node is on the source side of the found |
929 | 929 |
/// minimum cut. This method can be called both after running \ref |
930 | 930 |
/// startFirstPhase() and \ref startSecondPhase(). |
931 | 931 |
/// |
932 | 932 |
/// \pre Either \ref run() or \ref init() must be called before |
933 | 933 |
/// using this function. |
934 | 934 |
bool minCut(const Node& node) const { |
935 | 935 |
return ((*_level)[node] == _level->maxLevel()) == _phase; |
936 | 936 |
} |
937 | 937 |
|
938 | 938 |
/// \brief Gives back a minimum value cut. |
939 | 939 |
/// |
940 | 940 |
/// Sets \c cutMap to the characteristic vector of a minimum value |
941 | 941 |
/// cut. \c cutMap should be a \ref concepts::WriteMap "writable" |
942 | 942 |
/// node map with \c bool (or convertible) value type. |
943 | 943 |
/// |
944 | 944 |
/// This method can be called both after running \ref startFirstPhase() |
945 | 945 |
/// and \ref startSecondPhase(). The result after the second phase |
946 | 946 |
/// could be slightly different if inexact computation is used. |
947 | 947 |
/// |
948 | 948 |
/// \note This function calls \ref minCut() for each node, so it runs in |
949 | 949 |
/// \f$O(n)\f$ time. |
950 | 950 |
/// |
951 | 951 |
/// \pre Either \ref run() or \ref init() must be called before |
952 | 952 |
/// using this function. |
953 | 953 |
template <typename CutMap> |
0 comments (0 inline)