简体   繁体   中英

Shortest path in weighted directed graph

i need to find the shortest path between two node s,t in a weighted directed graph. Here are the limitations:

  1. The weights can be negative.
  2. The path has to go through a specific edge lets call her e and shes from node u to v.
  3. The output path must be simple, ie we only pass through a node once.

Now i have an idea for a solution but i don't know if the output will be a simple path or not.

My solution is to run bellman ford algorithm twice, once from s, second from v. the shortest path will be s to u, u to v, v to t.

Because i want it to be simple i will not use nodes i already used in the second bellman ford run.

Because i want it to be shortest i will check if running bellman ford from v to t before running from s to u is quicker than the other way around ( if there is a node both use where is the best place to put it).

Thanks for the helpers!

Even finding such a path is NP-complete. This is because two vertex/edge disjoint paths problem is NPC in directed graphs. Suppose edge e=(u,v) then you are looking for an (s,u), (v,t) disjoint paths but this is NP-complete in digraphs.

Here you can find the hardness result: https://www.sciencedirect.com/science/article/pii/0304397580900092

Your current algorithm based on Bellman-ford does not give the right answer for all cases (it may fail to find a path while there is a path), however, it might be a good heuristics. If your graph was undirected then the task was much easier.

If you allow repeating vertices then any shortest path algorithm is a right way to do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM