3

I have an ordered list of points in a 2D plane. I'd like to find the shortest route such that it gets at least within distance X (or closer) from each point, in the given order. How do I find this route?

I realize that the points that will determine the route (the direction changes there) will lie on circles of perimeter X, centered on the input points themselves, but I didn't get any further.

I'm implementing this in Python, but will be happy for any theoretical help.

Example: (oops I can't count so skipped 7) Example

M. Volf
  • 1,259
  • 11
  • 29
  • This is a generalisation of the Travelling Salesman Problem, so I'd start there. https://en.wikipedia.org/wiki/Travelling_salesman_problem – kaya3 Dec 31 '20 at 15:30
  • @kaya3 This is not the TSP - the points have a given order – M. Volf Dec 31 '20 at 15:31
  • Can you please add more details to the question , it seems to be a specific case of BFS . – User Dec 31 '20 at 15:35
  • @Mouse I edited the question to add an approximate, hand-made example. I don't understand how BFS would be related – M. Volf Dec 31 '20 at 15:43
  • Is a approximation allowed? It feels the points depend on each other, but the dependency effect fades away quickly after 2-3 hops... – Willem Hendriks Jan 01 '21 at 09:26
  • @user3184950 for my purposes it's ok. I've been thinking about it and always ended up on mutual dependencies too – M. Volf Jan 01 '21 at 10:04

2 Answers2

5

Perhaps there's an analytical approach, but this problem certainly can be solved with convex programming. Here's a Python implementation with cvxpy that outputs EPS.

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()

enter image description here

David Eisenstat
  • 64,237
  • 7
  • 60
  • 120
0

It seems you have to find minimum distance to the point which is x minimux x points away from the next point in the route.

I would suggesting finding the shortest distance between the starting point and all the circles cirumfrence , then choosing the shortest value and again repeating the same step.

So it will be like .

you have 4 points and you start at point 1(starting point which is at the cicumfrence of the circle 1),

calculate the shortest distance using shortest distance formula from cirumfrence

for the rest of the 3 circles (The distance will be calculated from point 1 to the circumfrence of all 3 circles ) and after that select the minimum distance from three.

Now move to point two (the one has the shortest distance) and repeat same for other two points left.


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.
User
  • 572
  • 2
  • 10
  • I'm sorry, but I'm having trouble understanding what you're saying. But I feel like you're always looking for the closest point, but that's incorrect. The points have pre-determined order, I just don't want to pass directly through them, but "cut the corners" making use of that I only need to get within given distance of that point, not go directly through it – M. Volf Dec 31 '20 at 17:11
  • nope , it's not looking at the closest point but the closest point on the cirumfrence of a circle drawn with the points. Note that the formula works whether P is inside or outside the circle. – User Dec 31 '20 at 17:18