codac4matlab 2.0.0.dev14__cp313-cp313-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codac4matlab/__init__.py +4 -0
- codac4matlab/_core.cp313-win32.pyd +0 -0
- codac4matlab/_graphics.cp313-win32.pyd +0 -0
- codac4matlab/_unsupported.cp313-win32.pyd +0 -0
- codac4matlab/core/__init__.py +340 -0
- codac4matlab/graphics/__init__.py +1 -0
- codac4matlab/tests/__init__.py +1 -0
- codac4matlab/tests/test_AnalyticFunction.py +419 -0
- codac4matlab/tests/test_AnalyticTraj.py +63 -0
- codac4matlab/tests/test_Approx.py +27 -0
- codac4matlab/tests/test_BoolInterval.py +40 -0
- codac4matlab/tests/test_Color.py +79 -0
- codac4matlab/tests/test_ConvexPolygon.py +207 -0
- codac4matlab/tests/test_CtcAction.py +30 -0
- codac4matlab/tests/test_CtcCartProd.py +39 -0
- codac4matlab/tests/test_CtcCtcBoundary.py +48 -0
- codac4matlab/tests/test_CtcFixpoint.py +65 -0
- codac4matlab/tests/test_CtcInter.py +39 -0
- codac4matlab/tests/test_CtcInverse.py +157 -0
- codac4matlab/tests/test_CtcInverseNotIn.py +129 -0
- codac4matlab/tests/test_CtcLazy.py +50 -0
- codac4matlab/tests/test_CtcPolygon.py +91 -0
- codac4matlab/tests/test_CtcSegment.py +104 -0
- codac4matlab/tests/test_Ellipsoid.py +20 -0
- codac4matlab/tests/test_IntFullPivLU.py +57 -0
- codac4matlab/tests/test_Interval.py +230 -0
- codac4matlab/tests/test_IntervalMatrix.py +664 -0
- codac4matlab/tests/test_IntervalVector.py +657 -0
- codac4matlab/tests/test_Interval_operations.py +293 -0
- codac4matlab/tests/test_Matrix.py +68 -0
- codac4matlab/tests/test_OctaSym.py +32 -0
- codac4matlab/tests/test_Polygon.py +108 -0
- codac4matlab/tests/test_SampledTraj.py +113 -0
- codac4matlab/tests/test_Segment.py +123 -0
- codac4matlab/tests/test_SepCartProd.py +34 -0
- codac4matlab/tests/test_SepCtcBoundary.py +52 -0
- codac4matlab/tests/test_SepInverse.py +104 -0
- codac4matlab/tests/test_SepPolygon.py +102 -0
- codac4matlab/tests/test_SepProj.py +39 -0
- codac4matlab/tests/test_SepTransform.py +41 -0
- codac4matlab/tests/test_Vector.py +41 -0
- codac4matlab/tests/test_arithmetic_add.py +54 -0
- codac4matlab/tests/test_arithmetic_div.py +46 -0
- codac4matlab/tests/test_arithmetic_mul.py +114 -0
- codac4matlab/tests/test_arithmetic_sub.py +54 -0
- codac4matlab/tests/test_capd.py +19 -0
- codac4matlab/tests/test_cart_prod.py +37 -0
- codac4matlab/tests/test_eigen.py +19 -0
- codac4matlab/tests/test_geometry.py +136 -0
- codac4matlab/tests/test_hull.py +35 -0
- codac4matlab/tests/test_ibex.py +19 -0
- codac4matlab/tests/test_inversion.py +57 -0
- codac4matlab/tests/test_linear_ctc.py +77 -0
- codac4matlab/tests/test_operators.py +348 -0
- codac4matlab/tests/test_transformations.py +61 -0
- codac4matlab/unsupported/__init__.py +1 -0
- codac4matlab/version.py +1 -0
- codac4matlab-2.0.0.dev14.dist-info/METADATA +23 -0
- codac4matlab-2.0.0.dev14.dist-info/RECORD +61 -0
- codac4matlab-2.0.0.dev14.dist-info/WHEEL +5 -0
- codac4matlab-2.0.0.dev14.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
class TestConvexPolygon(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
def tests_ConvexPolygon_degenerate_base(self):
|
|
16
|
+
|
|
17
|
+
p = ConvexPolygon([[1,2],[1,2]])
|
|
18
|
+
self.assertTrue(len(p.unsorted_vertices()) == 1)
|
|
19
|
+
|
|
20
|
+
p = ConvexPolygon([[1,3],[1,2],[1,2]])
|
|
21
|
+
self.assertTrue(len(p.unsorted_vertices()) == 2)
|
|
22
|
+
|
|
23
|
+
p = ConvexPolygon([[1,2],[1,3],[1,2],[1,2]])
|
|
24
|
+
self.assertTrue(len(p.unsorted_vertices()) == 2)
|
|
25
|
+
|
|
26
|
+
p = ConvexPolygon([[1,2],[1,3],[1,3],[1,2],[1,2]])
|
|
27
|
+
self.assertTrue(len(p.unsorted_vertices()) == 2)
|
|
28
|
+
|
|
29
|
+
self.assertTrue(len(convex_hull([[1,2],[1,2],[1,2]])) == 1)
|
|
30
|
+
p = ConvexPolygon([[1,2],[1,2],[1,2]])
|
|
31
|
+
self.assertTrue(len(p.unsorted_vertices()) == 1)
|
|
32
|
+
|
|
33
|
+
p = ConvexPolygon([[1,2],[1,3]])
|
|
34
|
+
self.assertTrue(len(p.unsorted_vertices()) == 2)
|
|
35
|
+
|
|
36
|
+
p = ConvexPolygon([[1,2],[1,3],[1,2]])
|
|
37
|
+
self.assertTrue(len(p.unsorted_vertices()) == 2)
|
|
38
|
+
|
|
39
|
+
p = ConvexPolygon([[1,2],[1,3],[1,2],[1,2]])
|
|
40
|
+
self.assertTrue(len(p.unsorted_vertices()) == 2)
|
|
41
|
+
|
|
42
|
+
p = ConvexPolygon([[1,2],[1,3],[1,3],[1,2]])
|
|
43
|
+
self.assertTrue(len(p.unsorted_vertices()) == 2)
|
|
44
|
+
|
|
45
|
+
def tests_ConvexPolygon_degenerate_cases(self):
|
|
46
|
+
|
|
47
|
+
p1 = ConvexPolygon([[0,4]])
|
|
48
|
+
self.assertTrue(len(p1.edges()) == 1)
|
|
49
|
+
self.assertTrue(p1.edges()[0][0] == IntervalVector([0,4]))
|
|
50
|
+
self.assertTrue(p1.edges()[0][1] == IntervalVector([0,4]))
|
|
51
|
+
|
|
52
|
+
p1 = ConvexPolygon([[0,4],[2,8]])
|
|
53
|
+
self.assertTrue(len(p1.edges()) == 1)
|
|
54
|
+
self.assertTrue(p1.edges()[0][0] == IntervalVector([0,4]))
|
|
55
|
+
self.assertTrue(p1.edges()[0][1] == IntervalVector([2,8]))
|
|
56
|
+
self.assertTrue(p1 == ConvexPolygon([[2,8],[0,4]]))
|
|
57
|
+
|
|
58
|
+
def tests_ConvexPolygon_intersection(self):
|
|
59
|
+
|
|
60
|
+
p1 = ConvexPolygon([[0,4],[4,8],[7,0]])
|
|
61
|
+
p2 = ConvexPolygon([[-1,2],[-1,3],[5,3],[5,2]])
|
|
62
|
+
self.assertTrue((p1 & p2) == ConvexPolygon([
|
|
63
|
+
[3.5,2],[5,2],[5,3],[1.75,3]
|
|
64
|
+
]))
|
|
65
|
+
|
|
66
|
+
p1 = ConvexPolygon([[3,2],[1,6],[6,5]])
|
|
67
|
+
p2 = ConvexPolygon(IntervalVector([[0,4],[0,4]]))
|
|
68
|
+
self.assertTrue((p1 & p2) == ConvexPolygon([
|
|
69
|
+
[3,2],[2,4],[4,4],[4,3]
|
|
70
|
+
]))
|
|
71
|
+
|
|
72
|
+
p1 = ConvexPolygon([[1,2],[3,4],[5,1],[2,1]])
|
|
73
|
+
p2 = ConvexPolygon(IntervalVector([[2,6],[2,6]]))
|
|
74
|
+
self.assertTrue(Approx(p1 & p2) == ConvexPolygon([
|
|
75
|
+
[2,2],[2,3],[3,4],[4.+1./3.,2.]
|
|
76
|
+
]))
|
|
77
|
+
|
|
78
|
+
# Big box
|
|
79
|
+
p1 = ConvexPolygon([[1,2],[3,4],[5,1],[2,1]])
|
|
80
|
+
p2 = ConvexPolygon(IntervalVector([[-10,10],[-10,10]]))
|
|
81
|
+
self.assertTrue((p1 & p2) == p1) # same polygon
|
|
82
|
+
|
|
83
|
+
# Inner box
|
|
84
|
+
p1 = ConvexPolygon([[1,2],[3,4],[5,1],[2,1]])
|
|
85
|
+
p2 = ConvexPolygon(IntervalVector([[2.8,3],[2.8,3]]))
|
|
86
|
+
self.assertTrue((p1 & p2) == p2) # same box
|
|
87
|
+
|
|
88
|
+
p1 = ConvexPolygon([[2,1],[3,1],[4,2],[4,3],[3,4],[2,4],[1,3],[1,2]])
|
|
89
|
+
p2 = ConvexPolygon(IntervalVector([[1,4],[1,4]]))
|
|
90
|
+
self.assertTrue((p1 & p2) == p1) # same polygon
|
|
91
|
+
|
|
92
|
+
# Shifted polygon points declaration
|
|
93
|
+
p1 = ConvexPolygon([[3,4],[2,4],[1,3],[1,2],[2,1],[3,1],[4,2],[4,3]])
|
|
94
|
+
p2 = ConvexPolygon(IntervalVector([[1,4],[1,4]]))
|
|
95
|
+
self.assertTrue((p1 & p2) == p1) # same polygon
|
|
96
|
+
|
|
97
|
+
# Degenerate case
|
|
98
|
+
p1 = ConvexPolygon([[4000,200]])
|
|
99
|
+
p2 = ConvexPolygon(IntervalVector([4000,200]))
|
|
100
|
+
self.assertTrue((p1 & p2) == p1) # same polygon
|
|
101
|
+
|
|
102
|
+
p1 = ConvexPolygon([[1,1],[2,4],[7,5],[6,2]])
|
|
103
|
+
p2 = ConvexPolygon(IntervalVector([[2,6],[1,5]]))
|
|
104
|
+
q = p1 & p2
|
|
105
|
+
self.assertTrue(Approx(q) == Polygon([[2,1.2],[6,2],[6,4.8],[2,4]]))
|
|
106
|
+
self.assertTrue(len(q.edges()) == 4)
|
|
107
|
+
self.assertTrue(len(q.unsorted_vertices()) == 4)
|
|
108
|
+
|
|
109
|
+
p1 = ConvexPolygon([[1,1],[2,4],[7,5],[6,2]])
|
|
110
|
+
p2 = ConvexPolygon(IntervalVector([[3,5],[1,5]]))
|
|
111
|
+
q = p1 & p2
|
|
112
|
+
self.assertTrue(Approx(q) == Polygon([[3,1.4],[5,1.8],[5,4.6],[3,4.2]]))
|
|
113
|
+
self.assertTrue(len(q.edges()) == 4)
|
|
114
|
+
self.assertTrue(len(q.unsorted_vertices()) == 4)
|
|
115
|
+
|
|
116
|
+
# Degenerated box
|
|
117
|
+
p1 = ConvexPolygon([[1,1],[2,4],[7,5],[6,2]])
|
|
118
|
+
p2 = ConvexPolygon(IntervalVector([[4],[1,5]]))
|
|
119
|
+
|
|
120
|
+
self.assertTrue(p1.edges()[0] == Segment([[1,1],[6,2]]))
|
|
121
|
+
self.assertTrue(p1.edges()[1] == Segment([[6,2],[7,5]]))
|
|
122
|
+
self.assertTrue(p1.edges()[2] == Segment([[7,5],[2,4]]))
|
|
123
|
+
self.assertTrue(p1.edges()[3] == Segment([[2,4],[1,1]]))
|
|
124
|
+
self.assertTrue(len(p1.edges()) == 4)
|
|
125
|
+
|
|
126
|
+
self.assertTrue(p2.edges()[0] == Segment([[4,1],[4,5]]))
|
|
127
|
+
self.assertTrue(len(p2.edges()) == 1)
|
|
128
|
+
|
|
129
|
+
self.assertTrue((p1.edges()[1] & p2.edges()[0]) == IntervalVector.empty(2))
|
|
130
|
+
self.assertTrue(Approx(p1.edges()[0] & p2.edges()[0]) == IntervalVector([4,1.6]))
|
|
131
|
+
self.assertTrue((p1.edges()[3] & p2.edges()[0]) == IntervalVector.empty(2))
|
|
132
|
+
self.assertTrue(Approx(p1.edges()[2] & p2.edges()[0]) == IntervalVector([4,4.4]))
|
|
133
|
+
|
|
134
|
+
q = p1 & p2
|
|
135
|
+
self.assertTrue(Approx(q) == Polygon([[4,4.4],[4,1.6]]))
|
|
136
|
+
self.assertTrue(len(q.unsorted_vertices()) == 2)
|
|
137
|
+
|
|
138
|
+
# Degenerated polygon
|
|
139
|
+
p1 = ConvexPolygon([[1,1],[2,4],[7,5],[6,2]])
|
|
140
|
+
p2 = ConvexPolygon([[4,1],[4,5]])
|
|
141
|
+
q = p1 & p2
|
|
142
|
+
self.assertTrue(Approx(q) == Polygon([[4,4.4],[4,1.6]]))
|
|
143
|
+
self.assertTrue(len(q.unsorted_vertices()) == 2)
|
|
144
|
+
|
|
145
|
+
# Point intersection
|
|
146
|
+
p1 = ConvexPolygon([[1,1],[2,4],[7,5],[6,2]])
|
|
147
|
+
p2 = ConvexPolygon([[2,4],[-4,4],[0,8]])
|
|
148
|
+
q = p1 & p2
|
|
149
|
+
self.assertTrue(q == Polygon([[2,4]]))
|
|
150
|
+
self.assertTrue(len(q.unsorted_vertices()) == 1)
|
|
151
|
+
|
|
152
|
+
# Point intersection, line polygon
|
|
153
|
+
p1 = ConvexPolygon([[1,1],[2,4],[7,5],[6,2]])
|
|
154
|
+
p2 = ConvexPolygon([[2,4],[-4,4]])
|
|
155
|
+
q = p1 & p2
|
|
156
|
+
self.assertTrue(q == Polygon([[2,4]]))
|
|
157
|
+
self.assertTrue(len(q.unsorted_vertices()) == 1)
|
|
158
|
+
|
|
159
|
+
# Empty intersection
|
|
160
|
+
p1 = ConvexPolygon([[1,1],[2,4],[7,5],[6,2]])
|
|
161
|
+
p2 = ConvexPolygon([[5,1.5],[8,2],[8,0],[5,0]])
|
|
162
|
+
q = p1 & p2
|
|
163
|
+
self.assertTrue(q == Polygon.empty())
|
|
164
|
+
self.assertTrue(len(q.unsorted_vertices()) == 0)
|
|
165
|
+
self.assertTrue(q.is_empty())
|
|
166
|
+
|
|
167
|
+
# Empty intersection, degenerate case
|
|
168
|
+
p1 = ConvexPolygon([[1,1],[2,4],[7,5],[6,2]])
|
|
169
|
+
p2 = ConvexPolygon([[5,1.5],[80,2]])
|
|
170
|
+
q = p1 & p2
|
|
171
|
+
self.assertTrue(q == Polygon.empty())
|
|
172
|
+
self.assertTrue(len(q.unsorted_vertices()) == 0)
|
|
173
|
+
self.assertTrue(q.is_empty())
|
|
174
|
+
|
|
175
|
+
# Intersection of empty polygons
|
|
176
|
+
p1 = ConvexPolygon.empty()
|
|
177
|
+
p2 = ConvexPolygon.empty()
|
|
178
|
+
q = p1 & p2
|
|
179
|
+
self.assertTrue(q == Polygon.empty())
|
|
180
|
+
self.assertTrue(q.is_empty())
|
|
181
|
+
|
|
182
|
+
# Intersection of a polygon and one empty polygon
|
|
183
|
+
p1 = ConvexPolygon([[1,1],[2,4],[7,5],[6,2]])
|
|
184
|
+
p2 = ConvexPolygon.empty()
|
|
185
|
+
q = p1 & p2
|
|
186
|
+
self.assertTrue(q == Polygon.empty())
|
|
187
|
+
self.assertTrue(q.is_empty())
|
|
188
|
+
|
|
189
|
+
# Intersection of a polygon and one empty polygon (line)
|
|
190
|
+
p1 = ConvexPolygon([[5,1.5],[80,2]])
|
|
191
|
+
p2 = ConvexPolygon.empty()
|
|
192
|
+
q = p1 & p2
|
|
193
|
+
self.assertTrue(q == Polygon.empty())
|
|
194
|
+
self.assertTrue(q.is_empty())
|
|
195
|
+
|
|
196
|
+
# Other test with inflated points
|
|
197
|
+
p1 = ConvexPolygon(IntervalVector([[-4,4],[-3,3]]))
|
|
198
|
+
a1,a2 = IntervalVector([-4,-6]), IntervalVector([-4,6])
|
|
199
|
+
a1.inflate(1e-10); a2.inflate(1e-10)
|
|
200
|
+
p2 = ConvexPolygon([Segment(a1,a2)])
|
|
201
|
+
q = p1 & p2
|
|
202
|
+
self.assertTrue(len(q.edges()) == 1)
|
|
203
|
+
self.assertTrue(Approx(q.edges()[0][0],1e-5) == IntervalVector([-4,-3]))
|
|
204
|
+
self.assertTrue(Approx(q.edges()[0][1],1e-5) == IntervalVector([-4,3]))
|
|
205
|
+
|
|
206
|
+
if __name__ == '__main__':
|
|
207
|
+
unittest.main()
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
class TestCtcAction(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
def tests_CtcAction(self):
|
|
16
|
+
|
|
17
|
+
x = VectorVar(2)
|
|
18
|
+
c1 = CtcInverse(AnalyticFunction([x], x-IntervalVector([[1,5],[8,6]])), IntervalVector([[0],[0]]))
|
|
19
|
+
|
|
20
|
+
b = IntervalVector(2)
|
|
21
|
+
c1.contract(b)
|
|
22
|
+
self.assertTrue(b == IntervalVector([[1,5],[8,6]]))
|
|
23
|
+
|
|
24
|
+
c2 = CtcAction(c1, [2,-1])
|
|
25
|
+
b = IntervalVector(2)
|
|
26
|
+
c2.contract(b)
|
|
27
|
+
self.assertTrue(b == IntervalVector([[8,6],[-5,1]]))
|
|
28
|
+
|
|
29
|
+
if __name__ == '__main__':
|
|
30
|
+
unittest.main()
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
class TestCtcCartProd(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
def tests_CtcCartProd(self):
|
|
16
|
+
|
|
17
|
+
v = VectorVar(1)
|
|
18
|
+
c1 = CtcInverse(AnalyticFunction([v], v), IntervalVector([[-1,1]]))
|
|
19
|
+
c2 = CtcInverse(AnalyticFunction([v], v), IntervalVector([[5,6]]))
|
|
20
|
+
|
|
21
|
+
a = IntervalVector(1)
|
|
22
|
+
b = IntervalVector(1)
|
|
23
|
+
c1.contract(a)
|
|
24
|
+
self.assertTrue(a == IntervalVector([[-1,1]]))
|
|
25
|
+
c2.contract(b)
|
|
26
|
+
self.assertTrue(b == IntervalVector([[5,6]]))
|
|
27
|
+
|
|
28
|
+
x = IntervalVector(2)
|
|
29
|
+
c3 = CtcCartProd(c1,c2)
|
|
30
|
+
c3.contract(x)
|
|
31
|
+
self.assertTrue(x == IntervalVector([[-1,1],[5,6]]))
|
|
32
|
+
|
|
33
|
+
y = IntervalVector(2)
|
|
34
|
+
c4 = cart_prod(c1,c2)
|
|
35
|
+
c4.contract(y)
|
|
36
|
+
self.assertTrue(y == IntervalVector([[-1,1],[5,6]]))
|
|
37
|
+
|
|
38
|
+
if __name__ == '__main__':
|
|
39
|
+
unittest.main()
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
def test_inside_diamond(x):
|
|
14
|
+
if (x[1] < x[0]+1) and (x[1] > x[0]-1) and (x[1] < -x[0]+1) and (x[1] > -x[0]-1):
|
|
15
|
+
return BoolInterval.TRUE
|
|
16
|
+
elif not(x[1] < x[0]+1) or not(x[1] > x[0]-1) or not(x[1] < -x[0]+1) or not(x[1] > -x[0]-1):
|
|
17
|
+
return BoolInterval.FALSE
|
|
18
|
+
else:
|
|
19
|
+
return BoolInterval.UNKNOWN
|
|
20
|
+
|
|
21
|
+
class TestCtcCtcBoundary(unittest.TestCase):
|
|
22
|
+
|
|
23
|
+
def tests_CtcCtcBoundary(self):
|
|
24
|
+
|
|
25
|
+
ctc_bound_diamond = CtcSegment([[-1],[0]], [[0],[-1]]) | CtcSegment([[0],[-1]], [[1],[0]]) \
|
|
26
|
+
| CtcSegment([[1],[0]], [[0],[1]]) | CtcSegment([[0],[1]], [[-1],[0]])
|
|
27
|
+
|
|
28
|
+
ctc_diamond = CtcCtcBoundary(ctc_bound_diamond,test_inside_diamond)
|
|
29
|
+
#draw_while_paving(IntervalVector([[-2,2],[-2,2]]), ctc_diamond, 0.1)
|
|
30
|
+
|
|
31
|
+
x = IntervalVector(2)
|
|
32
|
+
ctc_diamond.contract(x)
|
|
33
|
+
#self.assertTrue(x == IntervalVector([[-1,1],[-1,1]]))
|
|
34
|
+
|
|
35
|
+
x = IntervalVector([[0,10],[0,10]])
|
|
36
|
+
ctc_diamond.contract(x)
|
|
37
|
+
#self.assertTrue(x == IntervalVector([[0,1],[0,1]]))
|
|
38
|
+
|
|
39
|
+
x = IntervalVector([[0.2,10],[0.2,10]])
|
|
40
|
+
ctc_diamond.contract(x)
|
|
41
|
+
#self.assertTrue(x == IntervalVector([[0.2,0.8],[0.2,0.8]]))
|
|
42
|
+
|
|
43
|
+
x = IntervalVector([[0.5,10],[0.5,10]])
|
|
44
|
+
ctc_diamond.contract(x)
|
|
45
|
+
#self.assertTrue(x == IntervalVector([[0.5],[0.5]]))
|
|
46
|
+
|
|
47
|
+
if __name__ == '__main__':
|
|
48
|
+
unittest.main()
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CtcCustom(Ctc):
|
|
15
|
+
|
|
16
|
+
def __init__(self):
|
|
17
|
+
Ctc.__init__(self, 2)
|
|
18
|
+
|
|
19
|
+
def contract(self, x):
|
|
20
|
+
if x[0].rad() > 1.:
|
|
21
|
+
return IntervalVector(x.mid()).inflate(0.5*x.rad())
|
|
22
|
+
return x
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TestCtcFixpoint(unittest.TestCase):
|
|
26
|
+
|
|
27
|
+
def tests_CtcFixpoint(self):
|
|
28
|
+
|
|
29
|
+
ctc_custom = CtcCustom()
|
|
30
|
+
x = IntervalVector([[-1000,1000],[-1000,1000]])
|
|
31
|
+
x = ctc_custom.contract(x)
|
|
32
|
+
self.assertTrue(Approx(x) == IntervalVector([[-500,500],[-500,500]]))
|
|
33
|
+
x = ctc_custom.contract(x)
|
|
34
|
+
self.assertTrue(Approx(x) == IntervalVector([[-250,250],[-250,250]]))
|
|
35
|
+
x = ctc_custom.contract(x)
|
|
36
|
+
self.assertTrue(Approx(x) == IntervalVector([[-125,125],[-125,125]]))
|
|
37
|
+
|
|
38
|
+
ctc_fixed = CtcFixpoint(ctc_custom, 0.)
|
|
39
|
+
|
|
40
|
+
x = IntervalVector([[-1000,1000],[-1000,1000]])
|
|
41
|
+
ctc_fixed.contract(x)
|
|
42
|
+
self.assertTrue(Approx(x,1e-1) == IntervalVector([[-1,1],[-1,1]]))
|
|
43
|
+
x = IntervalVector([[-500,500],[-500,500]])
|
|
44
|
+
ctc_fixed.contract(x)
|
|
45
|
+
self.assertTrue(Approx(x,1e-1) == IntervalVector([[-1,1],[-1,1]]))
|
|
46
|
+
|
|
47
|
+
ctc_fixed = CtcFixpoint(ctc_custom, 0.8)
|
|
48
|
+
|
|
49
|
+
x = IntervalVector([[-1000,1000],[-1000,1000]])
|
|
50
|
+
ctc_fixed.contract(x)
|
|
51
|
+
self.assertTrue(Approx(x) == IntervalVector([[-500,500],[-500,500]]))
|
|
52
|
+
ctc_fixed.contract(x)
|
|
53
|
+
self.assertTrue(Approx(x) == IntervalVector([[-250,250],[-250,250]]))
|
|
54
|
+
|
|
55
|
+
ctc_fixed = CtcFixpoint(ctc_custom, 1.)
|
|
56
|
+
|
|
57
|
+
x = IntervalVector([[-1000,1000],[-1000,1000]])
|
|
58
|
+
ctc_fixed.contract(x)
|
|
59
|
+
self.assertTrue(Approx(x) == IntervalVector([[-500,500],[-500,500]]))
|
|
60
|
+
ctc_fixed.contract(x)
|
|
61
|
+
self.assertTrue(Approx(x) == IntervalVector([[-250,250],[-250,250]]))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if __name__ == '__main__':
|
|
65
|
+
unittest.main()
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
class TestCtcInter(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
def tests_CtcInter(self):
|
|
16
|
+
|
|
17
|
+
c1 = CtcWrapper([[-10,10],[-2,2]])
|
|
18
|
+
c2 = CtcWrapper([[-12,2],[0,4]])
|
|
19
|
+
|
|
20
|
+
c3 = c1 & c2
|
|
21
|
+
|
|
22
|
+
x = IntervalVector([[-oo,oo],[-oo,oo]])
|
|
23
|
+
c3.contract(x)
|
|
24
|
+
self.assertTrue(x == IntervalVector([[-10,2],[0,2]]))
|
|
25
|
+
|
|
26
|
+
x = IntervalVector([[-oo,0],[-oo,0]])
|
|
27
|
+
c3.contract(x)
|
|
28
|
+
self.assertTrue(x == IntervalVector([[-10,0],[0,0]]))
|
|
29
|
+
|
|
30
|
+
x = IntervalVector([[0,oo],[0,oo]])
|
|
31
|
+
c3.contract(x)
|
|
32
|
+
self.assertTrue(x == IntervalVector([[0,2],[0,2]]))
|
|
33
|
+
|
|
34
|
+
x = IntervalVector([[0,0],[0,0]])
|
|
35
|
+
c3.contract(x)
|
|
36
|
+
self.assertTrue(x == IntervalVector.zero(2))
|
|
37
|
+
|
|
38
|
+
if __name__ == '__main__':
|
|
39
|
+
unittest.main()
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
class TestCtcInverse(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
# not supported (yet) in Python; # Contractors based on functions with two variables
|
|
16
|
+
# not supported (yet) in Python; x = ScalarVar()
|
|
17
|
+
# not supported (yet) in Python; y = ScalarVar()
|
|
18
|
+
# not supported (yet) in Python; f = AnalyticFunction([x,y], x-y)
|
|
19
|
+
# not supported (yet) in Python; c = CtcInverse(f, Interval(0.))
|
|
20
|
+
|
|
21
|
+
def tests_CtcInverse_1(self):
|
|
22
|
+
|
|
23
|
+
x = VectorVar(2)
|
|
24
|
+
f = AnalyticFunction([x], x[0]-x[1])
|
|
25
|
+
c = CtcInverse(f, 0)
|
|
26
|
+
self.assertTrue(c.function().input_size() == 2)
|
|
27
|
+
|
|
28
|
+
b = IntervalVector(2)
|
|
29
|
+
|
|
30
|
+
c.contract(b)
|
|
31
|
+
self.assertTrue(b == IntervalVector(2))
|
|
32
|
+
|
|
33
|
+
b = IntervalVector([[1,2],[1,2]])
|
|
34
|
+
c.contract(b)
|
|
35
|
+
self.assertTrue(b == IntervalVector([[1,2],[1,2]]))
|
|
36
|
+
|
|
37
|
+
b = IntervalVector([[1,oo],[1,oo]])
|
|
38
|
+
c.contract(b)
|
|
39
|
+
self.assertTrue(b == IntervalVector([[1,oo],[1,oo]]))
|
|
40
|
+
|
|
41
|
+
b = IntervalVector([[10],[10]])
|
|
42
|
+
c.contract(b)
|
|
43
|
+
self.assertTrue(b == IntervalVector([[10],[10]]))
|
|
44
|
+
|
|
45
|
+
b = IntervalVector([[1,5],[8,9]])
|
|
46
|
+
c.contract(b)
|
|
47
|
+
self.assertTrue(b == IntervalVector.empty(2))
|
|
48
|
+
|
|
49
|
+
def tests_CtcInverse_2(self):
|
|
50
|
+
|
|
51
|
+
x = VectorVar(2)
|
|
52
|
+
f = AnalyticFunction([x], vec(x[0]-x[1]))
|
|
53
|
+
c = CtcInverse(f, [[0]])
|
|
54
|
+
|
|
55
|
+
b = IntervalVector(2)
|
|
56
|
+
|
|
57
|
+
c.contract(b)
|
|
58
|
+
self.assertTrue(b == IntervalVector(2))
|
|
59
|
+
|
|
60
|
+
b = IntervalVector([[1,2],[1,2]])
|
|
61
|
+
c.contract(b)
|
|
62
|
+
self.assertTrue(b == IntervalVector([[1,2],[1,2]]))
|
|
63
|
+
|
|
64
|
+
b = IntervalVector([[1,oo],[1,oo]])
|
|
65
|
+
c.contract(b)
|
|
66
|
+
self.assertTrue(b == IntervalVector([[1,oo],[1,oo]]))
|
|
67
|
+
|
|
68
|
+
b = IntervalVector([[10],[10]])
|
|
69
|
+
c.contract(b)
|
|
70
|
+
self.assertTrue(b == IntervalVector([[10],[10]]))
|
|
71
|
+
|
|
72
|
+
b = IntervalVector([[1,5],[8,9]])
|
|
73
|
+
c.contract(b)
|
|
74
|
+
self.assertTrue(b == IntervalVector.empty(2))
|
|
75
|
+
|
|
76
|
+
def tests_CtcInverse_3(self):
|
|
77
|
+
|
|
78
|
+
x = VectorVar(2)
|
|
79
|
+
f = AnalyticFunction([x], vec(x[0],sqr(x[0]/7.)+sqr(x[1]/3.)))
|
|
80
|
+
c = CtcInverse(f, [[0,oo],[1]])
|
|
81
|
+
|
|
82
|
+
b = IntervalVector([[0,0.8],[-2.28,-1.56]])
|
|
83
|
+
c.contract(b)
|
|
84
|
+
self.assertTrue(b == IntervalVector.empty(2))
|
|
85
|
+
|
|
86
|
+
b = IntervalVector([[4,5.4],[-0.05,2.45]])
|
|
87
|
+
c.contract(b)
|
|
88
|
+
self.assertTrue(Approx(b,1e-2) == IntervalVector([[4.0397,5.40],[1.9089,2.45]]))
|
|
89
|
+
|
|
90
|
+
b = IntervalVector([[6.25,6.7],[0.9,1.85]])
|
|
91
|
+
c.contract(b)
|
|
92
|
+
self.assertTrue(Approx(b,1e-2) == IntervalVector([[6.25,6.67],[0.9,1.351]]))
|
|
93
|
+
|
|
94
|
+
b = IntervalVector([[-6,-5],[0,2]])
|
|
95
|
+
c.contract(b)
|
|
96
|
+
self.assertTrue(b == IntervalVector.empty(2))
|
|
97
|
+
|
|
98
|
+
b = IntervalVector([[2,3],[-1,1]])
|
|
99
|
+
c.contract(b)
|
|
100
|
+
self.assertTrue(b == IntervalVector.empty(2))
|
|
101
|
+
|
|
102
|
+
def tests_CtcInverse_4(self):
|
|
103
|
+
|
|
104
|
+
x = VectorVar(2)
|
|
105
|
+
f = AnalyticFunction([x], vec(x[0],sqr(x[0]/7.)+sqr(x[1]/3.)))
|
|
106
|
+
c = CtcInverse(f, CtcWrapper([[0,oo],[1]]))
|
|
107
|
+
|
|
108
|
+
b = IntervalVector([[0,0.8],[-2.28,-1.56]])
|
|
109
|
+
c.contract(b)
|
|
110
|
+
self.assertTrue(b == IntervalVector.empty(2))
|
|
111
|
+
|
|
112
|
+
b = IntervalVector([[4,5.4],[-0.05,2.45]])
|
|
113
|
+
c.contract(b)
|
|
114
|
+
self.assertTrue(Approx(b,1e-2) == IntervalVector([[4.0397,5.40],[1.9089,2.45]]))
|
|
115
|
+
|
|
116
|
+
b = IntervalVector([[6.25,6.7],[0.9,1.85]])
|
|
117
|
+
c.contract(b)
|
|
118
|
+
self.assertTrue(Approx(b,1e-2) == IntervalVector([[6.25,6.67],[0.9,1.351]]))
|
|
119
|
+
|
|
120
|
+
b = IntervalVector([[-6,-5],[0,2]])
|
|
121
|
+
c.contract(b)
|
|
122
|
+
self.assertTrue(b == IntervalVector.empty(2))
|
|
123
|
+
|
|
124
|
+
b = IntervalVector([[2,3],[-1,1]])
|
|
125
|
+
c.contract(b)
|
|
126
|
+
self.assertTrue(b == IntervalVector.empty(2))
|
|
127
|
+
|
|
128
|
+
def tests_ParabolasExample(self):
|
|
129
|
+
|
|
130
|
+
u = ScalarVar()
|
|
131
|
+
v = ScalarVar()
|
|
132
|
+
a = VectorVar(4)
|
|
133
|
+
a0 = VectorVar(3); a1 = VectorVar(3); a2 = VectorVar(3)
|
|
134
|
+
b0 = VectorVar(3); b1 = VectorVar(3); b2 = VectorVar(3)
|
|
135
|
+
|
|
136
|
+
b = AnalyticFunction([u,a0,a1,a2], sqr(1-u)*a0+2*u*(1-u)*a1+sqr(u)*a2)
|
|
137
|
+
f = AnalyticFunction([u,v,a0,a1,a2,b0,b1,b2], (1-v)*b(u,a0,a1,a2)+v*b(u,b0,b1,b2))
|
|
138
|
+
|
|
139
|
+
h = AnalyticFunction([a],
|
|
140
|
+
f(a[0],a[1],
|
|
141
|
+
IntervalVector([[0],[0],[0]]),IntervalVector([[1],[0],[1]]),IntervalVector([[2],[0],[0]]),
|
|
142
|
+
IntervalVector([[0],[2],[0]]),IntervalVector([[1],[2],[1]]),IntervalVector([[2],[2],[0]]))
|
|
143
|
+
-f(a[2],a[3],
|
|
144
|
+
IntervalVector([[0],[0],[0.55]]),IntervalVector([[0],[1],[-0.45]]),IntervalVector([[0],[2],[0.55]]),
|
|
145
|
+
IntervalVector([[2],[0],[0.55]]),IntervalVector([[2],[1],[-0.45]]),IntervalVector([[2],[2],[0.55]]))
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
ctc = CtcInverse(h, [0,0,0])
|
|
149
|
+
x0 = [[0,1],[0,1],[0.05,0.18],[0.05,0.18]]
|
|
150
|
+
#draw_while_paving(x0, ctc, 0.001)
|
|
151
|
+
p = pave(x0, ctc, 0.01)
|
|
152
|
+
cs = p.connected_subsets()
|
|
153
|
+
self.assertTrue(len(cs) == 1)
|
|
154
|
+
self.assertTrue(Approx(cs[0].box(),1e-4) == [[0.149199,0.182388],[0.148306,0.1826],[0.148054,0.18],[0.148732,0.18]])
|
|
155
|
+
|
|
156
|
+
if __name__ == '__main__':
|
|
157
|
+
unittest.main()
|