2 This is a testbench for the Zpolylib (part of polylib manipulating
6 #include <polylib/polylib.h>
12 Matrix
*a
=NULL
, *b
, *c
, *d
, *e
, *g
;
13 LatticeUnion
*l1
,*l2
,*l3
,*l4
,*temp
;
14 Polyhedron
*A
=NULL
, *B
=NULL
, *C
, *D
;
15 ZPolyhedron
*ZA
, *ZB
, *ZC
, *ZD
, *Zlast
;
16 int nbPol
, nbMat
, func
, rank
;
19 /* The structure of the input file to this program is the following:
20 First a line containing
22 Where nbMat is an integer indicating how many Matrices will
23 be described in the following. temporary debugging. Next
24 the matrice are described. For each matrix, the first row is two
27 Then the matrix is written row by row. a line starting with
28 a `#' is considered as a comment
30 Then a line containing
32 where nbDomain is an integer indicating how many domain will
33 be described in the following. Domains are describled as for
34 polylib, the first row is two integers:
35 nbConstraints dimension
36 then the constraints are described in the Polylib format.
37 The last line of the input file contains :
39 which indicates which test will be performed on the data.
40 Warning, currently no more than 3 matrice of Polyhedra can be read*/
45 ((sscanf(s
, "D %d", &nbPol
)<1) && (sscanf(s
, "M %d", &nbMat
)<1)) )
50 /* fprintf(stdout,"nbMat=%d",nbMat);fflush(stdout); */
63 case 3: a
= Matrix_Read();
71 ((sscanf(s
, "D %d", &nbPol
)<1) && (sscanf(s
, "M %d", &nbMat
)<1)) )
76 /* fprintf(stdout,"nbPol=%d",nbPol);fflush(stdout); */
82 A
= Constraints2Polyhedron(g
,2000);
88 A
= Constraints2Polyhedron(g
,2000);
91 B
= Constraints2Polyhedron(g
,2000);
97 A
= Constraints2Polyhedron(g
,2000);
100 B
= Constraints2Polyhedron(g
,2000);
103 C
= Constraints2Polyhedron(g
,2000);
108 fgets(s
, 128, stdin
);
109 while ((*s
=='#') || (sscanf(s
, "F %d", &func
)<1) ) fgets(s
, 128, stdin
);
116 /* just a test of polylib functions */
117 C
= DomainUnion(A
, B
, 200);
118 D
= DomainConvex(C
, 200);
119 d
= Polyhedron2Constraints(D
);
120 Matrix_Print(stdout
,P_VALUE_FMT
, d
);
126 case 2: /* AffineHermite */
128 AffineHermite(a
,&b
,&c
);
129 Matrix_Print(stdout
,P_VALUE_FMT
, b
);
130 Matrix_Print(stdout
,P_VALUE_FMT
, c
);
136 case 3: /* LatticeIntersection */
138 c
= LatticeIntersection(a
,b
);
139 Matrix_Print(stdout
,P_VALUE_FMT
, c
);
145 case 4: /* LatticeDifference */
147 fprintf(stdout
," 2 in 1 : %d\n",LatticeIncludes(b
,a
));
148 fprintf(stdout
," 1 in 3 : %d\n",LatticeIncludes(c
,a
));
149 fprintf(stdout
," 1 in 2 : %d\n",LatticeIncludes(a
,b
));
155 case 5: /* LatticeDifference */
157 l1
=LatticeDifference(a
,b
);
158 l2
=LatticeDifference(b
,a
);
159 l3
=LatticeDifference(c
,a
);
160 l4
=LatticeDifference(b
,c
);
161 fprintf(stdout
,"L1 - L2 :\n");
165 Matrix_Print(stdout
,P_VALUE_FMT
,temp
->M
);
168 fprintf(stdout
,"Diff2:\n");
171 Matrix_Print(stdout
,P_VALUE_FMT
, temp
->M
);
174 fprintf(stdout
,"Diff3:\n");
177 Matrix_Print(stdout
,P_VALUE_FMT
, temp
->M
);
180 fprintf(stdout
,"Diff4:\n");
183 Matrix_Print(stdout
,P_VALUE_FMT
, temp
->M
);
191 case 6: /* isEmptyZPolyhedron */
193 ZA
=ZPolyhedron_Alloc(a
,A
);
194 fprintf(stdout
,"is Empty? :%d \n", isEmptyZPolyhedron(ZA
));
198 case 7: /* ZDomainIntersection */
200 ZA
=ZPolyhedron_Alloc(a
,A
);
201 ZB
=ZPolyhedron_Alloc(b
,B
);
202 ZC
= ZDomainIntersection(ZA
,ZB
);
203 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
206 case 8: /* ZDomainUnion */
208 ZA
=ZPolyhedron_Alloc(a
,A
);
209 ZB
=ZPolyhedron_Alloc(b
,B
);
210 ZC
= ZDomainUnion(ZA
,ZB
);
211 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
214 case 9: /* ZDomainDifference */
216 ZA
=ZPolyhedron_Alloc(a
,A
);
217 ZB
=ZPolyhedron_Alloc(b
,B
);
218 ZC
= ZDomainDifference(ZA
,ZB
);
219 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
222 case 10: /* ZDomainImage */
224 ZA
=ZPolyhedron_Alloc(a
,A
);
225 ZC
= ZDomainImage(ZA
,b
);
226 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
229 case 11: /* ZDomainPreimage */
231 ZA
=ZPolyhedron_Alloc(a
,A
);
232 ZC
= ZDomainPreimage(ZA
,b
);
233 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
236 case 12: /* ZDomainDifference */
237 ZA
=ZPolyhedron_Alloc(a
,A
);
238 ZC
= ZDomainPreimage(ZA
,b
);
239 ZD
= ZDomainImage(ZC
,b
);
240 Zlast
=ZDomainDifference(ZD
,ZC
);
241 fprintf(stdout
,"the Two zpol are equal? :%d\n",
242 isEmptyZPolyhedron(Zlast
));
245 case 13: /* ZDomainSimplify */
247 ZA
=ZPolyhedron_Alloc(a
,A
);
248 ZA
->next
= ZPolyhedron_Alloc(b
,B
);
249 ZDomainPrint(stdout
,P_VALUE_FMT
, ZA
);
250 ZD
= ZDomainSimplify(ZA
);
251 ZDomainPrint(stdout
,P_VALUE_FMT
, ZD
);
254 case 14: /* EmptyZpolyhedron */
256 ZA
=EmptyZPolyhedron(3);
257 fprintf(stdout
,"is Empty? :%d \n", isEmptyZPolyhedron(ZA
));
261 case 15: /* ZDomainInclude */
263 ZA
=ZPolyhedron_Alloc(a
,A
);
264 ZB
=ZPolyhedron_Alloc(b
,B
);
265 fprintf(stdout
,"A in B :%d \nB in A :%d \n",
266 ZPolyhedronIncludes(ZA
,ZB
),
267 ZPolyhedronIncludes(ZB
,ZA
));
270 case 16: /* LatticePreimage */
272 c
= LatticePreimage(a
,b
);
273 Matrix_Print(stdout
,P_VALUE_FMT
, c
);
274 AffineHermite(c
,&d
,&e
);
275 Matrix_Print(stdout
,P_VALUE_FMT
, d
);
278 case 17: /* LatticeImage */
280 c
= LatticeImage(a
,b
);
281 Matrix_Print(stdout
,P_VALUE_FMT
, c
);
282 AffineHermite(c
,&d
,&e
);
283 Matrix_Print(stdout
,P_VALUE_FMT
, d
);
286 case 18: /* EmptyLattice */
288 fprintf(stdout
,"is Empty? :%d \n", isEmptyLattice(a
));
289 fprintf(stdout
,"is Empty? :%d \n", isEmptyLattice(EmptyLattice(3)));
292 case 19: /* CanonicalForm */
294 ZA
=ZPolyhedron_Alloc(a
,A
);
295 ZB
=ZPolyhedron_Alloc(a
,B
);
296 CanonicalForm(ZA
,&ZC
,&c
);
297 CanonicalForm(ZB
,&ZD
,&d
);
298 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
299 ZDomainPrint(stdout
,P_VALUE_FMT
, ZD
);
302 case 20: /* LatticeSimplify */
304 l1
=LatticeUnion_Alloc();
305 l2
=LatticeUnion_Alloc();
306 l1
->M
=Matrix_Copy(a
);
308 l2
->M
=Matrix_Copy(b
);
309 l1
=LatticeSimplify(l1
);
310 PrintLatticeUnion(stdout
,P_VALUE_FMT
,l1
);
311 LatticeUnion_Free(l1
);
314 case 21: /* AffineSmith */
316 AffineSmith(a
,&b
,&c
, &d
);
317 Matrix_Print(stdout
,P_VALUE_FMT
, b
);
318 Matrix_Print(stdout
,P_VALUE_FMT
, c
);
319 Matrix_Print(stdout
,P_VALUE_FMT
, d
);
326 case 22: /* SolveDiophantine */
328 rank
=SolveDiophantine(a
,&d
,&v
);
329 Matrix_Print(stdout
,P_VALUE_FMT
, a
);
330 fprintf(stdout
," rank: %d \n ",rank
);
331 Matrix_Print(stdout
,P_VALUE_FMT
, d
);
332 Vector_Print(stdout
,P_VALUE_FMT
, v
);
333 rank
=SolveDiophantine(b
,&d
,&v
);
334 Matrix_Print(stdout
,P_VALUE_FMT
, b
);
335 fprintf(stdout
," rank: %d \n ",rank
);
336 Matrix_Print(stdout
,P_VALUE_FMT
, d
);
337 Vector_Print(stdout
,P_VALUE_FMT
, v
);
338 rank
=SolveDiophantine(c
,&d
,&v
);
339 Matrix_Print(stdout
,P_VALUE_FMT
, c
);
340 fprintf(stdout
," rank: %d \n ",rank
);
341 Matrix_Print(stdout
,P_VALUE_FMT
, d
);
342 Vector_Print(stdout
,P_VALUE_FMT
, v
);
349 case 23: /* SplitZPolyhedron */
351 ZA
=ZPolyhedron_Alloc(a
,A
);
352 ZC
= SplitZpolyhedron(ZA
,b
);
353 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
357 case 100: /* debug */
359 ZA
=ZPolyhedron_Alloc(a
,A
);
360 ZDomainPrint(stdout
,P_VALUE_FMT
, ZA
);
365 printf("? unknown function\n");
368 /* Polyhedron_Free(A); */