gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Slightly modify the interface of Circulation and Preflow (#266) in order to synchronize them to the interface of NetworkSimplex. Circulation: - The "delta" notation is replaced by "supply". - lowerCapMap(), upperCapMap() are renamed to lowerMap() and upperMap(). - Value is renamed to Flow. Preflow: - Value is renamed to Flow.
0 3 0
default
3 files changed with 150 insertions and 133 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
... ...
@@ -28,58 +28,58 @@
28 28
///
29 29
namespace lemon {
30 30

	
31 31
  /// \brief Default traits class of Circulation class.
32 32
  ///
33 33
  /// Default traits class of Circulation class.
34
  /// \tparam GR Digraph type.
35
  /// \tparam LM Lower bound capacity map type.
36
  /// \tparam UM Upper bound capacity map type.
37
  /// \tparam DM Delta map type.
34
  ///
35
  /// \tparam GR Type of the digraph the algorithm runs on.
36
  /// \tparam LM The type of the lower bound map.
37
  /// \tparam UM The type of the upper bound (capacity) map.
38
  /// \tparam SM The type of the supply map.
38 39
  template <typename GR, typename LM,
39
            typename UM, typename DM>
40
            typename UM, typename SM>
40 41
  struct CirculationDefaultTraits {
41 42

	
42 43
    /// \brief The type of the digraph the algorithm runs on.
43 44
    typedef GR Digraph;
44 45

	
45
    /// \brief The type of the map that stores the circulation lower
46
    /// bound.
46
    /// \brief The type of the lower bound map.
47 47
    ///
48
    /// The type of the map that stores the circulation lower bound.
49
    /// It must meet the \ref concepts::ReadMap "ReadMap" concept.
50
    typedef LM LCapMap;
48
    /// The type of the map that stores the lower bounds on the arcs.
49
    /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
50
    typedef LM LowerMap;
51 51

	
52
    /// \brief The type of the map that stores the circulation upper
53
    /// bound.
52
    /// \brief The type of the upper bound (capacity) map.
54 53
    ///
55
    /// The type of the map that stores the circulation upper bound.
56
    /// It must meet the \ref concepts::ReadMap "ReadMap" concept.
57
    typedef UM UCapMap;
54
    /// The type of the map that stores the upper bounds (capacities)
55
    /// on the arcs.
56
    /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
57
    typedef UM UpperMap;
58 58

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

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

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

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

	
85 85
    /// \brief The elevator type used by the algorithm.
... ...
@@ -90,95 +90,110 @@
90 90
    /// \sa LinkedElevator
91 91
    typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator;
92 92

	
93 93
    /// \brief Instantiates an Elevator.
94 94
    ///
95 95
    /// This function instantiates an \ref Elevator.
96
    /// \param digraph The digraph, to which we would like to define
96
    /// \param digraph The digraph for which we would like to define
97 97
    /// the elevator.
98 98
    /// \param max_level The maximum level of the elevator.
99 99
    static Elevator* createElevator(const Digraph& digraph, int max_level) {
100 100
      return new Elevator(digraph, max_level);
101 101
    }
102 102

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

	
108 108
  };
109 109

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

	
113 113
     \ingroup max_flow
114
     This class implements a push-relabel algorithm for the network
115
     circulation problem.
114
     This class implements a push-relabel algorithm for the \e network
115
     \e circulation problem.
116 116
     It is to find a feasible circulation when lower and upper bounds
117
     are given for the flow values on the arcs and lower bounds
118
     are given for the supply values of the nodes.
117
     are given for the flow values on the arcs and lower bounds are
118
     given for the difference between the outgoing and incoming flow
119
     at the nodes.
119 120

	
120 121
     The exact formulation of this problem is the following.
121 122
     Let \f$G=(V,A)\f$ be a digraph,
122
     \f$lower, upper: A\rightarrow\mathbf{R}^+_0\f$,
123
     \f$delta: V\rightarrow\mathbf{R}\f$. Find a feasible circulation
124
     \f$f: A\rightarrow\mathbf{R}^+_0\f$ so that
125
     \f[ \sum_{a\in\delta_{out}(v)} f(a) - \sum_{a\in\delta_{in}(v)} f(a)
126
     \geq delta(v) \quad \forall v\in V, \f]
127
     \f[ lower(a)\leq f(a) \leq upper(a) \quad \forall a\in A. \f]
128
     \note \f$delta(v)\f$ specifies a lower bound for the supply of node
129
     \f$v\f$. It can be either positive or negative, however note that
130
     \f$\sum_{v\in V}delta(v)\f$ should be zero or negative in order to
131
     have a feasible solution.
123
     \f$lower, upper: A\rightarrow\mathbf{R}^+_0\f$ denote the lower and
124
     upper bounds on the arcs, for which \f$0 \leq lower(uv) \leq upper(uv)\f$
125
     holds for all \f$uv\in A\f$, and \f$sup: V\rightarrow\mathbf{R}\f$
126
     denotes the signed supply values of the nodes.
127
     If \f$sup(u)>0\f$, then \f$u\f$ is a supply node with \f$sup(u)\f$
128
     supply, if \f$sup(u)<0\f$, then \f$u\f$ is a demand node with
129
     \f$-sup(u)\f$ demand.
130
     A feasible circulation is an \f$f: A\rightarrow\mathbf{R}^+_0\f$
131
     solution of the following problem.
132 132

	
133
     \note A special case of this problem is when
134
     \f$\sum_{v\in V}delta(v) = 0\f$. Then the supply of each node \f$v\f$
135
     will be \e equal \e to \f$delta(v)\f$, if a circulation can be found.
136
     Thus a feasible solution for the
137
     \ref min_cost_flow "minimum cost flow" problem can be calculated
138
     in this way.
133
     \f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu)
134
     \geq sup(u) \quad \forall u\in V, \f]
