PPL  1.2
Parma_Polyhedra_Library::Linear_Expression_Impl< Row > Class Template Reference

A linear expression. More...

#include <Linear_Expression_Impl_defs.hh>

Inheritance diagram for Parma_Polyhedra_Library::Linear_Expression_Impl< Row >:
Collaboration diagram for Parma_Polyhedra_Library::Linear_Expression_Impl< Row >:

Classes

class  const_iterator
 

Public Member Functions

 Linear_Expression_Impl ()
 Default constructor: returns a copy of Linear_Expression_Impl::zero(). More...
 
 Linear_Expression_Impl (const Linear_Expression_Impl &e)
 Ordinary copy constructor. More...
 
template<typename Row2 >
 Linear_Expression_Impl (const Linear_Expression_Impl< Row2 > &e)
 Copy constructor for other row types. More...
 
 Linear_Expression_Impl (const Linear_Expression_Interface &e)
 Copy constructor from any implementation of Linear_Expression_Interface. More...
 
virtual ~Linear_Expression_Impl ()
 Destructor. More...
 
virtual bool OK () const
 Checks if all the invariants are satisfied. More...
 
 Linear_Expression_Impl (Coefficient_traits::const_reference n)
 Builds the linear expression corresponding to the inhomogeneous term n. More...
 
 Linear_Expression_Impl (Variable v)
 Builds the linear expression corresponding to the variable v. More...
 
virtual Representation representation () const
 Returns the current representation of this linear expression. More...
 
virtual const_iterator_interfacebegin () const
 
virtual const_iterator_interfaceend () const
 
virtual const_iterator_interfacelower_bound (Variable v) const
 
virtual dimension_type space_dimension () const
 Returns the dimension of the vector space enclosing *this. More...
 
virtual void set_space_dimension (dimension_type n)
 Sets the dimension of the vector space enclosing *this to n . More...
 
virtual Coefficient_traits::const_reference coefficient (Variable v) const
 Returns the coefficient of v in *this. More...
 
virtual void set_coefficient (Variable v, Coefficient_traits::const_reference n)
 Sets the coefficient of v in *this to n. More...
 
virtual Coefficient_traits::const_reference inhomogeneous_term () const
 Returns the inhomogeneous term of *this. More...
 
virtual void set_inhomogeneous_term (Coefficient_traits::const_reference n)
 Sets the inhomogeneous term of *this to n. More...
 
virtual void linear_combine (const Linear_Expression_Interface &y, Variable v)
 
virtual void linear_combine (const Linear_Expression_Interface &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2)
 
virtual void linear_combine_lax (const Linear_Expression_Interface &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2)
 
virtual void swap_space_dimensions (Variable v1, Variable v2)
 Swaps the coefficients of the variables v1 and v2 . More...
 
virtual void remove_space_dimensions (const Variables_Set &vars)
 Removes all the specified dimensions from the expression. More...
 
virtual void shift_space_dimensions (Variable v, dimension_type n)
 
virtual void permute_space_dimensions (const std::vector< Variable > &cycle)
 Permutes the space dimensions of the expression. More...
 
virtual bool is_zero () const
 Returns true if and only if *this is $0$. More...
 
virtual bool all_homogeneous_terms_are_zero () const
 Returns true if and only if all the homogeneous terms of *this are $0$. More...
 
virtual memory_size_type total_memory_in_bytes () const
 Returns a lower bound to the total size in bytes of the memory occupied by *this. More...
 
virtual memory_size_type external_memory_in_bytes () const
 Returns the size in bytes of the memory managed by *this. More...
 
virtual void ascii_dump (std::ostream &s) const
 Writes to s an ASCII representation of *this. More...
 
virtual 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. More...
 
 Linear_Expression_Impl (const Linear_Expression_Interface &e, dimension_type space_dim)
 Copy constructor with a specified space dimension. More...
 
virtual bool is_equal_to (const Linear_Expression_Interface &x) const
 
virtual void normalize ()
 
virtual void sign_normalize ()
 
virtual void negate (dimension_type first, dimension_type last)
 Negates the elements from index first (included) to index last (excluded). More...
 
virtual Linear_Expression_Imploperator+= (Coefficient_traits::const_reference n)
 
virtual Linear_Expression_Imploperator-= (Coefficient_traits::const_reference n)
 
virtual Linear_Expression_Imploperator+= (const Linear_Expression_Interface &e2)
 
virtual Linear_Expression_Imploperator+= (const Variable v)
 
virtual Linear_Expression_Imploperator-= (const Linear_Expression_Interface &e2)
 
virtual Linear_Expression_Imploperator-= (const Variable v)
 
virtual Linear_Expression_Imploperator*= (Coefficient_traits::const_reference n)
 
virtual Linear_Expression_Imploperator/= (Coefficient_traits::const_reference n)
 
virtual void negate ()
 
virtual Linear_Expression_Impladd_mul_assign (Coefficient_traits::const_reference n, const Variable v)
 
virtual Linear_Expression_Implsub_mul_assign (Coefficient_traits::const_reference n, const Variable v)
 
virtual void add_mul_assign (Coefficient_traits::const_reference factor, const Linear_Expression_Interface &e2)
 
virtual void sub_mul_assign (Coefficient_traits::const_reference factor, const Linear_Expression_Interface &e2)
 
virtual void print (std::ostream &s) const
 
virtual bool all_zeroes (const Variables_Set &vars) const
 Returns true if the coefficient of each variable in vars[i] is $0$. More...
 
virtual bool have_a_common_variable (const Linear_Expression_Interface &x, Variable first, Variable last) const
 
virtual Coefficient_traits::const_reference get (dimension_type i) const
 Returns the i-th coefficient. More...
 
virtual void set (dimension_type i, Coefficient_traits::const_reference n)
 Sets the i-th coefficient to n. More...
 
virtual bool all_zeroes (dimension_type start, dimension_type end) const
 Returns true if (*this)[i] is $0$, for each i in [start, end). More...
 
virtual dimension_type num_zeroes (dimension_type start, dimension_type end) const
 Returns the number of zero coefficient in [start, end). More...
 
virtual Coefficient gcd (dimension_type start, dimension_type end) const
 Returns the gcd of the nonzero coefficients in [start,end). If all the coefficients in this range are 0 returns 0. More...
 
virtual void exact_div_assign (Coefficient_traits::const_reference c, dimension_type start, dimension_type end)
 
virtual void mul_assign (Coefficient_traits::const_reference n, dimension_type start, dimension_type end)
 Equivalent to (*this)[i] *= n, for each i in [start, end). More...
 
virtual void linear_combine (const Linear_Expression_Interface &y, dimension_type i)
 
virtual void linear_combine (const Linear_Expression_Interface &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2, dimension_type start, dimension_type end)
 
virtual void linear_combine_lax (const Linear_Expression_Interface &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2, dimension_type start, dimension_type end)
 
virtual dimension_type last_nonzero () const
 
virtual bool all_zeroes_except (const Variables_Set &vars, dimension_type start, dimension_type end) const
 Returns true if each coefficient in [start,end) is *not* in $0$, disregarding coefficients of variables in vars. More...
 
virtual void scalar_product_assign (Coefficient &result, const Linear_Expression_Interface &y, dimension_type start, dimension_type end) const
 Sets results to the sum of (*this)[i]*y[i], for each i in [start,end). More...
 
virtual int scalar_product_sign (const Linear_Expression_Interface &y, dimension_type start, dimension_type end) const
 Computes the sign of the sum of (*this)[i]*y[i], for each i in [start,end). More...
 
virtual dimension_type first_nonzero (dimension_type first, dimension_type last) const
 
virtual dimension_type last_nonzero (dimension_type first, dimension_type last) const
 
virtual void has_a_free_dimension_helper (std::set< dimension_type > &x) const
 Removes from the set x all the indexes of nonzero elements of *this. More...
 
virtual bool is_equal_to (const Linear_Expression_Interface &x, dimension_type start, dimension_type end) const
 Returns true if (*this)[i] is equal to x[i], for each i in [start,end). More...
 
virtual bool is_equal_to (const Linear_Expression_Interface &x, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2, dimension_type start, dimension_type end) const
 
virtual void get_row (Dense_Row &r) const
 Sets r to a copy of the row that implements *this. More...
 
virtual void get_row (Sparse_Row &r) const
 Sets r to a copy of the row that implements *this. More...
 
 Linear_Expression_Impl (dimension_type space_dim, bool)
 Implementation sizing constructor. More...
 
template<typename Row2 >
void linear_combine (const Linear_Expression_Impl< Row2 > &y, Variable v)
 
template<typename Row2 >
void linear_combine (const Linear_Expression_Impl< Row2 > &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2)
 
template<typename Row2 >
void linear_combine_lax (const Linear_Expression_Impl< Row2 > &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2)
 
template<typename Row2 >
bool is_equal_to (const Linear_Expression_Impl< Row2 > &x) const
 
template<typename Row2 >
Linear_Expression_Imploperator+= (const Linear_Expression_Impl< Row2 > &e2)
 
template<typename Row2 >
Linear_Expression_Imploperator-= (const Linear_Expression_Impl< Row2 > &e2)
 
template<typename Row2 >
Linear_Expression_Implsub_mul_assign (Coefficient_traits::const_reference n, const Linear_Expression_Impl< Row2 > &y, dimension_type start, dimension_type end)
 
template<typename Row2 >
void add_mul_assign (Coefficient_traits::const_reference factor, const Linear_Expression_Impl< Row2 > &e2)
 
template<typename Row2 >
void sub_mul_assign (Coefficient_traits::const_reference factor, const Linear_Expression_Impl< Row2 > &e2)
 
template<typename Row2 >
void linear_combine (const Linear_Expression_Impl< Row2 > &y, dimension_type i)
 
template<typename Row2 >
void linear_combine (const Linear_Expression_Impl< Row2 > &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2, dimension_type start, dimension_type end)
 
template<typename Row2 >
void linear_combine_lax (const Linear_Expression_Impl< Row2 > &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2, dimension_type start, dimension_type end)
 
template<typename Row2 >
void scalar_product_assign (Coefficient &result, const Linear_Expression_Impl< Row2 > &y, dimension_type start, dimension_type end) const
 Sets results to the sum of (*this)[i]*y[i], for each i in [start,end). More...
 
template<typename Row2 >
int scalar_product_sign (const Linear_Expression_Impl< Row2 > &y, dimension_type start, dimension_type end) const
 
template<typename Row2 >
bool is_equal_to (const Linear_Expression_Impl< Row2 > &x, dimension_type start, dimension_type end) const
 Returns true if (*this)[i] is equal to x[i], for each i in [start,end). More...
 
template<typename Row2 >
bool is_equal_to (const Linear_Expression_Impl< Row2 > &x, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2, dimension_type start, dimension_type end) const
 
template<typename Row2 >
bool have_a_common_variable (const Linear_Expression_Impl< Row2 > &x, Variable first, Variable last) const
 
template<>
bool OK () const
 
template<>
bool OK () const
 
template<>
void remove_space_dimensions (const Variables_Set &vars)
 Removes all the specified dimensions from the expression. More...
 
template<>
void remove_space_dimensions (const Variables_Set &vars)
 Removes all the specified dimensions from the expression. More...
 
template<>
bool is_zero () const
 Returns true if and only if *this is $0$. More...
 
template<>
bool all_homogeneous_terms_are_zero () const
 Returns true if and only if all the homogeneous terms of *this are $0$. More...
 
template<>
bool all_zeroes (dimension_type start, dimension_type end) const
 Returns true if (*this)[i] is $0$, for each i in [start, end). More...
 
template<>
dimension_type num_zeroes (dimension_type start, dimension_type end) const
 Returns the number of zero coefficient in [start, end). More...
 
template<>
Coefficient gcd (dimension_type start, dimension_type end) const
 Returns the gcd of the nonzero coefficients in [start,end). If all the coefficients in this range are 0 returns 0. More...
 
template<>
Coefficient gcd (dimension_type start, dimension_type end) const
 Returns the gcd of the nonzero coefficients in [start,end). If all the coefficients in this range are 0 returns 0. More...
 
template<>
bool all_zeroes (const Variables_Set &vars) const
 Returns true if the coefficient of each variable in vars[i] is $0$. More...
 
template<>
bool all_zeroes (const Variables_Set &vars) const
 Returns true if the coefficient of each variable in vars[i] is $0$. More...
 
template<>
bool all_zeroes_except (const Variables_Set &vars, dimension_type start, dimension_type end) const
 Returns true if each coefficient in [start,end) is *not* in $0$, disregarding coefficients of variables in vars. More...
 
template<>
bool all_zeroes_except (const Variables_Set &vars, dimension_type start, dimension_type end) const
 Returns true if each coefficient in [start,end) is *not* in $0$, disregarding coefficients of variables in vars. More...
 
template<>
dimension_type last_nonzero () const
 
template<>
dimension_type first_nonzero (dimension_type first, dimension_type last) const
 
template<>
dimension_type last_nonzero (dimension_type first, dimension_type last) const
 
template<>
void has_a_free_dimension_helper (std::set< dimension_type > &x) const
 Removes from the set x all the indexes of nonzero elements of *this. More...
 
template<>
void has_a_free_dimension_helper (std::set< dimension_type > &x) const
 Removes from the set x all the indexes of nonzero elements of *this. More...
 
template<>
bool have_a_common_variable (const Linear_Expression_Impl< Dense_Row > &y, Variable first, Variable last) const
 
template<>
bool have_a_common_variable (const Linear_Expression_Impl< Dense_Row > &y, Variable first, Variable last) const
 
template<>
bool have_a_common_variable (const Linear_Expression_Impl< Sparse_Row > &y, Variable first, Variable last) const
 
