Template Class CostModelSumTpl
Defined in File cost-sum.hpp
Class Documentation
-
template<typename _Scalar>
class CostModelSumTpl 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()andcalcDiff()routines.calc()computes the costs (and its residuals) andcalcDiff()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
Public Types
-
typedef MathBaseTpl<Scalar> MathBase
-
typedef CostDataSumTpl<Scalar> CostDataSum
-
typedef StateAbstractTpl<Scalar> StateAbstract
-
typedef CostModelAbstractTpl<Scalar> CostModelAbstract
-
typedef CostDataAbstractTpl<Scalar> CostDataAbstract
-
typedef DataCollectorAbstractTpl<Scalar> DataCollectorAbstract
-
typedef CostItemTpl<Scalar> CostItem
-
typedef std::map<std::string, std::shared_ptr<CostDataAbstract>> CostDataContainer
Public Functions
Initialize the cost-sum model.
- Parameters:
state – [in] State description
nu – [in] Dimension of control vector
Initialize the cost-sum model.
The default
nuvalue is obtained fromStateAbstractTpl::get_nv().- Parameters:
state – [in] State description
-
~CostModelSumTpl()
Add a cost item.
- Parameters:
name – [in] Cost name
cost – [in] Cost model
weight – [in] Cost weight
active – [in] True if the cost is activated (default true)
Add a cost item.
- Parameters:
cost_item – [in] Cost item
-
void removeCost(const std::string &name)
Remove a cost item.
- Parameters:
name – [in] Cost name
-
void changeCostStatus(const std::string &name, const bool active)
Change the cost status.
- Parameters:
name – [in] Cost name
active – [in] Cost status (true for active and false for inactive)
Compute the total cost value.
- 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 the total cost.
- 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 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:
data – [in] Cost data
x – [in] State point \(\mathbf{x}\in\mathbb{R}^{ndx}\)
u – [in] Control input \(\mathbf{u}\in\mathbb{R}^{nu}\)
-
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:
data – Data collector
- Returns:
the cost data
-
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:
NewScalar – The new scalar type to cast to.
- Returns:
CostModelSumTpl<NewScalar> A cost-sum model with the new scalar type.
-
const std::shared_ptr<StateAbstract> &get_state() const
Return the state.
-
const CostModelContainer &get_costs() const
Return the stack of cost models.
-
std::size_t get_nu() const
Return the dimension of the control input.
-
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.
-
const std::set<std::string> &get_active_set() const
Return the names of the set of active costs.
-
const std::set<std::string> &get_inactive_set() const
Return the names of the set of inactive costs.
- 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()"
-
inline const std::vector<std::string> &get_inactive()
-
bool getCostStatus(const std::string &name) const
Return the status of a given cost name.
- Parameters:
name – [in] Cost name
Public Members
- EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar
Friends
-
template<class Scalar>
friend std::ostream &operator<<(std::ostream &os, const CostModelSumTpl<Scalar> &model) Print information on the stack of costs.
-
typedef MathBaseTpl<Scalar> MathBase