robotoc
robotoc - efficient ROBOT Optimal Control solvers
|
Stack of the inequality constraints. Composed by constraint components that inherits ConstraintComponentBase or ImpactConstraintComponentBase. More...
#include <constraints.hpp>
Public Types | |
using | ConstraintComponentBasePtr = std::shared_ptr< ConstraintComponentBase > |
using | ImpactConstraintComponentBasePtr = std::shared_ptr< ImpactConstraintComponentBase > |
Public Member Functions | |
Constraints (const double barrier_param=1.0e-03, const double fraction_to_boundary_rule=0.995) | |
Constructor. More... | |
~Constraints ()=default | |
Default destructor. More... | |
Constraints (const Constraints &)=default | |
Default copy constructor. More... | |
Constraints & | operator= (const Constraints &)=default |
Default copy operator. More... | |
Constraints (Constraints &&) noexcept=default | |
Default move constructor. More... | |
Constraints & | operator= (Constraints &&) noexcept=default |
Default move assign operator. More... | |
bool | exist (const std::string &name) const |
Checks if thsi has a constraint component of the specified name. More... | |
void | add (const std::string &name, ConstraintComponentBasePtr constraint) |
Adds a constraint component. If a component of the same name exists, throws an exeption. More... | |
void | add (const std::string &name, ImpactConstraintComponentBasePtr constraint) |
Adds a constraint component. If a component of the same name exists, throws an exeption. More... | |
void | erase (const std::string &name) |
Erases a constraint component. If a component of the specified name does not exist, throws an exeption. More... | |
ConstraintComponentBasePtr | getConstraintComponent (const std::string &name) const |
Gets a constraint component. If a component of the specified name does not exist, throws an exeption. More... | |
ImpactConstraintComponentBasePtr | getImpactConstraintComponent (const std::string &name) const |
Gets a constraint component. If a component of the specified name does not exist, throws an exeption. More... | |
void | clear () |
Clears constraints by removing all components. More... | |
ConstraintsData | createConstraintsData (const Robot &robot, const int time_stage=-1) const |
Creates ConstraintsData according to robot model and constraint components. More... | |
bool | isFeasible (Robot &robot, const ContactStatus &contact_status, ConstraintsData &data, const SplitSolution &s) const |
Checks whether the current split solution s is feasible or not. More... | |
bool | isFeasible (Robot &robot, const ImpactStatus &impact_status, ConstraintsData &data, const SplitSolution &s) const |
Checks whether the current impact split solution s is feasible or not. More... | |
void | setSlackAndDual (Robot &robot, const ContactStatus &contact_status, ConstraintsData &data, const SplitSolution &s) const |
Sets the slack and dual variables of each constraint components. More... | |
void | setSlackAndDual (Robot &robot, const ImpactStatus &impact_status, ConstraintsData &data, const SplitSolution &s) const |
Sets the slack and dual variables of each impact constraint components. More... | |
void | evalConstraint (Robot &robot, const ContactStatus &contact_status, ConstraintsData &data, const SplitSolution &s) const |
Computes the primal residual, residual in the complementary slackness, and the log-barrier function of the slack varible. More... | |
void | evalConstraint (Robot &robot, const ImpactStatus &impact_status, ConstraintsData &data, const SplitSolution &s) const |
Computes the primal residual, residual in the complementary slackness, and the log-barrier function of the slack varible. More... | |
void | linearizeConstraints (Robot &robot, const ContactStatus &contact_status, ConstraintsData &data, const SplitSolution &s, SplitKKTResidual &kkt_residual) const |
Evaluates the constraints (i.e., calls evalConstraint()) and adds the products of the Jacobian of the constraints and Lagrange multipliers. More... | |
void | linearizeConstraints (Robot &robot, const ImpactStatus &impact_status, ConstraintsData &data, const SplitSolution &s, SplitKKTResidual &kkt_residual) const |
Evaluates the constraints (i.e., calls evalConstraint()) and adds the products of the Jacobian of the constraints and Lagrange multipliers. More... | |
void | condenseSlackAndDual (const ContactStatus &contact_status, ConstraintsData &data, SplitKKTMatrix &kkt_matrix, SplitKKTResidual &kkt_residual) const |
Condenses the slack and dual variables. linearizeConstraints() must be called before this function. More... | |
void | condenseSlackAndDual (const ImpactStatus &impact_status, ConstraintsData &data, SplitKKTMatrix &kkt_matrix, SplitKKTResidual &kkt_residual) const |
Condenses the slack and dual variables. linearizeConstraints() must be called before this function. More... | |
void | expandSlackAndDual (const ContactStatus &contact_status, ConstraintsData &data, const SplitDirection &d) const |
Expands the slack and dual, i.e., computes the directions of the slack and dual variables from the directions of the primal variables. More... | |
void | expandSlackAndDual (const ImpactStatus &impact_status, ConstraintsData &data, const SplitDirection &d) const |
Expands the slack and dual, i.e., computes the directions of the slack and dual variables from the directions of the primal variables. More... | |
double | maxSlackStepSize (const ConstraintsData &data) const |
Computes and returns the maximum step size by applying fraction-to-boundary-rule to the directions of the slack variables. More... | |
double | maxDualStepSize (const ConstraintsData &data) const |
Computes and returns the maximum step size by applying fraction-to-boundary-rule to the directions of the dual variables. More... | |
void | setBarrierParam (const double barrier_param) |
Sets the barrier parameter for all the constraint components. More... | |
void | setFractionToBoundaryRule (const double fraction_to_boundary_rule) |
Sets the parameter of the fraction-to-boundary-rule for all the constraint components. More... | |
double | getBarrierParam () const |
Gets the barrier parameter. More... | |
double | getFractionToBoundaryRule () const |
Gets the parameter of the fraction-to-boundary-rule. More... | |
std::vector< std::string > | getPositionLevelConstraintList () const |
Gets a list of the position-level constraints. More... | |
std::vector< std::string > | getVelocityLevelConstraintList () const |
Gets a list of the velocity-level constraints. More... | |
std::vector< std::string > | getAccelerationLevelConstraintList () const |
Gets a list of the acceleration-level constraints. More... | |
std::vector< std::string > | getImpactLevelConstraintList () const |
Gets a list of the impact-level constraints. More... | |
std::vector< std::string > | getConstraintList () const |
Gets a list of the constraints. More... | |
void | disp (std::ostream &os) const |
Displays the constraints onto a ostream. More... | |
Static Public Member Functions | |
static void | updateSlack (ConstraintsData &data, const double step_size) |
Updates the slack variables according to step_size. More... | |
static void | updateDual (ConstraintsData &data, const double step_size) |
Updates the dual variables according to step_size. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Constraints &constraints) |
std::ostream & | operator<< (std::ostream &os, const std::shared_ptr< Constraints > &constraints) |
Stack of the inequality constraints. Composed by constraint components that inherits ConstraintComponentBase or ImpactConstraintComponentBase.
using robotoc::Constraints::ConstraintComponentBasePtr = std::shared_ptr<ConstraintComponentBase> |
using robotoc::Constraints::ImpactConstraintComponentBasePtr = std::shared_ptr<ImpactConstraintComponentBase> |
robotoc::Constraints::Constraints | ( | const double | barrier_param = 1.0e-03 , |
const double | fraction_to_boundary_rule = 0.995 |
||
) |
Constructor.
[in] | barrier_param | Barrier parameter. Must be positive. Should be small. Default is 1.0e-03 |
[in] | fraction_to_boundary_rule | Must be larger than 0 and smaller than 1. Should be between 0.9 and 0.995. Default is 0.995. |
|
default |
Default destructor.
|
default |
Default copy constructor.
|
defaultnoexcept |
Default move constructor.
void robotoc::Constraints::add | ( | const std::string & | name, |
ConstraintComponentBasePtr | constraint | ||
) |
Adds a constraint component. If a component of the same name exists, throws an exeption.
[in] | name | Name of the constraint component. |
[in] | constraint | shared pointer to the constraint component. |
void robotoc::Constraints::add | ( | const std::string & | name, |
ImpactConstraintComponentBasePtr | constraint | ||
) |
Adds a constraint component. If a component of the same name exists, throws an exeption.
[in] | name | Name of the constraint component. |
[in] | constraint | shared pointer to the constraint component. |
void robotoc::Constraints::clear | ( | ) |
Clears constraints by removing all components.
void robotoc::Constraints::condenseSlackAndDual | ( | const ContactStatus & | contact_status, |
ConstraintsData & | data, | ||
SplitKKTMatrix & | kkt_matrix, | ||
SplitKKTResidual & | kkt_residual | ||
) | const |
Condenses the slack and dual variables. linearizeConstraints() must be called before this function.
[in] | contact_status | Contact status. |
[in] | data | Constraints data. |
[out] | kkt_matrix | Split KKT matrix. The condensed Hessians are added to this data. |
[out] | kkt_residual | Split KKT residual. The condensed residual are added to this data. |
void robotoc::Constraints::condenseSlackAndDual | ( | const ImpactStatus & | impact_status, |
ConstraintsData & | data, | ||
SplitKKTMatrix & | kkt_matrix, | ||
SplitKKTResidual & | kkt_residual | ||
) | const |
Condenses the slack and dual variables. linearizeConstraints() must be called before this function.
[in] | impact_status | Impact status. |
[in] | data | Constraints data. |
[out] | kkt_matrix | Impact split KKT matrix. The condensed Hessians are added to this data. |
[out] | kkt_residual | Impact split KKT residual. The condensed residual are added to this data. |
ConstraintsData robotoc::Constraints::createConstraintsData | ( | const Robot & | robot, |
const int | time_stage = -1 |
||
) | const |
Creates ConstraintsData according to robot model and constraint components.
[in] | robot | Robot model. |
[in] | time_stage | Time stage. If -1, the impact stage is assumed. |
void robotoc::Constraints::disp | ( | std::ostream & | os | ) | const |
Displays the constraints onto a ostream.
void robotoc::Constraints::erase | ( | const std::string & | name | ) |
Erases a constraint component. If a component of the specified name does not exist, throws an exeption.
[in] | name | Name of the constraint component. |
void robotoc::Constraints::evalConstraint | ( | Robot & | robot, |
const ContactStatus & | contact_status, | ||
ConstraintsData & | data, | ||
const SplitSolution & | s | ||
) | const |
Computes the primal residual, residual in the complementary slackness, and the log-barrier function of the slack varible.
Computes the primal and dual residuals of the constraints.
[in] | robot | Robot model. |
[in] | contact_status | Contact status. |
[in] | data | Constraints data. |
[in] | s | Split solution. |
void robotoc::Constraints::evalConstraint | ( | Robot & | robot, |
const ImpactStatus & | impact_status, | ||
ConstraintsData & | data, | ||
const SplitSolution & | s | ||
) | const |
Computes the primal residual, residual in the complementary slackness, and the log-barrier function of the slack varible.
[in] | robot | Robot model. |
[in] | impact_status | Impact status. |
[in] | data | Constraints data. |
[in] | s | Impact split solution. |
bool robotoc::Constraints::exist | ( | const std::string & | name | ) | const |
Checks if thsi has a constraint component of the specified name.
[in] | name | Name of the constraint component. |
void robotoc::Constraints::expandSlackAndDual | ( | const ContactStatus & | contact_status, |
ConstraintsData & | data, | ||
const SplitDirection & | d | ||
) | const |
Expands the slack and dual, i.e., computes the directions of the slack and dual variables from the directions of the primal variables.
[in] | contact_status | Contact status. |
[in,out] | data | Constraints data. |
[in] | d | Split direction. |
void robotoc::Constraints::expandSlackAndDual | ( | const ImpactStatus & | impact_status, |
ConstraintsData & | data, | ||
const SplitDirection & | d | ||
) | const |
Expands the slack and dual, i.e., computes the directions of the slack and dual variables from the directions of the primal variables.
[in] | impact_status | Impact status. |
[in,out] | data | Constraints data. |
[in] | d | Impact split direction. |
std::vector< std::string > robotoc::Constraints::getAccelerationLevelConstraintList | ( | ) | const |
Gets a list of the acceleration-level constraints.
double robotoc::Constraints::getBarrierParam | ( | ) | const |
Gets the barrier parameter.
ConstraintComponentBasePtr robotoc::Constraints::getConstraintComponent | ( | const std::string & | name | ) | const |
Gets a constraint component. If a component of the specified name does not exist, throws an exeption.
[in] | name | Name of the constraint component. |
std::vector< std::string > robotoc::Constraints::getConstraintList | ( | ) | const |
Gets a list of the constraints.
double robotoc::Constraints::getFractionToBoundaryRule | ( | ) | const |
Gets the parameter of the fraction-to-boundary-rule.
ImpactConstraintComponentBasePtr robotoc::Constraints::getImpactConstraintComponent | ( | const std::string & | name | ) | const |
Gets a constraint component. If a component of the specified name does not exist, throws an exeption.
[in] | name | Name of the constraint component. |
std::vector< std::string > robotoc::Constraints::getImpactLevelConstraintList | ( | ) | const |
Gets a list of the impact-level constraints.
std::vector< std::string > robotoc::Constraints::getPositionLevelConstraintList | ( | ) | const |
Gets a list of the position-level constraints.
std::vector< std::string > robotoc::Constraints::getVelocityLevelConstraintList | ( | ) | const |
Gets a list of the velocity-level constraints.
bool robotoc::Constraints::isFeasible | ( | Robot & | robot, |
const ContactStatus & | contact_status, | ||
ConstraintsData & | data, | ||
const SplitSolution & | s | ||
) | const |
Checks whether the current split solution s is feasible or not.
[in] | robot | Robot model. |
[in] | contact_status | Contact status. |
[in] | data | Constraints data. |
[in] | s | Split solution. |
bool robotoc::Constraints::isFeasible | ( | Robot & | robot, |
const ImpactStatus & | impact_status, | ||
ConstraintsData & | data, | ||
const SplitSolution & | s | ||
) | const |
Checks whether the current impact split solution s is feasible or not.
[in] | robot | Robot model. |
[in] | impact_status | Impact status. |
[in] | data | Constraints data. |
[in] | s | Split solution. |
void robotoc::Constraints::linearizeConstraints | ( | Robot & | robot, |
const ContactStatus & | contact_status, | ||
ConstraintsData & | data, | ||
const SplitSolution & | s, | ||
SplitKKTResidual & | kkt_residual | ||
) | const |
Evaluates the constraints (i.e., calls evalConstraint()) and adds the products of the Jacobian of the constraints and Lagrange multipliers.
[in] | robot | Robot model. |
[in] | contact_status | Contact status. |
[in] | data | Constraints data. |
[in] | s | Split solution. |
[out] | kkt_residual | KKT residual. |
void robotoc::Constraints::linearizeConstraints | ( | Robot & | robot, |
const ImpactStatus & | impact_status, | ||
ConstraintsData & | data, | ||
const SplitSolution & | s, | ||
SplitKKTResidual & | kkt_residual | ||
) | const |
Evaluates the constraints (i.e., calls evalConstraint()) and adds the products of the Jacobian of the constraints and Lagrange multipliers.
[in] | robot | Robot model. |
[in] | impact_status | Impact status. |
[in] | data | Constraints data. |
[in] | s | Split solution. |
[out] | kkt_residual | KKT residual. |
double robotoc::Constraints::maxDualStepSize | ( | const ConstraintsData & | data | ) | const |
Computes and returns the maximum step size by applying fraction-to-boundary-rule to the directions of the dual variables.
[in] | data | Constraints data. |
double robotoc::Constraints::maxSlackStepSize | ( | const ConstraintsData & | data | ) | const |
Computes and returns the maximum step size by applying fraction-to-boundary-rule to the directions of the slack variables.
[in] | data | Constraints data. |
|
default |
Default copy operator.
|
defaultnoexcept |
Default move assign operator.
void robotoc::Constraints::setBarrierParam | ( | const double | barrier_param | ) |
Sets the barrier parameter for all the constraint components.
[in] | barrier_param | Barrier parameter. Must be positive. Should be small. |
void robotoc::Constraints::setFractionToBoundaryRule | ( | const double | fraction_to_boundary_rule | ) |
Sets the parameter of the fraction-to-boundary-rule for all the constraint components.
[in] | fraction_to_boundary_rule | Must be larger than 0 and smaller than 1. Should be between 0.9 and 0.995. |
void robotoc::Constraints::setSlackAndDual | ( | Robot & | robot, |
const ContactStatus & | contact_status, | ||
ConstraintsData & | data, | ||
const SplitSolution & | s | ||
) | const |
Sets the slack and dual variables of each constraint components.
[in] | robot | Robot model. |
[in] | contact_status | Contact status. |
[out] | data | Constraints data. |
[in] | s | Split solution. |
void robotoc::Constraints::setSlackAndDual | ( | Robot & | robot, |
const ImpactStatus & | impact_status, | ||
ConstraintsData & | data, | ||
const SplitSolution & | s | ||
) | const |
Sets the slack and dual variables of each impact constraint components.
[in] | robot | Robot model. |
[in] | impact_status | Impact status. |
[out] | data | Constraints data. |
[in] | s | Split solution. |
|
static |
Updates the dual variables according to step_size.
[in,out] | data | Constraints data. |
[in] | step_size | Step size. |
|
static |
Updates the slack variables according to step_size.
[in,out] | data | Constraints data. |
[in] | step_size | Step size. |
|
friend |
|
friend |