polylib 5.22.8
ehrhart_upper_bound.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4
5#include <polylib/polylib.h>
6
7
8int main( int argc, char **argv)
9{
10 int i;
11 const char **param_name;
12 Matrix *C1, *P1;
13 Polyhedron *P, *C;
14 Enumeration *e, *en;
15
16 Matrix * Validity_Lattice;
17 int nb_parms;
18
19#ifdef EP_EVALUATION
20 Value *p, *tmp;
21 int k;
22#endif
23
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);
30 }
31
32 /* Read the name of the parameters */
33 param_name = Read_ParamNames(stdin,nb_parms);
34
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);
38
39 /* compute a polynomial approximation of the Ehrhart polynomial */
40 e = Ehrhart_Quick_Apx(P1, C1, &Validity_Lattice, 1024);
41
42 Matrix_Free(C1);
43 Matrix_Free(P1);
44
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" );
51 }
52
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);
66 }
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]);
72 }
73 fprintf(stdout," ) = ");
74 value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
75 free(tmp);
76 fprintf(stdout,"\n");
77 }
78 }
79#endif /* EP_EVALUATION */
80
81 while( e )
82 {
83 free_evalue_refs( &(e->EP) );
85 en = e ->next;
86 free( e );
87 e = en;
88 }
89 Free_ParamNames(param_name, nb_parms);
90 return 0;
91}
#define value_read(val, str)
Definition: arithmetique.h:486
#define value_print(Dst, fmt, val)
Definition: arithmetique.h:487
#define value_init(val)
Definition: arithmetique.h:481
void free_evalue_refs(evalue *e)
releases all memory referenced by e.
Definition: ehrhart.c:115
void print_evalue(FILE *DST, evalue *e, const char **pname)
Definition: ehrhart.c:169
Enumeration * Ehrhart_Quick_Apx(Matrix *M, Matrix *C, Matrix **Validity_Lattice, unsigned maxRays)
Computes the approximation of the Ehrhart polynomial of a polyhedron (implicit form -> matrix),...
Definition: ehrhart.c:2627
int main(int argc, char **argv)
Value * compute_poly(Enumeration *en, Value *list_args)
Definition: eval_ehrhart.c:137
Matrix * Matrix_Read(void)
Definition: matrix.c:209
void Matrix_Free(Matrix *Mat)
Definition: matrix.c:71
void mpolyhedron_inflate(Matrix *polyh, unsigned int nb_parms)
inflates a polyhedron (represented as a matrix) P, so that the apx of its Ehrhart Polynomial is an up...
Definition: matrix_addon.c:164
#define show_matrix(M)
Polylib matrix addons Mainly, deals with polyhedra represented in implicit form (set of constraints).
Definition: matrix_addon.h:15
const char ** Read_ParamNames(FILE *in, int m)
Definition: param.c:14
void Free_ParamNames(const char **params, int m)
Definition: param.c:63
void Polyhedron_Free(Polyhedron *Pol)
Definition: polyhedron.c:1614
void Print_Domain(FILE *DST, Polyhedron *D, const char **pname)
Definition: polyparam.c:1680
Polyhedron * ValidityDomain
Definition: types.h:191
evalue EP
Definition: types.h:192
struct _enumeration * next
Definition: types.h:193
Definition: types.h:75
unsigned NbColumns
Definition: types.h:76
#define FOREVER
Definition: types.h:232