Presentation is loading. Please wait.

Presentation is loading. Please wait.

TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)

Similar presentations


Presentation on theme: "TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)"— Presentation transcript:

1 TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)

2 TU/e Algorithms (2IL15) – Lecture 8 2 3 / Flow network  directed graph with source and sink, and capacities on the edges  if (u,v) in E then we cannot have (v,u) in E Flow in a network  must satisfy capacity constraints and “flow in = flow out”  value of flow: |f | = ∑ v in V f (s,v) − ∑ v in V f (v,s) 10 2 3 3 51 3 2 s t 2 / 3 / 4 / 2 / 1 / 2 / 1 / flow / capacity 1 /3 value = 4+3−1 = 6 5

3 TU/e Algorithms (2IL15) – Lecture 8 3 augmenting path Ford-Fulkerson: increase flow using augmenting paths in residual network 2 / 2 3 5 3 6 5 1 2 2 s t 3 0 / 2 / 5 / 0 / 5 / 0 / 6 1 1 1 1 s t 2 2 1 2 1 2 5 5 3 1 5 flow network residual network: contains edges with residual capacity > 0  residual capacity of original edge (u,v): c f (u,v) = c(u,v) – f (u,v)  residual capacity of reverse edge (v,u): c f (v,u) = f (u,v)

4 TU/e Algorithms (2IL15) – Lecture 8 4 Ford-Fulkerson ( G, s, t )  Initialize flow: set f (u,v) = 0 for each pair (u,v) in V x V  Construct residual network G f  while there is an augmenting path p in the residual network G f  do // increase flow by augmenting flow along p  c f (p) ← residual capacity of the path p  for each edge (u,v) on the path p  do if (u,v) in E  then f (u,v) ← f (u,v) + c f (p)  else f (v,u) ← f (v,u) − c f (p)  Update the residual network G f  return f need algorithm to find path between two given vertices (s and t)

5 TU/e Algorithms (2IL15) – Lecture 8 5 Properties of Ford-Fulkerson:  Invariant: flow is valid  Flow increases at each iteration Questions:  Are we sure we have max flow when algorithm terminates ? want to prove: no augmenting path max flow to prove this we have to look at cuts  Are we sure it always terminates? not guaranteed if capacities are irrational and augmenting paths are chosen in the “wrong” way  How many iterations before termination (no augmenting path) ?

6 TU/e Algorithms (2IL15) – Lecture 8 6 Cuts of flow network G = (V,E) cut (S,T) = partitioning of V into subsets S and T, with s in S and t in T flow f (S,T) across cut (S,T) = ∑ u in S ∑ v in T f(u,v) − ∑ u in S ∑ v in T f(v,u) = ( 2 + 2 + 3 + 1 ) − ( 1 + 1 ) = 6 capacity c(S,T) of cut (S,T) = max flow across the cut = ∑ u in S ∑ v in T c(u,v) = ( 2 + 3 + 3 + 5 ) = 13 10 2 5 3 2 51 3 2 s t 3 2 / 3 / 4 / 2 / 1 / 2 / 1 / 0 /

7 TU/e Algorithms (2IL15) – Lecture 8 7 Max-flow min-cut Theorem: Let f be a flow in a flow network G. Then the following conditions are equivalent: (i) f is a maximum flow in G (ii) residual network G f contains no augmenting path (iii) there is a cut (S,T) with |f | = c(S,T) Consequence: maximum flow = capacity of minimum cut This implies: if Ford-Fulkerson terminates it has found max flow Lemma: Flow across any cut is the same, and equals the value of the flow.

8 TU/e Algorithms (2IL15) – Lecture 8 8 Properties of Ford-Fulkerson:  Invariant: flow is valid  Flow increases at each iteration Questions:  Are we sure we have max flow when algorithm terminates ? want to prove: no augmenting path max flow  Are we sure it always terminates? not guaranteed if capacities are irrational and augmenting paths are chosen in the “wrong” way  How many iterations before termination (no augmenting path) ?

9 TU/e Algorithms (2IL15) – Lecture 8 9 round 0: send flow 1 Example where Ford-Fulkerson is not guaranteed to terminate flow network initial residual network st 2 4 1 3 σ 1 σ = (√5 -1) / 2 ≈ 0.61… so σ j+2 = σ j − σ j+1 for all j 1 st 2 4 1 3 σ 1 1 other edges have capacity C ≥ 2  max flow = 1 + 2C

