graph_join#
- graph_tool.generation.graph_join(g1, g2)[git][source]#
Return the join of two graphs.
- Parameters:
- Returns:
- g
Graph The join of both graphs, where the vertices of
g1come first, in the order of their indices, followed by those ofg2.
- g
See also
graph_unionUnion of two graphs
complement_graphComplement of a graph
graph_productProduct of two graphs
generate_cographRandom cograph
Notes
The join [harary-graph-1969] is the disjoint union of both graphs, with an additional edge between every vertex of
g1and every vertex ofg2(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 withgraph_union()(withvmap=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") <...>
Join of the cycle \(C_6\) (blue) and the path \(P_3\) (red).#