polylib: ehrhart_ranking.c Source File

- Main Page
- Classes
- Files

- File List
- File Members

# ehrhart_ranking.c

Go to the documentation of this file.

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