alpaqa 1.0.0a8
Nonconvex constrained optimization
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
DLControlProblem Class Reference

#include <interop/dl/include/alpaqa/dl/dl-problem.hpp>

Detailed Description

Class that loads an optimal control problem using dlopen.

The shared library should export a C function with the name <symbol_prefix>_register that accepts a void pointer with user data, and returns a struct of type alpaqa_control_problem_register_t that contains all data to represent the problem, as well as function pointers for all required operations. See C++/DLProblem/main.cpp

Note
Copies are shallow, they all share the same problem instance, take that into account when using multiple threads.
See also
TypeErasedControlProblem

Definition at line 206 of file dl-problem.hpp.

+ Inheritance diagram for DLControlProblem:
+ Collaboration diagram for DLControlProblem:

Public Types

using Box = alpaqa::Box< config_t >
 
using instance_t = DLLoader::instance_t
 

Public Member Functions

 DLControlProblem (std::string so_filename, std::string symbol_prefix="alpaqa_control_problem", void *user_param=nullptr)
 Load a problem from a shared library.
 
length_t get_N () const
 
length_t get_nx () const
 
length_t get_nu () const
 
length_t get_nh () const
 
length_t get_nh_N () const
 
length_t get_nc () const
 
length_t get_nc_N () const
 
void check () const
 
void get_U (Box &U) const
 
void get_D (Box &D) const
 
void get_D_N (Box &D) const
 
void get_x_init (rvec x_init) const
 
void eval_f (index_t timestep, crvec x, crvec u, rvec fxu) const
 
void eval_jac_f (index_t timestep, crvec x, crvec u, rmat J_fxu) const
 
void eval_grad_f_prod (index_t timestep, crvec x, crvec u, crvec p, rvec grad_fxu_p) const
 
void eval_h (index_t timestep, crvec x, crvec u, rvec h) const
 
void eval_h_N (crvec x, rvec h) const
 
real_t eval_l (index_t timestep, crvec h) const
 
real_t eval_l_N (crvec h) const
 
void eval_qr (index_t timestep, crvec xu, crvec h, rvec qr) const
 
void eval_q_N (crvec x, crvec h, rvec q) const
 
void eval_add_Q (index_t timestep, crvec xu, crvec h, rmat Q) const
 
void eval_add_Q_N (crvec x, crvec h, rmat Q) const
 
void eval_add_R_masked (index_t timestep, crvec xu, crvec h, crindexvec mask, rmat R, rvec work) const
 
void eval_add_S_masked (index_t timestep, crvec xu, crvec h, crindexvec mask, rmat S, rvec work) 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
 
void eval_add_S_prod_masked (index_t timestep, crvec xu, crvec h, crindexvec mask_K, crvec v, rvec out, rvec work) const
 
length_t get_R_work_size () const
 
length_t get_S_work_size () const
 
void eval_constr (index_t timestep, crvec x, rvec c) const
 
void eval_constr_N (crvec x, rvec c) const
 
void eval_grad_constr_prod (index_t timestep, crvec x, crvec p, rvec grad_cx_p) const
 
void eval_grad_constr_prod_N (crvec x, crvec p, rvec grad_cx_p) const
 
void eval_add_gn_hess_constr (index_t timestep, crvec x, crvec M, rmat out) const
 
void eval_add_gn_hess_constr_N (crvec x, crvec M, rmat out) const
 
bool provides_get_D () const
 
bool provides_get_D_N () const
 
bool provides_eval_add_Q_N () const
 
bool provides_eval_add_R_prod_masked () const
 
bool provides_eval_add_S_prod_masked () const
 
bool provides_get_R_work_size () const
 
bool provides_get_S_work_size () const
 
bool provides_eval_constr () const
 
bool provides_eval_constr_N () const
 
bool provides_eval_grad_constr_prod () const
 
bool provides_eval_grad_constr_prod_N () const
 
bool provides_eval_add_gn_hess_constr () const
 
bool provides_eval_add_gn_hess_constr_N () const
 
template<class Signature , class... Args>
decltype(auto) call_extra_func (const std::string &name, Args &&...args) const
 
template<class Signature , class... Args>
decltype(auto) call_extra_func (const std::string &name, Args &&...args)
 

Private Types

using dl_handle_t = std::shared_ptr< void >
 

