| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////// | ||
| 2 | // BSD 3-Clause License | ||
| 3 | // | ||
| 4 | // Copyright (C) 2021-2025, Heriot-Watt University, University of Edinburgh | ||
| 5 | // Copyright note valid unless otherwise stated in individual files. | ||
| 6 | // All rights reserved. | ||
| 7 | /////////////////////////////////////////////////////////////////////////////// | ||
| 8 | |||
| 9 | #include "crocoddyl/core/solvers/intro.hpp" | ||
| 10 | |||
| 11 | #include "python/crocoddyl/core/core.hpp" | ||
| 12 | #include "python/crocoddyl/utils/copyable.hpp" | ||
| 13 | |||
| 14 | #define SCALAR_float32 | ||
| 15 | |||
| 16 | namespace crocoddyl { | ||
| 17 | namespace python { | ||
| 18 | |||
| 19 | BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(SolverIntro_solves, SolverIntro::solve, | ||
| 20 | 0, 5) | ||
| 21 | BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(SolverIntro_trySteps, | ||
| 22 | SolverIntro::tryStep, 0, 1) | ||
| 23 | |||
| 24 | ✗ | void exposeSolverIntro() { | |
| 25 | #ifdef SCALAR_float64 | ||
| 26 | bp::register_ptr_to_python<std::shared_ptr<SolverIntro> >(); | ||
| 27 | |||
| 28 | bp::enum_<EqualitySolverType>("EqualitySolverType") | ||
| 29 | .value("LuNull", LuNull) | ||
| 30 | .value("QrNull", QrNull) | ||
| 31 | .value("Schur", Schur) | ||
| 32 | .export_values(); | ||
| 33 | |||
| 34 | bp::class_<SolverIntro, bp::bases<SolverFDDP> >( | ||
| 35 | "SolverIntro", bp::init<std::shared_ptr<ShootingProblem> >( | ||
| 36 | bp::args("self", "problem"), | ||
| 37 | "Initialize the vector dimension.\n\n" | ||
| 38 | ":param problem: shooting problem.")) | ||
| 39 | .def("solve", &SolverIntro::solve, | ||
| 40 | SolverIntro_solves( | ||
| 41 | bp::args("self", "init_xs", "init_us", "maxiter", "is_feasible", | ||
| 42 | "init_reg"), | ||
| 43 | "Compute the optimal trajectory xopt, uopt as lists of T+1 and " | ||
| 44 | "T terms.\n\n" | ||
| 45 | "From an initial guess init_xs,init_us (feasible or not), " | ||
| 46 | "iterate\n" | ||
| 47 | "over computeDirection and tryStep until stoppingCriteria is " | ||
| 48 | "below\n" | ||
| 49 | "threshold. It also describes the globalization strategy used\n" | ||
| 50 | "during the numerical optimization.\n" | ||
| 51 | ":param init_xs: initial guess for state trajectory with T+1 " | ||
| 52 | "elements (default [])\n" | ||
| 53 | ":param init_us: initial guess for control trajectory with T " | ||
| 54 | "elements (default []).\n" | ||
| 55 | ":param maxiter: maximum allowed number of iterations (default " | ||
| 56 | "100).\n" | ||
| 57 | ":param is_feasible: true if the init_xs are obtained from " | ||
| 58 | "integrating the init_us (rollout)\n" | ||
| 59 | "(default False).\n" | ||
| 60 | ":param init_reg: initial guess for the regularization value. " | ||
| 61 | "Very low values are typically\n" | ||
| 62 | " used with very good guess points (default " | ||
| 63 | "1e-9).\n" | ||
| 64 | ":returns the optimal trajectory xopt, uopt and a boolean that " | ||
| 65 | "describes if convergence was reached.")) | ||
| 66 | .def("tryStep", &SolverIntro::tryStep, | ||
| 67 | SolverIntro_trySteps( | ||
| 68 | bp::args("self", "stepLength"), | ||
| 69 | "Rollout the system with a predefined step length.\n\n" | ||
| 70 | ":param stepLength: step length (default 1)\n" | ||
| 71 | ":returns the cost improvement.")) | ||
| 72 | .add_property( | ||
| 73 | "eq_solver", bp::make_function(&SolverIntro::get_equality_solver), | ||
| 74 | bp::make_function(&SolverIntro::set_equality_solver), | ||
| 75 | "type of solver used for handling the equality constraints.") | ||
| 76 | .add_property("rho", bp::make_function(&SolverIntro::get_rho), | ||
| 77 | bp::make_function(&SolverIntro::set_rho), | ||
| 78 | "parameter used in the merit function to predict the " | ||
| 79 | "expected reduction.") | ||
| 80 | .add_property("upsilon", bp::make_function(&SolverIntro::get_upsilon), | ||
| 81 | "estimated penalty parameter that balances relative " | ||
| 82 | "contribution of the cost function and equality " | ||
| 83 | "constraints.") | ||
| 84 | .add_property("th_feas", bp::make_function(&SolverIntro::get_th_feas), | ||
| 85 | bp::make_function(&SolverIntro::set_th_feas), | ||
| 86 | "threshold to define feasibility.") | ||
| 87 | .add_property("zero_upsilon", | ||
| 88 | bp::make_function(&SolverIntro::get_zero_upsilon), | ||
| 89 | bp::make_function(&SolverIntro::set_zero_upsilon), | ||
| 90 | "True if we set estimated penalty parameter (upsilon) to " | ||
| 91 | "zero when solve is called.") | ||
| 92 | .add_property( | ||
| 93 | "Hu_rank", | ||
| 94 | make_function( | ||
| 95 | &SolverIntro::get_Hu_rank, | ||
| 96 | bp::return_value_policy<bp::reference_existing_object>()), | ||
| 97 | "rank of Hu") | ||
| 98 | .add_property( | ||
| 99 | "YZ", | ||
| 100 | make_function( | ||
| 101 | &SolverIntro::get_YZ, | ||
| 102 | bp::return_value_policy<bp::reference_existing_object>()), | ||
| 103 | "span and kernel of Hu") | ||
| 104 | .add_property( | ||
| 105 | "Qzz", | ||
| 106 | make_function( | ||
| 107 | &SolverIntro::get_Qzz, | ||
| 108 | bp::return_value_policy<bp::reference_existing_object>()), | ||
| 109 | "Qzz") | ||
| 110 | .add_property( | ||
| 111 | "Qxz", | ||
| 112 | make_function( | ||
| 113 | &SolverIntro::get_Qxz, | ||
| 114 | bp::return_value_policy<bp::reference_existing_object>()), | ||
| 115 | "Qxz") | ||
| 116 | .add_property( | ||
| 117 | "Quz", | ||
| 118 | make_function( | ||
| 119 | &SolverIntro::get_Quz, | ||
| 120 | bp::return_value_policy<bp::reference_existing_object>()), | ||
| 121 | "Quz") | ||
| 122 | .add_property( | ||
| 123 | "Qz", | ||
| 124 | make_function( | ||
| 125 | &SolverIntro::get_Qz, | ||
| 126 | bp::return_value_policy<bp::reference_existing_object>()), | ||
| 127 | "Qz") | ||
| 128 | .add_property( | ||
| 129 | "Hy", | ||
| 130 | make_function( | ||
| 131 | &SolverIntro::get_Hy, | ||
| 132 | bp::return_value_policy<bp::reference_existing_object>()), | ||
| 133 | "Hy") | ||
| 134 | .add_property( | ||
| 135 | "Kz", | ||
| 136 | make_function( | ||
| 137 | &SolverIntro::get_Kz, | ||
| 138 | bp::return_value_policy<bp::reference_existing_object>()), | ||
| 139 | "Kz") | ||
| 140 | .add_property( | ||
| 141 | "kz", | ||
| 142 | make_function( | ||
| 143 | &SolverIntro::get_kz, | ||
| 144 | bp::return_value_policy<bp::reference_existing_object>()), | ||
| 145 | "kz") | ||
| 146 | .add_property( | ||
| 147 | "Ks", | ||
| 148 | make_function( | ||
| 149 | &SolverIntro::get_Ks, | ||
| 150 | bp::return_value_policy<bp::reference_existing_object>()), | ||
| 151 | "Ks") | ||
| 152 | .add_property( | ||
| 153 | "ks", | ||
| 154 | make_function( | ||
| 155 | &SolverIntro::get_ks, | ||
| 156 | bp::return_value_policy<bp::reference_existing_object>()), | ||
| 157 | "ks") | ||
| 158 | .def(CopyableVisitor<SolverIntro>()); | ||
| 159 | #endif | ||
| 160 | ✗ | } | |
| 161 | |||
| 162 | } // namespace python | ||
| 163 | } // namespace crocoddyl | ||
| 164 |