64 Max Flow
64 Max Flow
64 Max Flow
capacity
4 15 15 10
10
s 5 8 10 t
15
4 6 15 10
16
3
Mincut problem
Def. A st-cut (cut) is a partition of the vertices into two disjoint sets,
with s in one set A and t in the other set B.
Def. Its capacity is the sum of the capacities of the edges from A to B.
10
s 5 t
15
capacity = 10 + 5 + 15 = 30
4
Mincut problem
Def. A st-cut (cut) is a partition of the vertices into two disjoint sets,
with s in one set A and t in the other set B.
Def. Its capacity is the sum of the capacities of the edges from A to B.
10
s 8 t
16
capacity = 10 + 8 + 16 = 34
5
Mincut problem
Def. A st-cut (cut) is a partition of the vertices into two disjoint sets,
with s in one set A and t in the other set B.
Def. Its capacity is the sum of the capacities of the edges from A to B.
10
s 8 t
10
capacity = 10 + 8 + 10 = 28
6
Mincut application (RAND 1950s)
"Free world" goal. Cut supplies (if cold war turns into real war).
8
Maxflow problem
capacity
15 15 10
4
10
s 5 8 10 t
15
6 15 10
4
16
9
Maxflow problem
flow capacity
inflow at v = 5 + 5 + 0 = 10
5/9 outflow at v = 10 + 0 = 10
5 5
10 0/4 /1 0 / 15 /
10
/ 5
10
s 5/5 5/8 v 10 / 10 t
10
/ 0 0 / 15 10
15 0/4 /6 /
10
10 / 16
10
Maxflow problem
5/9
5 5
10 0/4 /1 0 / 15 /
10
/ 5
10
10
/ 0 0 / 15 10
15 0/4 /6 /
10
10 / 16
11
Maxflow problem
8/9
2 8
10 0/4 /1 0 / 15 /
10
/ 5
10
13
/ 3 0 / 15 10
15 0/4 /6 /
10
13 / 16
12
Maxflow application (Tolstoǐ 1930s)
flow
capacity
facebook graph
14
Summary
8/9
2 8
/1 /
10 0/4 5 0 / 15 10 10
/
10
s 5/5 8/8 10 / 10 t s 8 t
13
/ 3 10
15 0/4 /6 0 / 15
/ 10
10
13 / 16
flow capacity
initialization
0/9
0
0 /
10 0/4 /1 0 / 15 10
/ 5
0 value of flow
s 0/5 0/8 0 / 10 t 0
0
/ 0 10
15 0/4 /6 0 / 15 /
0
0 / 16
17
Idea: increase flow along augmenting paths
10
— 0
0 /
10 / 10 0/4 /1 0 / 15 10
0
— 5
10
s 0/5 0/8 —
0 / 10 t 0 + 10 = 10
0
/ 0 10
15 0/4 /6 0 / 15 /
0
0 / 16
18
Idea: increase flow along augmenting paths
0/9
10 0
10 0/4 0 / 15 /
/ /1 10
5
10
s 0/5 0/8 10 / 10 t 10 + 10 = 20
10
—
0
/ 0 10 10
15 0/4 /6 0 / 15 /
0
—
10
—0 / 16
19
Idea: increase flow along augmenting paths
5 5
1—0 —
0
10 0/4 0 / 15 /
/ /1 10
5
10
5 5
s —
0/5 —
0/8 10 / 10 t 20 + 5 = 25
10 10
/ 0/4 0 0 / 15 /
15 /6 10
10 / 16
20
Idea: increase flow along augmenting paths
2 8
—
5
—
5 /
10 0/4 /1 0 / 15 10
/ 5
10
8
s 5/5 —
5/8 10 / 10 t 25 + 3 = 28
13
3
1—0 10
/ 0/4 —
0 0 / 15 /
15 /6 10
13
10
— / 16
21
Idea: increase flow along augmenting paths
8/9
2 8
10 0/4 /1 0 / 15 /
/ 10
5
10
s 5/5 8/8 10 / 10 t 28
13 10
/ 0/4 3 0 / 15 /
15 /6 10
22
Ford-Fulkerson algorithm
Ford-Fulkerson algorithm
Questions.
・How to compute a mincut?
・How to find an augmenting path?
・If FF terminates, does it always compute a maxflow?
・Does FF always terminate? If so, after how many augmentations?
23
6.4 M AXIMUM F LOW
‣ introduction
‣ Ford-Fulkerson algorithm
‣ maxflow-mincut theorem
Algorithms
‣ analysis of running time
Def. The net flow across a cut (A, B) is the sum of the flows on its edges
from A to B minus the sum of the flows on its edges from B to A.
5/9
5 5
10 0/4 /1 0 / 15 /
10
/ 5
10
10
/ 0 0 / 15 10
15 0/4 /6 /
10
10 / 16
25
Relationship between flows and cuts
Def. The net flow across a cut (A, B) is the sum of the flows on its edges
from A to B minus the sum of the flows on its edges from B to A.
5/9
5 5
10 0/4 /1 0 / 15 /
10
/ 5
10
10
/ 0 0 / 15 10
15 0/4 /6 /
10
10 / 16
26
Relationship between flows and cuts
Def. The net flow across a cut (A, B) is the sum of the flows on its edges
from A to B minus the sum of the flows on its edges from B to A.
5/9
edges from B to A
5 5
10 0/4 /1 0 / 15 /
10
/ 5
10
10
/ 0 0 / 15 10
15 0/4 /6 /
10
10 / 16
27
Relationship between flows and cuts
Flow-value lemma. Let f be any flow and let (A, B) be any cut. Then, the net
flow across (A, B) equals the value of f.
28
Relationship between flows and cuts
Weak duality. Let f be any flow and let (A, B) be any cut.
Then, the value of the flow ≤ the capacity of the cut.
Pf. Value of flow f = net flow across cut (A, B) ≤ capacity of cut (A, B).
8/9
2 8
/1 /
10 0/4 5 0 / 15 10
/ 10
10
s 5/5 7/8 9 / 10 t s 5 t
12
/ 2
15 0/4 /6 0 / 15 10 15
/
10
12 / 16
Pf. The following three conditions are equivalent for any flow f :
i. There exists a cut whose capacity equals the value of the flow f.
ii. f is a maxflow.
iii. There is no augmenting path with respect to f.
[i ii ]
・Suppose that (A, B) is a cut with capacity equal to the value of f.
・Then, the value of any flow f ' ≤ capacity of (A, B) = value of f.
・Thus, f is a maxflow. weak duality by assumption
30
Maxflow-mincut theorem
Pf. The following three conditions are equivalent for any flow f :
i. There exists a cut whose capacity equals the value of the flow f.
ii. f is a maxflow.
iii. There is no augmenting path with respect to f.
31
Maxflow-mincut theorem
Pf. The following three conditions are equivalent for any flow f :
i. There exists a cut whose capacity equals the value of the flow f.
ii. f is a maxflow.
iii. There is no augmenting path with respect to f.
[ iii i]
Suppose that there is no augmenting path with respect to f.
・Let (A, B) be a cut where A is the set of vertices connected to s by an
undirected path with no full forward or empty backward edges.
・By definition of cut, s is in A.
・Since no augmenting path, t is in B.
・Capacity of cut = net flow across cut forward edges full; backward edges empty
32
Computing a mincut from a maxflow
8/9
2 8
/
10 0/4
/1 0 / 15 10
/ 5
10
s 5/5 8/8 10 / 10 t
A 13
/ 3/4 6 10
15 /6 0 / 15 /
10
backward edge
(not empty) 33
6.4 M AXIMUM F LOW
‣ introduction
‣ Ford-Fulkerson algorithm
‣ maxflow-mincut theorem
Algorithms
‣ analysis of running time
Ford-Fulkerson algorithm
Questions.
・How to compute a mincut? Easy. ✔
・How to find an augmenting path? BFS works well.
・If FF terminates, does it always compute a maxflow? Yes. ✔
・Does FF always terminate? If so, after how many augmentations?
yes, provided edge capacities are integers requires clever analysis
(or augmenting paths are chosen carefully)
35
Ford-Fulkerson algorithm with integer capacities
36
Bad case for Ford-Fulkerson
Bad news. Even when edge capacities are integers, number of augmenting
paths could be equal to the value of the maxflow.
flow
0
0
0
10
10
capacity
0
0
1
0
0
10
0
10
0
t
37
Bad case for Ford-Fulkerson
Bad news. Even when edge capacities are integers, number of augmenting
paths could be equal to the value of the maxflow.
1st iteration s
1
0
0
0
10
10
0
0 1
1
1
0
0
10
0
10
0
t
38
Bad case for Ford-Fulkerson
Bad news. Even when edge capacities are integers, number of augmenting
paths could be equal to the value of the maxflow.
2nd iteration s
0
0
10
10
1
0
1 0
1
0
1
10
0
1
10
0
t
39
Bad case for Ford-Fulkerson
Bad news. Even when edge capacities are integers, number of augmenting
paths could be equal to the value of the maxflow.
3rd iteration s
2
1
1
0
10
10
0
0 1
1
2
1
1
10
0
10
0
t
40
Bad case for Ford-Fulkerson
Bad news. Even when edge capacities are integers, number of augmenting
paths could be equal to the value of the maxflow.
4th iteration s
1
0
10
10
2
0
1 0
1
1
2
10
0
2
10
0
t
41
Bad case for Ford-Fulkerson
Bad news. Even when edge capacities are integers, number of augmenting
paths could be equal to the value of the maxflow.
...
42
Bad case for Ford-Fulkerson
Bad news. Even when edge capacities are integers, number of augmenting
paths could be equal to the value of the maxflow.
199th iteration s
0
10
99
99 0
0
10
10
0 1
1
0
10
99
99 0
10
0
10
t
43
Bad case for Ford-Fulkerson
Bad news. Even when edge capacities are integers, number of augmenting
paths could be equal to the value of the maxflow.
200th iteration s
99 0
10
0
10
10
10
0
1 0
1
10 0
99 0
10
10
0
10
0
t
44
Bad case for Ford-Fulkerson
Bad news. Even when edge capacities are integers, number of augmenting
paths could be equal to the value of the maxflow.
can be exponential in input size
10 0
10
0
0
10
10
0
1
10
10 0
10
0
10
0
0
t
45
How to choose augmenting paths?
46
How to choose augmenting paths?
JACK EDMONDS
RICHARD M. K A R P
ABSTRACT. This paper presents new algorithms for t h e m a x i m u m flow problem, the Hitchcock
t r a n s p o r t a t i o n problem, and t h e general m i n i m u m - c o s t flow problem. U p p e r bounds on the
numbers of steps in these algorithms are derived, and are shown to compale favorably with
upper bounds on t h e numbers of steps required by earlier algorithms.
First, the paper states the m a x i m u m flow problem, gives the F o r d - F u l k e r s o n labeling method
for its solution, and points out t h a t an improper choice of flow a u g m e n t i n g p a t h s can lead to
Flow edge data type. Associate flow fe and capacity ce with edge e = v→w.
flow fe capacity ce
v 7/9 w
Flow network data type. Must be able to process edge e = v→w in either
direction: include e in adjacency lists of both v and w.
residual capacity
forward edge
Augment flow.
・Forward edge: add ∆ .
2
v w
・Backward edge: subtract ∆ . 7
backward edge
49
Flow network representation
4 9
/4 /
10
10 4/4 0 / 15
/
9
s 4/5 0/8 4 / 10 t
backward edge
residual network 9 (not empty)
9
9
4 15 1
1 4
s 1 8 6 t
4 4
forward edge
(not full)
residual capacity
forward edge
flow fe capacity ce
v 7/9 w v w
7
backward edge
51
Flow edge: Java implementation
residual capacity
forward edge
flow fe capacity ce
v 7/9 w v w
7
backward edge
53
Flow network API
public FlowNetwork(int V)
{
this.V = V;
adj = (Bag<FlowEdge>[]) new Bag[V];
for (int v = 0; v < V; v++)
adj[v] = new Bag<FlowEdge>();
}
55
Flow network: adjacency-lists representation
・Data mining.
・Open-pit mining.
・Bipartite matching.
・Network reliability.
・Baseball elimination.
・Image segmentation. liver and hepatic vascularization segmentation
・Network connectivity.
・Distributed computing.
・Security of statistical data.
・Egalitarian stable matching.
・Multi-camera scene reconstruction.
・Sensor placement for homeland security.
・Many, many, more.
60
Bipartite matching problem
61
Bipartite matching problem
1 6 1 Alice 6 Adobe
Alice —— Google
Adobe Alice
Bob —— Adobe Amazon Bob
Google Carol
Carol —— Facebook 2 7
2 Bob 7 Amazon
Dave —— Yahoo Adobe Alice
Eliza —— Amazon 3 8
Amazon Bob
3 Carol Dave
Adobe Eliza
Facebook 8 Facebook
4 9
Google Carol
4 Dave 9 Google
Amazon Alice
5 10
Yahoo Carol
5 Eliza 10 Yahoo
N students N companies
Amazon Dave
Yahoo Eliza
62
Network flow formulation of bipartite matching
・Create s, t, one vertex for each student, and one vertex for each job.
・Add edge from s to each student (capacity 1).
・Add edge from each job to t (capacity 1).
・Add edge from student to each job offered (infinite capacity).
flow network bipartite matching problem
1 6 1 Alice 6 Adobe
Adobe Alice
Amazon Bob
2 7 Google Carol
2 Bob 7 Amazon
Adobe Alice
s 3 8 t Amazon Bob
3 Carol Dave
Adobe Eliza
Facebook 8 Facebook
4 9
Google Carol
4 Dave 9 Google
Amazon Alice
5 10
Yahoo Carol
5 Eliza 10 Yahoo
N students N companies
Amazon Dave
Yahoo Eliza
63
Network flow formulation of bipartite matching
1 6 1 Alice 6 Adobe
Adobe Alice
Amazon Bob
2 7 Google Carol
2 Bob 7 Amazon
Adobe Alice
s 3 8 t Amazon Bob
3 Carol Dave
Adobe Eliza
Facebook 8 Facebook
4 9
Google Carol
4 Dave 9 Google
Amazon Alice
5 10
Yahoo Carol
5 Eliza 10 Yahoo
N students N companies
Amazon Dave
Yahoo Eliza
64
What the mincut tells us
1 6
S = { 2, 4, 5 }
2 7 T = { 7, 10 }
student in S
3 8
can be matched
only to
companies in T
4 9
|S| > | T |
5 10
65
What the mincut tells us
S = { 2, 4, 5 }
2 7 T = { 7, 10 }
student in S
s 3 8 t
can be matched
only to
companies in T
4 9
|S| > | T |
5 10
Q. Which teams have a chance of finishing the season with the most wins?
0 Atlanta 83 71 8 – 1 6 1
1 Philly 80 79 3 1 – 0 2
2 New York 78 78 6 6 0 – 0
3 Montreal 77 82 3 1 2 0 –
67
Baseball elimination problem
Q. Which teams have a chance of finishing the season with the most wins?
0 Atlanta 83 71 8 – 1 6 1
1 Philly 80 79 3 1 – 0 2
2 New York 78 78 6 6 0 – 0
3 Montreal 77 82 3 1 2 0 –
Q. Which teams have a chance of finishing the season with the most wins?
0 New York 75 59 28 – 3 8 7 3
1 Baltimore 71 63 28 3 – 2 7 4
2 Boston 69 66 27 8 2 – 0 0
3 Toronto 63 72 27 7 7 0 – 0
4 Detroit 49 86 27 3 4 0 0 –
0–1
0–3 1
∞
s g12 1–2 ∞ 2 w4 + r4 – w2 t
1–3 3
team vertices
2–3 (each team other than 4)
game vertices
(each pair of teams other than 4)
Fact. Team 4 not eliminated iff all edges pointing from s are full in maxflow.
70
Maximum flow algorithms: theory
? ? E ?
maxflow algorithms for sparse digraphs with E edges, integer capacities between 1 and U
71
Maximum flow algorithms: practice
On I m p l e m e n t i n g P u s h - R e l a b e l M e t h o d
for the M a x i m u m Flow P r o b l e m
EUROPEAN
JOURNAL
OF OPERATIONAL
Boris V. Cherkassky 1 and Andrew V. Goldberg 2 RESEARCH
ELSEVIER European Journal of Operational Research 97 (1997) 509-542
1 Central Institute for Economics and Mathematics,
Krasikova St. 32, 117418, Moscow, Russia
[email protected]
2 Computer Science Department, Stanford University Theory and Methodology
Stanford, CA 94305, USA
goldberg~cs. stanford, edu Computational investigations of maximum flow algorithms
Ravindra K . A h u j a a, M u r a l i K o d i a l a m b, A j a y K . M i s h r a c, J a m e s B . O r l i n d,.
A b s t r a c t . We study efficient implementations of the push-relabel method a Department t~'lndustrial and Management Engineering. Indian Institute of Technology. Kanpur, 208 016, India
for the maximum flow problem. The resulting codes are faster than the b AT& T Bell Laboratories, Holmdel, NJ 07733, USA
c KA'F-ZGraduate School of Business, University of Pittsburgh, Pittsburgh, PA 15260, USA
previous codes, and much faster on some problem families. The speedup d Sloun School of Management, Massachusetts Institute of Technology. Cambridge. MA 02139. USA
is due to the combination of heuristics used in our implementations. We
also exhibit a family of problems for which the running time of all known Received 30 August 1995; accepted 27 June 1996
methods seem to have a roughly quadratic growth rate.
Abstract
1 Introduction The maximum flow algorithm is distinguished by the long line of successive contributions researchers have made in
obtaining algorithms with incrementally better worst-case complexity. Some, but not all, of these theoretical improvements
The rnaximum flow problem is a classical combinatorial problem that comes up have produced improvements in practice. The purpose of this paper is to test some of the major algorithmic ideas developed
in a wide variety of applications. In this paper we study implementations of the in the recent years and to assess their utility on the empirical front. However, our study differs from previous studies in
push-rdabel [13, 17] method for the problem. several ways. Whereas previous studies focus primarily on CPU time analysis, our analysis goes further and provides 72
detailed insight into algorithmic behavior. It not only observes how algorithms behave but also tries to explain why
Summary
73