Main Page   Compound List   File List   Compound Members   File Members  

polytest.c

Go to the documentation of this file.
00001 /* polytest.c */
00002 #include <stdio.h>
00003 #include <polylib/polylib.h>
00004 
00005 
00006 char s[128];
00007 
00008 int main() { 
00009   
00010   Matrix *a=NULL, *b=NULL, *c, *d, *e, *f;
00011   Polyhedron *A, *B, *C, *D, *last, *tmp;
00012   int i, nbPol, nbMat, func;
00013   
00014   fgets(s, 128, stdin);
00015   nbPol = nbMat = 0;
00016   while ((*s=='#') ||
00017           ((sscanf(s, "D %d", &nbPol)<1) && (sscanf(s, "M %d", &nbMat)<1)) )
00018     fgets(s, 128, stdin);
00019 
00020   for (i=0, A=last=(Polyhedron *)0; i<nbPol; i++) {
00021     a = Matrix_Read();
00022     tmp = Constraints2Polyhedron(a,600);
00023     Matrix_Free(a);
00024     if (!last) A = last = tmp;
00025     else {
00026       last->next = tmp;
00027       last = tmp;
00028     }
00029     }
00030 
00031     if (nbMat)
00032     {  a = Matrix_Read(); }
00033 
00034     fgets(s,128,stdin);
00035     nbPol = nbMat = 0;
00036     while ( (*s=='#') ||
00037         ((sscanf(s, "D %d", &nbPol)<1) && (sscanf(s, "M %d", &nbMat)<1)) )
00038       fgets(s, 128, stdin);
00039 
00040     for (i=0, B=last=(Polyhedron *)0; i<nbPol; i++) {
00041       b = Matrix_Read();
00042       tmp = Constraints2Polyhedron(b,200);
00043       Matrix_Free(b);
00044       if (!last) B = last = tmp;
00045       else {
00046         last->next = tmp;
00047         last = tmp;
00048       }
00049     }
00050     
00051     if (nbMat)
00052       {  b = Matrix_Read(); }
00053     
00054     fgets(s, 128, stdin);
00055     while ((*s=='#') || (sscanf(s, "F %d", &func)<1))
00056       fgets(s, 128, stdin);
00057     
00058     switch (func) {
00059     case 1:
00060       C = DomainUnion(A, B, 200);
00061       D = DomainConvex(C, 200);
00062       d = Polyhedron2Constraints(D);
00063       Matrix_Print(stdout,P_VALUE_FMT,d);
00064       Matrix_Free(d);
00065       Domain_Free(C);
00066       Domain_Free(D);
00067       break;
00068     case 2:
00069       D = DomainSimplify(A, B, 200);
00070       d = Polyhedron2Constraints(D);
00071       Matrix_Print(stdout,P_VALUE_FMT,d);
00072       Matrix_Free(d);
00073       Domain_Free(D);
00074       break;
00075     case 3:
00076       a = Polyhedron2Constraints(A);
00077       Matrix_Print(stdout,P_VALUE_FMT,a);
00078       b = Polyhedron2Constraints(B);
00079       Matrix_Print(stdout,P_VALUE_FMT,b);
00080       break;
00081     case 4:
00082       a = Polyhedron2Rays(A);
00083       Matrix_Print(stdout,P_VALUE_FMT,a);
00084       break;
00085     case 5:
00086       
00087       /* a = ec , da = c , ed = 1 */
00088       right_hermite(a,&c,&d,&e);
00089       Matrix_Print(stdout,P_VALUE_FMT,c);
00090       Matrix_Print(stdout,P_VALUE_FMT,d);
00091       Matrix_Print(stdout,P_VALUE_FMT,e);
00092       f = Matrix_Alloc(e->NbRows,c->NbColumns);
00093       Matrix_Product(e,c,f);
00094       Matrix_Print(stdout,P_VALUE_FMT,f);
00095       Matrix_Free(f);
00096       f = Matrix_Alloc(d->NbRows,a->NbColumns);
00097       Matrix_Product(d,a,f);
00098       Matrix_Print(stdout,P_VALUE_FMT,f);
00099       Matrix_Free(f);
00100       f = Matrix_Alloc(e->NbRows, d->NbColumns);
00101       Matrix_Product(e,d,f);
00102       Matrix_Print(stdout,P_VALUE_FMT,f);
00103       break;
00104     case 6:
00105       
00106       /* a = ce , ad = c , de = 1 */
00107       left_hermite(a,&c,&d,&e);
00108       Matrix_Print(stdout,P_VALUE_FMT,c);
00109       Matrix_Print(stdout,P_VALUE_FMT,d);
00110       Matrix_Print(stdout,P_VALUE_FMT,e);
00111       f = Matrix_Alloc(c->NbRows, e->NbColumns);
00112       Matrix_Product(c,e,f);
00113       Matrix_Print(stdout,P_VALUE_FMT,f);
00114       Matrix_Free(f);
00115       f = Matrix_Alloc(a->NbRows, d->NbColumns);
00116       Matrix_Product(a,d,f);
00117       Matrix_Print(stdout,P_VALUE_FMT,f);
00118       Matrix_Free(f);
00119       f = Matrix_Alloc(d->NbRows, e->NbColumns);
00120       Matrix_Product(d,e,f);
00121       Matrix_Print(stdout,P_VALUE_FMT,f);
00122       break;
00123     case 7:               
00124      
00125       /* Polyhedron_Print(stdout,"%5d", A); */
00126       /* Matrix_Print(stdout,"%4d", b);     */
00127       
00128       C = Polyhedron_Image(A, b, 400);
00129       Polyhedron_Print(stdout,P_VALUE_FMT,C);
00130       break;
00131     case 8:
00132       
00133       printf("%s\n",
00134              Polyhedron_Not_Empty(A,B,600) ? "Not Empty" : "Empty");
00135       break;
00136     case 9:
00137       
00138       i = PolyhedronLTQ(A,B,1,0,600);
00139       printf("%s\n",
00140              i==-1 ? "A<B" : i==1 ? "A>B" : i==0 ? "A><B" : "error");
00141       i = PolyhedronLTQ(B,A,1,0,600);
00142       printf("%s\n",
00143              i==-1 ? "A<B" : i==1 ? "A>B" : i==0 ? "A><B" : "error");
00144       break;
00145     case 10:
00146       i = GaussSimplify(a,b);
00147       Matrix_Print(stdout,P_VALUE_FMT,b);
00148       break;
00149      
00150     default:
00151       printf("? unknown function\n");
00152     }
00153     
00154     Domain_Free(A);
00155     Domain_Free(B);
00156     
00157     return 0;
00158 }
00159 
00160 

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