3 #include <barvinok/options.h>
4 #include <barvinok/util.h>
7 /* RANGE : normal range for evalutations (-RANGE -> RANGE) */
10 /* SRANGE : small range for evalutations */
13 /* if dimension >= BIDDIM, use SRANGE */
16 /* VSRANGE : very small range for evalutations */
19 /* if dimension >= VBIDDIM, use VSRANGE */
22 static struct argp_option argp_options
[] = {
23 { "verify", 'T', 0, 0 },
24 { "exact", 'E', 0, 0 },
25 { "print-all", 'A', 0, 0 },
26 { "continue-on-error", 'C', 0, 0 },
27 { "min", 'm', "int", 0 },
28 { "max", 'M', "int", 0 },
29 { "range", 'r', "int", 0 },
33 static error_t
parse_opt(int key
, char *arg
, struct argp_state
*state
)
35 struct verify_options
*options
= state
->input
;
41 options
->print_all
= 0;
42 options
->continue_on_error
= 0;
55 options
->print_all
= 1;
58 options
->continue_on_error
= 1;
61 options
->m
= atoi(arg
);
65 options
->M
= atoi(arg
);
69 options
->M
= atoi(arg
);
70 options
->m
= -options
->M
;
74 return ARGP_ERR_UNKNOWN
;
79 void verify_options_set_range(struct verify_options
*options
, int dim
)
85 else if (dim
>= BIGDIM
)
89 if (options
->M
== INT_MIN
)
91 if (options
->m
== INT_MAX
)
94 if (options
->verify
&& options
->m
> options
->M
) {
95 fprintf(stderr
,"Nothing to do: min > max !\n");
100 struct argp verify_argp
= {
101 argp_options
, parse_opt
, 0, 0
104 Polyhedron
*check_poly_context_scan(Polyhedron
*P
, Polyhedron
**C
,
106 const struct verify_options
*options
)
110 Polyhedron
*CC
, *CC2
, *CS
, *U
;
111 unsigned MaxRays
= options
->barvinok
->MaxRays
;
119 CC
= Polyhedron_Project(P
, nparam
);
121 CC2
= DomainIntersection(*C
, CC
, MaxRays
);
127 /* Intersect context with range */
128 MM
= Matrix_Alloc(2*nparam
, nparam
+2);
129 for (i
= 0; i
< nparam
; ++i
) {
130 value_set_si(MM
->p
[2*i
][0], 1);
131 value_set_si(MM
->p
[2*i
][1+i
], 1);
132 value_set_si(MM
->p
[2*i
][1+nparam
], -options
->m
);
133 value_set_si(MM
->p
[2*i
+1][0], 1);
134 value_set_si(MM
->p
[2*i
+1][1+i
], -1);
135 value_set_si(MM
->p
[2*i
+1][1+nparam
], options
->M
);
137 CC2
= AddConstraints(MM
->p
[0], 2*nparam
, CC
, options
->barvinok
->MaxRays
);
141 U
= Universe_Polyhedron(0);
142 CS
= Polyhedron_Scan(CC
, U
, MaxRays
& POL_NO_DUAL
? 0 : MaxRays
);
149 void check_poly_init(Polyhedron
*C
, struct verify_options
*options
)
153 if (options
->print_all
)
155 if (C
->Dimension
<= 0)
158 d
= options
->M
- options
->m
;
160 options
->st
= 1+d
/80;
163 for (i
= options
->m
; i
<= options
->M
; i
+= options
->st
)
169 static void print_rational(FILE *out
, Value n
, Value d
)
171 value_print(out
, VALUE_FMT
, n
);
172 if (value_notone_p(d
)) {
174 value_print(out
, VALUE_FMT
, d
);
178 void check_poly_print(int ok
, int nparam
, Value
*z
,
179 Value want_n
, Value want_d
,
180 Value got_n
, Value got_d
,
181 const char *op
, const char *check
,
183 const struct verify_options
*options
)
187 if (options
->print_all
) {
189 value_print(stdout
, VALUE_FMT
, z
[0]);
190 for (k
= 1; k
< nparam
; ++k
) {
192 value_print(stdout
, VALUE_FMT
, z
[k
]);
195 print_rational(stdout
, got_n
, got_d
);
196 printf(", %s = ", check
);
197 print_rational(stdout
, want_n
, want_d
);
204 fprintf(stderr
, "Error !\n");
205 fprintf(stderr
, "%s(", op
);
206 value_print(stderr
, VALUE_FMT
, z
[0]);
207 for (k
= 1; k
< nparam
; ++k
) {
208 fprintf(stderr
,", ");
209 value_print(stderr
, VALUE_FMT
, z
[k
]);
211 fprintf(stderr
, ") should be ");
212 print_rational(stderr
, want_n
, want_d
);
213 fprintf(stderr
, ", while %s gives ", long_op
);
214 print_rational(stderr
, got_n
, got_d
);
215 fprintf(stderr
, ".\n");
216 } else if (options
->print_all
)
220 /****************************************************/
221 /* function check_poly : */
222 /* scans the parameter space from Min to Max (all */
223 /* directions). Computes the number of points in */
224 /* the polytope using both methods, and compare them*/
225 /* returns 1 on success */
226 /****************************************************/
228 int check_poly(Polyhedron
*CS
, const struct check_poly_data
*data
,
229 int nparam
, int pos
, Value
*z
,
230 const struct verify_options
*options
)
233 if (!data
->check(data
, nparam
, z
, options
) && !options
->continue_on_error
)
240 ok
= !(lower_upper_bounds(1+pos
, CS
, z
-1, &LB
, &UB
));
242 for (; value_le(LB
, UB
); value_increment(LB
, LB
)) {
243 if (!options
->print_all
) {
244 int k
= VALUE_TO_INT(LB
);
245 if (!pos
&& !(k
% options
->st
)) {
251 value_assign(z
[pos
], LB
);
252 if (!check_poly(CS
->next
, data
, nparam
, pos
+1, z
, options
)) {
258 value_set_si(z
[pos
], 0);