4 #include <barvinok/util.h>
5 #include <barvinok/barvinok.h>
11 #include "omega/convert.h"
14 #include "verif_ehrhart.h"
15 #include "evalue_convert.h"
17 /* The input of this example program is a polytope in combined
18 * data and parameter space followed by two lines indicating
19 * the number of existential variables and parameters respectively.
20 * The first lines starts with "E ", followed by a number.
21 * The second lines starts with "P ", followed by a number.
22 * These two lines are (optionally) followed by the names of the parameters.
23 * The polytope is in PolyLib notation.
26 struct argp_option argp_options
[] = {
27 { "omega", 'o', 0, 0 },
29 { "series", 's', 0, 0 },
30 { "scarf", 'S', 0, 0 },
36 struct verify_options verify
;
37 struct convert_options convert
;
45 error_t
parse_opt(int key
, char *arg
, struct argp_state
*state
)
47 struct arguments
*arguments
= (struct arguments
*)(state
->input
);
51 state
->child_inputs
[0] = arguments
->verify
.barvinok
;
52 state
->child_inputs
[1] = &arguments
->verify
;
53 state
->child_inputs
[2] = &arguments
->convert
;
56 arguments
->series
= 1;
65 error(0, 0, "--omega option not supported");
72 arguments
->verbose
= 1;
75 return ARGP_ERR_UNKNOWN
;
82 Polyhedron
*Omega_simplify(Polyhedron
*P
,
83 unsigned exist
, unsigned nparam
, char **parms
)
87 Relation r
= Polyhedron2relation(P
, exist
, nparam
, parms
);
89 return relation2Domain(r
, varv
, paramv
);
92 Polyhedron
*Omega_simplify(Polyhedron
*P
,
93 unsigned exist
, unsigned nparam
, char **parms
)
99 static void verify_results(Polyhedron
*P
, evalue
*EP
, int exist
, int nparam
,
100 verify_options
*options
);
102 int main(int argc
, char **argv
)
107 int exist
, nparam
, nvar
;
110 int print_solution
= 1;
111 struct arguments arguments
;
112 static struct argp_child argp_children
[] = {
113 { &barvinok_argp
, 0, 0, 0 },
114 { &verify_argp
, 0, "verification", BV_GRP_LAST
+1 },
115 { &convert_argp
, 0, "output conversion", BV_GRP_LAST
+2 },
118 static struct argp argp
= { argp_options
, parse_opt
, 0, 0, argp_children
};
119 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
121 arguments
.verify
.barvinok
= options
;
125 arguments
.series
= 0;
126 arguments
.verbose
= 0;
128 set_program_name(argv
[0]);
129 argp_parse(&argp
, argc
, argv
, 0, 0, &arguments
);
131 if (arguments
.series
&& !arguments
.scarf
) {
133 "--series currently only available if --scarf is specified\n");
138 A
= Constraints2Polyhedron(MA
, options
->MaxRays
);
141 fgets(s
, 128, stdin
);
142 while ((*s
=='#') || (sscanf(s
, "E %d", &exist
)<1))
143 fgets(s
, 128, stdin
);
145 fgets(s
, 128, stdin
);
146 while ((*s
=='#') || (sscanf(s
, "P %d", &nparam
)<1))
147 fgets(s
, 128, stdin
);
149 /******* Read the options: initialize Min and Max ********/
151 if (arguments
.verify
.verify
) {
152 verify_options_set_range(&arguments
.verify
, A
->Dimension
);
153 if (!arguments
.verbose
)
157 if (print_solution
&& arguments
.verbose
) {
158 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
159 printf("exist: %d, nparam: %d\n", exist
, nparam
);
161 param_name
= Read_ParamNames(stdin
, nparam
);
162 nvar
= A
->Dimension
- exist
- nparam
;
163 if (arguments
.omega
) {
164 A
= Omega_simplify(A
, exist
, nparam
, param_name
);
166 exist
= A
->Dimension
- nvar
- nparam
;
168 if (arguments
.series
) {
170 assert(arguments
.scarf
);
171 gf
= barvinok_enumerate_scarf_series(A
, exist
, nparam
, options
);
172 if (print_solution
) {
173 gf
->print(std::cout
, nparam
, param_name
);
179 EP
= barvinok_enumerate_scarf(A
, exist
, nparam
, options
);
180 else if (arguments
.pip
&& exist
> 0)
181 EP
= barvinok_enumerate_pip_with_options(A
, exist
, nparam
, options
);
183 EP
= barvinok_enumerate_e_with_options(A
, exist
, nparam
, options
);
185 if (evalue_convert(EP
, &arguments
.convert
, arguments
.verbose
, nparam
,
189 print_evalue(stdout
, EP
, param_name
);
190 if (arguments
.verify
.verify
) {
191 arguments
.verify
.params
= param_name
;
192 verify_results(A
, EP
, exist
, nparam
, &arguments
.verify
);
194 free_evalue_refs(EP
);
197 Free_ParamNames(param_name
, nparam
);
199 barvinok_options_free(options
);
203 void verify_results(Polyhedron
*P
, evalue
*EP
, int exist
, int nparam
,
204 verify_options
*options
)
210 unsigned MaxRays
= options
->barvinok
->MaxRays
;
211 Polyhedron
*C
= NULL
;
214 p
= (Value
*)malloc(sizeof(Value
) * (P
->Dimension
+2));
215 for(i
=0;i
<=P
->Dimension
;i
++) {
217 value_set_si(p
[i
],0);
220 value_set_si(p
[i
],1);
222 CS
= check_poly_context_scan(P
, &C
, nparam
, options
);
224 /* S = scanning list of polyhedra */
225 S
= Polyhedron_Scan(P
, C
, MaxRays
& POL_NO_DUAL
? 0 : MaxRays
);
227 check_poly_init(C
, options
);
229 /******* CHECK NOW *********/
231 if (S
&& !check_poly_EP(S
, CS
, EP
, exist
, nparam
, 0, p
, options
)) {
232 fprintf(stderr
,"Check failed !\n");
236 if (!options
->print_all
)
239 for(i
=0;i
<=(P
->Dimension
+1);i
++)