volume.c: allow computation of lower and upper bound volumes
[barvinok.git] / omega / count.cc
blob6ecbbbd5dc7710257decc7f5b555861061de468b
1 #include <barvinok/barvinok.h>
2 #include <barvinok/util.h>
3 #include <omega.h>
4 #include "omega/convert.h"
5 #include "count.h"
6 #include "config.h"
8 #include <iostream>
9 using namespace std;
11 #ifdef HAVE_GROWING_CHERNIKOVA
12 #define MAXRAYS POL_NO_DUAL
13 #else
14 #define MAXRAYS 600
15 #endif
17 evalue *count_relation(Relation& r)
19 varvector vv;
20 varvector params;
21 Polyhedron *D = relation2Domain(r, vv, params);
22 int dim = r.is_set() ? r.n_set() : r.n_inp() + r.n_out();
24 int d = 0;
25 evalue *EP = NULL;
26 for (Polyhedron *P = D; P; P = P->next, ++d) {
27 assert(d == 0);
28 int exist = P->Dimension - params.size() - dim;
29 EP = barvinok_enumerate_e(P, exist, params.size(), MAXRAYS);
31 reduce_evalue(EP);
32 Domain_Free(D);
33 return EP;
36 evalue *rank_relation(Relation& r)
38 varvector vv;
39 varvector params;
40 Polyhedron *D = relation2Domain(r, vv, params);
41 int dim = r.is_set() ? r.n_set() : r.n_inp() + r.n_out();
43 evalue *EP = NULL;
44 if (D) {
45 assert(D->next == NULL);
46 Polyhedron *C = Universe_Polyhedron(params.size());
47 EP = barvinok_lexsmaller_ev(D, D, dim, C, MAXRAYS);
48 Polyhedron_Free(C);
50 Domain_Free(D);
51 return EP;
54 evalue *count_lexsmaller(Relation& r, Relation& domain)
56 varvector P_vv;
57 varvector P_params;
58 varvector D_vv;
59 varvector D_params;
60 Polyhedron *P = relation2Domain(r, P_vv, P_params);
61 int P_dim = r.is_set() ? r.n_set() : r.n_inp() + r.n_out();
62 Polyhedron *D = relation2Domain(domain, D_vv, D_params);
63 int D_dim = r.is_set() ? r.n_set() : r.n_inp() + r.n_out();
64 assert(P_dim == D_dim);
66 evalue *EP = NULL;
67 if (P && D) {
68 assert(P->next == NULL);
69 assert(D->next == NULL);
70 Polyhedron *C = Universe_Polyhedron(D_params.size());
71 EP = barvinok_lexsmaller_ev(P, D, D_dim, C, MAXRAYS);
72 Polyhedron_Free(C);
74 Domain_Free(P);
75 Domain_Free(D);
76 return EP;