ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
MaxFlow.h

The maximum flow of section 15.2 in a network \( G = ( V , E , s , t , c ) \), with integer capacities, and the minimum cut. More...

Files

file  ADS/graph/MaxFlow.h
 The maximum flow of section 15.2 in a network \( G = ( V , E , s , t , c ) \), with integer capacities, and the minimum cut.

Classes

class  ADS::FlowNetwork
 a network of flow with integer capacities More...
struct  ADS::BoundedEdge
 an edge \( ( u , v ) \) with lower and upper bounds on its flow More...

Enumerations

enum class  ADS::Augment { ADS::Augment::FORD_FULKERSON , ADS::Augment::EDMONDS_KARP , ADS::Augment::DINIC , ADS::Augment::PUSH_RELABEL }
 the way of increasing the flow More...

Functions

bool ADS::feasibleCirculation (int n, const std::vector< BoundedEdge > &E, std::vector< long long > *flows=nullptr)
 whether the edges admit a circulation, a flow conserved at every node with \( \mathit{low} \le f( e ) \le \mathit{high} \); then the flows in *flows, if given

Detailed description

The maximum flow of section 15.2 in a network \( G = ( V , E , s , t , c ) \), with integer capacities, and the minimum cut.

The definitions, the invariants and the costs of the area are in Theory of graphs.

Enumeration type documentation

◆ Augment

enum class ADS::Augment
strong

the way of increasing the flow

Enumerator
FORD_FULKERSON 

any augmenting path, by a visit in depth

EDMONDS_KARP 

a shortest augmenting path, by a visit in breadth

DINIC 

a blocking flow on the levels of a visit in breadth

PUSH_RELABEL 

the pushes and the relabelings of a preflow

Function documentation

◆ feasibleCirculation()

bool ADS::feasibleCirculation ( int n,
const std::vector< BoundedEdge > & E,
std::vector< long long > * flows = nullptr )
inline

whether the edges admit a circulation, a flow conserved at every node with \( \mathit{low} \le f( e ) \le \mathit{high} \); then the flows in *flows, if given

In pseudocode (the reduction to a maximum flow): sending the lower bounds first leaves each node an excess, positive or negative, which a flow from a new source s to a new sink t must balance within the capacities high - low.

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{feasibleCirculation}( n , E ) \cr 2 & \quad N \gets \text{a network of the nodes } 0 , \ldots , n + 1;\ s \gets n;\ t \gets n + 1 \cr 3 & \quad \textbf{foreach}\ ( u , v , \mathit{low} , \mathit{high} ) \in E \ \textbf{do} \cr 4 & \qquad \textbf{if}\ \mathit{low} > \mathit{high}\ \textbf{then return false} \cr 5 & \qquad \text{add } ( u , v ) \text{ to } N \text{ with capacity } \mathit{high} - \mathit{low} \cr 6 & \qquad e[ v ] \gets e[ v ] + \mathit{low};\ e[ u ] \gets e[ u ] - \mathit{low} \cr 7 & \quad \textbf{foreach}\ v\ \textbf{with}\ e[ v ] > 0\ \textbf{do} \ \text{add } ( s , v ) \text{ with capacity } e[ v ] \cr 8 & \quad \textbf{foreach}\ v\ \textbf{with}\ e[ v ] < 0\ \textbf{do} \ \text{add } ( v , t ) \text{ with capacity } -e[ v ] \cr 9 & \quad \textbf{return}\ N.\mathrm{maxFlow}( s , t ) = \sum_{e[ v ] > 0} e[ v ]\quad \triangleright\ \text{the flow of each edge is then } \mathit{low} + f \end{array}} \]

Precondition
\( n \ge 0 \), the ends of the edges in \( [ 0 , n ) \)
Postcondition
the flows given are within the bounds and conserved (audit)