8#define ALPAQA_DL_ABI_VERSION 0xA1A000000005
10#ifdef ALPAQA_DL_PROBLEM_EXPORT
12#define ALPAQA_DL_PROBLEM_EXPORT
13#elif defined(__GNUC__)
14#define ALPAQA_DL_PROBLEM_EXPORT __attribute__((visibility("default")))
16#define ALPAQA_DL_PROBLEM_EXPORT
21#define ALPAQA_DEFAULT(...) {__VA_ARGS__}
23#define ALPAQA_DEFAULT(...)
642#if !defined(__cplusplus) || defined(DOXYGEN)
661#define ALPAQA_PROBLEM_REGISTER_INIT(self) \
663 alpaqa_problem_register_t *: alpaqa_problem_register_init, \
664 alpaqa_control_problem_register_t \
665 *: alpaqa_control_problem_register_init)(self)
668#if defined(__cplusplus) && \
669 (__cplusplus > 201703L || (defined(_MSVC_LANG) && _MSVC_LANG > 201703L))
678 std::map<std::string, std::any>
dict{};
696template <
class Signature>
700template <
class Signature>
710 if (extra_functions ==
nullptr)
712 extra_functions->
dict.insert_or_assign(
721 std::forward<Func>(func));
728 std::forward<Func>(func));
731template <
class Result,
class T,
class Ret,
class... Args>
733 Ret (T::*member)(Args...)) {
735 [member](
void *self_, Args... args) -> Ret {
736 auto *self = reinterpret_cast<T *>(self_);
737 return (self->*member)(std::forward<Args>(args)...);
741template <
class Result,
class T,
class Ret,
class... Args>
743 Ret (T::*member)(Args...)
const) {
745 [member](
const void *self_, Args... args) -> Ret {
746 const auto *self = reinterpret_cast<const T *>(self_);
747 return (self->*member)(std::forward<Args>(args)...);
754template <
auto Member,
class Class,
class Ret,
class... Args>
756 return [](
void *self_, Args... args) -> Ret {
757 auto *self =
reinterpret_cast<Class *
>(self_);
758 return (self->*Member)(std::forward<Args>(args)...);
763template <
auto Member,
class Class,
class Ret,
class... Args>
765 return []<
class Self>(Self *self_, Args... args) -> Ret
766 requires std::is_void_v<Self>
768 const auto *self =
reinterpret_cast<const Class *
>(self_);
769 return (self->*Member)(std::forward<Args>(args)...);
774template <auto Member,
class Class,
class Ret>
776 return []<
class Self>(Self *self_) ->
decltype(
auto)
777 requires std::is_void_v<Self>
779 using CClass = std::conditional_t<std::is_const_v<Self>,
780 std::add_const_t<Class>, Class>;
781 auto *self =
reinterpret_cast<CClass *
>(self_);
782 return self->*Member;
801template <auto Member>
814 delete extra_functions;
815 extra_functions =
nullptr;
void(* eval_add_Q)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *xu, const alpaqa_real_t *h, alpaqa_real_t *Q)
static void alpaqa_control_problem_register_init(alpaqa_control_problem_register_t *self)
void(* eval_grad_f_prod)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *x, const alpaqa_real_t *u, const alpaqa_real_t *p, alpaqa_real_t *grad_fxu_p)
#define ALPAQA_DL_ABI_VERSION
void(* eval_projection_multipliers)(void *instance, alpaqa_real_t *y, alpaqa_real_t M)
Project the Lagrange multipliers.
alpaqa_length_t num_variables
Number of decision variables.
alpaqa_sparse_coo_ll_t sparse_coo_ll
alpaqa_register_arg_type_t
@ alpaqa_register_arg_unspecified
No type was specified (discouraged).
@ alpaqa_register_arg_strings
The data pointer points to a dynamic C++ std::span of std::string_view.
@ alpaqa_register_arg_std_any
The data pointer points to a C++ std::any object.
@ alpaqa_register_arg_py_args
The data pointer points to a C++ tuple of pybind11::args and pybind11::kwargs.
void(* cleanup)(void *)
Pointer to the function to clean up instance.
alpaqa_real_t(* eval_augmented_lagrangian)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, const alpaqa_real_t *Σ, const alpaqa_real_t *zl, const alpaqa_real_t *zu, alpaqa_real_t *ŷ)
Augmented Lagrangian.
alpaqa_sparsity_t(* get_lagrangian_hessian_sparsity)(void *instance)
Get the sparsity pattern of the Hessian of the Lagrangian.
alpaqa_sparsity_t(* get_augmented_lagrangian_hessian_sparsity)(void *instance)
Get the sparsity pattern of the Hessian of the augmented Lagrangian.
void(* eval_add_gn_hess_constr)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *x, const alpaqa_real_t *M, alpaqa_real_t *out)
void(* eval_qr)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *xu, const alpaqa_real_t *h, alpaqa_real_t *qr)
struct alpaqa_function_dict_s alpaqa_function_dict_t
Opaque type for a C++-only map of extra functions.
alpaqa_length_t(* get_S_work_size)(void *instance)
ptrdiff_t alpaqa_length_t
void(* eval_objective_gradient)(void *instance, const alpaqa_real_t *x, alpaqa_real_t *grad_fx)
Gradient of the cost function.
#define ALPAQA_DEFAULT(...)
alpaqa_real_t(* eval_l_N)(void *instance, const alpaqa_real_t *h)
alpaqa_length_t alpaqa_index_t
void(* eval_grad_constr_prod_N)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *p, alpaqa_real_t *grad_cx_p)
void(* get_x_init)(void *instance, alpaqa_real_t *x_init)
void(* eval_add_S_masked)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *xu, const alpaqa_real_t *h, const alpaqa_index_t *mask, alpaqa_real_t *S, alpaqa_real_t *work)
void(* initialize_variable_bounds)(void *instance, alpaqa_real_t *lb, alpaqa_real_t *ub)
Provide the initial values for the bounds of variable_bounds, i.e.
alpaqa_exception_ptr_t * exception
Pointer to an exception that ocurred during problem creation.
void(* eval_q_N)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *h, alpaqa_real_t *q)
void(* eval_objective_gradient_and_constraints_gradient_product)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, alpaqa_real_t *grad_f, alpaqa_real_t *grad_gxy)
Gradient of the cost and gradient-vector product of the constraints.
void(* eval_lagrangian_hessian_product)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, alpaqa_real_t scale, const alpaqa_real_t *v, alpaqa_real_t *Hv)
Hessian-vector product of the Lagrangian.
uint64_t alpaqa_dl_abi_version_t
#define ALPAQA_DL_PROBLEM_EXPORT
alpaqa_real_t(* eval_objective)(void *instance, const alpaqa_real_t *x)
Cost function.
void(* eval_lagrangian_gradient)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, alpaqa_real_t *grad_L, alpaqa_real_t *work_n)
Gradient of the Lagrangian.
void * data
Pointer to the user-provided argument passed to the problem registration functions.
void(* eval_augmented_lagrangian_gradient)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, const alpaqa_real_t *Σ, const alpaqa_real_t *zl, const alpaqa_real_t *zu, alpaqa_real_t *grad_ψ, alpaqa_real_t *work_n, alpaqa_real_t *work_m)
Gradient of the augmented Lagrangian.
void(* eval_augmented_lagrangian_hessian_product)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, const alpaqa_real_t *Σ, alpaqa_real_t scale, const alpaqa_real_t *zl, const alpaqa_real_t *zu, const alpaqa_real_t *v, alpaqa_real_t *Hv)
Hessian-vector product of the augmented Lagrangian.
void(* get_D)(void *instance, alpaqa_real_t *lb, alpaqa_real_t *ub)
void(* eval_f)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *x, const alpaqa_real_t *u, alpaqa_real_t *fxu)
alpaqa_dl_abi_version_t abi_version
To check whether the loaded problem is compatible with the version of the solver.
void(* eval_grad_gi)(void *instance, const alpaqa_real_t *x, alpaqa_index_t i, alpaqa_real_t *grad_gi)
Gradient of specific constraint function.
struct alpaqa_exception_ptr_s alpaqa_exception_ptr_t
Opaque type for a C++-only exception pointer.
alpaqa_real_t(* eval_augmented_lagrangian_and_gradient)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, const alpaqa_real_t *Σ, const alpaqa_real_t *zl, const alpaqa_real_t *zu, alpaqa_real_t *grad_ψ, alpaqa_real_t *work_n, alpaqa_real_t *work_m)
Augmented Lagrangian and its gradient.
void(* eval_grad_constr_prod)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *x, const alpaqa_real_t *p, alpaqa_real_t *grad_cx_p)
const char * name
Name of the problem.
void(* initialize_l1_reg)(void *instance, alpaqa_real_t *lambda, alpaqa_length_t *size)
Provide the initial values for l1_reg, the ℓ₁-regularization factor.
void(* eval_add_R_masked)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *xu, const alpaqa_real_t *h, const alpaqa_index_t *mask, alpaqa_real_t *R, alpaqa_real_t *work)
alpaqa_index_t(* eval_inactive_indices_res_lna)(void *instance, alpaqa_real_t γ, const alpaqa_real_t *x, const alpaqa_real_t *grad_ψ, alpaqa_index_t *J)
Active indices for proximal operator.
alpaqa_sparse_csc_ll_t sparse_csc_ll
alpaqa_sparse_csc_t sparse_csc
void(* eval_h)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *x, const alpaqa_real_t *u, alpaqa_real_t *h)
std::map< std::string, std::any > dict
alpaqa_real_t(* eval_l)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *h)
void(* eval_jac_f)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *x, const alpaqa_real_t *u, alpaqa_real_t *J_fxu)
void(* eval_add_R_prod_masked)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *xu, const alpaqa_real_t *h, const alpaqa_index_t *mask_J, const alpaqa_index_t *mask_K, const alpaqa_real_t *v, alpaqa_real_t *out, alpaqa_real_t *work)
alpaqa_real_t(* eval_proximal_gradient_step)(void *instance, alpaqa_real_t γ, const alpaqa_real_t *x, const alpaqa_real_t *grad_ψ, alpaqa_real_t *x̂, alpaqa_real_t *p)
Proximal gradient step.
alpaqa_length_t num_constraints
Number of constraints.
void(* eval_add_gn_hess_constr_N)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *M, alpaqa_real_t *out)
alpaqa_length_t(* get_R_work_size)(void *instance)
alpaqa_sparse_csc_l_t sparse_csc_l
void(* initialize_general_bounds)(void *instance, alpaqa_real_t *lb, alpaqa_real_t *ub)
Provide the initial values for the bounds of general_bounds, i.e.
alpaqa_real_t(* eval_objective_and_gradient)(void *instance, const alpaqa_real_t *x, alpaqa_real_t *grad_fx)
Cost and its gradient.
void(* get_D_N)(void *instance, alpaqa_real_t *lb, alpaqa_real_t *ub)
void(* eval_constraints_jacobian)(void *instance, const alpaqa_real_t *x, alpaqa_real_t *J_values)
Jacobian of the constraints function.
alpaqa_register_arg_type_t type
Specifies the type of the data pointed to by data.
void(* eval_constr)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *x, alpaqa_real_t *c)
void(* eval_constraints)(void *instance, const alpaqa_real_t *x, alpaqa_real_t *gx)
Constraints function.
void(* eval_add_Q_N)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *h, alpaqa_real_t *Q)
alpaqa_function_dict_t * extra_functions
Pointer to a map of extra functions (C++ only).
alpaqa_control_problem_functions_t * functions
Non-owning pointer, lifetime at least as long as instance.
void(* eval_constraints_gradient_product)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, alpaqa_real_t *grad_gxy)
Gradient-vector product of the constraints function.
void(* eval_projecting_difference_constraints)(void *instance, const alpaqa_real_t *z, alpaqa_real_t *e)
Difference between point and its projection onto the general constraint set D.
void(* eval_lagrangian_hessian)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, alpaqa_real_t scale, alpaqa_real_t *H_values)
Hessian of the Lagrangian.
alpaqa_sparse_coo_t sparse_coo
void(* eval_add_S_prod_masked)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *xu, const alpaqa_real_t *h, const alpaqa_index_t *mask_K, const alpaqa_real_t *v, alpaqa_real_t *out, alpaqa_real_t *work)
void(* eval_augmented_lagrangian_hessian)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, const alpaqa_real_t *Σ, alpaqa_real_t scale, const alpaqa_real_t *zl, const alpaqa_real_t *zu, alpaqa_real_t *H_values)
Hessian of the augmented Lagrangian.
void * instance
Owning pointer.
void(* get_U)(void *instance, alpaqa_real_t *lb, alpaqa_real_t *ub)
alpaqa_problem_functions_t * functions
Non-owning pointer, lifetime at least as long as instance.
void(* eval_constr_N)(void *instance, const alpaqa_real_t *x, alpaqa_real_t *c)
static void alpaqa_problem_register_init(alpaqa_problem_register_t *self)
alpaqa_sparsity_t(* get_constraints_jacobian_sparsity)(void *instance)
Get the sparsity pattern of the Jacobian of the constraints function.
alpaqa_sparse_coo_l_t sparse_coo_l
alpaqa_real_t(* eval_objective_and_constraints)(void *instance, const alpaqa_real_t *x, alpaqa_real_t *g)
Cost and constraints.
void(* eval_h_N)(void *instance, const alpaqa_real_t *x, alpaqa_real_t *h)
C API providing function pointers to problem functions.
User-provided argument that is passed to the problem registration functions.
static auto member_caller(Ret(Class::*)(Args...))
Overload for non-const-qualified member functions.
function_wrapper_t(std::function< Signature >) -> function_wrapper_t< Signature >
std::function< Signature > function
Custom type for which we can export the RTTI to support std::any across shared library boundaries whe...
alpaqa_problem_register_t problem_register_t
alpaqa_control_problem_register_t control_problem_register_t
alpaqa_problem_functions_t problem_functions_t
void unregister_functions(function_dict_t *&extra_functions)
Cleans up the extra functions registered by register_function.
alpaqa_function_dict_t function_dict_t
alpaqa_control_problem_functions_t control_problem_functions_t
void register_function(function_dict_t *&extra_functions, std::string name, Func &&func)
Make the given function available to alpaqa.
void register_member_function(Result &result, std::string name, Ret(T::*member)(Args...))
static auto member_caller()
Wrap the given member function or variable into a (possibly generic) lambda function that accepts the...
@ alpaqa_sparse_coo_l_sorted_by_rows_and_cols
@ alpaqa_sparse_coo_l_sorted_by_cols_and_rows
@ alpaqa_sparse_coo_l_unsorted
@ alpaqa_sparse_coo_l_sorted_by_cols_only
@ alpaqa_sparse_coo_l_sorted_by_rows_only
@ alpaqa_sparse_coo_ll_sorted_by_rows_only
@ alpaqa_sparse_coo_ll_sorted_by_cols_only
@ alpaqa_sparse_coo_ll_unsorted
@ alpaqa_sparse_coo_ll_sorted_by_rows_and_cols
@ alpaqa_sparse_coo_ll_sorted_by_cols_and_rows
const long long * row_indices
const long long * col_indices
@ alpaqa_sparse_coo_unsorted
@ alpaqa_sparse_coo_sorted_by_cols_only
@ alpaqa_sparse_coo_sorted_by_rows_and_cols
@ alpaqa_sparse_coo_sorted_by_cols_and_rows
@ alpaqa_sparse_coo_sorted_by_rows_only
@ alpaqa_sparse_csc_l_sorted_rows
@ alpaqa_sparse_csc_l_unsorted
const long long * inner_idx
const long long * outer_ptr
@ alpaqa_sparse_csc_ll_unsorted
@ alpaqa_sparse_csc_ll_sorted_rows
@ alpaqa_sparse_csc_sorted_rows
@ alpaqa_sparse_csc_unsorted
@ alpaqa_sparsity_sparse_csc
@ alpaqa_sparsity_sparse_coo_l
@ alpaqa_sparsity_sparse_coo_ll
@ alpaqa_sparsity_sparse_csc_ll
@ alpaqa_sparsity_sparse_csc_l
@ alpaqa_sparsity_sparse_coo