2 #include <NTL/mat_ZZ.h>
4 #include <polylib/polylibgmp.h>
5 #include <barvinok/evalue.h>
7 #include <barvinok/util.h>
8 #include <barvinok/barvinok.h>
10 #include "verif_ehrhart.h"
12 #ifdef HAVE_GROWING_CHERNIKOVA
20 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
23 struct option options
[] = {
24 { "explicit", no_argument
, 0, 'e' },
25 { "series", no_argument
, 0, 's' },
26 { "verbose", no_argument
, 0, 'v' },
27 { "version", no_argument
, 0, 'V' },
32 /* RANGE : normal range for evalutations (-RANGE -> RANGE) */
35 /* SRANGE : small range for evalutations */
38 /* if dimension >= BIDDIM, use SRANGE */
41 /* VSRANGE : very small range for evalutations */
44 /* if dimension >= VBIDDIM, use VSRANGE */
47 int check_series(Polyhedron
*S
, Polyhedron
*CS
, gen_fun
*gf
,
48 int nparam
,int pos
,Value
*z
)
60 /* Computes the coefficient */
61 gf
->coefficient(&z
[S
->Dimension
-nparam
+1], &c
);
63 /* if c=0 we may be out of context. */
64 /* scanning is useless in this case*/
66 #ifdef PRINT_ALL_RESULTS
68 value_print(stdout
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
69 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
71 value_print(stdout
,VALUE_FMT
,z
[k
]);
74 value_print(stdout
,VALUE_FMT
,c
);
77 /* Manually count the number of points */
78 count_points(1,S
,z
,&tmp
);
79 #ifdef PRINT_ALL_RESULTS
81 value_print(stdout
, P_VALUE_FMT
, tmp
);
88 fprintf(stderr
,"Error !\n");
89 fprintf(stderr
,"EP( ");
90 value_print(stderr
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
91 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
93 value_print(stderr
,VALUE_FMT
,z
[k
]);
95 fprintf(stderr
," ) should be ");
96 value_print(stderr
,VALUE_FMT
,tmp
);
97 fprintf(stderr
,", while EP eval gives ");
98 value_print(stderr
,VALUE_FMT
,c
);
99 fprintf(stderr
,".\n");
100 #ifndef DONT_BREAK_ON_ERROR
101 value_clear(c
); value_clear(tmp
);
105 #ifdef PRINT_ALL_RESULTS
111 !(lower_upper_bounds(1+pos
, CS
, &z
[S
->Dimension
-nparam
], &LB
, &UB
));
113 for(value_assign(tmp
,LB
); value_le(tmp
,UB
); value_increment(tmp
,tmp
)) {
114 #ifndef PRINT_ALL_RESULTS
115 k
= VALUE_TO_INT(tmp
);
116 if(!pos
&& !(k
%st
)) {
121 value_assign(z
[pos
+S
->Dimension
-nparam
+1],tmp
);
122 if(!check_series(S
, CS
, gf
, nparam
, pos
+1, z
)) {
123 value_clear(c
); value_clear(tmp
);
129 value_set_si(z
[pos
+S
->Dimension
-nparam
+1],0);
139 int main(int argc
,char *argv
[]) {
141 Matrix
*C1
, *P1
, *MM
;
142 Polyhedron
*C
, *P
, *S
, *CS
, *U
;
148 int m
= INT_MAX
, M
= INT_MIN
, r
;
155 while ((c
= getopt_long(argc
, argv
, "m:M:r:sveV", options
, &ind
)) != -1) {
177 printf(barvinok_version());
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
)
212 fprintf(stderr
,"Nothing to do: Min > Max !\n");
221 /******* Compute true context *******/
222 CC
= align_context(C
,P
->Dimension
,MAXRAYS
);
223 PP
= DomainIntersection(P
,CC
,MAXRAYS
);
225 C1
= Matrix_Alloc(C
->Dimension
+1,P
->Dimension
+1);
227 for(i
=0;i
<C1
->NbRows
;i
++)
228 for(j
=0;j
<C1
->NbColumns
;j
++)
229 if(i
==j
-P
->Dimension
+C
->Dimension
)
230 value_set_si(C1
->p
[i
][j
],1);
232 value_set_si(C1
->p
[i
][j
],0);
233 CC
= Polyhedron_Image(PP
,C1
,MAXRAYS
);
239 /* Intersect context with range */
240 if(C
->Dimension
> 0) {
241 MM
= Matrix_Alloc(2*C
->Dimension
, C
->Dimension
+2);
242 for (i
= 0; i
< C
->Dimension
; ++i
) {
243 value_set_si(MM
->p
[2*i
][0], 1);
244 value_set_si(MM
->p
[2*i
][1+i
], 1);
245 value_set_si(MM
->p
[2*i
][1+C
->Dimension
], -m
);
246 value_set_si(MM
->p
[2*i
+1][0], 1);
247 value_set_si(MM
->p
[2*i
+1][1+i
], -1);
248 value_set_si(MM
->p
[2*i
+1][1+C
->Dimension
], M
);
250 CC
= AddConstraints(MM
->p
[0], 2*C
->Dimension
, C
, MAXRAYS
);
251 U
= Universe_Polyhedron(0);
252 CS
= Polyhedron_Scan(CC
, U
, MAXRAYS
);
261 /******* Compute EP *********/
263 en
= barvinok_enumerate(P
,C
,MAXRAYS
);
266 gf
= barvinok_series(P
, C
, MAXRAYS
);
268 gf
->print(C
->Dimension
, params
);
273 en
= partition2enumeration(EP
);
277 /******* Initializations for check *********/
278 p
= (Value
*)malloc(sizeof(Value
) * (P
->Dimension
+2));
279 for(i
=0;i
<=P
->Dimension
;i
++) {
281 value_set_si(p
[i
],0);
284 value_set_si(p
[i
],1);
286 /* S = scanning list of polyhedra */
287 S
= Polyhedron_Scan(P
,C
,MAXRAYS
);
289 #ifndef PRINT_ALL_RESULTS
290 if(C
->Dimension
> 0) {
291 value_subtract(tmp
,Max
,Min
);
292 if (VALUE_TO_INT(tmp
) > 80)
293 st
= 1+(VALUE_TO_INT(tmp
))/80;
296 for(i
=VALUE_TO_INT(Min
);i
<=VALUE_TO_INT(Max
);i
+=st
)
303 /******* CHECK NOW *********/
305 if (!series
|| function
) {
306 if (!check_poly(S
, CS
,en
,C
->Dimension
,0,p
))
309 if (!check_series(S
, CS
,gf
,C
->Dimension
,0,p
))
316 fprintf(stderr
,"Check failed !\n");
318 #ifndef PRINT_ALL_RESULTS
325 for(i
=0;i
<=(P
->Dimension
+1);i
++)
329 Free_ParamNames(params
, C
->Dimension
);