Skip to main content

diameter

Function diameter 

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

Diameter of graph — the maximum vertex eccentricity. None for a graph with no vertices.

Counterpart of igraph_diameter(_, NULL_weights, _, NULL, NULL, NULL, NULL, _, /*unconn=*/true).

§Examples

use rust_igraph::{Graph, diameter, radius, eccentricity};

// Path 0-1-2-3-4: longest geodesic is 0→4 of length 4.
let mut g = Graph::with_vertices(5);
for i in 0..4 { g.add_edge(i, i + 1).unwrap(); }
assert_eq!(diameter(&g).unwrap(), Some(4));
// Centre of the path (vertex 2) has eccentricity 2 → radius 2.
assert_eq!(radius(&g).unwrap(), Some(2));
assert_eq!(eccentricity(&g).unwrap(), vec![4, 3, 2, 3, 4]);