polylib: ehrhart_lower_bound.c Source File

- Main Page
- Classes
- Files

- File List
- File Members

# ehrhart_lower_bound.c

Go to the documentation of this file.

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