Slide 1

Slide 1 text

Class 15: Stable Matching cs2102: Discrete Mathematics | F16 uvacs2102.github.io David Evans | University of Virginia Storage fees on Exam 1 double after today! Can pick up after class today No class Thursday

Slide 2

Slide 2 text

Plan Stable Matching Gale-Shapley Algorithm Proving Correctness Secure Stable Matching No class Thursday PS6 is due Friday

Slide 3

Slide 3 text

Stable Matching

Slide 4

Slide 4 text

Formal Problem Definition Input: Output:

Slide 5

Slide 5 text

Formal Problem Definition Input: Output: Stable matching between and , , ≺% , ≺& A matching, = { , , , , . , . , … , 0 , 0 } is a stable matching if there is no pair (3 , 4 ) where 3 ≺67 4 and 4 ≺89 3 .

Slide 6

Slide 6 text

Stable Matching Anna Elsa Hans Kristoff

Slide 7

Slide 7 text

Stable Matching Anna Elsa Hans Kristoff Kristoff ≺:;;?

Slide 8

Slide 8 text

Stable Matches? Anna Elsa Hans Kristoff Kristoff ≺:;;?

Slide 9

Slide 9 text

Stable Matches? Anna Elsa Olaf Kristoff Olfa ≺:;;?

Slide 10

Slide 10 text

Gale- Shapley Algorithm Lloyd Shapley (1923-2016) accepting Nobel Prize (2012) (co-awarded to Alvin Roth)

Slide 11

Slide 11 text

David Gale (1921 – 2008)

Slide 12

Slide 12 text

Olfa ≺:;;< Kristoff Kristoff ≺=>?< Olaf Anna ≺G>

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Simplified Code (Non-Defensive) Do not write programs like this: assertions (especially) and comments are valuable (but don’t fit on slides)

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Modeling the Program How should we model the program as a state machine?

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

= { , | = { , ∈ , ∈ , no duplicate occurences of or = , , . , … , 0 where 0 ≤ 3 ≤ }

Slide 19

Slide 19 text

= { , | = { , ∈ , ∈ , no duplicate occurences of or = , , . , … , 0 where 0 ≤ 3 ≤ } = , ⟶ g, g All cases:

Slide 20

Slide 20 text

= { , | = { , ∈ , ∈ , no duplicate occurences of or = , , . , … , 0 where 0 ≤ 3 ≤ } = , ⟶ g, g All cases: g = , , . , … , 3 + 1, … , 0 j is the 3 -ranked match for 3 Case 1:

Slide 21

Slide 21 text

= { , | = { , ∈ , ∈ , no duplicate occurences of or = , , . , … , 0 where 0 ≤ 3 ≤ } = , ⟶ g, g All cases: g = , , . , … , 3 + 1, … , 0 j is the 3 -ranked match for 3 Case 1: new pairing ∀l ∈ . l , j ∉ g = ∪ 3 , j Case 2: better pairing ∃l ∈ . l , j ∈ , j prefers 3 to j g = ∪ 3 , j Case 3: rejected proposal ∃l ∈ . l , j ∈ , j prefers j to 3 g =

Slide 22

Slide 22 text

Proving Termination For all valid inputs, gale_shapley eventually terminates (returns a pairing). Each step, one of the proposals counts increases by 1 (and all others stay the same). After .steps, must be , , … , so no further transitions possible.

Slide 23

Slide 23 text

Proving Correctness For all valid inputs, gale_shapley returns a stable matching of its inputs. A matching, = { , , , … , 0 , 0 } is a stable matching if there is no pair (3 , 4 ) where 3 ≺67 4 and 4 ≺89 3 .

Slide 24

Slide 24 text

For all valid inputs, gale_shapley returns a stable matching of its inputs. A matching, = { , , , … , 0 , 0 } is a stable matching if there is no pair (3 , 4 ) where 3 ≺67 4 and 4 ≺89 3 . = , ⟶ g, g All cases: g = , , . , …, 3 + 1, …, 0 jis the 3-ranked match for 3 Case 1: new pairing ∀l ∈ . l , j ∉ g = ∪ 3 , j Case 2: better pairing ∃l ∈ . l , j ∈ , j prefers 3 to j g = ∪ 3 , j Case 3: rejected proposal ∃l ∈ . l , j ∈ , j prefers j to 3 g = Left as problem for PS7

Slide 25

Slide 25 text

Charge No class Thursday Problem Set 6 due Friday