You are on page 1of 104

Teoria dos Grafos e Computabilidade

— Network Flow —
Silvio Jamil F. Guimarães
Graduate Program in Informatics – PPGINF
Image and Multimedia Data Science Laboratory – IMScience
Pontifical Catholic University of Minas Gerais – PUC Minas
Aug 2021
Teoria dos Grafos e Computabilidade
— Maximum Flow and Minimum Cut —
Silvio Jamil F. Guimarães
Graduate Program in Informatics – PPGINF
Image and Multimedia Data Science Laboratory – IMScience
Pontifical Catholic University of Minas Gerais – PUC Minas
Aug 2021
Maximum Flow and Minimum Cut

I Two rich algorithmic problems.


I Fundamental problems in combinatorial optimization.
I Beautiful mathematical duality between flows and cuts.
I Numerous non-trivial applications:
I Bipartite matching .
I Network reliability.
I Data mining.
I Distributed computing.
I Project selection.
I Egalitarian stable matching.
I Airline scheduling.
I Security of statistical data.
I Baseball elimination . I Network intrusion detection.
I Image segmentation . I Multi-camera scene
reconstruction.
I Network connectivity .
I Gene function prediction.
I Open-pit mining.
Silvio Jamil F. Guimarães Network Flow 3 de 32
Flow Networks

I Use directed graphs to model transportation networks :


I edges carry traffic and have capacities.
I nodes act as switches.
I source nodes generate traffic, sink nodes absorb traffic.

Silvio Jamil F. Guimarães Network Flow 4 de 32


Flow Networks

I Use directed graphs to model transportation networks :


I edges carry traffic and have capacities.
I nodes act as switches.
I source nodes generate traffic, sink nodes absorb traffic.

u I A flow network is a directed graph


G = (V , E )
20 10 I Each edge e ∈ E has a capacity
s 30 t c(e) > 0.

10 20

Silvio Jamil F. Guimarães Network Flow 4 de 32


Flow Networks

I Use directed graphs to model transportation networks :


I edges carry traffic and have capacities.
I nodes act as switches.
I source nodes generate traffic, sink nodes absorb traffic.

u I A flow network is a directed graph


G = (V , E )
20 10 I Each edge e ∈ E has a capacity
s 30 t c(e) > 0.
I There is a single source node s ∈ V .
10 20 I There is a single sink node t ∈ V .
v I Nodes other than s and t are internal .

Silvio Jamil F. Guimarães Network Flow 4 de 32


Defining Flow

I In a flow network G = (V , E ), an s-t flow is a function


f : E → R+ such that
(i) Capacity conditions For each e ∈ E , 0 ≤ f (e) ≤ c(e).
(ii) Conservation conditions For each internal node v ,
X X
f (e) = f (e)
e into v e out of v

P
I The value of a flow is ν(f ) = e out of s f (e).

Silvio Jamil F. Guimarães Network Flow 5 de 32


Defining Flow

I In a flow network G = (V , E ), an s-t flow is a function


f : E → R+ such that
(i) Capacity conditions For each e ∈ E , 0 ≤ f (e) ≤ c(e).
(ii) Conservation conditions For each internal node v ,
X X
f (e) = f (e)
e into v e out of v

P
I The value of a flow is ν(f ) = e out of s f (e).
I Useful notation:
f out (v ) = e out of v f (e) f in (v ) =
P P
e into v f (e)
For S ⊆ V P ,
f out (S) = e out of S f (e) f in (S) =
P
e into S f (e)

Silvio Jamil F. Guimarães Network Flow 5 de 32


Maximum-Flow Problem

Maximum Flow

INSTANCE A flow network G

SOLUTION The flow with largest value in G

u I Assumptions :
20 10
1. No edges enter s, no edges leave t.
s 30 t

10 20

Silvio Jamil F. Guimarães Network Flow 6 de 32


Maximum-Flow Problem

Maximum Flow

INSTANCE A flow network G

SOLUTION The flow with largest value in G

u I Assumptions :
20 10
1. No edges enter s, no edges leave t.
s 30 t 2. There is at least one edge incident
on each node.
10 20

Silvio Jamil F. Guimarães Network Flow 6 de 32


Maximum-Flow Problem

Maximum Flow

INSTANCE A flow network G

SOLUTION The flow with largest value in G

u I Assumptions :
20/20 10/10
1. No edges enter s, no edges leave t.
s 10/30 t 2. There is at least one edge incident
on each node.
10/10 20/20
3. All edge capacities are integers .
v

Silvio Jamil F. Guimarães Network Flow 6 de 32


Questions

Questions?
Network Flow
– Maximum Flow and Minimum
Cut –

Silvio Jamil F. Guimarães Network Flow 7 de 32


Teoria dos Grafos e Computabilidade
— Ford-Fulkerson Algorithm —
Silvio Jamil F. Guimarães
Graduate Program in Informatics – PPGINF
Image and Multimedia Data Science Laboratory – IMScience
Pontifical Catholic University of Minas Gerais – PUC Minas
Aug 2021
Developing the Algorithm

I A flow network is a directed graph G = (V , E )

20 10

s 30 t

10 20

Silvio Jamil F. Guimarães Network Flow 9 de 32


Developing the Algorithm

I A flow network is a directed graph G = (V , E )


I Let us take a greedy approach.
1. Start with zero flow along all edges.

0/20 0/10

s 0/30 t

0/10 0/20

Silvio Jamil F. Guimarães Network Flow 9 de 32


Developing the Algorithm

I A flow network is a directed graph G = (V , E )


I Let us take a greedy approach.
1. Start with zero flow along all edges.
2. Find an s-t path and push as much flow along it as possible.

u u

20 10 20 10

s 30 t s 30 t

10 20 10 20

v v

Silvio Jamil F. Guimarães Network Flow 9 de 32


Developing the Algorithm

I A flow network is a directed graph G = (V , E )


I Let us take a greedy approach.
1. Start with zero flow along all edges.
2. Find an s-t path and push as much flow along it as possible.
3. Key idea : Push flow along edges with leftover capacity and
undo flow on edges already carrying flow.

