简体   繁体   English

在有向无环加权图中找到前3条最长路径

[英]Finding top 3 longest path in directed acyclic weighted graph

I am able to use this algorithm to find the longest path in a weighted DAG (using topological sort and then relaxing each edge). 我能够使用此算法在加权DAG中找到最长的路径(使用拓扑排序,然后放宽每个边)。 My question now is if there is an algorithm to find the top 3 longest paths of the DAG? 我现在的问题是,是否有一种算法可以找到DAG的前3条最长路径? Or, is there any javascript or java library that implements this algorithm? 或者,是否有实现此算法的JavaScript或Java库?

You can easily compute first longest path, and you can use following algorithm for finding the next longest path: 您可以轻松计算出第一条最长路径,并且可以使用以下算法查找下一条最长路径:

Delete each edge of the main longest path one by one and the run the algorithm again to find the longest path on the modified graph then put back the deleted edge and delete one other edge. 一条一条地删除主要最长路径的每个边,然后再次运行算法以在修改后的图上找到最长路径,然后放回已删除的边并删除另一个边。

Why this works? 为什么这样有效?
You need a path the is not exactly the first longest path, so the second longest path must be different in at least one edge, so if you ignore one edge and find the longest path for each of the edges you eventually find a longest path that don't share at least one edge with the main longest path. 您需要的路径并不完全是第一条最长的路径,因此第二条最长的路径在至少一个边缘上必须不同,因此,如果忽略一条边缘,并为每个边缘找到最长的路径,则最终会找到一条最长的路径,不要与最长的主路径共享至少一条边。
The third longest path is a path that is a longest path and doesn't share at least one edge with the first and the second longest path. 第三最长路径是一条最长路径,并且与第一和第二最长路径不共享至少一条边。

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

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