alpaqa 1.0.0a13
Nonconvex constrained optimization
Loading...
Searching...
No Matches
CasADiProblem.hpp
Go to the documentation of this file.
1#pragma once
2
8#include <filesystem>
9#include <map>
10#include <string>
11
12namespace alpaqa {
13namespace casadi_loader {
14template <Config>
15struct CasADiFunctionsWithParam;
16} // namespace casadi_loader
17
19 std::map<std::string, std::string> functions;
20};
21
22/// Problem definition for a CasADi problem, loaded from a DLL.
23/// @ingroup grp_Problems
24template <Config Conf = EigenConfigd>
25class CasADiProblem : public BoxConstrProblem<Conf> {
26 public:
30
31 /// Load a problem generated by CasADi (with parameters).
32 ///
33 /// @param filename
34 /// Filename of the shared library to load the functions from.
35 ///
36 /// The file should contain functions with the names `f`, `grad_f`, `g` and
37 /// `grad_g`. These functions evaluate the objective function, its gradient,
38 /// the constraints, and the constraint gradient times a vector respectively.
39 /// For second order solvers, additional functions `hess_L`, `hess_ψ`,
40 /// `hess_L_prod` and `hess_ψ_prod` can be provided to evaluate the
41 /// Hessian of the (augmented) Lagrangian and Hessian-vector products.
42 ///
43 /// @throws std::invalid_argument
44 /// The dimensions of the loaded functions do not match.
45 CasADiProblem(const std::string &filename);
46 /// Create a problem from a collection of serialized CasADi functions.
49
54
55 /// Load the numerical problem data (bounds and parameters) from a CSV file.
56 /// The file should contain 7 rows, with the following contents:
57 /// 1. @ref C lower bound [n]
58 /// 2. @ref C upper bound [n]
59 /// 3. @ref D lower bound [m]
60 /// 4. @ref D upper bound [m]
61 /// 5. @ref param [p]
62 /// 6. @ref l1_reg [0, 1 or n]
63 /// 7. @ref penalty_alm_split [1]
64 ///
65 /// Line endings are encoded using a single line feed (`\n`), and the column
66 /// separator can be specified using the @p sep argument.
68 char sep = ',');
69
70 // clang-format off
73 real_t eval_f_grad_f(crvec x, rvec grad_fx) const; // NOLINT(*nodiscard)
74 void eval_g(crvec x, rvec g) const;
76 void eval_grad_ψ(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const;
77 real_t eval_ψ_grad_ψ(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const; // NOLINT(*nodiscard)
78 void eval_grad_L(crvec x, crvec y, rvec grad_L, rvec work_n) const;
89 // clang-format on
90
91 /// @see @ref TypeErasedProblem::provides_eval_grad_gi
93 /// @see @ref TypeErasedProblem::provides_eval_jac_g
95 /// @see @ref TypeErasedProblem::provides_eval_hess_L_prod
97 /// @see @ref TypeErasedProblem::provides_eval_hess_L
99 /// @see @ref TypeErasedProblem::provides_eval_hess_ψ_prod
101 /// @see @ref TypeErasedProblem::provides_eval_hess_ψ
103
104 private:
105 using Functions = casadi_loader::CasADiFunctionsWithParam<Conf>;
106 util::copyable_unique_ptr<Functions> impl;
107};
108
110
111} // 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
std::map< std::string, std::string > functions
Double-precision double configuration.
Definition config.hpp:135
Stores any of the supported sparsity patterns.
Definition sparsity.hpp:106