Abstract class for constraint models. More...
#include <constraint-base.hpp>
Public Types | |
typedef ConstraintDataAbstractTpl< Scalar > | ConstraintDataAbstract |
typedef DataCollectorAbstractTpl< Scalar > | DataCollectorAbstract |
typedef MathBaseTpl< Scalar > | MathBase |
typedef ResidualModelAbstractTpl< Scalar > | ResidualModelAbstract |
typedef StateAbstractTpl< Scalar > | StateAbstract |
typedef MathBase::VectorXs | VectorXs |
Public Member Functions | |
ConstraintModelAbstractTpl (boost::shared_ptr< StateAbstract > state, boost::shared_ptr< ResidualModelAbstract > residual, const std::size_t ng, const std::size_t nh) | |
Initialize the constraint model. More... | |
ConstraintModelAbstractTpl (boost::shared_ptr< StateAbstract > state, const std::size_t ng, const std::size_t nh) | |
Initialize the constraint model. More... | |
ConstraintModelAbstractTpl (boost::shared_ptr< StateAbstract > state, const std::size_t nu, const std::size_t ng, const std::size_t nh) | |
the constraint model More... | |
virtual void | calc (const boost::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x) |
Compute the constraint value for nodes that depends only on the state. More... | |
virtual void | calc (const boost::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0 |
Compute the constraint value. More... | |
virtual void | calcDiff (const boost::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x) |
Compute the Jacobian of the constraint with respect to the state only. More... | |
virtual void | calcDiff (const boost::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0 |
Compute the Jacobian of the constraint. More... | |
virtual boost::shared_ptr< ConstraintDataAbstract > | createData (DataCollectorAbstract *const data) |
Create the constraint data. More... | |
const VectorXs & | get_lb () const |
Return the lower bound of the constraint. | |
std::size_t | get_ng () const |
Return the number of inequality constraints. | |
std::size_t | get_nh () const |
Return the number of equality constraints. | |
std::size_t | get_nu () const |
Return the dimension of the control input. | |
const boost::shared_ptr< ResidualModelAbstract > & | get_residual () const |
Return the residual model. | |
const boost::shared_ptr< StateAbstract > & | get_state () const |
Return the state. | |
ConstraintType | get_type () const |
Return the type of constraint. | |
const VectorXs & | get_ub () const |
Return the upper bound of the constraint. | |
virtual void | print (std::ostream &os) const |
Print relevant information of the constraint model. More... | |
void | remove_bounds () |
Remove the bounds of the constraint. | |
void | update_bounds (const VectorXs &lower, const VectorXs &upper) |
Update the lower and upper bounds the upper bound of constraint. | |
Public Attributes | |
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar | Scalar |
Protected Attributes | |
VectorXs | lb_ |
Lower bound of the constraint. | |
std::size_t | ng_ |
Number of inequality constraints. | |
std::size_t | nh_ |
Number of equality constraints. | |
std::size_t | nu_ |
Control dimension. | |
boost::shared_ptr< ResidualModelAbstract > | residual_ |
Residual model. | |
boost::shared_ptr< StateAbstract > | state_ |
State description. | |
ConstraintType | type_ |
Type of constraint: inequality=0, equality=1, both=2. | |
VectorXs | ub_ |
Upper bound of the constraint. | |
VectorXs | unone_ |
No control vector. | |
Friends | |
template<class Scalar > | |
std::ostream & | operator<< (std::ostream &os, const CostModelAbstractTpl< Scalar > &model) |
Print information on the constraint model. | |
Abstract class for constraint models.
A constraint model defines both: inequality \(\mathbf{g}(\mathbf{x}, \mathbf{u})\in\mathbb{R}^{ng}\) and equality \(\mathbf{h}(\mathbf{x}, \mathbf{u})\in\mathbb{R}^{nh}\) constraints. The constraint function depends on the state point \(\mathbf{x}\in\mathcal{X}\), which lies in the state manifold described with a nx
-tuple, its velocity \(\dot{\mathbf{x}}\in T_{\mathbf{x}}\mathcal{X}\) that belongs to the tangent space with ndx
dimension, and the control input \(\mathbf{u}\in\mathbb{R}^{nu}\).
The main computations are carried out in calc()
and calcDiff()
routines. calc()
computes the constraint residual and calcDiff()
computes the Jacobians of the constraint function. Concretely speaking, calcDiff()
builds a linear approximation of the constraint function with the form: \(\mathbf{g_x}\in\mathbb{R}^{ng\times ndx}\), \(\mathbf{g_u}\in\mathbb{R}^{ng\times nu}\), \(\mathbf{h_x}\in\mathbb{R}^{nh\times ndx}\) \(\mathbf{h_u}\in\mathbb{R}^{nh\times nu}\). Additionally, it is important to note that calcDiff()
computes the derivatives using the latest stored values by calc()
. Thus, we need to first run calc()
.
calc()
, calcDiff()
, createData()
Definition at line 50 of file constraint-base.hpp.
ConstraintModelAbstractTpl | ( | boost::shared_ptr< StateAbstract > | state, |
boost::shared_ptr< ResidualModelAbstract > | residual, | ||
const std::size_t | ng, | ||
const std::size_t | nh | ||
) |
Initialize the constraint model.
[in] | state | State of the multibody system |
[in] | residual | Residual model |
[in] | ng | Number of inequality constraints |
[in] | nh | Number of equality constraints |
ConstraintModelAbstractTpl | ( | boost::shared_ptr< StateAbstract > | state, |
const std::size_t | nu, | ||
const std::size_t | ng, | ||
const std::size_t | nh | ||
) |
the constraint model
[in] | state | State of the multibody system |
[in] | nu | Dimension of control vector |
[in] | ng | Number of inequality constraints |
[in] | nh | Number of equality constraints |
ConstraintModelAbstractTpl | ( | boost::shared_ptr< StateAbstract > | state, |
const std::size_t | ng, | ||
const std::size_t | nh | ||
) |
Initialize the constraint model.
The default nu
value is obtained from StateAbstractTpl::get_nv()
.
[in] | state | State of the multibody system |
[in] | ng | Number of inequality constraints |
[in] | nh | Number of equality constraints |
|
pure virtual |
Compute the constraint value.
[in] | data | Constraint data |
[in] | x | State point \(\mathbf{x}\in\mathbb{R}^{ndx}\) |
[in] | u | Control input \(\mathbf{u}\in\mathbb{R}^{nu}\) |
Implemented in ConstraintModelNumDiffTpl< _Scalar >, and ConstraintModelResidualTpl< _Scalar >.
|
virtual |
Compute the constraint value for nodes that depends only on the state.
It updates the constraint based on the state only. This function is commonly used in the terminal nodes of an optimal control problem.
[in] | data | Constraint data |
[in] | x | State point \(\mathbf{x}\in\mathbb{R}^{ndx}\) |
Reimplemented in ConstraintModelNumDiffTpl< _Scalar >, and ConstraintModelResidualTpl< _Scalar >.
|
pure virtual |
Compute the Jacobian of the constraint.
It computes the Jacobian of the constraint function. It assumes that calc()
has been run first.
[in] | data | Constraint data |
[in] | x | State point \(\mathbf{x}\in\mathbb{R}^{ndx}\) |
[in] | u | Control input \(\mathbf{u}\in\mathbb{R}^{nu}\) |
Implemented in ConstraintModelNumDiffTpl< _Scalar >, and ConstraintModelResidualTpl< _Scalar >.
|
virtual |
Compute the Jacobian of the constraint with respect to the state only.
It computes the Jacobian of the constraint function based on the state only. This function is commonly used in the terminal nodes of an optimal control problem.
[in] | data | Constraint data |
[in] | x | State point \(\mathbf{x}\in\mathbb{R}^{ndx}\) |
Reimplemented in ConstraintModelNumDiffTpl< _Scalar >, and ConstraintModelResidualTpl< _Scalar >.
|
virtual |
Create the constraint data.
The default data contains objects to store the values of the constraint, residual vector and their first derivatives. However, it is possible to specialize this function is we need to create additional data, for instance, to avoid dynamic memory allocation.
data | Data collector |
Reimplemented in ConstraintModelNumDiffTpl< _Scalar >, and ConstraintModelResidualTpl< _Scalar >.
|
virtual |
Print relevant information of the constraint model.
[out] | os | Output stream object |
Reimplemented in ConstraintModelResidualTpl< _Scalar >.