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

Lecture11 IO BLG336E 2022

The document discusses network flow theory, focusing on maximum flows, minimum cuts, and the Ford-Fulkerson algorithm. It explains concepts such as s-t cuts, flow conservation, and the relationship between maximum flow and minimum cut through the max-flow min-cut theorem. Additionally, it provides examples and exercises to illustrate these concepts in directed graphs with capacities.

Uploaded by

pearsonicin
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 views83 pages

Lecture11 IO BLG336E 2022

The document discusses network flow theory, focusing on maximum flows, minimum cuts, and the Ford-Fulkerson algorithm. It explains concepts such as s-t cuts, flow conservation, and the relationship between maximum flow and minimum cut through the max-flow min-cut theorem. Additionally, it provides examples and exercises to illustrate these concepts in directed graphs with capacities.

Uploaded by

pearsonicin
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/ 83

BLG 336E

Analysis of Algorithms II
Lecture 11:
Network Flow II
Max flows, Min cuts, and Ford-Fulkerson

1
The plan for today
• Minimum s-t cuts
• Maximum s-t flows
• The Ford-Fulkerson Algorithm
• Finds min cuts and max flows!
• Applications
• Why do we want to find these things?
Last time graphs were
Last time undirected and
unweighted.
• We talked about global min-cuts
• A cut is a partition of the vertices into two nonempty
parts.

Part 1 Part 2
Today
• Graphs are directed and edges have “capacities” (weights)
• We have a special “source” vertex s and “sink” vertex t.
• s has only outgoing edges*
• t has only incoming edges*
3
4
4 2 6
6
2 4
s t
3
2 6
3 4
6
10
*at least for this class
An s-t cut
is a cut which separates s from t

3
4
4 2 6
6
2 4
s t
3
2 6
3 4
6
10
An s-t cut
is a cut which separates s from t

3
4
4 2 6
6
2 4
s t
3
2 6
3 4
6
10
An s-t cut
is a cut which separates s from t
• An edge crosses the cut if it goes from s’s side to t’s side.

3
4
4 2 6
6
2 4
s t
3
2 6
3 4
6
10
An s-t cut
is a cut which separates s from t
• An edge crosses the cut if it goes from s’s side to t’s side.
• The cost (or capacity) of a cut is the sum of the
capacities of the edges that cross the cut.
This cut has cost
3 4 + 2 + 10 = 16
4
4 2 6
6
2 4
s t
3
2 6
3 4
6
this edge does not
cross the cut; it’s going 10
in the wrong direction.
A minimum s-t cut
is a cut which separates s from t
with minimum capacity.
• Question: how do we find a minimum s-t cut?
This cut has cost
4 + 3 + 4 = 11
3
4
4 2 6
6
2 4
s t
3
2 6
3 4
6
10
Example where this comes up
• 1955 map of rail
networks from the Soviet
this says
Union to Eastern Europe.
“the bottleneck”
• Declassified in 1999.
• 44 edges, 105 vertices

• The US wanted to cut off


routes from suppliers in
Russia to Eastern Europe
as efficiently as possible.
These numbers
are capacities.
• In 1955, Ford and
Fulkerson at the RAND
corporation gave an
algorithm which finds the
optimal s-t cut.
Schriver 2002
Flows
• In addition to a capacity, each edge has a flow
• (unmarked edges in the picture have flow 0)
• The flow on an edge must be less that its capacity.
• At each vertex, the incoming flows must equal the outgoing
flows.
4 units in, 3
1+1+2 = 4 units out. 2
2 4
4 1 6
2 6 1
4
2 4
s 1 2 t
3
2 1+1 = 2 units in, 6
6 2 units3out. 4 of this as
Think
meaning “send 2
10 units of stuff along
this edge.”
Because of conservation of
Flows flows at vertices,

• The value of a flow is: stuff you put in


=
• The amount of stuff coming out of s
stuff you take out.
• The amount of stuff flowing into t
• These are the same!

3
2
2 4
4 1 6
2 6 1
4
2 4
s 1 2 t
3
2 6
3 4
6

The value of 10
this flow is 4.
A maximum flow
is a flow of maximum value.
• This example flow is pretty wasteful, I’m not utilizing
the capacities very well.
3
2
2 4
4 1 6
2 6 1
4
2 4
s 1 2 t
3
2 6
3 4
6

