4 #include <barvinok/util.h>
5 #include <barvinok/barvinok.h>
10 #include "omega/convert.h"
13 #include "verif_ehrhart.h"
15 /* The input of this example program is a polytope in combined
16 * data and parameter space followed by two lines indicating
17 * the number of existential variables and parameters respectively.
18 * The first lines starts with "E ", followed by a number.
19 * The second lines starts with "P ", followed by a number.
20 * These two lines are (optionally) followed by the names of the parameters.
21 * The polytope is in PolyLib notation.
24 struct argp_option argp_options
[] = {
25 { "omega", 'o', 0, 0 },
27 { "series", 's', 0, 0 },
28 { "scarf", 'S', 0, 0 },
29 { "convert", 'c', 0, 0 },
30 { "floor", 'f', 0, 0 },
31 { "range-reduction", 'R', 0, 0 },
36 struct verify_options verify
;
46 error_t
parse_opt(int key
, char *arg
, struct argp_state
*state
)
48 struct arguments
*arguments
= (struct arguments
*)(state
->input
);
52 state
->child_inputs
[0] = arguments
->verify
.barvinok
;
53 state
->child_inputs
[1] = &arguments
->verify
;
56 arguments
->series
= 1;
65 error(0, 0, "--omega option not supported");
72 error(0, 0, "--pip option not supported");
79 arguments
->convert
= 1;
85 return ARGP_ERR_UNKNOWN
;
92 Polyhedron
*Omega_simplify(Polyhedron
*P
,
93 unsigned exist
, unsigned nparam
, char **parms
)
97 Relation r
= Polyhedron2relation(P
, exist
, nparam
, parms
);
99 return relation2Domain(r
, varv
, paramv
);
102 Polyhedron
*Omega_simplify(Polyhedron
*P
,
103 unsigned exist
, unsigned nparam
, char **parms
)
109 static void verify_results(Polyhedron
*P
, evalue
*EP
, int exist
, int nparam
,
110 verify_options
*options
);
112 int main(int argc
, char **argv
)
117 int exist
, nparam
, nvar
;
120 int print_solution
= 1;
121 struct arguments arguments
;
122 static struct argp_child argp_children
[] = {
123 { &barvinok_argp
, 0, 0, 0 },
124 { &verify_argp
, 0, "verification", 1 },
127 static struct argp argp
= { argp_options
, parse_opt
, 0, 0, argp_children
};
128 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
130 arguments
.verify
.barvinok
= options
;
132 arguments
.convert
= 0;
136 arguments
.series
= 0;
139 argp_parse(&argp
, argc
, argv
, 0, 0, &arguments
);
141 if (arguments
.series
&& !arguments
.scarf
) {
143 "--series currently only available if --scarf is specified\n");
148 A
= Constraints2Polyhedron(MA
, options
->MaxRays
);
151 fgets(s
, 128, stdin
);
152 while ((*s
=='#') || (sscanf(s
, "E %d", &exist
)<1))
153 fgets(s
, 128, stdin
);
155 fgets(s
, 128, stdin
);
156 while ((*s
=='#') || (sscanf(s
, "P %d", &nparam
)<1))
157 fgets(s
, 128, stdin
);
159 /******* Read the options: initialize Min and Max ********/
160 verify_options_set_range(&arguments
.verify
, A
);
162 if (arguments
.verify
.verify
)
165 if (print_solution
) {
166 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
167 printf("exist: %d, nparam: %d\n", exist
, nparam
);
169 param_name
= Read_ParamNames(stdin
, nparam
);
170 nvar
= A
->Dimension
- exist
- nparam
;
171 if (arguments
.omega
) {
172 A
= Omega_simplify(A
, exist
, nparam
, param_name
);
174 exist
= A
->Dimension
- nvar
- nparam
;
176 if (arguments
.series
) {
178 barvinok_options
*options
= barvinok_options_new_with_defaults();
179 assert(arguments
.scarf
);
180 gf
= barvinok_enumerate_scarf_series(A
, exist
, nparam
, options
);
181 if (print_solution
) {
182 gf
->print(std::cout
, nparam
, param_name
);
186 barvinok_options_free(options
);
188 if (arguments
.scarf
) {
189 barvinok_options
*options
= barvinok_options_new_with_defaults();
190 EP
= barvinok_enumerate_scarf(A
, exist
, nparam
, options
);
191 barvinok_options_free(options
);
192 } else if (arguments
.pip
&& exist
> 0)
193 EP
= barvinok_enumerate_pip_with_options(A
, exist
, nparam
, options
);
195 EP
= barvinok_enumerate_e_with_options(A
, exist
, nparam
, options
);
199 evalue_range_reduction(EP
);
201 print_evalue(stdout
, EP
, param_name
);
202 if (arguments
.floor
) {
203 fprintf(stderr
, "WARNING: floor conversion not supported\n");
204 evalue_frac2floor2(EP
, 0);
206 print_evalue(stdout
, EP
, param_name
);
207 } else if (arguments
.convert
) {
208 evalue_mod2table(EP
, nparam
);
210 print_evalue(stdout
, EP
, param_name
);
212 if (arguments
.verify
.verify
) {
213 arguments
.verify
.params
= param_name
;
214 verify_results(A
, EP
, exist
, nparam
, &arguments
.verify
);
216 free_evalue_refs(EP
);
219 Free_ParamNames(param_name
, nparam
);
224 void verify_results(Polyhedron
*P
, evalue
*EP
, int exist
, int nparam
,
225 verify_options
*options
)
231 unsigned MaxRays
= options
->barvinok
->MaxRays
;
232 Polyhedron
*C
= Polyhedron_Project(P
, nparam
);
235 p
= (Value
*)malloc(sizeof(Value
) * (P
->Dimension
+2));
236 for(i
=0;i
<=P
->Dimension
;i
++) {
238 value_set_si(p
[i
],0);
241 value_set_si(p
[i
],1);
243 /* S = scanning list of polyhedra */
244 S
= Polyhedron_Scan(P
, C
, MaxRays
& POL_NO_DUAL
? 0 : MaxRays
);
246 CS
= check_poly_context_scan(C
, options
);
248 check_poly_init(C
, options
);
250 /******* CHECK NOW *********/
252 if (S
&& !check_poly(S
, CS
, EP
, exist
, nparam
, 0, p
, options
)) {
253 fprintf(stderr
,"Check failed !\n");
257 if (!options
->print_all
)
260 for(i
=0;i
<=(P
->Dimension
+1);i
++)