5 #include <barvinok/polylib.h>
6 #include <barvinok/util.h>
7 #include <barvinok/barvinok.h>
9 #include "skewed_genfun.h"
11 #include "verif_ehrhart.h"
12 #include "verify_series.h"
13 #include "evalue_convert.h"
14 #include "barvinok_enumerate_e_options.h"
16 /* The input of this example program is a polytope in combined
17 * data and parameter space followed by two lines indicating
18 * the number of existential variables and parameters respectively.
19 * The first lines starts with "E ", followed by a number.
20 * The second lines starts with "P ", followed by a number.
21 * These two lines are (optionally) followed by the names of the parameters.
22 * The polytope is in PolyLib notation.
25 static void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
26 int exist
, int nparam
,
27 enumerate_e_options
*options
);
29 static char *next_line(FILE *input
, char *line
, unsigned len
)
34 if (!(p
= fgets(line
, len
, input
)))
36 while (isspace(*p
) && *p
!= '\n')
38 } while (*p
== '#' || *p
== '\n');
43 int main(int argc
, char **argv
)
47 const char **param_name
;
52 int print_solution
= 1;
53 struct enumerate_e_options
*options
= enumerate_e_options_new_with_defaults();
55 argc
= enumerate_e_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
58 A
= Constraints2Polyhedron(MA
, options
->verify
->barvinok
->MaxRays
);
62 while (next_line(stdin
, s
, sizeof(s
)))
63 if (sscanf(s
, "E %d", &exist
) == 1)
68 while (next_line(stdin
, s
, sizeof(s
)))
69 if (sscanf(s
, "P %d", &nparam
) == 1)
73 if (options
->verify
->verify
) {
74 verify_options_set_range(options
->verify
, A
->Dimension
);
75 if (!options
->verify
->barvinok
->verbose
)
79 if (print_solution
&& options
->verify
->barvinok
->verbose
) {
80 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
81 printf("exist: %d, nparam: %d\n", exist
, nparam
);
83 param_name
= Read_ParamNames(stdin
, nparam
);
84 if (options
->series
) {
85 if (exist
== 2 && options
->scarf
)
86 gf
= barvinok_enumerate_scarf_series(A
, exist
, nparam
,
87 options
->verify
->barvinok
);
89 gf
= barvinok_enumerate_e_series(A
, exist
, nparam
,
90 options
->verify
->barvinok
);
92 gf
->print(std::cout
, nparam
, param_name
);
95 if (options
->function
) {
98 print_evalue(stdout
, EP
, param_name
);
101 if (exist
== 2 && options
->scarf
)
102 EP
= barvinok_enumerate_scarf(A
, exist
, nparam
,
103 options
->verify
->barvinok
);
104 else if (options
->isl
&& exist
> 0)
105 EP
= barvinok_enumerate_isl(A
, exist
, nparam
,
106 options
->verify
->barvinok
);
108 EP
= barvinok_enumerate_e_with_options(A
, exist
, nparam
,
109 options
->verify
->barvinok
);
111 if (evalue_convert(EP
, options
->convert
,
112 options
->verify
->barvinok
->verbose
, nparam
, param_name
))
115 print_evalue(stdout
, EP
, param_name
);
117 if (options
->verify
->verify
) {
118 options
->verify
->params
= param_name
;
119 verify_results(A
, EP
, gf
, exist
, nparam
, options
);
126 if (options
->verify
->barvinok
->print_stats
)
127 barvinok_stats_print(options
->verify
->barvinok
->stats
, stdout
);
129 Free_ParamNames(param_name
, nparam
);
131 enumerate_e_options_free(options
);
135 void verify_results(Polyhedron
*P
, evalue
*EP
, gen_fun
*gf
,
136 int exist
, int nparam
,
137 enumerate_e_options
*options
)
143 unsigned MaxRays
= options
->verify
->barvinok
->MaxRays
;
144 Polyhedron
*C
= NULL
;
147 p
= Vector_Alloc(P
->Dimension
+2);
148 value_set_si(p
->p
[P
->Dimension
+1], 1);
150 CS
= check_poly_context_scan(P
, &C
, nparam
, options
->verify
);
152 C
= Universe_Polyhedron(nparam
);
154 /* S = scanning list of polyhedra */
155 S
= Polyhedron_Scan(P
, C
, MaxRays
& POL_NO_DUAL
? 0 : MaxRays
);
157 check_poly_init(C
, options
->verify
);
159 /******* CHECK NOW *********/
161 if (!options
->series
|| options
->function
) {
162 if (!check_poly_EP(S
, CS
, EP
, exist
, nparam
, 0, p
->p
,
166 skewed_gen_fun
*sgf
= new skewed_gen_fun(new gen_fun(gf
));
167 if (!check_poly_gf(S
, CS
, sgf
, exist
, nparam
, 0, p
->p
,
174 if (!options
->verify
->print_all
)