X-Git-Url: https://svn.cri.ensmp.fr/git/linpy.git/blobdiff_plain/3ff02ec4a397d81d1019080a78198c454861c1e2..3bbc19830f1dc2432f91bba40123bb60936a0be3:/pypol/linear.py diff --git a/pypol/linear.py b/pypol/linear.py index 331d3af..8e96f35 100644 --- a/pypol/linear.py +++ b/pypol/linear.py @@ -4,8 +4,8 @@ import numbers from fractions import Fraction, gcd -from . import isl, islhelper -from .isl import libisl, Context +from . import isl +from .isl import libisl __all__ = [ @@ -42,6 +42,9 @@ def _polymorphic_operator(func): return wrapper +_main_ctx = isl.Context() + + class Expression: """ This class implements linear expressions. @@ -357,12 +360,6 @@ class Polyhedron: raise TypeError('non-integer constraint: ' '{} <= 0'.format(constraint)) self._inequalities.append(constraint) - self._bset = self._to_isl() - #print(self._bset) - #put this here just to test from isl method - #from_isl = self.from_isl(self._bset) - #print(from_isl) - #rint(self) return self @property @@ -504,8 +501,7 @@ class Polyhedron: if symbols is None: symbols = self.symbols() num_coefficients = len(symbols) - ctx = Context() - space = libisl.isl_space_set_alloc(ctx, 0, num_coefficients) + space = libisl.isl_space_set_alloc(_main_ctx, 0, num_coefficients) bset = libisl.isl_basic_set_universe(libisl.isl_space_copy(space)) ls = libisl.isl_local_space_from_space(space) ceq = libisl.isl_equality_alloc(libisl.isl_local_space_copy(ls)) @@ -520,7 +516,7 @@ class Polyhedron: for eq in coeff_eq: num = coeff_eq.get(eq) iden = symbols.index(eq) - ceq = libisl.isl_constraint_set_coefficient_si(ceq, islhelper.isl_dim_set, iden, num) #use 3 for type isl_dim_set + ceq = libisl.isl_constraint_set_coefficient_si(ceq, libisl.isl_dim_set, iden, num) #use 3 for type isl_dim_set bset = libisl.isl_basic_set_add_constraint(bset, ceq) if list(self.inequalities): #check if any inequalities exist for ineq in self.inequalities: @@ -531,13 +527,9 @@ class Polyhedron: for ineq in coeff_in: num = coeff_in.get(ineq) iden = symbols.index(ineq) - cin = libisl.isl_constraint_set_coefficient_si(cin, islhelper.isl_dim_set, iden, num) #use 3 for type isl_dim_set + cin = libisl.isl_constraint_set_coefficient_si(cin, libisl.isl_dim_set, iden, num) #use 3 for type isl_dim_set bset = libisl.isl_basic_set_add_constraint(bset, cin) - ip = libisl.isl_printer_to_str(ctx) #create string printer - ip = libisl.isl_printer_print_basic_set(ip, bset) #print basic set to printer - string = libisl.isl_printer_get_str(ip) #get string from printer - string = str(string.decode()) - print(string) + bset = isl.BasicSet(bset) return bset def from_isl(self, bset): @@ -561,7 +553,5 @@ if __name__ == '__main__': ex1 = Expression(coefficients={'a': 1, 'x': 2}, constant=2) ex2 = Expression(coefficients={'a': 3 , 'b': 2}, constant=3) p = Polyhedron(inequalities=[ex1, ex2]) - #p = eq(ex2, 0)# 2a+4 = 0, in fact 6a+3 = 0 - #p.to_isl() - -#universe = Polyhedron() + bs = p._to_isl() + print(bs)