The value of 10
this flow is 4.
That’s the same as the

A maximum flow minimum cut in this graph!

is a flow of maximum value.


• This one is maximal; it has value 11.

3
3
3 4
4 6
4
2 6 1

2 4
s 2 3 4 t
3
5 2 1 6
3 4
6 4
5
10
Example
• 1955 map of rail
networks from the Soviet
Union to Eastern Europe.
• Declassified in 1999.
• 44 edges, 105 vertices

• The Soviet Union wants


to route supplies from
suppliers in Russia to
These numbers Eastern Europe as
are capacities. efficiently as possible.

These numbers
are flows.

Schriver 2002
Exercise
• Each edge is a (directed) rickety bridge.
• How many bridges need to fall down to disconnect
s from t?
• If only one person can be on a bridge at a time, and
you want to keep traffic moving (aka, no waiting at
vertices allowed), how many people can get to t at
a time?

s t
How about now?
• Each edge is a (directed) rickety bridge.
• How many bridges need to fall down to disconnect
s from t?
• If only one person can be on a bridge at a time, and
you want to keep traffic moving (aka, no waiting at
vertices allowed), how many people can get to t at
a time?

s t
How about now?
• Each edge is a (directed) rickety bridge.
• How many bridges need to fall down to disconnect
s from t?
• If only one person can be on a bridge at a time, and
you want to keep traffic moving (aka, no waiting at
vertices allowed), how many people can get to t at
a time?

s t
Exercise
• Can you come up with a graph where the two
numbers are different?
Theorem
Max-flow min-cut theorem
The value of a max flow from s to t Intuition: in a max flow,
is equal to the min cut better fill up,
and this is the bottleneck.
the cost of a min s-t cut.
3
3
3 4
4 6
4
2 6 1

2 4
s 2 3 4 t
3
5 2 1 6
3 4
6 4
5
10
Proof outline
• Lemma 1: max flow ≤ min cut.
• Proof-by-picture
• Lemma 2: max flow ≥ min cut.
• Proof-by-algorithm, using a “Residual graph” 𝐺𝑓
• Sub-Lemma: t is not reachable from s in 𝐺𝑓 ⇔ f is a max flow.
• ⇐ first we do this direction:
• Claim: If there is a path from s to t in 𝐺𝑓 , then we can increase the
flow in G.
• Hence we couldn’t have started with a max flow.
• ⇒ for this direction, proof-by-picture again.

This claim actually gives us an algorithm: Find paths from s to


t in Gf and keep increasing the flow until you can’t anymore.
Proof of Min-Cut Max-Flow Thm
• Lemma 1:
• For ANY s-t flow and ANY s-t cut, the value of the flow is
at most the cost of the cut.
• Hence max flow ≤ min cut.
ANY s-t CUT
Proof by picture:
All that stuff has to cross
So x ≤ cost of this cut
the cut at some point.

x stuff
comes
out of s
t
s
Proof of Min-Cut Max-Flow Thm
• Lemma 1:
• For ANY s-t flow and ANY s-t cut, the value of the flow is
at most the cost of the cut.
• Hence max flow ≤ min cut.
Proof of Min-Cut Max-Flow Thm
• Lemma 1:
• For ANY s-t flow and ANY s-t cut, the value of the flow is
at most the cost of the cut.
• Hence max flow ≤ min cut.

• The theorem is stronger:


• max flow = min cut
• Need to show max flow ≥ min cut.
• Next: Proof by algorithm!
Ford-Fulkerson algorithm
• Usually we state the algorithm first and then prove
that it works.
• Today we’re going to just start with the proof, and
this will inspire the algorithm.

