generate_navigable_small_world#
- graph_tool.generation.generate_navigable_small_world(n, p=1, q=1, r=2, dim=2)[git][source]#
Generate a navigable small-world graph with Kleinberg’s model.
- Parameters:
- n
int Length of the side of the lattice.
- p
int(optional, default:1) Range of the local connections, in lattice distance.
- q
int(optional, default:1) Number of long-range connections of every vertex.
- r
float(optional, default:2) Exponent of the distance in the long-range connection probabilities.
- dim
int(optional, default:2) Dimension of the lattice.
- n
- Returns:
- g
Graph The generated directed graph.
- pos
VertexPropertyMap Lattice coordinates of the vertices.
- g
See also
generate_watts_strogatzWatts-Strogatz model
latticeSquare lattice
Notes
In Kleinberg’s model [kleinberg-small-world-2000], the vertices are the points of an \(n^d\) square lattice (without periodic boundaries), where \(d\) is
dim; every vertex \(u\) has directed edges to all vertices \(v \ne u\) within lattice (Manhattan) distance \(\ell_{uv} \le p\), and \(q\) further edges to targets \(v \ne u\) chosen independently among all vertices with probability\[P(v | u) = \frac{\ell_{uv}^{-r}}{\sum_{w\ne u}\ell_{uw}^{-r}},\]where repeated targets, and targets that are already local neighbors, are merged into a single edge, so that the graph has no parallel edges or self-loops. For \(r = d\), greedy routing finds paths of polylogarithmic length. The algorithm runs in time \(O(N^2)\), for \(N = n^d\).
References
[kleinberg-small-world-2000]Jon Kleinberg, “The small-world phenomenon: An algorithmic perspective”, in Proceedings of the Thirty-Second Annual ACM Symposium on Theory of Computing (STOC 2000), 163-170 (2000), DOI: 10.1145/335305.335325 [sci-hub, @tor]
Examples
>>> g, pos = gt.generate_navigable_small_world(30) >>> print(g.num_vertices(), g.num_edges()) 900 4105
A smaller instance is drawn as follows, with the vertices at their lattice positions:
>>> g, pos = gt.generate_navigable_small_world(8) >>> gt.graph_draw(g, pos=pos, ... output="generate_navigable_small_world-small.pdf") <...>
Navigable small-world graph on a \(8\times 8\) lattice, with \(p=q=1\) and \(r=2\).#