mini max flow unit
play

Mini Max-Flow Unit Part 1: Introduction, Ford-Fulkerson Lucca - PowerPoint PPT Presentation

Mini Max-Flow Unit Part 1: Introduction, Ford-Fulkerson Lucca Siaudzionis and Jack Spalding-Jamieson 2020/03/31 University of British Columbia Announcements A5 is going to be released tonight (probably) It does not contain any flow


  1. Mini Max-Flow Unit Part 1: Introduction, Ford-Fulkerson Lucca Siaudzionis and Jack Spalding-Jamieson 2020/03/31 University of British Columbia

  2. Announcements • A5 is going to be released tonight (probably) • It does not contain any flow problems. • Presentations are due Friday. • We will not be marking your projects before we see your presentations, please assume that we have not been exposed to them beforehand (this way your fellow students can also watch them). 1

  3. Maximum Flow: Problem Statement (1) Input : • A directed graph G = ( V , E ) • A source node s ∈ V and sink node t ∈ V . • For each edge e ∈ E , a capacity c e . A 3 2 s t 5 2 3 B 2

  4. Maximum Flow: Problem Statement (2) A flow is an assignment of values f e to each edge meeting the following constraints: • Capacity constraints: For every e ∈ E , f e ≤ c e • Conservation constraints: For every non-terminal node v ∈ V \ { s , t } , the total flow leaving v = the total flow entering v , i.e.: � � f vu = f uv vu ∈ E , u ∈ V uv ∈ E , u ∈ V Output : A flow maximizing the (net) flow leaving s , i.e. maximizing     �  + � f sv f vs    sv ∈ E , v ∈ V vs ∈ E , v ∈ V Analogy : If edges are (capacitated) pipes, then the flow is the rate of water (or oil, etc.) flow. 3

  5. Maximum Flow: Flow Example 2 A 3 2 1 s t 5 2 3 B 3 4

  6. Maximum Flow: Notation Instead of labelling both the flow paths and the capacities, we will instead label how much of the capacity is used. The label x / y indicates that x units of flow are going across an edge of capacity y . A 3 / 3 2 / 2 s t 1 / 5 2 / 2 3 / 3 B 5

  7. Maximum Flow: Near-Solution An augmenting path is a path from s to t (an s − t path) for which all the edges have unused capacity. Let’s try the following greedy algorithm: while there is an augmenting path: 1 pick any augmenting path P 2 increase the flow on edges of P 3 6

  8. Maximum Flow: Near-Solution - Failure This greedy algorithm fails. Consider the following graph and flow of 3: A 3 / 3 0 / 2 3 s t 3 / 5 0 / 2 3 / 3 B There is no way to augment this. However, a flow of 4 is possible. 7

  9. Maximum Flow: Residual Graph (1) If we re-consider this locally maximum graph, where are all the edges across which we can push flow? A 3 / 3 0 / 2 s t 3 / 5 0 / 2 3 / 3 B Key observation: We can push flow backwards across an edge. Use this to create a residual graph. Intuition: Water can push back against water. This is similar to finding the net force in physics. 8

  10. Maximum Flow: Residual Graph (2) If we also draw all the edges across which we can push, we get the following graph: A 3 / 3 0 / 2 2 / 2 s 0 / 3 t 3 / 5 2 / 5 2 / 2 0 / 3 0 / 2 3 / 3 B 9

  11. Maximum Flow: Residual Graph (3) This is called the residual graph of G under flow f . It is denoted as G f . It has the following properties: • V ( G f ) = V ( G ). • For each edge e ∈ G f , c f e is the residual capacity. • For each edge e = uv ∈ E ( G ), we have the following edges in G f : • The forward edge: edge uv with capacity c f uv = c e − f e . • The backward edge: edge vu with capacity c f vu = f e . We typically only draw or care about the edges with residual capacity > 0. 10

  12. Maximum Flow: Ford-Fulkerson Algorithm We modify the previous algorithm slightly (and give more details): while there is an augmenting path in the residual graph: 1 pick an augmenting path P 2 # augment the flow 3 push = min(capacity[e] for e in P) 4 for e in P: 5 if e is a forward edge: 6 increase the flow on e by push 7 else: 8 decrease the flow on the corresponding forward edge by push 9 update the residual graph 10 11

  13. Maximum Flow: Ford-Fulkerson Example (1) A 0 / 3 0 / 2 2 / 2 s 3 / 3 t 0 / 5 5 / 5 2 / 2 3 / 3 0 / 2 0 / 3 B 12

  14. Maximum Flow: Ford-Fulkerson Example (2) A 0 / 3 0 / 2 2 / 2 s 3 / 3 t 0 / 5 5 / 5 2 / 2 3 / 3 0 / 2 0 / 3 B Found an augmenting path of 3. 13

  15. Maximum Flow: Ford-Fulkerson Example (3) A 3 / 3 0 / 2 2 / 2 s 0 / 3 t 3 / 5 2 / 5 2 / 2 0 / 3 0 / 2 3 / 3 B 14

  16. Maximum Flow: Ford-Fulkerson Example (3) A 3 / 3 0 / 2 2 / 2 s 0 / 3 t 3 / 5 2 / 5 2 / 2 0 / 3 0 / 2 3 / 3 B Found an augmenting path of 2. 15

  17. Maximum Flow: Ford-Fulkerson Example (4) A 3 / 3 2 / 2 2 / 2 s 0 / 3 t 1 / 5 4 / 5 0 / 2 0 / 3 2 / 2 3 / 3 B Total (maximum) flow is 5. 16

  18. Maximum Flow: Ford-Fulkerson Runtime Ford-Fulkerson only necessarily terminates if the capacities are all rational. Let’s assume they’re integers: • Every augmentation increases the flow by ≥ 1 unit. • Overall, need O ( | f | ) iterations. • Each augmentation takes O ( | E | ) time to find (use DFS). The overall time complexity is then O ( | E || f | ) (this is not necessarily polynomial). 17

  19. Maximum Flow: Complexity Note: • If we use BFS to find the augmenting paths, we get Edmonds-Karp algorithm, with � min( | E || f | , | V || E | 2 ) � runtime O • This runtime has been improved several times. Very approachable improvements include Dinic’s algorithm and Push-Relabel. • The best theoretical complexity is O ( | V || E | ) (Orlin, 2013). This is also the fastest possible in the general case. 18

  20. Maximum Flow: Edmonds-Karp (BFS part) Here we have some pseudocode for Edmonds-Karp: def EdmondsKarp_BFS(graph, s, t): # find an augmenting path and update the flow 1 initialize previous[v] to null (for all vertices v) 2 initialize flow_to[v] to inf (for all vertices v) 3 q = new queue containing s 4 while q is not empty: 5 u = dequeue(q) 6 for edge e from u to v, where v is a neighbour of u: 7 if flow[e] < capacity[e] and previous[v] is null: 8 previous[v] = u 9 flow_to[v] = min(flow_to[u], capacity[e] - flow[e]) 10 enqueue(v) 11 if previous[t] is null: # no more augmenting paths 12 return 0 13 # iterate over edges by following previous[], starting from t and ending at null 14 for edge e in augmenting path: 15 flow[e] += flow_to[t] # increase flow on the edge in the path 16 flow[opposite edge of e] -= flow_to[t] # decrease flow on the opposite edge 17 return flow_to[t] 19 18

  21. Maximum Flow: Edmonds-Karp (Main part) def EdmondsKarp(graph, s, t): 20 # add backward edges 21 for edge e in graph from u to v: 22 op = edge from v to u, with capacity 0 23 add op to graph 24 # keep finding augmenting paths 25 max_flow = 0 26 current_flow = EdmondsKarp_BFS(graph, s, t) 27 while current_flow > 0: 28 max_flow += current_flow 29 current_flow = EdmondsKarp_BFS(graph, s, t) 30 return max_flow 31 20

  22. Minimum Cut: The Cold War We want to find the cheapest way to disconnect the Soviet Union from the rest of Europe, using the least force. We need study s − t cuts. 21

  23. Minimum Cut: Problem Statement An s − t cut partitions the nodes of a graph into sets S , T (i.e. V = S ∪ T and S ∩ T = ∅ ), such that s ∈ S and t ∈ T . • The capacity of a cut is the sum of the edge capacities in E ∩ ( S × T ), i.e. the sum of the edges from S to T . A 3 2 s t 5 2 3 B Figure 1: A cut of capacity 6. 22

  24. Minimum Cut: Example What’s the minimum cut in this graph? A 3 2 s t 5 2 3 B 23

  25. Minimum Cut: Example What’s the minimum cut in this graph? A 3 2 s t 5 2 3 B It’s 5! 23

  26. Maximum Flow and Minimum Cut (1) Theorem 1 : Any cut has capacity ≥ the value of any flow. Proof: If we remove all the edges in a cut, the maximum flow across the resulting graph is 0. Note: This is called weak duality. Theorem 2 : The maximum s − t flow is equal to the capacity of the minimum s − t cut. • Proof 1: By linear programming duality. • Proof 2: • Run Ford-Fulkerson (or similar) to find the maximum flow f . • Let S be the set of nodes still reachable from s in G f , and T = V \ S . • Claim: the capacity of the cut ( S , T ) is | f | . • All the edges from S to T are saturated (otherwise there would have been a path along a forward edge to the node). • All of the edges from T to S have zero flow (otherwise there would have been a path along a backward edge to the node). 24

  27. Reductions - Warm-up Input : A capacitated network with sources s 1 , s 2 , . . . , s p and sinks t 1 , t 2 , . . . , t q . Output : The maximum total flow from all sources to all sinks. 2 3 4 s 1 3 t 1 5 5 7 s 2 45 t 2 4 2 s 3 3 1 25

  28. Reductions - Warm-up Solution Create a super source s and super sink t . Add edges s → s i and t i → t with infinite capacity. Instead of infinite capacity, we could also use a capacity that is the sum of all capacities in the original graph. 2 3 4 s 1 3 t 1 ∞ ∞ 5 5 7 ∞ s 2 s t 45 t 2 ∞ 4 ∞ 2 s 3 3 1 26

  29. Reductions Why is max-flow useful? 27

  30. Reductions Why is max-flow useful? Lots of problems can be reduce to max-flow. 27

  31. Reductions - Problem 1 Input : A directed graph G and notes s , t ∈ V ( G ). Output : The edge connectivity of s , t , i.e. the maximum number of edge-disjoint paths from s to t . 28

  32. Reductions - Problem 1 Solution Set the capacity of every edge to 1. Find the maximum s − t flow. To recover the paths, you can greedily choose them in O ( | E | ) time. 29

  33. Reductions - Problem 2 Input : A capacitated network G , and notes s and t . In addition to edge capacities, also include vertex capacities. Output : The maximum flow through this network, also obeying vertex capacities. 30

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend