polylib 5.22.8
Zpolytest.c
Go to the documentation of this file.
1/* zpolytest.c
2This is a testbench for the Zpolylib (part of polylib manipulating
3Z-polyhedra. */
4
5#include <stdio.h>
6#include <polylib/polylib.h>
7
8#define WS 0
9
10char s[128];
11
12int main() {
13
14 Matrix *a=NULL, *b=NULL, *c=NULL, *d, *e, *g;
15 LatticeUnion *l1,*l2,*l3,*l4,*temp;
16 Polyhedron *A=NULL, *B=NULL, *C=NULL, *D;
17 ZPolyhedron *ZA, *ZB, *ZC, *ZD, *Zlast;
18 int nbPol, nbMat, func, rank ;
19 Vector *v=NULL;
20
21 /* The structure of the input file to this program is the following:
22 First a line containing
23 M nbMat
24 Where nbMat is an integer indicating how many Matrices will
25 be described in the following. temporary debugging. Next
26 the matrice are described. For each matrix, the first row is two
27 integers:
28 nbRows nbColumns
29 Then the matrix is written row by row. a line starting with
30 a `#' is considered as a comment
31
32 Then a line containing
33 D nbDomain
34 where nbDomain is an integer indicating how many domain will
35 be described in the following. Domains are describled as for
36 polylib, the first row is two integers:
37 nbConstraints dimension
38 then the constraints are described in the Polylib format.
39 The last line of the input file contains :
40 F numTest
41 which indicates which test will be performed on the data.
42 Warning, currently no more than 3 matrice of Polyhedra can be read*/
43
44 fgets(s, 128, stdin);
45 nbPol = nbMat = 0;
46 while ( (*s=='#') ||
47 ((sscanf(s, "D %d", &nbPol)<1) && (sscanf(s, "M %d", &nbMat)<1)) )
48 fgets(s, 128, stdin);
49
50
51 /* debug */
52 /* fprintf(stdout,"nbMat=%d",nbMat);fflush(stdout); */
53
54 switch (nbMat) {
55
56 case 1:
57 a = Matrix_Read();
58 break;
59
60 case 2:
61 a = Matrix_Read();
62 b = Matrix_Read();
63 break;
64
65 case 3: a = Matrix_Read();
66 b = Matrix_Read();
67 c = Matrix_Read();
68 break;
69 }
70
71 fgets(s, 128, stdin);
72 while ((*s=='#') ||
73 ((sscanf(s, "D %d", &nbPol)<1) && (sscanf(s, "M %d", &nbMat)<1)) )
74 fgets(s, 128, stdin);
75
76
77 /* debug */
78 /* fprintf(stdout,"nbPol=%d",nbPol);fflush(stdout); */
79
80 switch (nbPol) {
81
82 case 1:
83 g = Matrix_Read();
85 Matrix_Free(g);
86 break;
87
88 case 2:
89 g = Matrix_Read();
91 Matrix_Free(g);
92 g = Matrix_Read();
94 Matrix_Free(g);
95 break;
96
97 case 3:
98 g = Matrix_Read();
100 Matrix_Free(g);
101 g = Matrix_Read();
103 Matrix_Free(g);
104 g = Matrix_Read();
106 Matrix_Free(g);
107 break;
108 }
109
110 fgets(s, 128, stdin);
111 while ((*s=='#') || (sscanf(s, "F %d", &func)<1) ) fgets(s, 128, stdin);
112
113
114 switch (func) {
115
116 case 1:
117
118 /* just a test of polylib functions */
119 C = DomainUnion(A, B, 200);
120 D = DomainConvex(C, 200);
122 Matrix_Print(stdout,P_VALUE_FMT, d);
123 Matrix_Free(d);
124 Domain_Free(D);
125 break;
126
127 case 2: /* AffineHermite */
128
129 AffineHermite(a,&b,&c);
130 Matrix_Print(stdout,P_VALUE_FMT, b);
131 Matrix_Print(stdout,P_VALUE_FMT, c);
132 break;
133
134 case 3: /* LatticeIntersection */
135
136 c = LatticeIntersection(a,b);
137 Matrix_Print(stdout,P_VALUE_FMT, c);
138 break;
139
140 case 4: /* LatticeDifference */
141
142 fprintf(stdout," 2 in 1 : %d\n",LatticeIncludes(b,a));
143 fprintf(stdout," 1 in 3 : %d\n",LatticeIncludes(c,a));
144 fprintf(stdout," 1 in 2 : %d\n",LatticeIncludes(a,b));
145 break;
146
147 case 5: /* LatticeDifference */
148
149 l1=LatticeDifference(a,b);
150 l2=LatticeDifference(b,a);
151 l3=LatticeDifference(c,a);
152 l4=LatticeDifference(b,c);
153 fprintf(stdout,"L1 - L2 :\n");
154 temp=l1;
155 while (temp!=NULL) {
156
157 Matrix_Print(stdout,P_VALUE_FMT,temp->M);
158 temp=temp->next;
159 };
160 fprintf(stdout,"Diff2:\n");
161 temp=l2;
162 while (temp!=NULL) {
163 Matrix_Print(stdout,P_VALUE_FMT, temp->M);
164 temp=temp->next;
165 };
166 fprintf(stdout,"Diff3:\n");
167 temp=l3;
168 while (temp!=NULL) {
169 Matrix_Print(stdout,P_VALUE_FMT, temp->M);
170 temp=temp->next;
171 };
172 fprintf(stdout,"Diff4:\n");
173 temp=l4;
174 while (temp!=NULL) {
175 Matrix_Print(stdout,P_VALUE_FMT, temp->M);
176 temp=temp->next;
177 };
178 break;
179
180 case 6: /* isEmptyZPolyhedron */
181
182 ZA=ZPolyhedron_Alloc(a,A);
183 fprintf(stdout,"is Empty? :%d \n", isEmptyZPolyhedron(ZA));
184 ZDomain_Free(ZA);
185 break;
186
187 case 7: /* ZDomainIntersection */
188
189 ZA=ZPolyhedron_Alloc(a,A);
190 ZB=ZPolyhedron_Alloc(b,B);
191 ZC = ZDomainIntersection(ZA,ZB);
192 ZDomainPrint(stdout,P_VALUE_FMT, ZC);
193 ZDomain_Free(ZA);
194 ZDomain_Free(ZB);
195 ZDomain_Free(ZC);
196 break;
197
198 case 8: /* ZDomainUnion */
199
200 ZA=ZPolyhedron_Alloc(a,A);
201 ZB=ZPolyhedron_Alloc(b,B);
202 ZC = ZDomainUnion(ZA,ZB);
203 ZDomainPrint(stdout,P_VALUE_FMT, ZC);
204 break;
205
206 case 9: /* ZDomainDifference */
207
208 ZA=ZPolyhedron_Alloc(a,A);
209 ZB=ZPolyhedron_Alloc(b,B);
210 ZC = ZDomainDifference(ZA,ZB);
211 ZDomainPrint(stdout,P_VALUE_FMT, ZC);
212 break;
213
214 case 10: /* ZDomainImage */
215
216 ZA=ZPolyhedron_Alloc(a,A);
217 ZC = ZDomainImage(ZA,b);
218 ZDomainPrint(stdout,P_VALUE_FMT, ZC);
219 break;
220
221 case 11: /* ZDomainPreimage */
222
223 ZA=ZPolyhedron_Alloc(a,A);
224 ZC = ZDomainPreimage(ZA,b);
225 ZDomainPrint(stdout,P_VALUE_FMT, ZC);
226 break;
227
228 case 12: /* ZDomainDifference */
229 ZA=ZPolyhedron_Alloc(a,A);
230 ZC = ZDomainPreimage(ZA,b);
231 ZD = ZDomainImage(ZC,b);
232 Zlast=ZDomainDifference(ZD,ZC);
233 fprintf(stdout,"the Two zpol are equal? :%d\n",
234 isEmptyZPolyhedron(Zlast));
235 break;
236
237 case 13: /* ZDomainSimplify */
238
239 ZA=ZPolyhedron_Alloc(a,A);
240 ZA->next = ZPolyhedron_Alloc(b,B);
241 ZDomainPrint(stdout,P_VALUE_FMT, ZA);
242 ZD = ZDomainSimplify(ZA);
243 ZDomainPrint(stdout,P_VALUE_FMT, ZD);
244 break;
245
246 case 14: /* EmptyZpolyhedron */
247
248 ZA=EmptyZPolyhedron(3);
249 fprintf(stdout,"is Empty? :%d \n", isEmptyZPolyhedron(ZA));
250 ZDomain_Free(ZA);
251 break;
252
253 case 15: /* ZDomainInclude */
254
255 ZA=ZPolyhedron_Alloc(a,A);
256 ZB=ZPolyhedron_Alloc(b,B);
257 fprintf(stdout,"A in B :%d \nB in A :%d \n",
258 ZPolyhedronIncludes(ZA,ZB),
259 ZPolyhedronIncludes(ZB,ZA));
260 break;
261
262 case 16: /* LatticePreimage */
263
264 c = LatticePreimage(a,b);
265 Matrix_Print(stdout,P_VALUE_FMT, c);
266 AffineHermite(c,&d,&e);
267 Matrix_Print(stdout,P_VALUE_FMT, d);
268 break;
269
270 case 17: /* LatticeImage */
271
272 c = LatticeImage(a,b);
273 Matrix_Print(stdout,P_VALUE_FMT, c);
274 AffineHermite(c,&d,&e);
275 Matrix_Print(stdout,P_VALUE_FMT, d);
276 break;
277
278 case 18: /* EmptyLattice */
279
280 fprintf(stdout,"is Empty? :%d \n", isEmptyLattice(a));
281 fprintf(stdout,"is Empty? :%d \n", isEmptyLattice(EmptyLattice(3)));
282 break;
283
284 case 19: /* CanonicalForm */
285
286 ZA=ZPolyhedron_Alloc(a,A);
287 ZB=ZPolyhedron_Alloc(a,B);
288 CanonicalForm(ZA,&ZC,&c);
289 CanonicalForm(ZB,&ZD,&d);
290 ZDomainPrint(stdout,P_VALUE_FMT, ZC);
291 ZDomainPrint(stdout,P_VALUE_FMT, ZD);
292 break;
293
294 case 20: /* LatticeSimplify */
295
298 l1->M=Matrix_Copy(a);
299 l1->next=l2;
300 l2->M=Matrix_Copy(b);
301 l1=LatticeSimplify(l1);
302 PrintLatticeUnion(stdout,P_VALUE_FMT,l1);
304 break;
305
306 case 21: /* AffineSmith */
307
308 AffineSmith(a,&b,&c, &d);
309 Matrix_Print(stdout,P_VALUE_FMT, b);
310 Matrix_Print(stdout,P_VALUE_FMT, c);
311 Matrix_Print(stdout,P_VALUE_FMT, d);
312 Matrix_Free(d);
313 break;
314
315 case 22: /* SolveDiophantine */
316
317 rank=SolveDiophantine(a,&d,&v);
318 Matrix_Print(stdout,P_VALUE_FMT, a);
319 fprintf(stdout," rank: %d \n ",rank);
320 Matrix_Print(stdout,P_VALUE_FMT, d);
321 Vector_Print(stdout,P_VALUE_FMT, v);
322 rank=SolveDiophantine(b,&d,&v);
323 Matrix_Print(stdout,P_VALUE_FMT, b);
324 fprintf(stdout," rank: %d \n ",rank);
325 Matrix_Print(stdout,P_VALUE_FMT, d);
326 Vector_Print(stdout,P_VALUE_FMT, v);
327 rank=SolveDiophantine(c,&d,&v);
328 Matrix_Print(stdout,P_VALUE_FMT, c);
329 fprintf(stdout," rank: %d \n ",rank);
330 Matrix_Print(stdout,P_VALUE_FMT, d);
331 Vector_Print(stdout,P_VALUE_FMT, v);
332 Vector_Free(v);
333 break;
334
335 case 23: /* SplitZPolyhedron */
336
337 ZA=ZPolyhedron_Alloc(a,A);
338 ZC = SplitZpolyhedron(ZA,b);
339 ZDomainPrint(stdout,P_VALUE_FMT, ZC);
340 break;
341
342
343 case 100: /* debug */
344
345 ZA=ZPolyhedron_Alloc(a,A);
346 ZDomainPrint(stdout,P_VALUE_FMT, ZA);
347 ZDomain_Free(ZA);
348 break;
349
350 default:
351 printf("? unknown function\n");
352 }
353
354 /* Polyhedron_Free(A); */
355 if (a)
356 Matrix_Free(a);
357 if (b)
358 Matrix_Free(b);
359 if (c)
360 Matrix_Free(c);
361
362 if (A)
363 Domain_Free(A);
364 if (B)
365 Domain_Free(B);
366 if (C)
367 Domain_Free(C);
368
369 return 0;
370} /* main */
Lattice * EmptyLattice(int dimension)
Definition: Lattice.c:77
LatticeUnion * LatticeUnion_Alloc(void)
Definition: Lattice.c:42
void AffineHermite(Lattice *A, Lattice **H, Matrix **U)
Definition: Lattice.c:158
LatticeUnion * LatticeDifference(Lattice *A, Lattice *B)
Method :
Definition: Lattice.c:802
Bool isEmptyLattice(Lattice *A)
Definition: Lattice.c:100
Lattice * LatticeIntersection(Lattice *X, Lattice *Y)
Definition: Lattice.c:459
Bool LatticeIncludes(Lattice *A, Lattice *B)
Definition: Lattice.c:324
LatticeUnion * LatticeSimplify(LatticeUnion *latlist)
Definition: Lattice.c:1654
void AffineSmith(Lattice *A, Lattice **U, Lattice **V, Lattice **Diag)
Definition: Lattice.c:203
Lattice * LatticePreimage(Lattice *L, Matrix *G)
Definition: Lattice.c:1158
void LatticeUnion_Free(LatticeUnion *Head)
Definition: Lattice.c:26
void PrintLatticeUnion(FILE *fp, char *format, LatticeUnion *Head)
Definition: Lattice.c:14
Lattice * LatticeImage(Lattice *A, Matrix *M)
Definition: Lattice.c:1119
Matrix * Matrix_Copy(Matrix const *Src)
Definition: Matop.c:98
int SolveDiophantine(Matrix *M, Matrix **U, Vector **X)
Definition: SolveDio.c:64
ZPolyhedron * ZDomainIntersection(ZPolyhedron *A, ZPolyhedron *B)
Definition: Zpolyhedron.c:375
ZPolyhedron * ZDomainSimplify(ZPolyhedron *ZDom)
Definition: Zpolyhedron.c:871
void ZDomain_Free(ZPolyhedron *Head)
Definition: Zpolyhedron.c:75
ZPolyhedron * SplitZpolyhedron(ZPolyhedron *ZPol, Lattice *B)
Definition: Zpolyhedron.c:955
ZPolyhedron * ZDomainDifference(ZPolyhedron *A, ZPolyhedron *B)
Definition: Zpolyhedron.c:412
void ZDomainPrint(FILE *fp, const char *format, ZPolyhedron *A)
Definition: Zpolyhedron.c:319
ZPolyhedron * ZPolyhedron_Alloc(Lattice *Lat, Polyhedron *Poly)
Definition: Zpolyhedron.c:37
Bool isEmptyZPolyhedron(ZPolyhedron *Zpol)
Definition: Zpolyhedron.c:22
ZPolyhedron * EmptyZPolyhedron(int dimension)
Definition: Zpolyhedron.c:245
ZPolyhedron * ZDomainImage(ZPolyhedron *A, Matrix *Func)
Definition: Zpolyhedron.c:466
ZPolyhedron * ZDomainPreimage(ZPolyhedron *A, Matrix *Func)
Definition: Zpolyhedron.c:494
ZPolyhedron * ZDomainUnion(ZPolyhedron *A, ZPolyhedron *B)
Definition: Zpolyhedron.c:353
void CanonicalForm(ZPolyhedron *Zpol, ZPolyhedron **Result, Matrix **Basis)
Definition: Zpolyhedron.c:743
Bool ZPolyhedronIncludes(ZPolyhedron *A, ZPolyhedron *B)
Definition: Zpolyhedron.c:287
char s[128]
Definition: Zpolytest.c:10
#define WS
Definition: Zpolytest.c:8
int main()
Definition: Zpolytest.c:12
Matrix * Matrix_Read(void)
Definition: matrix.c:209
void Matrix_Print(FILE *Dst, const char *Format, Matrix *Mat)
Definition: matrix.c:115
void Matrix_Free(Matrix *Mat)
Definition: matrix.c:71
Polyhedron * DomainConvex(Polyhedron *Pol, unsigned NbMaxConstrs)
Definition: polyhedron.c:3659
Polyhedron * DomainUnion(Polyhedron *Pol1, Polyhedron *Pol2, unsigned NbMaxRays)
Definition: polyhedron.c:3585
Matrix * Polyhedron2Constraints(Polyhedron *Pol)
Definition: polyhedron.c:2060
Polyhedron * Constraints2Polyhedron(Matrix *Constraints, unsigned NbMaxRays)
Given a matrix of constraints ('Constraints'), construct and return a polyhedron.
Definition: polyhedron.c:1905
void Domain_Free(Polyhedron *Pol)
Definition: polyhedron.c:1626
struct LatticeUnion * next
Definition: types.h:222
Lattice * M
Definition: types.h:221
Definition: types.h:70
struct ZPolyhedron * next
Definition: types.h:228
Definition: types.h:75
#define P_VALUE_FMT
Definition: types.h:39
void Vector_Free(Vector *vector)
Definition: vector.c:162
void Vector_Print(FILE *Dst, const char *Format, Vector *vector)
Definition: vector.c:177