iDynTree::optimalcontrol::Constraint class

The Constraint virtual class definition.

Inherit publicly from this class to define a constraint of an optimal control problem.

Derived classes

class LinearConstraint

Constructors, destructors, conversion operators

Constraint(size_t size, const std::string name)
Constraint constructor.
~Constraint() virtual
Default destructor.

Public functions

auto constraintSize() const -> size_t
Getter for the constraint size.
auto name() const -> const std::string&
Getter for the constraint name.
auto setLowerBound(const VectorDynSize& lowerBound) -> bool
Set the constraint lower bound.
auto getLowerBound(VectorDynSize& lowerBound) -> bool
Get the constraint lower bound.
auto setUpperBound(const VectorDynSize& upperBound) -> bool
Set the constraint upper bound.
auto getUpperBound(VectorDynSize& upperBound) -> bool
Get the constraint upper bound.
auto isFeasiblePoint(double time, const VectorDynSize& state, const VectorDynSize& control) -> bool virtual
Check if the constraint is satisfied given the specified state and control.
auto evaluateConstraint(double time, const VectorDynSize& state, const VectorDynSize& control, VectorDynSize& constraint) -> bool pure virtual
Evaluate the constraint.
auto constraintJacobianWRTState(double time, const VectorDynSize& state, const VectorDynSize& control, MatrixDynSize& jacobian) -> bool virtual
Evaluate the constraint jacobian with respect to the state variables This methods evaluates the partial derivative of the constraint wrt to the state.
auto constraintJacobianWRTControl(double time, const VectorDynSize& state, const VectorDynSize& control, MatrixDynSize& jacobian) -> bool virtual
Evaluate the constraint jacobian with respect to the control variables This methods evaluates the partial derivative of the constraint wrt to the control.
auto expectedStateSpaceSize() const -> size_t virtual
The dimension the state vector is supposed to have.
auto expectedControlSpaceSize() const -> size_t virtual
The dimension the control vector is supposed to have.
auto constraintJacobianWRTStateSparsity(iDynTree::optimalcontrol::SparsityStructure& stateSparsity) -> bool virtual
Returns the set of nonzeros elements in terms of row and colun index, in the state jacobian.
auto constraintJacobianWRTControlSparsity(iDynTree::optimalcontrol::SparsityStructure& controlSparsity) -> bool virtual
Returns the set of nonzeros elements in terms of row and colun index, in the control jacobian.
auto constraintSecondPartialDerivativeWRTState(double time, const VectorDynSize& state, const VectorDynSize& control, const VectorDynSize& lambda, MatrixDynSize& hessian) -> bool virtual
Evaluate constraint second partial derivative wrt the state variables.
auto constraintSecondPartialDerivativeWRTControl(double time, const VectorDynSize& state, const VectorDynSize& control, const VectorDynSize& lambda, MatrixDynSize& hessian) -> bool virtual
Evaluate constraint second partial derivative wrt the control.
auto constraintSecondPartialDerivativeWRTStateControl(double time, const VectorDynSize& state, const VectorDynSize& control, const VectorDynSize& lambda, MatrixDynSize& hessian) -> bool virtual
Evaluate constraint second partial derivative wrt the state and control.
auto constraintSecondPartialDerivativeWRTStateSparsity(iDynTree::optimalcontrol::SparsityStructure& stateSparsity) -> bool virtual
Returns the set of nonzeros elements in terms of row and colun index, in the state hessian.
auto constraintSecondPartialDerivativeWRTStateControlSparsity(iDynTree::optimalcontrol::SparsityStructure& stateControlSparsity) -> bool virtual
Returns the set of nonzeros elements in terms of row and colun index, in the mixed hessian.
auto constraintSecondPartialDerivativeWRTControlSparsity(iDynTree::optimalcontrol::SparsityStructure& controlSparsity) -> bool virtual
Returns the set of nonzeros elements in terms of row and colun index, in the control hessian.

Protected variables

VectorDynSize m_lowerBound
The vector containing the lower bound.
VectorDynSize m_upperBound
The vector containing the upper bound.
bool m_isLowerBounded
True if the constraint is lower bounded.
bool m_isUpperBounded
True if the constraint is upper bounded.

Function documentation

iDynTree::optimalcontrol::Constraint::Constraint(size_t size, const std::string name)

Constraint constructor.

Parameters
size in Dimension of the constraint.
name in Univocal name of the constraint.

