evalue_read.c: correct constness of name in parameter_new
[barvinok.git] / barvinok_union.cc
blob5280ffc8fbc42d8477de62044c228b1857b4416c
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 free_evalue_refs(EP);
93 free(EP);
95 Free_ParamNames(param_name, C->Dimension);
96 Domain_Free(D);
97 Polyhedron_Free(C);
98 barvinok_options_free(bv_options);
99 return 0;