0% found this document useful (0 votes)
5 views

19-flow2

This document discusses the Ford-Fulkerson algorithm for computing maximum flow in a network, detailing its correctness through the max-flow min-cut theorem. It explains the relationship between flows and cuts, introduces the flow value lemma, and presents theorems regarding maximum flow and minimum cut. Additionally, it addresses the running time of the algorithm and considerations for improving efficiency.

Uploaded by

Phương Lê Thu
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)
5 views

19-flow2

This document discusses the Ford-Fulkerson algorithm for computing maximum flow in a network, detailing its correctness through the max-flow min-cut theorem. It explains the relationship between flows and cuts, introduces the flow value lemma, and presents theorems regarding maximum flow and minimum cut. Additionally, it addresses the running time of the algorithm and considerations for improving efficiency.

Uploaded by

Phương Lê Thu
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/ 76

COMPSCI 311: Introduction to Algorithms

Lecture 19: Network Flow

Ghazaleh Parvini

University of Massachusetts Amherst


Review: Ford-Fulkerson Algorithm

▷ Augment flow as long as it is possible


while there exists an s-t path P in redisual graph Gf do
f = Augment(f , P )
update Gf
end while
return f

Pearson Demo

Correctness: relate maximum flow to minimum cut


Step 3: F-F returns a maximum flow

We will prove this by establishing a deep connection between flows


and cuts in graphs: the max-flow min-cut theorem.
Step 3: F-F returns a maximum flow

We will prove this by establishing a deep connection between flows


and cuts in graphs: the max-flow min-cut theorem.
▶ An s-t cut (A, B) is a partition of the nodes into sets A and B
where s ∈ A, t ∈ B
Step 3: F-F returns a maximum flow

We will prove this by establishing a deep connection between flows


and cuts in graphs: the max-flow min-cut theorem.
▶ An s-t cut (A, B) is a partition of the nodes into sets A and B
where s ∈ A, t ∈ B
▶ Capacity of cut (A, B) equals
X
c(A, B) = c(e)
e from A to B
Step 3: F-F returns a maximum flow

We will prove this by establishing a deep connection between flows


and cuts in graphs: the max-flow min-cut theorem.
▶ An s-t cut (A, B) is a partition of the nodes into sets A and B
where s ∈ A, t ∈ B
▶ Capacity of cut (A, B) equals
X
c(A, B) = c(e)
e from A to B

▶ Flow across a cut (A, B) equals


X X
f (A, B) = f (e) − f (e)
e out of A e into A
Example of Cut

12/12
v1 v2
15/20
11/16

s 1/4 t
4/9 7/7

8/13 4/4
v3 v4
11/14

Exercise: write capacity of cut and flow across cut.


Example of Cut

12/12
v1 v2
15/20
11/16

s 1/4 t
4/9 7/7

8/13 4/4
v3 v4
11/14

Exercise: write capacity of cut and flow across cut.


Capacity is 29 and flow across cut is 19.
Clicker Question
What is the capacity of the cut and the flow across the cut?

Capacity Flow
A. 16+4+9+14 11+1+3+11
B. 16+4 -9+14 11+1 -4+11
C. 16+4+14 11+1 -4+11
D. 16+4+14 11+1+11

12/12
v1 v2
15/20
11/16

s 1/4 t
4/9 7/7

8/13 4/4
v3 v4
11/14
Flow Value Lemma

First relationship between cuts and flows

Lemma: let f be any flow and (A, B) be any s-t cut. Then

X X
v(f ) = f (e) − f (e)
e out of A e into A
Flow Value Lemma

First relationship between cuts and flows

Lemma: let f be any flow and (A, B) be any s-t cut. Then

X X
v(f ) = f (e) − f (e)
e out of A e into A

Proof: see book. Basic idea is to use conservation of flow:


all the flow out of s must leave A eventually.
Corollary: Cuts and Flows

Really important corollary of flow-value lemma

Corollary: Let f be any s-t flow and let (A, B) be any s-t cut.
Then v(f ) ≤ c(A, B).
Corollary: Cuts and Flows

Really important corollary of flow-value lemma

Corollary: Let f be any s-t flow and let (A, B) be any s-t cut.
Then v(f ) ≤ c(A, B).
Proof:
Corollary: Cuts and Flows

Really important corollary of flow-value lemma

Corollary: Let f be any s-t flow and let (A, B) be any s-t cut.
Then v(f ) ≤ c(A, B).
Proof: X X
v(f ) = f (e) − f (e)
e out of A e into A
Corollary: Cuts and Flows

Really important corollary of flow-value lemma

