Artificial parameters in PIP solution trees. More...
#include <PIP_Tree.defs.hh>


Public Member Functions | |
| Artificial_Parameter () | |
| Default constructor: builds a zero artificial parameter. | |
| Artificial_Parameter (const Linear_Expression &expr, Coefficient_traits::const_reference den) | |
| Constructor. | |
| Artificial_Parameter (const Artificial_Parameter &y) | |
| Copy constructor. | |
| Coefficient_traits::const_reference | denominator () const |
| Returns the normalized (i.e., positive) denominator. | |
| void | 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.) | |
| std::ostream & | operator<< (std::ostream &os, const PIP_Tree_Node::Artificial_Parameter &x) |
| Output operator. | |
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 276 of file PIP_Tree.defs.hh.
| Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::Artificial_Parameter | ( | ) | [inline] |
Default constructor: builds a zero artificial parameter.
Definition at line 107 of file PIP_Tree.inlines.hh.
References OK().
00108 : Linear_Expression(), denom(1) { 00109 PPL_ASSERT(OK()); 00110 }
| Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::Artificial_Parameter | ( | const Linear_Expression & | expr, | |
| Coefficient_traits::const_reference | den | |||
| ) |
Constructor.
Builds artificial parameter
.
| expr | The expression that, after normalization, will form the numerator of the artificial parameter. | |
| den | The integer constant thatm after normalization, will form the denominator of the artificial parameter. |
| std::invalid_argument | Thrown if den is zero. |
Normalization will ensure that the denominator is positive.
Definition at line 370 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_DIRTY_TEMP_COEFFICIENT, and Parma_Polyhedra_Library::Linear_Expression::space_dimension().
00372 : Linear_Expression(expr), denom(den) { 00373 if (denom == 0) 00374 throw std::invalid_argument("PIP_Tree_Node::Artificial_Parameter(e, d): " 00375 "denominator d is zero."); 00376 00377 // Normalize if needed. 00378 // FIXME: Provide a proper normalization helper. 00379 Linear_Expression& param_expr = *this; 00380 if (denom < 0) { 00381 neg_assign(denom); 00382 param_expr *= -1; 00383 } 00384 00385 // Compute GCD of parameter expression and denum. 00386 PPL_DIRTY_TEMP_COEFFICIENT(gcd); 00387 gcd = denom; 00388 gcd_assign(gcd, param_expr.inhomogeneous_term(), gcd); 00389 if (gcd == 1) 00390 return; 00391 const dimension_type space_dim = param_expr.space_dimension(); 00392 for (dimension_type i = space_dim; i-- > 0; ) { 00393 Coefficient_traits::const_reference 00394 e_i = param_expr.coefficient(Variable(i)); 00395 if (e_i != 0) { 00396 gcd_assign(gcd, e_i, gcd); 00397 if (gcd == 1) 00398 return; 00399 } 00400 } 00401 00402 // Divide coefficients and denominator by their (non-trivial) GCD. 00403 PPL_ASSERT(gcd > 1); 00404 Linear_Expression normalized(0 * Variable(space_dim-1)); 00405 PPL_DIRTY_TEMP_COEFFICIENT(coeff); 00406 exact_div_assign(coeff, param_expr.inhomogeneous_term(), gcd); 00407 normalized += coeff; 00408 for (dimension_type i = space_dim; i-- > 0; ) { 00409 Coefficient_traits::const_reference 00410 e_i = param_expr.coefficient(Variable(i)); 00411 if (e_i != 0) { 00412 exact_div_assign(coeff, e_i, gcd); 00413 add_mul_assign(normalized, coeff, Variable(i)); 00414 } 00415 } 00416 // Replace the parameter expression with the normalized one. 00417 param_expr = normalized; 00418 exact_div_assign(denom, denom, gcd); 00419 00420 PPL_ASSERT(OK()); 00421 }
| Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::Artificial_Parameter | ( | const Artificial_Parameter & | y | ) | [inline] |
Copy constructor.
Definition at line 114 of file PIP_Tree.inlines.hh.
References OK().
00115 : Linear_Expression(y), denom(y.denom) { 00116 PPL_ASSERT(OK()); 00117 }
| void Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::ascii_dump | ( | std::ostream & | s | ) | const |
Writes to s an ASCII representation of *this.
Reimplemented from Parma_Polyhedra_Library::Linear_Expression.
Definition at line 458 of file PIP_Tree.cc.
References ascii_dump(), and denom.
00458 { 00459 s << "artificial_parameter "; 00460 Linear_Expression::ascii_dump(s); 00461 s << " / " << denom << "\n"; 00462 }
| void Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::ascii_dump | ( | ) | const |
Writes to std::cerr an ASCII representation of *this.
Reimplemented from Parma_Polyhedra_Library::Linear_Expression.
Referenced by ascii_dump().
| bool Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::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.
Reimplemented from Parma_Polyhedra_Library::Linear_Expression.
Definition at line 465 of file PIP_Tree.cc.
References Parma_Polyhedra_Library::Linear_Expression::ascii_load(), denom, and OK().
Referenced by Parma_Polyhedra_Library::PIP_Tree_Node::ascii_load().
00465 { 00466 std::string str; 00467 if (!(s >> str) || str != "artificial_parameter") 00468 return false; 00469 if (!Linear_Expression::ascii_load(s)) 00470 return false; 00471 if (!(s >> str) || str != "/") 00472 return false; 00473 if (!(s >> denom)) 00474 return false; 00475 PPL_ASSERT(OK()); 00476 return true; 00477 }
| 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.
References denom.
Referenced by Parma_Polyhedra_Library::IO_Operators::operator<<().
00120 { 00121 return denom; 00122 }
| memory_size_type Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::external_memory_in_bytes | ( | ) | const |
Returns the size in bytes of the memory managed by *this.
Reimplemented from Parma_Polyhedra_Library::Linear_Expression.
Definition at line 2839 of file PIP_Tree.cc.
References denom.
Referenced by total_memory_in_bytes().
02839 { 02840 return Linear_Expression::external_memory_in_bytes() 02841 + Parma_Polyhedra_Library::external_memory_in_bytes(denom); 02842 }
| bool Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::OK | ( | ) | const |
Returns true if and only if the parameter is well-formed.
Reimplemented from Parma_Polyhedra_Library::Linear_Expression.
Definition at line 446 of file PIP_Tree.cc.
References denom.
Referenced by Artificial_Parameter(), and ascii_load().
00446 { 00447 if (denom <= 0) { 00448 #ifndef NDEBUG 00449 std::cerr << "PIP_Tree_Node::Artificial_Parameter " 00450 << "has a non-positive denominator.\n"; 00451 #endif 00452 return false; 00453 } 00454 return true; 00455 }
| 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 441 of file PIP_Tree.cc.
References operator==().
00441 { 00442 return !operator==(y); 00443 }
| 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 425 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().
Referenced by operator!=().
00425 { 00426 const Artificial_Parameter& x = *this; 00427 if (x.space_dimension() != y.space_dimension()) 00428 return false; 00429 if (x.denom != y.denom) 00430 return false; 00431 if (x.inhomogeneous_term() != y.inhomogeneous_term()) 00432 return false; 00433 for (dimension_type i = x.space_dimension(); i-- > 0; ) 00434 if (x.coefficient(Variable(i)) != y.coefficient(Variable(i))) 00435 return false; 00436 return true; 00437 }
| void Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::print | ( | ) | const |
Prints *this to std::cerr using operator<<.
Reimplemented from Parma_Polyhedra_Library::Linear_Expression.
| void Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::swap | ( | Artificial_Parameter & | y | ) | [inline] |
Swaps *this with y.
Definition at line 125 of file PIP_Tree.inlines.hh.
References denom.
00125 { 00126 Linear_Expression::swap(y); 00127 std::swap(denom, y.denom); 00128 }
| memory_size_type Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::total_memory_in_bytes | ( | ) | const |
Returns the total size in bytes of the memory occupied by *this.
Reimplemented from Parma_Polyhedra_Library::Linear_Expression.
Definition at line 2845 of file PIP_Tree.cc.
References external_memory_in_bytes().
02845 { 02846 return sizeof(*this) + external_memory_in_bytes(); 02847 }
| std::ostream & operator<< | ( | std::ostream & | os, | |
| const PIP_Tree_Node::Artificial_Parameter & | x | |||
| ) | [related] |
Output operator.
Definition at line 347 of file PIP_Tree.cc.
00347 { 00348 const Linear_Expression& expr = static_cast<const Linear_Expression&>(x); 00349 os << "(" << expr << ") div " << x.denominator(); 00350 return os; 00351 }
The normalized (i.e., positive) denominator.
Definition at line 339 of file PIP_Tree.defs.hh.
Referenced by Artificial_Parameter(), ascii_dump(), ascii_load(), denominator(), external_memory_in_bytes(), OK(), operator==(), and swap().
1.6.3