Graph - Maple Help

GraphTheory

 Graph
 construct a graph

 Calling Sequence Graph(V, opts) Graph(V, E, opts) Graph(L, opts) Graph(V, L, opts) Graph(T, opts) Graph(A, opts) Graph(V, E, A, opts) Graph(N, opts)

Parameters

 V - (optional) list of vertices (integers, symbols, or strings) or integer specifying the vertices 1,2,...,V E - (optional) set of edges L - (optional) list or Array of neighbors T - (optional) function of the form Trail(a,b,c,,...) or Trail([a,b,c,...]) A - (optional) adjacency Matrix (of edge weights) N - (optional) procedure (a networks graph) opts - (optional) one or more options as specified below

Options

 The opts parameter is used to specify one or more additional properties of the graph.
 • weighted or weighted=true
 Specifies that this graph has weighted edges.
 unweighted or weighted=false
 Specifies that this graph has no edge weights.
 • directed or directed=true
 Specifies that this graph has directed edges.
 • undirected or directed=false
 Specifies that this graph has no directed edges.
 • selfloops=true or false
 Specifies whether self-loops should be permitted in the graph. If false, an error will be issued if the edge information provided with parameters E, L, T, or A contains a self-loop. The default is true.
 • vertexcolor=c
 Specifies a color or list of colors to associate with the vertices in vertex order.
 • vertexpositions=p
 Specifies coordinate positions for the vertices for use with DrawGraph.

Description

 • The type of each argument determines what it is.  Because of this the arguments can appear in any order.
 • A symbol can be one of directed, undirected, weighted, or unweighted. This specifies the type of the graph.  If not specified, a default is chosen depending on the type of the other inputs.
 • An integer n specifies the number of vertices and implicitly the vertex labels 1 through n.
 • A list V of integers, symbols or strings specifies the vertices. Each vertex must be an integer, symbol or string.
 • A set E specifies the set of edges. An undirected edge between vertices i and j is input as a set of two vertices $\left\{i,j\right\}$.  A directed edge from vertex a to vertex b is input as a list $\left[a,b\right]$.  A weighted edge is input as either $\left[e,w\right]$ where e is an edge (directed or undirected) and w, the edge weight, is a number (integer or decimal).
 • An Array (or list) of lists / sets of vertices L specifies a mapping from vertices to their neighbors. Note that the mapping is an integer mapping that indicates the vertices (if the vertices are labeled as $\left[1,2,3,\mathrm{...}\right]$) or the location of each vertex in the vertex list V. If the graph is undirected, then the lists / sets of neighbors must be symmetric.
 • A function T of the form Trail(a,b,c,...) or Trail([a,b,c,...]) specifies a trail of edges from a to b to c ....  By default the edges are undirected.  If the symbol directed is specified as an option then they are directed.  More than one trail can be specified.  This is often the easiest way to enter a graph interactively.
 • A matrix A means the adjacency matrix.  A symmetric matrix is interpreted as an undirected graph unless the edge direction is stated otherwise. Likewise, a matrix of 0's and 1's is interpreted as an unweighted graph unless specified otherwise. The diagonal entries of an adjacency matrix must all be equal to 0.
 • A procedure N means a networks graph.  This option allows conversion from a networks graph representation to the GraphTheory representation. Note, the GraphTheory package does not support multigraphs.

Examples

 > $\mathrm{with}\left(\mathrm{GraphTheory}\right):$

Build a graph with 5 vertices and no edges.

 > $G≔\mathrm{Graph}\left(5\right)$
 ${G}{≔}{\mathrm{Graph 1: an undirected unweighted graph with 5 vertices and 0 edge\left(s\right)}}$ (1)
 > $\mathrm{Vertices}\left(G\right)$
 $\left[{1}{,}{2}{,}{3}{,}{4}{,}{5}\right]$ (2)
 > $\mathrm{Edges}\left(G\right)$
 ${\varnothing }$ (3)

