15-251 Great Theoretical Ideas in Computer Science Lecture 11: - - PowerPoint PPT Presentation

15 251 great theoretical ideas in computer science
SMART_READER_LITE
LIVE PREVIEW

15-251 Great Theoretical Ideas in Computer Science Lecture 11: - - PowerPoint PPT Presentation

15-251 Great Theoretical Ideas in Computer Science Lecture 11: Graphs III: Maximum and Stable Matchings October 8th, 2015 Todays Goal: Save lives. Todays Goal: Maximum matching problem (in bipartite graphs) Stable matching problem


slide-1
SLIDE 1

October 8th, 2015

15-251 Great Theoretical Ideas in Computer Science

Lecture 11: Graphs III: Maximum and Stable Matchings

slide-2
SLIDE 2

Today’s Goal: Save lives.

slide-3
SLIDE 3

Today’s Goal: Maximum matching problem (in bipartite graphs) Stable matching problem

slide-4
SLIDE 4

Maximum matching problem (in bipartite graphs)

slide-5
SLIDE 5

Some motivating real-world examples

matching machines and jobs . . . Job 1 Job 2 Job n . . .

slide-6
SLIDE 6

Some motivating real-world examples

matching professors and courses . . . 15-110 15-112 15-122 15-150 15-251 . . .

slide-7
SLIDE 7

Some motivating real-world examples

matching students and internships

slide-8
SLIDE 8

Some motivating real-world examples

matching kidney donors and patients

slide-9
SLIDE 9

How do you solve a problem like this?

  • 1. Formulate the problem
  • 2. Ask: Is there a trivial algorithm?
  • 3. Ask: Is there a better algorithm?
  • 4. Find and analyze
slide-10
SLIDE 10
slide-11
SLIDE 11

Bipartite Graphs

X Y X Y V is bipartite if: G = (V, E)

  • there exists a bipartition and of
  • each edge connects a vertex in to a vertex in

X Y not allowed Given a graph , we could ask, is it bipartite? G = (V, E)

slide-12
SLIDE 12

Bipartite Graphs

Given a graph , we could ask, is it bipartite? G = (V, E) 1 2 3 1 2 3 4 1 2 3 4 5

slide-13
SLIDE 13

Bipartite Graphs

X Y Sometimes we write the bipartition explicitly: G = (X, Y, E)

slide-14
SLIDE 14

Bipartite Graphs

Great for modeling relations between two classes of

  • bjects.

Examples: = machines, = jobs An edge means is capable of doing . X Y {x, y} x y = professors, = courses An edge means can teach . X Y {x, y} x y = students, = internship jobs

An edge means and are interested in each other.

X Y {x, y} x y …

slide-15
SLIDE 15

Matchings in bipartite graphs

Often, we are interested in finding a matching in a bipartite graph X Y A matching : A subset of the edges that do not share an endpoint.

slide-16
SLIDE 16

Matchings in bipartite graphs

Often, we are interested in finding a matching in a bipartite graph X Y A matching : A subset of the edges that do not share an endpoint. matching

slide-17
SLIDE 17

Matchings in bipartite graphs

Often, we are interested in finding a matching in a bipartite graph X Y A matching : A subset of the edges that do not share an endpoint. matching

slide-18
SLIDE 18

Matchings in bipartite graphs

Often, we are interested in finding a matching in a bipartite graph X Y A matching : A subset of the edges that do not share an endpoint. not a matching

slide-19
SLIDE 19

Matchings in bipartite graphs

Often, we are interested in finding a matching in a bipartite graph X Y maximum matching Maximum matching: a matching with largest number

  • f edges (among all possible matchings).
slide-20
SLIDE 20

Matchings in bipartite graphs

Often, we are interested in finding a matching in a bipartite graph X Y maximal matching

Cannot add more edges. “Local optimum”

Maximal matching: a matching which cannot contain any more edges.

slide-21
SLIDE 21

Matchings in bipartite graphs

Often, we are interested in finding a matching in a bipartite graph X Y Perfect matching: a matching that covers all vertices. perfect matching

a necessary condition for perfect matching:

|X| = |Y |

slide-22
SLIDE 22

Important Note We can define matchings for non-bipartite graphs as well.

