Skip to main content

decompose

Function decompose 

Source
pub fn decompose(graph: &Graph) -> IgraphResult<Vec<Graph>>
Expand description

Decompose graph into its weakly connected components.

Returns one new Graph per component; the order matches the natural BFS-from-lowest-unvisited-vertex traversal used by igraph_decompose(_, _, IGRAPH_WEAK, _, _) (components.c:620). The component graph’s vertex IDs are remapped to 0..k, where k is the size of the component, in BFS visit order from the seed vertex. Edges within the component (loops and parallel edges included) are preserved with their original direction.

On directed input the decomposition still uses weak connectivity (edge direction is ignored when discovering components, but each component graph is built as directed and retains the original edge orientations). Strong decomposition is a follow-up AWU.

§Examples

use rust_igraph::{Graph, decompose};

// Two components: {0, 1, 2} (triangle) and {3, 4} (edge).
let mut g = Graph::with_vertices(5);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 0).unwrap();
g.add_edge(3, 4).unwrap();

let parts = decompose(&g).unwrap();
assert_eq!(parts.len(), 2);
// Triangle: 3 vertices, 3 edges.
assert_eq!(parts[0].vcount(), 3);
assert_eq!(parts[0].ecount(), 3);
// Edge component: 2 vertices, 1 edge.
assert_eq!(parts[1].vcount(), 2);
assert_eq!(parts[1].ecount(), 1);