u u u

20 10 20 10 20 10

s 30 t s 30 t s 30 10 t

10 20 10 20 10 20

v v v

Silvio Jamil F. Guimarães Network Flow 9 de 32


Residual Graph

I Given a flow network G = (V , E ) and a flow f on G , the residual


graph Gf of G with respect to f is a directed graph such that
(i) Nodes – Gf has the same nodes as G .

20 10

s 30 t

10 20

Silvio Jamil F. Guimarães Network Flow 10 de 32


Residual Graph

I Given a flow network G = (V , E ) and a flow f on G , the residual


graph Gf of G with respect to f is a directed graph such that
(i) Nodes – Gf has the same nodes as G .

0/20 0/10

s 0/30 t

0/10 0/20

Silvio Jamil F. Guimarães Network Flow 10 de 32


Residual Graph

I Given a flow network G = (V , E ) and a flow f on G , the residual


graph Gf of G with respect to f is a directed graph such that
(i) Nodes – Gf has the same nodes as G .
(ii) Forward edges – For each edge e = (u, v ) ∈ E such that
f (e) < c(e), Gf contains the edge (u, v ) with a residual capacity
c(e) − f (e).
(iii) Backward edges – For each edge e ∈ E such that f (e) > 0, Gf
contains the edge e 0 = (v , u) with a residual capacity f (e).

u u f /c v

0/20 0/10

s 0/30 t

0/10 0/20
c −f
u v
v f

Silvio Jamil F. Guimarães Network Flow 10 de 32


Residual Graph

I Given a flow network G = (V , E ) and a flow f on G , the residual


graph Gf of G with respect to f is a directed graph such that
(i) Nodes – Gf has the same nodes as G .
(ii) Forward edges – For each edge e = (u, v ) ∈ E such that
f (e) < c(e), Gf contains the edge (u, v ) with a residual capacity
c(e) − f (e).
(iii) Backward edges – For each edge e ∈ E such that f (e) > 0, Gf
contains the edge e 0 = (v , u) with a residual capacity f (e).

u u f /c v u

0/20 0/10 20 10
0 0

s 0/30 t s 0 30 t

0/10 0/20 10 20
c −f 0 0
u v
v f v

Silvio Jamil F. Guimarães Network Flow 10 de 32


Augmenting Paths in a Residual Graph

I Let P be a simple s-t path in Gf .


I bottleneck(P, f ) is the minimum residual capacity of any edge in P.
I The following operation augment(f , P) yields a new flow f 0 in G :

Algorithm: Augmented path


input : A graph G = (V , E ), a path P and a
source s and a sink t nodes.
u
output: The distances of the vertices from s
0/20 0/10 1 Let b = bottleneck(P, f ) ;
2 foreach edge e = (u, v ) ∈ P do
s 0/30 t 3 if e is a forward edge then
4 increase f (e) in G by b
0/10 0/20
5 else if e is a backward edge then
6 decrease f (e) in G by b;
v
7 end
8

Silvio Jamil F. Guimarães Network Flow 11 de 32


Augmenting Paths in a Residual Graph

I Let P be a simple s-t path in Gf .


I bottleneck(P, f ) is the minimum residual capacity of any edge in P.
I The following operation augment(f , P) yields a new flow f 0 in G :

Algorithm: Augmented path


input : A graph G = (V , E ), a path P and a
source s and a sink t nodes.
u
output: The distances of the vertices from s
20 10 1 Let b = bottleneck(P, f ) ;
0 0
2 foreach edge e = (u, v ) ∈ P do
s 0 30 t 3 if e is a forward edge then
10 20 4 increase f (e) in G by b
0 0 5 else if e is a backward edge then
6 decrease f (e) in G by b;
v
7 end
8

Silvio Jamil F. Guimarães Network Flow 11 de 32


Augmenting Paths in a Residual Graph

I Let P be a simple s-t path in Gf .


I bottleneck(P, f ) is the minimum residual capacity of any edge in P.
I The following operation augment(f , P) yields a new flow f 0 in G :

Algorithm: Augmented path


input : A graph G = (V , E ), a path P and a
source s and a sink t nodes.
u
output: The distances of the vertices from s
20 10 1 Let b = bottleneck(P, f ) ;
0 0
2 foreach edge e = (u, v ) ∈ P do
s 0 30 t 3 if e is a forward edge then
10 20 4 increase f (e) in G by b
0 0 5 else if e is a backward edge then
6 decrease f (e) in G by b;
v
7 end
8

Silvio Jamil F. Guimarães Network Flow 11 de 32


Augmenting Paths in a Residual Graph

I Let P be a simple s-t path in Gf .


I bottleneck(P, f ) is the minimum residual capacity of any edge in P.
I The following operation augment(f , P) yields a new flow f 0 in G :

Algorithm: Augmented path


input : A graph G = (V , E ), a path P and a
source s and a sink t nodes.
u
output: The distances of the vertices from s
20/20 0/10 1 Let b = bottleneck(P, f ) ;
2 foreach edge e = (u, v ) ∈ P do
s 20/30 t 3 if e is a forward edge then
4 increase f (e) in G by b
0/10 20/20
5 else if e is a backward edge then
6 decrease f (e) in G by b;
v
7 end
8

Silvio Jamil F. Guimarães Network Flow 11 de 32


Augmenting Paths in a Residual Graph

I Let P be a simple s-t path in Gf .


I bottleneck(P, f ) is the minimum residual capacity of any edge in P.
I The following operation augment(f , P) yields a new flow f 0 in G :

Algorithm: Augmented path


input : A graph G = (V , E ), a path P and a
source s and a sink t nodes.
u
output: The distances of the vertices from s
0 10 1 Let b = bottleneck(P, f ) ;
20 0
2 foreach edge e = (u, v ) ∈ P do
s 20 10 t 3 if e is a forward edge then
10 0 4 increase f (e) in G by b
0 20 5 else if e is a backward edge then
6 decrease f (e) in G by b;
v
7 end
8

Silvio Jamil F. Guimarães Network Flow 11 de 32


