Shortest Possible Path from All Nodes in a Graph
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
A M
am 26 Jan. 2017
Beantwortet: Walter Roberson
am 27 Jan. 2017
[dist,path,pred] = graphshortestpath(DG,1,6) would return shortest path from Node 1 to Node 6 in a graph. Is there any way to find shortest paths from all other nodes (i.e. 2,3,4 and 5) to the destination (i.e. 6) simultaneously with one MATLAB command?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 27 Jan. 2017
No, there is no built-in command for that. You could look in the File Exchange.
If you have a vector of source node numbers, s, and a vector of destination (target) node numbers, t, and for any given index K, the distance from node number s(K) to destination t(K) is given by cost c(K), and you only fill in the list in one direction (assume that the backwards links will automatically be filled in by the software), then
maxnode = max([s(:), t(:)]);
sendpaths = cell(maxnode, 1);
G = graph(s, t, c);
for K = 1 : maxnode
sendpaths{K} = shortestpath(G, K, sinknode);
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!