Directory: | ./ |
---|---|
File: | unittest/factory/integrator.cpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 56 | 65 | 86.2% |
Branches: | 20 | 48 | 41.7% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2021, University of Edinburgh, LAAS-CNRS, University of Trento | ||
5 | // Copyright note valid unless otherwise stated in individual files. | ||
6 | // All rights reserved. | ||
7 | /////////////////////////////////////////////////////////////////////////////// | ||
8 | |||
9 | #include "integrator.hpp" | ||
10 | |||
11 | #include "crocoddyl/core/integrator/euler.hpp" | ||
12 | #include "crocoddyl/core/integrator/rk.hpp" | ||
13 | #include "crocoddyl/core/utils/exception.hpp" | ||
14 | |||
15 | namespace crocoddyl { | ||
16 | namespace unittest { | ||
17 | |||
18 | const std::vector<IntegratorTypes::Type> IntegratorTypes::all( | ||
19 | IntegratorTypes::init_all()); | ||
20 | |||
21 | 345 | std::ostream& operator<<(std::ostream& os, IntegratorTypes::Type type) { | |
22 |
4/6✓ Branch 0 taken 92 times.
✓ Branch 1 taken 69 times.
✓ Branch 2 taken 92 times.
✓ Branch 3 taken 92 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
345 | switch (type) { |
23 | 92 | case IntegratorTypes::IntegratorEuler: | |
24 | 92 | os << "IntegratorEuler"; | |
25 | 92 | break; | |
26 | 69 | case IntegratorTypes::IntegratorRK2: | |
27 | 69 | os << "IntegratorRK2"; | |
28 | 69 | break; | |
29 | 92 | case IntegratorTypes::IntegratorRK3: | |
30 | 92 | os << "IntegratorRK3"; | |
31 | 92 | break; | |
32 | 92 | case IntegratorTypes::IntegratorRK4: | |
33 | 92 | os << "IntegratorRK4"; | |
34 | 92 | break; | |
35 | ✗ | case IntegratorTypes::NbIntegratorTypes: | |
36 | ✗ | os << "NbIntegratorTypes"; | |
37 | ✗ | break; | |
38 | ✗ | default: | |
39 | ✗ | break; | |
40 | } | ||
41 | 345 | return os; | |
42 | } | ||
43 | |||
44 | 1035 | IntegratorFactory::IntegratorFactory() {} | |
45 | 1035 | IntegratorFactory::~IntegratorFactory() {} | |
46 | |||
47 | boost::shared_ptr<crocoddyl::IntegratedActionModelAbstract> | ||
48 | 368 | IntegratorFactory::create( | |
49 | IntegratorTypes::Type type, | ||
50 | boost::shared_ptr<DifferentialActionModelAbstract> model) const { | ||
51 | 368 | boost::shared_ptr<crocoddyl::IntegratedActionModelAbstract> action; | |
52 |
4/5✓ Branch 0 taken 92 times.
✓ Branch 1 taken 92 times.
✓ Branch 2 taken 92 times.
✓ Branch 3 taken 92 times.
✗ Branch 4 not taken.
|
368 | switch (type) { |
53 | 92 | case IntegratorTypes::IntegratorEuler: | |
54 |
1/2✓ Branch 1 taken 92 times.
✗ Branch 2 not taken.
|
92 | action = boost::make_shared<crocoddyl::IntegratedActionModelEuler>(model); |
55 | 92 | break; | |
56 | 92 | case IntegratorTypes::IntegratorRK2: | |
57 | 92 | action = boost::make_shared<crocoddyl::IntegratedActionModelRK>( | |
58 |
1/2✓ Branch 1 taken 92 times.
✗ Branch 2 not taken.
|
92 | model, RKType::two); |
59 | 92 | break; | |
60 | 92 | case IntegratorTypes::IntegratorRK3: | |
61 | 92 | action = boost::make_shared<crocoddyl::IntegratedActionModelRK>( | |
62 |
1/2✓ Branch 1 taken 92 times.
✗ Branch 2 not taken.
|
92 | model, RKType::three); |
63 | 92 | break; | |
64 | 92 | case IntegratorTypes::IntegratorRK4: | |
65 | 92 | action = boost::make_shared<crocoddyl::IntegratedActionModelRK>( | |
66 |
1/2✓ Branch 1 taken 92 times.
✗ Branch 2 not taken.
|
92 | model, RKType::four); |
67 | 92 | break; | |
68 | ✗ | default: | |
69 | ✗ | throw_pretty(__FILE__ ": Wrong IntegratorTypes::Type given"); | |
70 | break; | ||
71 | } | ||
72 | 368 | return action; | |
73 | } | ||
74 | |||
75 | boost::shared_ptr<crocoddyl::IntegratedActionModelAbstract> | ||
76 | 713 | IntegratorFactory::create( | |
77 | IntegratorTypes::Type type, | ||
78 | boost::shared_ptr<DifferentialActionModelAbstract> model, | ||
79 | boost::shared_ptr<ControlParametrizationModelAbstract> control) const { | ||
80 | 713 | boost::shared_ptr<crocoddyl::IntegratedActionModelAbstract> action; | |
81 |
4/5✓ Branch 0 taken 161 times.
✓ Branch 1 taken 138 times.
✓ Branch 2 taken 207 times.
✓ Branch 3 taken 207 times.
✗ Branch 4 not taken.
|
713 | switch (type) { |
82 | 161 | case IntegratorTypes::IntegratorEuler: | |
83 |
1/2✓ Branch 1 taken 161 times.
✗ Branch 2 not taken.
|
322 | action = boost::make_shared<crocoddyl::IntegratedActionModelEuler>( |
84 | 161 | model, control); | |
85 | 161 | break; | |
86 | 138 | case IntegratorTypes::IntegratorRK2: | |
87 | 138 | action = boost::make_shared<crocoddyl::IntegratedActionModelRK>( | |
88 |
1/2✓ Branch 1 taken 138 times.
✗ Branch 2 not taken.
|
138 | model, control, RKType::two); |
89 | 138 | break; | |
90 | 207 | case IntegratorTypes::IntegratorRK3: | |
91 | 207 | action = boost::make_shared<crocoddyl::IntegratedActionModelRK>( | |
92 |
1/2✓ Branch 1 taken 207 times.
✗ Branch 2 not taken.
|
207 | model, control, RKType::three); |
93 | 207 | break; | |
94 | 207 | case IntegratorTypes::IntegratorRK4: | |
95 | 207 | action = boost::make_shared<crocoddyl::IntegratedActionModelRK>( | |
96 |
1/2✓ Branch 1 taken 207 times.
✗ Branch 2 not taken.
|
207 | model, control, RKType::four); |
97 | 207 | break; | |
98 | ✗ | default: | |
99 | ✗ | throw_pretty(__FILE__ ": Wrong IntegratorTypes::Type given"); | |
100 | break; | ||
101 | } | ||
102 | 713 | return action; | |
103 | } | ||
104 | |||
105 | } // namespace unittest | ||
106 | } // namespace crocoddyl | ||
107 |