Main Page | Class List | File List | Class Members | File Members

ehrhart_lower_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   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 upper bound for the EP's polyhedron.
00036   mpolyhedron_deflate(P1,nb_parms);
00037 
00038   // compute a polynomial approximation of the Ehrhart polynomial
00039   e = Ehrhart_Quick_Apx(P1, C1, &Validity_Lattice, 1024, param_name);
00040   
00041   Matrix_Free(C1);
00042   Matrix_Free(P1);
00043 
00044   printf("============ Ehrhart polynomial quick polynomial lower bound ============\n");
00045   show_matrix(Validity_Lattice);
00046   for( en=e ; en ; en=en->next ) {    
00047     Print_Domain(stdout,en->ValidityDomain, param_name);
00048     print_evalue(stdout,&en->EP, param_name);
00049     printf( "\n-----------------------------------\n" );
00050   }
00051  
00052 #ifdef EP_EVALUATION
00053   if( isatty(0) && nb_parms != 0)
00054   {  /* no tty input or no polyhedron -> no evaluation. */
00055     printf("Evaluation of the Ehrhart polynomial :\n");
00056     p = (Value *)malloc(sizeof(Value) * (nb_parms));
00057     for(i=0;i<nb_parms;i++) 
00058       value_init(p[i]);
00059     FOREVER {
00060       fflush(stdin);
00061       printf("Enter %d parameters : ",nb_parms);
00062       for(k=0;k<nb_parms;++k) {
00063         scanf("%s",str);
00064         value_read(p[k],str);
00065       }
00066       fprintf(stdout,"EP( ");
00067       value_print(stdout,VALUE_FMT,p[0]);
00068       for(k=1;k<nb_parms;++k) {
00069         fprintf(stdout,",");
00070         value_print(stdout,VALUE_FMT,p[k]);
00071       }
00072       fprintf(stdout," ) = ");
00073       value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
00074       free(tmp);
00075       fprintf(stdout,"\n");  
00076     }
00077   }
00078 #endif /* EP_EVALUATION */
00079   
00080   while( e )
00081     {
00082       free_evalue_refs( &(e->EP) );
00083       Polyhedron_Free( e->ValidityDomain );
00084       en = e ->next;
00085       free( e );
00086       e = en;
00087     }
00088   for( i=0 ; i<nb_parms ; i++ )
00089     free( param_name[i] );
00090   free(param_name);
00091   return 0;
00092 }

Generated on Mon Sep 12 15:15:10 2005 for polylib by doxygen 1.3.5