pub fn degree_centrality<G>(graph: G, direction: Option<Direction>) -> Vec<f64>where
G: NodeIndexable + IntoNodeIdentifiers + IntoNeighbors + IntoNeighborsDirected + NodeCount + GraphProp,
G::NodeId: Eq + Hash,
Expand description
Compute the degree centrality of all nodes in a graph.
For undirected graphs, this calculates the normalized degree for each node. For directed graphs, this calculates the normalized out-degree for each node.
Arguments:
graph
- The graph object to calculate degree centrality for
ยงExample
use rustworkx_core::petgraph::graph::{UnGraph, DiGraph};
use rustworkx_core::centrality::degree_centrality;
// Undirected graph example
let graph = UnGraph::<i32, ()>::from_edges(&[
(0, 1), (1, 2), (2, 3), (3, 0)
]);
let centrality = degree_centrality(&graph, None);
// Directed graph example
let digraph = DiGraph::<i32, ()>::from_edges(&[
(0, 1), (1, 2), (2, 3), (3, 0), (0, 2), (1, 3)
]);
let centrality = degree_centrality(&digraph, None);