25  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
 
   27  typedef _Scalar Scalar;
 
   29  typedef typename MathBase::VectorXs VectorXs;
 
   30  typedef typename MathBase::MatrixXs MatrixXs;
 
   33                      const Scalar b = (Scalar)1.)
 
   34      : lb(lower), ub(upper), beta(b) {
 
   35    if (lb.size() != ub.size()) {
 
   36      throw_pretty(
"Invalid argument: " 
   37                   << 
"The lower and upper bounds don't have the same " 
   38                      "dimension (lb,ub dimensions equal to " +
 
   39                          std::to_string(lb.size()) + 
"," +
 
   40                          std::to_string(ub.size()) + 
", respectively)");
 
   42    if (beta < Scalar(0) || beta > Scalar(1.)) {
 
   44          "Invalid argument: " << 
"The range of beta is between 0 and 1");
 
   47    for (std::size_t i = 0; i < static_cast<std::size_t>(lb.size()); ++i) {
 
   48      if (isfinite(lb(i)) && isfinite(ub(i))) {
 
   49        if (lb(i) - ub(i) > 0) {
 
   50          throw_pretty(
"Invalid argument: " 
   51                       << 
"The lower and upper bounds are badly defined; ub " 
   52                          "has to be bigger / equals to lb");
 
   56      if (!isfinite(lb(i))) {
 
   57        lb(i) = -std::numeric_limits<Scalar>::max();
 
   59      if (!isfinite(ub(i))) {
 
   60        ub(i) = std::numeric_limits<Scalar>::max();
 
   64    if (beta >= Scalar(0) && beta <= Scalar(1.)) {
 
   65      for (std::size_t i = 0; i < static_cast<std::size_t>(lb.size()); ++i) {
 
   67        if (lb(i) != (-std::numeric_limits<Scalar>::max()) &&
 
   68            ub(i) != (std::numeric_limits<Scalar>::max())) {
 
   69          Scalar m = Scalar(0.5) * (lb(i) + ub(i));
 
   70          Scalar d = Scalar(0.5) * (ub(i) - lb(i));
 
   80      : lb(other.lb), ub(other.ub), beta(other.beta) {}
 
 
  101  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
 
  103  typedef _Scalar Scalar;
 
  109  typedef typename MathBase::VectorXs VectorXs;
 
  110  typedef typename MathBase::MatrixXs MatrixXs;
 
  113      : 
Base(bounds.lb.size()), bounds_(bounds) {};
 
  116  virtual void calc(
const std::shared_ptr<ActivationDataAbstract>& data,
 
  117                    const Eigen::Ref<const VectorXs>& r) {
 
  118    if (
static_cast<std::size_t
>(r.size()) != nr_) {
 
  120          "Invalid argument: " << 
"r has wrong dimension (it should be " +
 
  121                                      std::to_string(nr_) + 
")");
 
  124    std::shared_ptr<Data> d = std::static_pointer_cast<Data>(data);
 
  126    d->rlb_min_ = (r - bounds_.lb).array().min(Scalar(0.));
 
  127    d->rub_max_ = (r - bounds_.ub).array().max(Scalar(0.));
 
  128    data->a_value = Scalar(0.5) * d->rlb_min_.matrix().squaredNorm() +
 
  129                    Scalar(0.5) * d->rub_max_.matrix().squaredNorm();
 
  132  virtual void calcDiff(
const std::shared_ptr<ActivationDataAbstract>& data,
 
  133                        const Eigen::Ref<const VectorXs>& r) {
 
  134    if (
static_cast<std::size_t
>(r.size()) != nr_) {
 
  136          "Invalid argument: " << 
"r has wrong dimension (it should be " +
 
  137                                      std::to_string(nr_) + 
")");
 
  140    std::shared_ptr<Data> d = std::static_pointer_cast<Data>(data);
 
  141    data->Ar = (d->rlb_min_ + d->rub_max_).matrix();
 
  143    using pinocchio::internal::if_then_else;
 
  144    for (Eigen::Index i = 0; i < data->Arr.cols(); i++) {
 
  145      data->Arr.diagonal()[i] = if_then_else(
 
  146          pinocchio::internal::LE, r[i] - bounds_.lb[i], Scalar(0.), Scalar(1.),
 
  147          if_then_else(pinocchio::internal::GE, r[i] - bounds_.ub[i],
 
  148                       Scalar(0.), Scalar(1.), Scalar(0.)));
 
  152  virtual std::shared_ptr<ActivationDataAbstract> createData() {
 
  153    return std::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), 
this);
 
  164  virtual void print(std::ostream& os)
 const {
 
  165    os << 
"ActivationModelQuadraticBarrier {nr=" << nr_ << 
"}";