26 const std::vector<Scalar> &weights)
33 auto clone()
const {
return std::make_shared<CostSumTpl>(*
this); }
79 weight = rhs * weight;
88 ostr <<
"CostSum(num_components=" << nc;
89 ostr <<
", weights=(";
90 for (std::size_t i = 0; i < nc; i++) {
101 Scalar a) -> shared_ptr<CostSumTpl> {
102 auto out = self.clone();
110 return self *
static_cast<Scalar>(-1.);
117#include "proxsuite-nlp/cost-sum.hxx"
119#ifdef PROXSUITE_NLP_ENABLE_TEMPLATE_INSTANTIATION
120#include "proxsuite-nlp/cost-sum.txx"
#define PROXSUITE_NLP_DYNAMIC_TYPEDEFS(Scalar)
Base class for differentiable cost functions.
Defines the sum of one or more cost functions .
friend auto operator-(CostSumTpl const &self)
CostSumTpl< Scalar > & operator+=(const shared_ptr< Base > &other)
friend auto operator*(CostSumTpl const &self, Scalar a) -> shared_ptr< CostSumTpl >
CostSumTpl< Scalar > & operator+=(const CostSumTpl< Scalar > &other)
void computeHessian(const ConstVectorRef &x, MatrixRef out) const
friend auto operator*(Scalar a, CostSumTpl const &self)
std::vector< BasePtr > components_
Scalar call(const ConstVectorRef &x) const
Evaluate the cost function.
CostSumTpl< Scalar > & operator*=(Scalar rhs)
void computeGradient(const ConstVectorRef &x, VectorRef out) const
shared_ptr< Base > BasePtr
CostSumTpl(int nx, int ndx)
cost component weights
void addComponent(shared_ptr< Base > comp, const Scalar w=1.)
std::vector< Scalar > weights_
component sub-costs
CostSumTpl(int nx, int ndx, const std::vector< BasePtr > &comps, const std::vector< Scalar > &weights)
Constructor with a predefined vector of components.
friend std::ostream & operator<<(std::ostream &ostr, const CostSumTpl< Scalar > &cost)
std::size_t numComponents() const