graph_product

Contents

graph_product#

graph_tool.generation.graph_product(g1, g2, kind='cartesian', root=0)[git][source]#

Return the product of two graphs.

Parameters:
g1Graph

First graph.

g2Graph

Second graph, with the same directedness as g1.

kindstr (optional, default: "cartesian")

Kind of product: "cartesian", "tensor", "strong", "lexicographic", "rooted", "modular", or "corona".

rootint (optional, default: 0)

Root vertex of g2, used only by the rooted product.

Returns:
gGraph

The product graph, where the vertex \((i, j)\), for the vertices \(i\) of g1 and \(j\) of g2 (in the order of their indices), has the index \(iV_2 + j\). For the corona product, the vertices of g1 keep their indices, and the vertex \(j\) of the copy of g2 attached to the vertex \(i\) has the index \(V_1 + iV_2 + j\).

See also

graph_join

Join of two graphs

graph_composition

Relational composition of two graphs

graph_union

Union of two graphs

lattice

Square lattice

Notes

The vertices \((i, j)\) and \((i', j')\) are adjacent in the product [hammack-handbook-2011] when:

Product

Condition

cartesian

\(i = i'\) and \(j \sim j'\), or \(i \sim i'\) and \(j = j'\)

tensor

\(i \sim i'\) and \(j \sim j'\)

strong

the union of the cartesian and tensor products

lexicographic

\(i \sim i'\), or \(i = i'\) and \(j \sim j'\)

rooted

\(i = i'\) and \(j \sim j'\), or \(i \sim i'\) and \(j = j' = r\), for the root \(r\) of g2

modular

\(i \neq i'\), \(j \neq j'\), and either \(i \sim i'\) and \(j \sim j'\), or \(i \not\sim i'\) and \(j \not\sim j'\)

where \(\sim\) means adjacency (along the edge direction, for directed graphs). The rooted product [godsil-new-1978] is a copy of g2 for every vertex of g1, with the edges of g1 between the copies of the root, and the corona product [frucht-corona-1970] is g1 with a copy of g2 for every vertex \(i\), all of whose vertices are adjacent to \(i\) (with edges from \(i\), for directed graphs). The modular product, whose cliques correspond to the common induced subgraphs of the factors [barrow-subgraph-1976], ignores the parallel edges and self-loops of the factors; for the other products, they propagate to the product in the corresponding way. The cartesian product of paths is a grid, as given by lattice(). The algorithm runs in time proportional to the size of the product, which is \(O(V_1^2V_2^2)\) for the modular product.

References

[hammack-handbook-2011]

Richard Hammack, Wilfried Imrich and Sandi Klavžar, “Handbook of Product Graphs”, 2nd edition, CRC Press (2011), DOI: 10.1201/b10959 [sci-hub, @tor]

[godsil-new-1978]

C. D. Godsil and B. D. McKay, “A new graph product and its spectrum”, Bulletin of the Australian Mathematical Society 18, 21-28 (1978), DOI: 10.1017/S0004972700007760 [sci-hub, @tor]

[frucht-corona-1970]

Roberto Frucht and Frank Harary, “On the corona of two graphs”, Aequationes Mathematicae 4, 322-325 (1970), DOI: 10.1007/BF01844162 [sci-hub, @tor]

[barrow-subgraph-1976]

H. G. Barrow and R. M. Burstall, “Subgraph isomorphism, matching relational structures and maximal cliques”, Information Processing Letters 4, 83-84 (1976), DOI: 10.1016/0020-0190(76)90049-1 [sci-hub, @tor]

Examples

>>> g = gt.graph_product(gt.circular_graph(4), gt.complete_graph(3))
>>> print(g.num_vertices(), g.num_edges())
12 24
>>> g = gt.graph_product(gt.circular_graph(4), gt.complete_graph(3),
...                      kind="corona")
>>> print(g.num_vertices(), g.num_edges())
16 28

The cartesian product of a cycle and a path, a cylindrical grid, is drawn as follows:

>>> g = gt.graph_product(gt.circular_graph(10), gt.named_graph("path", 4))
>>> gt.graph_draw(g, pos=gt.sfdp_layout(g),
...               output="graph_product-cartesian.pdf")
<...>
../_images/graph_product-cartesian.png

Cartesian product of the cycle \(C_{10}\) and the path \(P_4\).#