GCC Code Coverage Report


Directory: ./
File: unittest/factory/solver.cpp
Date: 2025-02-24 23:41:29
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 std::shared_ptr<crocoddyl::SolverAbstract> SolverFactory::create(
63 SolverTypes::Type solver_type,
64 std::shared_ptr<crocoddyl::ActionModelAbstract> model,
65 std::shared_ptr<crocoddyl::ActionModelAbstract> model2,
66 std::shared_ptr<crocoddyl::ActionModelAbstract> modelT, size_t T) const {
67 64 std::shared_ptr<crocoddyl::SolverAbstract> solver;
68 64 std::vector<std::shared_ptr<crocoddyl::ActionModelAbstract> > running_models;
69 64 const size_t halfway = T / 2;
70
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 64 times.
384 for (size_t i = 0; i < halfway; ++i) {
71
1/2
✓ Branch 1 taken 320 times.
✗ Branch 2 not taken.
320 running_models.push_back(model);
72 }
73
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 64 times.
384 for (size_t i = 0; i < T - halfway; ++i) {
74
1/2
✓ Branch 1 taken 320 times.
✗ Branch 2 not taken.
320 running_models.push_back(model2);
75 }
76
77 std::shared_ptr<crocoddyl::ShootingProblem> problem =
78
1/2
✓ Branch 4 taken 64 times.
✗ Branch 5 not taken.
64 std::make_shared<crocoddyl::ShootingProblem>(model->get_state()->zero(),
79
1/2
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
64 running_models, modelT);
80
81
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) {
82 39 case SolverTypes::SolverKKT:
83
1/2
✓ Branch 1 taken 39 times.
✗ Branch 2 not taken.
39 solver = std::make_shared<crocoddyl::SolverKKT>(problem);
84 39 break;
85 5 case SolverTypes::SolverDDP:
86
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 solver = std::make_shared<crocoddyl::SolverDDP>(problem);
87 5 break;
88 5 case SolverTypes::SolverFDDP:
89
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 solver = std::make_shared<crocoddyl::SolverFDDP>(problem);
90 5 break;
91 5 case SolverTypes::SolverBoxDDP:
92
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 solver = std::make_shared<crocoddyl::SolverBoxDDP>(problem);
93 5 break;
94 5 case SolverTypes::SolverBoxFDDP:
95
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 solver = std::make_shared<crocoddyl::SolverBoxFDDP>(problem);
96 5 break;
97 #ifdef CROCODDYL_WITH_IPOPT
98 5 case SolverTypes::SolverIpopt:
99
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 solver = std::make_shared<crocoddyl::SolverIpopt>(problem);
100 5 break;
101 #endif
102 default:
103 throw_pretty(__FILE__ ": Wrong SolverTypes::Type given");
104 break;
105 }
106 128 return solver;
107 64 }
108
109 } // namespace unittest
110 } // namespace crocoddyl
111