1 #include <barvinok/polylib.h>
4 * Replaces constraint a x >= c by x >= ceil(c/a)
5 * where "a" is a common factor in the coefficients
6 * old is the constraint; v points to an initialized
7 * value that this procedure can use.
8 * Return non-zero if something changed.
9 * Result is placed in new.
11 int ConstraintSimplify(Value
*old
, Value
*new, int len
, Value
* v
)
13 Vector_Gcd(old
+1, len
- 2, v
);
18 Vector_AntiScale(old
+1, new+1, *v
, len
-2);
19 mpz_fdiv_q(new[len
-1], old
[len
-1], *v
);
23 static Polyhedron
*p_simplify_constraints(Polyhedron
*P
, Vector
*row
,
24 Value
*g
, unsigned MaxRays
)
26 Polyhedron
*T
, *R
= P
;
27 int len
= P
->Dimension
+2;
30 /* Also look at equalities.
31 * If an equality can be "simplified" then there
32 * are no integer solutions anyway and the following loop
33 * will add a conflicting constraint
35 for (r
= 0; r
< R
->NbConstraints
; ++r
) {
36 if (ConstraintSimplify(R
->Constraint
[r
], row
->p
, len
, g
)) {
38 R
= AddConstraints(row
->p
, 1, R
, MaxRays
);
50 * Replaces constraint a x >= c by x >= ceil(c/a)
51 * where "a" is a common factor in the coefficients
52 * Destroys P and returns a newly allocated Polyhedron
53 * or just returns P in case no changes were made
55 Polyhedron
*DomainConstraintSimplify(Polyhedron
*P
, unsigned MaxRays
)
58 int len
= P
->Dimension
+2;
59 Vector
*row
= Vector_Alloc(len
);
61 Polyhedron
*R
= P
, *N
;
62 value_set_si(row
->p
[0], 1);
65 for (prev
= &R
; P
; P
= N
) {
68 T
= p_simplify_constraints(P
, row
, &g
, MaxRays
);
70 if (emptyQ(T
) && prev
!= &R
) {
82 if (R
->next
&& emptyQ(R
)) {