Skip to main content

widest_paths_to

Function widest_paths_to 

Source
pub fn widest_paths_to(
    graph: &Graph,
    from: VertexId,
    targets: &[VertexId],
    weights: &[f64],
) -> IgraphResult<Vec<WidestPathResult>>
Expand description

Widest paths from a single source to multiple targets. Returns one WidestPathResult per element of targets, in the same order; None means the target is unreachable from from.

Self-target entries (from == targets[i]) return the trivial Some((vec![from], vec![])). Repeating the same target id in targets is allowed โ€” both entries get the same path.

Same weight semantics as widest_path_widths: NaN rejected, -f64::INFINITY edges ignored, negative finite weights act as small bottlenecks.

Counterpart of igraph_get_widest_paths(_, vertices, edges, from, to, weights, IGRAPH_OUT, parents=NULL, inbound_edges=NULL) from references/igraph/src/paths/widest_paths.c:102.

ยงExamples

use rust_igraph::{Graph, widest_paths_to};

// Triangle 0-1-2 weights (1, 4, 2). From 0, paths to 1 and 2.
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();  // edge 0, width 1
g.add_edge(0, 2).unwrap();  // edge 1, width 4
g.add_edge(1, 2).unwrap();  // edge 2, width 2
let paths = widest_paths_to(&g, 0, &[1, 2], &[1.0, 4.0, 2.0]).unwrap();
// 0โ†’1 goes via the shortcut at 2 (bottleneck 2 beats direct 1)
assert_eq!(paths[0].as_ref().unwrap().0, vec![0, 2, 1]);
// 0โ†’2 takes the direct edge (width 4 is widest)
assert_eq!(paths[1].as_ref().unwrap().0, vec![0, 2]);