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

Algorithm Class Lecture 4

Algorithm Class lecture 4

Uploaded by

minjoopjjm
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)
31 views

Algorithm Class Lecture 4

Algorithm Class lecture 4

Uploaded by

minjoopjjm
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/ 31

CSE 347 Lecture 4

Maximum flow

1
Ship cement from factory to building
20 10

20
s t
Factory 10 20
Building
Input: site
𝒔: source; 𝒕: destination
Graph with directed edges
weights on each edge: capacity
Goal: Ship as much stuff as possible while obeying
capacity constraints.
2
Solution

20 10 20 10

20 20
s t s t
10 20 10 20

3
Maximum Flow Problem
Graph: (𝑉, 𝐸) directed and weighted
• Unique source and sink nodes à 𝑠, 𝑡
• Each edge has capacity 𝑐(𝑒) [Integer]
A valid flow assignment assigns an integer 𝑓(𝑒) to each edge s.t.
Capacity constraint: 0 ≤ 𝑓 𝑒 ≤ 𝑐 𝑒
Flow conservation: ∑!∈#!" (%) 𝑓 𝑒 = ∑!∈##$% (%) 𝑓(𝑒), ∀𝑣 ∈ 𝑉 −
𝑠, 𝑡
𝐸'( (𝑣): set of incoming edges to 𝑣
𝐸)*+ 𝑣 : set of outgoing edges from 𝑣
Compute: Maximum Flow: Find a valid flow assignment to
Maximize 𝐹 = ∑ 𝑓 𝑒 =∑ 𝑓 𝑒
!∈# (,) !∈# (+)
)*+ '(
4
Additional assumptions
1. 𝑠 has no incoming edges, 𝑡 has no outgoing edges
2. You do not have a cycle of 2 nodes

u v

5
A proposed algorithm:
1. Find a path from 𝑠 to 𝑡
2. Push as much flow along the path as possible
3. Adjust the capacities
4. Repeat until we cannot find a path

6
A proposed algorithm
1. Find a path from 𝑠 to 𝑡
2. Push as much flow along the path
3. Adjust the capacities
4. Repeat until we cannot find a path

20 10

20
s t s t
10 20

s t s t
7
Does it always get us the maximum flow?

20 10

20
s t s t
10 20

8
What now?
Greedy?
Dynamic Programming?

9
Let’s fix it:

Residual Graph: If there is an edge 𝑒 = 𝑢, 𝑣 in 𝐺, we


will add a back edge 𝑒̅ = (𝑣, 𝑢). Capacity of 𝑒̅ = flow
on 𝑒. Call this graph 𝐺! .
Initialize:

20 10

20
s t
10 20

10
Augmenting Paths Algorithm:
Algorithm:
• Find an “augmenting path” 𝑃.
• 𝑃 can contain forward or backward edges!
• Say the smallest residual capacity along the path is 𝑘.
• Push k flow on the path (𝑓 𝑒 = 𝑓 𝑒 + 𝑘 for all
edges on path 𝑃)
• Reduce the capacity of all edges on the path 𝑃 by k
• Increase the capacity of the corresponding
mirror/back edges
Repeat until there are no augmenting paths
11
Execution of Algorithm

20 10

20
s t s t
10 20

s t s t

12
Formalize: Ford-Fulkerson(FF)
Algorithm
1. Initialize the residual graph 𝐺! = 𝐺
2. Find an augmenting path 𝑃 with capacity 𝑘
3. Fix up the residual capacities in 𝐺!
– 𝑐 𝑒 =
– 𝑐 𝑒̃ =
4. Repeat 2 and 3 until no augmenting path can be
found in 𝐺!

13
Proof of Correctness: Valid Flow
Lemma 1: FF finds a valid flow
– Capacity and conservation constraints are not violated
– Capacity constraint: 0 ≤ 𝑓 𝑒 ≤ 𝑐 𝑒
– Flow conservation: ∑!∈#!"(%) 𝑓 𝑒 = ∑!∈##$%(%) 𝑓(𝑒),
∀𝑣 ∈ 𝑉 − 𝑠, 𝑡
Proof: Induct on augmenting paths
– Base Case: 𝑓 𝑒 = 0 on all edges

14
Inductive Case
Lemma 1: FF finds a valid flow
Inductive Hypothesis:

