Skip to main content

get_all_shortest_paths_dijkstra

Function get_all_shortest_paths_dijkstra 

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

Find all shortest paths from source to every reachable vertex using Dijkstra’s algorithm with non-negative edge weights.

When weights is None, all edges are treated as having weight 1 (unweighted BFS-like traversal via Dijkstra).

For directed graphs, use get_all_shortest_paths_dijkstra_with_mode to control direction.

§Errors

§Examples

use rust_igraph::{Graph, get_all_shortest_paths_dijkstra};

// Diamond: 0-1, 0-2, 1-3, 2-3. Weights: 1, 1, 1, 1.
// Two shortest paths from 0 to 3: 0→1→3 and 0→2→3, both cost 2.
let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(1, 3).unwrap();
g.add_edge(2, 3).unwrap();
let r = get_all_shortest_paths_dijkstra(&g, 0, &[1.0, 1.0, 1.0, 1.0]).unwrap();
assert_eq!(r.paths[3].len(), 2);
assert_eq!(r.nrgeo[3], 2);