4 #include <barvinok/util.h>
5 #include <barvinok/barvinok.h>
11 #include "omega_interface/convert.h"
12 #include "omega_interface/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
, const 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
, const char **parms
,
113 evalue
*barvinok_enumerate_parker(Polyhedron
*P
,
114 unsigned exist
, unsigned nparam
,
122 static void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
123 int exist
, int nparam
,
126 int main(int argc
, char **argv
)
130 const char **param_name
;
131 int exist
, nparam
, nvar
;
135 int print_solution
= 1;
136 struct arguments arguments
;
137 static struct argp_child argp_children
[] = {
138 { &barvinok_argp
, 0, 0, 0 },
139 { &verify_argp
, 0, "verification", BV_GRP_LAST
+1 },
140 { &convert_argp
, 0, "output conversion", BV_GRP_LAST
+2 },
143 static struct argp argp
= { argp_options
, parse_opt
, 0, 0, argp_children
};
144 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
146 arguments
.verify
.barvinok
= options
;
148 arguments
.parker
= 0;
151 arguments
.series
= 0;
152 arguments
.function
= 0;
154 set_program_name(argv
[0]);
155 argp_parse(&argp
, argc
, argv
, 0, 0, &arguments
);
158 A
= Constraints2Polyhedron(MA
, options
->MaxRays
);
161 fgets(s
, 128, stdin
);
162 while ((*s
=='#') || (sscanf(s
, "E %d", &exist
)<1))
163 fgets(s
, 128, stdin
);
165 fgets(s
, 128, stdin
);
166 while ((*s
=='#') || (sscanf(s
, "P %d", &nparam
)<1))
167 fgets(s
, 128, stdin
);
169 /******* Read the options: initialize Min and Max ********/
171 if (arguments
.verify
.verify
) {
172 verify_options_set_range(&arguments
.verify
, A
->Dimension
);
173 if (!options
->verbose
)
177 if (print_solution
&& options
->verbose
) {
178 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
179 printf("exist: %d, nparam: %d\n", exist
, nparam
);
181 param_name
= Read_ParamNames(stdin
, nparam
);
182 nvar
= A
->Dimension
- exist
- nparam
;
183 if (arguments
.omega
) {
184 A
= Omega_simplify(A
, exist
, nparam
, param_name
, options
->MaxRays
);
186 exist
= A
->Dimension
- nvar
- nparam
;
188 if (arguments
.series
) {
190 gf
= barvinok_enumerate_scarf_series(A
, exist
, nparam
, options
);
192 gf
= barvinok_enumerate_e_series(A
, exist
, nparam
, options
);
193 if (print_solution
) {
194 gf
->print(std::cout
, nparam
, param_name
);
197 if (arguments
.function
) {
200 print_evalue(stdout
, EP
, param_name
);
203 if (arguments
.parker
)
204 EP
= barvinok_enumerate_parker(A
, A
->Dimension
-nparam
-exist
,
205 nparam
, options
->MaxRays
);
206 else if (arguments
.scarf
)
207 EP
= barvinok_enumerate_scarf(A
, exist
, nparam
, options
);
208 else if (arguments
.pip
&& exist
> 0)
209 EP
= barvinok_enumerate_pip_with_options(A
, exist
, nparam
, options
);
211 EP
= barvinok_enumerate_e_with_options(A
, exist
, nparam
, options
);
213 if (evalue_convert(EP
, &arguments
.convert
, options
->verbose
, nparam
,
217 print_evalue(stdout
, EP
, param_name
);
219 if (arguments
.verify
.verify
) {
220 arguments
.verify
.params
= param_name
;
221 verify_results(A
, EP
, gf
, exist
, nparam
, &arguments
);
228 if (options
->print_stats
)
229 barvinok_stats_print(options
->stats
, stdout
);
231 Free_ParamNames(param_name
, nparam
);
233 barvinok_options_free(options
);
237 void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
238 int exist
, int nparam
,
246 unsigned MaxRays
= options
->verify
.barvinok
->MaxRays
;
247 Polyhedron
*C
= NULL
;
250 p
= Vector_Alloc(P
->Dimension
+2);
251 value_set_si(p
->p
[P
->Dimension
+1], 1);
253 CS
= check_poly_context_scan(P
, &C
, nparam
, &options
->verify
);
255 C
= Universe_Polyhedron(nparam
);
257 /* S = scanning list of polyhedra */
258 S
= Polyhedron_Scan(P
, C
, MaxRays
& POL_NO_DUAL
? 0 : MaxRays
);
260 check_poly_init(C
, &options
->verify
);
262 /******* CHECK NOW *********/
264 if (!options
->series
|| options
->function
) {
265 if (!check_poly_EP(S
, CS
, EP
, exist
, nparam
, 0, p
->p
,
269 skewed_gen_fun
*sgf
= new skewed_gen_fun(new gen_fun(gf
));
270 if (!check_poly_gf(S
, CS
, sgf
, exist
, nparam
, 0, p
->p
,
277 if (!options
->verify
.print_all
)