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 ↑
Show white space 6 line context
... ...
@@ -64,15 +64,15 @@
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
    ///
... ...
@@ -104,7 +104,7 @@
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

	
... ...
@@ -187,8 +187,8 @@
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;
... ...
@@ -221,7 +221,7 @@
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;
... ...
@@ -530,7 +530,7 @@
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;
... ...
@@ -563,11 +563,11 @@
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)) {
... ...
@@ -591,7 +591,7 @@
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)) {
... ...
@@ -661,13 +661,13 @@
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

	
... ...
@@ -750,7 +750,7 @@
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;
... ...
@@ -765,10 +765,10 @@
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];
Show white space 6 line context
... ...
@@ -56,10 +56,10 @@
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.
... ...
@@ -67,23 +67,23 @@
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
... ...
@@ -206,15 +206,15 @@
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
... ...
@@ -232,16 +232,16 @@
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;
... ...
@@ -278,16 +278,16 @@
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

	
... ...
@@ -695,12 +695,12 @@
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");
... ...
@@ -725,14 +725,14 @@
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
      }
... ...
@@ -747,14 +747,14 @@
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
      }
... ...
@@ -790,7 +790,7 @@
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>
... ...
@@ -798,7 +798,7 @@
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
      }
... ...
@@ -823,7 +823,7 @@
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;
... ...
@@ -1025,7 +1025,7 @@
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

	
... ...
@@ -1204,7 +1204,7 @@
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;
... ...
@@ -1275,7 +1275,7 @@
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
... ...
@@ -1315,7 +1315,7 @@
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;
Show white space 6 line context
... ...
@@ -46,13 +46,13 @@
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
    ///
... ...
@@ -84,7 +84,7 @@
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

	
... ...
@@ -125,7 +125,7 @@
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;
... ...
@@ -151,7 +151,7 @@
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;
... ...
@@ -470,7 +470,7 @@
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
        }
... ...
@@ -519,7 +519,7 @@
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;
... ...
@@ -531,7 +531,7 @@
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;
... ...
@@ -564,11 +564,11 @@
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) {
... ...
@@ -591,7 +591,7 @@
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) {
... ...
@@ -637,11 +637,11 @@
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) {
... ...
@@ -664,7 +664,7 @@
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) {
... ...
@@ -778,12 +778,12 @@
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) {
... ...
@@ -806,7 +806,7 @@
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) {
... ...
@@ -897,18 +897,18 @@
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

	
0 comments (0 inline)