Template Class CostModelAbstractTpl
Defined in File cost-base.hpp
Inheritance Relationships
Base Type
public crocoddyl::CostModelBase(Class CostModelBase)
Derived Types
public crocoddyl::CostModelNumDiffTpl< _Scalar >(Template Class CostModelNumDiffTpl)public crocoddyl::CostModelResidualTpl< _Scalar >(Template Class CostModelResidualTpl)
Class Documentation
-
template<typename _Scalar>
class CostModelAbstractTpl : public crocoddyl::CostModelBase 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 anx-tuple, its velocity \(\dot{\mathbf{x}}\in T_{\mathbf{x}}\mathcal{X}\) that belongs to the tangent space withndxdimension, and the control input \(\mathbf{u}\in\mathbb{R}^{nu}\). The residual vector is defined by \(\mathbf{r}\in\mathbb{R}^{nr}\) wherenrdescribes 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()andcalcDiff()routines.calc()computes the cost (and its residual) andcalcDiff()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 thatcalcDiff()computes the derivatives using the latest stored values bycalc(). Thus, we need to first runcalc().Subclassed by crocoddyl::CostModelNumDiffTpl< _Scalar >, crocoddyl::CostModelResidualTpl< _Scalar >
Public Types
-
typedef MathBaseTpl<Scalar> MathBase
-
typedef CostDataAbstractTpl<Scalar> CostDataAbstract
-
typedef StateAbstractTpl<Scalar> StateAbstract
-
typedef ActivationModelAbstractTpl<Scalar> ActivationModelAbstract
-
typedef ResidualModelAbstractTpl<Scalar> ResidualModelAbstract
-
typedef ActivationModelQuadTpl<Scalar> ActivationModelQuad
-
typedef DataCollectorAbstractTpl<Scalar> DataCollectorAbstract
Public Functions
Initialize the cost model.
- Parameters:
state – [in] State of the dynamical system
activation – [in] Activation model
residual – [in] Residual model
Initialize the cost model.
- Parameters:
state – [in] State of the dynamical system
activation – [in] Activation model
nu – [in] Dimension of control vector
The default
nuvalue is obtained fromStateAbstractTpl::get_nv().- Parameters:
state – [in] State of the dynamical system
activation – [in] Activation model
We use
ActivationModelQuadTplas a default activation model (i.e., \(a=\frac{1}{2}\|\mathbf{r}\|^2\))- Parameters:
state – [in] State of the dynamical system
residual – [in] Residual model
We use
ActivationModelQuadTplas a default activation model (i.e., \(a=\frac{1}{2}\|\mathbf{r}\|^2\))- Parameters:
state – [in] State of the system
nr – [in] Dimension of residual vector
nu – [in] Dimension of control vector
We use
ActivationModelQuadTplas a default activation model (i.e., \(a=\frac{1}{2}\|\mathbf{r}\|^2\)). Furthermore, the defaultnuvalue is obtained fromStateAbstractTpl::get_nv().- Parameters:
state – [in] State of the dynamical system
nr – [in] Dimension of residual vector
nu – [in] Dimension of control vector
-
virtual ~CostModelAbstractTpl() = default
Compute the cost value and its residual vector.
- Parameters:
data – [in] Cost data
x – [in] State point \(\mathbf{x}\in\mathbb{R}^{ndx}\)
u – [in] Control input \(\mathbf{u}\in\mathbb{R}^{nu}\)
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:
data – [in] Cost data
x – [in] State point \(\mathbf{x}\in\mathbb{R}^{ndx}\)
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:
data – [in] Cost data
x – [in] State point \(\mathbf{x}\in\mathbb{R}^{ndx}\)
u – [in] Control input \(\mathbf{u}\in\mathbb{R}^{nu}\)
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:
data – [in] Cost data
x – [in] State point \(\mathbf{x}\in\mathbb{R}^{ndx}\)
-
virtual std::shared_ptr<CostDataAbstract> 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 if we need to create additional data, for instance, to avoid dynamic memory allocation.
- Parameters:
data – Data collector
- Returns:
the cost data
-
const std::shared_ptr<StateAbstract> &get_state() const
Return the state.
-
const std::shared_ptr<ActivationModelAbstract> &get_activation() const
Return the activation model.
-
const std::shared_ptr<ResidualModelAbstract> &get_residual() const
Return the residual model.
-
std::size_t get_nu() const
Return the dimension of the control input.
-
template<class ReferenceType>
void set_reference(ReferenceType ref) Modify the cost reference.
-
template<class ReferenceType>
ReferenceType get_reference() Return the cost reference.
-
virtual void print(std::ostream &os) const
Print relevant information of the cost model.
- Parameters:
os – [out] Output stream object
Public Members
- EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar
Protected Functions
-
virtual void set_referenceImpl(const std::type_info&, const void*)
Modify the cost reference.
-
virtual void get_referenceImpl(const std::type_info&, void*)
Return the cost reference.
-
inline CostModelAbstractTpl()
Protected Attributes
-
std::shared_ptr<StateAbstract> state_
State description.
-
std::shared_ptr<ActivationModelAbstract> activation_
Activation model.
-
std::shared_ptr<ResidualModelAbstract> residual_
Residual model.
-
std::size_t nu_
Control dimension.
Friends
-
template<class Scalar>
friend std::ostream &operator<<(std::ostream &os, const CostModelAbstractTpl<Scalar> &model) Print information on the cost model.
-
typedef MathBaseTpl<Scalar> MathBase