template<typename GR, typename CAP, typename TR>
class lemon::EdmondsKarp< GR, CAP, TR >
This class provides an implementation of the Edmonds-Karp algorithm producing a flow of maximum value in a digraph clrs01algorithms, amo93networkflows, edmondskarp72theoretical. 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.
- Template Parameters
-
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. |
|
| EdmondsKarp (const Digraph &digraph, const CapacityMap &capacity, Node source, Node target) |
| The constructor of the class.
|
|
| ~EdmondsKarp () |
|
EdmondsKarp & | capacityMap (const CapacityMap &map) |
| Sets the capacity map.
|
|
EdmondsKarp & | flowMap (FlowMap &map) |
| Sets the flow map.
|
|
EdmondsKarp & | source (const Node &node) |
| Sets the source node.
|
|
EdmondsKarp & | target (const Node &node) |
| Sets the target node.
|
|
EdmondsKarp & | tolerance (const Tolerance &tolerance) |
| Sets the tolerance used by algorithm.
|
|
const Tolerance & | tolerance () const |
| Returns a const reference to the tolerance.
|
|
|
The simplest way to execute the algorithm is to use run().
If you need better control on the initial solution or the execution, you have to call one of the init() functions first, then start() or multiple times the augment() function.
|
void | init () |
| Initializes the algorithm.
|
|
template<typename FlowMap > |
void | init (const FlowMap &flowMap) |
| Initializes the algorithm using the given flow map.
|
|
template<typename FlowMap > |
bool | checkedInit (const FlowMap &flowMap) |
| Initializes the algorithm using the given flow map.
|
|
bool | augment () |
| Augments the solution along a shortest path.
|
|
void | start () |
| Executes the algorithm.
|
|
void | run () |
| Runs the algorithm.
|
|
|
The result of the Edmonds-Karp algorithm can be obtained using these functions.
Either run() or start() should be called before using them.
|
Value | flowValue () const |
| Returns the value of the maximum flow.
|
|
Value | flow (const Arc &arc) const |
| Returns the flow value on the given arc.
|
|
const FlowMap & | flowMap () const |
| Returns a const reference to the flow map.
|
|
bool | minCut (const Node &node) const |
| Returns true when the node is on the source side of the minimum cut.
|
|
template<typename CutMap > |
void | minCutMap (CutMap &cutMap) const |
| Gives back a minimum value cut.
|
|