shortest path between two nodes in unweighted graph
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Using shortestpath command in matlab2015 version unable to find two or more shortest path of same length in between two nodes(for unweighted graph or graph with same weight). It gives only one of these paths. Can anyone suggest a way to find all such shortest path of same length? Thanks in advance
1 Kommentar
Antworten (1)
Walter Roberson
am 12 Okt. 2017
Extract the neighbors of the destination node as a list.
Now run shortestpathtree() between the source and all of those neighbours, giving the 'OutputForm', 'cell' option. Also request the second output, d.
Select only the entries from the cells whose d value is equal to the minimum of the d values.
If you want, explicitly add the destination node to each of the resulting paths.
3 Kommentare
Walter Roberson
am 12 Okt. 2017
In that case, extract the neighbors of the destination node. Loop over them calling shortestpath() between the source and each of those destinations and recording the distances as you go -- or, rather, the distance plus the cost of the edge between that destination and the actual final node. Discard all the entries where the distance is not equal to the minimum distance.
... actually I just realized this strategy would fail if the branch was in the middle and that it merged back again with the cost of the branches being equal. I will need to think about that more.
Possibly you could get somewhere with bfsearch() the breadth-first search. However that was introduced in R2015b, and I am not clear as to whether you have R2015a or R2015b.
Siehe auch
Kategorien
Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!