5 #include <barvinok/util.h>
6 #include <barvinok/barvinok.h>
9 #include "omega_interface/convert.h"
10 #include "omega_interface/count.h"
12 #include "skewed_genfun.h"
14 #include "verif_ehrhart.h"
15 #include "verify_series.h"
16 #include "evalue_convert.h"
17 #include "barvinok_enumerate_e_options.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.
30 Polyhedron
*Omega_simplify(Polyhedron
*P
,
31 unsigned exist
, unsigned nparam
, const char **parms
,
36 Relation r
= Polyhedron2relation(P
, exist
, nparam
, parms
);
38 return relation2Domain(r
, varv
, paramv
, MaxRays
);
41 Polyhedron
*Omega_simplify(Polyhedron
*P
,
42 unsigned exist
, unsigned nparam
, const char **parms
,
48 evalue
*barvinok_enumerate_parker(Polyhedron
*P
,
49 unsigned exist
, unsigned nparam
,
57 static void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
58 int exist
, int nparam
,
59 enumerate_e_options
*options
);
61 static char *next_line(FILE *input
, char *line
, unsigned len
)
66 if (!(p
= fgets(line
, len
, input
)))
68 while (isspace(*p
) && *p
!= '\n')
70 } while (*p
== '#' || *p
== '\n');
75 int main(int argc
, char **argv
)
79 const char **param_name
;
80 int exist
, nparam
, nvar
;
84 int print_solution
= 1;
85 struct enumerate_e_options
*options
= enumerate_e_options_new_with_defaults();
87 argc
= enumerate_e_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
90 A
= Constraints2Polyhedron(MA
, options
->verify
->barvinok
->MaxRays
);
94 while (next_line(stdin
, s
, sizeof(s
)))
95 if (sscanf(s
, "E %d", &exist
) == 1)
100 while (next_line(stdin
, s
, sizeof(s
)))
101 if (sscanf(s
, "P %d", &nparam
) == 1)
105 /******* Read the options: initialize Min and Max ********/
107 if (options
->verify
->verify
) {
108 verify_options_set_range(options
->verify
, A
->Dimension
);
109 if (!options
->verify
->barvinok
->verbose
)
113 if (print_solution
&& options
->verify
->barvinok
->verbose
) {
114 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
115 printf("exist: %d, nparam: %d\n", exist
, nparam
);
117 param_name
= Read_ParamNames(stdin
, nparam
);
118 nvar
= A
->Dimension
- exist
- nparam
;
119 if (options
->omega
) {
120 A
= Omega_simplify(A
, exist
, nparam
, param_name
,
121 options
->verify
->barvinok
->MaxRays
);
123 exist
= A
->Dimension
- nvar
- nparam
;
125 if (options
->series
) {
127 gf
= barvinok_enumerate_scarf_series(A
, exist
, nparam
,
128 options
->verify
->barvinok
);
130 gf
= barvinok_enumerate_e_series(A
, exist
, nparam
,
131 options
->verify
->barvinok
);
132 if (print_solution
) {
133 gf
->print(std::cout
, nparam
, param_name
);
136 if (options
->function
) {
139 print_evalue(stdout
, EP
, param_name
);
143 EP
= barvinok_enumerate_parker(A
, A
->Dimension
-nparam
-exist
, nparam
,
144 options
->verify
->barvinok
->MaxRays
);
145 else if (options
->scarf
)
146 EP
= barvinok_enumerate_scarf(A
, exist
, nparam
,
147 options
->verify
->barvinok
);
148 else if (options
->isl
&& exist
> 0)
149 EP
= barvinok_enumerate_isl(A
, exist
, nparam
,
150 options
->verify
->barvinok
);
152 EP
= barvinok_enumerate_e_with_options(A
, exist
, nparam
,
153 options
->verify
->barvinok
);
155 if (evalue_convert(EP
, options
->convert
,
156 options
->verify
->barvinok
->verbose
, nparam
, param_name
))
159 print_evalue(stdout
, EP
, param_name
);
161 if (options
->verify
->verify
) {
162 options
->verify
->params
= param_name
;
163 verify_results(A
, EP
, gf
, exist
, nparam
, options
);
170 if (options
->verify
->barvinok
->print_stats
)
171 barvinok_stats_print(options
->verify
->barvinok
->stats
, stdout
);
173 Free_ParamNames(param_name
, nparam
);
175 enumerate_e_options_free(options
);
179 void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
180 int exist
, int nparam
,
181 enumerate_e_options
*options
)
188 unsigned MaxRays
= options
->verify
->barvinok
->MaxRays
;
189 Polyhedron
*C
= NULL
;
192 p
= Vector_Alloc(P
->Dimension
+2);
193 value_set_si(p
->p
[P
->Dimension
+1], 1);
195 CS
= check_poly_context_scan(P
, &C
, nparam
, options
->verify
);
197 C
= Universe_Polyhedron(nparam
);
199 /* S = scanning list of polyhedra */
200 S
= Polyhedron_Scan(P
, C
, MaxRays
& POL_NO_DUAL
? 0 : MaxRays
);
202 check_poly_init(C
, options
->verify
);
204 /******* CHECK NOW *********/
206 if (!options
->series
|| options
->function
) {
207 if (!check_poly_EP(S
, CS
, EP
, exist
, nparam
, 0, p
->p
,
211 skewed_gen_fun
*sgf
= new skewed_gen_fun(new gen_fun(gf
));
212 if (!check_poly_gf(S
, CS
, sgf
, exist
, nparam
, 0, p
->p
,
219 if (!options
->verify
->print_all
)