polylib 7.01
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 char **param_name;
11 Matrix *C1, *P1;
12 Enumeration *e, *en;
13
14 Matrix * Validity_Lattice;
15 int nb_parms;
16
17#ifdef EP_EVALUATION
18 Value *p, *tmp;
19 int k;
20#endif
21
22 P1 = Matrix_Read();
23 C1 = Matrix_Read();
24 nb_parms = C1->NbColumns-2;
25 if(nb_parms < 0) {
26 fprintf( stderr, "Not enough parameters !\n" );
27 exit(0);
28 }
29
30 /* Read the name of the parameters */
31 param_name = Read_ParamNames(stdin,nb_parms);
32
33 /* inflate the polyhedron, so that the inflated EP approximation will be an
34 upper bound for the EP's polyhedron. */
35 mpolyhedron_inflate(P1,nb_parms);
36
37 /* compute a polynomial approximation of the Ehrhart polynomial */
38 e = Ehrhart_Quick_Apx(P1, C1, &Validity_Lattice, 1024);
39
40 Matrix_Free(C1);
41 Matrix_Free(P1);
42
43 printf("============ Ehrhart polynomial quick polynomial upper bound ============\n");
44 show_matrix(Validity_Lattice);
45 for( en=e ; en ; en=en->next ) {
46 Print_Domain(stdout,en->ValidityDomain, param_name);
47 print_evalue(stdout,&en->EP, param_name);
48 printf( "\n-----------------------------------\n" );
49 }
50
51#ifdef EP_EVALUATION
52 if( isatty(0) && nb_parms != 0)
53 { /* no tty input or no polyhedron -> no evaluation. */
54 printf("Evaluation of the Ehrhart polynomial :\n");
55 p = (Value *)malloc(sizeof(Value) * (nb_parms));
56 for(i=0;i<nb_parms;i++)
57 value_init(p[i]);
58 FOREVER {
59 fflush(stdin);
60 printf("Enter %d parameters : ",nb_parms);
61 for(k=0;k<nb_parms;++k) {
62 scanf("%s",str);
63 value_read(p[k],str);
64 }
65 fprintf(stdout,"EP( ");
66 value_print(stdout,VALUE_FMT,p[0]);
67 for(k=1;k<nb_parms;++k) {
68 fprintf(stdout,",");
69 value_print(stdout,VALUE_FMT,p[k]);
70 }
71 fprintf(stdout," ) = ");
72 value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
73 free(tmp);
74 fprintf(stdout,"\n");
75 }
76 }
77#endif /* EP_EVALUATION */
78
79 while( e )
80 {
81 free_evalue_refs( &(e->EP) );
83 en = e ->next;
84 free( e );
85 e = en;
86 }
87 Free_ParamNames(param_name, nb_parms);
88 return 0;
89}
#define VALUE_FMT
Definition: arithmetique.h:295
int Value
Definition: arithmetique.h:294
#define value_read(val, str)
Definition: arithmetique.h:489
#define value_print(Dst, fmt, val)
Definition: arithmetique.h:490
#define value_init(val)
Definition: arithmetique.h:484
void print_evalue(FILE *DST, evalue *e, char **pname)
Definition: ehrhart.c:169
void free_evalue_refs(evalue *e)
releases all memory referenced by e.
Definition: ehrhart.c:115
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:2584
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:218
void Matrix_Free(Matrix *Mat)
Definition: matrix.c:69
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
char ** Read_ParamNames(FILE *in, int m)
Definition: param.c:14
void Free_ParamNames(char **params, int m)
Definition: param.c:63
void Polyhedron_Free(Polyhedron *Pol)
Definition: polyhedron.c:1621
void Print_Domain(FILE *DST, Polyhedron *D, char **pname)
Definition: polyparam.c:1682
Polyhedron * ValidityDomain
Definition: types.h:210
evalue EP
Definition: types.h:211
struct _enumeration * next
Definition: types.h:212
Definition: types.h:88
unsigned NbColumns
Definition: types.h:89
#define FOREVER
Definition: types.h:48