Augmenting Paths in a Residual Graph

I Let P be a simple s-t path in Gf .


I bottleneck(P, f ) is the minimum residual capacity of any edge in P.
I The following operation augment(f , P) yields a new flow f 0 in G :

Algorithm: Augmented path


input : A graph G = (V , E ), a path P and a
source s and a sink t nodes.
u
output: The distances of the vertices from s
0 0 1 Let b = bottleneck(P, f ) ;
20 10
2 foreach edge e = (u, v ) ∈ P do
s 10 20 t 3 if e is a forward edge then
0 0 4 increase f (e) in G by b
10 20 5 else if e is a backward edge then
6 decrease f (e) in G by b;
v
7 end
8

Silvio Jamil F. Guimarães Network Flow 11 de 32


Correctness of augment(f , P)

I A simple s-t path in the residual graph is an


augmenting path .
I Let f 0 be the flow returned by augment(f , P).
I Claim: f 0 is a flow. Verify capacity and conservation
conditions.

Silvio Jamil F. Guimarães Network Flow 12 de 32


Correctness of augment(f , P)

I A simple s-t path in the residual graph is an


augmenting path .
I Let f 0 be the flow returned by augment(f , P).
I Claim: f 0 is a flow. Verify capacity and conservation
conditions.
I Only need to check edges and internal nodes in P.

Silvio Jamil F. Guimarães Network Flow 12 de 32


Correctness of augment(f , P)

I A simple s-t path in the residual graph is an


augmenting path .
I Let f 0 be the flow returned by augment(f , P).
I Claim: f 0 is a flow. Verify capacity and conservation
conditions.
I Only need to check edges and internal nodes in P.
I Capacity condition on e = (u, v ) ∈ Gf : Note that
bottleneck(P, f ) ≤ residual capacity of (u, v ).

Silvio Jamil F. Guimarães Network Flow 12 de 32


Correctness of augment(f , P)

I A simple s-t path in the residual graph is an


augmenting path .
I Let f 0 be the flow returned by augment(f , P).
I Claim: f 0 is a flow. Verify capacity and conservation
conditions.
I Only need to check edges and internal nodes in P.
I Capacity condition on e = (u, v ) ∈ Gf : Note that
bottleneck(P, f ) ≤ residual capacity of (u, v ).
I e is a forward edge: 0 ≤ f (e) ≤ f 0 (e) =
f (e) + bottleneck(P, f ) ≤ f (e) + (c(e) − f (e)) = c(e).

Silvio Jamil F. Guimarães Network Flow 12 de 32


Correctness of augment(f , P)

I A simple s-t path in the residual graph is an


augmenting path .
I Let f 0 be the flow returned by augment(f , P).
I Claim: f 0 is a flow. Verify capacity and conservation
conditions.
I Only need to check edges and internal nodes in P.
I Capacity condition on e = (u, v ) ∈ Gf : Note that
bottleneck(P, f ) ≤ residual capacity of (u, v ).
I e is a forward edge: 0 ≤ f (e) ≤ f 0 (e) =
f (e) + bottleneck(P, f ) ≤ f (e) + (c(e) − f (e)) = c(e).
I e is a backward edge: c(e) ≥ f (e) ≥ f 0 (e) =
f (e) − bottleneck(P, f ) ≥ f (e) − f (e) = 0.

Silvio Jamil F. Guimarães Network Flow 12 de 32


Correctness of augment(f , P)

I A simple s-t path in the residual graph is an


augmenting path .
I Let f 0 be the flow returned by augment(f , P).
I Claim: f 0 is a flow. Verify capacity and conservation
conditions.
I Only need to check edges and internal nodes in P.
I Capacity condition on e = (u, v ) ∈ Gf : Note that
bottleneck(P, f ) ≤ residual capacity of (u, v ).
I e is a forward edge: 0 ≤ f (e) ≤ f 0 (e) =
f (e) + bottleneck(P, f ) ≤ f (e) + (c(e) − f (e)) = c(e).
I e is a backward edge: c(e) ≥ f (e) ≥ f 0 (e) =
f (e) − bottleneck(P, f ) ≥ f (e) − f (e) = 0.
I Conservation condition on internal node v ∈ P.

Silvio Jamil F. Guimarães Network Flow 12 de 32


Correctness of augment(f , P)

I A simple s-t path in the residual graph is an


augmenting path .
I Let f 0 be the flow returned by augment(f , P).
I Claim: f 0 is a flow. Verify capacity and conservation
conditions.
I Only need to check edges and internal nodes in P.
I Capacity condition on e = (u, v ) ∈ Gf : Note that
bottleneck(P, f ) ≤ residual capacity of (u, v ).
I e is a forward edge: 0 ≤ f (e) ≤ f 0 (e) =
f (e) + bottleneck(P, f ) ≤ f (e) + (c(e) − f (e)) = c(e).
I e is a backward edge: c(e) ≥ f (e) ≥ f 0 (e) =
f (e) − bottleneck(P, f ) ≥ f (e) − f (e) = 0.
I Conservation condition on internal node v ∈ P. Four
cases to work out.
Silvio Jamil F. Guimarães Network Flow 12 de 32
Ford-Fulkerson Algorithm
Algorithm: Ford-Fulkerson Algorithm
input : A graph G = (V , E ), a source s and a sink t
nodes.
output: The flow f
1 f (e) = 0, ∀e ∈ E ;
2 while there is a path s-t in the residual graph Gf do
3 Let P be a simple s-t path in Gf ;
4 f 0 = augment(f , P);
5 Update f to be f 0 ;
6 Update the residual graph Gf to be Gf 0 ;
7 end
8 return f ;

20 10

s 30 t

10 20

Silvio Jamil F. Guimarães Network Flow 13 de 32


Ford-Fulkerson Algorithm
Algorithm: Ford-Fulkerson Algorithm
input : A graph G = (V , E ), a source s and a sink t
nodes.
output: The flow f
1 f (e) = 0, ∀e ∈ E ;
2 while there is a path s-t in the residual graph Gf do
3 Let P be a simple s-t path in Gf ;
4 f 0 = augment(f , P);
5 Update f to be f 0 ;
6 Update the residual graph Gf to be Gf 0 ;
7 end
8 return f ;

