alpaqa pantr
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,
18 rvec old_e, real_t norm_e,
19 real_t old_norm_e, crvec Σ_old, rvec Σ,
20 bool monotone) {
21 const real_t θ = params.rel_penalty_increase_threshold;
22 if (norm_e <= params.dual_tolerance) {
23 Σ = Σ_old;
24 return;
25 }
26 if (params.single_penalty_factor) {
27 if (first_iter || norm_e > θ * old_norm_e) {
28 real_t new_Σ = std::fmin(params.max_penalty, Δ * Σ_old(0));
29 Σ.setConstant(new_Σ);
30 } else {
31 Σ = Σ_old;
32 }
33 } else {
34 for (index_t i = 0; i < e.rows(); ++i) {
35 if (first_iter || std::abs(e(i)) > θ * std::abs(old_e(i))) {
36 Σ(i) = std::fmin(params.max_penalty,
37 std::fmax(Δ * std::abs(e(i)) / norm_e,
38 real_t(1) * monotone) *
39 Σ_old(i));
40 } else {
41 Σ(i) = Σ_old(i);
42 }
43 }
44 }
45 }
46
48 const ALMParams<config_t> &params, crvec x0,
49 rvec Σ) {
50 real_t f0 = p.eval_f(x0);
51 vec g0(p.get_m());
52 p.eval_g(x0, g0);
53 // TODO: reuse evaluations of f ang g in PANOC?
54 real_t σ = params.initial_penalty_factor *
55 std::max(real_t(1), std::abs(f0)) /
56 std::max(real_t(1), real_t(0.5) * g0.squaredNorm());
57 σ = std::clamp(σ, params.min_penalty, params.max_penalty);
58 Σ.fill(σ);
59 }
60
61#if ALPAQA_WITH_OCP
62 static void initialize_penalty(
63 [[maybe_unused]] const TypeErasedControlProblem<config_t> &p,
64 const ALMParams<config_t> &params, [[maybe_unused]] crvec x0, rvec Σ) {
65 real_t σ = 1;
66 σ = std::clamp(σ, params.min_penalty, params.max_penalty);
67 Σ.fill(σ);
68 }
69#endif
70};
71
76#ifdef ALPAQA_WITH_QUAD_PRECISION
77ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ALMHelpers, EigenConfigq);
78#endif
79
80} // namespace alpaqa::detail
Nonlinear optimal control problem with finite horizon .
Definition: ocproblem.hpp:243
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:42
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
Definition: export.hpp:21
real_t initial_penalty_factor
Initial penalty parameter factor.
Definition: alm.hpp:41
real_t min_penalty
Minimum penalty factor (used during initialization).
Definition: alm.hpp:65
real_t dual_tolerance
Dual tolerance (constraint violation and complementarity).
Definition: alm.hpp:26
typename Conf::real_t real_t
Definition: config.hpp:51
real_t max_penalty
Maximum penalty factor.
Definition: alm.hpp:63
typename Conf::index_t index_t
Definition: config.hpp:63
real_t rel_penalty_increase_threshold
Error tolerance for penalty increase.
Definition: alm.hpp:59
typename Conf::rvec rvec
Definition: config.hpp:55
typename Conf::crvec crvec
Definition: config.hpp:56
typename Conf::vec vec
Definition: config.hpp:52
bool single_penalty_factor
Use one penalty factor for all m constraints.
Definition: alm.hpp:89
Parameters for the Augmented Lagrangian solver.
Definition: alm.hpp:20
Double-precision double configuration.
Definition: config.hpp:115
Single-precision float configuration.
Definition: config.hpp:111
long double configuration.
Definition: config.hpp:120
static void initialize_penalty(const TypeErasedControlProblem< config_t > &p, const ALMParams< config_t > &params, crvec x0, rvec Σ)
Definition: alm-helpers.tpp:62
static void initialize_penalty(const TypeErasedProblem< config_t > &p, const ALMParams< config_t > &params, crvec x0, rvec Σ)
Definition: alm-helpers.tpp:47
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, crvec Σ_old, rvec Σ, bool monotone)
Definition: alm-helpers.tpp:16