lattice_point.cc: add ceiling function
[barvinok/uuh.git] / barvinok_union.cc
blob3d737e23121138eb07ed6ba3d0141afba4ca1ff7
1 #include <barvinok/barvinok.h>
2 #include <barvinok/util.h>
3 #include "argp.h"
4 #include "progname.h"
6 /* The input of this example program is similar to that of ehrhart_union
7 * in the PolyLib distribution, the difference being that the number of
8 * polytopes in the union needs to be specified explicitly.
9 * The input starts with this number, followed by this number of
10 * polytopes in combined data and parameter space, a context polytope
11 * in parameter space and (optionally) the names of the parameters.
12 * All polytopes are in PolyLib notation.
15 struct argp_option argp_options[] = {
16 { "series", 's', 0, 0, "compute rational generating function" },
17 { 0 }
20 struct arguments {
21 int series;
22 struct barvinok_options *barvinok;
25 static error_t parse_opt(int key, char *arg, struct argp_state *state)
27 struct arguments *options = (struct arguments*) state->input;
29 switch (key) {
30 case ARGP_KEY_INIT:
31 state->child_inputs[0] = options->barvinok;
32 options->series = 0;
33 break;
34 case 's':
35 options->series = 1;
36 break;
37 default:
38 return ARGP_ERR_UNKNOWN;
40 return 0;
44 int main(int argc, char **argv)
46 Matrix *M;
47 Polyhedron *C, *D = NULL;
48 int i, npol;
49 char **param_name;
50 char s[128];
51 int c, ind = 0;
52 int series = 0;
53 struct arguments options;
54 static struct argp_child argp_children[] = {
55 { &barvinok_argp, 0, 0, 0 },
56 { 0 }
58 static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children };
59 struct barvinok_options *bv_options = barvinok_options_new_with_defaults();
61 options.barvinok = bv_options;
62 set_program_name(argv[0]);
63 argp_parse(&argp, argc, argv, 0, 0, &options);
65 fgets(s, 128, stdin);
66 while ((*s=='#') || (sscanf(s, "%d", &npol)<1))
67 fgets(s, 128, stdin);
69 for (i = 0; i < npol; ++i) {
70 Polyhedron *P;
71 M = Matrix_Read();
72 P = Constraints2Polyhedron(M, bv_options->MaxRays);
73 Matrix_Free(M);
74 D = DomainConcat(P, D);
76 M = Matrix_Read();
77 C = Constraints2Polyhedron(M, bv_options->MaxRays);
78 Matrix_Free(M);
79 Polyhedron_Print(stdout, P_VALUE_FMT, D);
80 Polyhedron_Print(stdout, P_VALUE_FMT, C);
81 param_name = Read_ParamNames(stdin, C->Dimension);
82 if (series) {
83 gen_fun *gf;
84 gf = barvinok_enumerate_union_series(D, C, bv_options->MaxRays);
85 gf->print(std::cout, C->Dimension, param_name);
86 puts("");
87 delete gf;
88 } else {
89 evalue *EP;
90 EP = barvinok_enumerate_union(D, C, bv_options->MaxRays);
91 print_evalue(stdout, EP, param_name);
92 evalue_free(EP);
94 Free_ParamNames(param_name, C->Dimension);
95 Domain_Free(D);
96 Polyhedron_Free(C);
97 barvinok_options_free(bv_options);
98 return 0;