1 #include <NTL/vec_ZZ.h>
2 #include <NTL/mat_ZZ.h>
3 #include <barvinok/polylib.h>
6 struct counter_base
: public np_base
{
13 counter_base(unsigned dim
, unsigned long max_index
) : np_base(dim
) {
15 num
= Matrix_Alloc(max_index
, 1);
16 den
= Matrix_Alloc(dim
, 1);
17 lambda
= Vector_Alloc(dim
);
21 virtual void init(Polyhedron
*P
, int n_try
) {
23 randomvector(P
, l
, dim
, n_try
);
24 zz2values(l
, lambda
->p
);
27 virtual void reset() {
28 mpq_set_si(count
, 0, 0);
39 virtual void add_lattice_points(int sign
) = 0;
41 virtual void handle(const mat_ZZ
& rays
, Value
*vertex
, const QQ
& c
,
42 unsigned long det
, barvinok_options
*options
);
43 virtual void get_count(Value
*result
) {
44 assert(value_one_p(&count
[0]._mp_den
));
45 value_assign(*result
, &count
[0]._mp_num
);
49 struct counter
: public counter_base
{
50 counter(unsigned dim
, unsigned long max_index
) :
51 counter_base(dim
, max_index
) {}
53 virtual void add_lattice_points(int sign
);
56 struct tcounter
: public counter_base
{
62 tcounter(unsigned dim
, unsigned long max_index
) :
63 counter_base(dim
, max_index
), todd(dim
) {
69 void setup_todd(unsigned dim
);
71 void adapt_todd(dpoly
& t
, const Value c
);
72 void add_powers(dpoly
& n
, const Value c
);
76 Vector_Free(todd_denom
);
80 virtual void add_lattice_points(int sign
);
83 /* A counter for possibly infinite sets.
84 * Rather than just keeping track of the constant term
85 * of the Laurent expansions, we also keep track of the
86 * coefficients of negative powers.
87 * If any of these is non-zero, then the counted set is infinite.
89 struct infinite_counter
{
90 /* an array of coefficients; count[i] is the coeffient of
91 * the term with power -i.
98 infinite_counter(unsigned dim
, unsigned maxlen
) : maxlen(maxlen
) {
99 count
= new mpq_t
[maxlen
+1];
100 for (int i
= 0; i
<= maxlen
; ++i
)
105 void init(Polyhedron
*context
, int n_try
);
107 void reduce(const vec_QQ
& c
, const mat_ZZ
& num
, const mat_ZZ
& den_f
);
109 ~infinite_counter() {
110 for (int i
= 0; i
<= maxlen
; ++i
)