2 This is a testbench for the Zpolylib (part of polylib manipulating
5 This file is part of PolyLib.
7 PolyLib is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 PolyLib is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with PolyLib. If not, see <http://www.gnu.org/licenses/>.
23 #include <polylib/polylib.h>
31 Matrix
*a
=NULL
, *b
=NULL
, *c
=NULL
, *d
, *e
, *g
;
32 LatticeUnion
*l1
,*l2
,*l3
,*l4
,*temp
;
33 Polyhedron
*A
=NULL
, *B
=NULL
, *C
=NULL
, *D
;
34 ZPolyhedron
*ZA
, *ZB
, *ZC
, *ZD
, *Zlast
;
35 int nbPol
, nbMat
, func
, rank
;
38 /* The structure of the input file to this program is the following:
39 First a line containing
41 Where nbMat is an integer indicating how many Matrices will
42 be described in the following. temporary debugging. Next
43 the matrice are described. For each matrix, the first row is two
46 Then the matrix is written row by row. a line starting with
47 a `#' is considered as a comment
49 Then a line containing
51 where nbDomain is an integer indicating how many domain will
52 be described in the following. Domains are describled as for
53 polylib, the first row is two integers:
54 nbConstraints dimension
55 then the constraints are described in the Polylib format.
56 The last line of the input file contains :
58 which indicates which test will be performed on the data.
59 Warning, currently no more than 3 matrice of Polyhedra can be read*/
64 ((sscanf(s
, "D %d", &nbPol
)<1) && (sscanf(s
, "M %d", &nbMat
)<1)) )
69 /* fprintf(stdout,"nbMat=%d",nbMat);fflush(stdout); */
82 case 3: a
= Matrix_Read();
90 ((sscanf(s
, "D %d", &nbPol
)<1) && (sscanf(s
, "M %d", &nbMat
)<1)) )
95 /* fprintf(stdout,"nbPol=%d",nbPol);fflush(stdout); */
101 A
= Constraints2Polyhedron(g
,WS
);
107 A
= Constraints2Polyhedron(g
,WS
);
110 B
= Constraints2Polyhedron(g
,WS
);
116 A
= Constraints2Polyhedron(g
,WS
);
119 B
= Constraints2Polyhedron(g
,WS
);
122 C
= Constraints2Polyhedron(g
,WS
);
127 fgets(s
, 128, stdin
);
128 while ((*s
=='#') || (sscanf(s
, "F %d", &func
)<1) ) fgets(s
, 128, stdin
);
135 /* just a test of polylib functions */
136 C
= DomainUnion(A
, B
, 200);
137 D
= DomainConvex(C
, 200);
138 d
= Polyhedron2Constraints(D
);
139 Matrix_Print(stdout
,P_VALUE_FMT
, d
);
144 case 2: /* AffineHermite */
146 AffineHermite(a
,&b
,&c
);
147 Matrix_Print(stdout
,P_VALUE_FMT
, b
);
148 Matrix_Print(stdout
,P_VALUE_FMT
, c
);
151 case 3: /* LatticeIntersection */
153 c
= LatticeIntersection(a
,b
);
154 Matrix_Print(stdout
,P_VALUE_FMT
, c
);
157 case 4: /* LatticeDifference */
159 fprintf(stdout
," 2 in 1 : %d\n",LatticeIncludes(b
,a
));
160 fprintf(stdout
," 1 in 3 : %d\n",LatticeIncludes(c
,a
));
161 fprintf(stdout
," 1 in 2 : %d\n",LatticeIncludes(a
,b
));
164 case 5: /* LatticeDifference */
166 l1
=LatticeDifference(a
,b
);
167 l2
=LatticeDifference(b
,a
);
168 l3
=LatticeDifference(c
,a
);
169 l4
=LatticeDifference(b
,c
);
170 fprintf(stdout
,"L1 - L2 :\n");
174 Matrix_Print(stdout
,P_VALUE_FMT
,temp
->M
);
177 fprintf(stdout
,"Diff2:\n");
180 Matrix_Print(stdout
,P_VALUE_FMT
, temp
->M
);
183 fprintf(stdout
,"Diff3:\n");
186 Matrix_Print(stdout
,P_VALUE_FMT
, temp
->M
);
189 fprintf(stdout
,"Diff4:\n");
192 Matrix_Print(stdout
,P_VALUE_FMT
, temp
->M
);
197 case 6: /* isEmptyZPolyhedron */
199 ZA
=ZPolyhedron_Alloc(a
,A
);
200 fprintf(stdout
,"is Empty? :%d \n", isEmptyZPolyhedron(ZA
));
204 case 7: /* ZDomainIntersection */
206 ZA
=ZPolyhedron_Alloc(a
,A
);
207 ZB
=ZPolyhedron_Alloc(b
,B
);
208 ZC
= ZDomainIntersection(ZA
,ZB
);
209 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
215 case 8: /* ZDomainUnion */
217 ZA
=ZPolyhedron_Alloc(a
,A
);
218 ZB
=ZPolyhedron_Alloc(b
,B
);
219 ZC
= ZDomainUnion(ZA
,ZB
);
220 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
223 case 9: /* ZDomainDifference */
225 ZA
=ZPolyhedron_Alloc(a
,A
);
226 ZB
=ZPolyhedron_Alloc(b
,B
);
227 ZC
= ZDomainDifference(ZA
,ZB
);
228 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
231 case 10: /* ZDomainImage */
233 ZA
=ZPolyhedron_Alloc(a
,A
);
234 ZC
= ZDomainImage(ZA
,b
);
235 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
238 case 11: /* ZDomainPreimage */
240 ZA
=ZPolyhedron_Alloc(a
,A
);
241 ZC
= ZDomainPreimage(ZA
,b
);
242 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
245 case 12: /* ZDomainDifference */
246 ZA
=ZPolyhedron_Alloc(a
,A
);
247 ZC
= ZDomainPreimage(ZA
,b
);
248 ZD
= ZDomainImage(ZC
,b
);
249 Zlast
=ZDomainDifference(ZD
,ZC
);
250 fprintf(stdout
,"the Two zpol are equal? :%d\n",
251 isEmptyZPolyhedron(Zlast
));
254 case 13: /* ZDomainSimplify */
256 ZA
=ZPolyhedron_Alloc(a
,A
);
257 ZA
->next
= ZPolyhedron_Alloc(b
,B
);
258 ZDomainPrint(stdout
,P_VALUE_FMT
, ZA
);
259 ZD
= ZDomainSimplify(ZA
);
260 ZDomainPrint(stdout
,P_VALUE_FMT
, ZD
);
263 case 14: /* EmptyZpolyhedron */
265 ZA
=EmptyZPolyhedron(3);
266 fprintf(stdout
,"is Empty? :%d \n", isEmptyZPolyhedron(ZA
));
270 case 15: /* ZDomainInclude */
272 ZA
=ZPolyhedron_Alloc(a
,A
);
273 ZB
=ZPolyhedron_Alloc(b
,B
);
274 fprintf(stdout
,"A in B :%d \nB in A :%d \n",
275 ZPolyhedronIncludes(ZA
,ZB
),
276 ZPolyhedronIncludes(ZB
,ZA
));
279 case 16: /* LatticePreimage */
281 c
= LatticePreimage(a
,b
);
282 Matrix_Print(stdout
,P_VALUE_FMT
, c
);
283 AffineHermite(c
,&d
,&e
);
284 Matrix_Print(stdout
,P_VALUE_FMT
, d
);
287 case 17: /* LatticeImage */
289 c
= LatticeImage(a
,b
);
290 Matrix_Print(stdout
,P_VALUE_FMT
, c
);
291 AffineHermite(c
,&d
,&e
);
292 Matrix_Print(stdout
,P_VALUE_FMT
, d
);
295 case 18: /* EmptyLattice */
297 fprintf(stdout
,"is Empty? :%d \n", isEmptyLattice(a
));
298 fprintf(stdout
,"is Empty? :%d \n", isEmptyLattice(EmptyLattice(3)));
301 case 19: /* CanonicalForm */
303 ZA
=ZPolyhedron_Alloc(a
,A
);
304 ZB
=ZPolyhedron_Alloc(a
,B
);
305 CanonicalForm(ZA
,&ZC
,&c
);
306 CanonicalForm(ZB
,&ZD
,&d
);
307 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
308 ZDomainPrint(stdout
,P_VALUE_FMT
, ZD
);
311 case 20: /* LatticeSimplify */
313 l1
=LatticeUnion_Alloc();
314 l2
=LatticeUnion_Alloc();
315 l1
->M
=Matrix_Copy(a
);
317 l2
->M
=Matrix_Copy(b
);
318 l1
=LatticeSimplify(l1
);
319 PrintLatticeUnion(stdout
,P_VALUE_FMT
,l1
);
320 LatticeUnion_Free(l1
);
323 case 21: /* AffineSmith */
325 AffineSmith(a
,&b
,&c
, &d
);
326 Matrix_Print(stdout
,P_VALUE_FMT
, b
);
327 Matrix_Print(stdout
,P_VALUE_FMT
, c
);
328 Matrix_Print(stdout
,P_VALUE_FMT
, d
);
332 case 22: /* SolveDiophantine */
334 rank
=SolveDiophantine(a
,&d
,&v
);
335 Matrix_Print(stdout
,P_VALUE_FMT
, a
);
336 fprintf(stdout
," rank: %d \n ",rank
);
337 Matrix_Print(stdout
,P_VALUE_FMT
, d
);
338 Vector_Print(stdout
,P_VALUE_FMT
, v
);
339 rank
=SolveDiophantine(b
,&d
,&v
);
340 Matrix_Print(stdout
,P_VALUE_FMT
, b
);
341 fprintf(stdout
," rank: %d \n ",rank
);
342 Matrix_Print(stdout
,P_VALUE_FMT
, d
);
343 Vector_Print(stdout
,P_VALUE_FMT
, v
);
344 rank
=SolveDiophantine(c
,&d
,&v
);
345 Matrix_Print(stdout
,P_VALUE_FMT
, c
);
346 fprintf(stdout
," rank: %d \n ",rank
);
347 Matrix_Print(stdout
,P_VALUE_FMT
, d
);
348 Vector_Print(stdout
,P_VALUE_FMT
, v
);
352 case 23: /* SplitZPolyhedron */
354 ZA
=ZPolyhedron_Alloc(a
,A
);
355 ZC
= SplitZpolyhedron(ZA
,b
);
356 ZDomainPrint(stdout
,P_VALUE_FMT
, ZC
);
360 case 100: /* debug */
362 ZA
=ZPolyhedron_Alloc(a
,A
);
363 ZDomainPrint(stdout
,P_VALUE_FMT
, ZA
);
368 printf("? unknown function\n");
371 /* Polyhedron_Free(A); */