# The Stable Marriage Problem and Constraint Programming.

## Presentation on theme: "The Stable Marriage Problem and Constraint Programming."— Presentation transcript:

The Stable Marriage Problem and Constraint Programming

1: 2 3 6 1 4 5 1: 6 5 1 3 2 4 2: 4 6 1 2 5 3 2: 2 4 6 1 3 5 3: 1 4 5 3 6 2 3: 4 3 6 2 5 1 4: 6 5 3 4 2 1 4: 1 3 5 4 2 6 5: 2 3 1 4 5 6 5: 3 2 6 1 4 5 6: 3 1 2 5 6 4 6: 5 1 3 4 6 2 What is a SM? MENWOMEN What do you mean by stable? assume man I is married to woman Y woman X is married to man J man I prefers woman X to his partner (woman Y) woman X prefers man I to her partner (man J) the marriages are unstable man I and woman X will elope Harrison Ford is not going to leave his wife and take Andrea away from me

A Blocking Pair 1: 2 3 6 1 4 5 1: 6 5 1 3 2 4 2: 4 6 1 2 5 3 2: 2 4 6 1 3 5 3: 1 4 5 3 6 2 3: 4 3 6 2 5 1 4: 6 5 3 4 2 1 4: 1 3 5 4 2 6 5: 2 3 1 4 5 6 5: 3 2 6 1 4 5 6: 3 1 2 5 6 4 6: 5 1 3 4 6 2 MENWOMEN M6 marries W6, his 5th choice W5 marries M1, her 4th choice M6 prefers W5 to W6 & W5 prefers M6 to M1 This is a blocking pair, and is unstable Romeo marries Liz, Richard marries Juliet … is this stable?

A Solution 1: 2 3 6 1 4 5 1: 6 5 1 3 2 4 2: 4 6 1 2 5 3 2: 2 4 6 1 3 5 3: 1 4 5 3 6 2 3: 4 3 6 2 5 1 4: 6 5 3 4 2 1 4: 1 3 5 4 2 6 5: 2 3 1 4 5 6 5: 3 2 6 1 4 5 6: 3 1 2 5 6 4 6: 5 1 3 4 6 2 MENWOMEN

The Basic Gale Shapley (GS) Algorithm 1. L := list of free men 2. While isNotEmpty(L) 2.1 m := selectFrom(L) // but do not delete m from L 2.2 w := first(preferenceList(m)) // ms most preferred partner 2.3 if isUnmarried(w) 2.3.1 marry(m,w) 2.3.2 L := remove(L,m) 2.4 else // w is already married 2.4.1 if w prefers m to partner(w) 2.4.1.1 L := add(L,partner(w)) // free, at last! 2.4.1.2 delete(preferenceList(w),partner(w)) // divorced :( 2.4.1.3 delete(preferenceList(partner(w)),w) // divorced :( 2.4.1.4 marry(m,w) // w gets a better partner :) 2.4.2 else 2.4.2.1 delete(preferenceList(w),m) // w will not remarry for m 2.4.2.1 delete(preferenceList(m),w) // and m stays in L Note: 1. Man optimal, men propose 2. The order of L is immaterial 3. The algorithm terminates with a man optimal (woman pessimal) stable matching always (there is always a stable matching) 4. O(n^2), and uses data structures initialised in O(n^2)

The Extended Gale Shapley Algorithm (man optimal) 1. L := list of free men 2. While isNotEmpty(L) 2.1 m := selectAndRemoveFrom(L) // note, removed from L 2.2 w := first(preferenceList(m)) 2.3 if isMarried(w) // unconditional remarriage! 2.3.1 L := add(L,partner(w)) 2.3.2 delete(preferenceList(w),partner(w)) 2.3.3 delete(preferenceList(partner(w)),w) 2.4 marry(m,w) 2.5 for each m in preferenceList(w) 2.5.1 if w prefers m to m // remove unacceptable pairs 2.5.1.1 delete(preferenceList(w),m) 2.5.1.2 delete(preferenceList(m),w) … reduces the preference lists by eliminating pairs that can readily be identified as not belonging to any stable matching Gusfield and Irving, 1.2.4, page 15, 1989

The Extended Gale Shapley Algorithm We can apply the algorithm for men, and then for women The reduced preference lists are called the GS-lists The GS lists contain all matchings We can generate a man optimal matching by marrying each man to his first preference

A (naïve) CP encoding of SM 1: 2 3 6 1 4 5 1: 6 5 1 3 2 4 2: 4 6 1 2 5 3 2: 2 4 6 1 3 5 3: 1 4 5 3 6 2 3: 4 3 6 2 5 1 4: 6 5 3 4 2 1 4: 1 3 5 4 2 6 5: 2 3 1 4 5 6 5: 3 2 6 1 4 5 6: 3 1 2 5 6 4 6: 5 1 3 4 6 2 MENWOMEN a permutation problem with n variables, each with n values n man variables and n woman variables, domain size of n a marriage constraint between each (man,woman) pair if manX marries womanY then womanY marries manX a stability constraint between each (man,woman) pair list all blocking pairs between a man and woman an allDifferent constraint

