pub struct FlowEdge {
pub to: usize,
pub capacity: f64,
pub flow: f64,
pub rev: usize,
}Expand description
A single directed edge in a flow network.
Each edge stores its target node, capacity, current flow, and — crucially — the index of its reverse edge in the adjacency list of the target node. This reverse-index pattern is the standard safe Rust approach to residual graph updates: instead of holding two mutable references simultaneously, we use indices to locate and update both the forward and backward edges.
Fields§
§to: usizeDestination node index.
capacity: f64Maximum capacity of this edge.
flow: f64Current flow along this edge.
rev: usizeIndex of the reverse (residual) edge in adjacency[to].
When we send flow along edge (u→v), we simultaneously increase the
residual capacity of (v→u) by indexing: adjacency[to][rev].
Implementations§
Source§impl FlowEdge
impl FlowEdge
Sourcepub fn residual(&self) -> f64
pub fn residual(&self) -> f64
Returns the residual capacity of this edge: how much more flow can be pushed along it.
For a forward edge this is capacity - flow. For a reverse (residual)
edge this equals the flow already sent on the corresponding forward
edge.
§Examples
use graph_flow::flow_graph::FlowEdge;
let edge = FlowEdge { to: 1, capacity: 10.0, flow: 3.0, rev: 0 };
assert_eq!(edge.residual(), 7.0);