pub struct DinicMaxFlow { /* private fields */ }Expand description
Dinic’s maximum flow algorithm.
Builds a level graph with BFS and finds blocking flows with DFS. Time complexity: O(V² E) for general graphs, O(E √V) for unit-capacity.
§Example
use scirs2_graph::flow::max_flow::DinicMaxFlow;
let mut d = DinicMaxFlow::new(4);
d.add_edge(0, 1, 10);
d.add_edge(0, 2, 10);
d.add_edge(1, 3, 10);
d.add_edge(2, 3, 10);
d.add_edge(1, 2, 1);
let flow = d.max_flow(0, 3);
assert_eq!(flow, 20);Implementations§
Source§impl DinicMaxFlow
impl DinicMaxFlow
Sourcepub fn add_edge(&mut self, u: usize, v: usize, cap: i64)
pub fn add_edge(&mut self, u: usize, v: usize, cap: i64)
Add a directed edge from u to v with capacity cap.
A reverse edge with capacity 0 is automatically added.
Trait Implementations§
Source§impl Clone for DinicMaxFlow
impl Clone for DinicMaxFlow
Source§fn clone(&self) -> DinicMaxFlow
fn clone(&self) -> DinicMaxFlow
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for DinicMaxFlow
impl RefUnwindSafe for DinicMaxFlow
impl Send for DinicMaxFlow
impl Sync for DinicMaxFlow
impl Unpin for DinicMaxFlow
impl UnsafeUnpin for DinicMaxFlow
impl UnwindSafe for DinicMaxFlow
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more