24 #ifndef PPL_wrap_assign_hh
25 #define PPL_wrap_assign_hh 1
31 #include "assertions.hh"
35 namespace Implementation {
42 Coefficient_traits::const_reference f,
43 Coefficient_traits::const_reference l)
44 : var(v), first_quadrant(f), last_quadrant(l) {
50 template <
typename PSET>
54 Wrap_Translations::const_iterator first,
55 Wrap_Translations::const_iterator end,
57 Coefficient_traits::const_reference min_value,
58 Coefficient_traits::const_reference max_value,
63 for (Wrap_Translations::const_iterator i = first; i != end; ++i) {
70 PSET hull(space_dim,
EMPTY);
71 for (quadrant = first_quadrant; quadrant <= last_quadrant; ++quadrant) {
75 p.affine_image(x, x - shift, 1);
83 p.refine_with_constraints(cs);
87 cs_end = cs.
end(); j != cs_end; ++j) {
88 if (j->expression().all_zeroes(vars)) {
90 p.refine_with_constraint(*j);
94 p.refine_with_constraint(min_value <= x);
95 p.refine_with_constraint(x <= max_value);
96 hull.upper_bound_assign(p);
98 pointset.m_swap(hull);
102 template <
typename PSET>
107 Wrap_Translations::const_iterator first,
108 Wrap_Translations::const_iterator end,
110 Coefficient_traits::const_reference min_value,
111 Coefficient_traits::const_reference max_value,
117 p.refine_with_constraints(*cs_p);
119 for (Variables_Set::const_iterator i = vars.begin(),
120 vars_end = vars.end(); i != vars_end; ++i) {
122 p.refine_with_constraint(min_value <= x);
123 p.refine_with_constraint(x <= max_value);
125 dest.upper_bound_assign(p);
134 for (quadrant = first_quadrant; quadrant <= last_quadrant; ++quadrant) {
138 p.affine_image(x, x - shift, 1);
143 wrap_assign_col(dest, src, vars, first+1, end, w, min_value, max_value,
150 template <
typename PSET>
158 const unsigned complexity_threshold,
159 const bool wrap_individually,
160 const char* class_name) {
168 std::ostringstream s;
169 s <<
"PPL::" << class_name <<
"::wrap_assign(..., cs_p, ...):"
171 <<
"vars.space_dimension() == " << vars_space_dim
173 throw std::invalid_argument(s.str());
181 Variables_Set::const_iterator vars_end = vars.end();
183 cs_end = cs.
end(); i != cs_end; ++i) {
187 || vars.find(d) != vars_end);
196 pointset.refine_with_constraints(*cs_p);
204 std::ostringstream s;
205 s <<
"PPL::" << class_name <<
"::wrap_assign(vs, ...):" << std::endl
206 <<
"this->space_dimension() == " << space_dim
208 throw std::invalid_argument(s.str());
212 if (pointset.is_empty()) {
234 Wrap_Translations translations;
245 unsigned collective_wrap_complexity = 1;
249 bool collective_wrap_too_complex =
false;
251 if (!wrap_individually) {
252 translations.reserve(space_dim);
264 for (Variables_Set::const_iterator i = vars.begin(),
265 vars_end = vars.end(); i != vars_end; ++i) {
271 if (!pointset.minimize(x, l_n, l_d, extremum)) {
273 pointset.unconstrain(x);
274 full_range_bounds.
insert(min_value <= x);
275 full_range_bounds.
insert(x <= max_value);
279 if (!pointset.maximize(x, u_n, u_d, extremum)) {
293 if (first_quadrant == 0 && last_quadrant == 0) {
299 if (first_quadrant < 0) {
300 full_range_bounds.
insert(min_value <= x);
302 if (last_quadrant > 0) {
303 full_range_bounds.
insert(x <= max_value);
313 quadrants = last_quadrant - first_quadrant + 1;
321 if (!wrap_individually && !collective_wrap_too_complex) {
322 res = mul_assign_r(collective_wrap_complexity,
325 || collective_wrap_complexity > complexity_threshold) {
326 collective_wrap_too_complex =
true;
328 if (collective_wrap_too_complex) {
330 for (Wrap_Translations::const_iterator j = translations.begin(),
331 translations_end = translations.end();
332 j != translations_end;
335 pointset.unconstrain(y);
336 full_range_bounds.
insert(min_value <= y);
337 full_range_bounds.
insert(y <= max_value);
342 if (wrap_individually && cs_p == 0) {
347 PSET hull(space_dim,
EMPTY);
348 for ( ; quadrant <= last_quadrant; ++quadrant) {
352 p.affine_image(x, x - shift, 1);
354 p.refine_with_constraint(min_value <= x);
355 p.refine_with_constraint(x <= max_value);
356 hull.upper_bound_assign(p);
358 pointset.m_swap(hull);
360 else if (wrap_individually || !collective_wrap_too_complex) {
361 PPL_ASSERT(!wrap_individually || cs_p != 0);
362 dimensions_to_be_translated.
insert(x);
368 if (!translations.empty()) {
369 if (wrap_individually) {
370 PPL_ASSERT(cs_p != 0);
372 translations.begin(), translations.end(),
373 w, min_value, max_value, *cs_p, l_n, l_d);
376 PSET hull(space_dim,
EMPTY);
378 translations.begin(), translations.end(),
379 w, min_value, max_value, cs_p, l_n);
380 pointset.m_swap(hull);
385 pointset.refine_with_constraints(*cs_p);
387 pointset.refine_with_constraints(full_range_bounds);
394 #endif // !defined(PPL_wrap_assign_hh)
int result_overflow(Result r)
Enable_If< Is_Native_Or_Checked< To >::value &&Is_Special< From >::value, Result >::type assign_r(To &to, const From &, Rounding_Dir dir)
An iterator over a system of constraints.
dimension_type space_dimension() const
Returns the dimension of the smallest vector space enclosing all the variables whose indexes are in t...
The empty element, i.e., the empty set.
void wrap_assign_ind(PSET &pointset, Variables_Set &vars, Wrap_Translations::const_iterator first, Wrap_Translations::const_iterator end, Bounded_Integer_Type_Width w, Coefficient_traits::const_reference min_value, Coefficient_traits::const_reference max_value, const Constraint_System &cs, Coefficient &tmp1, Coefficient &tmp2)
A linear equality or inequality.
size_t dimension_type
An unsigned integral type for representing space dimensions.
An std::set of variables' indexes.
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
Declare a local variable named id, of type Coefficient, and containing an unknown initial value...
void insert(const Constraint &c)
Inserts in *this a copy of the constraint c, increasing the number of space dimensions if needed...
Result
Possible outcomes of a checked arithmetic computation.
const_iterator begin() const
Returns the const_iterator pointing to the first constraint, if *this is not empty; otherwise...
Coefficient_traits::const_reference coefficient(Variable v) const
Returns the coefficient of v in *this.
dimension_type id() const
Returns the index of the Cartesian axis associated to the variable.
A dimension of the vector space.
Bounded_Integer_Type_Overflow
On overflow, the result is undefined.
void wrap_assign_col(PSET &dest, const PSET &src, const Variables_Set &vars, Wrap_Translations::const_iterator first, Wrap_Translations::const_iterator end, Bounded_Integer_Type_Width w, Coefficient_traits::const_reference min_value, Coefficient_traits::const_reference max_value, const Constraint_System *cs_p, Coefficient &tmp)
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
Bounded_Integer_Type_Width
const_iterator end() const
Returns the past-the-end const_iterator.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
void wrap_assign(PSET &pointset, const Variables_Set &vars, const Bounded_Integer_Type_Width w, const Bounded_Integer_Type_Representation r, const Bounded_Integer_Type_Overflow o, const Constraint_System *cs_p, const unsigned complexity_threshold, const bool wrap_individually, const char *class_name)
void mul_2exp_assign(GMP_Integer &x, const GMP_Integer &y, unsigned int exp)
Coefficient first_quadrant
void neg_assign(GMP_Integer &x)
The entire library is confined to this namespace.
void insert(Variable v)
Inserts the index of variable v into the set.
Signed binary where negative values are represented by the two's complement of the absolute value...
Wrap_Dim_Translations(Variable v, Coefficient_traits::const_reference f, Coefficient_traits::const_reference l)
Coefficient_traits::const_reference Coefficient_one()
Returns a const reference to a Coefficient with value 1.
#define PPL_UNINITIALIZED(type, name)
std::vector< Wrap_Dim_Translations > Wrap_Translations
Bounded_Integer_Type_Representation
Coefficient last_quadrant