template<>
bool have_a_common_variable (const Linear_Expression_Impl< Sparse_Row > &y, Variable first, Variable last) const
 
template<>
bool OK () const
 
template<>
bool OK () const
 
template<>
bool all_homogeneous_terms_are_zero () const
 Returns true if and only if all the homogeneous terms of *this are $0$. More...
 
template<>
bool all_homogeneous_terms_are_zero () const
 Returns true if and only if all the homogeneous terms of *this are $0$. More...
 
template<>
bool all_zeroes (dimension_type start, dimension_type end) const
 Returns true if (*this)[i] is $0$, for each i in [start, end). More...
 
template<>
bool all_zeroes (dimension_type start, dimension_type end) const
 Returns true if (*this)[i] is $0$, for each i in [start, end). More...
 
template<>
bool all_zeroes (const Variables_Set &vars) const
 Returns true if the coefficient of each variable in vars[i] is $0$. More...
 
template<>
bool all_zeroes (const Variables_Set &vars) const
 Returns true if the coefficient of each variable in vars[i] is $0$. More...
 
template<>
bool all_zeroes_except (const Variables_Set &vars, dimension_type start, dimension_type end) const
 Returns true if each coefficient in [start,end) is *not* in $0$, disregarding coefficients of variables in vars. More...
 
template<>
bool all_zeroes_except (const Variables_Set &vars, dimension_type start, dimension_type end) const
 Returns true if each coefficient in [start,end) is *not* in $0$, disregarding coefficients of variables in vars. More...
 
template<>
dimension_type first_nonzero (dimension_type first, dimension_type last) const
 
template<>
dimension_type first_nonzero (dimension_type first, dimension_type last) const
 
template<>
Coefficient gcd (dimension_type start, dimension_type end) const
 Returns the gcd of the nonzero coefficients in [start,end). If all the coefficients in this range are 0 returns 0. More...
 
template<>
Coefficient gcd (dimension_type start, dimension_type end) const
 Returns the gcd of the nonzero coefficients in [start,end). If all the coefficients in this range are 0 returns 0. More...
 
template<>
void has_a_free_dimension_helper (std::set< dimension_type > &x) const
 Removes from the set x all the indexes of nonzero elements of *this. More...
 
template<>
void has_a_free_dimension_helper (std::set< dimension_type > &x) const
 Removes from the set x all the indexes of nonzero elements of *this. More...
 
template<>
bool have_a_common_variable (const Linear_Expression_Impl< Dense_Row > &y, Variable first, Variable last) const
 
template<>
bool have_a_common_variable (const Linear_Expression_Impl< Sparse_Row > &y, Variable first, Variable last) const
 
template<>
bool have_a_common_variable (const Linear_Expression_Impl< Dense_Row > &y, Variable first, Variable last) const
 
template<>
bool have_a_common_variable (const Linear_Expression_Impl< Sparse_Row > &y, Variable first, Variable last) const
 
template<>
bool is_zero () const
 Returns true if and only if *this is $0$. More...
 
template<>
bool is_zero () const
 Returns true if and only if *this is $0$. More...
 
template<>
dimension_type last_nonzero () const
 
template<>
dimension_type last_nonzero () const
 
template<>
dimension_type last_nonzero (dimension_type first, dimension_type last) const
 
template<>
dimension_type last_nonzero (dimension_type first, dimension_type last) const
 
template<>
dimension_type num_zeroes (dimension_type start, dimension_type end) const
 Returns the number of zero coefficient in [start, end). More...
 
template<>
dimension_type num_zeroes (dimension_type start, dimension_type end) const
 Returns the number of zero coefficient in [start, end). More...
 
template<>
void remove_space_dimensions (const Variables_Set &vars)
 Removes all the specified dimensions from the expression. More...
 
template<>
void remove_space_dimensions (const Variables_Set &vars)
 Removes all the specified dimensions from the expression. More...
 
template<>
Representation representation () const
 Returns the current representation of this linear expression. More...
 
template<>
Representation representation () const
 Returns the current representation of this linear expression. More...
 
template<>
bool is_zero () const
 Returns true if and only if *this is $0$. More...
 
template<>
bool all_homogeneous_terms_are_zero () const
 Returns true if and only if all the homogeneous terms of *this are $0$. More...
 
template<>
bool all_zeroes (dimension_type start, dimension_type end) const
 Returns true if (*this)[i] is $0$, for each i in [start, end). More...
 
template<>
dimension_type num_zeroes (dimension_type start, dimension_type end) const
 Returns the number of zero coefficient in [start, end). More...
 
template<>
dimension_type last_nonzero () const
 
template<>
dimension_type first_nonzero (dimension_type first, dimension_type last) const
 
template<>
dimension_type last_nonzero (dimension_type first, dimension_type last) const
 
template<>
Representation representation () const
 Returns the current representation of this linear expression. More...
 
template<>
Representation representation () const
 Returns the current representation of this linear expression. More...
 
template<typename Row2 >
Linear_Expression_Impl< Row > & operator+= (const Linear_Expression_Impl< Row2 > &e)
 
- Public Member Functions inherited from Parma_Polyhedra_Library::Linear_Expression_Interface
virtual ~Linear_Expression_Interface ()
 

Static Public Member Functions

static dimension_type max_space_dimension ()
 Returns the maximum space dimension a Linear_Expression_Impl can handle. More...
 

Private Member Functions

void construct (const Linear_Expression_Interface &e)
 
void construct (const Linear_Expression_Interface &e, dimension_type space_dim)
 
template<typename Row2 >
void construct (const Linear_Expression_Impl< Row2 > &e)
 
template<typename Row2 >
void construct (const Linear_Expression_Impl< Row2 > &e, dimension_type space_dim)
 

Private Attributes

Row row
 

Friends

template<typename Row2 >
class Linear_Expression_Impl
 

Related Functions

(Note that these are not member functions.)

virtual int compare (const Linear_Expression_Interface &y) const
 The basic comparison function. More...
 
template<typename Row2 >
int compare (const Linear_Expression_Impl< Row2 > &y) const
 The basic comparison function. More...
 
template<typename Row >
std::ostream & operator<< (std::ostream &s, const Linear_Expression_Impl< Row > &e)
 Output operator. More...
 
template<typename Row >
Linear_Expression_Impl< Row > & operator+= (const Variable v)
 
template<typename Row2 >
Linear_Expression_Impl< Row > & operator-= (const Linear_Expression_Impl< Row2 > &e2)
 
template<typename Row >
Linear_Expression_Impl< Row > & operator-= (const Variable v)
 
template<typename Row >
Linear_Expression_Impl< Row > & operator*= (Coefficient_traits::const_reference n)
 
template<typename Row >
Linear_Expression_Impl< Row > & operator/= (Coefficient_traits::const_reference n)
 
template<typename Row >
void negate ()
 
template<typename Row >
Linear_Expression_Impl< Row > & add_mul_assign (Coefficient_traits::const_reference n, const Variable v)
 
template<typename Row >
Linear_Expression_Impl< Row > & sub_mul_assign (Coefficient_traits::const_reference n, const Variable v)
 

Detailed Description

template<typename Row>
class Parma_Polyhedra_Library::Linear_Expression_Impl< Row >

A linear expression.

An object of the class Linear_Expression_Impl represents the linear expression

\[ \sum_{i=0}^{n-1} a_i x_i + b \]

where $n$ is the dimension of the vector space, each $a_i$ is the integer coefficient of the $i$-th variable $x_i$ and $b$ is the integer for the inhomogeneous term.

How to build a linear expression.

Linear expressions are the basic blocks for defining both constraints (i.e., linear equalities or inequalities) and generators (i.e., lines, rays, points and closure points). A full set of functions is defined to provide a convenient interface for building complex linear expressions starting from simpler ones and from objects of the classes Variable and Coefficient: available operators include unary negation, binary addition and subtraction, as well as multiplication by a Coefficient. The space dimension of a linear expression is defined as the maximum space dimension of the arguments used to build it: in particular, the space dimension of a Variable x is defined as x.id()+1, whereas all the objects of the class Coefficient have space dimension zero.

Example
The following code builds the linear expression $4x - 2y - z + 14$, having space dimension $3$:
Linear_Expression_Impl e = 4*x - 2*y - z + 14;
Another way to build the same linear expression is: Note that e1, e2 and e3 have space dimension 1, 2 and 3, respectively; also, in the fourth line of code, e is created with space dimension zero and then extended to space dimension 3 in the fifth line.

Definition at line 103 of file Linear_Expression_Impl_defs.hh.

Constructor & Destructor Documentation

template<typename Row >
Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::Linear_Expression_Impl ( )
inline

Default constructor: returns a copy of Linear_Expression_Impl::zero().

Definition at line 40 of file Linear_Expression_Impl_inlines.hh.

References Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::OK().

41  : row(1) {
42  PPL_ASSERT(OK());
43 }
virtual bool OK() const
Checks if all the invariants are satisfied.

Ordinary copy constructor.

Definition at line 41 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::construct().

41  {
42  construct(e);
43 }
template<typename Row >
template<typename Row2 >
Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::Linear_Expression_Impl ( const Linear_Expression_Impl< Row2 > &  e)

Copy constructor for other row types.

Definition at line 48 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::construct().

48  {
49  construct(e);
50 }

Copy constructor from any implementation of Linear_Expression_Interface.

Definition at line 54 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::construct().

54  {
55  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
56  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
57  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&e)) {
58  construct(*p);
59  }
60  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&e)) {
61  construct(*p);
62  }
63  else {
64  // Add implementations for other derived classes here.
65  PPL_UNREACHABLE;
66  }
67 }
template<typename Row >
Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::~Linear_Expression_Impl ( )
inlinevirtual

Destructor.

Definition at line 55 of file Linear_Expression_Impl_inlines.hh.

55  {
56 }
template<typename Row >
Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::Linear_Expression_Impl ( Coefficient_traits::const_reference  n)
inlineexplicit

Builds the linear expression corresponding to the inhomogeneous term n.

Definition at line 61 of file Linear_Expression_Impl_inlines.hh.

62  : row(1) {
63  if (n != 0) {
64  row.insert(0, n);
65  }
66  PPL_ASSERT(OK());
67 }
virtual bool OK() const
Checks if all the invariants are satisfied.

Builds the linear expression corresponding to the variable v.

Exceptions
std::length_errorThrown if the space dimension of v exceeds Linear_Expression_Impl::max_space_dimension().

Definition at line 221 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::max_space_dimension(), and Parma_Polyhedra_Library::Variable::space_dimension().

221  {
222  if (v.space_dimension() > max_space_dimension()) {
223  throw std::length_error("Linear_Expression_Impl::"
224  "Linear_Expression_Impl(v):\n"
225  "v exceeds the maximum allowed "
226  "space dimension.");
227  }
228  set_space_dimension(v.space_dimension());
229  (*this) += v;
230  PPL_ASSERT(OK());
231 }
virtual bool OK() const
Checks if all the invariants are satisfied.
static dimension_type max_space_dimension()
Returns the maximum space dimension a Linear_Expression_Impl can handle.
virtual void set_space_dimension(dimension_type n)
Sets the dimension of the vector space enclosing *this to n .

Copy constructor with a specified space dimension.

Definition at line 71 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::construct().

72  {
73  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
74  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
75  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&e)) {
76  construct(*p, space_dim);
77  }
78  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&e)) {
79  construct(*p, space_dim);
80  }
81  else {
82  // Add implementations for other derived classes here.
83  PPL_UNREACHABLE;
84  }
85 }
template<typename Row >
Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::Linear_Expression_Impl ( dimension_type  space_dim,
bool   
)
inline

Implementation sizing constructor.

The bool parameter is just to avoid problems with the constructor Linear_Expression_Impl(Coefficient_traits::const_reference n).

Definition at line 48 of file Linear_Expression_Impl_inlines.hh.

49  : row(space_dim + 1) {
50  PPL_ASSERT(OK());
51 }
virtual bool OK() const
Checks if all the invariants are satisfied.

Member Function Documentation

template<typename Row>
virtual Linear_Expression_Impl& Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::add_mul_assign ( Coefficient_traits::const_reference  n,
const Variable  v 
)
virtual
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::add_mul_assign ( Coefficient_traits::const_reference  factor,
const Linear_Expression_Interface e2 
)
virtual

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 1013 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::add_mul_assign().

1014  {
1015  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
1016  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
1017  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
1018  add_mul_assign(factor, *p);
1019  }
1020  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
1021  add_mul_assign(factor, *p);
1022  }
1023  else {
1024  // Add implementations for new derived classes here.
1025  PPL_UNREACHABLE;
1026  }
1027 }
virtual Linear_Expression_Impl & add_mul_assign(Coefficient_traits::const_reference n, const Variable v)
template<typename Row >
template<typename Row2 >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::add_mul_assign ( Coefficient_traits::const_reference  factor,
const Linear_Expression_Impl< Row2 > &  e2 
)

Definition at line 449 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Coefficient_one(), and Parma_Polyhedra_Library::linear_combine().

450  {
451  if (factor != 0) {
452  linear_combine(y, Coefficient_one(), factor);
453  }
454 }
virtual void linear_combine(const Linear_Expression_Interface &y, Variable v)
Coefficient_traits::const_reference Coefficient_one()
Returns a const reference to a Coefficient with value 1.
template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::all_homogeneous_terms_are_zero ( ) const
virtual

Returns true if and only if all the homogeneous terms of *this are $0$.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 152 of file Linear_Expression_Impl.cc.

