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

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

#include "ADS/Contract.h"
#include <algorithm>
#include <cstddef>
#include <limits>
#include <vector>
#include "ADS/graph/impl/MaxFlow.tpp"
#include "ADS/graph/PushRelabel.h"

Go to the source code of this file.

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...

Namespaces

namespace  ADS

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 network keeps for each edge its residual twin, so that the residual capacity \( c_f( u , v ) = c( u , v ) - f( u , v ) \) of both directions is at hand. By Theorem 15.1 (maximum flow / minimum cut) \( f \) is maximum if and only if there is no augmenting path, a path from \( s \) to \( t \) in the residual network, and then the nodes \( S \) reached from \( s \) give a cut \( ( S , V \setminus S ) \) of capacity \( | f | \). The local search augments the flow along augmenting paths:

  • FORD_FULKERSON, any path, by a depth first visit: \( O( ( n + m ) |f^*| ) \);
  • EDMONDS_KARP, a shortest path, by a breadth first visit: \( O( n m^2 ) \);
  • DINIC, the blocking flows of the levels of a breadth first visit: \( O( n^2 m ) \), and \( O( m \sqrt{n} ) \) with unit capacities, e.g., the bipartite matching (the bound that the book gives for the algorithm of the three Indians, Karzanov, Malhotra, Kumar and Maheshwari, of which this is the forerunner);
  • PUSH_RELABEL, beyond the book, the push-relabel of Goldberg and Tarjan, which keeps a preflow and labels that bound the distances from \( t \), with its global relabelings and gaps and its warm start from the flow there is [see PushRelabel.h, which this header includes].

The best bound that the book attributes to Karmarkar (1984), \( O( n m \log( n^2 / m ) ) \), is the one of the push-relabel of Goldberg and Tarjan (1988) with the dynamic trees; Karmarkar's is the interior point method for linear programming. Every way starts from the flow there is, and setCapacity() may lower a capacity below the flow of its edge, which leaves an excess and a deficit for the next maxFlow() to route first (the reparametrization of the dynamic cuts of Kohli and Torr), so that a flow is reoptimized after any change of the capacities [see MaxFlowObserver of Reoptimization.h]. feasibleCirculation() decides whether a circulation with lower and upper bounds on the edges exists, by a maximum flow from a new source that gives each node the lower bounds entering it.

The contracts [see Contract.h]: a network has \( n \ge 0 \) nodes, an edge joins two of them with a capacity \( c \ge 0 \), maxFlow() needs two distinct nodes; the invariant is the skew symmetry of the flow on each edge and its twin, within the capacity. At the level of the audits maxFlow() ensures that no augmenting path is left, and feasibleCirculation() that the flows it gives are within the bounds and conserved at every node. The operations are defined in MaxFlow.tpp.

See also
A. Montresor, Algoritmi e Strutture Dati, 2025, section 15.2, https://algoritmicamente.it/materiali/libro/capitoli/cap15.pdf
L. R. Ford, D. R. Fulkerson, Maximal flow through a network, Canadian Journal of Mathematics 8, 399-404, 1956, doi:10.4153/CJM-1956-045-5
J. Edmonds, R. M. Karp, Theoretical improvements in algorithmic efficiency for network flow problems, Journal of the ACM 19(2), 248-264, 1972, doi:10.1145/321694.321699
E. A. Dinic, Algorithm for solution of a problem of maximum flow in a network with power estimation, Soviet Mathematics Doklady 11, 1277-1280, 1970
A. V. Karzanov, Determining the maximal flow in a network by the method of preflows, Soviet Mathematics Doklady 15, 434-437, 1974
V. M. Malhotra, M. P. Kumar, S. N. Maheshwari, An \( O( |V|^3 ) \) algorithm for finding maximum flows in networks, Information Processing Letters 7(6), 277-278, 1978, doi:10.1016/0020-0190(78)90016-9
N. Karmarkar, A new polynomial-time algorithm for linear programming, Combinatorica 4(4), 373-395, 1984, doi:10.1007/BF02579150
A. V. Goldberg, R. E. Tarjan, A new approach to the maximum-flow problem, Journal of the ACM 35(4), 921-940, 1988, doi:10.1145/48014.61051
P. Kohli, P. H. S. Torr, Dynamic graph cuts for efficient inference in Markov random fields, IEEE Transactions on Pattern Analysis and Machine Intelligence 29(12), 2079-2088, 2007, doi:10.1109/TPAMI.2007.1128
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa