rustworkx.unweighted_average_shortest_path_length#
- unweighted_average_shortest_path_length(graph, parallel_threshold=300, disconnected=False)[source]#
Return the average shortest path length with unweighted edges.
The average shortest path length is calculated as
\[a =\sum_{s,t \in V, s \ne t} \frac{d(s, t)}{n(n-1)}\]where \(V\) is the set of nodes in
graph
, \(d(s, t)\) is the shortest path length from \(s\) to \(t\), and \(n\) is the number of nodes ingraph
. Ifdisconnected
is set toTrue
, the average will be taken only between connected nodes.This function is also multithreaded and will run in parallel if the number of nodes in the graph is above the value of
parallel_threshold
(it defaults to 300). If the function will be running in parallel the env varRAYON_NUM_THREADS
can be used to adjust how many threads will be used. By default it will use all available CPUs if the environment variable is not specified.- Parameters:
graph – The graph to compute the average shortest path length for, can be either a
PyGraph
orPyDiGraph
.parallel_threshold (int) – The number of nodes to calculate the the distance matrix in parallel at. It defaults to 300, but this can be tuned to any number of nodes.
as_undirected (bool) – If set to
True
the input directed graph will be treated as if each edge was bidirectional/undirected while finding the shortest paths. Default:False
.disconnected (bool) – If set to
True
only connected vertex pairs will be included in the calculation. IfFalse
, infinity is returned for disconnected graphs. Default:False
.
- Returns:
The average shortest path length. If no vertex pairs can be included in the calculation this will return NaN.
- Return type:
float