2 #include "omega_interface/convert.h"
4 static void max_index(Constraint_Handle c
, varvector
& vv
, varvector
& params
)
6 for (Constr_Vars_Iter
cvi(c
); cvi
; ++cvi
) {
7 Variable_ID var
= (*cvi
).var
;
8 if (find(vv
.begin(), vv
.end(), var
) == vv
.end() &&
9 find(params
.begin(), params
.end(), var
) == params
.end())
14 static void set_constraint(Matrix
*M
, int row
,
15 Constraint_Handle c
, varvector
& vv
, int geq
)
17 value_set_si(M
->p
[row
][0], geq
);
18 for (int i
= 0; i
< vv
.size(); ++i
)
19 value_set_si(M
->p
[row
][1+i
], c
.get_coef(vv
[i
]));
20 value_set_si(M
->p
[row
][1+vv
.size()], c
.get_const());
23 Polyhedron
*relation2Domain(Relation
& r
, varvector
& vv
, varvector
& params
,
29 Polyhedron
**next
= &D
;
34 for (int j
= 1; j
<= r
.n_set(); ++j
)
35 vv
.push_back(r
.set_var(j
));
37 for (int j
= 1; j
<= r
.n_inp(); ++j
)
38 vv
.push_back(r
.input_var(j
));
39 for (int j
= 1; j
<= r
.n_out(); ++j
)
40 vv
.push_back(r
.output_var(j
));
44 const Variable_ID_Tuple
* globals
= r
.global_decls();
45 for (int i
= 0; i
< globals
->size(); ++i
)
46 params
.push_back(r
.get_local((*globals
)[i
+1]));
49 for (DNF_Iterator
di(r
.query_DNF()); di
; ++di
) {
51 for (EQ_Iterator ei
= (*di
)->EQs(); ei
; ++ei
)
52 max_index((*ei
), vv
, params
);
53 for (GEQ_Iterator gi
= (*di
)->GEQs(); gi
; ++gi
)
54 max_index((*gi
), vv
, params
);
55 if (vv
.size() > max_size
)
59 for (DNF_Iterator
di(r
.query_DNF()); di
; ++di
) {
64 for (EQ_Iterator ei
= (*di
)->EQs(); ei
; ++ei
, ++c
)
65 max_index((*ei
), vv
, params
);
66 for (GEQ_Iterator gi
= (*di
)->GEQs(); gi
; ++gi
, ++c
)
67 max_index((*gi
), vv
, params
);
68 for (int i
= 0; i
< params
.size(); ++i
)
69 vv
.push_back(params
[i
]);
71 Matrix
*M
= Matrix_Alloc(c
, vv
.size() + 2);
73 for (EQ_Iterator ei
= (*di
)->EQs(); ei
; ++ei
)
74 set_constraint(M
, row
++, (*ei
), vv
, 0);
75 for (GEQ_Iterator gi
= (*di
)->GEQs(); gi
; ++gi
)
76 set_constraint(M
, row
++, (*gi
), vv
, 1);
77 *next
= Constraints2Polyhedron(M
, MaxRays
);
79 next
= &(*next
)->next
;
85 typedef std::vector
<Global_Var_Decl
*> globalvector
;
87 static void create_globals(globalvector
& globals
, unsigned nparam
,
90 for (int i
= 0; i
< nparam
; ++i
)
91 globals
.push_back(new Global_Var_Decl(params
[i
]));
94 Relation
Polyhedron2relation(Polyhedron
*P
,
95 unsigned exist
, globalvector
& globals
)
97 int nvar
= P
->Dimension
- exist
- globals
.size();
101 F_Exists
*e
= r
.add_exists();
102 F_And
*base
= e
->add_and();
104 for (int j
= 1; j
<= r
.n_set(); ++j
)
105 vars
.push_back(r
.set_var(j
));
106 for (int i
= 0; i
< exist
; ++i
)
107 vars
.push_back(e
->declare());
108 for (int i
= 0; i
< globals
.size(); ++i
)
109 vars
.push_back(r
.get_local(globals
[i
]));
111 for (int i
= 0; i
< P
->NbConstraints
; ++i
) {
113 if (value_notzero_p(P
->Constraint
[i
][0]))
117 for (int j
= 1; j
<= P
->Dimension
; ++j
)
118 h
.update_coef(vars
[j
-1], VALUE_TO_INT(P
->Constraint
[i
][j
]));
119 h
.update_const(VALUE_TO_INT(P
->Constraint
[i
][1+P
->Dimension
]));
125 Relation
Polyhedron2relation(Polyhedron
*P
,
126 unsigned exist
, unsigned nparam
, const char **params
)
128 globalvector globals
;
129 create_globals(globals
, nparam
, params
);
130 return Polyhedron2relation(P
, exist
, globals
);
133 Relation
Domain2relation(Polyhedron
*D
, unsigned nvar
, unsigned nparam
,
136 globalvector globals
;
137 create_globals(globals
, nparam
, params
);
139 Relation r
= Polyhedron2relation(D
, D
->Dimension
- nvar
- nparam
,
141 for (Polyhedron
*P
= D
->next
; P
; P
= P
->next
) {
142 Relation s
= Polyhedron2relation(P
, P
->Dimension
- nvar
- nparam
,