average_shortest_path_length

average_shortest_path_length#

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

Return the average shortest path length between the pairs of vertices.

Parameters:
gGraph

Graph to be used.

weightsEdgePropertyMap (optional, default: None)

Edge weights (lengths).

Returns:
ellfloat

The average of \(d(u, v)\) over the ordered pairs of distinct vertices such that \(v\) can be reached from \(u\).

See also

wiener_index

Sum of the distances between all pairs

global_efficiency

Average inverse distance

graph_tool.stats.distance_histogram

Distribution of the distances

Notes

This is the average path length of the graph. Unreachable pairs are excluded from the average, so that the graph need not be connected. The distances are computed with a search from every vertex, in parallel, in time \(O(VE)\) without weights.

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.

Examples

>>> g = gt.collection.data["karate"]
>>> print(gt.average_shortest_path_length(g))
2.4081996...