dump to cerr instead of cout.
[barvinok.git] / barvinok_enumerate_e.c
blob90b868bd88c76b61142724a896fdc24e72fbccd4
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 a polytope in combined
9 * data and parameter space followed by two lines indicating
10 * the number of existential variables and parameters respectively.
11 * The first lines starts with "E ", followed by a number.
12 * The second lines starts with "P ", followed by a number.
13 * These two lines are (optionally) followed by the names of the parameters.
14 * The polytope is in PolyLib notation.
17 #ifdef HAVE_GROWING_CHERNIKOVA
18 #define MAXRAYS 0
19 #else
20 #define MAXRAYS 600
21 #endif
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 { "pip", no_argument, 0, 'p' },
29 { "convert", no_argument, 0, 'c' },
30 { "floor", no_argument, 0, 'f' },
31 { "range", no_argument, 0, 'r' },
32 { 0, 0, 0, 0 }
34 #endif
36 int main(int argc, char **argv)
38 Polyhedron *A;
39 Matrix *M;
40 char **param_name;
41 int exist, nparam;
42 char s[128];
43 evalue *EP;
44 int c, ind = 0;
45 int range = 0;
46 int convert = 0;
47 int pip = 0;
48 int floor = 0;
50 while ((c = getopt_long(argc, argv, "pfcr", options, &ind)) != -1) {
51 switch (c) {
52 case 'p':
53 pip = 1;
54 break;
55 case 'f':
56 floor = 1;
57 break;
58 case 'c':
59 convert = 1;
60 break;
61 case 'r':
62 range = 1;
63 break;
67 M = Matrix_Read();
68 A = Constraints2Polyhedron(M, MAXRAYS);
69 Matrix_Free(M);
71 fgets(s, 128, stdin);
72 while ((*s=='#') || (sscanf(s, "E %d", &exist)<1))
73 fgets(s, 128, stdin);
75 fgets(s, 128, stdin);
76 while ((*s=='#') || (sscanf(s, "P %d", &nparam)<1))
77 fgets(s, 128, stdin);
79 Polyhedron_Print(stdout, P_VALUE_FMT, A);
80 printf("exist: %d, nparam: %d\n", exist, nparam);
81 param_name = Read_ParamNames(stdin, nparam);
82 if (pip && exist > 0)
83 EP = barvinok_enumerate_pip(A, exist, nparam, MAXRAYS);
84 else
85 EP = barvinok_enumerate_e(A, exist, nparam, MAXRAYS);
86 reduce_evalue(EP);
87 evalue_combine(EP);
88 if (range)
89 evalue_range_reduction(EP);
90 print_evalue(stdout, EP, param_name);
91 if (floor) {
92 fprintf(stderr, "WARNING: floor conversion not supported\n");
93 evalue_frac2floor(EP);
94 print_evalue(stdout, EP, param_name);
95 } else if (convert) {
96 evalue_mod2table(EP, nparam);
97 print_evalue(stdout, EP, param_name);
99 free_evalue_refs(EP);
100 free(EP);
101 Free_ParamNames(param_name, nparam);
102 Polyhedron_Free(A);
103 return 0;