alpaqa 1.0.0a10
Nonconvex constrained optimization
Loading...
Searching...
No Matches
alm.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <alpaqa/export.hpp>
8
9#include <chrono>
10#include <iostream>
11#include <string>
12
13namespace alpaqa {
14
15template <class InnerSolverStats>
16struct InnerStatsAccumulator;
17
18/// Parameters for the Augmented Lagrangian solver.
19template <Config Conf = DefaultConfig>
20struct ALMParams {
22
23 /// Primal tolerance (used for stopping criterion of inner solver).
25 /// Dual tolerance (constraint violation and complementarity).
27 /// Factor used in updating the penalty parameters.
29 /// Factor to reduce @ref penalty_update_factor when inner convergence fails.
31 /// Minimum value for @ref penalty_update_factor after reduction because of inner convergence
32 /// failure.
34 /// Initial penalty parameter. When set to zero (which is the default),
35 /// it is computed automatically, based on the constraint violation in the
36 /// starting point and the parameter @ref initial_penalty_factor.
37 /// @todo Change default to 0.
39 /// Initial penalty parameter factor. Active if @ref initial_penalty is set
40 /// to zero.
42 /// Factor to reduce the initial penalty factor by if convergence fails in
43 /// in the first iteration.
45 /// Initial primal tolerance.
47 /// Factor to increase the initial primal tolerance if convergence fails in
48 /// the first iteration.
50 /// Update factor for primal tolerance.
52 /// Factor to increase the primal tolerance update factor by if convergence
53 /// fails.
55 /// Maximum value of @ref tolerance_update_factor after increase because of inner convergence
56 /// failure.
58 /// Error tolerance for penalty increase
60 /// Lagrange multiplier bound.
62 /// Maximum penalty factor.
64 /// Minimum penalty factor (used during initialization).
66 /// Maximum number of outer ALM iterations.
67 unsigned int max_iter = 100;
68 /// Maximum duration.
69 std::chrono::nanoseconds max_time = std::chrono::minutes(5);
70
71 /// How many times can the initial penalty @ref initial_penalty or
72 /// @ref initial_penalty_factor and the initial primal tolerance @ref initial_tolerance
73 /// be reduced.
75 /// How many times can the penalty update factor @ref penalty_update_factor and the
76 /// primal tolerance factor @ref tolerance_update_factor be reduced.
77 unsigned max_num_retries = 0;
78 /// Combined limit for @ref max_num_initial_retries and
79 /// @ref max_num_retries.
81
82 /// When to print progress. If set to zero, nothing will be printed.
83 /// If set to N != 0, progress is printed every N iterations.
84 unsigned print_interval = 0;
85 /// The precision of the floating point values printed by the solver.
86 int print_precision = std::numeric_limits<real_t>::max_digits10 / 2;
87
88 /// Use one penalty factor for all m constraints.
90};
91
92/// Augmented Lagrangian Method solver
93///
94/// @ingroup grp_ALMSolver
95template <class InnerSolverT>
96class ALMSolver {
97 public:
98 USING_ALPAQA_CONFIG_TEMPLATE(InnerSolverT::config_t);
99
101 using InnerSolver = InnerSolverT;
102 using Problem = typename InnerSolver::Problem;
103
104 struct Stats {
105 /// Total number of outer ALM iterations (i.e. the number of times that
106 /// the inner solver was invoked).
107 unsigned outer_iterations = 0;
108 /// Total elapsed time.
109 std::chrono::nanoseconds elapsed_time{};
110 /// The number of times that the initial penalty factor was reduced by
111 /// @ref ALMParams::initial_penalty_lower and that the initial tolerance was
112 /// increased by @ref ALMParams::initial_tolerance_increase because the inner solver
113 /// failed to converge in the first ALM iteration. If this number is
114 /// greater than zero, consider lowering the initial penalty factor
115 /// @ref ALMParams::initial_penalty or @ref ALMParams::initial_penalty_factor or increasing the initial
116 /// tolerance @ref ALMParams::initial_tolerance (or both).
118 /// The number of times that the penalty update factor @ref ALMParams::penalty_update_factor
119 /// was reduced, that the tolerance update factor @ref ALMParams::tolerance_update_factor was
120 /// increased, and that an ALM iteration had to be restarted with a
121 /// lower penalty factor and a higher tolerance because the inner solver
122 /// failed to converge (not applicable in the first ALM iteration).
123 /// If this number is greater than zero, consider lowerering the
124 /// penalty update factor @ref ALMParams::penalty_update_factor or increasing the tolerance
125 /// update factor (or both). Lowering the initial penalty factor could
126 /// help as well.
127 unsigned penalty_reduced = 0;
128 /// The total number of times that the inner solver failed to converge.
130 /// Final primal tolerance that was reached, depends on the stopping
131 /// criterion used by the inner solver, see for example
132 /// @ref PANOCStopCrit.
133 real_t ε = inf<config_t>;
134 /// Final dual tolerance or constraint violation that was reached:
135 /// @f[
136 /// \delta = \| \Pi_D\left(g(x^k) + \Sigma^{-1}y\right) \|_\infty
137 /// @f]
138 real_t δ = inf<config_t>;
139 /// 2-norm of the final penalty factors @f$ \| \Sigma \|_2 @f$.
141
142 /// Whether the solver converged or not.
143 /// @see @ref SolverStatus
145
146 /// The statistics of the inner solver invocations, accumulated over all
147 /// ALM iterations.
149 };
150
152 : params(params),
153 inner_solver(std::forward<InnerSolver>(inner_solver)) {}
156
157 Stats operator()(const Problem &problem, rvec x, rvec y,
158 std::optional<rvec> Σ = std::nullopt);
159 template <class P>
160 Stats operator()(const P &problem, rvec x, rvec y,
161 std::optional<rvec> Σ = std::nullopt) {
162 return operator()(Problem::template make<P>(problem), x, y, Σ);
163 }
164
165 std::string get_name() const {
166 return "ALMSolver<" + inner_solver.get_name() + ">";
167 }
168
169 /// Abort the computation and return the result so far.
170 /// Can be called from other threads or signal handlers.
171 void stop() { inner_solver.stop(); }
172
173 const Params &get_params() const { return params; }
174
175 private:
178
179 public:
181 std::ostream *os = &std::cout;
182};
183
188
189} // namespace alpaqa
Augmented Lagrangian Method solver.
Definition: alm.hpp:96
Params params
Definition: alm.hpp:176
std::string get_name() const
Definition: alm.hpp:165
unsigned penalty_reduced
The number of times that the penalty update factor ALMParams::penalty_update_factor was reduced,...
Definition: alm.hpp:127
ALMSolver(Params params, const InnerSolver &inner_solver)
Definition: alm.hpp:154
real_t δ
Final dual tolerance or constraint violation that was reached:
Definition: alm.hpp:138
real_t norm_penalty
2-norm of the final penalty factors .
Definition: alm.hpp:140
typename InnerSolver::Problem Problem
Definition: alm.hpp:102
std::chrono::nanoseconds elapsed_time
Total elapsed time.
Definition: alm.hpp:109
unsigned initial_penalty_reduced
The number of times that the initial penalty factor was reduced by ALMParams::initial_penalty_lower a...
Definition: alm.hpp:117
InnerStatsAccumulator< typename InnerSolver::Stats > inner
The statistics of the inner solver invocations, accumulated over all ALM iterations.
Definition: alm.hpp:148
unsigned inner_convergence_failures
The total number of times that the inner solver failed to converge.
Definition: alm.hpp:129
void stop()
Abort the computation and return the result so far.
Definition: alm.hpp:171
real_t ε
Final primal tolerance that was reached, depends on the stopping criterion used by the inner solver,...
Definition: alm.hpp:133
const Params & get_params() const
Definition: alm.hpp:173
unsigned outer_iterations
Total number of outer ALM iterations (i.e.
Definition: alm.hpp:107
Stats operator()(const P &problem, rvec x, rvec y, std::optional< rvec > Σ=std::nullopt)
Definition: alm.hpp:160
InnerSolverT InnerSolver
Definition: alm.hpp:101
ALMSolver(Params params, InnerSolver &&inner_solver)
Definition: alm.hpp:151
InnerSolver inner_solver
Definition: alm.hpp:180
Stats operator()(const Problem &problem, rvec x, rvec y, std::optional< rvec > Σ=std::nullopt)
Definition: alm.tpp:20
SolverStatus status
Whether the solver converged or not.
Definition: alm.hpp:144
std::ostream * os
Definition: alm.hpp:181
#define USING_ALPAQA_CONFIG(Conf)
Definition: config.hpp:54
#define ALPAQA_IF_QUADF(...)
Definition: config.hpp:171
#define ALPAQA_IF_LONGD(...)
Definition: config.hpp:183
#define ALPAQA_IF_FLOAT(...)
Definition: config.hpp:177
#define USING_ALPAQA_CONFIG_TEMPLATE(Conf)
Definition: config.hpp:58
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
Definition: export.hpp:21
real_t max_multiplier
Lagrange multiplier bound.
Definition: alm.hpp:61
unsigned max_total_num_retries
Combined limit for max_num_initial_retries and max_num_retries.
Definition: alm.hpp:80
real_t initial_penalty_factor
Initial penalty parameter factor.
Definition: alm.hpp:41
real_t tolerance
Primal tolerance (used for stopping criterion of inner solver).
Definition: alm.hpp:24
real_t tolerance_update_factor
Update factor for primal tolerance.
Definition: alm.hpp:51
real_t penalty_update_factor
Factor used in updating the penalty parameters.
Definition: alm.hpp:28
unsigned int max_iter
Maximum number of outer ALM iterations.
Definition: alm.hpp:67
real_t min_penalty
Minimum penalty factor (used during initialization).
Definition: alm.hpp:65
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
@ Busy
In progress.
unsigned max_num_retries
How many times can the penalty update factor penalty_update_factor and the primal tolerance factor to...
Definition: alm.hpp:77
real_t dual_tolerance
Dual tolerance (constraint violation and complementarity).
Definition: alm.hpp:26
typename Conf::real_t real_t
Definition: config.hpp:63
real_t max_penalty
Maximum penalty factor.
Definition: alm.hpp:63
real_t initial_tolerance
Initial primal tolerance.
Definition: alm.hpp:46
real_t ρ_max
Maximum value of tolerance_update_factor after increase because of inner convergence failure.
Definition: alm.hpp:57
real_t initial_penalty_lower
Factor to reduce the initial penalty factor by if convergence fails in in the first iteration.
Definition: alm.hpp:44
std::chrono::nanoseconds max_time
Maximum duration.
Definition: alm.hpp:69
real_t initial_tolerance_increase
Factor to increase the initial primal tolerance if convergence fails in the first iteration.
Definition: alm.hpp:49
unsigned max_num_initial_retries
How many times can the initial penalty initial_penalty or initial_penalty_factor and the initial prim...
Definition: alm.hpp:74
real_t rel_penalty_increase_threshold
Error tolerance for penalty increase.
Definition: alm.hpp:59
typename Conf::rvec rvec
Definition: config.hpp:67
real_t penalty_update_factor_lower
Factor to reduce penalty_update_factor when inner convergence fails.
Definition: alm.hpp:30
unsigned print_interval
When to print progress.
Definition: alm.hpp:84
int print_precision
The precision of the floating point values printed by the solver.
Definition: alm.hpp:86
real_t ρ_increase
Factor to increase the primal tolerance update factor by if convergence fails.
Definition: alm.hpp:54
real_t initial_penalty
Initial penalty parameter.
Definition: alm.hpp:38
bool single_penalty_factor
Use one penalty factor for all m constraints.
Definition: alm.hpp:89
real_t min_penalty_update_factor
Minimum value for penalty_update_factor after reduction because of inner convergence failure.
Definition: alm.hpp:33
Parameters for the Augmented Lagrangian solver.
Definition: alm.hpp:20
Double-precision double configuration.
Definition: config.hpp:127
Single-precision float configuration.
Definition: config.hpp:123
long double configuration.
Definition: config.hpp:132