4 #include <barvinok/util.h>
5 #include <barvinok/barvinok.h>
11 #include "omega/convert.h"
13 #include "skewed_genfun.h"
15 #include "verif_ehrhart.h"
16 #include "verify_series.h"
17 #include "evalue_convert.h"
19 /* The input of this example program is a polytope in combined
20 * data and parameter space followed by two lines indicating
21 * the number of existential variables and parameters respectively.
22 * The first lines starts with "E ", followed by a number.
23 * The second lines starts with "P ", followed by a number.
24 * These two lines are (optionally) followed by the names of the parameters.
25 * The polytope is in PolyLib notation.
28 #define PRINT_STATS (BV_OPT_LAST+1)
30 struct argp_option argp_options
[] = {
31 { "omega", 'o', 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 },
38 { "print-stats", PRINT_STATS
, 0, 0 },
43 struct verify_options verify
;
44 struct convert_options convert
;
54 error_t
parse_opt(int key
, char *arg
, struct argp_state
*state
)
56 struct arguments
*arguments
= (struct arguments
*)(state
->input
);
60 state
->child_inputs
[0] = arguments
->verify
.barvinok
;
61 state
->child_inputs
[1] = &arguments
->verify
;
62 state
->child_inputs
[2] = &arguments
->convert
;
65 arguments
->print_stats
= 1;
68 arguments
->function
= 1;
71 arguments
->series
= 1;
80 error(0, 0, "--omega option not supported");
87 arguments
->verbose
= 1;
90 return ARGP_ERR_UNKNOWN
;
97 Polyhedron
*Omega_simplify(Polyhedron
*P
,
98 unsigned exist
, unsigned nparam
, char **parms
)
102 Relation r
= Polyhedron2relation(P
, exist
, nparam
, parms
);
104 return relation2Domain(r
, varv
, paramv
);
107 Polyhedron
*Omega_simplify(Polyhedron
*P
,
108 unsigned exist
, unsigned nparam
, char **parms
)
114 static void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
115 int exist
, int nparam
,
118 int main(int argc
, char **argv
)
123 int exist
, nparam
, nvar
;
127 int print_solution
= 1;
128 struct arguments arguments
;
129 static struct argp_child argp_children
[] = {
130 { &barvinok_argp
, 0, 0, 0 },
131 { &verify_argp
, 0, "verification", BV_GRP_LAST
+1 },
132 { &convert_argp
, 0, "output conversion", BV_GRP_LAST
+2 },
135 static struct argp argp
= { argp_options
, parse_opt
, 0, 0, argp_children
};
136 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
138 arguments
.verify
.barvinok
= options
;
142 arguments
.series
= 0;
143 arguments
.function
= 0;
144 arguments
.verbose
= 0;
145 arguments
.print_stats
= 0;
147 set_program_name(argv
[0]);
148 argp_parse(&argp
, argc
, argv
, 0, 0, &arguments
);
150 if (arguments
.series
&& !arguments
.scarf
) {
152 "--series currently only available if --scarf is specified\n");
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 (!arguments
.verbose
)
176 if (print_solution
&& arguments
.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
);
185 exist
= A
->Dimension
- nvar
- nparam
;
187 if (arguments
.series
) {
188 assert(arguments
.scarf
);
189 gf
= barvinok_enumerate_scarf_series(A
, exist
, nparam
, options
);
190 if (print_solution
) {
191 gf
->print(std::cout
, nparam
, param_name
);
194 if (arguments
.function
) {
197 print_evalue(stdout
, EP
, param_name
);
201 EP
= barvinok_enumerate_scarf(A
, exist
, nparam
, options
);
202 else if (arguments
.pip
&& exist
> 0)
203 EP
= barvinok_enumerate_pip_with_options(A
, exist
, nparam
, options
);
205 EP
= barvinok_enumerate_e_with_options(A
, exist
, nparam
, options
);
207 if (evalue_convert(EP
, &arguments
.convert
, arguments
.verbose
, nparam
,
211 print_evalue(stdout
, EP
, param_name
);
213 if (arguments
.verify
.verify
) {
214 arguments
.verify
.params
= param_name
;
215 verify_results(A
, EP
, gf
, exist
, nparam
, &arguments
);
222 if (arguments
.print_stats
)
223 barvinok_stats_print(options
->stats
, stdout
);
225 Free_ParamNames(param_name
, nparam
);
227 barvinok_options_free(options
);
231 void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
232 int exist
, int nparam
,
240 unsigned MaxRays
= options
->verify
.barvinok
->MaxRays
;
241 Polyhedron
*C
= NULL
;
244 p
= Vector_Alloc(P
->Dimension
+2);
245 value_set_si(p
->p
[P
->Dimension
+1], 1);
247 CS
= check_poly_context_scan(P
, &C
, nparam
, &options
->verify
);
249 C
= Universe_Polyhedron(nparam
);
251 /* S = scanning list of polyhedra */
252 S
= Polyhedron_Scan(P
, C
, MaxRays
& POL_NO_DUAL
? 0 : MaxRays
);
254 check_poly_init(C
, &options
->verify
);
256 /******* CHECK NOW *********/
258 if (!options
->series
|| options
->function
) {
259 if (!check_poly_EP(S
, CS
, EP
, exist
, nparam
, 0, p
->p
,
263 skewed_gen_fun
*sgf
= new skewed_gen_fun(new gen_fun(gf
));
264 if (!check_poly_gf(S
, CS
, sgf
, exist
, nparam
, 0, p
->p
,
271 if (!options
->verify
.print_all
)