0% found this document useful (0 votes)
15 views61 pages

Seminar 8 - Network Flow (Handout)

The document discusses the maximum flow problem in flow networks, detailing the Ford-Fulkerson method for solving it. It explains the properties of flow networks, including capacity constraints and flow conservation, and introduces concepts such as augmenting paths and residual networks. The seminar aims to provide a comprehensive understanding of network flow algorithms and their applications.

Uploaded by

ttri0026
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)
15 views61 pages

Seminar 8 - Network Flow (Handout)

The document discusses the maximum flow problem in flow networks, detailing the Ford-Fulkerson method for solving it. It explains the properties of flow networks, including capacity constraints and flow conservation, and introduces concepts such as augmenting paths and residual networks. The seminar aims to provide a comprehensive understanding of network flow algorithms and their applications.

Uploaded by

ttri0026
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/ 61

FIT2004 - Algorithms and Data Structures

Seminar 8 - Network Flow

Rafael Dowsley
28 April 2025
Agenda

Divide-and- Greedy Dynamic Network Data


Conquer Algorithms Programming Flow Structures
(W1-3) (W4-5) (W6-7) (W8-9) (W10-11)

1 Maximum Flow Problem

2 Ford-Fulkerson method

3 Min-cut Max-flow Theorem


Maximum Flow Problem
Flow networks

3
a c
3 3

s t

3
5 5
b d
5

• A flow network is a connected directed graph where:

I There is a single source vertex, often denoted by s, which only has


outgoing edges.

I There is a single sink/target vertex, often denoted by t, which only has


incoming edges.

I Each edge has a given non-negative capacity (usually integers) giving the
maximum amount/rate of flow that the edge can carry.

1/51
What are flow networks used for?

3
a c
3 3

s t

3
5 5
b d
5

• Flow networks can model many real-world problems, such as:

I Water flowing through an assembly of pipes.


I Electric current flowing through electrical circuits.
I Information flowing through communication networks.

• Can be applied to solve a large range of other combinatorial


problems unrelated to physical flows.

2/51
Flow

3/3
a c 0/
3
3/ 3

s t

3
3/
2/
5 5/5
b d
5/5

• For an edge e, its flow f (e) is an assignment of how much material


is flowing through it in the flow network given its capacity c(e).

• All vertices (except source and sink) conserve their flow:

I Let Ein (v ) denote the set of all incoming edges to a vertex v , and similarly
Eout (v ) denote its set of outgoing edges.
I The total amount flowing into any vertex (through incoming edges) is equal
to the total amount flowing out of that vertex (through outgoing edges).

3/51
Quiz time!
Properties of a flow network

A flow network must satisfy the following properties:

Capacity constraint
For every edge e, its flow is bounded by its capacity: 0 ≤ f (e) ≤ c(e).

Flow conservation
For every vertex v ∈ V \ {s, t}, it holds that
X X
f (ein ) = f (eout )
ein ∈Ein (v ) eout ∈Eout (v )

We only consider integer capacities.

4/51
Flow of the network

3/3 12/12
a c 0/3 a c 15/
3/3 16
11/ 20

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


3/ 4/
2/5 8/1
5/5 3 4/4
b d b d
5/5 11/14

• Given that the flow network satisfies the capacity constraint and
flow conservation properties, the flow of the network is the total flow
out of the source vertex.

I Equivalently, this is the same as the total flow into sink vertex.

I What is the flow value in the left flow network? 5

I What is the flow value in the right flow network? 19

5/51
Maximum-flow problem

3/3 12/12
a c 0/3 a c 15/
3/3 16
11/ 20

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


3/ 4/
2/5 8/1
5/5 3 4/4
b d b d
5/5 11/14

Maximum-flow problem
Given a flow network, determine the maximum value of the flow that
can be sent from source s to sink t without violating the capacity
constraint and flow conservation properties.

6/51
Ford-Fulkerson method
Ford-Fulkerson method

Ford-Fulkerson is a method for solving max-flow problems.

