From: Vivien Maisonneuve Date: Wed, 18 Jun 2014 20:32:11 +0000 (+0200) Subject: Fix Polyhedron.isempty() X-Git-Tag: 1.0~240 X-Git-Url: https://svn.cri.ensmp.fr/git/linpy.git/commitdiff_plain/af10bce9dc286c2b3ffe6520c4ed0047a4475320?ds=inline;hp=a157f7c947533f4be375e55f78adfa3dae7eeef7 Fix Polyhedron.isempty() --- diff --git a/pypol/linear.py b/pypol/linear.py index a562a3f..5f3c559 100644 --- a/pypol/linear.py +++ b/pypol/linear.py @@ -139,7 +139,7 @@ class Expression: @_polymorphic_method def __add__(self, other): coefficients = dict(self.coefficients()) - for symbol, coefficient in other.coefficients: + for symbol, coefficient in other.coefficients(): if symbol in coefficients: coefficients[symbol] += coefficient else: @@ -152,7 +152,7 @@ class Expression: @_polymorphic_method def __sub__(self, other): coefficients = dict(self.coefficients()) - for symbol, coefficient in other.coefficients: + for symbol, coefficient in other.coefficients(): if symbol in coefficients: coefficients[symbol] -= coefficient else: @@ -378,9 +378,6 @@ class Polyhedron: def inequalities(self): return self._inequalities - def isempty(self): - return bool(libisl.isl_basic_set_is_empty(self._bset)) - @property def constraints(self): return self._constraints @@ -404,10 +401,11 @@ class Polyhedron: raise NotImplementedError def isempty(self): - return self == empty + bset = self._to_isl() + return bool(libisl.isl_basic_set_is_empty(bset)) def isuniverse(self): - return self == universe + raise NotImplementedError def isdisjoint(self, other): # return true if the polyhedron has no elements in common with other @@ -523,7 +521,7 @@ class Polyhedron: return bset @classmethod - def from_isl(cls, bset): + def _from_isl(cls, bset): '''takes basic set in isl form and puts back into python version of polyhedron isl example code gives isl form as: "{[i] : exists (a : i = 2a and i >= 10 and i <= 42)}") @@ -551,3 +549,5 @@ if __name__ == '__main__': p = Polyhedron(inequalities=[ex1, ex2]) bs = p._to_isl() print(bs) + print('empty ?', p.isempty()) + print('empty ?', eq(0, 1).isempty())