gen_fun::Hadamard_product: don't assume equalities are independent
[barvinok.git] / barvinok_count.c
blobce3f5abea066b4448a33764b267c8e95af85cfda
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 #ifdef HAVE_GROWING_CHERNIKOVA
10 #define MAXRAYS (POL_NO_DUAL | POL_INTEGER)
11 #else
12 #define MAXRAYS 600
13 #endif
15 #ifndef HAVE_GETOPT_H
16 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
17 #else
18 #include <getopt.h>
19 struct option options[] = {
20 { "version", no_argument, 0, 'V' },
21 { 0, 0, 0, 0 }
23 #endif
25 static Polyhedron *Polyhedron_Read()
27 int vertices = 0;
28 unsigned NbRows, NbColumns;
29 Matrix *M;
30 Polyhedron *P;
31 char s[128];
33 while (fgets(s, sizeof(s), stdin)) {
34 if (*s == '#')
35 continue;
36 if (strncasecmp(s, "vertices", sizeof("vertices")-1) == 0)
37 vertices = 1;
38 if (sscanf(s, "%u %u", &NbRows, &NbColumns) == 2)
39 break;
41 if (feof(stdin))
42 return NULL;
43 M = Matrix_Alloc(NbRows,NbColumns);
44 Matrix_Read_Input(M);
45 if (vertices)
46 P = Rays2Polyhedron(M, MAXRAYS);
47 else
48 P = Constraints2Polyhedron(M, MAXRAYS);
49 Matrix_Free(M);
50 return P;
53 int main(int argc, char **argv)
55 Value cb;
56 Polyhedron *A;
57 int c, ind = 0;
59 while ((c = getopt_long(argc, argv, "V", options, &ind)) != -1) {
60 switch (c) {
61 case 'V':
62 printf(barvinok_version());
63 exit(0);
64 break;
68 A = Polyhedron_Read();
69 value_init(cb);
70 Polyhedron_Print(stdout, P_VALUE_FMT, A);
71 barvinok_count(A, &cb, MAXRAYS);
72 value_print(stdout, P_VALUE_FMT, cb);
73 puts("");
74 value_clear(cb);
75 Polyhedron_Free(A);
76 return 0;