This class provides an implementation of the Edmonds-Karp algorithm producing a flow of maximum value in a digraph [6], [1], [12]. The Edmonds-Karp algorithm is slower than the Preflow algorithm, but it has an advantage of the step-by-step execution control with feasible flow solutions. The source node, the target node, the capacity of the arcs and the starting flow value of the arcs should be passed to the algorithm through the constructor.
The time complexity of the algorithm is in worst case. Always try the Preflow algorithm instead of this if you just want to compute the optimal flow.
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 EdmondsKarpDefaultTraits<GR, CAP>. In most cases, this parameter should not be set directly, consider to use the named template parameters instead. |
#include <lemon/edmonds_karp.h>
Classes | |
struct | SetFlowMap |
Named parameter for setting FlowMap type 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::Tolerance | Tolerance |
The type of the tolerance. | |
Public Member Functions | |
EdmondsKarp (const Digraph &digraph, const CapacityMap &capacity, Node source, Node target) | |
The constructor of the class. More... | |
~EdmondsKarp () | |
Destructor. More... | |
EdmondsKarp & | capacityMap (const CapacityMap &map) |
Sets the capacity map. More... | |
EdmondsKarp & | flowMap (FlowMap &map) |
Sets the flow map. More... | |
EdmondsKarp & | source (const Node &node) |
Sets the source node. More... | |
EdmondsKarp & | target (const Node &node) |
Sets the target node. More... | |
EdmondsKarp & | tolerance (const Tolerance &tolerance) |
Sets the tolerance used by algorithm. More... | |
const Tolerance & | tolerance () const |
Returns a const reference to the tolerance. More... | |
Execution control | |
void | init () |
Initializes the algorithm. More... | |
template<typename FlowMap > | |
void | init (const FlowMap &flowMap) |
Initializes the algorithm using the given flow map. More... | |
template<typename FlowMap > | |
bool | checkedInit (const FlowMap &flowMap) |
Initializes the algorithm using the given flow map. More... | |
bool | augment () |
Augments the solution along a shortest path. More... | |
void | start () |
Executes the algorithm. More... | |
void | run () |
Runs the algorithm. 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 |
|
inline |
Sets the source node.
(*this)
|
inline |
Sets the target node.
(*this)
|
inline |
Sets the tolerance used by 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 feasible flow, i.e. at each node excluding the source and the target, the incoming flow should be equal to the outgoing flow.
|
inline |
Initializes the internal data structures and sets the initial flow to the given flowMap
. The flowMap
should contain a feasible flow, i.e. at each node excluding the source and the target, the incoming flow should be equal to the outgoing flow.
false
when the given flowMap
does not contain a feasible flow.
|
inline |
Augments the solution along a shortest path. This function searches a shortest path between the source and the target in the residual digraph by the Bfs algoritm. Then it increases the flow on this path with the minimal residual capacity on the path. If there is no such path, it gives back false.
false
when the augmenting did not success, i.e. the current flow is a feasible and optimal solution.
|
inline |
Executes the algorithm by performing augmenting phases until the optimal solution is reached.
|
inline |
Runs the Edmonds-Karp algorithm.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |