generate_cograph#
- graph_tool.generation.generate_cograph(n)[git][source]#
Generate a random cograph with \(2^n\) vertices.
- Parameters:
- n
int Number of doubling steps.
- n
- Returns:
- g
Graph The generated undirected cograph.
- g
See also
graph_joinJoin of two graphs
graph_unionUnion of two graphs
complement_graphComplement of a graph
Notes
Starting from a single vertex, the graph is doubled \(n\) times; at every step, the copy is either joined to the original (all edges between them are added) or not, with equal probabilities. The result is a cograph [corneil-complement-1981], since every step is a disjoint union or a join. Two vertices \(u\) and \(v\) are adjacent if and only if the step corresponding to the highest bit in which \(u\) and \(v\) differ was a join, which allows the edges to be generated directly, in time \(O(2^n + E)\).
References
[corneil-complement-1981]D. G. Corneil, H. Lerchs and L. Stewart Burlingham, “Complement reducible graphs”, Discrete Applied Mathematics 3, 163-174 (1981), DOI: 10.1016/0166-218X(81)90013-5 [sci-hub, @tor]
Examples
>>> g = gt.generate_cograph(8) >>> print(g.num_vertices(), g.num_edges()) 256 17664
A smaller instance is drawn as follows:
>>> g = gt.generate_cograph(4) >>> gt.graph_draw(g, pos=gt.sfdp_layout(g), ... output="generate_cograph-small.pdf") <...>
Random cograph with \(2^4\) vertices.#