Lester Ford Jr. Delbert Fulkerson

7/51
Ford-Fulkerson intuition

0/3
a c 0/
3
0/ 3

s t

3
0/
0/
5 0/5
b d
0/5

How can we increase the flow in the above network?

8/51
Quiz time!
Ford-Fulkerson intuition

0/3
a c 0/
3
0/ 3

s t

3
0/
0/
5 0/5
b d
0/5

How can we increase the flow in the above network?

1. Choose a path from source to sink.

2. Increase flow along it as much as possible.

Seems easy enough!

9/51
Ford-Fulkerson intuition

3/3
a c 0/
3
3/ 3

s t

3
3/
2/
5 5/5
b d
5/5

Can we increase the flow in the above network?

10/51
Quiz time!
Ford-Fulkerson intuition

3/3
a c 0/
3
3/ 3

s t

3
3/
2/
5 5/5
b d
5/5

Can we increase the flow in the above network?

We can! But there is no path from source to sink with spare capacity. . .

11/51
Ford-Fulkerson intuition

3/3
a c 3/
3
3/ 3

s t

3
0/
2/
5 5/5
b d
5/5

• There is no path from s to t with spare capacity.

• Redirect the 3 units on the edge c → b to go to edge c → t.

• Problem: The flow through b is not conserved anymore.

12/51
Ford-Fulkerson intuition

3/3
a c 3/
3
3/ 3

s t

3
0/
5/
5 5/5
b d
5/5

• There is no path from s to t with spare capacity.

• Redirect the 3 units on the edge c → b to go to edge c → t.

• Problem: The flow through b is not conserved anymore.

• Solution: Send 3 more units along s → b.

13/51
What actually happened here?

3/3
a c 3/
3
3/ 3

s t

3
0/
5/
5 5/5
b d
5/5

• We increased the total flow by 3.

• We sent 3 additional units along s → b, c → t.

• We removed 3 units of flow from c → b.

• Our path was s → b → c → t, but we had a backwards edge. . .

14/51
Residual network

Flow network Residual network


0
3/3
a c 1/ a c 2
3 0 3
3/ 3
3 2 1
s t s 2 t

3
1 4
2/ 2/ 5
5 4/ 3 4 1
b d b d
4/5
1

• Residual network has the same vertices as the original network.

• For every directed edge u → v in flow network, we add two edges in


the residual network:
I Forward edge/residual edge: an edge in the same direction as u → v with
the residual/remaining capacity in the flow network.
I Backward edge/reversible flow edge: an edge in the direction v → u with
weight equal to the current flow of u → v in the flow network.

15/51
Augmenting path

Flow network Residual network


3/3
a c 1/ a c 2
3 3
3/ 3
3 2 1
s t s 2 t

3
1 4
2/ 2/ 5
5 4/ 3 4 1
b d b d
4/5
1

• Augmenting path is any simple path (a path without repeating


vertices) from source s to target t along edges with positive weight
in the residual network.

I We can omit edges with weight 0 from the residual network.

• Residual capacity is the minimum edge weight in the residual along


this augmenting path (e.g., 2 in the example).

16/51
Ford-Fulkerson method

Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f

Flow of the network = 0


3
0/3
a c 0/ a c 3
3 3
0/ 3

s t s t
3

3
0/

0/ 5
5 0/ 5 5
b d b d
0/5
5

17/51
Ford-Fulkerson method

Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f

Flow of the network = 0 Path capacity = 3


3
0/3
a c 0/ a c 3
3 3
0/ 3

s t s t
3

3
0/

0/ 5
5 0/ 5 5
b d b d
0/5
5

18/51
Ford-Fulkerson method

Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f

Flow of the network = 3 Path capacity = 3


3
3/3
a c 0/ a c 3
3 3
3/ 3

s t s t
3

3
3/

0/ 5
5 3/ 5 5
b d b d
3/5
5

19/51
Ford-Fulkerson method

Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f

Flow of the network = 3 Residual needs to be updated!


