Skip to main content

dijkstra_path_to

Function dijkstra_path_to 

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

Reconstruct a single source-to-target path returning vertex and edge sequences. Ok(None) if target is unreachable; the source vertex appears as the first element when reachable.

Counterpart of igraph_get_shortest_path_dijkstra.

§Examples

use rust_igraph::{Graph, dijkstra_path_to};

let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();   // edge 0, weight 1
g.add_edge(1, 2).unwrap();   // edge 1, weight 1
g.add_edge(2, 3).unwrap();   // edge 2, weight 1
g.add_edge(0, 3).unwrap();   // edge 3, weight 10 — heavier
let (vs, es) = dijkstra_path_to(&g, 0, 3, &[1.0, 1.0, 1.0, 10.0])
    .unwrap()
    .expect("target reachable");
assert_eq!(vs, vec![0, 1, 2, 3]);
assert_eq!(es, vec![0, 1, 2]);