Presentation is loading. Please wait.

Presentation is loading. Please wait.

Instructor Neelima Gupta Edited by Divya Gaur(39, MCS '09) Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09)

Similar presentations


Presentation on theme: "Instructor Neelima Gupta Edited by Divya Gaur(39, MCS '09) Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09)"— Presentation transcript:

1 Instructor Neelima Gupta ngupta@cs.du.ac.in

2 Edited by Divya Gaur(39, MCS '09) Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09)

3 Edited by Divya Gaur(39, MCS '09) DOMAIN Depict flow of a material (liquid, gas, current) from source to sink. Source: Material generator. Sink: Final destination to receive material. Flow: Rate of flow of material. Conduit: Medium for material transfer (pipe, wires). Capacity: Maximum rate at which material can flow through conduit.

4 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) Goal To solve the Maximum Flow problem Compute greatest rate at which material can flow from source to sink subject to specified constraints.

5 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) TECHNIQUE Flow Network A directed graph depicting source, conduit, sink modeling the flow. Each directed edge represents conduit. Vertices are conduit conjunctions through which material flows but does not collect. At a vertex, Rate of inflow = rate of outflow.

6 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) NOTATIONS AND CONSTRAINTS Flow Network : G(V,E) Edge : (u,v) є E Capacity of edge: c(u, v) ≥ 0 If (u,v) does not belong to E the c(u,v) = 0 Source: s Sink: t Graph connected ie. |E| ≥|V| - 1

7 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) Flow in G a real valued function f: V X V → R satisfying constraints: Capacity Constraint: For all u,v є V, f(u,v) ≤ c(u,v) Flow from one vertex to another must not exceed given capacity. Skew Symmetry: For all u,v є V, f(u,v) = -f(v,u) Flow from a vertex u to a vertex is the negative of the flow in the reverse direction. Flow Conservation: For all u є V- {s,t} Σf(u,v) = 0 v є V

8 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) f(u,v) : Flow from u to v. It can be either positive, negative or zero. Value of flow |f| =Σf(u,v) = 0 : Total flow out of source. v є V Total flow out of a vertex V ≠ u, v =0 By Skew symmetry Σf(u,v) = 0 u є V for all v є V- {s,t} ie.. total flow into vertex =0. Total net flow at a vertex : Total positive flow leaving a vertex – Total positive flow entering a vertex. So by Flow Conservation property total net flow at a vertex =0

9 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) Flow Network S 12 34 T 18 14 16 15 19 20 54 : SOURCE : SINK S T IJ : K is Capacity K SINGLE SOURCE SINGLE SINK

10 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) MULTIPLE SOURCE MULTIPLE SINK s1 s2 s5 t3 t2 t1 s3 s4 10 5 8 14 11 2 12 7 18 20 15 3 6 13

11 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) Add a supersource s and directed edge (s,s i ) with c(s,s i ) = ∞ for each i=1,2,….,m Add a supersink t and directed edge (t i,t) with c(t i,t) = ∞ for each i =1,2,….,n To solve multiple source multiple sink problem

12 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) s1 s2 s5 t3 t2 t1 s3 s4 10 5 8 14 11 2 12 7 18 20 15 3 6 13 S T ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞

13 Edited by Divya Gaur(39, MCS '09) Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Instructor: Ms Neelima Gupta

14 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) Ford_Fulkerson(G,s,t) 1. initialize flow f to 0 2. while there exists augmenting path p 3. do augment f along p 4. return f

15 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) RESIDUAL NETWORK RESIDUAL CAPACITY OF (u,v) c f The amount of additional flow that can be pushed from u to v before exceeding c(u,v). c f = c(u,v) – f(u,v) Eg : - c(u,v)=10, f(u,v)=5 then flow can be increased by 5 units ie.. residual capacity = 5. RESIDUAL NETWORK OF G INDUCED BY f, G f G f =(V,E f ) where E f = {(u,v) є V X V: c f (u,v) > 0 } ie. Each edge of the residual network or residual edge can admit flow > 0.

16 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) AUGMENTING PATHS AUGMENTING PATH ( P) Path from s to t in residual network G f. The augmenting path admits additional positive flow from u to v within capacity constraint. The maximum amount by which flow can be increased on each edge in P is residual capacity of P, c f = min{c f (u,v): (u,v) is on P}. Example: if c f (u,v)=3 then the flow through each edge of p can be increased by 3 without violating capacity constraint.

17 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) ALGORITHM FORD_FULKERSON(G,s,t) 1. for each edge (u,v) є E[G] 2. do f[u,v] ← 0 3. f[v,u] ← 0 4. while there exists a path from s to t in G f 5. do c f (p) ← min{c(u,v) :(u,v) is in p} 6. for each edge (u,v) in p 7. do f[u,v] ← f[u,v] + c f (p) 8. f[u,v] ← - f[u,v]

18 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) DESCRIPTION OF ALGORITHM 1-3 initialise flow f to 0. 4-8 finds augmenting path p in residual network and augments flow f along p by residual capacity c f (p). When no augmenting path exists flow f is maximum.

