Polyhedron_Sample: rename "dim" variable to "space"
[barvinok.git] / barvinok_ehrhart.cc
blob0f3d36d071833665cb5208a86f13e722d487e522
1 #include <unistd.h>
2 #include <stdlib.h>
3 #include <strings.h>
4 #include <barvinok/polylib.h>
5 #include <barvinok/util.h>
6 #include <barvinok/barvinok.h>
7 #include "evalue_convert.h"
8 #include "barvinok_ehrhart_options.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
14 * final column.
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
21 * should always be 1.
24 int main(int argc, char **argv)
26 Polyhedron *A, *C, *U;
27 const char **param_name;
28 int print_solution = 1;
29 struct ehrhart_options *options = ehrhart_options_new_with_defaults();
31 argc = ehrhart_options_parse(options, argc, argv, ISL_ARG_ALL);
33 A = Polyhedron_Read(options->barvinok->MaxRays);
34 param_name = Read_ParamNames(stdin, 1);
35 Polyhedron_Print(stdout, P_VALUE_FMT, A);
36 C = Cone_over_Polyhedron(A);
37 U = Universe_Polyhedron(1);
38 if (options->series) {
39 gen_fun *gf;
40 gf = barvinok_series_with_options(C, U, options->barvinok);
41 gf->print(std::cout, U->Dimension, param_name);
42 puts("");
43 delete gf;
44 } else {
45 evalue *EP;
46 /* A (conceptually) obvious optimization would be to pass in
47 * the parametric vertices, which are just n times the original
48 * vertices, rather than letting barvinok_enumerate_ev (re)compute
49 * them through Polyhedron2Param_SimplifiedDomain.
51 EP = barvinok_enumerate_with_options(C, U, options->barvinok);
52 assert(EP);
53 if (evalue_convert(EP, options->convert, options->barvinok->verbose,
54 C->Dimension, param_name))
55 print_solution = 0;
56 if (print_solution)
57 print_evalue(stdout, EP, param_name);
58 evalue_free(EP);
60 Free_ParamNames(param_name, 1);
61 Polyhedron_Free(A);
62 Polyhedron_Free(C);
63 Polyhedron_Free(U);
64 ehrhart_options_free(options);
65 return 0;