FindShortestPath
FindShortestPath[g,s,t]
finds the shortest path from source vertex s to target vertex t in the graph g.
FindShortestPath[g,s,All]
generates a ShortestPathFunction[…] that can be applied repeatedly to different t.
FindShortestPath[g,All,t]
generates a ShortestPathFunction[…] that can be applied repeatedly to different s.
generates a ShortestPathFunction[…] that can be applied to different s and t.
FindShortestPath[{vw,…},…]
uses rules vw to specify the graph g.
Details and Options
- FindShortestPath[g,s,t] gives a path from s to t.
- FindShortestPath[g,s] is equivalent to FindShortestPath[g,s,All].
- FindShortestPath[g] is equivalent to FindShortestPath[g,All,All].
- For an unweighted graph, edge length is assumed to be 1.
- For a weighted graph, edge length is taken to be the weight.
- A Method option can also be given. Possible Method settings include:
-
"BellmanFord" supports positive and negative weights "Dijkstra" supports positive weights - FindShortestPath works with undirected graphs, directed graphs, weighted graphs, multigraphs, and mixed graphs.
Examples
open allclose allBasic Examples (1)
Scope (9)
Specification (7)
FindShortestPath works with undirected graphs:
The shortest path has the smallest total edge weight:
Collection (2)
Find the shortest paths from one vertex to all vertices:
Apply the ShortestPathFunction to every vertex of the graph:
Find the shortest paths to one vertex from all vertices:
Apply the ShortestPathFunction to every vertex of the graph:
Options (3)
Applications (3)
Text
Wolfram Research (2010), FindShortestPath, Wolfram Language function, https://reference.wolfram.com/language/ref/FindShortestPath.html (updated 2015).
CMS
Wolfram Language. 2010. "FindShortestPath." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/FindShortestPath.html.
APA
Wolfram Language. (2010). FindShortestPath. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FindShortestPath.html