Default constructor. It needs the constraint dimension and and an univocal name.

size_t iDynTree::optimalcontrol::Constraint::constraintSize() const

Getter for the constraint size.

Returns The dimension of the constraint.

const std::string& iDynTree::optimalcontrol::Constraint::name() const

Getter for the constraint name.

Returns The name of the constraint.

bool iDynTree::optimalcontrol::Constraint::setLowerBound(const VectorDynSize& lowerBound)

Set the constraint lower bound.

Returns True if successfull. A failure may be induced by a dimension mismatch.

bool iDynTree::optimalcontrol::Constraint::getLowerBound(VectorDynSize& lowerBound)

Get the constraint lower bound.

Returns True if the constraint has a lower bound. False otherwise.

bool iDynTree::optimalcontrol::Constraint::setUpperBound(const VectorDynSize& upperBound)

Set the constraint upper bound.

Returns True if successfull. A failure may be induced by a dimension mismatch.

bool iDynTree::optimalcontrol::Constraint::getUpperBound(VectorDynSize& upperBound)

Get the constraint upper bound.

Returns True if the constraint has a lower bound. False otherwise.

bool iDynTree::optimalcontrol::Constraint::isFeasiblePoint(double time, const VectorDynSize& state, const VectorDynSize& control) virtual

Check if the constraint is satisfied given the specified state and control.

Parameters
time in The time at which the constraint is evaluated.
state in The state at which the constraint is evaluated.
control in The control at which the constraint is evaluated.
Returns True if successfull, false otherwise.

This method has a default implementation which exploits the definition of the bounds and the method evaluateConstraint.

Unless particular implementations are needed, there is no need of overriding this method.

bool iDynTree::optimalcontrol::Constraint::evaluateConstraint(double time, const VectorDynSize& state, const VectorDynSize& control, VectorDynSize& constraint) pure virtual

Evaluate the constraint.

Parameters
time in The time at which the constraint is evaluated.
state in The state at which the constraint is evaluated.
control in The control at which the constraint is evaluated
constraint out The constraint right hand value.
Returns True if successfull, false otherwise.

This method has to be overriden when defining the constraint.

bool iDynTree::optimalcontrol::Constraint::constraintJacobianWRTState(double time, const VectorDynSize& state, const VectorDynSize& control, MatrixDynSize& jacobian) virtual

Evaluate the constraint jacobian with respect to the state variables This methods evaluates the partial derivative of the constraint wrt to the state.

Parameters
time in The time at which the constraint jacobian is evaluated.
state in The state at which the constraint jacobian is evaluated.
control in The control at which the constraint jacobian is evaluated
jacobian out The jacobian right hand side value.
Returns True if successful. False otherwise (or by default).

By default, the implementation return false. The user needs to override this method if the constraint will be used, for example, within an optimal control problem that will be solved using an optimizer that needs this information (i.e. Ipopt).

bool iDynTree::optimalcontrol::Constraint::constraintJacobianWRTControl(double time, const VectorDynSize& state, const VectorDynSize& control, MatrixDynSize& jacobian) virtual

Evaluate the constraint jacobian with respect to the control variables This methods evaluates the partial derivative of the constraint wrt to the control.

Parameters
time in The time at which the constraint jacobian is evaluated.
state in The state at which the constraint jacobian is evaluated.
control in The control at which the constraint jacobian is evaluated
jacobian out The jacobian right hand side value.
Returns True if successful. False otherwise (or by default).

By default, the implementation return false. The user needs to override this method if the constraint will be used, for example, within an optimal control problem that will be solved using an optimizer that needs this information (i.e. Ipopt).

size_t iDynTree::optimalcontrol::Constraint::expectedStateSpaceSize() const virtual

The dimension the state vector is supposed to have.

Returns The expected dimension of the state vectors.

Override this method to specify the dimension the state vector is supposed to have. This method is useful for the OptimalControlProblem class to allocate some buffers. By default it returns 0.

size_t iDynTree::optimalcontrol::Constraint::expectedControlSpaceSize() const virtual

The dimension the control vector is supposed to have.

Returns The expected dimension of the control vectors.

Override this method to specify the dimension the control vector is supposed to have. This method is useful for the OptimalControlProblem class to allocate some buffers. By default it returns 0.

bool iDynTree::optimalcontrol::Constraint::constraintJacobianWRTStateSparsity(iDynTree::optimalcontrol::SparsityStructure& stateSparsity) virtual

