Skip to main content

is_cluster_graph

Function is_cluster_graph 

Source
pub fn is_cluster_graph(graph: &Graph) -> IgraphResult<bool>
Expand description

Check whether a graph is a cluster graph (disjoint union of cliques).

Every connected component must be a complete graph. This is equivalent to the graph being P3-free.

Returns false for directed graphs (the concept is defined for undirected graphs). Also returns false if the graph has self-loops or parallel edges, since components would not be simple cliques.

An empty graph (0 vertices) is a cluster graph (vacuously). An edgeless graph is a cluster graph (each vertex is K1).

ยงExamples

use rust_igraph::{Graph, is_cluster_graph};

// K3 + K2 + isolated vertex
let mut g = Graph::with_vertices(6);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 0).unwrap();
g.add_edge(3, 4).unwrap();
assert!(is_cluster_graph(&g).unwrap());

// Path P3 is NOT a cluster graph (contains induced P3)
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
assert!(!is_cluster_graph(&g).unwrap());