lexmin.cc: drop unused compress_parameters
[barvinok.git] / reducer.h
blobc23021d3f51630272fd7b65d49f005d172e9697a
1 #ifndef REDUCER_H
2 #define REDUCER_H
4 #include <assert.h>
5 #include <NTL/mat_ZZ.h>
6 #include <barvinok/NTL_QQ.h>
7 #include <barvinok/options.h>
8 #include "decomposer.h"
9 #include "dpoly.h"
11 using namespace NTL;
13 struct gen_fun;
15 extern struct OrthogonalException {} Orthogonal;
17 /* base for non-parametric counting */
18 struct np_base : public signed_cone_consumer {
19 unsigned dim;
21 np_base(unsigned dim) {
22 assert(dim > 0);
23 this->dim = dim;
26 virtual void handle(const mat_ZZ& rays, Value *vertex, const QQ& c,
27 unsigned long det,
28 barvinok_options *options) = 0;
29 virtual void handle(const signed_cone& sc, barvinok_options *options);
30 virtual void start(Polyhedron *P, barvinok_options *options);
31 void do_vertex_cone(const QQ& factor, Polyhedron *Cone,
32 Value *vertex, barvinok_options *options) {
33 current_vertex = vertex;
34 this->factor = factor;
35 barvinok_decompose(Cone, *this, options);
37 virtual void init(Polyhedron *P, int n_try) {
39 virtual void reset() {
40 assert(0);
42 virtual void get_count(Value *result) {
43 assert(0);
45 virtual ~np_base() {
48 private:
49 QQ factor;
50 Value *current_vertex;
53 struct reducer : public np_base {
54 mat_ZZ vertex;
55 mpq_t tcount;
56 mpz_t tn;
57 mpz_t td;
58 int lower; // call base when only this many variables is left
59 Value tz;
61 reducer(unsigned dim) : np_base(dim) {
62 vertex.SetDims(1, dim);
63 mpq_init(tcount);
64 mpz_init(tn);
65 mpz_init(td);
66 value_init(tz);
69 ~reducer() {
70 value_clear(tz);
71 mpq_clear(tcount);
72 mpz_clear(tn);
73 mpz_clear(td);
76 virtual void handle(const mat_ZZ& rays, Value *vertex, const QQ& c,
77 unsigned long det, barvinok_options *options);
78 void reduce(const vec_QQ& c, const mat_ZZ& num, const mat_ZZ& den_f);
79 void reduce_canonical(const vec_QQ& c, const mat_ZZ& num,
80 const mat_ZZ& den_f);
81 virtual void base(const QQ& c, const vec_ZZ& num, const mat_ZZ& den_f) = 0;
82 virtual void base(const vec_QQ& c, const mat_ZZ& num, const mat_ZZ& den_f);
83 virtual void split(const mat_ZZ& num, vec_ZZ& num_s, mat_ZZ& num_p,
84 const mat_ZZ& den_f, vec_ZZ& den_s, mat_ZZ& den_r) = 0;
85 virtual gen_fun *get_gf() {
86 assert(0);
87 return NULL;
91 void split_one(const mat_ZZ& num, vec_ZZ& num_s, mat_ZZ& num_p,
92 const mat_ZZ& den_f, vec_ZZ& den_s, mat_ZZ& den_r);
94 struct ireducer : public reducer {
95 ireducer(unsigned dim) : reducer(dim) {}
97 virtual void split(const mat_ZZ& num, vec_ZZ& num_s, mat_ZZ& num_p,
98 const mat_ZZ& den_f, vec_ZZ& den_s, mat_ZZ& den_r) {
99 split_one(num, num_s, num_p, den_f, den_s, den_r);
103 void normalize(ZZ& sign, vec_ZZ& num_s, mat_ZZ& num_p, vec_ZZ& den_s, vec_ZZ& den_p,
104 mat_ZZ& f);
106 // incremental counter
107 struct icounter : public ireducer {
108 mpq_t count;
110 icounter(unsigned dim) : ireducer(dim) {
111 mpq_init(count);
112 lower = 1;
114 ~icounter() {
115 mpq_clear(count);
117 virtual void base(const QQ& c, const vec_ZZ& num, const mat_ZZ& den_f);
118 virtual void get_count(Value *result) {
119 assert(value_one_p(&count[0]._mp_den));
120 value_assign(*result, &count[0]._mp_num);
124 #endif