【问题标题】:Path that gets within given distance of each point in order按顺序到达每个点的给定距离内的路径
【发布时间】:2021-04-07 21:20:33
【问题描述】:

我有一个二维平面中点的有序列表。我想找到最短的路线,使其至少按照给定的顺序在距每个点的距离 X (或更近)内。如何找到这条路线?

我意识到将确定路线(那里的方向改变)的点将位于周长 X 的圆上,以输入点本身为中心,但我没有进一步了解。

我正在 Python 中实现这一点,但很高兴获得任何理论上的帮助。

示例:(哎呀,我数不过来,所以跳过了 7)

【问题讨论】:

  • 这是旅行商问题的概括,所以我将从那里开始。 en.wikipedia.org/wiki/Travelling_salesman_problem
  • @kaya3 这不是 TSP - 点有一个给定的顺序
  • 您能否在问题中添加更多详细信息,这似乎是 BFS 的一个特定案例。
  • @Mouse 我编辑了问题以添加一个近似的手工示例。我不明白 BFS 是如何关联的
  • 是否允许使用近似值?感觉点相互依赖,但是2-3跳后依赖效果很快就消失了……

标签: algorithm shortest-path euclidean-distance plane


【解决方案1】:

也许有一种分析方法,但这个问题当然可以通过凸规划来解决。这是一个使用 cvxpy 输出 EPS 的 Python 实现。

import cvxpy as cp
import numpy as np


def objective(points):
    return np.sum(np.linalg.norm(points[1:] - points[:-1]))


def shortest_path(x, centers):
    points = cp.reshape(cp.Variable(centers.size), centers.shape)
    cost = cp.sum(cp.norm(points[1:] - points[:-1], axis=1))
    constraints = []
    for i, center in enumerate(centers):
        constraints.append(cp.SOC(x, points[i] - center))
    prob = cp.Problem(cp.Minimize(cost), constraints)
    prob.solve()
    return points.value


def main():
    x = 0.05
    centers = np.random.random_sample((10, 2))
    points = shortest_path(x, centers)
    print("%!PS-Adobe-3.0 EPSF-3.0")
    print("%%BoundingBox:0 0 504 504")
    print("72 dup translate")
    print("360 dup scale")
    print("0 setlinewidth")
    for center in centers:
        print(*center, x, 0, 360, "arc")
        print("stroke")
    for i, point in enumerate(points):
        print(*point, "lineto" if i else "moveto")
    print("stroke")


if __name__ == "__main__":
    main()

【讨论】:

    【解决方案2】:

    看来你必须找到距离路线中下一个点 x minimux x 点的最小距离。

    我建议找到起点和所有圆周之间的最短距离,然后选择最短的值并再次重复相同的步骤。

    所以它会像。

    你有 4 个点,你从点 1 开始(起点在圆 1 的中心),

    使用shortest distance formula from cirumfrence计算最短距离

    对于剩下的 3 个圆(距离将计算从点 1 到所有 3 个圆的圆周),然后从三个中选择最小距离。

    现在移动到第二点(距离最短的那个),对剩下的其他两个点重复同样的操作。

    
    circle1(x0,y0)
    circle2(xx0,yy0)
    circle3(xxx0,yyy0)
    circle4(xxxx0,yyyy0)
    
    cirle 1 (x0,y0) is the center and you have **p1** on circumfrence p1(x1,y1) 
    
    from p1 calculate the shortest distance to all three circles like 
    distance from p1 to circle2 
    Distp1Toc2= sqrt(square(x1-xx0) + square(y1-yy0) -r) // this will give you shortest distance from point 1 to a point on circle2 cirumfrence 
    
    repeat this for circle3 and cirlce4 to calculate **Dist_p1_To_c3** and **Dist_p1_To_c4**  then select the minimum distance
    
    lets consider **Dist_p1_To_c2** is minimum and now from the point Dist_p1_To_c2 again calculate the distance to circle 3 and circle4 to find minimum distance.
    

    【讨论】:

    • 很抱歉,我无法理解您在说什么。但我觉得你一直在寻找最近的点,但这是不正确的。这些点有预先确定的顺序,我只是不想直接通过它们,而是“偷工减料”,我只需要在该点的给定距离内到达,而不是直接通过它
    • 不,它不是查看最近的点,而是查看用这些点绘制的圆的圆周上的最近点。请注意,无论 P 在圆内还是圆外,该公式都有效。
    猜你喜欢
    • 1970-01-01
    • 2019-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多