50 "? PDomainIntersection: operation on different dimensions\n");
60 for (p1 = Pol1; p1; p1 = p1->
next) {
61 for (p2 = Pol2; p2; p2 = p2->
next) {
93 fprintf(stderr,
"? PDomainDifference: operation on different dimensions\n");
103 for (p2 = Pol2; p2; p2 = p2->
next) {
104 for (p1 = Pol1; p1; p1 = p1->
next) {
136 Value m1, m2, m3, gcd, tmp;
150 for (j = k + 1; j < Mat->
NbRows; ++j) {
180 for (j = k + 1; j < Mat->
NbRows; ++j) {
184 for (i = k + 1; i < Mat->
NbColumns; ++i) {
215 unsigned int NbColumns;
222 unsigned int **q, *p;
230 result->
p = q = (
unsigned int **)malloc(rows *
sizeof(
unsigned int *));
233 (
unsigned int *)malloc(rows * cols *
sizeof(
unsigned int));
236 for (i = 0; i < rows; i++) {
249 unsigned NbRows, NbColumns;
253 for (i = 0; i < NbRows; i++) {
255 for (j = 0; j < NbColumns; j++)
256 fprintf(stderr,
" %10X ", *p++);
257 fprintf(stderr,
"\n");
264 free((
char *)
matrix->p_init);
332#define INT_BITS (sizeof(unsigned) * 8)
338 unsigned int *bv = (
unsigned int *)calloc(words,
sizeof(
unsigned));
340 for (i = 0, ix = 0, bx =
MSB; i <
n; ++i) {
369 for (k = 0, c = 0, kx = 0, bx =
MSB; k < D->
NbRays; ++k) {
379 for (j = 0; j <
m + 1; ++j) {
380 for (i = 0; i < c; ++i)
393 for (j = 0; j <
n; j++)
395 for (j = 0; j <
m; j++)
412 fprintf(stderr,
"\nRaysDi=\n");
415 fprintf(stderr,
"Invalid ");
416 fprintf(stderr,
"Pi=\n");
422 fprintf(stderr,
"Eliminated because of no vertex\n");
436 fprintf(stderr,
"Xi = ");
438 fprintf(stderr,
"Pi = ");
447 fprintf(stderr,
"Eliminated because of no inverse Pi\n");
454 fprintf(stderr,
"FACE GENERATED!\n");
455 fprintf(stderr,
"PiInv = ");
464 fprintf(stderr,
"Si = ");
483 fprintf(stderr,
"RaysDi = ");
485 fprintf(stderr,
"PDi = ");
512 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
513 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
514 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
515 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
517 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
518 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
519 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
520 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
522 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
523 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
524 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
525 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
527 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
528 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
529 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
530 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8};
534 register unsigned int i, tmp, cnt = 0;
536 for (i = 0; i <
nr; i++) {
538 cnt = cnt +
cntbit[tmp & 0xff] +
cntbit[(tmp >> 8) & 0xff] +
539 cntbit[(tmp >> 16) & 0xff] +
cntbit[(tmp >> 24) & 0xff];
548 for (j = 0; j < len; j++) {
550 fprintf(stderr,
"mf=%08X Sat=%08X &=%08X\n", part[j], bv[j],
553 if ((part[j] & bv[j]) != part[j])
606 unsigned int *new_mf;
609 fprintf(stderr,
"Start scan_m_face(pos=%d, nb_un=%d, n=%d, m=%d\n", pos,
611 fprintf(stderr,
"mf = ");
614 for (i = 0; i <
nr; i++)
615 fprintf(stderr,
"%08X", mf[i]);
616 fprintf(stderr,
"\nequality = [");
618 fprintf(stderr,
" %1d",
egalite[i]);
619 fprintf(stderr,
"]\n");
630 for (i = 0; i < pos - 1; i++) {
636 fprintf(stderr,
"Sat[%d]\n", i);
640 fprintf(stderr,
"Redundant with constraint %d\n", i);
667 new_mf = (
unsigned int *)malloc(
nr *
sizeof(
unsigned int));
668 for (k = 0; k <
nr; k++)
669 new_mf[k] = mf[k] &
Sat->
p[pos][k];
672 fprintf(stderr,
"new_mf = ");
675 for (i = 0; i <
nr; i++) {
676 fprintf(stderr,
"%08X", new_mf[i]);
678 fprintf(stderr,
"\ncount(new_mf) = %d\n",
count_sat(new_mf));
743 Value *p1, *p2, p3, tmp;
744 unsigned Dimension, NbRay, NbCon, bx;
755 nr = (NbRay - 1) / (
sizeof(
int) * 8) + 1;
757 Temp = (
unsigned int *)malloc(
nr *
sizeof(
unsigned int));
759 memset(Temp, 0,
nr *
sizeof(
unsigned int));
762 for (k = 0; k < NbRay; k++) {
763 for (i = 0; i < NbCon; i++) {
765 p2 = &Pol->
Ray[k][1];
767 for (j = 0; j < Dimension; j++) {
797 int nbRows, nbColumns;
804 for (i = 0, rays = 0; i < nbRows; i++)
811 result->
nbV = nbRows - rays;
817 for (i = 0; i < nbRows; i++) {
827 for (j = 1; j < nbColumns - 1; j++) {
832 paramVertex->
Vertex = vertex;
838 paramVertex->
Facets = NULL;
839 paramVertex->
next = result->
V;
840 result->
V = paramVertex;
845 size = (nbRows - 1) / (8 *
sizeof(
int)) + 1;
849 result->
D->
next = NULL;
851 result->
D->
F = (
unsigned int *)malloc(size *
sizeof(
int));
852 memset(&result->
D->
F[0], 0xFF, size *
sizeof(
int));
875 memset(p, 0,
sizeof(
int) * (E->
NbEq));
878 fprintf(stderr,
"\n\nPreElim_Columns starting\n");
879 fprintf(stderr,
"E =\n");
883 for (l = 0; l < E->
NbEq; ++l) {
885 fprintf(stderr,
"Internal error: Elim_Columns (polyparam.c), expecting "
886 "equalities first in E.\n");
892 fprintf(stderr,
"Internal error: Elim_Columns (polyparam.c), expecting "
893 "non-empty constraint in E.\n");
901 fprintf(stderr,
"p[%d] = %d,", l, p[l]);
908 for (j = 0; j < E->
NbEq; ++j)
913 fprintf(stderr,
"ref[%d] = %d,", i, ref[i]);
920 for (j = 0; j < T->
NbRows; j++)
927 fprintf(stderr,
"\nTransMatrix =\n");
953 fprintf(stderr,
"\nElim_Columns starting\n");
954 fprintf(stderr,
"A =\n");
960 for (l = 0; l < E->
NbEq; ++l) {
961 for (c = 0; c < M->
NbRows; ++c) {
975 fprintf(stderr,
"\nElim_Columns after zeroing columns of A.\n");
976 fprintf(stderr,
"M =\n");
982 for (l = 0; l < C->
NbRows; ++l)
988 fprintf(stderr,
"\nElim_Columns after eliminating columns of A.\n");
989 fprintf(stderr,
"C =\n");
1021 int i, j, nbr, dimfaces;
1028 for (i = 0; i < RC->
NbRays; i++)
1032 for (i = 0, j = 0; j < nbr; i++)
1036 dimfaces = RC->
NbBid;
1040 fprintf(stderr,
"Rays = ");
1042 fprintf(stderr,
"dimfaces = %d\n", dimfaces);
1081 fprintf(stderr,
"Find_m_faces: ?%d parameters of a %d-polyhedron !\n",
m,
1092 fprintf(stderr,
"m = %d\n",
m);
1093 fprintf(stderr,
"D = ");
1095 fprintf(stderr,
"C1 = ");
1102 fprintf(stderr,
"D1 = ");
1118 for (i = 0; i <
n; i++)
1124 fprintf(stderr,
"True context C1 = ");
1133 if (C1->NbEq == 0) {
1144 for (j = 0, i = 0; i < C1->NbEq; ++i, ++j) {
1172 for (i = 0; i < C1->NbConstraints; ++i) {
1190 p = (
int *)malloc(
sizeof(
int) * (CEq1->
NbEq));
1193 ref = (
int *)malloc(
sizeof(
int) * (CEq1->
Dimension + 2 - CEq1->
NbEq));
1201 fprintf(stderr,
"D2\t Dim = %3d\tNbEq = %3d\tLines = %3d\n", D2->
Dimension,
1204 fprintf(stderr,
"C2\t Dim = %3d\tNbEq = %3d\tLines = %3d\n", C2->Dimension,
1205 C2->NbEq, C2->NbBid);
1216 fprintf(stderr,
"Polyhedron CEq = ");
1218 fprintf(stderr,
"Matrix CT = ");
1235 fprintf(stderr,
"Polyhedron D1 (D AND C) = ");
1237 fprintf(stderr,
"Polyhedron CEqualities = ");
1241 fprintf(stderr,
"NULL\n");
1261 fprintf(stderr,
"Sat = ");
1264 fprintf(stderr,
"mf = ");
1265 for (i = 0; i <
nr; i++)
1266 fprintf(stderr,
"%08X", mf[i]);
1267 fprintf(stderr,
"\n");
1271 egalite = (
unsigned int *)malloc(
sizeof(
int) * D1->NbConstraints);
1272 memset(
egalite, 0,
sizeof(
int) * D1->NbConstraints);
1274 for (i = 0; i < D1->NbEq; i++)
1294 if (m_dim < D1->NbBid)
1295 fprintf(stderr,
"m_dim (%d) < D1->NbBid (%d)\n",
m_dim, D1->NbBid);
1297 if (m_dim < D1->NbBid)
1304 fprintf(stderr,
"m_dim = %d\n",
m_dim);
1306 "Target: find faces that saturate %d constraints and %d rays/lines\n",
1316 fprintf(stderr,
"Number of m-faces: %d\n", nbfaces);
1360 if (nb_domains == 0) {
1363 fprintf(stderr,
"No domains\n");
1370 if (!PD->
next && PD->
F)
1374 nv = (nb_domains - 1) / (8 *
sizeof(
int)) + 1;
1377 fprintf(stderr,
"nv = %d\n", nv);
1380 for (p1 = PD, i = 0, ix = 0, bx =
MSB; p1; p1 = p1->
next, i++) {
1383 p1->
F = (
unsigned *)malloc(nv *
sizeof(
unsigned));
1386 memset(p1->
F, 0, nv *
sizeof(
unsigned));
1392 fprintf(stderr,
"nb of vertices=%d\n", i);
1398 for (p1 = PD; p1; p1 = p1->
next) {
1399 for (p2prev = p1, p2 = p1->
next; p2; p2prev = p2, p2 = p2->
next) {
1407 fprintf(stderr,
"Empty dx (p1 inter p2). Continuing\n");
1415 fprintf(stderr,
"Begin PDomainDifference\n");
1416 fprintf(stderr,
"p1=");
1418 fprintf(stderr,
"p2=");
1425 fprintf(stderr,
"p1\\p2=");
1427 fprintf(stderr,
"p2\\p1=");
1429 fprintf(stderr,
"END PDomainDifference\n\n");
1434 fprintf(stderr,
"Empty d1\n");
1443 fprintf(stderr,
"Empty d2 (deleting)\n");
1450 for (i = 0; i < nv; i++)
1451 p1->
F[i] |= p2->
F[i];
1462 fprintf(stderr,
"p2 replaced by d2\n");
1465 for (i = 0; i < nv; i++)
1466 p1->
F[i] |= p2->
F[i];
1476 fprintf(stderr,
"p1 replaced by d1\n");
1485 for (i = 0; i < nv; i++)
1486 p2->
F[i] |= p1->
F[i];
1494 fprintf(stderr,
"Non-empty d1 and d2\nNew node created\n");
1498 PDNew->
F = (
unsigned int *)malloc(nv *
sizeof(
int));
1499 memset(PDNew->
F, 0, nv *
sizeof(
int));
1502 for (i = 0; i < nv; i++)
1503 PDNew->
F[i] = p1->
F[i] | p2->
F[i];
1534 int working_space) {
1544 fprintf(stderr,
"Polyhedron2Param_Vertices algorithm starting at : %.2fs\n",
1545 (
float)clock() / CLOCKS_PER_SEC);
1549 result =
Find_m_faces(&Din, Cin, 0, working_space, NULL, NULL);
1552 fprintf(stderr,
"nb of points : %d\n", result->
nbV);
1556 fprintf(stderr,
"end main loop : %.2fs\n", (
float)clock() / CLOCKS_PER_SEC);
1594 for (l = 0; l < V->
NbRows; ++l) {
1599 for (v = 0; v < V->
NbColumns - 2; ++v) {
1618 fprintf(DST,
"%s/", param_names[v]);
1621 fprintf(DST,
"%s", param_names[v]);
1640 if (l < V->NbRows - 1)
1662 for (i = 0; i < V->
NbRows; ++i) {
1665 for (k = 0; k < CT->
NbRows; k++)
1696 fprintf(DST,
"%s ", pname[v - 1]);
1698 fprintf(DST,
"+ %s ", pname[v - 1]);
1700 fprintf(DST,
"- %s ", pname[v - 1]);
1705 fprintf(DST,
"%s ", pname[v - 1]);
1722 fprintf(DST,
"UNION\n");
1733 char **param_names) {
1737 fprintf(DST,
"Vertex :\n");
1741 fprintf(DST,
" If :\n");
1758 int working_space) {
1772 fprintf(stderr,
"Polyhedron2Param_Polyhedron algorithm starting at : %.2fs\n",
1773 (
float)clock() / CLOCKS_PER_SEC);
1778 result =
Find_m_faces(&Din, Cin, 1, working_space, NULL, NULL);
1782 fprintf(stderr,
"Number of vertices : %d\n", result->
nbV);
1783 fprintf(stderr,
"Vertices found at : %.2fs\n",
1784 (
float)clock() / CLOCKS_PER_SEC);
1791 for (D = result->
D; D; D = D->
next)
1796 fprintf(stderr,
"domains found at : %.2fs\n",
1797 (
float)clock() / CLOCKS_PER_SEC);
1823 fprintf(stderr,
"Polyhedron2Param_Polyhedron algorithm starting at : %.2fs\n",
1824 (
float)clock() / CLOCKS_PER_SEC);
1829 result =
Find_m_faces(Din, Cin, 1, working_space, CEq, CT);
1833 fprintf(stderr,
"Number of vertices : %d\n", result->
nbV);
1834 fprintf(stderr,
"Vertices found at : %.2fs\n",
1835 (
float)clock() / CLOCKS_PER_SEC);
1849 fprintf(stderr,
"domains found at : %.2fs\n",
1850 (
float)clock() / CLOCKS_PER_SEC);
1895 Value *det,
unsigned MaxRays) {
1897 int nb_param, nb_vars;
1900 Value global_var_lcm;
1917 for (V = PP->
V; V; V = V->
next)
1918 for (i = 0; i < nb_vars; i++)
1922 for (i = 0; i < nb_vars; i++) {
1924 value_lcm(global_var_lcm, global_var_lcm, denoms->
p[i]);
1928 for (V = PP->
V; V; V = V->
next)
1929 for (i = 0; i < nb_vars; i++) {
1937 for (i = 0; i < nb_vars; i++)
1943 expansion =
Matrix_Alloc(nb_vars + nb_param + 1, nb_vars + nb_param + 1);
1944 for (i = 0; i < nb_vars; i++)
1946 for (i = nb_vars; i < nb_vars + nb_param + 1; i++)
#define value_mone_p(val)
#define value_notzero_p(val)
#define value_divexact(ref, val1, val2)
#define value_gcd(ref, val1, val2)
#define value_notone_p(val)
#define value_lcm(ref, val1, val2)
#define value_zero_p(val)
#define value_assign(v1, v2)
#define value_set_si(val, i)
#define value_division(ref, val1, val2)
#define value_multiply(ref, val1, val2)
#define value_print(Dst, fmt, val)
#define value_subtract(ref, val1, val2)
#define value_addto(ref, val1, val2)
#define value_posz_p(val)
Matrix * Matrix_Alloc(unsigned NbRows, unsigned NbColumns)
void Matrix_Print(FILE *Dst, const char *Format, Matrix *Mat)
void rat_prodmat(Matrix *S, Matrix *X, Matrix *P)
int MatInverse(Matrix *Mat, Matrix *MatInv)
void Matrix_Free(Matrix *Mat)
Polyhedron * DomainAddRays(Polyhedron *Pol, Matrix *Ray, unsigned NbMaxConstrs)
Add rays pointed by 'Ray' to each and every polyhedron in the polyhedral domain 'Pol'.
Polyhedron * align_context(Polyhedron *Pol, int align_dimension, int NbMaxRays)
void Polyhedron_Free(Polyhedron *Pol)
Polyhedron * DomainConvex(Polyhedron *Pol, unsigned NbMaxConstrs)
Polyhedron * AddPolyToDomain(Polyhedron *Pol, Polyhedron *PolDomain)
Polyhedron * Polyhedron_Preimage(Polyhedron *Pol, Matrix *Func, unsigned NbMaxRays)
Polyhedron * DomainIntersection(Polyhedron *Pol1, Polyhedron *Pol2, unsigned NbMaxRays)
Polyhedron * Polyhedron_Copy(Polyhedron *Pol)
Polyhedron * DomainSimplify(Polyhedron *Pol1, Polyhedron *Pol2, unsigned NbMaxRays)
Polyhedron * Universe_Polyhedron(unsigned Dimension)
Polyhedron * Rays2Polyhedron(Matrix *Ray, unsigned NbMaxConstrs)
Given a matrix of rays 'Ray', create and return a polyhedron.
Matrix * Polyhedron2Constraints(Polyhedron *Pol)
Polyhedron * Constraints2Polyhedron(Matrix *Constraints, unsigned NbMaxRays)
Given a matrix of constraints ('Constraints'), construct and return a polyhedron.
Polyhedron * AddConstraints(Value *Con, unsigned NbConstraints, Polyhedron *Pol, unsigned NbMaxRays)
void Polyhedron_Print(FILE *Dst, const char *Format, const Polyhedron *Pol)
void Domain_Free(Polyhedron *Pol)
Polyhedron * SubConstraint(Value *Con, Polyhedron *Pol, unsigned NbMaxRays, int Pass)
#define POL_ENSURE_VERTICES(P)
#define POL_ENSURE_FACETS(P)
void Param_Vertices_Free(Param_Vertices *PV)
Polyhedron * Elim_Columns(Polyhedron *A, Polyhedron *E, int *p, int *ref)
static Param_Domain * PDomains
void Param_Vertices_Print(FILE *DST, Param_Vertices *PV, char **param_names)
static void traite_m_face(Polyhedron *, unsigned int *, unsigned int *)
Param_Polyhedron * Polyhedron2Param_Vertices(Polyhedron *Din, Polyhedron *Cin, int working_space)
static SatMatrix * Poly2Sat(Polyhedron *Pol, unsigned int **L)
static int ComputeNPLinesRays(int n, Polyhedron *D1, Matrix **Rays)
void Param_Polyhedron_Free(Param_Polyhedron *P)
void Print_Vertex(FILE *DST, Matrix *V, char **param_names)
Param_Polyhedron * Find_m_faces(Polyhedron **Di, Polyhedron *C, int keep_dom, int working_space, Polyhedron **CEq, Matrix **CT)
static Param_Vertices * PV_Result
void Param_Domain_Free(Param_Domain *PD)
static SatMatrix * SMAlloc(int rows, int cols)
void Compute_PDomains(Param_Domain *PD, int nb_domains, int working_space)
void Param_Polyhedron_Scale_Integer(Param_Polyhedron *PP, Polyhedron **P, Value *det, unsigned MaxRays)
void Print_Domain(FILE *DST, Polyhedron *D, char **pname)
Matrix * VertexCT(Matrix *V, Matrix *CT)
static unsigned int * egalite
static int count_sat(unsigned int *mf)
static int TestRank(Matrix *Mat)
Param_Polyhedron * GenParamPolyhedron(Polyhedron *Pol, Matrix *Rays)
unsigned int * int_array2bit_vector(unsigned int *array, int n)
Param_Polyhedron * Polyhedron2Param_SimplifiedDomain(Polyhedron **Din, Polyhedron *Cin, int working_space, Polyhedron **CEq, Matrix **CT)
static Polyhedron * Add_CEqualities(Polyhedron *D)
static void scan_m_face(int, int, Polyhedron *, unsigned int *)
static int bit_vector_includes(unsigned int *bv, int len, unsigned int *part)
static Polyhedron * Recession_Cone(Polyhedron *P, unsigned nvar, unsigned MaxRays)
static void SMFree(SatMatrix *matrix)
Matrix * PreElim_Columns(Polyhedron *E, int *p, int *ref, int m)
Polyhedron * PDomainIntersection(Polyhedron *Pol1, Polyhedron *Pol2, unsigned NbMaxRays)
Polyhedron * PDomainDifference(Polyhedron *Pol1, Polyhedron *Pol2, unsigned NbMaxRays)
Param_Polyhedron * Polyhedron2Param_Domain(Polyhedron *Din, Polyhedron *Cin, int working_space)
static Polyhedron * CEqualities
struct _Param_Domain * next
struct _Param_Vertex * next
void Vector_Free(Vector *vector)
void Vector_Scale(Value *p1, Value *p2, Value lambda, unsigned length)
void Vector_Normalize(Value *p, unsigned length)
Vector * Vector_Alloc(unsigned length)
void Vector_Copy(Value *p1, Value *p2, unsigned length)