Dijkstra's algorithm with 'must-pass' nodes

老子叫甜甜 提交于 2019-11-29 05:15:49

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.

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!