22 ExtraFuncs(std::shared_ptr<function_dict_t> &&extra_funcs)
28 template <
class Signature>
29 requires std::is_function_v<Signature>
30 const std::function<Signature> &
extra_func(
const std::string &name)
const {
32 throw std::out_of_range(
"DLProblem: no extra functions");
35 throw std::out_of_range(
"DLProblem: no extra function named \"" +
38 return std::any_cast<const std::function<Signature> &>(it->second);
39 }
catch (
const std::bad_any_cast &e) {
40 throw std::logic_error(
41 "DLProblem: incorrect type for extra function \"" + name +
50 template <
class Ret,
class... FArgs,
class... Args>
53 FuncTag<Ret(
const instance_t *, FArgs...)>,
54 const std::string &name, Args &&...args)
const {
55 return extra_func<Ret(
const void *, FArgs...)>(name)(
56 instance, std::forward<Args>(args)...);
59 template <
class Ret,
class... FArgs,
class... Args>
62 const std::string &name, Args &&...args) {
63 return extra_func<Ret(
void *, FArgs...)>(name)(
64 instance, std::forward<Args>(args)...);
67 template <
class Ret,
class... FArgs,
class... Args>
69 const std::string &name,
70 Args &&...args)
const {
71 return extra_func<Ret(FArgs...)>(name)(std::forward<Args>(args)...);
99 const std::string &so_filename,
101 std::string symbol_prefix =
"alpaqa_problem",
103 void *user_param =
nullptr);
166 template <
class Signature,
class... Args>
168 Args &&...args)
const {
169 return call_extra_func_helper(
instance.get(),
171 std::forward<Args>(args)...);
174 template <
class Signature,
class... Args>
178 std::forward<Args>(args)...);
205 const std::string &so_filename,
207 std::string symbol_prefix =
"alpaqa_control_problem",
209 void *user_param =
nullptr);
280 template <
class Signature,
class... Args>
282 Args &&...args)
const {
285 std::forward<Args>(args)...);
288 template <
class Signature,
class... Args>
292 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
ExtraFuncs::instance_t instance_t
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
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
std::shared_ptr< void > handle
Handle to the shared module defining the problem.
void eval_qr(index_t timestep, crvec xu, crvec h, rvec qr) const
ExtraFuncs extra_funcs
Dictionary of extra functions that were registered by the problem.
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
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
ExtraFuncs::instance_t instance_t
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
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
std::shared_ptr< void > handle
Handle to the shared module defining the problem.
ExtraFuncs extra_funcs
Dictionary of extra functions that were registered by the problem.
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
Double-precision double configuration.
C API providing function pointers to problem functions.