alpaqa 1.0.0a13
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.
19/// @ingroup grp_Parameters
20template <Config Conf = DefaultConfig>
21struct ALMParams {
23
24 /// Primal tolerance (used for stopping criterion of inner solver).
26 /// Dual tolerance (constraint violation and complementarity).
28 /// Factor used in updating the penalty parameters.
30 /// Initial penalty parameter. When set to zero (which is the default),
31 /// it is computed automatically, based on the constraint violation in the
32 /// starting point and the parameter @ref initial_penalty_factor.
33 /// @todo Change default to 0.
35 /// Initial penalty parameter factor. Active if @ref initial_penalty is set
36 /// to zero.
38 /// Initial primal tolerance.
40 /// Update factor for primal tolerance.
42 /// Error tolerance for penalty increase.
44 /// Lagrange multiplier bound.
46 /// Maximum penalty factor.
48 /// Minimum penalty factor (used during initialization).
50 /// Maximum number of outer ALM iterations.
51 unsigned int max_iter = 100;
52 /// Maximum duration.
53 std::chrono::nanoseconds max_time = std::chrono::minutes(5);
54
55 /// When to print progress. If set to zero, nothing will be printed.
56 /// If set to N != 0, progress is printed every N iterations.
57 unsigned print_interval = 0;
58 /// The precision of the floating point values printed by the solver.
59 int print_precision = std::numeric_limits<real_t>::max_digits10 / 2;
60
61 /// Use one penalty factor for all m constraints.
63};
64
65/// Augmented Lagrangian Method solver
66///
67/// @ingroup grp_ALMSolver
68template <class InnerSolverT>
69class ALMSolver {
70 public:
71 USING_ALPAQA_CONFIG_TEMPLATE(InnerSolverT::config_t);
72
75 using Problem = typename InnerSolver::Problem;
76
77 struct Stats {
78 /// Total number of outer ALM iterations (i.e. the number of times that
79 /// the inner solver was invoked).
80 unsigned outer_iterations = 0;
81 /// Total elapsed time.
82 std::chrono::nanoseconds elapsed_time{};
83 /// The total number of times that the inner solver failed to converge.
85 /// Final primal tolerance that was reached, depends on the stopping
86 /// criterion used by the inner solver, see for example
87 /// @ref PANOCStopCrit.
89 /// Final dual tolerance or constraint violation that was reached:
90 /// @f[
91 /// \delta = \| \Pi_D\left(g(x^k) + \Sigma^{-1}y\right) \|_\infty
92 /// @f]
94 /// 2-norm of the final penalty factors @f$ \| \Sigma \|_2 @f$.
96
97 /// Whether the solver converged or not.
98 /// @see @ref SolverStatus
100
101 /// The statistics of the inner solver invocations, accumulated over all
102 /// ALM iterations.
104 };
105
111
112 Stats operator()(const Problem &problem, rvec x, rvec y,
113 std::optional<rvec> Σ = std::nullopt);
114 template <class P>
115 Stats operator()(const P &problem, rvec x, rvec y,
116 std::optional<rvec> Σ = std::nullopt) {
117 return operator()(Problem{&problem}, x, y, Σ);
118 }
119
120 std::string get_name() const {
121 return "ALMSolver<" + inner_solver.get_name() + ">";
122 }
123
124 /// Abort the computation and return the result so far.
125 /// Can be called from other threads or signal handlers.
126 void stop() { inner_solver.stop(); }
127
128 const Params &get_params() const { return params; }
129
130 private:
133
134 public:
136 std::ostream *os = &std::cout;
137};
138
143
144} // namespace alpaqa
Augmented Lagrangian Method solver.
Definition alm.hpp:69
Params params
Definition alm.hpp:131
std::string get_name() const
Definition alm.hpp:120
ALMSolver(Params params, const InnerSolver &inner_solver)
Definition alm.hpp:109
real_t δ
Final dual tolerance or constraint violation that was reached:
Definition alm.hpp:93
real_t norm_penalty
2-norm of the final penalty factors .
Definition alm.hpp:95
typename InnerSolver::Problem Problem
Definition alm.hpp:75
std::chrono::nanoseconds elapsed_time
Total elapsed time.
Definition alm.hpp:82
InnerStatsAccumulator< typename InnerSolver::Stats > inner
The statistics of the inner solver invocations, accumulated over all ALM iterations.
Definition alm.hpp:103
unsigned inner_convergence_failures
The total number of times that the inner solver failed to converge.
Definition alm.hpp:84
void stop()
Abort the computation and return the result so far.
Definition alm.hpp:126
real_t ε
Final primal tolerance that was reached, depends on the stopping criterion used by the inner solver,...
Definition alm.hpp:88
const Params & get_params() const
Definition alm.hpp:128
unsigned outer_iterations
Total number of outer ALM iterations (i.e.
Definition alm.hpp:80
Stats operator()(const P &problem, rvec x, rvec y, std::optional< rvec > Σ=std::nullopt)
Definition alm.hpp:115
InnerSolverT InnerSolver
Definition alm.hpp:74
ALMSolver(Params params, InnerSolver &&inner_solver)
Definition alm.hpp:106
InnerSolver inner_solver
Definition alm.hpp:135
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:99
std::ostream * os
Definition alm.hpp:136
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:56
#define ALPAQA_IF_QUADF(...)
Definition config.hpp:182
#define ALPAQA_IF_LONGD(...)
Definition config.hpp:194
#define ALPAQA_IF_FLOAT(...)
Definition config.hpp:188
#define USING_ALPAQA_CONFIG_TEMPLATE(Conf)
Definition config.hpp:60
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
Definition export.hpp:21
real_t max_multiplier
Lagrange multiplier bound.
Definition alm.hpp:45
real_t initial_penalty_factor
Initial penalty parameter factor.
Definition alm.hpp:37
real_t tolerance
Primal tolerance (used for stopping criterion of inner solver).
Definition alm.hpp:25
real_t tolerance_update_factor
Update factor for primal tolerance.
Definition alm.hpp:41
real_t penalty_update_factor
Factor used in updating the penalty parameters.
Definition alm.hpp:29
unsigned int max_iter
Maximum number of outer ALM iterations.
Definition alm.hpp:51
real_t min_penalty
Minimum penalty factor (used during initialization).
Definition alm.hpp:49
real_t dual_tolerance
Dual tolerance (constraint violation and complementarity).
Definition alm.hpp:27
real_t max_penalty
Maximum penalty factor.
Definition alm.hpp:47
real_t initial_tolerance
Initial primal tolerance.
Definition alm.hpp:39
std::chrono::nanoseconds max_time
Maximum duration.
Definition alm.hpp:53
real_t rel_penalty_increase_threshold
Error tolerance for penalty increase.
Definition alm.hpp:43
unsigned print_interval
When to print progress.
Definition alm.hpp:57
int print_precision
The precision of the floating point values printed by the solver.
Definition alm.hpp:59
real_t initial_penalty
Initial penalty parameter.
Definition alm.hpp:34
bool single_penalty_factor
Use one penalty factor for all m constraints.
Definition alm.hpp:62
Parameters for the Augmented Lagrangian solver.
Definition alm.hpp:21
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
@ Busy
In progress.
typename Conf::real_t real_t
Definition config.hpp:65
constexpr const auto inf
Definition config.hpp:85
typename Conf::rvec rvec
Definition config.hpp:69
Double-precision double configuration.
Definition config.hpp:135
Single-precision float configuration.
Definition config.hpp:131
long double configuration.
Definition config.hpp:140