volume.c: drop redundant arguments to volume_simplex
[barvinok.git] / barvinok_ehrhart.cc
blobf9c99a941c3d5bd33208c15a0ddd604c5970a8da
1 #include <unistd.h>
2 #include <stdlib.h>
3 #include <strings.h>
4 #include <barvinok/util.h>
5 #include <barvinok/barvinok.h>
6 #include "config.h"
8 /* The input of this example program is a polytope in PolyLib notation,
9 * i.e., an n by d+2 matrix of the n constraints A x + b >= 0 defining
10 * the polytope * sitting in a d-dimensional space. The first column
11 * is 1 for an inequality and 0 for an equality. b is placed in the
12 * final column.
13 * Alternatively, if the matrix is preceded by the word "vertices"
14 * on a line by itself, it will be interpreted as a list of vertices
15 * in PolyLib notation, i.e., an n by (d+2) matrix, where n is
16 * the number of vertices/rays and d the dimension. The first column is
17 * 0 for lines and 1 for vertices/rays. The final column is the denominator
18 * or 0 for rays. Note that for barvinok_ehrhart, the first column
19 * should always be 1.
22 #ifndef HAVE_GETOPT_H
23 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
24 #else
25 #include <getopt.h>
26 struct option options[] = {
27 { "convert", no_argument, 0, 'c' },
28 { "floor", no_argument, 0, 'f' },
29 { "series", no_argument, 0, 's' },
30 { "version", no_argument, 0, 'V' },
31 { 0, 0, 0, 0 }
33 #endif
35 int main(int argc, char **argv)
37 Polyhedron *A, *C, *U;
38 char **param_name;
39 int c, ind = 0;
40 int convert = 0;
41 int floor = 0;
42 int series = 0;
43 barvinok_options *bv_options = barvinok_options_new_with_defaults();
45 while ((c = getopt_long(argc, argv, "sfcV", options, &ind)) != -1) {
46 switch (c) {
47 case 's':
48 series = 1;
49 break;
50 case 'c':
51 convert = 1;
52 break;
53 case 'f':
54 floor = 1;
55 break;
56 case 'V':
57 printf(barvinok_version());
58 exit(0);
59 break;
63 A = Polyhedron_Read(bv_options->MaxRays);
64 param_name = Read_ParamNames(stdin, 1);
65 Polyhedron_Print(stdout, P_VALUE_FMT, A);
66 C = Cone_over_Polyhedron(A);
67 U = Universe_Polyhedron(1);
68 if (series) {
69 gen_fun *gf;
70 gf = barvinok_series_with_options(C, U, bv_options);
71 gf->print(std::cout, U->Dimension, param_name);
72 puts("");
73 delete gf;
74 } else {
75 evalue *EP;
76 /* A (conceptually) obvious optimization would be to pass in
77 * the parametric vertices, which are just n times the original
78 * vertices, rather than letting barvinok_enumerate_ev (re)compute
79 * them through Polyhedron2Param_SimplifiedDomain.
81 EP = barvinok_enumerate_with_options(C, U, bv_options);
82 print_evalue(stdout, EP, param_name);
83 if (floor) {
84 fprintf(stderr, "WARNING: floor conversion not supported\n");
85 evalue_frac2floor2(EP, 0);
86 print_evalue(stdout, EP, param_name);
87 } else if (convert) {
88 evalue_mod2table(EP, C->Dimension);
89 print_evalue(stdout, EP, param_name);
91 free_evalue_refs(EP);
92 free(EP);
94 Free_ParamNames(param_name, 1);
95 Polyhedron_Free(A);
96 Polyhedron_Free(C);
97 Polyhedron_Free(U);
98 barvinok_options_free(bv_options);
99 return 0;