6.4 ford-fulkerson demo - depaul...
TRANSCRIPT
Algorithms, 4th Edition · Robert Sedgewick and Kevin Wayne · Copyright © 2002–2011 · February 23, 2012 4:05:54 PM
AlgorithmsF O U R T H E D I T I O N
R O B E R T S E D G E W I C K K E V I N W A Y N E
6.4 FORD-FULKERSON DEMO
click to begin demo
2
‣ Ford-Fulkerson algorithm‣ computing a min cut
Initialization. Start with 0 flow.
Ford-Fulkerson algorithm
3
s t
0 / 4
0 / 40 / 15
0 / 10 0 / 15
0 / 15
0 / 10
0 / 10
0 / 9
0 / 15
0 / 8
0 / 6
0 / 16
initialization
0 / 5 0
value of flow
0 / 10
flow capacity
Augmenting path. Find an undirected path from s to t such that:
• Can increase flow on forward edges (not full).
• Can decrease flow on backward edge (not empty).
Idea: increase flow along augmenting paths
4
0 / 4
0 / 40 / 15
0 / 15
0 / 15 0 / 10
0 / 9
0 / 8
0 / 6
0 / 16
s t
0 / 10 0 / 15
0 / 100 / 5
1st augmenting path
0
0 / 10
Augmenting path. Find an undirected path from s to t such that:
• Can increase flow on forward edges (not full).
• Can decrease flow on backward edge (not empty).
Idea: increase flow along augmenting paths
4
0 / 4
0 / 40 / 15
0 / 15
0 / 15 0 / 10
0 / 9
0 / 8
0 / 6
0 / 16
s t
0 / 10 0 / 15
0 / 10
0 / 10 0 / 15
0 / 100 / 5
1st augmenting path
0
0 / 10
Augmenting path. Find an undirected path from s to t such that:
• Can increase flow on forward edges (not full).
• Can decrease flow on backward edge (not empty).
Idea: increase flow along augmenting paths
4
0 / 4
0 / 40 / 15
0 / 15
0 / 15 0 / 10
0 / 9
0 / 8
0 / 6
0 / 16
s t
0 / 10 0 / 15
0 / 10
0 / 10 0 / 15
0 / 100 / 5
1st augmenting path
0
0 / 10
bottleneck capacity = 10
Augmenting path. Find an undirected path from s to t such that:
• Can increase flow on forward edges (not full).
• Can decrease flow on backward edge (not empty).
Idea: increase flow along augmenting paths
4
0 / 4
0 / 40 / 15
0 / 15
0 / 15 0 / 10
0 / 9
0 / 8
0 / 6
0 / 16
s t
0 / 10 0 / 15
0 / 10
0 / 10 0 / 15
0 / 10
10
10
10
—
—
—0 / 5
1st augmenting path
0 + 10 = 10
0 / 10
bottleneck capacity = 10
Augmenting path. Find an undirected path from s to t such that:
• Can increase flow on forward edges (not full).
• Can decrease flow on backward edge (not empty).
Idea: increase flow along augmenting paths
5
0 / 5
0 / 4
0 / 4
0 / 15
0 / 15
0 / 10
0 / 9
0 / 8
0 / 6
10 / 10 10 / 15
10 / 10s t
0 / 15 0 / 10
0 / 16
2nd augmenting path
10
Augmenting path. Find an undirected path from s to t such that:
• Can increase flow on forward edges (not full).
• Can decrease flow on backward edge (not empty).
Idea: increase flow along augmenting paths
5
0 / 5
0 / 4
0 / 4
0 / 15
0 / 15
0 / 10
0 / 9
0 / 8
0 / 6
10 / 10 10 / 15
10 / 10s t
0 / 15 0 / 10
0 / 16
0 / 15 0 / 10
0 / 16
2nd augmenting path
10
Augmenting path. Find an undirected path from s to t such that:
• Can increase flow on forward edges (not full).
• Can decrease flow on backward edge (not empty).
Idea: increase flow along augmenting paths
5
0 / 5
0 / 4
0 / 4
0 / 15
0 / 15
0 / 10
0 / 9
0 / 8
0 / 6
10 / 10 10 / 15
10 / 10s t
0 / 15 0 / 10
0 / 16
0 / 15 0 / 10
0 / 16
10
10
10
—
—
—
2nd augmenting path
10 + 10 = 20
Augmenting path. Find an undirected path from s to t such that:
• Can increase flow on forward edges (not full).
• Can decrease flow on backward edge (not empty).
Idea: increase flow along augmenting paths
6
0 / 4
0 / 4 0 / 150 / 6
10 / 10
10 / 10
10 / 15 10 / 10
10 / 16
s t0 / 5
0 / 10
0 / 9
0 / 8
10 / 15
3rd augmenting path
20
0 / 15
Augmenting path. Find an undirected path from s to t such that:
• Can increase flow on forward edges (not full).
• Can decrease flow on backward edge (not empty).
Idea: increase flow along augmenting paths
6
0 / 4
0 / 4 0 / 150 / 6
10 / 10
10 / 10
10 / 15 10 / 10
10 / 16
s t0 / 5
0 / 10
0 / 9
0 / 8
10 / 15
0 / 5
0 / 10
0 / 9
0 / 8
10 / 15
3rd augmenting path
20
0 / 15
backward edge
(not empty)
Augmenting path. Find an undirected path from s to t such that:
• Can increase flow on forward edges (not full).
• Can decrease flow on backward edge (not empty).
Idea: increase flow along augmenting paths
6
0 / 4
0 / 4 0 / 150 / 6
10 / 10
10 / 10
10 / 15 10 / 10
10 / 16
s t0 / 5
0 / 10
0 / 9
0 / 8
10 / 15
0 / 5
0 / 10
0 / 9
0 / 8
10 / 15
3rd augmenting path
20 + 5 = 255
—
5
—
5—
5—
5—
0 / 15
backward edge
(not empty)
Augmenting path. Find an undirected path from s to t such that:
• Can increase flow on forward edges (not full).
• Can decrease flow on backward edge (not empty).
Idea: increase flow along augmenting paths
7
0 / 4
0 / 4 0 / 15
10 / 10
10 / 105 / 5s t
0 / 6
5 / 10
5 / 9
5 / 8
5 / 15
10 / 1010 / 15
10 / 16
4th augmenting path
25
0 / 15
Augmenting path. Find an undirected path from s to t such that:
• Can increase flow on forward edges (not full).
• Can decrease flow on backward edge (not empty).
Idea: increase flow along augmenting paths
7
0 / 4
0 / 4 0 / 15
10 / 10
10 / 105 / 5s t
0 / 6
5 / 10
5 / 9
5 / 8
0 / 6
5 / 10
5 / 9
5 / 8
5 / 155 / 15
10 / 1010 / 15
10 / 15
10 / 1610 / 16
4th augmenting path
25
0 / 15
backward edge
(not empty)
Augmenting path. Find an undirected path from s to t such that:
• Can increase flow on forward edges (not full).
• Can decrease flow on backward edge (not empty).
Idea: increase flow along augmenting paths
7
0 / 4
0 / 4 0 / 15
10 / 10
10 / 105 / 5s t
0 / 6
5 / 10
5 / 9
5 / 8
0 / 6
5 / 10
5 / 9
5 / 8
5 / 155 / 15
10 / 1010 / 15
10 / 15
10 / 1610 / 16
4th augmenting path
25 + 3 = 288
—
2—
8—
8—
13—
13
—
3—
0 / 15
backward edge
(not empty)
Termination. All paths from s to t are blocked by either a
• Full forward edge.
• Empty backward edge.
Idea: increase flow along augmenting paths
8
no more augmenting paths
0 / 4
0 / 4 0 / 15
10 / 10
10 / 105 / 5s t
3 / 6
8 / 10
8 / 9
8 / 8
2 / 15
10 / 1013 / 15
28
13 / 16
0 / 15
full forward edge
empty backward edge
9
‣ Ford-Fulkerson algorithm‣ computing a min cut
To compute mincut (A, B) from maxflow f :
• By augmenting path theorem, no augmenting paths with respect to f.
• Compute A = set of vertices connected to s by an undirected pathwith no full forward or empty backward edges.
Computing a mincut from a maxflow
10
0 / 4
0 / 15
10 / 10
10 / 105 / 5 t
8 / 10
8 / 9
8 / 8
2 / 15
10 / 10
16 / 16
0 / 15
s
13 / 156 / 6
3 / 4
A
To compute mincut (A, B) from maxflow f :
• By augmenting path theorem, no augmenting paths with respect to f.
• Compute A = set of vertices connected to s by an undirected pathwith no full forward or empty backward edges.
Computing a mincut from a maxflow
10
0 / 4
0 / 15
10 / 10
10 / 105 / 5 t
8 / 10
8 / 9
8 / 8
2 / 15
10 / 10
16 / 16
0 / 15
ss
13 / 156 / 6
3 / 4
A
To compute mincut (A, B) from maxflow f :
• By augmenting path theorem, no augmenting paths with respect to f.
• Compute A = set of vertices connected to s by an undirected pathwith no full forward or empty backward edges.
Computing a mincut from a maxflow
10
forward edge
(not full)
0 / 4
0 / 15
10 / 10
10 / 105 / 5 t
8 / 10
8 / 9
8 / 8
2 / 15
10 / 10
16 / 16
0 / 15
ss
13 / 15
13 / 156 / 6
3 / 4
A
To compute mincut (A, B) from maxflow f :
• By augmenting path theorem, no augmenting paths with respect to f.
• Compute A = set of vertices connected to s by an undirected pathwith no full forward or empty backward edges.
Computing a mincut from a maxflow
10
forward edge
(not full)
0 / 4
0 / 15
10 / 10
10 / 105 / 5 t
8 / 10
8 / 9
8 / 8
2 / 15
10 / 10
16 / 16
0 / 15
ss
13 / 15
13 / 156 / 6
3 / 4
A
To compute mincut (A, B) from maxflow f :
• By augmenting path theorem, no augmenting paths with respect to f.
• Compute A = set of vertices connected to s by an undirected pathwith no full forward or empty backward edges.
Computing a mincut from a maxflow
10
forward edge
(not full)
backward edge
(not empty)
0 / 4
0 / 15
10 / 10
10 / 105 / 5 t
8 / 10
8 / 9
8 / 8
2 / 15
10 / 10
16 / 16
0 / 15
ss
13 / 15
13 / 156 / 6
3 / 43 / 4
A
To compute mincut (A, B) from maxflow f :
• By augmenting path theorem, no augmenting paths with respect to f.
• Compute A = set of vertices connected to s by an undirected pathwith no full forward or empty backward edges.
Computing a mincut from a maxflow
10
forward edge
(not full)
backward edge
(not empty)
0 / 4
0 / 15
10 / 10
10 / 105 / 5 t
8 / 10
8 / 9
8 / 8
2 / 15
10 / 10
16 / 16
0 / 15
ss
13 / 15
13 / 156 / 6
3 / 43 / 4
A
To compute mincut (A, B) from maxflow f :
• By augmenting path theorem, no augmenting paths with respect to f.
• Compute A = set of vertices connected to s by an undirected pathwith no full forward or empty backward edges.
Computing a mincut from a maxflow
10
forward edge
(not full)
backward edge
(not empty)
0 / 4
0 / 15
10 / 10
10 / 105 / 5 t
8 / 10
8 / 9
8 / 8
2 / 15
10 / 10
16 / 16
0 / 15
ss
13 / 15
13 / 156 / 66 / 6
3 / 43 / 4
A
To compute mincut (A, B) from maxflow f :
• By augmenting path theorem, no augmenting paths with respect to f.
• Compute A = set of vertices connected to s by an undirected pathwith no full forward or empty backward edges.
Computing a mincut from a maxflow
10
forward edge
(not full)
backward edge
(not empty)
0 / 4
0 / 15
10 / 10
10 / 105 / 5 t
8 / 10
8 / 9
8 / 8
2 / 15
10 / 10
16 / 16
0 / 15
ss
13 / 15
13 / 156 / 66 / 6
3 / 43 / 4
A
To compute mincut (A, B) from maxflow f :
• By augmenting path theorem, no augmenting paths with respect to f.
• Compute A = set of vertices connected to s by an undirected pathwith no full forward or empty backward edges.
Computing a mincut from a maxflow
10
forward edge
(not full)
backward edge
(not empty)
0 / 4
0 / 15
10 / 10
10 / 105 / 5 t
8 / 10
8 / 9
8 / 8
2 / 15
10 / 10
16 / 16
0 / 15
ss
13 / 15
13 / 156 / 66 / 6
3 / 43 / 4
full forward edge
empty backward edge
A