update AUTHORS
[barvinok.git] / counter.h
blobca2cae2a73bfc518ce747315fa2bd50018c5fca0
1 #include <NTL/vec_ZZ.h>
2 #include <NTL/mat_ZZ.h>
3 #include <barvinok/polylib.h>
4 #include "reducer.h"
6 struct counter_base: public np_base {
7 Vector *lambda;
8 Matrix *den;
9 Matrix *num;
10 mpq_t count;
11 Value tmp;
13 counter_base(unsigned dim, unsigned long max_index) : np_base(dim) {
14 mpq_init(count);
15 num = Matrix_Alloc(max_index, 1);
16 den = Matrix_Alloc(dim, 1);
17 lambda = Vector_Alloc(dim);
18 value_init(tmp);
21 virtual void init(Polyhedron *P, int n_try) {
22 vec_ZZ l;
23 randomvector(P, l, dim, n_try);
24 zz2values(l, lambda->p);
27 virtual void reset() {
28 mpq_set_si(count, 0, 0);
31 ~counter_base() {
32 Matrix_Free(num);
33 Matrix_Free(den);
34 Vector_Free(lambda);
35 mpq_clear(count);
36 value_clear(tmp);
39 virtual void add_lattice_points(int sign) = 0;
41 virtual void handle(const mat_ZZ& rays, Value *vertex, const QQ& c,
42 unsigned long det, barvinok_options *options);
43 virtual void get_count(Value *result) {
44 assert(value_one_p(&count[0]._mp_den));
45 value_assign(*result, &count[0]._mp_num);
49 struct counter : public counter_base {
50 counter(unsigned dim, unsigned long max_index) :
51 counter_base(dim, max_index) {}
53 virtual void add_lattice_points(int sign);
56 struct tcounter : public counter_base {
57 mpq_t tcount;
58 dpoly todd;
59 Vector *todd_denom;
60 Value denom;
62 tcounter(unsigned dim, unsigned long max_index) :
63 counter_base(dim, max_index), todd(dim) {
64 mpq_init(tcount);
65 setup_todd(dim);
66 value_init(denom);
69 void setup_todd(unsigned dim);
71 void adapt_todd(dpoly& t, const Value c);
72 void add_powers(dpoly& n, const Value c);
74 ~tcounter() {
75 mpq_clear(tcount);
76 Vector_Free(todd_denom);
77 value_clear(denom);
80 virtual void add_lattice_points(int sign);
83 /* A counter for possibly infinite sets.
84 * Rather than just keeping track of the constant term
85 * of the Laurent expansions, we also keep track of the
86 * coefficients of negative powers.
87 * If any of these is non-zero, then the counted set is infinite.
89 struct infinite_counter {
90 /* an array of coefficients; count[i] is the coeffient of
91 * the term with power -i.
93 vec_ZZ lambda;
94 mpq_t *count;
95 unsigned maxlen;
96 Value tz;
98 infinite_counter(unsigned dim, unsigned maxlen) : maxlen(maxlen) {
99 count = new mpq_t[maxlen+1];
100 for (int i = 0; i <= maxlen; ++i)
101 mpq_init(count[i]);
102 value_init(tz);
105 void init(Polyhedron *context, int n_try);
107 void reduce(const vec_QQ& c, const mat_ZZ& num, const mat_ZZ& den_f);
109 ~infinite_counter() {
110 for (int i = 0; i <= maxlen; ++i)
111 mpq_clear(count[i]);
112 delete [] count;
113 value_clear(tz);