Skip to main content

mostar_index

Function mostar_index 

Source
pub fn mostar_index(graph: &Graph) -> IgraphResult<u64>
Expand description

Compute the Mostar index of a graph.

Mo(G) = Σ_{(u,v)∈E} |n_u(e) - n_v(e)|

A graph is distance-balanced iff Mo = 0.

§Examples

use rust_igraph::{Graph, mostar_index};

// Cycle C_4 is distance-balanced → Mo = 0
let g = Graph::from_edges(&[(0,1),(1,2),(2,3),(3,0)], false, Some(4)).unwrap();
assert_eq!(mostar_index(&g).unwrap(), 0);

// Path 0-1-2: edge(0,1) |1-2|=1, edge(1,2) |2-1|=1 → Mo = 2
let g = Graph::from_edges(&[(0,1),(1,2)], false, Some(3)).unwrap();
assert_eq!(mostar_index(&g).unwrap(), 2);