【发布时间】:2015-04-23 21:41:42
【问题描述】:
我的问题如下:
Given a number of 2n points, I can calculate the distance between all points
and get a symmetrical matrix.
Can you create n pairs of points, so that the sum of the distance of all pairs is
minimal?
EDIT: Every point has to be in one of the pairs. Which means that
every point is only allowed to be in one pair.
我曾经天真地尝试过使用匈牙利算法,希望它能给我一个作业,让作业是对称的。但这显然不起作用,因为我没有二分图。
经过一番搜索,我找到了Stable roommates problem,这似乎和我的问题类似,但不同的是,它只是试图找到匹配,而不是试图最小化某种距离。
有没有人知道类似的问题甚至解决方案?我错过了什么?这个问题实际上看起来并不难,但我就是想不出一个最佳的解决方案。
【问题讨论】:
-
所以如果我理解正确的话,你有一个包含每个点之间距离的对称矩阵?为什么不将该矩阵转换为按距离 [start_point,end_point,distance] 排序的集合并选择前 n 对?
-
每个点只允许一对。如果我只按距离排序,这不能保证。我应该将此添加到问题描述中。
-
嗯,这确实使它变得更加困难。但是,您确定匈牙利算法不起作用吗?与其将其视为完整的无向图,不如将每个点拆分为两个点(源和目标),并将其视为完整的二分有向图。
标签: algorithm matrix hungarian-algorithm