简体   繁体   English

加权有向图中的最短路径

[英]Shortest path in weighted directed graph

i need to find the shortest path between two node s,t in a weighted directed graph.我需要在加权有向图中找到两个节点 s,t 之间的最短路径。 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.路径必须通过特定的边,让她从节点 u 到 v 称她为 e 和 shes。
  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.我的解决方案是运行 bellman Ford 算法两次,一次从 s,第二次从 v。最短路径将是 s 到 u,u 到 v,v 到 t。

Because i want it to be simple i will not use nodes i already used in the second bellman ford run.因为我希望它很简单,所以我不会使用我在第二次 bellman Ford 运行中已经使用过的节点。

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).因为我希望它最短,所以我会检查在从 s 到 u 运行之前从 v 到 t 运行 bellman Ford 是否比其他方式更快(如果有一个节点,则两者都使用放置它的最佳位置)。

Thanks for the helpers!感谢帮助者!

Even finding such a path is NP-complete.即使找到这样的路径也是 NP 完全的。 This is because two vertex/edge disjoint paths problem is NPC in directed graphs.这是因为两个顶点/边不相交的路径问题是有向图中的 NPC。 Suppose edge e=(u,v) then you are looking for an (s,u), (v,t) disjoint paths but this is NP-complete in digraphs.假设边 e=(u,v) 那么你正在寻找一个 (s,u), (v,t) 不相交的路径,但这在有向图中是 NP 完全的。

Here you can find the hardness result: https://www.sciencedirect.com/science/article/pii/0304397580900092在这里你可以找到硬度结果: 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.您当前基于 Bellman-ford 的算法并未针对所有情况给出正确答案(在有路径时可能无法找到路径),但是,它可能是一个很好的启发式方法。 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.如果您允许重复顶点,那么任何最短路径算法都是正确的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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