graphopt_layout

graphopt_layout#

graph_tool.draw.graphopt_layout(g, weight=None, pos=None, dim=2, niter=500, charge=0.001, mass=30.0, spring_length=0.0, spring_constant=1.0, max_move=5.0, cutoff=500.0, theta=0.6)[git][source]#

Calculate a force-directed layout of the graph with the GraphOpt model.

Parameters:
gGraph

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

weightEdgePropertyMap (optional, default: None)

Non-negative edge weights, which multiply the spring constant. If not given, every edge has unit weight.

posVertexPropertyMap (optional, default: None)

Initial positions, which are modified in place. If not given, random positions in a square (or cube) of side \(20\sqrt{V}\) are used.

dimint (optional, default: 2)

Number of dimensions.

niterint (optional, default: 500)

Number of iterations.

chargefloat (optional, default: 0.001)

Electric charge \(q\) of every vertex.

massfloat (optional, default: 30.)

Mass \(m\) of every vertex.

spring_lengthfloat (optional, default: 0.)

Rest length \(\ell\) of the springs.

spring_constantfloat (optional, default: 1.)

Spring constant \(k_s\).

max_movefloat (optional, default: 5.)

Largest move of a vertex along every axis in one iteration.

cutofffloat (optional, default: 500.)

Distance beyond which vertices do not repel. If None, there is no cutoff.

thetafloat (optional, default: 0.6)

Opening angle of the Barnes-Hut approximation of the repulsion, in two dimensions. If 0, all pairs are summed exactly.

Returns:
posVertexPropertyMap

The vertex positions.

See also

fruchterman_reingold_layout

Fruchterman-Reingold spring-block layout

arf_layout

ARF spring-block layout

forceatlas2_layout

ForceAtlas2 force-directed layout

sfdp_layout

Multilevel force-directed layout

Notes

In the GraphOpt model of Michael Schmuhl [schmuhl-graphopt], the vertices are electric charges that repel each other according to Coulomb’s law, with the force \(k_e q^2 / d_{ij}^2\) for distances below cutoff, where \(k_e = 8.9875\times 10^9\) is Coulomb’s constant, and the edges are springs that follow Hooke’s law, with the force \(k_s w_{ij}(d_{ij} - \ell)\), shared equally by the two endpoints. In every iteration, every vertex moves by its total force divided by its mass, limited to max_move along every axis. There is no cooling, so that the vertices may keep oscillating around a stable configuration.

In two dimensions, the repulsion is computed with the Barnes-Hut approximation [barnes-hierarchical-1986], so that every iteration takes time \(O(V\log V + E)\); otherwise, or with theta=0, it takes time \(O(V^2 + E)\). The initial positions are drawn with NumPy’s random number generator.

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

[barnes-hierarchical-1986]

Josh Barnes and Piet Hut, “A hierarchical O(N log N) force-calculation algorithm”, Nature 324, 446-449 (1986), DOI: 10.1038/324446a0 [sci-hub, @tor]

Examples

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

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