thread safe polylib configuration
[polylib.git] / applications / ehrhart_upper_bound.c
blob29c24b287c129b69cb806d118109086e7ea7b3fb
1 /*
2 This file is part of PolyLib.
4 PolyLib is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 PolyLib is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with PolyLib. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdio.h>
19 #include <string.h>
20 #include <stdlib.h>
22 #include <polylib/polylib.h>
25 int main( int argc, char **argv)
27 int i;
28 const char **param_name;
29 Matrix *C1, *P1;
30 Polyhedron *P, *C;
31 Enumeration *e, *en;
33 Matrix * Validity_Lattice;
34 int nb_parms;
36 #ifdef EP_EVALUATION
37 Value *p, *tmp;
38 int k;
39 #endif
41 P1 = Matrix_Read();
42 C1 = Matrix_Read();
43 nb_parms = C1->NbColumns-2;
44 if(nb_parms < 0) {
45 fprintf( stderr, "Not enough parameters !\n" );
46 exit(0);
49 /* Read the name of the parameters */
50 param_name = Read_ParamNames(stdin,nb_parms);
52 /* inflate the polyhedron, so that the inflated EP approximation will be an
53 upper bound for the EP's polyhedron. */
54 mpolyhedron_inflate(P1,nb_parms);
56 /* compute a polynomial approximation of the Ehrhart polynomial */
57 e = Ehrhart_Quick_Apx(P1, C1, &Validity_Lattice, 1024);
59 Matrix_Free(C1);
60 Matrix_Free(P1);
62 printf("============ Ehrhart polynomial quick polynomial upper bound ============\n");
63 show_matrix(Validity_Lattice);
64 for( en=e ; en ; en=en->next ) {
65 Print_Domain(stdout,en->ValidityDomain, param_name);
66 print_evalue(stdout,&en->EP, param_name);
67 printf( "\n-----------------------------------\n" );
70 #ifdef EP_EVALUATION
71 if( isatty(0) && nb_parms != 0)
72 { /* no tty input or no polyhedron -> no evaluation. */
73 printf("Evaluation of the Ehrhart polynomial :\n");
74 p = (Value *)malloc(sizeof(Value) * (nb_parms));
75 for(i=0;i<nb_parms;i++)
76 value_init(p[i]);
77 FOREVER {
78 fflush(stdin);
79 printf("Enter %d parameters : ",nb_parms);
80 for(k=0;k<nb_parms;++k) {
81 scanf("%s",str);
82 value_read(p[k],str);
84 fprintf(stdout,"EP( ");
85 value_print(stdout,VALUE_FMT,p[0]);
86 for(k=1;k<nb_parms;++k) {
87 fprintf(stdout,",");
88 value_print(stdout,VALUE_FMT,p[k]);
90 fprintf(stdout," ) = ");
91 value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
92 free(tmp);
93 fprintf(stdout,"\n");
96 #endif /* EP_EVALUATION */
98 while( e )
100 free_evalue_refs( &(e->EP) );
101 Polyhedron_Free( e->ValidityDomain );
102 en = e ->next;
103 free( e );
104 e = en;
106 Free_ParamNames(param_name, nb_parms);
107 return 0;