GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/tsid/bindings/python/utils/container.hpp Lines: 51 57 89.5 %
Date: 2024-05-10 01:36:27 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
2
    stringstream ss;
41
5
    for (ConstraintLevel::const_iterator iit = m_std_const.begin();
42
8
         iit != m_std_const.end(); iit++) {
43
6
      auto c = iit->second;
44



3
      ss << " - " << c->name() << ": w=" << iit->first << ", ";
45

3
      if (c->isEquality())
46
2
        ss << "equality, ";
47

1
      else if (c->isInequality())
48
1
        ss << "inequality, ";
49
      else
50
        ss << "bound, ";
51



3
      ss << c->rows() << "x" << c->cols() << endl;
52
    }
53

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
2
    m_std_const.push_back(
60
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
    m_std_const.push_back(
66
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
2
    stringstream ss;
89
2
    unsigned int priority = 0;
90
6
    for (HQPData::const_iterator it = m_std_hqp.begin(); it != m_std_hqp.end();
91
4
         it++) {
92

4
      ss << "Level " << priority << endl;
93
17
      for (ConstraintLevel::const_iterator iit = it->begin(); iit != it->end();
94
13
           iit++) {
95
26
        auto c = iit->second;
96



13
        ss << " - " << c->name() << ": w=" << iit->first << ", ";
97

13
        if (c->isEquality())
98
10
          ss << "equality, ";
99

3
        else if (c->isInequality())
100
3
          ss << "inequality, ";
101
        else
102
          ss << "bound, ";
103



13
        ss << c->rows() << "x" << c->cols() << endl;
104
      }
105
4
      priority++;
106
    }
107

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__