Directory: | ./ |
---|---|
File: | unittest/factory/solver.cpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 51 | 61 | 83.6% |
Branches: | 25 | 47 | 53.2% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2019-2024, LAAS-CNRS, New York University, | ||
5 | // Max Planck Gesellschaft, University of Edinburgh, | ||
6 | // Heriot-Watt University | ||
7 | // Copyright note valid unless otherwise stated in individual files. | ||
8 | // All rights reserved. | ||
9 | /////////////////////////////////////////////////////////////////////////////// | ||
10 | |||
11 | #include "solver.hpp" | ||
12 | |||
13 | #include "crocoddyl/core/solvers/box-ddp.hpp" | ||
14 | #include "crocoddyl/core/solvers/box-fddp.hpp" | ||
15 | #include "crocoddyl/core/solvers/ddp.hpp" | ||
16 | #include "crocoddyl/core/solvers/fddp.hpp" | ||
17 | #ifdef CROCODDYL_WITH_IPOPT | ||
18 | #include "crocoddyl/core/solvers/ipopt.hpp" | ||
19 | #endif | ||
20 | #include "crocoddyl/core/utils/exception.hpp" | ||
21 | |||
22 | namespace crocoddyl { | ||
23 | namespace unittest { | ||
24 | |||
25 | const std::vector<SolverTypes::Type> SolverTypes::all(SolverTypes::init_all()); | ||
26 | |||
27 | 25 | std::ostream& operator<<(std::ostream& os, SolverTypes::Type type) { | |
28 |
5/8✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 5 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
25 | switch (type) { |
29 | ✗ | case SolverTypes::SolverKKT: | |
30 | ✗ | os << "SolverKKT"; | |
31 | ✗ | break; | |
32 | 5 | case SolverTypes::SolverDDP: | |
33 | 5 | os << "SolverDDP"; | |
34 | 5 | break; | |
35 | 5 | case SolverTypes::SolverFDDP: | |
36 | 5 | os << "SolverFDDP"; | |
37 | 5 | break; | |
38 | 5 | case SolverTypes::SolverBoxDDP: | |
39 | 5 | os << "SolverBoxDDP"; | |
40 | 5 | break; | |
41 | 5 | case SolverTypes::SolverBoxFDDP: | |
42 | 5 | os << "SolverBoxFDDP"; | |
43 | 5 | break; | |
44 | #ifdef CROCODDYL_WITH_IPOPT | ||
45 | 5 | case SolverTypes::SolverIpopt: | |
46 | 5 | os << "SolverIpopt"; | |
47 | 5 | break; | |
48 | #endif | ||
49 | ✗ | case SolverTypes::NbSolverTypes: | |
50 | ✗ | os << "NbSolverTypes"; | |
51 | ✗ | break; | |
52 | ✗ | default: | |
53 | ✗ | break; | |
54 | } | ||
55 | 25 | return os; | |
56 | } | ||
57 | |||
58 | 39 | SolverFactory::SolverFactory() {} | |
59 | |||
60 | 39 | SolverFactory::~SolverFactory() {} | |
61 | |||
62 | 64 | boost::shared_ptr<crocoddyl::SolverAbstract> SolverFactory::create( | |
63 | SolverTypes::Type solver_type, | ||
64 | boost::shared_ptr<crocoddyl::ActionModelAbstract> model, | ||
65 | boost::shared_ptr<crocoddyl::ActionModelAbstract> model2, | ||
66 | boost::shared_ptr<crocoddyl::ActionModelAbstract> modelT, size_t T) const { | ||
67 | 64 | boost::shared_ptr<crocoddyl::SolverAbstract> solver; | |
68 | std::vector<boost::shared_ptr<crocoddyl::ActionModelAbstract> > | ||
69 | 64 | running_models; | |
70 | 64 | const size_t halfway = T / 2; | |
71 |
2/2✓ Branch 0 taken 320 times.
✓ Branch 1 taken 64 times.
|
384 | for (size_t i = 0; i < halfway; ++i) { |
72 |
1/2✓ Branch 1 taken 320 times.
✗ Branch 2 not taken.
|
320 | running_models.push_back(model); |
73 | } | ||
74 |
2/2✓ Branch 0 taken 320 times.
✓ Branch 1 taken 64 times.
|
384 | for (size_t i = 0; i < T - halfway; ++i) { |
75 |
1/2✓ Branch 1 taken 320 times.
✗ Branch 2 not taken.
|
320 | running_models.push_back(model2); |
76 | } | ||
77 | |||
78 | boost::shared_ptr<crocoddyl::ShootingProblem> problem = | ||
79 |
1/2✓ Branch 4 taken 64 times.
✗ Branch 5 not taken.
|
64 | boost::make_shared<crocoddyl::ShootingProblem>(model->get_state()->zero(), |
80 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | running_models, modelT); |
81 | |||
82 |
6/7✓ Branch 0 taken 39 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 5 times.
✗ Branch 6 not taken.
|
64 | switch (solver_type) { |
83 | 39 | case SolverTypes::SolverKKT: | |
84 |
1/2✓ Branch 1 taken 39 times.
✗ Branch 2 not taken.
|
39 | solver = boost::make_shared<crocoddyl::SolverKKT>(problem); |
85 | 39 | break; | |
86 | 5 | case SolverTypes::SolverDDP: | |
87 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | solver = boost::make_shared<crocoddyl::SolverDDP>(problem); |
88 | 5 | break; | |
89 | 5 | case SolverTypes::SolverFDDP: | |
90 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | solver = boost::make_shared<crocoddyl::SolverFDDP>(problem); |
91 | 5 | break; | |
92 | 5 | case SolverTypes::SolverBoxDDP: | |
93 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | solver = boost::make_shared<crocoddyl::SolverBoxDDP>(problem); |
94 | 5 | break; | |
95 | 5 | case SolverTypes::SolverBoxFDDP: | |
96 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | solver = boost::make_shared<crocoddyl::SolverBoxFDDP>(problem); |
97 | 5 | break; | |
98 | #ifdef CROCODDYL_WITH_IPOPT | ||
99 | 5 | case SolverTypes::SolverIpopt: | |
100 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | solver = boost::make_shared<crocoddyl::SolverIpopt>(problem); |
101 | 5 | break; | |
102 | #endif | ||
103 | ✗ | default: | |
104 | ✗ | throw_pretty(__FILE__ ": Wrong SolverTypes::Type given"); | |
105 | break; | ||
106 | } | ||
107 | 128 | return solver; | |
108 | 64 | } | |
109 | |||
110 | } // namespace unittest | ||
111 | } // namespace crocoddyl | ||
112 |