简体   繁体   English

加权无向图上的最长路径

[英]Longest path on weighted undirected graph

I know this is exponential. 我知道这是指数级的。 I already implemented a method to find the shortest path using Dijkstra's algorithm. 我已经实现了一种使用Dijkstra算法找到最短路径的方法。 Is it possible to modify the method to find the longest path instead? 是否可以修改方法来找到最长路径? If I make all the weights negative, shouldn't this work. 如果我将所有重量都设为负值,那么这不应该起作用。 All the weights on my current graph are positive. 我当前图表上的所有权重都是正数。 Also there should be no repeating paths. 也应该没有重复的路径。

I know the Bellman Ford algorithm works with negative weights, but im hoping I can just modify my existing shortest path method. 我知道Bellman Ford算法适用于负权重,但我希望我可以修改现有的最短路径方法。

If the graph is undirected, then the longest path has infinite length, because you can visit an edge forward and backward as many times as you want. 如果图形是无向的,那么最长的路径具有无限长度,因为您可以根据需要向前和向后访问边缘。 Therefore you should put some more conditions, like : a node can only be visited once, or the graph must be directed. 因此,您应该添加一些条件,例如:一个节点只能访问一次,或者图形必须是定向的。

Making all weights negative and running Dijkstra will make infinite loop. 使所有权重为负并运行Dijkstra将使无限循环。 It is in fact equivalent to what I just explained above. 它实际上等同于我刚才解释的内容。

For more information, I invite you to read about these : http://en.wikipedia.org/wiki/Topological_sorting http://en.wikipedia.org/wiki/Travelling_salesman_problem 有关更多信息,我邀请您阅读以下内容: http//en.wikipedia.org/wiki/Topological_sorting http://en.wikipedia.org/wiki/Travelling_salesman_problem

Good luck ! 祝好运 !

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

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