GRAPH UTILITIES PACKAGE SYMBOL

# GraphDistanceMatrix

GraphDistanceMatrix[g]
gives a matrix in which the entry is the length of a shortest path in g between vertices i and j.

returns a three-dimensional matrix in which the entry is the length of a shortest path from i to j and the entry is the predecessor of j in a shortest path from i to j.

## Details and OptionsDetails and Options

• To use , you first need to load the Graph Utilities Package using Needs["GraphUtilities`"].
• The following options can be given:
•  Method Automatic the method used to compute the shortest path Weighted True whether edge weights are to be taken into account

## ExamplesExamplesopen allclose all

### Basic Examples (1)Basic Examples (1)

This defines a simple directed graph:

 Out[3]=

This calculates the distance between the vertices:

 Out[4]//MatrixForm=

This shows also the predecessors in the shortest path:

 Out[5]//MatrixForm=

The path from 1 to 3 is :

 Out[6]=

This confirms the shortest path:

 Out[7]=

## TutorialsTutorials

New to Mathematica? Find your learning path »
Have a question? Ask support »