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