robotoc
robotoc - efficient ROBOT Optimal Control solvers
Loading...
Searching...
No Matches
robotoc::Constraints Class Reference

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...
 
Constraintsoperator= (const Constraints &)=default
 Default copy operator. More...
 
 Constraints (Constraints &&) noexcept=default
 Default move constructor. More...
 
Constraintsoperator= (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)
 

Detailed Description

Stack of the inequality constraints. Composed by constraint components that inherits ConstraintComponentBase or ImpactConstraintComponentBase.

Member Typedef Documentation

◆ ConstraintComponentBasePtr

◆ ImpactConstraintComponentBasePtr

Constructor & Destructor Documentation

◆ Constraints() [1/3]

robotoc::Constraints::Constraints ( const double  barrier_param = 1.0e-03,
const double  fraction_to_boundary_rule = 0.995 
)

Constructor.

Parameters
[in]barrier_paramBarrier parameter. Must be positive. Should be small. Default is 1.0e-03
[in]fraction_to_boundary_ruleMust be larger than 0 and smaller than 1. Should be between 0.9 and 0.995. Default is 0.995.

◆ ~Constraints()

robotoc::Constraints::~Constraints ( )
default

Default destructor.

◆ Constraints() [2/3]

robotoc::Constraints::Constraints ( const Constraints )
default

Default copy constructor.

◆ Constraints() [3/3]

robotoc::Constraints::Constraints ( Constraints &&  )
defaultnoexcept

Default move constructor.

Member Function Documentation

◆ add() [1/2]

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.

Parameters
[in]nameName of the constraint component.
[in]constraintshared pointer to the constraint component.

◆ add() [2/2]

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.

Parameters
[in]nameName of the constraint component.
[in]constraintshared pointer to the constraint component.

◆ clear()

void robotoc::Constraints::clear ( )

Clears constraints by removing all components.

◆ condenseSlackAndDual() [1/2]

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.

Parameters
[in]contact_statusContact status.
[in]dataConstraints data.
[out]kkt_matrixSplit KKT matrix. The condensed Hessians are added
to this data.
[out]kkt_residualSplit KKT residual. The condensed residual are added to this data.

◆ condenseSlackAndDual() [2/2]

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.

Parameters
[in]impact_statusImpact status.
[in]dataConstraints data.
[out]kkt_matrixImpact split KKT matrix. The condensed Hessians
are added to this data.
[out]kkt_residualImpact split KKT residual. The condensed
residual are added to this data.

◆ createConstraintsData()

ConstraintsData robotoc::Constraints::createConstraintsData ( const Robot robot,
const int  time_stage = -1 
) const

Creates ConstraintsData according to robot model and constraint components.

Parameters
[in]robotRobot model.
[in]time_stageTime stage. If -1, the impact stage is assumed.
Returns
Constraints data.

◆ disp()

void robotoc::Constraints::disp ( std::ostream &  os) const

Displays the constraints onto a ostream.

◆ erase()

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.

Parameters
[in]nameName of the constraint component.

◆ evalConstraint() [1/2]

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.

Parameters
[in]robotRobot model.
[in]contact_statusContact status.
[in]dataConstraints data.
[in]sSplit solution.

◆ evalConstraint() [2/2]

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.

Parameters
[in]robotRobot model.
[in]impact_statusImpact status.
[in]dataConstraints data.
[in]sImpact split solution.

◆ exist()

bool robotoc::Constraints::exist ( const std::string &  name) const

Checks if thsi has a constraint component of the specified name.

Parameters
[in]nameName of the constraint component.
Returns
treu if a constraint component of the specified name exists.

◆ expandSlackAndDual() [1/2]

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.

Parameters
[in]contact_statusContact status.
[in,out]dataConstraints data.
[in]dSplit direction.

◆ expandSlackAndDual() [2/2]

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.

Parameters
[in]impact_statusImpact status.
[in,out]dataConstraints data.
[in]dImpact split direction.

◆ getAccelerationLevelConstraintList()

std::vector< std::string > robotoc::Constraints::getAccelerationLevelConstraintList ( ) const

Gets a list of the acceleration-level constraints.

Returns
Name list of the acceleration-level constraints.

◆ getBarrierParam()

double robotoc::Constraints::getBarrierParam ( ) const

Gets the barrier parameter.

Returns
Barrier parameter.

◆ getConstraintComponent()

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.

Parameters
[in]nameName of the constraint component.
Returns
Shared ptr to the specified constraint component.

