3 # Copyright 2014 MINES ParisTech
5 # This file is part of LinPy.
7 # LinPy is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # LinPy is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with LinPy. If not, see <http://www.gnu.org/licenses/>.
25 def __new__(cls

, polyhedron

, range_symbols

, domain_symbols

):
26 self

= object().__new

__(cls

)
27 self

.polyhedron

= polyhedron

28 self

.range_symbols

= range_symbols

29 self

.domain_symbols

= domain_symbols

34 return self

.range_symbols

+ self

.domain_symbols

37 delta_symbols

= [symbol

.asdummy() for symbol

in self

.range_symbols

]
39 polyhedron

= self

.polyhedron

40 for x

, xprime

, dx

in zip(self

.range_symbols

, self

.domain_symbols

, delta_symbols

):
41 polyhedron

&= Eq(dx

, xprime

- x

)
42 polyhedron

= polyhedron

.project(self

.symbols

)
43 equalities

, inequalities

= [], []
44 for equality

in polyhedron

.equalities

:
45 equality

+= (k

-1) * equality

.constant

46 equalities

.append(equality

)
47 for inequality

in polyhedron

.inequalities

:
48 inequality

+= (k

-1) * inequality

.constant

49 inequalities

.append(inequality

)
50 polyhedron

= Polyhedron(equalities

, inequalities

) & Ge(k

, 0)
51 polyhedron

= polyhedron

.project([k

])
52 for x

, xprime

, dx

in zip(self

.range_symbols

, self

.domain_symbols

, delta_symbols

):
53 polyhedron

&= Eq(dx

, xprime

- x

)
54 polyhedron

= polyhedron

.project(delta_symbols

)
55 return Transformer(polyhedron

, self

.range_symbols

, self

.domain_symbols

)
58 if __name__

== '__main__':
59 i

, iprime

, j

, jprime

= symbols("i i' j j'")
60 transformer

= Transformer(Eq(iprime

, i

+ 2) & Eq(jprime

, j

+ 1),
61 [i

, j

], [iprime

, jprime

])
62 print('T =', transformer

.polyhedron

)
63 print('T* =', transformer

.star().polyhedron

)