Corollary: Let f be any s-t flow and let (A, B) be any s-t cut.
Then v(f ) ≤ c(A, B).
Proof: X X
v(f ) = f (e) − f (e)
e out of A e into A
X
≤ f (e)
e out of A
Corollary: Cuts and Flows

Really important corollary of flow-value lemma

Corollary: Let f be any s-t flow and let (A, B) be any s-t cut.
Then v(f ) ≤ c(A, B).
Proof: X X
v(f ) = f (e) − f (e)
e out of A e into A
X
≤ f (e)
e out of A
X
≤ c(e)
e out of A
Corollary: Cuts and Flows

Really important corollary of flow-value lemma

Corollary: Let f be any s-t flow and let (A, B) be any s-t cut.
Then v(f ) ≤ c(A, B).
Proof: X X
v(f ) = f (e) − f (e)
e out of A e into A
X
≤ f (e)
e out of A
X
≤ c(e)
e out of A
= c(A, B)
Duality

Illustration on board
Duality

Illustration on board

Claim If there is a flow f ∗ and cut (A∗ , B ∗ ) such that


v(f ∗ ) = c(A∗ , B ∗ ), then
▶ f ∗ is a maximum flow
▶ (A∗ , B ∗ ) is a minimum cut
Clicker

Suppose f is a flow, and there is a path from s to u in Gf , but no


path from s to v in Gf . Then
A. There is no edge from u to v in G.
B. If there is an edge from u to v in G then f does not send any
flow on this edge.
C. If there is an edge from u to v in G then f fully saturates it
with flow.
D. None of the above.
Clicker

Suppose f is a flow, and there is a path from s to u in Gf , but no


path from s to v in Gf . Then
A. There is no edge from v to u in G.
B. If there is an edge from v to u in G then f does not send any
flow on this edge.
C. If there is an edge from v to u in G then f fully saturates it
with flow.
D. None of the above.
F-F returns a maximum flow

Theorem: The s-t flow f returned by F-F is a maximum flow.


F-F returns a maximum flow

Theorem: The s-t flow f returned by F-F is a maximum flow.

▶ Since f is the final flow there are no residual paths in Gf .


F-F returns a maximum flow

Theorem: The s-t flow f returned by F-F is a maximum flow.

▶ Since f is the final flow there are no residual paths in Gf .


▶ Let (A, B) be the s-t cut where A consists of all nodes
reachable from s in the residual graph.
F-F returns a maximum flow

Theorem: The s-t flow f returned by F-F is a maximum flow.

▶ Since f is the final flow there are no residual paths in Gf .


▶ Let (A, B) be the s-t cut where A consists of all nodes
reachable from s in the residual graph.
▶ Any edge out of A must have f (e) = c(e) otherwise there
would be more nodes than just A that reachable from s.
F-F returns a maximum flow

Theorem: The s-t flow f returned by F-F is a maximum flow.

▶ Since f is the final flow there are no residual paths in Gf .


▶ Let (A, B) be the s-t cut where A consists of all nodes
reachable from s in the residual graph.
▶ Any edge out of A must have f (e) = c(e) otherwise there
would be more nodes than just A that reachable from s.
▶ Any edge into A must have f (e) = 0 otherwise there would be
more nodes than just A that reachable from s.
F-F returns a maximum flow

Theorem: The s-t flow f returned by F-F is a maximum flow.

▶ Since f is the final flow there are no residual paths in Gf .


▶ Let (A, B) be the s-t cut where A consists of all nodes
reachable from s in the residual graph.
▶ Any edge out of A must have f (e) = c(e) otherwise there
would be more nodes than just A that reachable from s.
▶ Any edge into A must have f (e) = 0 otherwise there would be
more nodes than just A that reachable from s.
▶ Therefore
X X
v(f ) = f (e) − f (e)
e out ofA e intoA
F-F returns a maximum flow

Theorem: The s-t flow f returned by F-F is a maximum flow.

▶ Since f is the final flow there are no residual paths in Gf .


▶ Let (A, B) be the s-t cut where A consists of all nodes
reachable from s in the residual graph.
▶ Any edge out of A must have f (e) = c(e) otherwise there
would be more nodes than just A that reachable from s.
▶ Any edge into A must have f (e) = 0 otherwise there would be
more nodes than just A that reachable from s.
▶ Therefore
X X
v(f ) = f (e) − f (e)
e out ofA e intoA
X
= c(e)
e out ofA
F-F returns a maximum flow

Theorem: The s-t flow f returned by F-F is a maximum flow.

▶ Since f is the final flow there are no residual paths in Gf .