Outline of algorithm:
• Start with zero flow
• We will maintain a “residual graph” Gf
• A path from s to t in Gf will give us a Assume for today that we
way to improve our flow. don’t have edges like this,
although it’s not necessary.
• We will continue until there are no s-t
paths left.
Tool: Residual networks
Say we have a flow 𝑐 𝑢, 𝑣 − 𝑓 𝑢, 𝑣
𝑐𝑓 𝑢, 𝑣 = ቐ 𝑓 𝑣, 𝑢
𝑖𝑓 𝑢, 𝑣 ∈ 𝐸
𝑖𝑓 𝑣, 𝑢 ∈ 𝐸
a 0 𝑒𝑙𝑠𝑒
2 • 𝑓(𝑢, 𝑣) is the flow on edge 𝑢, 𝑣 .
• c(𝑢, 𝑣) is the capacity on edge 𝑢, 𝑣
2
3 6
4 1
t
s
8
1 3 2
a
b 3
Call the flow 𝑓 2
Call the graph 𝐺 0
1 5
s
1 t
Create a new residual 7 1
network from this flow:
1 b 2
Call this graph 𝐺𝑓
Tool: Residual networks
Say we have a flow
a
Forward edges are the
2 amount that’s left.
6
2 Backwards edges are the
3
4 1
amount that’s been used.
t
s
8
1 3 2
a
b 3
Call the flow 𝑓
Call the graph 𝐺
2
1 5
s
1 t
Create a new residual 7 1
network from this flow:
1 b 2
Call this graph 𝐺𝑓
Why look at residual networks?
Lemma:
• t is not reachable from s in 𝐺𝑓 ⇔ f is a max flow.
Example: s is reachable from t in this
example, so not a max flow.

2
2 3
3 6 2
4 1 1 5
t
s 8 s 1 t
1 3 2 7 1
Call the flow 𝑓 1 2
Call the graph 𝐺 Call this graph 𝐺𝑓
Why look at residual networks?
Lemma:
• t is not reachable from s in 𝐺𝑓 ⇔ f is a max flow.
To see that this flow is not
Example: s is reachable from t in this
maximal, notice that we can example, so not a max flow.
improve it by sending one
more unit more stuff along Now update the residual graph…
this path:

2
2 3
43 6 2
4 21 1 5
t
s 8 s 1 t
1 3 32 7 1
Call the flow 𝑓 1 2
Call the graph 𝐺 Call this graph 𝐺𝑓
Why look at residual networks?
Lemma:
• t is not reachable from s in 𝐺𝑓 ⇔ f is a max flow.
Example:
To see that this flow is not
maximal, notice that we can Now we get this residual graph:
improve it by sending one
more unit more stuff along
this path:

2
2 4
43 6 2
4 21 0 4
t
s 8 s 2 t
1 3 32 7 0
Call the flow 𝑓 1 3
Call the graph 𝐺 Call this graph 𝐺𝑓
Why look at residual networks?
Lemma:
• t is not reachable from s in 𝐺𝑓 ⇔ f is a max flow.
Example:
Now we get this residual graph:
Now we can’t reach t from s.
So the lemma says that f is a
max flow.
2
2 4
43 6 2
4 21
t 4
s 8 s 2 t
1 3 32 7
Call the flow 𝑓 1 3
Call the graph 𝐺 Call this graph 𝐺𝑓
Let’s prove the Lemma
• t is not reachable from s in 𝐺𝑓 ⇔ f is a max flow.
We will prove the
Lemma: ⇐ first this direction ⇐ contrapositive

t is not reachable from s in 𝐺𝑓 ⇔ f is a max flow.


• Suppose there is a path from s to t in 𝐺𝑓.
• This is called an augmenting path.
• Claim: if there is an augmenting path, we can increase the
flow along that path. we will come back
to this in a second.
• So do that and update the flow.
• This results in a bigger flow
• so we can’t have started with a max flow.

2
2 3
43 6 2
4 21 1 5
t
s 8 s 1 t
1 3 32 7 1
Call the flow 𝑓 1 2
Call the graph 𝐺 Call this graph 𝐺𝑓
claim:
if there is an augmenting path, we can
increase the flow along that path.
• In the situation we just saw, this is pretty obvious.

2
2 3
43 6 2
4 21 1 5
t
s 8 s 1 t
1 3 32 7 1
Call the flow 𝑓 1 2
Call the graph 𝐺 Call this graph 𝐺𝑓

• Every edge on the path in Gf was a forward edge,


so increase the flow on all the edges. aka, an edge indicating how
much stuff can still go through
claim:
if there is an augmenting path, we can
increase the flow along that path.
• But maybe there are backward edges in the path.
• Here’s a slightly different example of a flow:

