GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/solvers/kkt.cpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 40 41 97.6%
Branches: 28 56 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2020-2023, LAAS-CNRS, Heriot-Watt University
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "crocoddyl/core/solvers/kkt.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(SolverKKT_solves, SolverKKT::solve, 0, 5)
18 10 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(SolverKKT_computeDirections,
19 SolverKKT::computeDirection, 0, 1)
20 20 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(SolverKKT_trySteps, SolverKKT::tryStep,
21 0, 1)
22
23 10 void exposeSolverKKT() {
24 10 bp::register_ptr_to_python<boost::shared_ptr<SolverKKT> >();
25
26
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<SolverKKT, bp::bases<SolverAbstract> >(
27 "SolverKKT",
28 "KKT solver.\n\n"
29 "The KKT solver computes a primal and dual optimal by inverting\n"
30 "the kkt matrix \n"
31 ":param shootingProblem: shooting problem (list of action models along "
32 "trajectory.)",
33
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<boost::shared_ptr<ShootingProblem> >(
34 20 bp::args("self", "problem"),
35 "Initialize the vector dimension.\n\n"
36 ":param problem: shooting problem."))
37
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("solve", &SolverKKT::solve,
38
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 SolverKKT_solves(
39
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "init_xs", "init_us", "maxiter", "isFeasible",
40 "regInit"),
41 "Compute the optimal primal(xopt, uopt) and dual(Vx) terms.\n\n"
42 ":param init_xs: initial guess for state trajectory with T+1 "
43 "elements (default []).\n"
44 ":param init_us: initial guess for control trajectory with T "
45 "elements (default []) (default []).\n"
46 ":param maxiter: maximun allowed number of iterations (default "
47 "100).\n"
48 ":param isFeasible: true if the init_xs are obtained from "
49 "integrating the init_us (rollout) (default "
50 "False).\n"
51 ":param regInit: initial guess for the regularization value. "
52 "Very low values are typical\n"
53 " used with very good guess points (init_xs, "
54 "init_us) (default None).\n"
55 ":returns the optimal trajectory xopt, uopt and a boolean that "
56 "describes if convergence was reached."))
57
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("computeDirection", &SolverKKT::computeDirection,
58
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 SolverKKT_computeDirections(
59
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "recalc"),
60 "Compute the search direction (dx, du), lambdas for the current "
61 "guess (xs, us).\n\n"
62 "You must call setCandidate first in order to define the "
63 "current\n"
64 "guess. A current guess defines a state and control trajectory\n"
65 "(xs, us) of T+1 and T elements, respectively.\n"
66 ":params recalc: true for recalculating the derivatives at "
67 "current state and control.\n"
68 ":returns the search direction dx, du and the dual lambdas as "
69 "lists of T+1, T and T+1 lengths."))
70
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("tryStep", &SolverKKT::tryStep,
71
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 SolverKKT_trySteps(
72
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", " stepLength=1"),
73 "Rollout the system with a predefined step length.\n\n"
74 ":param stepLength: step length\n"
75 ":returns the cost improvement."))
76
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
20 .def("stoppingCriteria", &SolverKKT::stoppingCriteria, bp::args("self"),
77 "Return a sum of positive parameters whose sum quantifies the DDP "
78 "termination.")
79
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("expectedImprovement", &SolverKKT::expectedImprovement,
80 bp::return_value_policy<bp::copy_const_reference>(),
81
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self"),
82 "Return two scalars denoting the quadratic improvement model\n\n"
83 "For computing the expected improvement, you need to compute first\n"
84 "the search direction by running computeDirection. The quadratic\n"
85 "improvement model is described as dV = f_0 - f_+ = d1*a + "
86 "d2*a**2/2.")
87
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
88 "kkt",
89
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 make_function(&SolverKKT::get_kkt,
90 10 bp::return_value_policy<bp::copy_const_reference>()),
91 "kkt")
92
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
93 "kktref",
94
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 make_function(&SolverKKT::get_kktref,
95 10 bp::return_value_policy<bp::copy_const_reference>()),
96 "kktref")
97
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
98 "primaldual",
99
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 make_function(&SolverKKT::get_primaldual,
100 10 bp::return_value_policy<bp::copy_const_reference>()),
101 "primaldual")
102
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
103 "lambdas",
104
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 make_function(&SolverKKT::get_lambdas,
105 10 bp::return_value_policy<bp::copy_const_reference>()),
106 "lambdas")
107
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
108 "dxs",
109
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 make_function(&SolverKKT::get_dxs,
110 10 bp::return_value_policy<bp::copy_const_reference>()),
111 "dxs")
112
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
113 "dus",
114
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 make_function(&SolverKKT::get_dus,
115 10 bp::return_value_policy<bp::copy_const_reference>()),
116 "dus")
117
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<SolverKKT>());
118 10 }
119
120 } // namespace python
121 } // namespace crocoddyl
122