slide-23
SLIDE 23

Important Note We can define matchings for non-bipartite graphs as well.

slide-24
SLIDE 24

Maximum matching problem

The restriction where G is bipartite is already interesting! The problem we want to solve is: Input: A graph . G = (V, E) Output: A maximum matching in . G Maximum matching problem

slide-25
SLIDE 25

Bipartite maximum matching problem

The problem we want to solve is: Input: A bipartite graph . Output: A maximum matching in . G Bipartite maximum matching problem G = (X, Y, E)

slide-26
SLIDE 26

How do you solve a problem like this?

  • 1. Formulate the problem
  • 2. Ask: Is there a trivial algorithm?
  • 3. Ask: Is there a better algorithm?
  • 4. Find and analyze
slide-27
SLIDE 27

Bipartite maximum matching problem

Is there a (trivial) algorithm to solve this problem? Try all possible subsets of the edges. Check if it is a matching. Keep track of the maximum one found. Running time: Ω(2m) Input: A bipartite graph . Output: A maximum matching in . G Bipartite maximum matching problem G = (X, Y, E)

slide-28
SLIDE 28

How do you solve a problem like this?

  • 1. Formulate the problem
  • 2. Ask: Is there a trivial algorithm?
  • 3. Ask: Is there a better algorithm?
  • 4. Find and analyze
slide-29
SLIDE 29

Bipartite maximum matching problem

What if we picked edges greedily?

slide-30
SLIDE 30

Bipartite maximum matching problem

What if we picked edges greedily?

slide-31
SLIDE 31

Bipartite maximum matching problem

What if we picked edges greedily?

slide-32
SLIDE 32

Bipartite maximum matching problem

What if we picked edges greedily? maximal matching but not maximum Is there a way to get out of this local optimum?

slide-33
SLIDE 33

Augmenting paths

Let M be some matching. 1 2 3 4 5 6 7 8 Augmenting path: 4-8-2-5-1-7 An augmenting path with respect to M is a path in G such that:

  • the edges in the path alternate between

being in M and not being in M

  • the first and last vertices are not matched by M
slide-34
SLIDE 34

Augmenting paths

1 2 3 4 5 6 7 8 Augmenting path: 4-8-2-5-1-7 4 8 2 5 1 7 4 8 2 5 1 7 augmenting path can obtain a bigger matching. = ⇒

slide-35
SLIDE 35

Augmenting paths and maximum matchings

augmenting path can obtain a bigger matching. = ⇒ no augmenting path maximum matching. In fact, it turns out: = ⇒ Theorem: A matching M is maximum if and only if there is no augmenting path with respect to M.

slide-36
SLIDE 36

Augmenting paths and maximum matchings

Proof: If there is an augmenting path with respect to M, we saw that M is not maximum. Want to show: If M is not maximum, then there is an augmenting path. Let M* be a maximum matching. |M*| > |M|. 1 2 3 4 5 6 7 8 Let S be the set of edges contained in M* or M but not both. S = (M* M) - (M M*) ∪ ∩

slide-37
SLIDE 37

Augmenting paths and maximum matchings

Proof: 1 2 3 4 5 6 7 8 S = (M* M) - (M M*) ∪ ∩ What does S look like? So S is a collection of cycles and paths. (exercise) The edges alternate red and blue. Each vertex has degree at most 2. (why?) (will find an augmenting path in S) Let S be the set of edges contained in M* or M but not both.

slide-38
SLIDE 38

Augmenting paths and maximum matchings

Proof: 1 2 3 4 5 6 7 8 Let S be the set of edges contained in M* or M but not both. # red > # blue in S # red = # blue in cycles This is an augmenting path with respect to M. So a path with # red > # blue. ∃ So S is a collection of cycles and paths. (exercise) The edges alternate red and blue. S = (M* M) - (M M*) ∪ ∩

slide-39
SLIDE 39

Algorithm to find maximum matching

OK, but how do you find an augmenting path? Theorem: A matching M is maximum if and only if there is no augmenting path with respect to M. Exercise (homework?) Algorithm:

  • Start with a single edge as your matching M.
  • Find an augmenting path with respect to M.
  • Update M according to the augmenting path.
  • Repeat until there is no augmenting path w.r.t. M:
