Presentation is loading. Please wait.

Presentation is loading. Please wait.

MAXIMUM flow by Eric Wengert.

Similar presentations


Presentation on theme: "MAXIMUM flow by Eric Wengert."— Presentation transcript:

1 MAXIMUM flow by Eric Wengert

2 Overview Flow network Maximum Flow Ford-Fulkerson method
Max-flow min cut theorem Edmund’s Karp algorithm Maximum bipartite matching Push Relabel Algorithm

3 Flow network A directed graph where material is produced at a source and consumed at a sink Each edge has a capacity Non-source, non-sink nodes have input equal to output S A B T C D

4 Maximum flow Optimization problem
Compute the greatest rate that material can be shipped from source to sink without violating capacity constraints A flow is maximum  its residual network contains no augmenting path

5 Ford-Fulkerson method(G,s,t)
Initialize flow f to 0 While there exists an augmenting path p in the residual network Gf augment flow f along p Return f Augmenting path – p is a simple path from s to t in the residual network Gf

6 Basic Ford-Fulkerson algorithm
For each edge (u,v) Є G,E (u,v).f = 0 # initialize edge flow to 0 While Ǝ a path p from s to t in residual network cf(p) = min{cf(u,v) : (u,v) is in p} #find min capacity for each edge (u,v) in p if (u,v) Є E (u,v).f = (u,v).f + cf(p) #add flow else (v,u).f = (v,u).f - cf(p)

7 Ford-Fulkerson method(G,s,t)
A B T C D 0/8 0/5 0/2 0/10 0/7

8 Ford-Fulkerson method(G,s,t)
A B T C D 0/8 0/5 0/2 0/10 0/7 Path S-C-D-B-T

9 Ford-Fulkerson method(G,s,t)
A B T C D 0/8 0/5 0/2 0/10 0/7 Path S-C-D-B-T Minimum capacity of 7

10 Ford-Fulkerson method(G,s,t)
A B T C D 7/8 0/5 0/2 0/10 7/7 7/10 Path S-C-D-B-T Minimum capacity of 7 Total flow: 7

11 Ford-Fulkerson method(G,s,t)
A B T C D 7/8 0/5 0/2 0/10 7/7 7/10 G Path S-C-D-B-T Minimum capacity of 7 Total flow: 7 Gf S A B T C D 7 5 2 10 0/10 1 3

12 Ford-Fulkerson method(G,s,t)
A B T C D 7/8 0/5 0/2 0/10 7/7 7/10 G Path S-C-D-T Minimum capacity of 1 Total flow: 7

13 Ford-Fulkerson method(G,s,t)
A B T C D 8/8 0/5 0/2 0/10 7/7 1/10 7/8 8/10 G Path S-C-D-T Minimum capacity of 1 Total flow: 8

14 Ford-Fulkerson method(G,s,t)
A B T C D 8/8 0/5 0/2 0/10 7/7 1/10 7/8 8/10 G Path S-C-D-T Minimum capacity of 1 Total flow: 8 Gf S A B T C D 8 5 2 10 7 9 1

15 Ford-Fulkerson method(G,s,t)
A B T C D 8/8 0/5 0/2 0/10 7/7 1/10 7/8 8/10 G Path S-A-B-T Minimum capacity of 5 Total flow: 8

16 Ford-Fulkerson method(G,s,t)
A B T C D 8/8 5/5 0/2 5/10 7/7 1/10 7/8 8/10 G Path S-A-B-T Minimum capacity of 5 Total flow: 8 1

17 Ford-Fulkerson method(G,s,t)
A B T C D 8/8 5/5 0/2 5/10 7/7 1/10 7/8 8/10 G Path S-A-B-T Minimum capacity of 5 Total flow: 8 Gf S A B T C D 8 5 2 10 7 9 1 1

18 Ford-Fulkerson method(G,s,t)
A B T C D 8/8 5/5 0/2 5/10 7/7 1/10 7/8 8/10 G Path S-A-B-T Minimum capacity of 5 Total flow: 8 Gf S A B T C D 8 5 2 10 7 9 1 for each edge (u,v) in p if (u,v) Є E (u,v).f = (u,v).f + cf(p) else (v,u).f = (v,u).f - cf(p) 1

