Skip to main content

is_wheel

Function is_wheel 

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

Check whether a graph is a wheel graph.

A wheel graph has n ≥ 4 vertices: one hub of degree n-1 connected to all others, and the remaining n-1 vertices form a cycle (each has degree 3).

Returns false for directed graphs, non-simple graphs, and graphs with fewer than 4 vertices.

§Examples

use rust_igraph::{Graph, is_wheel};

// W4: hub 0 + triangle 1-2-3
let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(0, 3).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
g.add_edge(3, 1).unwrap();
assert!(is_wheel(&g).unwrap());

// K4 is NOT a wheel (all vertices have degree 3, no unique hub)
// Actually K4 IS W4 — every vertex can serve as the hub.
// But a cycle C4 is NOT a wheel:
let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
g.add_edge(3, 0).unwrap();
assert!(!is_wheel(&g).unwrap());