gem_layout

Contents

gem_layout#

graph_tool.draw.gem_layout(g, pos=None, K=1.0, max_iter=None, t_init=None, t_max=None, t_min=None, gravity=0.0625)[git][source]#

Calculate a layout of the graph with the GEM algorithm.

Parameters:
gGraph

Graph to be used (the edge directions are ignored).

posVertexPropertyMap (optional, default: None)

Initial positions. If not provided, they are drawn uniformly in a square of side \(K\sqrt{V}\), and the new positions are stored in a new property map.

Kfloat (optional, default: 1.)

Desired edge length.

max_iterint (optional, default: None)

Maximum number of rounds, in each of which every vertex is moved once. If not given, max(100, 4 * V) is used.

t_initfloat (optional, default: None)

Initial temperature (i.e. step length) of every vertex. If not given, K * sqrt(V) / 4 is used.

t_maxfloat (optional, default: None)

Largest temperature of a vertex. If not given, t_init is used.

t_minfloat (optional, default: None)

The algorithm stops when the mean temperature falls below this value. If not given, K / 100 is used.

gravityfloat (optional, default: 1/16.)

Strength of the attraction to the barycenter.

Returns:
posVertexPropertyMap

Vector vertex property map with the \((x, y)\) coordinates.

See also

fruchterman_reingold_layout

Fruchterman-Reingold spring-block layout

davidson_harel_layout

Layout by simulated annealing

sfdp_layout

Multilevel force-directed layout

Notes

In the GEM (“graph embedder”) force-directed algorithm of Frick, Ludwig, and Mehldau [frick-fast-1995], the vertices are moved one at a time, in random order. The impulse of vertex \(v\) is

\[\boldsymbol{p}_v = \gamma\Phi_v(\boldsymbol{c} - \boldsymbol{x}_v) + \boldsymbol{\eta} + \sum_{u\ne v} K^2\frac{\boldsymbol{x}_v - \boldsymbol{x}_u}{|\boldsymbol{x}_v - \boldsymbol{x}_u|^2} - \sum_{u\in\partial v}\frac{|\boldsymbol{x}_v - \boldsymbol{x}_u|^2(\boldsymbol{x}_v-\boldsymbol{x}_u)}{K^2\Phi_v},\]

where \(\boldsymbol{c}\) is the barycenter, \(\gamma\) the gravity, \(\Phi_v = 1 + k_v/2\) the “mass” of the vertex, \(\boldsymbol{\eta}\) a random disturbance uniform in \([-K/4, K/4]^2\), and \(\partial v\) the neighbors of \(v\), with \(k_v\) the number of its edges (self-loops are ignored). The vertex is moved along its impulse by its own temperature \(t_v\), \(\boldsymbol x_v \leftarrow \boldsymbol x_v + t_v\boldsymbol p_v/|\boldsymbol p_v|\), and \(t_v\), initially t_init, is then updated from the angle \(\beta\) between the current and the previous move: it is multiplied by \(1 + \sigma_o\cos\beta\), with \(\sigma_o=1/3\), when \(|\cos\beta|\ge\cos(\alpha_o/2)\), with \(\alpha_o=\pi/2\) (accelerating straight moves and damping oscillations), and multiplied by \(1 - \min(|s_v|, 1)\), where the “skew gauge” \(s_v\) accumulates \(\sigma_r\operatorname{sign}(\sin\beta)\), with \(\sigma_r=1/2V\), whenever \(|\sin\beta|\ge\sin(\pi/2 + \alpha_r/2)\), with \(\alpha_r=\pi/3\) (damping rotations), and finally capped at t_max. The algorithm stops when the mean temperature falls below t_min, or after max_iter rounds. Every round takes time \(O(V^2 + E)\), so that the algorithm is suited only for small graphs.

References

[frick-fast-1995]

Arne Frick, Andreas Ludwig and Heiko Mehldau, “A fast adaptive layout algorithm for undirected graphs”, Graph Drawing (GD ‘94), Lecture Notes in Computer Science 894, 388-403 (1995), DOI: 10.1007/3-540-58950-3_393 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["football"]
>>> pos = gt.gem_layout(g)
>>> gt.graph_draw(g, pos=pos, vertex_fill_color=g.vp.value,
...               output="football-gem.pdf")
<...>
../_images/football-gem.png

GEM layout of the network of American college football games, with the vertex colors given by the conferences.#