1 /* Test Polyhedron::add_space_dimensions_and_project()
2 and Polyhedron::add_space_dimensions_and_embed().
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 bool
test01()30 test01() {
31 Variable x(0);
32 Variable y(1);
33
34 Generator_System gs;
35 gs.insert(point());
36 gs.insert(point(x));
37 gs.insert(point(y));
38 gs.insert(point(x + y));
39
40 C_Polyhedron ph(gs);
41
42 print_generators(ph, "*** ph ***");
43
44 ph.add_space_dimensions_and_project(1);
45
46 C_Polyhedron known_result(3, EMPTY);
47 known_result.add_generator(point());
48 known_result.add_generator(point(x));
49 known_result.add_generator(point(y));
50 known_result.add_generator(point(x + y));
51
52 bool ok = (ph == known_result);
53
54 print_generators(ph, "*** after add_space_dimensions_and_project ***");
55
56 return ok;
57 }
58
59 bool
test02()60 test02() {
61 C_Polyhedron ph(3, EMPTY);
62
63 print_constraints(ph, "*** ph ***");
64
65 C_Polyhedron computed_result1(ph);
66 C_Polyhedron computed_result2(ph);
67
68 computed_result1.add_space_dimensions_and_project(4);
69 computed_result2.add_space_dimensions_and_embed(4);
70
71 C_Polyhedron known_result(7, EMPTY);
72
73 bool ok = (computed_result1 == known_result
74 && computed_result2 == known_result);
75
76 print_constraints(computed_result1, "*** computed_result1 ***");
77 print_constraints(computed_result2, "*** computed_result2 ***");
78
79 return ok;
80 }
81
82 bool
test03()83 test03() {
84 Variable x(0);
85 Variable y(1);
86 Variable z(2);
87 Variable u(3);
88 Variable v(4);
89 Variable w(5);
90
91 Generator_System gs;
92 gs.insert(point());
93 gs.insert(ray(x + y));
94
95 C_Polyhedron ph(gs);
96
97 print_generators(ph, "*** ph ***");
98
99 Constraint_System cs = ph.constraints();
100
101 ph.add_space_dimensions_and_embed(2);
102
103 print_generators(ph, "*** after add_space_dimensions_and_embed(2) ***");
104
105 ph.add_space_dimensions_and_embed(2);
106
107 C_Polyhedron known_result(6, EMPTY);
108 known_result.add_generator(point());
109 known_result.add_generator(ray(x + y));
110 known_result.add_generator(line(z));
111 known_result.add_generator(line(u));
112 known_result.add_generator(line(v));
113 known_result.add_generator(line(w));
114
115 bool ok = (ph == known_result);
116
117 print_generators(ph, "*** ph ***");
118
119 return ok;
120 }
121
122 bool
test04()123 test04() {
124 C_Polyhedron ph1;
125
126 print_generators(ph1, "*** ph1 ***");
127
128 ph1.add_space_dimensions_and_project(3);
129
130 print_generators(ph1, "*** after add_space_dimensions_and_project(3) ***");
131
132 C_Polyhedron ph2;
133 Constraint_System cs = ph2.constraints();
134
135 print_generators(ph2, "*** ph2 ***");
136
137 ph2.add_space_dimensions_and_project(3);
138
139 bool ok = (ph1 == ph2);
140
141 print_generators(ph2, "*** after add_space_dimensions_and_project(3) ***");
142
143 return ok;
144 }
145
146 bool
test05()147 test05() {
148 Variable C(2);
149
150 C_Polyhedron ph(2);
151
152 print_constraints(ph, "*** ph ***");
153
154 ph.add_space_dimensions_and_project(1);
155
156 C_Polyhedron known_result(3);
157 known_result.add_constraint(C == 0);
158
159 bool ok = (ph == known_result);
160
161 print_constraints(ph,
162 "*** after ph.add_space_dimensions_and_project(1) ***");
163
164 return ok;
165 }
166
167 bool
test06()168 test06() {
169 Variable A(0);
170
171 C_Polyhedron ph1(2);
172 ph1.add_constraint(A >= 0);
173 ph1.add_constraint(A <= 2);
174
175 C_Polyhedron ph2(ph1);
176
177 print_constraints(ph1, "*** ph1 ***");
178 print_constraints(ph2, "*** ph2 ***");
179
180 ph1.add_space_dimensions_and_embed(0);
181 ph2.add_space_dimensions_and_project(0);
182
183 bool ok = (ph1 == ph2);
184
185 print_constraints(ph1,
186 "*** after ph1.add_space_dimensions_and_embed(0) ***");
187 print_constraints(ph2,
188 "*** after ph2.add_space_dimensions_and_project(0) ***");
189
190 return ok;
191 }
192
193 } // namespace
194
195 BEGIN_MAIN
196 DO_TEST(test01);
197 DO_TEST(test02);
198 DO_TEST(test03);
199 DO_TEST(test04);
200 DO_TEST(test05);
201 DO_TEST(test06);
202 END_MAIN
203