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 /*************************************************/
20 #include <polylib/polylibgmp.h>
21 #include "ev_operations.h"
26 #ifdef HAVE_GROWING_CHERNIKOVA
33 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
36 struct option options
[] = {
37 { "min", no_argument
, 0, 'm' },
38 { "max", no_argument
, 0, 'M' },
39 { "range", no_argument
, 0, 'r' },
40 { "pip", no_argument
, 0, 'p' },
45 /* define this to print all the results */
46 /* else, only a progress bar is printed */
47 /* #define PRINT_ALL_RESULTS
48 /* define this to continue the test after first error found */
49 /* #define DONT_BREAK_ON_ERROR */
51 /* RANGE : normal range for evalutations (-RANGE -> RANGE) */
54 /* SRANGE : small range for evalutations */
57 /* if dimension >= BIDDIM, use SRANGE */
60 /* VSRANGE : very small range for evalutations */
63 /* if dimension >= VBIDDIM, use VSRANGE */
70 #ifdef DONT_BREAK_ON_ERROR
71 #define PRINT_ALL_RESULTS
74 #ifndef PRINT_ALL_RESULTS
78 /****************************************************/
79 /* function check_poly : */
80 /* scans the parameter space from min to max (all */
81 /* directions). Computes the number of points in */
82 /* the polytope using both methods, and compare them*/
83 /* returns 1 on success */
84 /****************************************************/
86 int check_poly(Polyhedron
*S
, Polyhedron
*C
, evalue
*EP
,
87 int exist
, int nparam
, int pos
, Value
*z
) {
92 value_init(c
); value_init(tmp
);
96 /* Computes the ehrhart polynomial */
97 value_set_double(c
, compute_evalue(EP
,&z
[S
->Dimension
-nparam
+1])+.25);
98 /* if c=0 we may be out of context. */
99 /* scanning is useless in this case*/
100 if(!in_domain(C
,&z
[S
->Dimension
-nparam
+1])) {
106 #ifdef PRINT_ALL_RESULTS
108 value_print(stdout
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
109 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
111 value_print(stdout
,VALUE_FMT
,z
[k
]);
114 value_print(stdout
,VALUE_FMT
,c
);
118 /* Manually count the number of points */
119 count_points_e(1, S
, exist
, nparam
, z
, &tmp
);
120 #ifdef PRINT_ALL_RESULTS
121 printf(", count = ");
122 value_print(stdout
, P_VALUE_FMT
, tmp
);
126 if(value_ne(tmp
,c
)) {
129 fprintf(stderr
,"Error !\n");
130 fprintf(stderr
,"EP( ");
131 value_print(stderr
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
132 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
133 fprintf(stderr
,", ");
134 value_print(stderr
,VALUE_FMT
,z
[k
]);
136 fprintf(stderr
," ) should be ");
137 value_print(stderr
,VALUE_FMT
,tmp
);
138 fprintf(stderr
,", while EP eval gives ");
139 value_print(stderr
,VALUE_FMT
,c
);
140 fprintf(stderr
,".\n");
141 print_evalue(stderr
, EP
, params
);
142 #ifndef DONT_BREAK_ON_ERROR
143 value_clear(c
); value_clear(tmp
);
148 #ifdef PRINT_ALL_RESULTS
155 for(value_assign(tmp
,min
); value_le(tmp
,max
); value_increment(tmp
,tmp
)) {
157 #ifndef PRINT_ALL_RESULTS
158 k
= VALUE_TO_INT(tmp
);
159 if(!pos
&& !(k
%st
)) {
165 value_assign(z
[pos
+S
->Dimension
-nparam
+1],tmp
);
166 if(!check_poly(S
, C
, EP
, exist
, nparam
, pos
+1, z
)) {
167 value_clear(c
); value_clear(tmp
);
171 value_clear(c
); value_clear(tmp
);
175 int main(int argc
,char *argv
[])
178 Polyhedron
*C
, *P
, *S
;
189 /******* Read the input *********/
192 fgets(s
, 128, stdin
);
193 while ((*s
=='#') || (sscanf(s
, "E %d", &exist
)<1))
194 fgets(s
, 128, stdin
);
196 fgets(s
, 128, stdin
);
197 while ((*s
=='#') || (sscanf(s
, "P %d", &nparam
)<1))
198 fgets(s
, 128, stdin
);
200 P
= Constraints2Polyhedron(P1
,MAXRAYS
);
201 params
= Read_ParamNames(stdin
, nparam
);
204 /******* Read the options: initialize min and max ********/
205 if(P
->Dimension
>= VBIGDIM
)
207 else if(P
->Dimension
>= BIGDIM
)
213 while ((c
= getopt_long(argc
, argv
, "pm:M:r:", options
, &ind
)) != -1) {
232 fprintf(stderr
,"Nothing to do: min > max !\n");
241 /******* Compute true context *******/
242 C1
= Matrix_Alloc(nparam
+1,P
->Dimension
+1);
244 for(i
=0;i
<C1
->NbRows
;i
++)
245 for(j
=0;j
<C1
->NbColumns
;j
++)
246 if(i
==j
-P
->Dimension
+nparam
)
247 value_set_si(C1
->p
[i
][j
],1);
249 value_set_si(C1
->p
[i
][j
],0);
250 C
= Polyhedron_Image(P
,C1
,MAXRAYS
);
253 /******* Compute EP *********/
255 EP
= barvinok_enumerate_pip(P
, exist
, nparam
, MAXRAYS
);
257 EP
= barvinok_enumerate_e(P
, exist
, nparam
, MAXRAYS
);
259 /******* Initializations for check *********/
260 p
= (Value
*)malloc(sizeof(Value
) * (P
->Dimension
+2));
261 for(i
=0;i
<=P
->Dimension
;i
++) {
263 value_set_si(p
[i
],0);
266 value_set_si(p
[i
],1);
268 /* S = scanning list of polyhedra */
269 S
= Polyhedron_Scan(P
,C
,MAXRAYS
);
271 #ifndef PRINT_ALL_RESULTS
272 if(C
->Dimension
> 0) {
273 value_substract(tmp
,max
,min
);
274 if (VALUE_TO_INT(tmp
) > 80)
275 st
= 1+(VALUE_TO_INT(tmp
))/80;
278 for(i
=VALUE_TO_INT(min
);i
<=VALUE_TO_INT(max
);i
+=st
)
285 /******* CHECK NOW *********/
287 if(S
&& !check_poly(S
, C
, EP
, exist
, nparam
, 0, p
)) {
288 fprintf(stderr
,"Check failed !\n");
292 #ifndef PRINT_ALL_RESULTS
296 for(i
=0;i
<=(P
->Dimension
+1);i
++)
300 Free_ParamNames(params
, C
->Dimension
);
304 free_evalue_refs(EP
);