Given a group of people, where each pair has a value, how can I find the configuration of pairings with the least total value?

我们两清 提交于 2020-01-04 05:15:12

问题


It's very much like the Assignment Problem, except with a complete undirected graph rather than a bipartite graph.

The dumbest, most brute force-iest solution is something like this:

  1. Get all possible configurations of pairs...

    groups = people.combination(2).to_a.combination(people.size/2).to_a

  2. ...rejecting all of the configurations that contain the same person more than once.

    groups.reject! { |group| group.flatten.uniq.size < people.size }

  3. Then find the configuration with the minimum value.

    groups.min_by { |group| group.inject(0) { |pair| value_for(pair) }

Is there a modification of the Branch and Bound solution for the Assignment Problem that takes into account that, here, the Job and Person are both People?

Could there be another combinatorics problem which more closely resembles what I've presented?

How can I get the best solution without frying my CPU?

Thanks!


回答1:


This is possible in polynomial time with https://en.wikipedia.org/wiki/Blossom_algorithm#Weighted_matching.



来源:https://stackoverflow.com/questions/34933386/given-a-group-of-people-where-each-pair-has-a-value-how-can-i-find-the-configu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!