4 #include <isl/polynomial.h>
5 #include <barvinok/barvinok.h>
6 #include <barvinok/util.h>
7 #include "barvinok_union_options.h"
9 /* The input of this example program is similar to that of ehrhart_union
10 * in the PolyLib distribution, the difference being that the number of
11 * polytopes in the union needs to be specified explicitly.
12 * The input starts with this number, followed by this number of
13 * polytopes in combined data and parameter space, a context polytope
14 * in parameter space and (optionally) the names of the parameters.
15 * All polytopes are in PolyLib notation.
19 /* Convert "EP" into an isl_pw_qpolynomial with "nparam" parameter names
20 * specified by "names".
22 static __isl_give isl_pw_qpolynomial
*evalue2pwqp(isl_ctx
*ctx
, evalue
*EP
,
23 unsigned nparam
, const char **names
)
28 space
= isl_space_params_alloc(ctx
, nparam
);
29 for (i
= 0; i
< nparam
; ++i
)
30 space
= isl_space_set_dim_name(space
,
31 isl_dim_param
, i
, names
[i
]);
32 return isl_pw_qpolynomial_from_evalue(space
, EP
);
35 /* Check that "pwqp" is equal to the piecewise quasi-polynomial
36 * that appears next on stdin.
38 static isl_stat
check_result(__isl_keep isl_pw_qpolynomial
*pwqp
)
42 isl_pw_qpolynomial
*exp
;
45 return isl_stat_error
;
46 ctx
= isl_pw_qpolynomial_get_ctx(pwqp
);
48 exp
= isl_pw_qpolynomial_read_from_file(ctx
, stdin
);
49 exp
= isl_pw_qpolynomial_sub(exp
, isl_pw_qpolynomial_copy(pwqp
));
50 equal
= isl_pw_qpolynomial_is_zero(exp
);
51 isl_pw_qpolynomial_free(exp
);
54 return isl_stat_error
;
56 isl_die(ctx
, isl_error_unknown
,
57 "unexpected result", return isl_stat_error
);
62 int main(int argc
, char **argv
)
66 Polyhedron
*C
, *D
= NULL
;
68 const char **param_name
;
72 struct union_options
*options
= union_options_new_with_defaults();
74 argc
= union_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
75 ctx
= isl_ctx_alloc_with_options(&union_options_args
, options
);
77 check
= options
->check
&& !options
->series
;
80 while ((*s
=='#') || (sscanf(s
, "%d", &npol
)<1))
83 for (i
= 0; i
< npol
; ++i
) {
86 P
= Constraints2Polyhedron(M
, options
->barvinok
->MaxRays
);
88 D
= DomainConcat(P
, D
);
91 C
= Constraints2Polyhedron(M
, options
->barvinok
->MaxRays
);
94 Polyhedron_Print(stdout
, P_VALUE_FMT
, D
);
95 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
97 param_name
= Read_ParamNames(stdin
, C
->Dimension
);
98 if (options
->series
) {
100 gf
= barvinok_enumerate_union_series(D
, C
, options
->barvinok
->MaxRays
);
101 gf
->print(std::cout
, C
->Dimension
, param_name
);
106 EP
= barvinok_enumerate_union(D
, C
, options
->barvinok
->MaxRays
);
108 isl_pw_qpolynomial
*pwqp
;
109 pwqp
= evalue2pwqp(ctx
, EP
, C
->Dimension
, param_name
);
110 if (check_result(pwqp
) < 0)
112 isl_pw_qpolynomial_free(pwqp
);
114 print_evalue(stdout
, EP
, param_name
);
118 Free_ParamNames(param_name
, C
->Dimension
);