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

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

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