GraphDistanceMatrix

GraphDistanceMatrix[g]

gives the matrix of distances between vertices for the graph g.

GraphDistanceMatrix[g,d]

gives the matrix of distances between vertices of maximal distance d in the graph g.

GraphDistanceMatrix[{vw,},]

uses rules vw to specify the graph g.

Details and Options

  • GraphDistanceMatrix returns a SparseArray object or an ordinary matrix.
  • The entries of the distance matrix dij give the shortest distance from vertex vi to vertex vj.
  • The diagonal entries dii of the distance matrix are always zero.
  • The entry dij is Infinity () if there is no path from vertex vi to vertex vj.
  • In GraphDistanceMatrix[g,d], an entry dij will be Infinity if there is no path from vertex vi to vertex vj in d steps or less.
  • The vertices vi are assumed to be in the order given by VertexList[g].
  • For a weighted graph, the distance is the minimum of the sum of weights along any path from vertex vi to vertex vj.
  • The following options can be given:
  • EdgeWeightAutomaticweight for each edge
    MethodAutomaticmethod to use
  • Possible Method settings include "Dijkstra", "FloydWarshall", and "Johnson".

Examples

open allclose all

Basic Examples  (1)

Give the distance matrix for a Petersen graph:

In[1]:=
Click for copyable input
Out[1]//MatrixForm=

Scope  (8)

Options  (6)

Applications  (2)

Properties & Relations  (5)

Possible Issues  (2)

Neat Examples  (1)

See Also

GraphDistance  AdjacencyMatrix  GraphPower  GraphRadius  GraphDiameter  GraphCenter  GraphPeriphery

Introduced in 2010
(8.0)
| Updated in 2015
(10.3)