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

Stack of the cost function. Composed by cost function components that inherits CostFunctionComponentBase. More...

#include <cost_function.hpp>

Public Types

using CostFunctionComponentBasePtr = std::shared_ptr< CostFunctionComponentBase >
 

Public Member Functions

 CostFunction (const double discount_factor, const double discount_time_step)
 Constructor with discount factor. More...
 
 CostFunction ()
 Default constructor. More...
 
 ~CostFunction ()=default
 Destructor. More...
 
 CostFunction (const CostFunction &)=default
 Default copy constructor. More...
 
CostFunctionoperator= (const CostFunction &)=default
 Default copy operator. More...
 
 CostFunction (CostFunction &&) noexcept=default
 Default move constructor. More...
 
CostFunctionoperator= (CostFunction &&) noexcept=default
 Default move assign operator. More...
 
void setDiscountFactor (const double discount_factor, const double discount_time_step)
 Sets the discount facor. More...
 
double discountFactor () const
 Gets the discount facor. More...
 
double discountTimeStep () const
 Gets the discount time step. More...
 
bool exist (const std::string &name) const
 Checks if thsi has a cost function component of the specified name. More...
 
void add (const std::string &name, const CostFunctionComponentBasePtr &cost)
 Adds a cost function component. If a component of the same name exists, throws an exeption. More...
 
void erase (const std::string &name)
 Erases a cost function component. If a component of the specified name does not exist, throws an exeption. More...
 
CostFunctionComponentBasePtr get (const std::string &name) const
 Gets a cost function component. If a component of the specified name does not exist, throws an exeption. More...
 
void clear ()
 Clear cost function by removing all components. More...
 
CostFunctionData createCostFunctionData (const Robot &robot) const
 Creates CostFunctionData according to robot model and cost function components. More...
 
double evalStageCost (Robot &robot, const ContactStatus &contact_status, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s) const
 Computes the stage cost. More...
 
double linearizeStageCost (Robot &robot, const ContactStatus &contact_status, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s, SplitKKTResidual &kkt_residual) const
 Computes the stage cost and its first-order partial derivatives. More...
 
double quadratizeStageCost (Robot &robot, const ContactStatus &contact_status, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s, SplitKKTResidual &kkt_residual, SplitKKTMatrix &kkt_matrix) const
 Computes the stage cost, its first-order partial derivatives, and its Hessian, i.e., its second-order partial derivatives. More...
 
double evalTerminalCost (Robot &robot, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s) const
 Computes the terminal cost. More...
 
double linearizeTerminalCost (Robot &robot, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s, SplitKKTResidual &kkt_residual) const
 Computes the terminal cost and its first-order partial derivatives. More...
 
double quadratizeTerminalCost (Robot &robot, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s, SplitKKTResidual &kkt_residual, SplitKKTMatrix &kkt_matrix) const
 Computes the terminal cost, its first-order partial derivatives, and its Hessian, i.e., its second-order partial derivatives. More...
 
double evalImpactCost (Robot &robot, const ImpactStatus &impact_status, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s) const
 Computes the impact cost. More...
 
double linearizeImpactCost (Robot &robot, const ImpactStatus &impact_status, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s, SplitKKTResidual &kkt_residual) const
 Computes the impact cost and its first-order partial derivatives. More...
 
double quadratizeImpactCost (Robot &robot, const ImpactStatus &impact_status, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s, SplitKKTResidual &kkt_residual, SplitKKTMatrix &kkt_matrix) const
 Computes the impact cost, its first-order partial derivatives, and its Hessian, i.e., its second-order partial derivatives. More...
 
std::vector< std::string > getCostComponentList () const
 Gets a list of the cost components. More...
 
void disp (std::ostream &os) const
 Displays the cost function onto a ostream. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const CostFunction &cost_function)
 
std::ostream & operator<< (std::ostream &os, const std::shared_ptr< CostFunction > &cost_function)
 

Detailed Description

Stack of the cost function. Composed by cost function components that inherits CostFunctionComponentBase.

Member Typedef Documentation

◆ CostFunctionComponentBasePtr

Constructor & Destructor Documentation

◆ CostFunction() [1/4]

robotoc::CostFunction::CostFunction ( const double  discount_factor,
const double  discount_time_step 
)

Constructor with discount factor.