135
     \f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A. \f]
136
     
137
     The sum of the supply values, i.e. \f$\sum_{u\in V} sup(u)\f$ must be
138
     zero or negative in order to have a feasible solution (since the sum
139
     of the expressions on the left-hand side of the inequalities is zero).
140
     It means that the total demand must be greater or equal to the total
141
     supply and all the supplies have to be carried out from the supply nodes,
142
     but there could be demands that are not satisfied.
143
     If \f$\sum_{u\in V} sup(u)\f$ is zero, then all the supply/demand
144
     constraints have to be satisfied with equality, i.e. all demands
145
     have to be satisfied and all supplies have to be used.
146
     
147
     If you need the opposite inequalities in the supply/demand constraints
148
     (i.e. the total demand is less than the total supply and all the demands
149
     have to be satisfied while there could be supplies that are not used),
150
     then you could easily transform the problem to the above form by reversing
151
     the direction of the arcs and taking the negative of the supply values
152
     (e.g. using \ref ReverseDigraph and \ref NegMap adaptors).
153

	
154
     Note that this algorithm also provides a feasible solution for the
155
     \ref min_cost_flow "minimum cost flow problem".
139 156

	
140 157
     \tparam GR The type of the digraph the algorithm runs on.
141
     \tparam LM The type of the lower bound capacity map. The default
158
     \tparam LM The type of the lower bound map. The default
142 159
     map type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
143
     \tparam UM The type of the upper bound capacity map. The default
144
     map type is \c LM.
145
     \tparam DM The type of the map that stores the lower bound
146
     for the supply of the nodes. The default map type is
160
     \tparam UM The type of the upper bound (capacity) map.
161
     The default map type is \c LM.
162
     \tparam SM The type of the supply map. The default map type is
147 163
     \ref concepts::Digraph::NodeMap "GR::NodeMap<UM::Value>".
148 164
  */
149 165
#ifdef DOXYGEN
150 166
template< typename GR,
151 167
          typename LM,
152 168
          typename UM,
153
          typename DM,
169
          typename SM,
154 170
          typename TR >
155 171
#else
156 172
template< typename GR,
157 173
          typename LM = typename GR::template ArcMap<int>,
158 174
          typename UM = LM,
159
          typename DM = typename GR::template NodeMap<typename UM::Value>,
160
          typename TR = CirculationDefaultTraits<GR, LM, UM, DM> >
175
          typename SM = typename GR::template NodeMap<typename UM::Value>,
176
          typename TR = CirculationDefaultTraits<GR, LM, UM, SM> >
