GRAPH UTILITIES 程序包 符号

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

## 更多信息更多信息

• 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

## 范例范例打开所有单元关闭所有单元

### 基本范例 (1)基本范例 (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]=

## 教程教程

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