pub fn betweenness_centrality<G>(
    graph: G,
    include_endpoints: bool,
    normalized: bool,
    parallel_threshold: usize
) -> Vec<Option<f64>>where
    G: NodeIndexable + IntoNodeIdentifiers + IntoNeighborsDirected + NodeCount + GraphProp + GraphBase + Sync,
    <G as GraphBase>::NodeId: Eq + Hash + Send,
Expand description

Compute the betweenness centrality of all nodes in a graph.

The algorithm used in this function is based on:

Ulrik Brandes, A Faster Algorithm for Betweenness Centrality. Journal of Mathematical Sociology 25(2):163-177, 2001.

This function is multithreaded and will run in parallel if the number of nodes in the graph is above the value of parallel_threshold. If the function will be running in parallel the env var RAYON_NUM_THREADS can be used to adjust how many threads will be used.

Arguments:

  • graph - The graph object to run the algorithm on
  • include_endpoints - Whether to include the endpoints of paths in the path lengths used to compute the betweenness
  • normalized - Whether to normalize the betweenness scores by the number of distinct paths between all pairs of nodes
  • parallel_threshold - The number of nodes to calculate the betweenness centrality in parallel at, if the number of nodes in graph is less than this value it will run in a single thread. A good default to use here if you’re not sure is 50 as that was found to be roughly the number of nodes where parallelism improves performance

Example

use rustworkx_core::petgraph;
use rustworkx_core::centrality::betweenness_centrality;

let g = petgraph::graph::UnGraph::<i32, ()>::from_edges(&[
    (0, 4), (1, 2), (2, 3), (3, 4), (1, 4)
]);
// Calculate the betweenness centrality
let output = betweenness_centrality(&g, true, true, 200);
assert_eq!(
    vec![Some(0.4), Some(0.5), Some(0.45), Some(0.5), Some(0.75)],
    output
);

See Also

edge_betweenness_centrality