Dijkstra's algorithm with 'must-pass' nodes

后端 未结 3 2018
醉话见心
醉话见心 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: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

提交回复
热议问题