This class provides an implementation of the Edmonds-Karpalgorithm 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 startingflow 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.
The simplest way to execute the algorithm is to use .\n 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.
Sets the flow map. If you don't use this function before calling run() or init(), an instance will be allocated automatically. The destructor deallocates this automatically allocated map, of course.
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.
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.
Returns
false when the given flowMap does not contain a feasible flow.
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.
Returns
false when the augmenting did not success, i.e. the current flow is a feasible and optimal solution.