Distance - Maple Help

Online Help

All Products    Maple    MapleSim


GraphTheory

  

Distance

  

distance between two vertices

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

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

withGraphTheory:

withSpecialGraphs:

PPetersenGraph

PGraph 1: an undirected unweighted graph with 10 vertices and 15 edge(s)

(1)

DistanceP,1,4

2

(2)

ShortestPathP,1,4

1,5,4

(3)

DMPGraphmapxsortconvertx,list,EdgesP

DMPGraph 2: a directed unweighted graph with 10 vertices and 15 arc(s)

(4)

DistanceDMP,1,4

3

(5)

ShortestPathDMP,1,4

1,2,3,4

(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.

See Also

AllPairsDistance

BellmanFordAlgorithm

Diameter

DijkstrasAlgorithm

ShortestPath