graph_join

Contents

graph_join#

graph_tool.generation.graph_join(g1, g2)[git][source]#

Return the join of two graphs.

Parameters:
g1Graph

First graph.

g2Graph

Second graph, with the same directedness as g1.

Returns:
gGraph

The join of both graphs, where the vertices of g1 come first, in the order of their indices, followed by those of g2.

See also

graph_union

Union of two graphs

complement_graph

Complement of a graph

graph_product

Product of two graphs

generate_cograph

Random cograph

Notes

The join [harary-graph-1969] is the disjoint union of both graphs, with an additional edge between every vertex of g1 and every vertex of g2 (one in each direction, for directed graphs). The complete bipartite graph \(K_{m,n}\) is the join of two empty graphs. The disjoint union is obtained with graph_union() (with vmap=None), to which the additional edges are added. The algorithm runs in time \(O(V_1 + V_2 + E_1 + E_2 + V_1V_2)\).

References

[harary-graph-1969]

Frank Harary, “Graph Theory”, Addison-Wesley, Reading (1969)

Examples

>>> g = gt.graph_join(gt.circular_graph(5), gt.Graph(1, directed=False))
>>> print(g.num_vertices(), g.num_edges())
6 10

The join of a cycle and a path is drawn as follows, with the vertices of the two graphs in different colors:

>>> g = gt.graph_join(gt.circular_graph(6), gt.named_graph("path", 3))
>>> b = g.new_vp("int", vals=[0] * 6 + [1] * 3)
>>> cmap = matplotlib.colors.ListedColormap(
...     ["#9bbedc", "#f28c8e"])
>>> gt.graph_draw(g, pos=gt.sfdp_layout(g), vertex_fill_color=b, vcmap=cmap,
...               output="graph_join-cycle-path.pdf")
<...>
../_images/graph_join-cycle-path.png

Join of the cycle \(C_6\) (blue) and the path \(P_3\) (red).#