PPL  0.12.1
Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter Class Reference

Artificial parameters in PIP solution trees. More...

#include <PIP_Tree.defs.hh>

Inheritance diagram for Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter:
Collaboration diagram for Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter:

List of all members.

Public Member Functions

 Artificial_Parameter ()
 Default constructor: builds a zero artificial parameter.
 Artificial_Parameter (const Linear_Expression &expr, Coefficient_traits::const_reference d)
 Constructor.
 Artificial_Parameter (const Artificial_Parameter &y)
 Copy constructor.
Coefficient_traits::const_reference denominator () const
 Returns the normalized (i.e., positive) denominator.
void m_swap (Artificial_Parameter &y)
 Swaps *this with y.
bool operator== (const Artificial_Parameter &y) const
 Returns true if and only if *this and y are equal.
bool operator!= (const Artificial_Parameter &y) const
 Returns true if and only if *this and y are different.
void ascii_dump () const
 Writes to std::cerr an ASCII representation of *this.
void ascii_dump (std::ostream &s) const
 Writes to s an ASCII representation of *this.
void print () const
 Prints *this to std::cerr using operator<<.
bool ascii_load (std::istream &s)
 Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this accordingly. Returns true if successful, false otherwise.
memory_size_type total_memory_in_bytes () const
 Returns the total size in bytes of the memory occupied by *this.
memory_size_type external_memory_in_bytes () const
 Returns the size in bytes of the memory managed by *this.
bool OK () const
 Returns true if and only if the parameter is well-formed.

Private Attributes

Coefficient denom
 The normalized (i.e., positive) denominator.

Related Functions

(Note that these are not member functions.)

void swap (PIP_Tree_Node::Artificial_Parameter &x, PIP_Tree_Node::Artificial_Parameter &y)
 Swaps x with y.
std::ostream & operator<< (std::ostream &os, const PIP_Tree_Node::Artificial_Parameter &x)
 Output operator.
void swap (PIP_Tree_Node::Artificial_Parameter &x, PIP_Tree_Node::Artificial_Parameter &y)

Detailed Description

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.

Definition at line 278 of file PIP_Tree.defs.hh.


Constructor & Destructor Documentation

Default constructor: builds a zero artificial parameter.

Definition at line 107 of file PIP_Tree.inlines.hh.

References OK(), and PPL_ASSERT.

Constructor.

Builds artificial parameter $\frac{\mathtt{expr}}{\mathtt{d}}$.

Parameters:
exprThe expression that, after normalization, will form the numerator of the artificial parameter.
dThe integer constant that, after normalization, will form the denominator of the artificial parameter.
Exceptions:
std::invalid_argumentThrown if d is zero.

Normalization will ensure that the denominator is positive.

Definition at line 874 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::Linear_Expression::add_mul_assign, Parma_Polyhedra_Library::Linear_Expression::coefficient(), denom, Parma_Polyhedra_Library::exact_div_assign(), Parma_Polyhedra_Library::gcd_assign(), Parma_Polyhedra_Library::Linear_Expression::inhomogeneous_term(), Parma_Polyhedra_Library::neg_assign(), OK(), PPL_ASSERT, PPL_DIRTY_TEMP_COEFFICIENT, and Parma_Polyhedra_Library::Linear_Expression::space_dimension().

  : Linear_Expression(expr), denom(d) {
  if (denom == 0)
    throw std::invalid_argument("PIP_Tree_Node::Artificial_Parameter(e, d): "
                                "denominator d is zero.");

  // Normalize if needed.
  // FIXME: Provide a proper normalization helper.
  Linear_Expression& param_expr = *this;
  if (denom < 0) {
    neg_assign(denom);
    param_expr *= -1;
  }

  // Compute GCD of parameter expression and denominator.
  PPL_DIRTY_TEMP_COEFFICIENT(gcd);
  gcd = denom;
  gcd_assign(gcd, param_expr.inhomogeneous_term(), gcd);
  if (gcd == 1)
    return;
  const dimension_type space_dim = param_expr.space_dimension();
  for (dimension_type i = space_dim; i-- > 0; ) {
    Coefficient_traits::const_reference
      e_i = param_expr.coefficient(Variable(i));
    if (e_i != 0) {
      gcd_assign(gcd, e_i, gcd);
      if (gcd == 1)
        return;
    }
  }

  // Divide coefficients and denominator by their (non-trivial) GCD.
  PPL_ASSERT(gcd > 1);
  Linear_Expression normalized(0 * Variable(space_dim-1));
  PPL_DIRTY_TEMP_COEFFICIENT(coeff);
  exact_div_assign(coeff, param_expr.inhomogeneous_term(), gcd);
  normalized += coeff;
  for (dimension_type i = space_dim; i-- > 0; ) {
    Coefficient_traits::const_reference
      e_i = param_expr.coefficient(Variable(i));
    if (e_i != 0) {
      exact_div_assign(coeff, e_i, gcd);
      add_mul_assign(normalized, coeff, Variable(i));
    }
  }
  // Replace the parameter expression with the normalized one.
  param_expr = normalized;
  exact_div_assign(denom, denom, gcd);

  PPL_ASSERT(OK());
}

