What is the difference between shortest_simple_paths and all_shortest_paths? #6381
-
I searched the method to find k the shortest paths in the networkx graph, and found functions named 'shortest_simple_paths' and 'all_shortest_paths'. It seems that Both of them are used to find all the shortest paths between specified source and target nodes. What is the difference of those methods? How I decide which to use. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The function The function Perhaps the docs should include a comparison of these functions... Anyone know if a paragraph be included in a Sphinx "See Also" section? |
Beta Was this translation helpful? Give feedback.
-
A text description can be added to entries in the |
Beta Was this translation helpful? Give feedback.
The function
shortest_simple_paths
yields all the simple paths in order of length. So most of the resulting paths are not "shortest paths". To explain the name, think of "I want the 6 shortest simple paths".The function
all_shortest_paths
yields all of the possible shortest paths. All of these paths will have the same length. The use for this function is when there are multiple ways to go that are the same distance. Instead of just giving one example of a shortest path, this function provides them all.Perhaps the docs should include a comparison of these functions... Anyone know if a paragraph be included in a Sphinx "See Also" section?