Skip to main content

dijkstra_distances_cutoff

Function dijkstra_distances_cutoff 

Source
pub fn dijkstra_distances_cutoff(
    graph: &Graph,
    source: VertexId,
    weights: &[f64],
    cutoff: Option<f64>,
) -> IgraphResult<Vec<Option<f64>>>
Expand description

Single-source Dijkstra distances with an optional cutoff. When cutoff = Some(c), vertices whose shortest-path distance exceeds c are returned as None (unreachable-within-cutoff); the search stops relaxing edges out of any vertex whose mindist > c.

cutoff = None is identical to dijkstra_distances.

Counterpart of igraph_distances_dijkstra_cutoff(..., IGRAPH_OUT, cutoff) for a single source. Upstream uses cutoff < 0 to disable; this Rust port uses None.

ยงExamples

use rust_igraph::{Graph, dijkstra_distances_cutoff};

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
let d = dijkstra_distances_cutoff(&g, 0, &[1.0, 10.0], Some(5.0)).unwrap();
assert!(d[0].is_some()); // distance 0
assert!(d[1].is_some()); // distance 1
assert!(d[2].is_none()); // distance 11, beyond cutoff