필터 지우기
필터 지우기

error in finding shortest path

조회 수: 2 (최근 30일)
FIR
FIR 2014년 1월 28일
답변: Walter Roberson 2015년 7월 17일
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

답변 (1개)

Walter Roberson
Walter Roberson 2015년 7월 17일
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.

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by