template<typename GR, typename V, typename C, typename TR>
class lemon::CapacityScaling< GR, V, C, TR >
CapacityScaling implements the capacity scaling version of the successive shortest path algorithm for finding a minimum cost flow [AMO93], [EK72]. It is an efficient dual solution method.
Most of the parameters of the problem (except for the digraph) can be given using separate functions, and the algorithm can be executed using the run() function. If some parameters are not specified, then default values will be used.
- Template Parameters
-
GR | The digraph type the algorithm runs on. |
V | The number type used for flow amounts, capacity bounds and supply values in the algorithm. By default, it is int . |
C | The number type used for costs and potentials in the algorithm. By default, it is the same as V . |
TR | The traits class that defines various types used by the algorithm. By default, it is CapacityScalingDefaultTraits<GR, V, C>. In most cases, this parameter should not be set directly, consider to use the named template parameters instead. |
- Warning
- Both number types must be signed and all input data must be integer.
-
This algorithm does not support negative costs for such arcs that have infinite upper bound.
|
| CapacityScaling (const GR &graph) |
| Constructor.
|
|
|
The parameters of the algorithm can be specified using these functions.
|
template<typename LowerMap > |
CapacityScaling & | lowerMap (const LowerMap &map) |
| Set the lower bounds on the arcs.
|
|
template<typename UpperMap > |
CapacityScaling & | upperMap (const UpperMap &map) |
| Set the upper bounds (capacities) on the arcs.
|
|
template<typename CostMap > |
CapacityScaling & | costMap (const CostMap &map) |
| Set the costs of the arcs.
|
|
template<typename SupplyMap > |
CapacityScaling & | supplyMap (const SupplyMap &map) |
| Set the supply values of the nodes.
|
|
CapacityScaling & | stSupply (const Node &s, const Node &t, Value k) |
| Set single source and target nodes and a supply value.
|
|
|
The algorithm can be executed using run().
|
ProblemType | run (int factor=4) |
| Run the algorithm.
|
|
CapacityScaling & | resetParams () |
| Reset all the parameters that have been given before.
|
|
CapacityScaling & | reset () |
| Reset the internal data structures and all the parameters that have been given before.
|
|
|
The results of the algorithm can be obtained using these functions.
The run() function must be called before using them.
|
template<typename Number > |
Number | totalCost () const |
| Return the total cost of the found flow.
|
|
Value | flow (const Arc &a) const |
| Return the flow on the given arc.
|
|
template<typename FlowMap > |
void | flowMap (FlowMap &map) const |
| Return the flow map (the primal solution).
|
|
Cost | potential (const Node &n) const |
| Return the potential (dual value) of the given node.
|
|
template<typename PotentialMap > |
void | potentialMap (PotentialMap &map) const |
| Return the potential map (the dual solution).
|
|
This function runs the algorithm. The paramters can be specified using functions lowerMap(), upperMap(), costMap(), supplyMap(), stSupply(). For example,
CapacityScaling<ListDigraph> cs(graph);
cs.lowerMap(lower).upperMap(upper).costMap(cost)
.supplyMap(sup).run();
This function can be called more than once. All the given parameters are kept for the next call, unless resetParams() or reset() is used, thus only the modified parameters have to be set again. If the underlying digraph was also modified after the construction of the class (or the last reset() call), then the reset() function must be called.
- Parameters
-
factor | The capacity scaling factor. It must be larger than one to use scaling. If it is less or equal to one, then scaling will be disabled. |
- Returns
INFEASIBLE
if no feasible flow exists,
OPTIMAL
if the problem has optimal solution (i.e. it is feasible and bounded), and the algorithm has found optimal flow and node potentials (primal and dual solutions),
UNBOUNDED
if the digraph contains an arc of negative cost and infinite upper bound. It means that the objective function is unbounded on that arc, however, note that it could actually be bounded over the feasible flows, but this algroithm cannot handle these cases.
- See Also
- ProblemType
-
resetParams(), reset()
This function resets all the paramaters that have been given before using functions lowerMap(), upperMap(), costMap(), supplyMap(), stSupply().
It is useful for multiple run() calls. Basically, all the given parameters are kept for the next run() call, unless resetParams() or reset() is used. If the underlying digraph was also modified after the construction of the class or the last reset() call, then the reset() function must be used, otherwise resetParams() is sufficient.
For example,
CapacityScaling<ListDigraph> cs(graph);
cs.lowerMap(lower).upperMap(upper).costMap(cost)
.supplyMap(sup).run();
cost[e] += 100;
cs.costMap(cost).run();
cs.resetParams();
cs.upperMap(capacity).costMap(cost)
.supplyMap(sup).run();
- Returns
(*this)
- See Also
- reset(), run()