Merge with master
[barvinok.git] / barvinok_enumerate.c
blob6ff18eeaa8d95b53d1a451938018b3327b743962
1 #include <unistd.h>
2 #include <polylib/polylibgmp.h>
3 #include "ev_operations.h"
4 #include <util.h>
5 #include <barvinok.h>
6 #include "config.h"
8 /* The input of this example program is the same as that of testehrhart
9 * in the PolyLib distribution, i.e., a polytope in combined
10 * data and parameter space, a context polytope in parameter space
11 * and (optionally) the names of the parameters.
12 * Both polytopes are in PolyLib notation.
15 #ifdef HAVE_GROWING_CHERNIKOVA
16 #define MAXRAYS 0
17 #else
18 #define MAXRAYS 600
19 #endif
21 #ifndef HAVE_GETOPT_H
22 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
23 #else
24 #include <getopt.h>
25 struct option options[] = {
26 { "convert", no_argument, 0, 'c' },
27 { "floor", no_argument, 0, 'f' },
28 { "size", no_argument, 0, 's' },
29 { 0, 0, 0, 0 }
31 #endif
33 int main(int argc, char **argv)
35 Polyhedron *A, *C;
36 Matrix *M;
37 evalue *EP;
38 char **param_name;
39 int c, ind = 0;
40 int convert = 0;
41 int floor = 0;
42 int size = 0;
44 while ((c = getopt_long(argc, argv, "fcs", options, &ind)) != -1) {
45 switch (c) {
46 case 'c':
47 convert = 1;
48 break;
49 case 'f':
50 floor = 1;
51 break;
52 case 's':
53 size = 1;
54 break;
58 M = Matrix_Read();
59 A = Constraints2Polyhedron(M, MAXRAYS);
60 Matrix_Free(M);
61 M = Matrix_Read();
62 C = Constraints2Polyhedron(M, MAXRAYS);
63 Matrix_Free(M);
64 Polyhedron_Print(stdout, P_VALUE_FMT, A);
65 Polyhedron_Print(stdout, P_VALUE_FMT, C);
66 param_name = Read_ParamNames(stdin, C->Dimension);
67 EP = barvinok_enumerate_ev(A, C, MAXRAYS);
68 print_evalue(stdout, EP, param_name);
69 if (size)
70 printf("\nSize: %d\n", evalue_size(EP));
71 if (floor) {
72 fprintf(stderr, "WARNING: floor conversion not supported\n");
73 evalue_frac2floor(EP);
74 print_evalue(stdout, EP, param_name);
75 } else if (convert) {
76 evalue_mod2table(EP, C->Dimension);
77 print_evalue(stdout, EP, param_name);
78 if (size)
79 printf("\nSize: %d\n", evalue_size(EP));
81 free_evalue_refs(EP);
82 free(EP);
83 Free_ParamNames(param_name, C->Dimension);
84 Polyhedron_Free(A);
85 Polyhedron_Free(C);
86 return 0;