u u

20 10 0/20 0/10

s 30 t s 0/30 t

10 20 0/10 0/20

v v

Silvio Jamil F. Guimarães Network Flow 13 de 32


Ford-Fulkerson Algorithm
Algorithm: Ford-Fulkerson Algorithm
input : A graph G = (V , E ), a source s and a sink t
nodes.
output: The flow f
1 f (e) = 0, ∀e ∈ E ;
2 while there is a path s-t in the residual graph Gf do
3 Let P be a simple s-t path in Gf ;
4 f 0 = augment(f , P);
5 Update f to be f 0 ;
6 Update the residual graph Gf to be Gf 0 ;
7 end
8 return f ;

u u u

20 10 0/20 0/10 20 10
0 0

s 30 t s 0/30 t s 0 30 t

10 20 0/10 0/20 10 20
0 0

v v v

Silvio Jamil F. Guimarães Network Flow 13 de 32


Ford-Fulkerson Algorithm
Algorithm: Ford-Fulkerson Algorithm
input : A graph G = (V , E ), a source s and a sink t
nodes.
output: The flow f
1 f (e) = 0, ∀e ∈ E ;
2 while there is a path s-t in the residual graph Gf do
3 Let P be a simple s-t path in Gf ;
4 f 0 = augment(f , P);
5 Update f to be f 0 ;
6 Update the residual graph Gf to be Gf 0 ;
7 end
8 return f ;

u u u u

20 10 0/20 0/10 20 10 20 10
0 0 0 0

s 30 t s 0/30 t s 0 30 t s 0 30 t

10 20 0/10 0/20 10 20 10 20
0 0 0 0

v v v v

Silvio Jamil F. Guimarães Network Flow 13 de 32


Ford-Fulkerson Algorithm
Algorithm: Ford-Fulkerson Algorithm
input : A graph G = (V , E ), a source s and a sink t
nodes.
output: The flow f
1 f (e) = 0, ∀e ∈ E ;
2 while there is a path s-t in the residual graph Gf do
3 Let P be a simple s-t path in Gf ;
4 f 0 = augment(f , P);
5 Update f to be f 0 ;
6 Update the residual graph Gf to be Gf 0 ;
7 end
8 return f ;

u u

20 10 20/20 0/10

s 30 t s 20/30 t

10 20 0/10 20/20

v v

Silvio Jamil F. Guimarães Network Flow 13 de 32


Ford-Fulkerson Algorithm
Algorithm: Ford-Fulkerson Algorithm
input : A graph G = (V , E ), a source s and a sink t
nodes.
output: The flow f
1 f (e) = 0, ∀e ∈ E ;
2 while there is a path s-t in the residual graph Gf do
3 Let P be a simple s-t path in Gf ;
4 f 0 = augment(f , P);
5 Update f to be f 0 ;
6 Update the residual graph Gf to be Gf 0 ;
7 end
8 return f ;

u u u

20 10 20/20 0/10 0 10
20 0

s 30 t s 20/30 t s 20 10 t

10 20 0/10 20/20 10 0
0 20

v v v

Silvio Jamil F. Guimarães Network Flow 13 de 32


Ford-Fulkerson Algorithm
Algorithm: Ford-Fulkerson Algorithm
input : A graph G = (V , E ), a source s and a sink t
nodes.
output: The flow f
1 f (e) = 0, ∀e ∈ E ;
2 while there is a path s-t in the residual graph Gf do
3 Let P be a simple s-t path in Gf ;
4 f 0 = augment(f , P);
5 Update f to be f 0 ;
6 Update the residual graph Gf to be Gf 0 ;
7 end
8 return f ;

u u u u

20 10 20/20 0/10 0 10 0 10
20 0 20 0

s 30 t s 20/30 t s 20 10 t s 20 10 t

10 20 0/10 20/20 10 0 10 0
0 20 0 20

v v v v

Silvio Jamil F. Guimarães Network Flow 13 de 32


Ford-Fulkerson Algorithm
Algorithm: Ford-Fulkerson Algorithm
input : A graph G = (V , E ), a source s and a sink t
nodes.
output: The flow f
1 f (e) = 0, ∀e ∈ E ;
2 while there is a path s-t in the residual graph Gf do
3 Let P be a simple s-t path in Gf ;
4 f 0 = augment(f , P);
5 Update f to be f 0 ;
6 Update the residual graph Gf to be Gf 0 ;
7 end
8 return f ;

u u

20 10 20/20 10/10

s 30 t s 10/30 t

10 20 10/10 20/20

v v

Silvio Jamil F. Guimarães Network Flow 13 de 32


Ford-Fulkerson Algorithm
Algorithm: Ford-Fulkerson Algorithm
input : A graph G = (V , E ), a source s and a sink t
nodes.
output: The flow f
1 f (e) = 0, ∀e ∈ E ;
2 while there is a path s-t in the residual graph Gf do
3 Let P be a simple s-t path in Gf ;
4 f 0 = augment(f , P);
5 Update f to be f 0 ;
6 Update the residual graph Gf to be Gf 0 ;
7 end
8 return f ;

u u u

20 10 20/20 10/10 0 0
20 10

s 30 t s 10/30 t s 10 20 t

10 20 10/10 20/20 0 0
10 20

v v v

Silvio Jamil F. Guimarães Network Flow 13 de 32


Termination of the Ford-Fulkerson Algorithm

I Claim: at each stage, flow values and residual


capacities are integers.

Silvio Jamil F. Guimarães Network Flow 14 de 32


Termination of the Ford-Fulkerson Algorithm

I Claim: at each stage, flow values and residual


capacities are integers. Prove by induction .

Silvio Jamil F. Guimarães Network Flow 14 de 32


Termination of the Ford-Fulkerson Algorithm

I Claim: at each stage, flow values and residual


capacities are integers. Prove by induction .
I Claim: Flow value strictly increases when we apply
augment(f , P).

