generate_navigable_small_world

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:
nint

Length of the side of the lattice.

pint (optional, default: 1)

Range of the local connections, in lattice distance.

qint (optional, default: 1)

Number of long-range connections of every vertex.

rfloat (optional, default: 2)

Exponent of the distance in the long-range connection probabilities.

dimint (optional, default: 2)

Dimension of the lattice.

Returns:
gGraph

The generated directed graph.

posVertexPropertyMap

Lattice coordinates of the vertices.

See also

generate_watts_strogatz

Watts-Strogatz model

lattice

Square 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")
<...>
../_images/generate_navigable_small_world-small.png

Navigable small-world graph on a \(8\times 8\) lattice, with \(p=q=1\) and \(r=2\).#