Parma_Polyhedra_Library::OR_Matrix< T > Class Template Reference

A matrix representing octagonal constraints. More...

#include <OR_Matrix.defs.hh>

Inheritance diagram for Parma_Polyhedra_Library::OR_Matrix< T >:

Inheritance graph
[legend]

List of all members.

Public Types

typedef Pseudo_Row< T > row_reference_type
 A (non const) reference to a matrix's row.
typedef Pseudo_Row< const T > const_row_reference_type
 A const reference to a matrix's row.
typedef any_row_iterator< T > row_iterator
 A (non const) row iterator.
typedef any_row_iterator< const T > const_row_iterator
 A const row iterator.
typedef DB_Row< T >::iterator element_iterator
 A (non const) element iterator.
typedef DB_Row< T >::const_iterator const_element_iterator
 A const element iterator.

Public Member Functions

 OR_Matrix (dimension_type space_dim)
 Builds a matrix with specified dimensions.
 OR_Matrix (const OR_Matrix &y)
 Copy-constructor.
template<typename U>
 OR_Matrix (const OR_Matrix< U > &y)
 Constructs a conservative approximation of y.
 ~OR_Matrix ()
 Destructor.
OR_Matrixoperator= (const OR_Matrix &y)
 Assignment operator.
void swap (OR_Matrix &y)
 Swaps *this with y.
void grow (dimension_type new_dim)
 Makes the matrix grow by adding more space dimensions.
void shrink (dimension_type new_dim)
 Makes the matrix shrink by removing the last space dimensions.
void resize_no_copy (dimension_type new_dim)
 Resizes the matrix without worrying about the old contents.
dimension_type space_dimension () const
 Returns the space-dimension of the matrix.
dimension_type num_rows () const
 Returns the number of rows in the matrix.
row_iterator row_begin ()
 Returns an iterator pointing to the first row, if *this is not empty; otherwise, returns the past-the-end const_iterator.
row_iterator row_end ()
 Returns the past-the-end const_iterator.
const_row_iterator row_begin () const
 Returns a const row iterator pointing to the first row, if *this is not empty; otherwise, returns the past-the-end const_iterator.
const_row_iterator row_end () const
 Returns the past-the-end const row iterator.
element_iterator element_begin ()
 Returns an iterator pointing to the first element, if *this is not empty; otherwise, returns the past-the-end const_iterator.
element_iterator element_end ()
 Returns the past-the-end const_iterator.
const_element_iterator element_begin () const
 Returns a const element iterator pointing to the first element, if *this is not empty; otherwise, returns the past-the-end const_iterator.
const_element_iterator element_end () const
 Returns the past-the-end const element iterator.
void clear ()
 Clears the matrix deallocating all its rows.
void ascii_dump () const
 Writes to std::cerr an ASCII representation of *this.
void ascii_dump (std::ostream &s) const
 Writes to s an ASCII representation of *this.
void print () const
 Prints *this to std::cerr using operator<<.
bool ascii_load (std::istream &s)
 Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this accordingly. Returns true if successful, false otherwise.
memory_size_type total_memory_in_bytes () const
 Returns the total size in bytes of the memory occupied by *this.
memory_size_type external_memory_in_bytes () const
 Returns the size in bytes of the memory managed by *this.
bool OK () const
 Checks if all the invariants are satisfied.
Subscript operators.
row_reference_type operator[] (dimension_type k)
 Returns a reference to the k-th row of the matrix.
const_row_reference_type operator[] (dimension_type k) const
 Returns a constant reference to the k-th row of the matrix.

Static Public Member Functions

static dimension_type max_num_rows ()
 Returns the maximum number of rows of a OR_Matrix.
static dimension_type row_size (dimension_type k)
 Returns the size of the row of index k.

Private Member Functions

 OR_Matrix ()
 Private and not implemented: default construction is not allowed.

Static Private Member Functions

static dimension_type row_first_element_index (dimension_type k)
 Returns the index into vec of the first element of the row of index k.

Private Attributes

DB_Row< T > vec
 Contains the rows of the matrix.
dimension_type space_dim
 Contains the dimension of the space of the matrix.
dimension_type vec_capacity
 Contains the capacity of vec.

Friends

