简体   繁体   English

为什么 Bellman-Ford 不能用于单源最长路径?

[英]Why can't Bellman-Ford be used for Single Source Longest Path?

Dijkstra's cannot be used for longest path because it uses the property that the current shortest path will be for sure shorter than one of the other paths. Dijkstra 不能用于最长路径,因为它使用当前最短路径肯定比其他路径之一短的属性。 This is correct, of course, assuming there are no negative edge weights.当然,假设没有负边权重,这是正确的。 This concept is also why longest path doesn't work on Dijkstra, because the current longest path doesn't guarantee that there won't be another longer path that takes a larger value later on.这个概念也是最长路径在 Dijkstra 上不起作用的原因,因为当前最长路径并不能保证以后不会有另一个更长的路径需要更大的值。

On the other hand, Bellman Ford offers the the flexibility of negative weights at a worse performance.另一方面,Bellman Ford 以较差的性能提供负权重的灵活性。 This means that for Bellman Ford, so it doesn't work on the same greedy property as Dijkstra.这意味着对于 Bellman Ford 而言,它不适用于与 Dijkstra 相同的贪婪属性。 So that's why I'm confused - why can't Bellman Ford be used on the Single Source Longest Path problem(NP hard)?所以这就是为什么我很困惑 - 为什么贝尔曼福特不能用于单源最长路径问题(NP 难)? For example, we can simply multiply all the weights of a graph by -1 and find the shortest path, which would be the longest path of the original graph.例如,我们可以简单地将图的所有权重乘以 -1 并找到最短路径,这将是原始图的最长路径。

Bellman-Ford 允许重复使用弧(否则即使存在负循环也会有明确定义的最短路径),而单源最长路径问题从它不这样做的事实中推导出其 NP 难度(否则你可以只需在将所有权重乘以 -1 后使用 Bellman-Ford)。

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

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