1 /* Test NNC_Polyhedron Java test class of the Parma Polyhedra Library Java
2    interface.
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 import parma_polyhedra_library.*;
26 
27 public class NNC_Polyhedron_test1 {
28     static {
29         try {
30             System.loadLibrary("ppl_java");
31         }
32         catch (UnsatisfiedLinkError  e) {
33             System.out.println("Unable to load the library");
34             System.out.println(e.getMessage());
35             System.exit(-1);
36         }
37     }
38 
test01()39     public static boolean test01() {
40         Variable X = new Variable(0);
41         Variable Y = new Variable(1);
42         Variable Z = new Variable(2);
43         NNC_Polyhedron ph = new NNC_Polyhedron(3, Degenerate_Element.UNIVERSE);
44         Linear_Expression le_X = new Linear_Expression_Variable(X);
45         Linear_Expression le_Y = new Linear_Expression_Variable(Y);
46         Linear_Expression le_Z = new Linear_Expression_Variable(Z);
47         Linear_Expression le_2Y = le_Y.times(new Coefficient(2));
48         Linear_Expression le_5Z = le_Z.times(new Coefficient(5));
49         Linear_Expression le_7
50             = new Linear_Expression_Coefficient(new Coefficient(7));
51         Linear_Expression le_5
52             = new Linear_Expression_Coefficient(new Coefficient(5));
53         Linear_Expression lhs1 = le_X.sum(le_2Y.sum(le_5Z));
54         NNC_Polyhedron ph1
55             = new NNC_Polyhedron(3, Degenerate_Element.UNIVERSE);
56         ph1.add_constraint(new Constraint(lhs1,
57                                           Relation_Symbol.GREATER_OR_EQUAL,
58                                           le_7));
59         ph1.add_constraint(new Constraint(le_X,
60                                           Relation_Symbol.LESS_THAN,
61                                           le_5Z));
62         PPL_Test.println_if_noisy(ph1.constraints().toString());
63         Constraint c = new Constraint(le_5Z,
64                                       Relation_Symbol.GREATER_THAN,
65                                       le_X);
66         Poly_Con_Relation rel = ph1.relation_with(c);
67         return rel.implies(Poly_Con_Relation.is_included());
68     }
69 
test02()70     public static boolean test02() {
71         // Test if `minimized_constraints' returns an empty Constraint_System
72         // if the Polyhedron is built from universe with a dimension greater
73         // than zero.
74         Variable X = new Variable(0);
75         Variable Y = new Variable(1);
76         Variable Z = new Variable(2);
77         NNC_Polyhedron ph = new NNC_Polyhedron(3, Degenerate_Element.UNIVERSE);
78         Constraint_System cs = ph.minimized_constraints();
79         return cs.isEmpty();
80     }
81 
test03()82     public static boolean test03() {
83         // Test termination methods.
84         Variable X1 = new Variable(0);
85         Variable X2 = new Variable(1);
86         Variable XP1 = new Variable(2);
87         Variable XP2 = new Variable(3);
88         NNC_Polyhedron ph = new NNC_Polyhedron(4, Degenerate_Element.UNIVERSE);
89         Coefficient coeff_1 = new Coefficient(1);
90         Coefficient coeff_0 = new Coefficient(0);
91         Linear_Expression le_X1 = new Linear_Expression_Variable(X1);
92         Linear_Expression le_X2 = new Linear_Expression_Variable(X2);
93         Linear_Expression le_XP1 = new Linear_Expression_Variable(XP1);
94         Linear_Expression le_XP2 = new Linear_Expression_Variable(XP2);
95         Linear_Expression le_1 = new Linear_Expression_Coefficient(coeff_1);
96         Linear_Expression le_0 = new Linear_Expression_Coefficient(coeff_0);
97         Linear_Expression le_X1_difference_XP1 = le_X1.sum(le_XP1);
98         Constraint c_XP2_eq_1
99           = new Constraint(le_XP2, Relation_Symbol.EQUAL, le_1);
100         Constraint c_X1_geq_1
101           = new Constraint(le_X1, Relation_Symbol.GREATER_OR_EQUAL, le_1);
102         Constraint c_X1_minus_XP1_geq_1
103           = new Constraint(le_X1_difference_XP1, Relation_Symbol.GREATER_OR_EQUAL, le_1);
104         Constraint c_X2_leq_0
105           = new Constraint(le_X2, Relation_Symbol.LESS_OR_EQUAL, le_0);
106         ph.add_constraint(c_XP2_eq_1);
107         ph.add_constraint(c_X1_geq_1);
108         ph.add_constraint(c_X1_minus_XP1_geq_1);
109         ph.add_constraint(c_X2_leq_0);
110         return Termination.termination_test_MS_NNC_Polyhedron(ph);
111     }
112 
main(String[] args)113     public static void main(String[] args) {
114         Parma_Polyhedra_Library.initialize_library();
115         boolean test_result_ok =
116             Test_Executor.executeTests(NNC_Polyhedron_test1.class);
117         Parma_Polyhedra_Library.finalize_library();
118         if (!test_result_ok)
119             System.exit(1);
120         System.exit(0);
121     }
122 
123 }
124