graph_product#
- graph_tool.generation.graph_product(g1, g2, kind='cartesian', root=0)[git][source]#
Return the product of two graphs.
- Parameters:
- Returns:
- g
Graph The product graph, where the vertex \((i, j)\), for the vertices \(i\) of
g1and \(j\) ofg2(in the order of their indices), has the index \(iV_2 + j\). For the corona product, the vertices ofg1keep their indices, and the vertex \(j\) of the copy ofg2attached to the vertex \(i\) has the index \(V_1 + iV_2 + j\).
- g
See also
graph_joinJoin of two graphs
graph_compositionRelational composition of two graphs
graph_unionUnion of two graphs
latticeSquare 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'\)
strongthe 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
g2modular\(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
g2for every vertex ofg1, with the edges ofg1between the copies of the root, and the corona product [frucht-corona-1970] isg1with a copy ofg2for 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 bylattice(). 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") <...>
Cartesian product of the cycle \(C_{10}\) and the path \(P_4\).#