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 },
37 { "print-stats", PRINT_STATS
, 0, 0 },
42 struct verify_options verify
;
43 struct convert_options convert
;
52 error_t
parse_opt(int key
, char *arg
, struct argp_state
*state
)
54 struct arguments
*arguments
= (struct arguments
*)(state
->input
);
58 state
->child_inputs
[0] = arguments
->verify
.barvinok
;
59 state
->child_inputs
[1] = &arguments
->verify
;
60 state
->child_inputs
[2] = &arguments
->convert
;
63 arguments
->print_stats
= 1;
66 arguments
->function
= 1;
69 arguments
->series
= 1;
78 error(0, 0, "--omega option not supported");
85 return ARGP_ERR_UNKNOWN
;
92 Polyhedron
*Omega_simplify(Polyhedron
*P
,
93 unsigned exist
, unsigned nparam
, char **parms
)
97 Relation r
= Polyhedron2relation(P
, exist
, nparam
, parms
);
99 return relation2Domain(r
, varv
, paramv
);
102 Polyhedron
*Omega_simplify(Polyhedron
*P
,
103 unsigned exist
, unsigned nparam
, char **parms
)
109 static void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
110 int exist
, int nparam
,
113 int main(int argc
, char **argv
)
118 int exist
, nparam
, nvar
;
122 int print_solution
= 1;
123 struct arguments arguments
;
124 static struct argp_child argp_children
[] = {
125 { &barvinok_argp
, 0, 0, 0 },
126 { &verify_argp
, 0, "verification", BV_GRP_LAST
+1 },
127 { &convert_argp
, 0, "output conversion", BV_GRP_LAST
+2 },
130 static struct argp argp
= { argp_options
, parse_opt
, 0, 0, argp_children
};
131 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
133 arguments
.verify
.barvinok
= options
;
137 arguments
.series
= 0;
138 arguments
.function
= 0;
139 arguments
.print_stats
= 0;
141 set_program_name(argv
[0]);
142 argp_parse(&argp
, argc
, argv
, 0, 0, &arguments
);
144 if (arguments
.series
&& !arguments
.scarf
) {
146 "--series currently only available if --scarf is specified\n");
151 A
= Constraints2Polyhedron(MA
, options
->MaxRays
);
154 fgets(s
, 128, stdin
);
155 while ((*s
=='#') || (sscanf(s
, "E %d", &exist
)<1))
156 fgets(s
, 128, stdin
);
158 fgets(s
, 128, stdin
);
159 while ((*s
=='#') || (sscanf(s
, "P %d", &nparam
)<1))
160 fgets(s
, 128, stdin
);
162 /******* Read the options: initialize Min and Max ********/
164 if (arguments
.verify
.verify
) {
165 verify_options_set_range(&arguments
.verify
, A
->Dimension
);
166 if (!options
->verbose
)
170 if (print_solution
&& options
->verbose
) {
171 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
172 printf("exist: %d, nparam: %d\n", exist
, nparam
);
174 param_name
= Read_ParamNames(stdin
, nparam
);
175 nvar
= A
->Dimension
- exist
- nparam
;
176 if (arguments
.omega
) {
177 A
= Omega_simplify(A
, exist
, nparam
, param_name
);
179 exist
= A
->Dimension
- nvar
- nparam
;
181 if (arguments
.series
) {
182 assert(arguments
.scarf
);
183 gf
= barvinok_enumerate_scarf_series(A
, exist
, nparam
, options
);
184 if (print_solution
) {
185 gf
->print(std::cout
, nparam
, param_name
);
188 if (arguments
.function
) {
191 print_evalue(stdout
, EP
, param_name
);
195 EP
= barvinok_enumerate_scarf(A
, exist
, nparam
, options
);
196 else if (arguments
.pip
&& exist
> 0)
197 EP
= barvinok_enumerate_pip_with_options(A
, exist
, nparam
, options
);
199 EP
= barvinok_enumerate_e_with_options(A
, exist
, nparam
, options
);
201 if (evalue_convert(EP
, &arguments
.convert
, options
->verbose
, nparam
,
205 print_evalue(stdout
, EP
, param_name
);
207 if (arguments
.verify
.verify
) {
208 arguments
.verify
.params
= param_name
;
209 verify_results(A
, EP
, gf
, exist
, nparam
, &arguments
);
216 if (arguments
.print_stats
)
217 barvinok_stats_print(options
->stats
, stdout
);
219 Free_ParamNames(param_name
, nparam
);
221 barvinok_options_free(options
);
225 void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
226 int exist
, int nparam
,
234 unsigned MaxRays
= options
->verify
.barvinok
->MaxRays
;
235 Polyhedron
*C
= NULL
;
238 p
= Vector_Alloc(P
->Dimension
+2);
239 value_set_si(p
->p
[P
->Dimension
+1], 1);
241 CS
= check_poly_context_scan(P
, &C
, nparam
, &options
->verify
);
243 C
= Universe_Polyhedron(nparam
);
245 /* S = scanning list of polyhedra */
246 S
= Polyhedron_Scan(P
, C
, MaxRays
& POL_NO_DUAL
? 0 : MaxRays
);
248 check_poly_init(C
, &options
->verify
);
250 /******* CHECK NOW *********/
252 if (!options
->series
|| options
->function
) {
253 if (!check_poly_EP(S
, CS
, EP
, exist
, nparam
, 0, p
->p
,
257 skewed_gen_fun
*sgf
= new skewed_gen_fun(new gen_fun(gf
));
258 if (!check_poly_gf(S
, CS
, sgf
, exist
, nparam
, 0, p
->p
,
265 if (!options
->verify
.print_all
)