constraints.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2017 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 #include <iostream>
19 
20 #include <boost/test/unit_test.hpp>
21 #include <boost/utility/binary.hpp>
22 
26 
27 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
28 
29 BOOST_AUTO_TEST_CASE(test_constraint_bounds) {
30  std::cout << "test_constraint_bounds\n";
31  using namespace tsid::math;
32  using namespace Eigen;
33  const unsigned int n = 5;
34 
35  VectorXd lb = -1.0 * VectorXd::Ones(n);
36  VectorXd ub = VectorXd::Ones(n);
37  ConstraintBound bounds("bounds", lb, ub);
38 
39  BOOST_CHECK(bounds.isBound());
40  BOOST_CHECK(!bounds.isEquality());
41  BOOST_CHECK(!bounds.isInequality());
42 
43  BOOST_CHECK(bounds.rows() == n);
44  BOOST_CHECK(bounds.cols() == n);
45 
46  BOOST_CHECK(lb.isApprox(bounds.lowerBound()));
47  BOOST_CHECK(ub.isApprox(bounds.upperBound()));
48 
49  lb *= 2.0;
50  BOOST_CHECK(!lb.isApprox(bounds.lowerBound()));
51  bounds.setLowerBound(lb);
52  BOOST_CHECK(lb.isApprox(bounds.lowerBound()));
53 
54  ub *= 2.0;
55  BOOST_CHECK(!ub.isApprox(bounds.upperBound()));
56  bounds.setUpperBound(ub);
57  BOOST_CHECK(ub.isApprox(bounds.upperBound()));
58 }
59 
60 BOOST_AUTO_TEST_CASE(test_constraint_equality) {
61  using namespace tsid::math;
62  using namespace Eigen;
63  using namespace std;
64 
65  const unsigned int n = 5;
66  const unsigned int m = 2;
67 
68  MatrixXd A = MatrixXd::Ones(m, n);
69  VectorXd b = VectorXd::Ones(m);
70  ConstraintEquality equality("equality", A, b);
71 
72  BOOST_CHECK(!equality.isBound());
73  BOOST_CHECK(equality.isEquality());
74  BOOST_CHECK(!equality.isInequality());
75 
76  BOOST_CHECK(equality.rows() == m);
77  BOOST_CHECK(equality.cols() == n);
78 
79  BOOST_CHECK(A.isApprox(equality.matrix()));
80  BOOST_CHECK(b.isApprox(equality.vector()));
81 
82  b *= 2.0;
83  BOOST_CHECK(!b.isApprox(equality.vector()));
84  equality.setVector(b);
85  BOOST_CHECK(b.isApprox(equality.vector()));
86 
87  A *= 2.0;
88  BOOST_CHECK(!A.isApprox(equality.matrix()));
89  equality.setMatrix(A);
90  BOOST_CHECK(A.isApprox(equality.matrix()));
91 }
92 
93 BOOST_AUTO_TEST_CASE(test_constraint_inequality) {
94  using namespace tsid::math;
95  using namespace Eigen;
96  using namespace std;
97 
98  const unsigned int n = 5;
99  const unsigned int m = 2;
100 
101  MatrixXd A = MatrixXd::Ones(m, n);
102  VectorXd lb = -1.0 * VectorXd::Ones(m);
103  VectorXd ub = VectorXd::Ones(m);
104  ConstraintInequality inequality("inequality", A, lb, ub);
105 
106  BOOST_CHECK(!inequality.isBound());
107  BOOST_CHECK(!inequality.isEquality());
108  BOOST_CHECK(inequality.isInequality());
109 
110  BOOST_CHECK(inequality.rows() == m);
111  BOOST_CHECK(inequality.cols() == n);
112 
113  BOOST_CHECK(A.isApprox(inequality.matrix()));
114  BOOST_CHECK(lb.isApprox(inequality.lowerBound()));
115  BOOST_CHECK(ub.isApprox(inequality.upperBound()));
116 
117  lb *= 2.0;
118  BOOST_CHECK(!lb.isApprox(inequality.lowerBound()));
119  inequality.setLowerBound(lb);
120  BOOST_CHECK(lb.isApprox(inequality.lowerBound()));
121 
122  A *= 2.0;
123  BOOST_CHECK(!A.isApprox(inequality.matrix()));
124  inequality.setMatrix(A);
125  BOOST_CHECK(A.isApprox(inequality.matrix()));
126 }
127 
128 BOOST_AUTO_TEST_SUITE_END()
ex_4_plan_LIPM_romeo.A
A
Definition: ex_4_plan_LIPM_romeo.py:110
Eigen
test_Constraint.ub
ub
Definition: test_Constraint.py:13
tsid::math::ConstraintEquality
Definition: math/constraint-equality.hpp:26
tsid::math::ConstraintBound
Definition: math/constraint-bound.hpp:26
constraint-equality.hpp
test_Constraint.inequality
inequality
Definition: test_Constraint.py:75
tsid::math
Definition: constraint-base.hpp:26
b
Vec3f b
test_Constraint.equality
equality
Definition: test_Constraint.py:44
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_constraint_bounds)
Definition: constraints.cpp:29
test_Constraint.lb
float lb
Definition: test_Constraint.py:12
tsid::math::ConstraintInequality
Definition: math/constraint-inequality.hpp:26
constraint-inequality.hpp
std
test_Constraint.m
int m
Definition: test_Constraint.py:41
constraint-bound.hpp
bounds
tuple bounds
n
Vec3f n


tsid
Author(s): Andrea Del Prete, Justin Carpentier
autogenerated on Thu Apr 3 2025 02:47:15