Find the longest path in a graph?
15 ビュー (過去 30 日間)
古いコメントを表示
Adjacency matrix of graph is given to us. Now we need to find out the longest path between two nodes. Input: Adjacency matrix of the graph, source node and destination node. Output: Longest path between source node and destination node.
2 件のコメント
回答 (2 件)
Massimo Zanetti
2016 年 10 月 9 日
Generally this is NP-hard problem. However, for DAGs (directed acyclic graphs) there is one clever way to solve the problem. It is called "topological sorting". See details here or elsewhere in google: https://en.wikipedia.org/wiki/Topological_sorting
0 件のコメント
Ivan
2017 年 12 月 14 日
Try to invert signs of weight coefficient and calculate shortest path with built-in shortestpath function. It will be the longest path for initial weights.
1 件のコメント
MICHAEL MONT-ETON
2020 年 11 月 29 日
Ivan, Thanks for the tip. It is useful for finding collection of independent paths.
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!