[GIT] ppl/ppl(pip): Improved class PIP_Tree_Node::Artificial_Parameter.

Module: ppl/ppl Branch: pip Commit: d7ab70ac7775d4c05233236d54e3387d6286d6bf URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=d7ab70ac7775d...
Author: Enea Zaffanella zaffanella@cs.unipr.it Date: Thu Feb 4 16:39:39 2010 +0100
Improved class PIP_Tree_Node::Artificial_Parameter.
---
src/PIP_Tree.cc | 13 +++++-- src/PIP_Tree.defs.hh | 93 ++++++++++++++++++++++++++++++++--------------- src/PIP_Tree.inlines.hh | 15 ++++++-- 3 files changed, 84 insertions(+), 37 deletions(-)
diff --git a/src/PIP_Tree.cc b/src/PIP_Tree.cc index 1194450..423ab70 100644 --- a/src/PIP_Tree.cc +++ b/src/PIP_Tree.cc @@ -300,23 +300,28 @@ operator==(const PIP_Tree_Node::Artificial_Parameter& x,
void PIP_Tree_Node::Artificial_Parameter::ascii_dump(std::ostream& s) const { - s << "\ndenominator " << denominator << "\n"; + s << "artificial_parameter "; Linear_Expression::ascii_dump(s); + s << " / " << denominator << "\n"; }
bool PIP_Tree_Node::Artificial_Parameter::ascii_load(std::istream& s) { std::string str; - if (!(s >> str) || str != "denominator") - return false; - if (!(s >> denominator)) + if (!(s >> str) || str != "artificial_parameter") return false; if (!Linear_Expression::ascii_load(s)) return false; + if (!(s >> str) || str != "/") + return false; + if (!(s >> denominator)) + return false; PPL_ASSERT(OK()); return true; }
+PPL_OUTPUT_DEFINITIONS(PIP_Tree_Node::Artificial_Parameter) + PIP_Decision_Node::~PIP_Decision_Node() { delete true_child; delete false_child; diff --git a/src/PIP_Tree.defs.hh b/src/PIP_Tree.defs.hh index 9c9f412..6bfa57d 100644 --- a/src/PIP_Tree.defs.hh +++ b/src/PIP_Tree.defs.hh @@ -79,36 +79,7 @@ public: */ const Constraint_System& constraints() const;
- /*! \brief - A class to store the expession of artificial parameters in solution trees. - - These locally new parameters are of the form of the integer division of a - linear expression of the other parameters (constant term included), by a - coefficient. Coefficients at indexes corresponding to variables always are - zero. - */ - class Artificial_Parameter : public Linear_Expression { - public: - Artificial_Parameter(); - Artificial_Parameter(const Linear_Expression& e, - Coefficient_traits::const_reference d); - Artificial_Parameter(const Artificial_Parameter& y); - - 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, - const Artificial_Parameter& y); - - void ascii_dump(std::ostream& s) const; - bool ascii_load(std::istream& s); - - //! Returns \c true if and only if the parameter is well-formed. - bool OK() const; - - private: - Coefficient denominator; - }; // class Artificial_Parameter + class Artificial_Parameter;
//! A type alias for a sequence of Artificial_Parameter's. typedef std::vector<Artificial_Parameter> Artificial_Parameter_Sequence; @@ -232,6 +203,68 @@ protected: }; // class PIP_Tree_Node
+/*! \brief + Artificial parameters in PIP solution trees. + + These parameters are built from a linear expression combining other + parameters (constant term included) divided by a positive integer + denominator. Coefficients at variables indices corresponding to + PIP problem variables are always zero. +*/ +class PIP_Tree_Node::Artificial_Parameter + : public Linear_Expression { +public: + //! Default constructor: builds a zero artificial parameter. + Artificial_Parameter(); + + //! Constructor. + /*! + Builds artificial parameter \f$\frac{\mathit{expr}}{\mathit{den}}\f$. + + \param expr + The expression that, after normalization, will form the numerator of + the artificial parameter. + + \param den + The integer constant thatm after normalization, will form the + denominator of the artificial parameter. + + \exception std::invalid_argument + Thrown if \p den is zero. + + Normalization will ensure that the denominator is positive. + */ + Artificial_Parameter(const Linear_Expression& expr, + Coefficient_traits::const_reference den); + + //! Copy constructor. + Artificial_Parameter(const Artificial_Parameter& y); + + //! Returns the normalized (i.e., positive) denominator. + 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, + const Artificial_Parameter& y); + + PPL_OUTPUT_DECLARATIONS + + /*! \brief + Loads from \p s an ASCII representation (as produced by + ascii_dump(std::ostream&) const) and sets \p *this accordingly. + Returns <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise. + */ + bool ascii_load(std::istream& s); + + //! Returns \c true if and only if the parameter is well-formed. + bool OK() const; + +private: + //! The normalized (i.e., positive) denominator. + Coefficient denominator; +}; // class PIP_Tree_Node::Artificial_Parameter + + //! A tree node representing part of the space of solutions. class PIP_Solution_Node : public PIP_Tree_Node { public: diff --git a/src/PIP_Tree.inlines.hh b/src/PIP_Tree.inlines.hh index 2ea2d93..6544e59 100644 --- a/src/PIP_Tree.inlines.hh +++ b/src/PIP_Tree.inlines.hh @@ -118,9 +118,18 @@ PIP_Tree_Node::Artificial_Parameter::Artificial_Parameter()
inline PIP_Tree_Node::Artificial_Parameter -::Artificial_Parameter(const Linear_Expression &e, - Coefficient_traits::const_reference d) - : Linear_Expression(e), denominator(d) { +::Artificial_Parameter(const Linear_Expression& expr, + Coefficient_traits::const_reference den) + : Linear_Expression(expr), denominator(den) { + if (denominator == 0) + throw std::invalid_argument("PIP_Tree_Node::Artificial_Parameter(e, d): " + "denominator d is zero."); + // Normalize if needed. + if (denominator < 0) { + neg_assign(denominator); + Linear_Expression& expr = *this; + expr *= -1; + } PPL_ASSERT(OK()); }
participants (1)
-
Enea Zaffanella