GCC Code Coverage Report


Directory: ./
File: unittest/factory/solver.cpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 51 61 83.6%
Branches: 26 49 53.1%

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
21 namespace crocoddyl {
22 namespace unittest {
23
24 const std::vector<SolverTypes::Type> SolverTypes::all(SolverTypes::init_all());
25
26 25 std::ostream& operator<<(std::ostream& os, SolverTypes::Type type) {
27
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) {
28 case SolverTypes::SolverKKT:
29 os << "SolverKKT";
30 break;
31 5 case SolverTypes::SolverDDP:
32 5 os << "SolverDDP";
33 5 break;
34 5 case SolverTypes::SolverFDDP:
35 5 os << "SolverFDDP";
36 5 break;
37 5 case SolverTypes::SolverBoxDDP:
38 5 os << "SolverBoxDDP";
39 5 break;
40 5 case SolverTypes::SolverBoxFDDP:
41 5 os << "SolverBoxFDDP";
42 5 break;
43 #ifdef CROCODDYL_WITH_IPOPT
44 5 case SolverTypes::SolverIpopt:
45 5 os << "SolverIpopt";
46 5 break;
47 #endif
48 case SolverTypes::NbSolverTypes:
49 os << "NbSolverTypes";
50 break;
51 default:
52 break;
53 }
54 25 return os;
55 }
56
57 39 SolverFactory::SolverFactory() {}
58
59 39 SolverFactory::~SolverFactory() {}
60
61 64 std::shared_ptr<crocoddyl::SolverAbstract> SolverFactory::create(
62 SolverTypes::Type solver_type,
63 std::shared_ptr<crocoddyl::ActionModelAbstract> model,
64 std::shared_ptr<crocoddyl::ActionModelAbstract> model2,
65 std::shared_ptr<crocoddyl::ActionModelAbstract> modelT, size_t T) const {
66 64 std::shared_ptr<crocoddyl::SolverAbstract> solver;
67 64 std::vector<std::shared_ptr<crocoddyl::ActionModelAbstract> > running_models;
68 64 const size_t halfway = T / 2;
69
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 64 times.
384 for (size_t i = 0; i < halfway; ++i) {
70
1/2
✓ Branch 1 taken 320 times.
✗ Branch 2 not taken.
320 running_models.push_back(model);
71 }
72
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 64 times.
384 for (size_t i = 0; i < T - halfway; ++i) {
73
1/2
✓ Branch 1 taken 320 times.
✗ Branch 2 not taken.
320 running_models.push_back(model2);
74 }
75
76 std::shared_ptr<crocoddyl::ShootingProblem> problem =
77
2/4
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 64 times.
✗ Branch 7 not taken.
64 std::make_shared<crocoddyl::ShootingProblem>(model->get_state()->zero(),
78
1/2
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
64 running_models, modelT);
79
80
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) {
81 39 case SolverTypes::SolverKKT:
82
1/2
✓ Branch 1 taken 39 times.
✗ Branch 2 not taken.
39 solver = std::make_shared<crocoddyl::SolverKKT>(problem);
83 39 break;
84 5 case SolverTypes::SolverDDP:
85
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 solver = std::make_shared<crocoddyl::SolverDDP>(problem);
86 5 break;
87 5 case SolverTypes::SolverFDDP:
88
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 solver = std::make_shared<crocoddyl::SolverFDDP>(problem);
89 5 break;
90 5 case SolverTypes::SolverBoxDDP:
91
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 solver = std::make_shared<crocoddyl::SolverBoxDDP>(problem);
92 5 break;
93 5 case SolverTypes::SolverBoxFDDP:
94
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 solver = std::make_shared<crocoddyl::SolverBoxFDDP>(problem);
95 5 break;
96 #ifdef CROCODDYL_WITH_IPOPT
97 5 case SolverTypes::SolverIpopt:
98
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 solver = std::make_shared<crocoddyl::SolverIpopt>(problem);
99 5 break;
100 #endif
101 default:
102 throw_pretty(__FILE__ ": Wrong SolverTypes::Type given");
103 break;
104 }
105 128 return solver;
106 64 }
107
108 } // namespace unittest
109 } // namespace crocoddyl
110