alpaqa matlab
Nonconvex constrained optimization
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Types | Private Attributes | List of all members
CasADiProblem< Conf > Class Template Reference

#include <alpaqa/casadi/CasADiProblem.hpp>

Detailed Description

template<Config Conf = EigenConfigd>
class alpaqa::CasADiProblem< Conf >

Problem definition for a CasADi problem, loaded from a DLL.

Examples
C++/CasADi/Rosenbrock/main.cpp.

Definition at line 35 of file CasADiProblem.hpp.

+ Inheritance diagram for CasADiProblem< Conf >:
+ Collaboration diagram for CasADiProblem< Conf >:

Public Types

using Sparsity = alpaqa::Sparsity< config_t >
 
using Box = alpaqa::Box< config_t >
 

Public Member Functions

 CasADiProblem (const std::string &filename)
 Load a problem generated by CasADi (with parameters).
 
 CasADiProblem (const SerializedCasADiFunctions &functions)
 Create a problem from a collection of serialized CasADi functions.
 
 CasADiProblem (const CasADiFunctions &functions)
 Create a problem from a collection of CasADi functions.
 
 ~CasADiProblem ()
 
 CasADiProblem (const CasADiProblem &)
 
CasADiProblemoperator= (const CasADiProblem &)
 
 CasADiProblem (CasADiProblem &&) noexcept
 
CasADiProblemoperator= (CasADiProblem &&) noexcept
 
void load_numerical_data (const std::filesystem::path &filepath, char sep=',')
 Load the numerical problem data (bounds and parameters) from a CSV file.
 
real_t eval_f (crvec x) const
 
void eval_grad_f (crvec x, rvec grad_fx) const
 
real_t eval_f_grad_f (crvec x, rvec grad_fx) const
 
void eval_g (crvec x, rvec g) const
 
void eval_grad_g_prod (crvec x, crvec y, rvec grad_gxy) const
 
