4 #include <barvinok/util.h>
5 #include <barvinok/barvinok.h>
11 #include "omega/convert.h"
12 #include "omega/count.h"
14 #include "skewed_genfun.h"
16 #include "verif_ehrhart.h"
17 #include "verify_series.h"
18 #include "evalue_convert.h"
20 /* The input of this example program is a polytope in combined
21 * data and parameter space followed by two lines indicating
22 * the number of existential variables and parameters respectively.
23 * The first lines starts with "E ", followed by a number.
24 * The second lines starts with "P ", followed by a number.
25 * These two lines are (optionally) followed by the names of the parameters.
26 * The polytope is in PolyLib notation.
29 struct argp_option argp_options
[] = {
30 { "omega", 'o', 0, 0 },
31 { "parker", 'P', 0, 0 },
33 { "series", 's', 0, 0 },
34 { "series", 's', 0, 0, "compute rational generating function" },
35 { "explicit", 'e', 0, 0, "convert rgf to psp" },
36 { "scarf", 'S', 0, 0 },
41 struct verify_options verify
;
42 struct convert_options convert
;
51 error_t
parse_opt(int key
, char *arg
, struct argp_state
*state
)
53 struct arguments
*arguments
= (struct arguments
*)(state
->input
);
57 state
->child_inputs
[0] = arguments
->verify
.barvinok
;
58 state
->child_inputs
[1] = &arguments
->verify
;
59 state
->child_inputs
[2] = &arguments
->convert
;
62 arguments
->function
= 1;
65 arguments
->series
= 1;
74 error(0, 0, "--omega option not supported");
79 arguments
->parker
= 1;
81 error(0, 0, "--parker option not supported");
88 return ARGP_ERR_UNKNOWN
;
95 Polyhedron
*Omega_simplify(Polyhedron
*P
,
96 unsigned exist
, unsigned nparam
, char **parms
,
101 Relation r
= Polyhedron2relation(P
, exist
, nparam
, parms
);
103 return relation2Domain(r
, varv
, paramv
, MaxRays
);
106 Polyhedron
*Omega_simplify(Polyhedron
*P
,
107 unsigned exist
, unsigned nparam
, char **parms
,
113 evalue
*barvinok_enumerate_parker(Polyhedron
*P
,
114 unsigned exist
, unsigned nparam
,
121 static void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
122 int exist
, int nparam
,
125 int main(int argc
, char **argv
)
130 int exist
, nparam
, nvar
;
134 int print_solution
= 1;
135 struct arguments arguments
;
136 static struct argp_child argp_children
[] = {
137 { &barvinok_argp
, 0, 0, 0 },
138 { &verify_argp
, 0, "verification", BV_GRP_LAST
+1 },
139 { &convert_argp
, 0, "output conversion", BV_GRP_LAST
+2 },
142 static struct argp argp
= { argp_options
, parse_opt
, 0, 0, argp_children
};
143 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
145 arguments
.verify
.barvinok
= options
;
147 arguments
.parker
= 0;
150 arguments
.series
= 0;
151 arguments
.function
= 0;
153 set_program_name(argv
[0]);
154 argp_parse(&argp
, argc
, argv
, 0, 0, &arguments
);
157 A
= Constraints2Polyhedron(MA
, options
->MaxRays
);
160 fgets(s
, 128, stdin
);
161 while ((*s
=='#') || (sscanf(s
, "E %d", &exist
)<1))
162 fgets(s
, 128, stdin
);
164 fgets(s
, 128, stdin
);
165 while ((*s
=='#') || (sscanf(s
, "P %d", &nparam
)<1))
166 fgets(s
, 128, stdin
);
168 /******* Read the options: initialize Min and Max ********/
170 if (arguments
.verify
.verify
) {
171 verify_options_set_range(&arguments
.verify
, A
->Dimension
);
172 if (!options
->verbose
)
176 if (print_solution
&& options
->verbose
) {
177 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
178 printf("exist: %d, nparam: %d\n", exist
, nparam
);
180 param_name
= Read_ParamNames(stdin
, nparam
);
181 nvar
= A
->Dimension
- exist
- nparam
;
182 if (arguments
.omega
) {
183 A
= Omega_simplify(A
, exist
, nparam
, param_name
, options
->MaxRays
);
185 exist
= A
->Dimension
- nvar
- nparam
;
187 if (arguments
.series
) {
189 gf
= barvinok_enumerate_scarf_series(A
, exist
, nparam
, options
);
191 gf
= barvinok_enumerate_e_series(A
, exist
, nparam
, options
);
192 if (print_solution
) {
193 gf
->print(std::cout
, nparam
, param_name
);
196 if (arguments
.function
) {
199 print_evalue(stdout
, EP
, param_name
);
202 if (arguments
.parker
)
203 EP
= barvinok_enumerate_parker(A
, A
->Dimension
-nparam
-exist
,
204 nparam
, options
->MaxRays
);
205 else if (arguments
.scarf
)
206 EP
= barvinok_enumerate_scarf(A
, exist
, nparam
, options
);
207 else if (arguments
.pip
&& exist
> 0)
208 EP
= barvinok_enumerate_pip_with_options(A
, exist
, nparam
, options
);
210 EP
= barvinok_enumerate_e_with_options(A
, exist
, nparam
, options
);
212 if (evalue_convert(EP
, &arguments
.convert
, options
->verbose
, nparam
,
216 print_evalue(stdout
, EP
, param_name
);
218 if (arguments
.verify
.verify
) {
219 arguments
.verify
.params
= param_name
;
220 verify_results(A
, EP
, gf
, exist
, nparam
, &arguments
);
227 if (options
->print_stats
)
228 barvinok_stats_print(options
->stats
, stdout
);
230 Free_ParamNames(param_name
, nparam
);
232 barvinok_options_free(options
);
236 void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
237 int exist
, int nparam
,
245 unsigned MaxRays
= options
->verify
.barvinok
->MaxRays
;
246 Polyhedron
*C
= NULL
;
249 p
= Vector_Alloc(P
->Dimension
+2);
250 value_set_si(p
->p
[P
->Dimension
+1], 1);
252 CS
= check_poly_context_scan(P
, &C
, nparam
, &options
->verify
);
254 C
= Universe_Polyhedron(nparam
);
256 /* S = scanning list of polyhedra */
257 S
= Polyhedron_Scan(P
, C
, MaxRays
& POL_NO_DUAL
? 0 : MaxRays
);
259 check_poly_init(C
, &options
->verify
);
261 /******* CHECK NOW *********/
263 if (!options
->series
|| options
->function
) {
264 if (!check_poly_EP(S
, CS
, EP
, exist
, nparam
, 0, p
->p
,
268 skewed_gen_fun
*sgf
= new skewed_gen_fun(new gen_fun(gf
));
269 if (!check_poly_gf(S
, CS
, sgf
, exist
, nparam
, 0, p
->p
,
276 if (!options
->verify
.print_all
)