shortest path between two nodes in unweighted graph
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
Respuestas (1)
Walter Roberson
el 12 de Oct. de 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 comentarios
Walter Roberson
el 12 de Oct. de 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.
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!