152  {
153  for (dimension_type i = 1; i < row.size(); ++i) {
154  if (row[i] != 0) {
155  return false;
156  }
157  }
158  return true;
159 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::all_homogeneous_terms_are_zero ( ) const
inlinevirtual

Returns true if and only if all the homogeneous terms of *this are $0$.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 191 of file Linear_Expression_Impl_inlines.hh.

191  {
192  return row.lower_bound(1) == row.end();
193 }
template<typename Row>
virtual bool Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::all_homogeneous_terms_are_zero ( ) const
virtual

Returns true if and only if all the homogeneous terms of *this are $0$.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::all_homogeneous_terms_are_zero ( ) const
virtual

Returns true if and only if all the homogeneous terms of *this are $0$.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::all_homogeneous_terms_are_zero ( ) const
virtual

Returns true if and only if all the homogeneous terms of *this are $0$.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::all_zeroes ( dimension_type  start,
dimension_type  end 
) const
virtual

Returns true if (*this)[i] is $0$, for each i in [start, end).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 163 of file Linear_Expression_Impl.cc.

164  {
165  for (dimension_type i = start; i < end; ++i) {
166  if (row[i] != 0) {
167  return false;
168  }
169  }
170  return true;
171 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::all_zeroes ( dimension_type  start,
dimension_type  end 
) const
inlinevirtual

Returns true if (*this)[i] is $0$, for each i in [start, end).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 197 of file Linear_Expression_Impl_inlines.hh.

198  {
199  return row.lower_bound(start) == row.lower_bound(end);
200 }
template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::all_zeroes ( const Variables_Set vars) const
virtual

Returns true if the coefficient of each variable in vars[i] is $0$.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 258 of file Linear_Expression_Impl.cc.

258  {
259  Variables_Set::const_iterator j = vars.begin();
260  Variables_Set::const_iterator j_end = vars.end();
261 
262  for ( ; j != j_end; ++j) {
263  if (row[*j + 1] != 0) {
264  return false;
265  }
266  }
267 
268  return true;
269 }
template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::all_zeroes ( const Variables_Set vars) const
virtual

Returns true if the coefficient of each variable in vars[i] is $0$.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 274 of file Linear_Expression_Impl.cc.

References Parma_Polyhedra_Library::CO_Tree::const_iterator::index().

274  {
275  Sparse_Row::const_iterator i = row.begin();
276  Sparse_Row::const_iterator i_end = row.end();
277  Variables_Set::const_iterator j = vars.begin();
278  Variables_Set::const_iterator j_end = vars.end();
279 
280  for ( ; j != j_end; ++j) {
281  i = row.lower_bound(i, *j + 1);
282  if (i == i_end) {
283  break;
284  }
285  if (i.index() == *j + 1) {
286  return false;
287  }
288  }
289 
290  return true;
291 }
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
template<typename Row>
virtual bool Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::all_zeroes ( const Variables_Set vars) const
virtual

Returns true if the coefficient of each variable in vars[i] is $0$.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Referenced by Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::is_equal_to().

template<typename Row>
virtual bool Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::all_zeroes ( dimension_type  start,
dimension_type  end 
) const
virtual

Returns true if (*this)[i] is $0$, for each i in [start, end).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::all_zeroes ( dimension_type  start,
dimension_type  end 
) const
virtual

Returns true if (*this)[i] is $0$, for each i in [start, end).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::all_zeroes ( dimension_type  start,
dimension_type  end 
) const
virtual

Returns true if (*this)[i] is $0$, for each i in [start, end).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::all_zeroes ( const Variables_Set vars) const
virtual

Returns true if the coefficient of each variable in vars[i] is $0$.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::all_zeroes ( const Variables_Set vars) const
virtual

Returns true if the coefficient of each variable in vars[i] is $0$.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::all_zeroes_except ( const Variables_Set vars,
dimension_type  start,
dimension_type  end 
) const
virtual

Returns true if each coefficient in [start,end) is *not* in $0$, disregarding coefficients of variables in vars.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 296 of file Linear_Expression_Impl.cc.

297  {
298  if (start == 0) {
299  if (row[0] != 0) {
300  return false;
301  }
302  ++start;
303  }
304  for (dimension_type i = start; i < end; ++i) {
305  if (row[i] != 0 && vars.count(i - 1) == 0) {
306  return false;
307  }
308  }
309  return true;
310 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::all_zeroes_except ( const Variables_Set vars,
dimension_type  start,
dimension_type  end 
) const
virtual

Returns true if each coefficient in [start,end) is *not* in $0$, disregarding coefficients of variables in vars.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 315 of file Linear_Expression_Impl.cc.

316  {
317  PPL_ASSERT(start <= end);
318  if (start == end) {
319  return true;
320  }
321  if (start == 0) {
322  if (row.find(0) != row.end()) {
323  return false;
324  }
325 
326  start = 1;
327  }
328 
329  PPL_ASSERT(start != 0);
330  PPL_ASSERT(start <= end);
331  for (Sparse_Row::const_iterator i = row.lower_bound(start),
332  i_end = row.lower_bound(end); i != i_end; ++i) {
333  if (vars.count(i.index() - 1) == 0) {
334  return false;
335  }
336  }
337 
338  return true;
339 }
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
template<typename Row>
virtual bool Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::all_zeroes_except ( const Variables_Set vars,
dimension_type  start,
dimension_type  end 
) const
virtual

Returns true if each coefficient in [start,end) is *not* in $0$, disregarding coefficients of variables in vars.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::all_zeroes_except ( const Variables_Set vars,
dimension_type  start,
dimension_type  end 
) const
virtual

Returns true if each coefficient in [start,end) is *not* in $0$, disregarding coefficients of variables in vars.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::all_zeroes_except ( const Variables_Set vars,
dimension_type  start,
dimension_type  end 
) const
virtual

Returns true if each coefficient in [start,end) is *not* in $0$, disregarding coefficients of variables in vars.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::ascii_dump ( std::ostream &  s) const
virtual

Writes to s an ASCII representation of *this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 1342 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::row, and Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::space_dimension().

1342  {
1343  s << "size " << (space_dimension() + 1) << " ";
1344  for (dimension_type i = 0; i < row.size(); ++i) {
1345  s << row.get(i);
1346  if (i != row.size() - 1) {
1347  s << ' ';
1348  }
1349  }
1350 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
virtual dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
template<typename Row >
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::ascii_load ( std::istream &  s)
virtual

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

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 1354 of file Linear_Expression_Impl_templates.hh.

References c, Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::OK(), PPL_DIRTY_TEMP_COEFFICIENT, and Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::row.

1354  {
1355  std::string str;
1356 
1357  if (!(s >> str)) {
1358  return false;
1359  }
1360  if (str != "size") {
1361  return false;
1362  }
1363 
1364  dimension_type new_size;
1365  if (!(s >> new_size)) {
1366  return false;
1367  }
1368 
1369  row.resize(0);
1370  row.resize(new_size);
1371 
1373 
1374  for (dimension_type j = 0; j < new_size; ++j) {
1375  if (!(s >> c)) {
1376  return false;
1377  }
1378  if (c != 0) {
1379  row.insert(j, c);
1380  }
1381  }
1382 
1383  PPL_ASSERT(OK());
1384  return true;
1385 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
Declare a local variable named id, of type Coefficient, and containing an unknown initial value...
virtual bool OK() const
Checks if all the invariants are satisfied.
Coefficient c
Definition: PIP_Tree.cc:64

This returns a pointer to dynamic-allocated memory. The caller has the duty to free the memory when it's not needed anymore.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 1267 of file Linear_Expression_Impl_templates.hh.

Referenced by Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::operator/=().

1267  {
1268  return new const_iterator(row, 1);
1269 }
template<typename Row >
Coefficient_traits::const_reference Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::coefficient ( Variable  v) const
inlinevirtual

Returns the coefficient of v in *this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 84 of file Linear_Expression_Impl_inlines.hh.

References Parma_Polyhedra_Library::Coefficient_zero(), Parma_Polyhedra_Library::Variable::id(), and Parma_Polyhedra_Library::Variable::space_dimension().

84  {
85  if (v.space_dimension() > space_dimension()) {
86  return Coefficient_zero();
87  }
88  return row.get(v.id() + 1);
89 }
Coefficient_traits::const_reference Coefficient_zero()
Returns a const reference to a Coefficient with value 0.
virtual dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::construct ( const Linear_Expression_Interface e)
private

Definition at line 1130 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::construct().

1130  {
1131  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
1132  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
1133  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
1134  return construct(*p);
1135  }
1136  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
1137  return construct(*p);
1138  }
1139  else {
1140  // Add implementations for new derived classes here.
1141  PPL_UNREACHABLE;
1142  }
1143 }
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::construct ( const Linear_Expression_Interface e,
dimension_type  space_dim 
)
private

Definition at line 1147 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::construct().

1148  {
1149  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
1150  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
1151  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
1152  return construct(*p, space_dim);
1153  }
1154  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
1155  return construct(*p, space_dim);
1156  }
1157  else {
1158  // Add implementations for new derived classes here.
1159  PPL_UNREACHABLE;
1160  }
1161 }
template<typename Row >
template<typename Row2 >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::construct ( const Linear_Expression_Impl< Row2 > &  e)
private

Definition at line 709 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::row.

709  {
710  row = e.row;
711  PPL_ASSERT(OK());
712 }
virtual bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
template<typename Row2 >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::construct ( const Linear_Expression_Impl< Row2 > &  e,
dimension_type  space_dim 
)
private

Definition at line 717 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::row, and Parma_Polyhedra_Library::swap().

718  {
719  Row x(e.row, space_dim + 1, space_dim + 1);
720  swap(row, x);
721  PPL_ASSERT(OK());
722 }
void swap(CO_Tree &x, CO_Tree &y)
virtual bool OK() const
Checks if all the invariants are satisfied.

This returns a pointer to dynamic-allocated memory. The caller has the duty to free the memory when it's not needed anymore.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 1273 of file Linear_Expression_Impl_templates.hh.

1273  {
1274  return new const_iterator(row, row.size());
1275 }
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::exact_div_assign ( Coefficient_traits::const_reference  c,
dimension_type  start,
dimension_type  end 
)
virtual

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 545 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::exact_div_assign().

546  {
547  // NOTE: Since all coefficients in [start,end) are multiple of c,
548  // each of the resulting coefficients will be nonzero iff the initial
549  // coefficient was.
550  for (typename Row::iterator i = row.lower_bound(start),
551  i_end = row.lower_bound(end); i != i_end; ++i) {
553  }
554  PPL_ASSERT(OK());
555 }
virtual bool OK() const
Checks if all the invariants are satisfied.
void exact_div_assign(Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y, const Checked_Number< T, Policy > &z)
Coefficient c
Definition: PIP_Tree.cc:64
template<typename Row >
memory_size_type Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::external_memory_in_bytes ( ) const
inlinevirtual

Returns the size in bytes of the memory managed by *this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 142 of file Linear_Expression_Impl_inlines.hh.

142  {
143  return row.external_memory_in_bytes();
144 }
template<>
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::first_nonzero ( dimension_type  first,
dimension_type  last 
) const
inlinevirtual

Returns the index of the first nonzero element, or last if there are no nonzero elements, considering only elements in [first,last).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 225 of file Linear_Expression_Impl_inlines.hh.

References Parma_Polyhedra_Library::CO_Tree::const_iterator::index().

225  {
226  PPL_ASSERT(first <= last);
227  PPL_ASSERT(last <= row.size());
228  Sparse_Row::const_iterator i = row.lower_bound(first);
229 
230  if (i != row.end() && i.index() < last) {
231  return i.index();
232  }
233  else {
234  return last;
235  }
236 }
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
template<>
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::first_nonzero ( dimension_type  first,
dimension_type  last 
) const
virtual

Returns the index of the first nonzero element, or last if there are no nonzero elements, considering only elements in [first,last).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 355 of file Linear_Expression_Impl.cc.

355  {
356  PPL_ASSERT(first <= last);
357  PPL_ASSERT(last <= row.size());
358  for (dimension_type i = first; i < last; ++i) {
359  if (row[i] != 0) {
360  return i;
361  }
362  }
363 
364  return last;
365 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
template<typename Row>
virtual dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::first_nonzero ( dimension_type  first,
dimension_type  last 
) const
virtual

Returns the index of the first nonzero element, or last if there are no nonzero elements, considering only elements in [first,last).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::first_nonzero ( dimension_type  first,
dimension_type  last 
) const
virtual

Returns the index of the first nonzero element, or last if there are no nonzero elements, considering only elements in [first,last).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::first_nonzero ( dimension_type  first,
dimension_type  last 
) const
virtual

Returns the index of the first nonzero element, or last if there are no nonzero elements, considering only elements in [first,last).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Returns the gcd of the nonzero coefficients in [start,end). If all the coefficients in this range are 0 returns 0.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 189 of file Linear_Expression_Impl.cc.

References Parma_Polyhedra_Library::gcd_assign(), and Parma_Polyhedra_Library::neg_assign().

190  {
191  dimension_type i;
192 
193  for (i = start; i < end; ++i) {
194  if (row[i] != 0) {
195  break;
196  }
197  }
198 
199  if (i == end) {
200  return 0;
201  }
202 
203  PPL_ASSERT(row[i] != 0);
204 
205  Coefficient result = row[i];
206  ++i;
207 
208  if (result < 0) {
209  neg_assign(result);
210  }
211 
212  for ( ; i < end; ++i) {
213  if (row[i] == 0) {
214  continue;
215  }
216  gcd_assign(result, row[i], result);
217  if (result == 1) {
218  return result;
219  }
220  }
221 
222  return result;
223 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
void neg_assign(GMP_Integer &x)
void gcd_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)

Returns the gcd of the nonzero coefficients in [start,end). If all the coefficients in this range are 0 returns 0.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 227 of file Linear_Expression_Impl.cc.

References Parma_Polyhedra_Library::gcd_assign(), and Parma_Polyhedra_Library::neg_assign().

228  {
229  Sparse_Row::const_iterator i = row.lower_bound(start);
230  Sparse_Row::const_iterator i_end = row.lower_bound(end);
231 
232  if (i == i_end) {
233  return 0;
234  }
235 
236  PPL_ASSERT(*i != 0);
237 
238  Coefficient result = *i;
239  ++i;
240 
241  if (result < 0) {
242  neg_assign(result);
243  }
244 
245  for ( ; i != i_end; ++i) {
246  gcd_assign(result, *i, result);
247  if (result == 1) {
248  return result;
249  }
250  }
251 
252  return result;
253 }
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
void neg_assign(GMP_Integer &x)
void gcd_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
template<typename Row>
virtual Coefficient Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::gcd ( dimension_type  start,
dimension_type  end 
) const
virtual

Returns the gcd of the nonzero coefficients in [start,end). If all the coefficients in this range are 0 returns 0.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Returns the gcd of the nonzero coefficients in [start,end). If all the coefficients in this range are 0 returns 0.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Returns the gcd of the nonzero coefficients in [start,end). If all the coefficients in this range are 0 returns 0.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<typename Row >
Coefficient_traits::const_reference Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::get ( dimension_type  i) const
virtual

Returns the i-th coefficient.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 525 of file Linear_Expression_Impl_templates.hh.

template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::get_row ( Dense_Row r) const
virtual

Sets r to a copy of the row that implements *this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 243 of file Linear_Expression_Impl_templates.hh.

template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::get_row ( Sparse_Row r) const
virtual

Sets r to a copy of the row that implements *this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 249 of file Linear_Expression_Impl_templates.hh.

template<>
void Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::has_a_free_dimension_helper ( std::set< dimension_type > &  x) const
virtual

Removes from the set x all the indexes of nonzero elements of *this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 385 of file Linear_Expression_Impl.cc.

References Parma_Polyhedra_Library::swap().

385  {
386  typedef std::set<dimension_type> set_t;
387  set_t result;
388  for (set_t::const_iterator i = x.begin(), i_end = x.end(); i != i_end; ++i) {
389  if (row[*i] == 0) {
390  result.insert(*i);
391  }
392  }
393  using std::swap;
394  swap(x, result);
395 }
void swap(CO_Tree &x, CO_Tree &y)
template<>
void Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::has_a_free_dimension_helper ( std::set< dimension_type > &  x) const
virtual

Removes from the set x all the indexes of nonzero elements of *this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 400 of file Linear_Expression_Impl.cc.

References Parma_Polyhedra_Library::CO_Tree::const_iterator::index(), and Parma_Polyhedra_Library::swap().

400  {
401  typedef std::set<dimension_type> set_t;
402  set_t result;
403  Sparse_Row::const_iterator itr = row.end();
404  Sparse_Row::const_iterator itr_end = row.end();
405  set_t::const_iterator i = x.begin();
406  set_t::const_iterator i_end = x.end();
407  for ( ; i != i_end; ++i) {
408  itr = row.lower_bound(itr, *i);
409  if (itr == itr_end) {
410  break;
411  }
412  if (itr.index() != *i) {
413  result.insert(*i);
414  }
415  }
416  for ( ; i != i_end; ++i) {
417  result.insert(*i);
418  }
419  using std::swap;
420  swap(x, result);
421 }
void swap(CO_Tree &x, CO_Tree &y)
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
template<typename Row>
virtual void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::has_a_free_dimension_helper ( std::set< dimension_type > &  x) const
virtual

Removes from the set x all the indexes of nonzero elements of *this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
void Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::has_a_free_dimension_helper ( std::set< dimension_type > &  x) const
virtual

Removes from the set x all the indexes of nonzero elements of *this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
void Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::has_a_free_dimension_helper ( std::set< dimension_type > &  x) const
virtual

Removes from the set x all the indexes of nonzero elements of *this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<typename Row >
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::have_a_common_variable ( const Linear_Expression_Interface x,
Variable  first,
Variable  last 
) const
virtual

Returns true if there is a variable in [first,last) whose coefficient is nonzero in both *this and x.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 1248 of file Linear_Expression_Impl_templates.hh.

Referenced by Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::have_a_common_variable().

1249  {
1250  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
1251  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
1252  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
1253  return have_a_common_variable(*p, first, last);
1254  }
1255  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
1256  return have_a_common_variable(*p, first, last);
1257  }
1258  else {
1259  // Add implementations for new derived classes here.
1260  PPL_UNREACHABLE;
1261  return false;
1262  }
1263 }
virtual bool have_a_common_variable(const Linear_Expression_Interface &x, Variable first, Variable last) const
template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::have_a_common_variable ( const Linear_Expression_Impl< Dense_Row > &  y,
Variable  first,
Variable  last 
) const

