
Module: ppl/ppl Branch: master Commit: 50030fba0045a46c3aad0dfc6d3906fbaa3590bf URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=50030fba0045a...
Author: Enea Zaffanella zaffanella@cs.unipr.it Date: Thu Mar 8 13:01:20 2012 +0100
Renamed Box methods get_{upper,lower}_bound() as has_{upper,lower}_bound(). Improved documentation: in particular, make clearer that undefined behavior is obtained when calling them on an empty box.
---
src/Box.defs.hh | 77 +++++++++++++++++++++++------------------- src/Box.inlines.hh | 8 ++-- src/Box.templates.hh | 10 +++--- src/Grid.templates.hh | 4 +- src/Polyhedron.templates.hh | 8 ++-- 5 files changed, 57 insertions(+), 50 deletions(-)
diff --git a/src/Box.defs.hh b/src/Box.defs.hh index cde52d0..4b5a4e3 100644 --- a/src/Box.defs.hh +++ b/src/Box.defs.hh @@ -1630,48 +1630,55 @@ public: void set_interval(Variable var, const ITV& i);
/*! \brief - If the <CODE>k</CODE>-th space dimension is unbounded below, returns - <CODE>false</CODE>. Otherwise returns <CODE>true</CODE> and set + If the <CODE>k</CODE>-th space dimension is unbounded below, return + <CODE>false</CODE>. Otherwise return <CODE>true</CODE> and set \p closed, \p n and \p d accordingly.
- Let \f$I\f$ the interval corresponding to the <CODE>k</CODE>-th - space dimension. If \f$I\f$ is not bounded from below, simply return - <CODE>false</CODE>. Otherwise, set <CODE>closed</CODE>, - <CODE>n</CODE> and <CODE>d</CODE> as follows: <CODE>closed</CODE> - is set to <CODE>true</CODE> if the the lower boundary of \f$I\f$ - is closed and is set to <CODE>false</CODE> otherwise; - <CODE>n</CODE> and <CODE>d</CODE> are assigned the integers - \f$n\f$ and \f$d\f$ such that the canonical fraction \f$n/d\f$ - corresponds to the greatest lower bound of \f$I\f$. The fraction - \f$n/d\f$ is in canonical form if and only if \f$n\f$ and \f$d\f$ - have no common factors and \f$d\f$ is positive, \f$0/1\f$ being - the unique representation for zero. - - An undefined behavior is obtained if \p k is greater than - or equal to the space dimension of \p *this. - */ - bool get_lower_bound(dimension_type k, bool& closed, + \note + It is assumed that <CODE>*this</CODE> is a non-empty box + having space dimension greater than \p k. An undefined behavior + is obtained if this assumption is not met. + + Let \f$I\f$ be the interval corresponding to the <CODE>k</CODE>-th + space dimension of the non-empty box <CODE>*this</CODE>. + If \f$I\f$ is not bounded from below, simply return <CODE>false</CODE> + (leaving all other parameters unchanged). + Otherwise, set \p closed, \p n and \p d as follows: + - \p closed is set to <CODE>true</CODE> if and only if the lower + boundary of \f$I\f$ is closed (i.e., it is included in the interval); + - \p n and \p d are assigned the integers \f$n\f$ and \f$d\f$ such + that the fraction \f$n/d\f$ corresponds to the greatest lower bound + of \f$I\f$. The fraction \f$n/d\f$ is in canonical form, meaning + that \f$n\f$ and \f$d\f$ have no common factors, \f$d\f$ is positive, + and if \f$n\f$ is zero then \f$d\f$ is one. + */ + bool has_lower_bound(dimension_type k, bool& closed, Coefficient& n, Coefficient& d) const;
/*! \brief - If the <CODE>k</CODE>-th space dimension is unbounded above, returns - <CODE>false</CODE>. Otherwise returns <CODE>true</CODE> and set + If the <CODE>k</CODE>-th space dimension is unbounded above, return + <CODE>false</CODE>. Otherwise return <CODE>true</CODE> and set \p closed, \p n and \p d accordingly.
- Let \f$I\f$ the interval corresponding to the <CODE>k</CODE>-th - space dimension. If \f$I\f$ is not bounded from above, simply return - <CODE>false</CODE>. Otherwise, set <CODE>closed</CODE>, - <CODE>n</CODE> and <CODE>d</CODE> as follows: <CODE>closed</CODE> - is set to <CODE>true</CODE> if the the upper boundary of \f$I\f$ - is closed and is set to <CODE>false</CODE> otherwise; - <CODE>n</CODE> and <CODE>d</CODE> are assigned the integers - \f$n\f$ and \f$d\f$ such that the canonical fraction \f$n/d\f$ - corresponds to the least upper bound of \f$I\f$. - - An undefined behavior is obtained if \p k is greater than - or equal to the space dimension of \p *this. - */ - bool get_upper_bound(dimension_type k, bool& closed, + \note + It is assumed that <CODE>*this</CODE> is a non-empty box + having space dimension greater than \p k. An undefined behavior + is obtained if this assumption is not met. + + Let \f$I\f$ be the interval corresponding to the <CODE>k</CODE>-th + space dimension of the non-empty box <CODE>*this</CODE>. + If \f$I\f$ is not bounded from above, simply return <CODE>false</CODE> + (leaving all other parameters unchanged). + Otherwise, set \p closed, \p n and \p d as follows: + - \p closed is set to <CODE>true</CODE> if and only if the upper + boundary of \f$I\f$ is closed (i.e., it is included in the interval); + - \p n and \p d are assigned the integers \f$n\f$ and \f$d\f$ such + that the fraction \f$n/d\f$ corresponds to the least upper bound + of \f$I\f$. The fraction \f$n/d\f$ is in canonical form, meaning + that \f$n\f$ and \f$d\f$ have no common factors, \f$d\f$ is positive, + and if \f$n\f$ is zero then \f$d\f$ is one. + */ + bool has_upper_bound(dimension_type k, bool& closed, Coefficient& n, Coefficient& d) const;
//! Returns a system of constraints defining \p *this. diff --git a/src/Box.inlines.hh b/src/Box.inlines.hh index b38e30f..8d0790c 100644 --- a/src/Box.inlines.hh +++ b/src/Box.inlines.hh @@ -264,9 +264,9 @@ operator!=(const Box<ITV>& x, const Box<ITV>& y) {
template <typename ITV> inline bool -Box<ITV>::get_lower_bound(const dimension_type k, bool& closed, +Box<ITV>::has_lower_bound(const dimension_type k, bool& closed, Coefficient& n, Coefficient& d) const { - PPL_ASSERT(k < seq.size()); + PPL_ASSERT(!is_empty() && k < seq.size()); const ITV& seq_k = seq[k];
if (seq_k.lower_is_boundary_infinity()) @@ -284,9 +284,9 @@ Box<ITV>::get_lower_bound(const dimension_type k, bool& closed,
template <typename ITV> inline bool -Box<ITV>::get_upper_bound(const dimension_type k, bool& closed, +Box<ITV>::has_upper_bound(const dimension_type k, bool& closed, Coefficient& n, Coefficient& d) const { - PPL_ASSERT(k < seq.size()); + PPL_ASSERT(!is_empty() && k < seq.size()); const ITV& seq_k = seq[k];
if (seq_k.upper_is_boundary_infinity()) diff --git a/src/Box.templates.hh b/src/Box.templates.hh index dc8bbd9..262e002 100644 --- a/src/Box.templates.hh +++ b/src/Box.templates.hh @@ -3873,13 +3873,13 @@ Box<ITV>::constraints() const { bool closed = false; PPL_DIRTY_TEMP(Coefficient, n); PPL_DIRTY_TEMP(Coefficient, d); - if (get_lower_bound(k, closed, n, d)) { + if (has_lower_bound(k, closed, n, d)) { if (closed) cs.insert(d*Variable(k) >= n); else cs.insert(d*Variable(k) > n); } - if (get_upper_bound(k, closed, n, d)) { + if (has_upper_bound(k, closed, n, d)) { if (closed) cs.insert(d*Variable(k) <= n); else @@ -3911,7 +3911,7 @@ Box<ITV>::minimized_constraints() const { bool closed = false; PPL_DIRTY_TEMP(Coefficient, n); PPL_DIRTY_TEMP(Coefficient, d); - if (get_lower_bound(k, closed, n, d)) { + if (has_lower_bound(k, closed, n, d)) { if (closed) // Make sure equality constraints are detected. if (seq[k].is_singleton()) { @@ -3923,7 +3923,7 @@ Box<ITV>::minimized_constraints() const { else cs.insert(d*Variable(k) > n); } - if (get_upper_bound(k, closed, n, d)) { + if (has_upper_bound(k, closed, n, d)) { if (closed) cs.insert(d*Variable(k) <= n); else @@ -3955,7 +3955,7 @@ Box<ITV>::congruences() const { bool closed = false; PPL_DIRTY_TEMP(Coefficient, n); PPL_DIRTY_TEMP(Coefficient, d); - if (get_lower_bound(k, closed, n, d) && closed) + if (has_lower_bound(k, closed, n, d) && closed) // Make sure equality congruences are detected. if (seq[k].is_singleton()) cgs.insert((d*Variable(k) %= n) / 0); diff --git a/src/Grid.templates.hh b/src/Grid.templates.hh index 8145c54..bc188ce 100644 --- a/src/Grid.templates.hh +++ b/src/Grid.templates.hh @@ -67,8 +67,8 @@ Grid::Grid(const Box<Interval>& box, Complexity_Class) // gen_sys.insert() at the end of the loop. bool closed = false; // TODO: Consider producing the system(s) in minimized form. - if (box.get_lower_bound(k, closed, l_n, l_d)) { - if (box.get_upper_bound(k, closed, u_n, u_d)) + if (box.has_lower_bound(k, closed, l_n, l_d)) { + if (box.has_upper_bound(k, closed, u_n, u_d)) if (l_n * u_d == u_n * l_d) { Grid_Generator& point = gen_sys[0]; // A point interval sets dimension k of every point to a diff --git a/src/Polyhedron.templates.hh b/src/Polyhedron.templates.hh index 51e7d25..015d70a 100644 --- a/src/Polyhedron.templates.hh +++ b/src/Polyhedron.templates.hh @@ -72,10 +72,10 @@ Polyhedron::Polyhedron(Topology topol, for (dimension_type k = space_dim; k-- > 0; ) { // See if we have a valid lower bound. bool l_closed = false; - bool l_bounded = box.get_lower_bound(k, l_closed, l_n, l_d); + bool l_bounded = box.has_lower_bound(k, l_closed, l_n, l_d); // See if we have a valid upper bound. bool u_closed = false; - bool u_bounded = box.get_upper_bound(k, u_closed, u_n, u_d); + bool u_bounded = box.has_upper_bound(k, u_closed, u_n, u_d);
// See if we have an implicit equality constraint. if (l_bounded && u_bounded @@ -99,10 +99,10 @@ Polyhedron::Polyhedron(Topology topol, for (dimension_type k = space_dim; k-- > 0; ) { // See if we have a valid lower bound. bool l_closed = false; - bool l_bounded = box.get_lower_bound(k, l_closed, l_n, l_d); + bool l_bounded = box.has_lower_bound(k, l_closed, l_n, l_d); // See if we have a valid upper bound. bool u_closed = false; - bool u_bounded = box.get_upper_bound(k, u_closed, u_n, u_d); + bool u_bounded = box.has_upper_bound(k, u_closed, u_n, u_d);
// See if we have an implicit equality constraint. if (l_bounded && u_bounded