161 177
#endif
162 178
  class Circulation {
163 179
  public:
164 180

	
165 181
    ///The \ref CirculationDefaultTraits "traits class" of the algorithm.
166 182
    typedef TR Traits;
167 183
    ///The type of the digraph the algorithm runs on.
168 184
    typedef typename Traits::Digraph Digraph;
169 185
    ///The type of the flow values.
170
    typedef typename Traits::Value Value;
186
    typedef typename Traits::Flow Flow;
171 187

	
172
    /// The type of the lower bound capacity map.
173
    typedef typename Traits::LCapMap LCapMap;
174
    /// The type of the upper bound capacity map.
175
    typedef typename Traits::UCapMap UCapMap;
176
    /// \brief The type of the map that stores the lower bound for
177
    /// the supply of the nodes.
178
    typedef typename Traits::DeltaMap DeltaMap;
188
    ///The type of the lower bound map.
189
    typedef typename Traits::LowerMap LowerMap;
190
    ///The type of the upper bound (capacity) map.
191
    typedef typename Traits::UpperMap UpperMap;
192
    ///The type of the supply map.
193
    typedef typename Traits::SupplyMap SupplyMap;
179 194
    ///The type of the flow map.
180 195
    typedef typename Traits::FlowMap FlowMap;
181 196

	
182 197
    ///The type of the elevator.
183 198
    typedef typename Traits::Elevator Elevator;
184 199
    ///The type of the tolerance.
... ...
@@ -188,23 +203,23 @@
188 203

	
189 204
    TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
190 205

	
191 206
    const Digraph &_g;
192 207
    int _node_num;
193 208

	
194
    const LCapMap *_lo;
195
    const UCapMap *_up;
196
    const DeltaMap *_delta;
209
    const LowerMap *_lo;
210
    const UpperMap *_up;
211
    const SupplyMap *_supply;
197 212

	
198 213
    FlowMap *_flow;
199 214
    bool _local_flow;
200 215

	
201 216
    Elevator* _level;
202 217
    bool _local_level;
203 218

	
204
    typedef typename Digraph::template NodeMap<Value> ExcessMap;
219
    typedef typename Digraph::template NodeMap<Flow> ExcessMap;
205 220
    ExcessMap* _excess;
206 221

	
207 222
    Tolerance _tol;
208 223
    int _el;
209 224

	
210 225
  public:
... ...
@@ -228,15 +243,15 @@
228 243
    /// FlowMap type
229 244
    ///
230 245
    /// \ref named-templ-param "Named parameter" for setting FlowMap
231 246
    /// type.
232 247
    template <typename _FlowMap>
233 248
    struct SetFlowMap
234
      : public Circulation<Digraph, LCapMap, UCapMap, DeltaMap,
249
      : public Circulation<Digraph, LowerMap, UpperMap, SupplyMap,
235 250
                           SetFlowMapTraits<_FlowMap> > {
236
      typedef Circulation<Digraph, LCapMap, UCapMap, DeltaMap,
251
      typedef Circulation<Digraph, LowerMap, UpperMap, SupplyMap,
237 252
                          SetFlowMapTraits<_FlowMap> > Create;
238 253
    };
239 254

	
240 255
    template <typename _Elevator>
241 256
    struct SetElevatorTraits : public Traits {
242 257
      typedef _Elevator Elevator;
... ...
@@ -254,15 +269,15 @@
254 269
    /// elevator object must be passed to the algorithm using the
255 270
    /// \ref elevator(Elevator&) "elevator()" function before calling
256 271
    /// \ref run() or \ref init().
257 272
    /// \sa SetStandardElevator
258 273
    template <typename _Elevator>
259 274
    struct SetElevator
260
      : public Circulation<Digraph, LCapMap, UCapMap, DeltaMap,
275
      : public Circulation<Digraph, LowerMap, UpperMap, SupplyMap,
261 276
                           SetElevatorTraits<_Elevator> > {
262
      typedef Circulation<Digraph, LCapMap, UCapMap, DeltaMap,
277
      typedef Circulation<Digraph, LowerMap, UpperMap, SupplyMap,
263 278
                          SetElevatorTraits<_Elevator> > Create;
264 279
    };
265 280

	
266 281
    template <typename _Elevator>
267 282
    struct SetStandardElevatorTraits : public Traits {
268 283
      typedef _Elevator Elevator;
... ...
@@ -282,38 +297,40 @@
282 297
    /// However an external elevator object could also be passed to the
283 298
    /// algorithm with the \ref elevator(Elevator&) "elevator()" function
284 299
    /// before calling \ref run() or \ref init().
285 300
    /// \sa SetElevator
286 301
    template <typename _Elevator>
287 302
    struct SetStandardElevator
288
      : public Circulation<Digraph, LCapMap, UCapMap, DeltaMap,
303
      : public Circulation<Digraph, LowerMap, UpperMap, SupplyMap,
289 304
                       SetStandardElevatorTraits<_Elevator> > {
290
      typedef Circulation<Digraph, LCapMap, UCapMap, DeltaMap,
305
      typedef Circulation<Digraph, LowerMap, UpperMap, SupplyMap,
291 306
                      SetStandardElevatorTraits<_Elevator> > Create;
292 307
    };
293 308

	
294 309
    /// @}
295 310

	
296 311
  protected:
297 312

	
298 313
    Circulation() {}
299 314

	
300 315
  public:
301 316

	
302
    /// The constructor of the class.
317
    /// Constructor.
303 318

	
304 319
    /// The constructor of the class.
305
    /// \param g The digraph the algorithm runs on.
306
    /// \param lo The lower bound capacity of the arcs.
307
    /// \param up The upper bound capacity of the arcs.
308
    /// \param delta The lower bound for the supply of the nodes.
309
    Circulation(const Digraph &g,const LCapMap &lo,
310
                const UCapMap &up,const DeltaMap &delta)
311
      : _g(g), _node_num(),
312
        _lo(&lo),_up(&up),_delta(&delta),_flow(0),_local_flow(false),
313
        _level(0), _local_level(false), _excess(0), _el() {}
320
    ///
321
    /// \param graph The digraph the algorithm runs on.
322
    /// \param lower The lower bounds for the flow values on the arcs.
323
    /// \param upper The upper bounds (capacities) for the flow values 
324
    /// on the arcs.
325
    /// \param supply The signed supply values of the nodes.
326
    Circulation(const Digraph &graph, const LowerMap &lower,
327
                const UpperMap &upper, const SupplyMap &supply)
328
      : _g(graph), _lo(&lower), _up(&upper), _supply(&supply),
329
        _flow(NULL), _local_flow(false), _level(NULL), _local_level(false),
330
        _excess(NULL) {}
314 331

	
315 332
    /// Destructor.
316 333
    ~Circulation() {
317 334
      destroyStructures();
318 335
    }
319 336

	
... ...
@@ -347,36 +364,36 @@
347 364
        delete _excess;
348 365
      }
349 366
    }
350 367

	
351 368
  public:
352 369

	
353
    /// Sets the lower bound capacity map.
370
    /// Sets the lower bound map.
354 371

	
355
    /// Sets the lower bound capacity map.
372
    /// Sets the lower bound map.
356 373
    /// \return <tt>(*this)</tt>
357
    Circulation& lowerCapMap(const LCapMap& map) {
374
    Circulation& lowerMap(const LowerMap& map) {
358 375
      _lo = &map;
359 376
      return *this;
360 377
    }
361 378

	
362
    /// Sets the upper bound capacity map.
379
    /// Sets the upper bound (capacity) map.
363 380

	
364
    /// Sets the upper bound capacity map.
381
    /// Sets the upper bound (capacity) map.
365 382
    /// \return <tt>(*this)</tt>
366
    Circulation& upperCapMap(const LCapMap& map) {
383
    Circulation& upperMap(const LowerMap& map) {
367 384
      _up = &map;
368 385
      return *this;
369 386
    }
370 387

	
371
    /// Sets the lower bound map for the supply of the nodes.
388
    /// Sets the supply map.
372 389

	
373
    /// Sets the lower bound map for the supply of the nodes.
390
    /// Sets the supply map.
374 391
    /// \return <tt>(*this)</tt>
375
    Circulation& deltaMap(const DeltaMap& map) {
376
      _delta = &map;
392
    Circulation& supplyMap(const SupplyMap& map) {
393
      _supply = &map;
377 394
      return *this;
378 395
    }
379 396

	
380 397
    /// \brief Sets the flow map.
381 398
    ///
382 399
    /// Sets the flow map.
... ...
@@ -450,13 +467,13 @@
450 467
    /// to the lower bound.
451 468
    void init()
452 469
    {
453 470
      createStructures();
454 471

	
455 472
      for(NodeIt n(_g);n!=INVALID;++n) {
456
        _excess->set(n, (*_delta)[n]);
473
        _excess->set(n, (*_supply)[n]);
457 474
      }
458 475

	
459 476
      for (ArcIt e(_g);e!=INVALID;++e) {
460 477
        _flow->set(e, (*_lo)[e]);
461 478
        _excess->set(_g.target(e), (*_excess)[_g.target(e)] + (*_flow)[e]);
462 479
        _excess->set(_g.source(e), (*_excess)[_g.source(e)] - (*_flow)[e]);
... ...
@@ -479,26 +496,26 @@
479 496
    /// to construct the initial solution.
480 497
    void greedyInit()
481 498
    {
482 499
      createStructures();
483 500

	
484 501
      for(NodeIt n(_g);n!=INVALID;++n) {
485
        _excess->set(n, (*_delta)[n]);
502
        _excess->set(n, (*_supply)[n]);
486 503
      }
487 504

	
488 505
      for (ArcIt e(_g);e!=INVALID;++e) {
489 506
        if (!_tol.positive((*_excess)[_g.target(e)] + (*_up)[e])) {
490 507
          _flow->set(e, (*_up)[e]);
491 508
          _excess->set(_g.target(e), (*_excess)[_g.target(e)] + (*_up)[e]);
492 509
          _excess->set(_g.source(e), (*_excess)[_g.source(e)] - (*_up)[e]);
493 510
        } else if (_tol.positive((*_excess)[_g.target(e)] + (*_lo)[e])) {
494 511
          _flow->set(e, (*_lo)[e]);
495 512
          _excess->set(_g.target(e), (*_excess)[_g.target(e)] + (*_lo)[e]);
496 513
          _excess->set(_g.source(e), (*_excess)[_g.source(e)] - (*_lo)[e]);
497 514
        } else {
498
          Value fc = -(*_excess)[_g.target(e)];
515
          Flow fc = -(*_excess)[_g.target(e)];
499 516
          _flow->set(e, fc);
500 517
          _excess->set(_g.target(e), 0);
501 518
          _excess->set(_g.source(e), (*_excess)[_g.source(e)] - fc);
502 519
        }
503 520
      }
504 521

	
... ...
@@ -525,17 +542,17 @@
525 542
      Node act;
526 543
      Node bact=INVALID;
527 544
      Node last_activated=INVALID;
528 545
      while((act=_level->highestActive())!=INVALID) {
529 546
        int actlevel=(*_level)[act];
530 547
        int mlevel=_node_num;
531
        Value exc=(*_excess)[act];
548
        Flow exc=(*_excess)[act];
532 549

	
533 550
        for(OutArcIt e(_g,act);e!=INVALID; ++e) {
534 551
          Node v = _g.target(e);
535
          Value fc=(*_up)[e]-(*_flow)[e];
552
          Flow fc=(*_up)[e]-(*_flow)[e];
536 553
          if(!_tol.positive(fc)) continue;
537 554
          if((*_level)[v]<actlevel) {
538 555
            if(!_tol.less(fc, exc)) {
539 556
              _flow->set(e, (*_flow)[e] + exc);
540 557
              _excess->set(v, (*_excess)[v] + exc);
541 558
              if(!_level->active(v) && _tol.positive((*_excess)[v]))
... ...
@@ -553,13 +570,13 @@
553 570
            }
554 571
          }
555 572
          else if((*_level)[v]<mlevel) mlevel=(*_level)[v];
556 573
        }
557 574
        for(InArcIt e(_g,act);e!=INVALID; ++e) {
558 575
          Node v = _g.source(e);
559
          Value fc=(*_flow)[e]-(*_lo)[e];
576
          Flow fc=(*_flow)[e]-(*_lo)[e];
560 577
          if(!_tol.positive(fc)) continue;
561 578
          if((*_level)[v]<actlevel) {
562 579
            if(!_tol.less(fc, exc)) {
563 580
              _flow->set(e, (*_flow)[e] - exc);
564 581
              _excess->set(v, (*_excess)[v] + exc);
565 582
              if(!_level->active(v) && _tol.positive((*_excess)[v]))
... ...
@@ -629,13 +646,13 @@
629 646
    /// \brief Returns the flow on the given arc.
630 647
    ///
631 648
    /// Returns the flow on the given arc.
632 649
    ///
633 650
    /// \pre Either \ref run() or \ref init() must be called before
634 651
    /// using this function.
635
    Value flow(const Arc& arc) const {
652
    Flow flow(const Arc& arc) const {
636 653
      return (*_flow)[arc];
637 654
    }
638 655

	
639 656
    /// \brief Returns a const reference to the flow map.
640 657
    ///
641 658
    /// Returns a const reference to the arc map storing the found flow.
... ...
@@ -648,14 +665,14 @@
648 665

	
649 666
    /**
650 667
       \brief Returns \c true if the given node is in a barrier.
651 668

	
652 669
       Barrier is a set \e B of nodes for which
653 670

	
654
       \f[ \sum_{a\in\delta_{out}(B)} upper(a) -
655
           \sum_{a\in\delta_{in}(B)} lower(a) < \sum_{v\in B}delta(v) \f]
671
       \f[ \sum_{uv\in A: u\in B} upper(uv) -
672
           \sum_{uv\in A: v\in B} lower(uv) < \sum_{v\in B} sup(v) \f]
656 673

	
657 674
       holds. The existence of a set with this property prooves that a
658 675
       feasible circualtion cannot exist.
659 676

	
660 677
       This function returns \c true if the given node is in the found
661 678
       barrier. If a feasible circulation is found, the function
... ...
@@ -712,13 +729,13 @@
712 729
    ///
713 730
    bool checkFlow() const {
714 731
      for(ArcIt e(_g);e!=INVALID;++e)
715 732
        if((*_flow)[e]<(*_lo)[e]||(*_flow)[e]>(*_up)[e]) return false;
716 733
      for(NodeIt n(_g);n!=INVALID;++n)
717 734
        {
718
          Value dif=-(*_delta)[n];
735
          Flow dif=-(*_supply)[n];
719 736
          for(InArcIt e(_g,n);e!=INVALID;++e) dif-=(*_flow)[e];
720 737
          for(OutArcIt e(_g,n);e!=INVALID;++e) dif+=(*_flow)[e];
721 738
          if(_tol.negative(dif)) return false;
722 739
        }
723 740
      return true;
724 741
    }
... ...
@@ -727,16 +744,16 @@
727 744

	
728 745
    ///Check whether or not the last execution provides a barrier.
729 746
    ///\sa barrier()
730 747
    ///\sa barrierMap()
731 748
    bool checkBarrier() const
732 749
    {
733
      Value delta=0;
750
      Flow delta=0;
734 751
      for(NodeIt n(_g);n!=INVALID;++n)
735 752
        if(barrier(n))
736
          delta-=(*_delta)[n];
753
          delta-=(*_supply)[n];
737 754
      for(ArcIt e(_g);e!=INVALID;++e)
738 755
        {
739 756
          Node s=_g.source(e);
740 757
          Node t=_g.target(e);
741 758
          if(barrier(s)&&!barrier(t)) delta+=(*_up)[e];
742 759
          else if(barrier(t)&&!barrier(s)) delta-=(*_lo)[e];
Ignore white space 6 line context
... ...
@@ -43,24 +43,24 @@
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 CM CapacityMap;
47 47

	
48 48
    /// \brief The type of the flow values.
49
    typedef typename CapacityMap::Value Value;
49
    typedef typename CapacityMap::Value Flow;
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<Value> FlowMap;
55
    typedef typename Digraph::template ArcMap<Flow> FlowMap;
56 56

	
57 57
    /// \brief Instantiates a FlowMap.
58 58
    ///
59 59
    /// This function instantiates a \ref FlowMap.
60
    /// \param digraph The digraph, to which we would like to define
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.
... ...
@@ -71,23 +71,23 @@
71 71
    /// \sa LinkedElevator
72 72
    typedef LinkedElevator<Digraph, typename Digraph::Node> Elevator;
73 73

	
74 74
    /// \brief Instantiates an Elevator.
75 75
    ///
76 76
    /// This function instantiates an \ref Elevator.
77
    /// \param digraph The digraph, to which we would like to define
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<Value> Tolerance;
87
    typedef lemon::Tolerance<Flow> Tolerance;
88 88

	
89 89
  };
90 90

	
91 91

	
92 92
  /// \ingroup max_flow
93 93
  ///
... ...
@@ -121,13 +121,13 @@
121 121
    typedef TR Traits;
122 122
    ///The type of the digraph the algorithm runs on.
123 123
    typedef typename Traits::Digraph Digraph;
124 124
    ///The type of the capacity map.
125 125
    typedef typename Traits::CapacityMap CapacityMap;
126 126
    ///The type of the flow values.
127
    typedef typename Traits::Value Value;
127
    typedef typename Traits::Flow Flow;
128 128

	
129 129
    ///The type of the flow map.
130 130
    typedef typename Traits::FlowMap FlowMap;
131 131
    ///The type of the elevator.
132 132
    typedef typename Traits::Elevator Elevator;
133 133
    ///The type of the tolerance.
... ...
@@ -147,13 +147,13 @@
147 147
    FlowMap* _flow;
148 148
    bool _local_flow;
149 149

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

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

	
156 156
    Tolerance _tolerance;
157 157

	
158 158
    bool _phase;
159 159

	
... ...
@@ -466,13 +466,13 @@
466 466

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

	
471 471
      for (NodeIt n(_graph); n != INVALID; ++n) {
472
        Value excess = 0;
472
        Flow excess = 0;
473 473
        for (InArcIt e(_graph, n); e != INVALID; ++e) {
474 474
          excess += (*_flow)[e];
475 475
        }
476 476
        for (OutArcIt e(_graph, n); e != INVALID; ++e) {
477 477
          excess -= (*_flow)[e];
478 478
        }
... ...
@@ -515,25 +515,25 @@
515 515
        }
516 516
        queue.swap(nqueue);
517 517
      }
518 518
      _level->initFinish();
519 519

	
520 520
      for (OutArcIt e(_graph, _source); e != INVALID; ++e) {
521
        Value rem = (*_capacity)[e] - (*_flow)[e];
521
        Flow rem = (*_capacity)[e] - (*_flow)[e];
522 522
        if (_tolerance.positive(rem)) {
523 523
          Node u = _graph.target(e);
524 524
          if ((*_level)[u] == _level->maxLevel()) continue;
525 525
          _flow->set(e, (*_capacity)[e]);
526 526
          _excess->set(u, (*_excess)[u] + rem);
527 527
          if (u != _target && !_level->active(u)) {
528 528
            _level->activate(u);
529 529
          }
530 530
        }
531 531
      }
532 532
      for (InArcIt e(_graph, _source); e != INVALID; ++e) {
533
        Value rem = (*_flow)[e];
533
        Flow rem = (*_flow)[e];
534 534
        if (_tolerance.positive(rem)) {
535 535
          Node v = _graph.source(e);
536 536
          if ((*_level)[v] == _level->maxLevel()) continue;
537 537
          _flow->set(e, 0);
538 538
          _excess->set(v, (*_excess)[v] + rem);
539 539
          if (v != _target && !_level->active(v)) {
... ...
@@ -560,17 +560,17 @@
560 560
      Node n = _level->highestActive();
561 561
      int level = _level->highestActiveLevel();
562 562
      while (n != INVALID) {
563 563
        int num = _node_num;
564 564

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

	
569 569
          for (OutArcIt e(_graph, n); e != INVALID; ++e) {
570
            Value rem = (*_capacity)[e] - (*_flow)[e];
570
            Flow rem = (*_capacity)[e] - (*_flow)[e];
571 571
            if (!_tolerance.positive(rem)) continue;
572 572
            Node v = _graph.target(e);
573 573
            if ((*_level)[v] < level) {
574 574
              if (!_level->active(v) && v != _target) {
575 575
                _level->activate(v);
576 576
              }
... ...
@@ -587,13 +587,13 @@
587 587
            } else if (new_level > (*_level)[v]) {
588 588
              new_level = (*_level)[v];
589 589
            }
590 590
          }
591 591

	
592 592
          for (InArcIt e(_graph, n); e != INVALID; ++e) {
593
            Value rem = (*_flow)[e];
593
            Flow rem = (*_flow)[e];
594 594
            if (!_tolerance.positive(rem)) continue;
595 595
            Node v = _graph.source(e);
596 596
            if ((*_level)[v] < level) {
597 597
              if (!_level->active(v) && v != _target) {
598 598
                _level->activate(v);
599 599
              }
... ...
@@ -633,17 +633,17 @@
633 633
          level = _level->highestActiveLevel();
634 634
          --num;
635 635
        }
636 636

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

	
642 642
          for (OutArcIt e(_graph, n); e != INVALID; ++e) {
643
            Value rem = (*_capacity)[e] - (*_flow)[e];
643
            Flow rem = (*_capacity)[e] - (*_flow)[e];
644 644
            if (!_tolerance.positive(rem)) continue;
645 645
            Node v = _graph.target(e);
646 646
            if ((*_level)[v] < level) {
647 647
              if (!_level->active(v) && v != _target) {
648 648
                _level->activate(v);
649 649
              }
... ...
@@ -660,13 +660,13 @@
660 660
            } else if (new_level > (*_level)[v]) {
661 661
              new_level = (*_level)[v];
662 662
            }
663 663
          }
664 664

	
665 665
          for (InArcIt e(_graph, n); e != INVALID; ++e) {
666
            Value rem = (*_flow)[e];
666
            Flow rem = (*_flow)[e];
667 667
            if (!_tolerance.positive(rem)) continue;
668 668
            Node v = _graph.source(e);
669 669
            if ((*_level)[v] < level) {
670 670
              if (!_level->active(v) && v != _target) {
671 671
                _level->activate(v);
672 672
              }
... ...
@@ -774,18 +774,18 @@
774 774
          _level->activate(n);
775 775
        }
776 776
      }
777 777

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

	
784 784
        for (OutArcIt e(_graph, n); e != INVALID; ++e) {
785
          Value rem = (*_capacity)[e] - (*_flow)[e];
785
          Flow rem = (*_capacity)[e] - (*_flow)[e];
786 786
          if (!_tolerance.positive(rem)) continue;
787 787
          Node v = _graph.target(e);
788 788
          if ((*_level)[v] < level) {
789 789
            if (!_level->active(v) && v != _source) {
790 790
              _level->activate(v);
791 791
            }
... ...
@@ -802,13 +802,13 @@
802 802
          } else if (new_level > (*_level)[v]) {
803 803
            new_level = (*_level)[v];
804 804
          }
805 805
        }
806 806

	
807 807
        for (InArcIt e(_graph, n); e != INVALID; ++e) {
808
          Value rem = (*_flow)[e];
808
          Flow rem = (*_flow)[e];
809 809
          if (!_tolerance.positive(rem)) continue;
810 810
          Node v = _graph.source(e);
811 811
          if ((*_level)[v] < level) {
812 812
            if (!_level->active(v) && v != _source) {
813 813
              _level->activate(v);
814 814
            }
... ...
@@ -893,24 +893,24 @@
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
    Value flowValue() const {
899
    Flow 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
    Value flow(const Arc& arc) const {
910
    Flow 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.
Ignore white space 12 line context
... ...
@@ -54,36 +54,36 @@
54 54
  typedef int VType;
55 55
  typedef concepts::Digraph Digraph;
56 56

	
57 57
  typedef Digraph::Node Node;
58 58
  typedef Digraph::Arc Arc;
59 59
  typedef concepts::ReadMap<Arc,VType> CapMap;
60
  typedef concepts::ReadMap<Node,VType> DeltaMap;
60
  typedef concepts::ReadMap<Node,VType> SupplyMap;
61 61
  typedef concepts::ReadWriteMap<Arc,VType> FlowMap;
62 62
  typedef concepts::WriteMap<Node,bool> BarrierMap;
63 63

	
64 64
  typedef Elevator<Digraph, Digraph::Node> Elev;
65 65
  typedef LinkedElevator<Digraph, Digraph::Node> LinkedElev;
66 66

	
67 67
  Digraph g;
68 68
  Node n;
69 69
  Arc a;
70 70
  CapMap lcap, ucap;
71
  DeltaMap delta;
71
  SupplyMap supply;
72 72
  FlowMap flow;
73 73
  BarrierMap bar;
74 74

	
75
  Circulation<Digraph, CapMap, CapMap, DeltaMap>
75
  Circulation<Digraph, CapMap, CapMap, SupplyMap>
76 76
    ::SetFlowMap<FlowMap>
77 77
    ::SetElevator<Elev>
78 78
    ::SetStandardElevator<LinkedElev>
79
    ::Create circ_test(g,lcap,ucap,delta);
79
    ::Create circ_test(g,lcap,ucap,supply);
80 80

	
81
  circ_test.lowerCapMap(lcap);
82
  circ_test.upperCapMap(ucap);
83
  circ_test.deltaMap(delta);
81
  circ_test.lowerMap(lcap);
82
  circ_test.upperMap(ucap);
83
  circ_test.supplyMap(supply);
84 84
  flow = circ_test.flowMap();
85 85
  circ_test.flowMap(flow);
86 86

	
87 87
  circ_test.init();
88 88
  circ_test.greedyInit();
89 89
  circ_test.start();
0 comments (0 inline)