◆ getConstraintList()

std::vector< std::string > robotoc::Constraints::getConstraintList ( ) const

Gets a list of the constraints.

Returns
Name list of acceleration impact-level constraints.

◆ getFractionToBoundaryRule()

double robotoc::Constraints::getFractionToBoundaryRule ( ) const

Gets the parameter of the fraction-to-boundary-rule.

Returns
The parameter of the fraction-to-boundary-rule.

◆ getImpactConstraintComponent()

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.

Parameters
[in]nameName of the constraint component.
Returns
Shared ptr to the specified constraint component.

◆ getImpactLevelConstraintList()

std::vector< std::string > robotoc::Constraints::getImpactLevelConstraintList ( ) const

Gets a list of the impact-level constraints.

Returns
Name list of acceleration impact-level constraints.

◆ getPositionLevelConstraintList()

std::vector< std::string > robotoc::Constraints::getPositionLevelConstraintList ( ) const

Gets a list of the position-level constraints.

Returns
Name list of the position-level constraints.

◆ getVelocityLevelConstraintList()

std::vector< std::string > robotoc::Constraints::getVelocityLevelConstraintList ( ) const

Gets a list of the velocity-level constraints.

Returns
Name list of the velocity-level constraints.

◆ isFeasible() [1/2]

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.

Parameters
[in]robotRobot model.
[in]contact_statusContact status.
[in]dataConstraints data.
[in]sSplit solution.
Returns
true if s is feasible. false if not.

◆ isFeasible() [2/2]

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.

Parameters
[in]robotRobot model.
[in]impact_statusImpact status.
[in]dataConstraints data.
[in]sSplit solution.
Returns
true if s is feasible. false if not.

◆ linearizeConstraints() [1/2]

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.

Parameters
[in]robotRobot model.
[in]contact_statusContact status.
[in]dataConstraints data.
[in]sSplit solution.
[out]kkt_residualKKT residual.

◆ linearizeConstraints() [2/2]

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.

Parameters
[in]robotRobot model.
[in]impact_statusImpact status.
[in]dataConstraints data.
[in]sSplit solution.
[out]kkt_residualKKT residual.

◆ maxDualStepSize()

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.

Parameters
[in]dataConstraints data.
Returns
Maximum step size regarding the dual variables.

◆ maxSlackStepSize()

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.

Parameters
[in]dataConstraints data.
Returns
Maximum step size regarding the slack variables.

◆ operator=() [1/2]

Constraints & robotoc::Constraints::operator= ( const Constraints )
default

Default copy operator.

◆ operator=() [2/2]

Constraints & robotoc::Constraints::operator= ( Constraints &&  )
defaultnoexcept

Default move assign operator.

◆ setBarrierParam()

void robotoc::Constraints::setBarrierParam ( const double  barrier_param)

Sets the barrier parameter for all the constraint components.

Parameters
[in]barrier_paramBarrier parameter. Must be positive. Should be small.

◆ setFractionToBoundaryRule()

void robotoc::Constraints::setFractionToBoundaryRule ( const double  fraction_to_boundary_rule)

Sets the parameter of the fraction-to-boundary-rule for all the constraint components.

Parameters
[in]fraction_to_boundary_ruleMust be larger than 0 and smaller than 1. Should be between 0.9 and 0.995.

◆ setSlackAndDual() [1/2]

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.

Parameters
[in]robotRobot model.
[in]contact_statusContact status.
[out]dataConstraints data.
[in]sSplit solution.

◆ setSlackAndDual() [2/2]

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.

Parameters
[in]robotRobot model.
[in]impact_statusImpact status.
[out]dataConstraints data.
[in]sSplit solution.

◆ updateDual()

static void robotoc::Constraints::updateDual ( ConstraintsData data,
const double  step_size 
)
static

Updates the dual variables according to step_size.

Parameters
[in,out]dataConstraints data.
[in]step_sizeStep size.

◆ updateSlack()

static void robotoc::Constraints::updateSlack ( ConstraintsData data,
const double  step_size 
)
static

Updates the slack variables according to step_size.

Parameters
[in,out]dataConstraints data.
[in]step_sizeStep size.

Friends And Related Function Documentation

◆ operator<< [1/2]

std::ostream & operator<< ( std::ostream &  os,
const Constraints constraints 
)
friend

◆ operator<< [2/2]

std::ostream & operator<< ( std::ostream &  os,
const std::shared_ptr< Constraints > &  constraints 
)
friend

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