How to find all possible paths between two nodes in a 246 nodes system.
4 ビュー (過去 30 日間)
古いコメントを表示
ld=[1 2 2; 1 3 2; 1 4 3; 2 3 3; 3 4 2; 4 5 4; 4 6 4; 5 6 3];
first two column represent edge (node connectivity) of graph and third column represent distance between that line. For example: I want to know all paths from 3 to 4.
My answer will be :
[3 4]
[3 1 4]
[3 2 1 4]
Please help me to solve this. I already use Dijkstra algorithm but Dijkstra algorithm is in xy plane or xyz plane, which is not like my problem.
1 件のコメント
John BG
2016 年 5 月 31 日
the column on the right is distance, so for the matrix example you can check whether there is a path defined between 3 and 4 with:
intersect(find(A(:,1)==3),find(A(:,1)==4))
Empty matrix: 0-by-1
If you allow the matrix to have multiple hops between start and stop nodes, then you may want to use a cell instead of a array of integers, because while a line may have just 2 nodes, the start and stop, next line may have for instance 20 hops between start and stop.
回答 (1 件)
Walter Roberson
2016 年 5 月 31 日
2 件のコメント
Walter Roberson
2016 年 5 月 31 日
Incorrect. That code has no built-in limits other than those imposed by MATLAB and the amount of memory you have available.
参考
カテゴリ
Help Center および File Exchange で Dijkstra algorithm についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!