4#include <alpaqa/dl-loader-export.h>
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",
123 const std::filesystem::path &so_filename,
127 const std::string &function_name,
129 std::any &user_param,
135 const std::filesystem::path &so_filename,
139 const std::string &function_name,
141 std::span<std::string_view> user_param,
143 DynamicLoadFlags dl_flags = {});
161 void eval_proj_diff_g(
crvec z,
rvec e)
const;
162 void eval_proj_multipliers(
rvec y,
real_t M)
const;
166 void eval_grad_f(
crvec x,
rvec grad_fx)
const;
169 void eval_jac_g(
crvec x,
rvec J_values)
const;
170 Sparsity get_jac_g_sparsity()
const;
174 Sparsity get_hess_L_sparsity()
const;
177 Sparsity get_hess_ψ_sparsity()
const;
185 std::string get_name()
const;
187 [[nodiscard]]
bool provides_eval_f()
const;
188 [[nodiscard]]
bool provides_eval_grad_f()
const;
189 [[nodiscard]]
bool provides_eval_g()
const;
190 [[nodiscard]]
bool provides_eval_grad_g_prod()
const;
191 [[nodiscard]]
bool provides_eval_jac_g()
const;
192 [[nodiscard]]
bool provides_get_jac_g_sparsity()
const;
193 [[nodiscard]]
bool provides_eval_grad_gi()
const;
194 [[nodiscard]]
bool provides_eval_hess_L_prod()
const;
195 [[nodiscard]]
bool provides_eval_hess_L()
const;
196 [[nodiscard]]
bool provides_get_hess_L_sparsity()
const;
197 [[nodiscard]]
bool provides_eval_hess_ψ_prod()
const;
198 [[nodiscard]]
bool provides_eval_hess_ψ()
const;
199 [[nodiscard]]
bool provides_get_hess_ψ_sparsity()
const;
200 [[nodiscard]]
bool provides_eval_f_grad_f()
const;
201 [[nodiscard]]
bool provides_eval_f_g()
const;
202 [[nodiscard]]
bool provides_eval_grad_f_grad_g_prod()
const;
203 [[nodiscard]]
bool provides_eval_grad_L()
const;
204 [[nodiscard]]
bool provides_eval_ψ()
const;
205 [[nodiscard]]
bool provides_eval_grad_ψ()
const;
206 [[nodiscard]]
bool provides_eval_ψ_grad_ψ()
const;
207 [[nodiscard]]
bool provides_get_box_C()
const;
208 [[nodiscard]]
bool provides_get_box_D()
const;
209 [[nodiscard]]
bool provides_eval_inactive_indices_res_lna()
const;
214 template <
class Signature,
class... Args>
216 Args &&...args)
const {
217 return call_extra_func_helper(instance.get(),
219 std::forward<Args>(args)...);
222 template <
class Signature,
class... Args>
226 std::forward<Args>(args)...);
252 const std::filesystem::path &so_filename,
256 const std::string &function_name =
"register_alpaqa_control_problem",
286 void get_U(
Box &U)
const;
287 void get_D(
Box &D)
const;
288 void get_D_N(
Box &D)
const;
289 void get_x_init(
rvec x_init)
const;
305 [[nodiscard]]
length_t get_R_work_size()
const;
306 [[nodiscard]]
length_t get_S_work_size()
const;
308 void eval_constr_N(
crvec x,
rvec c)
const;
310 void eval_grad_constr_prod_N(
crvec x,
crvec p,
rvec grad_cx_p)
const;
314 [[nodiscard]]
bool provides_get_D()
const;
315 [[nodiscard]]
bool provides_get_D_N()
const;
316 [[nodiscard]]
bool provides_eval_add_Q_N()
const;
317 [[nodiscard]]
bool provides_eval_add_R_prod_masked()
const;
318 [[nodiscard]]
bool provides_eval_add_S_prod_masked()
const;
319 [[nodiscard]]
bool provides_get_R_work_size()
const;
320 [[nodiscard]]
bool provides_get_S_work_size()
const;
321 [[nodiscard]]
bool provides_eval_constr()
const;
322 [[nodiscard]]
bool provides_eval_constr_N()
const;
323 [[nodiscard]]
bool provides_eval_grad_constr_prod()
const;
324 [[nodiscard]]
bool provides_eval_grad_constr_prod_N()
const;
325 [[nodiscard]]
bool provides_eval_add_gn_hess_constr()
const;
326 [[nodiscard]]
bool provides_eval_add_gn_hess_constr_N()
const;
331 template <
class Signature,
class... Args>
333 Args &&...args)
const {
336 std::forward<Args>(args)...);
339 template <
class Signature,
class... Args>
343 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
Flags to be passed to dlopen.
Double-precision double configuration.
Stores any of the supported sparsity patterns.
Failed to load a DLL or SO file, or failed to access a function in it.
C API providing function pointers to problem functions.