Commit working basic drop constraints
authorDanielle Bolan <n02702451@hawkmail.newpaltz.edu>
Tue, 1 Jul 2014 09:14:46 +0000 (11:14 +0200)
committerDanielle Bolan <n02702451@hawkmail.newpaltz.edu>
Tue, 1 Jul 2014 09:14:46 +0000 (11:14 +0200)
examples/squares.py
pypol/domains.py

index 0f4e1a5..d23e636 100755 (executable)
@@ -2,15 +2,15 @@
 
 from pypol import *
 
-x, y = symbols('x y')
+a, x, y, z = symbols('a x y z')
 
 sq1 = Le(0, x) & Le(x, 2) & Le(0, y) & Le(y, 2)
 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)
+sq7 = Le(0, x) & Le(x, 2) & Le(0, y) & Eq(z, 2) & Le(a, 3)
 u = Polyhedron([])
 x = sq1 - sq2
 
@@ -62,4 +62,6 @@ print('is sq5 bounded?', sq5.isbounded()) #unbounded should return False
 print()
 print('sq6:', sq6)
 print('sq6 simplified:', sq6.sample())
+print()
+print('sq7 with out constraints involving y and a', sq7.drop_dims('y a'))
 
index 9bb403e..4a1f9aa 100644 (file)
@@ -138,10 +138,11 @@ class Domain:
         return self.complement()
 
     def simplify(self):
-        # see isl_set_coalesce, isl_set_detect_equalities,
-        # isl_set_remove_redundancies
-        # which ones? in which order?
-        raise NotImplementedError
+        #does not change anything in any of the examples
+        #isl seems to do this naturally 
+        islset = self._toislset(self.polyhedra, self.symbols)
+        islset = libisl.isl_set_remove_redundancies(islset)
+        return self._fromislset(islset, self.symbols)
 
     def polyhedral_hull(self):
         # several types of hull are available
@@ -151,11 +152,18 @@ class Domain:
         islbset = libisl.isl_set_polyhedral_hull(islset)
         return Polyhedron._fromislbasicset(islbset, self.symbols)
 
-    def project(self, symbols):
-        # not sure what isl_set_project_out actually does…
-        # use isl_set_drop_constraints_involving_dims instead?
-        raise NotImplementedError
-
+    def drop_dims(self, dims):
+        # use to remove certain variables use isl_set_drop_constraints_involving_dims instead?
+        from .polyhedra import Polyhedron       
+        dims = list(dims)
+        symbols = list(self.symbols)
+        islset = self._toislset(self.polyhedra, self.symbols)
+        for dim in dims:
+            if dim in symbols:
+                num = symbols.index(dim)
+                islbset = libisl.isl_set_drop_constraints_involving_dims(islset, libisl.isl_dim_set, num, 1)
+        return Polyhedron._fromislset(islbset, self.symbols)
+    
     def sample(self):
         from .polyhedra import Polyhedron
         islset = self._toislset(self.polyhedra, self.symbols)
@@ -329,7 +337,6 @@ class Domain:
     def tosympy(self):
         raise NotImplementedError
 
-
 def And(*domains):
     if len(domains) == 0:
         from .polyhedra import Universe