Module: ppl/ppl Branch: products Commit: c7f4b16d84c83be74fb0e62080e2d22b51d170a6 URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=c7f4b16d84c83... Author: Patricia Hill <p.m.hill@leeds.ac.uk> Date: Thu May 14 07:41:22 2009 +0100 Added new method frequency() for Grids. --- src/Grid.defs.hh | 33 +++++++++++++++++++++++++++++++++ src/Grid_public.cc | 26 ++++++++++++++++++++++++++ tests/Grid/Makefile.am | 3 +++ 3 files changed, 62 insertions(+), 0 deletions(-) diff --git a/src/Grid.defs.hh b/src/Grid.defs.hh index 3049c31..0ad5277 100644 --- a/src/Grid.defs.hh +++ b/src/Grid.defs.hh @@ -861,6 +861,39 @@ public: Coefficient& inf_n, Coefficient& inf_d, bool& minimum, Generator& point) const; + /*! \brief + Returns <CODE>true</CODE> if and only if \p *this is not empty and + \p expr is discrete in \p *this, in which case the maximum frequency + and the value for \p expr that is closest to zero are computed. + + \param expr + The linear expression for which the frequency is needed; + + \param freq_n + The numerator of the maximum frequency of \p expr; + + \param freq_d + The denominator of the maximum frequency of \p expr; + + \param val_n + The numerator of a value of \p expr at a point in the grid + that is closest to zero; + + \param val_d + The denominator of a value of \p expr at a point in the grid + that is closest to zero; + + \exception std::invalid_argument + Thrown if \p expr and \p *this are dimension-incompatible. + + If \p *this is empty or \p expr can take any real number in \p *this, + <CODE>false</CODE> is returned and \p freq_n, \p freq_d, + \p val_n and \p val_d are left untouched. + */ + bool frequency(const Linear_Expression& expr, + Coefficient& freq_n, Coefficient& freq_d, + Coefficient& val_n, Coefficient& val_d) const; + //! Returns <CODE>true</CODE> if and only if \p *this contains \p y. /*! \exception std::invalid_argument diff --git a/src/Grid_public.cc b/src/Grid_public.cc index 16e6ba9..24a53f6 100644 --- a/src/Grid_public.cc +++ b/src/Grid_public.cc @@ -2475,6 +2475,32 @@ PPL::Grid::time_elapse_assign(const Grid& y) { assert(x.OK(true) && y.OK(true)); } +bool +PPL::Grid::frequency(const Linear_Expression& expr, + Coefficient& freq_n, Coefficient& freq_d, + Coefficient& val_n, Coefficient& val_d) const { + // The dimension of `expr' must be at most the dimension of *this. + if (space_dim < expr.space_dimension()) + throw_dimension_incompatible("frequency(e, ...)", "e", expr); + + // Space dimension = 0: if empty, then return false; + // otherwise the frequency is 1 and the value is 0 + if (space_dim == 0) { + if (is_empty()) + return false; + freq_n = 0; + freq_d = 1; + val_n = 0; + val_d = 1; + return true; + } + if (!generators_are_minimized() && !minimize()) + // Minimizing found `this' empty. + return false; + + return frequency_no_check(expr, freq_n, freq_d, val_n, val_d); +} + /*! \relates Parma_Polyhedra_Library::Grid */ bool PPL::operator==(const Grid& x, const Grid& y) { diff --git a/tests/Grid/Makefile.am b/tests/Grid/Makefile.am index 7189082..74bab01 100644 --- a/tests/Grid/Makefile.am +++ b/tests/Grid/Makefile.am @@ -81,6 +81,7 @@ disjoint1 \ equals1 \ expandspacedim1 \ foldspacedims1 \ +frequency1 \ frombdshape1 \ frombox1 \ fromgrid1 \ @@ -191,6 +192,8 @@ equals1_SOURCES = equals1.cc expandspacedim1_SOURCES = expandspacedim1.cc +frequency1_SOURCES = frequency1.cc + frombdshape1_SOURCES = frombdshape1.cc frombox1_SOURCES = frombox1.cc