2
2 1
1 6 2
4 1 3 5
t
s 3 s 1 t
1 3 0 2 3
Call the flow 𝑓 1
Call the graph 𝐺 Call this graph 𝐺𝑓

I changed some of
the weights and
edge directions.
claim:
if there is an augmenting path, we can
increase the flow along that path.
• But maybe there are backward edges in the path.
• Here’s a slightly different example of a flow:

2
2 1
1 6 2
4 1 3 5
t
s 3 s 1 t
1 3 0 2 3
Call the flow 𝑓 1
Call the graph 𝐺 Call this graph 𝐺𝑓
Now we should NOT increase the flow at
all the edges along the path! I changed some of
• For example, that will mess up the the weights and
conservation of stuff at this vertex. edge directions.
claim:
if there is an augmenting path, we can
increase the flow along that path.
• In this case we do something a bit different:
We will add We will remove flow here,
flow here since our augmenting path
is going backwards along
2 this edge.
2 1
21 6 2
4
01 3 5
t
s 3 s 1 t
1 3 10 2 3
Call the flow 𝑓 1
Call the graph 𝐺 Call this graph 𝐺𝑓

We will add
flow here
claim:
if there is an augmenting path, we can
increase the flow along that path.
• In this case we do something a bit different:
Then we’ll update the residual graph:

2
2 2
12 6 2
4 10 2 6
s t
3 s t
1 3 01 2 2
Call the flow 𝑓 1 1
Call the graph 𝐺 Call this graph 𝐺𝑓
2 in, 2 out
Before: flow value is 2
2
2 1
1 6 2
4 1 3 5
t
s 3 s 1 t
1 3 0 2 3
Call the flow 𝑓 1
Call the graph 𝐺 1 in, 1 out Call this graph 𝐺𝑓

After: 2 in, 2 out

2 flow value is 3
2 2
12 6 2
4 10 2 6
s t
3 s t
1 3 01 2 2
Call the flow 𝑓 1 1
Call the graph 𝐺 1 in, 1 out Call this graph 𝐺𝑓

Still a legit flow, but with a bigger value!


claim: Check that this
if there is an augmenting path, we can always makes a
bigger (and legit)
increase the flow along that path. flow!

• increaseFlow(path P in 𝐺𝑓 , flow f ):
• x = min weight on any edge in P
• for (u,v) in P:
• if (u,v) in E, 𝒇’ 𝒖, 𝒗 ← 𝒇(𝒖, 𝒗) + 𝒙.
This is f’
• if (v,u) in E, 𝒇’ 𝒗, 𝒖 ← 𝒇(𝒗, 𝒖) – 𝒙
• return f’

4 5 3 1 5 2 2
5 2 1 3 0
s t
flow f in G

2
x=2
3 4 3
s t
path P in 𝐺𝑓
That proves the claim

If there is an augmenting path, we can


increase the flow along that path
We will prove the
Lemma: ⇐ first this direction ⇐ contrapositive

t is not reachable from s in 𝐺𝑓 ⇔ f is a max flow.


• Suppose there is a path from s to t in 𝐺𝑓.
• This is called an augmenting path.
• Claim: if there is an augmenting path, we can increase the
flow along that path.
• So do that and update the flow.
• This results in a bigger flow
• so we can’t have started with a max flow.

2
1 6 2
2 4 43
21
3 5 s t
1 t 8
s 7 3 32
1 1
Call the flow 𝑓
1 2 Call the graph 𝐺
Call this graph 𝐺𝑓
Lemma: ⇒ now this direction ⇒
t is not reachable from s in 𝐺𝑓 ⇔ f is a max flow.
• Suppose there is not a path from s to t in 𝐺𝑓 .
• Consider the cut given by:
{things reachable from s} , {things not reachable from s}

2
2
4
4 6 2
4 2
t 5
s 8 s 1 t
1 3 3 7
Call the flow 𝑓 1 3
Call the graph 𝐺 Call this graph 𝐺𝑓
Lemma: ⇒ now this direction ⇒
t is not reachable from s in 𝐺𝑓 ⇔ f is a max flow.
• Suppose there is not a path from s to t in 𝐺𝑓 .
• Consider the cut given by:
{things reachable from s} , {things not reachable from s}
• The flow from s to t is equal to the cost of this cut.
• Similar to proof-by-picture we saw before:
• All of the stuff has to cross the cut.
• The edges in the cut are full because they don’t exist in 𝐺𝑓
• thus: this flow value = cost of this cut ≥ cost of min cut ≥ max flow

