the gale shapley algorithm

23
The Gale-Shapley Algorithm 老老 老老老 老老 老老老老 老老老 :、

Upload: phyrex-tsai

Post on 14-Apr-2017

218 views

Category:

Science


3 download

TRANSCRIPT

Page 1: The gale shapley algorithm

The Gale-Shapley Algorithm

老師:何瑁鎧學生:蔡詠捷、王芝吟

Page 2: The gale shapley algorithm

Agenda

• Stable Marriage Problem• Introduce • Gale-Shapley Algorithm• Algorithm Proof• Algorithm Big O• Pseudo Code• Animation Demo• Reference

Page 3: The gale shapley algorithm

Stable Marriage Problem

• 亦稱為 Stable matching problem• 給定兩個相同數量的元素集合• 每個元素給對面元素一個喜好排序• 讓彼此之間配對找出穩定配對• 配對:將兩邊的元素一對一組合成一組

Page 4: The gale shapley algorithm

Stable Marriage Problem

• 配對後需要達成每個人都有彼此的伴侶,並且提供給雙方的最大利益• 穩定配對– 假設 (A,B) 是一組配對– 不存在 A 男對 B’ 女喜好度大於現任妻子 B 女– 並且 B 女對 A’ 男喜好程度也大於現任丈夫 A 男

Page 5: The gale shapley algorithm

Stable Marriage Problem

• Stable marriage 的進行方式:– 給定兩組一樣的元素集合 , men 與 women– 每個元素給另外一個集合的元素進行喜好順序的排序– 進行每個元素的配對,依照求婚者喜好最高順序進行配對– 配對到兩兩元素間沒有比現在更好的選擇,配對就完成– 由上述條件可以知道,如果彼此間沒有更好的選擇,就代表這兩組元素是穩定配對

Page 6: The gale shapley algorithm

Introduce

• In 1962, David Gale and Lloyd Shapley proved that– For any equal number of men and women, it is

always possible to solve the SMP and make all marriages stable

Page 7: The gale shapley algorithm

Gale-Shapley Algorithm Concept

• 有 n 個男生與 n 個女生,每個男生將所有女生依據喜歡順序排成喜好列隊 (strictly ordered preference list) ,而每個女生也將所有男生依據喜歡順序排成喜好列隊

• M (match) 配對,是男生集合與女生集合的一個 1 to 1 對應

• PM(m)=w 與 PM(w)=m , w 是 m 的 M- 伴侶, m是 w 的 M- 伴侶

Page 8: The gale shapley algorithm

Gale-Shapley Algorithm Concept

• Blocking Pair : 若 (m,w) 在 M 中沒有配成一對, m喜歡 w 甚於 PM(m) ,而且 w 喜歡 m 甚於 PM(w) ,則稱 (m,w) 是 M 的阻撓對• Stable Match : 若配對 M 不存在阻撓對,則稱 M為穩定配對• Stable Pair : 若 (m,w) 在某一穩定配對中配成一對,則稱 (m,w) 為穩定對, m 與 w 互稱為穩定配偶

Page 9: The gale shapley algorithm

Gale-Shapley Algorithm

Page 10: The gale shapley algorithm

Gale-Shapley Algorithm

Page 11: The gale shapley algorithm

Gale-Shapley Algorithm

Page 12: The gale shapley algorithm

Gale-Shapley Algorithm

Page 13: The gale shapley algorithm

Gale-Shapley Algorithm

Page 14: The gale shapley algorithm

Gale-Shapley Algorithm

Page 15: The gale shapley algorithm

Gale-Shapley Algorithm

Page 16: The gale shapley algorithm

Stable Matching Proof

• 首先,每個男生都該被配到一個女生,這代表配對過程有正確進行• 若有男生沒被配到,表示他被所有女生拒絕• 可是女生拒絕他,表示當時已訂婚,又女生一旦訂婚只會換訂婚對象不會回到自由身• 因為男女的總數相同,這會導致矛盾

Page 17: The gale shapley algorithm

Stable Matching Proof

• 假設 m 喜歡 w 甚於 PM(m) ,則在演算中 w 曾拒絕m

• 當時因 w 較喜歡 m‘ 而拒絕 m , w 若有換訂婚對象也是換得比 m’ 更好的對象• 因此 w 喜歡 PM(w) 甚於 m ,因此 (m,w) 不會是 M的阻撓對,也就是說 M 沒有阻撓對, M 是穩定配對

Page 18: The gale shapley algorithm

Stable Matching Proof

• 假設 (m,w') 在 M 中不是一對,在某穩定配對M' 中為一對,而且 m 喜歡 w' 甚於 w=PM(m)

• m 在演算過程中必定曾遭 w' 拒絕• 我們可假設 m 是整個過程中第一個被穩定對的對象所拒絕的男人• m 被 w‘ 拒絕的原因是 w’ 喜歡當時的未婚夫 m‘ 甚於 m=PM′(w )′ ,又 w’ 是 m‘ 的穩定配偶中最喜歡的

( 因 m’ 不曾被被穩定對的對象所拒絕 ) ,所以m‘ 喜歡 w’ 甚於 PM′(m )≠w =P′ ′ M′(m) ,所以 (m‘,w’)是 M‘ 的阻撓對, M’ 不是穩定配對,產生矛盾

Page 19: The gale shapley algorithm

Algorithm Big O

• Assuming the same number of proposers and acceptors :– If exactly one proposer gets his last choice

woman, he will have proposed n times. – The remaining n−1 men are able to propose a

maximum of n−1 times so– (n−1)(n−1)+n = n2−2n+1+n = n2−n+1

Page 20: The gale shapley algorithm

Algorithm Big O

• The Gale-Shapley algorithm terminates after at most n2−n+1 proposals

• Time Complexity : T(n) = O(n2)

Page 21: The gale shapley algorithm

Pseudo Code

Page 22: The gale shapley algorithm

Animation Demo

• http://mathsite.math.berkeley.edu/smp/smp.html

Page 23: The gale shapley algorithm

Reference• https://en.wikipedia.org/wiki/Stable_marriage_problem• http://www.columbia.edu/~js1353/pubs/tst-ipco99.pdf• http://mathsite.math.berkeley.edu/smp/smp.html• http://www.sephlietz.com/gale-shapley/