GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/solver-base.hpp
Date: 2025-01-30 11:01:55
Exec Total Coverage
Lines: 4 30 13.3%
Branches: 1 46 2.2%

Line Branch Exec Source
1
2 ///////////////////////////////////////////////////////////////////////////////
3 // BSD 3-Clause License
4 //
5 // Copyright (C) 2019-2023, LAAS-CNRS, University of Edinburgh,
6 // Heriot-Watt University
7 // Copyright note valid unless otherwise stated in individual files.
8 // All rights reserved.
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef BINDINGS_PYTHON_CROCODDYL_CORE_SOLVER_BASE_HPP_
12 #define BINDINGS_PYTHON_CROCODDYL_CORE_SOLVER_BASE_HPP_
13
14 #include <memory>
15 #include <vector>
16
17 #include "crocoddyl/core/solver-base.hpp"
18 #include "python/crocoddyl/core/core.hpp"
19
20 namespace crocoddyl {
21 namespace python {
22
23 class SolverAbstract_wrap : public SolverAbstract,
24 public bp::wrapper<SolverAbstract> {
25 public:
26 using SolverAbstract::cost_;
27 using SolverAbstract::d_;
28 using SolverAbstract::dfeas_;
29 using SolverAbstract::dPhi_;
30 using SolverAbstract::dPhiexp_;
31 using SolverAbstract::dV_;
32 using SolverAbstract::dVexp_;
33 using SolverAbstract::feas_;
34 using SolverAbstract::ffeas_;
35 using SolverAbstract::ffeas_try_;
36 using SolverAbstract::fs_;
37 using SolverAbstract::gfeas_;
38 using SolverAbstract::gfeas_try_;
39 using SolverAbstract::hfeas_;
40 using SolverAbstract::hfeas_try_;
41 using SolverAbstract::is_feasible_;
42 using SolverAbstract::iter_;
43 using SolverAbstract::merit_;
44 using SolverAbstract::steplength_;
45 using SolverAbstract::stop_;
46 using SolverAbstract::us_;
47 using SolverAbstract::xs_;
48
49 24 explicit SolverAbstract_wrap(std::shared_ptr<ShootingProblem> problem)
50
1/2
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 : SolverAbstract(problem), bp::wrapper<SolverAbstract>() {}
51 48 ~SolverAbstract_wrap() {}
52
53 bool solve(const std::vector<Eigen::VectorXd>& init_xs,
54 const std::vector<Eigen::VectorXd>& init_us,
55 const std::size_t maxiter, const bool is_feasible,
56 const double reg_init) {
57 return bp::call<bool>(this->get_override("solve").ptr(), init_xs, init_us,
58 maxiter, is_feasible, reg_init);
59 }
60
61 void computeDirection(const bool recalc = true) {
62 return bp::call<void>(this->get_override("computeDirection").ptr(), recalc);
63 }
64
65 double tryStep(const double step_length = 1) {
66 return bp::call<double>(this->get_override("tryStep").ptr(), step_length);
67 }
68
69 double stoppingCriteria() {
70 stop_ = bp::call<double>(this->get_override("stoppingCriteria").ptr());
71 return stop_;
72 }
73
74 const Eigen::Vector2d& expectedImprovement() {
75 bp::list exp_impr =
76 bp::call<bp::list>(this->get_override("expectedImprovement").ptr());
77 d_ << bp::extract<double>(exp_impr[0]), bp::extract<double>(exp_impr[1]);
78 return d_;
79 }
80
81 bp::list expectedImprovement_wrap() {
82 expectedImprovement();
83 bp::list exp_impr;
84 exp_impr.append(d_[0]);
85 exp_impr.append(d_[1]);
86 return exp_impr;
87 }
88 };
89
90 class CallbackAbstract_wrap : public CallbackAbstract,
91 public bp::wrapper<CallbackAbstract> {
92 public:
93 CallbackAbstract_wrap()
94 : CallbackAbstract(), bp::wrapper<CallbackAbstract>() {}
95 ~CallbackAbstract_wrap() {}
96
97 void operator()(SolverAbstract& solver) {
98 return bp::call<void>(this->get_override("__call__").ptr(),
99 boost::ref(solver));
100 }
101 };
102
103 188 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(setCandidate_overloads,
104 SolverAbstract::setCandidate, 0, 3)
105
106 } // namespace python
107 } // namespace crocoddyl
108
109 #endif // BINDINGS_PYTHON_CROCODDYL_CORE_SOLVER_BASE_HPP_
110