| 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 "crocoddyl/core/solver-base.hpp" | ||
| 15 | #include "python/crocoddyl/core/core.hpp" | ||
| 16 | |||
| 17 | namespace crocoddyl { | ||
| 18 | namespace python { | ||
| 19 | |||
| 20 | class SolverAbstract_wrap : public SolverAbstract, | ||
| 21 | public bp::wrapper<SolverAbstract> { | ||
| 22 | public: | ||
| 23 | using SolverAbstract::cost_; | ||
| 24 | using SolverAbstract::d_; | ||
| 25 | using SolverAbstract::dfeas_; | ||
| 26 | using SolverAbstract::dPhi_; | ||
| 27 | using SolverAbstract::dPhiexp_; | ||
| 28 | using SolverAbstract::dV_; | ||
| 29 | using SolverAbstract::dVexp_; | ||
| 30 | using SolverAbstract::feas_; | ||
| 31 | using SolverAbstract::ffeas_; | ||
| 32 | using SolverAbstract::ffeas_try_; | ||
| 33 | using SolverAbstract::fs_; | ||
| 34 | using SolverAbstract::gfeas_; | ||
| 35 | using SolverAbstract::gfeas_try_; | ||
| 36 | using SolverAbstract::hfeas_; | ||
| 37 | using SolverAbstract::hfeas_try_; | ||
| 38 | using SolverAbstract::is_feasible_; | ||
| 39 | using SolverAbstract::iter_; | ||
| 40 | using SolverAbstract::merit_; | ||
| 41 | using SolverAbstract::steplength_; | ||
| 42 | using SolverAbstract::stop_; | ||
| 43 | using SolverAbstract::us_; | ||
| 44 | using SolverAbstract::xs_; | ||
| 45 | |||
| 46 | ✗ | explicit SolverAbstract_wrap(std::shared_ptr<ShootingProblem> problem) | |
| 47 | ✗ | : SolverAbstract(problem), bp::wrapper<SolverAbstract>() {} | |
| 48 | ✗ | ~SolverAbstract_wrap() {} | |
| 49 | |||
| 50 | ✗ | bool solve(const std::vector<Eigen::VectorXd>& init_xs, | |
| 51 | const std::vector<Eigen::VectorXd>& init_us, | ||
| 52 | const std::size_t maxiter, const bool is_feasible, | ||
| 53 | const double reg_init) { | ||
| 54 | ✗ | return bp::call<bool>(this->get_override("solve").ptr(), init_xs, init_us, | |
| 55 | ✗ | maxiter, is_feasible, reg_init); | |
| 56 | } | ||
| 57 | |||
| 58 | ✗ | void computeDirection(const bool recalc = true) { | |
| 59 | ✗ | return bp::call<void>(this->get_override("computeDirection").ptr(), recalc); | |
| 60 | } | ||
| 61 | |||
| 62 | ✗ | double tryStep(const double step_length = 1) { | |
| 63 | ✗ | return bp::call<double>(this->get_override("tryStep").ptr(), step_length); | |
| 64 | } | ||
| 65 | |||
| 66 | ✗ | double stoppingCriteria() { | |
| 67 | ✗ | stop_ = bp::call<double>(this->get_override("stoppingCriteria").ptr()); | |
| 68 | ✗ | return stop_; | |
| 69 | } | ||
| 70 | |||
| 71 | ✗ | const Eigen::Vector2d& expectedImprovement() { | |
| 72 | bp::list exp_impr = | ||
| 73 | ✗ | bp::call<bp::list>(this->get_override("expectedImprovement").ptr()); | |
| 74 | ✗ | d_ << bp::extract<double>(exp_impr[0]), bp::extract<double>(exp_impr[1]); | |
| 75 | ✗ | return d_; | |
| 76 | ✗ | } | |
| 77 | |||
| 78 | ✗ | bp::list expectedImprovement_wrap() { | |
| 79 | ✗ | expectedImprovement(); | |
| 80 | ✗ | bp::list exp_impr; | |
| 81 | ✗ | exp_impr.append(d_[0]); | |
| 82 | ✗ | exp_impr.append(d_[1]); | |
| 83 | ✗ | return exp_impr; | |
| 84 | ✗ | } | |
| 85 | }; | ||
| 86 | |||
| 87 | class CallbackAbstract_wrap : public CallbackAbstract, | ||
| 88 | public bp::wrapper<CallbackAbstract> { | ||
| 89 | public: | ||
| 90 | ✗ | CallbackAbstract_wrap() | |
| 91 | ✗ | : CallbackAbstract(), bp::wrapper<CallbackAbstract>() {} | |
| 92 | ✗ | ~CallbackAbstract_wrap() {} | |
| 93 | |||
| 94 | ✗ | void operator()(SolverAbstract& solver) { | |
| 95 | ✗ | return bp::call<void>(this->get_override("__call__").ptr(), | |
| 96 | ✗ | boost::ref(solver)); | |
| 97 | } | ||
| 98 | }; | ||
| 99 | |||
| 100 | ✗ | BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(setCandidate_overloads, | |
| 101 | SolverAbstract::setCandidate, 0, 3) | ||
| 102 | |||
| 103 | } // namespace python | ||
| 104 | } // namespace crocoddyl | ||
| 105 | |||
| 106 | #endif // BINDINGS_PYTHON_CROCODDYL_CORE_SOLVER_BASE_HPP_ | ||
| 107 |