Crocoddyl
 
Loading...
Searching...
No Matches
CostModelSumTpl< _Scalar > Class Template Reference

Summation of individual cost models. More...

#include <cost-sum.hpp>

Public Types

typedef CostDataAbstractTpl< Scalar > CostDataAbstract
 
typedef std::map< std::string, std::shared_ptr< CostDataAbstract > > CostDataContainer
 
typedef CostDataSumTpl< Scalar > CostDataSum
 
typedef CostItemTpl< Scalar > CostItem
 
typedef CostModelAbstractTpl< Scalar > CostModelAbstract
 
typedef std::map< std::string, std::shared_ptr< CostItem > > CostModelContainer
 
typedef DataCollectorAbstractTpl< Scalar > DataCollectorAbstract
 
typedef MathBaseTpl< Scalar > MathBase
 
typedef MathBase::MatrixXs MatrixXs
 
typedef StateAbstractTpl< Scalar > StateAbstract
 
typedef MathBase::VectorXs VectorXs
 

Public Member Functions

 CostModelSumTpl (std::shared_ptr< StateAbstract > state)
 Initialize the cost-sum model.
 
 CostModelSumTpl (std::shared_ptr< StateAbstract > state, const std::size_t nu)
 Initialize the cost-sum model.
 
void addCost (const std::shared_ptr< CostItem > &cost_item)
 Add a cost item.
 
void addCost (const std::string &name, std::shared_ptr< CostModelAbstract > cost, const Scalar weight, const bool active=true)
 Add a cost item.
 
void calc (const std::shared_ptr< CostDataSum > &data, const Eigen::Ref< const VectorXs > &x)
 Compute the total cost value for nodes that depends only on the state.
 