class OR_Matrix
bool operator== (const OR_Matrix< T > &x, const OR_Matrix< T > &y)
 Returns true if and only if x and y are identical.

Related Functions

(Note that these are not member functions.)

template<typename T>
std::ostream & operator<< (std::ostream &s, const OR_Matrix< T > &m)
 Output operator.
template<typename T>
void swap (Parma_Polyhedra_Library::OR_Matrix< T > &x, Parma_Polyhedra_Library::OR_Matrix< T > &y)
 Specializes std::swap.
template<typename T>
bool operator!= (const OR_Matrix< T > &x, const OR_Matrix< T > &y)
 Returns true if and only if x and y are different.
template<typename Temp, typename To, typename T>
bool rectilinear_distance_assign (Checked_Number< To, Extended_Number_Policy > &r, const OR_Matrix< T > &x, const OR_Matrix< T > &y, Rounding_Dir dir, Temp &tmp0, Temp &tmp1, Temp &tmp2)
 Computes the rectilinear (or Manhattan) distance between x and y.
template<typename Temp, typename To, typename T>
bool euclidean_distance_assign (Checked_Number< To, Extended_Number_Policy > &r, const OR_Matrix< T > &x, const OR_Matrix< T > &y, Rounding_Dir dir, Temp &tmp0, Temp &tmp1, Temp &tmp2)
 Computes the euclidean distance between x and y.
template<typename Temp, typename To, typename T>
bool l_infinity_distance_assign (Checked_Number< To, Extended_Number_Policy > &r, const OR_Matrix< T > &x, const OR_Matrix< T > &y, Rounding_Dir dir, Temp &tmp0, Temp &tmp1, Temp &tmp2)
 Computes the $L_\infty$ distance between x and y.
template<typename Specialization, typename Temp, typename To, typename T>
bool l_m_distance_assign (Checked_Number< To, Extended_Number_Policy > &r, const OR_Matrix< T > &x, const OR_Matrix< T > &y, const Rounding_Dir dir, Temp &tmp0, Temp &tmp1, Temp &tmp2)

Classes

class  any_row_iterator
 A template class to derive both OR_Matrix::iterator and OR_Matrix::const_iterator. More...
class  Pseudo_Row
 An object that behaves like a matrix's row with respect to the subscript operators. More...


Detailed Description

template<typename T>
class Parma_Polyhedra_Library::OR_Matrix< T >

A matrix representing octagonal constraints.

An OR_Matrix object is a DB_Row object that allows the representation of a pseudo-triangular matrix, like the following:

         _ _
   0    |_|_|
   1    |_|_|_ _
   2    |_|_|_|_|
   3    |_|_|_|_|_ _
   4    |_|_|_|_|_|_|
   5    |_|_|_|_|_|_|
         . . .
         _ _ _ _ _ _       _
 2n-2   |_|_|_|_|_|_| ... |_|
 2n-1   |_|_|_|_|_|_| ... |_|
         0 1 2 3 4 5  ... 2n-1

It is characterized by parameter n that defines the structure, and such that there are 2*n rows (and 2*n columns). It provides row_iterators for the access to the rows and element_iterators for the access to the elements.

Definition at line 105 of file OR_Matrix.defs.hh.


Member Typedef Documentation

template<typename T>
typedef Pseudo_Row<T> Parma_Polyhedra_Library::OR_Matrix< T >::row_reference_type

A (non const) reference to a matrix's row.

Definition at line 190 of file OR_Matrix.defs.hh.

template<typename T>
typedef Pseudo_Row<const T> Parma_Polyhedra_Library::OR_Matrix< T >::const_row_reference_type

A const reference to a matrix's row.

Definition at line 193 of file OR_Matrix.defs.hh.

template<typename T>
typedef any_row_iterator<T> Parma_Polyhedra_Library::OR_Matrix< T >::row_iterator

A (non const) row iterator.

Definition at line 322 of file OR_Matrix.defs.hh.

template<typename T>
typedef any_row_iterator<const T> Parma_Polyhedra_Library::OR_Matrix< T >::const_row_iterator

A const row iterator.

Definition at line 325 of file OR_Matrix.defs.hh.

template<typename T>
typedef DB_Row<T>::iterator Parma_Polyhedra_Library::OR_Matrix< T >::element_iterator

A (non const) element iterator.

