barvinok_enumerate: make sure the input polyhedra are fully specified.
[barvinok.git] / barvinok_enumerate_e.c
blob7f2b8a2abcaa3317e9d59aec6f047815ecd5ef84
1 #include <unistd.h>
2 #include <stdlib.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 { "version", no_argument, 0, 'V' },
34 { 0, 0, 0, 0 }
36 #endif
38 int main(int argc, char **argv)
40 Polyhedron *A;
41 Matrix *M;
42 char **param_name;
43 int exist, nparam;
44 char s[128];
45 evalue *EP;
46 int c, ind = 0;
47 int range = 0;
48 int convert = 0;
49 int pip = 0;
50 int floor = 0;
52 while ((c = getopt_long(argc, argv, "pfcrV", options, &ind)) != -1) {
53 switch (c) {
54 case 'p':
55 pip = 1;
56 break;
57 case 'f':
58 floor = 1;
59 break;
60 case 'c':
61 convert = 1;
62 break;
63 case 'r':
64 range = 1;
65 break;
66 case 'V':
67 printf(barvinok_version());
68 exit(0);
69 break;
73 M = Matrix_Read();
74 A = Constraints2Polyhedron(M, MAXRAYS);
75 Matrix_Free(M);
77 fgets(s, 128, stdin);
78 while ((*s=='#') || (sscanf(s, "E %d", &exist)<1))
79 fgets(s, 128, stdin);
81 fgets(s, 128, stdin);
82 while ((*s=='#') || (sscanf(s, "P %d", &nparam)<1))
83 fgets(s, 128, stdin);
85 Polyhedron_Print(stdout, P_VALUE_FMT, A);
86 printf("exist: %d, nparam: %d\n", exist, nparam);
87 param_name = Read_ParamNames(stdin, nparam);
88 if (pip && exist > 0)
89 EP = barvinok_enumerate_pip(A, exist, nparam, MAXRAYS);
90 else
91 EP = barvinok_enumerate_e(A, exist, nparam, MAXRAYS);
92 reduce_evalue(EP);
93 evalue_combine(EP);
94 if (range)
95 evalue_range_reduction(EP);
96 print_evalue(stdout, EP, param_name);
97 if (floor) {
98 fprintf(stderr, "WARNING: floor conversion not supported\n");
99 evalue_frac2floor(EP);
100 print_evalue(stdout, EP, param_name);
101 } else if (convert) {
102 evalue_mod2table(EP, nparam);
103 print_evalue(stdout, EP, param_name);
105 free_evalue_refs(EP);
106 free(EP);
107 Free_ParamNames(param_name, nparam);
108 Polyhedron_Free(A);
109 return 0;