polylib 5.22.8
ehrhart_quick_apx.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
7int main( int argc, char **argv)
8{
9 int i;
10 const char **param_name = NULL;
11 Matrix *C1, *P1;
12 Polyhedron *P, *C;
13 Enumeration *e, *en;
14
15 Matrix * Validity_Lattice;
16 int nb_parms;
17
18#ifdef EP_EVALUATION
19 Value *p, *tmp;
20 int k;
21#endif
22
23 P1 = Matrix_Read();
24 C1 = Matrix_Read();
25 nb_parms = C1->NbColumns-2;
26 if(nb_parms < 0) {
27 fprintf( stderr, "Not enough parameters !\n" );
28 exit(0);
29 }
30
31 /* Read the name of the parameters */
32 param_name = Read_ParamNames(stdin,nb_parms);
33
34 /* compute a polynomial approximation of the Ehrhart polynomial */
35 printf("============ Ehrhart polynomial quick approximation ============\n");
36 e = Ehrhart_Quick_Apx(P1, C1, &Validity_Lattice, 1024);
37
38 Matrix_Free(C1);
39 Matrix_Free(P1);
40
41 show_matrix(Validity_Lattice);
42 for( en=e ; en ; en=en->next ) {
43 Print_Domain(stdout,en->ValidityDomain, param_name);
44 print_evalue(stdout,&en->EP, param_name);
45 printf( "\n-----------------------------------\n" );
46 }
47
48#ifdef EP_EVALUATION
49 if( isatty(0) && nb_parms != 0)
50 { /* no tty input or no polyhedron -> no evaluation. */
51 printf("Evaluation of the Ehrhart polynomial :\n");
52 p = (Value *)malloc(sizeof(Value) * (nb_parms));
53 for(i=0;i<nb_parms;i++)
54 value_init(p[i]);
55 FOREVER {
56 fflush(stdin);
57 printf("Enter %d parameters : ",nb_parms);
58 for(k=0;k<nb_parms;++k) {
59 scanf("%s",str);
60 value_read(p[k],str);
61 }
62 fprintf(stdout,"EP( ");
63 value_print(stdout,VALUE_FMT,p[0]);
64 for(k=1;k<nb_parms;++k) {
65 fprintf(stdout,",");
66 value_print(stdout,VALUE_FMT,p[k]);
67 }
68 fprintf(stdout," ) = ");
69 value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
70 free(tmp);
71 fprintf(stdout,"\n");
72 }
73 }
74#endif /* EP_EVALUATION */
75
76 while( e )
77 {
78 free_evalue_refs( &(e->EP) );
80 en = e ->next;
81 free( e );
82 e = en;
83 }
84 Free_ParamNames(param_name, nb_parms);
85 return 0;
86}
#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
#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