lexmin: optionally use cdd during basis reduction
[barvinok.git] / edomain.h
blobb5d66d297b3f85a1a4cb4c9d4787300b36501224
1 #include <iostream>
2 #include <vector>
3 #include <gmp.h>
4 extern "C" {
5 #include <polylib/polylibgmp.h>
7 #include <barvinok/evalue.h>
8 #include <barvinok/options.h>
10 struct EDomain_floor {
11 bool substituted; // see substitute method
12 int refcount;
13 evalue *e;
14 /* first element is denominator */
15 Vector *v;
17 EDomain_floor(const evalue *f, int dim);
18 ~EDomain_floor() {
19 free_evalue_refs(e);
20 delete e;
21 Vector_Free(v);
23 EDomain_floor *ref() {
24 ++refcount;
25 return this;
27 static void unref(EDomain_floor* floor) {
28 if (!--floor->refcount)
29 delete floor;
31 void print(std::ostream& os, char **p) const;
32 void eval(Value *values, Value *res) const;
33 void substitute(evalue **sub, Matrix *T);
36 struct EDomain {
37 Polyhedron *D;
38 Vector *sample;
39 std::vector<EDomain_floor *> floors;
41 EDomain(Polyhedron *D) {
42 this->D = Polyhedron_Copy(D);
43 sample = NULL;
45 EDomain(Polyhedron *D, std::vector<EDomain_floor *>floors) {
46 this->D = Polyhedron_Copy(D);
47 add_floors(floors);
48 sample = NULL;
50 EDomain(EDomain *ED) {
51 this->D = Polyhedron_Copy(ED->D);
52 add_floors(ED->floors);
53 sample = NULL;
55 EDomain(Polyhedron *D, EDomain *ED, std::vector<EDomain_floor *>floors) {
56 this->D = Polyhedron_Copy(D);
57 add_floors(ED->floors);
58 add_floors(floors);
59 sample = NULL;
61 void add_floors(std::vector<EDomain_floor *>floors) {
62 for (int i = 0; i < floors.size(); ++i)
63 this->floors.push_back(floors[i]->ref());
65 int find_floor(evalue *needle) const {
66 for (int i = 0; i < floors.size(); ++i)
67 if (eequal(needle, floors[i]->e))
68 return i;
69 return -1;
71 void print(FILE *out, char **p);
72 void print_constraints(std::ostream& os, char **p,
73 barvinok_options *options) const;
74 ~EDomain() {
75 for (int i = 0; i < floors.size(); ++i)
76 EDomain_floor::unref(floors[i]);
77 Polyhedron_Free(D);
78 if (sample)
79 Vector_Free(sample);
82 unsigned dimension() const {
83 return D->Dimension - floors.size();
85 bool contains(Value *point, int len) const;
87 Matrix *add_ge_constraint(evalue *constraint,
88 std::vector<EDomain_floor *>& new_floors) const;
89 void substitute(evalue **sub, Matrix *T, Matrix *Eq, unsigned MaxRays);
92 int evalue2constraint(EDomain *D, evalue *E, Value *cons, int len);
93 void evalue_substitute(evalue *e, evalue **subs);