fastest path between more than two nodes
1 回表示 (過去 30 日間)
古いコメントを表示
I have a table of 217 node and i want to compute the fastestpath between only 20 node which called OD.
i have also a column which define these OD nodes from 1 to 20 and the other nodes are 0.
how can i write this code ; ”0” = no ShortestPath Calc; otherwise OD node?
2 件のコメント
Christine Tobler
2021 年 11 月 18 日
It looks like you have a set of nodes with X and Y coordinates, but not connectivity information between them (edges connecting pairs of nodes with each other).
What is the shortest path you're trying to compute? Is it the distance between two nodes when connected by a straight line, or some other thing?
回答 (1 件)
Christine Tobler
2021 年 11 月 18 日
To compute simply the shortest-path distance, you can use the distances function and pass in a graph object you've constructed using the connectivity information, and the OD vector you constructed above.
If you need the paths, you will need a for-loop:
for i=1:length(OD)
for j = 1:length(OD)
paths{i, j} = shortestpath(G, OD(i), OD(j));
end
end
2 件のコメント
Christine Tobler
2021 年 11 月 18 日
You need to use a for-loop and call shortestpath with just one node at a time, like in the code I added above.
参考
カテゴリ
Help Center および File Exchange で Construction についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!