▶ Let (A, B) be the s-t cut where A consists of all nodes
reachable from s in the residual graph.
▶ Any edge out of A must have f (e) = c(e) otherwise there
would be more nodes than just A that reachable from s.
▶ Any edge into A must have f (e) = 0 otherwise there would be
more nodes than just A that reachable from s.
▶ Therefore
X X
v(f ) = f (e) − f (e)
e out ofA e intoA
X
= c(e) = c(A, B)
e out ofA
F-F finds a minimum cut
Theorem: The cut (A, B) where A is the set of all nodes reachable
from s in the residual graph is a minimum-cut.

12
v1 v2
11 19

5 9 1
Gf s 1 3 7 t
1

3 4
12
v3 v4

11
F-F finds a minimum cut
Theorem: The cut (A, B) where A is the set of all nodes reachable
from s in the residual graph is a minimum-cut.

12
v1 v2
11 19

5 9 1
Gf s 1 3 7 t
1

3 4
12
v3 v4

11

12/12
v1 v2
19/20
11/16

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

12/13 4/4
v3 v4
11/14
F-F finds a minimum cut

Capacity 163,000 tons per day [Harris and Ross 1955]


,000 tons per day [Harris and Ross 1955] \end{center}
Ford-Fulkerson Running Time
Ford-Fulkerson Running Time

▶ Flow increases at least one unit per iteration


Ford-Fulkerson Running Time

▶ Flow increases at least one unit per iteration


▶ F-F terminates in at most C iterations, where C is the sum of
capacities leaving source.
Ford-Fulkerson Running Time

▶ Flow increases at least one unit per iteration


▶ F-F terminates in at most C iterations, where C is the sum of
capacities leaving source.
▶ C ≤ n Cmax , where Cmax = maximum edge capacity
Ford-Fulkerson Running Time

▶ Flow increases at least one unit per iteration


▶ F-F terminates in at most C iterations, where C is the sum of
capacities leaving source.
▶ C ≤ n Cmax , where Cmax = maximum edge capacity
▶ Running time: O(m n Cmax )
Ford-Fulkerson Running Time

▶ Flow increases at least one unit per iteration


▶ F-F terminates in at most C iterations, where C is the sum of
capacities leaving source.
▶ C ≤ n Cmax , where Cmax = maximum edge capacity
▶ Running time: O(m n Cmax )

Is this polynomial?
Ford-Fulkerson Running Time

▶ Flow increases at least one unit per iteration


▶ F-F terminates in at most C iterations, where C is the sum of
capacities leaving source.
▶ C ≤ n Cmax , where Cmax = maximum edge capacity
▶ Running time: O(m n Cmax )

Is this polynomial? pseudo-polynomial (exponential in log Cmax )


Running-Time Example

u
What is the smallest number of
augment operations with which
C C
Ford-Fulkerson can find a
maximum-flow in this graph?
s 1 t
A. 1
C C B. 2
C. 3
v D. C
Improving Running Time

u
Good path choice will find:
s → u → t, flow C
C C
s → v → t, flow C
s 1 t

C C

v
Improving Running Time

u
Good path choice will find:
s → u → t, flow C
C C
s → v → t, flow C
s 1 t Worst-case: keep incrementing by 1:
s → u → v → t, flow 1
C C s → v → u → t, flow 1
s → u → v → t, flow 1
v ...
Improving Running Time

u
Good path choice will find:
s → u → t, flow C
C C
s → v → t, flow C
s 1 t Worst-case: keep incrementing by 1:
s → u → v → t, flow 1
C C s → v → u → t, flow 1
s → u → v → t, flow 1
v ...

Solution: choose good augmenting paths, with


Improving Running Time

u
Good path choice will find:
s → u → t, flow C
C C
s → v → t, flow C
s 1 t Worst-case: keep incrementing by 1:
s → u → v → t, flow 1
C C s → v → u → t, flow 1
s → u → v → t, flow 1
v ...

Solution: choose good augmenting paths, with


▶ Large enough bottleneck capacity: capacity-scaling algorithm
Improving Running Time

u
Good path choice will find:
s → u → t, flow C
C C
s → v → t, flow C
s 1 t Worst-case: keep incrementing by 1:
s → u → v → t, flow 1
C C s → v → u → t, flow 1
s → u → v → t, flow 1
v ...

Solution: choose good augmenting paths, with


▶ Large enough bottleneck capacity: capacity-scaling algorithm
▶ Fewest edges: Edmonds-Karp, Dinitz
Capacity-scaling algorithm

Idea: ignore edges with small capacity at first


