ShortestPath - Maple Help

# Online Help

###### All Products    Maple    MapleSim

GraphTheory

 ShortestPath
 find a shortest path between two vertices

 Calling Sequence ShortestPath(G, u, v)

Parameters

 G - graph u, v - vertices of the graph

Description

 • ShortestPath returns a shortest path from u to v in G using a breadth-first search. The output is a list of vertices in the order they appear on the path. If no such a path exists, an error message is displayed.
 • Edge weights are ignored.
 • To compute shortest paths with respect to edge weights, use either DijkstrasAlgorithm or BellmanFordAlgorithm.

Examples

 > $\mathrm{with}\left(\mathrm{GraphTheory}\right):$
 > $\mathrm{C6}≔\mathrm{CycleGraph}\left(6\right)$
 ${\mathrm{C6}}{≔}{\mathrm{Graph 1: an undirected unweighted graph with 6 vertices and 6 edge\left(s\right)}}$ (1)
 > $\mathrm{IsReachable}\left(\mathrm{C6},1,5\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{ShortestPath}\left(\mathrm{C6},1,5\right)$
 $\left[{1}{,}{6}{,}{5}\right]$ (3)

 See Also