GraphDistance

GraphDistance[g,s,t]

gives the distance from source vertex s to target vertex t in the graph g.

GraphDistance[g,s]

gives the distance from s to all vertices of the graph g.

GraphDistance[{vw,},]

uses rules vw to specify the graph g.

Details and Options

  • GraphDistance[g,s,t] will give the length of the shortest path between s and t.
  • The distance is Infinity when there is no path between s and t.
  • For a weighted graph, the distance is the minimum of the sum of weights along any path between s and t.
  • The following options can be given:
  • EdgeWeightAutomaticweight for each edge
    MethodAutomaticmethod to use
  • Possible Method settings include "Dijkstra", "BellmanFord", and "UnitWeight".

Examples

open allclose all

Basic Examples  (1)

Give the distance for a grid graph:

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

Scope  (7)

Options  (4)

Applications  (5)

Properties & Relations  (3)

See Also

GraphDistanceMatrix  BreadthFirstScan  DepthFirstScan

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