2 This is a testbench for the Zpolylib (part of polylib manipulating
6 #include <polylib/polylib.h>
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
;
21 /* The structure of the input file to this program is the following:
22 First a line containing
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
29 Then the matrix is written row by row. a line starting with
30 a `#' is considered as a comment
32 Then a line containing
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 :
41 which indicates which test will be performed on the data.
42 Warning, currently no more than 3 matrice of Polyhedra can be read*/
47 ((sscanf(s
, "D %d", &nbPol
)<1) && (sscanf(s
, "M %d", &nbMat
)<1)) )
52 /* fprintf(stdout,"nbMat=%d",nbMat);fflush(stdout); */
65 case 3: a
= Matrix_Read();
73 ((sscanf(s
, "D %d", &nbPol
)<1) && (sscanf(s
, "M %d", &nbMat
)<1)) )
78 /* fprintf(stdout,"nbPol=%d",nbPol);fflush(stdout); */
84 A
= Constraints2Polyhedron(g
,WS
);
90 A
= Constraints2Polyhedron(g
,WS
);
93 B
= Constraints2Polyhedron(g
,WS
);
99 A
= Constraints2Polyhedron(g
,WS
);
102 B
= Constraints2Polyhedron(g
,WS
);
105 C
= Constraints2Polyhedron(g
,WS
);
110 fgets(s
, 128, stdin
);
111 while ((*s
=='#') || (sscanf(s
, "F %d", &func
)<1) ) fgets(s
, 128, stdin
);
118 /* just a test of polylib functions */
119 C
= DomainUnion(A
, B
, 200);
120 D
= DomainConvex(C
, 200);
121 d
= Polyhedron2Constraints(D
);
122 Matrix_Print(stdout
,P_VALUE_FMT
, d
);
127 case 2: /* AffineHermite */
129 AffineHermite(a
,&b
,&c
);
130 Matrix_Print(stdout
,P_VALUE_FMT
, b
);
131 Matrix_Print(stdout
,P_VALUE_FMT
, c
);
134 case 3: /* LatticeIntersection */
136 c
= LatticeIntersection(a
,b
);
137 Matrix_Print(stdout
,P_VALUE_FMT
, c
);
140 case 4: /* LatticeDifference */
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
));
147 case 5: /* LatticeDifference */
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");
157 Matrix_Print(stdout
,P_VALUE_FMT
,temp
->M
);
160 fprintf(stdout
,"Diff2:\n");
163 Matrix_Print(stdout
,P_VALUE_FMT
, temp
->M
);
166 fprintf(stdout
,"Diff3:\n");
169 Matrix_Print(stdout
,P_VALUE_FMT
, temp
->M
);
172 fprintf(stdout
,"Diff4:\n");
175 Matrix_Print(stdout
,P_VALUE_FMT
, temp
->M
);
180 case 6: /* isEmptyZPolyhedron */
182 ZA
=ZPolyhedron_Alloc(a
,A
);
183 fprintf(stdout
,"is Empty? :%d \n", isEmptyZPolyhedron(ZA
));
187 case 7: /* ZDomainIntersection */
189 ZA
=ZPolyhedron_Alloc(a
,A
);
190 ZB
=ZPolyhedron_Alloc(b
,B
);
191 ZC
= ZDomainIntersection(ZA
,ZB
);
192 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
198 case 8: /* ZDomainUnion */
200 ZA
=ZPolyhedron_Alloc(a
,A
);
201 ZB
=ZPolyhedron_Alloc(b
,B
);
202 ZC
= ZDomainUnion(ZA
,ZB
);
203 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
206 case 9: /* ZDomainDifference */
208 ZA
=ZPolyhedron_Alloc(a
,A
);
209 ZB
=ZPolyhedron_Alloc(b
,B
);
210 ZC
= ZDomainDifference(ZA
,ZB
);
211 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
214 case 10: /* ZDomainImage */
216 ZA
=ZPolyhedron_Alloc(a
,A
);
217 ZC
= ZDomainImage(ZA
,b
);
218 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
221 case 11: /* ZDomainPreimage */
223 ZA
=ZPolyhedron_Alloc(a
,A
);
224 ZC
= ZDomainPreimage(ZA
,b
);
225 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
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
));
237 case 13: /* ZDomainSimplify */
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
);
246 case 14: /* EmptyZpolyhedron */
248 ZA
=EmptyZPolyhedron(3);
249 fprintf(stdout
,"is Empty? :%d \n", isEmptyZPolyhedron(ZA
));
253 case 15: /* ZDomainInclude */
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
));
262 case 16: /* LatticePreimage */
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
);
270 case 17: /* LatticeImage */
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
);
278 case 18: /* EmptyLattice */
280 fprintf(stdout
,"is Empty? :%d \n", isEmptyLattice(a
));
281 fprintf(stdout
,"is Empty? :%d \n", isEmptyLattice(EmptyLattice(3)));
284 case 19: /* CanonicalForm */
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
);
294 case 20: /* LatticeSimplify */
296 l1
=LatticeUnion_Alloc();
297 l2
=LatticeUnion_Alloc();
298 l1
->M
=Matrix_Copy(a
);
300 l2
->M
=Matrix_Copy(b
);
301 l1
=LatticeSimplify(l1
);
302 PrintLatticeUnion(stdout
,P_VALUE_FMT
,l1
);
303 LatticeUnion_Free(l1
);
306 case 21: /* AffineSmith */
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
);
315 case 22: /* SolveDiophantine */
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
);
335 case 23: /* SplitZPolyhedron */
337 ZA
=ZPolyhedron_Alloc(a
,A
);
338 ZC
= SplitZpolyhedron(ZA
,b
);
339 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
343 case 100: /* debug */
345 ZA
=ZPolyhedron_Alloc(a
,A
);
346 ZDomainPrint(stdout
,P_VALUE_FMT
, ZA
);
351 printf("? unknown function\n");
354 /* Polyhedron_Free(A); */