3 struct counter_base
: public np_base
{
10 counter_base(unsigned dim
, unsigned long max_index
) : np_base(dim
) {
12 num
= Matrix_Alloc(max_index
, 1);
13 den
= Matrix_Alloc(dim
, 1);
14 lambda
= Vector_Alloc(dim
);
18 virtual void init(Polyhedron
*P
, int n_try
) {
20 randomvector(P
, l
, dim
, n_try
);
21 zz2values(l
, lambda
->p
);
24 virtual void reset() {
25 mpq_set_si(count
, 0, 0);
36 virtual void add_lattice_points(int sign
) = 0;
38 virtual void handle(const mat_ZZ
& rays
, Value
*vertex
, const QQ
& c
,
39 unsigned long det
, barvinok_options
*options
);
40 virtual void get_count(Value
*result
) {
41 assert(value_one_p(&count
[0]._mp_den
));
42 value_assign(*result
, &count
[0]._mp_num
);
46 struct counter
: public counter_base
{
47 counter(unsigned dim
, unsigned long max_index
) :
48 counter_base(dim
, max_index
) {}
50 virtual void add_lattice_points(int sign
);
53 struct tcounter
: public counter_base
{
59 tcounter(unsigned dim
, unsigned long max_index
) :
60 counter_base(dim
, max_index
), todd(dim
) {
66 void setup_todd(unsigned dim
);
68 void adapt_todd(dpoly
& t
, const Value c
);
69 void add_powers(dpoly
& n
, const Value c
);
73 Vector_Free(todd_denom
);
77 virtual void add_lattice_points(int sign
);
80 /* A counter for possibly infinite sets.
81 * Rather than just keeping track of the constant term
82 * of the Laurent expansions, we also keep track of the
83 * coefficients of negative powers.
84 * If any of these is non-zero, then the counted set is infinite.
86 struct infinite_counter
{
87 /* an array of coefficients; count[i] is the coeffient of
88 * the term with power -i.
95 infinite_counter(unsigned dim
, unsigned maxlen
) : maxlen(maxlen
) {
96 count
= new mpq_t
[maxlen
+1];
97 for (int i
= 0; i
<= maxlen
; ++i
)
102 void init(Polyhedron
*context
, int n_try
);
104 void reduce(const vec_QQ
& c
, const mat_ZZ
& num
, const mat_ZZ
& den_f
);
106 ~infinite_counter() {
107 for (int i
= 0; i
<= maxlen
; ++i
)