test_Constraint.py
Go to the documentation of this file.
1 import numpy as np
2 import pinocchio as se3
3 import tsid
4 
5 print("")
6 print("Test Constraint Bound")
7 print("")
8 
9 
10 tol = 1e-5
11 n = 5
12 lb = -1.0 * np.ones(n)
13 ub = np.ones(n)
14 ConstBound = tsid.ConstraintBound("bounds", lb, ub)
15 
16 assert ConstBound.isBound
17 assert not ConstBound.isEquality
18 assert not ConstBound.isInequality
19 
20 assert ConstBound.rows == n
21 assert ConstBound.cols == n
22 
23 assert lb.all() == ConstBound.lowerBound.all()
24 assert ub.all() == ConstBound.upperBound.all()
25 
26 lb *= 2.0
27 assert np.linalg.norm(lb - ConstBound.lowerBound, 2) != 0
28 ConstBound.setLowerBound(lb)
29 assert lb.all() == ConstBound.lowerBound.all()
30 
31 ub *= 2.0
32 assert np.linalg.norm(ub - ConstBound.upperBound, 2) != 0
33 ConstBound.setUpperBound(ub)
34 assert ub.all() == ConstBound.upperBound.all()
35 assert np.linalg.norm(ub - ConstBound.upperBound, 2) < tol
36 
37 print("")
38 print("Test Constraint Equality")
39 print("")
40 n = 5
41 m = 2
42 A = np.ones((m, n))
43 b = np.ones(m)
44 equality = tsid.ConstraintEquality("equality", A, b)
45 
46 assert not equality.isBound
47 assert equality.isEquality
48 assert not equality.isInequality
49 
50 assert equality.rows == m
51 assert equality.cols == n
52 
53 assert np.linalg.norm(A - equality.matrix, 2) < tol
54 assert np.linalg.norm(b - equality.vector, 2) < tol
55 
56 b *= 2.0
57 assert np.linalg.norm(b - equality.vector, 2) != 0
58 equality.setVector(b)
59 assert np.linalg.norm(b - equality.vector, 2) < tol
60 
61 A *= 2.0
62 assert np.linalg.norm(A - equality.matrix, 2) != 0
63 equality.setMatrix(A)
64 assert np.linalg.norm(A - equality.matrix, 2) < tol
65 
66 print("")
67 print("Test Constraint Inequality")
68 print("")
69 
70 n = 5
71 m = 2
72 A = np.ones((m, n))
73 lb = -np.ones(m)
74 ub = np.ones(m)
75 inequality = tsid.ConstraintInequality("inequality", A, lb, ub)
76 
77 assert not inequality.isBound
78 assert not inequality.isEquality
79 assert inequality.isInequality
80 
81 assert inequality.rows == m
82 assert inequality.cols == n
83 
84 lb *= 2.0
85 assert np.linalg.norm(lb - inequality.lowerBound, 2) != 0
86 inequality.setLowerBound(lb)
87 assert np.linalg.norm(lb - inequality.lowerBound, 2) < tol
88 
89 A *= 2.0
90 assert np.linalg.norm(A - inequality.matrix, 2) != 0
91 inequality.setMatrix(A)
92 assert np.linalg.norm(A - inequality.matrix, 2) < tol
93 
94 print("All test is done")


tsid
Author(s): Andrea Del Prete, Justin Carpentier
autogenerated on Sun Jul 2 2023 02:21:51