Build an undirected graph with 3 vertices, all of which are connected.

 > $G≔\mathrm{Graph}\left(\left\{\left\{a,b\right\},\left\{a,c\right\},\left\{b,c\right\}\right\}\right)$
 ${G}{≔}{\mathrm{Graph 2: an undirected unweighted graph with 3 vertices and 3 edge\left(s\right)}}$ (4)
 > $\mathrm{Vertices}\left(G\right)$
 $\left[{a}{,}{b}{,}{c}\right]$ (5)
 > $\mathrm{Edges}\left(G\right)$
 $\left\{\left\{{a}{,}{b}\right\}{,}\left\{{a}{,}{c}\right\}{,}\left\{{b}{,}{c}\right\}\right\}$ (6)
 > $\mathrm{DrawGraph}\left(G\right)$

Build a directed graph with 3 vertices which form a directed cycle.

 > $G≔\mathrm{Graph}\left(\left\{\left[1,2\right],\left[2,3\right],\left[3,1\right]\right\}\right)$
 ${G}{≔}{\mathrm{Graph 3: a directed unweighted graph with 3 vertices and 3 arc\left(s\right)}}$ (7)
 > $\mathrm{Edges}\left(G\right)$
 $\left\{\left[{1}{,}{2}\right]{,}\left[{2}{,}{3}\right]{,}\left[{3}{,}{1}\right]\right\}$ (8)
 > $V≔\left[a,b,c,d\right]:$
 > $E≔\left\{\left[\left[a,b\right],2\right],\left[\left[b,c\right],2.3\right],\left[\left[c,a\right],\frac{3}{2}\right]\right\}:$
 > $G≔\mathrm{Graph}\left(V,E\right)$
 ${G}{≔}{\mathrm{Graph 4: a directed weighted graph with 4 vertices and 3 arc\left(s\right)}}$ (9)
 > $\mathrm{WeightMatrix}\left(G\right)$
 $\left[\begin{array}{cccc}{0}& {2}& {0}& {0}\\ {0}& {0}& {2.3}& {0}\\ \frac{{3}}{{2}}& {0}& {0}& {0}\\ {0}& {0}& {0}& {0}\end{array}\right]$ (10)

Build a directed graph with 4 vertices which form a directed cycle.

 > $G≔\mathrm{Graph}\left(\left[a,b,c,d\right],\left[\left\{2\right\},\left\{3\right\},\left\{4\right\},\left\{1\right\}\right]\right)$
 ${G}{≔}{\mathrm{Graph 5: a directed unweighted graph with 4 vertices and 4 arc\left(s\right)}}$ (11)
 > $\mathrm{Edges}\left(G\right)$
 $\left\{\left[{a}{,}{b}\right]{,}\left[{b}{,}{c}\right]{,}\left[{c}{,}{d}\right]{,}\left[{d}{,}{a}\right]\right\}$ (12)

Build a undirected graph with 4 vertices by specifying a trail.

 > $G≔\mathrm{Graph}\left(\mathrm{Trail}\left(1,2,3,4,1,3\right)\right)$
 ${G}{≔}{\mathrm{Graph 6: an undirected unweighted graph with 4 vertices and 5 edge\left(s\right)}}$ (13)
 > $\mathrm{Edges}\left(G\right)$
 $\left\{\left\{{1}{,}{2}\right\}{,}\left\{{1}{,}{3}\right\}{,}\left\{{1}{,}{4}\right\}{,}\left\{{2}{,}{3}\right\}{,}\left\{{3}{,}{4}\right\}\right\}$ (14)
 > $G≔\mathrm{Graph}\left(\mathrm{directed},\mathrm{Trail}\left(1,2,3,1\right),\mathrm{Trail}\left(4,5,6,4\right)\right)$
 ${G}{≔}{\mathrm{Graph 7: a directed unweighted graph with 6 vertices and 6 arc\left(s\right)}}$ (15)
 > $\mathrm{Edges}\left(G\right)$
 $\left\{\left[{1}{,}{2}\right]{,}\left[{2}{,}{3}\right]{,}\left[{3}{,}{1}\right]{,}\left[{4}{,}{5}\right]{,}\left[{5}{,}{6}\right]{,}\left[{6}{,}{4}\right]\right\}$ (16)

