GraphPath
GraphPath[g,start,end]
finds a shortest path between vertices start and end in graph g.
Details and Options
- GraphPath functionality is now available in the built-in Wolfram Language function FindShortestPath.
- To use GraphPath, you first need to load the Graph Utilities Package using Needs["GraphUtilities`"].
- The following options can be used:
-
Method Automatic method to use to find the shortest path Weighted True specify whether edge weight is to be used in calculating distance
Examples
open allclose allBasic Examples (2)
This defines a small directed graph:
This finds the shortest path from vertex 1 to vertex 3:
This finds the shortest path from vertex 1 to vertex 3, ignoring the edge weights:
GraphPath has been superseded by FindShortestPath:
Options (1)
Method (1)
Because of the negative edge weight, the Dijkstra algorithm cannot be applied:
The Bellman–Ford algorithm works:
This defines a small graph with a negative cycle:
The Dijkstra algorithm does not work for negative edge weights:
The Bellman–Ford algorithm detects a negative weight cycle:
The default algorithm for graphs with negative edge weights is Bellman–Ford:
Properties & Relations (1)
Possible Issues (1)
Text
Wolfram Research (2007), GraphPath, Wolfram Language function, https://reference.wolfram.com/language/GraphUtilities/ref/GraphPath.html.
CMS
Wolfram Language. 2007. "GraphPath." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/GraphUtilities/ref/GraphPath.html.
APA
Wolfram Language. (2007). GraphPath. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/GraphUtilities/ref/GraphPath.html