1 #include <barvinok/util.h>
2 #include "remove_equalities.h"
4 static void transform(Polyhedron
**P
, Polyhedron
**C
, Matrix
*CP
, int free
,
11 T
= align_matrix(CP
, Q
->Dimension
+1);
12 *P
= Polyhedron_Preimage(Q
, T
, MaxRays
);
18 *C
= Polyhedron_Preimage(D
, CP
, MaxRays
);
23 /* Remove all equalities in P and the context C (if not NULL).
24 * Does not destroy P (or C).
25 * Returns transformation on the parameters in the Matrix pointed to by CPP
26 * (unless NULL) and transformation on the variables in the Matrix pointed to
27 * by CVP (unless NULL).
28 * Each of these transformation matrices maps the new parameters/variables
29 * back to the original ones.
31 int remove_all_equalities(Polyhedron
**P
, Polyhedron
**C
, Matrix
**CPP
, Matrix
**CVP
,
32 unsigned nparam
, unsigned MaxRays
)
47 assert(D
->Dimension
== nparam
);
50 /* compress_parms doesn't like equalities that only involve parameters */
51 for (i
= 0; i
< Q
->NbEq
; ++i
)
52 if (First_Non_Zero(Q
->Constraint
[i
]+1, Q
->Dimension
-nparam
) == -1)
56 Matrix
*M
= Matrix_Alloc(Q
->NbEq
, 1+nparam
+1);
58 for (; i
< Q
->NbEq
; ++i
) {
59 if (First_Non_Zero(Q
->Constraint
[i
]+1, Q
->Dimension
-nparam
) == -1)
60 Vector_Copy(Q
->Constraint
[i
]+1+Q
->Dimension
-nparam
,
61 M
->p
[n
++]+1, nparam
+1);
64 CV
= compress_variables(M
, 0);
66 transform(&Q
, &D
, CV
, Q
!= *P
, MaxRays
);
67 nparam
= CV
->NbColumns
-1;
83 /* Matrix "view" of equalities */
85 M
.NbColumns
= Q
->Dimension
+2;
88 CP
= compress_parms(&M
, nparam
);
95 transform(&Q
, &D
, CP
, Q
!= *P
, MaxRays
);
98 CP
= Matrix_Alloc(CV
->NbRows
, T
->NbColumns
);
99 Matrix_Product(CV
, T
, CP
);
104 nparam
= CP
->NbColumns
-1;
107 /* Matrix "view" of equalities */
109 M
.NbColumns
= Q
->Dimension
+2;
110 M
.p_Init
= Q
->p_Init
;
112 CV
= compress_variables(&M
, nparam
);
117 } else if (isIdentity(CV
)) {
121 R
= Polyhedron_Preimage(Q
, CV
, MaxRays
);