Silvio Jamil F. Guimarães Network Flow 14 de 32


Termination of the Ford-Fulkerson Algorithm

I Claim: at each stage, flow values and residual


capacities are integers. Prove by induction .
I Claim: Flow value strictly increases when we apply
augment(f , P).
v (f 0 ) = v (f ) + bottleneck(P, f ) > v (f ).

Silvio Jamil F. Guimarães Network Flow 14 de 32


Termination of the Ford-Fulkerson Algorithm

I Claim: at each stage, flow values and residual


capacities are integers. Prove by induction .
I Claim: Flow value strictly increases when we apply
augment(f , P).
v (f 0 ) = v (f ) + bottleneck(P, f ) > v (f ).
I Claim:PMaximum value of any flow is
C = e out of s c(e).

Silvio Jamil F. Guimarães Network Flow 14 de 32


Correctness of the Ford-Fulkerson Algorithm

I How large can the flow be?

Silvio Jamil F. Guimarães Network Flow 15 de 32


Correctness of the Ford-Fulkerson Algorithm

I How large can the flow be?


I Can we characterise the magnitude of the flow in
terms of the structure of the
Pgraph? For example, for
every flow f , ν(f ) ≤ C = eout of s c(e).
I Is there a better bound?

Silvio Jamil F. Guimarães Network Flow 15 de 32


Correctness of the Ford-Fulkerson Algorithm

I How large can the flow be?


I Can we characterise the magnitude of the flow in
terms of the structure of the
Pgraph? For example, for
every flow f , ν(f ) ≤ C = eout of s c(e).
I Is there a better bound?
I Idea: An s-t cut is a partition of V into sets A and
B such that s ∈ A and t ∈ B. P
I Capacity of the cut (A, B) is c(A, B) = e out of A c(e).
I Intuition: For every flow f , ν(f ) ≤ c(A, B).

Silvio Jamil F. Guimarães Network Flow 15 de 32


Fun Facts about Cuts

I Let f be any s-t flow and (A, B) any s-t cut.

Silvio Jamil F. Guimarães Network Flow 16 de 32


Fun Facts about Cuts

I Let f be any s-t flow and (A, B) any s-t cut.


I Claim: ν(f ) = f out (A) − f in (A).

Silvio Jamil F. Guimarães Network Flow 16 de 32


Fun Facts about Cuts

I Let f be any s-t flow and (A, B) any s-t cut.


I Claim: ν(f ) = f out (A) − f in (A).
I ν(f ) = f out (s) and f in (s) = 0 ⇒ ν(f ) = f out (s) − f in (s).

Silvio Jamil F. Guimarães Network Flow 16 de 32


Fun Facts about Cuts

I Let f be any s-t flow and (A, B) any s-t cut.


I Claim: ν(f ) = f out (A) − f in (A).
I ν(f ) = f out (s) and f in (s) = 0 ⇒ ν(f ) = f out (s) − f in (s).
I For every other node v ∈ A, f out (v ) − f in (v ) = 0.

Silvio Jamil F. Guimarães Network Flow 16 de 32


Fun Facts about Cuts

I Let f be any s-t flow and (A, B) any s-t cut.


I Claim: ν(f ) = f out (A) − f in (A).
I ν(f ) = f out (s) and f in (s) = 0 ⇒ ν(f ) = f out (s) − f in (s).
I For every
Pother node v ∈ A, f out in
 (v ) − f (v ) = 0.
out in
I ν(f ) = v ∈A f (v ) − f (v ) .

Silvio Jamil F. Guimarães Network Flow 16 de 32


Fun Facts about Cuts

I Let f be any s-t flow and (A, B) any s-t cut.


I Claim: ν(f ) = f out (A) − f in (A).
I ν(f ) = f out (s) and f in (s) = 0 ⇒ ν(f ) = f out (s) − f in (s).
I For every
Pother node v ∈ A, f out in
 (v ) − f (v ) = 0.
out in
I ν(f ) = v ∈A f (v ) − f (v ) .
I An edge e that has both ends in A or both ends out of A does not
contribute.
I An edge e that has its tail in A contributes f (e).
I An edge e that has its head in A contributes −f (e).

Silvio Jamil F. Guimarães Network Flow 16 de 32


Fun Facts about Cuts

I Let f be any s-t flow and (A, B) any s-t cut.


I Claim: ν(f ) = f out (A) − f in (A).
I ν(f ) = f out (s) and f in (s) = 0 ⇒ ν(f ) = f out (s) − f in (s).
I For every
Pother node v ∈ A, f out in
 (v ) − f (v ) = 0.
out in
I ν(f ) = v ∈A f (v ) − f (v ) .
I An edge e that has both ends in A or both ends out of A does not
contribute.
I An edge e that has its tail in A contributes f (e).
I An edge e that has its head
P in A contributesP −f (e).
f out (v ) − f in (v ) =
P
I
v ∈A e out of A f (e) − e into A f (e) =
out
f (A) − f in (A).

Silvio Jamil F. Guimarães Network Flow 16 de 32


Fun Facts about Cuts

I Let f be any s-t flow and (A, B) any s-t cut.


I Claim: ν(f ) = f out (A) − f in (A).
I ν(f ) = f out (s) and f in (s) = 0 ⇒ ν(f ) = f out (s) − f in (s).
I For every
Pother node v ∈ A, f out in
 (v ) − f (v ) = 0.
out in
I ν(f ) = v ∈A f (v ) − f (v ) .
I An edge e that has both ends in A or both ends out of A does not
contribute.
I An edge e that has its tail in A contributes f (e).
I An edge e that has its head
P in A contributesP −f (e).
f out (v ) − f in (v ) =
P
I
v ∈A e out of A f (e) − e into A f (e) =
out
f (A) − f in (A).
I Corollary: ν(f ) = f in (B) − f out (B).

Silvio Jamil F. Guimarães Network Flow 16 de 32


Fun Facts about Cuts

I Let f be any s-t flow and (A, B) any s-t cut.


