Skip to main content

reverse_residual_graph

Function reverse_residual_graph 

Source
pub fn reverse_residual_graph(
    graph: &Graph,
    capacity: Option<&[f64]>,
    flow: &[f64],
) -> IgraphResult<Graph>
Expand description

Compute the reverse-residual graph given capacity and flow vectors.

For each edge e in the original graph:

  • If flow[e] > 0: adds forward edge (from, to)
  • If flow[e] < capacity[e]: adds backward edge (to, from)

If capacity is None, all edges are assumed to have capacity 1.0.

§Errors

Returns an error if vector lengths don’t match the edge count.

§Examples

use rust_igraph::{Graph, reverse_residual_graph};

let mut g = Graph::new(3, true).unwrap();
g.add_edge(0, 1).unwrap(); // edge 0
g.add_edge(1, 2).unwrap(); // edge 1
let capacity = vec![10.0, 5.0];
let flow = vec![7.0, 5.0];
let result = reverse_residual_graph(&g, Some(&capacity), &flow).unwrap();
// Edge 0: flow>0 → forward (0,1); residual>0 → backward (1,0) = 2 edges
// Edge 1: flow>0 → forward (1,2); saturated → no backward = 1 edge
assert_eq!(result.vcount(), 3);
assert_eq!(result.ecount(), 3);