LongestPath - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


GraphTheory

  

LongestPath

  

find a longest path in a directed acyclic graph

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

Calling Sequence

LongestPath(G, opts)

LongestPath(G, u, v, opts)

Parameters

G

-

graph

u, v

-

vertices of the graph

opts

-

(optional) one or more options as specified below

Options

• 

avoidvertices=list or set

  

Specifies vertices to avoid in building a path.

  

If vertices are specified here, the resulting path may not be longest in G.

• 

distance=truefalse

  

Specifies whether to return the distance along with the shortest path.

  

If true, each element of the list output of LongestPath will be a two-element list, the first element of which is the path and the second of which is the weighted path distance to the common ancestor.

• 

endvertex=a valid vertex in G

  

Specifies a final vertex. If provided, the algorithm only considers paths terminating at endvertex.

• 

ignoreweights=truefalse

  

Specifies whether to ignore edge weights if present. The default is false.

• 

startvertex=a valid vertex in G

  

Specifies the starting vertex. If provided, the algorithm only considers paths beginning at startvertex.

Description

• 

LongestPath(G) returns a path of maximum length in a directed acyclic graph G. The output is a list of vertices in the order they appear on the path.

• 

If G is not a directed graph or has a directed cycle, an error is returned.

Examples

withGraphTheory:

GGraph6,1,2,2,3,2,6,3,4,3,5,4,5,5,6

GGraph 1: a directed graph with 6 vertices and 7 arcs

(1)

DrawGraphG,style=spring

LongestPathG

1,2,3,4,5,6

(2)

Compatibility

• 

The GraphTheory[LongestPath] command was introduced in Maple 2025.

• 

For more information on Maple 2025 changes, see Updates in Maple 2025.

See Also

ShortestPath

TopologicSort