Blah blah blah
Zoe’s shark
Thanks to the conference artist Phoebe
A Constraint Programming Approach to The Stable Marriage Problem
What is the Stable Marriage Problem? (SM) We have n men and n women Each man ranks the n women and each woman ranks the men Men Women 1 2 3 4 : 3 1 2 4 : 2 1 4 3 : 1 3 2 4 : 4 3 1 2 1 2 3 4 : 2 3 4 1 : 3 2 1 4 : 1 3 4 2 : 4 1 2 3 Each man has to marry a woman. Bigamy is not allowed. Marriages must be stable done
No Bigamy? There is a bijection from men to women man mi marries woman wj woman wj marries man mi No, not bigamy … bijection
Stable? An example 1 2 3 4 : 2 3 4 1 : 3 2 1 4 : 1 3 4 2 : 4 1 2 3 : 3 1 2 4 : 2 1 4 3 : 1 3 2 4 : 4 3 1 2 man 2 marries woman 4 <2,4> man 3 marries woman 1 <3,1> man 2 prefers woman 1 to woman 4 woman 1 prefers man 2 to man 3 man 2 and woman 1 will elope
There are algorithms for this The Gale Shapely algorithm, O(n2) problem has n variables, each with n partners and is of size O(n2) The complexity of the algorithm is linear in the size of the input
The Extended Gale Shapley Algorithm (man optimal) 1 L := list of free men 2. While L 2.1 m := selectAndRemoveFrom(L) // note, m is removed from L 2.2 w := first(preferenceList(m)) // m’s most preferred partner 2.3 if isMarried(w) // unconditional remarriage! 2.3.1 L := add(L,partner(w)) // w’s partner is free … again! 2.3.2 delete(preferenceList(w),partner(w)) 2.3.3 delete(preferenceList(partner(w)),w) 2.4 marry(m,w) // m and w get married. 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) Now you’ve seen it
The Extended Gale Shapley Algorithm (man optimal) “… reduces the preference lists by eliminating pairs that can readily be identified as not belonging to any stable matching” Gusfield and Irving, 1989
male-oriented extended Gale-Shapely algorithm An example of the male-oriented extended Gale-Shapely algorithm Male-oriented EGS
Free: 1,2,3,4 m = 1 (first free man) w = 3 (man 1’s first choice) engaged(m,w) delete pairs : <3,3>,<4,3>,<2,3> Men 1: 3 1 2 4 2: 2 1 4 3 3: 1 3 2 4 4: 4 3 1 2 Women 1: 2 3 4 1 2: 3 2 1 4 3: 1 3 4 2 4: 4 1 2 3 Men 1: 3 1 2 4 2: 2 1 4 3 3: 1 3 2 4 4: 4 3 1 2 Women 1: 2 3 4 1 2: 3 2 1 4 3: 1 3 4 2 4: 4 1 2 3 Men 1: 3 1 2 4 2: 2 1 4 3 3: 1 3 2 4 4: 4 3 1 2 Women 1: 2 3 4 1 2: 3 2 1 4 3: 1 3 4 2 4: 4 1 2 3 Men 1: 3 1 2 4 2: 2 1 4 3: 1 2 4 4: 4 1 2 Women 1: 2 3 4 1 2: 3 2 1 4 3: 1 4: 4 1 2 3
Free: 2,3,4 m = 2 (first free man) w = 2 (man 2’s first choice) engaged(m,w) delete pairs : <1,2>,<4,2> Men 1: 3 1 2 4 2: 2 1 4 3: 1 2 4 4: 4 1 2 Women 1: 2 3 4 1 2: 3 2 1 4 3: 1 4: 4 1 2 3 Men 1: 3 1 2 4 2: 2 1 4 3: 1 2 4 4: 4 1 2 Women 1: 2 3 4 1 2: 3 2 1 4 3: 1 4: 4 1 2 3 Men 1: 3 1 4 2: 2 1 4 3: 1 2 4 4: 4 1 Women 1: 2 3 4 1 2: 3 2 3: 1 4: 4 1 2 3 Men 1: 3 1 2 4 2: 2 1 4 3: 1 2 4 4: 4 1 2 Women 1: 2 3 4 1 2: 3 2 1 4 3: 1 4: 4 1 2 3
Free: 3,4 m = 3 (first free man) w = 1 (man 3’s first choice) engaged(m,w) delete pairs : <4,1>,<1,1> Men 1: 3 1 4 2: 2 1 4 3: 1 2 4 4: 4 1 Women 1: 2 3 4 1 2: 3 2 3: 1 4: 4 1 2 3 Men 1: 3 1 4 2: 2 1 4 3: 1 2 4 4: 4 1 Women 1: 2 3 4 1 2: 3 2 3: 1 4: 4 1 2 3 Men 1: 3 1 4 2: 2 1 4 3: 1 2 4 4: 4 1 Women 1: 2 3 4 1 2: 3 2 3: 1 4: 4 1 2 3 Men 1: 3 1 4 2: 2 1 4 3: 1 2 4 4: 4 1 Women 1: 2 3 4 1 2: 3 2 3: 1 4: 4 1 2 3 Men 1: 3 4 2: 2 1 4 3: 1 2 4 4: 4 Women 1: 2 3 2: 3 2 3: 1 4: 4 1 2 3
Free: 4 m = 4 (first free man) w = 4 (man 4’s first choice) engaged(m,w) delete pairs : <1,4>,<2,4>,<3,4> Men 1: 3 4 2: 2 1 4 3: 1 2 4 4: 4 Women 1: 2 3 2: 3 2 3: 1 4: 4 1 2 3 Men 1: 3 4 2: 2 1 4 3: 1 2 4 4: 4 Women 1: 2 3 2: 3 2 3: 1 4: 4 1 2 3 Men 1: 3 2: 2 1 3: 1 2 4: 4 Women 1: 2 3 2: 3 2 3: 1 Men 1: 3 4 2: 2 1 4 3: 1 2 4 4: 4 Women 1: 2 3 2: 3 2 3: 1 4: 4 1 2 3
Male-oriented EGS Free: Men 1: 3 1 2 4 2: 2 1 4 3 3: 1 3 2 4 4: 4 3 1 2 Women 1: 2 3 4 1 2: 3 2 1 4 3: 1 3 4 2 4: 4 1 2 3 before Men 1: 3 2: 2 1 3: 1 2 4: 4 Women 1: 2 3 2: 3 2 3: 1 after done
The Extended Gale Shapley Algorithm (man optimal) On completion we have man optimal GS-lists if men marry their 1st partners we get man optimal stable marriages female pessimal stable marriages We can also apply female oriented EGS The intersection of the man and woman lists gives us GS-lists
A Constraint Encoding (a 1st stab) 2 3 4 : 2 3 4 1 : 3 2 1 4 : 1 3 4 2 : 4 1 2 3 : 3 1 2 4 : 2 1 4 3 : 1 3 2 4 : 4 3 1 2 2n variables, each with a domain (1 .. n) n2 channeling constraints vi = j vj = i n2 stability constraints 2 allDiff’s (one for men, one for women) done
What’s a stability constraint? n2 stability constraints 1 2 3 4 : 2 3 4 1 : 3 2 1 4 : 1 3 4 2 : 4 1 2 3 : 3 1 2 4 : 2 1 4 3 : 1 3 2 4 : 4 3 1 2 An example, between man m4 and woman w3 (1) locate position of w3 in m4’s preference list (2) locate position of m4 in w3’s preference list (3) compute the Cartesian product beyond these points {(1,2),(2,2)} these are nogoods done
Arc consistency does not compute the GS-lists We require search Encoding is O(n4) allDiff’s are redundant No good news then?
Hey! It was a 1st stab!
Combining the Constraints The channeling constraints guarantee a bijection 1 2 3 4 : 2 3 4 1 : 3 2 1 4 : 1 3 4 2 : 4 1 2 3 : 3 1 2 4 : 2 1 4 3 : 1 3 2 4 : 4 3 1 2 m4 = 3 w3 = 4 Nogoods: m4 marries w3 and w3 marries some one else! {(3,1),(3,3),(3,2)} Nogoods: w3 marries m4 and m4 marries some one else! {(4,4),(1,4),(2,4)}
Combining the Constraints 1 2 3 4 : 2 3 4 1 : 3 2 1 4 : 1 3 4 2 : 4 1 2 3 : 3 1 2 4 : 2 1 4 3 : 1 3 2 4 : 4 3 1 2 (m4 = 3 w3 = 4) stable(m4,w3) Combined nogoods: {(3,1),(3,3),(3,2),(4,4),(1,4),(2,4),(1,2),(2,2)} Do this for all man/woman pairs
Combining the Constraints Arc consistency now computes the GS-lists we have a proof We have failure free enumeration with a value ordering heuristic The encoding trivially extends to SMTI (an NP-complete problem) The encoding is O(n4) So, some good news then?
The constraint has structure 1 2 3 4 : 2 3 4 1 : 3 2 1 4 : 1 3 4 2 : 4 1 2 3 : 3 1 2 4 : 2 1 4 3 : 1 3 2 4 : 4 3 1 2 Combined nogoods: {(3,1),(3,3),(3,2),(4,4),(1,4),(2,4),(1,2),(2,2)} m4 w3 m4 w3 Arrange in preference order Can’t see it?
The constraint has structure 1 2 3 4 : 2 3 4 1 : 3 2 1 4 : 1 3 4 2 : 4 1 2 3 : 3 1 2 4 : 2 1 4 3 : 1 3 2 4 : 4 3 1 2 Combined nogoods: {(3,1),(3,3),(3,2),(4,4),(1,4),(2,4),(1,2),(2,2)} m4 w3 I is illegal, bigamy B is blocking, unstable A is allowed More generally
Revision of constraints Revising only certain shapes of constraints has an effect mi wk mi wk wk is top of mi’s list mi is top of wk’s list Revise(i,k) Revise(i,k) Done
Nice, interesting, … but still O(n4)
An O(n2) encoding (a 1st stab) In a man’s world The intuition, part 1a Man to woman: I love you. Marry me. Please say yes! Woman to man: that’s the best offer I’ve had. Okay. (and by the way, all you other guys, beat it!) The intuition, part 1b Man to woman: I love you. Marry me. Please say yes! Woman to man: Who do you think you are! I’ve married someone better than you. Beat it! Man to man: Och well. There’s always someone else.
An O(n2) encoding (a 1st stab) The intuition, part 1.1a Assume man mi has proposed to his jth choice, woman wk assume wk is not engaged to someone she prefers to mi wk should reject any proposals from men less preferred than mi The intuition, part 1.1b Assume man mi has proposed to his jth choice, woman wk assume wk is engaged to someone she prefers to mi mi should then propose to his j+1th choice The following description is male-oriented and has a symmetric female orientation
An O(n2) encoding (a 1st stab) mi,j = 1 mi has proposed to his jth choice or worse wk,h = 0 wk has accepted a proposal from better than her hth choice wk,h = 0 wk,h+1 = 0 If wk has accepted a proposal from her hth choice or better then wk has accepted a proposal from her h+1th choice or better
An O(n2) encoding (a 1st stab) m3 proposes to 2nd choice w6 has been proposed to by better than her 5th
An O(n2) encoding, the stability constraints preference person Man m3 proposed to his 2nd choice, w6 Suppose man mi has a partner no better than jth choice, i.e. mi,j = 1 and jth choice is woman wk Suppose woman wk has a partner better than hth choice, i.e. wk,h = 0 and hth choice is man mi preference person Woman w6 has a partner better than her 7th choice, m3 Therefore mi is rejected by wk, and mi has a partner no better than his j+1th choice, i.e. mi,j+1 = 1
An O(n2) encoding, the stability constraints mi is rejected by wk, and mi has a partner no better than his j+1th choice, i.e. mi,j+1 = 1 wk is mi’s jth choice mi is wk’s hth choice the constraint is This increments the pointer to the head of mi’s preference list
An O(n2) encoding, the stability constraints Otherwise mi becomes engaged to wk, and wk now has a partner better than her h+1th choice, i.e. wk,h+1 = 0 wk is mi’s jth choice mi is wk’s hth choice This deletes the tail of wk’s preference list
An O(n2) encoding Obviously, symmetrically we have the female orientation
An O(n2) encoding On the completion of (male-oriented) propagation the preference list for mi the maximum value of j such that mij = 1 gives the head of the list the preference list for wi minimum value of j such that wi,j+1 = 0 gives the tail of the list when we do male and female propagation we get the XGS-list, a superset of the GS-list = (6,5,3) = (5,6)
An O(n2) encoding … the complexity 2n2 variables domains are {0,1} 6n(n-1) constraints arc consistency complexity is O(edr) where e is number of constraints d is domain size r is arity of constraints for our encoding e = 6n(n-1), d = 2, r 3 O(n2) This is same complexity as the GS algorithm, and is linear in the size of the input. It is optimal
A 2nd stab at the 0/1 encoding Generalises to incomplete list (SMI) we prove that the AC on the 0/1 model gives XGS-lists we prove that we get failure free enumeration
Conclusions A naïve encoding as a csp However, combining the constraints AC gives us GS-lists and failure free enumeration easily extend to SMTI O(n4) space 0/1 encoding gives us XGS-lists and failure free enumeration for SMI O(n2), optimal! Non-trivial SM constraint may be part of a bigger problem something like allDiff Question “If there is a special algorithm, such as GS, is it worth encoding as a csp?” In this case “Yes.”
Questions?