alpaqa 0.0.1
Nonconvex constrained optimization
decl/alm.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <chrono>
8#include <string>
9
10namespace alpaqa {
11
12/// Parameters for the Augmented Lagrangian solver.
13struct ALMParams {
14 /// Primal tolerance.
15 real_t ε = 1e-5;
16 /// Dual tolerance.
17 real_t δ = 1e-5;
18 /// Factor used in updating the penalty parameters.
19 real_t Δ = 10;
20 /// Factor to reduce @ref ALMParams::Δ when inner convergence fails.
22 /// Initial penalty parameter. When set to zero (which is the default),
23 /// it is computed automatically, based on the constraint violation in the
24 /// starting point and the parameter @ref ALMParams::σ₀.
25 /// @todo Change default to 0.
27 /// Initial penalty parameter factor. Active if @ref ALMParams::Σ₀ is set
28 /// to zero.
30 /// Factor to reduce the initial penalty factor by if convergence fails in
31 /// in the first iteration.
33 /// Initial primal tolerance.
35 /// Factor to increase the initial primal tolerance if convergence fails in
36 /// the first iteration.
38 /// Update factor for primal tolerance.
39 real_t ρ = 1e-1;
40 /// Factor to increase the primal tolerance update factor by if convergence
41 /// fails.
43 /// Error tolerance for penalty increase
44 real_t θ = 0.1;
45 /// Lagrange multiplier bound.
46 real_t M = 1e9;
47 /// Maximum penalty factor.
49 /// Minimum penalty factor (used during initialization).
50 real_t Σ_min = 1e-9;
51 /// Maximum number of outer ALM iterations.
52 unsigned int max_iter = 100;
53 /// Maximum duration.
54 std::chrono::microseconds max_time = std::chrono::minutes(5);
55
56 /// How many times can the initial penalty @ref ALMParams::Σ₀ or
57 /// @ref ALMParams::σ₀ and the initial primal tolerance @ref ALMParams::ε₀
58 /// be reduced.
60 /// How many times can the penalty update factor @ref ALMParams::Δ and the
61 /// primal tolerance factor @ref ALMParams::ρ be reduced.
62 unsigned max_num_retries = 20;
63 /// Combined limit for @ref ALMParams::max_num_initial_retries and
64 /// @ref ALMParams::max_num_retries.
65 unsigned max_total_num_retries = 40;
66
67 /// When to print progress. If set to zero, nothing will be printed.
68 /// If set to N != 0, progress is printed every N iterations.
69 unsigned print_interval = 0;
70
71 /// Apply preconditioning to the problem, based on the gradients in the
72 /// starting point.
73 bool preconditioning = false;
74 /// Use one penalty factor for all m constraints.
76};
77
78/// Augmented Lagrangian Method solver
79///
80/// @ingroup grp_ALMSolver
81template <class InnerSolverT = PANOCSolver<>>
82class ALMSolver {
83 public:
85 using InnerSolver = InnerSolverT;
86
87 struct Stats {
88 /// Total number of outer ALM iterations (i.e. the number of times that
89 /// the inner solver was invoked).
90 unsigned outer_iterations = 0;
91 /// Total elapsed time.
92 std::chrono::microseconds elapsed_time;
93 /// The number of times that the initial penalty factor was reduced by
94 /// @ref ALMParams::Σ₀_lower and that the initial tolerance was
95 /// increased by @ref ALMParams::ε₀_increase because the inner solver
96 /// failed to converge in the first ALM iteration. If this number is
97 /// greater than zero, consider lowering the initial penalty factor
98 /// @ref ALMParams::Σ₀ or @ref ALMParams::σ₀ or increasing the initial
99 /// tolerance @ref ALMParams::ε₀ (or both).
101 /// The number of times that the penalty update factor @ref ALMParams::Δ
102 /// was reduced, that the tolerance update factor @ref ALMParams::ρ was
103 /// increased, and that an ALM iteration had to be restarted with a
104 /// lower penalty factor and a higher tolerance because the inner solver
105 /// failed to converge (not applicable in the first ALM iteration).
106 /// If this number is greater than zero, consider lowerering the
107 /// penalty update factor @ref ALMParams::Δ or increasing the tolerance
108 /// update factor (or both). Lowering the initial penalty factor could
109 /// help as well.
110 unsigned penalty_reduced = 0;
111 /// The total number of times that the inner solver failed to converge.
113 /// Final primal tolerance that was reached, depends on the stopping
114 /// criterion used by the inner solver, see for example
115 /// @ref PANOCStopCrit.
117 /// Final dual tolerance or constraint violation that was reached:
118 /// @f[
119 /// \delta = \| \Pi_D\left(g(x^k) + \Sigma^{-1}y\right) \|_\infty
120 /// @f]
122 /// 2-norm of the final penalty factors @f$ \| \Sigma \|_2 @f$.
124
125 /// Whether the solver converged or not.
126 /// @see @ref SolverStatus
128
129 /// The statistics of the inner solver invocations, accumulated over all
130 /// ALM iterations.
132 };
133
135 : params(params),
136 inner_solver(std::forward<InnerSolver>(inner_solver)) {}
139
140 Stats operator()(const Problem &problem, rvec y, rvec x);
141
142 std::string get_name() const {
143 return "ALMSolver<" + inner_solver.get_name() + ">";
144 }
145
146 /// Abort the computation and return the result so far.
147 /// Can be called from other threads or signal handlers.
148 void stop() { inner_solver.stop(); }
149
150 const Params &get_params() const { return params; }
151
152 private:
154
155 public:
157};
158
159} // namespace alpaqa
Augmented Lagrangian Method solver.
Definition: decl/alm.hpp:82
std::string get_name() const
Definition: decl/alm.hpp:142
unsigned penalty_reduced
The number of times that the penalty update factor ALMParams::Δ was reduced, that the tolerance updat...
Definition: decl/alm.hpp:110
ALMSolver(Params params, const InnerSolver &inner_solver)
Definition: decl/alm.hpp:137
real_t δ
Final dual tolerance or constraint violation that was reached:
Definition: decl/alm.hpp:121
Stats operator()(const Problem &problem, rvec y, rvec x)
Definition: alm.hpp:16
real_t norm_penalty
2-norm of the final penalty factors .
Definition: decl/alm.hpp:123
unsigned initial_penalty_reduced
The number of times that the initial penalty factor was reduced by ALMParams::Σ₀_lower and that the i...
Definition: decl/alm.hpp:100
InnerStatsAccumulator< typename InnerSolver::Stats > inner
The statistics of the inner solver invocations, accumulated over all ALM iterations.
Definition: decl/alm.hpp:131
unsigned inner_convergence_failures
The total number of times that the inner solver failed to converge.
Definition: decl/alm.hpp:112
void stop()
Abort the computation and return the result so far.
Definition: decl/alm.hpp:148
real_t ε
Final primal tolerance that was reached, depends on the stopping criterion used by the inner solver,...
Definition: decl/alm.hpp:116
const Params & get_params() const
Definition: decl/alm.hpp:150
unsigned outer_iterations
Total number of outer ALM iterations (i.e.
Definition: decl/alm.hpp:90
std::chrono::microseconds elapsed_time
Total elapsed time.
Definition: decl/alm.hpp:92
InnerSolverT InnerSolver
Definition: decl/alm.hpp:85
ALMSolver(Params params, InnerSolver &&inner_solver)
Definition: decl/alm.hpp:134
InnerSolver inner_solver
Definition: decl/alm.hpp:156
SolverStatus status
Whether the solver converged or not.
Definition: decl/alm.hpp:127
real_t Δ_lower
Factor to reduce ALMParams::Δ when inner convergence fails.
Definition: decl/alm.hpp:21
real_t Σ_min
Minimum penalty factor (used during initialization).
Definition: decl/alm.hpp:50
real_t ε₀_increase
Factor to increase the initial primal tolerance if convergence fails in the first iteration.
Definition: decl/alm.hpp:37
real_t θ
Error tolerance for penalty increase.
Definition: decl/alm.hpp:44
real_t ε₀
Initial primal tolerance.
Definition: decl/alm.hpp:34
unsigned max_total_num_retries
Combined limit for ALMParams::max_num_initial_retries and ALMParams::max_num_retries.
Definition: decl/alm.hpp:65
real_t Δ
Factor used in updating the penalty parameters.
Definition: decl/alm.hpp:19
real_t Σ₀_lower
Factor to reduce the initial penalty factor by if convergence fails in in the first iteration.
Definition: decl/alm.hpp:32
real_t δ
Dual tolerance.
Definition: decl/alm.hpp:17
constexpr real_t inf
Definition: vec.hpp:26
real_t σ₀
Initial penalty parameter factor.
Definition: decl/alm.hpp:29
real_t ρ
Update factor for primal tolerance.
Definition: decl/alm.hpp:39
unsigned int max_iter
Maximum number of outer ALM iterations.
Definition: decl/alm.hpp:52
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
Definition: solverstatus.hpp:7
@ Unknown
Initial value.
std::chrono::microseconds max_time
Maximum duration.
Definition: decl/alm.hpp:54
unsigned max_num_retries
How many times can the penalty update factor ALMParams::Δ and the primal tolerance factor ALMParams::...
Definition: decl/alm.hpp:62
real_t Σ₀
Initial penalty parameter.
Definition: decl/alm.hpp:26
real_t ε
Primal tolerance.
Definition: decl/alm.hpp:15
unsigned max_num_initial_retries
How many times can the initial penalty ALMParams::Σ₀ or ALMParams::σ₀ and the initial primal toleranc...
Definition: decl/alm.hpp:59
double real_t
Default floating point type.
Definition: vec.hpp:8
unsigned print_interval
When to print progress.
Definition: decl/alm.hpp:69
real_t ρ_increase
Factor to increase the primal tolerance update factor by if convergence fails.
Definition: decl/alm.hpp:42
bool preconditioning
Apply preconditioning to the problem, based on the gradients in the starting point.
Definition: decl/alm.hpp:73
bool single_penalty_factor
Use one penalty factor for all m constraints.
Definition: decl/alm.hpp:75
real_t Σ_max
Maximum penalty factor.
Definition: decl/alm.hpp:48
real_t M
Lagrange multiplier bound.
Definition: decl/alm.hpp:46
Eigen::Ref< vec > rvec
Default type for mutable references to vectors.
Definition: vec.hpp:16
Parameters for the Augmented Lagrangian solver.
Definition: decl/alm.hpp:13
problem
Definition: main.py:16
Problem description for minimization problems.