pub fn girth<G>(graph: G) -> f32where
G: Visitable + NodeIndexable + IntoEdges + IntoNodeIdentifiers + GraphProp,
Expand description
Girth of a simple graph.
Calculate the girth of a simple graph (directed or undirected).
Examples
use graphalgs::metrics::girth;
use petgraph::graph::{ Graph, UnGraph };
// Create the following graph:
// 1 --- 2
// | |
// 0 3
let mut g = UnGraph::new_undirected();
let n0 = g.add_node(());
let n1 = g.add_node(());
let n2 = g.add_node(());
let n3 = g.add_node(());
g.add_edge(n0, n1, ());
g.add_edge(n1, n2, ());
g.add_edge(n2, n3, ());
// The graph is acyclic and its girth is infinite.
assert_eq!(girth(&g), f32::INFINITY);
// Add an edge {3, 0} and create a cycle in the graph.
g.add_edge(n3, n0, ());
assert_eq!(girth(&g), 4.0);