slide-40
SLIDE 40

Algorithm to find maximum matching

Algorithm:

  • Start with a single edge as your matching M.
  • Find an augmenting path with respect to M.
  • Update M according to the augmenting path.
  • Repeat until there is no augmenting path w.r.t. M:

Theorem: A matching M is maximum if and only if there is no augmenting path with respect to M. O(m · n) time algorithm in bipartite graphs.

slide-41
SLIDE 41

Today’s Goal: Maximum matching problem (in bipartite graphs) Stable matching problem

slide-42
SLIDE 42

Stable matching problem

slide-43
SLIDE 43

Finding internship

slide-44
SLIDE 44

Finding internship

1. 2. 3. 4.

  • 1. Alice
  • 2. Bob
  • 3. Charlie
  • 4. David
  • 1. Bob
  • 2. David
  • 3. Alice
  • 4. Charlie

. . . Other examples: medical residents - hospitals students - colleges

slide-45
SLIDE 45

Finding internship

What can go wrong? Alice Bob Charlie David Macrosoft Moogle Umbrella KLG Suppose Alice gets “matched” with Macrosoft. Charlie gets “matched” with Umbrella. But, say, Alice prefers Umbrella over Macrosoft and Umbrella prefers Alice over Charlie.

slide-46
SLIDE 46

Finding internship: Formalizing the problem

An instance of the problem can be represented as a complete bipartite graph Goal: Find a stable matching. + preference list of each node. (e,f,h,g) (e,g,h,f) (e,h,f,g) (e,f,g,h) (a,b,c,d) (a,b,c,d) (a,b,c,d) (a,b,c,d) X Y Students Companies a b c d e f g h |X| = |Y | = n

slide-47
SLIDE 47

Finding internship: Formalizing the problem

What is a stable matching? X Y a b e f (e,f) (e,f) (a,b) (a,b)

  • 1. It has to be a perfect matching.
  • 2. Cannot contain an unstable pair:

A pair (x, y) not matched but they prefer each other over their current partners.

slide-48
SLIDE 48

Finding internship: Formalizing the problem

X Y What is a stable matching? a b e f (e,f) (e,f) (a,b) (a,b)

  • 1. It has to be a perfect matching.
  • 2. Cannot contain an unstable pair:

(a, e) is an unstable pair. A pair (x, y) not matched but they prefer each other over their current partners.

slide-49
SLIDE 49

Finding internship: Formalizing the problem

X Y Goal: Find a stable matching. a b c d e f g h (e,f,h,g) (e,g,h,f) (e,h,f,g) (e,f,g,h) (a,b,c,d) (a,b,c,d) (a,b,c,d) (a,b,c,d) (Is it guaranteed to always exist?) |X| = |Y | = n An instance of the problem can be represented as a complete bipartite graph + preference list of each node.

slide-50
SLIDE 50

Stable matching: Is there a trivial algorithm?

X Y a b c d e f g h (e,f,h,g) (e,g,h,f) (e,h,f,g) (e,f,g,h) (a,b,c,d) (a,b,c,d) (a,b,c,d) (a,b,c,d) Try all possible perfect matchings, and check if it is stable. Trivial algorithm: # perfect matchings in terms : n = |X|

slide-51
SLIDE 51

# perfect matchings in terms : n = |X|

Stable matching: Is there a trivial algorithm?

X Y a b c d e f g h (e,f,h,g) (e,g,h,f) (e,h,f,g) (e,f,g,h) (a,b,c,d) (a,b,c,d) (a,b,c,d) (a,b,c,d) Try all possible perfect matchings, and check if it is stable. n! Trivial algorithm:

slide-52
SLIDE 52

Stable matching: Can we do better?

Nobel Prize in Economics 2012

The Gale-Shapley Proposal Algorithm (1962)

slide-53
SLIDE 53

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-54
SLIDE 54

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-55
SLIDE 55

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-56
SLIDE 56

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-57
SLIDE 57

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-58
SLIDE 58

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-59
SLIDE 59

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-60
SLIDE 60

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

hello handsome

