mini max flow unit
play

Mini Max-Flow Unit Part 2: Flow with Demands, Cool Reductions, - PowerPoint PPT Presentation

Mini Max-Flow Unit Part 2: Flow with Demands, Cool Reductions, Bipartite Matching, and Konigs Theorem Lucca Siaudzionis and Jack Spalding-Jamieson 2020/02/04 University of British Columbia Announcements Presentations are due tomorrow .


  1. Mini Max-Flow Unit Part 2: Flow with Demands, Cool Reductions, Bipartite Matching, and Konig’s Theorem Lucca Siaudzionis and Jack Spalding-Jamieson 2020/02/04 University of British Columbia

  2. Announcements • Presentations are due tomorrow . • A5 is out and optional. • There is no reason not to try and solve the cool problems, though :) 1

  3. Princeton Notes Many of the reductions we will talk about are covered here • www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/07NetworkFlowII.pdf It also contains explanations, and we recommend you check it out 2

  4. Flow with Demands The problems we’ve seen so far establish a capacity for each edge. • We can also call this supply. What if an edge can also have a demand? • In other words, each edge has a minimum amount of flow that is required to go through it. 3

  5. Flow with Demands – Illustrative Problem Each component in the circuit has a minimum current necessary to function. What’s the minimum current you need to send from + terminal to − terminal? Source: ACM ICPC Pacific Northwest Regionals 2008 4

  6. Flow with Demands – Intuition Each edge demands flow! Transform flow graph G into G ′ as follows: 5

  7. Flow with Demands – Intuition Each edge demands flow! Transform flow graph G into G ′ as follows: • Add new source s ′ and new sink t ′ • Add s ′ → u with net demand into u • Add u → t ′ with net demand out of u • Add t → s with infinite capacity • Original edges have new capacity = orig cap − demand Original graph has feasible flow ⇔ max flow in new graph saturates source and destination edges. How do we get the maximum flow? Take this flow (for edges in original graph), add demands back in, and augment more flow while keeping flow ≥ demand. 6

  8. Flow with Demands – Vertex Demand What if the demand is, instead, on a vertex? 7

  9. Flow with Demands – Vertex Demand What if the demand is, instead, on a vertex? • We can use the same idea from one of last class’ problems (vertex capacity) • Split a vertex v into two vertices v 1 and v 2 . • Edges going into v now going into v 1 , and edges leaving v now leave from v 2 . • Make the edge ( v 1 , v 2 ) have v ’s demand. 7

  10. Airline Scheduling Problem Input: k flights • Flight i departs from city a i at time b i and arrives at city v i at time f i . • Each flight needs a single pilot and only transport one pilot (this is a toy problem, ok?) Output: The minimum number of pilots needed to operate all flights. 8

  11. Airline Scheduling Problem – Solution We don’t know how many pilots we need, let’s binary search on that number! • Let c be the current number of available pilots. 9

  12. Airline Scheduling Problem – Solution • For each flight, make a node (technically, two) with capacity and demand equal to 1. • Add source s with demand − c , and and edge from s to each flight node with capacity 1. • Add sink t with demand c , from each flight node to t with capacity 1 • If flight j is reachable flight i , make an edge from flight i to flight j with capacity 1. Source: www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/07NetworkFlowII.pdf 10

  13. Project Selection Problem Input: • Set P of projects, each with a profit p v (potentially negative) • Set of prerequistes amongst projects Task: Find a set of projects that maximizes profit 11

  14. Project Selection Problem – Prerequisite Graph Add a graph ( v , w ) iff w is a prerequisite of v . This might be opposite of what you’d expect. Source: www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/07NetworkFlowII.pdf 12

  15. Project Selection Problem – Network Flow Graph • Add infinite capacity to each prerequisite edge. • For each v such that p v ≥ 0, add an edge ( s , v ) with capacity p v . • For each v such that p v < 0, add an edge ( s , v ) with capacity − p v (this will be positive) Source: www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/07NetworkFlowII.pdf 13

  16. Project Selection Problem – Min-Cut • Finding a cut is equivalent to “giving up” on positive projects and “bearing the cost” of negative projects. • Finding a min-cut = maximizing profit (profit = total projects - cut). Source: www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/07NetworkFlowII.pdf 14

  17. Open-Pit Mining Problem • We want to extract blocks of ore. • Each ore has a profit p v = value of ore - cost to remove it. • Cannot remove block v before removing blocks x and y . Source: www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/07NetworkFlowII.pdf 15

  18. Open-Pit Mining Problem – Solution This is a sub-case of the project selection problem! 16

  19. Baseball Elimination Problem Input: • Several baseball teams and their number of wins so far in the tournament. • All the games that are yet to be played. • Your favourite team. Output: • Can your favourite team win the tournament? • Find out if you can allocate winners to each match so that your favourite team ends the tournament with the most wins. • The point of this is to figure out whether your team has been mathematically eliminated or not. 17

  20. Baseball Elimination Problem Let’s formalize things a bit. • Let 1, ... , N be all teams. • Team i so far has w i wins and r i games left to play. • g ij is the number of games yet to be played between teams i and j . • Let z be your favourite team. 18

  21. Baseball Elimination Problem – Intuition Clearly, we want to make team z win all the games they have left to play. • This brings their final score to w z + r z For each team x , we want to make sure they do not win more than w z games total. • We need to bound their number of new wins to w z + r z − w x . 19

  22. Baseball Elimination Problem – Network Flow Graph • Create a node for each team x • Create an edge from x to t with capacity w z + r z − w x . • For each pair ( x , y ) such that g xy > 0, do: • Create a node x − y . • Add an edge from s to x − y with capacity g xy . • Create edges from x − y to x and y with infinite capacities. Source: www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/07NetworkFlowII.pdf 20

  23. Baseball Elimination Problem – Max-Flow If max-flow = number of games left to play, our favourite team can win! • In other words, if we can saturate all the edges from the source, our team can win. • This means we can allocate a winner to each game, without exceeding the maximum amount of teams any team is allowed to win. 21

  24. Maximum Bipartite Matching • A graph G = ( V , E ) is bipartite if V can be partitioned into disjoint sets A and B such that all edges goes from A to B . • A matching is a subset of edges M ⊂ E such that no two edges touch same vertex • Goal: find the maximum size matching in a bipartite graph. 22

  25. Maximum Bipartite Matching 22

  26. Maximum Bipartite Matching 22

  27. Maximum Bipartite Matching We can use maximum flow to solve this problem! Assume m vertices on one side, n on other side, n ≤ m , then time is Ford Fulkerson: O ( Ef ) = O ( mn 2 ) Dinic’s: O ( mn √ n ) (also known as Hopcroft–Karp in this case) 23

  28. Maximum Bipartite Matching – Quick Problem • There are m jobs and n applicants. • Each applicant applies to a subset of the jobs. • Each job can accept only 1 applicant • Each applicant can only work at 1 job. • What is the maximum number of applicants who get a job? 24

  29. Maximum Bipartite Matching – Quick Problem Solution Idea: match applicants to jobs! • Construct a bipartite graph with vertices for applicants and jobs. • Add edge i → j if applicant i applied for job j • Find the maximum matching! • Time Complexity: O ( nm ( n + m )). 25

  30. Vertex Cover Given a graph G = ( V , E ), a vertex cover C ⊂ V is such that all edges e ∈ E have ≥ 1 endpoint in C . We are generally interested in the minimum vertex cover. 26

  31. Vertex Cover Min-VC is an NP-Hard problem in general. 27

  32. Vertex Cover Min-VC is an NP-Hard problem in general. In the case of bipartite graphs, we have hope, thanks to our friend Konig! 27

  33. Vertex Cover in Bipartite Graphs Every edge in the matching needs to have ≥ 1 endpoint in the cover. ⇒ Size of any vertex cover ≥ the size of any matching. 28

  34. Vertex Cover in Bipartite Graphs The minimum vertex cover is 2. The size of the maximum matching in this graph is also 2! 29

  35. Konig’s Theorem Konig’s Theorem • In a bipartite graph, the size of the maximum matching is equal to the size of the minimum vertex cover. 30

  36. Konig’s Theorem – Proof Cut edge is either s → u or v → t ⇒ Minimum cut = minimum vertex cover! Suppose not, suppose u → v is not covered, then there is path s → u → v → t so we did not have a valid cut. 31

  37. Finding the Cover Find the maximum matching in G 1 DFS(source) in the residual graph 2 Let L = reachable vertices 3 Output C = ( U \ L ) ∪ ( V ∩ L ) 4 Proof: same as finding min cut in flow 32

  38. Finding the Cover 33

  39. Finding the Cover 33

  40. Finding the Cover 33

  41. Finding the Cover 33

  42. Finding the Cover 33

  43. Proof of Correctness Proof that C = ( U \ L ) ∪ ( V ∩ L ) is a vertex cover: Proof. • Suppose C is not a vertex cover. • Then ∃ e = ( u , v ) ∈ E s.t. u ∈ U ∩ L and v ∈ V \ L . 34

Recommend


More recommend