Parameters
[in]discount_factorDiscount factor. Must be positive and smaller than 1.0.
[in]discount_time_stepThe cost is reduced by discount_factor as the time proceeds to this value. Must be positive.

◆ CostFunction() [2/4]

robotoc::CostFunction::CostFunction ( )

Default constructor.

◆ ~CostFunction()

robotoc::CostFunction::~CostFunction ( )
default

Destructor.

◆ CostFunction() [3/4]

robotoc::CostFunction::CostFunction ( const CostFunction )
default

Default copy constructor.

◆ CostFunction() [4/4]

robotoc::CostFunction::CostFunction ( CostFunction &&  )
defaultnoexcept

Default move constructor.

Member Function Documentation

◆ add()

void robotoc::CostFunction::add ( const std::string &  name,
const CostFunctionComponentBasePtr cost 
)

Adds a cost function component. If a component of the same name exists, throws an exeption.

Parameters
[in]nameName of the cost function component.
[in]costshared pointer to the cost function component.

◆ clear()

void robotoc::CostFunction::clear ( )

Clear cost function by removing all components.

◆ createCostFunctionData()

CostFunctionData robotoc::CostFunction::createCostFunctionData ( const Robot robot) const

Creates CostFunctionData according to robot model and cost function components.

Parameters
[in]robotrobot model.
Returns
Cost function data.

◆ discountFactor()

double robotoc::CostFunction::discountFactor ( ) const

Gets the discount facor.

Returns
The discount facor.

◆ discountTimeStep()

double robotoc::CostFunction::discountTimeStep ( ) const

Gets the discount time step.

Returns
The discount time step.

◆ disp()

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

Displays the cost function onto a ostream.

◆ erase()

void robotoc::CostFunction::erase ( const std::string &  name)

Erases a cost function component. If a component of the specified name does not exist, throws an exeption.

Parameters
[in]nameName of the cost function component.

◆ evalImpactCost()

double robotoc::CostFunction::evalImpactCost ( Robot robot,
const ImpactStatus impact_status,
CostFunctionData data,
const GridInfo grid_info,
const SplitSolution s 
) const

Computes the impact cost.

Parameters
[in]robotRobot model.
[in]impact_statusImpact status.
[in]dataCost function data.
[in]grid_infoGrid info.
[in]sSplit solution.
Returns
Stage cost.

◆ evalStageCost()

double robotoc::CostFunction::evalStageCost ( Robot robot,
const ContactStatus contact_status,
CostFunctionData data,
const GridInfo grid_info,
const SplitSolution s 
) const

Computes the stage cost.

Parameters
[in]robotRobot model.
[in]contact_statusContact status.
[in]dataCost function data.
[in]grid_infoGrid info.
[in]sSplit solution.
Returns
Stage cost.

◆ evalTerminalCost()

double robotoc::CostFunction::evalTerminalCost ( Robot robot,
CostFunctionData data,
const GridInfo grid_info,
const SplitSolution s 
) const

Computes the terminal cost.

Parameters
[in]robotRobot model.
[in]dataCost function data.
[in]grid_infoGrid info.
[in]sSplit solution.
Returns
Terminal cost.

◆ exist()

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

Checks if thsi has a cost function component of the specified name.

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

◆ get()

CostFunctionComponentBasePtr robotoc::CostFunction::get ( const std::string &  name) const

Gets a cost function component. If a component of the specified name does not exist, throws an exeption.

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

◆ getCostComponentList()

std::vector< std::string > robotoc::CostFunction::getCostComponentList ( ) const

Gets a list of the cost components.

Returns
Name list of cost components.

◆ linearizeImpactCost()

double robotoc::CostFunction::linearizeImpactCost ( Robot robot,
const ImpactStatus impact_status,
CostFunctionData data,
const GridInfo grid_info,
const SplitSolution s,
SplitKKTResidual kkt_residual 
) const

Computes the impact cost and its first-order partial derivatives.

Parameters
[in]robotRobot model.
[in]impact_statusImpact status.
[in]dataCost function data.
[in]grid_infoGrid info.
[in]sSplit solution.
[in,out]kkt_residualSplit KKT residual. The partial derivatives are added to this object.
Returns
Stage cost.

◆ linearizeStageCost()

