This class provides an implementation of Goldberg-Tarjan's preflow push-relabel algorithm producing a flow of maximum value in a digraph [6], [1], [15]. The preflow algorithms are the fastest known maximum flow algorithms. The current implementation uses a mixture of the "highest label" and the "bound decrease" heuristics. The worst case time complexity of the algorithm is .
The algorithm consists of two phases. After the first phase the maximum flow value and the minimum cut is obtained. The second phase constructs a feasible maximum flow on each arc.
CAP::Value
).GR | The type of the digraph the algorithm runs on. |
CAP | The type of the capacity map. The default map type is GR::ArcMap<int>. |
TR | The traits class that defines various types used by the algorithm. By default, it is PreflowDefaultTraits<GR, CAP>. In most cases, this parameter should not be set directly, consider to use the named template parameters instead. |
#include <lemon/preflow.h>
Classes | |
struct | SetElevator |
Named parameter for setting Elevator type More... | |
struct | SetFlowMap |
Named parameter for setting FlowMap type More... | |
struct | SetStandardElevator |
Named parameter for setting Elevator type with automatic allocation More... | |
Public Types | |
typedef TR | Traits |
The traits class of the algorithm. | |
typedef Traits::Digraph | Digraph |
The type of the digraph the algorithm runs on. | |
typedef Traits::CapacityMap | CapacityMap |
The type of the capacity map. | |
typedef Traits::Value | Value |
The type of the flow values. | |
typedef Traits::FlowMap | FlowMap |
The type of the flow map. | |
typedef Traits::Elevator | Elevator |
The type of the elevator. | |
typedef Traits::Tolerance | Tolerance |
The type of the tolerance. | |
Public Member Functions | |
Preflow (const Digraph &digraph, const CapacityMap &capacity, Node source, Node target) | |
The constructor of the class. More... | |
~Preflow () | |
Destructor. More... | |
Preflow & | capacityMap (const CapacityMap &map) |
Sets the capacity map. More... | |
Preflow & | flowMap (FlowMap &map) |
Sets the flow map. More... | |
Preflow & | source (const Node &node) |
Sets the source node. More... | |
Preflow & | target (const Node &node) |
Sets the target node. More... | |
Preflow & | elevator (Elevator &elevator) |
Sets the elevator used by algorithm. More... | |
const Elevator & | elevator () const |
Returns a const reference to the elevator. More... | |
Preflow & | tolerance (const Tolerance &tolerance) |
Sets the tolerance used by the algorithm. More... | |
const Tolerance & | tolerance () const |
Returns a const reference to the tolerance. More... | |
Execution Control | |
The simplest way to execute the preflow algorithm is to use run() or runMinCut(). | |
void | init () |
Initializes the internal data structures. More... | |
template<typename FlowMap > | |
bool | init (const FlowMap &flowMap) |
Initializes the internal data structures using the given flow map. More... | |
void | startFirstPhase () |
Starts the first phase of the preflow algorithm. More... | |
void | startSecondPhase () |
Starts the second phase of the preflow algorithm. More... | |
void | run () |
Runs the preflow algorithm. More... | |
void | runMinCut () |
Runs the preflow algorithm to compute the minimum cut. More... | |
Query Functions | |
Value | flowValue () const |
Returns the value of the maximum flow. More... | |
Value | flow (const Arc &arc) const |
Returns the flow value on the given arc. More... | |
const FlowMap & | flowMap () const |
Returns a const reference to the flow map. More... | |
bool | minCut (const Node &node) const |
Returns true when the node is on the source side of the minimum cut. More... | |
template<typename CutMap > | |
void | minCutMap (CutMap &cutMap) const |
Gives back a minimum value cut. More... | |
|
inline |
The constructor of the class.
digraph | The digraph the algorithm runs on. |
capacity | The capacity of the arcs. |
source | The source node. |
target | The target node. |
|
inline |
Destructor.
|
inline |
Sets the capacity map.
(*this)
|
inline |
Sets the source node.
(*this)
|
inline |
Sets the target node.
(*this)
|
inline |
Sets the tolerance object used by the algorithm.
(*this)
|
inline |
Returns a const reference to the tolerance object used by the algorithm.
|
inline |
Initializes the internal data structures and sets the initial flow to zero on each arc.
|
inline |
Initializes the internal data structures and sets the initial flow to the given flowMap
. The flowMap
should contain a flow or at least a preflow, i.e. at each node excluding the source node the incoming flow should greater or equal to the outgoing flow.
false
if the given flowMap
is not a preflow.
|
inline |
The preflow algorithm consists of two phases, this method runs the first phase. After the first phase the maximum flow value and a minimum value cut can already be computed, although a maximum flow is not yet obtained. So after calling this method flowValue() returns the value of a maximum flow and minCut() returns a minimum cut.
|
inline |
The preflow algorithm consists of two phases, this method runs the second phase. After calling one of the init() functions and startFirstPhase() and then startSecondPhase(), flowMap() returns a maximum flow, flowValue() returns the value of a maximum flow, minCut() returns a minimum cut
|
inline |
Runs the preflow algorithm.
|
inline |
Runs the preflow algorithm to compute the minimum cut.
|
inline |
|
inline |
|
inline |
|
inline |
Returns true when the node is on the source side of the found minimum cut. This method can be called both after running startFirstPhase() and startSecondPhase().
|
inline |
Sets cutMap
to the characteristic vector of a minimum value cut. cutMap
should be a writable node map with bool
(or convertible) value type.
This method can be called both after running startFirstPhase() and startSecondPhase(). The result after the second phase could be slightly different if inexact computation is used.