Which algorithm can I use to find the next to shortest path in a graph?

前端 未结 8 688
独厮守ぢ
独厮守ぢ 2020-12-05 10:50

I want to find the next shortest path between 2 vertices in a graph and the path has a positive cost.The next shortest path is allowed to share edges of the shortest path .W

8条回答
  •  一整个雨季
    2020-12-05 11:42

    When you prefer a practical solution to an academic one, here is one.

    I solved this by setting a penalty to the shortest path edges and running the search again.

    E.g. shortest path has length 1000, penalty is 10%, so I search for a 2nd shortest path with 1000<=length<=1100.

    In the worst case I find the previous shortest path.
    In the best case I find a disjunct path with the same length.
    In most cases I find a path sharing some locally optimal subpaths.

    Increasing the penalty forces the algorithm to find alternative routes, while decreasing makes it sharing tolerant.

    When I find the 2nd shortest path, I have to subtract the sum of penalties on shared edges from the computed length to get the real length.

    For k-th shortest path I set the penalty to all edges used in previous k-1 shortest paths.

提交回复
热议问题