3/3
a c 0/ a c 3
3 3
3/ 3
3 3
s t s t
3

3
3/

0/ 5
5 3/ 5 3 2
b d b d
3/5
2

20/51
Ford-Fulkerson method

Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f

Flow of the network = 3 Path capacity = 3


3/3
a c 0/ a c 3
3 3
3/ 3
3 3
s t s t
3

3
3/

0/ 5
5 3/ 5 3 2
b d b d
3/5
2

21/51
Ford-Fulkerson method

Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f

Flow of the network = 6 Path capacity = 3


3/3
a c 3/ a c 3
3 3
3/ 3
3 3
s t s t
3

3
0/

3/ 5
5 3/ 5 3 2
b d b d
3/5
2

22/51
Ford-Fulkerson method

Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f

Flow of the network = 6 Residual needs to be updated!


3/3
a c 3/ a c
3 3
3/ 3
3 3
s t s 3 t
3

3 3
0/

3/ 5
5 3/ 2 3 2
b d b d
3/5
2

23/51
Ford-Fulkerson method

Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f

Flow of the network = 6 Path capacity = 2


3/3
a c 3/ a c
3 3
3/ 3
3 3
s t s 3 t
3

3 3
0/

3/ 5
5 3/ 2 3 2
b d b d
3/5
2

24/51
Ford-Fulkerson method

Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f

Flow of the network = 8 Path capacity = 2


3/3
a c 3/ a c
3 3
3/ 3
3 3
s t s 3 t
3

3 3
0/

5/ 5
5 5/ 2 3 2
b d b d
5/5
2

25/51
Ford-Fulkerson method

Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f

Flow of the network = 8 Residual needs to be updated!


3/3
a c 3/ a c
3 3
3/ 3
3 3
s t s 5 t
3

3 5
0/

5/ 5
5 5/ 5
b d b d
5/5

26/51
Ford-Fulkerson method

Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f

Flow of the network = 8 No further augmenting paths!


3/3
a c 3/ a c
3 3
3/ 3
3 3
s t s 5 t
3

3 5
0/

5/ 5
5 5/ 5
b d b d
5/5

27/51
Implementation details

• Edge “type” in the residual does not matter as we can send flow
along any of them.

I Forward edges can have flow sent along them because they have spare
capacity.

I Backward edges can have flow sent along them because reducing a flow in
one direction is the same as increasing the flow in the opposite direction.

• If a pair of vertices in the flow network have edges in both directions,


then in the residual network there are only 2 edges (not 4).

28/51
Quiz time!
Implementation details

Flow network Residual network

x x

a/b c/d (b − a) + c (d − c) + a

y y

• The amount of flow we can send from x to y consists of:

I The spare capacity (b − a).

I The existing flow from y to x which can be reversed (c units).

29/51
Time complexity

Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f

• Cost of finding an augmenting path: O(|V | + |E |) using BFS/DFS.

• Augmenting flow along a path: length of path ≤ |V | − 1, so O(|V |).

• Updating the residual: two edges per edge of the augmenting path, so O(|V |).

• Total work in one iteration of the loop: O(|V | + |E |) = O(|E |) as the graph is
connected.

30/51
Time complexity

Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f

• Total work in one iteration of the loop: O(|E |).

• How many iterations?

31/51
Quiz time!
Time complexity

Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f

• Total work in one iteration of the loop: O(|E |).

• How many iterations?

I Assuming integer capacities, Ford-Fulkerson flows are always


integer-valued, so flow grows by at least 1 in each iteration.
I If maximum flow in the network is F , then at most F iterations.

• Total work: O(|E | · F ).

32/51
Time complexity

Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f

• Total work: O(|E | · F ).

I This looks polynomial.


I But it isn’t because F is a number, so its value is exponential in the space
required to store it.

• It can be proven that the complexity is O(|V | · |E |2 ) when using BFS to find
augmenting paths, which is polynomial.

I These two bounds are incomparable.

33/51
Correctness

