Distance - Maple Help

GraphTheory

 Distance
 distance between two vertices

 Calling Sequence Distance(G, s, t)

Parameters

 G - graph s, t - vertices of the graph

Options

 • weighted=truefalse
 Specifies whether edge weights should be included in the calculation of weighted distance. The default is false.

Description

 • Distance returns the number of edges in the shortest path from s to t. If no such path exists, the output is infinity.  The strategy is to use a breadth-first search (BFS).
 • To find a path from s to t with minimum distance use the ShortestPath command.

Examples

 > $\mathrm{with}\left(\mathrm{GraphTheory}\right):$
 > $\mathrm{with}\left(\mathrm{SpecialGraphs}\right):$
 > $P≔\mathrm{PetersenGraph}\left(\right)$
 ${P}{≔}{\mathrm{Graph 1: an undirected unweighted graph with 10 vertices and 15 edge\left(s\right)}}$ (1)
 > $\mathrm{Distance}\left(P,1,4\right)$
 ${2}$ (2)
 > $\mathrm{ShortestPath}\left(P,1,4\right)$
 $\left[{1}{,}{5}{,}{4}\right]$ (3)
 > $\mathrm{DMP}≔\mathrm{Graph}\left(\mathrm{map}\left(x↦\mathrm{sort}\left(\mathrm{convert}\left(x,\mathrm{list}\right)\right),\mathrm{Edges}\left(P\right)\right)\right)$
 ${\mathrm{DMP}}{≔}{\mathrm{Graph 2: a directed unweighted graph with 10 vertices and 15 arc\left(s\right)}}$ (4)
 > $\mathrm{Distance}\left(\mathrm{DMP},1,4\right)$
 ${3}$ (5)
 > $\mathrm{ShortestPath}\left(\mathrm{DMP},1,4\right)$
 $\left[{1}{,}{2}{,}{3}{,}{4}\right]$ (6)

Compatibility

 • The GraphTheory[Distance] command was updated in Maple 2021.
 • The weighted option was introduced in Maple 2021.
 • For more information on Maple 2021 changes, see Updates in Maple 2021.