Maxflow
Maxflow
1/0 1/1
s 1/1 t
2/2 2/1
he main sources for the lectures are the books [8, 1, 9]. The original
ublications on the preflow-push algorithm are [6, 2]. [5] describes the currently
est flow algorithm for integral capacities. Papers by the instructors are [3, 7, 4].
R.K. Ahuja, T.L. Magnanti, and J.B. Orlin. Network Flows. Prentice Hall, 1993.
R.K. Ahuja and J.B. Orlin. A fast and simple algorithm for the maximum flow problem.
Operation Research, 37:748–759, 1989.
J. Cheriyan, T. Hagerup, and K. Mehlhorn. An o(n3 )-time maximum flow algorithm. SIAM
Journal of Computing, 25(6):1144–1170, 1996.
J. Cheriyan and K. Mehlhorn. An analysis of the highest-level selection rule in the
preflow-push max-flow algorithm. IPL, 69:239–242, 1999.
www.mpi-sb.mpg.de/~mehlhorn/ftp/maxflow.ps.
A.V. Goldberg and S. Rao. Beyond the flow decomposition barrier. JACM, 45(5), 1998.
A.V. Goldberg and R.E. Tarjan. A new approach to the maximum-flow problem. Journal of
the ACM, 35:921–940, 1988.
T. Hagerup, P. Sanders, and J. Träff. An implementation of the binary blocking flow
algorithm. In Proceedings of the 2nd Workshop on Algorithm Engineering (WAE’98), pages
143–154. Max-Planck-Institut für Informatik, 1998.
K. Mehlhorn. Data Structures and Algorithms. Springer, 1984.
K. Mehlhorn and S. Näher. The LEDA Platform for Combinatorial and Geometric
2
Computing. Cambridge University Press, 1999. 1018 pages.
PI Informatik
Some Notation and First Properties Kurt Mehlhorn
P P
• the excess of a node v: excess(v) = f (e) − f (e)
e;target(e)=v e;source(e)=v
learly: the net flow into t is equal to the next flow out of s.
emma 1 excess(t) = −excess(s)
he proof is short and illustrates an important technique
X
excess(s) + excess(t) = excess(v) = 0
v∈V
1/1 1/1
1/0 1/1 s t
s 1/1 t 1/0
4
PI Informatik
Cuts and Flows Kurt Mehlhorn
= cap(S).
Remarks:
• A saturated cut proves the optimality of a flow.
• For every maximal flow there is a 5saturated cut proving its optimality (=⇒)
PI Informatik
The Residual Network Kurt Mehlhorn
1/1 1/1
1/0 1/1 s t
s 1/1 t 1/0
6
PI Informatik
Maximum Flows and the Residual Graph Kurt Mehlhorn
G Gf G
An illustration of part a)
7
Maximum Flows and the Residual Graph: PartKurta Mehlhorn
PI Informatik
a path in Gf : s −→ v1 −→ v2 −→ v3 −→ v4 −→ v5 −→ t
8
Maximum Flows and the Residual Graph: PartKurt
PI Informatik
b Mehlhorn
t cannot be reached from s in Gf , f is maximal.
• Let S be the set of nodes reachable from s and let T = V \ S.
• There is no edge (v, w) in Gf with v ∈ S and w ∈ T .
• Hence
– f (e) = cap(e) for any e with e ∈ E ∩ (S × T ) and
– f (e) = 0 for any e with e ∈ E ∩ (T × S)
• Thus S is saturated and f is maximal.
Gf G
9
PI Informatik
Max-Flow-Min-Cut Theorem Kurt Mehlhorn
roof:
• ≤ is the content of Lemma 2, part (a).
• let f be a maximum flow
– then there is no path from s to t in Gf and
– the set S of nodes reachable from s form a saturated cut
– hence val (f ) = cap(S) by Lemma 2, part (b).
11
PI Informatik
Integrality Theorem Kurt Mehlhorn
heorem 3 If edge capacities are integral, there exists an integral maximal flow.
Moreover, the algorithm of Ford and Fulkerson finds it in time O((n + m)v ∗ ),
here v ∗ is the value of the maximum flow.
12
PI Informatik
Bipartite Matching Kurt Mehlhorn
0 4 0 4
1 5 1 5
2 6 2 6
3 7 3 7
13
PI Informatik
The Theorem of Hall Kurt Mehlhorn
15
emma 5 Max-res-cap-path can be determined in time O(m log m).
• sort the edges of Gf in decreasing order of residual capacity
• let e1 , e2 , . . . , em0 be the sorted list of edges
• want to find the minimal i such that {e1 , . . . , ei } contains a path from s to t
• for fixed i we can test existence of path in time O(n + m)
• determine i by binary search in O(log m) rounds.
16
emma 6 O(m + m logdv ∗ /me) augmentations suffice
• a flow can be decomposed into at most m paths
– start with a maximal flow f
– repeatedly construct a path from s to t, saturate it, and subtract from f
• augmentation along max-res-cap-path increases flow by at least 1/m of dist
to v ∗
• let gi be the diff between v ∗ and the flow value after the i-th iteration
• g0 = v ∗
• if gi > 0, gi+1 ≤ gi − max(1, gi /m) ≤ min(gi − 1, (1 − 1/m)gi )
• gi ≤ ( m−1
m )i
g0 and hence gi ≤ m if i is such that ( m ) g0 ≤ m.
m−1 i
∗ log(v ∗ /m)
• this is the case if i ≥ logm/(m−1) (v /m) = log m/(m−1)
17
Dinic’s Algorithm (1970), General Capacities
• the number of rounds is at most n, since the depth of Lf grows in each round
(without proof, but see analysis of # of saturating pushes in preflow-push alg)
• a blocking flow can be computed in time O(nm)
• T = O(n2 m) 18
PI Informatik
An Example Run of Dinic’s Algorithm Kurt Mehlhorn
will illustrate the sequence of residual graphs and residual level graphs.
1 2
1
0 1
1 1
3 3
4
2
1 1
5
19
PI Informatik
The Computation of Blocking Flows Kurt Mehlhorn
s v t
Question: What to do when v has positive excess but no outgoing eligible edge?
Answer: lift it up, i.e., increase d(v) by one (relabel v)
22
PI Informatik
The Generic Push-Relabel Algorithm Kurt Mehlhorn
s a t
2 1
nd here comes the sequence of residual graphs (residual capacities are shown)
24
PI Informatik
No Steep Edges Kurt Mehlhorn
n edge e = (v, w) ∈ Gf is called steep if d(w) < d(v) − 1, i.e., if it reaches down
y two or more levels.
emma 7 The algorithm maintains a preflow and does not generate steep edges.
he nodes s and t stay on levels 0 and n, respectively.
roof:
• the algorithm maintains a preflow by the restriction on δ
25
PI Informatik
The Maximum Level Stays Below 2n Kurt Mehlhorn
26
PI Informatik
Partial Correctness Kurt Mehlhorn
27
On the Number of Relabels and Saturating Pushes
PI Informatik Kurt Mehlhorn
emma 9 There are at most 2n2 relabels and at most nm saturating pushes.
roof:
• no distance label ever reaches 2n.
• therefore, each node is relabeled at most 2n times
• the number of relabels is therefore at most 2n2 .
28
On the Number of Non-Saturating Pushes: Scaling
PI Informatik Kurt Mehlhorn
• excesses are bounded by ∆, i.e., at all times and for all v 6= t: excess(v) ≤ ∆
• a non-saturating push moves ∆/2 29units of flow
On the Number of Non-Sat Pushes in Ahuja-Orlin
PI Informatik Kurt Mehlhorn
• Φ ≥ 0 always, Φ = 0 initially
• total decrease of Φ ≤ total increase of Φ
• a relabel increases Φ by at most one
• every push decreases Φ
• a non-saturating push decreases Φ by 1/2
• a change of ∆ increases Φ by at most 2n2
• ∆ is changed dlog U e times
• (1/2)#non sat pushes ≤ total decrease
30 ≤ total increase ≤ 2n2 + 2n2 dlog U e
PI Informatik
Maintaining the Set of High Excess Nodes Kurt Mehlhorn
31
PI Informatik
The Search for Eligible Edges Kurt Mehlhorn
• every node v stores the list of all edges (out and in) incident to it
• every node stores its height
• every edge stores its capacity and the current flow across it
• an out-edge e = (v, w) is eligible for pushing out of v iff f (e) < cap(e) and
d(w) < d(v)
• an in-edge e = (w, v) is eligible for pushing out of v iff f (e) > 0 and
d(w) < d(v)
• L 11 An edge can become eligible for pushing out of v only by a relabel of v
– consider a non-eligible out-edge e = (v, w), i.e., either d(w) ≥ d(v) or
f (e) = cap(e).
– the latter condition can only be changed by a push across the reversal of e.
– such a push is only possible if d(w) > d(v). Hence e cannot be eligible
after the push.
32
PI Informatik
The Search for Eligible Edges Kurt Mehlhorn
• every node maintains a pointer into its edge list (= the current edge)
• invariant: no edge to the left of the current edge is eligible
• in order to search for an eligible edge for pushing out of v, v advances its
current edge pointer until
– either an eligible edge is found
– or the end of the list is reached. Then v is relabeled and the current edge
pointer is reset to the beginning of the list
• correctness follows from Lemma on preceding slide
• time is O(deg(v)) between relabels of v and hence
P
• total time required to search for eligible edges = 2n · v deg(v) = O(nm)
33
On the Number of Non-Sat Pushes in the Generic Algorithm
PI Informatik Kurt Mehlhorn
34
PI Informatik
The Arbitrary Rule Kurt Mehlhorn
35
PI Informatik
The FIFO Rule Kurt Mehlhorn
36
2
√
emma 14 When the Highest-Level-rule is used, #non sat pushes = O(n m).
Warning: Proof in Ahuja/Magnanti/Orlin is wrong, proof here Cheriyan/M
√
• let K = m. For a node v, let d0 (v) = |{w; d(w) ≤ d(v)}|/K.
P
• potential function Φ = d0 (v).
v;v is active
38
PI Informatik Kurt Mehlhorn
Proving (1) to (5)
39
PI Informatik Kurt Mehlhorn
Proving (6)
40
Heuristic Improvements, see LEDAbook, pages 465Kurt
PI Informatik
– Mehlhorn
487
41
PI Informatik
Heuristic Improvements, Continued Kurt Mehlhorn
lobal relabeling: after O(m) edge inspections, update the dist-values of all
nodes by setting
µ(v, t) if there is a path from v to t in Gf
d(v) = n + µ(v, s) if there is a path from v to s in Gf but no
path from v to t in Gf
2n − 1 otherwise
Here µ(v, t) and µ(v, s) denote the lengths (= number of edges) of the
shortest paths from v to t, respectively s, in Gf .
global relabeling has cost O(m).
ap heuristic: when a level i, 1 ≤ i < n, becomes empty (because we lift the
last node on this level to a higher level),
lift all nodes in levels i + 1 to n − 1 to level n.
gap heuristic has cost proportional to the number of nodes moved to level n.
42
PI Informatik
Experimental Findings Kurt Mehlhorn
G1, CG2, and AMO are problem generators, see LEDAbook for details.
or each generator we ran the cases n = 5000 · 2i for i = 0, 1, and 2.