Returns the set of nonzeros elements in terms of row and colun index, in the state jacobian.

Parameters
stateSparsity Sparsity structure of the partial derivative of the constraint wrt state variables.
Returns true if the sparsity is available. False otherwise.

bool iDynTree::optimalcontrol::Constraint::constraintJacobianWRTControlSparsity(iDynTree::optimalcontrol::SparsityStructure& controlSparsity) virtual

Returns the set of nonzeros elements in terms of row and colun index, in the control jacobian.

Parameters
controlSparsity Sparsity structure of the partial derivative of the constraint wrt control variables.
Returns true if the sparsity is available. False otherwise.

bool iDynTree::optimalcontrol::Constraint::constraintSecondPartialDerivativeWRTState(double time, const VectorDynSize& state, const VectorDynSize& control, const VectorDynSize& lambda, MatrixDynSize& hessian) virtual

Evaluate constraint second partial derivative wrt the state variables.

Parameters
time in The time at which the partial derivative is computed.
state in The state value at which the partial derivative is computed.
control in The control value at which the partial derivative is computed..
lambda in The lagrange multipliers
hessian out The output partial derivative.
Returns True if successfull, false otherwise (or if not implemented).

It is the result of $\sum \lambda_i \frac{\partial^2 c(t, x, u)}{\partial x^2}$

bool iDynTree::optimalcontrol::Constraint::constraintSecondPartialDerivativeWRTControl(double time, const VectorDynSize& state, const VectorDynSize& control, const VectorDynSize& lambda, MatrixDynSize& hessian) virtual

Evaluate constraint second partial derivative wrt the control.

Parameters
time in The time at which the partial derivative is computed.
state in The state value at which the partial derivative is computed.
control in The control value at which the partial derivative is computed.
lambda in The lagrange multipliers
hessian out The output partial derivative.
Returns True if successfull, false otherwise (or if not implemented).

It is the result of $\sum \lambda_i \frac{\partial^2 c(t, x, u)}{\partial u^2}$

bool iDynTree::optimalcontrol::Constraint::constraintSecondPartialDerivativeWRTStateControl(double time, const VectorDynSize& state, const VectorDynSize& control, const VectorDynSize& lambda, MatrixDynSize& hessian) virtual

Evaluate constraint second partial derivative wrt the state and control.

Parameters
time in The time at which the partial derivative is computed.
state in The state value at which the partial derivative is computed.
control in The control value at which the partial derivative is computed.
lambda in The lagrange multipliers
hessian out The output partial derivative.
Returns True if successfull, false otherwise (or if not implemented).

It is the result of $\sum \lambda_i \frac{\partial^2 c(t, x, u)}{\partial x \partial u}$ , thus it has number of rows equals to the number of states and number of cols equal to the number of control inputs.

bool iDynTree::optimalcontrol::Constraint::constraintSecondPartialDerivativeWRTStateSparsity(iDynTree::optimalcontrol::SparsityStructure& stateSparsity) virtual

Returns the set of nonzeros elements in terms of row and colun index, in the state hessian.

Parameters
stateSparsity Sparsity structure of the partial derivative of the jacobian wrt state variables.
Returns true if the sparsity is available. False otherwise.

bool iDynTree::optimalcontrol::Constraint::constraintSecondPartialDerivativeWRTStateControlSparsity(iDynTree::optimalcontrol::SparsityStructure& stateControlSparsity) virtual

Returns the set of nonzeros elements in terms of row and colun index, in the mixed hessian.

Parameters
stateControlSparsity Sparsity structure of the partial derivative of the jacobian wrt state and control variables.
Returns true if the sparsity is available. False otherwise.

bool iDynTree::optimalcontrol::Constraint::constraintSecondPartialDerivativeWRTControlSparsity(iDynTree::optimalcontrol::SparsityStructure& controlSparsity) virtual

Returns the set of nonzeros elements in terms of row and colun index, in the control hessian.

Parameters
controlSparsity Sparsity structure of the partial derivative of the jacobian wrt control variables.
Returns true if the sparsity is available. False otherwise.

Variable documentation

bool iDynTree::optimalcontrol::Constraint::m_isLowerBounded protected

True if the constraint is lower bounded.

Corresponds to the return value of getUpperBound

bool iDynTree::optimalcontrol::Constraint::m_isUpperBounded protected

True if the constraint is upper bounded.

Corresponds to the return value of getLowerBound