Build a undirected graph with 4 vertices by specifying an adjacency matrix.

 > $\mathrm{A1}≔\mathrm{Matrix}\left(\left[\left[0,1,1,0\right],\left[1,0,0,1\right],\left[1,0,0,0\right],\left[0,1,0,0\right]\right]\right):$
 > $G≔\mathrm{Graph}\left(\mathrm{A1}\right)$
 ${G}{≔}{\mathrm{Graph 8: an undirected unweighted graph with 4 vertices and 3 edge\left(s\right)}}$ (17)
 > $\mathrm{Edges}\left(G\right)$
 $\left\{\left\{{1}{,}{2}\right\}{,}\left\{{1}{,}{3}\right\}{,}\left\{{2}{,}{4}\right\}\right\}$ (18)
 > $G≔\mathrm{Graph}\left(\mathrm{directed},\mathrm{A1},\mathrm{weighted}\right)$
 ${G}{≔}{\mathrm{Graph 9: a directed weighted graph with 4 vertices and 6 arc\left(s\right)}}$ (19)
 > $\mathrm{Edges}\left(G,\mathrm{weights}\right)$
 $\left\{\left[\left[{1}{,}{2}\right]{,}{1}\right]{,}\left[\left[{1}{,}{3}\right]{,}{1}\right]{,}\left[\left[{2}{,}{1}\right]{,}{1}\right]{,}\left[\left[{2}{,}{4}\right]{,}{1}\right]{,}\left[\left[{3}{,}{1}\right]{,}{1}\right]{,}\left[\left[{4}{,}{2}\right]{,}{1}\right]\right\}$ (20)
 > $\mathrm{A2}≔\mathrm{Matrix}\left(\left[\left[0,1.0,2.3,0\right],\left[4,0,0,3.1\right],\left[0,0,0,0\right],\left[0,0,0,0\right]\right]\right):$
 > $G≔\mathrm{Graph}\left(\mathrm{A2}\right)$
 ${G}{≔}{\mathrm{Graph 10: a directed weighted graph with 4 vertices and 4 arc\left(s\right)}}$ (21)
 > $\mathrm{Edges}\left(G,\mathrm{weights}\right)$
 $\left\{\left[\left[{1}{,}{2}\right]{,}{1.0}\right]{,}\left[\left[{1}{,}{3}\right]{,}{2.3}\right]{,}\left[\left[{2}{,}{1}\right]{,}{4}\right]{,}\left[\left[{2}{,}{4}\right]{,}{3.1}\right]\right\}$ (22)

