alpaqa 1.0.0a17
Nonconvex constrained optimization
Loading...
Searching...
No Matches
alm-helpers.tpp
Go to the documentation of this file.
1#pragma once
2
4#if ALPAQA_WITH_OCP
6#endif
7
8#include <algorithm>
9
10namespace alpaqa::detail {
11
12template <Config Conf>
13struct ALMHelpers {
15
17 real_t Δ, bool first_iter, rvec e,
21 if (norm_e <= params.dual_tolerance) {
22 return;
23 }
24 if (params.single_penalty_factor) {
25 if (first_iter || norm_e > θ * old_norm_e) {
26 real_t new_Σ = std::fmin(params.max_penalty, Δ * Σ(0));
27 Σ.setConstant(new_Σ);
28 }
29 } else {
30 for (index_t i = 0; i < e.rows(); ++i) {
31 if (first_iter || std::abs(e(i)) > θ * std::abs(old_e(i))) {
32 Σ(i) = std::fmin(
33 params.max_penalty,
34 std::fmax(Δ * std::abs(e(i)) / norm_e, real_t(1)) *
35 Σ(i));
36 }
37 }
38 }
39 }
40
42 const ALMParams<config_t> &params, crvec x0,
43 rvec Σ) {
44 real_t f0 = p.eval_f(x0);
45 vec g0(p.get_m());
46 p.eval_g(x0, g0);
47 // TODO: reuse evaluations of f ang g in PANOC?
49 std::max(real_t(1), std::abs(f0)) /
50 std::max(real_t(1), real_t(0.5) * g0.squaredNorm());
51 σ = std::clamp(σ, params.min_penalty, params.max_penalty);
52 Σ.setConstant(σ);
53 }
54
55#if ALPAQA_WITH_OCP
56 static void initialize_penalty(
58 const ALMParams<config_t> &params, [[maybe_unused]] crvec x0, rvec Σ) {
59 real_t σ = 1;
60 σ = std::clamp(σ, params.min_penalty, params.max_penalty);
61 Σ.setConstant(σ);
62 }
63#endif
64};
65
66// clang-format off
71// clang-format on
72
73} // namespace alpaqa::detail
Nonlinear optimal control problem with finite horizon .
The main polymorphic minimization problem interface.
length_t get_m() const
[Required] Number of constraints.
real_t eval_f(crvec x) const
[Required] Function that evaluates the cost,
void eval_g(crvec x, rvec gx) const
[Required] Function that evaluates the constraints,
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:77
#define ALPAQA_IF_QUADF(...)
Definition config.hpp:221
#define ALPAQA_IF_LONGD(...)
Definition config.hpp:233
#define ALPAQA_IF_FLOAT(...)
Definition config.hpp:227
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
Definition export.hpp:21
real_t initial_penalty_factor
Initial penalty parameter factor.
Definition alm.hpp:37
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 rel_penalty_increase_threshold
Error tolerance for penalty increase.
Definition alm.hpp:43
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
typename Conf::real_t real_t
Definition config.hpp:86
typename Conf::index_t index_t
Definition config.hpp:104
constexpr const auto inf
Definition config.hpp:112
typename Conf::rvec rvec
Definition config.hpp:91
typename Conf::crvec crvec
Definition config.hpp:92
typename Conf::vec vec
Definition config.hpp:88
Double-precision double configuration.
Definition config.hpp:174
Single-precision float configuration.
Definition config.hpp:170
long double configuration.
Definition config.hpp:179
static void initialize_penalty(const TypeErasedControlProblem< config_t > &p, const ALMParams< config_t > &params, crvec x0, rvec Σ)
static void update_penalty_weights(const ALMParams< config_t > &params, real_t Δ, bool first_iter, rvec e, rvec old_e, real_t norm_e, real_t old_norm_e, rvec Σ)
static void initialize_penalty(const TypeErasedProblem< config_t > &p, const ALMParams< config_t > &params, crvec x0, rvec Σ)