6#include <proxsuite-nlp/modelling/spaces/cartesian-product.hpp>
22 assert(!c1.valueless_after_move() && !c2.valueless_after_move());
27 shared_ptr<BaseData>
createData()
const override;
29 void evaluate(
const ConstVectorRef &x,
const ConstVectorRef &u,
37 using CartesianProduct = proxsuite::nlp::CartesianProductTpl<Scalar>;
38 auto get_product_space()
const {
39 return dynamic_cast<CartesianProduct
const &
>(*this->
space);
41 static Data &data_cast(
BaseData &data) {
return static_cast<Data &
>(data); }
52template <
typename Scalar>
54 const ConstVectorRef &u,
56 CartesianProduct
const space = get_product_space();
57 Data &d = data_cast(data);
58 auto xs = space.split(x);
59 ConstVectorRef u1 = u.head(c1_->nu);
60 ConstVectorRef u2 = u.tail(c2_->nu);
62 c1_->evaluate(xs[0], u1, *d.
data1_);
63 c2_->evaluate(xs[1], u2, *d.
data2_);
68template <
typename Scalar>
70 const ConstVectorRef &u,
72 CartesianProduct
const space = get_product_space();
73 Data &d = data_cast(data);
74 auto xs = space.split(x);
75 ConstVectorRef u1 = u.head(c1_->nu);
76 ConstVectorRef u2 = u.tail(c2_->nu);
81 c1_->computeGradients(xs[0], u1, d1);
82 c2_->computeGradients(xs[1], u2, d2);
84 d.
Lx_.head(c1_->ndx()) = d1.
Lx_;
85 d.
Lx_.tail(c2_->ndx()) = d2.
Lx_;
86 d.
Lu_.head(c1_->nu) = d1.
Lu_;
87 d.
Lu_.tail(c2_->nu) = d2.
Lu_;
90template <
typename Scalar>
92 const ConstVectorRef &u,
94 CartesianProduct
const space = get_product_space();
95 Data &d = data_cast(data);
96 auto xs = space.split(x);
97 ConstVectorRef u1 = u.head(c1_->nu);
98 ConstVectorRef u2 = u.tail(c2_->nu);
103 c1_->computeHessians(xs[0], u1, d1);
104 c2_->computeHessians(xs[1], u2, d2);
106 d.
Lxx_.topLeftCorner(c1_->ndx(), c1_->ndx()) = d1.
Lxx_;
107 d.
Lxx_.bottomRightCorner(c2_->ndx(), c2_->ndx()) = d2.
Lxx_;
109 d.
Luu_.topLeftCorner(c1_->nu, c1_->nu) = d1.
Luu_;
110 d.
Luu_.bottomRightCorner(c2_->nu, c2_->nu) = d2.
Luu_;
112 d.
Lxu_.topLeftCorner(c1_->ndx(), c1_->nu) = d1.
Lxu_;
113 d.
Lxu_.bottomRightCorner(c2_->ndx(), c2_->nu) = d2.
Lxu_;
118template <
typename Scalar>
120 return std::make_shared<Data>(*
this);
123template <
typename Scalar>
131#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
132#include "./cost-direct-sum.txx"
auto directSum(xyz::polymorphic< CostAbstractTpl< Scalar > > const &c1, xyz::polymorphic< CostAbstractTpl< Scalar > > const &c2)
Stage costs for control problems.
xyz::polymorphic< Manifold > space
Data struct for CostAbstractTpl.
shared_ptr< BaseData > data1_
shared_ptr< BaseData > data2_
Data(const DirectSumCostTpl &model)
void computeGradients(const ConstVectorRef &x, const ConstVectorRef &u, BaseData &data) const override
xyz::polymorphic< BaseCost > PolyCost
xyz::polymorphic< BaseCost > c1_
shared_ptr< BaseData > createData() const override
void evaluate(const ConstVectorRef &x, const ConstVectorRef &u, BaseData &data) const override
void computeHessians(const ConstVectorRef &x, const ConstVectorRef &u, BaseData &data) const override
ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
DirectSumCostTpl(const PolyCost &c1, const PolyCost &c2)
xyz::polymorphic< BaseCost > c2_
ManifoldAbstractTpl< Scalar > Manifold
CostDataAbstractTpl< Scalar > BaseData