5 #include <barvinok/util.h>
6 #include <barvinok/barvinok.h>
12 #include "omega_interface/convert.h"
13 #include "omega_interface/count.h"
15 #include "skewed_genfun.h"
17 #include "verif_ehrhart.h"
18 #include "verify_series.h"
19 #include "evalue_convert.h"
21 /* The input of this example program is a polytope in combined
22 * data and parameter space followed by two lines indicating
23 * the number of existential variables and parameters respectively.
24 * The first lines starts with "E ", followed by a number.
25 * The second lines starts with "P ", followed by a number.
26 * These two lines are (optionally) followed by the names of the parameters.
27 * The polytope is in PolyLib notation.
30 struct argp_option argp_options
[] = {
32 { "omega", 'o', 0, 0 },
33 { "parker", 'P', 0, 0 },
35 { "series", 's', 0, 0 },
36 { "series", 's', 0, 0, "compute rational generating function" },
37 { "explicit", 'e', 0, 0, "convert rgf to psp" },
38 { "scarf", 'S', 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
->function
= 1;
68 arguments
->series
= 1;
77 error(0, 0, "--omega option not supported");
82 arguments
->parker
= 1;
84 error(0, 0, "--parker option not supported");
94 return ARGP_ERR_UNKNOWN
;
101 Polyhedron
*Omega_simplify(Polyhedron
*P
,
102 unsigned exist
, unsigned nparam
, const char **parms
,
107 Relation r
= Polyhedron2relation(P
, exist
, nparam
, parms
);
109 return relation2Domain(r
, varv
, paramv
, MaxRays
);
112 Polyhedron
*Omega_simplify(Polyhedron
*P
,
113 unsigned exist
, unsigned nparam
, const char **parms
,
119 evalue
*barvinok_enumerate_parker(Polyhedron
*P
,
120 unsigned exist
, unsigned nparam
,
128 static void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
129 int exist
, int nparam
,
132 static char *next_line(FILE *input
, char *line
, unsigned len
)
137 if (!(p
= fgets(line
, len
, input
)))
139 while (isspace(*p
) && *p
!= '\n')
141 } while (*p
== '#' || *p
== '\n');
146 int main(int argc
, char **argv
)
150 const char **param_name
;
151 int exist
, nparam
, nvar
;
155 int print_solution
= 1;
156 struct arguments arguments
;
157 static struct argp_child argp_children
[] = {
158 { &barvinok_argp
, 0, 0, 0 },
159 { &verify_argp
, 0, "verification", BV_GRP_LAST
+1 },
160 { &convert_argp
, 0, "output conversion", BV_GRP_LAST
+2 },
163 static struct argp argp
= { argp_options
, parse_opt
, 0, 0, argp_children
};
164 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
166 arguments
.verify
.barvinok
= options
;
169 arguments
.parker
= 0;
172 arguments
.series
= 0;
173 arguments
.function
= 0;
175 set_program_name(argv
[0]);
176 argp_parse(&argp
, argc
, argv
, 0, 0, &arguments
);
179 A
= Constraints2Polyhedron(MA
, options
->MaxRays
);
183 while (next_line(stdin
, s
, sizeof(s
)))
184 if (sscanf(s
, "E %d", &exist
) == 1)
189 while (next_line(stdin
, s
, sizeof(s
)))
190 if (sscanf(s
, "P %d", &nparam
) == 1)
194 /******* Read the options: initialize Min and Max ********/
196 if (arguments
.verify
.verify
) {
197 verify_options_set_range(&arguments
.verify
, A
->Dimension
);
198 if (!options
->verbose
)
202 if (print_solution
&& options
->verbose
) {
203 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
204 printf("exist: %d, nparam: %d\n", exist
, nparam
);
206 param_name
= Read_ParamNames(stdin
, nparam
);
207 nvar
= A
->Dimension
- exist
- nparam
;
208 if (arguments
.omega
) {
209 A
= Omega_simplify(A
, exist
, nparam
, param_name
, options
->MaxRays
);
211 exist
= A
->Dimension
- nvar
- nparam
;
213 if (arguments
.series
) {
215 gf
= barvinok_enumerate_scarf_series(A
, exist
, nparam
, options
);
217 gf
= barvinok_enumerate_e_series(A
, exist
, nparam
, options
);
218 if (print_solution
) {
219 gf
->print(std::cout
, nparam
, param_name
);
222 if (arguments
.function
) {
225 print_evalue(stdout
, EP
, param_name
);
228 if (arguments
.parker
)
229 EP
= barvinok_enumerate_parker(A
, A
->Dimension
-nparam
-exist
,
230 nparam
, options
->MaxRays
);
231 else if (arguments
.scarf
)
232 EP
= barvinok_enumerate_scarf(A
, exist
, nparam
, options
);
233 else if (arguments
.isl
&& exist
> 0)
234 EP
= barvinok_enumerate_isl(A
, exist
, nparam
, options
);
235 else if (arguments
.pip
&& exist
> 0)
236 EP
= barvinok_enumerate_pip_with_options(A
, exist
, nparam
, options
);
238 EP
= barvinok_enumerate_e_with_options(A
, exist
, nparam
, options
);
240 if (evalue_convert(EP
, &arguments
.convert
, options
->verbose
, nparam
,
244 print_evalue(stdout
, EP
, param_name
);
246 if (arguments
.verify
.verify
) {
247 arguments
.verify
.params
= param_name
;
248 verify_results(A
, EP
, gf
, exist
, nparam
, &arguments
);
255 if (options
->print_stats
)
256 barvinok_stats_print(options
->stats
, stdout
);
258 Free_ParamNames(param_name
, nparam
);
260 barvinok_options_free(options
);
264 void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
265 int exist
, int nparam
,
273 unsigned MaxRays
= options
->verify
.barvinok
->MaxRays
;
274 Polyhedron
*C
= NULL
;
277 p
= Vector_Alloc(P
->Dimension
+2);
278 value_set_si(p
->p
[P
->Dimension
+1], 1);
280 CS
= check_poly_context_scan(P
, &C
, nparam
, &options
->verify
);
282 C
= Universe_Polyhedron(nparam
);
284 /* S = scanning list of polyhedra */
285 S
= Polyhedron_Scan(P
, C
, MaxRays
& POL_NO_DUAL
? 0 : MaxRays
);
287 check_poly_init(C
, &options
->verify
);
289 /******* CHECK NOW *********/
291 if (!options
->series
|| options
->function
) {
292 if (!check_poly_EP(S
, CS
, EP
, exist
, nparam
, 0, p
->p
,
296 skewed_gen_fun
*sgf
= new skewed_gen_fun(new gen_fun(gf
));
297 if (!check_poly_gf(S
, CS
, sgf
, exist
, nparam
, 0, p
->p
,
304 if (!options
->verify
.print_all
)