Week12 Chap5 MaxFlow Max Matching Hungarian
Week12 Chap5 MaxFlow Max Matching Hungarian
APPLIED ALGORITHMS
Maximum Flow and Maximum Matching on the Bipartite Graph
3
CONTENTS
4
MAXIMUM FLOW
• Definition of network
• Flow (luồng) and maximum flow problem (bài toán luồng cực đại)
• Cut (lát cắt) and minimum cut problem (bài toán lát cắt cực tiểu)
• The relationship between the maximum flow and minimum cut
problems
• Ford-Fulkerson algorithm
• Edmond-Karp algorithm
5
Network (Mạng)
6
Flow (luồng)
7
The maximum flow problem
v
• Maximum flow problem: On a network 2/6
1/3
8
Cut
• Cut is a way of partitioning the vertex set of a graph into two sets S and T such
that s S, t T.
• The capacity (khả năng thông qua) 𝐶𝑎𝑝(𝑆, 𝑇) of the cut 𝑆, 𝑇 is defined 𝐶𝑎𝑝 𝑆, 𝑇 =
σ 𝑢,𝑣 ∈𝐸,𝑢∈𝑆,𝑣∈𝑇 𝑓(𝑢, 𝑣)
S = {s}
Example 1
2 9 5
T = {t,2,3,4,5,6,7}
10 Cap(S, T) = 10+5+15=30
4 15 15 10
S
s 5 3 8 6 10 t
4 6 15 10
15
4 30 7
9
Minimum cut (Lát cắt cực tiểu)
• Cut is a way of partitioning the vertex set of a graph into two sets S and T such that s S, t T.
• Capacity 𝐶𝑎𝑝(𝑆, 𝑇) of the cut 𝑆, 𝑇 is defined as 𝐶𝑎𝑝 𝑆, 𝑇 = σ 𝑢,𝑣 ∈𝐸,𝑢∈𝑆,𝑣∈𝑇 𝑓(𝑢, 𝑣)
• The minimum cut problem: Among the cuts, find the cut with the smallest capacity
2 9 5
Example 2
10 15 15 10
4
s 5 3 8 6 10 t
4 6 15 10
15
cap(S2,T2) = 28
4 30 7
10
The relationship between max flow and min cut problems
eS →T
f (e) −
eT → S
f (e) = +
f (e) = val ( f )
eE (s )
11
Residual graph (đồ thị tăng luồng)
e = (u,v) eR = (v,u)
Residual graph: Gf = (V, Ef ).
• Ef = {e: f(e) < c(e) } {eR : f(e) > 0 }
cap
• Capacity of edge
c(e) − f (e) if e E v 11 w
c f ( e) = 6
f (e) if e R E
cap
12
Residual graph - Example
Residual graph: Gf = (V, Ef ). c(e) − f (e) if e E
c f ( e) =
– Ef = {e : f(e) < c(e)} {e : f(e) > 0}.
R
f (e) if e R E
– cf(e) indicates the maximum amount that can increase flow on edge e.
– cf(eR) indicates the maximum amount that can decrease flow on edge e.
4 5
0 (s,4)
0 4 0 (s,2)
G 4
0 4 (2,3)
10 4
10 10 (4,3)
s 10 2 13 3 10 t (2,5)
(3,t)
4 5
(5,t)
4
Gf 4
4
4
s 10 2 10 3 10 t
3
13
Residual graph - Example
4
Gf 4
4
4
s 10 2 6 3 10 t
7
15
Theorem about maximum flow and minimum cut
Augmenting path Theorem (Ford-Fulkerson, 1956): Flow is maximum if and only if there
does not exist augmenting path on network.
Max flow and min cut Theorem (Ford-Fulkerson, 1956): the maximum possible flow in a
network (from source to sink) is exactly equal to the minimum capacity of all possible cuts.
Theorem. Assume f is a flow in network. The following three statements are equivalent
(i) Can find the cut (S, T) such that val( f ) = cap(S, T).
(ii) f is maximum flow.
(iii) Could not find augmenting path to augment value flow f.
16
Ford – Fulkerson algorithm
17
Computation time
18
Example: Ford – Fulkerson algorithm does not terminate
▪ Zwick constructs examples showing that the algorithm may not stop, if the
capacity of edges is irrational
s
X X
X
1 1
X
X X
t
▪ There are 6 arcs with capacity = X, 2 edges with capacity = 1 and one edge with
capacity = ( 5-1)/2 0.618034...
19
Edmond-Karp algorithm
20
CONTENTS
21
Maximum matching on the Bipartite Graph
• Given a bipartite graph, each side consists of n vertices, find a way to select n
edges of the graph so that each vertex of the graph appears in exactly one selected
edge and the total weight of the selected edges is the largest.
22
Equality Graph (Đồ thị bù) và Augmenting path (Đường mở)
23
Equality Graph (Đồ thị bù) và Augmenting path (Đường mở)
(f, e, d) is (f, e, d, c, b, a) is
alternative augmenting path
path
24
Hungary algorithm
BEGIN
initialize labels on nodes
WHILE matching is not complete DO
find a root of an alternating path
WHILE augmenting path not found DO
try to find augmenting path in equality graph
IF augmenting path not found
THEN update labels
increase matching
END
25
Hungary algorithm- Initialize the weight on the vertex
26
Hungary algorithm – Procedure to Update labels
• Suppose we are trying to find an augmenting path 𝑝 but are unsuccessful, we need
to add edges to the graph 𝐺𝑡 to find an ougmenting path. Suppose 𝑝 is containing 𝑆
which is the set of vertices in 𝑋 and 𝑇 is the set of vertices in 𝑌. Calculate Δ
according to the following formular:
• Update the weights on the vertices according to the following formula before
finding the corresponding equality graph and finding the augmenting path:
27
Example
28
Example
29
Example
30
Example
31
Example
32
Example
33
Example
34
Example
35
Example
36
Reference
• https://algorithms.discrete.ma.tum.de/graph-algorithms/matchings-
hungarian-method/index_en.html
37
THANK YOU !
38