1 /* Test C_Polyhedron::contains_integer_point().
2    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3    Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #include "ppl_test.hh"
25 
26 namespace {
27 
28 bool
test01()29 test01() {
30   Variable x(0);
31   Variable y(1);
32 
33   Constraint_System cs;
34   cs.insert(x >= 0);
35   cs.insert(x <= 1);
36   cs.insert(3*y <= 2);
37   cs.insert(3*y >= 1);
38 
39   C_Polyhedron ph(2);
40   ph.add_constraints(cs);
41 
42   print_constraints(ph, "*** ph ***");
43 
44   bool contains = ph.contains_integer_point();
45 
46   nout << "ph.contains_integer_point() == "
47        << (contains ? "true" : "false") << endl;
48 
49   return !contains;
50 }
51 
52 bool
test02()53 test02() {
54   Variable x(0);
55   Variable y(1);
56   Variable z(2);
57 
58   Constraint_System cs;
59   cs.insert(x >= 0);
60   cs.insert(x <= 1);
61   cs.insert(3*y - 3*z <= 2);
62   cs.insert(8*z - 8*y >= 7);
63 
64   C_Polyhedron ph(3);
65   ph.add_constraints(cs);
66 
67   print_constraints(ph, "*** ph ***");
68 
69   bool contains = ph.contains_integer_point();
70 
71   nout << "ph.contains_integer_point() == "
72        << (contains ? "true" : "false") << endl;
73 
74   return contains;
75 }
76 
77 bool
test03()78 test03() {
79   Variable x(0);
80   Variable y(1);
81 
82   Constraint_System cs;
83   cs.insert(3*x - 3*y >= 1);
84   cs.insert(3*x - 3*y <= 2);
85 
86   C_Polyhedron ph(2);
87   ph.add_constraints(cs);
88 
89   print_constraints(ph, "*** ph ***");
90 
91   bool contains = ph.contains_integer_point();
92 
93   nout << "ph.contains_integer_point() == "
94        << (contains ? "true" : "false") << endl;
95 
96   return !contains;
97 }
98 
99 bool
test04()100 test04() {
101   Variable x(0);
102   Variable y(1);
103 
104   Constraint_System cs;
105   cs.insert(3*x + 3*y >= 13);
106   cs.insert(3*x + 3*y < 15);
107 
108   NNC_Polyhedron ph(2);
109   ph.add_constraints(cs);
110 
111   print_constraints(ph, "*** ph ***");
112 
113   bool contains = ph.contains_integer_point();
114 
115   nout << "ph.contains_integer_point() == "
116        << (contains ? "true" : "false") << endl;
117 
118   return !contains;
119 }
120 
121 bool
test05()122 test05() {
123   C_Polyhedron ph(2);
124   ph.add_constraint(Linear_Expression(0) >= 1);
125 
126   print_constraints(ph, "*** ph ***");
127 
128   bool contains = ph.contains_integer_point();
129 
130   nout << "ph.contains_integer_point() == "
131        << (contains ? "true" : "false") << endl;
132 
133   return !contains;
134 }
135 
136 bool
test06()137 test06() {
138   NNC_Polyhedron ph(2);
139   ph.add_constraint(Linear_Expression(1) > 1);
140 
141   print_constraints(ph, "*** ph ***");
142 
143   bool contains = ph.contains_integer_point();
144 
145   nout << "ph.contains_integer_point() == "
146        << (contains ? "true" : "false") << endl;
147 
148   return !contains;
149 }
150 
151 bool
test07()152 test07() {
153   NNC_Polyhedron ph(2);
154   ph.add_constraint(Linear_Expression(1) >= 0);
155 
156   print_constraints(ph, "*** ph ***");
157 
158   bool contains = ph.contains_integer_point();
159 
160   nout << "ph.contains_integer_point() == "
161        << (contains ? "true" : "false") << endl;
162 
163   return contains;
164 }
165 
166 } // namespace
167 
168 BEGIN_MAIN
169   DO_TEST(test01);
170   DO_TEST(test02);
171   DO_TEST(test03);
172   DO_TEST(test04);
173   DO_TEST(test05);
174   DO_TEST(test06);
175   DO_TEST(test07);
176 END_MAIN
177