Ford-Fulkerson method
1: function max flow(G = (V , E ), s, t)
2: set initial flow f to 0 on all edges
3: while there exists an augmenting path p in the residual network Gf do
4: augment the flow f along the augmenting path p as much as possible
5: return f

• Does the algorithm terminate?

I Yes, assuming all capacities are integers.


I The flow always increases by at least 1 per iteration and there cannot be
any augmenting path if all source’s outgoing edges (similarly, if all sink’s
incoming edges) are saturated.

• In order to show that the algorithm terminates exactly once it finds a flow whose
value is the maximum possible value among all feasible flows, we will need to
study the Min-cut Max-flow Theorem.

34/51
Min-cut Max-flow Theorem
Cut

12/12
6 a c 15/
1 1/1 20

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


4/
8/1
3 4/4
b d
11/14

• A cut (S,T ) of a flow network partitions the vertices into two


disjoint sets S and T such that s ∈ S and t ∈ T .

• The cut-set of a cut (S,T ) is the set of edges that “cross” the cut,
i.e., each edge connects one vertex in S with another in T .

I Outgoing edges of the cut: from a vertex in S to a vertex in T .

I Incoming edges of the cut: from a vertex in T to a vertex in S.

35/51
Flow and capacity of a cut

12/12
a c 15/
16
11/ 20

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


4/
8/1
3 4/4
b d
11/14

• Capacity of a cut (S,T ) is the total capacity of its outgoing edges.

• Flow of a cut (S,T ) is equal to total flow of outgoing edges − total


flow of incoming edges.

• Note that the flow of a cut is always ≤ to the capacity of the cut.
I Flow of an edge ≤ capacity of an edge.
I Capacity of a cut does not subtract capacities for incoming edges.

36/51
Flow and capacity of a cut

12/12
a c 15/
16
11/ 20

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


4/
8/1
3 4/4
b d
11/14

• Capacity of a cut (S,T ) is the total capacity of its outgoing edges.


I What is the capacity of this cut?
I 26

• Flow of a cut (S,T ) is equal to total flow of outgoing edges − total


flow of incoming edges.
I What is the flow of this cut?
I 19

37/51
Another cut

12/12
a c 15/
16
11/ 20

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


4/
8/1
3 4/4
b d
11/14

• Capacity of a cut (S,T ) is the total capacity of its outgoing edges.


I What is the capacity of this cut?
I 29

• Flow of a cut (S,T ) is equal to total flow of outgoing edges − total


flow of incoming edges.
I What is the flow of this cut?
I 19

38/51
Yet another cut

12/12
a c 15/
16
11/ 20

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


4/
8/1
3 4/4
b d
11/14

• Capacity of a cut (S,T ) is the total capacity of its outgoing edges.


I What is the capacity of this cut?
I 31

• Flow of a cut (S,T ) is equal to total flow of outgoing edges − total


flow of incoming edges.
I What is the flow of this cut?
I 19

39/51
Are the flows of every cut the same?

12/12
a c 15/
16
11/ 20

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


4/
8/1
3 4/4
b d
11/14

• It seems that the flow of every cut is the same, let’s prove this!

• Let Fout (v ) denote the total flow going out of vertex v and Fin (v )
denote the total flow coming into vertex v .

• Flow conservation property: Fout (v ) − Fin (v ) = 0 for every vertex


v ∈ V \ {s, t}.

• Flow of the network = Fout (s).


40/51
Flow of every cut is the same

12/12
a c 15/
16
11/ 20

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


4/
8/1
3 4/4
b d
11/14

X
Fout (s) = Fout (s) + (Fout (v ) − Fin (v ))
v ∈S\s
X
= (Fout (v ) − Fin (v ))
v ∈S
X
= (Fout (v ) + Fout (v ) − Fin (v ) − Fin (v ))
v ∈S

1st equation: by flow conservation, 2nd equation: as source has no incoming edges and
so Fin (s) = 0, 3rd equation: just separates the flow through red and green arrows.

41/51
Flow of every cut is the same

