gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Rename Flow to Value in the flow algorithms (#266) We agreed that using Flow for the value type is misleading, since a flow should be rather a function on the arcs, not a single value. This patch reverts the changes of [dacc2cee2b4c] for Preflow and Circulation.
0 3 0
default
3 files changed with 73 insertions and 73 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
... ...
@@ -55,33 +55,33 @@
55 55
    /// The type of the map that stores the upper bounds (capacities)
56 56
    /// on the arcs.
57 57
    /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
58 58
    typedef UM UpperMap;
59 59

	
60 60
    /// \brief The type of supply map.
61 61
    ///
62 62
    /// The type of the map that stores the signed supply values of the 
63 63
    /// nodes. 
64 64
    /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
65 65
    typedef SM SupplyMap;
66 66

	
67
    /// \brief The type of the flow values.
68
    typedef typename SupplyMap::Value Flow;
67
    /// \brief The type of the flow and supply values.
68
    typedef typename SupplyMap::Value Value;
69 69

	
70 70
    /// \brief The type of the map that stores the flow values.
71 71
    ///
72 72
    /// The type of the map that stores the flow values.
73 73
    /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap"
74 74
    /// concept.
75
    typedef typename Digraph::template ArcMap<Flow> FlowMap;
75
    typedef typename Digraph::template ArcMap<Value> FlowMap;
76 76

	
77 77
    /// \brief Instantiates a FlowMap.
78 78
    ///
79 79
    /// This function instantiates a \ref FlowMap.
80 80
    /// \param digraph The digraph for which we would like to define
81 81
    /// the flow map.
82 82
    static FlowMap* createFlowMap(const Digraph& digraph) {
83 83
      return new FlowMap(digraph);
84 84
    }
85 85

	
86 86
    /// \brief The elevator type used by the algorithm.
87 87
    ///
... ...
@@ -95,25 +95,25 @@
95 95
    ///
96 96
    /// This function instantiates an \ref Elevator.
97 97
    /// \param digraph The digraph for which we would like to define
98 98
    /// the elevator.
99 99
    /// \param max_level The maximum level of the elevator.
100 100
    static Elevator* createElevator(const Digraph& digraph, int max_level) {
101 101
      return new Elevator(digraph, max_level);
102 102
    }
103 103

	
104 104
    /// \brief The tolerance used by the algorithm
105 105
    ///
106 106
    /// The tolerance used by the algorithm to handle inexact computation.
107
    typedef lemon::Tolerance<Flow> Tolerance;
107
    typedef lemon::Tolerance<Value> Tolerance;
108 108

	
109 109
  };
