1 #include <barvinok/util.h>
2 #include "remove_equalities.h"
4 static void Polyhedron_Equalities_View(Polyhedron
*P
, Matrix
*M
)
6 /* Matrix "view" of equalities */
8 M
->NbColumns
= P
->Dimension
+2;
13 static void transform(Polyhedron
**P
, Polyhedron
**C
, Matrix
*CP
, int free
,
20 T
= align_matrix(CP
, Q
->Dimension
+1);
21 *P
= Polyhedron_Preimage(Q
, T
, MaxRays
);
27 *C
= Polyhedron_Preimage(D
, CP
, MaxRays
);
32 /* Remove all equalities in P and the context C (if not NULL).
33 * Does not destroy P (or C).
34 * Returns transformation on the parameters in the Matrix pointed to by CPP
35 * (unless NULL) and transformation on the variables in the Matrix pointed to
36 * by CVP (unless NULL).
37 * Each of these transformation matrices maps the new parameters/variables
38 * back to the original ones.
40 int remove_all_equalities(Polyhedron
**P
, Polyhedron
**C
, Matrix
**CPP
, Matrix
**CVP
,
41 unsigned nparam
, unsigned MaxRays
)
53 assert(D
->Dimension
== nparam
);
56 if (Q
->NbEq
== 0 && (!D
|| D
->NbEq
== 0))
60 Polyhedron_Equalities_View(D
, &M
);
61 CV
= compress_variables(&M
, 0);
62 transform(&Q
, &D
, CV
, Q
!= *P
, MaxRays
);
63 nparam
= CV
->NbColumns
-1;
66 /* compress_parms doesn't like equalities that only involve parameters */
67 for (i
= 0; i
< Q
->NbEq
; ++i
)
68 if (First_Non_Zero(Q
->Constraint
[i
]+1, Q
->Dimension
-nparam
) == -1)
71 /* If we already compressed the parameters, then there should be
72 * no such equalities left.
78 Matrix
*M
= Matrix_Alloc(Q
->NbEq
, 1+nparam
+1);
80 for (; i
< Q
->NbEq
; ++i
) {
81 if (First_Non_Zero(Q
->Constraint
[i
]+1, Q
->Dimension
-nparam
) == -1)
82 Vector_Copy(Q
->Constraint
[i
]+1+Q
->Dimension
-nparam
,
83 M
->p
[n
++]+1, nparam
+1);
86 CV
= compress_variables(M
, 0);
88 transform(&Q
, &D
, CV
, Q
!= *P
, MaxRays
);
89 nparam
= CV
->NbColumns
-1;
105 Polyhedron_Equalities_View(Q
, &M
);
106 CP
= compress_parms(&M
, nparam
);
108 if (isIdentity(CP
)) {
113 transform(&Q
, &D
, CP
, Q
!= *P
, MaxRays
);
116 CP
= Matrix_Alloc(CV
->NbRows
, T
->NbColumns
);
117 Matrix_Product(CV
, T
, CP
);
122 nparam
= CP
->NbColumns
-1;
125 /* Matrix "view" of equalities */
127 M
.NbColumns
= Q
->Dimension
+2;
128 M
.p_Init
= Q
->p_Init
;
130 CV
= compress_variables(&M
, nparam
);
135 } else if (isIdentity(CV
)) {
139 R
= Polyhedron_Preimage(Q
, CV
, MaxRays
);