fastest path between more than two nodes

조회 수: 2 (최근 30일)
Salah Gohar
Salah Gohar 2021년 11월 18일
댓글: Christine Tobler 2021년 11월 18일
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
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?
Salah Gohar
Salah Gohar 2021년 11월 18일
i have also the connectivity information and i already wrote the code for the Graph.
i tried this code to define the 20 OD node:
v=1
for i=1:217
if ODnode(i) ~= 0
OD(v) = ODnode(i);
i_no(v)=i;
v= v+1;
end
end
OD
i_no
i need now to get the shortest path between all the 20 ODnodes!

댓글을 달려면 로그인하십시오.

답변 (1개)

Christine Tobler
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
Salah Gohar
Salah Gohar 2021년 11월 18일
Error using graph/shortestpath (line 57)
Source must specify one node.
i have now a 20 by 20 MAtrix ,how can i get the shortestpath between them all?
Christine Tobler
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 CenterFile Exchange에서 Construction에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by