lattice_point.h: make sure correct evalues are used
[barvinok/uuh.git] / counter.h
blob8ff769882a87036b1715380bdacb6238822887b3
1 #include "reducer.h"
3 struct counter_base: public np_base {
4 Vector *lambda;
5 Matrix *den;
6 Matrix *num;
7 mpq_t count;
8 Value tmp;
10 counter_base(unsigned dim, unsigned long max_index) : np_base(dim) {
11 mpq_init(count);
12 num = Matrix_Alloc(max_index, 1);
13 den = Matrix_Alloc(dim, 1);
14 lambda = Vector_Alloc(dim);
15 value_init(tmp);
18 virtual void init(Polyhedron *P) {
19 vec_ZZ l;
20 randomvector(P, l, dim);
21 zz2values(l, lambda->p);
24 ~counter_base() {
25 Matrix_Free(num);
26 Matrix_Free(den);
27 Vector_Free(lambda);
28 mpq_clear(count);
29 value_clear(tmp);
32 virtual void add_lattice_points(int sign) = 0;
34 virtual void handle(const mat_ZZ& rays, Value *vertex, const QQ& c,
35 unsigned long det, barvinok_options *options);
36 virtual void get_count(Value *result) {
37 assert(value_one_p(&count[0]._mp_den));
38 value_assign(*result, &count[0]._mp_num);
42 struct counter : public counter_base {
43 counter(unsigned dim, unsigned long max_index) :
44 counter_base(dim, max_index) {}
46 virtual void reset() {
47 mpq_set_si(count, 0, 0);
50 virtual void add_lattice_points(int sign);
53 struct tcounter : public counter_base {
54 mpq_t tcount;
55 dpoly todd;
56 Vector *todd_denom;
57 Value denom;
59 tcounter(unsigned dim, unsigned long max_index) :
60 counter_base(dim, max_index), todd(dim) {
61 mpq_init(tcount);
62 setup_todd(dim);
63 value_init(denom);
66 void setup_todd(unsigned dim);
68 void adapt_todd(dpoly& t, const Value c);
69 void add_powers(dpoly& n, const Value c);
71 ~tcounter() {
72 mpq_clear(tcount);
73 Vector_Free(todd_denom);
74 value_clear(denom);
77 virtual void add_lattice_points(int sign);
80 /* A counter for possibly infinite sets.
81 * Rather than just keeping track of the constant term
82 * of the Laurent expansions, we also keep track of the
83 * coefficients of negative powers.
84 * If any of these is non-zero, then the counted set is infinite.
86 struct infinite_counter {
87 /* an array of coefficients; count[i] is the coeffient of
88 * the term with power -i.
90 vec_ZZ lambda;
91 mpq_t *count;
92 unsigned maxlen;
93 Value tz;
95 infinite_counter(unsigned dim, unsigned maxlen) : maxlen(maxlen) {
96 count = new mpq_t[maxlen+1];
97 for (int i = 0; i <= maxlen; ++i)
98 mpq_init(count[i]);
99 value_init(tz);
102 void init(Polyhedron *context);
104 void reduce(const vec_QQ& c, const mat_ZZ& num, const mat_ZZ& den_f);
106 ~infinite_counter() {
107 for (int i = 0; i <= maxlen; ++i)
108 mpq_clear(count[i]);
109 delete [] count;
110 value_clear(tz);