15aed1699bb7eda9f1d8659041ebf4a4a049ba0a
1 #!/usr/bin/env python3
3 # This is the code example used in the tutorial. It shows how to define and
4 # manipulate polyhedra.
6 import code
9 class InteractiveConsole(code.InteractiveConsole):
10 def push(self, line=''):
11 if line:
12 print('>>>', line)
13 return super().push(line)
14 else:
15 print()
18 if __name__ == '__main__':
20 shell = InteractiveConsole()
22 shell.push('from linpy import *')
23 shell.push("x, y = symbols('x y')")
24 shell.push()
26 shell.push('square1 = Le(0, x, 2) & Le(0, y, 2)')
27 shell.push('square1')
28 shell.push()
30 shell.push("square2 = Polyhedron('1 <= x <= 3, 1 <= y <= 3')")
31 shell.push('square2')
32 shell.push()
34 shell.push('inter = square1.intersection(square2)')
35 shell.push('inter')
36 shell.push()
38 shell.push('hull = square1.convex_union(square2)')
39 shell.push('hull')
40 shell.push()
42 shell.push('square1.project([y])')
43 shell.push()
45 shell.push('inter <= square1')
46 shell.push('inter == Empty')
47 shell.push()
49 shell.push('union = square1 | square2')
50 shell.push('union')
51 shell.push('union <= hull')
52 shell.push()
54 shell.push('diff = square1 - square2')
55 shell.push('diff')
56 shell.push('~square1')