verif_ehrhart.c: clean up indentation
[barvinok.git] / reduce_domain.c
blob622ef55f28cde52eb67e58c139667afb87fd242b
1 #include <barvinok/options.h>
2 #include "reduce_domain.h"
4 Polyhedron *reduce_domain(Polyhedron *D, Matrix *CT, Polyhedron *CEq,
5 Polyhedron **fVD, int nd,
6 struct barvinok_options *options)
8 Polyhedron *Dt, *rVD;
9 Polyhedron *C;
10 Value c;
11 int i;
13 C = D->next ? DomainConvex(D, options->MaxRays) : D;
14 Dt = CT ? DomainPreimage(C, CT, options->MaxRays) : C;
15 rVD = CEq ? DomainIntersection(Dt, CEq, options->MaxRays) : Domain_Copy(Dt);
17 /* if rVD is empty or too small in geometric dimension */
18 if(!rVD || emptyQ(rVD) ||
19 (CEq && rVD->Dimension-rVD->NbEq < Dt->Dimension-Dt->NbEq-CEq->NbEq)) {
20 if(rVD)
21 Domain_Free(rVD);
22 if (D->next)
23 Polyhedron_Free(C);
24 if (CT)
25 Domain_Free(Dt);
26 return 0; /* empty validity domain */
29 if (D->next)
30 Polyhedron_Free(C);
31 if (CT)
32 Domain_Free(Dt);
34 fVD[nd] = Domain_Copy(rVD);
35 for (i = 0 ; i < nd; ++i) {
36 Polyhedron *F;
37 Polyhedron *I = DomainIntersection(fVD[nd], fVD[i], options->MaxRays);
38 if (emptyQ(I)) {
39 Domain_Free(I);
40 continue;
42 F = DomainSimplify(I, fVD[nd], options->MaxRays);
43 if (F->NbEq == 1) {
44 Polyhedron *T = rVD;
45 rVD = DomainDifference(rVD, F, options->MaxRays);
46 Domain_Free(T);
48 Domain_Free(F);
49 Domain_Free(I);
52 rVD = DomainConstraintSimplify(rVD, options->MaxRays);
53 if (emptyQ(rVD)) {
54 Domain_Free(fVD[nd]);
55 Domain_Free(rVD);
56 return 0;
59 value_init(c);
60 barvinok_count_with_options(rVD, &c, options);
61 if (value_zero_p(c)) {
62 Domain_Free(rVD);
63 rVD = 0;
65 value_clear(c);
67 return rVD;