Definition at line 427 of file Linear_Expression_Impl.cc.

References Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::row, Parma_Polyhedra_Library::Dense_Row::size(), and Parma_Polyhedra_Library::Variable::space_dimension().

428  {
429  const dimension_type start = first.space_dimension();
430  const dimension_type end = last.space_dimension();
431  PPL_ASSERT(start <= end);
432  PPL_ASSERT(end <= row.size());
433  PPL_ASSERT(end <= y.row.size());
434  for (dimension_type i = start; i < end; ++i) {
435  if (row[i] != 0 && y.row[i] != 0) {
436  return true;
437  }
438  }
439  return false;
440 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::have_a_common_variable ( const Linear_Expression_Impl< Dense_Row > &  y,
Variable  first,
Variable  last 
) const

Definition at line 446 of file Linear_Expression_Impl.cc.

References Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::row, Parma_Polyhedra_Library::Dense_Row::size(), and Parma_Polyhedra_Library::Variable::space_dimension().

447  {
448  const dimension_type start = first.space_dimension();
449  const dimension_type end = last.space_dimension();
450  PPL_ASSERT(start <= end);
451  PPL_ASSERT(end <= row.size());
452  PPL_ASSERT(end <= y.row.size());
453  for (Sparse_Row::const_iterator i = row.lower_bound(start),
454  i_end = row.lower_bound(end); i != i_end; ++i) {
455  if (y.row[i.index()] != 0) {
456  return true;
457  }
458  }
459  return false;
460 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::have_a_common_variable ( const Linear_Expression_Impl< Sparse_Row > &  y,
Variable  first,
Variable  last 
) const

Definition at line 466 of file Linear_Expression_Impl.cc.

References Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::have_a_common_variable().

467  {
468  return y.have_a_common_variable(*this, first, last);
469 }
template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::have_a_common_variable ( const Linear_Expression_Impl< Sparse_Row > &  y,
Variable  first,
Variable  last 
) const

Definition at line 475 of file Linear_Expression_Impl.cc.

References Parma_Polyhedra_Library::CO_Tree::const_iterator::index(), Parma_Polyhedra_Library::Sparse_Row::lower_bound(), Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::row, Parma_Polyhedra_Library::Sparse_Row::size(), and Parma_Polyhedra_Library::Variable::space_dimension().

476  {
477  const dimension_type start = first.space_dimension();
478  const dimension_type end = last.space_dimension();
479  PPL_ASSERT(start <= end);
480  PPL_ASSERT(end <= row.size());
481  PPL_ASSERT(end <= y.row.size());
482  Sparse_Row::const_iterator i = row.lower_bound(start);
483  Sparse_Row::const_iterator i_end = row.lower_bound(end);
484  Sparse_Row::const_iterator j = y.row.lower_bound(start);
485  Sparse_Row::const_iterator j_end = y.row.lower_bound(end);
486  while (i != i_end && j != j_end) {
487  if (i.index() == j.index()) {
488  return true;
489  }
490  if (i.index() < j.index()) {
491  ++i;
492  }
493  else {
494  ++j;
495  }
496  }
497  return false;
498 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
template<typename Row>
template<typename Row2 >
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::have_a_common_variable ( const Linear_Expression_Impl< Row2 > &  x,
Variable  first,
Variable  last 
) const

Returns true if there is a variable in [first,last) whose coefficient is nonzero in both *this and x.

template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::have_a_common_variable ( const Linear_Expression_Impl< Dense_Row > &  y,
Variable  first,
Variable  last 
) const
template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::have_a_common_variable ( const Linear_Expression_Impl< Sparse_Row > &  y,
Variable  first,
Variable  last 
) const
template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::have_a_common_variable ( const Linear_Expression_Impl< Dense_Row > &  y,
Variable  first,
Variable  last 
) const
template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::have_a_common_variable ( const Linear_Expression_Impl< Sparse_Row > &  y,
Variable  first,
Variable  last 
) const
template<typename Row >
Coefficient_traits::const_reference Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::inhomogeneous_term ( ) const
inlinevirtual

Returns the inhomogeneous term of *this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 108 of file Linear_Expression_Impl_inlines.hh.

template<typename Row >
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::is_equal_to ( const Linear_Expression_Interface x) const
virtual

Returns true if *this is equal to x. Note that (*this == x) has a completely different meaning.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 956 of file Linear_Expression_Impl_templates.hh.

956  {
957  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
958  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
959  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
960  return is_equal_to(*p);
961  }
962  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
963  return is_equal_to(*p);
964  }
965  else {
966  // Add implementations for new derived classes here.
967  PPL_UNREACHABLE;
968  return false;
969  }
970 }
virtual bool is_equal_to(const Linear_Expression_Interface &x) const
template<typename Row >
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::is_equal_to ( const Linear_Expression_Interface x,
dimension_type  start,
dimension_type  end 
) const
virtual

Returns true if (*this)[i] is equal to x[i], for each i in [start,end).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 1206 of file Linear_Expression_Impl_templates.hh.

1207  {
1208  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
1209  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
1210  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
1211  return is_equal_to(*p, start, end);
1212  }
1213  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
1214  return is_equal_to(*p, start, end);
1215  }
1216  else {
1217  // Add implementations for new derived classes here.
1218  PPL_UNREACHABLE;
1219  return false;
1220  }
1221 }
virtual bool is_equal_to(const Linear_Expression_Interface &x) const
template<typename Row >
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::is_equal_to ( const Linear_Expression_Interface x,
Coefficient_traits::const_reference  c1,
Coefficient_traits::const_reference  c2,
dimension_type  start,
dimension_type  end 
) const
virtual

Returns true if (*this)[i]*c1 is equal to x[i]*c2, for each i in [start,end).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 1226 of file Linear_Expression_Impl_templates.hh.

1229  {
1230  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
1231  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
1232  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
1233  return is_equal_to(*p, c1, c2, start, end);
1234  }
1235  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
1236  return is_equal_to(*p, c1, c2, start, end);
1237  }
1238  else {
1239  // Add implementations for new derived classes here.
1240  PPL_UNREACHABLE;
1241  return false;
1242  }
1243 }
virtual bool is_equal_to(const Linear_Expression_Interface &x) const
template<typename Row >
template<typename Row2 >
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::is_equal_to ( const Linear_Expression_Impl< Row2 > &  x) const

Returns true if *this is equal to x. Note that (*this == x) has a completely different meaning.

Definition at line 237 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::row.

237  {
238  return row == x.row;
239 }
template<typename Row >
template<typename Row2 >
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::is_equal_to ( const Linear_Expression_Impl< Row2 > &  x,
dimension_type  start,
dimension_type  end 
) const

Returns true if (*this)[i] is equal to x[i], for each i in [start,end).

Definition at line 778 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::row.

779  {
780  const Linear_Expression_Impl<Row>& x = *this;
781  PPL_ASSERT(start <= end);
782  PPL_ASSERT(end <= x.row.size());
783  PPL_ASSERT(end <= y.row.size());
784 
785  typename Row::const_iterator i = x.row.lower_bound(start);
786  typename Row::const_iterator i_end = x.row.lower_bound(end);
787  typename Row2::const_iterator j = y.row.lower_bound(start);
788  typename Row2::const_iterator j_end = y.row.lower_bound(end);
789  while (i != i_end && j != j_end) {
790  if (i.index() == j.index()) {
791  if (*i != *j) {
792  return false;
793  }
794  ++i;
795  ++j;
796  }
797  else {
798  if (i.index() < j.index()) {
799  if (*i != 0) {
800  return false;
801  }
802  ++i;
803  }
804  else {
805  PPL_ASSERT(i.index() > j.index());
806  if (*j != 0) {
807  return false;
808  }
809  ++j;
810  }
811  }
812  }
813  for ( ; i != i_end; ++i) {
814  if (*i != 0) {
815  return false;
816  }
817  }
818  for ( ; j != j_end; ++j) {
819  if (*j != 0) {
820  return false;
821  }
822  }
823  return true;
824 }
template<typename Row >
template<typename Row2 >
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::is_equal_to ( const Linear_Expression_Impl< Row2 > &  x,
Coefficient_traits::const_reference  c1,
Coefficient_traits::const_reference  c2,
dimension_type  start,
dimension_type  end 
) const

Returns true if (*this)[i]*c1 is equal to x[i]*c2, for each i in [start,end).

Definition at line 830 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::all_zeroes(), and Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::row.