Convert a graph built using the legacy networks package to a GraphTheory graph.

 > $\mathrm{with}\left(\mathrm{networks}\right)$
 $\left[{\mathrm{acycpoly}}{,}{\mathrm{addedge}}{,}{\mathrm{addvertex}}{,}{\mathrm{adjacency}}{,}{\mathrm{allpairs}}{,}{\mathrm{ancestor}}{,}{\mathrm{arrivals}}{,}{\mathrm{bicomponents}}{,}{\mathrm{charpoly}}{,}{\mathrm{chrompoly}}{,}{\mathrm{complement}}{,}{\mathrm{complete}}{,}{\mathrm{components}}{,}{\mathrm{connect}}{,}{\mathrm{connectivity}}{,}{\mathrm{contract}}{,}{\mathrm{countcuts}}{,}{\mathrm{counttrees}}{,}{\mathrm{cube}}{,}{\mathrm{cycle}}{,}{\mathrm{cyclebase}}{,}{\mathrm{daughter}}{,}{\mathrm{degreeseq}}{,}{\mathrm{delete}}{,}{\mathrm{departures}}{,}{\mathrm{diameter}}{,}{\mathrm{dinic}}{,}{\mathrm{djspantree}}{,}{\mathrm{dodecahedron}}{,}{\mathrm{draw}}{,}{\mathrm{draw3d}}{,}{\mathrm{duplicate}}{,}{\mathrm{edges}}{,}{\mathrm{ends}}{,}{\mathrm{eweight}}{,}{\mathrm{flow}}{,}{\mathrm{flowpoly}}{,}{\mathrm{fundcyc}}{,}{\mathrm{getlabel}}{,}{\mathrm{girth}}{,}{\mathrm{graph}}{,}{\mathrm{graphical}}{,}{\mathrm{gsimp}}{,}{\mathrm{gunion}}{,}{\mathrm{head}}{,}{\mathrm{icosahedron}}{,}{\mathrm{incidence}}{,}{\mathrm{incident}}{,}{\mathrm{indegree}}{,}{\mathrm{induce}}{,}{\mathrm{isplanar}}{,}{\mathrm{maxdegree}}{,}{\mathrm{mincut}}{,}{\mathrm{mindegree}}{,}{\mathrm{neighbors}}{,}{\mathrm{new}}{,}{\mathrm{octahedron}}{,}{\mathrm{outdegree}}{,}{\mathrm{path}}{,}{\mathrm{petersen}}{,}{\mathrm{random}}{,}{\mathrm{rank}}{,}{\mathrm{rankpoly}}{,}{\mathrm{shortpathtree}}{,}{\mathrm{show}}{,}{\mathrm{shrink}}{,}{\mathrm{span}}{,}{\mathrm{spanpoly}}{,}{\mathrm{spantree}}{,}{\mathrm{tail}}{,}{\mathrm{tetrahedron}}{,}{\mathrm{tuttepoly}}{,}{\mathrm{vdegree}}{,}{\mathrm{vertices}}{,}{\mathrm{void}}{,}{\mathrm{vweight}}\right]$ (23)
 > $\mathrm{new}\left(N\right):$
 > $\mathrm{addvertex}\left(\left\{1,2,a,b\right\},N\right)$
 ${1}{,}{2}{,}{a}{,}{b}$ (24)
 > $\mathrm{addedge}\left(\left\{1,2\right\},N\right)$
 ${\mathrm{e1}}$ (25)
 > $\mathrm{addedge}\left(\left[a,b\right],N\right)$
 ${\mathrm{e2}}$ (26)
 > $\mathrm{addedge}\left(\left[b,a\right],N\right)$
 ${\mathrm{e3}}$ (27)
 > $G≔\mathrm{Graph}\left(N\right)$
 ${G}{≔}{\mathrm{Graph 11: a directed unweighted graph with 4 vertices and 4 arc\left(s\right)}}$ (28)
 > $\mathrm{Edges}\left(G\right)$
 $\left\{\left[{1}{,}{2}\right]{,}\left[{2}{,}{1}\right]{,}\left[{a}{,}{b}\right]{,}\left[{b}{,}{a}\right]\right\}$ (29)
 > $\mathrm{addedge}\left(\left[1,a\right],\mathrm{weights}=2,N\right)$
 ${\mathrm{e4}}$ (30)
 > $\mathrm{addedge}\left(\left[2,b\right],\mathrm{weights}=3,N\right)$
 ${\mathrm{e5}}$ (31)
 > $G≔\mathrm{Graph}\left(N\right)$
 ${G}{≔}{\mathrm{Graph 12: a directed weighted graph with 4 vertices and 6 arc\left(s\right)}}$ (32)
 > $\mathrm{Edges}\left(G,\mathrm{weights}\right)$
 $\left\{\left[\left[{1}{,}{2}\right]{,}{1}\right]{,}\left[\left[{1}{,}{a}\right]{,}{2}\right]{,}\left[\left[{2}{,}{1}\right]{,}{1}\right]{,}\left[\left[{2}{,}{b}\right]{,}{3}\right]{,}\left[\left[{a}{,}{b}\right]{,}{1}\right]{,}\left[\left[{b}{,}{a}\right]{,}{1}\right]\right\}$ (33)

Compatibility

 • The selfloops option was introduced in Maple 2020.