GraphTheory

Parameters

 G - undirected graph E - edge, trail, or set of edges ip - (optional) equation of the form inplace=true or false

Description

 • 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 $\left[\mathrm{edge},\mathrm{weight}\right]$, where the edge is just the set of two vertices, and the weight represents the value of the edge weight.

Examples

 > $\mathrm{with}\left(\mathrm{GraphTheory}\right):$
 > $G≔\mathrm{CycleGraph}\left(5\right)$
 ${G}{≔}{\mathrm{Graph 1: an undirected unweighted graph with 5 vertices and 5 edge\left(s\right)}}$ (1)
 > $\mathrm{AddEdge}\left(G,\left\{1,3\right\},\mathrm{inplace}=\mathrm{false}\right)$
 ${\mathrm{Graph 2: an undirected unweighted graph with 5 vertices and 6 edge\left(s\right)}}$ (2)
 > $G$
 ${\mathrm{Graph 1: an undirected unweighted graph with 5 vertices and 5 edge\left(s\right)}}$ (3)
 > $\mathrm{AddEdge}\left(G,\left\{\left\{1,3\right\},\left\{2,4\right\}\right\},\mathrm{inplace}=\mathrm{false}\right)$
 ${\mathrm{Graph 3: an undirected unweighted graph with 5 vertices and 7 edge\left(s\right)}}$ (4)
 > $\mathrm{AddEdge}\left(G,\left\{\left\{1,3\right\},\left\{2,4\right\}\right\}\right)$
 ${\mathrm{Graph 1: an undirected unweighted graph with 5 vertices and 7 edge\left(s\right)}}$ (5)
 > $G$
 ${\mathrm{Graph 1: an undirected unweighted graph with 5 vertices and 7 edge\left(s\right)}}$ (6)
 > $\mathrm{Gw}≔\mathrm{Graph}\left(\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),'\mathrm{weighted}'\right)$
 ${\mathrm{Gw}}{≔}{\mathrm{Graph 4: an undirected weighted graph with 4 vertices and 3 edge\left(s\right)}}$ (7)
 > $\mathrm{Edges}\left(\mathrm{Gw},\mathrm{weights}\right)$
 $\left\{\left[\left\{{1}{,}{2}\right\}{,}{1}\right]{,}\left[\left\{{1}{,}{3}\right\}{,}{1}\right]{,}\left[\left\{{2}{,}{4}\right\}{,}{1}\right]\right\}$ (8)
 > $\mathrm{AddEdge}\left(\mathrm{Gw},\left[\left\{1,4\right\},2\right]\right)$
 ${\mathrm{Graph 4: an undirected weighted graph with 4 vertices and 4 edge\left(s\right)}}$ (9)
 > $\mathrm{Edges}\left(\mathrm{Gw},\mathrm{weights}\right)$
 $\left\{\left[\left\{{1}{,}{2}\right\}{,}{1}\right]{,}\left[\left\{{1}{,}{3}\right\}{,}{1}\right]{,}\left[\left\{{1}{,}{4}\right\}{,}{2}\right]{,}\left[\left\{{2}{,}{4}\right\}{,}{1}\right]\right\}$ (10)
 > $G≔\mathrm{Graph}\left(\left[a,b,c,d\right]\right)$
 ${G}{≔}{\mathrm{Graph 5: an undirected unweighted graph with 4 vertices and 0 edge\left(s\right)}}$ (11)
 > $\mathrm{AddEdge}\left(G,\mathrm{Trail}\left(a,b,c,d,a\right)\right)$
 ${\mathrm{Graph 5: an undirected unweighted graph with 4 vertices and 4 edge\left(s\right)}}$ (12)
 > $\mathrm{Edges}\left(G\right)$
 $\left\{\left\{{a}{,}{b}\right\}{,}\left\{{a}{,}{d}\right\}{,}\left\{{b}{,}{c}\right\}{,}\left\{{c}{,}{d}\right\}\right\}$ (13)