Skip to main content

dijkstra_all_shortest_paths

Function dijkstra_all_shortest_paths 

Source
pub fn dijkstra_all_shortest_paths(
    graph: &Graph,
    source: VertexId,
    weights: &[f64],
    mode: DijkstraMode,
) -> IgraphResult<DijkstraAllPaths>
Expand description

All shortest weighted paths from source to every vertex, preserving every tie. Counterpart of igraph_get_all_shortest_paths_dijkstra(_, _, _, _, source, vss_all(), weights, mode).

Mirrors upstream’s tie handling: equal-cost alternative paths are recorded only when the connecting edge has non-zero weight (avoids infinite loops via 0-weight edges in undirected graphs). On undirected graphs every mode behaves identically.

§Examples

use rust_igraph::{Graph, dijkstra_all_shortest_paths, DijkstraMode};

// Diamond 0-1-3 and 0-2-3, all weight 1: two distinct shortest
// paths to vertex 3.
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 = dijkstra_all_shortest_paths(&g, 0, &[1.0, 1.0, 1.0, 1.0], DijkstraMode::Out)
    .unwrap();
assert_eq!(r.nrgeo, vec![1, 1, 1, 2]);
assert_eq!(r.vertex_paths[3].len(), 2); // {0,1,3} and {0,2,3}