polylib: ehrhart_upper_bound.c Source File

- Main Page
- Classes
- Files

# ehrhart_upper_bound.c

Go to the documentation of this file.

    00001 #include <stdio.h>
    00002 #include <string.h>
    00003 #include <stdlib.h>
    00004
    00005 #include <polylib/polylib.h>
    00006
    00007
    00008 int main( int argc, char **argv)
    00009 {
    00010   int i;
    00011   const char **param_name;
    00012   Matrix *C1, *P1;
    00013   Polyhedron *P, *C;
    00014   Enumeration *e, *en;
    00015
    00016   Matrix * Validity_Lattice;
    00017   int nb_parms;
    00018
    00019 #ifdef EP_EVALUATION
    00020   Value *p, *tmp;
    00021   int k;
    00022 #endif
    00023
    00024   P1 = Matrix_Read();
    00025   C1 = Matrix_Read();
    00026   nb_parms = C1->NbColumns-2;
    00027   if(nb_parms < 0) {
    00028     fprintf( stderr, "Not enough parameters !\n" );
    00029     exit(0);
    00030   }
    00031
    00032    /* Read the name of the parameters */
    00033   param_name = Read_ParamNames(stdin,nb_parms);
    00034
    00035   /* inflate the polyhedron, so that the inflated EP approximation will be an
    00036      upper bound for the EP's polyhedron. */
    00037   mpolyhedron_inflate(P1,nb_parms);
    00038
    00039   /* compute a polynomial approximation of the Ehrhart polynomial */
    00040   e = Ehrhart_Quick_Apx(P1, C1, &Validity_Lattice, 1024);
    00041
    00042   Matrix_Free(C1);
    00043   Matrix_Free(P1);
    00044
    00045   printf("============ Ehrhart polynomial quick polynomial upper bound ============\n");
    00046   show_matrix(Validity_Lattice);
    00047   for( en=e ; en ; en=en->next ) {
    00048     Print_Domain(stdout,en->ValidityDomain, param_name);
    00049     print_evalue(stdout,&en->EP, param_name);
    00050     printf( "\n-----------------------------------\n" );
    00051   }
    00052
    00053 #ifdef EP_EVALUATION
    00054   if( isatty(0) && nb_parms != 0)
    00055   {  /* no tty input or no polyhedron -> no evaluation. */
    00056     printf("Evaluation of the Ehrhart polynomial :\n");
    00057     p = (Value *)malloc(sizeof(Value) * (nb_parms));
    00058     for(i=0;i<nb_parms;i++)
    00059       value_init(p[i]);
    00060     FOREVER {
    00061       fflush(stdin);
    00062       printf("Enter %d parameters : ",nb_parms);
    00063       for(k=0;k<nb_parms;++k) {
    00064         scanf("%s",str);
    00065         value_read(p[k],str);
    00066       }
    00067       fprintf(stdout,"EP( ");
    00068       value_print(stdout,VALUE_FMT,p[0]);
    00069       for(k=1;k<nb_parms;++k) {
    00070         fprintf(stdout,",");
    00071         value_print(stdout,VALUE_FMT,p[k]);
    00072       }
    00073       fprintf(stdout," ) = ");
    00074       value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
    00075       free(tmp);
    00076       fprintf(stdout,"\n");
    00077     }
    00078   }
    00079 #endif /* EP_EVALUATION */
    00080
    00081   while( e )
    00082     {
    00083       free_evalue_refs( &(e->EP) );
    00084       Polyhedron_Free( e->ValidityDomain );
    00085       en = e ->next;
    00086       free( e );
    00087       e = en;
    00088     }
    00089   Free_ParamNames(param_name, nb_parms);
    00090   return 0;
    00091 }