833  {
834  const Linear_Expression_Impl<Row>& x = *this;
835  PPL_ASSERT(start <= end);
836  PPL_ASSERT(end <= x.row.size());
837  PPL_ASSERT(end <= y.row.size());
838 
839  // Deal with trivial cases.
840  if (c1 == 0) {
841  if (c2 == 0) {
842  return true;
843  }
844  else {
845  return y.all_zeroes(start, end);
846  }
847  }
848  if (c2 == 0) {
849  return x.all_zeroes(start, end);
850  }
851 
852  PPL_ASSERT(c1 != 0);
853  PPL_ASSERT(c2 != 0);
854  typename Row::const_iterator i = x.row.lower_bound(start);
855  typename Row::const_iterator i_end = x.row.lower_bound(end);
856  typename Row2::const_iterator j = y.row.lower_bound(start);
857  typename Row2::const_iterator j_end = y.row.lower_bound(end);
858  while (i != i_end && j != j_end) {
859  if (i.index() == j.index()) {
860  if ((*i) * c1 != (*j) * c2) {
861  return false;
862  }
863  ++i;
864  ++j;
865  }
866  else {
867  if (i.index() < j.index()) {
868  if (*i != 0) {
869  return false;
870  }
871  ++i;
872  }
873  else {
874  PPL_ASSERT(i.index() > j.index());
875  if (*j != 0) {
876  return false;
877  }
878  ++j;
879  }
880  }
881  }
882  for ( ; i != i_end; ++i) {
883  if (*i != 0) {
884  return false;
885  }
886  }
887  for ( ; j != j_end; ++j) {
888  if (*j != 0) {
889  return false;
890  }
891  }
892  return true;
893 }
template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::is_zero ( ) const
virtual

Returns true if and only if *this is $0$.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 141 of file Linear_Expression_Impl.cc.

141  {
142  for (dimension_type i = row.size(); i-- > 0; ) {
143  if (row[i] != 0) {
144  return false;
145  }
146  }
147  return true;
148 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::is_zero ( ) const
inlinevirtual

Returns true if and only if *this is $0$.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 185 of file Linear_Expression_Impl_inlines.hh.

185  {
186  return row.num_stored_elements() == 0;
187 }
template<typename Row>
virtual bool Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::is_zero ( ) const
virtual

Returns true if and only if *this is $0$.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::is_zero ( ) const
virtual

Returns true if and only if *this is $0$.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::is_zero ( ) const
virtual

Returns true if and only if *this is $0$.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::last_nonzero ( ) const
inlinevirtual

Returns the index of the last nonzero element, or 0 if there are no nonzero elements.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 213 of file Linear_Expression_Impl_inlines.hh.

References Parma_Polyhedra_Library::CO_Tree::const_iterator::index().

213  {
214  if (row.num_stored_elements() == 0) {
215  return 0;
216  }
218  --i;
219  return i.index();
220 }
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
template<>
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::last_nonzero ( dimension_type  first,
dimension_type  last 
) const
inlinevirtual

Returns the index of the last nonzero element in [first,last), or last if there are no nonzero elements.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 241 of file Linear_Expression_Impl_inlines.hh.

References Parma_Polyhedra_Library::CO_Tree::const_iterator::index().

241  {
242  PPL_ASSERT(first <= last);
243  PPL_ASSERT(last <= row.size());
244  Sparse_Row::const_iterator itr1 = row.lower_bound(first);
245  Sparse_Row::const_iterator itr2 = row.lower_bound(last);
246 
247  if (itr1 == itr2) {
248  return last;
249  }
250 
251  --itr2;
252  return itr2.index();
253 }
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
template<>
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::last_nonzero ( ) const
virtual

Returns the index of the last nonzero element, or 0 if there are no nonzero elements.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 343 of file Linear_Expression_Impl.cc.

343  {
344  for (dimension_type i = row.size(); i-- > 0; ) {
345  if (row[i] != 0) {
346  return i;
347  }
348  }
349  return 0;
350 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
template<>
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::last_nonzero ( dimension_type  first,
dimension_type  last 
) const
virtual

Returns the index of the last nonzero element in [first,last), or last if there are no nonzero elements.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 370 of file Linear_Expression_Impl.cc.

370  {
371  PPL_ASSERT(first <= last);
372  PPL_ASSERT(last <= row.size());
373  for (dimension_type i = last; i-- > first; ) {
374  if (row[i] != 0) {
375  return i;
376  }
377  }
378 
379  return last;
380 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
template<typename Row>
virtual dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::last_nonzero ( ) const
virtual

Returns the index of the last nonzero element, or 0 if there are no nonzero elements.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<typename Row>
virtual dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::last_nonzero ( dimension_type  first,
dimension_type  last 
) const
virtual

Returns the index of the last nonzero element in [first,last), or last if there are no nonzero elements.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::last_nonzero ( ) const
virtual

Returns the index of the last nonzero element, or 0 if there are no nonzero elements.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::last_nonzero ( ) const
virtual

Returns the index of the last nonzero element, or 0 if there are no nonzero elements.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::last_nonzero ( dimension_type  first,
dimension_type  last 
) const
virtual

Returns the index of the last nonzero element in [first,last), or last if there are no nonzero elements.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::last_nonzero ( dimension_type  first,
dimension_type  last 
) const
virtual

Returns the index of the last nonzero element in [first,last), or last if there are no nonzero elements.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::linear_combine ( const Linear_Expression_Interface y,
Variable  v 
)
virtual

Linearly combines *this with y so that the coefficient of v is 0.

Parameters
yThe expression that will be combined with *this object;
vThe variable whose coefficient has to become $0$.

Computes a linear combination of *this and y having the coefficient of variable v equal to $0$. Then it assigns the resulting expression to *this.

*this and y must have the same space dimension.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 898 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::linear_combine().

898  {
899  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
900  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
901  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
902  linear_combine(*p, v);
903  }
904  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
905  linear_combine(*p, v);
906  }
907  else {
908  // Add implementations for new derived classes here.
909  PPL_UNREACHABLE;
910  }
911 }
virtual void linear_combine(const Linear_Expression_Interface &y, Variable v)
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::linear_combine ( const Linear_Expression_Interface y,
Coefficient_traits::const_reference  c1,
Coefficient_traits::const_reference  c2 
)
virtual

Equivalent to *this = *this * c1 + y * c2, but assumes that *this and y have the same space dimension.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 916 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::linear_combine().

918  {
919  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
920  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
921  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
922  linear_combine(*p, c1, c2);
923  }
924  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
925  linear_combine(*p, c1, c2);
926  }
927  else {
928  // Add implementations for new derived classes here.
929  PPL_UNREACHABLE;
930  }
931 }
virtual void linear_combine(const Linear_Expression_Interface &y, Variable v)
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::linear_combine ( const Linear_Expression_Interface y,
dimension_type  i 
)
virtual

Linearly combines *this with y so that the coefficient of v is 0.

Parameters
yThe expression that will be combined with *this object;
iThe index of the coefficient that has to become $0$.

Computes a linear combination of *this and y having the i-th coefficient equal to $0$. Then it assigns the resulting expression to *this.

*this and y must have the same space dimension.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 1051 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::linear_combine().

1051  {
1052  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
1053  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
1054  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
1055  linear_combine(*p, i);
1056  }
1057  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
1058  linear_combine(*p, i);
1059  }
1060  else {
1061  // Add implementations for new derived classes here.
1062  PPL_UNREACHABLE;
1063  }
1064 }
virtual void linear_combine(const Linear_Expression_Interface &y, Variable v)
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::linear_combine ( const Linear_Expression_Interface y,
Coefficient_traits::const_reference  c1,
Coefficient_traits::const_reference  c2,
dimension_type  start,
dimension_type  end 
)
virtual

Equivalent to (*this)[i] = (*this)[i] * c1 + y[i] * c2, for each i in [start, end).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 1069 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::linear_combine().

1072  {
1073  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
1074  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
1075  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
1076  linear_combine(*p, c1, c2, start, end);
1077  }
1078  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
1079  linear_combine(*p, c1, c2, start, end);
1080  }
1081  else {
1082  // Add implementations for new derived classes here.
1083  PPL_UNREACHABLE;
1084  }
1085 }
virtual void linear_combine(const Linear_Expression_Interface &y, Variable v)
template<typename Row >
template<typename Row2 >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::linear_combine ( const Linear_Expression_Impl< Row2 > &  y,
Variable  v 
)

Linearly combines *this with y so that the coefficient of v is 0.

Parameters
yThe expression that will be combined with *this object;
vThe variable whose coefficient has to become $0$.

Computes a linear combination of *this and y having the coefficient of variable v equal to $0$. Then it assigns the resulting expression to *this.

*this and y must have the same space dimension.

Definition at line 91 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::linear_combine(), Parma_Polyhedra_Library::Variable::space_dimension(), and Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::space_dimension().

91  {
92  PPL_ASSERT(space_dimension() == y.space_dimension());
93  PPL_ASSERT(i.space_dimension() <= space_dimension());
94  linear_combine(y, i.space_dimension());
95 }
virtual void linear_combine(const Linear_Expression_Interface &y, Variable v)
virtual dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
template<typename Row >
template<typename Row2 >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::linear_combine ( const Linear_Expression_Impl< Row2 > &  y,
Coefficient_traits::const_reference  c1,
Coefficient_traits::const_reference  c2 
)

Equivalent to *this = *this * c1 + y * c2, but assumes that *this and y have the same space dimension.

Definition at line 124 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::linear_combine(), and Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::space_dimension().

126  {
127  PPL_ASSERT(c1 != 0);
128  PPL_ASSERT(c2 != 0);
129  if (space_dimension() < y.space_dimension()) {
130  set_space_dimension(y.space_dimension());
131  }
132  linear_combine(y, c1, c2, 0, y.space_dimension() + 1);
133  PPL_ASSERT(OK());
134 }
virtual void linear_combine(const Linear_Expression_Interface &y, Variable v)
virtual bool OK() const
Checks if all the invariants are satisfied.
virtual void set_space_dimension(dimension_type n)
Sets the dimension of the vector space enclosing *this to n .
virtual dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
template<typename Row >
template<typename Row2 >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::linear_combine ( const Linear_Expression_Impl< Row2 > &  y,
dimension_type  i 
)

Linearly combines *this with y so that the coefficient of v is 0.

Parameters
yThe expression that will be combined with *this object;
iThe index of the coefficient that has to become $0$.

Computes a linear combination of *this and y having the i-th coefficient equal to $0$. Then it assigns the resulting expression to *this.

*this and y must have the same space dimension.

Definition at line 101 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::linear_combine(), Parma_Polyhedra_Library::neg_assign(), Parma_Polyhedra_Library::normalize2(), PPL_DIRTY_TEMP_COEFFICIENT, Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::row, and Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::space_dimension().

101  {
102  const Linear_Expression_Impl& x = *this;
103  PPL_ASSERT(i < x.space_dimension() + 1);
104  PPL_ASSERT(x.space_dimension() == y.space_dimension());
105  Coefficient_traits::const_reference x_i = x.row.get(i);
106  Coefficient_traits::const_reference y_i = y.row.get(i);
107  PPL_ASSERT(x_i != 0);
108  PPL_ASSERT(y_i != 0);
109  PPL_DIRTY_TEMP_COEFFICIENT(normalized_x_v);
110  PPL_DIRTY_TEMP_COEFFICIENT(normalized_y_v);
111  normalize2(x_i, y_i, normalized_x_v, normalized_y_v);
112  neg_assign(normalized_x_v);
113  linear_combine(y, normalized_y_v, normalized_x_v);
114  // We cannot use x_i here because it may have been invalidated by
115  // linear_combine().
116  assert(x.row.get(i) == 0);
117  PPL_ASSERT(OK());
118 }
virtual void linear_combine(const Linear_Expression_Interface &y, Variable v)
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
Declare a local variable named id, of type Coefficient, and containing an unknown initial value...
virtual bool OK() const
Checks if all the invariants are satisfied.
Linear_Expression_Impl()
Default constructor: returns a copy of Linear_Expression_Impl::zero().
void neg_assign(GMP_Integer &x)
void normalize2(Coefficient_traits::const_reference x, Coefficient_traits::const_reference y, Coefficient &n_x, Coefficient &n_y)
If is the GCD of x and y, the values of x and y divided by are assigned to n_x and n_y...
template<typename Row >
template<typename Row2 >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::linear_combine ( const Linear_Expression_Impl< Row2 > &  y,
Coefficient_traits::const_reference  c1,
Coefficient_traits::const_reference  c2,
dimension_type  start,
dimension_type  end 
)

Equivalent to (*this)[i] = (*this)[i] * c1 + y[i] * c2, for each i in [start, end).

Definition at line 583 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::linear_combine(), and Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::row.

586  {
587  Parma_Polyhedra_Library::linear_combine(row, y.row, c1, c2, start, end);
588  PPL_ASSERT(OK());
589 }
void linear_combine(Dense_Row &x, const Dense_Row &y, Coefficient_traits::const_reference coeff1, Coefficient_traits::const_reference coeff2)
virtual bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::linear_combine_lax ( const Linear_Expression_Interface y,
Coefficient_traits::const_reference  c1,
Coefficient_traits::const_reference  c2 
)
virtual

Equivalent to *this = *this * c1 + y * c2. c1 and c2 may be 0.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 936 of file Linear_Expression_Impl_templates.hh.

938  {
939  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
940  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
941  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
942  linear_combine_lax(*p, c1, c2);
943  }
944  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
945  linear_combine_lax(*p, c1, c2);
946  }
947  else {
948  // Add implementations for new derived classes here.
949  PPL_UNREACHABLE;
950  }
951 }
virtual void linear_combine_lax(const Linear_Expression_Interface &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2)
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::linear_combine_lax ( const Linear_Expression_Interface y,
Coefficient_traits::const_reference  c1,
Coefficient_traits::const_reference  c2,
dimension_type  start,
dimension_type  end 
)
virtual

Equivalent to (*this)[i] = (*this)[i] * c1 + y[i] * c2, for each i in [start, end). c1 and c2 may be zero.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 1090 of file Linear_Expression_Impl_templates.hh.

