Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 三维空间中点间K最小距离的搜索_Algorithm_Math_Optimization_Set_Distance - Fatal编程技术网

Algorithm 三维空间中点间K最小距离的搜索

Algorithm 三维空间中点间K最小距离的搜索,algorithm,math,optimization,set,distance,Algorithm,Math,Optimization,Set,Distance,我有两个不相交的三维点集。我需要找到具有最小距离的k对点。每个点都有(x,y,z)坐标 约束条件:该解决方案必须是一个连续的最优解决方案。请不要使用多线程。可以使用分而治之/动态规划等方法 我目前的做法是: listOfPairs = [] for all points a in setA for all points b in setB distance = calcDistance(a, b) listOfPairs.append((a, b, dis

我有两个不相交的三维点集。我需要找到具有最小距离的k对点。每个点都有(x,y,z)坐标

约束条件:该解决方案必须是一个连续的最优解决方案。请不要使用多线程。可以使用分而治之/动态规划等方法

我目前的做法是:

listOfPairs = []
for all points a in setA
    for all points b in setB
        distance = calcDistance(a, b)
        listOfPairs.append((a, b, distance))

sortByDistance(distance) // using the built in sort method
PrintPointsAndDistances(listOfPairs, k) // print the first k elements

谢谢。

这可以通过优先级队列完成。正如你所做的

priorityQueue = PriorityQueue(k) // of size k
for all points a in setA
    for all points b in setB
        distance = calcDistance(a, b)
        priorityQueue.push_with_priority((a, b), distance)

剩下的是k个最短距离对,算法将在Θ(N*log(k))中运行。

关于k-D树呢?@meowgoestedog:kD树可能是一个有用的成分,但您需要详细说明。这个问题的用途并不简单,我的错。我正在考虑将较大的点集添加到k-D树中,并对较小集中的每个点执行操作,即
O((n+m)log(n+m))
而不是
O(nm)
(使用快速排序样式k-min)。@meowgoestedog,谢谢。你能详细说明一下吗?我看了k-D树,仍然不知道如何使用它来找到距离最小的k对原子。@ArjunC链接的Wikipedia部分描述了一种算法,可以在k-D树中找到距离任意查询点最近的点,对于随机分布的点,时间大约为对数。在Google上搜索很可能会得到很多现有的实现(比如)。(这假设
k
远小于
~nm
的总对数)谢谢。你知道我如何限制C++中的优先级队列的大小吗?看起来你需要自己做。您可以包装一个std::set,并且在每次推送时,如果大小已经为N个元素,则将最后一个元素作为set.erase(set.end())删除,并将删除指定为摊销常量时间。