barvinok.cc: enumerator::handle: drop unused variable
[barvinok.git] / bfcounter.h
blobb532539942d3d174cd2c1b7e3dd8a8228e2f4729
1 #include <assert.h>
2 #include <vector>
3 #include <gmp.h>
4 #include <barvinok/polylib.h>
5 #include <barvinok/NTL_QQ.h>
6 #include "reducer.h"
8 struct bfc_term_base {
9 // the number of times a given factor appears in the denominator
10 int *powers;
11 mat_ZZ terms;
13 bfc_term_base(int len) {
14 powers = new int[len];
17 virtual ~bfc_term_base() {
18 delete [] powers;
22 struct bfc_term : public bfc_term_base {
23 vec_QQ c;
25 bfc_term(int len) : bfc_term_base(len) {}
28 typedef std::vector< bfc_term_base * > bfc_vec;
30 struct bf_reducer;
32 struct bf_base : public np_base {
33 mpq_t tcount;
34 mpz_t tn;
35 mpz_t td;
36 int lower; // call base when only this many variables is left
38 bf_base(unsigned dim) : np_base(dim) {
39 mpq_init(tcount);
40 mpz_init(tn);
41 mpz_init(td);
44 ~bf_base() {
45 mpq_clear(tcount);
46 mpz_clear(tn);
47 mpz_clear(td);
50 virtual void handle(const mat_ZZ& rays, Value *vertex, const QQ& c,
51 unsigned long det, barvinok_options *options);
52 int setup_factors(const mat_ZZ& rays, mat_ZZ& factors, bfc_term_base* t, int s);
54 bfc_term_base* find_bfc_term(bfc_vec& v, int *powers, int len);
55 void add_term(bfc_term_base *t, vec_ZZ& num1, vec_ZZ& num);
56 void add_term(bfc_term_base *t, vec_ZZ& num);
58 void reduce(mat_ZZ& factors, bfc_vec& v, barvinok_options *options);
59 virtual void base(mat_ZZ& factors, bfc_vec& v) = 0;
61 virtual bfc_term_base* new_bf_term(int len) = 0;
62 virtual void set_factor(bfc_term_base *t, int k, int change) = 0;
63 virtual void set_factor(bfc_term_base *t, int k, mpq_t &f, int change) = 0;
64 virtual void set_factor(bfc_term_base *t, int k, const QQ& c, int change) = 0;
65 virtual void update_term(bfc_term_base *t, int i) = 0;
66 virtual void insert_term(bfc_term_base *t, int i) = 0;
67 virtual bool constant_vertex(int dim) = 0;
68 virtual void cum(bf_reducer *bfr, bfc_term_base *t, int k,
69 dpoly_r *r, barvinok_options *options) = 0;
72 struct bfcounter_base : public bf_base {
73 QQ c;
75 bfcounter_base(unsigned dim) : bf_base(dim) {
78 bfc_term_base* new_bf_term(int len);
80 virtual void set_factor(bfc_term_base *t, int k, int change);
81 virtual void set_factor(bfc_term_base *t, int k, mpq_t &f, int change);
82 virtual void set_factor(bfc_term_base *t, int k, const QQ& c_factor, int change);
83 virtual void insert_term(bfc_term_base *t, int i);
84 virtual void update_term(bfc_term_base *t, int i);
86 virtual bool constant_vertex(int dim) { return true; }
87 virtual void cum(bf_reducer *bfr, bfc_term_base *t, int k, dpoly_r *r,
88 barvinok_options *options) {
89 assert(0);
93 struct bf_reducer {
94 mat_ZZ& factors;
95 bfc_vec& v;
96 bf_base *bf;
98 unsigned nf;
99 unsigned d;
101 mat_ZZ nfactors;
102 int *old2new;
103 int *sign;
104 unsigned int nnf;
105 bfc_vec vn;
107 vec_ZZ extra_num;
108 int changes;
109 int no_param; // r from text
110 int only_param; // k-r-s from text
111 int total_power; // k from text
113 // created in compute_reduced_factors
114 int *bpowers;
115 // set in update_powers
116 int *npowers;
117 vec_ZZ l_extra_num;
118 int l_changes;
120 bf_reducer(mat_ZZ& factors, bfc_vec& v, bf_base *bf)
121 : factors(factors), v(v), bf(bf) {
122 nf = factors.NumRows();
123 d = factors.NumCols();
124 old2new = new int[nf];
125 sign = new int[nf];
127 extra_num.SetLength(d-1);
129 ~bf_reducer() {
130 delete [] old2new;
131 delete [] sign;
132 delete [] npowers;
133 delete [] bpowers;
136 void compute_reduced_factors();
137 void compute_extra_num(int i);
139 void reduce(barvinok_options *options);
141 void update_powers(const std::vector<int>& powers);