How does shortestpath function work?
6 ビュー (過去 30 日間)
古いコメントを表示
Riccardo Nebuloni
2021 年 12 月 7 日
コメント済み: Christine Tobler
2021 年 12 月 7 日
Hi everyone. i need a help.
i don't completely understand the "Shortest Path in Multigraph" example in "shortestpath" function (in particular, the edgepth). i don't understand the meaning of the indeces [1 7 9 10]: i thought they were the indeces of the couples of coordinates, but -if i were right- these couples shoud be 1-2/2,4/3,5/3,5 (that are not the right ones, couse in the "highlight" part and in the plot part everithing is ok.
Thx for your help
0 件のコメント
採用された回答
Christine Tobler
2021 年 12 月 7 日
Every edge has a number, which is the order in which they appear in the Edges table (try displaying g.Edges). The edgepath contains the number of each edge on the path:
G = graph([1 1 1 1 1 2 2 3 3 3 4 4],[2 2 2 2 2 3 4 4 5 5 5 2],[2 4 6 8 10 5 3 1 5 6 8 9])
G.Edges
So the array [1 7 9 10] points to the first, 7th, 9th and 10th rows of the Edges table as the edges on the path (this is relevant for a multigraph because there can be several edges between the same two nodes).
If we index into the Edges table using edgepath, we get just a table of the edges that are on the path (see g.Edges(edgepath, :) in the example).
4 件のコメント
Christine Tobler
2021 年 12 月 7 日
I see. The Edges table is always put into a standard format, as this makes it easier to compare graphs and the algorithms are much more efficient this way.
You can maintain the information about the original order of the edges by having the weights of the graph store this original order:
a=[1 1 1 1 1 2 2 3 3 3 4 4];
b= [2 2 2 2 2 3 4 4 5 5 5 2];
G = graph(a, b, 1:length(a));
G.Edges
Here the weight of each edge is giving the order in which it appeared in the original inputs.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!