Private Member Functions

std::shared_ptr< void > load_lib () const
 Open the shared library using dlopen
 
template<class F >
F * load_func (std::string_view name) const
 Load a function with signature F from the library using dlsym.
 
template<class Signature >
requires std::is_function_v<Signature>
const std::function< Signature > & extra_func (const std::string &name) const
 
template<class Ret , class... FArgs, class... Args>
decltype(auto) call_extra_func_helper (const void *instance, FuncTag< Ret(const instance_t *, FArgs...)>, const std::string &name, Args &&...args) const
 
template<class Ret , class... FArgs, class... Args>
decltype(auto) call_extra_func_helper (void *instance, FuncTag< Ret(instance_t *, FArgs...)>, const std::string &name, Args &&...args)
 
template<class Ret , class... FArgs, class... Args>
decltype(auto) call_extra_func_helper (const void *, FuncTag< Ret(FArgs...)>, const std::string &name, Args &&...args) const
 

Private Attributes

std::shared_ptr< void > instance
 Problem instance created by the registration function, including the deleter to destroy it.
 
control_problem_functions_tfunctions = nullptr
 Pointer to the struct of function pointers for evaluating the objective, constraints, their gradients, etc.
 
std::string so_filename
 
std::string symbol_prefix
 
dl_handle_t handle
 Handle to the shared library (returned by dlopen).
 
std::shared_ptr< function_dict_textra_functions
 An associative array of additional functions exposed by the problem.
 

Member Typedef Documentation

◆ Box

using Box = alpaqa::Box<config_t>

Definition at line 209 of file dl-problem.hpp.

◆ instance_t

using instance_t = DLLoader::instance_t

Definition at line 283 of file dl-problem.hpp.

◆ dl_handle_t

using dl_handle_t = std::shared_ptr<void>
protectedinherited

Definition at line 29 of file dl-problem.hpp.

Constructor & Destructor Documentation

◆ DLControlProblem()

DLControlProblem ( std::string  so_filename,
std::string  symbol_prefix = "alpaqa_control_problem",
void *  user_param = nullptr 
)

Load a problem from a shared library.

Parameters
so_filenameFilename of the shared library to load.
symbol_prefixPrefix of the registration function.
user_paramPointer to custom user data to pass to the registration function.

Definition at line 145 of file dl-problem.cpp.

Member Function Documentation

◆ get_N()

length_t get_N ( ) const
inline

Definition at line 229 of file dl-problem.hpp.

◆ get_nx()

length_t get_nx ( ) const
inline

Definition at line 230 of file dl-problem.hpp.

◆ get_nu()

length_t get_nu ( ) const
inline

Definition at line 231 of file dl-problem.hpp.

◆ get_nh()

length_t get_nh ( ) const
inline

Definition at line 232 of file dl-problem.hpp.

◆ get_nh_N()

length_t get_nh_N ( ) const
inline

Definition at line 233 of file dl-problem.hpp.

◆ get_nc()

length_t get_nc ( ) const
inline

Definition at line 234 of file dl-problem.hpp.

◆ get_nc_N()

length_t get_nc_N ( ) const
inline

Definition at line 235 of file dl-problem.hpp.

◆ check()

void check ( ) const
inline

Definition at line 237 of file dl-problem.hpp.

◆ get_U()

auto get_U ( Box U) const

Definition at line 161 of file dl-problem.cpp.

◆ get_D()

auto get_D ( Box D) const

Definition at line 162 of file dl-problem.cpp.

◆ get_D_N()

auto get_D_N ( Box D) const

Definition at line 163 of file dl-problem.cpp.

◆ get_x_init()

auto get_x_init ( rvec  x_init) const

Definition at line 164 of file dl-problem.cpp.

◆ eval_f()

auto eval_f ( index_t  timestep,
crvec  x,
crvec  u,
rvec  fxu 
) const

Definition at line 165 of file dl-problem.cpp.

◆ eval_jac_f()

auto eval_jac_f ( index_t  timestep,
crvec  x,
crvec  u,
rmat  J_fxu 
) const

Definition at line 166 of file dl-problem.cpp.

◆ eval_grad_f_prod()

auto eval_grad_f_prod ( index_t  timestep,
crvec  x,
crvec  u,
crvec  p,
rvec  grad_fxu_p 
) const

