Struct FlowGraph

Source
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

Source

pub fn new(vmax: usize, emax_hint: usize) -> Self

Initializes an flow network with vmax vertices and no edges.

Source

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.

Source

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.

Source

pub fn min_cut(&self, dist: &[i64]) -> Vec<usize>

After running maximum flow, use this to recover the dual minimum cut.

Source

pub fn mcf(&self, s: usize, t: usize) -> (i64, i64, Vec<i64>)

Among all s-t maximum flows, finds one with minimum cost, assuming s != t and no negative-cost cycles.

§Panics

Panics if the flow or cost overflow a 64-bit signed integer.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.