2
2
4
4 6 2
4 1
2 5
t
s 8 t
s 7
1 3 3
Call the flow 𝑓 1 3
Call the graph 𝐺 Call this graph 𝐺𝑓
Lemma: ⇒ now this direction ⇒
t is not reachable from s in 𝐺𝑓 ⇔ f is a max flow.
• Suppose there is not a path from s to t in 𝐺𝑓 .
• Consider the cut given by:
{things reachable from s} , {things not reachable from s}
• The flow from s to t is equal to the cost of this cut.
• Similar to proof-by-picture we saw before:
• All of the stuff has to cross the cut.
• The edges in the cut are full because they don’t exist in 𝐺𝑓
• thus: this flow value = cost of this cut ≥ cost of min cut ≥ max flow

2 flow value ≤ max flow value,


But this
so
2 they must be equal!
4
4 6 2
4 1
2 5
t
s 8 t
s 7
1 3 3
Call the flow 𝑓 1 3
Call the graph 𝐺 Call this graph 𝐺𝑓
We’ve proved:
• t is not reachable from s in 𝐺𝑓 ⇔ f is a max flow

• This inspires an algorithm:


• Ford-Fulkerson(G):
• 𝑓 ← all zero flow.
• 𝐺𝑓 ← 𝐺
• while t is reachable from s in 𝐺𝑓
• Find a path P from s to t in 𝐺𝑓 // eg, use BFS
• 𝑓 ← increaseFlow(P,f)
• update 𝐺𝑓
• return f
How do we choose which paths to use?
• The analysis we did still works no matter how we
choose the paths.
• That is, the algorithm will be correct if it terminates.
• However, the algorithm may not be efficient!!!
• May take a long time to terminate
• (Or may actually never terminate?)

• We need to be careful with our path selection to make


sure the algorithm terminates quickly.
• Using BFS leads to the Edmonds-Karp algorithm.
Example of Ford-Fulkerson
3 0
4
4 0 0
0 6
s 0 2 0 4 0 t
3
0
3 0
6 0 4
0
10
3
4 4
6
3 4
s t
2
3
6 4
10
Example of Ford-Fulkerson
3 0
4
4 0 0
0 6
s 0 2 0 4 0 t
3
0
3 0
6 0 4
0
10
3
4 4
6
3 4
s t
2
3
6 4
10
Example of Ford-Fulkerson
3 0
4
4 4 0
4 6
s 0 2 0 4 4 t
3
0
3 0
6 0 4
0
10
3
4
4 2
4
3 4
s t
2
3
6 4
10
Example of Ford-Fulkerson
3 0
4
4 4 0
4 6
s 0 2 0 4 4 t
3
0
3 0
6 0 4
0
10
3
4
4 2
4
3 4
s t
2
3
6 4
10
Example of Ford-Fulkerson
3 0
4
4 4 0
4 6
s 0 2 0 4 4 t
3
4
3 0
6 4 4
4
10
3
4
4 2
4
3 4
s t
2
4 3 4
2 4
6
Example of Ford-Fulkerson We will remove flow
from this edge.
3 0
4
4 4 0
4 6
s 0 2 0 4 4 t
3
4
3 0
6 4 4
4
10
Notice that we’re
going back along one
3
of the backwards 4
edges we added. 4 2
4
s 3 t
2 4
4 3 4
2 4
6
Example of Ford-Fulkerson We will remove flow
from this edge.
3 2
4
4 2 2
4 6
s 2 2 2 4 4 t
3
4
3 0
6 4 4
4
10
Notice that we’re
going back along one
1
of the backwards
2 2
edges we added. 4 4 2
2 2
s 1 t
4
4 3 2
4
2 4
6
Example of Ford-Fulkerson We will remove flow
from this edge AGAIN.
3 2
4
4 2 2
4 6
s 2 2 2 4 4 t
3
4
3 0
6 4 4
4
10
1
2 2
4 4 2
2
s
2 1 t
4
4 3 2
4
2 4
6
Example of Ford-Fulkerson We will remove flow
from this edge AGAIN.
3 3
4
4 1 3
4 6
s 2 2 3 4 4 t
3
5
3 1
6 4 4
5
10