Definition at line 167 of file dl-problem.cpp.

◆ eval_h()

auto eval_h ( index_t  timestep,
crvec  x,
crvec  u,
rvec  h 
) const

Definition at line 168 of file dl-problem.cpp.

◆ eval_h_N()

auto eval_h_N ( crvec  x,
rvec  h 
) const

Definition at line 169 of file dl-problem.cpp.

◆ eval_l()

auto eval_l ( index_t  timestep,
crvec  h 
) const

Definition at line 170 of file dl-problem.cpp.

◆ eval_l_N()

auto eval_l_N ( crvec  h) const

Definition at line 171 of file dl-problem.cpp.

◆ eval_qr()

auto eval_qr ( index_t  timestep,
crvec  xu,
crvec  h,
rvec  qr 
) const

Definition at line 172 of file dl-problem.cpp.

◆ eval_q_N()

auto eval_q_N ( crvec  x,
crvec  h,
rvec  q 
) const

Definition at line 173 of file dl-problem.cpp.

◆ eval_add_Q()

auto eval_add_Q ( index_t  timestep,
crvec  xu,
crvec  h,
rmat  Q 
) const

Definition at line 174 of file dl-problem.cpp.

◆ eval_add_Q_N()

auto eval_add_Q_N ( crvec  x,
crvec  h,
rmat  Q 
) const

Definition at line 175 of file dl-problem.cpp.

◆ eval_add_R_masked()

auto eval_add_R_masked ( index_t  timestep,
crvec  xu,
crvec  h,
crindexvec  mask,
rmat  R,
rvec  work 
) const

Definition at line 176 of file dl-problem.cpp.

◆ eval_add_S_masked()

auto eval_add_S_masked ( index_t  timestep,
crvec  xu,
crvec  h,
crindexvec  mask,
rmat  S,
rvec  work 
) const

Definition at line 177 of file dl-problem.cpp.

◆ eval_add_R_prod_masked()

auto 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

Definition at line 178 of file dl-problem.cpp.

◆ eval_add_S_prod_masked()

auto eval_add_S_prod_masked ( index_t  timestep,
crvec  xu,
crvec  h,
crindexvec  mask_K,
crvec  v,
rvec  out,
rvec  work 
) const

Definition at line 179 of file dl-problem.cpp.

◆ get_R_work_size()

auto get_R_work_size ( ) const

Definition at line 180 of file dl-problem.cpp.

◆ get_S_work_size()

auto get_S_work_size ( ) const

Definition at line 181 of file dl-problem.cpp.

◆ eval_constr()

auto eval_constr ( index_t  timestep,
crvec  x,
rvec  c 
) const

Definition at line 182 of file dl-problem.cpp.

◆ eval_constr_N()

auto eval_constr_N ( crvec  x,
rvec  c 
) const

Definition at line 183 of file dl-problem.cpp.

◆ eval_grad_constr_prod()

auto eval_grad_constr_prod ( index_t  timestep,
crvec  x,
crvec  p,
rvec  grad_cx_p 
) const

Definition at line 184 of file dl-problem.cpp.

◆ eval_grad_constr_prod_N()

auto eval_grad_constr_prod_N ( crvec  x,
crvec  p,
rvec  grad_cx_p 
) const

Definition at line 185 of file dl-problem.cpp.

◆ eval_add_gn_hess_constr()

auto eval_add_gn_hess_constr ( index_t  timestep,
crvec  x,
crvec  M,
rmat  out 
) const

Definition at line 186 of file dl-problem.cpp.

◆ eval_add_gn_hess_constr_N()

auto eval_add_gn_hess_constr_N ( crvec  x,
crvec  M,
rmat  out 
) const

Definition at line 187 of file dl-problem.cpp.

◆ provides_get_D()

bool provides_get_D ( ) const

Definition at line 189 of file dl-problem.cpp.

◆ provides_get_D_N()

bool provides_get_D_N ( ) const

Definition at line 190 of file dl-problem.cpp.

◆ provides_eval_add_Q_N()

bool provides_eval_add_Q_N ( ) const

Definition at line 191 of file dl-problem.cpp.

◆ provides_eval_add_R_prod_masked()

bool provides_eval_add_R_prod_masked ( ) const

