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

Online Help

All Products    Maple    MapleSim


GraphTheory Updates in Maple 2025

 

Description

New commands

New functionality for existing commands

Additions to SpecialGraphs

Description

A substantial effort was put into Graph Theory for Maple 2025, including new commands for graph computation and generation.

with(GraphTheory):

New commands

AllSimplePaths

The new AllSimplePaths command returns an iterator with which one can step through all paths from a given vertex to another vertex in a directed graph.

G1 := Graph({["A", "B"], ["A", "D"], ["B", "C"], ["C", "E"], ["D", "E"]});

G1Graph 1: a directed graph with 5 vertices and 5 arcs

(1)

DrawGraph(G1);

iterator := AllSimplePaths( G1, "A", "E" );

iteratorPath Iterator

(2)

iterator:-getNext();

A,D,E

(3)

iterator:-getNext();

A,B,C,E

(4)

iterator:-hasNext();

false

(5)

Ancestors and Descendants

The new Ancestors command returns a list of ancestors of the given vertex in the given directed graph. The related new command Descendants returns a list of descendants of the given vertex.

Ancestors( G1, "A" );

(6)

Ancestors( G1, "E" );

A,B,C,D

(7)

Descendants( G1, "A" );

B,C,D,E

(8)

FindCycle

The new FindCycle command finds a cycle, if one exists in the given graph.

FindCycle(G1);

(9)

FindCycle( Graph( {["A", "B"], ["B", "C"], ["C", "A"]} ) );

C,A,B,C

(10)

IsCaterpillarTree and IsLobsterTree

The new IsCaterpillarTree command tests whether the graph is a caterpillar tree, a tree for which there is some path such that every vertex is either on the path or the neighbor of a vertex on the path.

CT := Graph({{1,4},{2,4},{3,4},{4,5},{5,6},{6,7},{7,8},{7,9}});

CTGraph 2: an undirected graph with 9 vertices and 8 edges

(11)

DrawGraph(CT);

IsCaterpillarTree(CT);

true

(12)

The new IsLobsterTree command tests whether the graph is lobster tree, a tree such that the result of removing all leaf vertices is a caterpillar tree.

LT := Graph({{1,2},{2,3},{3,4},{4,5},{3,6},{6,7},{3,8},{8,9}});

LTGraph 3: an undirected graph with 9 vertices and 8 edges

(13)

DrawGraph(LT);

IsLobsterTree(LT);

true

(14)

IsCaterpillarTree(LT);

false

(15)

IsPlatonicGraph

The new IsPlatonicGraph command tests whether the graph is Platonic. The Platonic graphs consist of those graphs whose skeletons are the Platonic solids (polyhedra whose faces are identical).

IsPlatonicGraph( SpecialGraphs:-CubeGraph() );

true

(16)

LongestPath

The new LongestPath command computes the longest path within a given (directed) graph.

LongestPath(G1);

A,B,C,E

(17)

LowestCommonAncestors

The new LowestCommonAncestors command computes the set of lowest common ancestors in a given directed graph.

LowestCommonAncestors( G1, "C", "D" );

A

(18)

ModularityMatrix

The new ModularityMatrix command computes the modularity matrix of the graph G.

ModularityMatrix(G1);

01010251545150251515151251515151452525250

(19)

ResistanceDistance

The new ResistanceDistance command computes the resistance distance of the graph G.

ResistanceDistance(SpecialGraphs:-CubeGraph());

071271234712343456712034712347125634712340712345671234347127120563434712712343456071271234347125634712034712345671234712340712563434712347127120

(20)

ShortestAncestralPath and ShortestDescendantPath

The new ShortestAncestralPath constructs the shortest ancestral path between two nodes in the given directed graph.

ShortestAncestralPath( G1, "C", "D") ;

A,B,C,A,D

(21)

You can similarly find the shortest descendent path.

New functionality for existing commands

IsReachable and Reachable

The IsReachable and Reachable commands now have a new option distance to constrain the distance within a given vertex.

IsReachable( G1, "A", "E", distance = 1 );

false

(22)

Reachable( G1, "A", distance = 1 );

A,B,D

(23)

ShortestPath

The ShortestPath command accepts an option avoidvertices to constrain the search space for a shortest path to avoid some specified set of vertices.

ShortestPath( G1, "A", "E" );

A,D,E

(24)

ShortestPath( G1, "A", "E", avoidvertices = {"D"} );

A,B,C,E

(25)

Additions to SpecialGraphs

The SpecialGraphs subpackage now includes commands for the F26a graph and Hanoi graph.

• 

The F26a graph may be understood visually

FG := SpecialGraphs:-F26AGraph();

FGGraph 4: an undirected graph with 26 vertices and 39 edges

(26)

DrawGraph(FG);

• 

The Hanoi graph is a graph whose edges correspond to allowed moves of the tower of Hanoi problem.

HG4 := SpecialGraphs:-HanoiGraph(4);

HG4Graph 5: an undirected graph with 81 vertices and 120 edges

(27)