3 1
4 5 3
1
s
2 t
4
5 2 3
1 4
1 5
5
Example of Ford-Fulkerson
3 3
4
4 1 3
4 6
s 2 2 3 4 4 t
3
5
3 1
6 4 4
5
10
3
1
4 5 3
1
s
2 t
3 4
5 2 4
1
1 5
5
Example of Ford-Fulkerson
3 3
4
4 1 3
4 6
s 2 2 3 4 4 t
3
5 Max flow and min
3 1 cut are both 11.
6 4 4
5
10
3
1
4 5 3
1
s
2 t
3 4
There’s no path 5 2 4
from s to t, and
1
1 5
here’s the cut to
prove it. 5
What have we learned?
• Max s-t flow is equal to min s-t cut!
• The USSR and the USA were trying to
solve the same problem…
• The Ford-Fulkerson algorithm can
find the min-cut/max-flow.
• Repeatedly improve your flow along
an augmenting path.
• How long does this take???
Why should we be concerned?
Suppose we just picked paths arbitrarily.
Choose a really
a
C big number C.
C
0
0
0
1
t
s
C
0 C 0
a
b
C
C
1 t
s
C C
b
Why should we be concerned?
Suppose we just picked paths arbitrarily.
Choose a really
a
C big number C.
C
0
0
0
1
t
s
C
0 C 0
a
b
C
C
1 t
s
C C
b
Why should we be concerned?
Suppose we just picked paths arbitrarily.
Choose a really
a
C big number C.
C
1
0
1
1
t
s
C
1 C 0
a 1
b

C
C-1
1
The edge (b,a) disappeared s 1 t
from the residual graph!
C
C-1 b
Why should we be concerned?
Suppose we just picked paths arbitrarily.
Choose a really
a
C big number C.
C
1
0
1
1
t
s
C
1 C 0
a 1
b

C
C-1
1
t
s 1
C
C-1 b
Why should we be concerned?
Suppose we just picked paths arbitrarily.
Choose a really
a
C big number C.
C
1
1
0
1
t
s
C
1 C 1
a 1
b
1

C-1 C-1
The edge (b,a) re-appeared 1 t
s 1 1
in the residual graph!
C-1 b
C-1
Why should we be concerned?
Suppose we just picked paths arbitrarily.
Choose a really
a
C big number C.
C
1
1
0
1
t
s
C
1 C 1
a 1
b
1

C-1 C-1
1 t
s 1 1

C-1 b
C-1
Why should we be concerned?
Suppose we just picked paths arbitrarily.
Choose a really
a
C big number C.
C
2
1
1
1
t
s
C
2 C 1
a 2
b
1

C-1 C-2
1
The edge (b,a) disappeared s 2 t
1
from the residual graph!
C-2 b
C-1
Why should we be concerned?
Suppose we just picked paths arbitrarily.
Choose a really
a
C big number C.
C
2
1 This will go on for C steps,
1 adding flow along (b,a) and
1
t
s
C then subtracting it again.
2 C 1
a 2
b
1

C-1 C-2
1
The edge (b,a) disappeared s 2 t
1
from the residual graph!
C-2 b
C-1
Doing Ford-Fulkerson with BFS is called
the Edmonds-Karp algorithm.
Theorem
• If you use BFS, the Ford-Fulkerson algorithm runs in
time O(nm2). Doesn’t have anything to do with the edge weights!

• We will skip the proof in class.


• Basic idea:
• The number of times you remove an edge from the residual
graph is O(n).
• This is the hard part
• There are at most m edges.
• Each time we remove an edge we run BFS, which takes time
O(n+m).
• Actually, O(m), since we don’t need to explore the whole graph, just
the stuff reachable from s.
One more useful thing
• If all the capacities are integers, then the flows in
any max flow are also all integers.
• When we update flows in Ford-Fulkerson, we’re only
ever adding or subtracting integers.
• Since we started with 0 (an integer), everything stays
integral.
But wait, there’s more!
• Min-cut and max-flow are not just useful for the
USA and the USSR in 1955.
• An important algorithmic primitive!
• The Ford-Fulkerson algorithm is the basis for many
other graph algorithms.
• For the rest of today, we’ll see a few:
• Maximum bipartite matching
• Integer assignment problems

