5 #include <barvinok/polylib.h>
6 #include <barvinok/util.h>
7 #include <barvinok/barvinok.h>
10 #include "omega_interface/convert.h"
11 #include "omega_interface/count.h"
13 #include "skewed_genfun.h"
15 #include "verif_ehrhart.h"
16 #include "verify_series.h"
17 #include "evalue_convert.h"
18 #include "barvinok_enumerate_e_options.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.
31 Polyhedron
*Omega_simplify(Polyhedron
*P
,
32 unsigned exist
, unsigned nparam
, const char **parms
,
37 Relation r
= Polyhedron2relation(P
, exist
, nparam
, parms
);
39 return relation2Domain(r
, varv
, paramv
, MaxRays
);
42 Polyhedron
*Omega_simplify(Polyhedron
*P
,
43 unsigned exist
, unsigned nparam
, const char **parms
,
49 evalue
*barvinok_enumerate_parker(Polyhedron
*P
,
50 unsigned exist
, unsigned nparam
,
58 static void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
59 int exist
, int nparam
,
60 enumerate_e_options
*options
);
62 static char *next_line(FILE *input
, char *line
, unsigned len
)
67 if (!(p
= fgets(line
, len
, input
)))
69 while (isspace(*p
) && *p
!= '\n')
71 } while (*p
== '#' || *p
== '\n');
76 int main(int argc
, char **argv
)
80 const char **param_name
;
81 int exist
, nparam
, nvar
;
85 int print_solution
= 1;
86 struct enumerate_e_options
*options
= enumerate_e_options_new_with_defaults();
88 argc
= enumerate_e_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
91 A
= Constraints2Polyhedron(MA
, options
->verify
->barvinok
->MaxRays
);
95 while (next_line(stdin
, s
, sizeof(s
)))
96 if (sscanf(s
, "E %d", &exist
) == 1)
101 while (next_line(stdin
, s
, sizeof(s
)))
102 if (sscanf(s
, "P %d", &nparam
) == 1)
106 if (options
->verify
->verify
) {
107 verify_options_set_range(options
->verify
, A
->Dimension
);
108 if (!options
->verify
->barvinok
->verbose
)
112 if (print_solution
&& options
->verify
->barvinok
->verbose
) {
113 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
114 printf("exist: %d, nparam: %d\n", exist
, nparam
);
116 param_name
= Read_ParamNames(stdin
, nparam
);
117 nvar
= A
->Dimension
- exist
- nparam
;
118 if (options
->omega
) {
119 A
= Omega_simplify(A
, exist
, nparam
, param_name
,
120 options
->verify
->barvinok
->MaxRays
);
122 exist
= A
->Dimension
- nvar
- nparam
;
124 if (options
->series
) {
125 if (exist
== 2 && options
->scarf
)
126 gf
= barvinok_enumerate_scarf_series(A
, exist
, nparam
,
127 options
->verify
->barvinok
);
129 gf
= barvinok_enumerate_e_series(A
, exist
, nparam
,
130 options
->verify
->barvinok
);
131 if (print_solution
) {
132 gf
->print(std::cout
, nparam
, param_name
);
135 if (options
->function
) {
138 print_evalue(stdout
, EP
, param_name
);
142 EP
= barvinok_enumerate_parker(A
, A
->Dimension
-nparam
-exist
, nparam
,
143 options
->verify
->barvinok
->MaxRays
);
144 else if (exist
== 2 && options
->scarf
)
145 EP
= barvinok_enumerate_scarf(A
, exist
, nparam
,
146 options
->verify
->barvinok
);
147 else if (options
->isl
&& exist
> 0)
148 EP
= barvinok_enumerate_isl(A
, exist
, nparam
,
149 options
->verify
->barvinok
);
151 EP
= barvinok_enumerate_e_with_options(A
, exist
, nparam
,
152 options
->verify
->barvinok
);
154 if (evalue_convert(EP
, options
->convert
,
155 options
->verify
->barvinok
->verbose
, nparam
, param_name
))
158 print_evalue(stdout
, EP
, param_name
);
160 if (options
->verify
->verify
) {
161 options
->verify
->params
= param_name
;
162 verify_results(A
, EP
, gf
, exist
, nparam
, options
);
169 if (options
->verify
->barvinok
->print_stats
)
170 barvinok_stats_print(options
->verify
->barvinok
->stats
, stdout
);
172 Free_ParamNames(param_name
, nparam
);
174 enumerate_e_options_free(options
);
178 void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
179 int exist
, int nparam
,
180 enumerate_e_options
*options
)
186 unsigned MaxRays
= options
->verify
->barvinok
->MaxRays
;
187 Polyhedron
*C
= NULL
;
190 p
= Vector_Alloc(P
->Dimension
+2);
191 value_set_si(p
->p
[P
->Dimension
+1], 1);
193 CS
= check_poly_context_scan(P
, &C
, nparam
, options
->verify
);
195 C
= Universe_Polyhedron(nparam
);
197 /* S = scanning list of polyhedra */
198 S
= Polyhedron_Scan(P
, C
, MaxRays
& POL_NO_DUAL
? 0 : MaxRays
);
200 check_poly_init(C
, options
->verify
);
202 /******* CHECK NOW *********/
204 if (!options
->series
|| options
->function
) {
205 if (!check_poly_EP(S
, CS
, EP
, exist
, nparam
, 0, p
->p
,
209 skewed_gen_fun
*sgf
= new skewed_gen_fun(new gen_fun(gf
));
210 if (!check_poly_gf(S
, CS
, sgf
, exist
, nparam
, 0, p
->p
,
217 if (!options
->verify
->print_all
)