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

mini max flow unit
SMART_READER_LITE
LIVE PREVIEW

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 .


slide-1
SLIDE 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

slide-2
SLIDE 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

slide-3
SLIDE 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

slide-4
SLIDE 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

slide-5
SLIDE 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

slide-6
SLIDE 6

Flow with Demands – Intuition

Each edge demands flow! Transform flow graph G into G ′ as follows:

5

slide-7
SLIDE 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

slide-8
SLIDE 8

Flow with Demands – Vertex Demand

What if the demand is, instead, on a vertex?

7

slide-9
SLIDE 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 v1 and v2.
  • Edges going into v now going into v1, and edges leaving v now leave from v2.
  • Make the edge (v1, v2) have v’s demand.

7

slide-10
SLIDE 10

Airline Scheduling Problem

Input: k flights

  • Flight i departs from city ai at time bi and arrives at city vi at time fi.
  • 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

slide-11
SLIDE 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

slide-12
SLIDE 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

slide-13
SLIDE 13

Project Selection Problem

Input:

  • Set P of projects, each with a profit pv (potentially negative)
  • Set of prerequistes amongst projects

Task: Find a set of projects that maximizes profit

11

slide-14
SLIDE 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

slide-15
SLIDE 15

Project Selection Problem – Network Flow Graph

  • Add infinite capacity to each prerequisite edge.
  • For each v such that pv ≥ 0, add an edge (s, v) with capacity pv.
  • For each v such that pv < 0, add an edge (s, v) with capacity −pv (this will be positive)

Source: www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/07NetworkFlowII.pdf

13

slide-16
SLIDE 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

slide-17
SLIDE 17

Open-Pit Mining Problem

  • We want to extract blocks of ore.
  • Each ore has a profit pv = 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

slide-18
SLIDE 18

Open-Pit Mining Problem – Solution

This is a sub-case of the project selection problem!

16

slide-19
SLIDE 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
  • r not.

17

slide-20
SLIDE 20

Baseball Elimination Problem

Let’s formalize things a bit.

  • Let 1, ..., N be all teams.
  • Team i so far has wi wins and ri games left to play.
  • gij is the number of games yet to be played between teams i and j.
  • Let z be your favourite team.

18

slide-21
SLIDE 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 wz + rz

For each team x, we want to make sure they do not win more than wz games total.

  • We need to bound their number of new wins to wz + rz − wx.

19

slide-22
SLIDE 22

Baseball Elimination Problem – Network Flow Graph

  • Create a node for each team x
  • Create an edge from x to t with capacity wz + rz − wx.
  • For each pair (x, y) such that gxy > 0, do:
  • Create a node x − y.
  • Add an edge from s to x − y with capacity gxy.
  • Create edges from x − y to x and y with infinite capacities.

Source: www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/07NetworkFlowII.pdf

20

slide-23
SLIDE 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

slide-24
SLIDE 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

slide-25
SLIDE 25

Maximum Bipartite Matching

22

slide-26
SLIDE 26

Maximum Bipartite Matching

22

slide-27
SLIDE 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(mn2) Dinic’s: O(mn√n) (also known as Hopcroft–Karp in this case)

23

slide-28
SLIDE 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

slide-29
SLIDE 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

slide-30
SLIDE 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

slide-31
SLIDE 31

Vertex Cover

Min-VC is an NP-Hard problem in general.

27

slide-32
SLIDE 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

slide-33
SLIDE 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

slide-34
SLIDE 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

slide-35
SLIDE 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

slide-36
SLIDE 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

slide-37
SLIDE 37

Finding the Cover

1

Find the maximum matching in G

2

DFS(source) in the residual graph

3

Let L = reachable vertices

4

Output C = (U \ L) ∪ (V ∩ L) Proof: same as finding min cut in flow

32

slide-38
SLIDE 38

Finding the Cover

33

slide-39
SLIDE 39

Finding the Cover

33

slide-40
SLIDE 40

Finding the Cover

33

slide-41
SLIDE 41

Finding the Cover

33

slide-42
SLIDE 42

Finding the Cover

33

slide-43
SLIDE 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

slide-44
SLIDE 44

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.
  • e /

∈ M. If e ∈ M, then v ∈ L otherwise u would not be in L.

  • Thus, e ∈ E \ M.

34

slide-45
SLIDE 45

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.
  • e /

