1 /* Test Pointset_Powerset<PH>::add_space_dimensions(),
2 Pointset_Powerset<PH>::remove_higher_space_dimensions(),
3 Pointset_Powerset<PH>::remove_space_dimensions(),
4 Pointset_Powerset<PH>::expand_space_dimensions(),
5 Pointset_Powerset<PH>::fold_space_dimensions().
6 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
7 Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
8
9 This file is part of the Parma Polyhedra Library (PPL).
10
11 The PPL is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
15
16 The PPL is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
24
25 For the most up-to-date information see the Parma Polyhedra Library
26 site: http://bugseng.com/products/ppl/ . */
27
28 #include "ppl_test.hh"
29
30 namespace {
31
32 // Powerset of C polyhedra: add_space_dimensions_and_embed(),
33 // add_space_dimensions_and_project().
34 bool
test01()35 test01() {
36 Variable x(0);
37
38 C_Polyhedron ph1(1);
39 ph1.add_constraint(x == 1);
40
41 C_Polyhedron ph2(1);
42 ph2.add_constraint(x <= 2);
43 Pointset_Powerset<C_Polyhedron> ps(1, EMPTY);
44
45 ps.add_disjunct(ph1);
46 ps.add_disjunct(ph2);
47
48 dimension_type m = 2;
49
50 ps.add_space_dimensions_and_embed(m);
51 bool ok = (ps.space_dimension() == 3 && ps.affine_dimension() == 3);
52
53 ps.add_space_dimensions_and_project(m);
54 bool ok1 = (ps.space_dimension() == 5 && ps.affine_dimension() == 3);
55
56 ps.remove_higher_space_dimensions(4);
57 bool ok2 = (ps.space_dimension() == 4 && ps.affine_dimension() == 3);
58
59 Pointset_Powerset<Rational_Box> psb(7, EMPTY);
60 Rational_Box b(7);
61 b.add_constraint(x >= 1);
62 b.add_constraint(x <= 0);
63 psb.add_disjunct(b);
64 bool ok3 = (psb.space_dimension() == 7 && psb.affine_dimension() == 0);
65
66 Pointset_Powerset<Grid> psg(7, EMPTY);
67 Grid g(7);
68 g.add_congruence((x %= 0) / 2);
69 g.add_congruence((x %= 1) / 2);
70 psg.add_disjunct(g);
71 bool ok4 = (psg.space_dimension() == 7 && psg.affine_dimension() == 0);
72
73 return ok && ok1 && ok2 && ok3 && ok4 && ps.OK();
74 }
75
76 // Powerset of C polyhedra: remove_higher_space_dimensions().
77 bool
test02()78 test02() {
79 Variable x(0);
80
81 C_Polyhedron ph1(1);
82 ph1.add_constraint(x == 1);
83
84 C_Polyhedron ph2(1);
85 ph2.add_constraint(x <= 2);
86 Pointset_Powerset<C_Polyhedron> ps(1, EMPTY);
87
88 ps.add_disjunct(ph1);
89 ps.add_disjunct(ph2);
90
91 dimension_type m = 2;
92
93 ps.add_space_dimensions_and_embed(m);
94 bool ok = (ps.space_dimension() == 3 && ps.affine_dimension() == 3);
95
96 ps.add_space_dimensions_and_project(m);
97 bool ok1 = (ps.space_dimension() == 5 && ps.affine_dimension() == 3);
98
99 ps.remove_higher_space_dimensions(4);
100 bool ok2 = (ps.space_dimension() == 4 && ps.affine_dimension() == 3);
101
102 Pointset_Powerset<Rational_Box> psb(7, EMPTY);
103 Rational_Box b(7);
104 b.add_constraint(x >= 1);
105 b.add_constraint(x <= 0);
106 psb.add_disjunct(b);
107 bool ok3 = (psb.space_dimension() == 7 && psb.affine_dimension() == 0);
108
109 Pointset_Powerset<Grid> psg(7, EMPTY);
110 Grid g(7);
111 g.add_congruence((x %= 0) / 2);
112 g.add_congruence((x %= 1) / 2);
113 psg.add_disjunct(g);
114 bool ok4 = (psg.space_dimension() == 7 && psg.affine_dimension() == 0);
115
116 return ok && ok1 && ok2 && ok3 && ok4 && ps.OK();
117 }
118
119 // Powerset of C polyhedra: remove_space_dimensions().
120 bool
test03()121 test03() {
122 Variable x(0);
123 Variable y(1);
124 Variable z(2);
125 Variable w(3);
126
127 C_Polyhedron ph1(4);
128 ph1.add_constraint(x == 1);
129 ph1.add_constraint(z == 1);
130
131 C_Polyhedron ph2(4);
132 ph2.add_constraint(x <= 2);
133 ph2.add_constraint(z == 1);
134 Pointset_Powerset<C_Polyhedron> ps(4, EMPTY);
135
136 ps.add_disjunct(ph1);
137 ps.add_disjunct(ph2);
138
139 Variables_Set to_be_removed;
140 to_be_removed.insert(y);
141 to_be_removed.insert(w);
142
143 ps.remove_space_dimensions(to_be_removed);
144 bool ok = (ps.space_dimension() == 2 && ps.affine_dimension() == 1);
145
146 return ok && ps.OK();
147 }
148
149 // Powerset of C polyhedra: expand_space_dimension().
150 bool
test04()151 test04() {
152 Variable x(0);
153 Variable y(1);
154 Variable z(2);
155 Variable w(3);
156
157 C_Polyhedron ph1(4);
158 ph1.add_constraint(x == 1);
159 ph1.add_constraint(z == 1);
160
161 C_Polyhedron ph2(4);
162 ph2.add_constraint(x <= 2);
163 ph2.add_constraint(z == 1);
164 Pointset_Powerset<C_Polyhedron> ps(4, EMPTY);
165
166 ps.add_disjunct(ph1);
167 ps.add_disjunct(ph2);
168
169 ps.expand_space_dimension(y, 2);
170 bool ok = (ps.space_dimension() == 6 && ps.affine_dimension() == 5);
171
172 return ok && ps.OK();
173 }
174
175 // Powerset of C polyhedra: fold_space_dimensions().
176 bool
test05()177 test05() {
178 Variable x(0);
179 Variable y(1);
180 Variable z(2);
181 Variable w(3);
182
183 C_Polyhedron ph1(4);
184 ph1.add_constraint(x == 1);
185 ph1.add_constraint(z == 1);
186
187 C_Polyhedron ph2(4);
188 ph2.add_constraint(x <= 2);
189 ph2.add_constraint(z == 1);
190 Pointset_Powerset<C_Polyhedron> ps(4, EMPTY);
191
192 ps.add_disjunct(ph1);
193 ps.add_disjunct(ph2);
194
195 Variables_Set to_be_folded;
196 to_be_folded.insert(y);
197 to_be_folded.insert(w);
198
199 ps.fold_space_dimensions(to_be_folded, z);
200 bool ok = (ps.space_dimension() == 2 && ps.affine_dimension() == 2);
201
202 return ok && ps.OK();
203 }
204
205 } // namespace
206
207 BEGIN_MAIN
208 DO_TEST(test01);
209 DO_TEST(test02);
210 DO_TEST(test03);
211 DO_TEST(test04);
212 DO_TEST(test05);
213 END_MAIN
214