10 TU/e Algorithms (2IL15) – Lecture 8 10 residual network after zero-th round st 2 4 1 3 σ = σ 1 1=σ 0 other rounds: 4 iterations each Invariant: after k-th round  total flow = 1 + 2 ∑ 1≤i ≤ 2k σ i  res.cap. (2,1) = σ 2k  res.cap (2,3) = 0  res.cap. (4,3) = σ 2k+1 st 2 4 1 3 σ 1 1 σ = (√5 -1) / 2 ≈ 0.61… so σ j+2 = σ j − σ j+1 for all j total flow after zero-th round: 1

11 TU/e Algorithms (2IL15) – Lecture 8 11 first iteration: send flow σ 2k+1 st 2 4 1 3 σ 2k+1 σ 2k second iteration: send flow σ 2k+1 st 2 4 1 3 0 σ 2k+2 σ 2k+1 residual capacity of original edge before iteration st 2 4 1 3 σ 1 1 σ = (√5 -1) / 2 ≈ 0.61… so σ j+2 = σ j − σ j+1 for all j 0 total flow: … + σ 2k+1 total flow: … + 2σ 2k+1

12 TU/e Algorithms (2IL15) – Lecture 8 12 third iteration: send flow σ 2k+2 second iteration: send flow σ 2k+1 st 2 4 1 3 0 σ 2k+2 σ 2k+1 st 2 4 1 3 σ 1 1 σ = (√5 -1) / 2 ≈ 0.61… so σ j+2 = σ j − σ j+1 for all j st 2 4 1 3 0 σ 2k+1 σ 2k+2 total flow: … + 2σ 2k+1 total flow: … + 2σ 2k+1 + σ 2k+2

13 TU/e Algorithms (2IL15) – Lecture 8 13 fourth iteration: send flow σ 2k+2 third iteration: send flow σ 2k+2 st 2 4 1 3 σ 1 1 σ = (√5 -1) / 2 ≈ 0.61… so σ j+2 = σ j − σ j+1 for all j st 2 4 1 3 0 σ 2k+1 σ 2k+2 st 2 4 1 3 σ 2k+3 0 σ 2k+2 total flow: … + 2σ 2k+1 + σ 2k+2 total flow: … + 2σ 2k+1 + 2σ 2k+2

14 TU/e Algorithms (2IL15) – Lecture 8 14 fourth iteration: send flow σ 2k+2 st 2 4 1 3 σ 1 1 σ = (√5 -1) / 2 ≈ 0.61… so σ j+2 = σ j − σ j+1 for all j st 2 4 1 3 0 σ 2k+3 σ 2k+2 st 2 4 1 3 σ 2k+3 0 σ 2k+2 after fourth iteration total flow: … + 2σ 2k+1 + 2σ 2k+2

15 TU/e Algorithms (2IL15) – Lecture 8 15 residual network after (k+1)-st round other rounds: 4 iterations each Invariant: after k-th round  total flow = 1 + 2 ∑ 1≤i ≤ 2k σ i  res.cap. (2,1) = σ 2k  res.cap (2,3) = 0  res.cap. (4,3) = σ 2k+1 st 2 4 1 3 σ 1 1 σ = (√5 -1) / 2 ≈ 0.61… so σ j+2 = σ j − σ j+1 for all j st 2 4 1 3 0 σ 2k+3 σ 2k+2 total flow: … + 2σ 2k+1 + 2σ 2k+2  total flow converges to 1 + 2(1+ σ) < 1 + 2C  Ford-Fulkerson does not terminate

16 TU/e Algorithms (2IL15) – Lecture 8 16 Ford-Fulkerson for integral capacities  Invariant: flow is always integral  Flow increases at each iteration Then number of iterations ≤ OPT ( = value of max flow ) How much time do we need for one iteration?  Find s-to-t path in G f : O(|E|) Theorem: On flow network G=(V,E) with integral capacities, Ford-Fulkerson runs in time O( OPT∙ |E| ), where OPT is the value of a maximum flow.

17 TU/e Algorithms (2IL15) – Lecture 8 17  Can’t we get a running time that does not depend on OPT ?  What about non-integral capacities? We should not use just any augmenting path, but a specific one: Edmonds-Karp: always use shortest augmenting path (one with minimum number of edges)

18 TU/e Algorithms (2IL15) – Lecture 8 18 Lemma: The distances δ f (s,v) for v ≠ s,t do not decrease when flow is augmented (and, hence, G f is modified) in the Edmonds-Karp algorithm. Proof. Assume not true. f = flow before the augmentation g = flow after augmentation v = vertex with minimum δ g (s,v) whose distance decreases Claim 1: δ f (s,u) ≤ δ g (s,u) Claim 2: (u,v) not in E f Proof of Claim 2: otherwise δ f (s,v) ≤ δ f (s,u) + 1 ≤ δ g (s,u) + 1 = δ g (s,v) δ f (s,v) = distance from s to v in G f su v shortest path in G g

