Directory: | ./ |
---|---|
File: | include/tsid/bindings/python/utils/container.hpp |
Date: | 2024-11-10 01:12:44 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 53 | 59 | 89.8% |
Branches: | 59 | 116 | 50.9% |
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_util_container_hpp__ | ||
19 | #define __tsid_python_util_container_hpp__ | ||
20 | |||
21 | #include "tsid/bindings/python/fwd.hpp" | ||
22 | |||
23 | #include "tsid/solvers/fwd.hpp" | ||
24 | #include "tsid/math/constraint-equality.hpp" | ||
25 | #include "tsid/math/constraint-inequality.hpp" | ||
26 | #include "tsid/math/constraint-bound.hpp" | ||
27 | |||
28 | using namespace std; | ||
29 | namespace tsid { | ||
30 | namespace python { | ||
31 | typedef solvers::ConstraintLevel ConstraintLevel; | ||
32 | typedef solvers::HQPData HQPData; | ||
33 | |||
34 | class ConstraintLevels { | ||
35 | public: | ||
36 | 2 | ConstraintLevels() {} | |
37 | 2 | ~ConstraintLevels() {} | |
38 | |||
39 | 2 | inline void print() { | |
40 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | stringstream ss; |
41 | 2 | for (ConstraintLevel::const_iterator iit = m_std_const.begin(); | |
42 |
2/2✓ Branch 3 taken 3 times.
✓ Branch 4 taken 2 times.
|
5 | iit != m_std_const.end(); iit++) { |
43 | 3 | auto c = iit->second; | |
44 |
6/12✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
|
3 | ss << " - " << c->name() << ": w=" << iit->first << ", "; |
45 |
3/4✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
|
3 | if (c->isEquality()) |
46 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | ss << "equality, "; |
47 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | else if (c->isInequality()) |
48 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | ss << "inequality, "; |
49 | else | ||
50 | ✗ | ss << "bound, "; | |
51 |
6/12✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
|
3 | ss << c->rows() << "x" << c->cols() << endl; |
52 | 3 | } | |
53 |
3/6✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
|
2 | cout << ss.str() << endl; |
54 | 2 | } | |
55 | 2 | inline ConstraintLevel& get() { return m_std_const; } | |
56 | |||
57 | 2 | inline void append_eq(double num, | |
58 | std::shared_ptr<math::ConstraintEquality> i) { | ||
59 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | m_std_const.push_back( |
60 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | solvers::make_pair<double, std::shared_ptr<math::ConstraintBase> >(num, |
61 | i)); | ||
62 | 2 | } | |
63 | 1 | inline void append_ineq(double num, | |
64 | std::shared_ptr<math::ConstraintInequality> i) { | ||
65 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | m_std_const.push_back( |
66 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | solvers::make_pair<double, std::shared_ptr<math::ConstraintBase> >(num, |
67 | i)); | ||
68 | 1 | } | |
69 | ✗ | inline void append_bound(double num, | |
70 | std::shared_ptr<math::ConstraintBound> i) { | ||
71 | ✗ | m_std_const.push_back( | |
72 | ✗ | solvers::make_pair<double, std::shared_ptr<math::ConstraintBase> >(num, | |
73 | i)); | ||
74 | } | ||
75 | |||
76 | private: | ||
77 | ConstraintLevel m_std_const; | ||
78 | }; | ||
79 | |||
80 | class HQPDatas { | ||
81 | public: | ||
82 | 1002 | HQPDatas() {} | |
83 | 2003 | ~HQPDatas() {} | |
84 | |||
85 | ✗ | inline void resize(size_t i) { m_std_hqp.resize(i); } | |
86 | |||
87 | 2 | inline void print() const { | |
88 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | stringstream ss; |
89 | 2 | unsigned int priority = 0; | |
90 |
2/2✓ Branch 3 taken 4 times.
✓ Branch 4 taken 2 times.
|
6 | for (HQPData::const_iterator it = m_std_hqp.begin(); it != m_std_hqp.end(); |
91 | 4 | it++) { | |
92 |
3/6✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
|
4 | ss << "Level " << priority << endl; |
93 |
2/2✓ Branch 5 taken 13 times.
✓ Branch 6 taken 4 times.
|
17 | for (ConstraintLevel::const_iterator iit = it->begin(); iit != it->end(); |
94 | 13 | iit++) { | |
95 | 13 | auto c = iit->second; | |
96 |
6/12✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 13 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 13 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 13 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 13 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 13 times.
✗ Branch 19 not taken.
|
13 | ss << " - " << c->name() << ": w=" << iit->first << ", "; |
97 |
3/4✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 3 times.
|
13 | if (c->isEquality()) |
98 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | ss << "equality, "; |
99 |
2/4✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | else if (c->isInequality()) |
100 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | ss << "inequality, "; |
101 | else | ||
102 | ✗ | ss << "bound, "; | |
103 |
6/12✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 13 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 13 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 13 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 13 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 13 times.
✗ Branch 19 not taken.
|
13 | ss << c->rows() << "x" << c->cols() << endl; |
104 | 13 | } | |
105 | 4 | priority++; | |
106 | } | ||
107 |
3/6✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
|
2 | cout << ss.str() << endl; |
108 | 2 | } | |
109 | // inline void append (ConstraintLevel cons){ | ||
110 | // m_std_hqp.push_back(cons); | ||
111 | // } | ||
112 | 2 | inline void append_helper(ConstraintLevels* cons) { | |
113 | 2 | m_std_hqp.push_back(cons->get()); | |
114 | 2 | } | |
115 | |||
116 | 1100 | inline HQPData& get() { return m_std_hqp; } | |
117 | 1001 | inline bool set(const HQPData& data) { | |
118 | 1001 | m_std_hqp = data; | |
119 | 1001 | return true; | |
120 | } | ||
121 | |||
122 | private: | ||
123 | HQPData m_std_hqp; | ||
124 | }; | ||
125 | } // namespace python | ||
126 | } // namespace tsid | ||
127 | |||
128 | #endif // ifndef __tsid_python_util_container_hpp__ | ||
129 |