Definition at line 328 of file OR_Matrix.defs.hh.

template<typename T>
typedef DB_Row<T>::const_iterator Parma_Polyhedra_Library::OR_Matrix< T >::const_element_iterator

A const element iterator.

Definition at line 331 of file OR_Matrix.defs.hh.


Constructor & Destructor Documentation

template<typename T>
Parma_Polyhedra_Library::OR_Matrix< T >::OR_Matrix ( dimension_type  space_dim  )  [inline]

Builds a matrix with specified dimensions.

Parameters:
space_dim The space dimension of the matrix that will be created.
This constructor creates a matrix with 2*space_dim rows. Each element is initialized to plus infinity.

Definition at line 436 of file OR_Matrix.inlines.hh.

00437   : vec(2*dim*(dim+1)),
00438     space_dim(dim),
00439     vec_capacity(vec.size()) {
00440 }

template<typename T>
Parma_Polyhedra_Library::OR_Matrix< T >::OR_Matrix ( const OR_Matrix< T > &  y  )  [inline]

Copy-constructor.

Definition at line 505 of file OR_Matrix.inlines.hh.

00506   : vec(y.vec),
00507     space_dim(y.space_dim),
00508     vec_capacity(compute_capacity(y.vec.size())) {
00509 }

template<typename T>
template<typename U>
Parma_Polyhedra_Library::OR_Matrix< T >::OR_Matrix ( const OR_Matrix< U > &  y  )  [inline, explicit]

Constructs a conservative approximation of y.

Definition at line 514 of file OR_Matrix.inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::OK(), Parma_Polyhedra_Library::OR_Matrix< T >::vec, and Parma_Polyhedra_Library::OR_Matrix< T >::vec_capacity.

00515   : vec(),
00516     space_dim(y.space_dim),
00517     vec_capacity(compute_capacity(y.vec.size())) {
00518   vec.construct_upward_approximation(y.vec, vec_capacity);
00519   assert(OK());
00520 }

template<typename T>
Parma_Polyhedra_Library::OR_Matrix< T >::~OR_Matrix (  )  [inline]

Destructor.

Definition at line 444 of file OR_Matrix.inlines.hh.

00444                          {
00445 }

template<typename T>
Parma_Polyhedra_Library::OR_Matrix< T >::OR_Matrix (  )  [private]

Private and not implemented: default construction is not allowed.


Member Function Documentation

template<typename T>
dimension_type Parma_Polyhedra_Library::OR_Matrix< T >::max_num_rows (  )  [inline, static]

Returns the maximum number of rows of a OR_Matrix.

Definition at line 420 of file OR_Matrix.inlines.hh.

References Parma_Polyhedra_Library::isqrt().

00420                            {
00421   // Compute the maximum number of rows that
00422   // are contained in a DB_Row that allocates
00423   // a pseudo-triangular matrix.
00424   dimension_type k = isqrt(2*DB_Row<T>::max_size() + 1);
00425   return (k-1) & ~dimension_type(1);
00426 }

template<typename T>
OR_Matrix< T > & Parma_Polyhedra_Library::OR_Matrix< T >::operator= ( const OR_Matrix< T > &  y  )  [inline]

Assignment operator.

Definition at line 524 of file OR_Matrix.inlines.hh.

References Parma_Polyhedra_Library::compute_capacity(), Parma_Polyhedra_Library::OR_Matrix< T >::space_dim, Parma_Polyhedra_Library::OR_Matrix< T >::vec, and Parma_Polyhedra_Library::OR_Matrix< T >::vec_capacity.

00524                                           {
00525   vec = y.vec;
00526   space_dim = y.space_dim;
00527   vec_capacity = compute_capacity(y.vec.size());
00528   return *this;
00529 }

template<typename T>
dimension_type Parma_Polyhedra_Library::OR_Matrix< T >::row_first_element_index ( dimension_type  k  )  [inline, static, private]

Returns the index into vec of the first element of the row of index k.

Definition at line 39 of file OR_Matrix.inlines.hh.

Referenced by Parma_Polyhedra_Library::OR_Matrix< T >::operator[]().

00039                                                             {
00040   return ((k+1)*(k+1))/2;
00041 }

