Transcript Max-Flow
Maximum Flow
Haidong Xue (Haydon)
10/28/2013
What is a flow network?
β’ A no-selfloop, weak connected directed graph
(V, E)
β’ Among vertices in V
V
β There is one and only one source vertex π
β There is one and only one sink vertex π‘
β For each vertex v, there is a path π β π£ β π‘
β’ No antiparallel edges in E
E
β if π£1 , π£2 β πΈ, π£2 , π£1 β πΈ
β’ A Capacity is defined on each edge: π π’, π£
What is a flow network?
β’ A flow on a flow network
β π π’, π£
β’ ο’π’, π£οπ: 0 β€ π(π’, π£) ο£ π(π’, π£)
β i.e. π does not exceed π (capasity constraint)
β’ ο’π’οπ ο π , π‘ : οπ£ οπ π π’, π£ = οπ£ οπ π π£, π’
β i. e. the net flow is 0 (flow conservation)
Note:
In some definition of flow networks, negative flows are allowed;
in these slides, we keep consistent with the textbook
Red: flow
Green: capacity
What is a flow network?
β’ Are they flow networks with valid flows?
12/12
15/20
11/16
1/4
17/12
20/20
11/16
6/4
4/9
8/13
4/9
7/7
4/4
13/13
11/14
Not connected
Violate the capacity constraint
12/12
12/12
15/20
15/20
11/16
11/16
1/4
4/9
1/4
7/7
4/4
8/13
11/14
Multiple Sinks
4/9
7/7
4/4
10/13
11/14
Violate the flow conservation rule
Red: flow
Green: capacity
What is a flow network?
β’ Are they flow networks with valid flows?
0/7
12/12
12/12
15/20
11/16
1/4
4/9
0/10
7/7
4/4
8/13
have a self-loop
15/20
11/16
4/9
t
7/7
4/4
8/13
4/9
7/7
4/4
8/13
have an antiparallel edge
12/12
1/4
1/4
11/14
11/14
s
15/20
11/16
11/14
Page 710 Fig 26.1(b)
1 source; 1 sink;
no self-loop; no antiparallel edge;
no flow exceed capacity;
for all non-source non-sink vertices, total flow is 0.
What if the real problem has antiparallel edges
or multiple sinks or sources?
v1
v1
10
10
4
4
Vβ
10
Add an intermediate vertex to
eliminate antiparallel edges
v2
s1
10
ο₯
ο₯
sο’
ο₯
3
s2
s3
12
5
s4
s5
t1
15
6
8
t2
20
14
ο₯
ο₯
v2
7
11
13
18
t3
ο₯
ο₯
tο’
ο₯
2
Add a super-source and a super sink
Why do we
disallow
antiparallel
edges?
What is the max-flow problem?
12/12
15/20
11/16
s
1/4
4/9
t
7/7
4/4
8/13
11/14
The flow of a flow network, |π|:
the net output of the source
i.e., |π | = π£ οπ π(π , π£)-οπ£ οπ π(π£, π )
In the above example, |π | = 11+8=19
What is the max-flow problem?
Given a flow network, there could be more than one valid
flows:
10/12
15/20
9/16
s
1/4
2/9
|π | = 17
t
7/7
2/4
8/13
9/14
12/12
15/20
11/16
s
1/4
4/9
|π | = 19
t
7/7
The maximum-flow problem:
Given a flow network, find a
valid flow that has the
maximum |π |
4/4
8/13
11/14
12/12
19/20
12/16
s
4
9
t
7/7
4/4
11/13
11/14
|π | = 23 (it is a max-flow)
Find a maximum flow
β’ Input: a flow network
12
20
16
s
4
t
7
9
4
13
14
β’ Output: a flow net work with max-flow
12/12
19/20
12/16
s
4
9
t
7/7
4/4
11/13
11/14
Find a maximum flow- residual networks
β’ What are the possible modifications can be made
on an edge that does not break the capacity
constraint?
8/12
4/20
4/16
s
4/4
4/9
t
7
4/4
4/13
4/14
Increase it at most by 10 = c-f=14-4;
Decrease it at most by 4=f.
To represent a possible modifications, residual
networks are introduced
Find a maximum flow - residual networks
12/12
π£1
11/16
s
1/4
8/13
11
3
8
5
π£2
t
π£3
12
15
5
5
4
11
3
t
7
π£4
A flow network πΊ =
(π, πΈ) with a valid
flow
4/4
π£4
11/14
1
15/20
7/7
4/9
π£1
5
s
π£2
π£3
4
A residual network of πΊ, πΊπ = π, πΈπ
where
πΈπ = π’, π£ β π × π: ππ π’, π£ > 0
ππ π’, π£
π π’, π£ β π π’, π£ ππ(π’, π£) β πΈ
=
π π£, π’
ππ (π£, π’) β πΈ
0
Find a maximum flow β augmenting paths
11/16
12/12
π£1
s
1/4
8/13
π£2
π£3
t
7/7
4/9
11/14
11
s
4/4
π£4
π£1
5
15/20
3
8
5
π£2
π£3
12
1
5
5
4
11
3
πΊπ ππ πΊ
πΊ
An augmenting path is a simple path from s to t in the
residual network πΊπ
π£1
5
11
s
3
8
5
π£2
π£3
12
1
15
5
5
4
11
3
t
7
π£4
4
15
t
7
π£4
4
Find a maximum flow β augmenting paths
An augmenting path is a simple path from s to t in the
residual network πΊπ
π£1
5
11
s
3
8
4/5
π£3
12
1
π£2
15
4/5
5
11
t
7
4/4
π£4
4
3
The residual capacity of an augmenting path π:
ππ(π) = min{ππ(π’, π£): (π’, π£) ππ ππ π}
The flow defined by π, ππ :
ππ π’, π£ =
ππ π ,
0,
ππ π = 4
ππ (π’, π£) ππ ππ π
ππ‘βπππ€ππ π
Guaranteed by
Corollary 26.3 ,
modifying πΊ
according to this
flow on πΊπ does
not break the flow
conservation rule
Find a maximum flow β augmenting paths
11/16
12/12
π£1
s
1/4
8/13
π£2
π£3
4/9
11/14
t
7/7
11
s
4/4
π£4
π£1
5
15/20
3
1
8
4/5
π£2
π£3
12
15
4/5
5
11
π£4
3
Modify πΊ according to ππ
12/12
π£1
s
π£3
1/4
19/20
t
7/7
0/9
12/13
4
πΊπ ππ πΊ π€ππ‘β πππ‘β π πππ ππππ€ ππ
πΊ π€ππ‘β π
11/16
t
7
4/4
π£2
11/14
πΊ π€ππ‘β "π β ππ "
π£4
4/4
Find a maximum flow
β’ Corollary 26.3 guarantees that:
β π β ππ is a valid flow in πΊ
β π β ππ > |π|
β’ Theorem 26.6 (Max-flow min-cut theorem)
further tells that:
β If there is no augmenting path in πΊπ , π in πΊ is a
maximum flow
Do you have any idea to develop an algorithm to find a
max-flow?
Find a maximum flow β the basic FordFulkerson algorithm
FORD-FULKERSON(πΊ, π , π‘)
Initialize |π| to 0
for each π’, π£ ο πΊ. πΈ
(π’, π£). π = 0;
while there exist path π from π to π‘ in πΊπ
ππ(π) βΆ= min{ππ(π’, π£): (π’, π£) ππ ππ π};
for each (π’, π£) in p
if π’, π£ β πΊ. πΈ, π’, π£ . π = (π’, π£). π+ ππ π ;
else π’, π£ . π = π’, π£ . π β ππ π ;
Is it correct? What is the time complexity?
Repeatedly find a
ππ , and apply the
modification until
there is no
augmenting path
Find a maximum flow β Analysis of F-F
β’ Is it correct in general?
β No!
β A counter example:
http://en.wikipedia.org/wiki/Ford%E2%80%93Fulkerson_algorithm#Nonterminating_example
β’ Is it correct with integer capacities?
β
β
β
β
Yes.
To find a π, if using DFS or BFS that is O(|V|+|E|)=O(|E|)
At most, need to it |π β | times
Time complexity: π(|πΈ||π β |)
Find a maximum flow β Edmonds-Karp
algorithm
EDMONDS-KARP(πΊ, π , π‘)
for each π’, π£ ο πΊ. πΈ
(π’, π£). π = 0;
while there exist a BFS path π from π to π‘ in πΊπ
ππ(π) βΆ= min{ππ(π’, π£): (π’, π£) ππ ππ π};
for each (π’, π£) in p
if π’, π£ β πΊ. πΈ, π’, π£ . π = (π’, π£). π+ ππ π ;
else π’, π£ . π = π’, π£ . π β ππ π ;
Find a maximum flow β Analysis of E-K
β’ Theorem 26.8
β The total number of flow augmentations performed by the
algorithm is O(|V||E|)
β’ Time complexity
β π(|πΈ|) β π(|π||πΈ|) = π(|π||πΈ|2 )
Find a maximum flow β Example
πΊ
πΊπ
12
12
20
16
s
4
9
t
7
4
13
20
16
s
4
4
13
14
14
12/12
12
12/20
12/16
s
4
9
8
4
t
7
12
s
12
4
4
13
4
13
14
12
12/12
12/20
12/16
4
9
4/14
8
4
t
7
4/4
4/13
t
7
9
14
s
t
7
9
12
s
12
4
9
4
9
4
10
t
7
4
Find a maximum flow β Example
πΊ
πΊπ
12
12/12
12/20
12/16
s
4
9
12
s
t
7
12
4
4
9
12/12
12
19/20
12/16
4
4
10
4/14
s
t
7
9
4
4/4
4/13
8
4
9
t
7/7
11/14
A max-flow
12
s
19
4
9
11
4/4
11/13
1
4
11
2
t
7
4
3
π‘ cannot be reached by π
Maximum bipartite matching
β’ A problem can be converted to the max-flow
problem
β’ Bipartite Graph
β A undirected graph (V, E)
β π = πΏ βͺ π
, πΏ β© π
= β
β All edges in E go between πΏ and π
β Every vertex in V has at least one incident edge
Maximum bipartite matching
L
R
L
R
L
R
Maximum bipartite matching
A matching π: π β πΈ,
L
R
π =1
L
R
π =2
L
R
π =3
The maximum bipartite matching problem: find a M with the maximum π
Maximum bipartite matching
Convert it to a max-flow problem
L
R
L
R
s
t
Set each edge with a capacity of 1
By Lemma 26.9, π = |π|
Summary
β’ Max-flow problem
β
β
β
β
β
β
Flow network πΊ
The flow of πΊ
The residual network πΊπ ππ πΊ
A augmenting path π of πΊπ
ππ , ππ
Ford-Fulkerson, Edmonds-Karps
β’ Maximum bipartite Matching
β Bipartite graph
β Matching
β Convert a bipartite graph to a flow net work
FYI
β’ Your next assignment has already been posted
β’ Chaoyangβs will be holding extended office
hours on Wednesdays from 12:00pm-4:00pm
β’ ACM has an event tomorrow
Room 460, University Center
Distributed Content Delivery Systems with Real Time Route Optimization
Free knowledge, pizza, soda, donut, and a door price
Pop Quiz
Write down your official name clearly on the right-top corner
in the form: Last Name, First Name. (e.g. Xue, Haidong)