4#include <alpaqa/dl-loader-export.h>
21using util::dynamic_load_error;
24 using dynamic_load_error::dynamic_load_error;
33 ExtraFuncs(std::shared_ptr<function_dict_t> &&extra_funcs)
39 template <
class Signature>
40 requires std::is_function_v<Signature>
41 const std::function<Signature> &
extra_func(
const std::string &name)
const {
43 throw std::out_of_range(
"DLProblem: no extra functions");
46 throw std::out_of_range(
"DLProblem: no extra function named \"" +
50 return std::any_cast<const func_t &>(it->second).
function;
51 }
catch (
const std::bad_any_cast &) {
52 throw std::logic_error(
53 "DLProblem: incorrect type for extra function \"" + name +
66 const std::string &name,
Args &&...args)
const {
68 instance, std::forward<Args>(
args)...);
74 const std::string &name,
Args &&...args) {
76 instance, std::forward<Args>(
args)...);
81 const std::string &name,
82 Args &&...args)
const {
111 const std::filesystem::path &so_filename,
115 const std::string &function_name =
"register_alpaqa_problem",
121 const std::filesystem::path &so_filename,
125 const std::string &function_name,
127 std::any &user_param);
131 const std::filesystem::path &so_filename,
135 const std::string &function_name,
137 std::span<std::string_view> user_param);
155 void eval_proj_diff_g(
crvec z,
rvec e)
const;
156 void eval_proj_multipliers(
rvec y,
real_t M)
const;
160 void eval_grad_f(
crvec x,
rvec grad_fx)
const;
163 void eval_jac_g(
crvec x,
rvec J_values)
const;
164 Sparsity get_jac_g_sparsity()
const;
168 Sparsity get_hess_L_sparsity()
const;
171 Sparsity get_hess_ψ_sparsity()
const;
179 std::string get_name()
const;
181 [[nodiscard]]
bool provides_eval_f()
const;
182 [[nodiscard]]
bool provides_eval_grad_f()
const;
183 [[nodiscard]]
bool provides_eval_g()
const;
184 [[nodiscard]]
bool provides_eval_grad_g_prod()
const;
185 [[nodiscard]]
bool provides_eval_jac_g()
const;
186 [[nodiscard]]
bool provides_get_jac_g_sparsity()
const;
187 [[nodiscard]]
bool provides_eval_grad_gi()
const;
188 [[nodiscard]]
bool provides_eval_hess_L_prod()
const;
189 [[nodiscard]]
bool provides_eval_hess_L()
const;
190 [[nodiscard]]
bool provides_get_hess_L_sparsity()
const;
191 [[nodiscard]]
bool provides_eval_hess_ψ_prod()
const;
192 [[nodiscard]]
bool provides_eval_hess_ψ()
const;
193 [[nodiscard]]
bool provides_get_hess_ψ_sparsity()
const;
194 [[nodiscard]]
bool provides_eval_f_grad_f()
const;
195 [[nodiscard]]
bool provides_eval_f_g()
const;
196 [[nodiscard]]
bool provides_eval_grad_f_grad_g_prod()
const;
197 [[nodiscard]]
bool provides_eval_grad_L()
const;
198 [[nodiscard]]
bool provides_eval_ψ()
const;
199 [[nodiscard]]
bool provides_eval_grad_ψ()
const;
200 [[nodiscard]]
bool provides_eval_ψ_grad_ψ()
const;
201 [[nodiscard]]
bool provides_get_box_C()
const;
202 [[nodiscard]]
bool provides_get_box_D()
const;
203 [[nodiscard]]
bool provides_eval_inactive_indices_res_lna()
const;
208 template <
class Signature,
class... Args>
210 Args &&...args)
const {
211 return call_extra_func_helper(instance.get(),
213 std::forward<Args>(args)...);
216 template <
class Signature,
class... Args>
220 std::forward<Args>(args)...);
246 const std::filesystem::path &so_filename,
250 const std::string &function_name =
"register_alpaqa_control_problem",
278 void get_U(
Box &U)
const;
279 void get_D(
Box &D)
const;
280 void get_D_N(
Box &D)
const;
281 void get_x_init(
rvec x_init)
const;
297 [[nodiscard]]
length_t get_R_work_size()
const;
298 [[nodiscard]]
length_t get_S_work_size()
const;
300 void eval_constr_N(
crvec x,
rvec c)
const;
302 void eval_grad_constr_prod_N(
crvec x,
crvec p,
rvec grad_cx_p)
const;
306 [[nodiscard]]
bool provides_get_D()
const;
307 [[nodiscard]]
bool provides_get_D_N()
const;
308 [[nodiscard]]
bool provides_eval_add_Q_N()
const;
309 [[nodiscard]]
bool provides_eval_add_R_prod_masked()
const;
310 [[nodiscard]]
bool provides_eval_add_S_prod_masked()
const;
311 [[nodiscard]]
bool provides_get_R_work_size()
const;
312 [[nodiscard]]
bool provides_get_S_work_size()
const;
313 [[nodiscard]]
bool provides_eval_constr()
const;
314 [[nodiscard]]
bool provides_eval_constr_N()
const;
315 [[nodiscard]]
bool provides_eval_grad_constr_prod()
const;
316 [[nodiscard]]
bool provides_eval_grad_constr_prod_N()
const;
317 [[nodiscard]]
bool provides_eval_add_gn_hess_constr()
const;
318 [[nodiscard]]
bool provides_eval_add_gn_hess_constr_N()
const;
323 template <
class Signature,
class... Args>
325 Args &&...args)
const {
328 std::forward<Args>(args)...);
331 template <
class Signature,
class... Args>
335 std::forward<Args>(args)...);
Implements common problem functions for minimization problems with box constraints.
Class that loads an optimal control problem using dlopen.
ExtraFuncs::instance_t instance_t
std::shared_ptr< void > instance
Problem instance created by the registration function, including the deleter to destroy it.
length_t get_nc_N() const
decltype(auto) call_extra_func(const std::string &name, Args &&...args) const
length_t get_nh_N() const
decltype(auto) call_extra_func(const std::string &name, Args &&...args)
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.
Class that loads a problem using dlopen.
ExtraFuncs::instance_t instance_t
std::shared_ptr< void > instance
Problem instance created by the registration function, including the deleter to destroy it.
decltype(auto) call_extra_func(const std::string &name, Args &&...args) const
std::filesystem::path file
Path to the shared module file.
decltype(auto) call_extra_func(const std::string &name, Args &&...args)
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.
#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.
User-provided argument that is passed to the problem registration functions.
std::function< Signature > function
Custom type for which we can export the RTTI to support std::any across shared library boundaries whe...
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
Result(const MemberGetter &) func_t
Double-precision double configuration.
Stores any of the supported sparsity patterns.
C API providing function pointers to problem functions.