Expand description

Graph density - measures how dense or sparse a graph is.

It is defined as the ratio of the number of edges in the graph to the total number of possible edges. A dense graph has a high edge-to-vertex ratio, while a sparse graph has a low edge-to-vertex ratio.

For example in social network analysis, a dense graph may indicate a highly interconnected community, while a sparse graph may indicate more isolated individuals.

Examples

use raphtory::algorithms::directed_graph_density::directed_graph_density;
use raphtory::db::graph::Graph;
use raphtory::db::view_api::*;

let g = Graph::new(1);
let windowed_graph = g.window(0, 7);
let vs = vec![
    (1, 1, 2),
    (2, 1, 3),
    (3, 2, 1),
    (4, 3, 2),
    (5, 1, 4),
    (6, 4, 5),
];

for (t, src, dst) in &vs {
g.add_edge(*t, *src, *dst, &vec![], None);
}

println!("graph density: {:?}", directed_graph_density(&windowed_graph));

Functions