I Claim: ν(f ) = f out (A) − f in (A).
I ν(f ) = f out (s) and f in (s) = 0 ⇒ ν(f ) = f out (s) − f in (s).
I For every
Pother node v ∈ A, f out in
 (v ) − f (v ) = 0.
out in
I ν(f ) = v ∈A f (v ) − f (v ) .
I An edge e that has both ends in A or both ends out of A does not
contribute.
I An edge e that has its tail in A contributes f (e).
I An edge e that has its head
P in A contributesP −f (e).
f out (v ) − f in (v ) =
P
I
v ∈A e out of A f (e) − e into A f (e) =
out
f (A) − f in (A).
I Corollary: ν(f ) = f in (B) − f out (B).
I ν(f ) ≤ c(A, B) .

Silvio Jamil F. Guimarães Network Flow 16 de 32


Fun Facts about Cuts

I Let f be any s-t flow and (A, B) any s-t cut.


I Claim: ν(f ) = f out (A) − f in (A).
I ν(f ) = f out (s) and f in (s) = 0 ⇒ ν(f ) = f out (s) − f in (s).
I For every
Pother node v ∈ A, f out in
 (v ) − f (v ) = 0.
out in
I ν(f ) = v ∈A f (v ) − f (v ) .
I An edge e that has both ends in A or both ends out of A does not
contribute.
I An edge e that has its tail in A contributes f (e).
I An edge e that has its head
P in A contributesP −f (e).
f out (v ) − f in (v ) =
P
I
v ∈A e out of A f (e) − e into A f (e) =
out
f (A) − f in (A).
I Corollary: ν(f ) = f in (B) − f out (B).
I ν(f ) ≤ c(A, B) .
X
ν(f ) = f out (A) − f in (A) ≤ f out (A) = f (e)
e out of A
X
≤ c(e) = c(A, B).
e out of A
Silvio Jamil F. Guimarães Network Flow 16 de 32
Max-Flows and Min-Cuts

I Let f be any s-t flow and (A, B) any s-t cut. We


proved ν(f ) ≤ c(A, B).

Silvio Jamil F. Guimarães Network Flow 17 de 32


Max-Flows and Min-Cuts

I Let f be any s-t flow and (A, B) any s-t cut. We


proved ν(f ) ≤ c(A, B).
I Very strong statement: The value of every flow is ≤
capacity of any cut.

Silvio Jamil F. Guimarães Network Flow 17 de 32


Max-Flows and Min-Cuts

I Let f be any s-t flow and (A, B) any s-t cut. We


proved ν(f ) ≤ c(A, B).
I Very strong statement: The value of every flow is ≤
capacity of any cut.
I Corollary: The maximum flow is, at most, the
smallest capacity of a cut.

Silvio Jamil F. Guimarães Network Flow 17 de 32


Max-Flows and Min-Cuts

I Let f be any s-t flow and (A, B) any s-t cut. We


proved ν(f ) ≤ c(A, B).
I Very strong statement: The value of every flow is ≤
capacity of any cut.
I Corollary: The maximum flow is, at most, the
smallest capacity of a cut.
I Question: Is the reverse true? Is the smallest
capacity of a cut at most the maximum flow?

Silvio Jamil F. Guimarães Network Flow 17 de 32


Max-Flows and Min-Cuts

I Let f be any s-t flow and (A, B) any s-t cut. We


proved ν(f ) ≤ c(A, B).
I Very strong statement: The value of every flow is ≤
capacity of any cut.
I Corollary: The maximum flow is, at most, the
smallest capacity of a cut.
I Question: Is the reverse true? Is the smallest
capacity of a cut at most the maximum flow?
I Answer: Yes, and the Ford-Fulkerson algorithm
computes this cut !

Silvio Jamil F. Guimarães Network Flow 17 de 32


Flows and Cuts

I Let f¯ denote the flow computed by the


Ford-Fulkerson algorithm .
I Enough to show ∃ s-t cut (A∗ , B ∗ ) such that
ν(f¯) = c(A∗ , B ∗ ).
I When the algorithm terminates, the residual graph
has no s-t path .

Silvio Jamil F. Guimarães Network Flow 18 de 32


Flows and Cuts

I Let f¯ denote the flow computed by the


Ford-Fulkerson algorithm .
I Enough to show ∃ s-t cut (A∗ , B ∗ ) such that
ν(f¯) = c(A∗ , B ∗ ).
I When the algorithm terminates, the residual graph
has no s-t path .
I Claim: If f is an s-t flow such that Gf has no s-t
path, then there is an s-t cut (A∗ , B ∗ ) such that
ν(f ) = c(A∗ , B ∗ ).
I Claim applies to any flow f such that Gf has no s-t path,
and not just to the flow f¯ computed by the
Ford-Fulkerson algorithm.
Silvio Jamil F. Guimarães Network Flow 18 de 32
Proof of Claim Relating Flows to Cuts

I Claim: f is an s-t flow and Gf has no s-t path ⇒ ∃


s-t cut (A∗ , B ∗ ), ν(f ) = c(A∗ , B ∗ ).
I A∗ = set of nodes reachable from s in Gf ,
B ∗ = V − A∗ .

Silvio Jamil F. Guimarães Network Flow 19 de 32


Proof of Claim Relating Flows to Cuts

I Claim: f is an s-t flow and Gf has no s-t path ⇒ ∃


s-t cut (A∗ , B ∗ ), ν(f ) = c(A∗ , B ∗ ).
I A∗ = set of nodes reachable from s in Gf ,
B ∗ = V − A∗ .
I Claim: (A∗ , B ∗ ) is an s-t cut.

Silvio Jamil F. Guimarães Network Flow 19 de 32


Proof of Claim Relating Flows to Cuts

I Claim: f is an s-t flow and Gf has no s-t path ⇒ ∃


s-t cut (A∗ , B ∗ ), ν(f ) = c(A∗ , B ∗ ).
I A∗ = set of nodes reachable from s in Gf ,
B ∗ = V − A∗ .
I Claim: (A∗ , B ∗ ) is an s-t cut.
I Claim: If e = (u, v ) such that u ∈ A∗ , v ∈ B ∗ , then
.