Definition at line 192 of file dl-problem.cpp.

◆ provides_eval_add_S_prod_masked()

bool provides_eval_add_S_prod_masked ( ) const

Definition at line 193 of file dl-problem.cpp.

◆ provides_get_R_work_size()

bool provides_get_R_work_size ( ) const

Definition at line 194 of file dl-problem.cpp.

◆ provides_get_S_work_size()

bool provides_get_S_work_size ( ) const

Definition at line 195 of file dl-problem.cpp.

◆ provides_eval_constr()

bool provides_eval_constr ( ) const

Definition at line 196 of file dl-problem.cpp.

◆ provides_eval_constr_N()

bool provides_eval_constr_N ( ) const

Definition at line 197 of file dl-problem.cpp.

◆ provides_eval_grad_constr_prod()

bool provides_eval_grad_constr_prod ( ) const

Definition at line 198 of file dl-problem.cpp.

◆ provides_eval_grad_constr_prod_N()

bool provides_eval_grad_constr_prod_N ( ) const

Definition at line 199 of file dl-problem.cpp.

◆ provides_eval_add_gn_hess_constr()

bool provides_eval_add_gn_hess_constr ( ) const

Definition at line 200 of file dl-problem.cpp.

◆ provides_eval_add_gn_hess_constr_N()

bool provides_eval_add_gn_hess_constr_N ( ) const

Definition at line 201 of file dl-problem.cpp.

◆ call_extra_func() [1/2]

decltype(auto) call_extra_func ( const std::string &  name,
Args &&...  args 
) const
inline

Definition at line 286 of file dl-problem.hpp.

◆ call_extra_func() [2/2]

decltype(auto) call_extra_func ( const std::string &  name,
Args &&...  args 
)
inline

Definition at line 293 of file dl-problem.hpp.

+ Here is the call graph for this function:

◆ load_lib()

std::shared_ptr< void > load_lib ( ) const
protectedinherited

Open the shared library using dlopen

Definition at line 12 of file dl-problem.cpp.

◆ load_func()

F * load_func ( std::string_view  name) const
protectedinherited

Load a function with signature F from the library using dlsym.

Definition at line 22 of file dl-problem.cpp.

◆ extra_func()

const std::function< Signature > & extra_func ( const std::string &  name) const
inlineprotectedinherited

Definition at line 44 of file dl-problem.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ call_extra_func_helper() [1/3]

decltype(auto) call_extra_func_helper ( const void *  instance,
FuncTag< Ret(const instance_t *, FArgs...)>  ,
const std::string &  name,
Args &&...  args 
) const
inlineprotectedinherited

Definition at line 71 of file dl-problem.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ call_extra_func_helper() [2/3]

decltype(auto) call_extra_func_helper ( void *  instance,
FuncTag< Ret(instance_t *, FArgs...)>  ,
const std::string &  name,
Args &&...  args 
)
inlineprotectedinherited

Definition at line 80 of file dl-problem.hpp.

+ Here is the call graph for this function:

◆ call_extra_func_helper() [3/3]

decltype(auto) call_extra_func_helper ( const void *  ,
FuncTag< Ret(FArgs...)>  ,
const std::string &  name,
Args &&...  args 
) const
inlineprotectedinherited

Definition at line 87 of file dl-problem.hpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ instance

std::shared_ptr<void> instance
private

Problem instance created by the registration function, including the deleter to destroy it.

Definition at line 223 of file dl-problem.hpp.

◆ functions

control_problem_functions_t* functions = nullptr
private

Pointer to the struct of function pointers for evaluating the objective, constraints, their gradients, etc.

Definition at line 226 of file dl-problem.hpp.

◆ so_filename

std::string so_filename
protectedinherited

Definition at line 26 of file dl-problem.hpp.

◆ symbol_prefix

std::string symbol_prefix
protectedinherited

Definition at line 27 of file dl-problem.hpp.

◆ handle

dl_handle_t handle
protectedinherited

Handle to the shared library (returned by dlopen).

Definition at line 31 of file dl-problem.hpp.

◆ extra_functions

std::shared_ptr<function_dict_t> extra_functions
protectedinherited

An associative array of additional functions exposed by the problem.

Definition at line 34 of file dl-problem.hpp.


The documentation for this class was generated from the following files: