How does shortestpath function work?

1 visualización (últimos 30 días)
Riccardo Nebuloni
Riccardo Nebuloni el 7 de Dic. de 2021
Comentada: Christine Tobler el 7 de Dic. de 2021
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

Respuesta aceptada

Christine Tobler
Christine Tobler el 7 de Dic. de 2021
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 =
graph with properties: Edges: [12×2 table] Nodes: [5×0 table]
G.Edges
ans = 12×2 table
EndNodes Weight ________ ______ 1 2 2 1 2 4 1 2 6 1 2 8 1 2 10 2 3 5 2 4 3 2 4 9 3 4 1 3 5 5 3 5 6 4 5 8
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 comentarios
Riccardo Nebuloni
Riccardo Nebuloni el 7 de Dic. de 2021
no, i mean the first two vectors inside []:
lets call them a=[1 1 1 1 1 2 2 3 3 3 4 4] and b= [2 2 2 2 2 3 4 4 5 5 5 2].
the branch matrix will be C= [a' b']. i will obtain line indeces that link the starting and final points of a branch eg:
  1. 1-2
  2. 1-2
  3. 1-2
  4. 1-2
  5. 1-2
  6. 2-3
  7. 2-4
  8. 3-4
  9. 3-5
  10. 3-5
  11. 4-5
  12. 4-2
this order is not the same of the first two columns of the table. my question is: is there a way to keep the input order of the nodes?
Christine Tobler
Christine Tobler el 7 de Dic. de 2021
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
ans = 12×2 table
EndNodes Weight ________ ______ 1 2 1 1 2 2 1 2 3 1 2 4 1 2 5 2 3 6 2 4 7 2 4 12 3 4 8 3 5 9 3 5 10 4 5 11
Here the weight of each edge is giving the order in which it appeared in the original inputs.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Networks en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by