9#include <guanaqo/atomic-stop-signal.hpp>
10#include <guanaqo/not-implemented.hpp>
36 err_z += y.cwiseQuotient(Σ);
40 err_z -= y.cwiseQuotient(Σ);
58 throw std::out_of_range(
"Invalid PANOCStopCrit");
79 auto err = (1 / γ) * pₖ + (grad_ψₖ - grad_̂ψₖ);
85 auto err = (1 / γ) * pₖ + (grad_ψₖ - grad_̂ψₖ);
99 return norm_inf(work_n2);
104 return work_n2.norm();
107 return norm_inf(pₖ) / γ;
110 return pₖ.norm() / γ;
116 auto err = norm_inf(work_n2);
117 auto n = 2 * (ŷₖ.size() + x̂ₖ.size());
122 auto C_lagr_mult = norm_1(work_n2);
123 auto D_lagr_mult = norm_1(ŷₖ);
127 std::max(s_max, (C_lagr_mult + D_lagr_mult) / s_n) / s_max;
133 return norm_inf(work_n2) / std::fmax(
real_t(1), xₖ.norm());
137 throw std::out_of_range(
"Invalid PANOCStopCrit");
160 real_t rounding_tolerance,
193 real_t margin = (1 + std::abs(ψₖ)) * rounding_tolerance;
194 while (ψx̂ₖ - ψₖ > grad_ψₖᵀpₖ +
real_t(0.5) * Lₖ * norm_sq_pₖ + margin) {
195 if (not(Lₖ * 2 <= L_max))
204 grad_ψₖᵀpₖ = grad_ψₖ.dot(pₖ);
205 norm_sq_pₖ = pₖ.squaredNorm();
216 template <
class ParamsT,
class DurationT>
223 DurationT time_elapsed,
227 const guanaqo::AtomicStopSignal &stop_signal,
231 unsigned no_progress) {
233 auto max_time =
params.max_time;
235 max_time = std::min(max_time, *opts.
max_time);
237 bool out_of_time = time_elapsed > max_time;
238 bool out_of_iter = iteration ==
params.max_iter;
239 bool interrupted = stop_signal.stop_requested();
240 bool not_finite = not std::isfinite(εₖ);
241 bool converged = εₖ <= tolerance;
242 bool max_no_progress = no_progress >
params.max_no_progress;
278 real_t cbrt_ε = std::cbrt(std::numeric_limits<real_t>::epsilon());
279 real_t h = cbrt_ε * (1 + xₖ.norm());
322 x, y, Σ, grad_ψ, work_n, work_m);
326 .select((ε * grad_ψ).cwiseMax(δ), (ε * grad_ψ).cwiseMin(-δ));
331 work_x, y, Σ, work_grad_ψ, work_n, work_m);
334 real_t L = (work_grad_ψ - grad_ψ).norm() / norm_h;
335 return std::clamp(L, L_min, L_max);
368 auto h = (xₖ * ε).cwiseAbs().cwiseMax(δ);
373 work_n1, y, Σ, work_n2, work_n3, work_m);
376 xₖ, y, Σ, grad_ψ, work_n1, work_m);
379 real_t L = (work_n2 - grad_ψ).norm() / norm_h;
380 return std::clamp(L, L_min, L_max);
The main polymorphic minimization problem interface.
void eval_constraints(crvec x, rvec gx) const
[Required] Function that evaluates the constraints,
real_t eval_augmented_lagrangian_and_gradient(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
[Optional] Calculate both ψ(x) and its gradient ∇ψ(x).
length_t get_num_constraints() const
[Required] Number of constraints.
void eval_augmented_lagrangian_gradient(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
[Optional] Calculate the gradient ∇ψ(x).
void eval_projecting_difference_constraints(crvec z, rvec e) const
[Required] Function that evaluates the difference between the given point and its projection onto th...
real_t eval_augmented_lagrangian(crvec x, crvec y, crvec Σ, rvec ŷ) const
[Optional] Calculate both ψ(x) and the vector ŷ that can later be used to compute ∇ψ.
real_t eval_proximal_gradient_step(real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p) const
[Required] Function that computes a proximal gradient step.
#define USING_ALPAQA_CONFIG(Conf)
#define ALPAQA_IF_QUADF(...)
#define ALPAQA_IF_LONGD(...)
#define ALPAQA_IF_FLOAT(...)
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
auto norm_inf(const Eigen::MatrixBase< Derived > &v)
Get the maximum or infinity-norm of the given vector.
auto norm_1(const Eigen::MatrixBase< Derived > &v)
Get the 1-norm of the given vector.
@ LBFGSBpp
The stopping criterion used by LBFGS++, see https://lbfgspp.statr.me/doc/classLBFGSpp_1_1LBFGSBParam....
@ ProjGradUnitNorm
∞-norm of the projected gradient with unit step size:
@ ProjGradNorm
∞-norm of the projected gradient with step size γ:
@ Ipopt
The stopping criterion used by Ipopt, see https://link.springer.com/article/10.1007/s10107-004-0559-y...
@ FPRNorm2
2-norm of fixed point residual:
@ ProjGradNorm2
2-norm of the projected gradient with step size γ:
@ ApproxKKT
Find an ε-approximate KKT point in the ∞-norm:
@ FPRNorm
∞-norm of fixed point residual:
@ ApproxKKT2
Find an ε-approximate KKT point in the 2-norm:
@ ProjGradUnitNorm2
2-norm of the projected gradient with unit step size:
std::optional< std::chrono::nanoseconds > max_time
Maximum run time (in addition to the inner solver's own timeout).
real_t tolerance
Desired tolerance (overrides the solver's own tolerance).
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
@ Interrupted
Solver was interrupted by the user.
@ MaxTime
Maximum allowed execution time exceeded.
@ NoProgress
No progress was made in the last iteration.
@ MaxIter
Maximum number of iterations exceeded.
@ Converged
Converged and reached given tolerance.
@ NotFinite
Intermediate results were infinite or not-a-number.
typename Conf::real_t real_t
typename Conf::crvec crvec
Double-precision double configuration.
Single-precision float configuration.
long double configuration.
static real_t descent_lemma(const Problem &problem, real_t rounding_tolerance, real_t L_max, crvec xₖ, real_t ψₖ, crvec grad_ψₖ, crvec y, crvec Σ, rvec x̂ₖ, rvec pₖ, rvec ŷx̂ₖ, real_t &ψx̂ₖ, real_t &norm_sq_pₖ, real_t &grad_ψₖᵀpₖ, real_t &Lₖ, real_t &γₖ)
Increase the estimate of the Lipschitz constant of the objective gradient and decrease the step size ...
static bool stop_crit_requires_grad_ψx̂(PANOCStopCrit crit)
static real_t initial_lipschitz_estimate(const Problem &problem, crvec x, crvec y, crvec Σ, real_t ε, real_t δ, real_t L_min, real_t L_max, real_t &ψ, rvec grad_ψ, rvec work_x, rvec work_grad_ψ, rvec work_n, rvec work_m)
Estimate the Lipschitz constant of the gradient using finite differences.
static real_t calc_error_stop_crit(const Problem &problem, PANOCStopCrit crit, crvec pₖ, real_t γ, crvec xₖ, crvec x̂ₖ, crvec ŷₖ, crvec grad_ψₖ, crvec grad_̂ψₖ, rvec work_n1, rvec work_n2)
Compute the ε from the stopping criterion, see PANOCStopCrit.
static real_t initial_lipschitz_estimate(const Problem &problem, crvec xₖ, crvec y, crvec Σ, real_t ε, real_t δ, real_t L_min, real_t L_max, rvec grad_ψ, rvec work_n1, rvec work_n2, rvec work_n3, rvec work_m)
Estimate the Lipschitz constant of the gradient using finite differences.
alpaqa::Box< config_t > Box
static void calc_err_z(const Problem &p, crvec x̂, crvec y, crvec Σ, rvec err_z)
Calculate the error between ẑ and g(x).
static void calc_augmented_lagrangian_hessian_prod_fd(const Problem &problem, crvec xₖ, crvec y, crvec Σ, crvec grad_ψ, crvec v, rvec Hv, rvec work_n1, rvec work_n2, rvec work_m)
Compute the Hessian matrix of the augmented Lagrangian function multiplied by the given vector,...
alpaqa::TypeErasedProblem< config_t > Problem
static SolverStatus check_all_stop_conditions(const ParamsT ¶ms, const InnerSolveOptions< config_t > &opts, DurationT time_elapsed, unsigned iteration, const guanaqo::AtomicStopSignal &stop_signal, real_t εₖ, unsigned no_progress)
Check all stop conditions (required tolerance reached, out of time, maximum number of iterations exce...