alpaqa 1.0.0a12
Nonconvex constrained optimization
Loading...
Searching...
No Matches
CasADiProblem.hpp
Go to the documentation of this file.
1#pragma once
2
8#include <filesystem>
9
10namespace alpaqa {
11namespace casadi_loader {
12template <Config>
13struct CasADiFunctionsWithParam;
14} // namespace casadi_loader
15
16/// Problem definition for a CasADi problem, loaded from a DLL.
17/// @ingroup grp_Problems
18template <Config Conf = EigenConfigd>
19class CasADiProblem : public BoxConstrProblem<Conf> {
20 public:
24
25 /// Load a problem generated by CasADi (with parameters).
26 ///
27 /// @param filename
28 /// Filename of the shared library to load the functions from.
29 ///
30 /// The file should contain functions with the names `f`, `grad_f`, `g` and
31 /// `grad_g`. These functions evaluate the objective function, its gradient,
32 /// the constraints, and the constraint gradient times a vector respectively.
33 /// For second order solvers, additional functions `hess_L`, `hess_ψ`,
34 /// `hess_L_prod` and `hess_ψ_prod` can be provided to evaluate the
35 /// Hessian of the (augmented) Lagrangian and Hessian-vector products.
36 ///
37 /// @throws std::invalid_argument
38 /// The dimensions of the loaded functions do not match.
39 CasADiProblem(const std::string &filename);
41
46
47 /// Load the numerical problem data (bounds and parameters) from a CSV file.
48 /// The file should contain 7 rows, with the following contents:
49 /// 1. @ref C lower bound [n]
50 /// 2. @ref C upper bound [n]
51 /// 3. @ref D lower bound [m]
52 /// 4. @ref D upper bound [m]
53 /// 5. @ref param [p]
54 /// 6. @ref l1_reg [0, 1 or n]
55 /// 7. @ref penalty_alm_split [1]
56 ///
57 /// Line endings are encoded using a single line feed (`\n`), and the column
58 /// separator can be specified using the @p sep argument.
60 char sep = ',');
61
62 // clang-format off
65 real_t eval_f_grad_f(crvec x, rvec grad_fx) const; // NOLINT(*nodiscard)
66 void eval_g(crvec x, rvec g) const;
68 void eval_grad_ψ(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const;
69 real_t eval_ψ_grad_ψ(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const; // NOLINT(*nodiscard)
70 void eval_grad_L(crvec x, crvec y, rvec grad_L, rvec work_n) const;
81 // clang-format on
82
83 /// @see @ref TypeErasedProblem::provides_eval_grad_gi
85 /// @see @ref TypeErasedProblem::provides_eval_jac_g
87 /// @see @ref TypeErasedProblem::provides_eval_hess_L_prod
89 /// @see @ref TypeErasedProblem::provides_eval_hess_L
91 /// @see @ref TypeErasedProblem::provides_eval_hess_ψ_prod
93 /// @see @ref TypeErasedProblem::provides_eval_hess_ψ
95
96 private:
97 using Functions = casadi_loader::CasADiFunctionsWithParam<Conf>;
98 util::copyable_unique_ptr<Functions> impl;
99};
100
102
103} // namespace alpaqa
#define CASADI_LOADER_EXPORT_EXTERN_TEMPLATE(strcls, name,...)
Implements common problem functions for minimization problems with box constraints.
Problem definition for a CasADi problem, loaded from a DLL.
bool provides_eval_hess_L() const
void eval_g(crvec x, rvec g) const
bool provides_eval_hess_ψ_prod() const
void eval_jac_g(crvec x, rvec J_values) const
Sparsity get_jac_g_sparsity() const
Sparsity get_hess_ψ_sparsity() const
bool provides_eval_jac_g() const
void eval_hess_ψ(crvec x, crvec y, crvec Σ, real_t scale, rvec H_values) const
Sparsity get_hess_L_sparsity() const
void load_numerical_data(const std::filesystem::path &filepath, char sep=',')
Load the numerical problem data (bounds and parameters) from a CSV file.
CasADiProblem & operator=(const CasADiProblem &)
void eval_grad_L(crvec x, crvec y, rvec grad_L, rvec work_n) const
real_t eval_ψ(crvec x, crvec y, crvec Σ, rvec ŷ) const
CasADiProblem(CasADiProblem &&) noexcept
bool provides_eval_hess_L_prod() const
util::copyable_unique_ptr< Functions > impl
real_t eval_f_grad_f(crvec x, rvec grad_fx) const
void eval_grad_g_prod(crvec x, crvec y, rvec grad_gxy) const
void eval_hess_L_prod(crvec x, crvec y, real_t scale, crvec v, rvec Hv) const
bool provides_eval_grad_gi() const
void eval_grad_f(crvec x, rvec grad_fx) const
real_t eval_ψ_grad_ψ(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
real_t eval_f(crvec x) const
CasADiProblem(const CasADiProblem &)
void eval_grad_gi(crvec x, index_t i, rvec grad_i) const
void eval_hess_L(crvec x, crvec y, real_t scale, rvec H_values) const
bool provides_eval_hess_ψ() const
void eval_grad_ψ(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
void eval_hess_ψ_prod(crvec x, crvec y, crvec Σ, real_t scale, crvec v, rvec Hv) const
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:56
typename Conf::real_t real_t
Definition config.hpp:65
typename Conf::index_t index_t
Definition config.hpp:77
constexpr const auto inf
Definition config.hpp:85
typename Conf::rvec rvec
Definition config.hpp:69
typename Conf::crvec crvec
Definition config.hpp:70
typename Conf::vec vec
Definition config.hpp:66
Double-precision double configuration.
Definition config.hpp:135
Stores any of the supported sparsity patterns.
Definition sparsity.hpp:105