19 Ford-Fulkerson method(G,s,t)
A B T C D 8/8 5/5 0/2 5/10 7/7 6/10 2/8 8/10 G Path S-A-B-T Minimum capacity of 5 Total flow: 13 Gf S A B T C D 8 5 2 7 4 6 5 6

20 Ford-Fulkerson method(G,s,t)
A B T C D 8/8 5/5 0/2 5/10 7/7 6/10 2/8 8/10 G Path S-A-C-D-T Minimum capacity of 2 Total flow: 13

21 Ford-Fulkerson method(G,s,t)
A B T C D 8/8 5/5 2/2 7/10 7/7 8/10 2/8 10/10 G Path S-A-C-D-T Minimum capacity of 2 Total flow: 15

22 Ford-Fulkerson method(G,s,t)
A B T C D 8/8 5/5 2/2 7/10 7/7 8/10 2/8 10/10 G Path S-A-C-D-T Minimum capacity of 2 Total flow: 15 Gf S A B T C D 8 5 2 3 7 10 6 7 8

23 Time complexity Find augmenting path O(E) Compute bottleneck capacity
Augment each edge and total flow Max number of iterations O(f) O(Ef)

24 Max-flow min-cut theorem
S A B T C D 8 5 2 7 10 G Total flow: 15 15 19 15 15

25 Edmonds-Karp algorithm
Ford-Fulkerson altered by finding the augmented path with a breadth-first search Choose shortest path from s to t in the residual network Time Complexity Breadth-first search O(E) Total number of flow augmentations O(VE) O(VE2)

26 Maximum bipartite matching

27 Maximum bipartite matching

28 Maximum bipartite matching
Finding a path from s to t using DFS or BFS O(E) Value of maximum flow to t O(V) O(VE)

29 Push Relabel Flow from higher point to lower point
Source is highest h = |v| Sink is lowest h = 0 Source pushes maximum flow onto edges Height increased to allow flow out Increasing the height is called relabel

30 Push Relabel algorithm
Initialize preflow to 0 While Ǝ an applicable push or relabel operation select an applicable push or relabel operation and perform it

31 Push Relabel S A B T C D h = 0 e = 0 h = 0 e = 0 0/12 0/15 0/5 0/10
0/3 0/17 0/8 0/6 h = 0 e = 0 h = 6 h = 0 e = 0 h = 0 e = 0

32 Push Relabel S A B T C D h = 0 e = 0 h = 0 e = 0 0/12 0/15 0/5 0/10
0/3 0/17 0/8 0/6 h = 0 e = 0 h = 6 h = 0 e = 0 h = 0 e = 0

33 Push Relabel S A B T C D Push flow from source and update excess flow
12/12 0/15 0/5 10/10 0/3 0/17 0/8 0/6 h = 0 e = 0 h = 6 h = 0 e = 12 h = 0 e = 0 Push flow from source and update excess flow

34 Push Relabel S A B T C D From C push flow to A, but A.h = C.h = 0
12/12 0/15 0/5 10/10 0/3 0/17 0/8 0/6 h = 6 h = 0 e = 12 e = 10 e = 0 From C push flow to A, but A.h = C.h = 0

35 Push Relabel S A B T C D relabel C.h =h h = 0 e = 10 e = 0 0/15 0/3
12/12 0/15 0/5 10/10 0/3 0/17 0/8 0/6 h = 6 h = 1 e = 12 h = 0 e = 10 e = 0 relabel C.h =h

36 Push Relabel S A B T C D Push 5 to A and update C.e and A.e h = 0
12/12 0/15 5/5 10/10 0/3 0/17 0/8 0/6 h = 0 e = 0 h = 6 h = 1 e = 7 h = 0 e = 0 Push 5 to A and update C.e and A.e