The Stability Constraint 1: 2 3 6 1 4 5 1: 6 5 1 3 2 4 2: 4 6 1 2 5 3 2: 2 4 6 1 3 5 3: 1 4 5 3 6 2 3: 4 3 6 2 5 1 4: 6 5 3 4 2 1 4: 1 3 5 4 2 6 5: 2 3 1 4 5 6 5: 3 2 6 1 4 5 6: 3 1 2 5 6 4 6: 5 1 3 4 6 2 MENWOMEN by example, consider man 6 and woman 5 the following marriages for (m6,w5) are unstable (6,1) m6 prefers w5 to w6 and w5 prefers m6 to m1 (6,4) m6 prefers w5 to w6 and w5 prefers m6 to m4 (6,5) m6 w5 w6 w5 m6 m5 (4,1) m6 prefers w5 to w4 and w5 prefers m6 to m1 (4,4) w4 m4 (4,5) w4 m5 easily generated, as cross product of tails of preference lists a binary constraint, extensional representation, list of nogoods

The Marriage Constraint 1: 2 3 6 1 4 5 1: 6 5 1 3 2 4 2: 4 6 1 2 5 3 2: 2 4 6 1 3 5 3: 1 4 5 3 6 2 3: 4 3 6 2 5 1 4: 6 5 3 4 2 1 4: 1 3 5 4 2 6 5: 2 3 1 4 5 6 5: 3 2 6 1 4 5 6: 3 1 2 5 6 4 6: 5 1 3 4 6 2 MENWOMEN a binary constraint between (man,woman) pairs manX = Y -> womanY = X this is called a channeling constraint the allDiff constraint is now redundant

Improving Propagation 1: 1 3 6 2 4 5 1: 1 5 6 3 2 4 2: 4 6 1 2 5 3 2: 2 4 6 1 3 5 3: 1 4 5 3 6 2 3: 4 3 6 2 5 1 4: 6 5 3 4 2 1 4: 1 3 5 4 2 6 5: 2 3 1 4 5 6 5: 3 2 6 1 4 5 6: 3 1 2 5 6 4 6: 5 1 3 4 6 2 MENWOMEN The problem has been slightly changed it should be obvious that in all stable matchings man 1 marries woman 1 (anything else is unstable) nogoods stability {(3,5),(3,6), … (3,4), …, (5,5), …,(5,4)} achieving arc consistency does NOT detect this marriage (channeling) constraint and stability constraint operate independently however we can COMBINE marriage and stability constraints nogoods marriage {(2,1),(3,1),…,(6,1),(1,2),(1,3),…,(1,6)} we now have one (not two) tighter constraint capturing all the nogoods {(2,1),(3,1),…,(6,1), (1,2),(1,3),…,(1,6),(3,5),(3,6),…,(3,4),…,(5,5),…,(5,4)}

So? AC now detects inevitability of marriage of man 1 to woman 1 AC reduces the domains more than the initial encoding However O(n^4) encoding in space and time there are n(n-1) constraints each constraint is of size O(n^2) this is also true of the naïve encoding

1: 2 3 6 1 4 5 1: 6 5 1 3 2 4 2: 4 6 1 2 5 3 2: 2 4 6 1 3 5 3: 1 4 5 3 6 2 3: 4 3 6 2 5 1 4: 6 5 3 4 2 1 4: 1 3 5 4 2 6 5: 2 3 1 4 5 6 5: 3 2 6 1 4 5 6: 3 1 2 5 6 4 6: 5 1 3 4 6 2 MENWOMEN Nogoods: {(6,1),(6,4),(4,1),(4,4), (5,1),(5,2),(5,3),(5,4),(5,5), (1,6),(2,6),(3,6),(4,6),(6,6)}

1: 1 3 6 2 4 5 1: 1 5 6 3 2 4 2: 4 6 1 2 5 3 2: 2 4 6 1 3 5 3: 1 4 5 3 6 2 3: 4 3 6 2 5 1 4: 6 5 3 4 2 1 4: 1 3 5 4 2 6 5: 2 3 1 4 5 6 5: 3 2 6 1 4 5 6: 3 1 2 5 6 4 6: 5 1 3 4 6 2 MENWOMEN

AC and EGS, the main results the Arc Consistent domains are (extended) Gale Shapley lists Enumerating all solutions using MAC can result in failure driven backtracking we have examples of this the domains are not GAC they may contain pairs that are not in any stable matching SAC would achieve GAC Using value ordering and MAC results in failure free enumeration AC on SM is O(n^4) whereas GS is O(n^2) There is an O(n^2) algorithm for achieving GAC

A brief history on how we got there 1. Naïve encoding of Davids exam question in choco (494) 2. Ian and Toby investigate constrainedness of SM (489,500) 3. Barbara encodes SM in Solver (497) … it would be nice if it could be solved polynomially in constraint programming. and … it might be possible to show that AC by itself is sufficient to remove all values which cannot participate in a solution … 4. David, Rob, Ian and Patrick improve propagation (495) 5. Barbara shows that enumerating solutions is not failure free (498) 6. Proof that AC domains are GS-lists (502) 7. Barbara finds a small counter example for (5) above From 1 to 7 in 3 weeks, with 6 people

Still to do 1. Prove that value ordering and MAC allows failure free enumeration 2. Explore the connection between rotations and MAC enumeration 3. Investigate how to efficiently encode AC and GAC for SM into a CP language 4. Investigate AC and SMI

Download ppt "The Stable Marriage Problem and Constraint Programming."

Similar presentations