Drop_dims working for any order!
[linpy.git] / pypol / domains.py
index 9bb403e..12cf471 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,30 @@ 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 
+        n = 0 
+        dims = sorted(dims)
+        symbols = sorted(self.symbols)
+        islset = self._toislset(self.polyhedra, self.symbols)
+        for dim in dims:
+            dim_index = dims.index(dim)
+            if dim in symbols:
+                first = symbols.index(dim) 
+                try:
+                    for dim in dims:
+                        if symbols[first+1] is dims[dim_index+1]: #check if next value in symbols is same as next value in dims
+                            n += 1
+                        islbset = libisl.isl_set_project_out(islset, libisl.isl_dim_set, first, n) 
+                        symbols.remove(dim)
+                except:
+                    islbset = libisl.isl_set_project_out(islset, libisl.isl_dim_set, first, 1) 
+                    symbols.remove(dim) 
+            else:
+                islbset = libisl.isl_set_project_out(islset, libisl.isl_dim_set, 0, 0)     
+        return Polyhedron._fromislset(islbset, symbols)
+    
     def sample(self):
         from .polyhedra import Polyhedron
         islset = self._toislset(self.polyhedra, self.symbols)
@@ -329,7 +349,6 @@ class Domain:
     def tosympy(self):
         raise NotImplementedError
 
-
 def And(*domains):
     if len(domains) == 0:
         from .polyhedra import Universe