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>
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 /* define this to print all the results */
32 /* else, only a progress bar is printed */
33 /* #define PRINT_ALL_RESULTS */
34 /* define this to continue the test after first error found */
35 /* #define DONT_BREAK_ON_ERROR */
37 /* RANGE : normal range for evalutations (-RANGE -> RANGE) */
40 /* SRANGE : small range for evalutations */
43 /* if dimension >= BIDDIM, use SRANGE */
46 /* VSRANGE : very small range for evalutations */
49 /* if dimension >= VBIDDIM, use VSRANGE */
56 #ifdef DONT_BREAK_ON_ERROR
57 #define PRINT_ALL_RESULTS
60 #ifndef PRINT_ALL_RESULTS
64 /****************************************************/
65 /* function check_poly : */
66 /* scans the parameter space from min to max (all */
67 /* directions). Computes the number of points in */
68 /* the polytope using both methods, and compare them*/
69 /* returns 1 on success */
70 /****************************************************/
72 int check_poly(Polyhedron
*S
,Polyhedron
*C
,Enumeration
*en
,
73 int nparam
,int pos
,Value
*z
) {
78 value_init(c
); value_init(tmp
);
82 /* Computes the ehrhart polynomial */
83 value_assign(c
,*(ctmp
=compute_poly(en
,&z
[S
->Dimension
-nparam
+1])));
85 /* if c=0 we may be out of context. */
86 /* scanning is useless in this case*/
87 if(!in_domain(C
,&z
[S
->Dimension
-nparam
+1])) {
93 #ifdef PRINT_ALL_RESULTS
95 value_print(stdout
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
96 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
98 value_print(stdout
,VALUE_FMT
,z
[k
]);
101 value_print(stdout
,VALUE_FMT
,c
);
105 /* Manually count the number of points */
106 count_points(1,S
,z
,&tmp
);
107 #ifdef PRINT_ALL_RESULTS
108 printf(", count = ");
109 value_print(stdout
, P_VALUE_FMT
, tmp
);
113 if(value_ne(tmp
,c
)) {
116 fprintf(stderr
,"Error !\n");
117 fprintf(stderr
,"EP( ");
118 value_print(stderr
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
119 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
120 fprintf(stderr
,", ");
121 value_print(stderr
,VALUE_FMT
,z
[k
]);
123 fprintf(stderr
," ) should be ");
124 value_print(stderr
,VALUE_FMT
,tmp
);
125 fprintf(stderr
,", while EP eval gives ");
126 value_print(stderr
,VALUE_FMT
,c
);
127 fprintf(stderr
,".\n");
129 Enumeration_Print(stderr
, en
, params
);
133 if (in_domain(ee
->ValidityDomain
,&z
[S
->Dimension
-nparam
+1])) {
134 Print_Domain(stderr
, ee
->ValidityDomain
, params
);
135 print_evalue(stderr
, &ee
->EP
, params
);
140 #ifndef DONT_BREAK_ON_ERROR
141 value_clear(c
); value_clear(tmp
);
146 #ifdef PRINT_ALL_RESULTS
153 for(value_assign(tmp
,min
); value_le(tmp
,max
); value_increment(tmp
,tmp
)) {
155 #ifndef PRINT_ALL_RESULTS
156 k
= VALUE_TO_INT(tmp
);
157 if(!pos
&& !(k
%st
)) {
163 value_assign(z
[pos
+S
->Dimension
-nparam
+1],tmp
);
164 if(!check_poly(S
,C
,en
,nparam
,pos
+1,z
)) {
165 value_clear(c
); value_clear(tmp
);
169 value_clear(c
); value_clear(tmp
);
173 int main(int argc
,char *argv
[]) {
176 Polyhedron
*C
, *P
, *S
;
183 /******* Read the input *********/
187 if(C1
->NbColumns
< 2) {
188 fprintf(stderr
,"Not enough parameters !\n");
192 P
= Constraints2Polyhedron(P1
,MAXRAYS
);
193 C
= Constraints2Polyhedron(C1
,MAXRAYS
);
194 params
= Read_ParamNames(stdin
, C
->Dimension
);
198 /******* Read the options: initialize min and max ********/
199 if(P
->Dimension
>= VBIGDIM
)
201 else if(P
->Dimension
>= BIGDIM
)
207 for(i
=1;i
<argc
;i
++) {
208 if(!strncmp(argv
[i
],"-m",2)) {
211 m
= atoi(&argv
[i
][2]);
213 else if(!strncmp(argv
[i
],"-M",2)) {
216 M
= atoi(&argv
[i
][2]);
218 else if(!strncmp(argv
[i
], "-r", 2)) {
220 /* range specified */
221 M
= atoi(&argv
[i
][2]);
225 fprintf(stderr
,"Unknown option: %s\n",argv
[i
]);
226 fprintf(stderr
,"Usage: %s [-m<>][-M<>][-r<>]\n",argv
[0]);
232 fprintf(stderr
,"Nothing to do: min > max !\n");
241 /******* Compute true context *******/
242 CC
= align_context(C
,P
->Dimension
,MAXRAYS
);
243 PP
= DomainIntersection(P
,CC
,MAXRAYS
);
245 C1
= Matrix_Alloc(C
->Dimension
+1,P
->Dimension
+1);
247 for(i
=0;i
<C1
->NbRows
;i
++)
248 for(j
=0;j
<C1
->NbColumns
;j
++)
249 if(i
==j
-P
->Dimension
+C
->Dimension
)
250 value_set_si(C1
->p
[i
][j
],1);
252 value_set_si(C1
->p
[i
][j
],0);
253 CC
= Polyhedron_Image(PP
,C1
,MAXRAYS
);
257 /******* Compute EP *********/
258 en
= barvinok_enumerate(P
,C
,MAXRAYS
);
260 /******* Initializations for check *********/
261 p
= (Value
*)malloc(sizeof(Value
) * (P
->Dimension
+2));
262 for(i
=0;i
<=P
->Dimension
;i
++) {
264 value_set_si(p
[i
],0);
267 value_set_si(p
[i
],1);
269 /* S = scanning list of polyhedra */
270 S
= Polyhedron_Scan(P
,C
,MAXRAYS
);
272 #ifndef PRINT_ALL_RESULTS
273 if(C
->Dimension
> 0) {
274 value_substract(tmp
,max
,min
);
275 if (VALUE_TO_INT(tmp
) > 80)
276 st
= 1+(VALUE_TO_INT(tmp
))/80;
279 for(i
=VALUE_TO_INT(min
);i
<=VALUE_TO_INT(max
);i
+=st
)
286 /******* CHECK NOW *********/
287 if(S
&& !check_poly(S
,C
,en
,C
->Dimension
,0,p
)) {
288 fprintf(stderr
,"Check failed !\n");
289 for(i
=0;i
<=(P
->Dimension
+1);i
++)
295 #ifndef PRINT_ALL_RESULTS
299 for(i
=0;i
<=(P
->Dimension
+1);i
++)
302 Free_ParamNames(params
, C
->Dimension
);