9#include <guanaqo/not-implemented.hpp>
10#include <guanaqo/required-method.hpp>
11#include <guanaqo/type-erasure.hpp>
18using guanaqo::not_implemented_error;
108 ALPAQA_EXPORT_STATIC static
index_t
113 ALPAQA_EXPORT_STATIC static Sparsity
124 ALPAQA_EXPORT_STATIC static Sparsity
126 ALPAQA_EXPORT_STATIC static
void
130 ALPAQA_EXPORT_STATIC static
void
134 ALPAQA_EXPORT_STATIC static Sparsity
136 ALPAQA_EXPORT_STATIC static
real_t
139 ALPAQA_EXPORT_STATIC static
real_t
142 ALPAQA_EXPORT_STATIC static
void
151 ALPAQA_EXPORT_STATIC static
real_t
154 ALPAQA_EXPORT_STATIC static
void
158 ALPAQA_EXPORT_STATIC static
real_t
172 ProblemVTable(std::in_place_t, P &p) : guanaqo::BasicVTable{std::in_place, p} {
173 auto &vtable = *
this;
199 GUANAQO_TE_OPTIONAL_METHOD(vtable, P,
210 GUANAQO_TE_OPTIONAL_METHOD(vtable, P,
check, p);
211 GUANAQO_TE_OPTIONAL_METHOD(vtable, P,
get_name, p);
214 vtable.n = p.get_num_variables();
215 vtable.m = p.get_num_constraints();
249 using TypeErased = guanaqo::TypeErased<VTable, allocator_type>;
250 using TypeErased::TypeErased;
253 using TypeErased::call;
254 using TypeErased::self;
255 using TypeErased::vtable;
258 template <
class T,
class... Args>
498 rvec H_values)
const;
523 rvec grad_gxy)
const;
602 return vtable.eval_inactive_indices_res_lna != vtable.default_eval_inactive_indices_res_lna;
607 return vtable.eval_constraints_jacobian != vtable.default_eval_constraints_jacobian;
612 return vtable.get_constraints_jacobian_sparsity !=
613 vtable.default_get_constraints_jacobian_sparsity;
618 return vtable.eval_grad_gi != vtable.default_eval_grad_gi;
623 return vtable.eval_lagrangian_hessian_product !=
624 vtable.default_eval_lagrangian_hessian_product;
629 return vtable.eval_lagrangian_hessian != vtable.default_eval_lagrangian_hessian;
634 return vtable.get_lagrangian_hessian_sparsity !=
635 vtable.default_get_lagrangian_hessian_sparsity;
640 return vtable.eval_augmented_lagrangian_hessian_product !=
641 vtable.default_eval_augmented_lagrangian_hessian_product;
646 return vtable.eval_augmented_lagrangian_hessian !=
647 vtable.default_eval_augmented_lagrangian_hessian;
652 return vtable.get_augmented_lagrangian_hessian_sparsity !=
653 vtable.default_get_augmented_lagrangian_hessian_sparsity;
658 return vtable.eval_objective_and_gradient != vtable.default_eval_objective_and_gradient;
663 return vtable.eval_objective_and_constraints !=
664 vtable.default_eval_objective_and_constraints;
669 return vtable.eval_objective_gradient_and_constraints_gradient_product !=
670 vtable.default_eval_objective_gradient_and_constraints_gradient_product;
675 return vtable.eval_lagrangian_gradient != vtable.default_eval_lagrangian_gradient;
680 return vtable.eval_augmented_lagrangian != vtable.default_eval_augmented_lagrangian;
685 return vtable.eval_augmented_lagrangian_gradient !=
686 vtable.default_eval_augmented_lagrangian_gradient;
691 return vtable.eval_augmented_lagrangian_and_gradient !=
692 vtable.default_eval_augmented_lagrangian_and_gradient;
697 return vtable.get_variable_bounds != vtable.default_get_variable_bounds;
702 return vtable.get_general_bounds != vtable.default_get_general_bounds;
705 [[nodiscard]]
bool provides_check()
const {
return vtable.check != vtable.default_check; }
708 return vtable.get_name != vtable.default_get_name;
763template <
class Tref,
class Allocator>
768template <Config Conf,
class Allocator>
772template <Config Conf,
class Allocator>
777template <Config Conf,
class Allocator>
780 return call(vtable.eval_projecting_difference_constraints, z, e);
782template <Config Conf,
class Allocator>
784 return call(vtable.eval_projection_multipliers, y, M);
786template <Config Conf,
class Allocator>
790 return call(vtable.eval_proximal_gradient_step, γ, x, grad_ψ, x̂, p);
792template <Config Conf,
class Allocator>
795 return call(vtable.eval_inactive_indices_res_lna, γ, x, grad_ψ, J);
797template <Config Conf,
class Allocator>
799 return call(vtable.eval_objective, x);
801template <Config Conf,
class Allocator>
803 return call(vtable.eval_objective_gradient, x, grad_fx);
805template <Config Conf,
class Allocator>
807 return call(vtable.eval_constraints, x, gx);
809template <Config Conf,
class Allocator>
811 rvec grad_gxy)
const {
812 return call(vtable.eval_constraints_gradient_product, x, y, grad_gxy);
814template <Config Conf,
class Allocator>
816 return call(vtable.eval_grad_gi, x, i, grad_gi);
818template <Config Conf,
class Allocator>
820 return call(vtable.eval_constraints_jacobian, x, J_values);
822template <Config Conf,
class Allocator>
824 return call(vtable.get_constraints_jacobian_sparsity);
826template <Config Conf,
class Allocator>
830 return call(vtable.eval_lagrangian_hessian_product, x, y, scale, v, Hv);
832template <Config Conf,
class Allocator>
834 rvec H_values)
const {
835 return call(vtable.eval_lagrangian_hessian, x, y, scale, H_values);
837template <Config Conf,
class Allocator>
839 return call(vtable.get_lagrangian_hessian_sparsity);
841template <Config Conf,
class Allocator>
844 return call(vtable.eval_augmented_lagrangian_hessian_product, x, y, Σ, scale, v, Hv);
846template <Config Conf,
class Allocator>
849 rvec H_values)
const {
850 return call(vtable.eval_augmented_lagrangian_hessian, x, y, Σ, scale, H_values);
852template <Config Conf,
class Allocator>
855 return call(vtable.get_augmented_lagrangian_hessian_sparsity);
857template <Config Conf,
class Allocator>
860 return call(vtable.eval_objective_and_gradient, x, grad_fx);
862template <Config Conf,
class Allocator>
865 return call(vtable.eval_objective_and_constraints, x, g);
867template <Config Conf,
class Allocator>
870 return call(vtable.eval_objective_gradient_and_constraints_gradient_product, x, y, grad_f,
873template <Config Conf,
class Allocator>
876 return call(vtable.eval_lagrangian_gradient, x, y, grad_L, work_n);
878template <Config Conf,
class Allocator>
881 return call(vtable.eval_augmented_lagrangian, x, y, Σ, ŷ);
883template <Config Conf,
class Allocator>
888 return call(vtable.eval_augmented_lagrangian_gradient, x, y, Σ, grad_ψ, work_n, work_m);
890template <Config Conf,
class Allocator>
893 return call(vtable.eval_augmented_lagrangian_and_gradient, x, y, Σ, grad_ψ, work_n, work_m);
895template <Config Conf,
class Allocator>
897 return call(vtable.calc_ŷ_dᵀŷ, g_ŷ, y, Σ);
899template <Config Conf,
class Allocator>
901 return call(vtable.get_variable_bounds);
903template <Config Conf,
class Allocator>
905 return call(vtable.get_general_bounds);
907template <Config Conf,
class Allocator>
909 return call(vtable.check);
911template <Config Conf,
class Allocator>
913 return call(vtable.get_name);
919template <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 ALPAQA_EXPORT_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 ALPAQA_EXPORT_STATIC Sparsity default_get_lagrangian_hessian_sparsity(const void *, const ProblemVTable &)
optional_function_t< Sparsity() const > get_constraints_jacobian_sparsity
static ALPAQA_EXPORT_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 ALPAQA_EXPORT_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 ALPAQA_EXPORT_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 ALPAQA_EXPORT_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 ALPAQA_EXPORT_STATIC void default_eval_grad_gi(const void *, crvec, index_t, rvec, const ProblemVTable &)
static ALPAQA_EXPORT_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 ALPAQA_EXPORT_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 ALPAQA_EXPORT_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 ALPAQA_EXPORT_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 ALPAQA_EXPORT_STATIC const Box & default_get_variable_bounds(const void *, const ProblemVTable &)
optional_function_t< Sparsity() const > get_augmented_lagrangian_hessian_sparsity
static ALPAQA_EXPORT_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 ALPAQA_EXPORT_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 ALPAQA_EXPORT_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 ALPAQA_EXPORT_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 ALPAQA_EXPORT_STATIC index_t default_eval_inactive_indices_res_lna(const void *, real_t, crvec, crvec, rindexvec, const ProblemVTable &)
static ALPAQA_EXPORT_STATIC void default_check(const void *, const ProblemVTable &)
static ALPAQA_EXPORT_STATIC real_t default_eval_objective_and_constraints(const void *self, crvec x, rvec g, const ProblemVTable &vtable)
static ALPAQA_EXPORT_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 ALPAQA_EXPORT_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 ALPAQA_EXPORT_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)