lexmin: make lexmin options private
[barvinok.git] / reducer.h
blob81596c2ac7548d31f6aac063a85d3820697b1bd9
1 #ifndef REDUCER_H
2 #define REDUCER_H
4 #include <NTL/mat_ZZ.h>
5 #include <barvinok/NTL_QQ.h>
6 #include <barvinok/options.h>
7 #include "decomposer.h"
8 #include "dpoly.h"
10 #ifdef NTL_STD_CXX
11 using namespace NTL;
12 #endif
14 struct gen_fun;
16 /* base for non-parametric counting */
17 struct np_base : public signed_cone_consumer {
18 unsigned dim;
19 ZZ one;
21 np_base(unsigned dim) {
22 this->dim = dim;
23 one = 1;
26 virtual void handle(const mat_ZZ& rays, Value *vertex, QQ c, int *closed,
27 barvinok_options *options) = 0;
28 virtual void handle(const signed_cone& sc, barvinok_options *options);
29 virtual void start(Polyhedron *P, barvinok_options *options);
30 void do_vertex_cone(const QQ& factor, Polyhedron *Cone,
31 Value *vertex, barvinok_options *options) {
32 current_vertex = vertex;
33 this->factor = factor;
34 barvinok_decompose(Cone, *this, options);
36 virtual void init(Polyhedron *P) {
38 virtual void get_count(Value *result) {
39 assert(0);
41 virtual ~np_base() {
44 private:
45 QQ factor;
46 Value *current_vertex;
49 struct reducer : public np_base {
50 vec_ZZ vertex;
51 //vec_ZZ den;
52 ZZ num;
53 mpq_t tcount;
54 mpz_t tn;
55 mpz_t td;
56 int lower; // call base when only this many variables is left
58 reducer(unsigned dim) : np_base(dim) {
59 //den.SetLength(dim);
60 mpq_init(tcount);
61 mpz_init(tn);
62 mpz_init(td);
65 ~reducer() {
66 mpq_clear(tcount);
67 mpz_clear(tn);
68 mpz_clear(td);
71 virtual void handle(const mat_ZZ& rays, Value *vertex, QQ c, int *closed,
72 barvinok_options *options);
73 void reduce(QQ c, vec_ZZ& num, const mat_ZZ& den_f);
74 virtual void base(QQ& c, const vec_ZZ& num, const mat_ZZ& den_f) = 0;
75 virtual void split(vec_ZZ& num, ZZ& num_s, vec_ZZ& num_p,
76 const mat_ZZ& den_f, vec_ZZ& den_s, mat_ZZ& den_r) = 0;
77 virtual gen_fun *get_gf() {
78 assert(0);
79 return NULL;
83 struct ireducer : public reducer {
84 ireducer(unsigned dim) : reducer(dim) {}
86 virtual void split(vec_ZZ& num, ZZ& num_s, vec_ZZ& num_p,
87 const mat_ZZ& den_f, vec_ZZ& den_s, mat_ZZ& den_r);
90 void normalize(ZZ& sign, ZZ& num_s, vec_ZZ& num_p, vec_ZZ& den_s, vec_ZZ& den_p,
91 mat_ZZ& f);
93 // incremental counter
94 struct icounter : public ireducer {
95 mpq_t count;
97 icounter(unsigned dim) : ireducer(dim) {
98 mpq_init(count);
99 lower = 1;
101 ~icounter() {
102 mpq_clear(count);
104 virtual void base(QQ& c, const vec_ZZ& num, const mat_ZZ& den_f);
105 virtual void get_count(Value *result) {
106 assert(value_one_p(&count[0]._mp_den));
107 value_assign(*result, &count[0]._mp_num);
111 void normalize(ZZ& sign, ZZ& num, vec_ZZ& den);
113 /* An incremental counter for possibly infinite sets.
114 * Rather than just keeping track of the constant term
115 * of the Laurent expansions, we also keep track of the
116 * coefficients of negative powers.
117 * If any of these is non-zero, then the counted set is infinite.
119 struct infinite_icounter : public ireducer {
120 /* an array of coefficients; count[i] is the coeffient of
121 * the term with power -i.
123 mpq_t *count;
124 unsigned len;
126 infinite_icounter(unsigned dim, unsigned maxlen) : ireducer(dim), len(maxlen+1) {
127 /* Not sure whether it works for dim != 1 */
128 assert(dim == 1);
129 count = new mpq_t[len];
130 for (int i = 0; i < len; ++i)
131 mpq_init(count[i]);
132 lower = 1;
134 ~infinite_icounter() {
135 for (int i = 0; i < len; ++i)
136 mpq_clear(count[i]);
137 delete [] count;
139 virtual void base(QQ& c, const vec_ZZ& num, const mat_ZZ& den_f);
142 #endif