6#include <boost/unordered_map.hpp>
10template <
typename Scalar>
struct CostStackDataTpl;
28 using CostKey = std::variant<std::size_t, std::string>;
29 using CostMap = boost::unordered::unordered_map<CostKey, CostItem>;
42 const std::vector<PolyCost> &comps = {},
43 const std::vector<Scalar> &weights = {});
48 for (
const auto &[key, item] : comps) {
49 auto &cost = *item.first;
52 "Cannot add new component due to inconsistent input dimensions "
53 "(got ({:d}, {:d}), expected ({:d}, {:d}))",
54 cost.ndx(), cost.nu, this->ndx(), this->nu));
64 return this->
addCost(size, cost, weight);
75 return dynamic_cast<Derived *
>(&*item.first);
78 template <
typename Derived>
81 return dynamic_cast<const Derived *
>(&*item.first);
84 void evaluate(
const ConstVectorRef &x,
const ConstVectorRef &u,
99 xyz::polymorphic<CostAbstractTpl<T>>;
104xyz::polymorphic<CostStackTpl<T>>
operator+(
const CostPtr<T> &c1,
105 const CostPtr<T> &c2) {
106 return xyz::polymorphic<CostStackTpl<T>>({c1, c2}, {1., 1.});
110xyz::polymorphic<CostStackTpl<T>>
117xyz::polymorphic<CostStackTpl<T>>
119 c1->addCost(std::move(c2), 1.);
124xyz::polymorphic<CostStackTpl<T>>
126 c1->addCost(std::move(c2), 1.);
131xyz::polymorphic<CostStackTpl<T>>
133 for (
auto &[key, item] : c1->components_) {
139template <
typename _Scalar>
146 boost::unordered::unordered_map<CostKey, shared_ptr<CostData>>;
152#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
153#include "aligator/modelling/costs/sum-of-costs.txx"
#define ALIGATOR_DOMAIN_ERROR(msg)
xyz::polymorphic< CostStackTpl< T > > operator*(T u, xyz::polymorphic< CostStackTpl< T > > &&c1)
xyz::polymorphic< CostStackTpl< T > > operator+(const CostPtr< T > &c1, const CostPtr< T > &c2)
Stage costs for control problems.
xyz::polymorphic< Manifold > space
Data struct for CostAbstractTpl.
CostStackDataTpl(const CostStackTpl< Scalar > &obj)
typename CostStack::CostKey CostKey
boost::unordered::unordered_map< CostKey, shared_ptr< CostData > > DataMap
Weighted sum of multiple cost components.
CostItem & addCost(const PolyCost &cost, const Scalar weight=1.)
CostItem & addCost(const CostKey &key, const PolyCost &cost, const Scalar weight=1.)
void computeGradients(const ConstVectorRef &x, const ConstVectorRef &u, CostData &data) const
std::variant< std::size_t, std::string > CostKey
ManifoldAbstractTpl< Scalar > Manifold
Derived * getComponent(const CostKey &key)
Get component, cast down to the specified type.
xyz::polymorphic< CostBase > PolyCost
CostStackTpl(const PolyCost &cost)
Constructor from a single CostBase instance.
CostStackTpl(xyz::polymorphic< Manifold > space, const int nu, const std::vector< PolyCost > &comps={}, const std::vector< Scalar > &weights={})
Constructor with a specified dimension, and optional vector of components and weights.
boost::unordered::unordered_map< CostKey, CostItem > CostMap
CostStackTpl(xyz::polymorphic< Manifold > space, const int nu, const CostMap &comps)
ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
void evaluate(const ConstVectorRef &x, const ConstVectorRef &u, CostData &data) const
bool checkDimension(const CostBase &comp) const
Check the dimension of a component.
typename CostMap::iterator CostIterator
const Derived * getComponent(const CostKey &key) const
void computeHessians(const ConstVectorRef &x, const ConstVectorRef &u, CostData &data) const
shared_ptr< CostData > createData() const
std::pair< PolyCost, Scalar > CostItem