Maximum Flow
Chapter 26
Flow Concepts
• Source vertex s
– where material is produced
• Sink vertex t
– where material is consumed
• For all other vertices – what goes in must go out
– Flow conservation
• Goal: determine maximum rate of material flow
from source to sink
Introduction - network
Representation
Example: oil pipeline
Flow network: directed graph G=(V,E)
v1
v3
S
v1
S
t
v2
v4
v3
source
t
v2
v4
sink
Introduction – max-flow problem
Representation
Example: oil pipeline
Flow network: directed graph G=(V,E)
v1
v3
S
v1
S
t
v2
v4
v3
source
t
v2
v4
sink
Informal definition of the max-flow problem:
What is the greatest rate at which material can be shipped from
the source to the sink without violating any capacity contraints?
Introduction - capacity
Representation
Example: oil pipeline
Flow network: directed graph G=(V,E)
3
v3
v1
8
v3
v1
6
3
S
t
S
t
3
6
v2
u
v4
6
12
8
v2
v
c(u,v)=12
u
6
c(u,v)=6
v4
Big pipe
v
Small pipe
Introduction - capacity
Representation
Example: oil pipeline
Flow network: directed graph G=(V,E)
3
v3
v1
8
v1
v3
6
3
S
t
S
t
3
6
v2
6
8
v4
If (u,v) E c(u,v) = 0
6
v2
v4
0
0
v4
v3
0
v2
v4
Introduction – flow
Representation
Example: oil pipeline
Flow network: directed graph G=(V,E)
3
v3
v1
8
v1
v3
6
3
S
t
S
t
3
6
v2
u
v4
6
6/12
8
v2
v
f(u,v)=6
u
6/6
f(u,v)=6
v4
Flow below capacity
v
Maximum flow
Introduction – flow
Representation
Example: oil pipeline
Flow network: directed graph G=(V,E)
3
v3
v1
8
v1
v3
6
3
S
t
S
t
3
6
v2
6
v4
8
v2
v4
Introduction – flow
Representation
Example: oil pipeline
Flow network: directed graph G=(V,E)
3
v3
v1
8
v1
v3
6
3
S
t
S
t
3
6/6
v2
6/6
v4
6/8
v2
v4
Introduction – flow
Representation
Example: oil pipeline
Flow network: directed graph G=(V,E)
3
v3
v1
8
v1
v3
6
3
S
t
S
t
3
6/6
v2
6/6
v4
6/8
v2
v4
Introduction – flow
Representation
Example: oil pipeline
Flow network: directed graph G=(V,E)
3/3
v3
v1
3/8
v1
v3
3/6
3
S
t
S
t
3
6/6
v2
6/6
v4
6/8
v2
v4
Introduction – flow
Representation
Example: oil pipeline
Flow network: directed graph G=(V,E)
3/3
v3
v1
3/8
v1
v3
3/6
3
S
t
S
t
3
6/6
v2
6/6
v4
6/8
v2
v4
Introduction – flow
Representation
Example: oil pipeline
Flow network: directed graph G=(V,E)
3/3
v3
v1
5/8
v1
v3
3/6
2/3
S
t
S
t
3
6/6
v2
6/6
v4
8/8
v2
v4
Introduction – cancellation
Representation
Example: oil pipeline
Flow network: directed graph G=(V,E)
3/3
v3
v1
5/8
v1
v3
3/6
2/3
S
t
S
t
3
6/6
v2
6/6
v4
8/8
v2
v4
Introduction – cancellation
Representation
Example: oil pipeline
Flow network: directed graph G=(V,E)
3/3
v3
v1
6/8
v3
v1
4/6
3/3
S
S
t
t
1/3
6/6
v2
v4
5/6
8/8
u
10
u
u
4
v
v2
8/10
4
v
8/10
u
3/4
v
v4
5/10
4
v
Maximum Flow Problem
• Given:
Directed graph G=(V, E),
Supply (source) node O, demand (sink) node T
Capacity function u: E R .
Given the arc capacities,
send as much flow as possible
from supply node O to demand node T
through the network.
• Goal:
• Example:
A
4
4
O
4
5
B
6
D
5
T
4
C
5
Towards the Augmenting Path Algorithm
• Idea: Find a path from the source to the sink,
and use it to send as much flow as possible.
• In our example,
5 units of flow can be sent through the path O B D T ;
Then use the path O C T to send 4 units of flow.
The total flow is 5 + 4 = 9 at this point.
• Can we send more?
A
4
5
O
4
5
B
5
4
6
4
5
D
5
4
4
C
5
T
Towards the Augmenting Path Algorithm
• If we redirect 1 unit of flow
from path O B D T to path O B C T,
then the freed capacity of arc D T could be used
to send 1 more unit of flow through path O A D T,
making the total flow equal to 9+1=10 .
• To realize the idea of redirecting the flow in a systematic way,
we need the concept of residual
capacities.
A
1
1
4
4
5
O
4
45
B
5
6
4
4
4
5
D
5
1
5
4
C
5
T
Residual Network
• The network given by the undirected arcs and residual capacities
is called residual network.
• In our example,
the residual network before sending any flow:
A
0
4
O
5
0
4
4
0
6
B
0
4
0
0
C
D
5
0
0
T
5
Note that the sum of the residual capacities on both ends of an arc
is equal to the original capacity of the arc.
• How to increase the flow in the network
based on the values of residual capacities?
Residual capacities
• Suppose we have an arc with capacity 6 and current flow 5:
5
D
B
6
• Then there is a residual capacity of 6-5=1
for any additional flow through B D .
• On the other hand,
at most 5 units of flow can be sent back from D to B, i.e.,
5 units of previously assigned flow can be canceled.
In that sense, 5 can be considered as
the residual capacity of the reverse arc D B .
• To record the residual capacities in the network,
we will replace the original directed arcs with undirected arcs:
B
1
5
D
The number at B is the residual capacity of BD;
the number at D is the residual capacity of DB.
Augmenting paths
• An augmenting path is a directed path
from the source to the sink in the residual network
such that
every arc on this path has positive residual capacity.
• The minimum of these residual capacities
is called the residual capacity of the augmenting path.
This is the amount
that can be feasibly added to the entire path.
• The flow in the network can be increased
by finding an augmenting path
and sending flow through it.
Updating the residual network
by sending flow through augmenting paths
Continuing with the example,
• Iteration 1: O B D T is an augmenting path
with residual capacity 5 = min{5, 6, 5}.
• After sending 5 units of flow
through the path O B D T,
the new residual network is:
A
0
4
O
50
05
4
B
4
0
6
1
0
5
4
0
0
C
D
5
0
0
5
0
5
T
Updating the residual network
by sending flow through augmenting paths
• Iteration 2:
O C T is an augmenting path
with residual capacity 4 = min{4, 5}.
• After sending 4 units of flow
through the path O C T,
the new residual network is:
A
0
4
O
0
5
0
4
4
0
B
1
5
4
40
0
C
D
0
5
4
0
1
5
T
Updating the residual network
by sending flow through augmenting paths
• Iteration 3:
O A D B C T is an augmenting path
with residual capacity 1 = min{4, 4, 5, 4, 1}.
• After sending 1 units of flow
through the path O A D B C T ,
the new residual network is:
A
10
34
O
0
5
0
4
34
10
B 21
34
10
C
45
D
0
5
54
01
T
Terminating the Algorithm:
Returning an Optimal Flow
• There are no augmenting paths in the last residual network.
So the flow from the source to the sink cannot be increased further,
and the current flow is optimal.
• Thus, the current residual network is optimal.
The optimal flow on each directed arc of the original network
is the residual capacity of its reverse arc:
flow(OA)=1, flow(OB)=5, flow(OC)=4,
flow(AD)=1, flow(BD)=4, flow(BC)=1,
flow(DT)=5, flow(CT)=5.
The amount of maximum flow through the network is
5 + 4 + 1 = 10
(the sum of path flows of all iterations).
Flow properties
Flow in G = (V,E): f: V x V R with 3 properties:
1) Capacity constraint: For all u,v V : f(u,v) < c(u,v)
2) Skew symmetry:
For all u,v V : f(u,v) = - f(v,u)
3) Flow conservation: For all u V \ {s,t} :
f(u,v) = 0
vV
Flow properties
Flow in G = (V,E): f: V x V R with 3 properties:
1) Capacity constraint: For all u,v V : f(u,v) < c(u,v)
2) Skew symmetry:
For all u,v V : f(u,v) = - f(v,u)
3) Flow conservation: For all u V \ {s,t} :
Flow network G = (V,E)
v1
12/12
v3
f(u,v) = 0
vV
Note:
by skew symmetry
S
t
v2
11/14
v4
f (v3,v1) = - 12
Net flow and value of a flow
u
Net Flow:
positive or negative value
of f(u,v)
8/10
u
3/4
5/10
v
f(u,v) = 5
4
f(v,u) = -5
v
3/3
v3
v1
Value of a Flow f:
Def:
|f| = v V f(s,v)
6/8
4/6
3/3
S
t
1/3
6/6
v2
5/6
v4
8/8
The max-flow problem
Informal definition of the max-flow problem:
What is the greatest rate at which material can be shipped from
the source to the sink without violating any capacity contraints?
Formal definition of the max-flow problem:
The max-flow problem is to find a valid flow for a given weighted
directed graph G, that has the maximum value over all valid
flows.
The Ford-Fulkerson method
a way how to find the max-flow
This method contains 3 important ideas:
1) residual networks
2) augmenting paths
3) cuts of flow networks
Ford-Fulkerson – pseudo code
1 initialize flow f to 0
2 while there exits an augmenting path p
3
do augment flow f along p
4 return f
Ford Fulkerson – residual networks
The residual network Gf of a given flow network G with a valid flow f consists
of the same vertices v V as in G which are linked with residual edges (u,v)
Ef that can admit more strictly positive net flow.
The residual capacity cf represents the weight of each edge Ef and is the
amount of additional net flow f(u,v) before exceeding the capacity c(u,v)
Flow network G = (V,E)
v1
12/12
residual network Gf = (V,Ef)
v3
S
v1
t
v2
11/14
v3
S
v4
t
v2
cf(u,v) = c(u,v) – f(u,v)
v4
Ford Fulkerson – residual networks
The residual network Gf of a given flow network G with a valid flow f consists
of the same vertices v V as in G which are linked with residual edges (u,v)
Ef that can admit more strictly positive net flow.
The residual capacity cf represents the weight of each edge Ef and is the
amount of additional net flow f(u,v) before exceeding the capacity c(u,v)
Flow network G = (V,E)
v1
12/12
residual network Gf = (V,Ef)
v3
S
v1
t
v2
11/14
12
v3
S
v4
t
v2
3
11
cf(u,v) = c(u,v) – f(u,v)
v4
Ford Fulkerson – augmenting paths
Definition: An augmenting path p is a simple (free of any cycle) path from s to
t in the residual network Gf
Residual capacity of p
cf(p) = min{cf (u,v): (u,v) is on p}
Flow network G = (V,E)
v1
12/12
residual network Gf = (V,Ef)
v3
S
v1
t
v2
11/14
v4
12
v3
S
t
v2
3
11
v4
Ford Fulkerson – augmenting paths
Definition: An augmenting path p is a simple (free of any cycle) path from s to
t in the residual network Gf
Residual capacity of p
cf(p) = min{cf (u,v): (u,v) is on p}
Flow network G = (V,E)
v1
12/12
residual network Gf = (V,Ef)
v3
S
v1
t
v2
11/14
v4
12
v3
S
t
v2
3
v4
11
Augmenting path
Ford Fulkerson – augmenting paths
We define a flow: fp: V x V R such as:
cf(p)
fp(u,v) =
- cf(p) if (v,u) is on p
0
otherwise
Flow network G = (V,E)
v1
12/12
residual network Gf = (V,Ef)
v3
S
v1
t
v2
11/14
if (u,v) is on p
v4
12
v3
S
t
v2
3
11
v4
Ford Fulkerson – augmenting paths
We define a flow: fp: V x V R such as:
cf(p)
fp(u,v) =
- cf(p) if (v,u) is on p
0
otherwise
Flow network G = (V,E)
v1
12/12
residual network Gf = (V,Ef)
v3
S
v1
t
v2
11/14
if (u,v) is on p
v4
12
v3
S
t
v2
3
v4
11
Our virtual flow fp along the
augmenting path p in Gf
Ford Fulkerson – augmenting paths
We define a flow: fp: V x V R such as:
cf(p)
fp(u,v) =
- cf(p) if (v,u) is on p
0
otherwise
Flow network G = (V,E)
v1
12/12
residual network Gf = (V,Ef)
v3
S
v1
t
v2
11/14
if (u,v) is on p
v4
12
v3
S
t
v2
3
v4
11
Our virtual flow fp along the
augmenting path p in Gf
Ford Fulkerson – augmenting the flow
We define a flow: fp: V x V R such as:
cf(p)
fp(u,v) =
- cf(p) if (v,u) is on p
0
otherwise
Flow network G = (V,E)
v1
12/12
New flow:
residual network Gf = (V,Ef)
v3
S
v1
t
v2
11/14
if (u,v) is on p
v4
f´: V x V R : f´=f + fp
12
v3
S
t
v2
3
v4
11
Our virtual flow fp along the
augmenting path p in Gf
Ford Fulkerson – new valid flow
proof of capacity constraint
cf(p)
Lemma:
f´ : V x V R : f´ = f + fp
fp(u,v) =
in G
if (u,v) is on p
- cf(p) if (v,u) is on p
0
otherwise
cf(p) = min{cf (u,v): (u,v) is on p}
Capacity constraint:
cf(u,v) = c(u,v) – f(u,v)
For all u,v V, we require f(u,v) < c(u,v)
Proof:
fp (u ,v) < cf (u ,v) = c (u ,v) – f (u ,v)
(f + fp) (u ,v) = f (u ,v) + fp (u ,v) < c (u ,v)
The Ford-Fulkerson method
Ford-Fulkerson(G,s,t)
1 for each edge (u,v) in G.E do
2
f(u,v) f(v,u) 0
3 while there exists a path p from s to t in residual
network Gf do
4
cf = min{cf(u,v): (u,v) is in p}
5
for each edge (u,v) in p do
6
f(u,v) f(u,v) + cf
7
f(v,u) -f(u,v)
8 return f
The algorithms based on this method differ in how they choose p in step 3.
If chosen poorly the algorithm might not terminate.
Execution of Ford-Fulkerson (1)
Left Side = Residual Graph
Right Side = Augmented Flow
Execution of Ford-Fulkerson (2)
Left Side = Residual Graph
Right Side = Augmented Flow
Cuts
• Does the method find the minimum flow?
– Yes, if we get to the point where the residual graph has no path from s to t
– A cut is a partition of V into S and T = V – S, such that s S and t T
– The net flow (f(S,T)) through the cut is the sum of flows f(u,v), where s S
and t T
• Includes negative flows back from T to S
– The capacity (c(S,T)) of the cut is the sum of capacities c(u,v), where s S
and t T
• The sum of positive capacities
– Minimum cut – a cut with the smallest capacity of all cuts.
|f|= f(S,T) i.e. the value of a max flow is equal to the capacity of a min cut.
10/15
s
6/14
Cut capacity = 24
a
2/4
c
8/13
10
b
9
8/11
13/19
t
5/5
d
3/3
Min Cut capacity = 21
Max Flow / Min Cut Theorem
1. Since |f| c(S,T) for all cuts of (S,T) then if |f| =
c(S,T) then c(S,T) must be the min cut of G
2. This implies that f is a maximum flow of G
3. This implies that the residual network Gf contains
no augmenting paths.
•
•
If there were augmenting paths this would contradict
that we found the maximum flow of G
1231 … and from 23 we have that the
Ford Fulkerson method finds the maximum flow if
the residual graph has no augmenting paths.
Worst Case Running Time
• Assuming integer flow
• Each augmentation increases the value of the flow by some
positive amount.
• Augmentation can be done in O(E).
• Total worst-case running time O(E|f*|), where f* is the maxflow found by the algorithm.
• Example of worst case:
Augmenting path of 1
Resulting Residual Network
Resulting Residual Network
Application – Bipartite Matching
• Example – given a community with n men and m
women
• Assume we have a way to determine which couples
(man/woman) are compatible for marriage
– E.g. (Joe, Susan) or (Fred, Susan) but not (Frank, Susan)
• Problem: Maximize the number of marriages
– No polygamy allowed
– Can solve this problem by creating a flow network out of a
bipartite graph
Bipartite Graph
• A bipartite graph is an undirected graph G=(V,E) in which V
can be partitioned into two sets V1 and V2 such that (u,v) E
implies either u V1 and v V12 or vice versa.
• That is, all edges go between the two sets V1 and V2 and not
within V1 and V2.
Model for Matching Problem
• Men on leftmost set, women on rightmost set,
edges if they are compatible
A
X
B
Y
C
Z
D
Men
A
A
X
B
B
Y
Y
C
C
Z
D
Women
A matching
X
Z
D
Optimal matching
Solution Using Max Flow
• Add a supersouce, supersink, make each
undirected edge directed with a flow of 1
A
A
X
B
Y
C
s
B
Y
C
Z
D
X
Z
D
Since the input is 1, flow conservation prevents multiple matchings
t
Transshipment Problem
• Given: Directed network G=(V, E)
Supply (source) nodes Si with supply amounts si, i=1,…,p
Demand (sink) nodes Di with demand amounts di, i=1,…,q
Total supply ≥ total demand
Capacity function u: E R
• Goal: Find a feasible flow through the network which satisfies the
total demand (if such a flow exists).
• Ex.: 11
17
4
S1
5
5
2
D1
B
2
5
A
2
4
16
S2
19
15
C
5
9
D2
8
Solving the Transshipment Problem via Maximum Flow
• The transshipment problem can be solved by creating and solving a related
instance of maximum flow problem:
– Create a supersource O. For each supply node
Si, add an arc O Si
with capacity equal to the supply amount of Si .
– Create a supersink T. For each demand node Di, add an arc Di T with capacity
equal to the supply amount of Di .
– Find the maximum flow from O to T in the resulting auxiliary network.
– If maximum flow value = total demand
then the current maximum flow is a feasible flow for the transshipment
problem,else the problem is infeasible
11
4
B
5
2
11
O
S1
5
D1
17
17
2
5
T
A
16
2
4
16
S2
19
15
C
8
5
9
D2
8
Solving the Transshipment Problem via Maximum Flow
• In our example,
– The maximum flow from O to T is obtained by applying the
Augmenting Path algorithm. The maximum flow value is 25.
The bold red numbers on the arcs show the flow values.
– Since the maximum flow value = 25 = 17+8 = total demand,
the current maximum flow is a feasible flow
for the transshipment problem.
11
S1
9
O
5
2
4
16
S2
19
18
2
17
D1
17
17
T
13
1
A
16
4
2
2
2
16
4
B
5
2
11
5
5
15
C
8
5
9
8
8
D2
8
Showing the infeasibility of an assignment problem using
minimum-cut-based arguments
• The O-side of the minimum cut is {O, A, B, D, x, y, z} (the set of the
nodes that are reachable from O via augmenting paths)
• Return to the original network (delete nodes O and T and the arcs
incident to them).
O
1
A
people
1
jobs
B
x
1
1
1
C
1
D
1
E
1
z
y
1
1
u
1
T
1
1
v
F
1
1
w
Solving the Assignment Problem via Maximum Flow
• The assignment problem can be solved by creating and solving a related instance of
the transshipment problem:
– Each person-node is considered as a supply node with supply amount 1.
– Each job-node is considered as a demand node with demand amount 1.
– Assign capacity 1 to each arc.
– Solve the resulting transshipment problem by finding maximum flow in the
auxiliary network.
– If maximum flow value = n
then the current maximum flow gives a feasible assignment,
else the assignment problem is infeasible.
people
jobs
1
1
A
x
1
B
z
y
1
1
C
1
1
D
v
u
1
E
1
1
Solving the Assignment Problem via Maximum Flow
• In our example,
the red numbers on the arcs show the optimal flow values.
Since the maximum flow value is 5,
the assignment problem is feasible.
The feasible assignment is A x , B y, C u , D z , E v .
O
1
1
1
jobs
B
A
1
1
1
1
z
1
1
1
T
v
u
1
1
E
D
1
y
1
1
C
1
x
1
1
1
1
people
1
1
1
1
1
Showing the infeasibility of an assignment problem using
maximum-flow-based arguments
• Let’s solve the assignment problem below via maximum flow.
The red numbers on the arcs show the optimal flow values.
Since the maximum flow value = 5 < 6 = number of jobs,
the assignment problem is infeasible.
O
1
A
people
1
jobs
B
x
1
1
1
C
1
D
1
E
1
z
y
1
1
u
1
T
1
1
v
F
1
1
w
Showing the infeasibility of an assignment problem using
minimum-cut-based arguments
• The O-side of the minimum cut is {O, A, B, D, x, y, z} (the set of the
nodes that are reachable from O via augmenting paths)
• Return to the original network (delete nodes O and T and the arcs
incident to them).
O
1
A
people
1
jobs
B
x
1
1
1
C
1
D
1
E
1
z
y
1
1
u
1
T
1
1
v
F
1
1
w
© Copyright 2026 Paperzz