[英]Find matching couples to maximize global happiness
A belated Valentines day question for you all:一个迟来的情人节问题给大家:
Suppose we have M men an W women, and they are all heterosexual.假设我们有 M 个男人和 W 个女人,他们都是异性恋。 We have a (MxW) matrix A where
A[m, w]
quantifies how happy the couple (m, w)
would be if married.我们有一个 (MxW) 矩阵 A,其中
A[m, w]
量化了这对夫妇(m, w)
结婚后的幸福程度。
How can we pair the couples so that the global maximum happiness is achieved?我们如何配对夫妻才能实现全球最大的幸福? (ie I'm looking to produce a length
min(M, W)
array of 2-tuples identifying who should be paired up, such that sum(A[m, w] for m, w in couples)
is maximized, and each m
and each w
is only used once. (即,我希望生成一个长度为
min(M, W)
的 2 元组数组,以确定谁应该配对,这样sum(A[m, w] for m, w in couples)
被最大化,并且每个m
并且每个w
只使用一次。
Note 1: Ideally I'm looking for a fast numpy implementation, but that's kind of secondary to finding the right algorithm.注 1:理想情况下,我正在寻找一种快速的 numpy 实现,但这对于找到正确的算法来说是次要的。
Note 2: This is similar, but not the same as the Stable Marriage Problem , where you specify each person's ranked preferences instead of a happiness value.注 2:这与稳定婚姻问题类似,但不同的是,您指定每个人的排名偏好而不是幸福值。
Well, thanks to the commenters for pointing out that this is the Assignment Problem , and is usually described in terms of workers and jobs.好吧,感谢评论者指出这是分配问题,通常以工人和工作的形式描述。
Scipy has a function that solves it using the Hungarian Algorithm. Scipy 有一个使用匈牙利算法解决它的函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.