12/12
a c 15/
16
11/ 20

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


4/
8/1
3 4/4
b d
11/14

X
Fout (s) = (Fout (v ) + Fout (v ) − Fin (v ) − Fin (v ))
v ∈S
X X
= (Fout (v ) − Fin (v )) + (Fout (v ) − Fin (v ))
v ∈S v ∈S
X
= (Fout (v ) − Fin (v ))
v ∈S

The last equation follows from the fact that each red edge appears once as an incoming
edge and once as an outgoing edge.

42/51
Flow of every cut is the same

12/12
a c 15/
16
11/ 20

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


4/
8/1
3 4/4
b d
11/14

X
Fout (s) = (Fout (v ) − Fin (v ))
v ∈S

We conclude that the flow of any cut is equal to the flow of the network.

43/51
Min-cut

• Min-cut of a flow network is the cut with the minimum


capacity.

• Flow of the network = flow of any cut ≤ capacity of that cut.

• Maximum possible flow of the network ≤ capacity of min-cut.

• What if we can find a pair of flow and cut such that the flow of the
network = capacity of the cut?

I The flow value cannot be increased any further as it would violate the
capacity of that cut, so it is the maximum flow.
I The cut is a min-cut of the flow network.

44/51
Min-cut Max-flow Theorem

Min-cut Max-flow Theorem


Maximum possible flow of a network = capacity of the min-cut.

We will show that the Ford-Fulkerson method always terminates and


outputs a flow with value equal to the capacity of the min-cut.

45/51
Proof of correctness

Flow network Residual network


3/3
a c 3/ a c 1
4 1 3
3/ 4
3 3
s t s 5 t

3
3 5
5/
6 0/ 5/
6 1 5 1
b d b d
5/5

• Suppose the Ford-Fulkerson method has terminated (i.e., there does


not exist any augmenting path in the residual network).

• We define a cut (S,T ) such that:

I S contains every vertex v that is reachable from s in the residual network.

I T contains every other vertex. Note t cannot be in S because it is not


reachable from s (there is no further augmenting paths).

46/51
Proof of correctness

Flow network Residual network


3/3
a c 3/ a c 1
4 1 3
3/ 4
3 3
s t s 5 t

3
3 5
5/
6 0/ 5/
6 1 5 1
b d b d
5/5

• The flow of this cut equals to the capacity of this cut:

I For each outgoing edge, e.g., a → c, its flow is equal to the capacity of the
edge. Otherwise, edge a → c would be in the residual network and c would
be reachable from s (but we know this is not the case as c 6∈ S).

I For each incoming edge, e.g., c → b, its flow is zero. Otherwise, there
would be an edge b → c in the residual network implying c is reachable
from s (but we know this is not the case as c 6∈ S).

47/51
Min-cut max-flow connection used in practice

Original application: US Air Force wanted to identify targets for air


strikes to effectively cut off Soviet supply chains in Eastern Europe in
case of a conflict during the Cold War.

48/51
Min-cut max-flow connection used in practice

• Manage traffic flow and preventing bottlenecks on roads.

• Identifying parts that can lead to catastrophic failures in the power


grid.

• Businesses use it to analyse critical parts of their supply chain and


operational networks.

• Social networks use it to analyse and optimise flow of information.

• It can help identifying potential vulnerabilities in complex systems


and planning to increase their resilience.

49/51
Reading

• Course Notes: Chapter 9

• You can also check algorithms’ textbooks for contents related to this
lecture, e.g.:

I CLRS: Sections 26.1 and 26.2

I KT: Sections 7.1, 7.2 and 7.3

50/51
Concluding remarks

• Take home message: maximum flow of a network is equal to the


capacity of its min-cut and both can be found using Ford-Fulkerson.

• Things to do: make sure you understand Ford-Fulkerson


algorithm, why it is correct, and how to use it to find
max-flows and min-cuts.

• Coming up next: Circulation with demands, applications of network


flow to combinatorial problems.

51/51

You might also like