154 auto &vtable = *
this;
193 vtable.n = p.get_n();
194 vtable.m = p.get_m();
229 using TypeErased::TypeErased;
232 using TypeErased::call;
233 using TypeErased::self;
234 using TypeErased::vtable;
237 template <
class T,
class... Args>
239 return TypeErased::template make<TypeErasedProblem, T>(std::forward<Args>(args)...);
448 rvec H_values)
const;
592 return vtable.eval_inactive_indices_res_lna != vtable.default_eval_inactive_indices_res_lna;
597 return vtable.eval_jac_g != vtable.default_eval_jac_g;
602 return vtable.get_jac_g_num_nonzeros != vtable.default_get_jac_g_num_nonzeros;
607 return vtable.eval_grad_gi != vtable.default_eval_grad_gi;
612 return vtable.eval_hess_L_prod != vtable.default_eval_hess_L_prod;
617 return vtable.eval_hess_L != vtable.default_eval_hess_L;
622 return vtable.get_hess_L_num_nonzeros != vtable.default_get_hess_L_num_nonzeros;
627 return vtable.eval_hess_ψ_prod != vtable.default_eval_hess_ψ_prod;
632 return vtable.eval_hess_ψ != vtable.default_eval_hess_ψ;
637 return vtable.get_hess_ψ_num_nonzeros != vtable.default_get_hess_ψ_num_nonzeros;
642 return vtable.eval_f_grad_f != vtable.default_eval_f_grad_f;
647 return vtable.eval_f_g != vtable.default_eval_f_g;
652 return vtable.eval_grad_f_grad_g_prod != vtable.default_eval_grad_f_grad_g_prod;
657 return vtable.eval_grad_L != vtable.default_eval_grad_L;
661 [[nodiscard]]
bool provides_eval_ψ()
const {
return vtable.eval_ψ != vtable.default_eval_ψ; }
665 return vtable.eval_grad_ψ != vtable.default_eval_grad_ψ;
670 return vtable.eval_ψ_grad_ψ != vtable.default_eval_ψ_grad_ψ;
675 return vtable.get_box_C != vtable.default_get_box_C;
680 return vtable.get_box_D != vtable.default_get_box_D;
683 [[nodiscard]]
bool provides_check()
const {
return vtable.check != vtable.default_check; }
721template <
class Tref,
class Allocator>
726template <Config Conf,
class Allocator>
730template <Config Conf,
class Allocator>
735template <Config Conf,
class Allocator>
737 return call(vtable.eval_proj_diff_g, z, e);
739template <Config Conf,
class Allocator>
741 return call(vtable.eval_proj_multipliers, y, M);
743template <Config Conf,
class Allocator>
746 return call(vtable.eval_prox_grad_step, γ, x, grad_ψ, x̂, p);
748template <Config Conf,
class Allocator>
753 return call(vtable.eval_inactive_indices_res_lna, γ, x, grad_ψ, J);
755template <Config Conf,
class Allocator>
757 return call(vtable.eval_f, x);
759template <Config Conf,
class Allocator>
761 return call(vtable.eval_grad_f, x, grad_fx);
763template <Config Conf,
class Allocator>
765 return call(vtable.eval_g, x, gx);
767template <Config Conf,
class Allocator>
769 return call(vtable.eval_grad_g_prod, x, y, grad_gxy);
771template <Config Conf,
class Allocator>
773 return call(vtable.eval_grad_gi, x, i, grad_gi);
775template <Config Conf,
class Allocator>
778 return call(vtable.eval_jac_g, x, inner_idx, outer_ptr, J_values);
780template <Config Conf,
class Allocator>
782 return call(vtable.get_jac_g_num_nonzeros);
784template <Config Conf,
class Allocator>
787 return call(vtable.eval_hess_L_prod, x, y, scale, v, Hv);
789template <Config Conf,
class Allocator>
792 rvec H_values)
const {
793 return call(vtable.eval_hess_L, x, y, scale, inner_idx, outer_ptr, H_values);
795template <Config Conf,
class Allocator>
797 return call(vtable.get_hess_L_num_nonzeros);
799template <Config Conf,
class Allocator>
802 return call(vtable.eval_hess_ψ_prod, x, y, Σ, scale, v, Hv);
804template <Config Conf,
class Allocator>
807 rvec H_values)
const {
808 return call(vtable.eval_hess_ψ, x, y, Σ, scale, inner_idx, outer_ptr, H_values);
810template <Config Conf,
class Allocator>
812 return call(vtable.get_hess_ψ_num_nonzeros);
814template <Config Conf,
class Allocator>
816 return call(vtable.eval_f_grad_f, x, grad_fx);
818template <Config Conf,
class Allocator>
820 return call(vtable.eval_f_g, x, g);
822template <Config Conf,
class Allocator>
824 rvec grad_gxy)
const {
825 return call(vtable.eval_grad_f_grad_g_prod, x, y, grad_f, grad_gxy);
827template <Config Conf,
class Allocator>
830 return call(vtable.eval_grad_L, x, y, grad_L, work_n);
832template <Config Conf,
class Allocator>
834 return call(vtable.eval_ψ, x, y, Σ, ŷ);
836template <Config Conf,
class Allocator>
839 return call(vtable.eval_grad_ψ, x, y, Σ, grad_ψ, work_n, work_m);
841template <Config Conf,
class Allocator>
844 return call(vtable.eval_ψ_grad_ψ, x, y, Σ, grad_ψ, work_n, work_m);
846template <Config Conf,
class Allocator>
848 return call(vtable.calc_ŷ_dᵀŷ, g_ŷ, y, Σ);
850template <Config Conf,
class Allocator>
852 return call(vtable.get_box_C);
854template <Config Conf,
class Allocator>
856 return call(vtable.get_box_D);
858template <Config Conf,
class Allocator>
860 return call(vtable.check);
866template <Config Conf>
The main polymorphic minimization problem interface.
bool provides_eval_hess_L() const
Returns true if the problem provides an implementation of eval_hess_L.
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.
real_t eval_ψ_grad_ψ(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
[Optional] Calculate both ψ(x) and its gradient ∇ψ(x).
const Box & get_box_D() const
[Optional] Get the rectangular constraint set of the general constraint function, .
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_hess_ψ(crvec x, crvec y, crvec Σ, real_t scale, rindexvec inner_idx, rindexvec outer_ptr, rvec H_values) const
[Optional] Function that evaluates the Hessian of the augmented Lagrangian,
bool provides_eval_hess_ψ_prod() const
Returns true if the problem provides an implementation of eval_hess_ψ_prod.
bool provides_eval_ψ_grad_ψ() const
Returns true if the problem provides a specialized implementation of eval_ψ_grad_ψ,...
bool provides_get_box_C() const
Returns true if the problem provides an implementation of get_box_C.
real_t eval_f_g(crvec x, rvec g) const
[Optional] Evaluate both and .
bool provides_get_hess_L_num_nonzeros() const
Returns true if the problem provides an implementation of get_hess_L_num_nonzeros.
bool provides_get_jac_g_num_nonzeros() const
Returns true if the problem provides an implementation of get_jac_g_num_nonzeros.
bool provides_eval_jac_g() const
Returns true if the problem provides an implementation of eval_jac_g.
bool provides_check() const
Returns true if the problem provides an implementation of check.
length_t get_n() const
[Required] Number of decision variables.
void check() const
[Optional] Check that the problem formulation is well-defined, the dimensions match,...
length_t get_m() const
[Required] Number of constraints.
real_t eval_ψ(crvec x, crvec y, crvec Σ, rvec ŷ) const
[Optional] Calculate both ψ(x) and the vector ŷ that can later be used to compute ∇ψ.
bool provides_eval_inactive_indices_res_lna() const
Returns true if the problem provides an implementation of eval_inactive_indices_res_lna.
void eval_grad_L(crvec x, crvec y, rvec grad_L, rvec work_n) const
[Optional] Evaluate the gradient of the Lagrangian
void eval_grad_f_grad_g_prod(crvec x, crvec y, rvec grad_f, rvec grad_gxy) const
[Optional] Evaluate both and .
bool provides_eval_grad_f_grad_g_prod() const
Returns true if the problem provides a specialized implementation of eval_grad_f_grad_g_prod,...
void eval_hess_L(crvec x, crvec y, real_t scale, rindexvec inner_idx, rindexvec outer_ptr, rvec H_values) const
[Optional] Function that evaluates the Hessian of the Lagrangian as a sparse matrix,
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 provides_eval_hess_L_prod() const
Returns true if the problem provides an implementation of eval_hess_L_prod.
bool provides_get_hess_ψ_num_nonzeros() const
Returns true if the problem provides an implementation of get_hess_ψ_num_nonzeros.
real_t eval_f_grad_f(crvec x, rvec grad_fx) const
[Optional] Evaluate both and its gradient, .
bool provides_eval_f_grad_f() const
Returns true if the problem provides a specialized implementation of eval_f_grad_f,...
void eval_grad_g_prod(crvec x, crvec y, rvec grad_gxy) const
[Required] Function that evaluates the gradient of the constraints times a vector,
void eval_hess_L_prod(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,
bool provides_eval_grad_gi() const
Returns true if the problem provides an implementation of eval_grad_gi.
void eval_proj_multipliers(rvec y, real_t M) const
[Required] Function that projects the Lagrange multipliers for ALM.
bool provides_eval_f_g() const
Returns true if the problem provides a specialized implementation of eval_f_g, false if it uses the d...
void eval_grad_f(crvec x, rvec grad_fx) const
[Required] Function that evaluates the gradient of the cost,
real_t eval_f(crvec x) const
[Required] Function that evaluates the cost,
bool provides_eval_grad_L() const
Returns true if the problem provides a specialized implementation of eval_grad_L, false if it uses th...
bool provides_eval_grad_ψ() const
Returns true if the problem provides a specialized implementation of eval_grad_ψ, false if it uses th...
void eval_g(crvec x, rvec gx) const
[Required] Function that evaluates the constraints,
length_t get_jac_g_num_nonzeros() const
[Optional] Function that gets the number of nonzeros of the sparse Jacobian of the constraints.
bool provides_eval_hess_ψ() const
Returns true if the problem provides an implementation of eval_hess_ψ.
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 ∇ψ(...
bool provides_get_box_D() const
Returns true if the problem provides an implementation of get_box_D.
const Box & get_box_C() const
[Optional] Get the rectangular constraint set of the decision variables, .
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...
void eval_jac_g(crvec x, rindexvec inner_idx, rindexvec outer_ptr, rvec J_values) const
[Optional] Function that evaluates the Jacobian of the constraints as a sparse matrix,
void eval_grad_ψ(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
[Optional] Calculate the gradient ∇ψ(x).
bool provides_eval_ψ() const
Returns true if the problem provides a specialized implementation of eval_ψ, false if it uses the def...
void eval_hess_ψ_prod(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,
length_t get_hess_ψ_num_nonzeros() const
[Optional] Function that gets the number of nonzeros of the Hessian of the augmented Lagrangian.
length_t get_hess_L_num_nonzeros() const
[Optional] Function that gets the number of nonzeros of the sparse Hessian of the Lagrangian.
Class for polymorphism through type erasure.
#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)
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
#define ALPAQA_TE_OPTIONAL_METHOD(vtable, type, member, instance)
#define ALPAQA_TE_REQUIRED_METHOD(vtable, type, member)
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...
required_const_function_t< real_t(crvec x)> eval_f
util::BasicVTable::optional_const_function_t< F, ProblemVTable > optional_const_function_t
optional_const_function_t< void(crvec x, crvec y, real_t scale, crvec v, rvec Hv)> eval_hess_L_prod
required_const_function_t< real_t(real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p)> eval_prox_grad_step
static real_t default_eval_ψ(const void *self, crvec x, crvec y, crvec Σ, rvec ŷ, const ProblemVTable &vtable)
optional_const_function_t< real_t(crvec x, rvec grad_fx)> eval_f_grad_f
static length_t default_get_hess_L_num_nonzeros(const void *, const ProblemVTable &)
optional_const_function_t< void(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m)> eval_grad_ψ
static void default_eval_hess_L(const void *, crvec, crvec, real_t, rindexvec, rindexvec, rvec, const ProblemVTable &)
static void default_eval_hess_L_prod(const void *, crvec, crvec, real_t, crvec, rvec, const ProblemVTable &)
optional_const_function_t< void(crvec x, crvec y, rvec grad_L, rvec work_n)> eval_grad_L
static void default_eval_hess_ψ_prod(const void *self, crvec x, crvec y, crvec, real_t scale, crvec v, rvec Hv, const ProblemVTable &vtable)
optional_const_function_t< real_t(crvec x, crvec y, crvec Σ, rvec ŷ)> eval_ψ
optional_const_function_t< index_t(real_t γ, crvec x, crvec grad_ψ, rindexvec J)> eval_inactive_indices_res_lna
ProblemVTable(std::in_place_t, P &p)
optional_const_function_t< void(crvec x, crvec y, crvec Σ, real_t scale, crvec v, rvec Hv)> eval_hess_ψ_prod
static void default_eval_jac_g(const void *, crvec, rindexvec, rindexvec, rvec, const ProblemVTable &)
optional_const_function_t< length_t()> get_hess_ψ_num_nonzeros
optional_const_function_t< void()> check
optional_const_function_t< real_t(crvec x, rvec g)> eval_f_g
static void default_eval_grad_gi(const void *, crvec, index_t, rvec, const ProblemVTable &)
optional_const_function_t< real_t(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m)> eval_ψ_grad_ψ
util::BasicVTable::optional_function_t< F, ProblemVTable > optional_function_t
static length_t default_get_jac_g_num_nonzeros(const void *, const ProblemVTable &)
static void default_eval_grad_ψ(const void *self, crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m, const ProblemVTable &vtable)
required_const_function_t< void(crvec x, rvec gx)> eval_g
optional_const_function_t< length_t()> get_jac_g_num_nonzeros
optional_const_function_t< void(crvec x, crvec y, crvec Σ, real_t scale, rindexvec inner_idx, rindexvec outer_ptr, rvec H_values)> eval_hess_ψ
optional_const_function_t< const Box &()> get_box_D
optional_const_function_t< void(crvec x, crvec y, real_t scale, rindexvec inner_idx, rindexvec outer_ptr, rvec H_values)> eval_hess_L
static const Box & default_get_box_C(const void *, const ProblemVTable &)
static void default_eval_grad_L(const void *self, crvec x, crvec y, rvec grad_L, rvec work_n, const ProblemVTable &vtable)
static const Box & default_get_box_D(const void *, const ProblemVTable &)
optional_const_function_t< void(crvec x, crvec y, rvec grad_f, rvec grad_gxy)> eval_grad_f_grad_g_prod
required_const_function_t< void(crvec z, rvec e)> eval_proj_diff_g
static real_t default_eval_f_g(const void *self, crvec x, rvec g, const ProblemVTable &vtable)
optional_const_function_t< void(crvec x, index_t i, rvec grad_gi)> eval_grad_gi
optional_const_function_t< length_t()> get_hess_L_num_nonzeros
static void default_eval_hess_ψ(const void *self, crvec x, crvec y, crvec, real_t scale, rindexvec inner_idx, rindexvec outer_ptr, rvec H_values, 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 calc_ŷ_dᵀŷ(const void *self, rvec g_ŷ, crvec y, crvec Σ, const ProblemVTable &vtable)
static void default_eval_grad_f_grad_g_prod(const void *self, crvec x, crvec y, rvec grad_f, rvec grad_gxy, const ProblemVTable &vtable)
required_const_function_t< void(crvec x, crvec y, rvec grad_gxy)> eval_grad_g_prod
static real_t default_eval_f_grad_f(const void *self, crvec x, rvec grad_fx, const ProblemVTable &vtable)
required_const_function_t< void(rvec y, real_t M)> eval_proj_multipliers
required_const_function_t< void(crvec x, rvec grad_fx)> eval_grad_f
optional_const_function_t< void(crvec x, rindexvec inner_idx, rindexvec outer_ptr, rvec J_values)> eval_jac_g
static length_t default_get_hess_ψ_num_nonzeros(const void *, const ProblemVTable &)
static real_t default_eval_ψ_grad_ψ(const void *self, crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m, const ProblemVTable &vtable)
optional_const_function_t< const Box &()> get_box_C
Struct that stores the size of a polymorphic object, as well as pointers to functions to copy,...
typename optional_function< F, VTable >::type optional_function_t
An optional function includes a void pointer to self, the arguments of F, and an additional reference...
typename required_const_function< F >::type required_const_function_t
A required function includes a void pointer to self, in addition to the arguments of F.
typename optional_const_function< F, VTable >::type optional_const_function_t
An optional function includes a void pointer to self, the arguments of F, and an additional reference...