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 struct argp_option argp_options
[] = {
29 { "omega", 'o', 0, 0 },
31 { "series", 's', 0, 0 },
32 { "series", 's', 0, 0, "compute rational generating function" },
33 { "explicit", 'e', 0, 0, "convert rgf to psp" },
34 { "scarf", 'S', 0, 0 },
39 struct verify_options verify
;
40 struct convert_options convert
;
48 error_t
parse_opt(int key
, char *arg
, struct argp_state
*state
)
50 struct arguments
*arguments
= (struct arguments
*)(state
->input
);
54 state
->child_inputs
[0] = arguments
->verify
.barvinok
;
55 state
->child_inputs
[1] = &arguments
->verify
;
56 state
->child_inputs
[2] = &arguments
->convert
;
59 arguments
->function
= 1;
62 arguments
->series
= 1;
71 error(0, 0, "--omega option not supported");
78 return ARGP_ERR_UNKNOWN
;
85 Polyhedron
*Omega_simplify(Polyhedron
*P
,
86 unsigned exist
, unsigned nparam
, char **parms
)
90 Relation r
= Polyhedron2relation(P
, exist
, nparam
, parms
);
92 return relation2Domain(r
, varv
, paramv
);
95 Polyhedron
*Omega_simplify(Polyhedron
*P
,
96 unsigned exist
, unsigned nparam
, char **parms
)
102 static void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
103 int exist
, int nparam
,
106 int main(int argc
, char **argv
)
111 int exist
, nparam
, nvar
;
115 int print_solution
= 1;
116 struct arguments arguments
;
117 static struct argp_child argp_children
[] = {
118 { &barvinok_argp
, 0, 0, 0 },
119 { &verify_argp
, 0, "verification", BV_GRP_LAST
+1 },
120 { &convert_argp
, 0, "output conversion", BV_GRP_LAST
+2 },
123 static struct argp argp
= { argp_options
, parse_opt
, 0, 0, argp_children
};
124 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
126 arguments
.verify
.barvinok
= options
;
130 arguments
.series
= 0;
131 arguments
.function
= 0;
133 set_program_name(argv
[0]);
134 argp_parse(&argp
, argc
, argv
, 0, 0, &arguments
);
137 A
= Constraints2Polyhedron(MA
, options
->MaxRays
);
140 fgets(s
, 128, stdin
);
141 while ((*s
=='#') || (sscanf(s
, "E %d", &exist
)<1))
142 fgets(s
, 128, stdin
);
144 fgets(s
, 128, stdin
);
145 while ((*s
=='#') || (sscanf(s
, "P %d", &nparam
)<1))
146 fgets(s
, 128, stdin
);
148 /******* Read the options: initialize Min and Max ********/
150 if (arguments
.verify
.verify
) {
151 verify_options_set_range(&arguments
.verify
, A
->Dimension
);
152 if (!options
->verbose
)
156 if (print_solution
&& options
->verbose
) {
157 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
158 printf("exist: %d, nparam: %d\n", exist
, nparam
);
160 param_name
= Read_ParamNames(stdin
, nparam
);
161 nvar
= A
->Dimension
- exist
- nparam
;
162 if (arguments
.omega
) {
163 A
= Omega_simplify(A
, exist
, nparam
, param_name
);
165 exist
= A
->Dimension
- nvar
- nparam
;
167 if (arguments
.series
) {
169 gf
= barvinok_enumerate_scarf_series(A
, exist
, nparam
, options
);
171 gf
= barvinok_enumerate_e_series(A
, exist
, nparam
, options
);
172 if (print_solution
) {
173 gf
->print(std::cout
, nparam
, param_name
);
176 if (arguments
.function
) {
179 print_evalue(stdout
, EP
, param_name
);
183 EP
= barvinok_enumerate_scarf(A
, exist
, nparam
, options
);
184 else if (arguments
.pip
&& exist
> 0)
185 EP
= barvinok_enumerate_pip_with_options(A
, exist
, nparam
, options
);
187 EP
= barvinok_enumerate_e_with_options(A
, exist
, nparam
, options
);
189 if (evalue_convert(EP
, &arguments
.convert
, options
->verbose
, nparam
,
193 print_evalue(stdout
, EP
, param_name
);
195 if (arguments
.verify
.verify
) {
196 arguments
.verify
.params
= param_name
;
197 verify_results(A
, EP
, gf
, exist
, nparam
, &arguments
);
204 if (options
->print_stats
)
205 barvinok_stats_print(options
->stats
, stdout
);
207 Free_ParamNames(param_name
, nparam
);
209 barvinok_options_free(options
);
213 void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
214 int exist
, int nparam
,
222 unsigned MaxRays
= options
->verify
.barvinok
->MaxRays
;
223 Polyhedron
*C
= NULL
;
226 p
= Vector_Alloc(P
->Dimension
+2);
227 value_set_si(p
->p
[P
->Dimension
+1], 1);
229 CS
= check_poly_context_scan(P
, &C
, nparam
, &options
->verify
);
231 C
= Universe_Polyhedron(nparam
);
233 /* S = scanning list of polyhedra */
234 S
= Polyhedron_Scan(P
, C
, MaxRays
& POL_NO_DUAL
? 0 : MaxRays
);
236 check_poly_init(C
, &options
->verify
);
238 /******* CHECK NOW *********/
240 if (!options
->series
|| options
->function
) {
241 if (!check_poly_EP(S
, CS
, EP
, exist
, nparam
, 0, p
->p
,
245 skewed_gen_fun
*sgf
= new skewed_gen_fun(new gen_fun(gf
));
246 if (!check_poly_gf(S
, CS
, sgf
, exist
, nparam
, 0, p
->p
,
253 if (!options
->verify
.print_all
)