GraphTheory
AddEdge
add edge to graph
Calling Sequence
Parameters
Description
Examples
AddEdge(G, E)
AddEdge(G, E, ip)
G
-
undirected graph
E
edge, trail, or set of edges
ip
(optional) equation of the form inplace=true or false
The AddEdge command adds one or more edges to an undirected graph. By default, the original graph is changed to a graph containing the specified set of edge(s). By setting inplace=false the original graph remains unchanged and a new graph containing the specified set of edges is created.
If the graph is weighted, then a weighted edge can be added by calling AddEdge with one or more edges in the form edge,weight, where the edge is just the set of two vertices, and the weight represents the value of the edge weight.
with⁡GraphTheory:
G≔CycleGraph⁡5
G≔Graph 1: an undirected graph with 5 vertices and 5 edge(s)
AddEdge⁡G,1,3,inplace=false
Graph 2: an undirected graph with 5 vertices and 6 edge(s)
Graph 1: an undirected graph with 5 vertices and 5 edge(s)
AddEdge⁡G,1,3,2,4,inplace=false
Graph 3: an undirected graph with 5 vertices and 7 edge(s)
AddEdge⁡G,1,3,2,4
Graph 1: an undirected graph with 5 vertices and 7 edge(s)
Gw≔Graph⁡Matrix⁡0,1,1,0,1,0,0,1,1,0,0,0,0,1,0,0,weighted
Gw≔Graph 4: an undirected weighted graph with 4 vertices and 3 edge(s)
Edges⁡Gw,weights
1,2,1,1,3,1,2,4,1
AddEdge⁡Gw,1,4,2
Graph 4: an undirected weighted graph with 4 vertices and 4 edge(s)
1,2,1,1,3,1,1,4,2,2,4,1
G≔Graph⁡a,b,c,d
G≔Graph 5: an undirected graph with 4 vertices and 0 edge(s)
AddEdge⁡G,Trail⁡a,b,c,d,a
Graph 5: an undirected graph with 4 vertices and 4 edge(s)
Edges⁡G
a,b,a,d,b,c,c,d
See Also
AddArc
DeleteEdge
Edges
Graph
HasEdge
Trail
Download Help Document