4#include <alpaqa/dl-loader-export.h>
21 using std::runtime_error::runtime_error;
25 using std::runtime_error::runtime_error;
34 ExtraFuncs(std::shared_ptr<function_dict_t> &&extra_funcs)
40 template <
class Signature>
41 requires std::is_function_v<Signature>
42 const std::function<Signature> &
extra_func(
const std::string &name)
const {
44 throw std::out_of_range(
"DLProblem: no extra functions");
47 throw std::out_of_range(
"DLProblem: no extra function named \"" +
51 return std::any_cast<const func_t &>(it->second).
function;
52 }
catch (
const std::bad_any_cast &) {
53 throw std::logic_error(
54 "DLProblem: incorrect type for extra function \"" + name +
67 const std::string &name,
Args &&...args)
const {
69 instance, std::forward<Args>(
args)...);
75 const std::string &name,
Args &&...args) {
77 instance, std::forward<Args>(
args)...);
82 const std::string &name,
83 Args &&...args)
const {
112 const std::filesystem::path &so_filename,
116 const std::string &function_name =
"register_alpaqa_problem",
122 const std::filesystem::path &so_filename,
126 const std::string &function_name,
128 std::any &user_param);
132 const std::filesystem::path &so_filename,
136 const std::string &function_name,
138 std::span<std::string_view> user_param);
156 void eval_proj_diff_g(
crvec z,
rvec e)
const;
157 void eval_proj_multipliers(
rvec y,
real_t M)
const;
161 void eval_grad_f(
crvec x,
rvec grad_fx)
const;
164 void eval_jac_g(
crvec x,
rvec J_values)
const;
165 Sparsity get_jac_g_sparsity()
const;
169 Sparsity get_hess_L_sparsity()
const;
172 Sparsity get_hess_ψ_sparsity()
const;
180 std::string get_name()
const;
182 [[nodiscard]]
bool provides_eval_f()
const;
183 [[nodiscard]]
bool provides_eval_grad_f()
const;
184 [[nodiscard]]
bool provides_eval_g()
const;
185 [[nodiscard]]
bool provides_eval_grad_g_prod()
const;
186 [[nodiscard]]
bool provides_eval_jac_g()
const;
187 [[nodiscard]]
bool provides_get_jac_g_sparsity()
const;
188 [[nodiscard]]
bool provides_eval_grad_gi()
const;
189 [[nodiscard]]
bool provides_eval_hess_L_prod()
const;
190 [[nodiscard]]
bool provides_eval_hess_L()
const;
191 [[nodiscard]]
bool provides_get_hess_L_sparsity()
const;
192 [[nodiscard]]
bool provides_eval_hess_ψ_prod()
const;
193 [[nodiscard]]
bool provides_eval_hess_ψ()
const;
194 [[nodiscard]]
bool provides_get_hess_ψ_sparsity()
const;
195 [[nodiscard]]
bool provides_eval_f_grad_f()
const;
196 [[nodiscard]]
bool provides_eval_f_g()
const;
197 [[nodiscard]]
bool provides_eval_grad_f_grad_g_prod()
const;
198 [[nodiscard]]
bool provides_eval_grad_L()
const;
199 [[nodiscard]]
bool provides_eval_ψ()
const;
200 [[nodiscard]]
bool provides_eval_grad_ψ()
const;
201 [[nodiscard]]
bool provides_eval_ψ_grad_ψ()
const;
202 [[nodiscard]]
bool provides_get_box_C()
const;
203 [[nodiscard]]
bool provides_get_box_D()
const;
204 [[nodiscard]]
bool provides_eval_inactive_indices_res_lna()
const;
209 template <
class Signature,
class... Args>
211 Args &&...args)
const {
212 return call_extra_func_helper(instance.get(),
214 std::forward<Args>(args)...);
217 template <
class Signature,
class... Args>
221 std::forward<Args>(args)...);
247 const std::filesystem::path &so_filename,
251 const std::string &function_name =
"register_alpaqa_control_problem",
279 void get_U(
Box &U)
const;
280 void get_D(
Box &D)
const;
281 void get_D_N(
Box &D)
const;
282 void get_x_init(
rvec x_init)
const;
298 [[nodiscard]]
length_t get_R_work_size()
const;
299 [[nodiscard]]
length_t get_S_work_size()
const;
301 void eval_constr_N(
crvec x,
rvec c)
const;
303 void eval_grad_constr_prod_N(
crvec x,
crvec p,
rvec grad_cx_p)
const;
307 [[nodiscard]]
bool provides_get_D()
const;
308 [[nodiscard]]
bool provides_get_D_N()
const;
309 [[nodiscard]]
bool provides_eval_add_Q_N()
const;
310 [[nodiscard]]
bool provides_eval_add_R_prod_masked()
const;
311 [[nodiscard]]
bool provides_eval_add_S_prod_masked()
const;
312 [[nodiscard]]
bool provides_get_R_work_size()
const;
313 [[nodiscard]]
bool provides_get_S_work_size()
const;
314 [[nodiscard]]
bool provides_eval_constr()
const;
315 [[nodiscard]]
bool provides_eval_constr_N()
const;
316 [[nodiscard]]
bool provides_eval_grad_constr_prod()
const;
317 [[nodiscard]]
bool provides_eval_grad_constr_prod_N()
const;
318 [[nodiscard]]
bool provides_eval_add_gn_hess_constr()
const;
319 [[nodiscard]]
bool provides_eval_add_gn_hess_constr_N()
const;
324 template <
class Signature,
class... Args>
326 Args &&...args)
const {
329 std::forward<Args>(args)...);
332 template <
class Signature,
class... Args>
336 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.