Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.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 通过坐标的最短距离_Algorithm_Computational Geometry_Shortest Path - Fatal编程技术网

Algorithm 通过坐标的最短距离

Algorithm 通过坐标的最短距离,algorithm,computational-geometry,shortest-path,Algorithm,Computational Geometry,Shortest Path,在x-y平面上给我一组点={x1,y1,x2,y2,…xn,yn} 我得到了两个点axa,ya和bxb,yb,并要求我找到覆盖最短路径的点集 没有给出点之间的连接。如果我假设每一个点都有一个连接,计算加权图的这些值需要很长时间。谁能告诉我该做些什么。这个问题属于什么主题的图形算法?!!有没有什么特别的算法我已经在这上面呆了好几天了。注意:需要通过这些点。不能跳过这些点。无需移动集合中的每个点。只有到达B点的点以及这样做所覆盖的距离应该是最小的。例:{1,3,1,4,1,1,5,2,5,3,1,4

在x-y平面上给我一组点={x1,y1,x2,y2,…xn,yn}

我得到了两个点axa,ya和bxb,yb,并要求我找到覆盖最短路径的点集

没有给出点之间的连接。如果我假设每一个点都有一个连接,计算加权图的这些值需要很长时间。谁能告诉我该做些什么。这个问题属于什么主题的图形算法?!!有没有什么特别的算法我已经在这上面呆了好几天了。注意:需要通过这些点。不能跳过这些点。无需移动集合中的每个点。只有到达B点的点以及这样做所覆盖的距离应该是最小的。例:{1,3,1,4,1,1,5,2,5,3,1,4,2,2,1,2,1,3} 假设A=1,1,B=1,4,那么路径={1,1,1,2,1,3,1,4}
注意:路径不必是直线,也可以是之字形。

可能更正式的跨越点定义对于解决此问题至关重要。可以从计算不违反不跳跃规则的边的距离开始。下一步使用Dijkstra算法或A*处理图形。首先找到如何从数学上识别有效边。

由于我们一次最多可以移动两个距离单位,因此我们可以使用集合轻松实现DFS遍历,并且只需猜测点是否存在,因为我们必须猜测每个点最多8个点:

input: set points //a set of points that are placed on the grid
       point a
       point b
output: list path //a list of points, from a to b

map predecessor
predecessor.put(a , null)

set visited
visited.add(a)

//stores pairs consisting of (distance traveled , point)
//ordered ascending by distance to a
sortedset tovisit(sortyBy(pair::first , comparison::ascending)) 
tovisit.add(pair(0 , a))

//flag to check, if path was found
bool pathFound = false

while !tovisit.isEmpty()
    pair search = tovisit.remove(0)
    int dist = search.first()
    point pt = search.second()

    //check if we reached the end of the path
    if pt == b
        pathFound = true
        break

    //check if a point exists down from the current point
    //with a distance of at most 2 units that hasn't been visited
    point next = point(pt.x , pt.y + 1)
    if points.contains(next)
        if !visited.contains(next)
            predecessor.put(next , a)
            tovisit.add(pair(dist + 1 , next)
    else if points.contains(point(next.x , next.y + 1)
        next = point(pt.x , pt.y + 2)
        if !visited.contains(next)
            predecessor.put(next , a)
            tovisit.add(pair(dist + 2 , next)

    //proceed for other directions
    //...    

//build path
if !pathFound
    return null

list path
node tmp = b
do
    path.prepend(tmp)
    tmp = predecessor.get(tmp)
while tmp != null

return path
这段代码利用了这样一个事实,即我们在每个方向上最多只能遍历2个单位,因此我们最多只能检查8个方向


如果没有给出,我们必须首先构建一个表示网格的数据结构。一个简单的解决方案是构建一个网格,其中每个点都连接到^2上的直接邻居,并使用DFS遍历该网格。

您是指从A到b的最短路径还是访问从A开始到b结束的所有点的最短路径?前者只是一个简单的直接联系,后者被称为旅行商问题。你说的覆盖最短路径是什么意思?请给我们一些图像例子。主要的问题是:从a到b的真正限制是什么?它不仅仅是a->b绝对最短路径,它是否通过了所有点,通过了最少数量的点,通过了足够接近a-b的点,就像穿越了一张地图,其中的点就像是十字路口,还有别的什么吗?如果没有关于约束的信息,这个问题就没有什么意义。@DragonSurfer:跳跃不能超过2个单位。到访问点之间存在最大距离这一事实是您的问题中缺少的关键信息。下次试着从一开始就写下完整的问题陈述,你可能会得到有用的答案