Inductive Step:

15
Inductive Case
Capacity Constraints: Consider an edge 𝑒 in 𝑃
(a) If 𝑒 is a forward edge (in the original graph)

(b) If 𝑒 is a back edge with residual capacity ≥ 𝑘

16
Inductive Case
Conservation Constraints: Consider a vertex 𝑣 on path 𝑃

(a) Both forward edges

(b) Both back edges

(c) Redirecting flow

(d) Similar to (c)


17
Proof of Correctness: Termination
Lemma 2: FF terminates
Proof:

18
Runtime of Ford-Fulkerson Algorithm
Runtime:
(time to find a path) × (number of augmenting paths)

Food for thought: Is this indeed polynomial time?

19
Proof of Correctness: Optimality
From Lemma 1 and 2, we know that FF returns a feasible
solution, but does it return the maximum flow?
Max-flow Min-cut Theorem!
• Given a graph 𝐺(𝑉, 𝐸), a graph cut is a partition of
vertices into 2 subsets.
– 𝑺: 𝑠 + maybe some other vertices
– 𝑽 − 𝑺: 𝑡 + maybe some other vertices

20
Graph Cut
Graph cut: a partition of vertices into 2 subsets.
𝑺 = 𝑠 + maybe some other vertices
𝑽 − 𝑺 = 𝑻 = 𝑡 + maybe some other vertices
a

s t s t

21
Graph Cut
Graph cut: a partition of vertices into 2 subsets.
𝑺: 𝑠 + maybe some other vertices
𝑽 − 𝑺 = 𝑻: 𝑡 + maybe some other vertices
Define the cut by 𝑺.
Capacity of the cut:

sum of capacity of edges that go from a vertex in 𝑆 to a


vertex in 𝑇.

22
Cut Capacity
Capacity: 𝐶 𝑆 = ∑"∈$,&∈' 𝑐(𝑢, 𝑣)

20 10

20

s t
10 20

23
Max-flow Min-cut Theorem
Lemma: For all valid flows 𝑓, 𝑓 ≤ 𝐶(𝑆) for all cut 𝑆.
Proof:

Min-cut: cut of smallest capacity, 𝑆 ∗ . 𝑓 ≤ 𝐶(𝑆 ∗ )


Lemma: FF produces a flow = 𝐶(𝑆 ∗ )

24
Max-flow Min-cut Theorem
Min-cut: cut of smallest capacity, 𝑆 ∗ . 𝑓 ≤ 𝐶(𝑆 ∗ )
Lemma: FF produces a flow = 𝐶(𝑆 ∗ )
Proof: Let 𝒇B be the flow found by FF. No augmenting
paths in 𝐺! .
𝒔D : all vertices that can be reached from s using edges with
capacities > 0.

25
Max-flow Min-cut Theorem
• All edges going out of this cut is saturated.
• All real edges out of this cut are saturated (residual
capacity = 0).
• No flow is going into the cut 𝑆. Why?

H so FF produces the max-flow!


• 𝐶 𝑆 ∗ = |𝑓|,
26
New Problem: Bipartite Matching
• n classes and n rooms; we want to match classes to
rooms.

27
New Problem: Bipartite Matching
• Bipartite graph 𝐺 = (𝑉, 𝐸) (unweighted and undirected)
– Vertices are either in set L or R
– Edges only go between vertices of different sets
• Matching: A subset of edges 𝑀 ⊆ 𝐸 s.t.
– Each vertex has at least one edge from M incident on it.
• Maximum Matching: matching of the largest size.
• We will reduce the problem to the problem of finding
the maximum flow

28
Reduction
• Given a bipartite graph 𝐺 = 𝑉, 𝐸 , construct a graph
𝐺 / = 𝑉 / , 𝐸 / s.t.

29
Proof of Correctness
Claim: G’ has a flow of k iff G has a matching of size k
Proof: Two directions:
Direction 1:

Direction 2:

Corollary: 30
Conclusion: Maximum Flow
• Problem input and target
• Ford-Fulkerson Algorithm
– Execution: residual graph
– Runtime
• FF correctness proof
– Max-flow Min-cut Theorem
– Graph Cut definition
– Capacity of cut
• Reduction to Bipartite Matching

31

You might also like