pub struct FlowGraph {
pub graph: Graph,
pub cap: Vec<i64>,
pub cost: Vec<i64>,
}
Expand description
Representation of a network flow problem with (optional) costs.
Fields§
§graph: Graph
Owned graph, managed by this FlowGraph object.
cap: Vec<i64>
Edge capacities.
cost: Vec<i64>
Edge cost per unit flow.
Implementations§
Source§impl FlowGraph
impl FlowGraph
Sourcepub fn new(vmax: usize, emax_hint: usize) -> Self
pub fn new(vmax: usize, emax_hint: usize) -> Self
Initializes an flow network with vmax vertices and no edges.
Sourcepub fn add_edge(&mut self, u: usize, v: usize, cap: i64, rcap: i64, cost: i64)
pub fn add_edge(&mut self, u: usize, v: usize, cap: i64, rcap: i64, cost: i64)
Adds an edge with specified directional capacities and cost per unit of flow. If only forward flow is allowed, rcap should be zero.
Sourcepub fn dinic(&self, s: usize, t: usize) -> (i64, Vec<i64>)
pub fn dinic(&self, s: usize, t: usize) -> (i64, Vec<i64>)
Dinic’s algorithm to find the maximum flow from s to t where s != t. Generalizes the Hopcroft-Karp maximum bipartite matching algorithm. V^2E in general, min(V^(2/3),sqrt(E))E when all edges are unit capacity, sqrt(V)E when all vertices are unit capacity as in bipartite graphs.
§Panics
Panics if the maximum flow is 2^63 or larger.
Auto Trait Implementations§
impl Freeze for FlowGraph
impl RefUnwindSafe for FlowGraph
impl Send for FlowGraph
impl Sync for FlowGraph
impl Unpin for FlowGraph
impl UnwindSafe for FlowGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more