GraphUnion - Maple Help

GraphTheory

 GraphUnion
 construct graph union of graphs

 Calling Sequence GraphUnion(G1,...,Gs)

Parameters

 G1,...,Gs - graphs

Description

 • The GraphUnion function returns a graph G which is the union of the graphs G1,...,Gs, such that

$\mathrm{Vertices}\left(G\right)=\mathrm{Vertices}\left(\mathrm{G1}\right)\cup \cdots \cup \mathrm{Vertices}\left(\mathrm{Gs}\right)$

$\mathrm{Edges}\left(G\right)=\mathrm{Edges}\left(\mathrm{G1}\right)\cup \cdots \cup \mathrm{Edges}\left(\mathrm{Gs}\right)$

 • Note that the graphs G1,...,Gs must all be directed or all undirected, and the resulting graph is directed or undirected, respectively. Likewise, the graphs G1,...,Gs must all be weighted or all unweighted, and the resulting graph is then weighted or unweighted, respectively.
 • Moreover, if G1,...,Gs are all weighted graphs, the resulting graph is a weighted graph where the weight of any common edge is the sum of the weights of that edge in G1,...,Gs.

Examples

 > $\mathrm{with}\left(\mathrm{GraphTheory}\right):$
 > $\mathrm{G1}≔\mathrm{Graph}\left(\mathrm{directed},\left[1,2,3\right],\left\{\left[1,2\right],\left[2,3\right]\right\}\right)$
 ${\mathrm{G1}}{≔}{\mathrm{Graph 1: a directed unweighted graph with 3 vertices and 2 arc\left(s\right)}}$ (1)
 > $\mathrm{G2}≔\mathrm{Graph}\left(\mathrm{directed},\left[1,2,3\right],\left\{\left[2,3\right],\left[3,1\right]\right\}\right)$
 ${\mathrm{G2}}{≔}{\mathrm{Graph 2: a directed unweighted graph with 3 vertices and 2 arc\left(s\right)}}$ (2)
 > $G≔\mathrm{GraphUnion}\left(\mathrm{G1},\mathrm{G2}\right)$
 ${G}{≔}{\mathrm{Graph 3: a directed unweighted graph with 3 vertices and 3 arc\left(s\right)}}$ (3)
 > $\mathrm{Vertices}\left(G\right)$
 $\left[{1}{,}{2}{,}{3}\right]$ (4)
 > $\mathrm{Edges}\left(G\right)$
 $\left\{\left[{1}{,}{2}\right]{,}\left[{2}{,}{3}\right]{,}\left[{3}{,}{1}\right]\right\}$ (5)

In this example, note that the vertices of G1 and G2 are permuted differently.

 > $\mathrm{G1}≔\mathrm{Graph}\left(\left[a,b,c\right],\left\{\left[\left\{a,b\right\},3\right],\left[\left\{b,c\right\},4\right]\right\}\right)$
 ${\mathrm{G1}}{≔}{\mathrm{Graph 4: an undirected weighted graph with 3 vertices and 2 edge\left(s\right)}}$ (6)
 > $\mathrm{G2}≔\mathrm{Graph}\left(\left[a,c,b\right],\left\{\left[\left\{a,c\right\},5\right],\left[\left\{b,c\right\},6\right]\right\}\right)$
 ${\mathrm{G2}}{≔}{\mathrm{Graph 5: an undirected weighted graph with 3 vertices and 2 edge\left(s\right)}}$ (7)
 > $G≔\mathrm{GraphUnion}\left(\mathrm{G1},\mathrm{G2}\right)$
 ${G}{≔}{\mathrm{Graph 6: an undirected weighted graph with 3 vertices and 3 edge\left(s\right)}}$ (8)
 > $\mathrm{Vertices}\left(G\right)$
 $\left[{a}{,}{b}{,}{c}\right]$ (9)
 > $\mathrm{Edges}\left(G\right)$
 $\left\{\left\{{a}{,}{b}\right\}{,}\left\{{a}{,}{c}\right\}{,}\left\{{b}{,}{c}\right\}\right\}$ (10)
 > $\mathrm{WeightMatrix}\left(\mathrm{G1}\right),\mathrm{WeightMatrix}\left(\mathrm{G2}\right),\mathrm{WeightMatrix}\left(G\right)$
 $\left[\begin{array}{ccc}{0}& {3}& {0}\\ {3}& {0}& {4}\\ {0}& {4}& {0}\end{array}\right]{,}\left[\begin{array}{ccc}{0}& {5}& {0}\\ {5}& {0}& {6}\\ {0}& {6}& {0}\end{array}\right]{,}\left[\begin{array}{ccc}{0}& {3}& {5}\\ {3}& {0}& {10}\\ {5}& {10}& {0}\end{array}\right]$ (11)

In this example, note that there is one common vertex between the two graphs

 > $\mathrm{G1}≔\mathrm{Graph}\left(\left["a","b"\right],\left\{\left\{"a","b"\right\}\right\}\right)$
 ${\mathrm{G1}}{≔}{\mathrm{Graph 7: an undirected unweighted graph with 2 vertices and 1 edge\left(s\right)}}$ (12)
 > $\mathrm{G2}≔\mathrm{Graph}\left(\left["a","c"\right],\left\{\left\{"a","c"\right\}\right\}\right)$
 ${\mathrm{G2}}{≔}{\mathrm{Graph 8: an undirected unweighted graph with 2 vertices and 1 edge\left(s\right)}}$ (13)
 > $G≔\mathrm{GraphUnion}\left(\mathrm{G1},\mathrm{G2}\right)$
 ${G}{≔}{\mathrm{Graph 9: an undirected unweighted graph with 3 vertices and 2 edge\left(s\right)}}$ (14)
 > $\mathrm{Vertices}\left(G\right)$
 $\left[{"a"}{,}{"b"}{,}{"c"}\right]$ (15)
 > $\mathrm{Edges}\left(G\right)$
 $\left\{\left\{{"a"}{,}{"b"}\right\}{,}\left\{{"a"}{,}{"c"}\right\}\right\}$ (16)