【问题标题】:Getting the best combination of closest pairs between 2 sets of points获得两组点之间最近对的最佳组合
【发布时间】:2015-10-22 16:14:23
【问题描述】:

我必须设置点,比如说设置 A 和 B

  • A 和 B 大小相等
  • A 的每个元素都与 B 的一个元素耦合

A 的所有点都必须“移动”到 B 的一个点,但 B 的一个点不能耦合到 A 的多个点。

我需要找到最佳组合,其中总(步行)距离(从每对之间的距离相加)是最小的。

出于演示目的,我在 Java 中做了一个示例(目前暴力破解所有可能的组合并检查总距离最小的组合)

示例 1

示例 2

绿色矩形表示集合 A 中的一个点,青色矩形表示集合 B 中的一个点,忽略橙色方块

我该如何处理?

【问题讨论】:

    标签: java algorithm closest-points


    【解决方案1】:

    这是一个assignment problemHungarian algorithm 可以在 O(n³) 时间内解决。找到源代码或自己实现应该不会太难。

    【讨论】:

      【解决方案2】:
      loop over A points
        find closest B point NOT already connected to A point
      

      这将以最少的处理时间提供一个不错的启动解决方案

      如果你还有一些额外的时间,然后尝试改进

      loop over connections
         loop over connections with index greater then selected in previous loop
            sum total length of two connections
            swap connection pairs
            sum total length of swapped connections
            if swap is less
               replace original with swapped
            if reached time budget
               end
      

      【讨论】:

        猜你喜欢
        • 2012-08-18
        • 2019-03-01
        • 1970-01-01
        • 2019-02-17
        • 2012-01-20
        • 1970-01-01
        • 2023-03-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多