error in finding shortest path
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have created a graph with values
y =
(1,3) 0.8615
(2,3) 0.8479
(1,5) 0.1064
(2,5) 0.9705
(3,5) 0.6588
(4,5) 0.8535
(1,6) 0.3939
(3,6) 0.7948
(1,7) 0.5726
(4,7) 0.6146
(6,7) 0.8340
(2,8) 0.6760
(4,8) 0.5518
(5,8) 0.7033
(4,9) 0.2783
(7,9) 0.3425
(8,9) 0.7412
bg=(biograph(y,[],'ShowArrows', 'off','ShowWeights','on'));
view(bg)
now i have found shortest path between two nodes,it works for some nodes and gives the path and distance,but for some nodes the path is empty ,for example
[dist,path,pred] = graphshortestpath(y,3,4)
the path is empty, kindly tell why i get empty path
0 comentarios
Respuestas (1)
Walter Roberson
el 17 de Jul. de 2015
Links are unidirectional.
You have a link from 3 to 5 and from 3 to 6.
If you use (3,5) then the only link from 5 is (5,8) so you have to take that. Once you are at 8, the only link is (8,9) so you take that. There are no links from 9 so the path is a dead end.
So you need to instead use (3,6). Once you are at 6 the only link is (6,7) so you have to take that. Once you are at 7, the only link is (7,9) so you take that. There are no links from 9 so the path is a dead end.
Therefor with the data matrix you have, there is no route from 3 to 5.
If you want the routes to be symmetric then you need to add in the symmetric entries.
Y = y + y';
Now if you ask for the path on Y you will get a result.
0 comentarios
Ver también
Categorías
Más información sobre Graph and Network Algorithms en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!