Gale-Shapley algorithm 博弈算法

真是个比较好的算法,非常易用,老早就出来了,最近才得的诺奖

伪代码如下



Algorithm 伪代码
//GS算法婚姻配对
function stableMatching {
	//初始化所有m和w
    Initialize all m ∈ M and w ∈ W to free
    //如果存在自由男人没向所有的女人求过婚
	while ? free man m who still has a woman w to propose to {
       //w赋值为此男人当前得分最高的女人
	   w = m's highest ranked such woman to whom he has not yet proposed
       if w is free
         (m, w) become engaged
       else some pair (m', w) already exists
         if w prefers m to m'
           (m, w) become engaged
		   //下面一行隐含的操作是此男人的求婚列表向下一个移动
           m' becomes free
         else
           (m', w) remain engaged
    }
}







你可能感兴趣的:(Gale-Shapley algorithm 博弈算法)