Blah blah blah. Zoes shark Thanks to the conference artist Phoebe.

Presentation on theme: "Blah blah blah. Zoes shark Thanks to the conference artist Phoebe."— Presentation transcript:

Blah blah blah

Zoes 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 12341234 and n women : 2 3 4 1 : 3 2 1 4 : 1 3 4 2 : 4 1 2 3 Each man ranks the n women : 3 1 2 4 : 2 1 4 3 : 1 3 2 4 : 4 3 1 2 12341234 and each woman ranks the men MenWomen 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 m i marries woman w j woman w j marries man m i No, not bigamy … bijection

Stable?An example 12341234 : 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 12341234 man 2 prefers woman 1 to woman 4 woman 1 prefers man 2 to man 3 man 2 and woman 1 will elope man 2 marries woman 4 man 3 marries woman 1

There are algorithms for this The Gale Shapely algorithm, O(n 2 ) problem has n variables, each with n partners and is of size O(n 2 ) 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)) // ms most preferred partner 2.3 if isMarried(w) // unconditional remarriage! 2.3.1 L := add(L,partner(w)) // ws 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 youve 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

An example of the male-oriented extended Gale-Shapely algorithm Male-oriented EGS

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 Free: 1,2,3,4 m = 1 (first free man) w = 3 (man 1s first choice) engaged(m,w) delete pairs :,, 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 2s first choice) engaged(m,w) delete pairs :, 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 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

Free: 3,4 m = 3 (first free man) w = 1 (man 3s first choice) engaged(m,w) delete pairs :, 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 4s first choice) engaged(m,w) delete pairs :,, 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 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 4: 4

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 after Male-oriented EGS Men 1: 3 2: 2 1 3: 1 2 4: 4 Women 1: 2 3 2: 3 2 3: 1 4: 4 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 1 st stab) 12341234 : 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 12341234 2n variables, each with a domain (1.. n) n 2 channeling constraints v i = j v j = i n 2 stability constraints 2 allDiffs (one for men, one for women) done

Whats a stability constraint? 12341234 : 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 12341234 n 2 stability constraints An example, between man m 4 and woman w 3 (1) locate position of w 3 in m 4 s preference list (2) locate position of m 4 in w 3 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(n 4 ) allDiffs are redundant No good news then?

Hey! It was a 1 st stab!

Combining the Constraints The channeling constraints guarantee a bijection 12341234 : 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 12341234 m 4 = 3 w 3 = 4 Nogoods: m 4 marries w 3 and w 3 marries some one else! {(3,1),(3,3),(3,2)} Nogoods: w 3 marries m 4 and m 4 marries some one else! {(4,4),(1,4),(2,4)}

Combining the Constraints 12341234 : 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 12341234 (m 4 = 3 w 3 = 4) stable(m 4,w 3 ) 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

Arc consistency now computes the GS-lists we have a proof We have failure free enumeration with a value ordering heuristic we have a proof The encoding trivially extends to SMTI (an NP-complete problem) The encoding is O(n 4 ) So, some good news then? Combining the Constraints

The constraint has structure 12341234 : 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 12341234 Combined nogoods: {(3,1),(3,3),(3,2),(4,4),(1,4),(2,4),(1,2),(2,2)} m4m4 w3w3 m4m4 w3w3 Arrange in preference order Cant see it?

The constraint has structure 12341234 : 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 12341234 Combined nogoods: {(3,1),(3,3),(3,2),(4,4),(1,4),(2,4),(1,2),(2,2)} m4m4 w3w3 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 w k is top of m i s listm i is top of w k s list mimi wkwk mimi wkwk Done Revise(i,k)

Nice, interesting, … but still O(n 4 )

An O(n 2 ) encoding (a 1 st stab) The intuition, part 1a Man to woman: I love you. Marry me. Please say yes! Woman to man: thats the best offer Ive 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! Ive married someone better than you. Beat it! Man to man: Och well. Theres always someone else. In a mans world

An O(n 2 ) encoding (a 1 st stab) The intuition, part 1.1b Assume man m i has proposed to his j th choice, woman w k assume w k is engaged to someone she prefers to m i m i should then propose to his j+1 th choice The intuition, part 1.1a Assume man m i has proposed to his j th choice, woman w k assume w k is not engaged to someone she prefers to m i w k should reject any proposals from men less preferred than m i The following description is male-oriented and has a symmetric female orientation

An O(n 2 ) encoding (a 1 st stab) w k,h = 0 w k has accepted a proposal from better than her h th choice w k,h = 0 w k,h+1 = 0 If w k has accepted a proposal from her h th choice or better then w k has accepted a proposal from her h+1 th choice or better m i,j = 1 m i has proposed to his j th choice or worse

An O(n 2 ) encoding (a 1 st stab) m 3 proposes to 2 nd choice w 6 has been proposed to by better than her 5 th

An O(n 2 ) encoding, the stability constraints Suppose man m i has a partner no better than j th choice, i.e. m i,j = 1 and j th choice is woman w k preference person Man m 3 proposed to his 2 nd choice, w 6 Suppose woman w k has a partner better than h th choice, i.e. w k,h = 0 and h th choice is man m i preference person Woman w 6 has a partner better than her 7 th choice, m 3 Therefore m i is rejected by w k, and m i has a partner no better than his j+1 th choice, i.e. m i,j+1 = 1

m i is rejected by w k, and m i has a partner no better than his j+1 th choice, i.e. m i,j+1 = 1 w k is m i s jth choice m i is w k s h th choice the constraint is An O(n 2 ) encoding, the stability constraints This increments the pointer to the head of m i s preference list

Otherwise m i becomes engaged to w k, and w k now has a partner better than her h+1 th choice, i.e. w k,h+1 = 0 w k is m i s jth choice m i is w k s h th choice This deletes the tail of w k s preference list An O(n 2 ) encoding, the stability constraints

An O(n 2 ) encoding Obviously, symmetrically we have the female orientation

An O(n 2 ) encoding On the completion of (male-oriented) propagation the preference list for m i the maximum value of j such that m ij = 1 gives the head of the list the preference list for w i minimum value of j such that w i,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(n 2 ) encoding … the complexity 2n 2 variables domains are {0,1} 6n(n-1) constraints arc consistency complexity is O(ed r ) 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(n 2 ) This is same complexity as the GS algorithm, and is linear in the size of the input. It is optimal

A 2 nd 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(n 4 ) space 0/1 encoding gives us XGS-lists and failure free enumeration for SMI O(n 2 ), 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?

Download ppt "Blah blah blah. Zoes shark Thanks to the conference artist Phoebe."

Similar presentations