1 #!/usr/bin/env python3
3 """
4 This file is part of Linpy.
6 Linpy is free software: you can redistribute it and/or modify
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Linpy is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Linpy. If not, see <http://www.gnu.org/licenses/>.
18 """
20 from pypol import *
22 a, x, y, z = symbols('a x y z')
24 sq1 = Le(0, x) & Le(x, 2) & Le(0, y) & Le(y, 2)
25 sq2 = Le(2, x) & Le(x, 4) & Le(2, y) & Le(y, 4)
26 sq3 = Le(0, x) & Le(x, 3) & Le(0, y) & Le(y, 3)
27 sq4 = Le(1, x) & Le(x, 2) & Le(1, y) & Le(y, 2)
28 sq5 = Le(1, x) & Le(x, 2) & Le(1, y)
29 sq6 = Le(1, x) & Le(x, 2) & Le(1, y) & Le(y, 3)
30 sq7 = Le(0, x) & Le(x, 2) & Le(0, y) & Eq(z, 2) & Le(a, 3)
31 p = Le(2*x+1, y) & Le(-2*x-1, y) & Le(y, 1)
34 universe = Polyhedron([])
35 q = sq1 - sq2
36 e = Empty
38 print('sq1 =', sq1) #print correct square
39 print('sq2 =', sq2) #print correct square
40 print('sq3 =', sq3) #print correct square
41 print('sq4 =', sq4) #print correct square
42 print('universe =', universe) #print correct square
43 print()
44 print('¬sq1 =', ~sq1) #test complement
45 print()
46 print('sq1 + sq1 =', sq1 + sq2) #test addition
47 print('sq1 + sq2 =', Polyhedron(sq1 + sq2)) #test addition
48 print()
49 print('universe + universe =', universe + universe)#test addition
50 print('universe - universe =', universe - universe) #test subtraction
51 print()
52 print('sq2 - sq1 =', sq2 - sq1) #test subtraction
53 print('sq2 - sq1 =', Polyhedron(sq2 - sq1)) #test subtraction
54 print('sq1 - sq1 =', Polyhedron(sq1 - sq1)) #test subtraction
55 print()
56 print('sq1 ∩ sq2 =', sq1 & sq2) #test intersection
57 print('sq1 ∪ sq2 =', sq1 | sq2) #test union
58 print()
59 print('sq1 ⊔ sq2 =', Polyhedron(sq1 | sq2)) # test convex union
60 print()
61 print('check if sq1 and sq2 disjoint:', sq1.isdisjoint(sq2)) #should return false
62 print()
63 print('sq1 disjoint:', sq1.disjoint()) #make disjoint
64 print('sq2 disjoint:', sq2.disjoint()) #make disjoint
65 print()
66 print('is square 1 universe?:', sq1.isuniverse()) #test if square is universe
67 print('is u universe?:', universe.isuniverse()) #test if square is universe
68 print()
69 print('is sq1 a subset of sq2?:', sq1.issubset(sq2)) #test issubset()
70 print('is sq4 less than sq3?:', sq4.__lt__(sq3)) # test lt(), must be a strict subset
71 print()
72 print('lexographic min of sq1:', sq1.lexmin()) #test lexmin()
73 print('lexographic max of sq1:', sq1.lexmax()) #test lexmin()
74 print()
75 print('lexographic min of sq2:', sq2.lexmin()) #test lexmax()
76 print('lexographic max of sq2:', sq2.lexmax()) #test lexmax()
77 print()
78 print('Polyhedral hull of sq1 + sq2 is:', q.aspolyhedron()) #test polyhedral hull
79 print()
80 print('is sq1 bounded?', sq1.isbounded()) #unbounded should return True
81 print('is sq5 bounded?', sq5.isbounded()) #unbounded should return False
82 print()
83 print('sq6:', sq6)
84 print('sq6 simplified:', sq6.sample())
85 print()
86 print(universe.project([x]))
87 print('sq7 with out constraints involving y and a', sq7.project([a, z, x, y])) #drops dims that are passed
88 print()
89 print('sq1 has {} parameters'.format(sq1.num_parameters()))
90 print()
91 print('does sq1 constraints involve x?', sq1.involves_dims([x]))
92 print()
93 print('the verticies for s are:', p.vertices())
94 print()
95 print(p.plot())
97 # Copyright 2014 MINES ParisTech