lexmin.cc: keep heads in partial order separate
[barvinok.git] / reduce_domain.c
blobf5952c1b5a367c1a4d5858ff80d5164276dea3a9
1 #include "reduce_domain.h"
3 Polyhedron *reduce_domain(Polyhedron *D, Matrix *CT, Polyhedron *CEq,
4 Polyhedron **fVD, int nd, unsigned MaxRays)
6 Polyhedron *Dt, *rVD;
7 Polyhedron *C;
8 Value c;
9 int i;
11 C = D->next ? DomainConvex(D, MaxRays) : D;
12 Dt = CT ? DomainPreimage(C, CT, MaxRays) : C;
13 rVD = CEq ? DomainIntersection(Dt, CEq, MaxRays) : Domain_Copy(Dt);
15 /* if rVD is empty or too small in geometric dimension */
16 if(!rVD || emptyQ(rVD) ||
17 (CEq && rVD->Dimension-rVD->NbEq < Dt->Dimension-Dt->NbEq-CEq->NbEq)) {
18 if(rVD)
19 Domain_Free(rVD);
20 if (D->next)
21 Polyhedron_Free(C);
22 if (CT)
23 Domain_Free(Dt);
24 return 0; /* empty validity domain */
27 if (D->next)
28 Polyhedron_Free(C);
29 if (CT)
30 Domain_Free(Dt);
32 fVD[nd] = Domain_Copy(rVD);
33 for (i = 0 ; i < nd; ++i) {
34 Polyhedron *F;
35 Polyhedron *I = DomainIntersection(fVD[nd], fVD[i], MaxRays);
36 if (emptyQ(I)) {
37 Domain_Free(I);
38 continue;
40 F = DomainSimplify(I, fVD[nd], MaxRays);
41 if (F->NbEq == 1) {
42 Polyhedron *T = rVD;
43 rVD = DomainDifference(rVD, F, MaxRays);
44 Domain_Free(T);
46 Domain_Free(F);
47 Domain_Free(I);
50 rVD = DomainConstraintSimplify(rVD, MaxRays);
51 if (emptyQ(rVD)) {
52 Domain_Free(fVD[nd]);
53 Domain_Free(rVD);
54 return 0;
57 value_init(c);
58 barvinok_count(rVD, &c, MaxRays);
59 if (value_zero_p(c)) {
60 Domain_Free(rVD);
61 rVD = 0;
63 value_clear(c);
65 return rVD;