Manage the individual constraint models. More...
#include <constraint-manager.hpp>
Public Types | |
typedef ConstraintDataAbstractTpl< Scalar > | ConstraintDataAbstract |
typedef std::map< std::string, boost::shared_ptr< ConstraintDataAbstract > > | ConstraintDataContainer |
typedef ConstraintDataManagerTpl< Scalar > | ConstraintDataManager |
typedef ConstraintItemTpl< Scalar > | ConstraintItem |
typedef ConstraintModelAbstractTpl< Scalar > | ConstraintModelAbstract |
typedef std::map< std::string, boost::shared_ptr< ConstraintItem > > | ConstraintModelContainer |
typedef DataCollectorAbstractTpl< Scalar > | DataCollectorAbstract |
typedef MathBaseTpl< Scalar > | MathBase |
typedef MathBase::MatrixXs | MatrixXs |
typedef StateAbstractTpl< Scalar > | StateAbstract |
typedef MathBase::VectorXs | VectorXs |
Public Member Functions | |
ConstraintModelManagerTpl (boost::shared_ptr< StateAbstract > state) | |
Initialize the constraint-manager model. More... | |
ConstraintModelManagerTpl (boost::shared_ptr< StateAbstract > state, const std::size_t nu) | |
Initialize the constraint-manager model. More... | |
void | addConstraint (const std::string &name, boost::shared_ptr< ConstraintModelAbstract > constraint, const bool active=true) |
Add a constraint item. More... | |
void | calc (const boost::shared_ptr< ConstraintDataManager > &data, const Eigen::Ref< const VectorXs > &x) |
Compute the total constraint value for nodes that depends only on the state. More... | |
void | calc (const boost::shared_ptr< ConstraintDataManager > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u) |
Compute the total constraint value. More... | |
void | calcDiff (const boost::shared_ptr< ConstraintDataManager > &data, const Eigen::Ref< const VectorXs > &x) |
Compute the Jacobian of the total constraint with respect to the state only. More... | |
void | calcDiff (const boost::shared_ptr< ConstraintDataManager > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u) |
Compute the Jacobian of the total constraint. More... | |
void | changeConstraintStatus (const std::string &name, bool active) |
Change the constraint status. More... | |
boost::shared_ptr< ConstraintDataManager > | createData (DataCollectorAbstract *const data) |
Create the constraint data. More... | |
const std::set< std::string > & | get_active_set () const |
Return the names of the set of active constraints. | |
const ConstraintModelContainer & | get_constraints () const |
Return the stack of constraint models. | |
const std::set< std::string > & | get_inactive_set () const |
Return the names of the set of inactive constraints. | |
const VectorXs & | get_lb () const |
Return the state lower bound. | |
std::size_t | get_ng () const |
Return the number of active inequality constraints. | |
std::size_t | get_nh () const |
Return the number of active equality constraints. | |
std::size_t | get_nu () const |
Return the dimension of the control input. | |
const boost::shared_ptr< StateAbstract > & | get_state () const |
Return the state. | |
const VectorXs & | get_ub () const |
Return the state upper bound. | |
bool | getConstraintStatus (const std::string &name) const |
Return the status of a given constraint name. More... | |
void | removeConstraint (const std::string &name) |
Remove a constraint item. More... | |
Public Attributes | |
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar | Scalar |
Friends | |
template<class Scalar > | |
std::ostream & | operator<< (std::ostream &os, const ConstraintModelManagerTpl< Scalar > &model) |
Print information on the stack of constraints. | |
Manage the individual constraint models.
This class serves to manage a set of added constraint models. The constraint functions might active or inactive, with this approach we avoid dynamic allocation of memory. Each constraint model is added through addConstraint
, where its status can be defined.
The main computations are carring out in calc
and calcDiff
routines. calc
computes the constraint residuals and calcDiff
computes the Jacobians of the constraint functions. Concretely speaking, calcDiff
builds a linear approximation of the total constraint function (both inequality and equality) with the form: \(\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}\).
StateAbstractTpl
, calc()
, calcDiff()
, createData()
Definition at line 68 of file constraint-manager.hpp.
ConstraintModelManagerTpl | ( | boost::shared_ptr< StateAbstract > | state, |
const std::size_t | nu | ||
) |
Initialize the constraint-manager model.
[in] | state | State of the multibody system |
[in] | nu | Dimension of control vector |
|
explicit |
Initialize the constraint-manager model.
The default nu
value is obtained from StateAbstractTpl::get_nv()
.
[in] | state | State of the multibody system |
void addConstraint | ( | const std::string & | name, |
boost::shared_ptr< ConstraintModelAbstract > | constraint, | ||
const bool | active = true |
||
) |
Add a constraint item.
[in] | name | Constraint name |
[in] | constraint | Constraint model |
[in] | weight | Constraint weight |
[in] | active | True if the constraint is activated (default true) |
void removeConstraint | ( | const std::string & | name | ) |
Remove a constraint item.
[in] | name | Constraint name |
void changeConstraintStatus | ( | const std::string & | name, |
bool | active | ||
) |
Change the constraint status.
[in] | name | Constraint name |
[in] | active | Constraint status (true for active and false for inactive) |
void calc | ( | const boost::shared_ptr< ConstraintDataManager > & | data, |
const Eigen::Ref< const VectorXs > & | x, | ||
const Eigen::Ref< const VectorXs > & | u | ||
) |
Compute the total 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}\) |
void calc | ( | const boost::shared_ptr< ConstraintDataManager > & | data, |
const Eigen::Ref< const VectorXs > & | x | ||
) |
Compute the total 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}\) |
void calcDiff | ( | const boost::shared_ptr< ConstraintDataManager > & | data, |
const Eigen::Ref< const VectorXs > & | x, | ||
const Eigen::Ref< const VectorXs > & | u | ||
) |
Compute the Jacobian of the total constraint.
[in] | data | Constraint data |
[in] | x | State point \(\mathbf{x}\in\mathbb{R}^{ndx}\) |
[in] | u | Control input \(\mathbf{u}\in\mathbb{R}^{nu}\) |
void calcDiff | ( | const boost::shared_ptr< ConstraintDataManager > & | data, |
const Eigen::Ref< const VectorXs > & | x | ||
) |
Compute the Jacobian of the total 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}\) |
boost::shared_ptr<ConstraintDataManager> createData | ( | DataCollectorAbstract *const | data | ) |
Create the constraint data.
The default data contains objects to store the values of the constraint and their derivatives (i.e. Jacobians). 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 |
bool getConstraintStatus | ( | const std::string & | name | ) | const |
Return the status of a given constraint name.
[in] | name | Constraint name |