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 { "print-all", no_argument
, 0, 'A' },
27 { "verbose", no_argument
, 0, 'v' },
28 { "version", no_argument
, 0, 'V' },
33 /* RANGE : normal range for evalutations (-RANGE -> RANGE) */
36 /* SRANGE : small range for evalutations */
39 /* if dimension >= BIDDIM, use SRANGE */
42 /* VSRANGE : very small range for evalutations */
45 /* if dimension >= VBIDDIM, use VSRANGE */
48 int check_series(Polyhedron
*S
, Polyhedron
*CS
, gen_fun
*gf
,
49 int nparam
, int pos
, Value
*z
, int print_all
)
61 /* Computes the coefficient */
62 gf
->coefficient(&z
[S
->Dimension
-nparam
+1], &c
);
64 /* if c=0 we may be out of context. */
65 /* scanning is useless in this case*/
69 value_print(stdout
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
70 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
72 value_print(stdout
,VALUE_FMT
,z
[k
]);
75 value_print(stdout
,VALUE_FMT
,c
);
78 /* Manually count the number of points */
79 count_points(1,S
,z
,&tmp
);
82 value_print(stdout
, P_VALUE_FMT
, tmp
);
89 fprintf(stderr
,"Error !\n");
90 fprintf(stderr
,"EP( ");
91 value_print(stderr
,VALUE_FMT
,z
[S
->Dimension
-nparam
+1]);
92 for(k
=S
->Dimension
-nparam
+2;k
<=S
->Dimension
;++k
) {
94 value_print(stderr
,VALUE_FMT
,z
[k
]);
96 fprintf(stderr
," ) should be ");
97 value_print(stderr
,VALUE_FMT
,tmp
);
98 fprintf(stderr
,", while EP eval gives ");
99 value_print(stderr
,VALUE_FMT
,c
);
100 fprintf(stderr
,".\n");
101 #ifndef DONT_BREAK_ON_ERROR
102 value_clear(c
); value_clear(tmp
);
105 } else if (print_all
)
109 !(lower_upper_bounds(1+pos
, CS
, &z
[S
->Dimension
-nparam
], &LB
, &UB
));
111 for(value_assign(tmp
,LB
); value_le(tmp
,UB
); value_increment(tmp
,tmp
)) {
113 k
= VALUE_TO_INT(tmp
);
114 if(!pos
&& !(k
%st
)) {
119 value_assign(z
[pos
+S
->Dimension
-nparam
+1],tmp
);
120 if (!check_series(S
, CS
->next
, gf
, nparam
, pos
+1, z
, print_all
)) {
121 value_clear(c
); value_clear(tmp
);
127 value_set_si(z
[pos
+S
->Dimension
-nparam
+1],0);
137 int main(int argc
,char *argv
[]) {
139 Matrix
*C1
, *P1
, *MM
;
140 Polyhedron
*C
, *P
, *S
, *CS
, *U
;
142 Enumeration
*en
= NULL
;
146 int m
= INT_MAX
, M
= INT_MIN
, r
;
154 while ((c
= getopt_long(argc
, argv
, "m:M:r:sveVA", options
, &ind
)) != -1) {
179 printf(barvinok_version());
185 /******* Read the input *********/
189 if(C1
->NbColumns
< 2) {
190 fprintf(stderr
,"Not enough parameters !\n");
194 P
= Constraints2Polyhedron(P1
,MAXRAYS
);
195 C
= Constraints2Polyhedron(C1
,MAXRAYS
);
196 params
= Read_ParamNames(stdin
, C
->Dimension
);
200 /******* Read the options: initialize Min and Max ********/
201 if(P
->Dimension
>= VBIGDIM
)
203 else if(P
->Dimension
>= BIGDIM
)
214 fprintf(stderr
,"Nothing to do: Min > Max !\n");
223 /******* Compute true context *******/
224 CC
= align_context(C
,P
->Dimension
,MAXRAYS
);
225 PP
= DomainIntersection(P
,CC
,MAXRAYS
);
227 C1
= Matrix_Alloc(C
->Dimension
+1,P
->Dimension
+1);
229 for(i
=0;i
<C1
->NbRows
;i
++)
230 for(j
=0;j
<C1
->NbColumns
;j
++)
231 if(i
==j
-P
->Dimension
+C
->Dimension
)
232 value_set_si(C1
->p
[i
][j
],1);
234 value_set_si(C1
->p
[i
][j
],0);
235 CC
= Polyhedron_Image(PP
,C1
,MAXRAYS
);
241 /* Intersect context with range */
242 if(C
->Dimension
> 0) {
243 MM
= Matrix_Alloc(2*C
->Dimension
, C
->Dimension
+2);
244 for (i
= 0; i
< C
->Dimension
; ++i
) {
245 value_set_si(MM
->p
[2*i
][0], 1);
246 value_set_si(MM
->p
[2*i
][1+i
], 1);
247 value_set_si(MM
->p
[2*i
][1+C
->Dimension
], -m
);
248 value_set_si(MM
->p
[2*i
+1][0], 1);
249 value_set_si(MM
->p
[2*i
+1][1+i
], -1);
250 value_set_si(MM
->p
[2*i
+1][1+C
->Dimension
], M
);
252 CC
= AddConstraints(MM
->p
[0], 2*C
->Dimension
, C
, MAXRAYS
);
253 U
= Universe_Polyhedron(0);
254 CS
= Polyhedron_Scan(CC
, U
, MAXRAYS
);
263 /******* Compute EP *********/
265 en
= barvinok_enumerate(P
,C
,MAXRAYS
);
267 Enumeration_Print(stdout
, en
, params
);
270 gf
= barvinok_series(P
, C
, MAXRAYS
);
272 gf
->print(std::cout
, C
->Dimension
, params
);
277 en
= partition2enumeration(EP
);
279 Enumeration_Print(stdout
, en
, params
);
283 /******* Initializations for check *********/
284 p
= (Value
*)malloc(sizeof(Value
) * (P
->Dimension
+2));
285 for(i
=0;i
<=P
->Dimension
;i
++) {
287 value_set_si(p
[i
],0);
290 value_set_si(p
[i
],1);
292 /* S = scanning list of polyhedra */
293 S
= Polyhedron_Scan(P
,C
,MAXRAYS
);
296 if (C
->Dimension
> 0) {
297 value_subtract(tmp
,Max
,Min
);
298 if (VALUE_TO_INT(tmp
) > 80)
299 st
= 1+(VALUE_TO_INT(tmp
))/80;
302 for(i
=VALUE_TO_INT(Min
);i
<=VALUE_TO_INT(Max
);i
+=st
)
308 /******* CHECK NOW *********/
310 if (!series
|| function
) {
311 if (!check_poly(S
, CS
,en
,C
->Dimension
,0,p
, print_all
))
314 if (!check_series(S
, CS
,gf
,C
->Dimension
,0,p
, print_all
))
321 fprintf(stderr
,"Check failed !\n");
327 Enumeration_Free(en
);
331 for(i
=0;i
<=(P
->Dimension
+1);i
++)
337 Free_ParamNames(params
, C
->Dimension
);