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++) {
248 unsigned NbRows, NbColumns;
252 for (i = 0; i < NbRows; i++) {
254 for (j = 0; j < NbColumns; j++)
255 fprintf(stderr,
" %10X ", *p++);
256 fprintf(stderr,
"\n");
262 free((
char *)
matrix->p_init);
330#define INT_BITS (sizeof(unsigned) * 8)
336 unsigned int *bv = (
unsigned int *)calloc(words,
sizeof(
unsigned));
338 for (i = 0, ix = 0, bx =
MSB; i <
n; ++i) {
367 for (k = 0, c = 0, kx = 0, bx =
MSB; k < D->
NbRays; ++k) {
377 for (j = 0; j <
m + 1; ++j) {
378 for (i = 0; i < c; ++i)
391 for (j = 0; j <
n; j++)
393 for (j = 0; j <
m; j++)
410 fprintf(stderr,
"\nRaysDi=\n");
413 fprintf(stderr,
"Invalid ");
414 fprintf(stderr,
"Pi=\n");
420 fprintf(stderr,
"Eliminated because of no vertex\n");
434 fprintf(stderr,
"Xi = ");
436 fprintf(stderr,
"Pi = ");
445 fprintf(stderr,
"Eliminated because of no inverse Pi\n");
452 fprintf(stderr,
"FACE GENERATED!\n");
453 fprintf(stderr,
"PiInv = ");
462 fprintf(stderr,
"Si = ");
481 fprintf(stderr,
"RaysDi = ");
483 fprintf(stderr,
"PDi = ");
510 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
511 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
512 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
513 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
515 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
516 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
517 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
518 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
520 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
521 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
522 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
523 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
525 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
526 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
527 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
528 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8};
532 register unsigned int i, tmp, cnt = 0;
534 for (i = 0; i <
nr; i++) {
536 cnt = cnt +
cntbit[tmp & 0xff] +
cntbit[(tmp >> 8) & 0xff] +
537 cntbit[(tmp >> 16) & 0xff] +
cntbit[(tmp >> 24) & 0xff];
546 for (j = 0; j < len; j++) {
548 fprintf(stderr,
"mf=%08X Sat=%08X &=%08X\n", part[j], bv[j],
551 if ((part[j] & bv[j]) != part[j])
604 unsigned int *new_mf;
607 fprintf(stderr,
"Start scan_m_face(pos=%d, nb_un=%d, n=%d, m=%d\n", pos,
609 fprintf(stderr,
"mf = ");
612 for (i = 0; i <
nr; i++)
613 fprintf(stderr,
"%08X", mf[i]);
614 fprintf(stderr,
"\nequality = [");
616 fprintf(stderr,
" %1d",
egalite[i]);
617 fprintf(stderr,
"]\n");
628 for (i = 0; i < pos - 1; i++) {
634 fprintf(stderr,
"Sat[%d]\n", i);
638 fprintf(stderr,
"Redundant with constraint %d\n", i);
665 new_mf = (
unsigned int *)malloc(
nr *
sizeof(
unsigned int));
666 for (k = 0; k <
nr; k++)
667 new_mf[k] = mf[k] &
Sat->
p[pos][k];
670 fprintf(stderr,
"new_mf = ");
673 for (i = 0; i <
nr; i++) {
674 fprintf(stderr,
"%08X", new_mf[i]);
676 fprintf(stderr,
"\ncount(new_mf) = %d\n",
count_sat(new_mf));
741 Value *p1, *p2, p3, tmp;
742 unsigned Dimension, NbRay, NbCon, bx;
753 nr = (NbRay - 1) / (
sizeof(
int) * 8) + 1;
755 Temp = (
unsigned int *)malloc(
nr *
sizeof(
unsigned int));
757 memset(Temp, 0,
nr *
sizeof(
unsigned int));
760 for (k = 0; k < NbRay; k++) {
761 for (i = 0; i < NbCon; i++) {
763 p2 = &Pol->
Ray[k][1];
765 for (j = 0; j < Dimension; j++) {
795 int nbRows, nbColumns;
802 for (i = 0, rays = 0; i < nbRows; i++)
809 result->
nbV = nbRows - rays;
815 for (i = 0; i < nbRows; i++) {
825 for (j = 1; j < nbColumns - 1; j++) {
830 paramVertex->
Vertex = vertex;
836 paramVertex->
Facets = NULL;
837 paramVertex->
next = result->
V;
838 result->
V = paramVertex;
843 size = (nbRows - 1) / (8 *
sizeof(
int)) + 1;
847 result->
D->
next = NULL;
849 result->
D->
F = (
unsigned int *)malloc(size *
sizeof(
int));
850 memset(&result->
D->
F[0], 0xFF, size *
sizeof(
int));
873 memset(p, 0,
sizeof(
int) * (E->
NbEq));
876 fprintf(stderr,
"\n\nPreElim_Columns starting\n");
877 fprintf(stderr,
"E =\n");
881 for (l = 0; l < E->
NbEq; ++l) {
883 fprintf(stderr,
"Internal error: Elim_Columns (polyparam.c), expecting "
884 "equalities first in E.\n");
890 fprintf(stderr,
"Internal error: Elim_Columns (polyparam.c), expecting "
891 "non-empty constraint in E.\n");
899 fprintf(stderr,
"p[%d] = %d,", l, p[l]);
906 for (j = 0; j < E->
NbEq; ++j)
911 fprintf(stderr,
"ref[%d] = %d,", i, ref[i]);
918 for (j = 0; j < T->
NbRows; j++)
925 fprintf(stderr,
"\nTransMatrix =\n");
951 fprintf(stderr,
"\nElim_Columns starting\n");
952 fprintf(stderr,
"A =\n");
958 for (l = 0; l < E->
NbEq; ++l) {
959 for (c = 0; c < M->
NbRows; ++c) {
973 fprintf(stderr,
"\nElim_Columns after zeroing columns of A.\n");
974 fprintf(stderr,
"M =\n");
980 for (l = 0; l < C->
NbRows; ++l)
986 fprintf(stderr,
"\nElim_Columns after eliminating columns of A.\n");
987 fprintf(stderr,
"C =\n");
1019 int i, j, nbr, dimfaces;
1026 for (i = 0; i < RC->
NbRays; i++)
1030 for (i = 0, j = 0; j < nbr; i++)
1034 dimfaces = RC->
NbBid;
1038 fprintf(stderr,
"Rays = ");
1040 fprintf(stderr,
"dimfaces = %d\n", dimfaces);
1079 fprintf(stderr,
"Find_m_faces: ?%d parameters of a %d-polyhedron !\n",
m,
1090 fprintf(stderr,
"m = %d\n",
m);
1091 fprintf(stderr,
"D = ");
1093 fprintf(stderr,
"C1 = ");
1100 fprintf(stderr,
"D1 = ");
1116 for (i = 0; i <
n; i++)
1122 fprintf(stderr,
"True context C1 = ");
1131 if (C1->NbEq == 0) {
1142 for (j = 0, i = 0; i < C1->NbEq; ++i, ++j) {
1170 for (i = 0; i < C1->NbConstraints; ++i) {
1188 p = (
int *)malloc(
sizeof(
int) * (CEq1->
NbEq));
1191 ref = (
int *)malloc(
sizeof(
int) * (CEq1->
Dimension + 2 - CEq1->
NbEq));
1199 fprintf(stderr,
"D2\t Dim = %3d\tNbEq = %3d\tLines = %3d\n", D2->
Dimension,
1202 fprintf(stderr,
"C2\t Dim = %3d\tNbEq = %3d\tLines = %3d\n", C2->Dimension,
1203 C2->NbEq, C2->NbBid);
1214 fprintf(stderr,
"Polyhedron CEq = ");
1216 fprintf(stderr,
"Matrix CT = ");
1233 fprintf(stderr,
"Polyhedron D1 (D AND C) = ");
1235 fprintf(stderr,
"Polyhedron CEqualities = ");
1239 fprintf(stderr,
"NULL\n");
1259 fprintf(stderr,
"Sat = ");
1262 fprintf(stderr,
"mf = ");
1263 for (i = 0; i <
nr; i++)
1264 fprintf(stderr,
"%08X", mf[i]);
1265 fprintf(stderr,
"\n");
1269 egalite = (
unsigned int *)malloc(
sizeof(
int) * D1->NbConstraints);
1270 memset(
egalite, 0,
sizeof(
int) * D1->NbConstraints);
1272 for (i = 0; i < D1->NbEq; i++)
1292 if (m_dim < D1->NbBid)
1293 fprintf(stderr,
"m_dim (%d) < D1->NbBid (%d)\n",
m_dim, D1->NbBid);
1295 if (m_dim < D1->NbBid)
1302 fprintf(stderr,
"m_dim = %d\n",
m_dim);
1304 "Target: find faces that saturate %d constraints and %d rays/lines\n",
1314 fprintf(stderr,
"Number of m-faces: %d\n", nbfaces);
1358 if (nb_domains == 0) {
1361 fprintf(stderr,
"No domains\n");
1368 if (!PD->
next && PD->
F)
1372 nv = (nb_domains - 1) / (8 *
sizeof(
int)) + 1;
1375 fprintf(stderr,
"nv = %d\n", nv);
1378 for (p1 = PD, i = 0, ix = 0, bx =
MSB; p1; p1 = p1->
next, i++) {
1381 p1->
F = (
unsigned *)malloc(nv *
sizeof(
unsigned));
1384 memset(p1->
F, 0, nv *
sizeof(
unsigned));
1390 fprintf(stderr,
"nb of vertices=%d\n", i);
1396 for (p1 = PD; p1; p1 = p1->
next) {
1397 for (p2prev = p1, p2 = p1->
next; p2; p2prev = p2, p2 = p2->
next) {
1405 fprintf(stderr,
"Empty dx (p1 inter p2). Continuing\n");
1413 fprintf(stderr,
"Begin PDomainDifference\n");
1414 fprintf(stderr,
"p1=");
1416 fprintf(stderr,
"p2=");
1423 fprintf(stderr,
"p1\\p2=");
1425 fprintf(stderr,
"p2\\p1=");
1427 fprintf(stderr,
"END PDomainDifference\n\n");
1432 fprintf(stderr,
"Empty d1\n");
1441 fprintf(stderr,
"Empty d2 (deleting)\n");
1448 for (i = 0; i < nv; i++)
1449 p1->
F[i] |= p2->
F[i];
1460 fprintf(stderr,
"p2 replaced by d2\n");
1463 for (i = 0; i < nv; i++)
1464 p1->
F[i] |= p2->
F[i];
1474 fprintf(stderr,
"p1 replaced by d1\n");
1483 for (i = 0; i < nv; i++)
1484 p2->
F[i] |= p1->
F[i];
1492 fprintf(stderr,
"Non-empty d1 and d2\nNew node created\n");
1496 PDNew->
F = (
unsigned int *)malloc(nv *
sizeof(
int));
1497 memset(PDNew->
F, 0, nv *
sizeof(
int));
1500 for (i = 0; i < nv; i++)
1501 PDNew->
F[i] = p1->
F[i] | p2->
F[i];
1532 int working_space) {
1542 fprintf(stderr,
"Polyhedron2Param_Vertices algorithm starting at : %.2fs\n",
1543 (
float)clock() / CLOCKS_PER_SEC);
1547 result =
Find_m_faces(&Din, Cin, 0, working_space, NULL, NULL);
1550 fprintf(stderr,
"nb of points : %d\n", result->
nbV);
1554 fprintf(stderr,
"end main loop : %.2fs\n", (
float)clock() / CLOCKS_PER_SEC);
1592 for (l = 0; l < V->
NbRows; ++l) {
1597 for (v = 0; v < V->
NbColumns - 2; ++v) {
1616 fprintf(DST,
"%s/", param_names[v]);
1619 fprintf(DST,
"%s", param_names[v]);
1638 if (l < V->NbRows - 1)
1660 for (i = 0; i < V->
NbRows; ++i) {
1663 for (k = 0; k < CT->
NbRows; k++)
1694 fprintf(DST,
"%s ", pname[v - 1]);
1696 fprintf(DST,
"+ %s ", pname[v - 1]);
1698 fprintf(DST,
"- %s ", pname[v - 1]);
1703 fprintf(DST,
"%s ", pname[v - 1]);
1720 fprintf(DST,
"UNION\n");
1731 const char **param_names) {
1735 fprintf(DST,
"Vertex :\n");
1739 fprintf(DST,
" If :\n");
1756 int working_space) {
1770 fprintf(stderr,
"Polyhedron2Param_Polyhedron algorithm starting at : %.2fs\n",
1771 (
float)clock() / CLOCKS_PER_SEC);
1776 result =
Find_m_faces(&Din, Cin, 1, working_space, NULL, NULL);
1780 fprintf(stderr,
"Number of vertices : %d\n", result->
nbV);
1781 fprintf(stderr,
"Vertices found at : %.2fs\n",
1782 (
float)clock() / CLOCKS_PER_SEC);
1789 for (D = result->
D; D; D = D->
next)
1794 fprintf(stderr,
"domains found at : %.2fs\n",
1795 (
float)clock() / CLOCKS_PER_SEC);
1821 fprintf(stderr,
"Polyhedron2Param_Polyhedron algorithm starting at : %.2fs\n",
1822 (
float)clock() / CLOCKS_PER_SEC);
1827 result =
Find_m_faces(Din, Cin, 1, working_space, CEq, CT);
1831 fprintf(stderr,
"Number of vertices : %d\n", result->
nbV);
1832 fprintf(stderr,
"Vertices found at : %.2fs\n",
1833 (
float)clock() / CLOCKS_PER_SEC);
1847 fprintf(stderr,
"domains found at : %.2fs\n",
1848 (
float)clock() / CLOCKS_PER_SEC);
1893 Value *det,
unsigned MaxRays) {
1895 int nb_param, nb_vars;
1898 Value global_var_lcm;
1915 for (V = PP->
V; V; V = V->
next)
1916 for (i = 0; i < nb_vars; i++)
1920 for (i = 0; i < nb_vars; i++) {
1922 value_lcm(global_var_lcm, global_var_lcm, denoms->
p[i]);
1926 for (V = PP->
V; V; V = V->
next)
1927 for (i = 0; i < nb_vars; i++) {
1935 for (i = 0; i < nb_vars; i++)
1941 expansion =
Matrix_Alloc(nb_vars + nb_param + 1, nb_vars + nb_param + 1);
1942 for (i = 0; i < nb_vars; i++)
1944 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)
Return the intersection of two polyhedral domains 'Pol1' and 'Pol2'.
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
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)
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)
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)
void Param_Vertices_Print(FILE *DST, Param_Vertices *PV, const char **param_names)
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)
static void SMPrint(SatMatrix *matrix)
Matrix * PreElim_Columns(Polyhedron *E, int *p, int *ref, int m)
Polyhedron * PDomainIntersection(Polyhedron *Pol1, Polyhedron *Pol2, unsigned NbMaxRays)
void Print_Vertex(FILE *DST, Matrix *V, const char **param_names)
void Print_Domain(FILE *DST, Polyhedron *D, const char **pname)
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)