| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////// | ||
| 2 | // BSD 3-Clause License | ||
| 3 | // | ||
| 4 | // Copyright (C) 2019-2025, LAAS-CNRS, University of Edinburgh, | ||
| 5 | // Heriot-Watt University | ||
| 6 | // Copyright note valid unless otherwise stated in individual files. | ||
| 7 | // All rights reserved. | ||
| 8 | /////////////////////////////////////////////////////////////////////////////// | ||
| 9 | |||
| 10 | namespace crocoddyl { | ||
| 11 | |||
| 12 | template <typename Scalar> | ||
| 13 | ✗ | CostModelAbstractTpl<Scalar>::CostModelAbstractTpl( | |
| 14 | std::shared_ptr<StateAbstract> state, | ||
| 15 | std::shared_ptr<ActivationModelAbstract> activation, | ||
| 16 | std::shared_ptr<ResidualModelAbstract> residual) | ||
| 17 | ✗ | : state_(state), | |
| 18 | ✗ | activation_(activation), | |
| 19 | ✗ | residual_(residual), | |
| 20 | ✗ | nu_(residual->get_nu()), | |
| 21 | ✗ | unone_(VectorXs::Zero(residual->get_nu())) { | |
| 22 | ✗ | if (activation_->get_nr() != residual_->get_nr()) { | |
| 23 | ✗ | throw_pretty("Invalid argument: " | |
| 24 | << "nr is equals to " + std::to_string(residual_->get_nr())); | ||
| 25 | } | ||
| 26 | ✗ | } | |
| 27 | |||
| 28 | template <typename Scalar> | ||
| 29 | ✗ | CostModelAbstractTpl<Scalar>::CostModelAbstractTpl( | |
| 30 | std::shared_ptr<StateAbstract> state, | ||
| 31 | std::shared_ptr<ActivationModelAbstract> activation, const std::size_t nu) | ||
| 32 | ✗ | : state_(state), | |
| 33 | ✗ | activation_(activation), | |
| 34 | ✗ | residual_(std::make_shared<ResidualModelAbstractTpl<Scalar>>( | |
| 35 | ✗ | state, activation->get_nr(), nu)), | |
| 36 | ✗ | nu_(nu), | |
| 37 | ✗ | unone_(VectorXs::Zero(nu)) {} | |
| 38 | |||
| 39 | template <typename Scalar> | ||
| 40 | ✗ | CostModelAbstractTpl<Scalar>::CostModelAbstractTpl( | |
| 41 | std::shared_ptr<StateAbstract> state, | ||
| 42 | std::shared_ptr<ActivationModelAbstract> activation) | ||
| 43 | ✗ | : state_(state), | |
| 44 | ✗ | activation_(activation), | |
| 45 | ✗ | residual_(std::make_shared<ResidualModelAbstractTpl<Scalar>>( | |
| 46 | ✗ | state, activation->get_nr())), | |
| 47 | ✗ | nu_(state->get_nv()), | |
| 48 | ✗ | unone_(VectorXs::Zero(state->get_nv())) {} | |
| 49 | |||
| 50 | template <typename Scalar> | ||
| 51 | ✗ | CostModelAbstractTpl<Scalar>::CostModelAbstractTpl( | |
| 52 | std::shared_ptr<StateAbstract> state, | ||
| 53 | std::shared_ptr<ResidualModelAbstract> residual) | ||
| 54 | ✗ | : state_(state), | |
| 55 | ✗ | activation_( | |
| 56 | ✗ | std::make_shared<ActivationModelQuadTpl<Scalar>>(residual->get_nr())), | |
| 57 | ✗ | residual_(residual), | |
| 58 | ✗ | nu_(residual->get_nu()), | |
| 59 | ✗ | unone_(VectorXs::Zero(residual->get_nu())) {} | |
| 60 | |||
| 61 | template <typename Scalar> | ||
| 62 | ✗ | CostModelAbstractTpl<Scalar>::CostModelAbstractTpl( | |
| 63 | std::shared_ptr<StateAbstract> state, const std::size_t nr, | ||
| 64 | const std::size_t nu) | ||
| 65 | ✗ | : state_(state), | |
| 66 | ✗ | activation_(std::make_shared<ActivationModelQuadTpl<Scalar>>(nr)), | |
| 67 | ✗ | residual_(std::make_shared<ResidualModelAbstract>(state, nr, nu)), | |
| 68 | ✗ | nu_(nu), | |
| 69 | ✗ | unone_(VectorXs::Zero(nu)) {} | |
| 70 | |||
| 71 | template <typename Scalar> | ||
| 72 | ✗ | CostModelAbstractTpl<Scalar>::CostModelAbstractTpl( | |
| 73 | std::shared_ptr<StateAbstract> state, const std::size_t nr) | ||
| 74 | ✗ | : state_(state), | |
| 75 | ✗ | activation_(std::make_shared<ActivationModelQuadTpl<Scalar>>(nr)), | |
| 76 | ✗ | residual_(std::make_shared<ResidualModelAbstract>(state, nr)), | |
| 77 | ✗ | nu_(state->get_nv()), | |
| 78 | ✗ | unone_(VectorXs::Zero(state->get_nv())) {} | |
| 79 | |||
| 80 | template <typename Scalar> | ||
| 81 | ✗ | void CostModelAbstractTpl<Scalar>::calc( | |
| 82 | const std::shared_ptr<CostDataAbstract>& data, | ||
| 83 | const Eigen::Ref<const VectorXs>& x) { | ||
| 84 | ✗ | calc(data, x, unone_); | |
| 85 | ✗ | } | |
| 86 | |||
| 87 | template <typename Scalar> | ||
| 88 | ✗ | void CostModelAbstractTpl<Scalar>::calcDiff( | |
| 89 | const std::shared_ptr<CostDataAbstract>& data, | ||
| 90 | const Eigen::Ref<const VectorXs>& x) { | ||
| 91 | ✗ | calcDiff(data, x, unone_); | |
| 92 | ✗ | } | |
| 93 | |||
| 94 | template <typename Scalar> | ||
| 95 | std::shared_ptr<CostDataAbstractTpl<Scalar>> | ||
| 96 | ✗ | CostModelAbstractTpl<Scalar>::createData(DataCollectorAbstract* const data) { | |
| 97 | return std::allocate_shared<CostDataAbstract>( | ||
| 98 | ✗ | Eigen::aligned_allocator<CostDataAbstract>(), this, data); | |
| 99 | } | ||
| 100 | |||
| 101 | template <typename Scalar> | ||
| 102 | ✗ | void CostModelAbstractTpl<Scalar>::print(std::ostream& os) const { | |
| 103 | ✗ | os << boost::core::demangle(typeid(*this).name()); | |
| 104 | ✗ | } | |
| 105 | |||
| 106 | template <typename Scalar> | ||
| 107 | const std::shared_ptr<StateAbstractTpl<Scalar>>& | ||
| 108 | ✗ | CostModelAbstractTpl<Scalar>::get_state() const { | |
| 109 | ✗ | return state_; | |
| 110 | } | ||
| 111 | |||
| 112 | template <typename Scalar> | ||
| 113 | const std::shared_ptr<ActivationModelAbstractTpl<Scalar>>& | ||
| 114 | ✗ | CostModelAbstractTpl<Scalar>::get_activation() const { | |
| 115 | ✗ | return activation_; | |
| 116 | } | ||
| 117 | |||
| 118 | template <typename Scalar> | ||
| 119 | const std::shared_ptr<ResidualModelAbstractTpl<Scalar>>& | ||
| 120 | ✗ | CostModelAbstractTpl<Scalar>::get_residual() const { | |
| 121 | ✗ | return residual_; | |
| 122 | } | ||
| 123 | |||
| 124 | template <typename Scalar> | ||
| 125 | ✗ | std::size_t CostModelAbstractTpl<Scalar>::get_nu() const { | |
| 126 | ✗ | return nu_; | |
| 127 | } | ||
| 128 | |||
| 129 | template <typename Scalar> | ||
| 130 | template <class ReferenceType> | ||
| 131 | void CostModelAbstractTpl<Scalar>::set_reference(ReferenceType ref) { | ||
| 132 | set_referenceImpl(typeid(ref), &ref); | ||
| 133 | } | ||
| 134 | |||
| 135 | template <typename Scalar> | ||
| 136 | ✗ | void CostModelAbstractTpl<Scalar>::set_referenceImpl(const std::type_info&, | |
| 137 | const void*) { | ||
| 138 | ✗ | throw_pretty("It has not been implemented the set_referenceImpl() function"); | |
| 139 | } | ||
| 140 | |||
| 141 | template <typename Scalar> | ||
| 142 | template <class ReferenceType> | ||
| 143 | ReferenceType CostModelAbstractTpl<Scalar>::get_reference() { | ||
| 144 | #pragma GCC diagnostic push // TODO: Remove once the deprecated FrameXX has | ||
| 145 | // been removed in a future release | ||
| 146 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | ||
| 147 | ReferenceType ref; | ||
| 148 | get_referenceImpl(typeid(ref), &ref); | ||
| 149 | return ref; | ||
| 150 | #pragma GCC diagnostic pop | ||
| 151 | } | ||
| 152 | |||
| 153 | template <typename Scalar> | ||
| 154 | ✗ | void CostModelAbstractTpl<Scalar>::get_referenceImpl(const std::type_info&, | |
| 155 | void*) { | ||
| 156 | ✗ | throw_pretty("It has not been implemented the set_referenceImpl() function"); | |
| 157 | } | ||
| 158 | |||
| 159 | template <class Scalar> | ||
| 160 | ✗ | std::ostream& operator<<(std::ostream& os, | |
| 161 | const CostModelAbstractTpl<Scalar>& model) { | ||
| 162 | ✗ | model.print(os); | |
| 163 | ✗ | return os; | |
| 164 | } | ||
| 165 | |||
| 166 | } // namespace crocoddyl | ||
| 167 |