19 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) EXECUTION OF BASIC FORD- FULKERSON ALGORITHM S 12 34 T 18 14 16 15 19 20 54 : SOURCE : SINK S T IJ : K is Capacity K

20 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) PATH CHOSEN :S 1 3 4 T S 12 34 T 18 14 16 15 19 20 54 MINIMUM CAPACITY IN THE PATH = 4

21 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) S 12 34 T 14 / 4 14 12 / 4 11 / 4 19 20 50 RESIDUAL GRAPH 4 4 4 4 C / F : Capacity / Flow a/b a = original capacity - minimum capacity of the selected path b = minimum capacity of the selected path c = b c

22 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) S 12 34 T 14 / 4 14 12 / 4 11 / 4 19 20 50 PATH CHOSEN:S 1 2 4 T MINIMUM CAPACITY IN THE PATH = 5

23 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) S 12 34 T 9 / 9 9 / 5 12 / 4 6 / 9 19 20 0/ 5 RESIDUAL GRAPH 5 9 C / F : Capacity / Flow 9 5 0/4

24 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) S 12 34 T 9 / 9 9 / 5 12 / 4 6 / 9 19 20 0/ 50 / 4 PATH CHOSEN : S 1 2 T MINIMUM CAPACITY IN THE PATH = 9

25 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) S 12 34 T 0 / 18 14 12 / 4 6 / 9 9 20 0/ 5 18 0/4 0/ 14 10 / 9 RESIDUAL GRAPH C / F : Capacity / Flow

26 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) S 12 34 T 0 \ 18 0 / 14 12 / 4 6 / 9 10 / 9 20 0/ 50 / 4 PATH CHOSEN :S 3 4 T MINIMUM CAPACITY IN THE PATH = 6

27 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) S 12 34 T 0 \ 18 0 / 14 6 / 10 15 10 / 9 14 / 6 0/ 50 / 4 RESIDUAL GRAPH C / F : Capacity / Flow 10 6 0 / 15

28 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) S 12 34 T 0 \ 18 0 / 14 6 / 10 10 / 9 14 / 6 0/ 50 / 4 0 / 15 PATH CHOSEN: S 3 4 2 T (BACKTRACKING) 5 MINIMUM CAPACITY IN THE PATH = 5

29 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) S 12 34 T 0 \ 18 0 / 14 1 / 15 14 9 / 11 00 / 4 0 / 15 11 15 / 0 5 5 / 14 RESIDUAL GRAPH C / F : Capacity / Flow Now the graph has no augmenting path, therefore the flow shown is the maximum flow. Maximum Flow :- 14+15 = 29

30 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) CUTS OF FLOW NETWORK Flow is maximum iff its residual network has no augmenting path. CUT(s,t) OF FLOW NETWORK G : A partition of V into S and T=V - S such that s є S and t є T. It is a collection of edges separating the network into S and T. If f is flow,then the net flow across the cut is f(S,T) and capacity is c(S,T). A minimum cut of network is cut with minimum capacity over all cuts of the network.

31 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) CUT S 12 34 T 0 \ 18 0 / 14 1 / 15 14 9 / 11 00 / 4 0 / 15 11 5 5 / 14

32 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) OPTIMALITY MAX FLOW MIN CUT THEOREM 1.f is maximum flow in G 2.G f contains no augmenting paths 3.|f| = c(S,T) for some cut(S,T) of G If the flow f* reported by the algorithm is optimal then there exists a cut C* on which residual capacity of cut = 0. The initial capacity of C* must have been f* and must have been utilised completely and hence residual capacity = 0. C* is a minimum cut since if another cut’s capacity is less than C*’s then it would not be possible to send f* flow. Optimality is achieved since otherwise some augmenting path would be present with capacity at least one.

33 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) ANALYSIS OF THE ALGORITHM Running time of the algorithm is O(f* X time to compute augmenting path). 1-3 take O(E) time. While loop is executed at most |f*| times since flow value increases by at least one unit in each iteration. Time to compute an augmenting path using BFS or DFS is O(E). Each iteration of the while loop hence takes O(E) time. Hence total running time of FORD FULKERSON is O(E |f*|).

34 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) f* can be very big as it depends on capacities. f* could be as big as Σc(u,v). Since it depends on the values of capacities so it is not polynomial in input size which is Σlog c i + E + V where c i ’s could be large. A DEEPER SIGHT INTO ANALYSIS

35 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) Running Time depends on how the augmenting path p is determined. If capacities are small and |f*| is small running time is good. Example illustrates effect on time with large |f*|.

