Stable marriage problem笔记

来源:互联网 发布:淘宝质量好的牛仔裤 编辑:程序博客网 时间:2024/05/21 21:39

Stable marriage problem


1.前言

看到一篇有意思的文章,讲配对算法的,写篇笔记记录一下~
How a matchmaking algorithm saved lives

例如傲慢与偏见里的人物,如果用算法给他们自动配对,岂不是很有意思~


2.算法

翻译 维基百科
the stable marriage problem (also stable matching problem or SMP) is the problem of finding a stable matching between two equally sized sets of elements given an ordering of preferences for each element. 简单翻译,稳定婚姻问题就是两个集合找配对的问题。

A matching is stable whenever it is not the case that both the following conditions hold. 一个匹配是稳定的,以下两个条件不能同时成立。

  • There is an element A of the first matched set which prefers some given element B of the second matched set over the element to which A is already matched, and
    A对于自己的匹配,更喜欢B
  • B also prefers A over the element to which B is already matched.
    B对于自己的匹配,更喜欢A

具体步骤
In the first round,
a) each unengaged man proposes to the woman he prefers most, and then
b) each woman replies “maybe” to her suitor she most prefers and “no” to all other suitors. She is then provisionally “engaged” to the suitor she most prefers so far, and that suitor is likewise provisionally engaged to her.
In each subsequent round,
a) each unengaged man proposes to the most-preferred woman to whom he has not yet proposed (regardless of whether the woman is already engaged), and then
b) each woman replies “maybe” if she is currently not engaged or if she prefers this guy over her current provisional partner (in this case, she rejects her current provisional partner who becomes unengaged).
This process is repeated until everyone is engaged.
The runtime complexity of this algorithm is O(n2) where n is number of men or women

第一回合
a) 所有没订婚的男士,向他们最喜欢的女士求婚
b) 所有没订婚的女士,对其求婚者中最喜欢的回复”maybe”, 对其他求婚者回复”no”
其余回合
a) 所有没订婚的男士,向他们没求过婚的最喜欢的女士求婚(不管该女士是否订婚)
b) 所有女士,依次考虑其每个求婚者,如果该女士没有订婚,则回复”maybe”与该求婚者订婚;如果已经订婚,但更喜欢该求婚者,则回复”maybe”与该求婚者订婚,被抛弃的订婚者变成未订婚者
重复该过程直到所有人订婚 (男女人数一样)

算法时间复杂度 O(n2)


3.应用

  • 医生和医院的匹配
  • 学生和学校的匹配

  • 肾脏捐献者和接收者匹配

In 2012, the Nobel Prize in Economics was awarded to Lloyd S. Shapley and Alvin E. Roth “for the theory of stable allocations and the practice of market design.”
论文作者在2012年获得诺贝尔经济学奖

论文:
College Admissions and the Stability of Marriage Gale, D.; Shapley, L. S. (1962). American Mathematical Monthly

0 0