Capacity-scaling algorithm

Idea: ignore edges with small capacity at first


u
u

107 102
107 102

s t
s 1 t

105 108
105 108

v
v
Gf (∆) for ∆ = 100. Def: only
original residual graph Gf
edges with residual capacity ≥ ∆
Capacity-scaling algorithm

Start with large ∆, divide by two in each phase


Capacity-scaling algorithm

Start with large ∆, divide by two in each phase


let f (e) = 0 for all e ∈ E
let ∆ = largest power of 2 ≤ Cmax
Capacity-scaling algorithm

Start with large ∆, divide by two in each phase


let f (e) = 0 for all e ∈ E
let ∆ = largest power of 2 ≤ Cmax
Capacity-scaling algorithm

Start with large ∆, divide by two in each phase


let f (e) = 0 for all e ∈ E
let ∆ = largest power of 2 ≤ Cmax
while ∆ ≥ 1 do
Capacity-scaling algorithm

Start with large ∆, divide by two in each phase


let f (e) = 0 for all e ∈ E
let ∆ = largest power of 2 ≤ Cmax
while ∆ ≥ 1 do
prune residual graph Gf to Gf (∆)
Capacity-scaling algorithm

Start with large ∆, divide by two in each phase


let f (e) = 0 for all e ∈ E
let ∆ = largest power of 2 ≤ Cmax
while ∆ ≥ 1 do
prune residual graph Gf to Gf (∆)
while there is augmenting s ⇝ t path P in Gf (∆) do
Capacity-scaling algorithm

Start with large ∆, divide by two in each phase


let f (e) = 0 for all e ∈ E
let ∆ = largest power of 2 ≤ Cmax
while ∆ ≥ 1 do
prune residual graph Gf to Gf (∆)
while there is augmenting s ⇝ t path P in Gf (∆) do
f = Augment(f, P )
Capacity-scaling algorithm

Start with large ∆, divide by two in each phase


let f (e) = 0 for all e ∈ E
let ∆ = largest power of 2 ≤ Cmax
while ∆ ≥ 1 do
prune residual graph Gf to Gf (∆)
while there is augmenting s ⇝ t path P in Gf (∆) do
f = Augment(f, P )
update Gf (∆) ▷ only ce ≥ ∆
Capacity-scaling algorithm

Start with large ∆, divide by two in each phase


let f (e) = 0 for all e ∈ E
let ∆ = largest power of 2 ≤ Cmax
while ∆ ≥ 1 do
prune residual graph Gf to Gf (∆)
while there is augmenting s ⇝ t path P in Gf (∆) do
f = Augment(f, P )
update Gf (∆) ▷ only ce ≥ ∆
end while
Capacity-scaling algorithm

Start with large ∆, divide by two in each phase


let f (e) = 0 for all e ∈ E
let ∆ = largest power of 2 ≤ Cmax
while ∆ ≥ 1 do
prune residual graph Gf to Gf (∆)
while there is augmenting s ⇝ t path P in Gf (∆) do
f = Augment(f, P )
update Gf (∆) ▷ only ce ≥ ∆
end while
∆ = ∆/2 ▷ refine
end while
Capacity-Scaling: Running Time

▶ How many scaling phases?


Capacity-Scaling: Running Time

▶ How many scaling phases? Θ(log Cmax )


Capacity-Scaling: Running Time

▶ How many scaling phases? Θ(log Cmax )


▶ How much does the flow increase at every augmentation?
Capacity-Scaling: Running Time

▶ How many scaling phases? Θ(log Cmax )


▶ How much does the flow increase at every augmentation? ≥ ∆
Capacity-Scaling: Running Time

▶ How many scaling phases? Θ(log Cmax )


▶ How much does the flow increase at every augmentation? ≥ ∆
Capacity-Scaling: Running Time

▶ How many scaling phases? Θ(log Cmax )


▶ How much does the flow increase at every augmentation? ≥ ∆
▶ How many augmentations per phase?
Capacity-Scaling: Running Time

▶ How many scaling phases? Θ(log Cmax )


▶ How much does the flow increase at every augmentation? ≥ ∆
▶ How many augmentations per phase? ≤ 2m
Capacity-Scaling: Running Time

▶ How many scaling phases? Θ(log Cmax )


▶ How much does the flow increase at every augmentation? ≥ ∆
▶ How many augmentations per phase? ≤ 2m
▶ Can show: at end of ∆ phase, flow value within m∆ of max.
Capacity-Scaling: Running Time

▶ How many scaling phases? Θ(log Cmax )