double robotoc::CostFunction::linearizeStageCost ( Robot robot,
const ContactStatus contact_status,
CostFunctionData data,
const GridInfo grid_info,
const SplitSolution s,
SplitKKTResidual kkt_residual 
) const

Computes the stage cost and its first-order partial derivatives.

Parameters
[in]robotRobot model.
[in]contact_statusContact status.
[in]dataCost function data.
[in]grid_infoGrid info.
[in]sSplit solution.
[in,out]kkt_residualSplit KKT residual. The partial derivatives are added to this object.
Returns
Stage cost.

◆ linearizeTerminalCost()

double robotoc::CostFunction::linearizeTerminalCost ( Robot robot,
CostFunctionData data,
const GridInfo grid_info,
const SplitSolution s,
SplitKKTResidual kkt_residual 
) const

Computes the terminal cost and its first-order partial derivatives.

Parameters
[in]robotRobot model.
[in]dataCost function data.
[in]grid_infoGrid info.
[in]sSplit solution.
[in,out]kkt_residualSplit KKT residual. The partial derivatives are added to this object.
Returns
Stage cost.

◆ operator=() [1/2]

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

Default copy operator.

◆ operator=() [2/2]

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

Default move assign operator.

◆ quadratizeImpactCost()

double robotoc::CostFunction::quadratizeImpactCost ( Robot robot,
const ImpactStatus impact_status,
CostFunctionData data,
const GridInfo grid_info,
const SplitSolution s,
SplitKKTResidual kkt_residual,
SplitKKTMatrix kkt_matrix 
) const

Computes the impact cost, its first-order partial derivatives, and its Hessian, i.e., its second-order partial derivatives.

Parameters
[in]robotRobot model.
[in]impact_statusImpact status.
[in]dataCost function data.
[in]grid_infoGrid info.
[in]sSplit solution.
[in,out]kkt_residualSplit KKT residual. The partial derivatives are added to this object.
[in,out]kkt_matrixSplit KKT matrix. The Hessians are added to this object.
Returns
Stage cost.

◆ quadratizeStageCost()

double robotoc::CostFunction::quadratizeStageCost ( Robot robot,
const ContactStatus contact_status,
CostFunctionData data,
const GridInfo grid_info,
const SplitSolution s,
SplitKKTResidual kkt_residual,
SplitKKTMatrix kkt_matrix 
) const

Computes the stage cost, its first-order partial derivatives, and its Hessian, i.e., its second-order partial derivatives.

Parameters
[in]robotRobot model.
[in]contact_statusContact status.
[in]dataCost function data.
[in]grid_infoGrid info.
[in]sSplit solution.
[in,out]kkt_residualSplit KKT residual. The partial derivatives are added to this object.
[in,out]kkt_matrixSplit KKT matrix. The Hessians are added to this object.
Returns
Stage cost.

◆ quadratizeTerminalCost()

double robotoc::CostFunction::quadratizeTerminalCost ( Robot robot,
CostFunctionData data,
const GridInfo grid_info,
const SplitSolution s,
SplitKKTResidual kkt_residual,
SplitKKTMatrix kkt_matrix 
) const

Computes the terminal cost, its first-order partial derivatives, and its Hessian, i.e., its second-order partial derivatives.

Parameters
[in]robotRobot model.
[in]dataCost function data.
[in]grid_infoGrid info.
[in]sSplit solution.
[in,out]kkt_residualSplit KKT residual. The partial derivatives are added to this object.
[in,out]kkt_matrixSplit KKT matrix. The Hessians are added to this object.
Returns
Stage cost.

◆ setDiscountFactor()

void robotoc::CostFunction::setDiscountFactor ( const double  discount_factor,
const double  discount_time_step 
)

Sets the discount facor.

Parameters
[in]discount_factorDiscount factor. Must be positive and smaller than 1.0. Otherwise, the discounted cost is disabled.
[in]discount_time_stepThe cost is reduced by discount_factor as the time proceeds to this value. Must be positive. Otherwise, the discounted cost is disabled.

Friends And Related Function Documentation

◆ operator<< [1/2]

std::ostream & operator<< ( std::ostream &  os,
const CostFunction cost_function 
)
friend

◆ operator<< [2/2]

std::ostream & operator<< ( std::ostream &  os,
const std::shared_ptr< CostFunction > &  cost_function 
)
friend

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