1 /* Test Pointset_Powerset<PH>::Pointset_Powerset(Box<T>),
2    Pointset_Powerset<PH>::Pointset_Powerset(Pointset_Powerset(Box<T>)).
3    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
4    Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
5 
6 This file is part of the Parma Polyhedra Library (PPL).
7 
8 The PPL is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 The PPL is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software Foundation,
20 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
21 
22 For the most up-to-date information see the Parma Polyhedra Library
23 site: http://bugseng.com/products/ppl/ . */
24 
25 #include "ppl_test.hh"
26 
27 namespace {
28 
29 // Constructs the powerset of polyhedra from a box.
30 bool
test01()31 test01() {
32   Variable x(0);
33   Variable y(1);
34 
35   Rational_Box box(2);
36   box.add_constraint(x >= 0);
37   box.add_constraint(2*x <= 1);
38   box.add_constraint(y >= 0);
39 
40   Pointset_Powerset<C_Polyhedron> pps(box);
41 
42   Pointset_Powerset<C_Polyhedron> known_pps(2);
43   known_pps.add_constraint(x >= 0);
44   known_pps.add_constraint(2*x <= 1);
45   known_pps.add_constraint(y >= 0);
46 
47   bool ok = (pps == known_pps);
48 
49   Pointset_Powerset<C_Polyhedron>::const_iterator i = pps.begin();
50   C_Polyhedron phi = i->pointset();
51   print_constraints(phi, "*** phi ***");
52 
53   return ok;
54 }
55 
56 // Constructs the powerset of polyhedra from an empty box.
57 bool
test02()58 test02() {
59   Variable x(0);
60   Variable y(1);
61 
62   Rational_Box box(2, EMPTY);
63 
64   Pointset_Powerset<C_Polyhedron> pps(box);
65 
66   Pointset_Powerset<C_Polyhedron> known_pps(2, EMPTY);
67 
68   bool ok = (pps == known_pps);
69 
70   return ok;
71 }
72 
73 // Constructs the powerset of polyhedra from a powerset of boxes.
74 bool
test03()75 test03() {
76   Variable x(0);
77   Variable y(1);
78 
79   Constraint_System cs;
80   cs.insert(x >= 1);
81   cs.insert(x <= 1);
82   cs.insert(y <= 0);
83   TBox box(cs);
84 
85   // The complexity should be ignored.
86   Pointset_Powerset<TBox> pps_box(box, POLYNOMIAL_COMPLEXITY);
87 
88   // The complexity should be ignored.
89   Pointset_Powerset<C_Polyhedron> pps(pps_box, POLYNOMIAL_COMPLEXITY);
90 
91   Pointset_Powerset<C_Polyhedron> known_pps(2);
92   known_pps.add_constraint(x == 1);
93   known_pps.add_constraint(y <= 0);
94 
95   bool ok = (pps == known_pps);
96 
97   Pointset_Powerset<C_Polyhedron>::const_iterator j = pps.begin();
98   C_Polyhedron phj = j->pointset();
99   print_constraints(phj, "*** pps disjunct ***");
100 
101   return ok;
102 }
103 
104 // Constructs the powerset of bd shapes from a box.
105 bool
test04()106 test04() {
107   Variable x(0);
108   Variable y(1);
109 
110   TBox box(2);
111   box.add_constraint(x >= 0);
112   box.add_constraint(y >= 0);
113 
114   // Complexity should be ignored.
115   Pointset_Powerset<TBD_Shape> pps(box, POLYNOMIAL_COMPLEXITY);
116 
117   Pointset_Powerset<TBD_Shape> known_pps(2);
118   known_pps.add_constraint(x >= 0);
119   known_pps.add_constraint(y >= 0);
120 
121   bool ok = (pps == known_pps);
122 
123   Pointset_Powerset<TBD_Shape>::const_iterator i = pps.begin();
124   TBD_Shape bdsi = i->pointset();
125   print_constraints(bdsi, "*** bdsi ***");
126 
127   return ok;
128 }
129 
130 // Constructs the powerset of bd shapes from an empty box.
131 bool
test05()132 test05() {
133   Variable x(0);
134   Variable y(1);
135 
136   TBox box(2, EMPTY);
137 
138   Pointset_Powerset<TBD_Shape> pps(box);
139 
140   Pointset_Powerset<TBD_Shape> known_pps(2, EMPTY);
141 
142   bool ok = (pps == known_pps);
143 
144   return ok;
145 }
146 
147 // Constructs the powerset of bd shapes from a powerset of boxes.
148 bool
test06()149 test06() {
150   Variable x(0);
151   Variable y(1);
152 
153   Constraint_System cs;
154   cs.insert(x >= 1);
155   cs.insert(y <= 0);
156   TBox box(cs);
157 
158   // The complexity should be ignored.
159   Pointset_Powerset<TBox> pps_box(box, POLYNOMIAL_COMPLEXITY);
160 
161   // The complexity should be ignored.
162   Pointset_Powerset<TBD_Shape> pps(pps_box, POLYNOMIAL_COMPLEXITY);
163 
164   Pointset_Powerset<TBD_Shape> known_pps(2);
165   known_pps.add_constraint(x >= 1);
166   known_pps.add_constraint(y <= 0);
167 
168   bool ok = (pps == known_pps);
169 
170   Pointset_Powerset<TBD_Shape>::const_iterator i_bds = pps.begin();
171   TBD_Shape bdsi = i_bds->pointset();
172   print_constraints(bdsi, "*** bdsi ***");
173 
174   return ok;
175 }
176 
177 // Constructs the powerset of octagonal_shapes from a box.
178 bool
test07()179 test07() {
180   Variable x(0);
181   Variable y(1);
182 
183   TBox box(2);
184   box.add_constraint(x >= 0);
185   box.add_constraint(y >= 0);
186 
187   // Complexity should be ignored.
188   Pointset_Powerset<TOctagonal_Shape> pps(box, POLYNOMIAL_COMPLEXITY);
189 
190   Pointset_Powerset<TOctagonal_Shape> known_pps(2);
191   known_pps.add_constraint(x >= 0);
192   known_pps.add_constraint(y >= 0);
193 
194   bool ok = (pps == known_pps);
195 
196   Pointset_Powerset<TOctagonal_Shape>::const_iterator i = pps.begin();
197   TOctagonal_Shape osi = i->pointset();
198   print_constraints(osi, "*** osi ***");
199 
200   return ok;
201 }
202 
203 // Constructs the powerset of octagonal_shapes from an empty box.
204 bool
test08()205 test08() {
206   Variable x(0);
207   Variable y(1);
208 
209   TBox box(2, EMPTY);
210 
211   Pointset_Powerset<TOctagonal_Shape> pps(box);
212 
213   Pointset_Powerset<TOctagonal_Shape> known_pps(2, EMPTY);
214 
215   bool ok = (pps == known_pps);
216 
217   return ok;
218 }
219 
220 // Constructs the powerset of octagonal_shapes from a powerset of boxes.
221 bool
test09()222 test09() {
223   Variable x(0);
224   Variable y(1);
225 
226   Constraint_System cs;
227   cs.insert(x >= 1);
228   cs.insert(y <= 0);
229   TBox box(cs);
230 
231   // The complexity should be ignored.
232   Pointset_Powerset<TBox> pps_box(box, POLYNOMIAL_COMPLEXITY);
233 
234   // The complexity should be ignored.
235   Pointset_Powerset<TOctagonal_Shape> pps(pps_box, POLYNOMIAL_COMPLEXITY);
236 
237   Pointset_Powerset<TOctagonal_Shape> known_pps(2);
238   known_pps.add_constraint(x >= 1);
239   known_pps.add_constraint(y <= 0);
240 
241   bool ok = (pps == known_pps);
242 
243   Pointset_Powerset<TOctagonal_Shape>::const_iterator i_os = pps.begin();
244   TOctagonal_Shape osi = i_os->pointset();
245   print_constraints(osi, "*** osi ***");
246 
247   return ok;
248 }
249 
250 // Constructs the powerset of boxes from a box.
251 bool
test10()252 test10() {
253   Variable x(0);
254   Variable y(1);
255   Variable z(2);
256   Variable w(3);
257 
258   TBox box(4);
259   box.add_constraint(x >= 2);
260   box.add_constraint(z == 1);
261 
262   Pointset_Powerset<TBox> pps1(box);
263   Pointset_Powerset<TBox> pps2(4, EMPTY);
264   pps2.add_disjunct(box);
265 
266   bool ok = (pps1 == pps2);
267 
268   print_constraints(box, "*** box ***");
269   Pointset_Powerset<TBox>::const_iterator i = pps1.begin();
270   TBox boxi = i->pointset();
271   print_constraints(boxi, "*** boxi ***");
272   Pointset_Powerset<TBox>::const_iterator i2 = pps2.begin();
273   TBox boxi2 = i2->pointset();
274   print_constraints(boxi2, "*** boxi2 ***");
275 
276   return ok && pps1.OK();
277 }
278 
279 // Constructs the powerset of boxes from an empty box.
280 bool
test11()281 test11() {
282   Variable x(0);
283   Variable y(1);
284 
285   Rational_Box box(2, EMPTY);
286 
287   Pointset_Powerset<TBox> pps(box);
288 
289   Pointset_Powerset<TBox> known_pps(2, EMPTY);
290 
291   bool ok = (pps == known_pps);
292 
293   return ok;
294 }
295 
296 // Constructs the powerset of boxes from a powerset of boxes.
297 bool
test12()298 test12() {
299   Variable x(0);
300   Variable y(1);
301 
302   Constraint_System cs;
303   cs.insert(x >= 1);
304   cs.insert(x <= 1);
305   cs.insert(y <= 0);
306   TBox box(cs);
307 
308   // The complexity should be ignored.
309   Pointset_Powerset<TBox> pps_box(box, POLYNOMIAL_COMPLEXITY);
310 
311   // The complexity should be ignored.
312   Pointset_Powerset<TBox> pps(pps_box, POLYNOMIAL_COMPLEXITY);
313 
314   Pointset_Powerset<TBox> known_pps(2);
315   known_pps.add_constraint(x == 1);
316   known_pps.add_constraint(y <= 0);
317 
318   bool ok = (pps == known_pps);
319 
320   Pointset_Powerset<TBox>::const_iterator j = pps.begin();
321   TBox boxj = j->pointset();
322   print_constraints(boxj, "*** pps disjunct ***");
323 
324   return ok;
325 }
326 
327 // Constructs the powerset of grids from a box.
328 bool
test13()329 test13() {
330   Variable x(0);
331   Variable y(1);
332 
333   Rational_Box box(2);
334   box.add_constraint(x >= 0);
335   box.add_constraint(2*x == 1);
336   box.add_constraint(y >= 0);
337 
338   Pointset_Powerset<Grid> pps(box);
339 
340   Pointset_Powerset<Grid> known_pps(2);
341   known_pps.add_constraint(2*x == 1);
342 
343   bool ok = (pps == known_pps);
344 
345   Pointset_Powerset<Grid>::const_iterator i = pps.begin();
346   Grid phi = i->pointset();
347   print_congruences(phi, "*** phi ***");
348 
349   return ok;
350 }
351 
352 // Constructs the powerset of grids from an empty box.
353 bool
test14()354 test14() {
355   Variable x(0);
356   Variable y(1);
357 
358   Rational_Box box(2, EMPTY);
359 
360   Pointset_Powerset<Grid> pps(box);
361 
362   Pointset_Powerset<Grid> known_pps(2, EMPTY);
363 
364   bool ok = (pps == known_pps);
365 
366   return ok;
367 }
368 
369 // Constructs the powerset of grids from a powerset of boxes.
370 bool
test15()371 test15() {
372   Variable x(0);
373   Variable y(1);
374 
375   Constraint_System cs;
376   cs.insert(x >= 1);
377   cs.insert(x <= 1);
378   cs.insert(y <= 0);
379   TBox box(cs);
380 
381   // The complexity should be ignored.
382   Pointset_Powerset<TBox> pps_box(box, POLYNOMIAL_COMPLEXITY);
383 
384   Pointset_Powerset<TBox>::const_iterator i_box = pps_box.begin();
385   TBox boxi = i_box->pointset();
386   print_constraints(boxi, "*** boxi ***");
387 
388   // The complexity should be ignored.
389   Pointset_Powerset<Grid> pps(pps_box, POLYNOMIAL_COMPLEXITY);
390 
391   Pointset_Powerset<Grid> known_pps(2);
392   known_pps.add_constraint(x == 1);
393 
394   bool ok = (pps == known_pps);
395 
396   Pointset_Powerset<Grid>::const_iterator i_gr = pps.begin();
397   Grid gri = i_gr->pointset();
398   print_congruences(gri, "*** gri ***");
399 
400   return ok;
401 }
402 
403 } // namespace
404 
405 BEGIN_MAIN
406   DO_TEST(test01);
407   DO_TEST(test02);
408   DO_TEST(test03);
409   DO_TEST(test04);
410   DO_TEST(test05);
411   DO_TEST(test06);
412   DO_TEST(test07);
413   DO_TEST(test08);
414   DO_TEST(test09);
415   DO_TEST(test10);
416   DO_TEST(test11);
417   DO_TEST(test12);
418   DO_TEST(test13);
419   DO_TEST(test14);
420   DO_TEST(test15);
421 END_MAIN
422