9#include <guanaqo/not-implemented.hpp>
10#include <guanaqo/required-method.hpp>
11#include <guanaqo/type-erasure.hpp>
18using guanaqo::not_implemented_error;
124 ALPAQA_EXPORT static
void
128 ALPAQA_EXPORT static
void
132 ALPAQA_EXPORT static Sparsity
149 ALPAQA_EXPORT static
void
153 ALPAQA_EXPORT static
real_t
166 ProblemVTable(std::in_place_t, P &p) : guanaqo::BasicVTable{std::in_place, p} {
167 auto &vtable = *
this;
193 GUANAQO_TE_OPTIONAL_METHOD(vtable, P,
204 GUANAQO_TE_OPTIONAL_METHOD(vtable, P,
check, p);
205 GUANAQO_TE_OPTIONAL_METHOD(vtable, P,
get_name, p);
208 vtable.n = p.get_num_variables();
209 vtable.m = p.get_num_constraints();
243 using TypeErased = guanaqo::TypeErased<VTable, allocator_type>;
244 using TypeErased::TypeErased;
247 using TypeErased::call;
248 using TypeErased::self;
249 using TypeErased::vtable;
252 template <
class T,
class... Args>
492 rvec H_values)
const;
517 rvec grad_gxy)
const;
596 return vtable.eval_inactive_indices_res_lna != vtable.default_eval_inactive_indices_res_lna;
601 return vtable.eval_constraints_jacobian != vtable.default_eval_constraints_jacobian;
606 return vtable.get_constraints_jacobian_sparsity !=
607 vtable.default_get_constraints_jacobian_sparsity;
612 return vtable.eval_grad_gi != vtable.default_eval_grad_gi;
617 return vtable.eval_lagrangian_hessian_product !=
618 vtable.default_eval_lagrangian_hessian_product;
623 return vtable.eval_lagrangian_hessian != vtable.default_eval_lagrangian_hessian;
628 return vtable.get_lagrangian_hessian_sparsity !=
629 vtable.default_get_lagrangian_hessian_sparsity;
634 return vtable.eval_augmented_lagrangian_hessian_product !=
635 vtable.default_eval_augmented_lagrangian_hessian_product;
640 return vtable.eval_augmented_lagrangian_hessian !=
641 vtable.default_eval_augmented_lagrangian_hessian;
646 return vtable.get_augmented_lagrangian_hessian_sparsity !=
647 vtable.default_get_augmented_lagrangian_hessian_sparsity;
652 return vtable.eval_objective_and_gradient != vtable.default_eval_objective_and_gradient;
657 return vtable.eval_objective_and_constraints !=
658 vtable.default_eval_objective_and_constraints;
663 return vtable.eval_objective_gradient_and_constraints_gradient_product !=
664 vtable.default_eval_objective_gradient_and_constraints_gradient_product;
669 return vtable.eval_lagrangian_gradient != vtable.default_eval_lagrangian_gradient;
674 return vtable.eval_augmented_lagrangian != vtable.default_eval_augmented_lagrangian;
679 return vtable.eval_augmented_lagrangian_gradient !=
680 vtable.default_eval_augmented_lagrangian_gradient;
685 return vtable.eval_augmented_lagrangian_and_gradient !=
686 vtable.default_eval_augmented_lagrangian_and_gradient;
691 return vtable.get_variable_bounds != vtable.default_get_variable_bounds;
696 return vtable.get_general_bounds != vtable.default_get_general_bounds;
699 [[nodiscard]]
bool provides_check()
const {
return vtable.check != vtable.default_check; }
702 return vtable.get_name != vtable.default_get_name;
757template <
class Tref,
class Allocator>
762template <Config Conf,
class Allocator>
766template <Config Conf,
class Allocator>
771template <Config Conf,
class Allocator>
774 return call(vtable.eval_projecting_difference_constraints, z, e);
776template <Config Conf,
class Allocator>
778 return call(vtable.eval_projection_multipliers, y, M);
780template <Config Conf,
class Allocator>
784 return call(vtable.eval_proximal_gradient_step, γ, x, grad_ψ, x̂, p);
786template <Config Conf,
class Allocator>
789 return call(vtable.eval_inactive_indices_res_lna, γ, x, grad_ψ, J);
791template <Config Conf,
class Allocator>
793 return call(vtable.eval_objective, x);
795template <Config Conf,
class Allocator>
797 return call(vtable.eval_objective_gradient, x, grad_fx);
799template <Config Conf,
class Allocator>
801 return call(vtable.eval_constraints, x, gx);
803template <Config Conf,
class Allocator>
805 rvec grad_gxy)
const {
806 return call(vtable.eval_constraints_gradient_product, x, y, grad_gxy);
808template <Config Conf,
class Allocator>
810 return call(vtable.eval_grad_gi, x, i, grad_gi);
812template <Config Conf,
class Allocator>
814 return call(vtable.eval_constraints_jacobian, x, J_values);
816template <Config Conf,
class Allocator>
818 return call(vtable.get_constraints_jacobian_sparsity);
820template <Config Conf,
class Allocator>
824 return call(vtable.eval_lagrangian_hessian_product, x, y, scale, v, Hv);
826template <Config Conf,
class Allocator>
828 rvec H_values)
const {
829 return call(vtable.eval_lagrangian_hessian, x, y, scale, H_values);
831template <Config Conf,
class Allocator>
833 return call(vtable.get_lagrangian_hessian_sparsity);
835template <Config Conf,
class Allocator>
838 return call(vtable.eval_augmented_lagrangian_hessian_product, x, y, Σ, scale, v, Hv);
840template <Config Conf,
class Allocator>
843 rvec H_values)
const {
844 return call(vtable.eval_augmented_lagrangian_hessian, x, y, Σ, scale, H_values);
846template <Config Conf,
class Allocator>
849 return call(vtable.get_augmented_lagrangian_hessian_sparsity);
851template <Config Conf,
class Allocator>
854 return call(vtable.eval_objective_and_gradient, x, grad_fx);
856template <Config Conf,
class Allocator>
859 return call(vtable.eval_objective_and_constraints, x, g);
861template <Config Conf,
class Allocator>
864 return call(vtable.eval_objective_gradient_and_constraints_gradient_product, x, y, grad_f,
867template <Config Conf,
class Allocator>
870 return call(vtable.eval_lagrangian_gradient, x, y, grad_L, work_n);
872template <Config Conf,
class Allocator>
875 return call(vtable.eval_augmented_lagrangian, x, y, Σ, ŷ);
877template <Config Conf,
class Allocator>
882 return call(vtable.eval_augmented_lagrangian_gradient, x, y, Σ, grad_ψ, work_n, work_m);
884template <Config Conf,
class Allocator>
887 return call(vtable.eval_augmented_lagrangian_and_gradient, x, y, Σ, grad_ψ, work_n, work_m);
889template <Config Conf,
class Allocator>
891 return call(vtable.calc_ŷ_dᵀŷ, g_ŷ, y, Σ);
893template <Config Conf,
class Allocator>
895 return call(vtable.get_variable_bounds);
897template <Config Conf,
class Allocator>
899 return call(vtable.get_general_bounds);
901template <Config Conf,
class Allocator>
903 return call(vtable.check);
905template <Config Conf,
class Allocator>
907 return call(vtable.get_name);
913template <Config Conf>
The main polymorphic minimization problem interface.
void eval_constraints(crvec x, rvec gx) const
[Required] Function that evaluates the constraints,
std::string get_name() const
[Optional] Get a descriptive name for the problem.
bool provides_eval_constraints_jacobian() const
Returns true if the problem provides an implementation of eval_constraints_jacobian.
Sparsity get_lagrangian_hessian_sparsity() const
[Optional] Function that returns (a view of) the sparsity pattern of the Hessian of the Lagrangian.
void eval_grad_gi(crvec x, index_t i, rvec grad_gi) const
[Optional] Function that evaluates the gradient of one specific constraint,
void eval_lagrangian_hessian_product(crvec x, crvec y, real_t scale, crvec v, rvec Hv) const
[Optional] Function that evaluates the Hessian of the Lagrangian multiplied by a vector,
std::allocator< std::byte > allocator_type
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).
void eval_lagrangian_hessian(crvec x, crvec y, real_t scale, rvec H_values) const
[Optional] Function that evaluates the nonzero values of the Hessian of the Lagrangian,
bool provides_eval_augmented_lagrangian() const
Returns true if the problem provides a specialized implementation of eval_augmented_lagrangian,...
real_t eval_objective_and_gradient(crvec x, rvec grad_fx) const
[Optional] Evaluate both and its gradient, .
void eval_projection_multipliers(rvec y, real_t M) const
[Required] Function that projects the Lagrange multipliers for ALM.
bool provides_check() const
Returns true if the problem provides an implementation of check.
void check() const
[Optional] Check that the problem formulation is well-defined, the dimensions match,...
bool provides_eval_objective_and_gradient() const
Returns true if the problem provides a specialized implementation of eval_objective_and_gradient,...
bool provides_eval_augmented_lagrangian_and_gradient() const
Returns true if the problem provides a specialized implementation of eval_augmented_lagrangian_and_gr...
const Box & get_variable_bounds() const
[Optional] Get the rectangular constraint set of the decision variables, .
void eval_constraints_jacobian(crvec x, rvec J_values) const
[Optional] Function that evaluates the nonzero values of the Jacobian matrix of the constraints,
bool provides_eval_inactive_indices_res_lna() const
Returns true if the problem provides an implementation of eval_inactive_indices_res_lna.
bool provides_get_name() const
Returns true if the problem provides an implementation of get_name.
void eval_objective_gradient_and_constraints_gradient_product(crvec x, crvec y, rvec grad_f, rvec grad_gxy) const
[Optional] Evaluate both and .
bool provides_eval_objective_gradient_and_constraints_gradient_product() const
Returns true if the problem provides a specialized implementation of eval_objective_gradient_and_cons...
bool provides_eval_objective_and_constraints() const
Returns true if the problem provides a specialized implementation of eval_objective_and_constraints,...
ProblemVTable< config_t > VTable
real_t eval_objective(crvec x) const
[Required] Function that evaluates the cost,
length_t get_num_constraints() const
[Required] Number of constraints.
void eval_augmented_lagrangian_hessian_product(crvec x, crvec y, crvec Σ, real_t scale, crvec v, rvec Hv) const
[Optional] Function that evaluates the Hessian of the augmented Lagrangian multiplied by a vector,
bool provides_get_lagrangian_hessian_sparsity() const
Returns true if the problem provides an implementation of get_lagrangian_hessian_sparsity.
static TypeErasedProblem make(Args &&...args)
index_t eval_inactive_indices_res_lna(real_t γ, crvec x, crvec grad_ψ, rindexvec J) const
[Optional] Function that computes the inactive indices for the evaluation of the linear Newton appro...
bool supports_eval_augmented_lagrangian_hessian() const
Returns true if eval_augmented_lagrangian_hessian can be called.
bool provides_eval_lagrangian_hessian_product() const
Returns true if the problem provides an implementation of eval_lagrangian_hessian_product.
bool provides_get_constraints_jacobian_sparsity() const
Returns true if the problem provides an implementation of get_constraints_jacobian_sparsity.
length_t get_num_variables() const
[Required] Number of decision variables.
void eval_lagrangian_gradient(crvec x, crvec y, rvec grad_L, rvec work_n) const
[Optional] Evaluate the gradient of the Lagrangian
Sparsity get_constraints_jacobian_sparsity() const
[Optional] Function that returns (a view of) the sparsity pattern of the Jacobian of the 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).
const Box & get_general_bounds() const
[Optional] Get the rectangular constraint set of the general constraint function, .
void eval_augmented_lagrangian_hessian(crvec x, crvec y, crvec Σ, real_t scale, rvec H_values) const
[Optional] Function that evaluates the nonzero values of the Hessian of the augmented Lagrangian,
bool provides_eval_augmented_lagrangian_hessian() const
Returns true if the problem provides an implementation of eval_augmented_lagrangian_hessian.
alpaqa::Box< config_t > Box
real_t eval_objective_and_constraints(crvec x, rvec g) const
[Optional] Evaluate both and .
bool provides_eval_augmented_lagrangian_gradient() const
Returns true if the problem provides a specialized implementation of eval_augmented_lagrangian_gradie...
bool provides_get_variable_bounds() const
Returns true if the problem provides an implementation of get_variable_bounds.
bool provides_eval_grad_gi() const
Returns true if the problem provides an implementation of eval_grad_gi.
guanaqo::TypeErased< VTable, allocator_type > TypeErased
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...
void eval_objective_gradient(crvec x, rvec grad_fx) const
[Required] Function that evaluates the gradient of the cost,
bool provides_eval_augmented_lagrangian_hessian_product() const
Returns true if the problem provides an implementation of eval_augmented_lagrangian_hessian_product.
bool provides_get_general_bounds() const
Returns true if the problem provides an implementation of get_general_bounds.
bool provides_eval_lagrangian_hessian() const
Returns true if the problem provides an implementation of eval_lagrangian_hessian.
void eval_constraints_gradient_product(crvec x, crvec y, rvec grad_gxy) const
[Required] Function that evaluates the gradient of the constraints times a vector,
bool provides_get_augmented_lagrangian_hessian_sparsity() const
Returns true if the problem provides an implementation of get_augmented_lagrangian_hessian_sparsity.
real_t calc_ŷ_dᵀŷ(rvec g_ŷ, crvec y, crvec Σ) const
Given g(x), compute the intermediate results ŷ and dᵀŷ that can later be used to compute ψ(x) and ∇ψ(...
Sparsity get_augmented_lagrangian_hessian_sparsity() const
[Optional] Function that returns (a view of) the sparsity pattern of the Hessian of the augmented Lag...
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 ∇ψ.
bool provides_eval_lagrangian_gradient() const
Returns true if the problem provides a specialized implementation of eval_lagrangian_gradient,...
bool supports_eval_augmented_lagrangian_hessian_product() const
Returns true if eval_augmented_lagrangian_hessian_product can be called.
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(...)
void print_provided_functions(std::ostream &os, const TypeErasedProblem< Conf > &problem)
EigenConfigd DefaultConfig
typename Conf::real_t real_t
typename Conf::rindexvec rindexvec
typename Conf::index_t index_t
typename Conf::length_t length_t
typename Conf::crvec crvec
Double-precision double configuration.
Single-precision float configuration.
long double configuration.
Struct containing function pointers to all problem functions (like the objective and constraint funct...
optional_function_t< void(crvec x, rvec J_values) const > eval_constraints_jacobian
guanaqo::required_function_t< F > required_function_t
optional_function_t< void() const > check
static std::string default_get_name(const void *, const ProblemVTable &)
optional_function_t< void(crvec x, crvec y, crvec Σ, real_t scale, crvec v, rvec Hv) const > eval_augmented_lagrangian_hessian_product
guanaqo::optional_function_t< F, ProblemVTable > optional_function_t
optional_function_t< Sparsity() const > get_lagrangian_hessian_sparsity
static Sparsity default_get_lagrangian_hessian_sparsity(const void *, const ProblemVTable &)
optional_function_t< Sparsity() const > get_constraints_jacobian_sparsity
static Sparsity default_get_constraints_jacobian_sparsity(const void *, const ProblemVTable &)
optional_function_t< void(crvec x, crvec y, real_t scale, rvec H_values) const > eval_lagrangian_hessian
optional_function_t< void(crvec x, index_t i, rvec grad_gi) const > eval_grad_gi
required_function_t< void(rvec y, real_t M) const > eval_projection_multipliers
ProblemVTable(std::in_place_t, P &p)
static void default_eval_objective_gradient_and_constraints_gradient_product(const void *self, crvec x, crvec y, rvec grad_f, rvec grad_gxy, const ProblemVTable &vtable)
static real_t default_eval_augmented_lagrangian(const void *self, crvec x, crvec y, crvec Σ, rvec ŷ, const ProblemVTable &vtable)
optional_function_t< real_t(crvec x, rvec grad_fx) const > eval_objective_and_gradient
static void default_eval_lagrangian_hessian(const void *, crvec, crvec, real_t, rvec, const ProblemVTable &)
required_function_t< void(crvec x, rvec grad_fx) const > eval_objective_gradient
optional_function_t< void(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const > eval_augmented_lagrangian_gradient
static void default_eval_grad_gi(const void *, crvec, index_t, rvec, const ProblemVTable &)
static Sparsity default_get_augmented_lagrangian_hessian_sparsity(const void *, const ProblemVTable &)
optional_function_t< const Box &() const > get_variable_bounds
required_function_t< real_t(real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p) const > eval_proximal_gradient_step
static void default_eval_lagrangian_gradient(const void *self, crvec x, crvec y, rvec grad_L, rvec work_n, const ProblemVTable &vtable)
required_function_t< void(crvec z, rvec e) const > eval_projecting_difference_constraints
optional_function_t< void(crvec x, crvec y, rvec grad_L, rvec work_n) const > eval_lagrangian_gradient
static const Box & default_get_general_bounds(const void *, const ProblemVTable &)
optional_function_t< real_t(crvec x, crvec y, crvec Σ, rvec ŷ) const > eval_augmented_lagrangian
optional_function_t< void(crvec x, crvec y, crvec Σ, real_t scale, rvec H_values) const > eval_augmented_lagrangian_hessian
optional_function_t< void(crvec x, crvec y, rvec grad_f, rvec grad_gxy) const > eval_objective_gradient_and_constraints_gradient_product
static void default_eval_lagrangian_hessian_product(const void *, crvec, crvec, real_t, crvec, rvec, const ProblemVTable &)
required_function_t< void(crvec x, rvec gx) const > eval_constraints
static const Box & default_get_variable_bounds(const void *, const ProblemVTable &)
optional_function_t< Sparsity() const > get_augmented_lagrangian_hessian_sparsity
static void default_eval_constraints_jacobian(const void *, crvec, rvec, const ProblemVTable &)
required_function_t< void(crvec x, crvec y, rvec grad_gxy) const > eval_constraints_gradient_product
static real_t default_eval_objective_and_gradient(const void *self, crvec x, rvec grad_fx, const ProblemVTable &vtable)
alpaqa::Box< config_t > Box
static real_t default_eval_augmented_lagrangian_and_gradient(const void *self, crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m, const ProblemVTable &vtable)
static void default_eval_augmented_lagrangian_hessian_product(const void *self, crvec x, crvec y, crvec, real_t scale, crvec v, rvec Hv, const ProblemVTable &vtable)
static index_t default_eval_inactive_indices_res_lna(const void *, real_t, crvec, crvec, rindexvec, const ProblemVTable &)
static void default_check(const void *, const ProblemVTable &)
static real_t default_eval_objective_and_constraints(const void *self, crvec x, rvec g, const ProblemVTable &vtable)
static real_t calc_ŷ_dᵀŷ(const void *self, rvec g_ŷ, crvec y, crvec Σ, const ProblemVTable &vtable)
optional_function_t< std::string() const > get_name
required_function_t< real_t(crvec x) const > eval_objective
optional_function_t< void(crvec x, crvec y, real_t scale, crvec v, rvec Hv) const > eval_lagrangian_hessian_product
optional_function_t< const Box &() const > get_general_bounds
static void default_eval_augmented_lagrangian_hessian(const void *self, crvec x, crvec y, crvec, real_t scale, rvec H_values, const ProblemVTable &vtable)
optional_function_t< index_t(real_t γ, crvec x, crvec grad_ψ, rindexvec J) const > eval_inactive_indices_res_lna
optional_function_t< real_t(crvec x, rvec g) const > eval_objective_and_constraints
optional_function_t< real_t(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const > eval_augmented_lagrangian_and_gradient
static void default_eval_augmented_lagrangian_gradient(const void *self, crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m, const ProblemVTable &vtable)