Changeset 942:2b6bffe0e7e8 in lemon-1.2 for lemon/preflow.h
- Timestamp:
- 12/20/11 18:15:14 (12 years ago)
- Branch:
- default
- Parents:
- 941:7c4ba7daaf5f (diff), 915:633956ca9421 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Phase:
- public
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/preflow.h
r877 r942 544 544 _flow->set(e, (*_capacity)[e]); 545 545 (*_excess)[u] += rem; 546 if (u != _target && !_level->active(u)) {547 _level->activate(u);548 }549 546 } 550 547 } … … 556 553 _flow->set(e, 0); 557 554 (*_excess)[v] += rem; 558 if (v != _target && !_level->active(v)) { 559 _level->activate(v); 560 } 561 } 562 } 555 } 556 } 557 for (NodeIt n(_graph); n != INVALID; ++n) 558 if(n!=_source && n!=_target && _tolerance.positive((*_excess)[n])) 559 _level->activate(n); 560 563 561 return true; 564 562 } … … 577 575 _phase = true; 578 576 579 Node n = _level->highestActive(); 580 int level = _level->highestActiveLevel(); 581 while (n != INVALID) { 577 while (true) { 582 578 int num = _node_num; 583 579 584 while (num > 0 && n != INVALID) { 580 Node n = INVALID; 581 int level = -1; 582 583 while (num > 0) { 584 n = _level->highestActive(); 585 if (n == INVALID) goto first_phase_done; 586 level = _level->highestActiveLevel(); 587 --num; 588 585 589 Value excess = (*_excess)[n]; 586 590 int new_level = _level->maxLevel(); … … 648 652 _level->deactivate(n); 649 653 } 650 651 n = _level->highestActive(); 652 level = _level->highestActiveLevel(); 654 } 655 656 num = _node_num * 20; 657 while (num > 0) { 658 while (level >= 0 && _level->activeFree(level)) { 659 --level; 660 } 661 if (level == -1) { 662 n = _level->highestActive(); 663 level = _level->highestActiveLevel(); 664 if (n == INVALID) goto first_phase_done; 665 } else { 666 n = _level->activeOn(level); 667 } 653 668 --num; 654 } 655 656 num = _node_num * 20; 657 while (num > 0 && n != INVALID) { 669 658 670 Value excess = (*_excess)[n]; 659 671 int new_level = _level->maxLevel(); … … 721 733 _level->deactivate(n); 722 734 } 723 724 while (level >= 0 && _level->activeFree(level)) { 725 --level; 726 } 727 if (level == -1) { 728 n = _level->highestActive(); 729 level = _level->highestActiveLevel(); 730 } else { 731 n = _level->activeOn(level); 732 } 733 --num; 734 } 735 } 735 } 736 } 737 first_phase_done:; 736 738 } 737 739 -
lemon/preflow.h
r901 r942 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 095 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 53 53 /// The type of the map that stores the flow values. 54 54 /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept. 55 #ifdef DOXYGEN 56 typedef GR::ArcMap<Value> FlowMap; 57 #else 55 58 typedef typename Digraph::template ArcMap<Value> FlowMap; 59 #endif 56 60 57 61 /// \brief Instantiates a FlowMap. … … 68 72 /// The elevator type used by Preflow algorithm. 69 73 /// 70 /// \sa Elevator 71 /// \sa LinkedElevator 72 typedef LinkedElevator<Digraph, typename Digraph::Node> Elevator; 74 /// \sa Elevator, LinkedElevator 75 #ifdef DOXYGEN 76 typedef lemon::Elevator<GR, GR::Node> Elevator; 77 #else 78 typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator; 79 #endif 73 80 74 81 /// \brief Instantiates an Elevator. … … 96 103 /// This class provides an implementation of Goldberg-Tarjan's \e preflow 97 104 /// \e push-relabel algorithm producing a \ref max_flow 98 /// "flow of maximum value" in a digraph. 105 /// "flow of maximum value" in a digraph \ref clrs01algorithms, 106 /// \ref amo93networkflows, \ref goldberg88newapproach. 99 107 /// The preflow algorithms are the fastest known maximum 100 /// flow algorithms. The current implementation use a mixture of the108 /// flow algorithms. The current implementation uses a mixture of the 101 109 /// \e "highest label" and the \e "bound decrease" heuristics. 102 110 /// The worst case time complexity of the algorithm is \f$O(n^2\sqrt{e})\f$. … … 106 114 /// second phase constructs a feasible maximum flow on each arc. 107 115 /// 116 /// \warning This implementation cannot handle infinite or very large 117 /// capacities (e.g. the maximum value of \c CAP::Value). 118 /// 108 119 /// \tparam GR The type of the digraph the algorithm runs on. 109 120 /// \tparam CAP The type of the capacity map. The default map 110 121 /// type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". 122 /// \tparam TR The traits class that defines various types used by the 123 /// algorithm. By default, it is \ref PreflowDefaultTraits 124 /// "PreflowDefaultTraits<GR, CAP>". 125 /// In most cases, this parameter should not be set directly, 126 /// consider to use the named template parameters instead. 111 127 #ifdef DOXYGEN 112 128 template <typename GR, typename CAP, typename TR> … … 258 274 /// able to automatically created by the algorithm (i.e. the 259 275 /// digraph and the maximum level should be passed to it). 260 /// However an external elevator object could also be passed to the276 /// However, an external elevator object could also be passed to the 261 277 /// algorithm with the \ref elevator(Elevator&) "elevator()" function 262 278 /// before calling \ref run() or \ref init(). … … 372 388 } 373 389 374 /// \brief Sets the tolerance used by algorithm. 375 /// 376 /// Sets the tolerance used by algorithm. 390 /// \brief Sets the tolerance used by the algorithm. 391 /// 392 /// Sets the tolerance object used by the algorithm. 393 /// \return <tt>(*this)</tt> 377 394 Preflow& tolerance(const Tolerance& tolerance) { 378 395 _tolerance = tolerance; … … 382 399 /// \brief Returns a const reference to the tolerance. 383 400 /// 384 /// Returns a const reference to the tolerance. 401 /// Returns a const reference to the tolerance object used by 402 /// the algorithm. 385 403 const Tolerance& tolerance() const { 386 404 return _tolerance; … … 390 408 /// The simplest way to execute the preflow algorithm is to use 391 409 /// \ref run() or \ref runMinCut().\n 392 /// If you need morecontrol on the initial solution or the execution,393 /// first you have to call one of the \ref init() functions, then410 /// If you need better control on the initial solution or the execution, 411 /// you have to call one of the \ref init() functions first, then 394 412 /// \ref startFirstPhase() and if you need it \ref startSecondPhase(). 395 413
Note: See TracChangeset
for help on using the changeset viewer.