fixed a small bug in eval ehrhart
[polylib.git] / applications / testehrhart.c
blob6fb3c70ac7973ce1f733a4898b6fc23faba1592d
1 /***********************************************************************/
2 /* Ehrhart V4.20 */
3 /* copyright 1997, Doran Wilde */
4 /* copyright 1997-2000, Vincent Loechner */
5 /* Permission is granted to copy, use, and distribute */
6 /* for any commercial or noncommercial purpose under the terms */
7 /* of the GNU General Public license, version 2, June 1991 */
8 /* (see file : LICENSING). */
9 /***********************************************************************/
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <ctype.h>
14 #include <string.h>
15 #include <unistd.h>
16 #include <assert.h>
18 #include <polylib/polylib.h>
20 /**
22 define this to print all constraints on the validity domains if not
23 defined, only new constraints (not in validity domain given by the
24 user) are printed
27 #define EPRINT_ALL_VALIDITY_CONSTRAINTS
29 /**
31 The following are mainly for debug purposes. You shouldn't need to
32 change anything for daily usage...
36 /** you may define each macro independently
37 <ol>
38 <li> #define EDEBUG minimal debug
39 <li> #define EDEBUG1 prints enumeration points
40 <li> #define EDEBUG11 prints number of points
41 <li> #define EDEBUG2 prints domains
42 <li> #define EDEBUG21 prints more domains
43 <li> #define EDEBUG3 prints systems of equations that are solved
44 <li> #define EDEBUG4 prints message for degree reduction
45 <li> #define EDEBUG5 prints result before simplification
46 <li> #define EDEBUG6 prints domains in Preprocess
47 <li> #define EDEBUG61 prints even more in Preprocess
48 <li> #define EDEBUG62 prints domains in Preprocess2
49 </ol>
52 /* #define EDEBUG */ /* minimal debug */
53 /* #define EDEBUG1 */ /* prints enumeration points */
54 /* #define EDEBUG11 */ /* prints number of points */
55 /* #define EDEBUG2 */ /* prints domains */
56 /* #define EDEBUG21 */ /* prints more domains */
57 /* #define EDEBUG3 */ /* prints systems of equations that are solved */
58 /* #define EDEBUG4 */ /* prints message for degree reduction */
59 /* #define EDEBUG5 */ /* prints result before simplification */
60 /* #define EDEBUG6 */ /* prints domains in Preprocess */
61 /* #define EDEBUG61 */ /* prints even more in Preprocess */
62 /* #define EDEBUG62 */ /* prints domains in Preprocess2 */
65 /**
67 Reduce the degree of resulting polynomials
70 #define REDUCE_DEGREE
72 /**
74 define this to print one warning message per domain overflow these
75 overflows should no longer happen since version 4.20
78 #define ALL_OVERFLOW_WARNINGS
80 /**
82 EPRINT : print results while computing the ehrhart polynomial. this
83 is done by default if you build the executable ehrhart. (If EMAIN is
84 defined). Don't define EMAIN here, it is defined when necessary in
85 the makefile.
87 <p>
89 Notice: you may however define EPRINT without defining EMAIN, but in
90 this case, you have to initialize the global variable param_name by
91 calling Read_ParamNames before any call to ehrhart. This is NOT
92 recommanded, unless you know what you do. EPRINT causes more debug
93 messages to be printed.
96 /* #define EPRINT */
98 int main() {
100 int i;
101 char str[1024];
102 Matrix *C1, *P1;
103 Polyhedron *C, *P;
104 Enumeration *en, *ee;
105 char **param_name;
107 #ifdef EP_EVALUATION
108 Value *p, *tmp;
109 int k;
110 #endif
112 P1 = Matrix_Read();
113 C1 = Matrix_Read();
114 if(C1->NbColumns < 2) {
115 fprintf( stderr, "Not enough parameters !\n" );
116 exit(0);
118 P = Constraints2Polyhedron(P1,1024);
119 C = Constraints2Polyhedron(C1,1024);
120 Matrix_Free(C1);
121 Matrix_Free(P1);
123 /* Read the name of the parameters */
124 param_name = Read_ParamNames(stdin,C->Dimension);
125 en = Polyhedron_Enumerate(P,C,1024,param_name);
127 #ifdef EP_EVALUATION
128 if( isatty(0) && C->Dimension != 0)
129 { /* no tty input or no polyhedron -> no evaluation. */
130 printf("Evaluation of the Ehrhart polynomial :\n");
131 p = (Value *)malloc(sizeof(Value) * (C->Dimension));
132 for(i=0;i<C->Dimension;i++)
133 value_init(p[i]);
134 FOREVER {
135 fflush(stdin);
136 printf("Enter %d parameters : ",C->Dimension);
137 for(k=0;k<C->Dimension;++k) {
138 scanf("%s",str);
139 value_read(p[k],str);
141 fprintf(stdout,"EP( ");
142 value_print(stdout,VALUE_FMT,p[0]);
143 for(k=1;k<C->Dimension;++k) {
144 fprintf(stdout,",");
145 value_print(stdout,VALUE_FMT,p[k]);
147 fprintf(stdout," ) = ");
148 value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
149 free(tmp);
150 fprintf(stdout,"\n");
153 #endif /* EP_EVALUATION */
155 while( en )
157 free_evalue_refs( &(en->EP) );
158 Polyhedron_Free( en->ValidityDomain );
159 ee = en ->next;
160 free( en );
161 en = ee;
163 for( i=0 ; i<C->Dimension ; i++ )
164 free( param_name[i] );
165 free(param_name);
166 Polyhedron_Free( P );
167 Polyhedron_Free( C );
169 return 0;