Copy constructor.

Definition at line 114 of file PIP_Tree.inlines.hh.

References OK(), and PPL_ASSERT.

  : Linear_Expression(y), denom(y.denom) {
  PPL_ASSERT(OK());
}

Member Function Documentation

Writes to std::cerr an ASCII representation of *this.

Reimplemented from Parma_Polyhedra_Library::Linear_Expression.

Writes to s an ASCII representation of *this.

Reimplemented from Parma_Polyhedra_Library::Linear_Expression.

Definition at line 962 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::PIP_Tree_Node::ascii_dump().

                                                                 {
  s << "artificial_parameter ";
  Linear_Expression::ascii_dump(s);
  s << " / " << denom << "\n";
}

Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this accordingly. Returns true if successful, false otherwise.

Reimplemented from Parma_Polyhedra_Library::Linear_Expression.

Definition at line 969 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::Linear_Expression::ascii_load(), Parma_Polyhedra_Library::PIP_Tree_Node::OK(), and PPL_ASSERT.

Referenced by Parma_Polyhedra_Library::PIP_Tree_Node::ascii_load().

                                                           {
  std::string str;
  if (!(s >> str) || str != "artificial_parameter")
    return false;
  if (!Linear_Expression::ascii_load(s))
    return false;
  if (!(s >> str) || str != "/")
    return false;
  if (!(s >> denom))
    return false;
  PPL_ASSERT(OK());
  return true;
}
Coefficient_traits::const_reference Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::denominator ( ) const
inline

Returns the normalized (i.e., positive) denominator.

Definition at line 120 of file PIP_Tree.inlines.hh.

Referenced by Parma_Polyhedra_Library::IO_Operators::operator<<().

                                                     {
  return denom;
}

Returns true if and only if the parameter is well-formed.

Reimplemented from Parma_Polyhedra_Library::Linear_Expression.

Definition at line 950 of file PIP_Tree.cc.

Referenced by Artificial_Parameter().

                                            {
  if (denom <= 0) {
#ifndef NDEBUG
    std::cerr << "PIP_Tree_Node::Artificial_Parameter "
              << "has a non-positive denominator.\n";
#endif
    return false;
  }
  return true;
}
bool Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::operator!= ( const Artificial_Parameter y) const

Returns true if and only if *this and y are different.

Definition at line 945 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::operator==().

                                                             {
  return !operator==(y);
}
bool Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::operator== ( const Artificial_Parameter y) const

Returns true if and only if *this and y are equal.

Note that two artificial parameters having different space dimensions are considered to be different.

Definition at line 929 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::Linear_Expression::coefficient(), denom, Parma_Polyhedra_Library::Linear_Expression::inhomogeneous_term(), and Parma_Polyhedra_Library::Linear_Expression::space_dimension().

                                                             {
  const Artificial_Parameter& x = *this;
  if (x.space_dimension() != y.space_dimension())
    return false;
  if (x.denom != y.denom)
    return false;
  if (x.inhomogeneous_term() != y.inhomogeneous_term())
    return false;
  for (dimension_type i = x.space_dimension(); i-- > 0; )
    if (x.coefficient(Variable(i)) != y.coefficient(Variable(i)))
      return false;
  return true;
}

Prints *this to std::cerr using operator<<.

Reimplemented from Parma_Polyhedra_Library::Linear_Expression.

Returns the total size in bytes of the memory occupied by *this.

Reimplemented from Parma_Polyhedra_Library::Linear_Expression.

Definition at line 3521 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::PIP_Solution_Node::external_memory_in_bytes().

                                                               {
  return sizeof(*this) + external_memory_in_bytes();
}

Friends And Related Function Documentation

std::ostream & operator<< ( std::ostream &  os,
const PIP_Tree_Node::Artificial_Parameter x 
)
related

Output operator.

Definition at line 851 of file PIP_Tree.cc.

                                                                       {
  const Linear_Expression& expr = static_cast<const Linear_Expression&>(x);
  os << "(" << expr << ") div " << x.denominator();
  return os;
}

Definition at line 133 of file PIP_Tree.inlines.hh.

References m_swap().

                                           {
  x.m_swap(y);
}

Swaps x with y.


Member Data Documentation

The normalized (i.e., positive) denominator.

Definition at line 341 of file PIP_Tree.defs.hh.

Referenced by Artificial_Parameter(), m_swap(), and operator==().


The documentation for this class was generated from the following files: