5 a
, x
, y
, z
= symbols('a x y z')
7 sq1
= Le(0, x
) & Le(x
, 2) & Le(0, y
) & Le(y
, 2)
8 sq2
= Le(2, x
) & Le(x
, 4) & Le(2, y
) & Le(y
, 4)
9 sq3
= Le(0, x
) & Le(x
, 3) & Le(0, y
) & Le(y
, 3)
10 sq4
= Le(1, x
) & Le(x
, 2) & Le(1, y
) & Le(y
, 2)
11 sq5
= Le(1, x
) & Le(x
, 2) & Le(1, y
)
12 sq6
= Le(1, x
) & Le(x
, 2) & Le(1, y
) & Le(y
, 3)
13 sq7
= Le(0, x
) & Le(x
, 2) & Le(0, y
) & Eq(z
, 2) & Le(a
, 3)
14 p
= Le(2*x
+1, y
) & Le(-2*x
-1, y
) & Le(y
, 1)
17 universe
= Polyhedron([])
21 print('sq1 =', sq1
) #print correct square
22 print('sq2 =', sq2
) #print correct square
23 print('sq3 =', sq3
) #print correct square
24 print('sq4 =', sq4
) #print correct square
25 print('universe =', universe
) #print correct square
27 print('¬sq1 =', ~sq1
) #test complement
29 print('sq1 + sq1 =', sq1
+ sq2
) #test addition
30 print('sq1 + sq2 =', Polyhedron(sq1
+ sq2
)) #test addition
32 print('universe + universe =', universe
+ universe
)#test addition
33 print('universe - universe =', universe
- universe
) #test subtraction
35 print('sq2 - sq1 =', sq2
- sq1
) #test subtraction
36 print('sq2 - sq1 =', Polyhedron(sq2
- sq1
)) #test subtraction
37 print('sq1 - sq1 =', Polyhedron(sq1
- sq1
)) #test subtraction
39 print('sq1 ∩ sq2 =', sq1
& sq2
) #test intersection
40 print('sq1 ∪ sq2 =', sq1 | sq2
) #test union
42 print('sq1 ⊔ sq2 =', Polyhedron(sq1 | sq2
)) # test convex union
44 print('check if sq1 and sq2 disjoint:', sq1
.isdisjoint(sq2
)) #should return false
46 print('sq1 disjoint:', sq1
.disjoint()) #make disjoint
47 print('sq2 disjoint:', sq2
.disjoint()) #make disjoint
49 print('is square 1 universe?:', sq1
.isuniverse()) #test if square is universe
50 print('is u universe?:', universe
.isuniverse()) #test if square is universe
52 print('is sq1 a subset of sq2?:', sq1
.issubset(sq2
)) #test issubset()
53 print('is sq4 less than sq3?:', sq4
.__lt__(sq3
)) # test lt(), must be a strict subset
55 print('lexographic min of sq1:', sq1
.lexmin()) #test lexmin()
56 print('lexographic max of sq1:', sq1
.lexmax()) #test lexmin()
58 print('lexographic min of sq2:', sq2
.lexmin()) #test lexmax()
59 print('lexographic max of sq2:', sq2
.lexmax()) #test lexmax()
61 print('Polyhedral hull of sq1 + sq2 is:', q
.aspolyhedron()) #test polyhedral hull
63 print('is sq1 bounded?', sq1
.isbounded()) #unbounded should return True
64 print('is sq5 bounded?', sq5
.isbounded()) #unbounded should return False
67 print('sq6 simplified:', sq6
.sample())
69 print(universe
.project([x
]))
70 print('sq7 with out constraints involving y and a', sq7
.project([a
, z
, x
, y
])) #drops dims that are passed
72 print('sq1 has {} parameters'.format(sq1
.num_parameters()))
74 print('does sq1 constraints involve x?', sq1
.involves_dims([x
]))
76 print('the verticies for s are:', p
.vertices())