Algorithm Optimization - Shortest Route Between Multiple Points

后端 未结 7 1434
离开以前
离开以前 2021-02-04 11:06

Problem: I have a large collection of points. Each of these points has a list with references to other points with the distance between them already calculated and stored. I

相关标签:
7条回答
  • 2021-02-04 11:52

    Perhaps this is what the original poster means by "iterating through each possibility manually and storing the shortest path", but I thought I'd like to make explicit what appears to be a baseline solution.

    Assume you already have a two-point shortest path algorithm--this has classical solutions for various kinds of graphs. Assume all distances are nonnegative and d(A->B->C) = d(A->B) + d(B->C).

    The essentials are that the path starts at S goes through one of intermediate cities "abcd" and ends with E:

    e.g. SabcdE, SacbdE, etc...

    With only 4 intermediate cities, you enumerate all 24 permutations. For each permutation use your shortest two-point algorithm to compute the path from head to tail, and its total distance.

    Then given the start and ending point, there are 12 possibilities attaching to one of abcd and for each two possibilities for the interior. You've computed these distances already, so you add on the distance from S to the head and the tail to E. Choose minimum. So once you've precomputed the intermediate distances for a fixed set of interior cities you need to do 12 two point shortest path problems for any pair of start and end points.

    This obviously scales poorly with increasing number of intermediate cities. It's not clear to me that it could do better unless you impose greater restrictions on the graph structure (is this in a physical Euclidenan space? Triangle inequality?).

    My thought example: suppose all intermediate distances between cities are O(1). With no restriction on the graph, then the distance from S to any intermediate city might be 1000 except for one being 1. Same for the tail. So you can force the first city to be visited to be anything. Now, go one layer down, take the first city as the "start point". Apply the same argument: you can make the best path go to any of the following cities by manipulating the distances in the graph.

    So it seems that the complexity can't be helped without additional assumptions.

    0 讨论(0)
提交回复
热议问题