summate.c: sum_base: check equality constraints in Param_Polyhedron
[barvinok.git] / edomain.h
blobe518b4662ea6620515dd3344a98de2c504e6f628
1 #include <iostream>
2 #include <vector>
3 #include <barvinok/evalue.h>
4 #include <barvinok/options.h>
5 #include "lexmin.h"
7 struct EDomain_floor {
8 bool substituted; // see substitute method
9 int refcount;
10 evalue *e;
11 /* first element is denominator */
12 Vector *v;
14 EDomain_floor(const evalue *f, int dim);
15 ~EDomain_floor() {
16 free_evalue_refs(e);
17 delete e;
18 Vector_Free(v);
20 EDomain_floor *ref() {
21 ++refcount;
22 return this;
24 static void unref(EDomain_floor* floor) {
25 if (!--floor->refcount)
26 delete floor;
28 void print(std::ostream& os, char **p) const;
29 void eval(Value *values, Value *res) const;
30 void substitute(evalue **sub, Matrix *T);
33 struct EDomain;
35 struct ge_constraint {
36 const EDomain * const D;
37 Matrix *M;
38 std::vector<EDomain_floor *> new_floors;
39 bool simplified;
41 ge_constraint(const EDomain *const D) : D(D) {}
42 ~ge_constraint() {
43 for (int i = 0; i < new_floors.size(); ++i)
44 EDomain_floor::unref(new_floors[i]);
45 Matrix_Free(M);
49 struct EDomain {
50 Polyhedron *D;
51 Vector *sample;
52 std::vector<EDomain_floor *> floors;
54 EDomain(Polyhedron *D) {
55 this->D = Polyhedron_Copy(D);
56 sample = NULL;
58 EDomain(Polyhedron *D, std::vector<EDomain_floor *>floors) {
59 this->D = Polyhedron_Copy(D);
60 add_floors(floors);
61 sample = NULL;
63 EDomain(EDomain *ED) {
64 this->D = Polyhedron_Copy(ED->D);
65 add_floors(ED->floors);
66 sample = NULL;
68 static EDomain *new_from_ge_constraint(ge_constraint *ge, int sign,
69 barvinok_options *options);
70 EDomain(Polyhedron *D, const EDomain *const ED,
71 std::vector<EDomain_floor *>floors) {
72 this->D = Polyhedron_Copy(D);
73 add_floors(ED->floors);
74 add_floors(floors);
75 sample = NULL;
77 void add_floors(std::vector<EDomain_floor *>floors) {
78 for (int i = 0; i < floors.size(); ++i)
79 this->floors.push_back(floors[i]->ref());
81 int find_floor(evalue *needle) const {
82 for (int i = 0; i < floors.size(); ++i)
83 if (eequal(needle, floors[i]->e))
84 return i;
85 return -1;
87 //void print(FILE *out, char **p);
88 void print_constraints(std::ostream& os, char **p,
89 barvinok_options *options) const;
90 ~EDomain() {
91 for (int i = 0; i < floors.size(); ++i)
92 EDomain_floor::unref(floors[i]);
93 Polyhedron_Free(D);
94 if (sample)
95 Vector_Free(sample);
98 unsigned dimension() const {
99 return D->Dimension - floors.size();
101 bool contains(Value *point, int len) const;
103 ge_constraint *compute_ge_constraint(evalue *constraint) const;
104 void substitute(evalue **sub, Matrix *T, Matrix *Eq, unsigned MaxRays);
105 bool not_empty(lexmin_options *options);
108 int evalue2constraint(EDomain *D, evalue *E, Value *cons, int len);