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

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