crocoddyl  1.6.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
CostModelSumTpl< _Scalar > Class Template Reference

Summation of individual cost models. More...

#include <crocoddyl/core/costs/cost-sum.hpp>

Public Types

typedef CostDataAbstractTpl< Scalar > CostDataAbstract
 
typedef std::map< std::string, boost::shared_ptr< CostDataAbstract > > CostDataContainer
 
typedef CostDataSumTpl< Scalar > CostDataSum
 
typedef CostItemTpl< Scalar > CostItem
 
typedef CostModelAbstractTpl< Scalar > CostModelAbstract
 
typedef std::map< std::string, boost::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 (boost::shared_ptr< StateAbstract > state, const std::size_t &nu)
 Initialize the cost-sum model. More...
 
 CostModelSumTpl (boost::shared_ptr< StateAbstract > state)
 Initialize the cost-sum model. More...
 
void addCost (const std::string &name, boost::shared_ptr< CostModelAbstract > cost, const Scalar &weight, bool active=true)
 Add a cost item. More...
 
void calc (const boost::shared_ptr< CostDataSum > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
 Compute the total cost value. More...
 
void calc (const boost::shared_ptr< CostDataSum > &data, const Eigen::Ref< const VectorXs > &x)
 
void calcDiff (const boost::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. More...
 
void calcDiff (const boost::shared_ptr< CostDataSum > &data, const Eigen::Ref< const VectorXs > &x)
 
void changeCostStatus (const std::string &name, bool active)
 Change the cost status. More...
 
boost::shared_ptr< CostDataSumcreateData (DataCollectorAbstract *const data)
 Create the cost data. More...
 
const std::vector< std::string > & get_active () const
 Return the names of the active costs.
 
const CostModelContainer & get_costs () const
 Return the stack of cost models.
 
const std::vector< std::string > & get_inactive () const
 Return the names of the inactive costs.
 
const std::size_t & get_nr () const
 Return the dimension of the active residual vector.
 
const std::size_t & get_nr_total () const
 Return the dimension of the total residual vector.
 
const std::size_t & get_nu () const
 Return the dimension of the control input.
 
const boost::shared_ptr< StateAbstract > & get_state () const
 Return the state.
 
bool getCostStatus (const std::string &name) const
 Return the status of a given cost name. More...
 
void removeCost (const std::string &name)
 Remove a cost item. More...
 

Public Attributes

EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar
 

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{l_x}\in\mathbb{R}^{ndx}\), \(\mathbf{l_u}\in\mathbb{R}^{nu}\), \(\mathbf{l_{xx}}\in\mathbb{R}^{ndx\times ndx}\), \(\mathbf{l_{xu}}\in\mathbb{R}^{ndx\times nu}\), \(\mathbf{l_{uu}}\in\mathbb{R}^{nu\times nu}\) are the Jacobians and Hessians, respectively.

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

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

Constructor & Destructor Documentation

◆ CostModelSumTpl() [1/2]

CostModelSumTpl ( boost::shared_ptr< StateAbstract state,
const std::size_t &  nu 
)

Initialize the cost-sum model.

Parameters
[in]stateState of the multibody system
[in]nuDimension of control vector

◆ CostModelSumTpl() [2/2]

CostModelSumTpl ( boost::shared_ptr< StateAbstract state)
explicit

Initialize the cost-sum model.

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

Parameters
[in]stateState of the multibody system

Member Function Documentation

◆ addCost()

void addCost ( const std::string &  name,
boost::shared_ptr< CostModelAbstract cost,
const Scalar &  weight,
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)

◆ removeCost()

void removeCost ( const std::string &  name)

Remove a cost item.

Parameters
[in]nameCost name

◆ changeCostStatus()

void changeCostStatus ( const std::string &  name,
bool  active 
)

Change the cost status.

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

◆ calc() [1/2]

void calc ( const boost::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}\)

◆ calcDiff() [1/2]

void calcDiff ( const boost::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}\)

◆ createData()

boost::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 specialized this function is we need to create additional data, for instance, to avoid dynamic memory allocation.

Parameters
dataData collector
Returns
the cost data

◆ calc() [2/2]

void calc ( const boost::shared_ptr< CostDataSum > &  data,
const Eigen::Ref< const VectorXs > &  x 
)

Compute the total cost value.

Parameters
[in]dataCost data
[in]xState point

◆ calcDiff() [2/2]

void calcDiff ( const boost::shared_ptr< CostDataSum > &  data,
const Eigen::Ref< const VectorXs > &  x 
)

Compute the Jacobian and Hessian of the total cost.

Parameters
[in]dataCost data
[in]xState point

◆ getCostStatus()

bool getCostStatus ( const std::string &  name) const

Return the status of a given cost name.

Parameters
[in]nameCost name

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