36 Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09) Edited by Divya Gaur(39, MCS '09) Here max flow = 400. But if the first augmenting path is s->v 1 ->v 2 ->t, flow would be one and then choosing s-> v 2 -- > v 1 - >t in even numbered iterations and s->u->v->t in odd ones increases flow by just one in each iteration(total of 400 iterations) and perform a total of 400 augmentations.

37 Thanks to: Swati Vohra (29, MCS '09)

38 Edmonds Karp Algorithm Choose the shortest augmenting path from s to t in residual network. Path is shortest in terms of no. of edges. Critical edge :- minimum weight edge of an augmenting path. s u v t

39 Thanks to: Swati Vohra (29, MCS '09) Notations Initial graph :- G Flow in G form s to u: f Residual graph : G f $ f (u,v) :- shortest path distance from u to v in G f Flow in residual graph : f 1 (computed as shortest path over G f )

40 Thanks to: Swati Vohra (29, MCS '09) As f is the shortest distance from s to u so f <= f1 and $ f (s,u) <= $ f1 (s,u) V u. s uv t u f f1

41 Thanks to: Swati Vohra (29, MCS '09) Critical Edge If (u,v) is critical edge along augmenting path then : $ f (s,v) = $ f (s,u) +1 (edge) $ f (s,v) in G f increases monotonically with each flow augmentation. Once the flow is augmented, edge (u,v) disappears from the G f. s uv t

42 Thanks to: Swati Vohra (29, MCS '09) When (u,v) is not present in augmenting path s u v t

43 Thanks to: Swati Vohra (29, MCS '09) For having (u,v) back in augmenting path edge (v,u) must be present on augmenting path (v,u) need not to be critical s u v t

44 Thanks to: Swati Vohra (29, MCS '09) So, $ f1 (s,u) = $ f1 (s,v) +1 & $ f (s,v) = $ f (s,u) +1 $ f (s,v) <= $ f1 (s,v) Therefore, $ f1 (s,u) = $ f1 (s,v) +1 >=($ f (s,v) +1) = $ f (s,u) +2

45 Thanks to: Swati Vohra (29, MCS '09) Analysis In a critical edge (u,v), Distance of u from s initially is at least 0. Every time (u,v) edge becomes critical again distance of u from s increased by at least 2. Intermediate vertices on shortest path from s to u can’t contain s,u,t. (since (u,v) on the critical path means s != t). So until u becomes unreachable from s its distance is at most IVI-2. So every (u,v) edge can become critical at most (IVI-2)/2 times.

46 Thanks to: Swati Vohra (29, MCS '09) Pair of vertices that can have edge in G f = O(E) Each edge can become critical O(V) time. Total no. of critical edges = O(VE). Each iteration of Ford Fulkerson can be implemented in O(E) time when augmenting path is found by BFS so total running time of Edmonds Karp= O(VE^2).

47 Thanks to: Geetanjali Shivas (13,MCS '09)

48 Problem:- There is a set T of teachers with a set C of courses. A teacher can teach only some set of courses. Assign 1 teacher to 1 course. T C t1 t2. tm c1 c2.c3. cn

49 Thanks to: Geetanjali Shivas (13,MCS '09) Each teacher is to be assigned at most one course and each course is to be assigned at most one teacher. This is a bipartite graph Let teachers be 2 and courses be 3. t1 t2 c1 c2 c3

50 Thanks to: Geetanjali Shivas (13,MCS '09) Convert the problem into flow network problem in which flows corresponds to matchings. Let source s and sink t be new vertices. Draw an edge from source s to each vertices in T and from each vertices in C to sink t. Capacity of each edge from s to T, T to C, C to t is 1. In the end, each unit of flow will be equivalent to a match between a teacher and a course, so each edge will be assigned a capacity of 1. t 1

51 Thanks to: Geetanjali Shivas (13,MCS '09) t1 t2 c1 c2 c3 s t 1 1 1 1 1 1 1 1 1 The corresponding flow network

52 Thanks to: Geetanjali Shivas (13,MCS '09) Now if we assign t1 to c1, then t2 will not get any course and c2, c3 are also not assigned to any teachers. Therefore we select a subset E’ of edges such that no two edges resides on same vertex. We want to find the maximum edges. Q:- Why capacity from s to T cannot be taken more than 1? Ans:- If capacity from s to T is more than 1 then any vertex in T would be selected more than 1 time and matched more than once.

53 Thanks to: Geetanjali Shivas (13,MCS '09) Select the path s-t1-c1-t. t1 t2 c1 c2 c3 s t 0/1 1 1 1 1 1 1 1

54 Thanks to: Geetanjali Shivas (13,MCS '09) Now t2 is not having any course. But capacity from s to t2 is 1. Therefore we do backtracking. Now the new path is s-t2-c1-t1-c2-t. t1 t2 c1 c2 c3 s t 0/1 1 1 1 1

55 Thanks to: Geetanjali Shivas (13,MCS '09) Now t2 is assigned c1 and t1 is assigned to c2. Flow from t1to c2 is 1, t2 to c1 is 1. But residual capacity from t1 to c2 is 0 and t2 to c1 is 0. Total network flow is 2. Therefore teacher t1 is matched with course c2 and teacher t2 is matched with course c1.


Download ppt "Instructor Neelima Gupta Edited by Divya Gaur(39, MCS '09) Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09)"

Similar presentations


Ads by Google