5
ADA: 12. Max Flow5 The maxflow problem o find a flow of maximum value The mincut problem o find a cut of minimum capacity Two problems that appear very different but are actually two versions of the same question. Most of this part is about the theory and implementation of maxflow. Two Flow Problems

11
ADA: 12. Max Flow11 A cut is a partition of a flow network's vertices into two disjoint sets, with the source (s) in one set A and the sink (t) in the other set B. A cut's capacity is the sum of the capacities of the edges from A to B. The minimum cut ( mincut ) problem: find a cut of minimum capacity. 3. The Mincut Problem

13
ADA: 12. Max Flow13 Initialization. Start with a 0 flow on every edge. Find an augmenting path from s to t such that: o we can increase flow on forward edges (while they are not full) o we can decrease flow on backward edge (while they are not empty) 4. Ford-Fulkerson (FF) Algorithm initially flow value =0

14
ADA: 12. Max Flow14 First Augmenting Path

15
ADA: 12. Max Flow15 Second Augmenting Path

16
ADA: 12. Max Flow16 Third Augmenting Path

17
ADA: 12. Max Flow17 Fourth Augmenting Path

18
ADA: 12. Max Flow18 No more augmenting paths All paths from s to t are blocked by either: o a full forward edge, or o a empty backward edgeTermination maxflow = 28 mincut = 28

20
ADA: 12. Max Flow20 Residual networks also show how flow along an edge can be reduced o this is shown by having extra edges in Gf which are not in G To represent a possible decrease of a flow f(u,v) on an edge in G, the edge (v,u) is added to Gf. Its residual capacity is: cf(v, u) = f(u,v) Gf Edges for Reducing

22
ADA: 12. Max Flow22 A path from s to t in Gf is an aug­menting path in G which carries flow f. The flow amount can be increased along an augmenting path by the minimum amount cf( p) = min {c f (u,v)} cf(p) is the residual or bottleneck capacity – it is the most that the flow can be increased due to one or more of p's edges being used at full capacity. Augmenting Paths (u,v) ∈ p

24
ADA: 12. Max Flow24 The new flow in G that results from augmenting along path p by its bottleneck capacity 4. Edges carrying no flow, such as (v3, v2), are labeled only by their capacity. The residual network Gf version of this G graph. No more augmented paths can be added, so f is the maxflow (f = 23).

27
ADA: 12. Max Flow27 The figures on the next 2 slides show successive iterations of the FF while-loop. The left side shows the residual network Gf with the chosen augmenting path p drawn as a shaded thick line. The right side shows the new flow f in G that results from adding the bottleneck capacity of p (cf(p)). Executing of FF with a Residual Network

28
ADA: 12. Max Flow28 GfG

29
ADA: 12. Max Flow29 The last residual network has no augmenting paths, and so the flow f shown in (e) above is a maximum flow (f = 23).

30
ADA: 12. Max Flow30 In the worst case, the running time of FF is O(E · |f|), where f is the maxflow o in the worst case, the FF while loop will iterate f times since it's possible for the flow to increase by only I flow unit at a time (see example on the next slides) o finding a path can have varying execution times, but if DFS or BFS is used to find a path, the running time is O(V + E), or O(E) is a dense graph FF Running Time

31
ADA: 12. Max Flow31 The following example is designed so that each augmented path only increases the flow by 1 unit (i.e. the cf(p) is always 1). Worst Running Time

32
ADA: 12. Max Flow32 The Augmenting Paths FirstSecond

33
ADA: 12. Max Flow33 ThirdFourth many, many more

34
ADA: 12. Max Flow34 199th 200th (= maxflow)

35
ADA: 12. Max Flow35 This case is easily avoided by a choosing a better series of augmenting paths. Choosing Paths is Important Only two iterations are needed.

37
ADA: 12. Max Flow37 Edmonds and Karp's implementation of Ford- Fulkerson finds an augmenting path by using a breadth-first search. o the algorithm is slightly changed: a weight of 1 is assigned to every edge, not the edge's capacity It runs in O(V· E 2 ) time o this can be proved by counting the number of augmenting paths needed to find the maxflow (which is O(V· E) ) o the proof requires the monotonicity lemma 7. Edmonds-Karp Algorithm

38
ADA: 12. Max Flow38 Let d(v) = df(s, v) be the breadth-first distance from s (the source) to a vertex v in Gf o each edge has a weight of 1 Lemma. During the execution of Edmonds-Karp, d(v) increases monotonically ( only gets bigger ). Monotonicity Lemma

