Directory: | ./ |
---|---|
File: | include/tsid/bindings/python/solvers/solver-HQP-eiquadprog.hpp |
Date: | 2025-03-29 14:29:37 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 22 | 30 | 73.3% |
Branches: | 19 | 48 | 39.6% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2018 CNRS | ||
3 | // | ||
4 | // This file is part of tsid | ||
5 | // tsid is free software: you can redistribute it | ||
6 | // and/or modify it under the terms of the GNU Lesser General Public | ||
7 | // License as published by the Free Software Foundation, either version | ||
8 | // 3 of the License, or (at your option) any later version. | ||
9 | // tsid is distributed in the hope that it will be | ||
10 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
11 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | // General Lesser Public License for more details. You should have | ||
13 | // received a copy of the GNU Lesser General Public License along with | ||
14 | // tsid If not, see | ||
15 | // <http://www.gnu.org/licenses/>. | ||
16 | // | ||
17 | |||
18 | #ifndef __tsid_python_solver_quadprog_hpp__ | ||
19 | #define __tsid_python_solver_quadprog_hpp__ | ||
20 | |||
21 | #include "tsid/bindings/python/fwd.hpp" | ||
22 | |||
23 | #include "tsid/solvers/solver-HQP-eiquadprog.hpp" | ||
24 | #include "tsid/solvers/solver-HQP-eiquadprog-fast.hpp" | ||
25 | #include "tsid/solvers/solver-HQP-output.hpp" | ||
26 | #include "tsid/solvers/fwd.hpp" | ||
27 | #include "tsid/bindings/python/utils/container.hpp" | ||
28 | |||
29 | namespace tsid { | ||
30 | namespace python { | ||
31 | namespace bp = boost::python; | ||
32 | |||
33 | template <typename Solver> | ||
34 | struct SolverHQuadProgPythonVisitor | ||
35 | : public boost::python::def_visitor<SolverHQuadProgPythonVisitor<Solver> > { | ||
36 | template <class PyClass> | ||
37 | |||
38 | 32 | void visit(PyClass &cl) const { | |
39 |
2/4✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 16 times.
✗ Branch 6 not taken.
|
32 | cl.def(bp::init<const std::string &>((bp::arg("name")), |
40 | "Default Constructor with name")) | ||
41 | |||
42 |
2/4✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
64 | .def("resize", &SolverHQuadProgPythonVisitor::resize, |
43 | bp::args("n", "neq", "nin")) | ||
44 | 64 | .add_property("ObjVal", &Solver::getObjectiveValue, "return obj value") | |
45 |
3/6✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
|
64 | .def("solve", &SolverHQuadProgPythonVisitor::solve, bp::args("HQPData")) |
46 |
2/4✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
64 | .def("solve", &SolverHQuadProgPythonVisitor::solver_helper, |
47 | bp::args("HQPData for Python")) | ||
48 | 64 | .add_property("qpData", &Solver::getQPData, "return QP Data object") | |
49 |
2/4✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
64 | .def("retrieveQPData", &Solver::retrieveQPData, bp::args("HQPData")) |
50 |
3/6✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
|
32 | .def("retrieveQPData", &SolverHQuadProgPythonVisitor::retrieveQPData, |
51 | bp::args("HQPData for Python")); | ||
52 | 32 | } | |
53 | |||
54 | 4 | static void resize(Solver &self, unsigned int n, unsigned int neq, | |
55 | unsigned int nin) { | ||
56 | 4 | self.resize(n, neq, nin); | |
57 | } | ||
58 | ✗ | static solvers::HQPOutput solve(Solver &self, | |
59 | const solvers::HQPData &problemData) { | ||
60 | ✗ | solvers::HQPOutput output; | |
61 | ✗ | output = self.solve(problemData); | |
62 | ✗ | return output; | |
63 | } | ||
64 | 1100 | static solvers::HQPOutput solver_helper(Solver &self, HQPDatas &HQPDatas) { | |
65 | 2200 | solvers::HQPOutput output; | |
66 | 2200 | solvers::HQPData &data = HQPDatas.get(); | |
67 | |||
68 |
2/4✓ Branch 1 taken 1100 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1100 times.
✗ Branch 5 not taken.
|
2200 | output = self.solve(data); |
69 | |||
70 | 2200 | return output; | |
71 | } | ||
72 | |||
73 | ✗ | static solvers::QPDataQuadProg retrieveQPData(Solver &self, | |
74 | HQPDatas &HQPDatas) { | ||
75 | ✗ | solvers::HQPData data = HQPDatas.get(); | |
76 | ✗ | self.retrieveQPData(data); | |
77 | ✗ | return self.getQPData(); | |
78 | } | ||
79 | |||
80 | 32 | static void expose(const std::string &class_name) { | |
81 |
1/2✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
|
32 | std::string doc = "Solver EiQuadProg info."; |
82 |
1/2✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
|
32 | bp::class_<Solver>(class_name.c_str(), doc.c_str(), bp::no_init) |
83 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
32 | .def(SolverHQuadProgPythonVisitor<Solver>()); |
84 | 32 | } | |
85 | }; | ||
86 | } // namespace python | ||
87 | } // namespace tsid | ||
88 | |||
89 | #endif // ifndef __tsid_python_solver_quadprog_hpp__ | ||
90 |