template<typename T>
dimension_type Parma_Polyhedra_Library::OR_Matrix< T >::row_size ( dimension_type  k  )  [inline, static]

template<typename T>
void Parma_Polyhedra_Library::OR_Matrix< T >::swap ( OR_Matrix< T > &  y  )  [inline]

template<typename T>
void Parma_Polyhedra_Library::OR_Matrix< T >::grow ( dimension_type  new_dim  )  [inline]

Makes the matrix grow by adding more space dimensions.

Parameters:
new_dim The new dimension of the resized matrix.
Adds new rows of right dimension to the end if there is enough capacity; otherwise, creates a new matrix, with the specified dimension, copying the old elements in the upper part of the new matrix, which is then assigned to *this. Each new element is initialized to plus infinity.

Definition at line 533 of file OR_Matrix.inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::element_begin(), Parma_Polyhedra_Library::OR_Matrix< T >::element_end(), Parma_Polyhedra_Library::OR_Matrix< T >::space_dim, Parma_Polyhedra_Library::OR_Matrix< T >::swap(), Parma_Polyhedra_Library::OR_Matrix< T >::vec, and Parma_Polyhedra_Library::OR_Matrix< T >::vec_capacity.

00533                                                {
00534   assert(new_dim >= space_dim);
00535   if (new_dim > space_dim) {
00536     const dimension_type new_size = 2*new_dim*(new_dim + 1);
00537     if (new_size <= vec_capacity) {
00538       // We can recycle the old vec.
00539       vec.expand_within_capacity(new_size);
00540       space_dim = new_dim;
00541     }
00542     else {
00543       // We cannot recycle the old vec.
00544       OR_Matrix<T> new_matrix(new_dim);
00545       element_iterator j = new_matrix.element_begin();
00546       for (element_iterator i = element_begin(),
00547              mend = element_end(); i != mend; ++i, ++j)
00548         assign_or_swap(*j, *i);
00549       swap(new_matrix);
00550     }
00551   }
00552 }

template<typename T>
void Parma_Polyhedra_Library::OR_Matrix< T >::shrink ( dimension_type  new_dim  )  [inline]

Makes the matrix shrink by removing the last space dimensions.

Parameters:
new_dim The new dimension of the resized matrix.
Erases from matrix to the end the rows with index greater than 2*new_dim-1.

Definition at line 556 of file OR_Matrix.inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::space_dim, and Parma_Polyhedra_Library::OR_Matrix< T >::vec.

Referenced by Parma_Polyhedra_Library::OR_Matrix< T >::resize_no_copy().

00556                                                  {
00557   assert(new_dim <= space_dim);
00558   const dimension_type new_size = 2*new_dim*(new_dim + 1);
00559   vec.shrink(new_size);
00560   space_dim = new_dim;
00561 }

template<typename T>
void Parma_Polyhedra_Library::OR_Matrix< T >::resize_no_copy ( dimension_type  new_dim  )  [inline]

Resizes the matrix without worrying about the old contents.

Parameters:
new_dim The new dimension of the resized matrix.
If the new dimension is greater than the old one, it adds new rows of right dimension to the end if there is enough capacity; otherwise, it creates a new matrix, with the specified dimension, which is then assigned to *this. If the new dimension is less than the old one, it erase from the matrix the rows having index greater than 2*new_dim-1

Definition at line 565 of file OR_Matrix.inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::shrink(), Parma_Polyhedra_Library::OR_Matrix< T >::space_dim, Parma_Polyhedra_Library::OR_Matrix< T >::swap(), Parma_Polyhedra_Library::OR_Matrix< T >::vec, and Parma_Polyhedra_Library::OR_Matrix< T >::vec_capacity.

Referenced by Parma_Polyhedra_Library::OR_Matrix< T >::ascii_load().

00565                                                          {
00566   if (new_dim > space_dim) {
00567     const dimension_type new_size = 2*new_dim*(new_dim + 1);
00568     if (new_size <= vec_capacity) {
00569       // We can recycle the old vec.
00570       vec.expand_within_capacity(new_size);
00571       space_dim = new_dim;
00572     }
00573     else {
00574       // We cannot recycle the old vec.
00575       OR_Matrix<T> new_matrix(new_dim);
00576       swap(new_matrix);
00577     }
00578   }
00579   else if (new_dim < space_dim)
00580     shrink(new_dim);
00581 }

