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"
25 #ifdef HAVE_GROWING_CHERNIKOVA
32 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
35 struct option options
[] = {
36 { "min", no_argument
, 0, 'm' },
37 { "max", no_argument
, 0, 'M' },
38 { "range", no_argument
, 0, 'r' },
39 { "pip", no_argument
, 0, 'p' },
44 /* define this to print all the results */
45 /* else, only a progress bar is printed */
46 /* #define PRINT_ALL_RESULTS
47 /* define this to continue the test after first error found */
48 /* #define DONT_BREAK_ON_ERROR */
50 /* RANGE : normal range for evalutations (-RANGE -> RANGE) */
53 /* SRANGE : small range for evalutations */
56 /* if dimension >= BIDDIM, use SRANGE */
59 /* VSRANGE : very small range for evalutations */
62 /* if dimension >= VBIDDIM, use VSRANGE */
69 #ifdef DONT_BREAK_ON_ERROR
70 #define PRINT_ALL_RESULTS
73 #ifndef PRINT_ALL_RESULTS
77 /****************************************************/
78 /* function check_poly : */
79 /* scans the parameter space from min to max (all */
80 /* directions). Computes the number of points in */
81 /* the polytope using both methods, and compare them*/
82 /* returns 1 on success */
83 /****************************************************/
85 int check_poly(Polyhedron
*S
, Polyhedron
*C
, evalue
*EP
,
86 int exist
, int nparam
, int pos
, Value
*z
) {
91 value_init(c
); value_init(tmp
);
95 /* Computes the ehrhart polynomial */
96 value_set_double(c
, compute_evalue(EP
,&z
[S
->Dimension
-nparam
+1])+.25);
97 /* if c=0 we may be out of context. */
98 /* scanning is useless in this case*/
99 if(!in_domain(C
,&z
[S
->Dimension
-nparam
+1])) {
105 #ifdef PRINT_ALL_RESULTS
107 value_print(stdout
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
108 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
110 value_print(stdout
,VALUE_FMT
,z
[k
]);
113 value_print(stdout
,VALUE_FMT
,c
);
117 /* Manually count the number of points */
118 count_points_e(1, S
, exist
, nparam
, z
, &tmp
);
119 #ifdef PRINT_ALL_RESULTS
120 printf(", count = ");
121 value_print(stdout
, P_VALUE_FMT
, tmp
);
125 if(value_ne(tmp
,c
)) {
128 fprintf(stderr
,"Error !\n");
129 fprintf(stderr
,"EP( ");
130 value_print(stderr
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
131 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
132 fprintf(stderr
,", ");
133 value_print(stderr
,VALUE_FMT
,z
[k
]);
135 fprintf(stderr
," ) should be ");
136 value_print(stderr
,VALUE_FMT
,tmp
);
137 fprintf(stderr
,", while EP eval gives ");
138 value_print(stderr
,VALUE_FMT
,c
);
139 fprintf(stderr
,".\n");
140 print_evalue(stderr
, EP
, params
);
141 #ifndef DONT_BREAK_ON_ERROR
142 value_clear(c
); value_clear(tmp
);
147 #ifdef PRINT_ALL_RESULTS
154 for(value_assign(tmp
,min
); value_le(tmp
,max
); value_increment(tmp
,tmp
)) {
156 #ifndef PRINT_ALL_RESULTS
157 k
= VALUE_TO_INT(tmp
);
158 if(!pos
&& !(k
%st
)) {
164 value_assign(z
[pos
+S
->Dimension
-nparam
+1],tmp
);
165 if(!check_poly(S
, C
, EP
, exist
, nparam
, pos
+1, z
)) {
166 value_clear(c
); value_clear(tmp
);
170 value_clear(c
); value_clear(tmp
);
174 int main(int argc
,char *argv
[])
177 Polyhedron
*C
, *P
, *S
;
188 /******* Read the input *********/
191 fgets(s
, 128, stdin
);
192 while ((*s
=='#') || (sscanf(s
, "E %d", &exist
)<1))
193 fgets(s
, 128, stdin
);
195 fgets(s
, 128, stdin
);
196 while ((*s
=='#') || (sscanf(s
, "P %d", &nparam
)<1))
197 fgets(s
, 128, stdin
);
199 P
= Constraints2Polyhedron(P1
,MAXRAYS
);
200 params
= Read_ParamNames(stdin
, nparam
);
203 /******* Read the options: initialize min and max ********/
204 if(P
->Dimension
>= VBIGDIM
)
206 else if(P
->Dimension
>= BIGDIM
)
212 while ((c
= getopt_long(argc
, argv
, "pm:M:r:", options
, &ind
)) != -1) {
231 fprintf(stderr
,"Nothing to do: min > max !\n");
240 /******* Compute true context *******/
241 C1
= Matrix_Alloc(nparam
+1,P
->Dimension
+1);
243 for(i
=0;i
<C1
->NbRows
;i
++)
244 for(j
=0;j
<C1
->NbColumns
;j
++)
245 if(i
==j
-P
->Dimension
+nparam
)
246 value_set_si(C1
->p
[i
][j
],1);
248 value_set_si(C1
->p
[i
][j
],0);
249 C
= Polyhedron_Image(P
,C1
,MAXRAYS
);
252 /******* Compute EP *********/
254 EP
= barvinok_enumerate_pip(P
, exist
, nparam
, MAXRAYS
);
256 EP
= barvinok_enumerate_e(P
, exist
, nparam
, MAXRAYS
);
258 /******* Initializations for check *********/
259 p
= (Value
*)malloc(sizeof(Value
) * (P
->Dimension
+2));
260 for(i
=0;i
<=P
->Dimension
;i
++) {
262 value_set_si(p
[i
],0);
265 value_set_si(p
[i
],1);
267 /* S = scanning list of polyhedra */
268 S
= Polyhedron_Scan(P
,C
,MAXRAYS
);
270 #ifndef PRINT_ALL_RESULTS
271 if(C
->Dimension
> 0) {
272 value_substract(tmp
,max
,min
);
273 if (VALUE_TO_INT(tmp
) > 80)
274 st
= 1+(VALUE_TO_INT(tmp
))/80;
277 for(i
=VALUE_TO_INT(min
);i
<=VALUE_TO_INT(max
);i
+=st
)
284 /******* CHECK NOW *********/
286 if(S
&& !check_poly(S
, C
, EP
, exist
, nparam
, 0, p
)) {
287 fprintf(stderr
,"Check failed !\n");
291 #ifndef PRINT_ALL_RESULTS
295 for(i
=0;i
<=(P
->Dimension
+1);i
++)
299 Free_ParamNames(params
, C
->Dimension
);
303 free_evalue_refs(EP
);