9 #ifndef CROCODDYL_CORE_COST_BASE_HPP_
10 #define CROCODDYL_CORE_COST_BASE_HPP_
12 #include <boost/make_shared.hpp>
13 #include <boost/shared_ptr.hpp>
15 #include "crocoddyl/core/activation-base.hpp"
16 #include "crocoddyl/core/activations/quadratic.hpp"
17 #include "crocoddyl/core/data-collector-base.hpp"
18 #include "crocoddyl/core/fwd.hpp"
19 #include "crocoddyl/core/residual-base.hpp"
20 #include "crocoddyl/core/state-base.hpp"
21 #include "crocoddyl/core/utils/deprecate.hpp"
58 template <
typename _Scalar>
61 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
63 typedef _Scalar Scalar;
71 typedef typename MathBase::VectorXs VectorXs;
72 typedef typename MathBase::MatrixXs MatrixXs;
82 boost::shared_ptr<ActivationModelAbstract> activation,
83 boost::shared_ptr<ResidualModelAbstract> residual);
93 boost::shared_ptr<ActivationModelAbstract> activation,
94 const std::size_t nu);
105 boost::shared_ptr<ActivationModelAbstract> activation);
117 boost::shared_ptr<ResidualModelAbstract> residual);
130 const std::size_t nr,
const std::size_t nu);
144 const std::size_t nr);
154 virtual void calc(
const boost::shared_ptr<CostDataAbstract>& data,
155 const Eigen::Ref<const VectorXs>& x,
156 const Eigen::Ref<const VectorXs>& u) = 0;
168 virtual void calc(
const boost::shared_ptr<CostDataAbstract>& data,
169 const Eigen::Ref<const VectorXs>& x);
181 virtual void calcDiff(
const boost::shared_ptr<CostDataAbstract>& data,
182 const Eigen::Ref<const VectorXs>& x,
183 const Eigen::Ref<const VectorXs>& u) = 0;
196 virtual void calcDiff(
const boost::shared_ptr<CostDataAbstract>& data,
197 const Eigen::Ref<const VectorXs>& x);
216 const boost::shared_ptr<StateAbstract>&
get_state()
const;
236 template <
class Scalar>
243 template <
class ReferenceType>
249 template <
class ReferenceType>
257 virtual void print(std::ostream& os)
const;
277 template <
typename _Scalar>
279 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
281 typedef _Scalar Scalar;
286 typedef typename MathBase::VectorXs VectorXs;
287 typedef typename MathBase::MatrixXs MatrixXs;
289 template <
template <
typename Scalar>
class Model>
293 activation(model->get_activation()->createData()),
294 residual(model->get_residual()->createData(data)),
296 Lx(model->get_state()->get_ndx()),
298 Lxx(model->get_state()->get_ndx(), model->get_state()->get_ndx()),
299 Lxu(model->get_state()->get_ndx(), model->get_nu()),
300 Luu(model->get_nu(), model->get_nu()) {
310 "Use residual.r",
const VectorXs& get_r()
const {
return residual->r; };)
313 const MatrixXs& get_Rx()
const {
return residual->Rx; };)
316 const MatrixXs& get_Ru()
const {
return residual->Ru; };)
318 "Use residual.r",
void set_r(
const VectorXs& r) { residual->r = r; };)
321 void set_Rx(
const MatrixXs& Rx) { residual->Rx = Rx; };)
324 void set_Ru(
const MatrixXs& Ru) { residual->Ru = Ru; };)
327 boost::shared_ptr<ActivationDataAbstract> activation;
328 boost::shared_ptr<ResidualDataAbstract> residual;
342 #include "crocoddyl/core/cost-base.hxx"
Abstract class for cost models.
CostModelAbstractTpl(boost::shared_ptr< StateAbstract > state, const std::size_t nr, const std::size_t nu)
Initialize the cost model.
virtual boost::shared_ptr< CostDataAbstract > createData(DataCollectorAbstract *const data)
Create the cost data.
CostModelAbstractTpl(boost::shared_ptr< StateAbstract > state, boost::shared_ptr< ActivationModelAbstract > activation, boost::shared_ptr< ResidualModelAbstract > residual)
Initialize the cost model.
const boost::shared_ptr< StateAbstract > & get_state() const
Return the state.
CostModelAbstractTpl(boost::shared_ptr< StateAbstract > state, boost::shared_ptr< ActivationModelAbstract > activation)
Initialize the cost model.
virtual void set_referenceImpl(const std::type_info &, const void *)
Modify the cost reference.
void set_reference(ReferenceType ref)
Modify the cost reference.
virtual void calcDiff(const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the Jacobian and Hessian of the cost functions with respect to the state only.
virtual void print(std::ostream &os) const
Print relevant information of the cost model.
friend std::ostream & operator<<(std::ostream &os, const CostModelAbstractTpl< Scalar > &model)
Print information on the cost model.
const boost::shared_ptr< ActivationModelAbstract > & get_activation() const
Return the activation model.
boost::shared_ptr< ActivationModelAbstract > activation_
Activation model.
virtual void calc(const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0
Compute the cost value and its residual vector.
virtual void get_referenceImpl(const std::type_info &, void *)
Return the cost reference.
boost::shared_ptr< StateAbstract > state_
State description.
std::size_t nu_
Control dimension.
VectorXs unone_
No control vector.
CostModelAbstractTpl(boost::shared_ptr< StateAbstract > state, boost::shared_ptr< ActivationModelAbstract > activation, const std::size_t nu)
Initialize the cost model.
CostModelAbstractTpl(boost::shared_ptr< StateAbstract > state, const std::size_t nr)
Initialize the cost model.
virtual void calcDiff(const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0
Compute the Jacobian and Hessian of cost and its residual vector.
ReferenceType get_reference()
Return the cost reference.
boost::shared_ptr< ResidualModelAbstract > residual_
Residual model.
virtual void calc(const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the total cost value for nodes that depends only on the state.
std::size_t get_nu() const
Return the dimension of the control input.
CostModelAbstractTpl(boost::shared_ptr< StateAbstract > state, boost::shared_ptr< ResidualModelAbstract > residual)
Initialize the cost model.
const boost::shared_ptr< ResidualModelAbstract > & get_residual() const
Return the residual model.
Abstract class for residual models.
Abstract class for the state representation.