X-Git-Url: https://svn.cri.ensmp.fr/git/linpy.git/blobdiff_plain/5de84d8c67faaedde2ecd0eb8dda080b38f86023..75b826058dcbdb53fea2ed5258b59e806b465449:/examples/squares.py?ds=inline diff --git a/examples/squares.py b/examples/squares.py index 6bc352a..98e2ca8 100755 --- a/examples/squares.py +++ b/examples/squares.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 -from pypol import * +from linpy import * +import matplotlib.pyplot as plt +from matplotlib import pylab a, x, y, z = symbols('a x y z') @@ -9,24 +11,27 @@ sq2 = Le(2, x) & Le(x, 4) & Le(2, y) & Le(y, 4) sq3 = Le(0, x) & Le(x, 3) & Le(0, y) & Le(y, 3) sq4 = Le(1, x) & Le(x, 2) & Le(1, y) & Le(y, 2) sq5 = Le(1, x) & Le(x, 2) & Le(1, y) -sq6 = Le(1, x) & Le(x, 2) & Le(1, y) & Eq(y, 3) +sq6 = Le(1, x) & Le(x, 2) & Le(1, y) & Le(y, 3) sq7 = Le(0, x) & Le(x, 2) & Le(0, y) & Eq(z, 2) & Le(a, 3) -u = Polyhedron([]) -x = sq1 - sq2 +p = Le(2*x+1, y) & Le(-2*x-1, y) & Le(y, 1) + +universe = Polyhedron([]) +q = sq1 - sq2 +e = Empty print('sq1 =', sq1) #print correct square print('sq2 =', sq2) #print correct square print('sq3 =', sq3) #print correct square print('sq4 =', sq4) #print correct square -print('u =', u) #print correct square +print('universe =', universe) #print correct square print() print('¬sq1 =', ~sq1) #test complement print() print('sq1 + sq1 =', sq1 + sq2) #test addition print('sq1 + sq2 =', Polyhedron(sq1 + sq2)) #test addition print() -print('u + u =', u + u)#test addition -print('u - u =', u - u) #test subtraction +print('universe + universe =', universe + universe)#test addition +print('universe - universe =', universe - universe) #test subtraction print() print('sq2 - sq1 =', sq2 - sq1) #test subtraction print('sq2 - sq1 =', Polyhedron(sq2 - sq1)) #test subtraction @@ -43,7 +48,7 @@ print('sq1 disjoint:', sq1.disjoint()) #make disjoint print('sq2 disjoint:', sq2.disjoint()) #make disjoint print() print('is square 1 universe?:', sq1.isuniverse()) #test if square is universe -print('is u universe?:', u.isuniverse()) #test if square is universe +print('is u universe?:', universe.isuniverse()) #test if square is universe print() print('is sq1 a subset of sq2?:', sq1.issubset(sq2)) #test issubset() print('is sq4 less than sq3?:', sq4.__lt__(sq3)) # test lt(), must be a strict subset @@ -54,14 +59,29 @@ print() print('lexographic min of sq2:', sq2.lexmin()) #test lexmax() print('lexographic max of sq2:', sq2.lexmax()) #test lexmax() print() -print('Polyhedral hull of sq1 + sq2 is:', x.polyhedral_hull()) #test polyhedral hull, returns same - #value as Polyhedron(sq1 + sq2) +print('Polyhedral hull of sq1 + sq2 is:', q.aspolyhedron()) #test polyhedral hull print() -print('is sq1 bounded?', sq1.isbounded()) #unbounded should return True +print('is sq1 bounded?', sq1.isbounded()) #bounded should return True print('is sq5 bounded?', sq5.isbounded()) #unbounded should return False print() print('sq6:', sq6) -print('sq6 simplified:', sq6.sample()) +print('sample Polyhedron from sq6:', sq6.sample()) +print() +print('sq7 with out constraints involving y and a', sq7.project([a, z, x, y])) print() -#print(u.drop_dims(' ')) -print('sq7 with out constraints involving y and a', sq7.project_out([y, a])) #drops dims that are passed +print('the verticies for s are:', p.vertices()) + + +# plotting the intersection of two squares +square1 = Le(0, x) & Le(x, 2) & Le(0, y) & Le(y, 2) +square2 = Le(1, x) & Le(x, 3) & Le(1, y) & Le(y, 3) + +fig = plt.figure() +plot = fig.add_subplot(1, 1, 1, aspect='equal') +square1.plot(plot, facecolor='red', alpha=0.3) +square2.plot(plot, facecolor='blue', alpha=0.3) + +squares = Polyhedron(square1 + square2) +squares.plot(plot, facecolor='blue', alpha=0.3) + +pylab.show()