
Module: ppl/ppl Branch: pip Commit: d11a14fc05769502dcb4332b2d2336681e57f229 URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=d11a14fc05769...
Author: Enea Zaffanella zaffanella@cs.unipr.it Date: Sat Jan 30 20:39:36 2010 +0100
Improved consistency checks in method PIP_Solution_Node::Tableau::OK(). Prefer using Coefficient_traits::const_reference in parameter passing.
---
src/PIP_Tree.cc | 39 +++++++++++++++++++++++++-------------- src/PIP_Tree.defs.hh | 16 +++++++++------- src/PIP_Tree.inlines.hh | 12 +++++------- 3 files changed, 39 insertions(+), 28 deletions(-)
diff --git a/src/PIP_Tree.cc b/src/PIP_Tree.cc index 36a60a8..800992b 100644 --- a/src/PIP_Tree.cc +++ b/src/PIP_Tree.cc @@ -32,9 +32,10 @@ namespace {
// Calculate positive modulo of x % y void -mod_assign(Coefficient &z, Coefficient_traits::const_reference x, +mod_assign(Coefficient &z, + Coefficient_traits::const_reference x, Coefficient_traits::const_reference y) { - z = x%y; + z = x % y; if (z < 0) z += y; } @@ -79,7 +80,7 @@ merge_assign(Matrix& x,
// Tranform expression "expr" into "-expr-1", using scaling void -negate_assign(Row& x, const Row& y, const Coefficient& sc) { +negate_assign(Row& x, const Row& y, Coefficient_traits::const_reference sc) { PPL_ASSERT(x.size() == y.size()); for (dimension_type i = x.size(); i-- > 0; ) x[i] = -y[i]; @@ -125,8 +126,8 @@ column_lower(const Matrix& tableau, dimension_type ja, const Row& pivot_b, dimension_type jb, - const Coefficient& cst_a = -1, - const Coefficient& cst_b = -1) { + Coefficient_traits::const_reference cst_a = -1, + Coefficient_traits::const_reference cst_b = -1) { PPL_DIRTY_TEMP_COEFFICIENT(cij_a); PPL_DIRTY_TEMP_COEFFICIENT(cij_b); const Coefficient& sij_a = pivot_a[ja]; @@ -237,7 +238,8 @@ PIP_Tree_Node::Artificial_Parameter::Artificial_Parameter() }
PIP_Tree_Node::Artificial_Parameter -::Artificial_Parameter(const Linear_Expression &e, const Coefficient &d) +::Artificial_Parameter(const Linear_Expression &e, + Coefficient_traits::const_reference d) : Linear_Expression(e), denominator(d) { }
@@ -424,20 +426,29 @@ PIP_Tree_Node::insert_artificials(Variables_Set ¶ms,
bool PIP_Solution_Node::Tableau::OK() const { + if (s.num_rows() != t.num_rows()) { #ifndef NDEBUG - using std::endl; - using std::cerr; + std::cerr << "PIP_Solution_Node::Tableau matrices " + << "have a different number of rows.\n"; #endif + return false; + }
- const dimension_type num_rows = s.num_rows(); - if (num_rows != t.num_rows()) { + if (!s.OK() || !t.OK()) { #ifndef NDEBUG - cerr << "The PIP_Solution_Node::Tableau matrices do not have the " - << "same number of rows." - << endl; + std::cerr << "A PIP_Solution_Node::Tableau matrix is broken.\n"; #endif return false; } + + if (denominator <= 0) { +#ifndef NDEBUG + std::cerr << "PIP_Solution_Node::Tableau with non-positive denominator.\n"; +#endif + return false; + } + + // All tests passed. return true; }
@@ -688,7 +699,7 @@ PIP_Solution_Node::Tableau::normalize() { }
void -PIP_Solution_Node::Tableau::scale(const Coefficient &ratio) { +PIP_Solution_Node::Tableau::scale(Coefficient_traits::const_reference ratio) { dimension_type i, j, k; dimension_type i_max = s.num_rows(); dimension_type j_max = s.num_columns(); diff --git a/src/PIP_Tree.defs.hh b/src/PIP_Tree.defs.hh index d984fea..9c07242 100644 --- a/src/PIP_Tree.defs.hh +++ b/src/PIP_Tree.defs.hh @@ -90,10 +90,11 @@ public: class Artificial_Parameter : public Linear_Expression { public: Artificial_Parameter(); - Artificial_Parameter(const Linear_Expression &e, const Coefficient &d); + Artificial_Parameter(const Linear_Expression &e, + Coefficient_traits::const_reference d); Artificial_Parameter(const Artificial_Parameter &x);
- const Coefficient& get_denominator() const; + Coefficient_traits::const_reference get_denominator() const;
//! Returns \b true if \p x and \p y are equal. friend bool operator==(const Artificial_Parameter& x, @@ -296,14 +297,14 @@ private: //! Tests whether the matrix is integer, \e ie. the denominator is 1. bool is_integer() const; //! Multiplies all coefficients and denominator with ratio. - void scale(const Coefficient &ratio); + void scale(Coefficient_traits::const_reference ratio); //! Normalizes the modulo of coefficients so that they are mutually prime. /*! Computes the Greatest Common Divisor (GCD) among the elements of the matrices and normalizes them and the denominator by the GCD itself. */ void normalize(); - //! + /*! \brief Compares two pivot row and column pairs before pivoting.
@@ -358,15 +359,16 @@ private: const dimension_type j, const dimension_type i_, const dimension_type j_) const; + //! Returns the value of the denominator. - const Coefficient &get_denominator() const; + Coefficient_traits::const_reference get_denominator() const;
void ascii_dump(std::ostream& s) const; bool ascii_load(std::istream& s);
//! Returns \c true if and only if \p *this is well formed. - virtual bool OK() const; - }; + bool OK() const; + }; // struct Tableau
//! The parametric simplex tableau. Tableau tableau; diff --git a/src/PIP_Tree.inlines.hh b/src/PIP_Tree.inlines.hh index d436da9..0449a2e 100644 --- a/src/PIP_Tree.inlines.hh +++ b/src/PIP_Tree.inlines.hh @@ -27,16 +27,14 @@ namespace Parma_Polyhedra_Library {
inline PIP_Solution_Node::Tableau::Tableau() - : s(), - t(), - denominator(1) { + : s(), t(), denominator(1) { + PPL_ASSERT(OK()); }
inline PIP_Solution_Node::Tableau::Tableau(const Tableau& y) - : s(y.s), - t(y.t), - denominator(y.denominator) { + : s(y.s), t(y.t), denominator(y.denominator) { + PPL_ASSERT(OK()); }
inline @@ -48,7 +46,7 @@ PIP_Solution_Node::Tableau::is_integer() const { return denominator == 1; }
-inline const Coefficient& +inline Coefficient_traits::const_reference PIP_Solution_Node::Tableau::get_denominator() const { return denominator; }