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