wiener_index

Contents

wiener_index#

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

Return the Wiener index of the graph.

Parameters:
gGraph

Graph to be used.

weightsEdgePropertyMap (optional, default: None)

Edge weights (lengths).

Returns:
Wfloat

The sum of the distances between all pairs of vertices [wiener-structural-1947] (unordered pairs for undirected graphs, ordered ones for directed graphs), or \(\infty\) if some pair is not connected.

See also

hyper_wiener_index

Wiener index that also includes squared distances

schultz_index

Degree-weighted variant

gutman_index

Degree-product-weighted variant

average_shortest_path_length

Average distance between pairs of vertices

Notes

The Wiener index [wiener-structural-1947] of an undirected graph is

\[W = \sum_{u<v} d(u, v),\]

where the sum runs over the unordered pairs of distinct vertices, and \(d(u, v)\) is the length of a shortest path between \(u\) and \(v\) (the number of its edges, or the sum of their weights). For directed graphs, the sum runs over the ordered pairs \(u \ne v\), and \(d(u, v)\) is the length of a shortest directed path from \(u\) to \(v\). If some vertex cannot be reached from another, \(W = \infty\). The algorithm runs in time \(O(VE)\) without weights, in parallel.

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

[wiener-structural-1947] (1,2)

Harry Wiener, “Structural determination of paraffin boiling points”, Journal of the American Chemical Society 69, 17-20 (1947), DOI: 10.1021/ja01193a005 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["karate"]
>>> print(gt.wiener_index(g))
1351.0