pub fn is_perfect(graph: &Graph) -> IgraphResult<bool>Expand description
Returns true when graph is a perfect graph.
The graph must be undirected and simple; otherwise an
IgraphError::InvalidArgument is returned, matching upstream’s
IGRAPH_EINVAL.
Time complexity: worst case exponential (the odd-hole search runs induced subgraph isomorphism), but the bipartite / chordal / girth fast paths resolve most inputs cheaply.
§Examples
use rust_igraph::{Graph, is_perfect};
// The 5-cycle C5 is the smallest imperfect graph (it is its own odd hole).
let mut c5 = Graph::new(5, false)?;
for (u, v) in [(0, 1), (1, 2), (2, 3), (3, 4), (4, 0)] {
c5.add_edge(u, v)?;
}
assert!(!is_perfect(&c5)?);
// A tree (here a path) is bipartite, hence perfect.
let mut path = Graph::new(4, false)?;
for (u, v) in [(0, 1), (1, 2), (2, 3)] {
path.add_edge(u, v)?;
}
assert!(is_perfect(&path)?);