9 #ifndef CROCODDYL_CORE_ACTIVATIONS_WEIGHTED_QUADRATIC_BARRIER_HPP_
10 #define CROCODDYL_CORE_ACTIVATIONS_WEIGHTED_QUADRATIC_BARRIER_HPP_
12 #include <pinocchio/utils/static-if.hpp>
14 #include "crocoddyl/core/activations/quadratic-barrier.hpp"
15 #include "crocoddyl/core/fwd.hpp"
16 #include "crocoddyl/core/utils/exception.hpp"
20 template <
typename _Scalar>
24 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
26 typedef _Scalar Scalar;
32 typedef typename MathBase::VectorXs VectorXs;
33 typedef typename MathBase::MatrixXs MatrixXs;
37 :
Base(bounds.lb.size()), bounds_(bounds), weights_(weights) {};
40 virtual void calc(
const boost::shared_ptr<ActivationDataAbstract>& data,
41 const Eigen::Ref<const VectorXs>& r) {
42 if (
static_cast<std::size_t
>(r.size()) != nr_) {
43 throw_pretty(
"Invalid argument: "
44 <<
"r has wrong dimension (it should be " +
45 std::to_string(nr_) +
")");
47 boost::shared_ptr<Data> d = boost::static_pointer_cast<Data>(data);
49 d->rlb_min_ = (r - bounds_.lb).array().min(Scalar(0.));
50 d->rub_max_ = (r - bounds_.ub).array().max(Scalar(0.));
51 d->rlb_min_.array() *= weights_.array();
52 d->rub_max_.array() *= weights_.array();
53 data->a_value = Scalar(0.5) * d->rlb_min_.matrix().squaredNorm() +
54 Scalar(0.5) * d->rub_max_.matrix().squaredNorm();
57 virtual void calcDiff(
const boost::shared_ptr<ActivationDataAbstract>& data,
58 const Eigen::Ref<const VectorXs>& r) {
59 if (
static_cast<std::size_t
>(r.size()) != nr_) {
60 throw_pretty(
"Invalid argument: "
61 <<
"r has wrong dimension (it should be " +
62 std::to_string(nr_) +
")");
64 boost::shared_ptr<Data> d = boost::static_pointer_cast<Data>(data);
65 data->Ar = (d->rlb_min_ + d->rub_max_).matrix();
66 data->Ar.array() *= weights_.array();
68 using pinocchio::internal::if_then_else;
69 for (Eigen::Index i = 0; i < data->Arr.cols(); i++) {
70 data->Arr.diagonal()[i] = if_then_else(
71 pinocchio::internal::LE, r[i] - bounds_.lb[i], Scalar(0.), Scalar(1.),
72 if_then_else(pinocchio::internal::GE, r[i] - bounds_.ub[i],
73 Scalar(0.), Scalar(1.), Scalar(0.)));
76 data->Arr.diagonal().array() *= weights_.array();
79 virtual boost::shared_ptr<ActivationDataAbstract> createData() {
80 return boost::allocate_shared<Data>(Eigen::aligned_allocator<Data>(),
this);
84 const VectorXs& get_weights()
const {
return weights_; };
86 void set_weights(
const VectorXs& weights) {
87 if (weights.size() != weights_.size()) {
88 throw_pretty(
"Invalid argument: "
89 <<
"weight vector has wrong dimension (it should be " +
90 std::to_string(weights_.size()) +
")");
100 virtual void print(std::ostream& os)
const {
101 os <<
"ActivationModelWeightedQuadraticBarrier {nr=" << nr_ <<
"}";
virtual void print(std::ostream &os) const
Print relevant information of the quadratic barrier model.