Close
Close window
Distance - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.
Maplesoft logo
Maplesoft logo

Online Help

All Products Maple MapleSim


[フレーム] [フレーム]

GraphTheory

Distance

distance between two vertices

Calling Sequence

Distance(G, s, t)

Parameters

G

-

graph

s, t

-

vertices of the graph

Options

ignoreweights=truefalse

Specifies whether to ignore edge weights if present.

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

Examples

>

withGraphTheory:

>

withSpecialGraphs:

>

PPetersenGraph

PGraph 1: an undirected graph with 10 vertices and 15 edges

(1)
>

DistanceP,1,4

2

(2)
>

ShortestPathP,1,4

1,5,4

(3)
>

DMPGraphmapxsortconvertx,list,EdgesP

DMPGraph 2: a directed graph with 10 vertices and 15 arcs

(4)
>

DistanceDMP,1,4

3

(5)
>

ShortestPathDMP,1,4

1,2,3,4

(6)
>

W6Graph1,2,10,1,6,10,2,3,10,3,4,10,4,5,10,5,6,9

W6Graph 3: a directed weighted graph with 6 vertices and 6 arcs

(7)
>

DistanceW6,1,6

9

(8)
>

DistanceW6,1,6,ignoreweights

1

(9)

Compatibility

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 .


Download Help Document

AltStyle によって変換されたページ (->オリジナル) /