polylib: ehrhart_ranking.c Source File

- Main Page
- Classes
- Files

# ehrhart_ranking.c

Go to the documentation of this file.

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