build all (32 64 GMP) lib versions by default if none specified
[polylib.git] / applications / ehrhart_quick_apx.c
blob068ae1112b0c8f9dd7a1edaae8279fb5a4b439d4
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>
24 int main( int argc, char **argv)
26 int i;
27 const char **param_name = NULL;
28 Matrix *C1, *P1;
29 Polyhedron *P, *C;
30 Enumeration *e, *en;
32 Matrix * Validity_Lattice;
33 int nb_parms;
35 #ifdef EP_EVALUATION
36 Value *p, *tmp;
37 int k;
38 #endif
40 P1 = Matrix_Read();
41 C1 = Matrix_Read();
42 nb_parms = C1->NbColumns-2;
43 if(nb_parms < 0) {
44 fprintf( stderr, "Not enough parameters !\n" );
45 exit(0);
48 /* Read the name of the parameters */
49 param_name = Read_ParamNames(stdin,nb_parms);
51 /* compute a polynomial approximation of the Ehrhart polynomial */
52 printf("============ Ehrhart polynomial quick approximation ============\n");
53 e = Ehrhart_Quick_Apx(P1, C1, &Validity_Lattice, 1024);
55 Matrix_Free(C1);
56 Matrix_Free(P1);
58 show_matrix(Validity_Lattice);
59 for( en=e ; en ; en=en->next ) {
60 Print_Domain(stdout,en->ValidityDomain, param_name);
61 print_evalue(stdout,&en->EP, param_name);
62 printf( "\n-----------------------------------\n" );
65 #ifdef EP_EVALUATION
66 if( isatty(0) && nb_parms != 0)
67 { /* no tty input or no polyhedron -> no evaluation. */
68 printf("Evaluation of the Ehrhart polynomial :\n");
69 p = (Value *)malloc(sizeof(Value) * (nb_parms));
70 for(i=0;i<nb_parms;i++)
71 value_init(p[i]);
72 FOREVER {
73 fflush(stdin);
74 printf("Enter %d parameters : ",nb_parms);
75 for(k=0;k<nb_parms;++k) {
76 scanf("%s",str);
77 value_read(p[k],str);
79 fprintf(stdout,"EP( ");
80 value_print(stdout,VALUE_FMT,p[0]);
81 for(k=1;k<nb_parms;++k) {
82 fprintf(stdout,",");
83 value_print(stdout,VALUE_FMT,p[k]);
85 fprintf(stdout," ) = ");
86 value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
87 free(tmp);
88 fprintf(stdout,"\n");
91 #endif /* EP_EVALUATION */
93 while( e )
95 free_evalue_refs( &(e->EP) );
96 Polyhedron_Free( e->ValidityDomain );
97 en = e ->next;
98 free( e );
99 e = en;
101 Free_ParamNames(param_name, nb_parms);
102 return 0;