polylib: ehrhart_quick_apx.c Source File

- Main Page
- Classes
- Files

- File List
- File Members

# ehrhart_quick_apx.c

Go to the documentation of this file.

    00001 /*
    00002     This file is part of PolyLib.
    00003
    00004     PolyLib is free software: you can redistribute it and/or modify
    00005     it under the terms of the GNU General Public License as published by
    00006     the Free Software Foundation, either version 3 of the License, or
    00007     (at your option) any later version.
    00008
    00009     PolyLib is distributed in the hope that it will be useful,
    00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012     GNU General Public License for more details.
    00013
    00014     You should have received a copy of the GNU General Public License
    00015     along with PolyLib.  If not, see <http://www.gnu.org/licenses/>.
    00016 */
    00017
    00018 #include <stdio.h>
    00019 #include <string.h>
    00020 #include <stdlib.h>
    00021
    00022 #include <polylib/polylib.h>
    00023
    00024 int main( int argc, char **argv)
    00025 {
    00026   int i;
    00027   const char **param_name = NULL;
    00028   Matrix *C1, *P1;
    00029   Polyhedron *P, *C;
    00030   Enumeration *e, *en;
    00031
    00032   Matrix * Validity_Lattice;
    00033   int nb_parms;
    00034
    00035 #ifdef EP_EVALUATION
    00036   Value *p, *tmp;
    00037   int k;
    00038 #endif
    00039
    00040   P1 = Matrix_Read();
    00041   C1 = Matrix_Read();
    00042   nb_parms = C1->NbColumns-2;
    00043   if(nb_parms < 0) {
    00044     fprintf( stderr, "Not enough parameters !\n" );
    00045     exit(0);
    00046   }
    00047
    00048    /* Read the name of the parameters */
    00049   param_name = Read_ParamNames(stdin,nb_parms);
    00050
    00051   /* compute a polynomial approximation of the Ehrhart polynomial */
    00052   printf("============ Ehrhart polynomial quick approximation ============\n");
    00053   e = Ehrhart_Quick_Apx(P1, C1, &Validity_Lattice, 1024);
    00054
    00055   Matrix_Free(C1);
    00056   Matrix_Free(P1);
    00057
    00058   show_matrix(Validity_Lattice);
    00059   for( en=e ; en ; en=en->next ) {
    00060     Print_Domain(stdout,en->ValidityDomain, param_name);
    00061     print_evalue(stdout,&en->EP, param_name);
    00062     printf( "\n-----------------------------------\n" );
    00063   }
    00064
    00065 #ifdef EP_EVALUATION
    00066   if( isatty(0) && nb_parms != 0)
    00067   {  /* no tty input or no polyhedron -> no evaluation. */
    00068     printf("Evaluation of the Ehrhart polynomial :\n");
    00069     p = (Value *)malloc(sizeof(Value) * (nb_parms));
    00070     for(i=0;i<nb_parms;i++)
    00071       value_init(p[i]);
    00072     FOREVER {
    00073       fflush(stdin);
    00074       printf("Enter %d parameters : ",nb_parms);
    00075       for(k=0;k<nb_parms;++k) {
    00076         scanf("%s",str);
    00077         value_read(p[k],str);
    00078       }
    00079       fprintf(stdout,"EP( ");
    00080       value_print(stdout,VALUE_FMT,p[0]);
    00081       for(k=1;k<nb_parms;++k) {
    00082         fprintf(stdout,",");
    00083         value_print(stdout,VALUE_FMT,p[k]);
    00084       }
    00085       fprintf(stdout," ) = ");
    00086       value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
    00087       free(tmp);
    00088       fprintf(stdout,"\n");
    00089     }
    00090   }
    00091 #endif /* EP_EVALUATION */
    00092
    00093   while( e )
    00094     {
    00095       free_evalue_refs( &(e->EP) );
    00096       Polyhedron_Free( e->ValidityDomain );
    00097       en = e ->next;
    00098       free( e );
    00099       e = en;
    00100     }
    00101   Free_ParamNames(param_name, nb_parms);
    00102   return 0;
    00103 }