19 TU/e Algorithms (2IL15) – Lecture 8 19 shortest path in G g Lemma: The distances δ f (s,v) for v ≠ s,t do not decrease when flow is augmented (and, hence, G f is modified) in the Edmonds-Karp algorithm. Proof. Assume not true. f = flow before the augmentation g = flow after augmentation v = vertex with minimum δ g (s,v) whose distance decreases Claim 1: δ f (s,u) ≤ δ g (s,u) Claim 2: (u,v) not in E f But then augmentation has increased flow along (v,u) and we get δ f (s,v) = δ f (s,u) − 1 ≤ δ g (s,u) − 1 = δ g (s,v) − 2 su v shortest path in G f δ f (s,v) = distance from s to v in G f contradiction

20 TU/e Algorithms (2IL15) – Lecture 8 20 Theorem: The number of iterations in Edmonds-Karp is O( |V |∙ |E| ). Proof. Definition: (u,v) is critical in G f if Claim: If (u,v) is critical in G f and later in G g then δ g (s,u) ≥ δ f (s,u) + 2 Proof of Claim:  if (u,v) is critical in G f then δ f (s,v) = δ f (s,u) + 1 and (u,v) disappears  if (u,v) re-appears when G h is handled, then (v,u) on augmenting path and so δ h (s,u) = δ h (s,v) + 1  Hence δ g (s,u) ≥ δ h (s,u) = δ h (s,v) + 1 ≥ δ f (s,v) + 1 = δ f (s,u) + 2 su v t augmenting path: c f (u,v) = c f (p) because distances never decrease

21 TU/e Algorithms (2IL15) – Lecture 8 21 Theorem: The number of iterations in Edmonds-Karp is O ( |V |∙ |E| ). Proof. Definition: (u,v) is critical in G f if Claim: If (u,v) is critical in G f and later in G g then δ g (s,u) ≥ δ f (s,u) + 2  min distance = 0  max distance is |V|−2 su v t augmenting path: c f (u,v) = c f (p) (u,v) can be critical at most |V | / 2 times at most 2 |E| ∙ ( |V |/2 ) = |E| ∙ |V | iterations

22 TU/e Algorithms (2IL15) – Lecture 8 22 Theorem: The running time of Edmonds-Karp is O ( |V |∙ |E| 2 ). There are faster algorithms for max flow  push-relabel algorithm with relabel-to-front: O( |V | 3 ) (in book)  or O( |V |∙ |E| log ( |V | 2 / |E|) ), or …

23 TU/e Algorithms (2IL15) – Lecture 8 23 Applications of Max-Flow: some examples  “robustness” of s-to-t connectivity  maximum bipartite matching  assigning jobs  … Many applications are based on the following lemma. Lemma. Let G=(V,E) be a flow network with integral capacities. Then there exists a max flow such that the flow along every edge is integral, and the Ford-Fulkerson method computes such a flow.

24 TU/e Algorithms (2IL15) – Lecture 8 24 Applications of Max Flow: example I “Robustness” of s-to-t paths

25 TU/e Algorithms (2IL15) – Lecture 8 25 “Robustness” of s-to-t connectivity  G = (V,E) directed graph  s, t: two nodes in the graph Question: how many edge-disjoint simple paths are there from s to t ? s t

26 TU/e Algorithms (2IL15) – Lecture 8 26 How many edge-disjoint simple paths are there from s to t ? s t  Turn G into flow network G* by assigning capacity 1 to every edge (and removing vertices that are not on any s-to-t path).  Compute max flow f in G* using Ford-Fulkerson method. NB: Ford-Fulkerson method computes integral flow  If only max number of edge-disjoint paths is required, then return |f | else compute paths themselves using f. 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 flow = 1flow = 0

27 TU/e Algorithms (2IL15) – Lecture 8 27 Lemma. Max number of edge-disjoint s-to-t paths in G = value of max flow in G*. Proof.  If we have M edge-disjoint paths, we can send 1 unit of flow along each path: −capacity constraint −flow in = flow out Hence, max number of edge-disjoint paths ≤ value of max flow  For any integral flow f, we can find |f | edge-disjoint simple paths (next slides). Hence, max number of edge-disjoint paths ≥ value of max flow NB Max number of edge-disjoint paths = min number of edges to be destroyed to disconnect s and t. (Follows from max flow = min cut)

28 TU/e Algorithms (2IL15) – Lecture 8 28 Finding edge-disjoint simple paths from an integral flow f  Let G = (V,E ) be the directed graph containing edges with flow =1.  x ← |f | // x = number of disjoint paths we can still find  while x > 0  do Find a simple s-to-t path in G.  Remove edges on the path from G.  x ← x − 1 s t 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 flow = 1flow = 0 Question: do we have flow=0 for every edge after algorithm?

