A belated Valentines day question for you all:
Suppose we have M men an W women, and they are all heterosexual. We have a (MxW) matrix A where A[m, w]
quantifies how happy the couple (m, w)
would be if married.
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.
Note 1: Ideally I'm looking for a fast numpy implementation, but that's kind of secondary to finding the right algorithm.
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.