1093  {
1094  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
1095  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
1096  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
1097  linear_combine_lax(*p, c1, c2, start, end);
1098  }
1099  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
1100  linear_combine_lax(*p, c1, c2, start, end);
1101  }
1102  else {
1103  // Add implementations for new derived classes here.
1104  PPL_UNREACHABLE;
1105  }
1106 }
virtual void linear_combine_lax(const Linear_Expression_Interface &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2)
template<typename Row >
template<typename Row2 >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::linear_combine_lax ( const Linear_Expression_Impl< Row2 > &  y,
Coefficient_traits::const_reference  c1,
Coefficient_traits::const_reference  c2 
)

Equivalent to *this = *this * c1 + y * c2. c1 and c2 may be 0.

Definition at line 140 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::space_dimension().

142  {
143  if (space_dimension() < y.space_dimension()) {
144  set_space_dimension(y.space_dimension());
145  }
146  linear_combine_lax(y, c1, c2, 0, y.space_dimension() + 1);
147  PPL_ASSERT(OK());
148 }
virtual bool OK() const
Checks if all the invariants are satisfied.
virtual void set_space_dimension(dimension_type n)
Sets the dimension of the vector space enclosing *this to n .
virtual dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
virtual void linear_combine_lax(const Linear_Expression_Interface &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2)
template<typename Row >
template<typename Row2 >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::linear_combine_lax ( const Linear_Expression_Impl< Row2 > &  y,
Coefficient_traits::const_reference  c1,
Coefficient_traits::const_reference  c2,
dimension_type  start,
dimension_type  end 
)

Equivalent to (*this)[i] = (*this)[i] * c1 + y[i] * c2, for each i in [start, end). c1 and c2 may be zero.

Definition at line 595 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::linear_combine(), and Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::row.

598  {
599  PPL_ASSERT(start <= end);
600  PPL_ASSERT(end <= row.size());
601  PPL_ASSERT(end <= y.row.size());
602  if (c1 == 0) {
603  if (c2 == 0) {
604  PPL_ASSERT(c1 == 0);
605  PPL_ASSERT(c2 == 0);
606  typename Row::iterator i = row.lower_bound(start);
607  const typename Row::iterator& i_end = row.end();
608  while (i != i_end && i.index() < end) {
609  i = row.reset(i);
610  }
611  }
612  else {
613  PPL_ASSERT(c1 == 0);
614  PPL_ASSERT(c2 != 0);
615 
616  typename Row::iterator i = row.lower_bound(start);
617  const typename Row::iterator& i_end = row.end();
618  typename Row2::const_iterator j = y.row.lower_bound(start);
619  typename Row2::const_iterator j_last = y.row.lower_bound(end);
620 
621  while (i != i_end && i.index() < end && j != j_last) {
622  if (i.index() < j.index()) {
623  i = row.reset(i);
624  continue;
625  }
626  if (i.index() > j.index()) {
627  i = row.insert(i, j.index(), *j);
628  (*i) *= c2;
629  ++i;
630  ++j;
631  continue;
632  }
633  PPL_ASSERT(i.index() == j.index());
634  (*i) = (*j);
635  (*i) *= c2;
636  ++i;
637  ++j;
638  }
639  while (i != i_end && i.index() < end) {
640  i = row.reset(i);
641  }
642  while (j != j_last) {
643  i = row.insert(i, j.index(), *j);
644  (*i) *= c2;
645  // No need to increment i here.
646  ++j;
647  }
648  }
649  }
650  else {
651  if (c2 == 0) {
652  PPL_ASSERT(c1 != 0);
653  PPL_ASSERT(c2 == 0);
654  for (typename Row::iterator i = row.lower_bound(start),
655  i_end = row.lower_bound(end); i != i_end; ++i) {
656  (*i) *= c1;
657  }
658  }
659  else {
660  PPL_ASSERT(c1 != 0);
661  PPL_ASSERT(c2 != 0);
662  Parma_Polyhedra_Library::linear_combine(row, y.row, c1, c2, start, end);
663  }
664  }
665  PPL_ASSERT(OK());
666 }
void linear_combine(Dense_Row &x, const Dense_Row &y, Coefficient_traits::const_reference coeff1, Coefficient_traits::const_reference coeff2)
virtual bool OK() const
Checks if all the invariants are satisfied.

This returns a pointer to dynamic-allocated memory. The caller has the duty to free the memory when it's not needed anymore. Returns (a pointer to) an iterator that points to the first nonzero coefficient of a variable greater than or equal to v, or at end if no such coefficient exists.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 1279 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Variable::space_dimension().

1279  {
1280  return new const_iterator(row, v.space_dimension());
1281 }
template<typename Row >
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::max_space_dimension ( )
inlinestatic

Returns the maximum space dimension a Linear_Expression_Impl can handle.

Definition at line 34 of file Linear_Expression_Impl_inlines.hh.

34  {
35  return Row::max_size() - 1;
36 }
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::mul_assign ( Coefficient_traits::const_reference  n,
dimension_type  start,
dimension_type  end 
)
virtual

Equivalent to (*this)[i] *= n, for each i in [start, end).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 560 of file Linear_Expression_Impl_templates.hh.

References c.

561  {
562  if (c == 0) {
563  typename Row::iterator i = row.lower_bound(start);
564  const typename Row::iterator& i_end = row.end();
565  while (i != i_end && i.index() < end) {
566  i = row.reset(i);
567  }
568  }
569  else {
570  for (typename Row::iterator
571  i = row.lower_bound(start), i_end = row.lower_bound(end);
572  i != i_end; ++i) {
573  (*i) *= c;
574  }
575  }
576  PPL_ASSERT(OK());
577 }
virtual bool OK() const
Checks if all the invariants are satisfied.
Coefficient c
Definition: PIP_Tree.cc:64
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::negate ( dimension_type  first,
dimension_type  last 
)
virtual

Negates the elements from index first (included) to index last (excluded).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 695 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::neg_assign().

695  {
696  PPL_ASSERT(first <= last);
697  PPL_ASSERT(last <= row.size());
698  typename Row::iterator i = row.lower_bound(first);
699  typename Row::iterator i_end = row.lower_bound(last);
700  for ( ; i != i_end; ++i) {
701  neg_assign(*i);
702  }
703  PPL_ASSERT(OK());
704 }
virtual bool OK() const
Checks if all the invariants are satisfied.
void neg_assign(GMP_Integer &x)
template<typename Row>
virtual void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::negate ( )
virtual
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::normalize ( )
inlinevirtual

Normalizes the modulo of the coefficients and of the inhomogeneous term so that they are mutually prime.

Computes the Greatest Common Divisor (GCD) among the coefficients and the inhomogeneous term and normalizes them by the GCD itself.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 178 of file Linear_Expression_Impl_inlines.hh.

178  {
179  row.normalize();
180  PPL_ASSERT(OK());
181 }
virtual bool OK() const
Checks if all the invariants are satisfied.
template<>
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::num_zeroes ( dimension_type  start,
dimension_type  end 
) const
virtual

Returns the number of zero coefficient in [start, end).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 175 of file Linear_Expression_Impl.cc.

176  {
177  PPL_ASSERT(start <= end);
178  dimension_type result = 0;
179  for (dimension_type i = start; i < end; ++i) {
180  if (row[i] == 0) {
181  ++result;
182  }
183  }
184  return result;
185 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
template<>
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::num_zeroes ( dimension_type  start,
dimension_type  end 
) const
inlinevirtual

Returns the number of zero coefficient in [start, end).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 204 of file Linear_Expression_Impl_inlines.hh.

205  {
206  PPL_ASSERT(start <= end);
207  return (end - start)
208  - std::distance(row.lower_bound(start), row.lower_bound(end));
209 }
template<typename Row>
virtual dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::num_zeroes ( dimension_type  start,
dimension_type  end 
) const
virtual

Returns the number of zero coefficient in [start, end).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::num_zeroes ( dimension_type  start,
dimension_type  end 
) const
virtual

Returns the number of zero coefficient in [start, end).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
dimension_type Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::num_zeroes ( dimension_type  start,
dimension_type  end 
) const
virtual

Returns the number of zero coefficient in [start, end).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
bool Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::OK ( ) const
virtual

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 41 of file Linear_Expression_Impl.cc.

41  {
42  if (row.size() == 0) {
43  return false;
44  }
45  for (Sparse_Row::const_iterator i = row.begin(),
46  i_end = row.end(); i != i_end; ++i) {
47  if (*i == 0) {
48  std::cerr << "Linear_Expression_Impl<Sparse_Row>::OK() failed."
49  << " row was:\n";
50  row.ascii_dump(std::cerr);
51  // Found a stored zero.
52  return false;
53  }
54  }
55  return true;
56 }
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
template<typename Row>
virtual Linear_Expression_Impl& Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::operator*= ( Coefficient_traits::const_reference  n)
virtual
template<typename Row>
template<typename Row2 >
Linear_Expression_Impl<Row>& Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::operator+= ( const Linear_Expression_Impl< Row2 > &  e)

Definition at line 287 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Coefficient_one(), and Parma_Polyhedra_Library::linear_combine().

287  {
289  return *this;
290 }
virtual void linear_combine(const Linear_Expression_Interface &y, Variable v)
Coefficient_traits::const_reference Coefficient_one()
Returns a const reference to a Coefficient with value 1.
template<typename Row >
Linear_Expression_Impl< Row > & Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::operator+= ( Coefficient_traits::const_reference  n)
inlinevirtual

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 154 of file Linear_Expression_Impl_inlines.hh.

154  {
155  typename Row::iterator itr = row.insert(0);
156  (*itr) += n;
157  if (*itr == 0) {
158  row.reset(itr);
159  }
160  PPL_ASSERT(OK());
161  return *this;
162 }
virtual bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
Linear_Expression_Impl< Row > & Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::operator+= ( const Linear_Expression_Interface e2)
virtual

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 975 of file Linear_Expression_Impl_templates.hh.

975  {
976  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
977  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
978  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
979  return operator+=(*p);
980  }
981  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
982  return operator+=(*p);
983  }
984  else {
985  // Add implementations for new derived classes here.
986  PPL_UNREACHABLE;
987  return *this;
988  }
989 }
virtual Linear_Expression_Impl & operator+=(Coefficient_traits::const_reference n)
template<typename Row>
virtual Linear_Expression_Impl& Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::operator+= ( const Variable  v)
virtual
template<typename Row>
template<typename Row2 >
Linear_Expression_Impl& Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::operator+= ( const Linear_Expression_Impl< Row2 > &  e2)
template<typename Row >
Linear_Expression_Impl< Row > & Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::operator-= ( Coefficient_traits::const_reference  n)
inlinevirtual

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 166 of file Linear_Expression_Impl_inlines.hh.

166  {
167  typename Row::iterator itr = row.insert(0);
168  (*itr) -= n;
169  if (*itr == 0) {
170  row.reset(itr);
171  }
172  PPL_ASSERT(OK());
173  return *this;
174 }
virtual bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
Linear_Expression_Impl< Row > & Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::operator-= ( const Linear_Expression_Interface e2)
virtual

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 994 of file Linear_Expression_Impl_templates.hh.

994  {
995  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
996  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
997  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
998  return operator-=(*p);
999  }
1000  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
1001  return operator-=(*p);
1002  }
1003  else {
1004  // Add implementations for new derived classes here.
1005  PPL_UNREACHABLE;
1006  return *this;
1007  }
1008 }
virtual Linear_Expression_Impl & operator-=(Coefficient_traits::const_reference n)
template<typename Row>
virtual Linear_Expression_Impl& Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::operator-= ( const Variable  v)
virtual
template<typename Row>
template<typename Row2 >
Linear_Expression_Impl& Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::operator-= ( const Linear_Expression_Impl< Row2 > &  e2)
template<typename Row>
virtual Linear_Expression_Impl& Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::operator/= ( Coefficient_traits::const_reference  n)
virtual
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::permute_space_dimensions ( const std::vector< Variable > &  cycle)
virtual

Permutes the space dimensions of the expression.

Parameters
cycleA vector representing a cycle of the permutation according to which the space dimensions must be rearranged.

The cycle vector represents a cycle of a permutation of space dimensions. For example, the permutation $ \{ x_1 \mapsto x_2, x_2 \mapsto x_3, x_3 \mapsto x_1 \}$ can be represented by the vector containing $ x_1, x_2, x_3 $.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 256 of file Linear_Expression_Impl_templates.hh.

References PPL_DIRTY_TEMP_COEFFICIENT, and Parma_Polyhedra_Library::swap().

256  {
257  const dimension_type n = cycle.size();
258  if (n < 2) {
259  return;
260  }
261 
262  if (n == 2) {
263  row.swap_coefficients(cycle[0].space_dimension(),
264  cycle[1].space_dimension());
265  }
266  else {
268  tmp = row.get(cycle.back().space_dimension());
269  for (dimension_type i = n - 1; i-- > 0; ) {
270  row.swap_coefficients(cycle[i + 1].space_dimension(),
271  cycle[i].space_dimension());
272  }
273  if (tmp == 0) {
274  row.reset(cycle[0].space_dimension());
275  }
276  else {
277  using std::swap;
278  swap(tmp, row[cycle[0].space_dimension()]);
279  }
280  }
281  PPL_ASSERT(OK());
282 }
void swap(CO_Tree &x, CO_Tree &y)
size_t dimension_type
An unsigned integral type for representing space dimensions.
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
Declare a local variable named id, of type Coefficient, and containing an unknown initial value...
virtual bool OK() const
Checks if all the invariants are satisfied.
virtual dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::print ( std::ostream &  s) const
virtual

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 469 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Coefficient_zero(), Parma_Polyhedra_Library::neg_assign(), Parma_Polyhedra_Library::IO_Operators::operator<<(), and PPL_DIRTY_TEMP_COEFFICIENT.