110 110

	
111 111
  /**
112 112
     \brief Push-relabel algorithm for the network circulation problem.
113 113

	
114 114
     \ingroup max_flow
115 115
     This class implements a push-relabel algorithm for the \e network
116 116
     \e circulation problem.
117 117
     It is to find a feasible circulation when lower and upper bounds
118 118
     are given for the flow values on the arcs and lower bounds are
119 119
     given for the difference between the outgoing and incoming flow
... ...
@@ -178,26 +178,26 @@
178 178
          typename LM = typename GR::template ArcMap<int>,
179 179
          typename UM = LM,
180 180
          typename SM = typename GR::template NodeMap<typename UM::Value>,
181 181
          typename TR = CirculationDefaultTraits<GR, LM, UM, SM> >
182 182
#endif
183 183
  class Circulation {
184 184
  public:
185 185

	
186 186
    ///The \ref CirculationDefaultTraits "traits class" of the algorithm.
187 187
    typedef TR Traits;
188 188
    ///The type of the digraph the algorithm runs on.
189 189
    typedef typename Traits::Digraph Digraph;
190
    ///The type of the flow values.
191
    typedef typename Traits::Flow Flow;
190
    ///The type of the flow and supply values.
191
    typedef typename Traits::Value Value;
192 192

	
193 193
    ///The type of the lower bound map.
194 194
    typedef typename Traits::LowerMap LowerMap;
195 195
    ///The type of the upper bound (capacity) map.
196 196
    typedef typename Traits::UpperMap UpperMap;
197 197
    ///The type of the supply map.
198 198
    typedef typename Traits::SupplyMap SupplyMap;
199 199
    ///The type of the flow map.
200 200
    typedef typename Traits::FlowMap FlowMap;
201 201

	
202 202
    ///The type of the elevator.
203 203
    typedef typename Traits::Elevator Elevator;
... ...
@@ -212,25 +212,25 @@
212 212
    int _node_num;
213 213

	
214 214
    const LowerMap *_lo;
215 215
    const UpperMap *_up;
216 216
    const SupplyMap *_supply;
217 217

	
218 218
    FlowMap *_flow;
219 219
    bool _local_flow;
220 220

	
221 221
    Elevator* _level;
222 222
    bool _local_level;
223 223

	
224
    typedef typename Digraph::template NodeMap<Flow> ExcessMap;
224
    typedef typename Digraph::template NodeMap<Value> ExcessMap;
225 225
    ExcessMap* _excess;
226 226

	
227 227
    Tolerance _tol;
228 228
    int _el;
229 229

	
230 230
  public:
231 231

	
232 232
    typedef Circulation Create;
233 233

	
234 234
    ///\name Named Template Parameters
235 235

	
236 236
    ///@{
... ...
@@ -521,25 +521,25 @@
521 521
      }
522 522

	
523 523
      for (ArcIt e(_g);e!=INVALID;++e) {
524 524
        if (!_tol.less(-(*_excess)[_g.target(e)], (*_up)[e])) {
525 525
          _flow->set(e, (*_up)[e]);
526 526
          (*_excess)[_g.target(e)] += (*_up)[e];
527 527
          (*_excess)[_g.source(e)] -= (*_up)[e];
528 528
        } else if (_tol.less(-(*_excess)[_g.target(e)], (*_lo)[e])) {
529 529
          _flow->set(e, (*_lo)[e]);
530 530
          (*_excess)[_g.target(e)] += (*_lo)[e];
531 531
          (*_excess)[_g.source(e)] -= (*_lo)[e];
532 532
        } else {
533
          Flow fc = -(*_excess)[_g.target(e)];
533
          Value fc = -(*_excess)[_g.target(e)];
534 534
          _flow->set(e, fc);
535 535
          (*_excess)[_g.target(e)] = 0;
536 536
          (*_excess)[_g.source(e)] -= fc;
537 537
        }
538 538
      }
539 539

	
540 540
      _level->initStart();
541 541
      for(NodeIt n(_g);n!=INVALID;++n)
542 542
        _level->initAddItem(n);
543 543
      _level->initFinish();
544 544
      for(NodeIt n(_g);n!=INVALID;++n)
545 545
        if(_tol.positive((*_excess)[n]))
... ...
@@ -554,53 +554,53 @@
554 554
    ///
555 555
    ///\sa barrier()
556 556
    ///\sa barrierMap()
557 557
    bool start()
558 558
    {
559 559

	
560 560
      Node act;
561 561
      Node bact=INVALID;
562 562
      Node last_activated=INVALID;
563 563
      while((act=_level->highestActive())!=INVALID) {
564 564
        int actlevel=(*_level)[act];
565 565
        int mlevel=_node_num;
566
        Flow exc=(*_excess)[act];
566
        Value exc=(*_excess)[act];
567 567

	
568 568
        for(OutArcIt e(_g,act);e!=INVALID; ++e) {
569 569
          Node v = _g.target(e);
570
          Flow fc=(*_up)[e]-(*_flow)[e];
570
          Value fc=(*_up)[e]-(*_flow)[e];
571 571
          if(!_tol.positive(fc)) continue;
572 572
          if((*_level)[v]<actlevel) {
573 573
            if(!_tol.less(fc, exc)) {
574 574
              _flow->set(e, (*_flow)[e] + exc);
575 575
              (*_excess)[v] += exc;
576 576
              if(!_level->active(v) && _tol.positive((*_excess)[v]))
577 577
                _level->activate(v);
578 578
              (*_excess)[act] = 0;
579 579
              _level->deactivate(act);
580 580
              goto next_l;
581 581
            }
582 582
            else {
583 583
              _flow->set(e, (*_up)[e]);
584 584
              (*_excess)[v] += fc;
585 585
              if(!_level->active(v) && _tol.positive((*_excess)[v]))
586 586
                _level->activate(v);
587 587
              exc-=fc;
588 588
            }
589 589
          }
590 590
          else if((*_level)[v]<mlevel) mlevel=(*_level)[v];
591 591
        }
592 592
        for(InArcIt e(_g,act);e!=INVALID; ++e) {
593 593
          Node v = _g.source(e);
594
          Flow fc=(*_flow)[e]-(*_lo)[e];
594
          Value fc=(*_flow)[e]-(*_lo)[e];
595 595
          if(!_tol.positive(fc)) continue;
596 596
          if((*_level)[v]<actlevel) {
597 597
            if(!_tol.less(fc, exc)) {
598 598
              _flow->set(e, (*_flow)[e] - exc);
599 599
              (*_excess)[v] += exc;
600 600
              if(!_level->active(v) && _tol.positive((*_excess)[v]))
601 601
                _level->activate(v);
602 602
              (*_excess)[act] = 0;
603 603
              _level->deactivate(act);
604 604
              goto next_l;
605 605
            }
606 606
            else {
... ...
@@ -652,31 +652,31 @@
652 652
    }
653 653

	
654 654
    /// @}
655 655

	
656 656
    /// \name Query Functions
657 657
    /// The results of the circulation algorithm can be obtained using
658 658
    /// these functions.\n
659 659
    /// Either \ref run() or \ref start() should be called before
660 660
    /// using them.
661 661

	
662 662
    ///@{
663 663

	
664
    /// \brief Returns the flow on the given arc.
664
    /// \brief Returns the flow value on the given arc.
665 665
    ///
666
    /// Returns the flow on the given arc.
666
    /// Returns the flow value on the given arc.
667 667
    ///
668 668
    /// \pre Either \ref run() or \ref init() must be called before
669 669
    /// using this function.
670
    Flow flow(const Arc& arc) const {
670
    Value flow(const Arc& arc) const {
671 671
      return (*_flow)[arc];
672 672
    }
673 673

	
674 674
    /// \brief Returns a const reference to the flow map.
675 675
    ///
676 676
    /// Returns a const reference to the arc map storing the found flow.
677 677
    ///
678 678
    /// \pre Either \ref run() or \ref init() must be called before
679 679
    /// using this function.
680 680
    const FlowMap& flowMap() const {
681 681
      return *_flow;
682 682
    }
... ...
@@ -741,43 +741,43 @@
741 741

	
742 742
    ///@{
743 743

	
744 744
    ///Check if the found flow is a feasible circulation
745 745

	
746 746
    ///Check if the found flow is a feasible circulation,
747 747
    ///
748 748
    bool checkFlow() const {
749 749
      for(ArcIt e(_g);e!=INVALID;++e)
750 750
        if((*_flow)[e]<(*_lo)[e]||(*_flow)[e]>(*_up)[e]) return false;
751 751
      for(NodeIt n(_g);n!=INVALID;++n)
752 752
        {
753
          Flow dif=-(*_supply)[n];
753
          Value dif=-(*_supply)[n];
754 754
          for(InArcIt e(_g,n);e!=INVALID;++e) dif-=(*_flow)[e];
755 755
          for(OutArcIt e(_g,n);e!=INVALID;++e) dif+=(*_flow)[e];
756 756
          if(_tol.negative(dif)) return false;
757 757
        }
758 758
      return true;
759 759
    }
760 760

	
761 761
    ///Check whether or not the last execution provides a barrier
762 762

	
763 763
    ///Check whether or not the last execution provides a barrier.
764 764
    ///\sa barrier()
765 765
    ///\sa barrierMap()
766 766
    bool checkBarrier() const
767 767
    {
768
      Flow delta=0;
769
      Flow inf_cap = std::numeric_limits<Flow>::has_infinity ?
770
        std::numeric_limits<Flow>::infinity() :
771
        std::numeric_limits<Flow>::max();
768
      Value delta=0;
769
      Value inf_cap = std::numeric_limits<Value>::has_infinity ?
770
        std::numeric_limits<Value>::infinity() :
771
        std::numeric_limits<Value>::max();
772 772
      for(NodeIt n(_g);n!=INVALID;++n)
773 773
        if(barrier(n))
774 774
          delta-=(*_supply)[n];
775 775
      for(ArcIt e(_g);e!=INVALID;++e)
776 776
        {
777 777
          Node s=_g.source(e);
778 778
          Node t=_g.target(e);
779 779
          if(barrier(s)&&!barrier(t)) {
780 780
            if (_tol.less(inf_cap - (*_up)[e], delta)) return false;
781 781
            delta+=(*_up)[e];
782 782
          }
783 783
          else if(barrier(t)&&!barrier(s)) delta-=(*_lo)[e];
Ignore white space 6 line context
... ...
@@ -47,52 +47,52 @@
47 47
  ///
48 48
  /// In general this class is the fastest implementation available
49 49
  /// in LEMON for the minimum cost flow problem.
50 50
  /// Moreover it supports both directions of the supply/demand inequality
51 51
  /// constraints. For more information see \ref SupplyType.
52 52
  ///
53 53
  /// Most of the parameters of the problem (except for the digraph)
54 54
  /// can be given using separate functions, and the algorithm can be
55 55
  /// executed using the \ref run() function. If some parameters are not
56 56
  /// specified, then default values will be used.
57 57
  ///
58 58
  /// \tparam GR The digraph type the algorithm runs on.
59
  /// \tparam F The value type used for flow amounts, capacity bounds
59
  /// \tparam V The value type used for flow amounts, capacity bounds
60 60
  /// and supply values in the algorithm. By default it is \c int.
61 61
  /// \tparam C The value type used for costs and potentials in the
62
  /// algorithm. By default it is the same as \c F.
62
  /// algorithm. By default it is the same as \c V.
63 63
  ///
64 64
  /// \warning Both value types must be signed and all input data must
65 65
  /// be integer.
66 66
  ///
67 67
  /// \note %NetworkSimplex provides five different pivot rule
68 68
  /// implementations, from which the most efficient one is used
69 69
  /// by default. For more information see \ref PivotRule.
70
  template <typename GR, typename F = int, typename C = F>
70
  template <typename GR, typename V = int, typename C = V>
71 71
  class NetworkSimplex
72 72
  {
73 73
  public:
74 74

	
75 75
    /// The flow type of the algorithm
76
    typedef F Flow;
76
    typedef V Value;
77 77
    /// The cost type of the algorithm
78 78
    typedef C Cost;
79 79
#ifdef DOXYGEN
80 80
    /// The type of the flow map
81
    typedef GR::ArcMap<Flow> FlowMap;
81
    typedef GR::ArcMap<Value> FlowMap;
82 82
    /// The type of the potential map
83 83
    typedef GR::NodeMap<Cost> PotentialMap;
84 84
#else
85 85
    /// The type of the flow map
86
    typedef typename GR::template ArcMap<Flow> FlowMap;
86
    typedef typename GR::template ArcMap<Value> FlowMap;
87 87
    /// The type of the potential map
88 88
    typedef typename GR::template NodeMap<Cost> PotentialMap;
89 89
#endif
90 90

	
91 91
  public:
92 92

	
93 93
    /// \brief Problem type constants for the \c run() function.
94 94
    ///
95 95
    /// Enum type containing the problem type constants that can be
96 96
    /// returned by the \ref run() function of the algorithm.
97 97
    enum ProblemType {
98 98
      /// The problem has no feasible solution (flow).
... ...
@@ -197,60 +197,60 @@
197 197

	
198 198
      /// The Altering Candidate List pivot rule.
199 199
      /// It is a modified version of the Candidate List method.
200 200
      /// It keeps only the several best eligible arcs from the former
201 201
      /// candidate list and extends this list in every iteration.
202 202
      ALTERING_LIST
203 203
    };
204 204
    
205 205
  private:
206 206

	
207 207
    TEMPLATE_DIGRAPH_TYPEDEFS(GR);
208 208

	
209
    typedef typename GR::template ArcMap<Flow> FlowArcMap;
209
    typedef typename GR::template ArcMap<Value> ValueArcMap;
210 210
    typedef typename GR::template ArcMap<Cost> CostArcMap;
211
    typedef typename GR::template NodeMap<Flow> FlowNodeMap;
211
    typedef typename GR::template NodeMap<Value> ValueNodeMap;
212 212

	
213 213
    typedef std::vector<Arc> ArcVector;
214 214
    typedef std::vector<Node> NodeVector;
215 215
    typedef std::vector<int> IntVector;
216 216
    typedef std::vector<bool> BoolVector;
217
    typedef std::vector<Flow> FlowVector;
217
    typedef std::vector<Value> FlowVector;
218 218
    typedef std::vector<Cost> CostVector;
219 219

	
220 220
    // State constants for arcs
221 221
    enum ArcStateEnum {
222 222
      STATE_UPPER = -1,
223 223
      STATE_TREE  =  0,
224 224
      STATE_LOWER =  1
225 225
    };
226 226

	
227 227
  private:
228 228

	
229 229
    // Data related to the underlying digraph
230 230
    const GR &_graph;
231 231
    int _node_num;
232 232
    int _arc_num;
233 233

	
234 234
    // Parameters of the problem
235
    FlowArcMap *_plower;
236
    FlowArcMap *_pupper;
235
    ValueArcMap *_plower;
236
    ValueArcMap *_pupper;
237 237
    CostArcMap *_pcost;
238
    FlowNodeMap *_psupply;
238
    ValueNodeMap *_psupply;
239 239
    bool _pstsup;
240 240
    Node _psource, _ptarget;
241
    Flow _pstflow;
241
    Value _pstflow;
242 242
    SupplyType _stype;
243 243
    
244
    Flow _sum_supply;
244
    Value _sum_supply;
245 245

	
246 246
    // Result maps
247 247
    FlowMap *_flow_map;
248 248
    PotentialMap *_potential_map;
249 249
    bool _local_flow;
250 250
    bool _local_potential;
251 251

	
252 252
    // Data structures for storing the digraph
253 253
    IntNodeMap _node_id;
254 254
    ArcVector _arc_ref;
255 255
    IntVector _source;
256 256
    IntVector _target;
... ...
@@ -269,34 +269,34 @@
269 269
    IntVector _rev_thread;
270 270
    IntVector _succ_num;
271 271
    IntVector _last_succ;
272 272
    IntVector _dirty_revs;
273 273
    BoolVector _forward;
274 274
    IntVector _state;
275 275
    int _root;
276 276

	
277 277
    // Temporary data used in the current pivot iteration
278 278
    int in_arc, join, u_in, v_in, u_out, v_out;
279 279
    int first, second, right, last;
280 280
    int stem, par_stem, new_stem;
281
    Flow delta;
281
    Value delta;
282 282

	
283 283
  public:
284 284
  
285 285
    /// \brief Constant for infinite upper bounds (capacities).
286 286
    ///
287 287
    /// Constant for infinite upper bounds (capacities).
288
    /// It is \c std::numeric_limits<Flow>::infinity() if available,
289
    /// \c std::numeric_limits<Flow>::max() otherwise.
290
    const Flow INF;
288
    /// It is \c std::numeric_limits<Value>::infinity() if available,
289
    /// \c std::numeric_limits<Value>::max() otherwise.
290
    const Value INF;
291 291

	
292 292
  private:
293 293

	
294 294
    // Implementation of the First Eligible pivot rule
295 295
    class FirstEligiblePivotRule
296 296
    {
297 297
    private:
298 298

	
299 299
      // References to the NetworkSimplex class
300 300
      const IntVector  &_source;
301 301
      const IntVector  &_target;
302 302
      const CostVector &_cost;
... ...
@@ -686,84 +686,84 @@
686 686
    /// \brief Constructor.
687 687
    ///
688 688
    /// The constructor of the class.
689 689
    ///
690 690
    /// \param graph The digraph the algorithm runs on.
691 691
    NetworkSimplex(const GR& graph) :
692 692
      _graph(graph),
693 693
      _plower(NULL), _pupper(NULL), _pcost(NULL),
694 694
      _psupply(NULL), _pstsup(false), _stype(GEQ),
695 695
      _flow_map(NULL), _potential_map(NULL),
696 696
      _local_flow(false), _local_potential(false),
697 697
      _node_id(graph),
698
      INF(std::numeric_limits<Flow>::has_infinity ?
699
          std::numeric_limits<Flow>::infinity() :
700
          std::numeric_limits<Flow>::max())
698
      INF(std::numeric_limits<Value>::has_infinity ?
699
          std::numeric_limits<Value>::infinity() :
700
          std::numeric_limits<Value>::max())
701 701
    {
702 702
      // Check the value types
703
      LEMON_ASSERT(std::numeric_limits<Flow>::is_signed,
703
      LEMON_ASSERT(std::numeric_limits<Value>::is_signed,
704 704
        "The flow type of NetworkSimplex must be signed");
705 705
      LEMON_ASSERT(std::numeric_limits<Cost>::is_signed,
706 706
        "The cost type of NetworkSimplex must be signed");
707 707
    }
708 708

	
709 709
    /// Destructor.
710 710
    ~NetworkSimplex() {
711 711
      if (_local_flow) delete _flow_map;
712 712
      if (_local_potential) delete _potential_map;
713 713
    }
714 714

	
715 715
    /// \name Parameters
716 716
    /// The parameters of the algorithm can be specified using these
717 717
    /// functions.
718 718

	
719 719
    /// @{
720 720

	
721 721
    /// \brief Set the lower bounds on the arcs.
722 722
    ///
723 723
    /// This function sets the lower bounds on the arcs.
724 724
    /// If it is not used before calling \ref run(), the lower bounds
725 725
    /// will be set to zero on all arcs.
726 726
    ///
727 727
    /// \param map An arc map storing the lower bounds.
728
    /// Its \c Value type must be convertible to the \c Flow type
728
    /// Its \c Value type must be convertible to the \c Value type
729 729
    /// of the algorithm.
730 730
    ///
731 731
    /// \return <tt>(*this)</tt>
732 732
    template <typename LowerMap>
733 733
    NetworkSimplex& lowerMap(const LowerMap& map) {
734 734
      delete _plower;
735
      _plower = new FlowArcMap(_graph);
735
      _plower = new ValueArcMap(_graph);
736 736
      for (ArcIt a(_graph); a != INVALID; ++a) {
737 737
        (*_plower)[a] = map[a];
738 738
      }
739 739
      return *this;
740 740
    }
741 741

	
742 742
    /// \brief Set the upper bounds (capacities) on the arcs.
743 743
    ///
744 744
    /// This function sets the upper bounds (capacities) on the arcs.
745 745
    /// If it is not used before calling \ref run(), the upper bounds
746 746
    /// will be set to \ref INF on all arcs (i.e. the flow value will be
747 747
    /// unbounded from above on each arc).
748 748
    ///
749 749
    /// \param map An arc map storing the upper bounds.
750
    /// Its \c Value type must be convertible to the \c Flow type
750
    /// Its \c Value type must be convertible to the \c Value type
751 751
    /// of the algorithm.
752 752
    ///
753 753
    /// \return <tt>(*this)</tt>
754 754
    template<typename UpperMap>
755 755
    NetworkSimplex& upperMap(const UpperMap& map) {
756 756
      delete _pupper;
757
      _pupper = new FlowArcMap(_graph);
757
      _pupper = new ValueArcMap(_graph);
758 758
      for (ArcIt a(_graph); a != INVALID; ++a) {
759 759
        (*_pupper)[a] = map[a];
760 760
      }
761 761
      return *this;
762 762
    }
763 763

	
764 764
    /// \brief Set the costs of the arcs.
765 765
    ///
766 766
    /// This function sets the costs of the arcs.
767 767
    /// If it is not used before calling \ref run(), the costs
768 768
    /// will be set to \c 1 on all arcs.
769 769
    ///
... ...
@@ -781,58 +781,58 @@
781 781
      }
782 782
      return *this;
783 783
    }
784 784

	
785 785
    /// \brief Set the supply values of the nodes.
786 786
    ///
787 787
    /// This function sets the supply values of the nodes.
788 788
    /// If neither this function nor \ref stSupply() is used before
789 789
    /// calling \ref run(), the supply of each node will be set to zero.
790 790
    /// (It makes sense only if non-zero lower bounds are given.)
791 791
    ///
792 792
    /// \param map A node map storing the supply values.
793
    /// Its \c Value type must be convertible to the \c Flow type
793
    /// Its \c Value type must be convertible to the \c Value type
794 794
    /// of the algorithm.
795 795
    ///
796 796
    /// \return <tt>(*this)</tt>
797 797
    template<typename SupplyMap>
798 798
    NetworkSimplex& supplyMap(const SupplyMap& map) {
799 799
      delete _psupply;
800 800
      _pstsup = false;
801
      _psupply = new FlowNodeMap(_graph);
801
      _psupply = new ValueNodeMap(_graph);
802 802
      for (NodeIt n(_graph); n != INVALID; ++n) {
803 803
        (*_psupply)[n] = map[n];
804 804
      }
805 805
      return *this;
806 806
    }
807 807

	
808 808
    /// \brief Set single source and target nodes and a supply value.
809 809
    ///
810 810
    /// This function sets a single source node and a single target node
811 811
    /// and the required flow value.
812 812
    /// If neither this function nor \ref supplyMap() is used before
813 813
    /// calling \ref run(), the supply of each node will be set to zero.
814 814
    /// (It makes sense only if non-zero lower bounds are given.)
815 815
    ///
816 816
    /// Using this function has the same effect as using \ref supplyMap()
817 817
    /// with such a map in which \c k is assigned to \c s, \c -k is
818 818
    /// assigned to \c t and all other nodes have zero supply value.
819 819
    ///
820 820
    /// \param s The source node.
821 821
    /// \param t The target node.
822 822
    /// \param k The required amount of flow from node \c s to node \c t
823 823
    /// (i.e. the supply of \c s and the demand of \c t).
824 824
    ///
825 825
    /// \return <tt>(*this)</tt>
826
    NetworkSimplex& stSupply(const Node& s, const Node& t, Flow k) {
826
    NetworkSimplex& stSupply(const Node& s, const Node& t, Value k) {
827 827
      delete _psupply;
828 828
      _psupply = NULL;
829 829
      _pstsup = true;
830 830
      _psource = s;
831 831
      _ptarget = t;
832 832
      _pstflow = k;
833 833
      return *this;
834 834
    }
835 835
    
836 836
    /// \brief Set the type of the supply constraints.
837 837
    ///
838 838
    /// This function sets the type of the supply/demand constraints.
... ...
@@ -1016,25 +1016,25 @@
1016 1016

	
1017 1017
#ifndef DOXYGEN
1018 1018
    Cost totalCost() const {
1019 1019
      return totalCost<Cost>();
1020 1020
    }
1021 1021
#endif
1022 1022

	
1023 1023
    /// \brief Return the flow on the given arc.
1024 1024
    ///
1025 1025
    /// This function returns the flow on the given arc.
1026 1026
    ///
1027 1027
    /// \pre \ref run() must be called before using this function.
1028
    Flow flow(const Arc& a) const {
1028
    Value flow(const Arc& a) const {
1029 1029
      return (*_flow_map)[a];
1030 1030
    }
1031 1031

	
1032 1032
    /// \brief Return a const reference to the flow map.
1033 1033
    ///
1034 1034
    /// This function returns a const reference to an arc map storing
1035 1035
    /// the found flow.
1036 1036
    ///
1037 1037
    /// \pre \ref run() must be called before using this function.
1038 1038
    const FlowMap& flowMap() const {
1039 1039
      return *_flow_map;
1040 1040
    }
... ...
@@ -1195,25 +1195,25 @@
1195 1195
        if (_pcost) {
1196 1196
          for (int i = 0; i != _arc_num; ++i)
1197 1197
            _cost[i] = (*_pcost)[_arc_ref[i]];
1198 1198
        } else {
1199 1199
          for (int i = 0; i != _arc_num; ++i)
1200 1200
            _cost[i] = 1;
1201 1201
        }
1202 1202
      }
1203 1203
      
1204 1204
      // Remove non-zero lower bounds
1205 1205
      if (_plower) {
1206 1206
        for (int i = 0; i != _arc_num; ++i) {
1207
          Flow c = (*_plower)[_arc_ref[i]];
1207
          Value c = (*_plower)[_arc_ref[i]];
1208 1208
          if (c > 0) {
1209 1209
            if (_cap[i] < INF) _cap[i] -= c;
1210 1210
            _supply[_source[i]] -= c;
1211 1211
            _supply[_target[i]] += c;
1212 1212
          }
1213 1213
          else if (c < 0) {
1214 1214
            if (_cap[i] < INF + c) {
1215 1215
              _cap[i] -= c;
1216 1216
            } else {
1217 1217
              _cap[i] = INF;
1218 1218
            }
1219 1219
            _supply[_source[i]] -= c;
... ...
@@ -1266,25 +1266,25 @@
1266 1266
    bool findLeavingArc() {
1267 1267
      // Initialize first and second nodes according to the direction
1268 1268
      // of the cycle
1269 1269
      if (_state[in_arc] == STATE_LOWER) {
1270 1270
        first  = _source[in_arc];
1271 1271
        second = _target[in_arc];
1272 1272
      } else {
1273 1273
        first  = _target[in_arc];
1274 1274
        second = _source[in_arc];
1275 1275
      }
1276 1276
      delta = _cap[in_arc];
1277 1277
      int result = 0;
1278
      Flow d;
1278
      Value d;
1279 1279
      int e;
1280 1280

	
1281 1281
      // Search the cycle along the path form the first node to the root
1282 1282
      for (int u = first; u != join; u = _parent[u]) {
1283 1283
        e = _pred[u];
1284 1284
        d = _forward[u] ?
1285 1285
          _flow[e] : (_cap[e] == INF ? INF : _cap[e] - _flow[e]);
1286 1286
        if (d < delta) {
1287 1287
          delta = d;
1288 1288
          u_out = u;
1289 1289
          result = 1;
1290 1290
        }
... ...
@@ -1306,25 +1306,25 @@
1306 1306
        v_in = second;
1307 1307
      } else {
1308 1308
        u_in = second;
1309 1309
        v_in = first;
1310 1310
      }
1311 1311
      return result != 0;
1312 1312
    }
1313 1313

	
1314 1314
    // Change _flow and _state vectors
1315 1315
    void changeFlow(bool change) {
1316 1316
      // Augment along the cycle
1317 1317
      if (delta > 0) {
1318
        Flow val = _state[in_arc] * delta;
1318
        Value val = _state[in_arc] * delta;
1319 1319
        _flow[in_arc] += val;
1320 1320
        for (int u = _source[in_arc]; u != join; u = _parent[u]) {
1321 1321
          _flow[_pred[u]] += _forward[u] ? -val : val;
1322 1322
        }
1323 1323
        for (int u = _target[in_arc]; u != join; u = _parent[u]) {
1324 1324
          _flow[_pred[u]] += _forward[u] ? val : -val;
1325 1325
        }
1326 1326
      }
1327 1327
      // Update the state of the entering and leaving arcs
1328 1328
      if (change) {
1329 1329
        _state[in_arc] = STATE_TREE;
1330 1330
        _state[_pred[u_out]] =
Ignore white space 24 line context
... ...
@@ -37,31 +37,31 @@
37 37
  struct PreflowDefaultTraits {
38 38

	
39 39
    /// \brief The type of the digraph the algorithm runs on.
40 40
    typedef GR Digraph;
41 41

	
42 42
    /// \brief The type of the map that stores the arc capacities.
43 43
    ///
44 44
    /// The type of the map that stores the arc capacities.
45 45
    /// It must meet the \ref concepts::ReadMap "ReadMap" concept.
46 46
    typedef CAP CapacityMap;
47 47

	
48 48
    /// \brief The type of the flow values.
49
    typedef typename CapacityMap::Value Flow;
49
    typedef typename CapacityMap::Value Value;
50 50

	
51 51
    /// \brief The type of the map that stores the flow values.
52 52
    ///
53 53
    /// The type of the map that stores the flow values.
54 54
    /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
55
    typedef typename Digraph::template ArcMap<Flow> FlowMap;
55
    typedef typename Digraph::template ArcMap<Value> FlowMap;
56 56

	
57 57
    /// \brief Instantiates a FlowMap.
58 58
    ///
59 59
    /// This function instantiates a \ref FlowMap.
60 60
    /// \param digraph The digraph for which we would like to define
61 61
    /// the flow map.
62 62
    static FlowMap* createFlowMap(const Digraph& digraph) {
63 63
      return new FlowMap(digraph);
64 64
    }
65 65

	
66 66
    /// \brief The elevator type used by Preflow algorithm.
67 67
    ///
... ...
@@ -75,25 +75,25 @@
75 75
    ///
76 76
    /// This function instantiates an \ref Elevator.
77 77
    /// \param digraph The digraph for which we would like to define
78 78
    /// the elevator.
79 79
    /// \param max_level The maximum level of the elevator.
80 80
    static Elevator* createElevator(const Digraph& digraph, int max_level) {
81 81
      return new Elevator(digraph, max_level);
82 82
    }
83 83

	
84 84
    /// \brief The tolerance used by the algorithm
85 85
    ///
86 86
    /// The tolerance used by the algorithm to handle inexact computation.
87
    typedef lemon::Tolerance<Flow> Tolerance;
87
    typedef lemon::Tolerance<Value> Tolerance;
88 88

	
89 89
  };
90 90

	
91 91

	
92 92
  /// \ingroup max_flow
93 93
  ///
94 94
  /// \brief %Preflow algorithm class.
95 95
  ///
96 96
  /// This class provides an implementation of Goldberg-Tarjan's \e preflow
97 97
  /// \e push-relabel algorithm producing a \ref max_flow
98 98
  /// "flow of maximum value" in a digraph.
99 99
  /// The preflow algorithms are the fastest known maximum
... ...
@@ -116,25 +116,25 @@
116 116
            typename TR = PreflowDefaultTraits<GR, CAP> >
117 117
#endif
118 118
  class Preflow {
119 119
  public:
120 120

	
121 121
    ///The \ref PreflowDefaultTraits "traits class" of the algorithm.
122 122
    typedef TR Traits;
123 123
    ///The type of the digraph the algorithm runs on.
124 124
    typedef typename Traits::Digraph Digraph;
125 125
    ///The type of the capacity map.
126 126
    typedef typename Traits::CapacityMap CapacityMap;
127 127
    ///The type of the flow values.
128
    typedef typename Traits::Flow Flow;
128
    typedef typename Traits::Value Value;
129 129

	
130 130
    ///The type of the flow map.
131 131
    typedef typename Traits::FlowMap FlowMap;
132 132
    ///The type of the elevator.
133 133
    typedef typename Traits::Elevator Elevator;
134 134
    ///The type of the tolerance.
135 135
    typedef typename Traits::Tolerance Tolerance;
136 136

	
137 137
  private:
138 138

	
139 139
    TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
140 140

	
... ...
@@ -142,25 +142,25 @@
142 142
    const CapacityMap* _capacity;
143 143

	
144 144
    int _node_num;
145 145

	
146 146
    Node _source, _target;
147 147

	
148 148
    FlowMap* _flow;
149 149
    bool _local_flow;
150 150

	
151 151
    Elevator* _level;
152 152
    bool _local_level;
153 153

	
154
    typedef typename Digraph::template NodeMap<Flow> ExcessMap;
154
    typedef typename Digraph::template NodeMap<Value> ExcessMap;
155 155
    ExcessMap* _excess;
156 156

	
157 157
    Tolerance _tolerance;
158 158

	
159 159
    bool _phase;
160 160

	
161 161

	
162 162
    void createStructures() {
163 163
      _node_num = countNodes(_graph);
164 164

	
165 165
      if (!_flow) {
166 166
        _flow = Traits::createFlowMap(_graph);
... ...
@@ -461,25 +461,25 @@
461 461
    /// source node the incoming flow should greater or equal to the
462 462
    /// outgoing flow.
463 463
    /// \return \c false if the given \c flowMap is not a preflow.
464 464
    template <typename FlowMap>
465 465
    bool init(const FlowMap& flowMap) {
466 466
      createStructures();
467 467

	
468 468
      for (ArcIt e(_graph); e != INVALID; ++e) {
469 469
        _flow->set(e, flowMap[e]);
470 470
      }
471 471

	
472 472
      for (NodeIt n(_graph); n != INVALID; ++n) {
473
        Flow excess = 0;
473
        Value excess = 0;
474 474
        for (InArcIt e(_graph, n); e != INVALID; ++e) {
475 475
          excess += (*_flow)[e];
476 476
        }
477 477
        for (OutArcIt e(_graph, n); e != INVALID; ++e) {
478 478
          excess -= (*_flow)[e];
479 479
        }
480 480
        if (excess < 0 && n != _source) return false;
481 481
        (*_excess)[n] = excess;
482 482
      }
483 483

	
484 484
      typename Digraph::template NodeMap<bool> reached(_graph, false);
485 485

	
... ...
@@ -510,37 +510,37 @@
510 510
            if (!reached[v] && _tolerance.positive((*_flow)[e])) {
511 511
              reached[v] = true;
512 512
              _level->initAddItem(v);
513 513
              nqueue.push_back(v);
514 514
            }
515 515
          }
516 516
        }
517 517
        queue.swap(nqueue);
518 518
      }
519 519
      _level->initFinish();
520 520

	
521 521
      for (OutArcIt e(_graph, _source); e != INVALID; ++e) {
522
        Flow rem = (*_capacity)[e] - (*_flow)[e];
522
        Value rem = (*_capacity)[e] - (*_flow)[e];
523 523
        if (_tolerance.positive(rem)) {
524 524
          Node u = _graph.target(e);
525 525
          if ((*_level)[u] == _level->maxLevel()) continue;
526 526
          _flow->set(e, (*_capacity)[e]);
527 527
          (*_excess)[u] += rem;
528 528
          if (u != _target && !_level->active(u)) {
529 529
            _level->activate(u);
530 530
          }
531 531
        }
532 532
      }
533 533
      for (InArcIt e(_graph, _source); e != INVALID; ++e) {
534
        Flow rem = (*_flow)[e];
534
        Value rem = (*_flow)[e];
535 535
        if (_tolerance.positive(rem)) {
536 536
          Node v = _graph.source(e);
537 537
          if ((*_level)[v] == _level->maxLevel()) continue;
538 538
          _flow->set(e, 0);
539 539
          (*_excess)[v] += rem;
540 540
          if (v != _target && !_level->active(v)) {
541 541
            _level->activate(v);
542 542
          }
543 543
        }
544 544
      }
545 545
      return true;
546 546
    }
... ...
@@ -555,52 +555,52 @@
555 555
    /// minCut() returns a minimum cut.
556 556
    /// \pre One of the \ref init() functions must be called before
557 557
    /// using this function.
558 558
    void startFirstPhase() {
559 559
      _phase = true;
560 560

	
561 561
      Node n = _level->highestActive();
562 562
      int level = _level->highestActiveLevel();
563 563
      while (n != INVALID) {
564 564
        int num = _node_num;
565 565

	
566 566
        while (num > 0 && n != INVALID) {
567
          Flow excess = (*_excess)[n];
567
          Value excess = (*_excess)[n];
568 568
          int new_level = _level->maxLevel();
569 569

	
570 570
          for (OutArcIt e(_graph, n); e != INVALID; ++e) {
571
            Flow rem = (*_capacity)[e] - (*_flow)[e];
571
            Value rem = (*_capacity)[e] - (*_flow)[e];
572 572
            if (!_tolerance.positive(rem)) continue;
573 573
            Node v = _graph.target(e);
574 574
            if ((*_level)[v] < level) {
575 575
              if (!_level->active(v) && v != _target) {
576 576
                _level->activate(v);
577 577
              }
578 578
              if (!_tolerance.less(rem, excess)) {
579 579
                _flow->set(e, (*_flow)[e] + excess);
580 580
                (*_excess)[v] += excess;
581 581
                excess = 0;
582 582
                goto no_more_push_1;
583 583
              } else {
584 584
                excess -= rem;
585 585
                (*_excess)[v] += rem;
586 586
                _flow->set(e, (*_capacity)[e]);
587 587
              }
588 588
            } else if (new_level > (*_level)[v]) {
589 589
              new_level = (*_level)[v];
590 590
            }
591 591
          }
592 592

	
593 593
          for (InArcIt e(_graph, n); e != INVALID; ++e) {
594
            Flow rem = (*_flow)[e];
594
            Value rem = (*_flow)[e];
595 595
            if (!_tolerance.positive(rem)) continue;
596 596
            Node v = _graph.source(e);
597 597
            if ((*_level)[v] < level) {
598 598
              if (!_level->active(v) && v != _target) {
599 599
                _level->activate(v);
600 600
              }
601 601
              if (!_tolerance.less(rem, excess)) {
602 602
                _flow->set(e, (*_flow)[e] - excess);
603 603
                (*_excess)[v] += excess;
604 604
                excess = 0;
605 605
                goto no_more_push_1;
606 606
              } else {
... ...
@@ -628,52 +628,52 @@
628 628
            }
629 629
          } else {
630 630
            _level->deactivate(n);
631 631
          }
632 632

	
633 633
          n = _level->highestActive();
634 634
          level = _level->highestActiveLevel();
635 635
          --num;
636 636
        }
637 637

	
638 638
        num = _node_num * 20;
639 639
        while (num > 0 && n != INVALID) {
640
          Flow excess = (*_excess)[n];
640
          Value excess = (*_excess)[n];
641 641
          int new_level = _level->maxLevel();
642 642

	
643 643
          for (OutArcIt e(_graph, n); e != INVALID; ++e) {
644
            Flow rem = (*_capacity)[e] - (*_flow)[e];
644
            Value rem = (*_capacity)[e] - (*_flow)[e];
645 645
            if (!_tolerance.positive(rem)) continue;
646 646
            Node v = _graph.target(e);
647 647
            if ((*_level)[v] < level) {
648 648
              if (!_level->active(v) && v != _target) {
649 649
                _level->activate(v);
650 650
              }
651 651
              if (!_tolerance.less(rem, excess)) {
652 652
                _flow->set(e, (*_flow)[e] + excess);
653 653
                (*_excess)[v] += excess;
654 654
                excess = 0;
655 655
                goto no_more_push_2;
656 656
              } else {
657 657
                excess -= rem;
658 658
                (*_excess)[v] += rem;
659 659
                _flow->set(e, (*_capacity)[e]);
660 660
              }
661 661
            } else if (new_level > (*_level)[v]) {
662 662
              new_level = (*_level)[v];
663 663
            }
664 664
          }
665 665

	
666 666
          for (InArcIt e(_graph, n); e != INVALID; ++e) {
667
            Flow rem = (*_flow)[e];
667
            Value rem = (*_flow)[e];
668 668
            if (!_tolerance.positive(rem)) continue;
669 669
            Node v = _graph.source(e);
670 670
            if ((*_level)[v] < level) {
671 671
              if (!_level->active(v) && v != _target) {
672 672
                _level->activate(v);
673 673
              }
674 674
              if (!_tolerance.less(rem, excess)) {
675 675
                _flow->set(e, (*_flow)[e] - excess);
676 676
                (*_excess)[v] += excess;
677 677
                excess = 0;
678 678
                goto no_more_push_2;
679 679
              } else {
... ...
@@ -769,53 +769,53 @@
769 769
      _level->initFinish();
770 770

	
771 771
      for (NodeIt n(_graph); n != INVALID; ++n) {
772 772
        if (!reached[n]) {
773 773
          _level->dirtyTopButOne(n);
774 774
        } else if ((*_excess)[n] > 0 && _target != n) {
775 775
          _level->activate(n);
776 776
        }
777 777
      }
778 778

	
779 779
      Node n;
780 780
      while ((n = _level->highestActive()) != INVALID) {
781
        Flow excess = (*_excess)[n];
781
        Value excess = (*_excess)[n];
782 782
        int level = _level->highestActiveLevel();
783 783
        int new_level = _level->maxLevel();
784 784

	
785 785
        for (OutArcIt e(_graph, n); e != INVALID; ++e) {
786
          Flow rem = (*_capacity)[e] - (*_flow)[e];
786
          Value rem = (*_capacity)[e] - (*_flow)[e];
787 787
          if (!_tolerance.positive(rem)) continue;
788 788
          Node v = _graph.target(e);
789 789
          if ((*_level)[v] < level) {
790 790
            if (!_level->active(v) && v != _source) {
791 791
              _level->activate(v);
792 792
            }
793 793
            if (!_tolerance.less(rem, excess)) {
794 794
              _flow->set(e, (*_flow)[e] + excess);
795 795
              (*_excess)[v] += excess;
796 796
              excess = 0;
797 797
              goto no_more_push;
798 798
            } else {
799 799
              excess -= rem;
800 800
              (*_excess)[v] += rem;
801 801
              _flow->set(e, (*_capacity)[e]);
802 802
            }
803 803
          } else if (new_level > (*_level)[v]) {
804 804
            new_level = (*_level)[v];
805 805
          }
806 806
        }
807 807

	
808 808
        for (InArcIt e(_graph, n); e != INVALID; ++e) {
809
          Flow rem = (*_flow)[e];
809
          Value rem = (*_flow)[e];
810 810
          if (!_tolerance.positive(rem)) continue;
811 811
          Node v = _graph.source(e);
812 812
          if ((*_level)[v] < level) {
813 813
            if (!_level->active(v) && v != _source) {
814 814
              _level->activate(v);
815 815
            }
816 816
            if (!_tolerance.less(rem, excess)) {
817 817
              _flow->set(e, (*_flow)[e] - excess);
818 818
              (*_excess)[v] += excess;
819 819
              excess = 0;
820 820
              goto no_more_push;
821 821
            } else {
... ...
@@ -888,36 +888,36 @@
888 888
    /// before using them.
889 889

	
890 890
    ///@{
891 891

	
892 892
    /// \brief Returns the value of the maximum flow.
893 893
    ///
894 894
    /// Returns the value of the maximum flow by returning the excess
895 895
    /// of the target node. This value equals to the value of
896 896
    /// the maximum flow already after the first phase of the algorithm.
897 897
    ///
898 898
    /// \pre Either \ref run() or \ref init() must be called before
899 899
    /// using this function.
900
    Flow flowValue() const {
900
    Value flowValue() const {
901 901
      return (*_excess)[_target];
902 902
    }
903 903

	
904
    /// \brief Returns the flow on the given arc.
904
    /// \brief Returns the flow value on the given arc.
905 905
    ///
906
    /// Returns the flow on the given arc. This method can
906
    /// Returns the flow value on the given arc. This method can
907 907
    /// be called after the second phase of the algorithm.
908 908
    ///
909 909
    /// \pre Either \ref run() or \ref init() must be called before
910 910
    /// using this function.
911
    Flow flow(const Arc& arc) const {
911
    Value flow(const Arc& arc) const {
912 912
      return (*_flow)[arc];
913 913
    }
914 914

	
915 915
    /// \brief Returns a const reference to the flow map.
916 916
    ///
917 917
    /// Returns a const reference to the arc map storing the found flow.
918 918
    /// This method can be called after the second phase of the algorithm.
919 919
    ///
920 920
    /// \pre Either \ref run() or \ref init() must be called before
921 921
    /// using this function.
922 922
    const FlowMap& flowMap() const {
923 923
      return *_flow;
0 comments (0 inline)