GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/core/integ-action-base.hxx
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 39 59 66.1%
Branches: 18 78 23.1%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021-2024, LAAS-CNRS, University of Edinburgh,
5 // University of Oxford, University of Trento,
6 // Heriot-Watt University
7 // Copyright note valid unless otherwise stated in individual files.
8 // All rights reserved.
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #include <boost/core/demangle.hpp>
12 #include <iostream>
13 #include <typeinfo>
14
15 #include "crocoddyl/core/controls/poly-zero.hpp"
16 #include "crocoddyl/core/integ-action-base.hpp"
17 #include "crocoddyl/core/utils/exception.hpp"
18
19 namespace crocoddyl {
20
21 template <typename Scalar>
22 713 IntegratedActionModelAbstractTpl<Scalar>::IntegratedActionModelAbstractTpl(
23 boost::shared_ptr<DifferentialActionModelAbstract> model,
24 boost::shared_ptr<ControlParametrizationModelAbstract> control,
25 const Scalar time_step, const bool with_cost_residual)
26 : Base(model->get_state(), control->get_nu(), model->get_nr(),
27 2852 model->get_ng(), model->get_nh()),
28 713 differential_(model),
29 713 control_(control),
30 713 time_step_(time_step),
31
1/2
✓ Branch 12 taken 713 times.
✗ Branch 13 not taken.
713 with_cost_residual_(with_cost_residual) {
32
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 713 times.
713 if (control->get_nw() != model->get_nu()) {
33 throw_pretty("Invalid argument: "
34 << "control.nw (" + std::to_string(control->get_nw()) +
35 ") is not equal to model.nu (" +
36 std::to_string(model->get_nu()) + ")");
37 }
38
1/2
✓ Branch 1 taken 713 times.
✗ Branch 2 not taken.
713 init();
39 713 }
40
41 template <typename Scalar>
42 378 IntegratedActionModelAbstractTpl<Scalar>::IntegratedActionModelAbstractTpl(
43 boost::shared_ptr<DifferentialActionModelAbstract> model,
44 const Scalar time_step, const bool with_cost_residual)
45 : Base(model->get_state(), model->get_nu(), model->get_nr(),
46 1512 model->get_ng(), model->get_nh()),
47 378 differential_(model),
48
1/2
✓ Branch 1 taken 378 times.
✗ Branch 2 not taken.
378 control_(
49
2/4
✓ Branch 3 taken 378 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 378 times.
✗ Branch 7 not taken.
378 new ControlParametrizationModelPolyZeroTpl<Scalar>(model->get_nu())),
50 378 time_step_(time_step),
51
1/2
✓ Branch 12 taken 378 times.
✗ Branch 13 not taken.
378 with_cost_residual_(with_cost_residual) {
52
1/2
✓ Branch 1 taken 378 times.
✗ Branch 2 not taken.
378 init();
53 378 }
54
55 template <typename Scalar>
56 1091 void IntegratedActionModelAbstractTpl<Scalar>::init() {
57 1091 time_step2_ = time_step_ * time_step_;
58
2/4
✓ Branch 1 taken 1091 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1091 times.
✗ Branch 5 not taken.
1091 VectorXs u_lb(nu_), u_ub(nu_);
59
5/10
✓ Branch 2 taken 1091 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1091 times.
✗ Branch 6 not taken.
✓ Branch 10 taken 1091 times.
✗ Branch 11 not taken.
✓ Branch 15 taken 1091 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 1091 times.
✗ Branch 19 not taken.
1091 control_->convertBounds(differential_->get_u_lb(), differential_->get_u_ub(),
60 u_lb, u_ub);
61
1/2
✓ Branch 1 taken 1091 times.
✗ Branch 2 not taken.
1091 Base::set_u_lb(u_lb);
62
1/2
✓ Branch 1 taken 1091 times.
✗ Branch 2 not taken.
1091 Base::set_u_ub(u_ub);
63
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1091 times.
1091 if (time_step_ < Scalar(0.)) {
64 time_step_ = Scalar(1e-3);
65 time_step2_ = time_step_ * time_step_;
66 std::cerr << "Warning: dt should be positive, set to 1e-3" << std::endl;
67 }
68 1091 }
69
70 template <typename Scalar>
71 2190 IntegratedActionModelAbstractTpl<Scalar>::~IntegratedActionModelAbstractTpl() {}
72
73 template <typename Scalar>
74 boost::shared_ptr<ActionDataAbstractTpl<Scalar> >
75 IntegratedActionModelAbstractTpl<Scalar>::createData() {
76 if (control_->get_nu() > differential_->get_nu())
77 std::cerr << "Warning: It is useless to use an Euler integrator with a "
78 "control parametrization larger than PolyZero"
79 << std::endl;
80 return boost::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this);
81 }
82
83 template <typename Scalar>
84 119775 std::size_t IntegratedActionModelAbstractTpl<Scalar>::get_ng() const {
85 119775 return differential_->get_ng();
86 }
87
88 template <typename Scalar>
89 157347 std::size_t IntegratedActionModelAbstractTpl<Scalar>::get_nh() const {
90 157347 return differential_->get_nh();
91 }
92
93 template <typename Scalar>
94 237914 std::size_t IntegratedActionModelAbstractTpl<Scalar>::get_ng_T() const {
95 237914 return differential_->get_ng_T();
96 }
97
98 template <typename Scalar>
99 200078 std::size_t IntegratedActionModelAbstractTpl<Scalar>::get_nh_T() const {
100 200078 return differential_->get_nh_T();
101 }
102
103 template <typename Scalar>
104 const typename MathBaseTpl<Scalar>::VectorXs&
105 IntegratedActionModelAbstractTpl<Scalar>::get_g_lb() const {
106 return differential_->get_g_lb();
107 }
108
109 template <typename Scalar>
110 const typename MathBaseTpl<Scalar>::VectorXs&
111 IntegratedActionModelAbstractTpl<Scalar>::get_g_ub() const {
112 return differential_->get_g_ub();
113 }
114
115 template <typename Scalar>
116 const boost::shared_ptr<DifferentialActionModelAbstractTpl<Scalar> >&
117 105004 IntegratedActionModelAbstractTpl<Scalar>::get_differential() const {
118 105004 return differential_;
119 }
120
121 template <typename Scalar>
122 const boost::shared_ptr<ControlParametrizationModelAbstractTpl<Scalar> >&
123 270806 IntegratedActionModelAbstractTpl<Scalar>::get_control() const {
124 270806 return control_;
125 }
126
127 template <typename Scalar>
128 const Scalar IntegratedActionModelAbstractTpl<Scalar>::get_dt() const {
129 return time_step_;
130 }
131
132 template <typename Scalar>
133 void IntegratedActionModelAbstractTpl<Scalar>::set_dt(const Scalar dt) {
134 if (dt < 0.) {
135 throw_pretty("Invalid argument: " << "dt has positive value");
136 }
137 time_step_ = dt;
138 time_step2_ = dt * dt;
139 }
140
141 template <typename Scalar>
142 void IntegratedActionModelAbstractTpl<Scalar>::set_differential(
143 boost::shared_ptr<DifferentialActionModelAbstract> model) {
144 if (control_->get_nw() != model->get_nu()) {
145 throw_pretty("Invalid argument: "
146 << "control.nw (" + std::to_string(control_->get_nw()) +
147 ") is not equal to model.nu (" +
148 std::to_string(model->get_nu()) + ")");
149 }
150
151 nr_ = model->get_nr();
152 state_ = model->get_state();
153 differential_ = model;
154
155 VectorXs p_lb(nu_), p_ub(nu_);
156 control_->convertBounds(differential_->get_u_lb(), differential_->get_u_ub(),
157 p_lb, p_ub);
158 Base::set_u_lb(p_lb);
159 Base::set_u_ub(p_ub);
160 }
161
162 } // namespace crocoddyl
163