Skip to main content

spanner

Function spanner 

Source
pub fn spanner(
    graph: &Graph,
    stretch: f64,
    weights: Option<&[f64]>,
) -> IgraphResult<Vec<u32>>
Expand description

Compute a t-spanner of the graph.

Returns a sorted list of edge IDs whose induced subgraph is a t-spanner of the input graph. Edge directions are ignored.

§Arguments

  • graph — input graph (undirected or directed; directions ignored).
  • stretch — the stretch factor t (must be ≥ 1.0).
  • weights — optional edge weight vector (all positive). None means unit weights.

§Errors

Returns an error if stretch < 1.0, weight vector length doesn’t match edge count, or weights contain non-positive/NaN values.

§Examples

use rust_igraph::{Graph, spanner};

// Path graph: 0-1-2-3. A 1-spanner must include all edges.
let mut g = Graph::new(4, false).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
let sp = spanner(&g, 1.0, None).unwrap();
assert_eq!(sp.len(), 3); // must keep all edges for stretch=1