31 void evaluate(
const ConstVectorRef &x,
const ConstVectorRef &u,
40 auto get_product_space()
const {
41 return dynamic_cast<CartesianProduct
const &
>(*this->
space);
43 static Data &data_cast(BaseData &data) {
return static_cast<Data &
>(data); }
55template <
typename Scalar>
57 const ConstVectorRef &u,
59 CartesianProduct
const space = get_product_space();
60 Data &d = data_cast(data);
61 auto xs =
space.split(x);
62 ConstVectorRef u1 = u.head(
c1_->nu);
63 ConstVectorRef u2 = u.tail(
c2_->nu);
65 c1_->evaluate(xs[0], u1, *d.data1_);
66 c2_->evaluate(xs[1], u2, *d.data2_);
68 d.value_ = d.data1_->value_ + d.data2_->value_;
71template <
typename Scalar>
73 const ConstVectorRef &u,
75 CartesianProduct
const space = get_product_space();
76 Data &d = data_cast(data);
77 auto xs =
space.split(x);
78 ConstVectorRef u1 = u.head(
c1_->nu);
79 ConstVectorRef u2 = u.tail(
c2_->nu);
84 c1_->computeGradients(xs[0], u1, d1);
85 c2_->computeGradients(xs[1], u2, d2);
87 d.Lx_.head(
c1_->ndx()) = d1.
Lx_;
88 d.Lx_.tail(
c2_->ndx()) = d2.
Lx_;
89 d.Lu_.head(
c1_->nu) = d1.
Lu_;
90 d.Lu_.tail(
c2_->nu) = d2.
Lu_;
93template <
typename Scalar>
95 const ConstVectorRef &u,
97 CartesianProduct
const space = get_product_space();
98 Data &d = data_cast(data);
99 auto xs =
space.split(x);
100 ConstVectorRef u1 = u.head(
c1_->nu);
101 ConstVectorRef u2 = u.tail(
c2_->nu);
106 c1_->computeHessians(xs[0], u1, d1);
107 c2_->computeHessians(xs[1], u2, d2);
109 d.Lxx_.topLeftCorner(
c1_->ndx(),
c1_->ndx()) = d1.
Lxx_;
110 d.Lxx_.bottomRightCorner(
c2_->ndx(),
c2_->ndx()) = d2.
Lxx_;
112 d.Luu_.topLeftCorner(
c1_->nu,
c1_->nu) = d1.
Luu_;
113 d.Luu_.bottomRightCorner(
c2_->nu,
c2_->nu) = d2.
Luu_;
115 d.Lxu_.topLeftCorner(
c1_->ndx(),
c1_->nu) = d1.
Lxu_;
116 d.Lxu_.bottomRightCorner(
c2_->ndx(),
c2_->nu) = d2.
Lxu_;
118 d.Lux_ = d.Lxu_.transpose();
121template <
typename Scalar>
123 return std::make_shared<Data>(*
this);
126template <
typename Scalar>
134#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
135#include "./cost-direct-sum.txx"
bool valueless_after_move() const noexcept
auto directSum(xyz::polymorphic< CostAbstractTpl< Scalar > > const &c1, xyz::polymorphic< CostAbstractTpl< Scalar > > const &c2)
The cartesian product of two or more manifolds.
Stage costs for control problems.
xyz::polymorphic< Manifold > space
CostAbstractTpl(U &&space, const int nu)
Data struct for CostAbstractTpl.
shared_ptr< BaseData > data2_
void computeGradients(const ConstVectorRef &x, const ConstVectorRef &u, BaseData &data) const override
Compute the cost gradients .
xyz::polymorphic< BaseCost > PolyCost
xyz::polymorphic< BaseCost > c1_
shared_ptr< BaseData > data1_
shared_ptr< BaseData > createData() const override
void evaluate(const ConstVectorRef &x, const ConstVectorRef &u, BaseData &data) const override
Evaluate the cost function.
void computeHessians(const ConstVectorRef &x, const ConstVectorRef &u, BaseData &data) const override
Compute the cost Hessians .
ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
DirectSumCostTpl(const PolyCost &c1, const PolyCost &c2)
CostAbstractTpl< Scalar > BaseCost
Data(const DirectSumCostTpl &model)
xyz::polymorphic< BaseCost > c2_
ManifoldAbstractTpl< Scalar > Manifold
CostDataAbstractTpl< Scalar > BaseData
Base class for manifolds, to use in cost funcs, solvers...