Crocoddyl
CostModelAbstractTpl< _Scalar > Class Template Referenceabstract

Abstract class for cost models. More...

#include <cost-base.hpp>

Inheritance diagram for CostModelAbstractTpl< _Scalar >:
CostModelNumDiffTpl< _Scalar > CostModelResidualTpl< _Scalar >

Public Types

typedef ActivationModelAbstractTpl< Scalar > ActivationModelAbstract
 
typedef ActivationModelQuadTpl< Scalar > ActivationModelQuad
 
typedef CostDataAbstractTpl< Scalar > CostDataAbstract
 
typedef DataCollectorAbstractTpl< Scalar > DataCollectorAbstract
 
typedef MathBaseTpl< Scalar > MathBase
 
typedef MathBase::MatrixXs MatrixXs
 
typedef ResidualModelAbstractTpl< Scalar > ResidualModelAbstract
 
typedef StateAbstractTpl< Scalar > StateAbstract
 
typedef MathBase::VectorXs VectorXs
 

Public Member Functions

 CostModelAbstractTpl (boost::shared_ptr< StateAbstract > state, boost::shared_ptr< ActivationModelAbstract > activation)
 Initialize the cost model. More...
 
 CostModelAbstractTpl (boost::shared_ptr< StateAbstract > state, boost::shared_ptr< ActivationModelAbstract > activation, boost::shared_ptr< ResidualModelAbstract > residual)
 Initialize the cost model. More...
 
 CostModelAbstractTpl (boost::shared_ptr< StateAbstract > state, boost::shared_ptr< ActivationModelAbstract > activation, const std::size_t nu)
 Initialize the cost model. More...
 
 CostModelAbstractTpl (boost::shared_ptr< StateAbstract > state, boost::shared_ptr< ResidualModelAbstract > residual)
 Initialize the cost model. More...
 
 CostModelAbstractTpl (boost::shared_ptr< StateAbstract > state, const std::size_t nr)
 Initialize the cost model. More...
 
 CostModelAbstractTpl (boost::shared_ptr< StateAbstract > state, const std::size_t nr, const std::size_t nu)
 Initialize the cost model. More...
 
