37 [[nodiscard]] std::shared_ptr<void>
load_lib()
const;
40 [[nodiscard]] F *
load_func(std::string_view name)
const;
42 template <
class Signature>
43 requires std::is_function_v<Signature>
44 const std::function<Signature> &
extra_func(
const std::string &name)
const {
46 throw std::out_of_range(
"DLProblem: no extra functions");
49 throw std::out_of_range(
"DLProblem: no extra function named \"" +
52 return std::any_cast<const std::function<Signature> &>(it->second);
53 }
catch (
const std::bad_any_cast &e) {
54 throw std::logic_error(
55 "DLProblem: incorrect type for extra function \"" + name +
69 template <
class Ret,
class... FArgs,
class... Args>
72 FuncTag<Ret(
const instance_t *, FArgs...)>,
73 const std::string &name, Args &&...args)
const {
74 return extra_func<Ret(
const void *, FArgs...)>(name)(
75 instance, std::forward<Args>(args)...);
78 template <
class Ret,
class... FArgs,
class... Args>
81 const std::string &name, Args &&...args) {
82 return extra_func<Ret(
void *, FArgs...)>(name)(
83 instance, std::forward<Args>(args)...);
86 template <
class Ret,
class... FArgs,
class... Args>
88 const std::string &name,
89 Args &&...args)
const {
90 return extra_func<Ret(FArgs...)>(name)(std::forward<Args>(args)...);
118 void *user_param =
nullptr);
177 template <
class Signature,
class... Args>
179 Args &&...args)
const {
181 std::forward<Args>(args)...);
184 template <
class Signature,
class... Args>
187 name, std::forward<Args>(args)...);
218 void *user_param =
nullptr);
285 template <
class Signature,
class... Args>
287 Args &&...args)
const {
289 std::forward<Args>(args)...);
292 template <
class Signature,
class... Args>
295 name, std::forward<Args>(args)...);
Implements common problem functions for minimization problems with box constraints.
Class that loads an optimal control problem using dlopen.
void eval_add_S_masked(index_t timestep, crvec xu, crvec h, crindexvec mask, rmat S, rvec work) const
bool provides_eval_grad_constr_prod() const
void eval_add_Q_N(crvec x, crvec h, rmat Q) const
bool provides_eval_add_gn_hess_constr() const
void eval_q_N(crvec x, crvec h, rvec q) const
void eval_add_gn_hess_constr(index_t timestep, crvec x, crvec M, rmat out) const
void eval_grad_constr_prod(index_t timestep, crvec x, crvec p, rvec grad_cx_p) const
void eval_add_R_prod_masked(index_t timestep, crvec xu, crvec h, crindexvec mask_J, crindexvec mask_K, crvec v, rvec out, rvec work) const
bool provides_eval_add_R_prod_masked() const
length_t get_S_work_size() const
void eval_constr_N(crvec x, rvec c) const
void get_D_N(Box &D) const
DLLoader::instance_t instance_t
bool provides_get_D() const
bool provides_get_S_work_size() const
void eval_grad_f_prod(index_t timestep, crvec x, crvec u, crvec p, rvec grad_fxu_p) const
bool provides_eval_add_Q_N() const
std::shared_ptr< void > instance
Problem instance created by the registration function, including the deleter to destroy it.
void eval_jac_f(index_t timestep, crvec x, crvec u, rmat J_fxu) const
real_t eval_l_N(crvec h) const
void eval_h_N(crvec x, rvec h) const
real_t eval_l(index_t timestep, crvec h) const
length_t get_nc_N() const
void eval_grad_constr_prod_N(crvec x, crvec p, rvec grad_cx_p) const
bool provides_eval_constr() const
control_problem_functions_t * functions
Pointer to the struct of function pointers for evaluating the objective, constraints,...
bool provides_get_D_N() const
decltype(auto) call_extra_func(const std::string &name, Args &&...args) const
void eval_add_gn_hess_constr_N(crvec x, crvec M, rmat out) const
length_t get_nh_N() const
void eval_f(index_t timestep, crvec x, crvec u, rvec fxu) const
bool provides_eval_grad_constr_prod_N() const
length_t get_R_work_size() const
void eval_add_S_prod_masked(index_t timestep, crvec xu, crvec h, crindexvec mask_K, crvec v, rvec out, rvec work) const
bool provides_eval_add_S_prod_masked() const
void get_x_init(rvec x_init) const
void eval_h(index_t timestep, crvec x, crvec u, rvec h) const
decltype(auto) call_extra_func(const std::string &name, Args &&...args)
void eval_add_R_masked(index_t timestep, crvec xu, crvec h, crindexvec mask, rmat R, rvec work) const
void eval_qr(index_t timestep, crvec xu, crvec h, rvec qr) const
bool provides_eval_constr_N() const
void eval_add_Q(index_t timestep, crvec xu, crvec h, rmat Q) const
bool provides_get_R_work_size() const
bool provides_eval_add_gn_hess_constr_N() const
void eval_constr(index_t timestep, crvec x, rvec c) const
decltype(auto) call_extra_func_helper(const void *instance, FuncTag< Ret(const instance_t *, FArgs...)>, const std::string &name, Args &&...args) const
decltype(auto) call_extra_func_helper(void *instance, FuncTag< Ret(instance_t *, FArgs...)>, const std::string &name, Args &&...args)
const std::function< Signature > & extra_func(const std::string &name) const
std::shared_ptr< function_dict_t > extra_functions
An associative array of additional functions exposed by the problem.
decltype(auto) call_extra_func_helper(const void *, FuncTag< Ret(FArgs...)>, const std::string &name, Args &&...args) const
F * load_func(std::string_view name) const
Load a function with signature F from the library using dlsym.
std::string symbol_prefix
std::shared_ptr< void > load_lib() const
Open the shared library using dlopen
dl_handle_t handle
Handle to the shared library (returned by dlopen).
std::shared_ptr< void > dl_handle_t
Class that loads a problem using dlopen.
bool provides_eval_hess_L() const
real_t eval_prox_grad_step(real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p) const
real_t eval_ψ_grad_ψ(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
void eval_grad_gi(crvec x, index_t i, rvec grad_gi) const
void eval_hess_L_prod(crvec x, crvec y, real_t scale, crvec v, rvec Hv) const
bool provides_eval_hess_ψ_prod() const
void eval_hess_ψ_prod(crvec x, crvec y, crvec Σ, real_t scale, crvec v, rvec Hv) const
bool provides_eval_ψ_grad_ψ() const
bool provides_get_box_C() const
real_t eval_f_g(crvec x, rvec g) const
bool provides_get_hess_L_num_nonzeros() const
void eval_hess_L(crvec x, crvec y, real_t scale, rindexvec inner_idx, rindexvec outer_ptr, rvec H_values) const
void eval_grad_f(crvec x, rvec grad_fx) const
bool provides_get_jac_g_num_nonzeros() const
bool provides_eval_jac_g() const
void eval_grad_f_grad_g_prod(crvec x, crvec y, rvec grad_f, rvec grad_gxy) const
DLLoader::instance_t instance_t
real_t eval_ψ(crvec x, crvec y, crvec Σ, rvec ŷ) const
std::shared_ptr< void > instance
Problem instance created by the registration function, including the deleter to destroy it.
bool provides_eval_g() const
void eval_grad_ψ(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
bool provides_eval_grad_f_grad_g_prod() const
decltype(auto) call_extra_func(const std::string &name, Args &&...args) const
bool provides_eval_f() const
bool provides_eval_hess_L_prod() const
bool provides_eval_grad_g_prod() const
bool provides_get_hess_ψ_num_nonzeros() const
real_t eval_f_grad_f(crvec x, rvec grad_fx) const
bool provides_eval_f_grad_f() const
bool provides_eval_grad_f() const
bool provides_eval_grad_gi() const
bool provides_eval_f_g() const
problem_functions_t * functions
Pointer to the struct of function pointers for evaluating the objective, constraints,...
real_t eval_f(crvec x) const
void eval_jac_g(crvec x, rindexvec inner_idx, rindexvec outer_ptr, rvec J_values) const
bool provides_eval_grad_L() const
void eval_grad_g_prod(crvec x, crvec y, rvec grad_gxy) const
bool provides_eval_grad_ψ() const
decltype(auto) call_extra_func(const std::string &name, Args &&...args)
length_t get_jac_g_num_nonzeros() const
bool provides_eval_hess_ψ() const
void eval_grad_L(crvec x, crvec y, rvec grad_L, rvec work_n) const
void eval_g(crvec x, rvec gx) const
void eval_hess_ψ(crvec x, crvec y, crvec Σ, real_t scale, rindexvec inner_idx, rindexvec outer_ptr, rvec H_values) const
bool provides_eval_ψ() const
length_t get_hess_ψ_num_nonzeros() const
length_t get_hess_L_num_nonzeros() const
#define USING_ALPAQA_CONFIG(Conf)
std::string demangled_typename(const std::type_info &t)
Get the pretty name of the given type as a string.
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
typename Conf::crindexvec crindexvec