bump version
[barvinok.git] / barvinok_enumerate_e.c
blobab7dbf281108fbeaf0080c5f116179bd830f8e86
1 #include <unistd.h>
2 #include <sys/times.h>
3 #include <polylib/polylibgmp.h>
4 #include "ev_operations.h"
5 #include <util.h>
6 #include <barvinok.h>
7 #include "config.h"
9 /* The input of this example program is a polytope in combined
10 * data and parameter space followed by two lines indicating
11 * the number of existential variables and parameters respectively.
12 * The first lines starts with "E ", followed by a number.
13 * The second lines starts with "P ", followed by a number.
14 * These two lines are (optionally) followed by the names of the parameters.
15 * The polytope is in PolyLib notation.
18 #ifdef HAVE_GROWING_CHERNIKOVA
19 #define MAXRAYS 0
20 #else
21 #define MAXRAYS 600
22 #endif
24 #ifndef HAVE_GETOPT_H
25 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
26 #else
27 #include <getopt.h>
28 struct option options[] = {
29 { "pip", no_argument, 0, 'p' },
30 { "convert", no_argument, 0, 'c' },
31 { "floor", no_argument, 0, 'f' },
32 { "range", no_argument, 0, 'r' },
33 { 0, 0, 0, 0 }
35 #endif
37 int main(int argc, char **argv)
39 Polyhedron *A;
40 Matrix *M;
41 char **param_name;
42 int exist, nparam;
43 char s[128];
44 evalue *EP;
45 int c, ind = 0;
46 int range = 0;
47 int convert = 0;
48 int pip = 0;
49 int floor = 0;
51 while ((c = getopt_long(argc, argv, "pfcr", options, &ind)) != -1) {
52 switch (c) {
53 case 'p':
54 pip = 1;
55 break;
56 case 'f':
57 floor = 1;
58 break;
59 case 'c':
60 convert = 1;
61 break;
62 case 'r':
63 range = 1;
64 break;
68 M = Matrix_Read();
69 A = Constraints2Polyhedron(M, MAXRAYS);
70 Matrix_Free(M);
72 fgets(s, 128, stdin);
73 while ((*s=='#') || (sscanf(s, "E %d", &exist)<1))
74 fgets(s, 128, stdin);
76 fgets(s, 128, stdin);
77 while ((*s=='#') || (sscanf(s, "P %d", &nparam)<1))
78 fgets(s, 128, stdin);
80 Polyhedron_Print(stdout, P_VALUE_FMT, A);
81 printf("exist: %d, nparam: %d\n", exist, nparam);
82 param_name = Read_ParamNames(stdin, nparam);
83 if (pip && exist > 0)
84 EP = barvinok_enumerate_pip(A, exist, nparam, MAXRAYS);
85 else
86 EP = barvinok_enumerate_e(A, exist, nparam, MAXRAYS);
87 reduce_evalue(EP);
88 evalue_combine(EP);
89 if (range)
90 evalue_range_reduction(EP);
91 print_evalue(stdout, EP, param_name);
92 if (floor) {
93 fprintf(stderr, "WARNING: floor conversion not supported\n");
94 evalue_frac2floor(EP);
95 print_evalue(stdout, EP, param_name);
96 } else if (convert) {
97 evalue_mod2table(EP, nparam);
98 print_evalue(stdout, EP, param_name);
100 free_evalue_refs(EP);
101 free(EP);
102 Free_ParamNames(param_name, nparam);
103 Polyhedron_Free(A);
104 return 0;