0

I want to calculate the shortest path from source S to sink T.
But the path must pass from node1 and then node2 at least once.

Eg: S->...->node1->....->node2->....->T

And i have to run shortest path algorithm only once (meanly,i am not allowed to calculate the path from s to node1, then node1 to node2 and finally node2 to T in three different shortest path calls)

The first thing that came my mind was TSP since in TSP every nodes are 'must' pass. But complexity of TSP is too high.

Can i modify the TSP in such a manner that i can reduce its complexity to polynomial, or do you have another approaches to the question

nagleria
  • 29
  • 5
  • What do you mean by saying you're not allowed to find shortest paths between S and node1? What's the full problem statement? – Mikhail Berlinkov Dec 29 '18 at 13:08
  • Actually, graph is dynamic, you start the algorithm in t=1, and every step is one timestep. When t==2T some nodes cant be reached (edges weight infinity), when t==2T+1 some other nodes cant be reached. – nagleria Dec 29 '18 at 15:07
  • Do you know what edges are available at each timestamp? – Mikhail Berlinkov Dec 30 '18 at 14:42
  • Yes it is given in input – nagleria Dec 30 '18 at 18:36
  • There're at least two ways to solve this problem then. The first one is just to build a corresponding static graph - imagine it as a multilayer graph where every layer represents a timestamp of a graph but existing edges goes one layer up. Then, you can just run normal algorithms in that graph. – Mikhail Berlinkov Dec 30 '18 at 20:58
  • Another option is to use a modified Breadth First Search until you find a path going through node1, node2 and T. The first difference with the normal BFS is that you don't mark nodes as visited and don't check it when building a new wave of nodes. The second difference is that along with each node in a wave you keep whether you already visited node1 and node2 (in this order) before reaching this node. When you encounter T you just use backtracking to find a path. – Mikhail Berlinkov Dec 30 '18 at 21:02
  • For your first solution, can you consider following: Assume every vertices are rooms and every edges are corridor, you are a warrior and corridor weihgts are ammo counts you need for pass to corridor. You have an ammo count initially , and you want to find shortest path that finishes you with max ammo – nagleria Dec 30 '18 at 21:46
  • But there are two rooms that contains ammo you can take. In this case , the following problem arises, we cant know whether our warrior should take the ammos before or after node1 or node2. Hence, i guess we cant implement the first solution for my case – nagleria Dec 30 '18 at 21:50
  • I mean, we cant run a shortest path from source to node1, and then node1 to node 2, and finally node2 to target seperately – nagleria Dec 30 '18 at 21:54

0 Answers0