37 Push Relabel h = 0 e = 15 h = 0 e = 0 S A B T C D 12/12 0/15 5/5 10/10 0/3 0/17 0/8 6/6 h = 0 e = 0 h = 6 h = 2 e = 1 h = 0 e = 6 Push 6 to D and update C.e and D.e, relabel C.h = 2

38 Push Relabel S A B T C D Relabel C.h = 7, send -1 to S 1/12 0/15 5/5
10/10 0/3 0/17 0/8 6/6 h = 6 h = 7 e = 0 h = 0 e = 15 e = 6 11/12 Relabel C.h = 7, send -1 to S

39 Push Relabel S A B T C D Relabel A.h = 1, push 15 to B 1/12 0/15 5/5
10/10 0/3 0/17 0/8 6/6 h = 6 h = 7 e = 0 h = 1 e = 15 h = 0 e = 6 11/12 Relabel A.h = 1, push 15 to B

40 Push Relabel S A B T C D Relabel B.h = 1, push 3 to T 1/12 15/15 5/5
10/10 0/3 0/17 0/8 6/6 h = 6 h = 7 e = 0 h = 1 h = 0 e = 15 e = 6 11/12 Relabel B.h = 1, push 3 to T

41 Push Relabel S A B T C D Relabel B.h = 1, push 8 to T 1/12 15/15 5/5
10/10 3/3 0/17 0/8 6/6 h = 6 h = 7 e = 0 h = 1 e = 12 h = 0 e = 6 e = 3 11/12 Relabel B.h = 1, push 8 to T

42 Push Relabel S A B T C D Relabel B.h = 2, push 8 to D 1/12 15/15 5/5
10/10 3/3 0/17 8/8 6/6 h = 6 h = 7 e = 0 h = 1 h = 2 e = 4 h = 0 e = 14 e = 3 11/12 Relabel B.h = 2, push 8 to D

43 Push Relabel S A B T C D Push -4 to A 1/12 11/15 5/5 10/10 3/3 0/17
8/8 6/6 h = 6 h = 7 e = 0 h = 1 e = 4 h = 2 h = 0 e = 14 e = 3 11/12 4/15 Push -4 to A

44 Push Relabel S A B T C D 1/12 11/15 5/5 10/10 3/3 0/17 8/8 6/6 h = 6
11/12 4/15

45 Push Relabel S A B T C D Relabel D.h = 1, Push 14 to T 1/12 11/15 5/5
10/10 3/3 3/17 8/8 6/6 h = 6 h = 7 e = 0 h = 1 e = 4 h = 2 h = 0 e = 17 11/12 4/15 14/17 Relabel D.h = 1, Push 14 to T

46 Push Relabel S A B T C D 1/12 11/15 5/5 10/10 3/3 3/17 8/8 6/6 h = 6
11/12 4/15 14/17

47 Push Relabel S A B T C D Relabel A.h = 3, Push 4 to B 1/12 15/15 5/5
10/10 3/3 3/17 8/8 6/6 h = 6 h = 7 e = 0 h = 3 h = 2 e = 4 h = 1 h = 0 e = 17 11/12 14/17 Relabel A.h = 3, Push 4 to B

48 Push Relabel S A B T C D 1/12 15/15 5/5 10/10 3/3 3/17 8/8 6/6 h = 6 h = 7 e = 0 h = 3 h = 4 e = 4 h = 1 h = 0 e = 17 11/12 14/17 Relabel B.h = 4, Push -4 to A, back and forth until A.h = 7

49 Push Relabel S A B T C D Push -4 to S 1/12 11/15 5/5 4/10 3/3 3/17 8/8
6/6 h = 6 h = 7 e = 0 h = 1 h = 0 e = 17 11/12 14/17 4/15 6/10 Push -4 to S

50 Push Relabel time complexity
O(V2) Relabels O(VE) Saturating pushes O(V2E) Non-saturating pushes Data structures can be designed to pick and execute an operation in O(1) O(V2E) time complexity

51 References Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein, (3rd edition), Mc Graw Hill Ford Fulkerson method example Push Relabel example by Ditixa Vyas


Download ppt "MAXIMUM flow by Eric Wengert."

Similar presentations


Ads by Google