1df6e3d21c608e9c1812e719fd310e75037d846f
4 This file is part of Linpy.
6 Linpy is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
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/>.
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([])
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
44 print('¬sq1 =', ~sq1
) #test complement
46 print('sq1 + sq1 =', sq1
+ sq2
) #test addition
47 print('sq1 + sq2 =', Polyhedron(sq1
+ sq2
)) #test addition
49 print('universe + universe =', universe
+ universe
)#test addition
50 print('universe - universe =', universe
- universe
) #test subtraction
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
56 print('sq1 ∩ sq2 =', sq1
& sq2
) #test intersection
57 print('sq1 ∪ sq2 =', sq1 | sq2
) #test union
59 print('sq1 ⊔ sq2 =', Polyhedron(sq1 | sq2
)) # test convex union
61 print('check if sq1 and sq2 disjoint:', sq1
.isdisjoint(sq2
)) #should return false
63 print('sq1 disjoint:', sq1
.disjoint()) #make disjoint
64 print('sq2 disjoint:', sq2
.disjoint()) #make disjoint
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
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
72 print('lexographic min of sq1:', sq1
.lexmin()) #test lexmin()
73 print('lexographic max of sq1:', sq1
.lexmax()) #test lexmin()
75 print('lexographic min of sq2:', sq2
.lexmin()) #test lexmax()
76 print('lexographic max of sq2:', sq2
.lexmax()) #test lexmax()
78 print('Polyhedral hull of sq1 + sq2 is:', q
.aspolyhedron()) #test polyhedral hull
80 print('is sq1 bounded?', sq1
.isbounded()) #unbounded should return True
81 print('is sq5 bounded?', sq5
.isbounded()) #unbounded should return False
84 print('sq6 simplified:', sq6
.sample())
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
89 print('sq1 has {} parameters'.format(sq1
.num_parameters()))
91 print('does sq1 constraints involve x?', sq1
.involves_dims([x
]))
93 print('the verticies for s are:', p
.vertices())
97 # Copyright 2014 MINES ParisTech