void eval_grad_ψ (crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
 
real_t eval_ψ_grad_ψ (crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
 
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
 
void eval_grad_gi (crvec x, index_t i, rvec grad_i) const
 
Sparsity get_jac_g_sparsity () const
 
void eval_jac_g (crvec x, rvec J_values) const
 
void eval_hess_L_prod (crvec x, crvec y, real_t scale, crvec v, rvec Hv) const
 
Sparsity get_hess_L_sparsity () const
 
void eval_hess_L (crvec x, crvec y, real_t scale, rvec H_values) const
 
void eval_hess_ψ_prod (crvec x, crvec y, crvec Σ, real_t scale, crvec v, rvec Hv) const
 
Sparsity get_hess_ψ_sparsity () const
 
void eval_hess_ψ (crvec x, crvec y, crvec Σ, real_t scale, rvec H_values) const
 
bool provides_eval_grad_L () const
 
bool provides_eval_ψ () const
 
bool provides_eval_grad_ψ () const
 
bool provides_eval_ψ_grad_ψ () const
 
bool provides_eval_grad_gi () const
 
bool provides_eval_jac_g () const
 
bool provides_eval_hess_L_prod () const
 
bool provides_eval_hess_L () const
 
bool provides_eval_hess_ψ_prod () const
 
bool provides_eval_hess_ψ () const
 
void resize (length_t n, length_t m)
 Change the dimensions of the problem (number of decision variables and number of constaints).
 
length_t get_n () const
 Number of decision variables, n.
 
length_t get_m () const
 Number of constraints, m.
 
real_t eval_prox_grad_step (real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p) const
 
void eval_proj_diff_g (crvec z, rvec p) const
 
void eval_proj_multipliers (rvec y, real_t M) const
 
const Boxget_box_C () const
 
const Boxget_box_D () const
 
index_t eval_inactive_indices_res_lna (real_t γ, crvec x, crvec grad_ψ, rindexvec J) const
 
void check () const
 

Static Public Member Functions

static real_t eval_proj_grad_step_box (const Box &C, real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p)
 Projected gradient step for rectangular box C.
 
static void eval_prox_grad_step_box_l1_impl (const Box &C, const auto &λ, real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p)
 Proximal gradient step for rectangular box C with ℓ₁-regularization.
 
static real_t eval_prox_grad_step_box_l1 (const Box &C, const auto &λ, real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p)
 Proximal gradient step for rectangular box C with ℓ₁-regularization.
 
static real_t eval_prox_grad_step_box_l1_scal (const Box &C, real_t λ, real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p)
 Proximal gradient step for rectangular box C with ℓ₁-regularization.
 
static void eval_proj_multipliers_box (const Box &D, rvec y, real_t M, index_t penalty_alm_split)
 

Public Attributes

vec param
 
length_t n
 Number of decision variables, dimension of x.
 
length_t m
 Number of constraints, dimension of g(x) and z.
 
Box C {this->n}
 Constraints of the decision variables, \( x \in C \).
 
Box D {this->m}
 Other constraints, \( g(x) \in D \).
 
vec l1_reg {}
 \( \ell_1 \) (1-norm) regularization parameter.
 
index_t penalty_alm_split = 0
 Components of the constraint function with indices below this number are handled using a quadratic penalty method rather than using an augmented Lagrangian method.
 

Private Types

using Functions = casadi_loader::CasADiFunctionsWithParam< Conf >
 

Private Attributes

util::copyable_unique_ptr< Functionsimpl
 

Member Typedef Documentation

◆ Sparsity

template<Config Conf = EigenConfigd>
using Sparsity = alpaqa::Sparsity<config_t>

Definition at line 38 of file CasADiProblem.hpp.

◆ Functions

template<Config Conf = EigenConfigd>
using Functions = casadi_loader::CasADiFunctionsWithParam<Conf>
private

Definition at line 125 of file CasADiProblem.hpp.

◆ Box

template<Config Conf>
using Box = alpaqa::Box<config_t>
inherited

Definition at line 19 of file box-constr-problem.hpp.

Constructor & Destructor Documentation

◆ CasADiProblem() [1/5]

template<Config Conf>
CasADiProblem ( const std::string &  filename)

Load a problem generated by CasADi (with parameters).

Parameters
filenameFilename of the shared library to load the functions from.

The file should contain functions with the names f, grad_f, g and grad_g. These functions evaluate the objective function, its gradient, the constraints, and the constraint gradient times a vector respectively. For second order solvers, additional functions hess_L, hess_ψ, hess_L_prod and hess_ψ_prod can be provided to evaluate the Hessian of the (augmented) Lagrangian and Hessian-vector products.

Exceptions
std::invalid_argumentThe dimensions of the loaded functions do not match.

Definition at line 135 of file CasADiProblem.tpp.

◆ CasADiProblem() [2/5]

template<Config Conf>
CasADiProblem ( const SerializedCasADiFunctions functions)

Create a problem from a collection of serialized CasADi functions.

Definition at line 161 of file CasADiProblem.tpp.

◆ CasADiProblem() [3/5]

template<Config Conf>
CasADiProblem ( const CasADiFunctions functions)

Create a problem from a collection of CasADi functions.

Definition at line 183 of file CasADiProblem.tpp.

◆ ~CasADiProblem()

template<Config Conf>
~CasADiProblem ( )
default

◆ CasADiProblem() [4/5]

template<Config Conf>
CasADiProblem ( const CasADiProblem< Conf > &  )
default

◆ CasADiProblem() [5/5]

template<Config Conf>
CasADiProblem ( CasADiProblem< Conf > &&  )
defaultnoexcept

Member Function Documentation

◆ operator=() [1/2]

template<Config Conf>
CasADiProblem< Conf > & operator= ( const CasADiProblem< Conf > &  )
default

◆ operator=() [2/2]

template<Config Conf>
CasADiProblem< Conf > & operator= ( CasADiProblem< Conf > &&  )
defaultnoexcept

◆ load_numerical_data()

template<Config Conf>
void load_numerical_data ( const std::filesystem::path &  filepath,
char  sep = ',' 
)

Load the numerical problem data (bounds and parameters) from a CSV file.

The file should contain 7 rows, with the following contents:

  1. C lower bound [n]
  2. C upper bound [n]
  3. D lower bound [m]
  4. D upper bound [m]
  5. param [p]
  6. l1_reg [0, 1 or n]
  7. penalty_alm_split [1]

Line endings are encoded using a single line feed (\n), and the column separator can be specified using the sep argument.

Definition at line 205 of file CasADiProblem.tpp.

+ Here is the call graph for this function:

◆ eval_f()

template<Config Conf>
auto eval_f ( crvec  x) const

Definition at line 268 of file CasADiProblem.tpp.

◆ eval_grad_f()

template<Config Conf>
void eval_grad_f ( crvec  x,
rvec  grad_fx 
) const

Definition at line 275 of file CasADiProblem.tpp.

◆ eval_f_grad_f()

template<Config Conf>
auto eval_f_grad_f ( crvec  x,
rvec  grad_fx 
) const

Definition at line 281 of file CasADiProblem.tpp.

◆ eval_g()

template<Config Conf>
void eval_g ( crvec  x,
rvec  g 
) const

Definition at line 288 of file CasADiProblem.tpp.

◆ eval_grad_g_prod()

template<Config Conf>
void eval_grad_g_prod ( crvec  x,
crvec  y,
rvec  grad_gxy 
) const

Definition at line 298 of file CasADiProblem.tpp.

◆ eval_grad_ψ()

template<Config Conf>
void eval_grad_ψ ( crvec  x,
crvec  y,
crvec  Σ,
rvec  grad_ψ,
rvec  work_n,
rvec  work_m 
) const

Definition at line 310 of file CasADiProblem.tpp.

◆ eval_ψ_grad_ψ()

template<Config Conf>
CasADiProblem< Conf >::real_t eval_ψ_grad_ψ ( crvec  x,
crvec  y,
crvec  Σ,
rvec  grad_ψ,
rvec  work_n,
rvec  work_m 
) const

Definition at line 325 of file CasADiProblem.tpp.

◆ eval_grad_L()

template<Config Conf>
void eval_grad_L ( crvec  x,
crvec  y,
rvec  grad_L,
rvec  work_n 
) const

Definition at line 337 of file CasADiProblem.tpp.

◆ eval_ψ()

template<Config Conf>
CasADiProblem< Conf >::real_t eval_ψ ( crvec  x,
crvec  y,
crvec  Σ,
rvec  ŷ 
) const

Definition at line 346 of file CasADiProblem.tpp.

◆ eval_grad_gi()

template<Config Conf>
void eval_grad_gi ( crvec  x,
index_t  i,
rvec  grad_i 
) const

Definition at line 357 of file CasADiProblem.tpp.

◆ get_jac_g_sparsity()

template<Config Conf>
auto get_jac_g_sparsity ( ) const

Definition at line 377 of file CasADiProblem.tpp.

◆ eval_jac_g()

template<Config Conf>
void eval_jac_g ( crvec  x,
rvec  J_values 
) const

Definition at line 392 of file CasADiProblem.tpp.

◆ eval_hess_L_prod()

template<Config Conf>
void eval_hess_L_prod ( crvec  x,
crvec  y,
real_t  scale,
crvec  v,
rvec  Hv 
) const

Definition at line 399 of file CasADiProblem.tpp.

◆ get_hess_L_sparsity()

template<Config Conf>
auto get_hess_L_sparsity ( ) const

Definition at line 408 of file CasADiProblem.tpp.

◆ eval_hess_L()

template<Config Conf>
void eval_hess_L ( crvec  x,
crvec  y,
real_t  scale,
rvec  H_values 
) const

Definition at line 422 of file CasADiProblem.tpp.

◆ eval_hess_ψ_prod()

template<Config Conf>
void eval_hess_ψ_prod ( crvec  x,
crvec  y,
crvec  Σ,
real_t  scale,
crvec  v,
rvec  Hv 
) const

Definition at line 431 of file CasADiProblem.tpp.

◆ get_hess_ψ_sparsity()

template<Config Conf>
auto get_hess_ψ_sparsity ( ) const

Definition at line 443 of file CasADiProblem.tpp.

◆ eval_hess_ψ()

template<Config Conf>
void eval_hess_ψ ( crvec  x,
crvec  y,
crvec  Σ,
real_t  scale,
rvec  H_values 
) const

Definition at line 457 of file CasADiProblem.tpp.

◆ provides_eval_grad_L()

template<Config Conf>
bool provides_eval_grad_L ( ) const
See also
TypeErasedProblem::provides_eval_grad_L

Definition at line 483 of file CasADiProblem.tpp.

◆ provides_eval_ψ()

template<Config Conf>
bool provides_eval_ψ ( ) const
See also
TypeErasedProblem::provides_eval_ψ

Definition at line 471 of file CasADiProblem.tpp.

◆ provides_eval_grad_ψ()

template<Config Conf>
bool provides_eval_grad_ψ ( ) const
See also
TypeErasedProblem::provides_eval_grad_ψ

Definition at line 475 of file CasADiProblem.tpp.

◆ provides_eval_ψ_grad_ψ()

template<Config Conf>
bool provides_eval_ψ_grad_ψ ( ) const

◆ provides_eval_grad_gi()

template<Config Conf>
bool provides_eval_grad_gi ( ) const
See also
TypeErasedProblem::provides_eval_grad_gi

Definition at line 467 of file CasADiProblem.tpp.

◆ provides_eval_jac_g()

template<Config Conf>
bool provides_eval_jac_g ( ) const
See also
TypeErasedProblem::provides_eval_jac_g

Definition at line 487 of file CasADiProblem.tpp.

◆ provides_eval_hess_L_prod()

template<Config Conf>
bool provides_eval_hess_L_prod ( ) const

◆ provides_eval_hess_L()

template<Config Conf>
bool provides_eval_hess_L ( ) const
See also
TypeErasedProblem::provides_eval_hess_L

Definition at line 495 of file CasADiProblem.tpp.

◆ provides_eval_hess_ψ_prod()

template<Config Conf>
bool provides_eval_hess_ψ_prod ( ) const

◆ provides_eval_hess_ψ()

template<Config Conf>
bool provides_eval_hess_ψ ( ) const
See also
TypeErasedProblem::provides_eval_hess_ψ

Definition at line 503 of file CasADiProblem.tpp.

◆ resize()

template<Config Conf>
void resize ( length_t  n,
length_t  m 
)
inlineinherited

Change the dimensions of the problem (number of decision variables and number of constaints).

Destructive: resizes and/or resets the members C, D, l1_reg and penalty_alm_split.

Definition at line 41 of file box-constr-problem.hpp.

◆ get_n()

template<Config Conf>
length_t get_n ( ) const
inlineinherited

Number of decision variables, n.

Definition at line 75 of file box-constr-problem.hpp.

◆ get_m()

template<Config Conf>
length_t get_m ( ) const
inlineinherited

Number of constraints, m.

Definition at line 77 of file box-constr-problem.hpp.

◆ eval_proj_grad_step_box()

template<Config Conf>
static real_t eval_proj_grad_step_box ( const Box C,
real_t  γ,
crvec  x,
crvec  grad_ψ,
rvec  ,
rvec  p 
)
inlinestaticinherited

Projected gradient step for rectangular box C.

\[ \begin{aligned} \hat x &= \Pi_C(x - \gamma\nabla\psi(x)) \\ p &= \hat x - x \\ &= \max(\underline x - x, \;\min(-\gamma\nabla\psi(x), \overline x - x) \end{aligned} \]

Definition at line 84 of file box-constr-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_prox_grad_step_box_l1_impl()

template<Config Conf>
static void eval_prox_grad_step_box_l1_impl ( const Box C,
const auto λ,
real_t  γ,
crvec  x,
crvec  grad_ψ,
rvec  ,
rvec  p 
)
inlinestaticinherited

Proximal gradient step for rectangular box C with ℓ₁-regularization.

\[ \begin{aligned} h(x) &= \|x\|_1 + \delta_C(x) \\ \hat x &= \prox_{\gamma h}(x - \gamma\nabla\psi(x)) \\ &= -\max\big( x - \overline x, \;\min\big( x - \underline x, \;\min\big( \gamma(\nabla\psi(x) + \lambda), \;\max\big( \gamma(\nabla\psi(x) - \lambda), x \big) \big) \big) \big) \end{aligned} \]

Definition at line 107 of file box-constr-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_prox_grad_step_box_l1()

template<Config Conf>
static real_t eval_prox_grad_step_box_l1 ( const Box C,
const auto λ,
real_t  γ,
crvec  x,
crvec  grad_ψ,
rvec  ,
rvec  p 
)
inlinestaticinherited

Proximal gradient step for rectangular box C with ℓ₁-regularization.

\[ \begin{aligned} h(x) &= \|x\|_1 + \delta_C(x) \\ \hat x &= \prox_{\gamma h}(x - \gamma\nabla\psi(x)) \\ &= -\max\big( x - \overline x, \;\min\big( x - \underline x, \;\min\big( \gamma(\nabla\psi(x) + \lambda), \;\max\big( \gamma(\nabla\psi(x) - \lambda), x \big) \big) \big) \big) \end{aligned} \]

Definition at line 116 of file box-constr-problem.hpp.

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

◆ eval_prox_grad_step_box_l1_scal()

template<Config Conf>
static real_t eval_prox_grad_step_box_l1_scal ( const Box C,
real_t  λ,
real_t  γ,
crvec  x,
crvec  grad_ψ,
rvec  ,
rvec  p 
)
inlinestaticinherited

Proximal gradient step for rectangular box C with ℓ₁-regularization.

\[ \begin{aligned} h(x) &= \|x\|_1 + \delta_C(x) \\ \hat x &= \prox_{\gamma h}(x - \gamma\nabla\psi(x)) \\ &= -\max\big( x - \overline x, \;\min\big( x - \underline x, \;\min\big( \gamma(\nabla\psi(x) + \lambda), \;\max\big( \gamma(\nabla\psi(x) - \lambda), x \big) \big) \big) \big) \end{aligned} \]

Definition at line 123 of file box-constr-problem.hpp.

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

◆ eval_prox_grad_step()

template<Config Conf>
real_t eval_prox_grad_step ( real_t  γ,
crvec  x,
crvec  grad_ψ,
rvec  ,
rvec  p 
) const
inlineinherited
See also
TypeErasedProblem::eval_prox_grad_step

Definition at line 132 of file box-constr-problem.hpp.

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

◆ eval_proj_diff_g()

template<Config Conf>
void eval_proj_diff_g ( crvec  z,
rvec  p 
) const
inlineinherited
See also
TypeErasedProblem::eval_proj_diff_g

Definition at line 142 of file box-constr-problem.hpp.

◆ eval_proj_multipliers_box()

template<Config Conf>
static void eval_proj_multipliers_box ( const Box D,
rvec  y,
real_t  M,
index_t  penalty_alm_split 
)
inlinestaticinherited

Definition at line 144 of file box-constr-problem.hpp.

+ Here is the caller graph for this function:

◆ eval_proj_multipliers()

template<Config Conf>
void eval_proj_multipliers ( rvec  y,
real_t  M 
) const
inlineinherited
See also
TypeErasedProblem::eval_proj_multipliers

Definition at line 166 of file box-constr-problem.hpp.

+ Here is the call graph for this function:

◆ get_box_C()

template<Config Conf>
const Box & get_box_C ( ) const
inlineinherited
See also
TypeErasedProblem::get_box_C

Definition at line 171 of file box-constr-problem.hpp.

◆ get_box_D()

template<Config Conf>
const Box & get_box_D ( ) const
inlineinherited
See also
TypeErasedProblem::get_box_D

Definition at line 173 of file box-constr-problem.hpp.

◆ eval_inactive_indices_res_lna()

template<Config Conf>
index_t eval_inactive_indices_res_lna ( real_t  γ,
crvec  x,
crvec  grad_ψ,
rindexvec  J 
) const
inlineinherited

◆ check()

template<Config Conf>
void check ( ) const
inlineinherited
See also
TypeErasedProblem::check

Definition at line 213 of file box-constr-problem.hpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ param

template<Config Conf = EigenConfigd>
vec param

Definition at line 39 of file CasADiProblem.hpp.

◆ impl

template<Config Conf = EigenConfigd>
util::copyable_unique_ptr<Functions> impl
private

Definition at line 126 of file CasADiProblem.hpp.

◆ n

template<Config Conf>
length_t n
inherited

Number of decision variables, dimension of x.

Examples
C++/CustomCppProblem/main.cpp.

Definition at line 22 of file box-constr-problem.hpp.

◆ m

template<Config Conf>
length_t m
inherited

Number of constraints, dimension of g(x) and z.

Examples
C++/CustomCppProblem/main.cpp.

Definition at line 24 of file box-constr-problem.hpp.

◆ C

template<Config Conf>
Box C {this->n}
inherited

Constraints of the decision variables, \( x \in C \).

Examples
C++/CasADi/Rosenbrock/main.cpp.

Definition at line 59 of file box-constr-problem.hpp.

◆ D

template<Config Conf>
Box D {this->m}
inherited

Other constraints, \( g(x) \in D \).

Definition at line 61 of file box-constr-problem.hpp.

◆ l1_reg

template<Config Conf>
vec l1_reg {}
inherited

\( \ell_1 \) (1-norm) regularization parameter.

Possible dimensions are: \( 0 \) (no regularization), \( 1 \) (a single scalar factor), or \( n \) (a different factor for each variable).

Definition at line 66 of file box-constr-problem.hpp.

◆ penalty_alm_split

template<Config Conf>
index_t penalty_alm_split = 0
inherited

Components of the constraint function with indices below this number are handled using a quadratic penalty method rather than using an augmented Lagrangian method.

Specifically, the Lagrange multipliers for these components (which determine the shifts in ALM) are kept at zero.

Definition at line 72 of file box-constr-problem.hpp.


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