Given are two sets of three-dimensional points, a source and a destination set. The number of points on each set is arbitrary (may be zero). The task is to assign one or no source point to every destination point, so that the sum of all distances is minimal. If there are more source than destination points, the additional points are to be ignored.
给定两组三维点,源和目标集。每组上的点数是任意的(可以是零)。任务是为每个目标点分配一个或没有源点,以便所有距离的总和最小。如果源位置多于目标点,则忽略其他点。
There is a brute-force solution to this problem, but since the number of points may be big, it is not feasible. I heard this problem is easy in 2D with equal set sizes, but sadly these preconditions are not given here.
这个问题有一个强力解决方案,但由于点数可能很大,因此不可行。我听说这个问题在2D中具有相同的设置尺寸很容易,但遗憾的是这些先决条件在这里没有给出。
I'm interested in both approximations and exact solutions.
我对近似和精确解决方案感兴趣。
Edit: Haha, yes, I suppose it does sound like homework. Actually, it's not. I'm writing a program that receives positions of a large number of cars and i'm trying to map them to their respective parking cells. :)
编辑:哈哈,是的,我想这听起来像家庭作业。实际上,事实并非如此。我正在编写一个接收大量汽车位置的程序,我正试图将它们映射到各自的停车位。 :)
3 个解决方案
#1
Off the top of my head, spatial sort followed by simulated annealing.
在我的头顶,空间排序,然后模拟退火。
Grid the space & sort the sets into spatial cells.
对空间进行网格化并将集合分类为空间单元格。
Solve the O(NM) problem within each cell, then within cell neighborhoods, and so on, to get a trial matching.
解决每个单元格内的O(NM)问题,然后解决单元格区域内的问题,等等,以获得试验匹配。
Finally, run lots of cycles of simulated annealing, in which you randomly alter matches, so as to explore the nearby space.
最后,运行大量的模拟退火循环,在其中随机改变匹配,以便探索附近的空间。
This is heuristic, getting you a good answer though not necessarily the best, and it should be fairly efficient due to the initial grid sort.
这是启发式的,虽然不一定是最好的,但是给你一个很好的答案,并且由于最初的网格排序,它应该是相当有效的。
#2
One way you could approach this problem is to treat is as the classical assignment problem: http://en.wikipedia.org/wiki/Assignment_problem
解决这个问题的一种方法是将待遇视为经典的分配问题:http://en.wikipedia.org/wiki/Assignment_problem
You treat the points as the vertices of the graph, and the weights of the edges are the distance between points. Because the fastest algorithms assume that you are looking for maximum matching (and not minimum as in your case), and that the weights are non-negative, you can redefine weights to be e.g.:
您将点视为图的顶点,边的权重是点之间的距离。因为最快的算法假设您正在寻找最大匹配(并且不是在您的情况下最小),并且权重是非负的,您可以将权重重新定义为例如:
weight(A, B) = bigNumber- distance(A,B)
where bigNumber
is bigger than your longest distance.
bigNumber大于你最长的距离。
Obviously you end up with a bipartite graph. Then you use one of the standard algorithms for maximum weighted bipartite matching (lots of resources on the web, e.g. http://valis.cs.uiuc.edu/~sariel/teach/courses/473/notes/27_matchings_notes.pdf or Wikipedia for overview: http://en.wikipedia.org/wiki/Perfect_matching#Maximum_bipartite_matchings) This way you will end-up with a O(NM max(N,M)) algoritms, where N and M are sizes of your sets of points.
显然你最终得到了一个二分图。然后使用一种标准算法进行最大加权二分匹配(网上有大量资源,例如http://valis.cs.uiuc.edu/~sariel/teach/courses/473/notes/27_matchings_notes.pdf或*概述:http://en.wikipedia.org/wiki/Perfect_matching#Maximum_bipartite_matchings)这样你最终得到一个O(NM max(N,M))算法,其中N和M是你的集合的大小点。
#3
Although I don't really have an answer to your question, I can suggest looking into the following topics. (I know very little about this, but encountered it previously on Stack Overflow.)
虽然我对你的问题没有真正的答案,但我可以建议你研究以下主题。 (我对此知之甚少,但之前在Stack Overflow上遇到过它。)
Hope this helps a bit.
希望这个对你有帮助。
#1
Off the top of my head, spatial sort followed by simulated annealing.
在我的头顶,空间排序,然后模拟退火。
Grid the space & sort the sets into spatial cells.
对空间进行网格化并将集合分类为空间单元格。
Solve the O(NM) problem within each cell, then within cell neighborhoods, and so on, to get a trial matching.
解决每个单元格内的O(NM)问题,然后解决单元格区域内的问题,等等,以获得试验匹配。
Finally, run lots of cycles of simulated annealing, in which you randomly alter matches, so as to explore the nearby space.
最后,运行大量的模拟退火循环,在其中随机改变匹配,以便探索附近的空间。
This is heuristic, getting you a good answer though not necessarily the best, and it should be fairly efficient due to the initial grid sort.
这是启发式的,虽然不一定是最好的,但是给你一个很好的答案,并且由于最初的网格排序,它应该是相当有效的。
#2
One way you could approach this problem is to treat is as the classical assignment problem: http://en.wikipedia.org/wiki/Assignment_problem
解决这个问题的一种方法是将待遇视为经典的分配问题:http://en.wikipedia.org/wiki/Assignment_problem
You treat the points as the vertices of the graph, and the weights of the edges are the distance between points. Because the fastest algorithms assume that you are looking for maximum matching (and not minimum as in your case), and that the weights are non-negative, you can redefine weights to be e.g.:
您将点视为图的顶点,边的权重是点之间的距离。因为最快的算法假设您正在寻找最大匹配(并且不是在您的情况下最小),并且权重是非负的,您可以将权重重新定义为例如:
weight(A, B) = bigNumber- distance(A,B)
where bigNumber
is bigger than your longest distance.
bigNumber大于你最长的距离。
Obviously you end up with a bipartite graph. Then you use one of the standard algorithms for maximum weighted bipartite matching (lots of resources on the web, e.g. http://valis.cs.uiuc.edu/~sariel/teach/courses/473/notes/27_matchings_notes.pdf or Wikipedia for overview: http://en.wikipedia.org/wiki/Perfect_matching#Maximum_bipartite_matchings) This way you will end-up with a O(NM max(N,M)) algoritms, where N and M are sizes of your sets of points.
显然你最终得到了一个二分图。然后使用一种标准算法进行最大加权二分匹配(网上有大量资源,例如http://valis.cs.uiuc.edu/~sariel/teach/courses/473/notes/27_matchings_notes.pdf或*概述:http://en.wikipedia.org/wiki/Perfect_matching#Maximum_bipartite_matchings)这样你最终得到一个O(NM max(N,M))算法,其中N和M是你的集合的大小点。
#3
Although I don't really have an answer to your question, I can suggest looking into the following topics. (I know very little about this, but encountered it previously on Stack Overflow.)
虽然我对你的问题没有真正的答案,但我可以建议你研究以下主题。 (我对此知之甚少,但之前在Stack Overflow上遇到过它。)
Hope this helps a bit.
希望这个对你有帮助。