GraphTheory

Parameters

 G - graph L - values for adjacent, nonadjacent, and diagonal entries opts - (optional) one or more options as specified below

Options

 • datatype=type
 Specifies a datatype for the generated Matrix as described in rtable. The default is datatype=anything.
 • order=one of C_order or Fortran_order
 Specifies the order of the generated Matrix. The default is order=C_order.
 • shape=name or list of names
 Specifies the storage allocation for Matrix entries. Must be a name or list of names specifying one or more built-in or user-defined indexing functions. The default is shape=symmetric if G is undirected and shape=[] if G is directed.
 • storage=name
 Specifies the storage mode. The default is storage=sparse if the number of edges is much smaller than the square of the number of vertices; otherwise, it is storage=triangular[upper] if G is undirected and storage=rectangular if G is directed.

Description

 • The AdjacencyMatrix command returns the adjacency matrix of a graph G whose rows and columns are indexed by the vertices. The entry $i,j$ of this matrix is 1 if there is an edge from vertex i to vertex j and 0 otherwise.
 • The optional parameter L is a list of three elements specifying alternate special-purpose values for the entries of the adjacency matrix. If specified, the generated matrix has the following properties:
 – A[i,j] = L[1] when there is an edge from i to j in G
 – A[i,j] = L[2] when there is no edge from i to j in G
 – A[i,i] = L[3] along the diagonal
 The default behavior corresponds to specifying the list [1,0,0].
 • The default output is an n by n Matrix with the following properties:
 – If G is directed or undirected: datatype=anything and order=C_order
 – If G is undirected: shape=symmetric, storage=triangular[upper],
 – If G is directed: storage=rectangular, shape=[]
 – If G is sparse, i.e., |E| << |V|^2 then storage=sparse is used.

Examples

 > $\mathrm{with}\left(\mathrm{GraphTheory}\right):$
 > $G≔\mathrm{Graph}\left(\left[1,2,3,4\right],\mathrm{Trail}\left(1,2,3,4,1\right)\right)$
 ${G}{≔}{\mathrm{Graph 1: an undirected unweighted graph with 4 vertices and 4 edge\left(s\right)}}$ (1)
 > $\mathrm{AdjacencyMatrix}\left(G\right)$
 $\left[\begin{array}{cccc}{0}& {1}& {0}& {1}\\ {1}& {0}& {1}& {0}\\ {0}& {1}& {0}& {1}\\ {1}& {0}& {1}& {0}\end{array}\right]$ (2)
 > $\mathrm{Neighbors}\left(G\right)$
 $\left[\left[{2}{,}{4}\right]{,}\left[{1}{,}{3}\right]{,}\left[{2}{,}{4}\right]{,}\left[{1}{,}{3}\right]\right]$ (3)
 > $H≔\mathrm{Digraph}\left(\left[1,2,3,4\right],\mathrm{Trail}\left(1,2,3,4,1\right)\right)$
 ${H}{≔}{\mathrm{Graph 2: a directed unweighted graph with 4 vertices and 4 arc\left(s\right)}}$ (4)
 > $\mathrm{AdjacencyMatrix}\left(H\right)$
 $\left[\begin{array}{cccc}{0}& {1}& {0}& {0}\\ {0}& {0}& {1}& {0}\\ {0}& {0}& {0}& {1}\\ {1}& {0}& {0}& {0}\end{array}\right]$ (5)
 > $\mathrm{Departures}\left(H\right)$
 $\left[\left[{2}\right]{,}\left[{3}\right]{,}\left[{4}\right]{,}\left[{1}\right]\right]$ (6)

Compatibility

 • The GraphTheory[AdjacencyMatrix] command was updated in Maple 2021.
 • The L parameter was introduced in Maple 2021.
 • The datatype, order, shape and storage options were introduced in Maple 2021.