Main Page | Class List | File List | Class Members | File Members

Zpolytest.c

Go to the documentation of this file.
00001 /* zpolytest.c
00002 This is a testbench for the Zpolylib (part of polylib manipulating 
00003 Z-polyhedra. */
00004 
00005 #include <stdio.h>
00006 #include <polylib/polylib.h>
00007 
00008 #define WS 0
00009 
00010 char s[128];
00011 
00012 int main() {
00013   
00014   Matrix *a=NULL, *b=NULL, *c=NULL, *d, *e, *g;
00015   LatticeUnion *l1,*l2,*l3,*l4,*temp;
00016   Polyhedron *A=NULL, *B=NULL, *C=NULL, *D;
00017   ZPolyhedron *ZA, *ZB, *ZC, *ZD, *Zlast;
00018   int  nbPol, nbMat, func, rank ;
00019   Vector *v=NULL;
00020     
00021   /* The structure of the input file to this program  is the following: 
00022        First a line containing        
00023            M nbMat
00024        Where nbMat is an integer indicating how many Matrices will 
00025        be described in the following. temporary debugging. Next 
00026        the matrice are described. For each matrix, the first row is two
00027        integers:
00028            nbRows nbColumns 
00029        Then the matrix is written row by row. a line starting with 
00030       a `#' is considered as a comment 
00031 
00032       Then a line containing 
00033            D nbDomain
00034       where nbDomain is an integer indicating how many domain will 
00035        be described in the following. Domains are describled as for 
00036        polylib,  the first row is two integers:
00037           nbConstraints dimension
00038       then the constraints are described in the Polylib format.
00039       The last line of the input file contains :
00040           F numTest
00041           which indicates which test will be performed on the data.
00042       Warning, currently no more than 3 matrice of Polyhedra can be read*/
00043   
00044   fgets(s, 128, stdin);
00045   nbPol = nbMat = 0;
00046   while ( (*s=='#') ||
00047           ((sscanf(s, "D %d", &nbPol)<1) && (sscanf(s, "M %d", &nbMat)<1)) )
00048     fgets(s, 128, stdin);
00049   
00050   
00051   /* debug */
00052   /*     fprintf(stdout,"nbMat=%d",nbMat);fflush(stdout); */
00053   
00054   switch (nbMat) {
00055     
00056   case 1: 
00057     a = Matrix_Read();
00058     break;
00059   
00060   case 2: 
00061     a = Matrix_Read();
00062     b = Matrix_Read();
00063     break;
00064   
00065   case 3: a = Matrix_Read();
00066     b = Matrix_Read();
00067     c = Matrix_Read();
00068     break;
00069   }
00070   
00071   fgets(s, 128, stdin);
00072   while ((*s=='#') ||
00073          ((sscanf(s, "D %d", &nbPol)<1) && (sscanf(s, "M %d", &nbMat)<1)) )
00074     fgets(s, 128, stdin);
00075   
00076   
00077   /* debug */
00078   /*  fprintf(stdout,"nbPol=%d",nbPol);fflush(stdout);  */
00079   
00080   switch (nbPol) { 
00081   
00082   case 1:  
00083     g = Matrix_Read();
00084     A = Constraints2Polyhedron(g,WS);
00085     Matrix_Free(g);
00086     break;
00087   
00088   case 2:         
00089     g = Matrix_Read();
00090     A = Constraints2Polyhedron(g,WS);
00091     Matrix_Free(g);
00092     g = Matrix_Read();
00093     B = Constraints2Polyhedron(g,WS);
00094     Matrix_Free(g);
00095     break;
00096   
00097   case 3:
00098     g = Matrix_Read();
00099     A = Constraints2Polyhedron(g,WS);
00100     Matrix_Free(g);
00101     g = Matrix_Read();
00102     B = Constraints2Polyhedron(g,WS);
00103     Matrix_Free(g);
00104     g = Matrix_Read();
00105     C = Constraints2Polyhedron(g,WS);
00106     Matrix_Free(g);
00107     break;
00108   }
00109   
00110   fgets(s, 128, stdin);
00111   while ((*s=='#') || (sscanf(s, "F %d", &func)<1) ) fgets(s, 128, stdin);
00112   
00113 
00114   switch (func) {
00115     
00116   case 1:
00117     
00118     /* just a  test of polylib functions */
00119     C = DomainUnion(A, B, 200);
00120     D = DomainConvex(C, 200);
00121     d = Polyhedron2Constraints(D);
00122     Matrix_Print(stdout,P_VALUE_FMT, d);
00123     Matrix_Free(d);
00124     Domain_Free(D);
00125     break;
00126     
00127   case 2: /* AffineHermite */
00128     
00129     AffineHermite(a,&b,&c);
00130     Matrix_Print(stdout,P_VALUE_FMT, b);
00131     Matrix_Print(stdout,P_VALUE_FMT, c);
00132     break;
00133     
00134   case 3: /* LatticeIntersection */
00135     
00136     c = LatticeIntersection(a,b);
00137     Matrix_Print(stdout,P_VALUE_FMT, c);
00138     break;
00139     
00140   case 4: /* LatticeDifference */
00141         
00142     fprintf(stdout," 2 in 1 : %d\n",LatticeIncludes(b,a));
00143     fprintf(stdout," 1 in 3 : %d\n",LatticeIncludes(c,a));
00144     fprintf(stdout," 1 in 2 : %d\n",LatticeIncludes(a,b));
00145     break;
00146   
00147   case 5: /* LatticeDifference */
00148     
00149     l1=LatticeDifference(a,b);
00150     l2=LatticeDifference(b,a);
00151     l3=LatticeDifference(c,a);
00152     l4=LatticeDifference(b,c);
00153     fprintf(stdout,"L1 - L2 :\n");
00154     temp=l1;
00155     while (temp!=NULL) {
00156       
00157       Matrix_Print(stdout,P_VALUE_FMT,temp->M);
00158       temp=temp->next; 
00159     };
00160     fprintf(stdout,"Diff2:\n");
00161     temp=l2;
00162     while (temp!=NULL) {
00163       Matrix_Print(stdout,P_VALUE_FMT, temp->M);
00164       temp=temp->next; 
00165     };
00166     fprintf(stdout,"Diff3:\n");
00167     temp=l3;
00168     while (temp!=NULL) {
00169       Matrix_Print(stdout,P_VALUE_FMT, temp->M);
00170       temp=temp->next; 
00171     };
00172     fprintf(stdout,"Diff4:\n");
00173     temp=l4;
00174     while (temp!=NULL) {
00175       Matrix_Print(stdout,P_VALUE_FMT, temp->M);
00176       temp=temp->next; 
00177     };
00178     break;
00179     
00180   case 6: /* isEmptyZPolyhedron */
00181     
00182     ZA=ZPolyhedron_Alloc(a,A);
00183     fprintf(stdout,"is Empty? :%d \n", isEmptyZPolyhedron(ZA));
00184     ZDomain_Free(ZA);
00185     break;
00186     
00187   case 7: /* ZDomainIntersection */
00188         
00189     ZA=ZPolyhedron_Alloc(a,A);
00190     ZB=ZPolyhedron_Alloc(b,B);
00191     ZC = ZDomainIntersection(ZA,ZB);
00192     ZDomainPrint(stdout,P_VALUE_FMT, ZC);
00193     ZDomain_Free(ZA);
00194     ZDomain_Free(ZB);
00195     ZDomain_Free(ZC);
00196     break;
00197     
00198   case 8: /* ZDomainUnion */
00199     
00200     ZA=ZPolyhedron_Alloc(a,A);
00201     ZB=ZPolyhedron_Alloc(b,B);
00202     ZC = ZDomainUnion(ZA,ZB);
00203     ZDomainPrint(stdout,P_VALUE_FMT, ZC);
00204     break;
00205     
00206   case 9: /* ZDomainDifference */
00207     
00208     ZA=ZPolyhedron_Alloc(a,A);
00209     ZB=ZPolyhedron_Alloc(b,B);
00210     ZC = ZDomainDifference(ZA,ZB);
00211     ZDomainPrint(stdout,P_VALUE_FMT, ZC);
00212     break;
00213     
00214   case 10: /* ZDomainImage */
00215     
00216     ZA=ZPolyhedron_Alloc(a,A);
00217     ZC = ZDomainImage(ZA,b); 
00218     ZDomainPrint(stdout,P_VALUE_FMT, ZC);
00219     break;
00220     
00221   case 11: /* ZDomainPreimage */
00222     
00223     ZA=ZPolyhedron_Alloc(a,A);
00224     ZC = ZDomainPreimage(ZA,b); 
00225     ZDomainPrint(stdout,P_VALUE_FMT, ZC);
00226     break;
00227     
00228   case 12: /* ZDomainDifference */
00229     ZA=ZPolyhedron_Alloc(a,A);
00230     ZC = ZDomainPreimage(ZA,b); 
00231     ZD = ZDomainImage(ZC,b); 
00232     Zlast=ZDomainDifference(ZD,ZC);
00233     fprintf(stdout,"the Two zpol are equal? :%d\n",
00234             isEmptyZPolyhedron(Zlast));
00235     break;
00236   
00237   case 13:  /* ZDomainSimplify */
00238     
00239     ZA=ZPolyhedron_Alloc(a,A);
00240     ZA->next = ZPolyhedron_Alloc(b,B);
00241     ZDomainPrint(stdout,P_VALUE_FMT, ZA);
00242     ZD = ZDomainSimplify(ZA);
00243     ZDomainPrint(stdout,P_VALUE_FMT, ZD);
00244     break;
00245     
00246   case 14:  /* EmptyZpolyhedron */
00247         
00248     ZA=EmptyZPolyhedron(3);
00249     fprintf(stdout,"is Empty? :%d \n", isEmptyZPolyhedron(ZA));
00250     ZDomain_Free(ZA);
00251     break;
00252     
00253   case 15:  /* ZDomainInclude */
00254   
00255     ZA=ZPolyhedron_Alloc(a,A);
00256     ZB=ZPolyhedron_Alloc(b,B);
00257     fprintf(stdout,"A in B  :%d \nB in A  :%d \n", 
00258             ZPolyhedronIncludes(ZA,ZB),
00259             ZPolyhedronIncludes(ZB,ZA));
00260     break;
00261   
00262   case 16: /* LatticePreimage */
00263         
00264     c = LatticePreimage(a,b);
00265     Matrix_Print(stdout,P_VALUE_FMT, c);
00266     AffineHermite(c,&d,&e);
00267     Matrix_Print(stdout,P_VALUE_FMT, d);
00268     break;
00269     
00270   case 17: /* LatticeImage */
00271     
00272     c = LatticeImage(a,b);
00273     Matrix_Print(stdout,P_VALUE_FMT, c);
00274     AffineHermite(c,&d,&e);
00275     Matrix_Print(stdout,P_VALUE_FMT, d);
00276     break;
00277       
00278   case 18:  /* EmptyLattice */
00279         
00280     fprintf(stdout,"is Empty? :%d \n", isEmptyLattice(a));
00281     fprintf(stdout,"is Empty? :%d \n", isEmptyLattice(EmptyLattice(3)));
00282     break;
00283   
00284   case 19:  /* CanonicalForm */
00285      
00286     ZA=ZPolyhedron_Alloc(a,A);
00287     ZB=ZPolyhedron_Alloc(a,B);
00288     CanonicalForm(ZA,&ZC,&c);
00289     CanonicalForm(ZB,&ZD,&d);
00290     ZDomainPrint(stdout,P_VALUE_FMT, ZC);
00291     ZDomainPrint(stdout,P_VALUE_FMT, ZD);
00292     break;
00293     
00294   case 20: /* LatticeSimplify */
00295     
00296     l1=LatticeUnion_Alloc();
00297     l2=LatticeUnion_Alloc();
00298     l1->M=Matrix_Copy(a);
00299     l1->next=l2;
00300     l2->M=Matrix_Copy(b);
00301     l1=LatticeSimplify(l1);
00302     PrintLatticeUnion(stdout,P_VALUE_FMT,l1); 
00303     LatticeUnion_Free(l1);
00304     break;
00305     
00306   case 21: /* AffineSmith */
00307   
00308     AffineSmith(a,&b,&c, &d);
00309     Matrix_Print(stdout,P_VALUE_FMT, b); 
00310     Matrix_Print(stdout,P_VALUE_FMT, c);
00311     Matrix_Print(stdout,P_VALUE_FMT, d);
00312     Matrix_Free(d);
00313     break;
00314   
00315   case 22: /* SolveDiophantine */
00316         
00317     rank=SolveDiophantine(a,&d,&v); 
00318     Matrix_Print(stdout,P_VALUE_FMT, a);
00319     fprintf(stdout," rank: %d \n ",rank);
00320     Matrix_Print(stdout,P_VALUE_FMT, d); 
00321     Vector_Print(stdout,P_VALUE_FMT, v);
00322     rank=SolveDiophantine(b,&d,&v); 
00323     Matrix_Print(stdout,P_VALUE_FMT, b);
00324     fprintf(stdout," rank: %d \n ",rank);
00325     Matrix_Print(stdout,P_VALUE_FMT, d); 
00326     Vector_Print(stdout,P_VALUE_FMT, v);
00327     rank=SolveDiophantine(c,&d,&v); 
00328     Matrix_Print(stdout,P_VALUE_FMT, c);
00329     fprintf(stdout," rank: %d \n ",rank);
00330     Matrix_Print(stdout,P_VALUE_FMT, d); 
00331     Vector_Print(stdout,P_VALUE_FMT, v);
00332     Vector_Free(v);
00333     break;
00334 
00335   case 23: /* SplitZPolyhedron */
00336         
00337     ZA=ZPolyhedron_Alloc(a,A);
00338     ZC = SplitZpolyhedron(ZA,b);
00339     ZDomainPrint(stdout,P_VALUE_FMT, ZC);
00340     break;
00341 
00342 
00343   case 100: /* debug */
00344     
00345     ZA=ZPolyhedron_Alloc(a,A);
00346     ZDomainPrint(stdout,P_VALUE_FMT, ZA);
00347     ZDomain_Free(ZA);
00348     break;
00349     
00350   default:
00351     printf("? unknown function\n");
00352   }
00353 
00354   /*    Polyhedron_Free(A); */
00355   if (a)
00356     Matrix_Free(a);
00357   if (b)
00358     Matrix_Free(b);
00359   if (c)
00360     Matrix_Free(c);
00361 
00362   if (A)
00363     Domain_Free(A);
00364   if (B)
00365     Domain_Free(B);
00366   if (C)
00367     Domain_Free(C);
00368   
00369   return 0;
00370 } /* main */

Generated on Mon Apr 23 19:23:53 2007 for polylib by doxygen 1.3.5