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

Two uses of the maximum flow of section 15.2. More...

Files

file  ADS/graph/FlowApplications.h
 Two uses of the maximum flow of section 15.2 [see MaxFlow.h]:

Enumerations

enum class  ADS::CapacityDecrease { ADS::CapacityDecrease::SLACK , ADS::CapacityDecrease::CYCLE , ADS::CapacityDecrease::PATH }
 what decreaseCapacity() did More...

Functions

template<Graph G>
std::vector< std::vector< int > > ADS::edgeDisjointPaths (const G &g, int s, int t, long long k=std::numeric_limits< long long >::max())
 at most \( k \) paths from \( s \) to \( t \) with no edge in common, as many as there can be, each as its nodes from \( s \) to \( t \)
template<class T>
CapacityDecrease ADS::decreaseCapacity (std::vector< std::vector< T > > &c, std::vector< std::vector< T > > &f, int s, int t, int u, int v)
 \( c( u , v ) \) decreases by 1, and the maximum flow \( f \) from \( s \) to \( t \) within \( c \) becomes a maximum flow within the new \( c \)

Detailed description

Two uses of the maximum flow of section 15.2.

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

Enumeration type documentation

◆ CapacityDecrease

enum class ADS::CapacityDecrease
strong

what decreaseCapacity() did

Enumerator
SLACK 

the edge was not saturated, nothing changed

CYCLE 

one unit of a cycle of flow canceled, the value kept

PATH 

one unit of a path canceled, then one augmenting path

Function documentation

◆ decreaseCapacity()

template<class T>
CapacityDecrease ADS::decreaseCapacity ( std::vector< std::vector< T > > & c,
std::vector< std::vector< T > > & f,
int s,
int t,
int u,
int v )

\( c( u , v ) \) decreases by 1, and the maximum flow \( f \) from \( s \) to \( t \) within \( c \) becomes a maximum flow within the new \( c \)

In pseudocode, f( y , x ) = -f( x , y ) on the matrices:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{decreaseCapacity}( c , f , s , t , u , v ) \cr 2 & \quad c( u , v ) \gets c( u , v ) - 1 \cr 3 & \quad \textbf{if}\ f( u , v ) \le c( u , v )\ \textbf{then return} \ \text{SLACK} \cr 4 & \quad f( u , v ) \gets f( u , v ) - 1;\ f( v , u ) \gets f( v , u ) + 1\quad \triangleright\ \text{an excess at } u \text{ , a deficit at } v \cr 5 & \quad \textbf{if}\ \text{a path } Q \text{ of positive flow goes } \text{from } v \text{ to } u\ \textbf{then} \cr 6 & \qquad \text{send one unit less along } Q;\ \textbf{return} \ \text{CYCLE} \cr 7 & \quad \text{send one unit less along a path of positive flow from } s \text{ to } u \text{ and one from } v \text{ to } t \cr 8 & \quad \text{augment by one path from } s \text{ to } t \text{ if } \text{there is one};\ \textbf{return}\ \text{PATH} \end{array}} \]

Precondition
\( c \) and \( f \) are square of the same size, \( s \) and \( t \) distinct nodes, \( u \) and \( v \) distinct nodes, \( c( u , v ) > 0 \), \( f \) a maximum flow within \( c \) (audit)
Postcondition
\( f \) a maximum flow within the new \( c \) (audit)

◆ edgeDisjointPaths()

template<Graph G>
std::vector< std::vector< int > > ADS::edgeDisjointPaths ( const G & g,
int s,
int t,
long long k = std::numeric_limits< long long >::max() )

at most \( k \) paths from \( s \) to \( t \) with no edge in common, as many as there can be, each as its nodes from \( s \) to \( t \)

In pseudocode (the theorem of Menger):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{edgeDisjointPaths}( G , s , t , k ) \cr 2 & \quad N \gets \text{a network with capacity 1 on each edge of } G \text{ , both ways if unoriented} \cr 3 & \quad \text{add a new source } s' \text{ and the edge } ( s' , s ) \text{ of capacity } k \cr 4 & \quad N.\mathrm{maxFlow}( s' , t )\quad \triangleright \text{integral: each edge carries 0 or 1} \cr 5 & \quad \text{cancel the opposite flows of the two edges of an } \text{unoriented edge} \cr 6 & \quad P \gets () \cr 7 & \quad \textbf{while}\ \text{an edge of flow 1 leaves } s\ \textbf{do} \cr 8 & \qquad W \gets ( s );\ \text{walk from } s \text{ along the edges of } \text{flow 1 not used yet, marking them, until } t \cr 9 & \qquad \text{cut out of } W \text{ every cycle met on the way}; \ \text{append } W \text{ to } P \cr 10 & \quad \textbf{return}\ P \end{array}} \]

Precondition
\( s \) and \( t \) are distinct nodes, \( k \ge 0 \)
Postcondition
at most \( k \) simple paths from \( s \) to \( t \) along the edges of the graph, no edge used twice (audit)