1 /*************************************************/
3 /* program to compare effective number of points */
4 /* in a polytope with the corresponding */
5 /* evaluation of the Ehrhart polynomial. */
6 /* Parameters vary in range -RANGE to RANGE */
7 /* (define below) by default. */
8 /* Can be overridden by specifying */
9 /* -r<RANGE>, or -m<min> and -M<max> */
11 /* written by Vincent Loechner (c) 2000. */
12 /* loechner@icps.u-strasbg.fr */
13 /*************************************************/
19 #include <polylib/polylibgmp.h>
20 #include "ev_operations.h"
24 #ifndef HAVE_COUNT_POINTS4
25 #define count_points(a,b,c,d) { \
26 int cc = count_points(a,b,c); \
27 value_set_si(*d,cc); \
31 #ifdef HAVE_GROWING_CHERNIKOVA
37 /* define this to print all the results */
38 /* else, only a progress bar is printed */
39 /* #define PRINT_ALL_RESULTS */
40 /* define this to continue the test after first error found */
41 /* #define DONT_BREAK_ON_ERROR */
43 /* RANGE : normal range for evalutations (-RANGE -> RANGE) */
46 /* SRANGE : small range for evalutations */
49 /* if dimension >= BIDDIM, use SRANGE */
52 /* VSRANGE : very small range for evalutations */
55 /* if dimension >= VBIDDIM, use VSRANGE */
62 #ifdef DONT_BREAK_ON_ERROR
63 #define PRINT_ALL_RESULTS
66 #ifndef PRINT_ALL_RESULTS
70 /****************************************************/
71 /* function check_poly : */
72 /* scans the parameter space from min to max (all */
73 /* directions). Computes the number of points in */
74 /* the polytope using both methods, and compare them*/
75 /* returns 1 on success */
76 /****************************************************/
78 int check_poly(Polyhedron
*S
,Polyhedron
*C
,Enumeration
*en
,
79 int nparam
,int pos
,Value
*z
) {
84 value_init(c
); value_init(tmp
);
88 /* Computes the ehrhart polynomial */
89 value_assign(c
,*(ctmp
=compute_poly(en
,&z
[S
->Dimension
-nparam
+1])));
91 /* if c=0 we may be out of context. */
92 /* scanning is useless in this case*/
93 if(!in_domain(C
,&z
[S
->Dimension
-nparam
+1])) {
99 #ifdef PRINT_ALL_RESULTS
101 value_print(stdout
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
102 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
104 value_print(stdout
,VALUE_FMT
,z
[k
]);
107 value_print(stdout
,VALUE_FMT
,c
);
111 /* Manually count the number of points */
112 count_points(1,S
,z
,&tmp
);
113 #ifdef PRINT_ALL_RESULTS
114 printf(", count = ");
115 value_print(stdout
, P_VALUE_FMT
, tmp
);
119 if(value_ne(tmp
,c
)) {
122 fprintf(stderr
,"Error !\n");
123 fprintf(stderr
,"EP( ");
124 value_print(stderr
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
125 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
126 fprintf(stderr
,", ");
127 value_print(stderr
,VALUE_FMT
,z
[k
]);
129 fprintf(stderr
," ) should be ");
130 value_print(stderr
,VALUE_FMT
,tmp
);
131 fprintf(stderr
,", while EP eval gives ");
132 value_print(stderr
,VALUE_FMT
,c
);
133 fprintf(stderr
,".\n");
136 Enumeration_Print(stderr
, en
, params
);
139 if (in_domain(ee
->ValidityDomain
,&z
[S
->Dimension
-nparam
+1])) {
140 Print_Domain(stderr
, ee
->ValidityDomain
, params
);
141 print_evalue(stderr
, &ee
->EP
, params
);
146 #ifndef DONT_BREAK_ON_ERROR
147 value_clear(c
); value_clear(tmp
);
152 #ifdef PRINT_ALL_RESULTS
159 for(value_assign(tmp
,min
); value_le(tmp
,max
); value_increment(tmp
,tmp
)) {
161 #ifndef PRINT_ALL_RESULTS
162 k
= VALUE_TO_INT(tmp
);
163 if(!pos
&& !(k
%st
)) {
169 value_assign(z
[pos
+S
->Dimension
-nparam
+1],tmp
);
170 if(!check_poly(S
,C
,en
,nparam
,pos
+1,z
)) {
171 value_clear(c
); value_clear(tmp
);
175 value_clear(c
); value_clear(tmp
);
179 int main(int argc
,char *argv
[]) {
182 Polyhedron
*C
, *P
, *S
;
189 /******* Read the input *********/
193 if(C1
->NbColumns
< 2) {
194 fprintf(stderr
,"Not enough parameters !\n");
198 P
= Constraints2Polyhedron(P1
,MAXRAYS
);
199 C
= Constraints2Polyhedron(C1
,MAXRAYS
);
200 params
= Read_ParamNames(stdin
, C
->Dimension
);
204 /******* Read the options: initialize min and max ********/
205 if(P
->Dimension
>= VBIGDIM
)
207 else if(P
->Dimension
>= BIGDIM
)
213 for(i
=1;i
<argc
;i
++) {
214 if(!strncmp(argv
[i
],"-m",2)) {
217 m
= atoi(&argv
[i
][2]);
219 else if(!strncmp(argv
[i
],"-M",2)) {
222 M
= atoi(&argv
[i
][2]);
224 else if(!strncmp(argv
[i
], "-r", 2)) {
226 /* range specified */
227 M
= atoi(&argv
[i
][2]);
231 fprintf(stderr
,"Unknown option: %s\n",argv
[i
]);
232 fprintf(stderr
,"Usage: %s [-m<>][-M<>][-r<>]\n",argv
[0]);
238 fprintf(stderr
,"Nothing to do: min > max !\n");
247 /******* Compute true context *******/
248 CC
= align_context(C
,P
->Dimension
,MAXRAYS
);
249 PP
= DomainIntersection(P
,CC
,MAXRAYS
);
251 C1
= Matrix_Alloc(C
->Dimension
+1,P
->Dimension
+1);
253 for(i
=0;i
<C1
->NbRows
;i
++)
254 for(j
=0;j
<C1
->NbColumns
;j
++)
255 if(i
==j
-P
->Dimension
+C
->Dimension
)
256 value_set_si(C1
->p
[i
][j
],1);
258 value_set_si(C1
->p
[i
][j
],0);
259 CC
= Polyhedron_Image(PP
,C1
,MAXRAYS
);
263 /******* Compute EP *********/
264 en
= barvinok_enumerate(P
,C
,MAXRAYS
);
266 /******* Initializations for check *********/
267 p
= (Value
*)malloc(sizeof(Value
) * (P
->Dimension
+2));
268 for(i
=0;i
<=P
->Dimension
;i
++) {
270 value_set_si(p
[i
],0);
273 value_set_si(p
[i
],1);
275 /* S = scanning list of polyhedra */
276 S
= Polyhedron_Scan(P
,C
,MAXRAYS
);
278 #ifndef PRINT_ALL_RESULTS
279 if(C
->Dimension
> 0) {
280 value_substract(tmp
,max
,min
);
281 if (VALUE_TO_INT(tmp
) > 80)
282 st
= 1+(VALUE_TO_INT(tmp
))/80;
285 for(i
=VALUE_TO_INT(min
);i
<=VALUE_TO_INT(max
);i
+=st
)
292 /******* CHECK NOW *********/
293 if(S
&& !check_poly(S
,C
,en
,C
->Dimension
,0,p
)) {
294 fprintf(stderr
,"Check failed !\n");
295 for(i
=0;i
<=(P
->Dimension
+1);i
++)
301 #ifndef PRINT_ALL_RESULTS
305 for(i
=0;i
<=(P
->Dimension
+1);i
++)
308 Free_ParamNames(params
, C
->Dimension
);