Graph(V, E, opts)
Graph(V, L, opts)
Graph(V, E, A, opts)
(optional) list of vertices (integers, symbols, or strings) or integer specifying the vertices 1,2,...,V
(optional) set of edges
(optional) list or Array of neighbors
(optional) function of the form Trail(a,b,c,,...) or Trail([a,b,c,...])
(optional) adjacency Matrix (of edge weights)
(optional) procedure (a networks graph)
(optional) zero or more options as specified below
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.
Specifies a color or list of colors to associate with the vertices in vertex order.
Specifies coordinate positions for the vertices for use with DrawGraph.
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 i,j. A directed edge from vertex a to vertex b is input as a list a,b. A weighted edge is input as either e,w where e is an edge (directed or undirected) and w, the edge weight, is a number (integer or decimal). Note that the vertices at the ends of either a directed or undirected edge must be distinct.
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 1,2,3,...) 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.
Build a graph with 5 vertices and no edges.
G ≔ Graph⁡5
G≔Graph 1: an undirected unweighted graph with 5 vertices and 0 edge(s)
Build an undirected graph with 3 vertices, all of which are connected.
G ≔ Graph⁡a,b,b,c,c,a
G≔Graph 2: an undirected unweighted graph with 3 vertices and 3 edge(s)
Build a directed graph with 3 vertices which form a directed cycle.
G ≔ Graph⁡1,2,2,3,3,1
G≔Graph 3: a directed unweighted graph with 3 vertices and 3 arc(s)
V ≔ a,b,c,d:
E ≔ a,b,2,b,c,2.3,c,a,32:
G ≔ Graph⁡V,E
G≔Graph 4: a directed weighted graph with 4 vertices and 3 arc(s)
Build a directed graph with 4 vertices which form a directed cycle.
G ≔ Graph⁡a,b,c,d,2,3,4,1
G≔Graph 5: a directed unweighted graph with 4 vertices and 4 arc(s)
Build a undirected graph with 4 vertices by specifying a trail.
G ≔ Graph⁡Trail⁡1,2,3,4,1,3
G≔Graph 6: an undirected unweighted graph with 4 vertices and 5 edge(s)
G ≔ Graph⁡directed,Trail⁡1,2,3,1,Trail⁡4,5,6,4
G≔Graph 7: a directed unweighted graph with 6 vertices and 6 arc(s)
Build a undirected graph with 4 vertices by specifying an adjacency matrix.
A1 ≔ Matrix⁡0,1,1,0,1,0,0,1,1,0,0,0,0,1,0,0:
G ≔ Graph⁡A1
G≔Graph 8: an undirected unweighted graph with 4 vertices and 3 edge(s)
G ≔ Graph⁡directed,A1,weighted
G≔Graph 9: a directed weighted graph with 4 vertices and 6 arc(s)
A2 ≔ Matrix⁡0,1.0,2.3,0,4,0,0,3.1,0,0,0,0,0,0,0,0:
G ≔ Graph⁡A2
G≔Graph 10: a directed weighted graph with 4 vertices and 4 arc(s)
Convert a graph built using the legacy networks package to a GraphTheory graph.
G ≔ Graph⁡N
G≔Graph 11: a directed unweighted graph with 4 vertices and 4 arc(s)
G≔Graph 12: a directed weighted graph with 4 vertices and 5 arc(s)
Download Help Document
What kind of issue would you like to report? (Optional)