Skip to main content

NetworkSimplex

Struct NetworkSimplex 

Source
pub struct NetworkSimplex<F, C> {
    n: usize,
    edges: Vec<Edge<F, C>>,
    lowers: Vec<F>,
    dss: Vec<F>,
    bucket_size: Option<usize>,
    minor_limit: Option<usize>,
}

Fields§

§n: usize§edges: Vec<Edge<F, C>>§lowers: Vec<F>§dss: Vec<F>§bucket_size: Option<usize>§minor_limit: Option<usize>

Implementations§

Source§

impl<F, C> NetworkSimplex<F, C>
where F: Copy + PartialOrd + Zero + Add<Output = F> + Sub<Output = F> + AddAssign + SubAssign, C: Copy + PartialOrd + Zero + One + Add<Output = C> + Sub<Output = C> + AddAssign + SubAssign + Neg<Output = C> + Mul<Output = C> + From<F>,

Source

pub fn new(n: usize) -> Self

Examples found in repository?
crates/library_checker/src/graph/min_cost_b_flow.rs (line 8)
5pub fn min_cost_b_flow(reader: impl Read, writer: impl Write) {
6    prepare_io!(reader, writer);
7    sc!(n, m, b: [i64; iter n]);
8    let mut ns = NetworkSimplex::<i64, i128>::new(n);
9    for (i, b) in b.enumerate() {
10        ns.add_demand_supply(i, b);
11    }
12    sc!(edges: [(usize, usize, i64, i64, i128); iter m]);
13    for (s, t, l, u, c) in edges {
14        ns.add_edge(s, t, l, u, c);
15    }
16    let sol = ns.solve_minimize();
17    if let Some(sol) = sol {
18        pp!(@lf sol.cost, @it sol.potentials, @it sol.flows);
19    } else {
20        pp!("infeasible");
21    }
22}
Source

pub fn add_demand(&mut self, vid: usize, demand: F)

Add demand

Source

pub fn add_supply(&mut self, vid: usize, supply: F)

Add supply

Source

pub fn add_demand_supply(&mut self, vid: usize, ds: F)

Add demand/supply (positive for supply, negative for demand)

Examples found in repository?
crates/library_checker/src/graph/min_cost_b_flow.rs (line 10)
5pub fn min_cost_b_flow(reader: impl Read, writer: impl Write) {
6    prepare_io!(reader, writer);
7    sc!(n, m, b: [i64; iter n]);
8    let mut ns = NetworkSimplex::<i64, i128>::new(n);
9    for (i, b) in b.enumerate() {
10        ns.add_demand_supply(i, b);
11    }
12    sc!(edges: [(usize, usize, i64, i64, i128); iter m]);
13    for (s, t, l, u, c) in edges {
14        ns.add_edge(s, t, l, u, c);
15    }
16    let sol = ns.solve_minimize();
17    if let Some(sol) = sol {
18        pp!(@lf sol.cost, @it sol.potentials, @it sol.flows);
19    } else {
20        pp!("infeasible");
21    }
22}
Source

pub fn add_edge(&mut self, from: usize, to: usize, lower: F, upper: F, cost: C)

Add edge with lower/upper capacity and cost

Examples found in repository?
crates/library_checker/src/graph/min_cost_b_flow.rs (line 14)
5pub fn min_cost_b_flow(reader: impl Read, writer: impl Write) {
6    prepare_io!(reader, writer);
7    sc!(n, m, b: [i64; iter n]);
8    let mut ns = NetworkSimplex::<i64, i128>::new(n);
9    for (i, b) in b.enumerate() {
10        ns.add_demand_supply(i, b);
11    }
12    sc!(edges: [(usize, usize, i64, i64, i128); iter m]);
13    for (s, t, l, u, c) in edges {
14        ns.add_edge(s, t, l, u, c);
15    }
16    let sol = ns.solve_minimize();
17    if let Some(sol) = sol {
18        pp!(@lf sol.cost, @it sol.potentials, @it sol.flows);
19    } else {
20        pp!("infeasible");
21    }
22}
Source

pub fn set_bucket_size(&mut self, size: usize)

Source

pub fn set_minor_limit(&mut self, limit: usize)

Source

pub fn solve_minimize(self) -> Option<NetworkSimplexSolution<F, C>>

Examples found in repository?
crates/library_checker/src/graph/min_cost_b_flow.rs (line 16)
5pub fn min_cost_b_flow(reader: impl Read, writer: impl Write) {
6    prepare_io!(reader, writer);
7    sc!(n, m, b: [i64; iter n]);
8    let mut ns = NetworkSimplex::<i64, i128>::new(n);
9    for (i, b) in b.enumerate() {
10        ns.add_demand_supply(i, b);
11    }
12    sc!(edges: [(usize, usize, i64, i64, i128); iter m]);
13    for (s, t, l, u, c) in edges {
14        ns.add_edge(s, t, l, u, c);
15    }
16    let sol = ns.solve_minimize();
17    if let Some(sol) = sol {
18        pp!(@lf sol.cost, @it sol.potentials, @it sol.flows);
19    } else {
20        pp!("infeasible");
21    }
22}

Trait Implementations§

Source§

impl<F: Clone, C: Clone> Clone for NetworkSimplex<F, C>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Debug, C: Debug> Debug for NetworkSimplex<F, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<F, C> Freeze for NetworkSimplex<F, C>
where Vec<Edge<F, C>>: Freeze, Vec<F>: Freeze,

§

impl<F, C> RefUnwindSafe for NetworkSimplex<F, C>
where Vec<Edge<F, C>>: RefUnwindSafe, Vec<F>: RefUnwindSafe,

§

impl<F, C> Send for NetworkSimplex<F, C>
where Vec<Edge<F, C>>: Send, Vec<F>: Send,

§

impl<F, C> Sync for NetworkSimplex<F, C>
where Vec<Edge<F, C>>: Sync, Vec<F>: Sync,

§

impl<F, C> Unpin for NetworkSimplex<F, C>
where Vec<Edge<F, C>>: Unpin, Vec<F>: Unpin,

§

impl<F, C> UnsafeUnpin for NetworkSimplex<F, C>
where Vec<Edge<F, C>>: UnsafeUnpin, Vec<F>: UnsafeUnpin,

§

impl<F, C> UnwindSafe for NetworkSimplex<F, C>
where Vec<Edge<F, C>>: UnwindSafe, Vec<F>: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToArrayVecScalar for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.