469  {
471  bool first = true;
472  for (typename Row::const_iterator i = row.lower_bound(1), i_end = row.end();
473  i != i_end; ++i) {
474  ev = *i;
475  if (ev == 0) {
476  continue;
477  }
478  if (!first) {
479  if (ev > 0) {
480  s << " + ";
481  }
482  else {
483  s << " - ";
484  neg_assign(ev);
485  }
486  }
487  else {
488  first = false;
489  }
490  if (ev == -1) {
491  s << "-";
492  }
493  else if (ev != 1) {
494  s << ev << "*";
495  }
496  IO_Operators::operator<<(s, Variable(i.index() - 1));
497  }
498  // Inhomogeneous term.
500  it = row[0];
501  if (it != 0) {
502  if (!first) {
503  if (it > 0) {
504  s << " + ";
505  }
506  else {
507  s << " - ";
508  neg_assign(it);
509  }
510  }
511  else {
512  first = false;
513  }
514  s << it;
515  }
516 
517  if (first) {
518  // The null linear expression.
519  s << Coefficient_zero();
520  }
521 }
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
Declare a local variable named id, of type Coefficient, and containing an unknown initial value...
std::ostream & operator<<(std::ostream &s, const Ask_Tell< D > &x)
void neg_assign(GMP_Integer &x)
Coefficient_traits::const_reference Coefficient_zero()
Returns a const reference to a Coefficient with value 0.
template<>
void Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::remove_space_dimensions ( const Variables_Set vars)
virtual

Removes all the specified dimensions from the expression.

The space dimension of the variable with the highest space dimension in vars must be at most the space dimension of this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 61 of file Linear_Expression_Impl.cc.

References Parma_Polyhedra_Library::Variables_Set::space_dimension().

61  {
62  PPL_ASSERT(vars.space_dimension() <= space_dimension());
63  if (vars.empty()) {
64  return;
65  }
66 
67  // For each variable to be removed, replace the corresponding coefficient
68  // by shifting left the coefficient to the right that will be kept.
69  Variables_Set::const_iterator vsi = vars.begin();
70  Variables_Set::const_iterator vsi_end = vars.end();
71  dimension_type dst_col = *vsi+1;
72  dimension_type src_col = dst_col + 1;
73  for (++vsi; vsi != vsi_end; ++vsi) {
74  const dimension_type vsi_col = *vsi+1;
75  // Move all columns in between to the left.
76  while (src_col < vsi_col) {
77  row.swap_coefficients(dst_col++, src_col++);
78  }
79  ++src_col;
80  }
81  // Move any remaining columns.
82  const dimension_type sz = row.size();
83  while (src_col < sz) {
84  row.swap_coefficients(dst_col++, src_col++);
85  }
86 
87  // The number of remaining coefficients is `dst_col'.
88  row.resize(dst_col);
89  PPL_ASSERT(OK());
90 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
virtual bool OK() const
Checks if all the invariants are satisfied.
virtual dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
template<>
void Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::remove_space_dimensions ( const Variables_Set vars)
virtual

Removes all the specified dimensions from the expression.

The space dimension of the variable with the highest space dimension in vars must be at most the space dimension of this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 95 of file Linear_Expression_Impl.cc.

References Parma_Polyhedra_Library::CO_Tree::iterator::index(), and Parma_Polyhedra_Library::Variables_Set::space_dimension().

95  {
96  PPL_ASSERT(vars.space_dimension() <= space_dimension());
97  if (vars.empty()) {
98  return;
99  }
100 
101  // For each variable to be removed, replace the corresponding coefficient
102  // by shifting left the coefficient to the right that will be kept.
103  Variables_Set::const_iterator vsi = vars.begin();
104  Variables_Set::const_iterator vsi_end = vars.end();
105  Sparse_Row::iterator src = row.lower_bound(*vsi + 1);
106  const Sparse_Row::iterator& row_end = row.end();
107  dimension_type num_removed = 0;
108  while (vsi != vsi_end) {
109  // Delete the element.
110  if (src != row_end && src.index() == *vsi + 1) {
111  src = row.reset(src);
112  }
113  ++num_removed;
114  ++vsi;
115  if (vsi != vsi_end) {
116  // Shift left the coefficients in [src.index(), *vsi + 1) by num_removed
117  // positions.
118  while (src != row_end && src.index() < *vsi + 1) {
119  row.fast_swap(src.index() - num_removed, src);
120  ++src;
121  }
122  }
123  else {
124  // Shift left the coefficients in [src.index(), row.size()) by
125  // num_removed positions.
126  while (src != row_end) {
127  row.fast_swap(src.index() - num_removed, src);
128  ++src;
129  }
130  }
131  }
132 
133  PPL_ASSERT(num_removed == vars.size());
134 
135  row.resize(row.size() - num_removed);
136  PPL_ASSERT(OK());
137 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
CO_Tree::iterator iterator
An iterator on the row elements.
virtual bool OK() const
Checks if all the invariants are satisfied.
virtual dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
template<typename Row>
virtual void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::remove_space_dimensions ( const Variables_Set vars)
virtual

Removes all the specified dimensions from the expression.

The space dimension of the variable with the highest space dimension in vars must be at most the space dimension of this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
void Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::remove_space_dimensions ( const Variables_Set vars)
virtual

Removes all the specified dimensions from the expression.

The space dimension of the variable with the highest space dimension in vars must be at most the space dimension of this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
void Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::remove_space_dimensions ( const Variables_Set vars)
virtual

Removes all the specified dimensions from the expression.

The space dimension of the variable with the highest space dimension in vars must be at most the space dimension of this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<typename Row>
virtual Representation Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::representation ( ) const
virtual

Returns the current representation of this linear expression.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
Representation Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::representation ( ) const
inlinevirtual

Returns the current representation of this linear expression.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 257 of file Linear_Expression_Impl_inlines.hh.

References Parma_Polyhedra_Library::DENSE.

257  {
258  return DENSE;
259 }
Dense representation: the coefficient sequence is represented as a vector of coefficients, including the zero coefficients. If there are only a few nonzero coefficients, this representation is faster and also uses a bit less memory.
template<>
Representation Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::representation ( ) const
inlinevirtual

Returns the current representation of this linear expression.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 263 of file Linear_Expression_Impl_inlines.hh.

References Parma_Polyhedra_Library::SPARSE.

263  {
264  return SPARSE;
265 }
Sparse representation: only the nonzero coefficient are stored. If there are many nonzero coefficient...
template<>
Representation Parma_Polyhedra_Library::Linear_Expression_Impl< Dense_Row >::representation ( ) const
virtual

Returns the current representation of this linear expression.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<>
Representation Parma_Polyhedra_Library::Linear_Expression_Impl< Sparse_Row >::representation ( ) const
virtual

Returns the current representation of this linear expression.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::scalar_product_assign ( Coefficient result,
const Linear_Expression_Interface y,
dimension_type  start,
dimension_type  end 
) const
virtual

Sets results to the sum of (*this)[i]*y[i], for each i in [start,end).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 1166 of file Linear_Expression_Impl_templates.hh.

1168  {
1169  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
1170  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
1171  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
1172  scalar_product_assign(result, *p, start, end);
1173  }
1174  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
1175  scalar_product_assign(result, *p, start, end);
1176  }
1177  else {
1178  // Add implementations for new derived classes here.
1179  PPL_UNREACHABLE;
1180  }
1181 }
virtual void scalar_product_assign(Coefficient &result, const Linear_Expression_Interface &y, dimension_type start, dimension_type end) const
Sets results to the sum of (*this)[i]*y[i], for each i in [start,end).
template<typename Row >
template<typename Row2 >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::scalar_product_assign ( Coefficient result,
const Linear_Expression_Impl< Row2 > &  y,
dimension_type  start,
dimension_type  end 
) const

Sets results to the sum of (*this)[i]*y[i], for each i in [start,end).

Definition at line 728 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::add_mul_assign(), and Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::row.

730  {
731  const Linear_Expression_Impl<Row>& x = *this;
732  PPL_ASSERT(start <= end);
733  PPL_ASSERT(end <= x.row.size());
734  PPL_ASSERT(end <= y.row.size());
735  result = 0;
736  typename Row ::const_iterator x_i = x.row.lower_bound(start);
737  typename Row ::const_iterator x_end = x.row.lower_bound(end);
738  typename Row2::const_iterator y_i = y.row.lower_bound(start);
739  typename Row2::const_iterator y_end = y.row.lower_bound(end);
740  while (x_i != x_end && y_i != y_end) {
741  if (x_i.index() == y_i.index()) {
742  Parma_Polyhedra_Library::add_mul_assign(result, *x_i, *y_i);
743  ++x_i;
744  ++y_i;
745  }
746  else {
747  if (x_i.index() < y_i.index()) {
748  PPL_ASSERT(y.row.get(x_i.index()) == 0);
749  // (*x_i) * 0 == 0, nothing to do.
750  ++x_i;
751  }
752  else {
753  PPL_ASSERT(x.row.get(y_i.index()) == 0);
754  // 0 * (*y_i) == 0, nothing to do.
755  ++y_i;
756  }
757  }
758  }
759  // In the remaining positions (if any) at most one row is nonzero, so
760  // there's nothing left to do.
761 }
void add_mul_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
template<typename Row >
int Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::scalar_product_sign ( const Linear_Expression_Interface y,
dimension_type  start,
dimension_type  end 
) const
virtual

Computes the sign of the sum of (*this)[i]*y[i], for each i in [start,end).

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 1186 of file Linear_Expression_Impl_templates.hh.

1187  {
1188  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
1189  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
1190  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
1191  return scalar_product_sign(*p, start, end);
1192  }
1193  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
1194  return scalar_product_sign(*p, start, end);
1195  }
1196  else {
1197  // Add implementations for new derived classes here.
1198  PPL_UNREACHABLE;
1199  return 0;
1200  }
1201 }
virtual int scalar_product_sign(const Linear_Expression_Interface &y, dimension_type start, dimension_type end) const
Computes the sign of the sum of (*this)[i]*y[i], for each i in [start,end).
template<typename Row >
template<typename Row2 >
int Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::scalar_product_sign ( const Linear_Expression_Impl< Row2 > &  y,
dimension_type  start,
dimension_type  end 
) const

Computes the sign of the sum of (*this)[i]*y[i], for each i in [start,end).

Definition at line 767 of file Linear_Expression_Impl_templates.hh.

References PPL_DIRTY_TEMP_COEFFICIENT, and Parma_Polyhedra_Library::Boundary_NS::sgn().

768  {
770  scalar_product_assign(result, y, start, end);
771  return sgn(result);
772 }
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
Declare a local variable named id, of type Coefficient, and containing an unknown initial value...
int sgn(Boundary_Type type, const T &x, const Info &info)
virtual void scalar_product_assign(Coefficient &result, const Linear_Expression_Interface &y, dimension_type start, dimension_type end) const
Sets results to the sum of (*this)[i]*y[i], for each i in [start,end).
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::set ( dimension_type  i,
Coefficient_traits::const_reference  n 
)
virtual

Sets the i-th coefficient to n.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 532 of file Linear_Expression_Impl_templates.hh.

532  {
533  if (n == 0) {
534  row.reset(i);
535  }
536  else {
537  row.insert(i, n);
538  }
539  PPL_ASSERT(OK());
540 }
virtual bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::set_coefficient ( Variable  v,
Coefficient_traits::const_reference  n 
)
inlinevirtual

Sets the coefficient of v in *this to n.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 94 of file Linear_Expression_Impl_inlines.hh.

References Parma_Polyhedra_Library::Variable::space_dimension().

94  {
95  PPL_ASSERT(v.space_dimension() <= space_dimension());
96  const dimension_type i = v.space_dimension();
97  if (n == 0) {
98  row.reset(i);
99  }
100  else {
101  row.insert(i, n);
102  }
103  PPL_ASSERT(OK());
104 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
virtual bool OK() const
Checks if all the invariants are satisfied.
virtual dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::set_inhomogeneous_term ( Coefficient_traits::const_reference  n)
inlinevirtual

Sets the inhomogeneous term of *this to n.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 115 of file Linear_Expression_Impl_inlines.hh.

115  {
116  if (n == 0) {
117  row.reset(0);
118  }
119  else {
120  row.insert(0, n);
121  }
122  PPL_ASSERT(OK());
123 }
virtual bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::set_space_dimension ( dimension_type  n)
inlinevirtual

Sets the dimension of the vector space enclosing *this to n .

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 77 of file Linear_Expression_Impl_inlines.hh.

77  {
78  row.resize(n + 1);
79  PPL_ASSERT(OK());
80 }
virtual bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::shift_space_dimensions ( Variable  v,
dimension_type  n 
)
inlinevirtual

Shift by n positions the coefficients of variables, starting from the coefficient of v. This increases the space dimension by n.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 134 of file Linear_Expression_Impl_inlines.hh.

References Parma_Polyhedra_Library::Variable::space_dimension().

135  {
136  row.add_zeroes_and_shift(n, v.space_dimension());
137  PPL_ASSERT(OK());
138 }
virtual bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::sign_normalize ( )
virtual

Ensures that the first nonzero homogeneous coefficient is positive, by negating the row if necessary.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 670 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::neg_assign().

670  {
671  typename Row::iterator i = row.lower_bound(1);
672  typename Row::iterator i_end = row.end();
673 
674  for ( ; i != i_end; ++i) {
675  if (*i != 0) {
676  break;
677  }
678  }
679 
680  if (i != i_end && *i < 0) {
681  for ( ; i != i_end; ++i) {
682  neg_assign(*i);
683  }
684  // Negate the first coefficient, too.
685  typename Row::iterator first = row.begin();
686  if (first != row.end() && first.index() == 0) {
687  neg_assign(*first);
688  }
689  }
690  PPL_ASSERT(OK());
691 }
virtual bool OK() const
Checks if all the invariants are satisfied.
void neg_assign(GMP_Integer &x)
template<typename Row>
virtual Linear_Expression_Impl& Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::sub_mul_assign ( Coefficient_traits::const_reference  n,
const Variable  v 
)
virtual
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::sub_mul_assign ( Coefficient_traits::const_reference  factor,
const Linear_Expression_Interface e2 
)
virtual

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 1032 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::sub_mul_assign().

1033  {
1034  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
1035  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
1036  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
1037  sub_mul_assign(factor, *p);
1038  }
1039  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
1040  sub_mul_assign(factor, *p);
1041  }
1042  else {
1043  // Add implementations for new derived classes here.
1044  PPL_UNREACHABLE;
1045  }
1046 }
virtual Linear_Expression_Impl & sub_mul_assign(Coefficient_traits::const_reference n, const Variable v)
template<typename Row>
template<typename Row2 >
Linear_Expression_Impl& Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::sub_mul_assign ( Coefficient_traits::const_reference  n,
const Linear_Expression_Impl< Row2 > &  y,
dimension_type  start,
dimension_type  end 
)
template<typename Row >
template<typename Row2 >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::sub_mul_assign ( Coefficient_traits::const_reference  factor,
const Linear_Expression_Impl< Row2 > &  e2 
)