Silvio Jamil F. Guimarães Network Flow 19 de 32


Proof of Claim Relating Flows to Cuts

I Claim: f is an s-t flow and Gf has no s-t path ⇒ ∃


s-t cut (A∗ , B ∗ ), ν(f ) = c(A∗ , B ∗ ).
I A∗ = set of nodes reachable from s in Gf ,
B ∗ = V − A∗ .
I Claim: (A∗ , B ∗ ) is an s-t cut.
I Claim: If e = (u, v ) such that u ∈ A∗ , v ∈ B ∗ , then
f (e) = c(e).

Silvio Jamil F. Guimarães Network Flow 19 de 32


Proof of Claim Relating Flows to Cuts

I Claim: f is an s-t flow and Gf has no s-t path ⇒ ∃


s-t cut (A∗ , B ∗ ), ν(f ) = c(A∗ , B ∗ ).
I A∗ = set of nodes reachable from s in Gf ,
B ∗ = V − A∗ .
I Claim: (A∗ , B ∗ ) is an s-t cut.
I Claim: If e = (u, v ) such that u ∈ A∗ , v ∈ B ∗ , then
f (e) = c(e).
I Claim: If e 0 = (u 0 , v 0 ) such that u 0 ∈ B ∗ , v 0 ∈ A∗ ,
then .

Silvio Jamil F. Guimarães Network Flow 19 de 32


Proof of Claim Relating Flows to Cuts

I Claim: f is an s-t flow and Gf has no s-t path ⇒ ∃


s-t cut (A∗ , B ∗ ), ν(f ) = c(A∗ , B ∗ ).
I A∗ = set of nodes reachable from s in Gf ,
B ∗ = V − A∗ .
I Claim: (A∗ , B ∗ ) is an s-t cut.
I Claim: If e = (u, v ) such that u ∈ A∗ , v ∈ B ∗ , then
f (e) = c(e).
I Claim: If e 0 = (u 0 , v 0 ) such that u 0 ∈ B ∗ , v 0 ∈ A∗ ,
then f (e 0 ) = 0.

Silvio Jamil F. Guimarães Network Flow 19 de 32


Proof of Claim Relating Flows to Cuts

I Claim: f is an s-t flow and Gf has no s-t path ⇒ ∃


s-t cut (A∗ , B ∗ ), ν(f ) = c(A∗ , B ∗ ).
I A∗ = set of nodes reachable from s in Gf ,
B ∗ = V − A∗ .
I Claim: (A∗ , B ∗ ) is an s-t cut.
I Claim: If e = (u, v ) such that u ∈ A∗ , v ∈ B ∗ , then
f (e) = c(e).
I Claim: If e 0 = (u 0 , v 0 ) such that u 0 ∈ B ∗ , v 0 ∈ A∗ ,
then f (e 0 ) = 0.
I Claim: ν(f ) = c(A∗ , B ∗ ).
Silvio Jamil F. Guimarães Network Flow 19 de 32
Max-Flow Min-Cut Theorem

I The flow f¯ computed by the Ford-Fulkerson algorithm is a


maximum flow .
I Given a flow of maximum value, we can compute a
minimum s-t cut .

Silvio Jamil F. Guimarães Network Flow 20 de 32


Max-Flow Min-Cut Theorem

I The flow f¯ computed by the Ford-Fulkerson algorithm is a


maximum flow .
I Given a flow of maximum value, we can compute a
minimum s-t cut .
I In every flow network, there is a flow f and a cut (A, B) such
that ν(f ) = c(A, B).
I Max-Flow Min-Cut Theorem : in every flow network, the
maximum value of an s-t flow is equal to the minimum
capacity of an s-t cut.

Silvio Jamil F. Guimarães Network Flow 20 de 32


Max-Flow Min-Cut Theorem

I The flow f¯ computed by the Ford-Fulkerson algorithm is a


maximum flow .
I Given a flow of maximum value, we can compute a
minimum s-t cut .
I In every flow network, there is a flow f and a cut (A, B) such
that ν(f ) = c(A, B).
I Max-Flow Min-Cut Theorem : in every flow network, the
maximum value of an s-t flow is equal to the minimum
capacity of an s-t cut.
I Corollary: If all capacities in a flow network are integers ,
then there is a maximum flow f where every flow value f (e) is
an integer .

Silvio Jamil F. Guimarães Network Flow 20 de 32


Questions

Questions?
Network Flow
– Ford-Fulkerson Algorithm –

Silvio Jamil F. Guimarães Network Flow 21 de 32


Teoria dos Grafos e Computabilidade
— Scaling Max-Flow Algorithm —
Silvio Jamil F. Guimarães
Graduate Program in Informatics – PPGINF
Image and Multimedia Data Science Laboratory – IMScience
Pontifical Catholic University of Minas Gerais – PUC Minas
Aug 2021
Bad Augmenting Paths

100 100

s 1 t

100 100

Silvio Jamil F. Guimarães Network Flow 23 de 32


Bad Augmenting Paths

0/100 0/100

s 0/1 t

0/100 0/100
u
v
100 100

s 1 t

100 100

Silvio Jamil F. Guimarães Network Flow 23 de 32


Bad Augmenting Paths

u u

0/100 0/100 100 100


0 0

s 0/1 t s 0 1 t

0/100 0/100 100 100


0 0
u
v v
100 100

s 1 t

100 100

Silvio Jamil F. Guimarães Network Flow 23 de 32


Bad Augmenting Paths

u u u

0/100 0/100 100 100 100 100


0 0 0 0

s 0/1 t s 0 1 t s 0 1 t

0/100 0/100 100 100 100 100


0 0 0 0
u
v v v
100 100

s 1 t

100 100

Silvio Jamil F. Guimarães Network Flow 23 de 32


Bad Augmenting Paths

u u u

0/100 0/100 100 100 100 100


0 0 0 0

s 0/1 t s 0 1 t s 0 1 t

0/100 0/100 100 100 100 100


0 0 0 0
u
v v v
100 100