template<typename T>
dimension_type Parma_Polyhedra_Library::OR_Matrix< T >::space_dimension (  )  const [inline]

template<typename T>
dimension_type Parma_Polyhedra_Library::OR_Matrix< T >::num_rows (  )  const [inline]

template<typename T>
OR_Matrix< T >::row_reference_type Parma_Polyhedra_Library::OR_Matrix< T >::operator[] ( dimension_type  k  )  [inline]

template<typename T>
OR_Matrix< T >::const_row_reference_type Parma_Polyhedra_Library::OR_Matrix< T >::operator[] ( dimension_type  k  )  const [inline]

Returns a constant reference to the k-th row of the matrix.

Definition at line 459 of file OR_Matrix.inlines.hh.

References PPL_OR_MATRIX_EXTRA_DEBUG, Parma_Polyhedra_Library::OR_Matrix< T >::row_first_element_index(), Parma_Polyhedra_Library::OR_Matrix< T >::row_size(), and Parma_Polyhedra_Library::OR_Matrix< T >::vec.

00459                                                {
00460   return const_row_reference_type(vec[row_first_element_index(k)]
00461 #if PPL_OR_MATRIX_EXTRA_DEBUG
00462                                   , row_size(k)
00463 #endif
00464                                   );
00465 }

template<typename T>
OR_Matrix< T >::row_iterator Parma_Polyhedra_Library::OR_Matrix< T >::row_begin (  )  [inline]

template<typename T>
OR_Matrix< T >::row_iterator Parma_Polyhedra_Library::OR_Matrix< T >::row_end (  )  [inline]

template<typename T>
OR_Matrix< T >::const_row_iterator Parma_Polyhedra_Library::OR_Matrix< T >::row_begin (  )  const [inline]

Returns a const row iterator pointing to the first row, if *this is not empty; otherwise, returns the past-the-end const_iterator.

Definition at line 361 of file OR_Matrix.inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::num_rows(), and Parma_Polyhedra_Library::OR_Matrix< T >::vec.

00361                               {
00362   return num_rows() == 0 ? const_row_iterator(0) : const_row_iterator(vec[0]);
00363 }

template<typename T>
OR_Matrix< T >::const_row_iterator Parma_Polyhedra_Library::OR_Matrix< T >::row_end (  )  const [inline]

Returns the past-the-end const row iterator.

Definition at line 367 of file OR_Matrix.inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::num_rows().

00367                             {
00368   return const_row_iterator(num_rows());
00369 }

template<typename T>
OR_Matrix< T >::element_iterator Parma_Polyhedra_Library::OR_Matrix< T >::element_begin (  )  [inline]

Returns an iterator pointing to the first element, if *this is not empty; otherwise, returns the past-the-end const_iterator.

Definition at line 373 of file OR_Matrix.inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::vec.

Referenced by Parma_Polyhedra_Library::OR_Matrix< T >::grow(), and Parma_Polyhedra_Library::OR_Matrix< T >::l_m_distance_assign().

00373                             {
00374   return vec.begin();
00375 }

template<typename T>
OR_Matrix< T >::element_iterator Parma_Polyhedra_Library::OR_Matrix< T >::element_end (  )  [inline]

Returns the past-the-end const_iterator.

Definition at line 379 of file OR_Matrix.inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::vec.

Referenced by Parma_Polyhedra_Library::OR_Matrix< T >::grow(), and Parma_Polyhedra_Library::OR_Matrix< T >::l_m_distance_assign().

00379                           {
00380   return vec.end();
00381 }

template<typename T>
OR_Matrix< T >::const_element_iterator Parma_Polyhedra_Library::OR_Matrix< T >::element_begin (  )  const [inline]

Returns a const element iterator pointing to the first element, if *this is not empty; otherwise, returns the past-the-end const_iterator.

Definition at line 385 of file OR_Matrix.inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::vec.

00385                                   {
00386   return vec.begin();
00387 }

template<typename T>
OR_Matrix< T >::const_element_iterator Parma_Polyhedra_Library::OR_Matrix< T >::element_end (  )  const [inline]

Returns the past-the-end const element iterator.

Definition at line 391 of file OR_Matrix.inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::vec.

