GraphUtilities`
GraphUtilities`

GraphPath

As of Version 10, all the functionality of the GraphUtilities package is built into the Wolfram System. >>

GraphPath[g,start,end]

finds a shortest path between vertices start and end in graph g.

Details

Examples

open allclose all

Basic 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)

This defines a small graph:

Because of the negative edge weight, the Dijkstra algorithm cannot be applied:

The BellmanFord algorithm works:

This defines a small graph with a negative cycle:

The Dijkstra algorithm does not work for negative edge weights:

The BellmanFord algorithm detects a negative weight cycle:

The default algorithm for graphs with negative edge weights is BellmanFord:

Properties & Relations  (1)

This defines a small directed graph:

This finds the shortest path from vertex 1 to 3:

This finds the distance of this path, taking into account the edge weights:

This finds the distance of this path, ignoring the edge weights:

Possible Issues  (1)

This defines a small directed graph:

If there are negative edge weights, the "Dijkstra" method cannot be used:

This finds the shortest path from vertex 1 to vertex 3 using the "BellmanFord" method:

Interactive Examples  (1)

This shows how to travel from vertex 1 to 7 through the shortest path: