generate_relaxed_caveman#
- graph_tool.generation.generate_relaxed_caveman(l, k, p)[git][source]#
Generate a relaxed caveman graph.
- Parameters:
- l
int Number of cliques (“caves”).
- k
int Size of the cliques.
- p
float Rewiring probability.
- l
- Returns:
- g
Graph The generated graph.
- b
VertexPropertyMap Clique of every vertex.
- g
See also
generate_planted_partitionPlanted partition model
generate_lfrLFR benchmark
named_graphCaveman and connected caveman graphs
Notes
The graph starts as \(l\) disjoint cliques of \(k\) vertices [watts-networks-1999], and every edge \((u, v)\) is visited once and, with probability \(p\), has its endpoint \(v\) moved to a vertex \(x\) chosen uniformly at random, unless \(x = u\) or the edge \((u, x)\) already exists, so that the graph remains simple. The algorithm runs in time \(O(lk^2)\).
References
[watts-networks-1999]Duncan J. Watts, “Networks, dynamics, and the small-world phenomenon”, American Journal of Sociology 105, 493-527 (1999), DOI: 10.1086/210318 [sci-hub, @tor]
Examples
>>> g, b = gt.generate_relaxed_caveman(20, 10, 0.1) >>> print(g.num_edges(), gt.global_clustering(g)[0]) 900 0.73357...
A smaller instance is drawn as follows:
>>> g, b = gt.generate_relaxed_caveman(6, 6, 0.1) >>> cmap = matplotlib.colors.ListedColormap( ... ["#9bbedc", "#f28c8e", "#a6d7a4", "#cba6d1", "#ffbf7f", ... "#ffff99"]) >>> gt.graph_draw(g, pos=gt.sfdp_layout(g), vertex_fill_color=b, vcmap=cmap, ... output="generate_relaxed_caveman-small.pdf") <...>
Relaxed caveman graph with \(l=6\) cliques of \(k=6\) vertices and \(p=0.1\). The vertex colors indicate the initial cliques.#