Dijkstra's algorithm with 'must-pass' nodes

后端 未结 3 2006
醉话见心
醉话见心 2020-12-17 05:56

I am trying to implement Dijkstra\'s algorithm which can find the shortest path between the start node and the end node. Before reach the end node there are some \'must-pass

相关标签:
3条回答
  • 2020-12-17 06:23

    By finding shortest path between must include node and two(end and start) node. Form graph, then run shortest path algo(Dijkstra's algorithm). Start and end nodes will be same.

    0 讨论(0)
  • 2020-12-17 06:25

    This is a generalisation of the travelling salesman problem. The TSP comes up as the case where all vertices are "must-pass".

    Find shortest paths between each pair of must-pass vertices, from the source to each must-pass vertex, and from each must-pass vertex to the sink. Then use the famous O(n 2^n) dynamic programming algorithm for TSP to find the shortest path from source to sink meeting your constraints; here n will be two plus the number of must-pass vertices.

    0 讨论(0)
  • 2020-12-17 06:41

    Unfortunately this problem is reduced to TSP so dont expect a polynomial solution but if no of intermediate node are small then you can do this reasonably fast like following :-

    1. try every sequence of nodes to visit possible.
    2. say you have s->a->b->c->d
    3. then evaluate min(s,d) + min(d,a) + min(c,d) using dijkstra
    4. the sequence that has minimum distance is your answer.

    Time complexity : O(k!*ElogV) where k is no of must pass nodes

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