alpaqa 1.0.0a8
Nonconvex constrained optimization
Loading...
Searching...
No Matches
kkt-error.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <numeric>
5
6namespace alpaqa {
7
8template <Config Conf>
9struct KKTError {
11 static constexpr auto NaN = alpaqa::NaN<config_t>;
13};
14
15template <Config Conf>
18
20 const auto n = x.size(), m = y.size();
21 vec z(n), grad_Lx(n), work(n), g(m), e(m);
22 // Gradient of Lagrangian, ∇ℒ(x,y) = ∇f(x) + ∇g(x) y
23 problem.eval_grad_L(x, y, grad_Lx, work);
24 // Eliminate normal cone of bound constraints, z = Π(x - ∇ℒ(x,y)) - x
25 problem.eval_prox_grad_step(1, x, grad_Lx, work, z);
26 // Stationarity, ‖Π(x - ∇ℒ(x,y)) - x‖
27 auto stationarity = alpaqa::vec_util::norm_inf(z);
28 // Constraints, g(x)
29 problem.eval_g(x, g);
30 // Distance to feasible set, e = g(x) - Π(g(x))
31 problem.eval_proj_diff_g(g, e);
32 // Constraint violation, ‖g(x) - Π(g(x))‖
33 auto constr_violation = alpaqa::vec_util::norm_inf(e);
34 // Complementary slackness
35 real_t complementarity = std::inner_product(
36 y.begin(), y.end(), e.begin(), real_t(0),
37 [](real_t acc, real_t ye) { return std::fmax(acc, std::abs(ye)); }, std::multiplies<>{});
38 return {.stationarity = stationarity,
39 .constr_violation = constr_violation,
40 .complementarity = complementarity};
41}
42
43} // namespace alpaqa
The main polymorphic minimization problem interface.
real_t eval_prox_grad_step(real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p) const
[Required] Function that computes a proximal gradient step.
void eval_grad_L(crvec x, crvec y, rvec grad_L, rvec work_n) const
[Optional] Evaluate the gradient of the Lagrangian
void eval_g(crvec x, rvec gx) const
[Required] Function that evaluates the constraints,
void eval_proj_diff_g(crvec z, rvec e) const
[Required] Function that evaluates the difference between the given point and its projection onto th...
#define USING_ALPAQA_CONFIG(Conf)
Definition: config.hpp:42
auto norm_inf(const Eigen::MatrixBase< Derived > &v)
Get the maximum or infinity-norm of the given vector.
Definition: config.hpp:151
KKTError< Conf > compute_kkt_error(const alpaqa::TypeErasedProblem< Conf > &problem, alpaqa::crvec< Conf > x, alpaqa::crvec< Conf > y)
Definition: kkt-error.hpp:16
typename Conf::real_t real_t
Definition: config.hpp:51
typename Conf::crvec crvec
Definition: config.hpp:56
typename Conf::vec vec
Definition: config.hpp:52
real_t complementarity
Definition: kkt-error.hpp:12
static constexpr auto NaN
Definition: kkt-error.hpp:11
real_t stationarity
Definition: kkt-error.hpp:12
real_t constr_violation
Definition: kkt-error.hpp:12