virtual void calc (const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
 Compute the total cost value for nodes that depends only on the state. More...
 
virtual void calc (const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0
 Compute the cost value and its residual vector. More...
 
virtual void calcDiff (const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
 Compute the Jacobian and Hessian of the cost functions with respect to the state only. More...
 
virtual void calcDiff (const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0
 Compute the Jacobian and Hessian of cost and its residual vector. More...
 
virtual boost::shared_ptr< CostDataAbstractcreateData (DataCollectorAbstract *const data)
 Create the cost data. More...
 
const boost::shared_ptr< ActivationModelAbstract > & get_activation () const
 Return the activation model.
 
std::size_t get_nu () const
 Return the dimension of the control input.
 
template<class ReferenceType >
ReferenceType get_reference ()
 Return the cost reference.
 
const boost::shared_ptr< ResidualModelAbstract > & get_residual () const
 Return the residual model.
 
const boost::shared_ptr< StateAbstract > & get_state () const
 Return the state.
 
virtual void print (std::ostream &os) const
 Print relevant information of the cost model. More...
 
template<class ReferenceType >
void set_reference (ReferenceType ref)
 Modify the cost reference.
 

Public Attributes

EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar
 

Protected Member Functions

virtual void get_referenceImpl (const std::type_info &, void *)
 Return the cost reference.
 
virtual void set_referenceImpl (const std::type_info &, const void *)
 Modify the cost reference.
 

Protected Attributes

boost::shared_ptr< ActivationModelAbstractactivation_
 Activation model.
 
std::size_t nu_
 Control dimension.
 
boost::shared_ptr< ResidualModelAbstractresidual_
 Residual model.
 
boost::shared_ptr< StateAbstractstate_
 State description.
 
VectorXs unone_
 No control vector.
 

Friends

template<class Scalar >
std::ostream & operator<< (std::ostream &os, const CostModelAbstractTpl< Scalar > &model)
 Print information on the cost model.
 

Detailed Description

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

Abstract class for cost models.

A cost model is defined by the scalar activation function \(a(\cdot)\) and by the residual function \(\mathbf{r}(\cdot)\) as follows:

\[ \ell(\mathbf{x},\mathbf{u}) = a(\mathbf{r}(\mathbf{x}, \mathbf{u})), \]

where the residual function depends on the state point \(\mathbf{x}\in\mathcal{X}\), which lies in the state manifold described with a nx-tuple, its velocity \(\dot{\mathbf{x}}\in T_{\mathbf{x}}\mathcal{X}\) that belongs to the tangent space with ndx dimension, and the control input \(\mathbf{u}\in\mathbb{R}^{nu}\). The residual vector is defined by \(\mathbf{r}\in\mathbb{R}^{nr}\) where nr describes its dimension in the Euclidean space. On the other hand, the activation function builds a cost value based on the definition of the residual vector. The residual vector has to be specialized in a derived classes.

The main computations are carring out in calc() and calcDiff() routines. calc() computes the cost (and its residual) and calcDiff() computes the derivatives of the cost function (and its residual). Concretely speaking, calcDiff() builds a linear-quadratic approximation of the 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. Additionally, it is important to note that calcDiff() computes the derivatives using the latest stored values by calc(). Thus, we need to first run calc().

See also
ActivationModelAbstractTpl, ResidualModelAbstractTpl calc(), calcDiff(), createData()

Definition at line 59 of file cost-base.hpp.

Constructor & Destructor Documentation

◆ CostModelAbstractTpl() [1/6]

CostModelAbstractTpl ( boost::shared_ptr< StateAbstract state,
boost::shared_ptr< ActivationModelAbstract activation,
boost::shared_ptr< ResidualModelAbstract residual 
)

Initialize the cost model.

Parameters
[in]stateState of the dynamical system
[in]activationActivation model
[in]residualResidual model

◆ CostModelAbstractTpl() [2/6]

CostModelAbstractTpl ( boost::shared_ptr< StateAbstract state,
boost::shared_ptr< ActivationModelAbstract activation,
const std::size_t  nu 
)

Initialize the cost model.

Parameters
[in]stateState of the dynamical system
[in]activationActivation model
[in]nuDimension of control vector

◆ CostModelAbstractTpl() [3/6]

CostModelAbstractTpl ( boost::shared_ptr< StateAbstract state,
boost::shared_ptr< ActivationModelAbstract activation 
)

Initialize the cost model.

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

Parameters
[in]stateState of the dynamical system
[in]activationActivation model

◆ CostModelAbstractTpl() [4/6]

CostModelAbstractTpl ( boost::shared_ptr< StateAbstract state,
boost::shared_ptr< ResidualModelAbstract residual 
)

Initialize the cost model.

We use ActivationModelQuadTpl as a default activation model (i.e., \(a=\frac{1}{2}\|\mathbf{r}\|^2\))

Parameters
[in]stateState of the dynamical system
[in]residualResidual model

◆ CostModelAbstractTpl() [5/6]

CostModelAbstractTpl ( boost::shared_ptr< StateAbstract state,
const std::size_t  nr,
const std::size_t  nu 
)

Initialize the cost model.

We use ActivationModelQuadTpl as a default activation model (i.e., \(a=\frac{1}{2}\|\mathbf{r}\|^2\))

Parameters
[in]stateState of the system
[in]nrDimension of residual vector
[in]nuDimension of control vector

◆ CostModelAbstractTpl() [6/6]

CostModelAbstractTpl ( boost::shared_ptr< StateAbstract state,
const std::size_t  nr 
)

Initialize the cost model.

We use ActivationModelQuadTpl as a default activation model (i.e., \(a=\frac{1}{2}\|\mathbf{r}\|^2\)). Furthermore, the default nu value is obtained from StateAbstractTpl::get_nv().

Parameters
[in]stateState of the dynamical system
[in]nrDimension of residual vector
[in]nuDimension of control vector

Member Function Documentation

◆ calc() [1/2]

virtual void calc ( const boost::shared_ptr< CostDataAbstract > &  data,
const Eigen::Ref< const VectorXs > &  x,
const Eigen::Ref< const VectorXs > &  u 
)
pure virtual

Compute the cost value and its residual vector.

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

Implemented in CostModelNumDiffTpl< _Scalar >, and CostModelResidualTpl< _Scalar >.

◆ calc() [2/2]

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

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}\)

Reimplemented in CostModelNumDiffTpl< _Scalar >, and CostModelResidualTpl< _Scalar >.

◆ calcDiff() [1/2]

virtual void calcDiff ( const boost::shared_ptr< CostDataAbstract > &  data,
const Eigen::Ref< const VectorXs > &  x,
const Eigen::Ref< const VectorXs > &  u 
)
pure virtual

Compute the Jacobian and Hessian of cost and its residual vector.

It computes the Jacobian and Hessian of the cost function. It assumes that calc() has been run first.

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

Implemented in CostModelNumDiffTpl< _Scalar >, and CostModelResidualTpl< _Scalar >.

◆ calcDiff() [2/2]

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

Compute the Jacobian and Hessian of the cost functions with respect to the state only.

It updates the Jacobian and Hessian of the cost function 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}\)

Reimplemented in CostModelNumDiffTpl< _Scalar >, and CostModelResidualTpl< _Scalar >.

◆ createData()

virtual boost::shared_ptr<CostDataAbstract> createData ( DataCollectorAbstract *const  data)
virtual

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 if we need to create additional data, for instance, to avoid dynamic memory allocation.

Parameters
dataData collector
Returns
the cost data

Reimplemented in CostModelNumDiffTpl< _Scalar >, and CostModelResidualTpl< _Scalar >.

◆ print()

virtual void print ( std::ostream &  os) const
virtual

Print relevant information of the cost model.

Parameters
[out]osOutput stream object

Reimplemented in CostModelResidualTpl< _Scalar >.


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