slide-61
SLIDE 61

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-62
SLIDE 62

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-63
SLIDE 63

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-64
SLIDE 64

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-65
SLIDE 65

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-66
SLIDE 66

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-67
SLIDE 67

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-68
SLIDE 68

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-69
SLIDE 69

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

Nice. Now I don’t have to marry Brad.

slide-70
SLIDE 70

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-71
SLIDE 71

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-72
SLIDE 72

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-73
SLIDE 73

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-74
SLIDE 74

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

#FeelTheBern Trump

slide-75
SLIDE 75

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-76
SLIDE 76

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-77
SLIDE 77

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-78
SLIDE 78

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

whatever

slide-79
SLIDE 79

The Gale-Shapley proposal algorithm

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

slide-80
SLIDE 80

The Gale-Shapley proposal algorithm

Cool, but does it work correctly?

  • Does it always terminate?
  • Does it always find a stable matching?

While there is a man m who is not matched:

  • Let w be the highest ranked woman in m’s list

to whom m has not proposed yet.

  • If w is unmatched, or w prefers m over her current match:
  • Match m and w.

(The previous match of w is now unmatched.)

(Does a stable matching always exist?)

slide-81
SLIDE 81

The Gale-Shapley proposal algorithm always terminates with a stable matching after at most iterations.

Gale-Shapley algorithm analysis

  • 1. Number of iterations is at most .

n2 3 things to show:

  • 2. The algorithm terminates with a perfect matching.
  • 3. The matching has no unstable pairs.

A constructive proof that a stable matching always exists. n2 Theorem:

slide-82
SLIDE 82

Gale-Shapley algorithm analysis

No man proposes to a woman more than once. So each man makes at most proposals. n # iterations = # proposals There are men in total. n # proposals . ≤ n2 = ⇒ # iterations . ≤ n2 = ⇒

  • 1. Number of iterations is at most .

n2

slide-83
SLIDE 83

Gale-Shapley algorithm analysis

A man is not matched All men must be matched. = ⇒ All women must be matched = ⇒ Contradiction

  • 2. The algorithm terminates with a perfect matching.

If we don’t have a perfect matching: Second implication: There are an equal number of men and women.

slide-84
SLIDE 84

Gale-Shapley algorithm analysis

A man is not matched All men must be matched. = ⇒ All women must be matched = ⇒ Contradiction

  • 2. The algorithm terminates with a perfect matching.

If we don’t have a perfect matching: First implication: A man got rejected by every woman: case1: she was already matched, or case2: she got a better offer Observe: once a woman is matched, she stays matched. Either way, she was matched at some point.

slide-85
SLIDE 85

Gale-Shapley algorithm analysis

Unstable pair: (m, w) not matched but they prefer each other.

  • 3. The matching has no unstable pairs.

m m’ w’ w Observations: > A man can only go down in his preference list. > A woman can only go up in her preference list. Case 1: m never proposed to w Case 2: m proposed to w w’ must be higher in the preference list of m than w w rejected m w prefers her current partner = ⇒ Consider any unmatched (m,w).

slide-86
SLIDE 86

Further questions

Does the order of how we pick men matter? Would it lead to different matchings? The Gale-Shapley proposal algorithm always terminates with a stable matching after at most iterations. n2 Theorem: Does this algorithm favor men or women or neither? Is the algorithm “fair”?

slide-87
SLIDE 87

Further questions

Theorem: The Gale-Shapley proposal algorithm always matches m with its best valid partner. Theorem: The Gale-Shapley proposal algorithm always matches w with its worst valid partner.

slide-88
SLIDE 88

Real-world applications

Alvin Roth Variants of the Gale-Shapley algorithm is used for:

  • matching doctors and hospitals
  • matching students to high schools (e.g. in New

York)

  • matching kidney donors to patients

> revolutionized the way kidney transplants were handled in the US > in 2003, 3436 patients on the waitlist died.

slide-89
SLIDE 89

“Throughout the United States nearly 2,000 patients have received kidneys under the system developed on Roth and Shapley’s models that would otherwise not have received them.”

  • Ruthanne Hanto,


Program Manager, Kidney Paired Donation Program, Organ Procurement and Transplantation Network (OPTN)

slide-90
SLIDE 90

Today’s Goal: Save lives.