void calc (const std::shared_ptr< CostDataSum > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
 Compute the total cost value.
 
void calcDiff (const std::shared_ptr< CostDataSum > &data, const Eigen::Ref< const VectorXs > &x)
 Compute the Jacobian and Hessian of the total cost for nodes that depends on the state only.
 
void calcDiff (const std::shared_ptr< CostDataSum > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
 Compute the Jacobian and Hessian of the total cost.
 
template<typename NewScalar >
CostModelSumTpl< NewScalar > cast () const
 Cast the cost-sum model to a different scalar type.
 
void changeCostStatus (const std::string &name, const bool active)
 Change the cost status.
 
std::shared_ptr< CostDataSumcreateData (DataCollectorAbstract *const data)
 Create the cost data.
 
 DEPRECATED ("get_active() is deprecated and will be replaced with get_active_set()", const std::vector< std::string > &get_active() { active_.clear();active_.reserve(active_set_.size());for(const auto &contact :active_set_) { active_.push_back(contact);} return active_;};) DEPRECATED("get_inactive() is deprecated and will be replaced with " "get_inactive_set()"
 
const std::set< std::string > & get_active_set () const
 Return the names of the set of active costs.
 
const CostModelContainer & get_costs () const
 Return the stack of cost models.
 
const std::vector< std::string > & get_inactive ()
 
const std::set< std::string > & get_inactive_set () const
 Return the names of the set of inactive costs.
 
std::size_t get_nr () const
 Return the dimension of the active residual vector.
 
std::size_t get_nr_total () const
 Return the dimension of the total residual vector.
 
std::size_t get_nu () const
 Return the dimension of the control input.
 
const std::shared_ptr< StateAbstract > & get_state () const
 Return the state.
 
bool getCostStatus (const std::string &name) const
 Return the status of a given cost name.
 
void removeCost (const std::string &name)
 Remove a cost item.
 

Public Attributes

EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar
 

Friends

template<class Scalar >
std::ostream & operator<< (std::ostream &os, const CostModelSumTpl< Scalar > &model)
 Print information on the stack of costs.
 

Detailed Description

template<typename _Scalar>
class crocoddyl::CostModelSumTpl< _Scalar >

Summation of individual cost models.

This class serves to manage a set of added cost models. The cost functions might active or inactive, with this approach we avoid dynamic allocation of memory. Each cost model is added through addCost, where the weight and its status can be defined.

The main computations are carring out in calc() and calcDiff() routines. calc() computes the costs (and its residuals) and calcDiff() computes the derivatives of the cost functions (and its residuals). Concretely speaking, calcDiff() builds a linear-quadratic approximation of the total cost function with the form: \(\mathbf{\ell_x}\in\mathbb{R}^{ndx}\), \(\mathbf{\ell_u}\in\mathbb{R}^{nu}\), \(\mathbf{\ell_{xx}}\in\mathbb{R}^{ndx\times ndx}\), \(\mathbf{\ell_{xu}}\in\mathbb{R}^{ndx\times nu}\), \(\mathbf{\ell_{uu}}\in\mathbb{R}^{nu\times nu}\) are the Jacobians and Hessians, respectively.

See also
CostModelAbstractTpl, calc(), calcDiff(), createData()

Definition at line 75 of file cost-sum.hpp.

Member Typedef Documentation

◆ MathBase

template<typename _Scalar >
typedef MathBaseTpl<Scalar> MathBase

Definition at line 80 of file cost-sum.hpp.

◆ CostDataSum

template<typename _Scalar >
typedef CostDataSumTpl<Scalar> CostDataSum

Definition at line 81 of file cost-sum.hpp.

◆ StateAbstract

template<typename _Scalar >
typedef StateAbstractTpl<Scalar> StateAbstract

Definition at line 82 of file cost-sum.hpp.

◆ CostModelAbstract

template<typename _Scalar >
typedef CostModelAbstractTpl<Scalar> CostModelAbstract

Definition at line 83 of file cost-sum.hpp.

◆ CostDataAbstract

template<typename _Scalar >
typedef CostDataAbstractTpl<Scalar> CostDataAbstract

Definition at line 84 of file cost-sum.hpp.

◆ DataCollectorAbstract

template<typename _Scalar >
typedef DataCollectorAbstractTpl<Scalar> DataCollectorAbstract

Definition at line 85 of file cost-sum.hpp.

◆ CostItem

template<typename _Scalar >
typedef CostItemTpl<Scalar> CostItem

Definition at line 86 of file cost-sum.hpp.

◆ VectorXs

template<typename _Scalar >
typedef MathBase::VectorXs VectorXs

Definition at line 87 of file cost-sum.hpp.

◆ MatrixXs

template<typename _Scalar >
typedef MathBase::MatrixXs MatrixXs

Definition at line 88 of file cost-sum.hpp.

◆ CostModelContainer

template<typename _Scalar >
typedef std::map<std::string, std::shared_ptr<CostItem> > CostModelContainer

Definition at line 90 of file cost-sum.hpp.

◆ CostDataContainer

template<typename _Scalar >
typedef std::map<std::string, std::shared_ptr<CostDataAbstract> > CostDataContainer

Definition at line 92 of file cost-sum.hpp.

Constructor & Destructor Documentation

◆ CostModelSumTpl() [1/2]

template<typename _Scalar >
CostModelSumTpl ( std::shared_ptr< StateAbstract state,
const std::size_t  nu 
)

Initialize the cost-sum model.

Parameters
[in]stateState description
[in]nuDimension of control vector

◆ CostModelSumTpl() [2/2]

template<typename _Scalar >
CostModelSumTpl ( std::shared_ptr< StateAbstract state)
explicit

Initialize the cost-sum model.

The default nu value is obtained from StateAbstractTpl::get_nv().

Parameters
[in]stateState description

Member Function Documentation

◆ addCost() [1/2]

template<typename _Scalar >
void addCost ( const std::string &  name,
std::shared_ptr< CostModelAbstract cost,
const Scalar  weight,
const bool  active = true 
)

Add a cost item.

Parameters
[in]nameCost name
[in]costCost model
[in]weightCost weight
[in]activeTrue if the cost is activated (default true)

◆ addCost() [2/2]

template<typename _Scalar >
void addCost ( const std::shared_ptr< CostItem > &  cost_item)

Add a cost item.

Parameters
[in]cost_itemCost item

◆ removeCost()

template<typename _Scalar >
void removeCost ( const std::string &  name)

Remove a cost item.

Parameters
[in]nameCost name

◆ changeCostStatus()

template<typename _Scalar >
void changeCostStatus ( const std::string &  name,
const bool  active 
)

Change the cost status.

Parameters
[in]nameCost name
[in]activeCost status (true for active and false for inactive)

◆ calc() [1/2]

template<typename _Scalar >
void calc ( const std::shared_ptr< CostDataSum > &  data,
const Eigen::Ref< const VectorXs > &  x,
const Eigen::Ref< const VectorXs > &  u 
)

Compute the total cost value.

Parameters
[in]dataCost data
[in]xState point \(\mathbf{x}\in\mathbb{R}^{ndx}\)
[in]uControl input \(\mathbf{u}\in\mathbb{R}^{nu}\)

◆ calc() [2/2]

template<typename _Scalar >
void calc ( const std::shared_ptr< CostDataSum > &  data,
const Eigen::Ref< const VectorXs > &  x 
)

Compute the total cost value for nodes that depends only on the state.

It updates the total cost based on the state only. This function is used in the terminal nodes of an optimal control problem.

Parameters
[in]dataCost data
[in]xState point \(\mathbf{x}\in\mathbb{R}^{ndx}\)

◆ calcDiff() [1/2]

template<typename _Scalar >
void calcDiff ( const std::shared_ptr< CostDataSum > &  data,
const Eigen::Ref< const VectorXs > &  x,
const Eigen::Ref< const VectorXs > &  u 
)

Compute the Jacobian and Hessian of the total cost.

Parameters
[in]dataCost data
[in]xState point \(\mathbf{x}\in\mathbb{R}^{ndx}\)
[in]uControl input \(\mathbf{u}\in\mathbb{R}^{nu}\)

◆ calcDiff() [2/2]

template<typename _Scalar >
void calcDiff ( const std::shared_ptr< CostDataSum > &  data,
const Eigen::Ref< const VectorXs > &  x 
)

Compute the Jacobian and Hessian of the total cost for nodes that depends on the state only.

It updates the Jacobian and Hessian of the total cost based on the state only. This function is used in the terminal nodes of an optimal control problem.

Parameters
[in]dataCost data
[in]xState point \(\mathbf{x}\in\mathbb{R}^{ndx}\)
[in]uControl input \(\mathbf{u}\in\mathbb{R}^{nu}\)

◆ createData()

template<typename _Scalar >
std::shared_ptr< CostDataSum > createData ( DataCollectorAbstract *const  data)

Create the cost data.

The default data contains objects to store the values of the cost, residual vector and their derivatives (first and second order derivatives). However, it is possible to specialize this function is we need to create additional data, for instance, to avoid dynamic memory allocation.

Parameters
dataData collector
Returns
the cost data

◆ cast()

template<typename _Scalar >
template<typename NewScalar >
CostModelSumTpl< NewScalar > cast ( ) const

Cast the cost-sum model to a different scalar type.

It is useful for operations requiring different precision or scalar types.

Template Parameters
NewScalarThe new scalar type to cast to.
Returns
CostModelSumTpl<NewScalar> A cost-sum model with the new scalar type.

◆ get_inactive()

template<typename _Scalar >
const std::vector< std::string > & get_inactive ( )
inline

Definition at line 269 of file cost-sum.hpp.

◆ getCostStatus()

template<typename _Scalar >
bool getCostStatus ( const std::string &  name) const

Return the status of a given cost name.

Parameters
[in]nameCost name

Member Data Documentation

◆ Scalar

template<typename _Scalar >
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar

Definition at line 79 of file cost-sum.hpp.


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