29 TU/e Algorithms (2IL15) – Lecture 8 29 “Robustness” of s-to-t connectivity Question: What if we also want vertex-disjointness (except at s and t) ?

30 TU/e Algorithms (2IL15) – Lecture 8 30 Applications of Max Flow: example II Maximum matching in bipartite graphs

31 TU/e Algorithms (2IL15) – Lecture 8 31 G = (V,E) undirected graph Matching: subset M E such that no two edges have a common vertex U Maximum matching = matching with maximum number of edges ( Maximal matching = matching to which we cannot add another edge matching can be maximal without being maximum )

32 TU/e Algorithms (2IL15) – Lecture 8 32 The maximum-matching problem  compute a maximum matching for a given graph G  we will study the problem for bipartite graphs G = (V,E) where V = L U R LR

33 TU/e Algorithms (2IL15) – Lecture 8 33 t Maximum matching for bipartite graphs  Turn graph G into a flow network G*  Compute max flow in G* with integral flow values { (u,v): u in L and v in R and f (u,v) = 1 } is maximum matching LR s 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

34 TU/e Algorithms (2IL15) – Lecture 8 34 Applications of Max Flow: example III Assigning jobs to people

35 TU/e Algorithms (2IL15) – Lecture 8 35 Assigning jobs to people  J 1, …, J n set of n jobs  P 1, …, P m set of m people  each person P j has a list L j of jobs that they are able to do  no person is allowed to do more than, say, 3 jobs Questions:  can jobs be assigned such that all jobs are done ?  if yes, compute such an assignment  if not, would it help if jobs can be shared? ( condition: if some person does part β i of J i, then ∑ i β i ≤ 3 )

36 TU/e Algorithms (2IL15) – Lecture 8 36 Modeling the problem as a “matching” problem construct bipartite graph G = ( L U R, E ) P1P1 P2P2 P3P3 P4P4 J1J1 J2J2 J3J3 J4J4 J5J5  L = { P 1, …, P m } set of people  R = { J 1, …, J m } set of jobs  E = { (P j, J i ) : person P j can do job J i } When can all jobs be done such that no person does more than three jobs?  “matching” where each P i is incident to at most 3 edges and each J j to exactly 1 edge

37 TU/e Algorithms (2IL15) – Lecture 8 37 t Solving the matching problem  Turn graph G into a flow network G*  Compute max flow in G* with integral flow values all jobs can be done if and only if s 1 1 1 1 1 1 1 1 1 3 3 1 1 3 3 P1P1 P2P2 P3P3 P4P4 J1J1 J2J2 J3J3 J4J4 J5J5 value of max flow = # jobs

38 TU/e Algorithms (2IL15) – Lecture 8 38 Lemma. All jobs can be done if and only if value of max flow = # jobs. Proof.  Suppose all jobs can be done. // argue there exists flow f with |f | = # jobs, and that f is maximal  Suppose value of max flow = # jobs. Then there is integral f with |f | = # jobs. If edge (P j, J i ) has flow 1 in f, then assign J i to P j Each J i is assigned to exactly one person because −out-flow of J i is 1 (otherwise total flow cannot be equal to # jobs) −flow in = flow out −flow is integral Each person P j is assigned at most three jobs, because −incoming flow is at most 3 −flow is integral

39 TU/e Algorithms (2IL15) – Lecture 8 39 Assigning jobs to people  J 1, …, J n set of n jobs  P 1, …, P m set of m people  each person P j has a list L j of jobs that they are able to do  no person is allowed to do more than, say, 3 jobs Questions:  can jobs be assigned such that all jobs are done ? check using max flow  if yes, compute such an assignment assign J i to P j if flow between them  if not, would it help if jobs can be shared? no: there is always an integral max flow

40 TU/e Algorithms (2IL15) – Lecture 8 40 Max-Flow Summary Flow network  directed graph with source and sink, and capacities on the edges  if (u,v) in E then we cannot have (v,u) in E Flow in a network  must satisfy capacity constraints and “flow in = flow out” Ford-Fulkerson method  iteratively increase flow using augmenting paths in residual graph  Edmonds-Karp variant: use shortest augment path  number of iterations O( |V| ∙ |E| )  running time O( |V| ∙ |E| 2 ) Relation between flows and cuts  for any flow f, the net flow across any cut is the same and equals |f |  Max flow = min cut Applications of max flow:  often use that if all capacities are integral then there exists a max flow that is integral everywhere (and Ford-Fulkerson method computes such a flow)


Download ppt "TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)"

Similar presentations


Ads by Google