new version 5.22.4
[polylib.git] / applications / ehrhart_upper_bound.c
blob5a0208728230a4a8f425691cd7fd1609808f600d
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
5 #include <polylib/polylib.h>
8 int main( int argc, char **argv)
10 int i;
11 const char **param_name;
12 Matrix *C1, *P1;
13 Polyhedron *P, *C;
14 Enumeration *e, *en;
16 Matrix * Validity_Lattice;
17 int nb_parms;
19 #ifdef EP_EVALUATION
20 Value *p, *tmp;
21 int k;
22 #endif
24 P1 = Matrix_Read();
25 C1 = Matrix_Read();
26 nb_parms = C1->NbColumns-2;
27 if(nb_parms < 0) {
28 fprintf( stderr, "Not enough parameters !\n" );
29 exit(0);
32 /* Read the name of the parameters */
33 param_name = Read_ParamNames(stdin,nb_parms);
35 /* inflate the polyhedron, so that the inflated EP approximation will be an
36 upper bound for the EP's polyhedron. */
37 mpolyhedron_inflate(P1,nb_parms);
39 /* compute a polynomial approximation of the Ehrhart polynomial */
40 e = Ehrhart_Quick_Apx(P1, C1, &Validity_Lattice, 1024);
42 Matrix_Free(C1);
43 Matrix_Free(P1);
45 printf("============ Ehrhart polynomial quick polynomial upper bound ============\n");
46 show_matrix(Validity_Lattice);
47 for( en=e ; en ; en=en->next ) {
48 Print_Domain(stdout,en->ValidityDomain, param_name);
49 print_evalue(stdout,&en->EP, param_name);
50 printf( "\n-----------------------------------\n" );
53 #ifdef EP_EVALUATION
54 if( isatty(0) && nb_parms != 0)
55 { /* no tty input or no polyhedron -> no evaluation. */
56 printf("Evaluation of the Ehrhart polynomial :\n");
57 p = (Value *)malloc(sizeof(Value) * (nb_parms));
58 for(i=0;i<nb_parms;i++)
59 value_init(p[i]);
60 FOREVER {
61 fflush(stdin);
62 printf("Enter %d parameters : ",nb_parms);
63 for(k=0;k<nb_parms;++k) {
64 scanf("%s",str);
65 value_read(p[k],str);
67 fprintf(stdout,"EP( ");
68 value_print(stdout,VALUE_FMT,p[0]);
69 for(k=1;k<nb_parms;++k) {
70 fprintf(stdout,",");
71 value_print(stdout,VALUE_FMT,p[k]);
73 fprintf(stdout," ) = ");
74 value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
75 free(tmp);
76 fprintf(stdout,"\n");
79 #endif /* EP_EVALUATION */
81 while( e )
83 free_evalue_refs( &(e->EP) );
84 Polyhedron_Free( e->ValidityDomain );
85 en = e ->next;
86 free( e );
87 e = en;
89 Free_ParamNames(param_name, nb_parms);
90 return 0;