Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/core/solvers/intro.cpp |
Date: | 2025-01-30 11:01:55 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 64 | 64 | 100.0% |
Branches: | 49 | 98 | 50.0% |
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 | 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<std::shared_ptr<SolverIntro> >(); | |
24 | |||
25 | 20 | bp::enum_<EqualitySolverType>("EqualitySolverType") | |
26 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .value("LuNull", LuNull) |
27 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .value("QrNull", QrNull) |
28 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .value("Schur", Schur) |
29 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .export_values(); |
30 | |||
31 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<SolverIntro, bp::bases<SolverFDDP> >( |
32 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | "SolverIntro", bp::init<std::shared_ptr<ShootingProblem> >( |
33 | 20 | bp::args("self", "problem"), | |
34 | "Initialize the vector dimension.\n\n" | ||
35 | ":param problem: shooting problem.")) | ||
36 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("solve", &SolverIntro::solve, |
37 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | SolverIntro_solves( |
38 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | "describes if convergence was reached.")) | ||
63 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("tryStep", &SolverIntro::tryStep, |
64 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | SolverIntro_trySteps( |
65 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | ":returns the cost improvement.")) | ||
69 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
70 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | "eq_solver", bp::make_function(&SolverIntro::get_equality_solver), |
71 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_function(&SolverIntro::set_equality_solver), |
72 | "type of solver used for handling the equality constraints.") | ||
73 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .add_property("rho", bp::make_function(&SolverIntro::get_rho), |
74 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_function(&SolverIntro::set_rho), |
75 | "parameter used in the merit function to predict the " | ||
76 | "expected reduction.") | ||
77 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
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 | "constraints.") | ||
81 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .add_property("th_feas", bp::make_function(&SolverIntro::get_th_feas), |
82 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_function(&SolverIntro::set_th_feas), |
83 | "threshold to define feasibility.") | ||
84 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("zero_upsilon", |
85 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&SolverIntro::get_zero_upsilon), |
86 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_function(&SolverIntro::set_zero_upsilon), |
87 | "True if we set estimated penalty parameter (upsilon) to " | ||
88 | "zero when solve is called.") | ||
89 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
90 | "Hu_rank", | ||
91 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | make_function( |
92 | &SolverIntro::get_Hu_rank, | ||
93 | 10 | bp::return_value_policy<bp::reference_existing_object>()), | |
94 | "rank of Hu") | ||
95 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
96 | "YZ", | ||
97 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | make_function( |
98 | &SolverIntro::get_YZ, | ||
99 | 10 | bp::return_value_policy<bp::reference_existing_object>()), | |
100 | "span and kernel of Hu") | ||
101 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
102 | "Qzz", | ||
103 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | make_function( |
104 | &SolverIntro::get_Qzz, | ||
105 | 10 | bp::return_value_policy<bp::reference_existing_object>()), | |
106 | "Qzz") | ||
107 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
108 | "Qxz", | ||
109 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | make_function( |
110 | &SolverIntro::get_Qxz, | ||
111 | 10 | bp::return_value_policy<bp::reference_existing_object>()), | |
112 | "Qxz") | ||
113 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
114 | "Quz", | ||
115 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | make_function( |
116 | &SolverIntro::get_Quz, | ||
117 | 10 | bp::return_value_policy<bp::reference_existing_object>()), | |
118 | "Quz") | ||
119 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
120 | "Qz", | ||
121 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | make_function( |
122 | &SolverIntro::get_Qz, | ||
123 | 10 | bp::return_value_policy<bp::reference_existing_object>()), | |
124 | "Qz") | ||
125 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
126 | "Hy", | ||
127 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | make_function( |
128 | &SolverIntro::get_Hy, | ||
129 | 10 | bp::return_value_policy<bp::reference_existing_object>()), | |
130 | "Hy") | ||
131 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
132 | "Kz", | ||
133 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | make_function( |
134 | &SolverIntro::get_Kz, | ||
135 | 10 | bp::return_value_policy<bp::reference_existing_object>()), | |
136 | "Kz") | ||
137 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
138 | "kz", | ||
139 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | make_function( |
140 | &SolverIntro::get_kz, | ||
141 | 10 | bp::return_value_policy<bp::reference_existing_object>()), | |
142 | "kz") | ||
143 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
144 | "Ks", | ||
145 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | make_function( |
146 | &SolverIntro::get_Ks, | ||
147 | 10 | bp::return_value_policy<bp::reference_existing_object>()), | |
148 | "Ks") | ||
149 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
150 | "ks", | ||
151 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | make_function( |
152 | &SolverIntro::get_ks, | ||
153 | 10 | bp::return_value_policy<bp::reference_existing_object>()), | |
154 | "ks") | ||
155 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<SolverIntro>()); |
156 | 10 | } | |
157 | |||
158 | } // namespace python | ||
159 | } // namespace crocoddyl | ||
160 |