0
2
0
... | ... |
@@ -540,29 +540,27 @@ |
540 | 540 |
Value rem = (*_capacity)[e] - (*_flow)[e]; |
541 | 541 |
if (_tolerance.positive(rem)) { |
542 | 542 |
Node u = _graph.target(e); |
543 | 543 |
if ((*_level)[u] == _level->maxLevel()) continue; |
544 | 544 |
_flow->set(e, (*_capacity)[e]); |
545 | 545 |
(*_excess)[u] += rem; |
546 |
if (u != _target && !_level->active(u)) { |
|
547 |
_level->activate(u); |
|
548 |
} |
|
549 | 546 |
} |
550 | 547 |
} |
551 | 548 |
for (InArcIt e(_graph, _source); e != INVALID; ++e) { |
552 | 549 |
Value rem = (*_flow)[e]; |
553 | 550 |
if (_tolerance.positive(rem)) { |
554 | 551 |
Node v = _graph.source(e); |
555 | 552 |
if ((*_level)[v] == _level->maxLevel()) continue; |
556 | 553 |
_flow->set(e, 0); |
557 | 554 |
(*_excess)[v] += rem; |
558 |
if (v != _target && !_level->active(v)) { |
|
559 |
_level->activate(v); |
|
560 |
} |
|
561 | 555 |
} |
562 | 556 |
} |
557 |
for (NodeIt n(_graph); n != INVALID; ++n) |
|
558 |
if(n!=_source && n!=_target && _tolerance.positive((*_excess)[n])) |
|
559 |
_level->activate(n); |
|
560 |
|
|
563 | 561 |
return true; |
564 | 562 |
} |
565 | 563 |
|
566 | 564 |
/// \brief Starts the first phase of the preflow algorithm. |
567 | 565 |
/// |
568 | 566 |
/// The preflow algorithm consists of two phases, this method runs |
... | ... |
@@ -153,12 +153,36 @@ |
153 | 153 |
} |
154 | 154 |
if (sum != 0) return false; |
155 | 155 |
} |
156 | 156 |
return true; |
157 | 157 |
} |
158 | 158 |
|
159 |
void initFlowTest() |
|
160 |
{ |
|
161 |
DIGRAPH_TYPEDEFS(SmartDigraph); |
|
162 |
|
|
163 |
SmartDigraph g; |
|
164 |
SmartDigraph::ArcMap<int> cap(g),iflow(g); |
|
165 |
Node s=g.addNode(); Node t=g.addNode(); |
|
166 |
Node n1=g.addNode(); Node n2=g.addNode(); |
|
167 |
Arc a; |
|
168 |
a=g.addArc(s,n1); cap[a]=20; iflow[a]=20; |
|
169 |
a=g.addArc(n1,n2); cap[a]=10; iflow[a]=0; |
|
170 |
a=g.addArc(n2,t); cap[a]=20; iflow[a]=0; |
|
171 |
|
|
172 |
Preflow<SmartDigraph> pre(g,cap,s,t); |
|
173 |
pre.init(iflow); |
|
174 |
pre.startFirstPhase(); |
|
175 |
check(pre.flowValue() == 10, "The incorrect max flow value."); |
|
176 |
check(pre.minCut(s), "Wrong min cut (Node s)."); |
|
177 |
check(pre.minCut(n1), "Wrong min cut (Node n1)."); |
|
178 |
check(!pre.minCut(n2), "Wrong min cut (Node n2)."); |
|
179 |
check(!pre.minCut(t), "Wrong min cut (Node t)."); |
|
180 |
} |
|
181 |
|
|
182 |
|
|
159 | 183 |
int main() { |
160 | 184 |
|
161 | 185 |
typedef SmartDigraph Digraph; |
162 | 186 |
|
163 | 187 |
typedef Digraph::Node Node; |
164 | 188 |
typedef Digraph::NodeIt NodeIt; |
... | ... |
@@ -243,8 +267,10 @@ |
243 | 267 |
min_cut_value=cutValue(g,min_cut3,cap); |
244 | 268 |
|
245 | 269 |
|
246 | 270 |
check(preflow_test.flowValue() == min_cut_value, |
247 | 271 |
"The max flow value or the three min cut values are incorrect."); |
248 | 272 |
|
273 |
initFlowTest(); |
|
274 |
|
|
249 | 275 |
return 0; |
250 | 276 |
} |
0 comments (0 inline)