0% found this document useful (0 votes)
21 views30 pages

06 Max Flow

The document discusses graph theory, focusing on flow networks and the maximum-flow problem, which involves finding the maximum flow from a source to a sink in a directed graph. It details the Ford-Fulkerson method and its variations, including the Edmonds-Karp algorithm, which utilizes breadth-first search to find augmenting paths. Additionally, it covers concepts such as residual networks, augmenting paths, and the max-flow min-cut theorem, providing a comprehensive overview of the principles and algorithms related to maximum flows in networks.

Uploaded by

Mëłły Lîlï
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views30 pages

06 Max Flow

The document discusses graph theory, focusing on flow networks and the maximum-flow problem, which involves finding the maximum flow from a source to a sink in a directed graph. It details the Ford-Fulkerson method and its variations, including the Edmonds-Karp algorithm, which utilizes breadth-first search to find augmenting paths. Additionally, it covers concepts such as residual networks, augmenting paths, and the max-flow min-cut theorem, providing a comprehensive overview of the principles and algorithms related to maximum flows in networks.

Uploaded by

Mëłły Lîlï
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Graph Theory

[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:

• G=(V,E): a flow network with capacity function c.


• s-- the source and t-- the sink.
• A flow in G: a real-valued function f:V*V à R satisfying
the following three properties:
• Capacity constraint: For all u,v ÎV,
we require f(u,v) £ c( u,v).
• Flow conservation: For all u ÎV-{s,t}, we require

å 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

– The total flow from source to any other vertices.


– The same as the total flow from any vertices to
the sink.
5
12/12

11/16 15/20

s 10 1/4 4/9 7/7 t

8/13 4/4

11/14

A flow f in G with value f = 19 .

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.

• How to solve it efficiently?

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

Given a graph G and two nodes (s, t)


• initialize flow f to 0
• while there exists an augmenting path p
• do augment flow f along p
• return f

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

• Let G=(V,E) be a flow network with source s and sink t, and


let f be a flow in G
• Let Gf be the residual network of G induced by f, and let f’
be a flow in Gf
Then, the flow sum f+f’ is a flow in G with value

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.

• Residual capacity of p : the maximum amount of net flow


that we can ship along the edges of an augmenting path p,
i.e., cf(p)=min{cf(u,v):(u,v) is on p}.

2 3 1

The residual capacity is 1 14


Example of an augment path (bold edges)

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)

We run a loop while there is an augmenting path.


In worst case, we may add 1 unit flow in every iteration.
Therefore the time complexity becomes 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

s 10 1/4 4/9 7/7 t

8/13 v2 v4 4/4
11/14
S T

A cut (S,T), where S={s,v1,v2} and T={v3,v4,t}.


The net flow across (S,T) is f(S,T) = 12-4+11 = 19
and the capacity is c(S,T)=12+14=26.
25
Property of cuts
• Let f be a flow in a flow network G with source s
and sink t, and let (S,T) be a cut of G.
Then, the net flow across (S,T) is f(S,T)= f .
• Proof: 1. f(S-s, V)=0 by flow conservation.
• 2. f(S, S)=0 since f(u, v)=-f(v, u).
• f(S, T)=f(S, V)-f(S, S)=f(S, V)
=f(s, V)+f(S-s, V)=f(s, V)=|f|.

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.

• Proof: f(S, T) £ c(S, T).

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

You might also like