polylib: polytest.c Source File

- Main Page
- Classes
- Files

- File List
- File Members

# polytest.c

Go to the documentation of this file.

    00001 /* polytest.c */
    00002 /*
    00003     This file is part of PolyLib.
    00004
    00005     PolyLib is free software: you can redistribute it and/or modify
    00006     it under the terms of the GNU General Public License as published by
    00007     the Free Software Foundation, either version 3 of the License, or
    00008     (at your option) any later version.
    00009
    00010     PolyLib is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00013     GNU General Public License for more details.
    00014
    00015     You should have received a copy of the GNU General Public License
    00016     along with PolyLib.  If not, see <http://www.gnu.org/licenses/>.
    00017 */
    00018
    00019 #include <stdio.h>
    00020 #include <polylib/polylib.h>
    00021
    00022 #define WS 0
    00023
    00024 char s[128];
    00025
    00026 int main() {
    00027
    00028   Matrix *a=NULL, *b=NULL, *c, *d, *e, *f;
    00029   Polyhedron *A, *B, *C, *D, *last, *tmp;
    00030   int i, nbPol, nbMat, func;
    00031
    00032   fgets(s, 128, stdin);
    00033   nbPol = nbMat = 0;
    00034   while ((*s=='#') ||
    00035           ((sscanf(s, "D %d", &nbPol)<1) && (sscanf(s, "M %d", &nbMat)<1)) )
    00036     fgets(s, 128, stdin);
    00037
    00038   for (i=0, A=last=(Polyhedron *)0; i<nbPol; i++) {
    00039     a = Matrix_Read();
    00040     tmp = Constraints2Polyhedron(a,WS);
    00041     Matrix_Free(a);
    00042     if (!last) A = last = tmp;
    00043     else {
    00044       last->next = tmp;
    00045       last = tmp;
    00046     }
    00047     }
    00048
    00049     if (nbMat)
    00050     {  a = Matrix_Read(); }
    00051
    00052     fgets(s,128,stdin);
    00053     nbPol = nbMat = 0;
    00054     while ( (*s=='#') ||
    00055         ((sscanf(s, "D %d", &nbPol)<1) && (sscanf(s, "M %d", &nbMat)<1)) )
    00056       fgets(s, 128, stdin);
    00057
    00058     for (i=0, B=last=(Polyhedron *)0; i<nbPol; i++) {
    00059       b = Matrix_Read();
    00060       tmp = Constraints2Polyhedron(b,WS);
    00061       Matrix_Free(b);
    00062       if (!last) B = last = tmp;
    00063       else {
    00064         last->next = tmp;
    00065         last = tmp;
    00066       }
    00067     }
    00068
    00069     if (nbMat)
    00070       {  b = Matrix_Read(); }
    00071
    00072     fgets(s, 128, stdin);
    00073     while ((*s=='#') || (sscanf(s, "F %d", &func)<1))
    00074       fgets(s, 128, stdin);
    00075
    00076     switch (func) {
    00077     case 1:
    00078       C = DomainUnion(A, B, WS);
    00079       D = DomainConvex(C, WS);
    00080       d = Polyhedron2Constraints(D);
    00081       Matrix_Print(stdout,P_VALUE_FMT,d);
    00082       Matrix_Free(d);
    00083       Domain_Free(C);
    00084       Domain_Free(D);
    00085       break;
    00086     case 2:
    00087       D = DomainSimplify(A, B, WS);
    00088       d = Polyhedron2Constraints(D);
    00089       Matrix_Print(stdout,P_VALUE_FMT,d);
    00090       Matrix_Free(d);
    00091       Domain_Free(D);
    00092       break;
    00093     case 3:
    00094       a = Polyhedron2Constraints(A);
    00095       Matrix_Print(stdout,P_VALUE_FMT,a);
    00096       b = Polyhedron2Constraints(B);
    00097       Matrix_Print(stdout,P_VALUE_FMT,b);
    00098       break;
    00099     case 4:
    00100       a = Polyhedron2Rays(A);
    00101       Matrix_Print(stdout,P_VALUE_FMT,a);
    00102       break;
    00103     case 5:
    00104
    00105       /* a = ec , da = c , ed = 1 */
    00106       right_hermite(a,&c,&d,&e);
    00107       Matrix_Print(stdout,P_VALUE_FMT,c);
    00108       Matrix_Print(stdout,P_VALUE_FMT,d);
    00109       Matrix_Print(stdout,P_VALUE_FMT,e);
    00110       f = Matrix_Alloc(e->NbRows,c->NbColumns);
    00111       Matrix_Product(e,c,f);
    00112       Matrix_Print(stdout,P_VALUE_FMT,f);
    00113       Matrix_Free(f);
    00114       f = Matrix_Alloc(d->NbRows,a->NbColumns);
    00115       Matrix_Product(d,a,f);
    00116       Matrix_Print(stdout,P_VALUE_FMT,f);
    00117       Matrix_Free(f);
    00118       f = Matrix_Alloc(e->NbRows, d->NbColumns);
    00119       Matrix_Product(e,d,f);
    00120       Matrix_Print(stdout,P_VALUE_FMT,f);
    00121       break;
    00122     case 6:
    00123
    00124       /* a = ce , ad = c , de = 1 */
    00125       left_hermite(a,&c,&d,&e);
    00126       Matrix_Print(stdout,P_VALUE_FMT,c);
    00127       Matrix_Print(stdout,P_VALUE_FMT,d);
    00128       Matrix_Print(stdout,P_VALUE_FMT,e);
    00129       f = Matrix_Alloc(c->NbRows, e->NbColumns);
    00130       Matrix_Product(c,e,f);
    00131       Matrix_Print(stdout,P_VALUE_FMT,f);
    00132       Matrix_Free(f);
    00133       f = Matrix_Alloc(a->NbRows, d->NbColumns);
    00134       Matrix_Product(a,d,f);
    00135       Matrix_Print(stdout,P_VALUE_FMT,f);
    00136       Matrix_Free(f);
    00137       f = Matrix_Alloc(d->NbRows, e->NbColumns);
    00138       Matrix_Product(d,e,f);
    00139       Matrix_Print(stdout,P_VALUE_FMT,f);
    00140       break;
    00141     case 7:
    00142
    00143       /* Polyhedron_Print(stdout,"%5d", A); */
    00144       /* Matrix_Print(stdout,"%4d", b);     */
    00145
    00146       C = Polyhedron_Image(A, b, WS);
    00147       Polyhedron_Print(stdout,P_VALUE_FMT,C);
    00148       break;
    00149     case 8:
    00150
    00151       printf("%s\n",
    00152              Polyhedron_Not_Empty(A,B,WS) ? "Not Empty" : "Empty");
    00153       break;
    00154     case 9:
    00155
    00156       i = PolyhedronLTQ(A,B,1,0,WS);
    00157       printf("%s\n",
    00158              i==-1 ? "A<B" : i==1 ? "A>B" : i==0 ? "A><B" : "error");
    00159       i = PolyhedronLTQ(B,A,1,0,WS);
    00160       printf("%s\n",
    00161              i==-1 ? "A<B" : i==1 ? "A>B" : i==0 ? "A><B" : "error");
    00162       break;
    00163     case 10:
    00164       i = GaussSimplify(a,b);
    00165       Matrix_Print(stdout,P_VALUE_FMT,b);
    00166       break;
    00167
    00168     default:
    00169       printf("? unknown function\n");
    00170     }
    00171
    00172     Domain_Free(A);
    00173     Domain_Free(B);
    00174
    00175     return 0;
    00176 }
    00177
    00178