Definition at line 460 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Coefficient_one(), and Parma_Polyhedra_Library::linear_combine().

461  {
462  if (factor != 0) {
463  linear_combine(y, Coefficient_one(), -factor);
464  }
465 }
virtual void linear_combine(const Linear_Expression_Interface &y, Variable v)
Coefficient_traits::const_reference Coefficient_one()
Returns a const reference to a Coefficient with value 1.
template<typename Row >
void Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::swap_space_dimensions ( Variable  v1,
Variable  v2 
)
inlinevirtual

Swaps the coefficients of the variables v1 and v2 .

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 127 of file Linear_Expression_Impl_inlines.hh.

References Parma_Polyhedra_Library::Variable::space_dimension().

127  {
128  row.swap_coefficients(v1.space_dimension(), v2.space_dimension());
129  PPL_ASSERT(OK());
130 }
virtual bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
memory_size_type Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::total_memory_in_bytes ( ) const
inlinevirtual

Returns a lower bound to the total size in bytes of the memory occupied by *this.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 148 of file Linear_Expression_Impl_inlines.hh.

References Parma_Polyhedra_Library::external_memory_in_bytes().

148  {
149  return external_memory_in_bytes() + sizeof(*this);
150 }
virtual memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.

Friends And Related Function Documentation

template<typename Row >
Linear_Expression_Impl< Row > & add_mul_assign ( Coefficient_traits::const_reference  n,
const Variable  v 
)
related

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 395 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Variable::space_dimension().

396  {
397  const dimension_type v_space_dim = v.space_dimension();
399  throw std::length_error("Linear_Expression_Impl& "
400  "add_mul_assign(e, n, v):\n"
401  "v exceeds the maximum allowed space dimension.");
402  }
403  if (space_dimension() < v_space_dim) {
404  set_space_dimension(v_space_dim);
405  }
406  if (n == 0) {
407  return *this;
408  }
409  typename Row::iterator itr = row.insert(v_space_dim);
410  (*itr) += n;
411  if (*itr == 0) {
412  row.reset(itr);
413  }
414  PPL_ASSERT(OK());
415  return *this;
416 }
dimension_type max_space_dimension()
Returns the maximum space dimension this library can handle.
size_t dimension_type
An unsigned integral type for representing space dimensions.
virtual bool OK() const
Checks if all the invariants are satisfied.
virtual void set_space_dimension(dimension_type n)
Sets the dimension of the vector space enclosing *this to n .
virtual dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
template<typename Row >
int Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::compare ( const Linear_Expression_Interface y) const
related

The basic comparison function.

Returns
-1 or -2 if x is less than y, 0 if they are equal and 1 or 2 is y is greater. The absolute value of the result is 1 if the difference is only in the inhomogeneous terms, 2 otherwise.

The order is a lexicographic. It starts comparing the variables' coefficient, starting from Variable(0), and at the end it compares the inhomogeneous terms.

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 1111 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::compare().

1111  {
1112  typedef const Linear_Expression_Impl<Dense_Row>* Dense_Ptr;
1113  typedef const Linear_Expression_Impl<Sparse_Row>* Sparse_Ptr;
1114  if (const Dense_Ptr p = dynamic_cast<Dense_Ptr>(&y)) {
1115  return compare(*p);
1116  }
1117  else if (const Sparse_Ptr p = dynamic_cast<Sparse_Ptr>(&y)) {
1118  return compare(*p);
1119  }
1120  else {
1121  // Add implementations for new derived classes here.
1122  PPL_UNREACHABLE;
1123  return 0;
1124  }
1125 }
virtual int compare(const Linear_Expression_Interface &y) const
The basic comparison function.
template<typename Row >
template<typename Row2 >
int Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::compare ( const Linear_Expression_Impl< Row2 > &  y) const
related

The basic comparison function.

Returns
-1 or -2 if x is less than y, 0 if they are equal and 1 or 2 is y is greater. The absolute value of the result is 1 if the difference is only in the inhomogeneous terms, 2 otherwise.

The order is a lexicographic. It starts comparing the variables' coefficient, starting from Variable(0), and at the end it compares the inhomogeneous terms.

Definition at line 154 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::cmp(), Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::row, and Parma_Polyhedra_Library::Boundary_NS::sgn().

154  {
155  const Linear_Expression_Impl& x = *this;
156  // Compare all the coefficients of the row starting from position 1.
157  // NOTE: x and y may be of different size.
158  typename Row::const_iterator i = x.row.lower_bound(1);
159  typename Row::const_iterator i_end = x.row.end();
160  typename Row2::const_iterator j = y.row.lower_bound(1);
161  typename Row2::const_iterator j_end = y.row.end();
162  while (i != i_end && j != j_end) {
163  if (i.index() < j.index()) {
164  const int s = sgn(*i);
165  if (s != 0) {
166  return 2*s;
167  }
168  ++i;
169  continue;
170  }
171  if (i.index() > j.index()) {
172  const int s = sgn(*j);
173  if (s != 0) {
174  return -2*s;
175  }
176  ++j;
177  continue;
178  }
179  PPL_ASSERT(i.index() == j.index());
180  const int s = cmp(*i, *j);
181  if (s < 0) {
182  return -2;
183  }
184  if (s > 0) {
185  return 2;
186  }
187  PPL_ASSERT(s == 0);
188  ++i;
189  ++j;
190  }
191  for ( ; i != i_end; ++i) {
192  const int s = sgn(*i);
193  if (s != 0) {
194  return 2*s;
195  }
196  }
197  for ( ; j != j_end; ++j) {
198  const int s = sgn(*j);
199  if (s != 0) {
200  return -2*s;
201  }
202  }
203 
204  // If all the coefficients in `x' equal all the coefficients in `y'
205  // (starting from position 1) we compare coefficients in position 0,
206  // i.e., inhomogeneous terms.
207  const int comp = cmp(x.row.get(0), y.row.get(0));
208  if (comp > 0) {
209  return 1;
210  }
211  if (comp < 0) {
212  return -1;
213  }
214  PPL_ASSERT(comp == 0);
215 
216  // `x' and `y' are equal.
217  return 0;
218 }
Linear_Expression_Impl()
Default constructor: returns a copy of Linear_Expression_Impl::zero().
int cmp(const GMP_Integer &x, const GMP_Integer &y)
int sgn(Boundary_Type type, const T &x, const Info &info)
template<typename Row>
template<typename Row2 >
friend class Linear_Expression_Impl
friend

Definition at line 734 of file Linear_Expression_Impl_defs.hh.

template<typename Row >
void negate ( )
related

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 384 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::neg_assign().

384  {
385  for (typename Row::iterator i = row.begin(),
386  i_end = row.end(); i != i_end; ++i) {
387  neg_assign(*i);
388  }
389  PPL_ASSERT(OK());
390 }
virtual bool OK() const
Checks if all the invariants are satisfied.
void neg_assign(GMP_Integer &x)
template<typename Row >
Linear_Expression_Impl< Row > & operator*= ( Coefficient_traits::const_reference  n)
related

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 348 of file Linear_Expression_Impl_templates.hh.

348  {
349  if (n == 0) {
350  row.clear();
351  PPL_ASSERT(OK());
352  return *this;
353  }
354  for (typename Row::iterator i = row.begin(),
355  i_end = row.end(); i != i_end; ++i) {
356  (*i) *= n;
357  }
358  PPL_ASSERT(OK());
359  return *this;
360 }
virtual bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
Linear_Expression_Impl< Row > & operator+= ( const Variable  v)
related

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 295 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Variable::space_dimension().

295  {
296  const dimension_type v_space_dim = v.space_dimension();
298  throw std::length_error("Linear_Expression_Impl& "
299  "operator+=(e, v):\n"
300  "v exceeds the maximum allowed space dimension.");
301  }
302  if (space_dimension() < v_space_dim) {
303  set_space_dimension(v_space_dim);
304  }
305  typename Row::iterator itr = row.insert(v_space_dim);
306  ++(*itr);
307  if (*itr == 0) {
308  row.reset(itr);
309  }
310  PPL_ASSERT(OK());
311  return *this;
312 }
dimension_type max_space_dimension()
Returns the maximum space dimension this library can handle.
size_t dimension_type
An unsigned integral type for representing space dimensions.
virtual bool OK() const
Checks if all the invariants are satisfied.
virtual void set_space_dimension(dimension_type n)
Sets the dimension of the vector space enclosing *this to n .
virtual dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
template<typename Row >
template<typename Row2 >
Linear_Expression_Impl< Row > & operator-= ( const Linear_Expression_Impl< Row2 > &  e2)
related

Definition at line 318 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Coefficient_one(), and Parma_Polyhedra_Library::linear_combine().

318  {
319  linear_combine(e2, Coefficient_one(), -1);
320  return *this;
321 }
virtual void linear_combine(const Linear_Expression_Interface &y, Variable v)
Coefficient_traits::const_reference Coefficient_one()
Returns a const reference to a Coefficient with value 1.
template<typename Row >
Linear_Expression_Impl< Row > & operator-= ( const Variable  v)
related

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 326 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Variable::space_dimension().

326  {
327  const dimension_type v_space_dim = v.space_dimension();
329  throw std::length_error("Linear_Expression_Impl& "
330  "operator-=(e, v):\n"
331  "v exceeds the maximum allowed space dimension.");
332  }
333  if (space_dimension() < v_space_dim) {
334  set_space_dimension(v_space_dim);
335  }
336  typename Row::iterator itr = row.insert(v_space_dim);
337  --(*itr);
338  if (*itr == 0) {
339  row.reset(itr);
340  }
341  PPL_ASSERT(OK());
342  return *this;
343 }
dimension_type max_space_dimension()
Returns the maximum space dimension this library can handle.
size_t dimension_type
An unsigned integral type for representing space dimensions.
virtual bool OK() const
Checks if all the invariants are satisfied.
virtual void set_space_dimension(dimension_type n)
Sets the dimension of the vector space enclosing *this to n .
virtual dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
template<typename Row >
Linear_Expression_Impl< Row > & operator/= ( Coefficient_traits::const_reference  n)
related

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 365 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::begin().

365  {
366  typename Row::iterator i = row.begin();
367  const typename Row::iterator& i_end = row.end();
368  while (i != i_end) {
369  (*i) /= n;
370  if (*i == 0) {
371  i = row.reset(i);
372  }
373  else {
374  ++i;
375  }
376  }
377  PPL_ASSERT(OK());
378  return *this;
379 }
virtual bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
std::ostream & operator<< ( std::ostream &  s,
const Linear_Expression_Impl< Row > &  e 
)
related

Output operator.

Definition at line 285 of file Linear_Expression_Impl_inlines.hh.

285  {
286  e.print(s);
287  return s;
288 }
template<typename Row >
Linear_Expression_Impl< Row > & sub_mul_assign ( Coefficient_traits::const_reference  n,
const Variable  v 
)
related

Implements Parma_Polyhedra_Library::Linear_Expression_Interface.

Definition at line 422 of file Linear_Expression_Impl_templates.hh.

References Parma_Polyhedra_Library::Variable::space_dimension().

423  {
424  const dimension_type v_space_dim = v.space_dimension();
426  throw std::length_error("Linear_Expression_Impl& "
427  "sub_mul_assign(e, n, v):\n"
428  "v exceeds the maximum allowed space dimension.");
429  }
430  if (space_dimension() < v_space_dim) {
431  set_space_dimension(v_space_dim);
432  }
433  if (n == 0) {
434  return *this;
435  }
436  typename Row::iterator itr = row.insert(v_space_dim);
437  (*itr) -= n;
438  if (*itr == 0) {
439  row.reset(itr);
440  }
441  PPL_ASSERT(OK());
442  return *this;
443 }
dimension_type max_space_dimension()
Returns the maximum space dimension this library can handle.
size_t dimension_type
An unsigned integral type for representing space dimensions.
virtual bool OK() const
Checks if all the invariants are satisfied.
virtual void set_space_dimension(dimension_type n)
Sets the dimension of the vector space enclosing *this to n .
virtual dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.

Member Data Documentation


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