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