s 1 t

100 100
u
v
1/100 0/100

s 1/1 t

0/100 1/100

Silvio Jamil F. Guimarães Network Flow 23 de 32


Bad Augmenting Paths

u u u

0/100 0/100 100 100 100 100


0 0 0 0

s 0/1 t s 0 1 t s 0 1 t

0/100 0/100 100 100 100 100


0 0 0 0
u
v v v
100 100

s 1 t

100 100
u u
v
1/100 0/100 99 100
1 0

s 1/1 t s 1 0 t

0/100 1/100 100 99


0 1

v v

Silvio Jamil F. Guimarães Network Flow 23 de 32


Bad Augmenting Paths

u u u

0/100 0/100 100 100 100 100


0 0 0 0

s 0/1 t s 0 1 t s 0 1 t

0/100 0/100 100 100 100 100


0 0 0 0
u
v v v
100 100

s 1 t

100 100
u u u
v
1/100 0/100 99 100 99 100
1 0 1 0

s 1/1 t s 1 0 t s 1 0 t

0/100 1/100 100 99 100 99


0 1 0 1

v v v

Silvio Jamil F. Guimarães Network Flow 23 de 32


Improving Ford-Fulkerson Algorithm

I Bad case for Ford-Fulkerson algorithm is when the


bottleneck edge is the augmenting path has a
low capacity .

I Idea: decrease number of iterations by picking s-t


path with bottleneck edge of largest capacity.

Silvio Jamil F. Guimarães Network Flow 24 de 32


Improving Ford-Fulkerson Algorithm

I Bad case for Ford-Fulkerson algorithm is when the


bottleneck edge is the augmenting path has a
low capacity .

I Idea: decrease number of iterations by picking s-t


path with bottleneck edge of largest capacity.
Computing this path can slow down each iteration
considerably.

Silvio Jamil F. Guimarães Network Flow 24 de 32


Other Maximum Flow Algorithms

I Desire a strongly polynomial algorithm: running


time is depends only on the size of the graph and is
independent of the numerical values of the capacities
(as long as numerical operations.

Silvio Jamil F. Guimarães Network Flow 25 de 32


Other Maximum Flow Algorithms

I Desire a strongly polynomial algorithm: running


time is depends only on the size of the graph and is
independent of the numerical values of the capacities
(as long as numerical operations.

I Edmonds-Karp, Dinitz : choose augmenting path to


be the shortest path in Gf (use breadth-first search).

Silvio Jamil F. Guimarães Network Flow 25 de 32


Questions

Questions?
Network Flow
– Scaling Max-Flow Algorithm –

Silvio Jamil F. Guimarães Network Flow 26 de 32


Teoria dos Grafos e Computabilidade
— Exercises —
Silvio Jamil F. Guimarães
Graduate Program in Informatics – PPGINF
Image and Multimedia Data Science Laboratory – IMScience
Pontifical Catholic University of Minas Gerais – PUC Minas
Aug 2021
Compute the maximum flow

a 9 f

10 4 15 15 10

s 5 c 8 d 10 t

15 4 6 15 10

b 30 e

Silvio Jamil F. Guimarães Network Flow 28 de 32


Compute the maximum flow

a 4 f

10 2 8 6 10

s 10 c 9 d 10 t

Silvio Jamil F. Guimarães Network Flow 29 de 32


Bipartite graph matching

Bipartite graph matching

INSTANCE Let G = (L∪R, E ) be an undirected graph. M ⊆ E


is a matching if each node appear in, at most, one
edge in M.

SOLUTION Find a max cardinality matching.

e j

d i

c h

b g

a f

Silvio Jamil F. Guimarães Network Flow 30 de 32


Bipartite graph matching

Bipartite graph matching

INSTANCE Let G = (L∪R, E ) be an undirected graph. M ⊆ E


is a matching if each node appear in, at most, one
edge in M.

SOLUTION Find a max cardinality matching.

e j

d i

c h

b g

a f

Silvio Jamil F. Guimarães Network Flow 30 de 32


Bipartite graph matching

Bipartite graph matching

INSTANCE Let G = (L∪R, E ) be an undirected graph. M ⊆ E


is a matching if each node appear in, at most, one
edge in M.

SOLUTION Find a max cardinality matching.

e j

d i

c h

b g

a f

Silvio Jamil F. Guimarães Network Flow 30 de 32


Edge Disjoint Paths

Disjoint path problem

INSTANCE Let G = (G , E ) be a directed graph and two ver-


tices s and t

SOLUTION Find a max number of edge-disjoint s-t paths.

Silvio Jamil F. Guimarães Network Flow 31 de 32


Edge Disjoint Paths

Disjoint path problem

INSTANCE Let G = (G , E ) be a directed graph and two ver-


tices s and t

SOLUTION Find a max number of edge-disjoint s-t paths.

a f

s c d t

b e

Silvio Jamil F. Guimarães Network Flow 31 de 32


Edge Disjoint Paths

Disjoint path problem

INSTANCE Let G = (G , E ) be a directed graph and two ver-


tices s and t

SOLUTION Find a max number of edge-disjoint s-t paths.

a f

s c d t

b e

Silvio Jamil F. Guimarães Network Flow 31 de 32


Network Connectivity

Network Connectivity

INSTANCE Let G = (G , E ) be a directed graph and two ver-


tices s and t

SOLUTION Find a min number of edges whose removal dis-


connects t from s

Silvio Jamil F. Guimarães Network Flow 32 de 32


Network Connectivity

Network Connectivity

INSTANCE Let G = (G , E ) be a directed graph and two ver-


tices s and t

SOLUTION Find a min number of edges whose removal dis-


connects t from s
a f

s c d t

b e

Silvio Jamil F. Guimarães Network Flow 32 de 32


Network Connectivity

Network Connectivity

INSTANCE Let G = (G , E ) be a directed graph and two ver-


tices s and t

SOLUTION Find a min number of edges whose removal dis-


connects t from s
a f

s c d t

b e

Silvio Jamil F. Guimarães Network Flow 32 de 32

You might also like