vertex_cone: check that dimension is at least one
[barvinok.git] / edomain.h
blob6fcbdb853c748aa753ae9b1842fc1a9ec42de77c
1 #include <iostream>
2 #include <vector>
3 #include <gmp.h>
4 #include <barvinok/evalue.h>
5 #include <barvinok/options.h>
6 #include "lexmin.h"
8 struct EDomain_floor {
9 bool substituted; // see substitute method
10 int refcount;
11 evalue *e;
12 /* first element is denominator */
13 Vector *v;
15 EDomain_floor(const evalue *f, int dim);
16 ~EDomain_floor() {
17 free_evalue_refs(e);
18 delete e;
19 Vector_Free(v);
21 EDomain_floor *ref() {
22 ++refcount;
23 return this;
25 static void unref(EDomain_floor* floor) {
26 if (!--floor->refcount)
27 delete floor;
29 void print(std::ostream& os, char **p) const;
30 void eval(Value *values, Value *res) const;
31 void substitute(evalue **sub, Matrix *T);
34 struct EDomain;
36 struct ge_constraint {
37 const EDomain * const D;
38 Matrix *M;
39 std::vector<EDomain_floor *> new_floors;
40 bool simplified;
42 ge_constraint(const EDomain *const D) : D(D) {}
43 ~ge_constraint() {
44 for (int i = 0; i < new_floors.size(); ++i)
45 EDomain_floor::unref(new_floors[i]);
46 Matrix_Free(M);
50 struct EDomain {
51 Polyhedron *D;
52 Vector *sample;
53 std::vector<EDomain_floor *> floors;
55 EDomain(Polyhedron *D) {
56 this->D = Polyhedron_Copy(D);
57 sample = NULL;
59 EDomain(Polyhedron *D, std::vector<EDomain_floor *>floors) {
60 this->D = Polyhedron_Copy(D);
61 add_floors(floors);
62 sample = NULL;
64 EDomain(EDomain *ED) {
65 this->D = Polyhedron_Copy(ED->D);
66 add_floors(ED->floors);
67 sample = NULL;
69 static EDomain *new_from_ge_constraint(ge_constraint *ge, int sign,
70 barvinok_options *options);
71 EDomain(Polyhedron *D, const EDomain *const ED,
72 std::vector<EDomain_floor *>floors) {
73 this->D = Polyhedron_Copy(D);
74 add_floors(ED->floors);
75 add_floors(floors);
76 sample = NULL;
78 void add_floors(std::vector<EDomain_floor *>floors) {
79 for (int i = 0; i < floors.size(); ++i)
80 this->floors.push_back(floors[i]->ref());
82 int find_floor(evalue *needle) const {
83 for (int i = 0; i < floors.size(); ++i)
84 if (eequal(needle, floors[i]->e))
85 return i;
86 return -1;
88 //void print(FILE *out, char **p);
89 void print_constraints(std::ostream& os, char **p,
90 barvinok_options *options) const;
91 ~EDomain() {
92 for (int i = 0; i < floors.size(); ++i)
93 EDomain_floor::unref(floors[i]);
94 Polyhedron_Free(D);
95 if (sample)
96 Vector_Free(sample);
99 unsigned dimension() const {
100 return D->Dimension - floors.size();
102 bool contains(Value *point, int len) const;
104 ge_constraint *compute_ge_constraint(evalue *constraint) const;
105 void substitute(evalue **sub, Matrix *T, Matrix *Eq, unsigned MaxRays);
106 bool not_empty(lexmin_options *options);
109 int evalue2constraint(EDomain *D, evalue *E, Value *cons, int len);