150 likes | 291 Views
The Stable Marriage Problem and Constraint Programming. What is a SM?. MEN. WOMEN. 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
E N D
What is a SM? MEN WOMEN 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 do you mean by “stable”? - assume mx is married to wx, and mx prefers wy to wx and wx prefers my to mx - this is okay so long as wy prefers her partner to mx and my prefers his partner to wx Harrison Ford is not going to leave his wife and take Andrea away from me
A Blocking Pair MEN WOMEN 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 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 MEN WOMEN 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 35 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
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)) // m’s 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 MEN WOMEN 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 • 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 MEN WOMEN 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 • 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 MEN WOMEN 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 • 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 MEN WOMEN 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 • 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
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 David’s 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