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