lgl_layout

Contents

lgl_layout#

graph_tool.draw.lgl_layout(g, root=None, pos=None, dim=2, K=1.0, cutoff=None, maxit=150, max_step=None, coolexp=1.5)[git][source]#

Calculate a layout of the graph with the Large Graph Layout (LGL) algorithm.

Parameters:
gGraph

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

rootint or Vertex (optional, default: None)

Vertex from which the layout grows. If not given, a random vertex is chosen. The components that do not contain it grow from a random vertex.

posVertexPropertyMap (optional, default: None)

If provided, the positions will be stored in this property map.

dimint (optional, default: 2)

Number of dimensions, either 2 or 3.

Kfloat (optional, default: 1.)

Natural edge length.

cutofffloat (optional, default: None)

Distance beyond which vertices do not repel. If not given, 2 * K is used.

maxitint (optional, default: 150)

Number of iterations after the addition of every shell.

max_stepfloat (optional, default: None)

Largest move of a vertex in the first iteration after the addition of every shell. If not given, K is used.

coolexpfloat (optional, default: 1.5)

Exponent of the cooling schedule.

Returns:
posVertexPropertyMap

The vertex positions.

See also

fruchterman_reingold_layout

Fruchterman-Reingold spring-block layout

drl_layout

DrL force-directed layout

sfdp_layout

Multilevel force-directed layout

Notes

The LGL algorithm [adai-lgl-2004] grows the layout from a root vertex, one breadth-first shell at a time: every vertex of a new shell is placed at distance \(K\) from its parent in the breadth-first search tree, in a random direction that points away from the parent of the parent (a uniformly random direction, reversed if it has a negative projection on the vector from the grandparent to the parent), and the vertices placed so far are then relaxed with maxit iterations of the forces of Fruchterman and Reingold [fruchterman-graph-1991], the attraction \(d^2/K\) between neighbors and the repulsion \(K^2/d\) between vertices closer than cutoff, i.e. the total force

\[\boldsymbol F_v = \sum_{u\,:\,0 < d_{uv} < R}K^2\frac{\boldsymbol x_v - \boldsymbol x_u}{d_{uv}^2} - \sum_{u\in\partial v}\frac{d_{uv} (\boldsymbol x_v - \boldsymbol x_u)}{K},\]

where \(d_{uv} = |\boldsymbol x_v - \boldsymbol x_u|\), \(R\) is cutoff and both sums run over the placed vertices. In iteration \(i = 0, \dots, n - 1\), all placed vertices move at once by \(\boldsymbol F_v\min(1, t_i/|\boldsymbol F_v|)\), i.e. by at most the temperature \(t_i = t_0(1 - i/n)^c\), where \(t_0\) is max_step, \(n\) is maxit, and \(c\) is coolexp. The root starts at the origin. The repulsion is computed with a grid of cells of side cutoff, so that only vertices in neighboring cells interact. Every iteration takes time \(O(V + E)\) for vertices that are spread evenly, and the whole layout \(O(Dn(V + E))\), where \(D\) is the eccentricity of the root. The connected components are laid out separately and placed side by side. The root vertices are chosen with NumPy’s random number generator, and the directions with graph-tool’s.

Parallel implementation.

If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.

References

[adai-lgl-2004]

Alex T. Adai, Shailesh V. Date, Shannon Wieland and Edward M. Marcotte, “LGL: Creating a map of protein function with an algorithm for visualizing very large biological networks”, Journal of Molecular Biology 340, 179-190 (2004), DOI: 10.1016/j.jmb.2004.04.047 [sci-hub, @tor]

[fruchterman-graph-1991]

Thomas M. J. Fruchterman and Edward M. Reingold, “Graph drawing by force-directed placement”, Software: Practice and Experience 21, 1129-1164 (1991), DOI: 10.1002/spe.4380211102 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["power"]
>>> pos = gt.lgl_layout(g)
>>> gt.graph_draw(g, pos=pos, output="power-lgl.png")
<...>
../_images/power-lgl.png

LGL layout of the power grid of the western United States.#