∈ M. If e ∈ M, then v ∈ L otherwise u would not be in L.

  • Thus, e ∈ E \ M.
  • But then, v is reachable from u - go from source to u, and take the edge to v since it has

residual capacity = 1.

  • ⇒ v ∈ L but this contradicts that v /

∈ L.

34

slide-46
SLIDE 46

Proof of Correctness

Proof that |C| ≤ |M|: Proof.

  • No vertex in U \ L is unmatched.
  • No vertex in V ∩ L is unmatched.
  • There is no e = (u, v) ∈ M s.t. u ∈ U \ L and v ∈ V ∩ L since otherwise, u ∈ L.

⇒ every vertex in C is matched and corresponding edges of matching are distinct. So |C| ≤ |M|.

35

slide-47
SLIDE 47

Proof of Correctness

Proof that |C| ≤ |M|: Proof.

  • No vertex in U \ L is unmatched.
  • No vertex in V ∩ L is unmatched.
  • There is no e = (u, v) ∈ M s.t. u ∈ U \ L and v ∈ V ∩ L since otherwise, u ∈ L.

⇒ every vertex in C is matched and corresponding edges of matching are distinct. So |C| ≤ |M|. We already know that |C| ≥ |M| for any cover and any matching. Thus, |C| = |M|.

35

slide-48
SLIDE 48

Proof of Correctness

Thus, C = (U \ L) ∪ (V ∩ L) is a minimum vertex cover.

36

slide-49
SLIDE 49

Maximum Independent Set

A set of vertices is an independent set if there are no edges between any pair of them. A maximum independent set is the largest such set

Figure 1: Red vertices form a maximum independent set. Source: Wikipedia

NP complete in general, but easy for bipartite graphs! Thanks Konig!

37

slide-50
SLIDE 50

Minimum Vertex Cover ⇔ Maximum Independent Set

This is because complement of any vertex cover is independent set and vice versa Proof

  • (⇒) if u and v are both not in vertex cover then there cannot be an edge between them
  • (⇐) for any edge u → v, at least one of u and v not in independent set

38

slide-51
SLIDE 51

Minimum Edge Cover

An edge cover is a set of edges such that every vertex is an endpoint of ≥ 1 edge in the edge cover.

39

slide-52
SLIDE 52

Minimum Edge Cover

An edge cover is a set of edges such that every vertex is an endpoint of ≥ 1 edge in the edge cover. A minimum edge cover an edge cover of the smallest possible size.

39

slide-53
SLIDE 53

Minimum Edge Cover

39

slide-54
SLIDE 54

Minimum Edge Cover

39

slide-55
SLIDE 55

Minimum Edge Cover

Note: There is no edge cover in a graph with isolated vertices.

39

slide-56
SLIDE 56

Minimum Edge Cover ⇔ Maximum Matching

In particular, let E = size min edge cover, M = size of matching E = V − M Proof

  • Take any matching, greedily add one edge from every unmatched vertex, then we must get

edge cover, so E ≤ M + (V − 2M) = V − M

  • Any minimum edge cover must not have path of length ≥ 3 (otherwise can delete some

edges) ⇒ must be graph of stars

  • Each star of q vertices has q − 1 edges

⇒ # vertices = # stars + # edges, so V = k + E

  • Construct matching by picking 1 edge from each star, then we get k ≤ M, so

E = V − k ≥ V − M

40

slide-57
SLIDE 57

Minimum Edge Cover

1

Find the maximum matching in G

2

Add rest of the edges greedily G is any graph, not necessarily bipartite.

41

slide-58
SLIDE 58

Tile Problem

You have unlimited tiles of size 1 × k and k × 1 for all k = 1, 2, 3, . . . . Use a minimum number of them to cover all the black tiles while not touching any white tiles. Tiles may overlap with each other.

42

slide-59
SLIDE 59

Tile Problem – Solution

Observation 1: want to expand every tile as much as possible – no point wasting two tiles adjacent in the same direction. ⇒ Every black cell covered by at most 2 tiles – one horizontal and one vertical ⇒ Form bipartite graph where i → j if intersection of horizontal tile i and vertical tile j is a black cell, find max vertex cover

43

slide-60
SLIDE 60

“Jack’s” Weekend “Recommendation”

The Shawshank Redemption

44

slide-61
SLIDE 61

Lucca’s Weekend Recommendation

Jojo Rabbit Also, Google Code Jam is tomorrow. You should do it!

45