volume.c: volume_triangulate: use vertex instead of barycenter by default
[barvinok.git] / barvinok_union.cc
blob18cb8adf2ad82506d86ffd2ebc619e36dac573cf
1 #include <barvinok/barvinok.h>
2 #include <barvinok/util.h>
3 #include "config.h"
5 /* The input of this example program is similar to that of ehrhart_union
6 * in the PolyLib distribution, the difference being that the number of
7 * polytopes in the union needs to specified explicitly.
8 * The input starts with this number, followed by this number of
9 * polytopes in combined data and parameter space, a context polytope
10 * in parameter space and (optionally) the names of the parameters.
11 * All polytopes are in PolyLib notation.
14 #ifdef HAVE_GROWING_CHERNIKOVA
15 #define MAXRAYS POL_NO_DUAL
16 #else
17 #define MAXRAYS 600
18 #endif
20 #include "config.h"
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 { "series", no_argument, 0, 's' },
27 { "version", no_argument, 0, 'V' },
28 { 0, 0, 0, 0 }
30 #endif
32 int main(int argc, char **argv)
34 Matrix *M;
35 Polyhedron *C, *D = NULL;
36 int i, npol;
37 char **param_name;
38 char s[128];
39 int c, ind = 0;
40 int series = 0;
42 while ((c = getopt_long(argc, argv, "sV", options, &ind)) != -1) {
43 switch (c) {
44 case 's':
45 series = 1;
46 break;
47 case 'V':
48 printf(barvinok_version());
49 exit(0);
50 break;
54 fgets(s, 128, stdin);
55 while ((*s=='#') || (sscanf(s, "%d", &npol)<1))
56 fgets(s, 128, stdin);
58 for (i = 0; i < npol; ++i) {
59 Polyhedron *P;
60 M = Matrix_Read();
61 P = Constraints2Polyhedron(M, MAXRAYS);
62 Matrix_Free(M);
63 D = DomainConcat(P, D);
65 M = Matrix_Read();
66 C = Constraints2Polyhedron(M, MAXRAYS);
67 Matrix_Free(M);
68 Polyhedron_Print(stdout, P_VALUE_FMT, D);
69 Polyhedron_Print(stdout, P_VALUE_FMT, C);
70 param_name = Read_ParamNames(stdin, C->Dimension);
71 if (series) {
72 gen_fun *gf;
73 gf = barvinok_enumerate_union_series(D, C, MAXRAYS);
74 gf->print(std::cout, C->Dimension, param_name);
75 puts("");
76 delete gf;
77 } else {
78 evalue *EP;
79 EP = barvinok_enumerate_union(D, C, MAXRAYS);
80 print_evalue(stdout, EP, param_name);
81 free_evalue_refs(EP);
82 free(EP);
84 Free_ParamNames(param_name, C->Dimension);
85 Domain_Free(D);
86 Polyhedron_Free(C);
87 return 0;