06 Max Flow
06 Max Flow
[6]
Documents are here:
Maximum flows
Ford-Fulkerson method
Edmonds and Karp’s algorithm
https://www-l2ti.univ-paris13.fr/~viennet/ens/2024-USTH-Graphs
Emmanuel Viennet
[email protected]
•material coursing through a system from a source to a sink
2
Flow networks:
• A flow network G=(V,E): a directed graph, where each
edge (u,v)ÎE has a nonnegative capacity c(u,v)>=0.
• If (u,v)ÏE, we assume that c(u,v)=0.
• two distinct vertices :a source s and a sink t.
12
16 20
s 10 4 9 7 t
13 4
14 3
Flow:
å f (e) = å f (e)
e.in .v e.out .v 4
Net flow and value of a flow f:
• The quantity f (u,v), which can be positive or
negative, is called the net flow from vertex u to
vertex v.
• The value of a flow is defined as
f = å f ( s, v )
vÎV
11/16 15/20
8/13 4/4
11/14
6
Maximum-flow problem:
• Given a flow network G with source s and sink t
• Find a flow of maximum value from s to t.
7
The Ford-Fulkerson method
This section presents the Ford-Fulkerson method for solving
the maximum-flow problem. We call it a “method” rather
than an “algorithm” because it encompasses several
implementations with different running times.
The Ford-Fulkerson method depends on three important
ideas that transcend the method and are relevant to many
flow algorithms and problems: residual networks,
augmenting paths, and cuts.
These ideas are essential to the important max-flow min-cut
theorem, which characterizes the value of maximum flow in
terms of cuts of the flow network.
8
The Ford-Fulkerson method
9
Residual networks
• Given a flow network and a flow, the residual
network consists of edges that can admit more net
flow.
• G=(V, E) a flow network with source s and sink t
• f: a flow in G.
• The amount of additional net flow from u to v
before exceeding the capacity c(u,v) is the residual
capacity of (u,v), given by: cf(u,v) = c(u,v) - f(u,v)
10
Example of residual network
12 4/12
v1 v3 v1 v3
16 20 4/16 20
s 10 4 9 7 t s 7
10 4 4/9 t
13 4 13 4/4
v2 v4 v2 v4
14 4/14
(a)
11
Example of Residual network (continued)
8
12 v1 v3
20
s 10 4 4 t
7
13 10 4
v2 v4
(b)
12
Fact 1
f + f' = f + f'
13
Augmenting paths
• Given a flow network G=(V,E) and a flow f, an augmenting
path is a simple path from s to t in the residual network Gf.
2 3 1
8
12 v1 v3
20
4
s 4 4
10 7 t
13 10 4
v2 v4
(b)
15
The basic Ford-Fulkerson
algorithm:
• FORD-FULKERSON(G,s,t)
• for each edge (u,v) Î E[G]
• do f[u,v] ¬ 0
• f[v,u] ¬ 0
• while there exists a path p from s to t in the residual
network Gf
• do cf(p)¬ min{cf(u,v): (u,v) is in p}
• for each edge (u,v) in p
• do f[u,v]¬ f[u,v] + cf(p)
•
16
Example: next slides (a) to (e)
Execution of the basic Ford-Fulkerson algorithm (successive
iterations of the while loop)
The left side of each part shows the residual network Gf with
a shaded augmenting path p.
The right side of each part shows the new flow f that results
from adding fp to f.
The residual network in (a) is the input network G.
(e) The residual network at the last while loop test. It has no
augmenting paths, and the flow f shown in (d) is therefore a
maximum flow.
17
residual network Gf new flow f
12 4/12
v1 v3 v1 v3
16 20 4/16 20
s 10 4 9 7 t s 7
10 4 4/9 t
13 4 13 4/4
v2 v4 v2 v4
14 4/14
(a)
18
residual network Gf new flow f
8
12 4/12
v1 v3 v1 v3
20 7/20
4 11/16
4
s 10 4 4 7 t s 7/10 4 7/7 t
5 4/9
13 10 4 13 4/4
v2 v4 v2 v4
4 11/14
(b)
19
residual network Gf new flow f
8 12/12
5 v1 v3 13 v1 v3
4 11/16 15/20
11 4
s 3 11 7 7 t s 7/7
10 1/4 4/9 t
5
13 3 8/13 4/4
v2 v4 4 v2 v4
11 11/14
(c)
20
residual network Gf new flow f
12 12/12
5 v1 v3 5 v1 v3
11/16 19/20
11 4
s 11 3 7 15 t s 10 1/4 9 7/7 t
5 5
8 3 12/13 4/4
v2 v4 4 v2 v4
11 11/14
(d)
21
12
5 v1 v3 1
No augmenting path !
s
1 11
3
9 7 19 t stop
12 3 4
v2 v4
11
(e)
22
Time complexity
Time complexity of the Ford-Fulkerson’s algorithm is
O(max_flow * E)
23
Cuts of flow networks
The proof of the correctness of the Ford-Fulkerson
method depends on a concept “cut”.
• A cut (S,T) of flow network G=(V,E) is a partition of
V into S and T=V-S such that sÎS and t ÎT.
• If f is a flow, then the net flow across the cut (S,T)
is F(S,T)=S uÎS&vÎT f(u, v).
• The capacity of the cut (S,T) is
c(S, T)= S uÎS&vÎT c(u, v).
24
12/12
v1 v3
11/16 15/20
8/13 v2 v4 4/4
11/14
S T
26
Property of cuts (cont.)
• The value of any flow f in a flow network G is bounded
from above by the capacity of any cut of G.
27
Max-flow min-cut theorem
If f is a flow in a flow network G=(V,E) with source s and sink t,
then the following conditions are equivalent:
1. f is a maximum flow in G;
2. The residual network Gf contains no augmenting paths;
3. |f| = c(S,T) for some cut (S,T) of G.
Proof:
1è2: Otherwise, if a aug. path exists, we can further increase
the flow.
2è3. If no aug. path exists, then we construct S as the set of
vertices that is reachable from s. T=V-S. By construction,
there is no edge (u, v) in the residual graph such that uÎS
and vÎT. Thus, |f|=f(S,T)=c(S, T).
3è1 |f|=f(S, T)=c(S,T). Recall that |f|= f(S, T) £ c(S,T).
Thus, |f| is maximum. 28
The Edmonds-Karp algorithm
• Find the augmenting path using breadth-
first search (BFS)
Breadth-first search gives the shortest
path for graphs (Assuming the length of each
edge is 1.)
• Time complexity of Edmonds-Karp
algorithm is O(VE2).
29
Playground:
https://visualgo.net/en/maxflow
More examples:
https://www.hackerearth.com/practice/algori
thms/graphs/maximum-flow/tutorial
30