Maximum Flow in Graphs: Ford-Fulkerson
Maximum Flow in Graphs: Ford-Fulkerson
By,
Dr. Kovendan AKP,
Senior Assistant Professor,
Department of Database Systems,
School of Computer Science and Engineering,
Vellore Institute of Technology, Vellore.
Flow Value:
1/2
2/2
b c
2/3 |f| = V(f) = fout(s)
= fin (t)
=3
1/7 2/6
S ?/6 t
?/4
9/11
b c
10/15
4/4
a d
3/4 8/10
1/7 2/6
S 6/6 t
4/4
9/11
b c
10/15
a d a 6 d
1
1 7 2 21
c c
3 2
2 21
c
2 21
c
t1 t1
∞ s1 ∞
s1
Internal Internal
s ∞
Node t2 Node t2 t
∞
s2 s2 ∞
t3 t3
𝑐 𝑢, 𝑣 − 𝑓 𝑢, 𝑣 , 𝑖𝑓 (𝑢, 𝑣) ∈ 𝐸
𝑐𝑓 𝑢, 𝑣 = ൞ 𝑓 𝑣, 𝑢 , 𝑖𝑓(𝑣, 𝑢) ∈ 𝐸
0, 𝑂𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Monday, 03 July 2023 Instructor: Dr. Kovendan AKP 15
Residual Graph Example 1
b b
1 1
1/1 1
a d a 1 1 d
1/2
1 1
1 1/1 c
c
5/7
a d
3/3 5/8
2/2 1/1
S 1/1 t
2/3
4/5
b c
3/3
Path in Residual
Graph
a a Augment the Path in
3 C(P’)=min{3,3,1}=1 1/3 Flow Graph
3 1/3
1 4 1 1/5 2/2
s b c t 1/1
s b c t
1 1
4 3 0/4 0/3
d e d e
2 0/2
Monday, 03 July 2023 Instructor: Dr. Kovendan AKP 21
Maximum Flow - The Ford-Fulkerson method
• We try to find out the max flow value of a graph.
• Max(V(f))
a
0/3 Flow initialized to
0/3
Zero
0/1 0/5 0/2
s b c t
0/4 0/3
d e
0/2
Path in Residual
Graph
a Augment the Path in
a C(P’)=min{1,5,5}=1 0/3 Flow Graph
3 0/3
3
1/1 1/5 2/2
1 s b c t
5 2
s b c t
0/4 0/3
4 3
d e
Monday, 03 July 2023 d e Instructor: Dr. Kovendan AKP
0/2 24
2
Flow graph a Residual graph
a 3
3
0/3
0/3
1 4 1
1/5 1/2 s b c t
1/1
s b c t 1 1
4 3
0/4 0/3
d e
d e 2
0/2
Path in Residual
Graph
a a Augment the Path in
3 C(P’)=min{3,3,1}=1 1/3 Flow Graph
3 1/3
1 4 1 1/5 2/2
s b c t 1/1
s b c t
1 1
4 3 0/4 0/3
d e d e
2 0/2
Monday, 03 July 2023 Instructor: Dr. Kovendan AKP 25
a Flow graph a Residual graph
1/3 1 1
1/3 2 2
1/5 2/2 1 4
1/1 s b c t
s b c t
1 2
0/4 0/3 4 3
d e d e
0/2 2
Path in Residual
Graph
a a Augment the Path in
1 C(P’)=min{2,2,1,4,2,3}=1 2/3 Flow Graph
1 2/3
2 2
1 4 1/1 0/5 2/2
s b c t s b c t
1 2
4 3 1/4 1/3
d e d e
Monday, 03 July 2023 2 Instructor: Dr. Kovendan AKP
1/2 26
a Flow graph a Residual graph
2 2
2/3 1 1
2/3
0/5 2/2 1 5
1/1 s b c t
s b c t 2
1 1
3 2
1/4 1/3 1
d e d e
1/2 1
Path in Residual
Graph
a Final Flow graph
a
Not a valid path !!! 2/3 Maximum Flow
2 2 2/3
1 1 V(f)=3
1 1 1/3
3 2 1/4
1
d e d e
Monday, 03 July 2023 1 Instructor: Dr. Kovendan AKP
1/2 27
Homework
• Apply Ford Fulkerson method to find the maximum flow in the given
graph.
Question
Solution
1 5 2
s b c t
4 3
d e T
2
Monday, 03 July 2023 Instructor: Dr. Kovendan AKP 30
a S
Capacity of a Cut 3
3
1 5 2
s b c t
• The capacity of a S-T cut is denoted by C(S,T).
4 3
𝐶 𝑆, 𝑇 = 𝐶(𝑢, 𝑣) d e T
𝑢∈𝑆 2
𝑣∈𝑇
• Summation of capacity of outgoing edges from S to T.
• Eg: S={s,a,c} T={b,d,e,t}
Outgoing edges={(s,b),(c,t)}
C(S,T) = 1+2
C(S,T) = 3
• A min cut in a S-T cut is defined as a cut with minimum capacity.
Monday, 03 July 2023 Instructor: Dr. Kovendan AKP 31
Flow across the cut
• It is also referred to a the net flow.
• If f is the flow in the graph G, then the net flow f(S,T) across the cut
(S,T) is defined as follows,
=2 0/4 0/3
d e T
0/2
f(v) = |f| = 2
f(S,T) = |f|
• Capacity
O(E .|f*|)
0/8
0/2 0/6
S t
0/10
0/10
b c
0/9
s 6 t
8 5
b
8 5
h(a) = 0 ; e(a) = 0
b h(b) = 0 ; e(b) = 0
h(t) = 0 ; e(t) = 0
h(b)=0
e(b)=0
a a
5 4 5/5 4
h(t)=0 h(t)=0
h(s)=4 s t h(s)=4 s 6 t
6 e(t)=0 e(t)=0
8 8/8 5
5
b b
h(b)=0 h(b)=0
e(b)=0 e(b)=8
a a
5/5 4 5/5 4
h(t)=0 h(t)=0
h(s)=4 s 6 t h(s)=4 s 6/6 t
e(t)=0 e(t)=0
8/8 5 8/8 5
b b
h(b)=0 h(b)=1
e(b)=8 e(b)=2
a a
5/5 4 5/5 4/4
h(t)=0 h(t)=0
h(s)=4 s t h(s)=4 s 6/6 t
6/6 e(t)=0 e(t)=4
8/8 5 8/8 5
b b
h(b)=1 h(b)=1
e(b)=2 e(b)=2
a a
5/5 4/4 5/5 4/4
h(t)=0 h(t)=0
h(s)=4 s 6/6 t h(s)=4 s 0/6 t
e(t)=4 e(t)=4
8/8 5 8/8 5
b b
h(b)=1 h(b)=1
e(b)=2 e(b)=8
a a
5/5 4/4 5/5 4/4
h(t)=0 h(t)=0
h(s)=4 s 0/6 t h(s)=4 s 0/6 t
e(t)=4 e(t)=9
h(b)=1 h(b)=1
e(b)=8 e(b)=3
a a
5/5 4/4 5/5 4/4
h(t)=0 h(t)=0
h(s)=4 s 0/6 t h(s)=4 s 0/6 t
e(t)=9 e(t)=9
h(b)=1 h(b)=2
e(b)=3 e(b)=3
Active Node: b
Neighbours : {s,a,t}
a a
5/5 4/4 5/5 4/4
h(t)=0 h(t)=0
h(s)=4 s 0/6 t h(s)=4 s 3/6 t
e(t)=9 e(t)=9
h(b)=2 h(b)=3
e(b)=3 e(b)=0
a a
5/5 4/4 5/5 4/4
h(t)=0 h(t)=0
h(s)=4 s 3/6 t h(s)=4 s 3/6 t
e(t)=9 e(t)=9
h(b)=3 h(b)=3
e(b)=0 e(b)=0
Active Node: a
Neighbours : {s,b,t}
a a
5/5 4/4 5/5 4/4
h(t)=0 h(t)=0
h(s)=4 s 3/6 t h(s)=4 s 0/6 t
e(t)=9 e(t)=9
h(b)=3 h(b)=3
e(b)=0 e(b)=3
a a
5/5 4/4 5/5 4/4
h(t)=0 h(t)=0
h(s)=4 s 0/6 t h(s)=4 s 0/6 t
e(t)=9 e(t)=9
h(b)=3 h(b)=4
e(b)=3 e(b)=3
Active Node: b
Neighbours : {s,a,t}
a a
5/5 4/4 5/5 4/4
h(t)=0 h(t)=0
h(s)=4 s 0/6 t h(s)=4 s 0/6 t
e(t)=9 e(t)=9
h(b)=4 h(b)=5
e(b)=3 e(b)=0
a a
5/5 4/4 4/5 4/4
h(t)=0 h(t)=0
h(s)=4 s 0/6 t h(s)=4 s 0/6 t
e(t)=9 e(t)=9
h(b)=5 h(b)=5
e(b)=0 e(b)=0
a
4/5 4/4
No excess in the intermediate
h(t)=0
h(s)=4 s 0/6 t nodes !!!
e(t)=9
So, Stop.
5/8 5/5
b
h(b)=5
e(b)=0
s 5 8 t
12 17
c d
6
5 8 h(t)=0
h(s)=6 s t
e(t)=0
12 17
c d
6
h(c)=0 h(d)=0
e(c)=0 e(d)=0
5 8 h(t)=0 h(t)=0
h(s)=6 s t h(s)=6 s 5 8 t
e(t)=0 e(t)=0
12 17 12/12 17
c d c d
6 6
h(c)=0 h(d)=0 h(c)=0 h(d)=0
e(c)=0 e(d)=0 e(c)=12 e(d)=0
17 12/12 17
12/12 c d
c d 6/6
6
h(c)=0 h(c)=1 h(d)=0
h(d)=0
e(c)=12 e(c)=6 e(d)=6
e(d)=0
12/12 17 12/12 17
c d c d
6/6 6/6
h(c)=1 h(d)=0 h(c)=1 h(d)=0
e(c)=6 e(d)=6 e(c)=6 e(d)=6
12/12 17 12/12 17
c d c d
6/6 6/6
h(c)=1 h(d)=0 h(c)=1 h(d)=0
e(c)=6 e(d)=6 e(c)=6 e(d)=14
e1 e2 e3
Also, |M P | = |M| + 1
A vertex can have one incident edge from M, or one incident edge from M’, or one
incident edge from M and another from M’
The cycles must be even cycles with alternating edges from M and M’
Since M’ has a cardinality greater than M, there must be at least one path
which starts and ends in M’.
Go to (1)
S T
Start from the free vertices in S
Suppose all the vertices in T are matched, then we follow the matched
edges back to S, and subsequently all free edges from the newly
encountered ones in S.
If we reach a free vertex in T we are done, otherwise again follow back the
matched edges into S.
Monday, 03 July 2023 Instructor: Dr. Kovendan AKP 97
Don’t include free edges from S into already reached vertices in T.
So vertices in T are never repeated
Any odd length path must have one end in S and another end
in T.
An example of a feasible label is l(y) = 0 for all vertices in Y and l(x) = maxyw(x,
y)
Equality subgraph consists of all vertices. An edge (x, y) is included in the equality
subgraph if l(x) + l(y) = w(x, y).
= Weight of M
So, if we can adjust the labels so that the equality subgraph has a perfect
matching, then we are done. Why?
Supposing, the equality subgraph had all the edges in the original graph.
Then it is a complete bipartite graph.
Hence, it would have a perfect matching.
However, any adjustment should be such that the labels are feasible.
If this is a perfect matching, then stop. Otherwise, readjust the labels and go to step
(2).
Monday, 03 July 2023 Instructor: Dr. Kovendan AKP 111
Readjustment of Labels
Construct the Hungarian tree w.r.t. the current maximum matching in the
equality subgraph.
The hungarian tree will not yield an augmenting path in the equality
subgraph.
Let S be the set of vertices in X in the tree, and T be the set of vertices
in Y.
Monday, 03 July 2023 Instructor: Dr. Kovendan AKP 112
Observe that there are no edges between S and Y – T in the equality
subgraph (else hungarian tree has not been grown properly).
At the same time, there are edges between S and Y – T in the original graph.
Reason: Current matching is not maximum in G, as G has a perfect matching, and this is
not a perfect matching.
So the hungarian tree must have an augmenting path in G.
But we know there is no augmenting path in the current hungarian tree.
This means that the current hungarian tree can grow further in G, and this is possible
only if there are edges between S and Y-T.
Edges between S and Y-T in G will now start entering the equality
subgraph.