00391                                 {
00392   return vec.end();
00393 }

template<typename T>
void Parma_Polyhedra_Library::OR_Matrix< T >::clear (  )  [inline]

Clears the matrix deallocating all its rows.

Definition at line 481 of file OR_Matrix.inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::swap().

00481                     {
00482   OR_Matrix<T>(0).swap(*this);
00483 }

template<typename T>
void Parma_Polyhedra_Library::OR_Matrix< T >::ascii_dump (  )  const

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

template<typename T>
void Parma_Polyhedra_Library::OR_Matrix< T >::ascii_dump ( std::ostream &  s  )  const [inline]

Writes to s an ASCII representation of *this.

Definition at line 64 of file OR_Matrix.templates.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::row_begin(), Parma_Polyhedra_Library::OR_Matrix< T >::row_end(), and Parma_Polyhedra_Library::OR_Matrix< T >::space_dimension().

00064                                             {
00065   const OR_Matrix<T>& x = *this;
00066   const char separator = ' ';
00067   dimension_type space = x.space_dimension();
00068   s << space << separator << "\n";
00069   for (const_row_iterator i = x.row_begin(),
00070          x_row_end = x.row_end(); i != x_row_end; ++i) {
00071     const_row_reference_type r = *i;
00072     dimension_type rs = i.row_size();
00073     for (dimension_type j = 0; j < rs; ++j) {
00074       using namespace IO_Operators;
00075       s << r[j] << separator;
00076     }
00077     s << "\n";
00078   }
00079 }

template<typename T>
void Parma_Polyhedra_Library::OR_Matrix< T >::print (  )  const

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

template<typename T>
bool Parma_Polyhedra_Library::OR_Matrix< T >::ascii_load ( std::istream &  s  )  [inline]

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

Definition at line 85 of file OR_Matrix.templates.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::OK(), Parma_Polyhedra_Library::OR_Matrix< T >::resize_no_copy(), Parma_Polyhedra_Library::OR_Matrix< T >::row_begin(), and Parma_Polyhedra_Library::OR_Matrix< T >::row_end().

00085                                       {
00086   dimension_type space;
00087   if (!(s >> space))
00088     return false;
00089   resize_no_copy(space);
00090   for (row_iterator i = row_begin(),
00091          this_row_end = row_end(); i != this_row_end; ++i) {
00092     row_reference_type r_i = *i;
00093     const dimension_type rs = i.row_size();
00094     for (dimension_type j = 0; j < rs; ++j) {
00095       Result r = input(r_i[j], s, ROUND_UP);
00096       // FIXME: V_CVT_STR_UNK is probably not the only possible error.
00097       if (!s || r == V_CVT_STR_UNK)
00098         return false;
00099     }
00100   }
00101   assert(OK());
00102   return true;
00103 }

template<typename T>
memory_size_type Parma_Polyhedra_Library::OR_Matrix< T >::total_memory_in_bytes (  )  const [inline]

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

Definition at line 430 of file OR_Matrix.inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::external_memory_in_bytes().

00430                                           {
00431   return sizeof(*this) + external_memory_in_bytes();
00432 }

template<typename T>
memory_size_type Parma_Polyhedra_Library::OR_Matrix< T >::external_memory_in_bytes (  )  const [inline]

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

Definition at line 32 of file OR_Matrix.templates.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::vec.

Referenced by Parma_Polyhedra_Library::OR_Matrix< T >::total_memory_in_bytes().

00032                                             {
00033   return vec.external_memory_in_bytes();
00034 }

template<typename T>
bool Parma_Polyhedra_Library::OR_Matrix< T >::OK (  )  const [inline]

Checks if all the invariants are satisfied.

Definition at line 38 of file OR_Matrix.templates.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::space_dimension(), Parma_Polyhedra_Library::OR_Matrix< T >::vec, and Parma_Polyhedra_Library::OR_Matrix< T >::vec_capacity.

Referenced by Parma_Polyhedra_Library::OR_Matrix< T >::ascii_load(), and Parma_Polyhedra_Library::OR_Matrix< T >::OR_Matrix().

