Shortest Path with Single Source Node and Multiple Target Nodes
Hi,
There is node from A to H and used shortestpath fn to find the short path
a=["A" "A" "A" "B" "B" "C" "C" "D" "D" "E" "F" "F" "G"];
b=["B" "C" "D" "D" "F" "D" "E" "E" "G" "G" "G" "H" "H"];
distance=[3 2 5 2 13 2 5 4 3 6 2 3 6];
c=digraph(a,b,distance)
plot(c,’EdgeLabel’,c.Edges.Weight)
[p,d]=shortestpath(c,"A","H")
got this
c =
digraph with properties:
Edges: [13×2 table]
Nodes: [8×1 table]
p = 1×5 string
"A" "C" "D" "G" "H" *
d = 13
But i need to have results from A to B , A to C ,…. till A to H. I have used shortestpathtree but gives only edges and nodes with distance. I need result like above one ‘p’ with multiple target nodes (with single source node). is that for loop helpful? else any other way.
Thanks in advance.Hi,
There is node from A to H and used shortestpath fn to find the short path
a=["A" "A" "A" "B" "B" "C" "C" "D" "D" "E" "F" "F" "G"];
b=["B" "C" "D" "D" "F" "D" "E" "E" "G" "G" "G" "H" "H"];
distance=[3 2 5 2 13 2 5 4 3 6 2 3 6];
c=digraph(a,b,distance)
plot(c,’EdgeLabel’,c.Edges.Weight)
[p,d]=shortestpath(c,"A","H")
got this
c =
digraph with properties:
Edges: [13×2 table]
Nodes: [8×1 table]
p = 1×5 string
"A" "C" "D" "G" "H" *
d = 13
But i need to have results from A to B , A to C ,…. till A to H. I have used shortestpathtree but gives only edges and nodes with distance. I need result like above one ‘p’ with multiple target nodes (with single source node). is that for loop helpful? else any other way.
Thanks in advance. Hi,
There is node from A to H and used shortestpath fn to find the short path
a=["A" "A" "A" "B" "B" "C" "C" "D" "D" "E" "F" "F" "G"];
b=["B" "C" "D" "D" "F" "D" "E" "E" "G" "G" "G" "H" "H"];
distance=[3 2 5 2 13 2 5 4 3 6 2 3 6];
c=digraph(a,b,distance)
plot(c,’EdgeLabel’,c.Edges.Weight)
[p,d]=shortestpath(c,"A","H")
got this
c =
digraph with properties:
Edges: [13×2 table]
Nodes: [8×1 table]
p = 1×5 string
"A" "C" "D" "G" "H" *
d = 13
But i need to have results from A to B , A to C ,…. till A to H. I have used shortestpathtree but gives only edges and nodes with distance. I need result like above one ‘p’ with multiple target nodes (with single source node). is that for loop helpful? else any other way.
Thanks in advance. shortestpath, graph, nodes, plot MATLAB Answers — New Questions