2 #include <barvinok/util.h>
3 #include "remove_equalities.h"
5 static void Polyhedron_Equalities_View(Polyhedron
*P
, Matrix
*M
)
7 /* Matrix "view" of equalities */
9 M
->NbColumns
= P
->Dimension
+2;
10 M
->p_Init
= P
->p_Init
;
14 static void transform(Polyhedron
**P
, Polyhedron
**C
, Matrix
*CP
, int free
,
21 T
= align_matrix(CP
, Q
->Dimension
+1);
22 *P
= Polyhedron_Preimage(Q
, T
, MaxRays
);
28 *C
= Polyhedron_Preimage(D
, CP
, MaxRays
);
33 /* Remove all equalities in P and the context C (if not NULL).
34 * Does not destroy P (or C).
35 * Returns transformation on the parameters in the Matrix pointed to by CPP
36 * (unless NULL) and transformation on the variables in the Matrix pointed to
37 * by CVP (unless NULL).
38 * Each of these transformation matrices maps the new parameters/variables
39 * back to the original ones.
41 int remove_all_equalities(Polyhedron
**P
, Polyhedron
**C
, Matrix
**CPP
, Matrix
**CVP
,
42 unsigned nparam
, unsigned MaxRays
)
54 assert(D
->Dimension
== nparam
);
57 if (Q
->NbEq
== 0 && (!D
|| D
->NbEq
== 0))
61 Polyhedron_Equalities_View(D
, &M
);
62 CV
= compress_variables(&M
, 0);
63 transform(&Q
, &D
, CV
, Q
!= *P
, MaxRays
);
64 nparam
= CV
->NbColumns
-1;
67 /* compress_parms doesn't like equalities that only involve parameters */
68 for (i
= 0; i
< Q
->NbEq
; ++i
)
69 if (First_Non_Zero(Q
->Constraint
[i
]+1, Q
->Dimension
-nparam
) == -1)
72 /* If we already compressed the parameters, then there should be
73 * no such equalities left.
79 Matrix
*M
= Matrix_Alloc(Q
->NbEq
, 1+nparam
+1);
81 for (; i
< Q
->NbEq
; ++i
) {
82 if (First_Non_Zero(Q
->Constraint
[i
]+1, Q
->Dimension
-nparam
) == -1)
83 Vector_Copy(Q
->Constraint
[i
]+1+Q
->Dimension
-nparam
,
84 M
->p
[n
++]+1, nparam
+1);
87 CV
= compress_variables(M
, 0);
89 transform(&Q
, &D
, CV
, Q
!= *P
, MaxRays
);
90 nparam
= CV
->NbColumns
-1;
106 Polyhedron_Equalities_View(Q
, &M
);
107 CP
= compress_parms(&M
, nparam
);
109 if (isIdentity(CP
)) {
114 transform(&Q
, &D
, CP
, Q
!= *P
, MaxRays
);
117 CP
= Matrix_Alloc(CV
->NbRows
, T
->NbColumns
);
118 Matrix_Product(CV
, T
, CP
);
123 nparam
= CP
->NbColumns
-1;
126 /* Matrix "view" of equalities */
128 M
.NbColumns
= Q
->Dimension
+2;
129 M
.p_Init
= Q
->p_Init
;
131 CV
= compress_variables(&M
, nparam
);
136 } else if (isIdentity(CV
)) {
140 R
= Polyhedron_Preimage(Q
, CV
, MaxRays
);