Skip to main content

regularity

Function regularity 

Source
pub fn regularity(graph: &Graph) -> IgraphResult<Option<u32>>
Expand description

Return the regularity degree of the graph, or None if the graph is not regular.

For undirected graphs, returns the common degree. For directed graphs, returns the common out-degree (which equals the common in-degree in a regular directed graph where out-degree == in-degree for all vertices; if out-degrees are all equal and in-degrees are all equal but differ from each other, returns None since such a graph is not considered regular in the standard sense for simple regularity queries).

An empty graph returns None (no vertices, no degree).

ยงExamples

use rust_igraph::{Graph, regularity};

// K3 is 2-regular
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 0).unwrap();
assert_eq!(regularity(&g).unwrap(), Some(2));

// Star graph is not regular
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();
assert_eq!(regularity(&g).unwrap(), None);