GraphDistance
GraphDistance[g,i,j]
gives the distance from vertex i to vertex j in the graph g.
Details and Options
- GraphDistance functionality is now available in the built-in Wolfram Language function GraphDistance.
- To use GraphDistance, you first need to load the Graph Utilities Package using Needs["GraphUtilities`"].
- GraphDistance returns the graph distance from one vertex to another. Infinity is returned if no path exists from i to j. By default every edge is assumed to have an edge weight of 1.
- The following option can be used:
-
Weighted False specifies whether edge weight is to be used in calculating distance
Examples
open allclose allBasic Examples (2)
This defines a simple directed graph:
This calculates the distance from vertex 1 to vertex 5:
This function has been superseded by GraphDistance in the Wolfram System:
Scope (1)
This defines a simple directed graph:
This calculates the distance from vertex 1 to vertex 5:
There is no path from vertex 4 to vertex 1:
This defines a simple directed graph with edge weights:
This shows that the distance from vertex 1 to 3 is 2 if unit edge weights are assumed:
But the distance becomes 0 if edge weights are taken into account:
Applications (1)
Possible Issues (1)
Text
Wolfram Research (2007), GraphDistance, Wolfram Language function, https://reference.wolfram.com/language/GraphUtilities/ref/GraphDistance.html.
CMS
Wolfram Language. 2007. "GraphDistance." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/GraphUtilities/ref/GraphDistance.html.
APA
Wolfram Language. (2007). GraphDistance. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/GraphUtilities/ref/GraphDistance.html