tests/ehrhart/classen*: mention contributor
[barvinok.git] / bfcounter.h
blobd6ca3b5f6626d1740836b34c9c05b284e272ddf3
1 #include <assert.h>
2 #include <vector>
3 #include <gmp.h>
4 #include <NTL/vec_ZZ.h>
5 #include <NTL/mat_ZZ.h>
6 #include <barvinok/polylib.h>
7 #include <barvinok/NTL_QQ.h>
8 #include "reducer.h"
10 struct bfc_term_base {
11 // the number of times a given factor appears in the denominator
12 int *powers;
13 mat_ZZ terms;
15 bfc_term_base(int len) {
16 powers = new int[len];
19 virtual ~bfc_term_base() {
20 delete [] powers;
24 struct bfc_term : public bfc_term_base {
25 vec_QQ c;
27 bfc_term(int len) : bfc_term_base(len) {}
30 typedef std::vector< bfc_term_base * > bfc_vec;
32 struct bf_reducer;
34 struct bf_base : public np_base {
35 mpq_t tcount;
36 mpz_t tn;
37 mpz_t td;
38 int lower; // call base when only this many variables is left
40 bf_base(unsigned dim) : np_base(dim) {
41 mpq_init(tcount);
42 mpz_init(tn);
43 mpz_init(td);
46 ~bf_base() {
47 mpq_clear(tcount);
48 mpz_clear(tn);
49 mpz_clear(td);
52 virtual void handle(const mat_ZZ& rays, Value *vertex, const QQ& c,
53 unsigned long det, barvinok_options *options);
54 int setup_factors(const mat_ZZ& rays, mat_ZZ& factors, bfc_term_base* t, int s);
56 bfc_term_base* find_bfc_term(bfc_vec& v, int *powers, int len);
57 void add_term(bfc_term_base *t, vec_ZZ& num1, vec_ZZ& num);
58 void add_term(bfc_term_base *t, vec_ZZ& num);
60 void reduce(mat_ZZ& factors, bfc_vec& v, barvinok_options *options);
61 virtual void base(mat_ZZ& factors, bfc_vec& v) = 0;
63 virtual bfc_term_base* new_bf_term(int len) = 0;
64 virtual void set_factor(bfc_term_base *t, int k, int change) = 0;
65 virtual void set_factor(bfc_term_base *t, int k, mpq_t &f, int change) = 0;
66 virtual void set_factor(bfc_term_base *t, int k, const QQ& c, int change) = 0;
67 virtual void update_term(bfc_term_base *t, int i) = 0;
68 virtual void insert_term(bfc_term_base *t, int i) = 0;
69 virtual bool constant_vertex(int dim) = 0;
70 virtual void cum(bf_reducer *bfr, bfc_term_base *t, int k,
71 dpoly_r *r, barvinok_options *options) = 0;
74 struct bfcounter_base : public bf_base {
75 QQ c;
77 bfcounter_base(unsigned dim) : bf_base(dim) {
80 bfc_term_base* new_bf_term(int len);
82 virtual void set_factor(bfc_term_base *t, int k, int change);
83 virtual void set_factor(bfc_term_base *t, int k, mpq_t &f, int change);
84 virtual void set_factor(bfc_term_base *t, int k, const QQ& c_factor, int change);
85 virtual void insert_term(bfc_term_base *t, int i);
86 virtual void update_term(bfc_term_base *t, int i);
88 virtual bool constant_vertex(int dim) { return true; }
89 virtual void cum(bf_reducer *bfr, bfc_term_base *t, int k, dpoly_r *r,
90 barvinok_options *options) {
91 assert(0);
95 struct bf_reducer {
96 mat_ZZ& factors;
97 bfc_vec& v;
98 bf_base *bf;
100 unsigned nf;
101 unsigned d;
103 mat_ZZ nfactors;
104 int *old2new;
105 int *sign;
106 unsigned int nnf;
107 bfc_vec vn;
109 vec_ZZ extra_num;
110 int changes;
111 int no_param; // r from text
112 int only_param; // k-r-s from text
113 int total_power; // k from text
115 // created in compute_reduced_factors
116 int *bpowers;
117 // set in update_powers
118 int *npowers;
119 vec_ZZ l_extra_num;
120 int l_changes;
122 bf_reducer(mat_ZZ& factors, bfc_vec& v, bf_base *bf)
123 : factors(factors), v(v), bf(bf) {
124 nf = factors.NumRows();
125 d = factors.NumCols();
126 old2new = new int[nf];
127 sign = new int[nf];
129 extra_num.SetLength(d-1);
131 ~bf_reducer() {
132 delete [] old2new;
133 delete [] sign;
134 delete [] npowers;
135 delete [] bpowers;
138 void compute_reduced_factors();
139 void compute_extra_num(int i);
141 void reduce(barvinok_options *options);
143 void update_powers(const std::vector<int>& powers);