39
ADA: 12. Max Flow39 Suppose that augmenting a flow f on G produces a new flow f'. Let d′(v) = df'(s, v). We’ll show d′(v) ≥ d(v) by induction on d′(v) o we are proving that increased flow makes the shortest path distance bigger for every vertex v For the base case, d′(v) = 0 implies v = s (the source), and since d(s) = 0, we have d′(v) ≥ d(v). So the base case is true.Proof

40
ADA: 12. Max Flow40 For the inductive case, consider a breadth-first path s → …→ u → v in Gf' We must have d′(v) = d′(u) + 1, since subpaths of shortest paths are shortest paths (optimality). So, we have d′(u) ≥ d(u) by induction, because d′(v) > d′(u). (u, v) ∈ Ef' (because we assumed it; see above). But we have to consider two cases depending on whether (u, v) ∈ Ef or not.

43
ADA: 12. Max Flow43 Theorem. The number of flow augmentations in the Edmonds-Karp algorithm (Ford-Fulkerson with breadth-first augmenting paths) is O(V· E). Proof. Let p be an augmenting path, and suppose that we have cf(u, v) = cf(p) for edge (u, v) ∈ p o i.e. the bottleneck edge is (u, v) We say that (u, v) is critical, and it disappears from the residual graph after flow augmentation. Counting Flow Augmentations

44
ADA: 12. Max Flow44 The first time an edge (u, v) is critical, we have d(v) = d(u) + 1, since p is a breadth-first path. We must wait until (v, u) is on an augmenting path before (u, v) can be critical again. Let d′ be the distance function when (v, u) is on an augmenting path. Then, we have d′(u) = d′(v) + 1 (breadth-first path) ≥ d(v) + 1 (monotonicity) = d(u) + 2 (breadth-first path)

45
ADA: 12. Max Flow45 Example Why "+2"? assume (u,v) is critical

46
ADA: 12. Max Flow46 was 5, now is 7 was 6, now is 8 assume (v,u) is critical

47
ADA: 12. Max Flow47 Path distances start out non-negative, never decrease, and are at most |V| - 1 long until the vertex becomes unreachable. Thus, (u, v) occurs as a critical edge at most O(V/2) times, because d(v) increases by at least 2 between occurrences o simplify O(V/2) to be O(V) Since the residual graph contains O(E) edges, the number of flow augmentations is O(V· E). Running time of Edmonds-Karp

54
ADA: 12. Max Flow54 The number of augmenting paths this algorithm calculates is O(E log C) o the log component is due to the outer while loop repeating O(log2 C) times since initially C ≤ Δ < 2C, and Δ decreases by a factor of 2 on each iteration Total running time is O(E 2 log C) o since each augmentating path will be calculated in O(E) time using BFS (as before) Running Time

55
ADA: 12. Max Flow55 The maxflow problem o find a flow of maximum value The mincut problem o find a cut of minimum capacity Two problems that appear very different but are actually two versions of the same question. Maxflow-mincut theorem: maxflow value = mincut capacity 9. Two Flow Problems Again

56
ADA: 12. Max Flow56 The net flow across a cut (A, B) is the sum of the flows on its edges from A to B minus the sum of the flows on its edges from from B to A. If f is the current flow and let (A, B) be any cut. Then, the net flow across (A, B) equals the value of f. Relationship between Flows and Cuts

57
ADA: 12. Max Flow57Example flow = 25 net flow across cut = = 25

58
ADA: 12. Max Flow58Example maxflow = 28 mincut = 28

59
ADA: 12. Max Flow59 It is easy to calculate the mincut (A, B) if the maxflow is known (f). The A set of the mincut = the set of vertices connected to s by an undirected path with no full forward or empty backward edges. Computing a mincut from a maxflow

60
ADA: 12. Max Flow60 N students apply for N jobs. Each gets several offers. Is there a way to match every student to a job? 10. Bipartite Matching

64
ADA: 12. Max Flow64 Given a digraph G = (V, E) and two nodes s and t, find the max number of edge-disjoint s-t paths. o two paths are edge-disjoint if they have no edge in common Example: communication networks 11. Edge Disjoint Paths

70
ADA: 12. Max Flow70 Worst-case big-Oh is generally not useful for predicting or comparing real-world max flow algorithm performance. Best in practice: push-relabel method with gap relabeling: O(E 3/2 ) (can be written as O(V 3 ) o very close to linear in E, but still an open question Analysis is Tricky