00038                        {
00039 #ifndef NDEBUG
00040   using std::endl;
00041   using std::cerr;
00042 #endif
00043   // The right number of cells should be in use.
00044   const dimension_type dim = space_dimension();
00045   if (vec.size() != 2*dim*(dim + 1)) {
00046 #ifndef NDEBUG
00047     cerr << "OR_Matrix has a wrong number of cells:\n"
00048          << "vec.size() is " << vec.size()
00049          << ", expected size is " << 2*dim*(dim+1) << "!\n";
00050 #endif
00051     return false;
00052   }
00053 
00054   // The underlying DB_Row should be OK.
00055   if (!vec.OK(vec.size(), vec_capacity))
00056     return false;
00057 
00058   // All checks passed.
00059   return true;
00060 }


Friends And Related Function Documentation

template<typename T>
friend class OR_Matrix [friend]

Definition at line 361 of file OR_Matrix.defs.hh.

template<typename T>
bool operator== ( const OR_Matrix< T > &  x,
const OR_Matrix< T > &  y 
) [friend]

Returns true if and only if x and y are identical.

Definition at line 490 of file OR_Matrix.inlines.hh.

00490                                                          {
00491   return x.space_dim == y.space_dim && x.vec == y.vec;
00492 }

template<typename T>
std::ostream & operator<< ( std::ostream &  s,
const OR_Matrix< T > &  m 
) [related]

Output operator.

Definition at line 110 of file OR_Matrix.templates.hh.

00110                                                              {
00111   for (typename OR_Matrix<T>::const_row_iterator m_iter = m.row_begin(),
00112          m_end = m.row_end(); m_iter != m_end; ++m_iter) {
00113     typename OR_Matrix<T>::const_row_reference_type r_m = *m_iter;
00114     const dimension_type mr_size = m_iter.row_size();
00115     for (dimension_type j = 0; j < mr_size; ++j)
00116       s << r_m[j] << " ";
00117     s << "\n";
00118   }
00119   return s;
00120 }

template<typename T>
void swap ( Parma_Polyhedra_Library::OR_Matrix< T > &  x,
Parma_Polyhedra_Library::OR_Matrix< T > &  y 
) [related]

Specializes std::swap.

Definition at line 703 of file OR_Matrix.inlines.hh.

References Parma_Polyhedra_Library::OR_Matrix< T >::swap().

00704                                              {
00705   x.swap(y);
00706 }

template<typename T>
bool operator!= ( const OR_Matrix< T > &  x,
const OR_Matrix< T > &  y 
) [related]

Returns true if and only if x and y are different.

Definition at line 499 of file OR_Matrix.inlines.hh.

00499                                                          {
00500   return !(x == y);
00501 }

template<typename Temp, typename To, typename T>
bool rectilinear_distance_assign ( Checked_Number< To, Extended_Number_Policy > &  r,
const OR_Matrix< T > &  x,
const OR_Matrix< T > &  y,
Rounding_Dir  dir,
Temp &  tmp0,
Temp &  tmp1,
Temp &  tmp2 
) [related]

Computes the rectilinear (or Manhattan) distance between x and y.

If the rectilinear distance between x and y is defined, stores an approximation of it into to r and returns true; returns false otherwise.

The direction of the approximation is specified by dir.

All computations are performed using the temporary variables tmp0, tmp1 and tmp2.

Definition at line 641 of file OR_Matrix.inlines.hh.

00647                                         {
00648   return
00649     l_m_distance_assign<Rectilinear_Distance_Specialization<Temp> >(r, x, y,
00650                                                                     dir,
00651                                                                     tmp0,
00652                                                                     tmp1,
00653                                                                     tmp2);
00654 }

template<typename Temp, typename To, typename T>
bool euclidean_distance_assign ( Checked_Number< To, Extended_Number_Policy > &  r,
const OR_Matrix< T > &  x,
const OR_Matrix< T > &  y,
Rounding_Dir  dir,
Temp &  tmp0,
Temp &  tmp1,
Temp &  tmp2 
) [related]

Computes the euclidean distance between x and y.

If the Euclidean distance between x and y is defined, stores an approximation of it into to r and returns true; returns false otherwise.

The direction of the approximation is specified by dir.

All computations are performed using the temporary variables tmp0, tmp1 and tmp2.

Definition at line 661 of file OR_Matrix.inlines.hh.

