Skip to main content

dijkstra_paths

Function dijkstra_paths 

Source
pub fn dijkstra_paths(
    graph: &Graph,
    source: VertexId,
    weights: &[f64],
) -> IgraphResult<DijkstraPaths>
Expand description

Single-source Dijkstra returning distances + parents + inbound edges over every vertex.

Counterpart of igraph_get_shortest_paths_dijkstra(..., to=igraph_vss_all(), IGRAPH_OUT, parents, inbound_edges).

§Examples

use rust_igraph::{Graph, dijkstra_paths};

// Triangle 0-1-2 with weights 1, 4, 2 → SPT from 0: parent[1]=0,
// parent[2]=1 (via the shortcut), inbound[1]=edge0, inbound[2]=edge2.
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(1, 2).unwrap();
let p = dijkstra_paths(&g, 0, &[1.0, 4.0, 2.0]).unwrap();
assert_eq!(p.distances, vec![Some(0.0), Some(1.0), Some(3.0)]);
assert_eq!(p.parents,   vec![None,      Some(0),   Some(1)]);
assert_eq!(p.inbound_edges, vec![None, Some(0), Some(2)]);