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, *c, *d, *e, *g;
00015   LatticeUnion *l1,*l2,*l3,*l4,*temp;
00016   Polyhedron *A=NULL, *B=NULL, *C, *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(C);
00125     Domain_Free(D);
00126     break;
00127     
00128   case 2: /* AffineHermite */
00129     
00130     AffineHermite(a,&b,&c);
00131     Matrix_Print(stdout,P_VALUE_FMT, b);
00132     Matrix_Print(stdout,P_VALUE_FMT, c);
00133     Matrix_Free(a);
00134     Matrix_Free(b);
00135     Matrix_Free(c);
00136     break;
00137     
00138   case 3: /* LatticeIntersection */
00139     
00140     c = LatticeIntersection(a,b);
00141     Matrix_Print(stdout,P_VALUE_FMT, c);
00142     Matrix_Free(a);
00143     Matrix_Free(b);
00144     Matrix_Free(c);
00145     break;
00146     
00147   case 4: /* LatticeDifference */
00148         
00149     fprintf(stdout," 2 in 1 : %d\n",LatticeIncludes(b,a));
00150     fprintf(stdout," 1 in 3 : %d\n",LatticeIncludes(c,a));
00151     fprintf(stdout," 1 in 2 : %d\n",LatticeIncludes(a,b));
00152     Matrix_Free(a);
00153     Matrix_Free(b);
00154     Matrix_Free(c);
00155     break;
00156   
00157   case 5: /* LatticeDifference */
00158     
00159     l1=LatticeDifference(a,b);
00160     l2=LatticeDifference(b,a);
00161     l3=LatticeDifference(c,a);
00162     l4=LatticeDifference(b,c);
00163     fprintf(stdout,"L1 - L2 :\n");
00164     temp=l1;
00165     while (temp!=NULL) {
00166       
00167       Matrix_Print(stdout,P_VALUE_FMT,temp->M);
00168       temp=temp->next; 
00169     };
00170     fprintf(stdout,"Diff2:\n");
00171     temp=l2;
00172     while (temp!=NULL) {
00173       Matrix_Print(stdout,P_VALUE_FMT, temp->M);
00174       temp=temp->next; 
00175     };
00176     fprintf(stdout,"Diff3:\n");
00177     temp=l3;
00178     while (temp!=NULL) {
00179       Matrix_Print(stdout,P_VALUE_FMT, temp->M);
00180       temp=temp->next; 
00181     };
00182     fprintf(stdout,"Diff4:\n");
00183     temp=l4;
00184     while (temp!=NULL) {
00185       Matrix_Print(stdout,P_VALUE_FMT, temp->M);
00186       temp=temp->next; 
00187     };
00188     Matrix_Free(a);
00189     Matrix_Free(b);
00190     Matrix_Free(c);
00191     break;
00192     
00193   case 6: /* isEmptyZPolyhedron */
00194     
00195     ZA=ZPolyhedron_Alloc(a,A);
00196     fprintf(stdout,"is Empty? :%d \n", isEmptyZPolyhedron(ZA));
00197     ZDomain_Free(ZA);
00198     break;
00199     
00200   case 7: /* ZDomainIntersection */
00201         
00202     ZA=ZPolyhedron_Alloc(a,A);
00203     ZB=ZPolyhedron_Alloc(b,B);
00204     ZC = ZDomainIntersection(ZA,ZB);
00205     ZDomainPrint(stdout,P_VALUE_FMT, ZC);
00206     break;
00207     
00208   case 8: /* ZDomainUnion */
00209     
00210     ZA=ZPolyhedron_Alloc(a,A);
00211     ZB=ZPolyhedron_Alloc(b,B);
00212     ZC = ZDomainUnion(ZA,ZB);
00213     ZDomainPrint(stdout,P_VALUE_FMT, ZC);
00214     break;
00215     
00216   case 9: /* ZDomainDifference */
00217     
00218     ZA=ZPolyhedron_Alloc(a,A);
00219     ZB=ZPolyhedron_Alloc(b,B);
00220     ZC = ZDomainDifference(ZA,ZB);
00221     ZDomainPrint(stdout,P_VALUE_FMT, ZC);
00222     break;
00223     
00224   case 10: /* ZDomainImage */
00225     
00226     ZA=ZPolyhedron_Alloc(a,A);
00227     ZC = ZDomainImage(ZA,b); 
00228     ZDomainPrint(stdout,P_VALUE_FMT, ZC);
00229     break;
00230     
00231   case 11: /* ZDomainPreimage */
00232     
00233     ZA=ZPolyhedron_Alloc(a,A);
00234     ZC = ZDomainPreimage(ZA,b); 
00235     ZDomainPrint(stdout,P_VALUE_FMT, ZC);
00236     break;
00237     
00238   case 12: /* ZDomainDifference */
00239     ZA=ZPolyhedron_Alloc(a,A);
00240     ZC = ZDomainPreimage(ZA,b); 
00241     ZD = ZDomainImage(ZC,b); 
00242     Zlast=ZDomainDifference(ZD,ZC);
00243     fprintf(stdout,"the Two zpol are equal? :%d\n",
00244             isEmptyZPolyhedron(Zlast));
00245     break;
00246   
00247   case 13:  /* ZDomainSimplify */
00248     
00249     ZA=ZPolyhedron_Alloc(a,A);
00250     ZA->next = ZPolyhedron_Alloc(b,B);
00251     ZDomainPrint(stdout,P_VALUE_FMT, ZA);
00252     ZD = ZDomainSimplify(ZA);
00253     ZDomainPrint(stdout,P_VALUE_FMT, ZD);
00254     break;
00255     
00256   case 14:  /* EmptyZpolyhedron */
00257         
00258     ZA=EmptyZPolyhedron(3);
00259     fprintf(stdout,"is Empty? :%d \n", isEmptyZPolyhedron(ZA));
00260     ZDomain_Free(ZA);
00261     break;
00262     
00263   case 15:  /* ZDomainInclude */
00264   
00265     ZA=ZPolyhedron_Alloc(a,A);
00266     ZB=ZPolyhedron_Alloc(b,B);
00267     fprintf(stdout,"A in B  :%d \nB in A  :%d \n", 
00268             ZPolyhedronIncludes(ZA,ZB),
00269             ZPolyhedronIncludes(ZB,ZA));
00270     break;
00271   
00272   case 16: /* LatticePreimage */
00273         
00274     c = LatticePreimage(a,b);
00275     Matrix_Print(stdout,P_VALUE_FMT, c);
00276     AffineHermite(c,&d,&e);
00277     Matrix_Print(stdout,P_VALUE_FMT, d);
00278     break;
00279     
00280   case 17: /* LatticeImage */
00281     
00282     c = LatticeImage(a,b);
00283     Matrix_Print(stdout,P_VALUE_FMT, c);
00284     AffineHermite(c,&d,&e);
00285     Matrix_Print(stdout,P_VALUE_FMT, d);
00286     break;
00287       
00288   case 18:  /* EmptyLattice */
00289         
00290     fprintf(stdout,"is Empty? :%d \n", isEmptyLattice(a));
00291     fprintf(stdout,"is Empty? :%d \n", isEmptyLattice(EmptyLattice(3)));
00292     break;
00293   
00294   case 19:  /* CanonicalForm */
00295      
00296     ZA=ZPolyhedron_Alloc(a,A);
00297     ZB=ZPolyhedron_Alloc(a,B);
00298     CanonicalForm(ZA,&ZC,&c);
00299     CanonicalForm(ZB,&ZD,&d);
00300     ZDomainPrint(stdout,P_VALUE_FMT, ZC);
00301     ZDomainPrint(stdout,P_VALUE_FMT, ZD);
00302     break;
00303     
00304   case 20: /* LatticeSimplify */
00305     
00306     l1=LatticeUnion_Alloc();
00307     l2=LatticeUnion_Alloc();
00308     l1->M=Matrix_Copy(a);
00309     l1->next=l2;
00310     l2->M=Matrix_Copy(b);
00311     l1=LatticeSimplify(l1);
00312     PrintLatticeUnion(stdout,P_VALUE_FMT,l1); 
00313     LatticeUnion_Free(l1);
00314     break;
00315     
00316   case 21: /* AffineSmith */
00317   
00318     AffineSmith(a,&b,&c, &d);
00319     Matrix_Print(stdout,P_VALUE_FMT, b); 
00320     Matrix_Print(stdout,P_VALUE_FMT, c);
00321     Matrix_Print(stdout,P_VALUE_FMT, d);
00322     Matrix_Free(a);
00323     Matrix_Free(b);
00324     Matrix_Free(c);
00325     Matrix_Free(d);
00326     break;
00327   
00328   case 22: /* SolveDiophantine */
00329         
00330     rank=SolveDiophantine(a,&d,&v); 
00331     Matrix_Print(stdout,P_VALUE_FMT, a);
00332     fprintf(stdout," rank: %d \n ",rank);
00333     Matrix_Print(stdout,P_VALUE_FMT, d); 
00334     Vector_Print(stdout,P_VALUE_FMT, v);
00335     rank=SolveDiophantine(b,&d,&v); 
00336     Matrix_Print(stdout,P_VALUE_FMT, b);
00337     fprintf(stdout," rank: %d \n ",rank);
00338     Matrix_Print(stdout,P_VALUE_FMT, d); 
00339     Vector_Print(stdout,P_VALUE_FMT, v);
00340     rank=SolveDiophantine(c,&d,&v); 
00341     Matrix_Print(stdout,P_VALUE_FMT, c);
00342     fprintf(stdout," rank: %d \n ",rank);
00343     Matrix_Print(stdout,P_VALUE_FMT, d); 
00344     Vector_Print(stdout,P_VALUE_FMT, v);
00345     Matrix_Free(a);
00346     Matrix_Free(b);
00347     Matrix_Free(c);
00348     Vector_Free(v);
00349     break;
00350 
00351   case 23: /* SplitZPolyhedron */
00352         
00353     ZA=ZPolyhedron_Alloc(a,A);
00354     ZC = SplitZpolyhedron(ZA,b);
00355     ZDomainPrint(stdout,P_VALUE_FMT, ZC);
00356     break;
00357 
00358 
00359   case 100: /* debug */
00360     
00361     ZA=ZPolyhedron_Alloc(a,A);
00362     ZDomainPrint(stdout,P_VALUE_FMT, ZA);
00363     ZDomain_Free(ZA);
00364     break;
00365     
00366   default:
00367     printf("? unknown function\n");
00368   }
00369 
00370   /*    Polyhedron_Free(A); */
00371   
00372   return 0;
00373 } /* main */

Generated on Mon Sep 12 14:48:30 2005 for polylib by doxygen 1.3.5