... | ... |
@@ -24,49 +24,51 @@ |
24 | 24 |
/// \brief Cycle-canceling algorithms for finding a minimum cost flow. |
25 | 25 |
|
26 | 26 |
#include <vector> |
27 | 27 |
#include <limits> |
28 | 28 |
|
29 | 29 |
#include <lemon/core.h> |
30 | 30 |
#include <lemon/maps.h> |
31 | 31 |
#include <lemon/path.h> |
32 | 32 |
#include <lemon/math.h> |
33 | 33 |
#include <lemon/static_graph.h> |
34 | 34 |
#include <lemon/adaptors.h> |
35 | 35 |
#include <lemon/circulation.h> |
36 | 36 |
#include <lemon/bellman_ford.h> |
37 | 37 |
#include <lemon/howard.h> |
38 | 38 |
|
39 | 39 |
namespace lemon { |
40 | 40 |
|
41 | 41 |
/// \addtogroup min_cost_flow_algs |
42 | 42 |
/// @{ |
43 | 43 |
|
44 | 44 |
/// \brief Implementation of cycle-canceling algorithms for |
45 | 45 |
/// finding a \ref min_cost_flow "minimum cost flow". |
46 | 46 |
/// |
47 | 47 |
/// \ref CycleCanceling implements three different cycle-canceling |
48 |
/// algorithms for finding a \ref min_cost_flow "minimum cost flow" |
|
48 |
/// algorithms for finding a \ref min_cost_flow "minimum cost flow" |
|
49 |
/// \ref amo93networkflows, \ref klein67primal, |
|
50 |
/// \ref goldberg89cyclecanceling. |
|
49 | 51 |
/// The most efficent one (both theoretically and practically) |
50 | 52 |
/// is the \ref CANCEL_AND_TIGHTEN "Cancel and Tighten" algorithm, |
51 | 53 |
/// thus it is the default method. |
52 | 54 |
/// It is strongly polynomial, but in practice, it is typically much |
53 | 55 |
/// slower than the scaling algorithms and NetworkSimplex. |
54 | 56 |
/// |
55 | 57 |
/// Most of the parameters of the problem (except for the digraph) |
56 | 58 |
/// can be given using separate functions, and the algorithm can be |
57 | 59 |
/// executed using the \ref run() function. If some parameters are not |
58 | 60 |
/// specified, then default values will be used. |
59 | 61 |
/// |
60 | 62 |
/// \tparam GR The digraph type the algorithm runs on. |
61 | 63 |
/// \tparam V The number type used for flow amounts, capacity bounds |
62 | 64 |
/// and supply values in the algorithm. By default, it is \c int. |
63 | 65 |
/// \tparam C The number type used for costs and potentials in the |
64 | 66 |
/// algorithm. By default, it is the same as \c V. |
65 | 67 |
/// |
66 | 68 |
/// \warning Both number types must be signed and all input data must |
67 | 69 |
/// be integer. |
68 | 70 |
/// \warning This algorithm does not support negative costs for such |
69 | 71 |
/// arcs that have infinite upper bound. |
70 | 72 |
/// |
71 | 73 |
/// \note For more information about the three available methods, |
72 | 74 |
/// see \ref Method. |
... | ... |
@@ -103,54 +105,56 @@ |
103 | 105 |
/// upper bound. It means that the objective function is unbounded |
104 | 106 |
/// on that arc, however, note that it could actually be bounded |
105 | 107 |
/// over the feasible flows, but this algroithm cannot handle |
106 | 108 |
/// these cases. |
107 | 109 |
UNBOUNDED |
108 | 110 |
}; |
109 | 111 |
|
110 | 112 |
/// \brief Constants for selecting the used method. |
111 | 113 |
/// |
112 | 114 |
/// Enum type containing constants for selecting the used method |
113 | 115 |
/// for the \ref run() function. |
114 | 116 |
/// |
115 | 117 |
/// \ref CycleCanceling provides three different cycle-canceling |
116 | 118 |
/// methods. By default, \ref CANCEL_AND_TIGHTEN "Cancel and Tighten" |
117 | 119 |
/// is used, which proved to be the most efficient and the most robust |
118 | 120 |
/// on various test inputs. |
119 | 121 |
/// However, the other methods can be selected using the \ref run() |
120 | 122 |
/// function with the proper parameter. |
121 | 123 |
enum Method { |
122 | 124 |
/// A simple cycle-canceling method, which uses the |
123 | 125 |
/// \ref BellmanFord "Bellman-Ford" algorithm with limited iteration |
124 | 126 |
/// number for detecting negative cycles in the residual network. |
125 | 127 |
SIMPLE_CYCLE_CANCELING, |
126 | 128 |
/// The "Minimum Mean Cycle-Canceling" algorithm, which is a |
127 |
/// well-known strongly polynomial method |
|
129 |
/// well-known strongly polynomial method |
|
130 |
/// \ref goldberg89cyclecanceling. It improves along a |
|
128 | 131 |
/// \ref min_mean_cycle "minimum mean cycle" in each iteration. |
129 | 132 |
/// Its running time complexity is O(n<sup>2</sup>m<sup>3</sup>log(n)). |
130 | 133 |
MINIMUM_MEAN_CYCLE_CANCELING, |
131 | 134 |
/// The "Cancel And Tighten" algorithm, which can be viewed as an |
132 |
/// improved version of the previous method |
|
135 |
/// improved version of the previous method |
|
136 |
/// \ref goldberg89cyclecanceling. |
|
133 | 137 |
/// It is faster both in theory and in practice, its running time |
134 | 138 |
/// complexity is O(n<sup>2</sup>m<sup>2</sup>log(n)). |
135 | 139 |
CANCEL_AND_TIGHTEN |
136 | 140 |
}; |
137 | 141 |
|
138 | 142 |
private: |
139 | 143 |
|
140 | 144 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR); |
141 | 145 |
|
142 | 146 |
typedef std::vector<int> IntVector; |
143 | 147 |
typedef std::vector<char> CharVector; |
144 | 148 |
typedef std::vector<double> DoubleVector; |
145 | 149 |
typedef std::vector<Value> ValueVector; |
146 | 150 |
typedef std::vector<Cost> CostVector; |
147 | 151 |
|
148 | 152 |
private: |
149 | 153 |
|
150 | 154 |
template <typename KT, typename VT> |
151 | 155 |
class VectorMap { |
152 | 156 |
public: |
153 | 157 |
typedef KT Key; |
154 | 158 |
typedef VT Value; |
155 | 159 |
|
156 | 160 |
VectorMap(std::vector<Value>& v) : _v(v) {} |
0 comments (0 inline)