00667                                       {
00668   return
00669     l_m_distance_assign<Euclidean_Distance_Specialization<Temp> >(r, x, y,
00670                                                                   dir,
00671                                                                   tmp0,
00672                                                                   tmp1,
00673                                                                   tmp2);
00674 }

template<typename Temp, typename To, typename T>
bool l_infinity_distance_assign ( Checked_Number< To, Extended_Number_Policy > &  r,
const OR_Matrix< T > &  x,
const OR_Matrix< T > &  y,
Rounding_Dir  dir,
Temp &  tmp0,
Temp &  tmp1,
Temp &  tmp2 
) [related]

Computes the $L_\infty$ distance between x and y.

If the $L_\infty$ distance between x and y is defined, stores an approximation of it into to r and returns true; returns false otherwise.

The direction of the approximation is specified by dir.

All computations are performed using the temporary variables tmp0, tmp1 and tmp2.

Definition at line 681 of file OR_Matrix.inlines.hh.

00687                                        {
00688   return
00689     l_m_distance_assign<L_Infinity_Distance_Specialization<Temp> >(r, x, y,
00690                                                                    dir,
00691                                                                    tmp0,
00692                                                                    tmp1,
00693                                                                    tmp2);
00694 }

template<typename Specialization, typename Temp, typename To, typename T>
bool l_m_distance_assign ( Checked_Number< To, Extended_Number_Policy > &  r,
const OR_Matrix< T > &  x,
const OR_Matrix< T > &  y,
const Rounding_Dir  dir,
Temp &  tmp0,
Temp &  tmp1,
Temp &  tmp2 
) [related]

Definition at line 588 of file OR_Matrix.inlines.hh.

References Parma_Polyhedra_Library::assign_r(), Parma_Polyhedra_Library::combine(), Parma_Polyhedra_Library::OR_Matrix< T >::element_begin(), Parma_Polyhedra_Library::OR_Matrix< T >::element_end(), Parma_Polyhedra_Library::finalize(), Parma_Polyhedra_Library::is_plus_infinity(), Parma_Polyhedra_Library::maybe_assign(), Parma_Polyhedra_Library::OR_Matrix< T >::num_rows(), and PLUS_INFINITY.

00594                                 {
00595   if (x.num_rows() != y.num_rows())
00596     return false;
00597   assign_r(tmp0, 0, ROUND_NOT_NEEDED);
00598   for (typename OR_Matrix<T>::const_element_iterator
00599          i = x.element_begin(), j = y.element_begin(),
00600          mat_end = x.element_end(); i != mat_end; ++i, ++j) {
00601     const T& x_i = *i;
00602     const T& y_i = *j;
00603     if (is_plus_infinity(x_i)) {
00604       if (is_plus_infinity(y_i))
00605         continue;
00606       else {
00607       pinf:
00608         assign_r(r, PLUS_INFINITY, ROUND_NOT_NEEDED);
00609         return true;
00610       }
00611     }
00612     else if (is_plus_infinity(y_i))
00613       goto pinf;
00614 
00615     const Temp* tmp1p;
00616     const Temp* tmp2p;
00617     if (x_i > y_i) {
00618       maybe_assign(tmp1p, tmp1, x_i, dir);
00619       maybe_assign(tmp2p, tmp2, y_i, inverse(dir));
00620     }
00621     else {
00622       maybe_assign(tmp1p, tmp1, y_i, dir);
00623       maybe_assign(tmp2p, tmp2, x_i, inverse(dir));
00624     }
00625     sub_assign_r(tmp1, *tmp1p, *tmp2p, dir);
00626     assert(sgn(tmp1) >= 0);
00627     Specialization::combine(tmp0, tmp1, dir);
00628   }
00629 
00630   Specialization::finalize(tmp0, dir);
00631   assign_r(r, tmp0, dir);
00632   return true;
00633 }


Member Data Documentation

template<typename T>
DB_Row<T> Parma_Polyhedra_Library::OR_Matrix< T >::vec [private]

template<typename T>
dimension_type Parma_Polyhedra_Library::OR_Matrix< T >::space_dim [private]

template<typename T>
dimension_type Parma_Polyhedra_Library::OR_Matrix< T >::vec_capacity [private]


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

Generated on Sat Oct 11 10:41:17 2008 for PPL by  doxygen 1.5.6