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 <barvinok/evalue.h>
20 #include <barvinok/barvinok.h>
21 #include "verif_ehrhart.h"
23 #undef CS /* for Solaris 10 */
26 #ifndef HAVE_COUNT_POINTS4
27 #define count_points(a,b,c,d) { \
28 int cc = count_points(a,b,c); \
29 value_set_si(*d,cc); \
33 struct check_poly_EP_data
{
34 struct check_poly_data cp
;
40 static int cp_EP(const struct check_poly_data
*data
, int nparam
, Value
*z
,
41 const struct verify_options
*options
)
46 int pa
= options
->barvinok
->polynomial_approximation
;
47 struct check_poly_EP_data
* EP_data
= (struct check_poly_EP_data
*) data
;
48 const evalue
*EP
= EP_data
->EP
;
49 int exist
= EP_data
->exist
;
50 Polyhedron
*S
= EP_data
->S
;
55 /* Computes the ehrhart polynomial */
56 value_set_double(c
, compute_evalue(EP
, z
)+.25);
58 if (options
->print_all
) {
60 value_print(stdout
, VALUE_FMT
, z
[0]);
61 for (k
= 1; k
< nparam
; ++k
) {
63 value_print(stdout
, VALUE_FMT
, z
[k
]);
66 value_print(stdout
, VALUE_FMT
, c
);
69 /* Manually count the number of points */
71 count_points_e(1, S
, exist
, nparam
, data
->z
, &tmp
);
73 count_points(1, S
, data
->z
, &tmp
);
75 if (options
->print_all
) {
77 value_print(stdout
, VALUE_FMT
, tmp
);
81 if (pa
== BV_POLAPPROX_PRE_APPROX
)
82 /* just accept everything */
84 else if (pa
== BV_POLAPPROX_PRE_LOWER
|| pa
== BV_POLAPPROX_LOWER
)
85 ok
= value_le(c
, tmp
);
86 else if (pa
== BV_POLAPPROX_PRE_UPPER
|| pa
== BV_POLAPPROX_UPPER
)
87 ok
= value_ge(c
, tmp
);
89 ok
= value_eq(c
, tmp
);
94 fprintf(stderr
, "Error !\n");
95 fprintf(stderr
, "EP(");
96 value_print(stderr
, VALUE_FMT
, z
[0]);
97 for (k
= 1; k
< nparam
; ++k
) {
99 value_print(stderr
, VALUE_FMT
, z
[k
]);
101 fprintf(stderr
, ") should be ");
102 value_print(stderr
, VALUE_FMT
, tmp
);
103 fprintf(stderr
, ", while EP eval gives ");
104 value_print(stderr
, VALUE_FMT
, c
);
105 fprintf(stderr
, ".\n");
106 print_evalue(stderr
, EP
, options
->params
);
107 if (value_zero_p(EP
->d
) && EP
->x
.p
->type
== partition
)
108 for (k
= 0; k
< EP
->x
.p
->size
/2; ++k
) {
109 Polyhedron
*D
= EVALUE_DOMAIN(EP
->x
.p
->arr
[2*k
]);
110 if (in_domain(D
, z
)) {
111 Print_Domain(stderr
, D
, options
->params
);
112 print_evalue(stderr
, &EP
->x
.p
->arr
[2*k
+1], options
->params
);
115 } else if (options
->print_all
)
124 int check_poly_EP(Polyhedron
*S
, Polyhedron
*CS
, evalue
*EP
, int exist
,
125 int nparam
, int pos
, Value
*z
, const struct verify_options
*options
)
127 struct check_poly_EP_data data
;
129 data
.cp
.check
= cp_EP
;
133 return check_poly(CS
, &data
.cp
, nparam
, pos
, z
+S
->Dimension
-nparam
+1, options
);