Some of the following material shamelessly stolen from Jeff Erickson’s excellent lecture notes:
http://jeffe.cs.illinois.edu/teaching/algorithms/2009/notes/17-maxflowapps.pdf
Maximum matching in bipartite graphs

• Different students only


want certain items of
Stanford swag (depending
on fit, style, etc).

• How can we make as


many students as possible
happy?

Stanford Students Stanford Swag


Maximum matching in bipartite graphs

• Different students only


want certain items of
Stanford swag (depending
on fit, style, etc).

• How can we make as


many students as possible
happy?

Stanford Students Stanford Swag


All edges have
Solution via max flow capacity 1.

s t

Stanford Students Stanford Swag


All edges have
Solution via max flow capacity 1.
1

1
1
1
1
s 1 t
1
1
1
1
1
1

Stanford Students Stanford Swag


Solution via max flow All edges have
why does this work? capacity 1.
4. The value of the
1. Because the
flow is the size of the
capacities are all 1 matching.
integers, so are the
flows – so they are 1
either 0 or 1. 1
1
1 Value of this
s 1 t
flow is 4.
1
1
1
1
1
1

2. Stuff in = stuff out 5. We conclude that


means that the number 3. Thus, the edges with flow on the max flow
of items assigned to them form a matching. (And, any corresponds to a
each student 0 or 1. matching gives a flow). maximal matching.
(And vice versa).
A slightly more complicated example:
assignment problems
• One set X
• Example: Stanford students
• Another set Y
• Example: tubs of ice cream
• Each x in X can participate in c(x) matches.
• Student x can only eat 4 scoops of ice cream.
• Each y in Y can only participate in c(y) matches.
• Tub of ice cream y only has 10 scoops in it.
• Each pair (x,y) can only be matched c(x,y) times.
• Student x only wants 3 scoops of flavor y
• Student x’ doesn’t want any scoops of flavor y’
• Goal: assign as many matches as possible.
How can we serve as much ice cream as possible?
Example
This person wants 4
scoops of ice cream, at 1 6
most 1 of chocolate 4
and at most 3 coffee. 3

3
3
3
1

1 1 10
5
10 3
10
This person is vegan 2
and not that hungry; 2
they only want two
6
scoops of the sorbet.
Stanford Students Tubs of ice cream
Solution via max flow
1

3
6
4
3 3
3
1
s 1 10
t
1
10
5
3
2
10 6
2

Stanford Students Tubs of ice cream


Give this person 1
Solution via max flow scoop of this ice cream.

1
1
3 4
4 3 6
4
3 3
3 3
3 3
1
s 1 10
1 1 3 t
1
7 10 1
5
1 3
2 6
2
2 10 6
2 6

Stanford Students Tubs of ice cream


No more than 3
scoops of sorbet
Solution via max flow can be assigned.

1 1
3 4
4 3 6
4
3 3
3 3 3
3
1
s 1 10
1 1 3 t
1
7 10 1
5
1 3
2 6
2
This student can 6
2 10
have flow at most
10 going in, and so 2 6
at most 10 going
out, so at most 10
scoops assigned.
As before, flows correspond to assignments, and
max flows correspond to max assignments.
What have we learned?
• Max flows and min cuts aren’t just for railway routing.
• Immediately, they apply to other sorts of routing too!
• But also they are useful for assigning items to Uni students!
Recap
• Today we talked about s-t cuts and s-t flows.
• The Min-Cut Max-Flow Theorem says that minimizing
the cost of cuts is the same as maximizing the value of
flows.
• The Ford-Fulkerson algorithm does this!
• Find an augmenting path
• Increase the flow along that path
• Repeat until you can’t find any more paths and then you’re
done!
• An important algorithmic primitive!
• eg, assignment problems.
NEXT LECTURE
• NP-Completeness
• P, NP, NP Hard
• Hamiltonian cycles
• Satisfiability (3-sat)

83

You might also like