▶ How much does the flow increase at every augmentation? ≥ ∆
▶ How many augmentations per phase? ≤ 2m
▶ Can show: at end of ∆ phase, flow value within m∆ of max.
=⇒ at most 2m iterations ∆/2 phase
Capacity-Scaling: Running Time

▶ How many scaling phases? Θ(log Cmax )


▶ How much does the flow increase at every augmentation? ≥ ∆
▶ How many augmentations per phase? ≤ 2m
▶ Can show: at end of ∆ phase, flow value within m∆ of max.
=⇒ at most 2m iterations ∆/2 phase
▶ (Sketch) Construct cut (A, B) as in max-flow / min-cut
theorem.
Capacity-Scaling: Running Time

▶ How many scaling phases? Θ(log Cmax )


▶ How much does the flow increase at every augmentation? ≥ ∆
▶ How many augmentations per phase? ≤ 2m
▶ Can show: at end of ∆ phase, flow value within m∆ of max.
=⇒ at most 2m iterations ∆/2 phase
▶ (Sketch) Construct cut (A, B) as in max-flow / min-cut
theorem.
▶ Edges from A to B are within ∆ of being saturated.
Capacity-Scaling: Running Time

▶ How many scaling phases? Θ(log Cmax )


▶ How much does the flow increase at every augmentation? ≥ ∆
▶ How many augmentations per phase? ≤ 2m
▶ Can show: at end of ∆ phase, flow value within m∆ of max.
=⇒ at most 2m iterations ∆/2 phase
▶ (Sketch) Construct cut (A, B) as in max-flow / min-cut
theorem.
▶ Edges from A to B are within ∆ of being saturated.
▶ Edges from B to A carry less than ∆ flow.
Capacity-Scaling: Running Time

▶ How many scaling phases? Θ(log Cmax )


▶ How much does the flow increase at every augmentation? ≥ ∆
▶ How many augmentations per phase? ≤ 2m
▶ Can show: at end of ∆ phase, flow value within m∆ of max.
=⇒ at most 2m iterations ∆/2 phase
▶ (Sketch) Construct cut (A, B) as in max-flow / min-cut
theorem.
▶ Edges from A to B are within ∆ of being saturated.
▶ Edges from B to A carry less than ∆ flow.
▶ =⇒ Cut capacity at most m∆ more than flow value.

▶ Recall: time to find augmenting path?


Capacity-Scaling: Running Time

▶ How many scaling phases? Θ(log Cmax )


▶ How much does the flow increase at every augmentation? ≥ ∆
▶ How many augmentations per phase? ≤ 2m
▶ Can show: at end of ∆ phase, flow value within m∆ of max.
=⇒ at most 2m iterations ∆/2 phase
▶ (Sketch) Construct cut (A, B) as in max-flow / min-cut
theorem.
▶ Edges from A to B are within ∆ of being saturated.
▶ Edges from B to A carry less than ∆ flow.
▶ =⇒ Cut capacity at most m∆ more than flow value.

▶ Recall: time to find augmenting path? O(m)


▶ Overall: O(m2 log Cmax ), polynomial
Running Times

▶ Basic F-F: O(mnCmax ) pseudo-polynomial


▶ polynomial in magnitude
Running Times

▶ Basic F-F: O(mnCmax ) pseudo-polynomial


▶ polynomial in magnitude

▶ Capacity-scaling: O(m2 log Cmax ) polynomial


▶ polynomial in number of bits
Running Times

▶ Basic F-F: O(mnCmax ) pseudo-polynomial


▶ polynomial in magnitude

▶ Capacity-scaling: O(m2 log Cmax ) polynomial


▶ polynomial in number of bits

▶ Edmonds-Karp: O(m2 n) strongly-polynomial


▶ does not depend on values, only m, n
Running Times

▶ Basic F-F: O(mnCmax ) pseudo-polynomial


▶ polynomial in magnitude

▶ Capacity-scaling: O(m2 log Cmax ) polynomial


▶ polynomial in number of bits

▶ Edmonds-Karp: O(m2 n) strongly-polynomial


▶ does not depend on values, only m, n

▶ Dinitz: O(mn2 ) even better


Running Times

▶ Basic F-F: O(mnCmax ) pseudo-polynomial


▶ polynomial in magnitude

▶ Capacity-scaling: O(m2 log Cmax ) polynomial


▶ polynomial in number of bits

▶ Edmonds-Karp: O(m2 n) strongly-polynomial


▶ does not depend on values, only m, n

▶ Dinitz: O(mn2 ) even better

▶ Edmonds-Karp and Dinitz: choose short augmenting paths

You might also like