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

Generated on Mon Mar 15 10:59:51 2004 for polylib by doxygen1.2.18