Directory: | ./ |
---|---|
File: | include/crocoddyl/core/constraints/constraint-manager.hpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 77 | 110 | 70.0% |
Branches: | 71 | 278 | 25.5% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2020-2024, University of Edinburgh, Heriot-Watt University | ||
5 | // Copyright note valid unless otherwise stated in individual files. | ||
6 | // All rights reserved. | ||
7 | /////////////////////////////////////////////////////////////////////////////// | ||
8 | |||
9 | #ifndef CROCODDYL_CORE_CONSTRAINTS_CONSTRAINT_MANAGER_HPP_ | ||
10 | #define CROCODDYL_CORE_CONSTRAINTS_CONSTRAINT_MANAGER_HPP_ | ||
11 | |||
12 | #include <map> | ||
13 | #include <set> | ||
14 | #include <string> | ||
15 | #include <utility> | ||
16 | |||
17 | #include "crocoddyl/core/constraint-base.hpp" | ||
18 | #include "crocoddyl/core/utils/exception.hpp" | ||
19 | |||
20 | namespace crocoddyl { | ||
21 | |||
22 | template <typename _Scalar> | ||
23 | struct ConstraintItemTpl { | ||
24 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW | ||
25 | |||
26 | typedef _Scalar Scalar; | ||
27 | typedef ConstraintModelAbstractTpl<Scalar> ConstraintModelAbstract; | ||
28 | |||
29 | ConstraintItemTpl() {} | ||
30 | 2453 | ConstraintItemTpl(const std::string& name, | |
31 | boost::shared_ptr<ConstraintModelAbstract> constraint, | ||
32 | bool active = true) | ||
33 | 2453 | : name(name), constraint(constraint), active(active) {} | |
34 | |||
35 | /** | ||
36 | * @brief Print information on the constraint item | ||
37 | */ | ||
38 | ✗ | friend std::ostream& operator<<(std::ostream& os, | |
39 | const ConstraintItemTpl<Scalar>& model) { | ||
40 | ✗ | os << "{" << *model.constraint << "}"; | |
41 | ✗ | return os; | |
42 | } | ||
43 | |||
44 | std::string name; | ||
45 | boost::shared_ptr<ConstraintModelAbstract> constraint; | ||
46 | bool active; | ||
47 | }; | ||
48 | |||
49 | /** | ||
50 | * @brief Manage the individual constraint models | ||
51 | * | ||
52 | * This class serves to manage a set of added constraint models. The constraint | ||
53 | * functions might active or inactive, with this approach we avoid dynamic | ||
54 | * allocation of memory. Each constraint model is added through `addConstraint`, | ||
55 | * where its status can be defined. | ||
56 | * | ||
57 | * The main computations are carring out in `calc` and `calcDiff` routines. | ||
58 | * `calc` computes the constraint residuals and `calcDiff` computes the | ||
59 | * Jacobians of the constraint functions. Concretely speaking, `calcDiff` builds | ||
60 | * a linear approximation of the total constraint function (both inequality and | ||
61 | * equality) with the form: \f$\mathbf{g_u}\in\mathbb{R}^{ng\times nu}\f$, | ||
62 | * \f$\mathbf{h_x}\in\mathbb{R}^{nh\times ndx}\f$ | ||
63 | * \f$\mathbf{h_u}\in\mathbb{R}^{nh\times nu}\f$. | ||
64 | * | ||
65 | * \sa `StateAbstractTpl`, `calc()`, `calcDiff()`, `createData()` | ||
66 | */ | ||
67 | template <typename _Scalar> | ||
68 | class ConstraintModelManagerTpl { | ||
69 | public: | ||
70 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW | ||
71 | |||
72 | typedef _Scalar Scalar; | ||
73 | typedef MathBaseTpl<Scalar> MathBase; | ||
74 | typedef ConstraintDataManagerTpl<Scalar> ConstraintDataManager; | ||
75 | typedef StateAbstractTpl<Scalar> StateAbstract; | ||
76 | typedef ConstraintModelAbstractTpl<Scalar> ConstraintModelAbstract; | ||
77 | typedef ConstraintDataAbstractTpl<Scalar> ConstraintDataAbstract; | ||
78 | typedef DataCollectorAbstractTpl<Scalar> DataCollectorAbstract; | ||
79 | typedef ConstraintItemTpl<Scalar> ConstraintItem; | ||
80 | typedef typename MathBase::VectorXs VectorXs; | ||
81 | typedef typename MathBase::MatrixXs MatrixXs; | ||
82 | |||
83 | typedef std::map<std::string, boost::shared_ptr<ConstraintItem> > | ||
84 | ConstraintModelContainer; | ||
85 | typedef std::map<std::string, boost::shared_ptr<ConstraintDataAbstract> > | ||
86 | ConstraintDataContainer; | ||
87 | |||
88 | /** | ||
89 | * @brief Initialize the constraint-manager model | ||
90 | * | ||
91 | * @param[in] state State of the multibody system | ||
92 | * @param[in] nu Dimension of control vector | ||
93 | */ | ||
94 | ConstraintModelManagerTpl(boost::shared_ptr<StateAbstract> state, | ||
95 | const std::size_t nu); | ||
96 | |||
97 | /** | ||
98 | * @brief Initialize the constraint-manager model | ||
99 | * | ||
100 | * The default `nu` value is obtained from `StateAbstractTpl::get_nv()`. | ||
101 | * | ||
102 | * @param[in] state State of the multibody system | ||
103 | */ | ||
104 | explicit ConstraintModelManagerTpl(boost::shared_ptr<StateAbstract> state); | ||
105 | ~ConstraintModelManagerTpl(); | ||
106 | |||
107 | /** | ||
108 | * @brief Add a constraint item | ||
109 | * | ||
110 | * @param[in] name Constraint name | ||
111 | * @param[in] constraint Constraint model | ||
112 | * @param[in] weight Constraint weight | ||
113 | * @param[in] active True if the constraint is activated (default true) | ||
114 | */ | ||
115 | void addConstraint(const std::string& name, | ||
116 | boost::shared_ptr<ConstraintModelAbstract> constraint, | ||
117 | const bool active = true); | ||
118 | |||
119 | /** | ||
120 | * @brief Remove a constraint item | ||
121 | * | ||
122 | * @param[in] name Constraint name | ||
123 | */ | ||
124 | void removeConstraint(const std::string& name); | ||
125 | |||
126 | /** | ||
127 | * @brief Change the constraint status | ||
128 | * | ||
129 | * @param[in] name Constraint name | ||
130 | * @param[in] active Constraint status (true for active and false for | ||
131 | * inactive) | ||
132 | */ | ||
133 | void changeConstraintStatus(const std::string& name, bool active); | ||
134 | |||
135 | /** | ||
136 | * @brief Compute the total constraint value | ||
137 | * | ||
138 | * @param[in] data Constraint data | ||
139 | * @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ | ||
140 | * @param[in] u Control input \f$\mathbf{u}\in\mathbb{R}^{nu}\f$ | ||
141 | */ | ||
142 | void calc(const boost::shared_ptr<ConstraintDataManager>& data, | ||
143 | const Eigen::Ref<const VectorXs>& x, | ||
144 | const Eigen::Ref<const VectorXs>& u); | ||
145 | |||
146 | /** | ||
147 | * @brief Compute the total constraint value for nodes that depends only on | ||
148 | * the state | ||
149 | * | ||
150 | * It updates the constraint based on the state only. This function is | ||
151 | * commonly used in the terminal nodes of an optimal control problem. | ||
152 | * | ||
153 | * @param[in] data Constraint data | ||
154 | * @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ | ||
155 | */ | ||
156 | void calc(const boost::shared_ptr<ConstraintDataManager>& data, | ||
157 | const Eigen::Ref<const VectorXs>& x); | ||
158 | |||
159 | /** | ||
160 | * @brief Compute the Jacobian of the total constraint | ||
161 | * | ||
162 | * @param[in] data Constraint data | ||
163 | * @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ | ||
164 | * @param[in] u Control input \f$\mathbf{u}\in\mathbb{R}^{nu}\f$ | ||
165 | */ | ||
166 | void calcDiff(const boost::shared_ptr<ConstraintDataManager>& data, | ||
167 | const Eigen::Ref<const VectorXs>& x, | ||
168 | const Eigen::Ref<const VectorXs>& u); | ||
169 | |||
170 | /** | ||
171 | * @brief Compute the Jacobian of the total constraint with respect to the | ||
172 | * state only | ||
173 | * | ||
174 | * It computes the Jacobian of the constraint function based on the state | ||
175 | * only. This function is commonly used in the terminal nodes of an optimal | ||
176 | * control problem. | ||
177 | * | ||
178 | * @param[in] data Constraint data | ||
179 | * @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ | ||
180 | */ | ||
181 | void calcDiff(const boost::shared_ptr<ConstraintDataManager>& data, | ||
182 | const Eigen::Ref<const VectorXs>& x); | ||
183 | |||
184 | /** | ||
185 | * @brief Create the constraint data | ||
186 | * | ||
187 | * The default data contains objects to store the values of the constraint and | ||
188 | * their derivatives (i.e. Jacobians). However, it is possible to specialize | ||
189 | * this function is we need to create additional data, for instance, to avoid | ||
190 | * dynamic memory allocation. | ||
191 | * | ||
192 | * @param data Data collector | ||
193 | * @return the constraint data | ||
194 | */ | ||
195 | boost::shared_ptr<ConstraintDataManager> createData( | ||
196 | DataCollectorAbstract* const data); | ||
197 | |||
198 | /** | ||
199 | * @brief Return the state | ||
200 | */ | ||
201 | const boost::shared_ptr<StateAbstract>& get_state() const; | ||
202 | |||
203 | /** | ||
204 | * @brief Return the stack of constraint models | ||
205 | */ | ||
206 | const ConstraintModelContainer& get_constraints() const; | ||
207 | |||
208 | /** | ||
209 | * @brief Return the dimension of the control input | ||
210 | */ | ||
211 | std::size_t get_nu() const; | ||
212 | |||
213 | /** | ||
214 | * @brief Return the number of active inequality constraints | ||
215 | */ | ||
216 | std::size_t get_ng() const; | ||
217 | |||
218 | /** | ||
219 | * @brief Return the number of active equality constraints | ||
220 | */ | ||
221 | std::size_t get_nh() const; | ||
222 | |||
223 | /** | ||
224 | * @brief Return the number of active inequality terminal constraints | ||
225 | */ | ||
226 | std::size_t get_ng_T() const; | ||
227 | |||
228 | /** | ||
229 | * @brief Return the number of active equality terminal constraints | ||
230 | */ | ||
231 | std::size_t get_nh_T() const; | ||
232 | |||
233 | /** | ||
234 | * @brief Return the names of the set of active constraints | ||
235 | */ | ||
236 | const std::set<std::string>& get_active_set() const; | ||
237 | |||
238 | /** | ||
239 | * @brief Return the names of the set of inactive constraints | ||
240 | */ | ||
241 | const std::set<std::string>& get_inactive_set() const; | ||
242 | |||
243 | /** | ||
244 | * @brief Return the state lower bound | ||
245 | */ | ||
246 | const VectorXs& get_lb() const; | ||
247 | |||
248 | /** | ||
249 | * @brief Return the state upper bound | ||
250 | */ | ||
251 | const VectorXs& get_ub() const; | ||
252 | |||
253 | /** | ||
254 | * @brief Return the status of a given constraint name | ||
255 | * | ||
256 | * @param[in] name Constraint name | ||
257 | */ | ||
258 | bool getConstraintStatus(const std::string& name) const; | ||
259 | |||
260 | /** | ||
261 | * @brief Print information on the stack of constraints | ||
262 | */ | ||
263 | template <class Scalar> | ||
264 | friend std::ostream& operator<<( | ||
265 | std::ostream& os, const ConstraintModelManagerTpl<Scalar>& model); | ||
266 | |||
267 | private: | ||
268 | boost::shared_ptr<StateAbstract> state_; //!< State description | ||
269 | ConstraintModelContainer constraints_; //!< Stack of constraint items | ||
270 | VectorXs lb_; //!< Lower bound of the constraint | ||
271 | VectorXs ub_; //!< Upper bound of the constraint | ||
272 | std::size_t nu_; //!< Dimension of the control input | ||
273 | std::size_t ng_; //!< Number of the active inequality constraints | ||
274 | std::size_t nh_; //!< Number of the active equality constraints | ||
275 | std::size_t ng_T_; //!< Number of the active inequality terminal constraints | ||
276 | std::size_t nh_T_; //!< Number of the active equality terminal constraints | ||
277 | std::set<std::string> active_set_; //!< Names of the active constraint items | ||
278 | std::set<std::string> | ||
279 | inactive_set_; //!< Names of the inactive constraint items | ||
280 | }; | ||
281 | |||
282 | template <typename _Scalar> | ||
283 | struct ConstraintDataManagerTpl { | ||
284 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW | ||
285 | |||
286 | typedef _Scalar Scalar; | ||
287 | typedef MathBaseTpl<Scalar> MathBase; | ||
288 | typedef DataCollectorAbstractTpl<Scalar> DataCollectorAbstract; | ||
289 | typedef ConstraintItemTpl<Scalar> ConstraintItem; | ||
290 | typedef typename MathBase::VectorXs VectorXs; | ||
291 | typedef typename MathBase::MatrixXs MatrixXs; | ||
292 | |||
293 | template <template <typename Scalar> class Model> | ||
294 | 50024 | ConstraintDataManagerTpl(Model<Scalar>* const model, | |
295 | DataCollectorAbstract* const data) | ||
296 |
1/2✓ Branch 2 taken 50024 times.
✗ Branch 3 not taken.
|
50024 | : g_internal(model->get_ng()), |
297 |
1/2✓ Branch 5 taken 50024 times.
✗ Branch 6 not taken.
|
50024 | Gx_internal(model->get_ng(), model->get_state()->get_ndx()), |
298 |
1/2✓ Branch 3 taken 50024 times.
✗ Branch 4 not taken.
|
50024 | Gu_internal(model->get_ng(), model->get_nu()), |
299 |
1/2✓ Branch 2 taken 50024 times.
✗ Branch 3 not taken.
|
50024 | h_internal(model->get_nh()), |
300 |
1/2✓ Branch 5 taken 50024 times.
✗ Branch 6 not taken.
|
50024 | Hx_internal(model->get_nh(), model->get_state()->get_ndx()), |
301 |
1/2✓ Branch 3 taken 50024 times.
✗ Branch 4 not taken.
|
50024 | Hu_internal(model->get_nh(), model->get_nu()), |
302 | 50024 | shared(data), | |
303 |
5/9✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 50015 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✓ Branch 6 taken 50015 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9 times.
✗ Branch 9 not taken.
|
50024 | g(g_internal.data(), model->get_ng()), |
304 |
5/9✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 6 taken 50015 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9 times.
✓ Branch 9 taken 50015 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 9 times.
✗ Branch 12 not taken.
|
50024 | Gx(Gx_internal.data(), model->get_ng(), model->get_state()->get_ndx()), |
305 |
5/9✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 50015 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9 times.
✓ Branch 7 taken 50015 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 9 times.
✗ Branch 10 not taken.
|
50024 | Gu(Gu_internal.data(), model->get_ng(), model->get_nu()), |
306 |
5/9✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 50015 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✓ Branch 6 taken 50015 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9 times.
✗ Branch 9 not taken.
|
50024 | h(h_internal.data(), model->get_nh()), |
307 |
5/9✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 6 taken 50015 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9 times.
✓ Branch 9 taken 50015 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 9 times.
✗ Branch 12 not taken.
|
50024 | Hx(Hx_internal.data(), model->get_nh(), model->get_state()->get_ndx()), |
308 |
5/9✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 50015 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 9 times.
✓ Branch 8 taken 50015 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 9 times.
✗ Branch 11 not taken.
|
100048 | Hu(Hu_internal.data(), model->get_nh(), model->get_nu()) { |
309 |
1/2✓ Branch 1 taken 50024 times.
✗ Branch 2 not taken.
|
50024 | g.setZero(); |
310 |
1/2✓ Branch 1 taken 50024 times.
✗ Branch 2 not taken.
|
50024 | Gx.setZero(); |
311 |
1/2✓ Branch 1 taken 50024 times.
✗ Branch 2 not taken.
|
50024 | Gu.setZero(); |
312 |
1/2✓ Branch 1 taken 50024 times.
✗ Branch 2 not taken.
|
50024 | h.setZero(); |
313 |
1/2✓ Branch 1 taken 50024 times.
✗ Branch 2 not taken.
|
50024 | Hx.setZero(); |
314 |
1/2✓ Branch 1 taken 50024 times.
✗ Branch 2 not taken.
|
50024 | Hu.setZero(); |
315 | 50024 | for (typename ConstraintModelManagerTpl< | |
316 | Scalar>::ConstraintModelContainer::const_iterator it = | ||
317 | 50024 | model->get_constraints().begin(); | |
318 |
2/2✓ Branch 3 taken 220648 times.
✓ Branch 4 taken 50024 times.
|
270672 | it != model->get_constraints().end(); ++it) { |
319 | 220648 | const boost::shared_ptr<ConstraintItem>& item = it->second; | |
320 |
1/2✓ Branch 1 taken 220648 times.
✗ Branch 2 not taken.
|
220648 | constraints.insert( |
321 |
2/4✓ Branch 3 taken 220648 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 220648 times.
✗ Branch 8 not taken.
|
220648 | std::make_pair(item->name, item->constraint->createData(data))); |
322 | } | ||
323 | 50024 | } | |
324 | |||
325 | template <class ActionData> | ||
326 | 97929 | void shareMemory(ActionData* const data) { | |
327 | // Save memory by setting the internal variables with null dimension | ||
328 | 97929 | g_internal.resize(0); | |
329 | 97929 | Gx_internal.resize(0, 0); | |
330 | 97929 | Gu_internal.resize(0, 0); | |
331 | 97929 | h_internal.resize(0); | |
332 | 97929 | Hx_internal.resize(0, 0); | |
333 | 97929 | Hu_internal.resize(0, 0); | |
334 | // Share memory with the differential action data | ||
335 |
1/2✓ Branch 5 taken 49946 times.
✗ Branch 6 not taken.
|
97929 | new (&g) Eigen::Map<VectorXs>(data->g.data(), data->g.size()); |
336 |
1/2✓ Branch 3 taken 49946 times.
✗ Branch 4 not taken.
|
97929 | new (&Gx) |
337 | 97929 | Eigen::Map<MatrixXs>(data->Gx.data(), data->Gx.rows(), data->Gx.cols()); | |
338 |
1/2✓ Branch 3 taken 49946 times.
✗ Branch 4 not taken.
|
97929 | new (&Gu) |
339 | 97929 | Eigen::Map<MatrixXs>(data->Gu.data(), data->Gu.rows(), data->Gu.cols()); | |
340 |
1/2✓ Branch 5 taken 49946 times.
✗ Branch 6 not taken.
|
97929 | new (&h) Eigen::Map<VectorXs>(data->h.data(), data->h.size()); |
341 |
1/2✓ Branch 3 taken 49946 times.
✗ Branch 4 not taken.
|
97929 | new (&Hx) |
342 | 97929 | Eigen::Map<MatrixXs>(data->Hx.data(), data->Hx.rows(), data->Hx.cols()); | |
343 |
1/2✓ Branch 3 taken 49946 times.
✗ Branch 4 not taken.
|
97929 | new (&Hu) |
344 | 97929 | Eigen::Map<MatrixXs>(data->Hu.data(), data->Hu.rows(), data->Hu.cols()); | |
345 | 97929 | } | |
346 | |||
347 | template <class Model> | ||
348 | 3 | void resize(Model* const model, const bool running_node = true) { | |
349 | 3 | const std::size_t ndx = model->get_state()->get_ndx(); | |
350 | 3 | const std::size_t nu = model->get_nu(); | |
351 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | const std::size_t ng = running_node ? model->get_ng() : model->get_ng_T(); |
352 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | const std::size_t nh = running_node ? model->get_nh() : model->get_nh_T(); |
353 |
1/2✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | new (&g) Eigen::Map<VectorXs>(g_internal.data(), ng); |
354 |
1/2✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | new (&Gx) Eigen::Map<MatrixXs>(Gx_internal.data(), ng, ndx); |
355 |
1/2✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | new (&Gu) Eigen::Map<MatrixXs>(Gu_internal.data(), ng, nu); |
356 |
1/2✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | new (&h) Eigen::Map<VectorXs>(h_internal.data(), nh); |
357 |
1/2✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | new (&Hx) Eigen::Map<MatrixXs>(Hx_internal.data(), nh, ndx); |
358 |
1/2✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | new (&Hu) Eigen::Map<MatrixXs>(Hu_internal.data(), nh, nu); |
359 | 3 | } | |
360 | |||
361 | template <class ActionModel, class ActionData> | ||
362 | 93771 | void resize(ActionModel* const model, ActionData* const data, | |
363 | const bool running_node = true) { | ||
364 | 93771 | const std::size_t ndx = model->get_state()->get_ndx(); | |
365 | 93771 | const std::size_t nu = model->get_nu(); | |
366 |
2/2✓ Branch 0 taken 43621 times.
✓ Branch 1 taken 4661 times.
|
93771 | const std::size_t ng = running_node ? model->get_ng() : model->get_ng_T(); |
367 |
2/2✓ Branch 0 taken 43621 times.
✓ Branch 1 taken 4661 times.
|
93771 | const std::size_t nh = running_node ? model->get_nh() : model->get_nh_T(); |
368 | 93771 | data->g.conservativeResize(ng); | |
369 | 93771 | data->Gx.conservativeResize(ng, ndx); | |
370 | 93771 | data->Gu.conservativeResize(ng, nu); | |
371 | 93771 | data->h.conservativeResize(nh); | |
372 | 93771 | data->Hx.conservativeResize(nh, ndx); | |
373 | 93771 | data->Hu.conservativeResize(nh, nu); | |
374 |
1/2✓ Branch 4 taken 48282 times.
✗ Branch 5 not taken.
|
93771 | new (&g) Eigen::Map<VectorXs>(data->g.data(), ng); |
375 |
1/2✓ Branch 4 taken 48282 times.
✗ Branch 5 not taken.
|
93771 | new (&Gx) Eigen::Map<MatrixXs>(data->Gx.data(), ng, ndx); |
376 |
1/2✓ Branch 4 taken 48282 times.
✗ Branch 5 not taken.
|
93771 | new (&Gu) Eigen::Map<MatrixXs>(data->Gu.data(), ng, nu); |
377 |
1/2✓ Branch 4 taken 48282 times.
✗ Branch 5 not taken.
|
93771 | new (&h) Eigen::Map<VectorXs>(data->h.data(), nh); |
378 |
1/2✓ Branch 4 taken 48282 times.
✗ Branch 5 not taken.
|
93771 | new (&Hx) Eigen::Map<MatrixXs>(data->Hx.data(), nh, ndx); |
379 |
1/2✓ Branch 4 taken 48282 times.
✗ Branch 5 not taken.
|
93771 | new (&Hu) Eigen::Map<MatrixXs>(data->Hu.data(), nh, nu); |
380 | 93771 | } | |
381 | |||
382 | ✗ | VectorXs get_g() const { return g; } | |
383 | ✗ | MatrixXs get_Gx() const { return Gx; } | |
384 | ✗ | MatrixXs get_Gu() const { return Gu; } | |
385 | ✗ | VectorXs get_h() const { return h; } | |
386 | ✗ | MatrixXs get_Hx() const { return Hx; } | |
387 | ✗ | MatrixXs get_Hu() const { return Hu; } | |
388 | |||
389 | ✗ | void set_g(const VectorXs& _g) { | |
390 | ✗ | if (g.size() != _g.size()) { | |
391 | ✗ | throw_pretty( | |
392 | "Invalid argument: " << "g has wrong dimension (it should be " + | ||
393 | std::to_string(g.size()) + ")"); | ||
394 | } | ||
395 | ✗ | g = _g; | |
396 | } | ||
397 | ✗ | void set_Gx(const MatrixXs& _Gx) { | |
398 | ✗ | if (Gx.rows() != _Gx.rows() || Gx.cols() != _Gx.cols()) { | |
399 | ✗ | throw_pretty( | |
400 | "Invalid argument: " << "Gx has wrong dimension (it should be " + | ||
401 | std::to_string(Gx.rows()) + ", " + | ||
402 | std::to_string(Gx.cols()) + ")"); | ||
403 | } | ||
404 | ✗ | Gx = _Gx; | |
405 | } | ||
406 | ✗ | void set_Gu(const MatrixXs& _Gu) { | |
407 | ✗ | if (Gu.rows() != _Gu.rows() || Gu.cols() != _Gu.cols()) { | |
408 | ✗ | throw_pretty( | |
409 | "Invalid argument: " << "Gu has wrong dimension (it should be " + | ||
410 | std::to_string(Gu.rows()) + ", " + | ||
411 | std::to_string(Gu.cols()) + ")"); | ||
412 | } | ||
413 | ✗ | Gu = _Gu; | |
414 | } | ||
415 | ✗ | void set_h(const VectorXs& _h) { | |
416 | ✗ | if (h.size() != _h.size()) { | |
417 | ✗ | throw_pretty( | |
418 | "Invalid argument: " << "h has wrong dimension (it should be " + | ||
419 | std::to_string(h.size()) + ")"); | ||
420 | } | ||
421 | ✗ | h = _h; | |
422 | } | ||
423 | ✗ | void set_Hx(const MatrixXs& _Hx) { | |
424 | ✗ | if (Hx.rows() != _Hx.rows() || Hx.cols() != _Hx.cols()) { | |
425 | ✗ | throw_pretty( | |
426 | "Invalid argument: " << "Hx has wrong dimension (it should be " + | ||
427 | std::to_string(Hx.rows()) + ", " + | ||
428 | std::to_string(Hx.cols()) + ")"); | ||
429 | } | ||
430 | ✗ | Hx = _Hx; | |
431 | } | ||
432 | ✗ | void set_Hu(const MatrixXs& _Hu) { | |
433 | ✗ | if (Hu.rows() != _Hu.rows() || Hu.cols() != _Hu.cols()) { | |
434 | ✗ | throw_pretty( | |
435 | "Invalid argument: " << "Hu has wrong dimension (it should be " + | ||
436 | std::to_string(Hu.rows()) + ", " + | ||
437 | std::to_string(Hu.cols()) + ")"); | ||
438 | } | ||
439 | ✗ | Hu = _Hu; | |
440 | } | ||
441 | |||
442 | // Creates internal data in case we don't share it externally | ||
443 | VectorXs g_internal; | ||
444 | MatrixXs Gx_internal; | ||
445 | MatrixXs Gu_internal; | ||
446 | VectorXs h_internal; | ||
447 | MatrixXs Hx_internal; | ||
448 | MatrixXs Hu_internal; | ||
449 | |||
450 | typename ConstraintModelManagerTpl<Scalar>::ConstraintDataContainer | ||
451 | constraints; | ||
452 | DataCollectorAbstract* shared; | ||
453 | Eigen::Map<VectorXs> g; | ||
454 | Eigen::Map<MatrixXs> Gx; | ||
455 | Eigen::Map<MatrixXs> Gu; | ||
456 | Eigen::Map<VectorXs> h; | ||
457 | Eigen::Map<MatrixXs> Hx; | ||
458 | Eigen::Map<MatrixXs> Hu; | ||
459 | }; | ||
460 | |||
461 | } // namespace crocoddyl | ||
462 | |||
463 | /* --- Details -------------------------------------------------------------- */ | ||
464 | /* --- Details -------------------------------------------------------------- */ | ||
465 | /* --- Details -------------------------------------------------------------- */ | ||
466 | #include "crocoddyl/core/constraints/constraint-manager.hxx" | ||
467 | |||
468 | #endif // CROCODDYL_CORE_CONSTRAINTS_CONSTRAINT_MANAGER_HPP_ | ||
469 |