Skip to main content

cohesive_blocks

Function cohesive_blocks 

Source
pub fn cohesive_blocks(graph: &Graph) -> IgraphResult<CohesiveBlocks>
Expand description

Identify the hierarchical cohesive block structure of a graph.

Cohesive blocking (J. Moody and D. R. White, “Structural cohesion and embeddedness: A hierarchical concept of social groups”, American Sociological Review 68(1):103–127, 2003) determines nested subsets of vertices ordered by their structural cohesion (vertex connectivity). The whole graph is the root block; each block’s maximally more-cohesive subsets are found recursively by removing minimum-size separators.

The returned CohesiveBlocks reports, for every block, its vertex set (sorted ascending), its cohesion, its parent in the hierarchy, and the hierarchy itself as a directed tree. Block 0 is always the whole graph with parent = -1.

For undirected, simple graphs only.

§Errors

§Examples

use rust_igraph::{Graph, cohesive_blocks};

// A 4-clique 0-1-2-3 with a pendant path 3-4-5: the clique is a more
// cohesive block (connectivity 3) inside the whole graph.
let mut g = Graph::with_vertices(6);
for (a, b) in [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3), (3, 4), (4, 5)] {
    g.add_edge(a, b).unwrap();
}
let cb = cohesive_blocks(&g).unwrap();
assert_eq!(cb.blocks[0], (0..6).collect::<Vec<_>>());
assert_eq!(cb.parent[0], -1);
// The 4-clique appears as a block with cohesion 3.
assert!(cb.blocks.iter().zip(&cb.cohesion).any(|(b, &c)| b == &[0, 1, 2, 3] && c == 3));