GraphTheory
Distance
distance between two vertices
Calling Sequence
Parameters
Options
Description
Examples
Compatibility
Distance(G, s, t)
G
-
graph
s, t
vertices of the graph
ignoreweights=truefalse
Specifies whether to ignore edge weights if present.
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) if the graph is unweighted and otherwise to use the same strategy as ShortestParth .
To find a path from s to t with minimum distance use the ShortestPath command.
with⁡GraphTheory:
with⁡SpecialGraphs:
P≔PetersenGraph⁡
P≔Graph 1: an undirected graph with 10 vertices and 15 edges
Distance⁡P,1,4
2
ShortestPath⁡P,1,4
1,5,4
DMP≔Graph⁡map⁡x↦sort⁡convert⁡x,list,Edges⁡P
DMP≔Graph 2: a directed graph with 10 vertices and 15 arcs
Distance⁡DMP,1,4
3
ShortestPath⁡DMP,1,4
1,2,3,4
W6≔Graph⁡1,2,10,1,6,10,2,3,−10,3,4,10,4,5,−10,5,6,9
W6≔Graph 3: a directed weighted graph with 6 vertices and 6 arcs
Distance⁡W6,1,6
9
Distance⁡W6,1,6,ignoreweights
1
The GraphTheory[Distance] command was updated in Maple 2024.
The ignoreweights option was introduced in Maple 2024.
For more information on Maple 2024 changes, see Updates in Maple 2024 .
See Also
AllPairsDistance
BellmanFordAlgorithm
Diameter
DijkstrasAlgorithm
ShortestPath
Download Help Document
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル