4 #include <barvinok/util.h>
5 #include <barvinok/barvinok.h>
8 #include "evalue_convert.h"
10 /* The input of this example program is a polytope in PolyLib notation,
11 * i.e., an n by d+2 matrix of the n constraints A x + b >= 0 defining
12 * the polytope * sitting in a d-dimensional space. The first column
13 * is 1 for an inequality and 0 for an equality. b is placed in the
15 * Alternatively, if the matrix is preceded by the word "vertices"
16 * on a line by itself, it will be interpreted as a list of vertices
17 * in PolyLib notation, i.e., an n by (d+2) matrix, where n is
18 * the number of vertices/rays and d the dimension. The first column is
19 * 0 for lines and 1 for vertices/rays. The final column is the denominator
20 * or 0 for rays. Note that for barvinok_ehrhart, the first column
24 struct argp_option argp_options
[] = {
25 { "series", 's', 0, 0, "compute rational generating function" },
31 struct barvinok_options
*barvinok
;
32 struct convert_options convert
;
35 static error_t
parse_opt(int key
, char *arg
, struct argp_state
*state
)
37 struct arguments
*options
= (struct arguments
*) state
->input
;
41 state
->child_inputs
[0] = options
->barvinok
;
42 state
->child_inputs
[1] = &options
->convert
;
49 return ARGP_ERR_UNKNOWN
;
54 int main(int argc
, char **argv
)
56 Polyhedron
*A
, *C
, *U
;
57 const char **param_name
;
58 int print_solution
= 1;
59 struct arguments options
;
60 static struct argp_child argp_children
[] = {
61 { &barvinok_argp
, 0, 0, 0 },
62 { &convert_argp
, 0, "output conversion", BV_GRP_LAST
+1 },
65 static struct argp argp
= { argp_options
, parse_opt
, 0, 0, argp_children
};
66 barvinok_options
*bv_options
= barvinok_options_new_with_defaults();
68 options
.barvinok
= bv_options
;
69 set_program_name(argv
[0]);
70 argp_parse(&argp
, argc
, argv
, 0, 0, &options
);
72 A
= Polyhedron_Read(bv_options
->MaxRays
);
73 param_name
= Read_ParamNames(stdin
, 1);
74 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
75 C
= Cone_over_Polyhedron(A
);
76 U
= Universe_Polyhedron(1);
79 gf
= barvinok_series_with_options(C
, U
, bv_options
);
80 gf
->print(std::cout
, U
->Dimension
, param_name
);
85 /* A (conceptually) obvious optimization would be to pass in
86 * the parametric vertices, which are just n times the original
87 * vertices, rather than letting barvinok_enumerate_ev (re)compute
88 * them through Polyhedron2Param_SimplifiedDomain.
90 EP
= barvinok_enumerate_with_options(C
, U
, bv_options
);
92 if (evalue_convert(EP
, &options
.convert
, bv_options
->verbose
,
93 C
->Dimension
, param_name
))
96 print_evalue(stdout
, EP
, param_name
);
99 Free_ParamNames(param_name
, 1);
103 barvinok_options_free(bv_options
);