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/polylib.h>
22 /* define this to print all the results */
23 /* else, only a progress bar is printed */
24 /* #define PRINT_ALL_RESULTS */
25 /* define this to continue the test after first error found */
26 /* #define DONT_BREAK_ON_ERROR */
28 /* RANGE : normal range for evalutations (-RANGE -> RANGE) */
31 /* SRANGE : small range for evalutations */
34 /* if dimension >= BIDDIM, use SRANGE */
37 /* VSRANGE : very small range for evalutations */
40 /* if dimension >= VBIDDIM, use VSRANGE */
45 #ifdef DONT_BREAK_ON_ERROR
46 #define PRINT_ALL_RESULTS
49 #ifndef PRINT_ALL_RESULTS
53 /****************************************************/
54 /* function check_poly : */
55 /* scans the parameter space from min to max (all */
56 /* directions). Computes the number of points in */
57 /* the polytope using both methods, and compare them*/
58 /* returns 1 on success */
59 /****************************************************/
61 int check_poly(Polyhedron
*S
,Polyhedron
*C
,Enumeration
*en
,
62 int nparam
,int pos
,Value
*z
) {
67 value_init(c
); value_init(tmp
);
71 /* Computes the ehrhart polynomial */
72 value_assign(c
,*(ctmp
=compute_poly(en
,&z
[S
->Dimension
-nparam
+1])));
74 /* if c=0 we may be out of context. */
75 /* scanning is useless in this case*/
76 if(!in_domain(C
,&z
[S
->Dimension
-nparam
+1])) {
82 #ifdef PRINT_ALL_RESULTS
84 value_print(stdout
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
85 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
87 value_print(stdout
,VALUE_FMT
,z
[k
]);
90 value_print(stdout
,VALUE_FMT
,c
);
94 /* Count manually the number of points */
95 count_points(1,S
,z
,&tmp
);
96 #ifdef PRINT_ALL_RESULTS
98 value_print(stdout
, P_VALUE_FMT
, tmp
);
102 if(value_ne(tmp
,c
)) {
105 fprintf(stderr
,"Error !\n");
106 fprintf(stderr
,"EP( ");
107 value_print(stderr
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
108 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
109 fprintf(stderr
,", ");
110 value_print(stderr
,VALUE_FMT
,z
[k
]);
112 fprintf(stderr
," ) should be ");
113 value_print(stderr
,VALUE_FMT
,tmp
);
114 fprintf(stderr
,", while EP eval gives ");
115 value_print(stderr
,VALUE_FMT
,c
);
116 fprintf(stderr
,".\n");
117 #ifndef DONT_BREAK_ON_ERROR
118 value_clear(c
); value_clear(tmp
);
123 #ifdef PRINT_ALL_RESULTS
130 for(value_assign(tmp
,min
); value_le(tmp
,max
); value_increment(tmp
,tmp
)) {
132 #ifndef PRINT_ALL_RESULTS
133 k
= VALUE_TO_INT(tmp
);
134 if(!pos
&& !(k
%st
)) {
140 value_assign(z
[pos
+S
->Dimension
-nparam
+1],tmp
);
141 if(!check_poly(S
,C
,en
,nparam
,pos
+1,z
)) {
142 value_clear(c
); value_clear(tmp
);
146 value_clear(c
); value_clear(tmp
);
150 int main(int argc
,char *argv
[]) {
153 Polyhedron
*C
, *P
, *S
;
160 /******* Read the input *********/
164 if(C1
->NbColumns
< 2) {
165 fprintf(stderr
,"Not enough parameters !\n");
169 P
= Constraints2Polyhedron(P1
,MAXRAYS
);
170 C
= Constraints2Polyhedron(C1
,MAXRAYS
);
174 /******* Read the options: initialize min and max ********/
175 if(P
->Dimension
>= VBIGDIM
)
177 else if(P
->Dimension
>= BIGDIM
)
183 for(i
=1;i
<argc
;i
++) {
184 if(!strncmp(argv
[i
],"-m",2)) {
187 m
= atoi(&argv
[i
][2]);
189 else if(!strncmp(argv
[i
],"-M",2)) {
192 M
= atoi(&argv
[i
][2]);
194 else if(!strncmp(argv
[i
], "-r", 2)) {
196 /* range specified */
197 M
= atoi(&argv
[i
][2]);
201 fprintf(stderr
,"Unknown option: %s\n",argv
[i
]);
202 fprintf(stderr
,"Usage: %s [-m<>][-M<>][-r<>]\n",argv
[0]);
208 fprintf(stderr
,"Nothing to do: min > max !\n");
217 /******* Compute true context *******/
218 CC
= align_context(C
,P
->Dimension
,MAXRAYS
);
219 PP
= DomainIntersection(P
,CC
,MAXRAYS
);
221 C1
= Matrix_Alloc(C
->Dimension
+1,P
->Dimension
+1);
223 for(i
=0;i
<C1
->NbRows
;i
++)
224 for(j
=0;j
<C1
->NbColumns
;j
++)
225 if(i
==j
-P
->Dimension
+C
->Dimension
)
226 value_set_si(C1
->p
[i
][j
],1);
228 value_set_si(C1
->p
[i
][j
],0);
229 CC
= Polyhedron_Image(PP
,C1
,MAXRAYS
);
233 /******* Compute EP *********/
234 en
= Polyhedron_Enumerate(P
,C
,MAXRAYS
,NULL
);
236 /******* Initializations for check *********/
237 p
= (Value
*)malloc(sizeof(Value
) * (P
->Dimension
+2));
238 for(i
=0;i
<=P
->Dimension
;i
++) {
240 value_set_si(p
[i
],0);
243 value_set_si(p
[i
],1);
245 /* S = scanning list of polyhedra */
246 S
= Polyhedron_Scan(P
,C
,MAXRAYS
);
248 #ifndef PRINT_ALL_RESULTS
249 if(C
->Dimension
> 0) {
250 value_subtract(tmp
,max
,min
);
251 if (VALUE_TO_INT(tmp
) > 80)
252 st
= 1+(VALUE_TO_INT(tmp
))/80;
255 for(i
=VALUE_TO_INT(min
);i
<=VALUE_TO_INT(max
);i
+=st
)
262 /******* CHECK NOW *********/
263 if(S
&& !check_poly(S
,C
,en
,C
->Dimension
,0,p
)) {
264 fprintf(stderr
,"Check failed !\n");
265 for(i
=0;i
<=(P
->Dimension
+1);i
++)
271 #ifndef PRINT_ALL_RESULTS
275 for(i
=0;i
<=(P
->Dimension
+1);i
++)