center

Contents

center#

graph_tool.structure.center(g, weights=None)[git][source]#

Return the center of the graph, i.e. the vertices of minimum eccentricity.

Parameters:
gGraph

Graph to be used.

weightsEdgePropertyMap (optional, default: None)

Edge weights (lengths).

Returns:
centernumpy.ndarray

The vertices whose eccentricity equals the radius.

See also

periphery

Vertices of maximum eccentricity

barycenter

Vertices of minimum total distance

eccentricity

Eccentricity of every vertex

radius

Minimum eccentricity

Notes

The center is the set

\[\{v : \epsilon(v) = \min_u \epsilon(u)\}, \qquad \epsilon(v) = \max_{u} d(v, u),\]

where \(\epsilon(v)\) is the eccentricity of \(v\), and \(d(v, u)\) the length of a shortest path from \(v\) to \(u\) (directed, for directed graphs), with the maximum taken only over the vertices reachable from \(v\). The eccentricities are computed with eccentricity(), so that for disconnected graphs the center is taken over all components (with isolated vertices having eccentricity zero). Eccentricities that differ by a relative amount of at most \(10^{-12}\) are considered equal.

Examples

>>> g = gt.collection.data["karate"]
>>> print(gt.center(g))
[ 0  1  2  3  8 13 19 31]

The center can be highlighted in a drawing of the network:

>>> vcolor = g.new_vp("string", val="#cccccc")
>>> for v in gt.center(g):
...     vcolor[v] = "#f28c8e"
>>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=vcolor,
...               edge_color="#999999", output="center-karate.pdf")
<...>
../_images/center-karate.png

Center of Zachary’s karate club network, with its vertices shown in red.#