bfcounter.cc: move some more code from barvinok.cc
[barvinok.git] / reducer.h
blob4cd0fe7672522ad09a4e40ae8f013137b5930236
1 #ifndef REDUCER_H
2 #define REDUCER_H
4 #include <NTL/mat_ZZ.h>
5 #include <barvinok/NTL_QQ.h>
6 #include "decomposer.h"
7 #include "dpoly.h"
9 #ifdef NTL_STD_CXX
10 using namespace NTL;
11 #endif
13 /* base for non-parametric counting */
14 struct np_base : public polar_decomposer {
15 unsigned dim;
16 QQ factor;
17 ZZ one;
19 np_base(unsigned dim) {
20 this->dim = dim;
21 factor.d = 1;
22 one = 1;
25 virtual void handle_polar(Polyhedron *C, Value *vertex, QQ c) = 0;
26 virtual void handle_polar(Polyhedron *C, int s);
27 void start(Polyhedron *P, unsigned MaxRays);
28 virtual void init(Polyhedron *P) {
31 private:
32 Value *current_vertex;
33 ZZ sign;
36 struct reducer : public np_base {
37 vec_ZZ vertex;
38 //vec_ZZ den;
39 ZZ num;
40 mpq_t tcount;
41 mpz_t tn;
42 mpz_t td;
43 int lower; // call base when only this many variables is left
45 reducer(unsigned dim) : np_base(dim) {
46 //den.SetLength(dim);
47 mpq_init(tcount);
48 mpz_init(tn);
49 mpz_init(td);
52 ~reducer() {
53 mpq_clear(tcount);
54 mpz_clear(tn);
55 mpz_clear(td);
58 virtual void handle_polar(Polyhedron *C, Value *vertex, QQ c);
59 void reduce(QQ c, vec_ZZ& num, mat_ZZ& den_f);
60 virtual void base(QQ& c, const vec_ZZ& num, const mat_ZZ& den_f) = 0;
61 virtual void split(vec_ZZ& num, ZZ& num_s, vec_ZZ& num_p,
62 mat_ZZ& den_f, vec_ZZ& den_s, mat_ZZ& den_r) = 0;
65 struct ireducer : public reducer {
66 ireducer(unsigned dim) : reducer(dim) {}
68 virtual void split(vec_ZZ& num, ZZ& num_s, vec_ZZ& num_p,
69 mat_ZZ& den_f, vec_ZZ& den_s, mat_ZZ& den_r);
72 void normalize(ZZ& sign, ZZ& num_s, vec_ZZ& num_p, vec_ZZ& den_s, vec_ZZ& den_p,
73 mat_ZZ& f);
75 #endif