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

A sparse matrix of Coefficient. More...

#include <Matrix_defs.hh>

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

Public Types

typedef Swapping_Vector< Row >::iterator iterator
 
typedef Swapping_Vector< Row >::const_iterator const_iterator
 

Public Member Functions

 Matrix (dimension_type n=0)
 Constructs a square matrix with the given size, filled with unstored zeroes. More...
 
 Matrix (dimension_type num_rows, dimension_type num_columns)
 Constructs a matrix with the given dimensions, filled with unstored zeroes. More...
 
void m_swap (Matrix &x)
 Swaps (*this) with x. More...
 
dimension_type num_rows () const
 Returns the number of rows in the matrix. More...
 
dimension_type num_columns () const
 Returns the number of columns in the matrix. More...
 
dimension_type capacity () const
 Returns the capacity of the row vector. More...
 
bool has_no_rows () const
 Returns true if and only if *this has no rows. More...
 
void resize (dimension_type n)
 Equivalent to resize(n, n). More...
 
void reserve_rows (dimension_type n)
 Reserves space for at least n rows. More...
 
void resize (dimension_type num_rows, dimension_type num_columns)
 Resizes this matrix to the specified dimensions. More...
 
void add_zero_rows_and_columns (dimension_type n, dimension_type m)
 Adds n rows and m columns of zeroes to the matrix. More...
 
void add_zero_rows (dimension_type n)
 Adds to the matrix n rows of zeroes. More...
 
void add_row (const Row &x)
 Adds a copy of the row x at the end of the matrix. More...
 
void add_recycled_row (Row &y)
 Adds the row y to the matrix. More...
 
void remove_trailing_rows (dimension_type n)
 Removes from the matrix the last n rows. More...
 
void remove_rows (iterator first, iterator last)
 
void permute_columns (const std::vector< dimension_type > &cycles)
 Permutes the columns of the matrix. More...
 
void swap_columns (dimension_type i, dimension_type j)
 Swaps the columns having indexes i and j. More...
 
void add_zero_columns (dimension_type n)
 Adds n columns of zeroes to the matrix. More...
 
void add_zero_columns (dimension_type n, dimension_type i)
 Adds n columns of non-stored zeroes to the matrix before column i. More...
 
void remove_column (dimension_type i)
 Removes the i-th from the matrix, shifting other columns to the left. More...
 
void remove_trailing_columns (dimension_type n)
 Shrinks the matrix by removing its n trailing columns. More...
 
void clear ()
 Equivalent to resize(0,0). More...
 
iterator begin ()
 Returns an iterator pointing to the first row. More...
 
iterator end ()
 Returns an iterator pointing after the last row. More...
 
const_iterator begin () const
 Returns an iterator pointing to the first row. More...
 
const_iterator end () const
 Returns an iterator pointing after the last row. More...
 
Row & operator[] (dimension_type i)
 Returns a reference to the i-th row. More...
 
const Row & operator[] (dimension_type i) const
 Returns a const reference to the i-th row. More...
 
bool ascii_load (std::istream &s)
 Loads the row from an ASCII representation generated using ascii_dump(). More...
 
void ascii_dump () const
 Writes to std::cerr an ASCII representation of *this. More...
 
void ascii_dump (std::ostream &s) const
 Writes to s an ASCII representation of *this. More...
 
void print () const
 Prints *this to std::cerr using operator<<. More...
 
memory_size_type total_memory_in_bytes () const
 Returns the total size in bytes of the memory occupied by *this. More...
 
memory_size_type external_memory_in_bytes () const
 Returns the size in bytes of the memory managed by *this. More...
 
bool OK () const
 Checks if all the invariants are satisfied. More...
 

Static Public Member Functions

static dimension_type max_num_rows ()
 Returns the maximum number of rows of a Sparse_Matrix. More...
 
static dimension_type max_num_columns ()
 Returns the maximum number of columns of a Sparse_Matrix. More...
 

Private Attributes

Swapping_Vector< Row > rows
 The vector that stores the matrix's elements. More...
 
dimension_type num_columns_
 The number of columns in this matrix. More...
 

Related Functions

(Note that these are not member functions.)

template<typename Row >
void swap (Matrix< Row > &x, Matrix< Row > &y)
 
template<typename Row >
bool operator== (const Matrix< Row > &x, const Matrix< Row > &y)
 Returns true if and only if x and y are identical. More...
 
template<typename Row >
bool operator!= (const Matrix< Row > &x, const Matrix< Row > &y)
 Returns true if and only if x and y are different. More...
 
template<typename Row >
bool operator== (const Matrix< Row > &x, const Matrix< Row > &y)
 
template<typename Row >
bool operator!= (const Matrix< Row > &x, const Matrix< Row > &y)
 

Detailed Description

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

A sparse matrix of Coefficient.

Definition at line 37 of file Matrix_defs.hh.

Member Typedef Documentation

template<typename Row>
typedef Swapping_Vector<Row>::const_iterator Parma_Polyhedra_Library::Matrix< Row >::const_iterator

Definition at line 41 of file Matrix_defs.hh.

template<typename Row>
typedef Swapping_Vector<Row>::iterator Parma_Polyhedra_Library::Matrix< Row >::iterator

Definition at line 40 of file Matrix_defs.hh.

Constructor & Destructor Documentation

template<typename Row >
Parma_Polyhedra_Library::Matrix< Row >::Matrix ( dimension_type  n = 0)
explicit

Constructs a square matrix with the given size, filled with unstored zeroes.

Parameters
nThe size of the new square matrix.

This method takes $O(n)$ time.

Definition at line 30 of file Matrix_templates.hh.

References Parma_Polyhedra_Library::Matrix< Row >::num_columns_, Parma_Polyhedra_Library::Matrix< Row >::OK(), Parma_Polyhedra_Library::Swapping_Vector< T >::resize(), Parma_Polyhedra_Library::Matrix< Row >::rows, and Parma_Polyhedra_Library::Swapping_Vector< T >::size().

31  : rows(n), num_columns_(n) {
32  for (dimension_type i = 0; i < rows.size(); ++i) {
34  }
35  PPL_ASSERT(OK());
36 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type num_columns_
The number of columns in this matrix.
Definition: Matrix_defs.hh:406
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
Parma_Polyhedra_Library::Matrix< Row >::Matrix ( dimension_type  num_rows,
dimension_type  num_columns 
)

Constructs a matrix with the given dimensions, filled with unstored zeroes.

Parameters
num_rowsThe number of rows in the new matrix.
num_columnsThe number of columns in the new matrix.

This method takes $O(n)$ time, where n is num_rows.

Definition at line 39 of file Matrix_templates.hh.

References Parma_Polyhedra_Library::Matrix< Row >::num_columns_, Parma_Polyhedra_Library::Matrix< Row >::OK(), Parma_Polyhedra_Library::Swapping_Vector< T >::resize(), Parma_Polyhedra_Library::Matrix< Row >::rows, and Parma_Polyhedra_Library::Swapping_Vector< T >::size().

41  for (dimension_type i = 0; i < rows.size(); ++i) {
43  }
44  PPL_ASSERT(OK());
45 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type num_columns() const
Returns the number of columns in the matrix.
dimension_type num_columns_
The number of columns in this matrix.
Definition: Matrix_defs.hh:406
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
bool OK() const
Checks if all the invariants are satisfied.
dimension_type num_rows() const
Returns the number of rows in the matrix.

Member Function Documentation

template<typename Row>
void Parma_Polyhedra_Library::Matrix< Row >::add_recycled_row ( Row &  y)
inline

Adds the row y to the matrix.

Parameters
yThe row to be added: it must have the same size and capacity as *this. It is not declared const because its data-structures will recycled to build the new matrix row.

Turns the $r \times c$ matrix $M$ into the $(r+1) \times c$ matrix $\genfrac{(}{)}{0pt}{}{M}{y}$. The matrix is expanded avoiding reallocation whenever possible.

Definition at line 111 of file Matrix_inlines.hh.

References Parma_Polyhedra_Library::swap().

111  {
112  add_zero_rows(1);
113  swap(rows.back(), x);
114  PPL_ASSERT(OK());
115 }
void swap(Matrix< Row > &x, Matrix< Row > &y)
void add_zero_rows(dimension_type n)
Adds to the matrix n rows of zeroes.
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row>
void Parma_Polyhedra_Library::Matrix< Row >::add_row ( const Row &  x)
inline

Adds a copy of the row x at the end of the matrix.

Parameters
xThe row that will be appended to the matrix.

This operation invalidates existing iterators.

This method takes $O(n)$ amortized time, where n is the numer of elements stored in x.

Definition at line 100 of file Matrix_inlines.hh.

References Parma_Polyhedra_Library::swap().

Referenced by Parma_Polyhedra_Library::PIP_Tree_Node::compatibility_check(), and Parma_Polyhedra_Library::PIP_Solution_Node::solve().

100  {
101  // TODO: Optimize this.
102  Row row(x);
103  add_zero_rows(1);
104  // Now x may have been invalidated, if it was a row of this matrix.
105  swap(rows.back(), row);
106  PPL_ASSERT(OK());
107 }
void swap(Matrix< Row > &x, Matrix< Row > &y)
void add_zero_rows(dimension_type n)
Adds to the matrix n rows of zeroes.
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Matrix< Row >::add_zero_columns ( dimension_type  n)
inline

Adds n columns of zeroes to the matrix.

Parameters
nThe number of columns to be added: must be strictly positive.

Turns the $r \times c$ matrix $M$ into the $r \times (c+n)$ matrix $(M \, 0)$.

This method takes $O(r)$ amortized time, where r is the numer of the matrix's rows.

Definition at line 131 of file Matrix_inlines.hh.

Referenced by Parma_Polyhedra_Library::PIP_Solution_Node::generate_cut().

131  {
132  resize(num_rows(), num_columns() + n);
133 }
dimension_type num_columns() const
Returns the number of columns in the matrix.
void resize(dimension_type n)
Equivalent to resize(n, n).
dimension_type num_rows() const
Returns the number of rows in the matrix.
template<typename Row >
void Parma_Polyhedra_Library::Matrix< Row >::add_zero_columns ( dimension_type  n,
dimension_type  i 
)

Adds n columns of non-stored zeroes to the matrix before column i.

Parameters
nThe numer of columns that will be added.
iThe index of the column before which the new columns will be added.

This operation invalidates existing iterators.

This method takes $O(\sum_{j=1}^{r} (k_j+\log n_j))$ time, where r is the number of rows, $k_j$ is the number of elements stored in the columns of the j-th row that must be shifted and $n_j$ is the number of elements stored in the j-th row. A weaker (but simpler) bound is $O(k+r*\log c)$ time, where k is the number of elements that must be shifted, r is the number of the rows and c is the number of the columns.

Definition at line 120 of file Matrix_templates.hh.

120  {
121  for (dimension_type j = rows.size(); j-- > 0; ) {
122  rows[j].add_zeroes_and_shift(n, i);
123  }
124  num_columns_ += n;
125  PPL_ASSERT(OK());
126 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type num_columns_
The number of columns in this matrix.
Definition: Matrix_defs.hh:406
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Matrix< Row >::add_zero_rows ( dimension_type  n)
inline

Adds to the matrix n rows of zeroes.

Parameters
nThe number of rows to be added: must be strictly positive.

Turns the $r \times c$ matrix $M$ into the $(r+n) \times c$ matrix $\genfrac{(}{)}{0pt}{}{M}{0}$. The matrix is expanded avoiding reallocation whenever possible.

This method takes $O(k)$ amortized time, where k is the number of the new rows.

Definition at line 94 of file Matrix_inlines.hh.

Referenced by Parma_Polyhedra_Library::PIP_Tree_Node::compatibility_check(), and Parma_Polyhedra_Library::PIP_Solution_Node::generate_cut().

94  {
95  resize(num_rows() + n, num_columns());
96 }
dimension_type num_columns() const
Returns the number of columns in the matrix.
void resize(dimension_type n)
Equivalent to resize(n, n).
dimension_type num_rows() const
Returns the number of rows in the matrix.
template<typename Row >
void Parma_Polyhedra_Library::Matrix< Row >::add_zero_rows_and_columns ( dimension_type  n,
dimension_type  m 
)
inline

Adds n rows and m columns of zeroes to the matrix.

Parameters
nThe number of rows to be added: must be strictly positive.
mThe number of columns to be added: must be strictly positive.

Turns the $r \times c$ matrix $M$ into the $(r+n) \times (c+m)$ matrix $\bigl(\genfrac{}{}{0pt}{}{M}{0} \genfrac{}{}{0pt}{}{0}{0}\bigr)$. The matrix is expanded avoiding reallocation whenever possible.

This method takes $O(r)$ time, where r is the number of the matrix's rows after the operation.

Definition at line 88 of file Matrix_inlines.hh.

88  {
89  resize(num_rows() + n, num_columns() + m);
90 }
dimension_type num_columns() const
Returns the number of columns in the matrix.
void resize(dimension_type n)
Equivalent to resize(n, n).
dimension_type num_rows() const
Returns the number of rows in the matrix.
template<typename Row >
void Parma_Polyhedra_Library::Matrix< Row >::ascii_dump ( std::ostream &  s) const

Writes to s an ASCII representation of *this.

Definition at line 140 of file Matrix_templates.hh.

140  {
141  s << num_rows() << " x ";
142  s << num_columns() << "\n";
143  for (const_iterator i = begin(), i_end = end(); i !=i_end; ++i) {
144  i->ascii_dump(s);
145  }
146 }
iterator end()
Returns an iterator pointing after the last row.
Swapping_Vector< Row >::const_iterator const_iterator
Definition: Matrix_defs.hh:41
iterator begin()
Returns an iterator pointing to the first row.
dimension_type num_columns() const
Returns the number of columns in the matrix.
dimension_type num_rows() const
Returns the number of rows in the matrix.
template<typename Row>
void Parma_Polyhedra_Library::Matrix< Row >::ascii_dump ( ) const

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

Referenced by Parma_Polyhedra_Library::PIP_Solution_Node::solve().

template<typename Row >
bool Parma_Polyhedra_Library::Matrix< Row >::ascii_load ( std::istream &  s)

Loads the row from an ASCII representation generated using ascii_dump().

Parameters
sThe stream from which read the ASCII representation.

This method takes $O(n*\log n)$ time.

Definition at line 152 of file Matrix_templates.hh.

References Parma_Polyhedra_Library::ascii_load().

152  {
153  std::string str;
154  dimension_type new_num_rows;
155  dimension_type new_num_cols;
156  if (!(s >> new_num_rows)) {
157  return false;
158  }
159  if (!(s >> str) || str != "x") {
160  return false;
161  }
162  if (!(s >> new_num_cols)) {
163  return false;
164  }
165 
166  for (iterator i = rows.begin(), i_end = rows.end();
167  i != i_end; ++i) {
168  i->clear();
169  }
170 
171  resize(new_num_rows, new_num_cols);
172 
173  for (dimension_type row = 0; row < new_num_rows; ++row) {
174  if (!rows[row].ascii_load(s)) {
175  return false;
176  }
177  }
178 
179  // Check invariants.
180  PPL_ASSERT(OK());
181  return true;
182 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
bool ascii_load(std::istream &s)
Loads the row from an ASCII representation generated using ascii_dump().
Swapping_Vector< Row >::iterator iterator
Definition: Matrix_defs.hh:40
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
void resize(dimension_type n)
Equivalent to resize(n, n).
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
Matrix< Row >::iterator Parma_Polyhedra_Library::Matrix< Row >::begin ( )
inline

Returns an iterator pointing to the first row.

This method takes $O(1)$ time.

Definition at line 150 of file Matrix_inlines.hh.

150  {
151  return rows.begin();
152 }
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
template<typename Row >
Matrix< Row >::const_iterator Parma_Polyhedra_Library::Matrix< Row >::begin ( ) const
inline

Returns an iterator pointing to the first row.

This method takes $O(1)$ time.

Definition at line 162 of file Matrix_inlines.hh.

162  {
163  return rows.begin();
164 }
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
template<typename Row >
dimension_type Parma_Polyhedra_Library::Matrix< Row >::capacity ( ) const
inline

Returns the capacity of the row vector.

Definition at line 63 of file Matrix_inlines.hh.

63  {
64  return rows.capacity();
65 }
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
template<typename Row >
void Parma_Polyhedra_Library::Matrix< Row >::clear ( )
inline

Equivalent to resize(0,0).

Definition at line 144 of file Matrix_inlines.hh.

144  {
145  resize(0, 0);
146 }
void resize(dimension_type n)
Equivalent to resize(n, n).
template<typename Row >
Matrix< Row >::iterator Parma_Polyhedra_Library::Matrix< Row >::end ( )
inline

Returns an iterator pointing after the last row.

This method takes $O(1)$ time.

Definition at line 156 of file Matrix_inlines.hh.

156  {
157  return rows.end();
158 }
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
template<typename Row >
Matrix< Row >::const_iterator Parma_Polyhedra_Library::Matrix< Row >::end ( ) const
inline

Returns an iterator pointing after the last row.

This method takes $O(1)$ time.

Definition at line 168 of file Matrix_inlines.hh.

168  {
169  return rows.end();
170 }
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
template<typename Row >
memory_size_type Parma_Polyhedra_Library::Matrix< Row >::external_memory_in_bytes ( ) const

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

This method is $O(r+k)$, where r is the number of rows and k is the number of elements stored in the matrix.

Definition at line 186 of file Matrix_templates.hh.

186  {
188 }
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
template<typename Row >
bool Parma_Polyhedra_Library::Matrix< Row >::has_no_rows ( ) const
inline

Returns true if and only if *this has no rows.

Note
The unusual naming for this method is intentional: we do not want it to be named empty because this would cause an error prone name clash with the corresponding methods in derived classes Constraint_System and Congruence_System (which have a different semantics).

Definition at line 69 of file Matrix_inlines.hh.

69  {
70  return num_rows() == 0;
71 }
dimension_type num_rows() const
Returns the number of rows in the matrix.
template<typename Row >
void Parma_Polyhedra_Library::Matrix< Row >::m_swap ( Matrix< Row > &  x)
inline

Swaps (*this) with x.

Parameters
xThe matrix that will be swapped with *this.

This method takes $O(1)$ time.

Definition at line 43 of file Matrix_inlines.hh.

References Parma_Polyhedra_Library::Matrix< Row >::num_columns_, Parma_Polyhedra_Library::Matrix< Row >::rows, and Parma_Polyhedra_Library::swap().

Referenced by Parma_Polyhedra_Library::swap().

43  {
44  using std::swap;
45  swap(rows, x.rows);
46  swap(num_columns_, x.num_columns_);
47 }
void swap(Matrix< Row > &x, Matrix< Row > &y)
void swap(Matrix< Row > &x, Matrix< Row > &y)
dimension_type num_columns_
The number of columns in this matrix.
Definition: Matrix_defs.hh:406
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
template<typename Row >
dimension_type Parma_Polyhedra_Library::Matrix< Row >::max_num_columns ( )
inlinestatic

Returns the maximum number of columns of a Sparse_Matrix.

Definition at line 37 of file Matrix_inlines.hh.

37  {
38  return Row::max_size();
39 }
template<typename Row >
dimension_type Parma_Polyhedra_Library::Matrix< Row >::max_num_rows ( )
inlinestatic

Returns the maximum number of rows of a Sparse_Matrix.

Definition at line 31 of file Matrix_inlines.hh.

31  {
32  return std::vector<Row>().max_size();
33 }
template<typename Row >
dimension_type Parma_Polyhedra_Library::Matrix< Row >::num_columns ( ) const
inline

Returns the number of columns in the matrix.

This method takes $O(1)$ time.

Definition at line 57 of file Matrix_inlines.hh.

Referenced by Parma_Polyhedra_Library::PIP_Tree_Node::compatibility_check(), and Parma_Polyhedra_Library::Matrix< Row >::operator==().

57  {
58  return num_columns_;
59 }
dimension_type num_columns_
The number of columns in this matrix.
Definition: Matrix_defs.hh:406
template<typename Row >
dimension_type Parma_Polyhedra_Library::Matrix< Row >::num_rows ( ) const
inline
template<typename Row >
bool Parma_Polyhedra_Library::Matrix< Row >::OK ( ) const

Checks if all the invariants are satisfied.

Definition at line 192 of file Matrix_templates.hh.

Referenced by Parma_Polyhedra_Library::PIP_Tree_Node::compatibility_check(), and Parma_Polyhedra_Library::Matrix< Row >::Matrix().

192  {
193  for (const_iterator i = begin(), i_end = end(); i != i_end; ++i) {
194  if (i->size() != num_columns_) {
195  return false;
196  }
197  }
198  return true;
199 }
iterator end()
Returns an iterator pointing after the last row.
Swapping_Vector< Row >::const_iterator const_iterator
Definition: Matrix_defs.hh:41
iterator begin()
Returns an iterator pointing to the first row.
dimension_type num_columns_
The number of columns in this matrix.
Definition: Matrix_defs.hh:406
template<typename Row >
Row & Parma_Polyhedra_Library::Matrix< Row >::operator[] ( dimension_type  i)
inline

Returns a reference to the i-th row.

Parameters
iThe index of the desired row.

This method takes $O(1)$ time.

Definition at line 174 of file Matrix_inlines.hh.

174  {
175  PPL_ASSERT(i < rows.size());
176  return rows[i];
177 }
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
template<typename Row >
const Row & Parma_Polyhedra_Library::Matrix< Row >::operator[] ( dimension_type  i) const
inline

Returns a const reference to the i-th row.

Parameters
iThe index of the desired row.

This method takes $O(1)$ time.

Definition at line 181 of file Matrix_inlines.hh.

181  {
182  PPL_ASSERT(i < rows.size());
183  return rows[i];
184 }
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
template<typename Row >
void Parma_Polyhedra_Library::Matrix< Row >::permute_columns ( const std::vector< dimension_type > &  cycles)

Permutes the columns of the matrix.

This method may be slow for some Row types, and should be avoided if possible.

Parameters
cyclesA vector representing the non-trivial cycles of the permutation according to which the columns must be rearranged.

The cycles vector contains, one after the other, the non-trivial cycles (i.e., the cycles of length greater than one) of a permutation of non-zero column indexes. Each cycle is terminated by zero. For example, assuming the matrix has 7 columns, the permutation $ \{ 1 \mapsto 3, 2 \mapsto 4, 3 \mapsto 6, 4 \mapsto 2, 5 \mapsto 5, 6 \mapsto 1 \}$ can be represented by the non-trivial cycles $(1 3 6)(2 4)$ that, in turn can be represented by a vector of 6 elements containing 1, 3, 6, 0, 2, 4, 0.

This method takes $O(k*\sum_{j=1}^{r} \log^2 n_j)$ expected time, where k is the size of the cycles vector, r the number of rows and $n_j$ the number of elements stored in row j. A weaker (but simpler) bound is $O(k*r*\log^2 c)$, where k is the size of the cycles vector, r is the number of rows and c is the number of columns.

Note
The first column of the matrix, having index zero, is never involved in a permutation.

Definition at line 75 of file Matrix_templates.hh.

References PPL_DIRTY_TEMP_COEFFICIENT, and Parma_Polyhedra_Library::swap().

75  {
77  const dimension_type n = cycles.size();
78  PPL_ASSERT(cycles[n - 1] == 0);
79  for (dimension_type k = num_rows(); k-- > 0; ) {
80  Row& rows_k = (*this)[k];
81  for (dimension_type i = 0, j = 0; i < n; i = ++j) {
82  // Make `j' be the index of the next cycle terminator.
83  while (cycles[j] != 0) {
84  ++j;
85  }
86  // Cycles of length less than 2 are not allowed.
87  PPL_ASSERT(j - i >= 2);
88  if (j - i == 2) {
89  // For cycles of length 2 no temporary is needed, just a swap.
90  rows_k.swap_coefficients(cycles[i], cycles[i + 1]);
91  }
92  else {
93  // Longer cycles need a temporary.
94  tmp = rows_k.get(cycles[j - 1]);
95  for (dimension_type l = (j - 1); l > i; --l) {
96  rows_k.swap_coefficients(cycles[l-1], cycles[l]);
97  }
98  if (tmp == 0) {
99  rows_k.reset(cycles[i]);
100  }
101  else {
102  using std::swap;
103  swap(tmp, rows_k[cycles[i]]);
104  }
105  }
106  }
107  }
108 }
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...
void swap(Matrix< Row > &x, Matrix< Row > &y)
dimension_type num_rows() const
Returns the number of rows in the matrix.
template<typename Row>
void Parma_Polyhedra_Library::Matrix< Row >::print ( ) const

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

template<typename Row >
void Parma_Polyhedra_Library::Matrix< Row >::remove_column ( dimension_type  i)

Removes the i-th from the matrix, shifting other columns to the left.

Parameters
iThe index of the column that will be removed.

This operation invalidates existing iterators on rows' elements.

This method takes $O(k + \sum_{j=1}^{r} (\log^2 n_j))$ amortized time, where k is the number of elements stored with column index greater than i, r the number of rows in this matrix and $n_j$ the number of elements stored in row j. A weaker (but simpler) bound is $O(r*(c-i+\log^2 c))$, where r is the number of rows, c is the number of columns and i is the parameter passed to this method.

Definition at line 130 of file Matrix_templates.hh.

130  {
131  for (dimension_type j = rows.size(); j-- > 0; ) {
132  rows[j].delete_element_and_shift(i);
133  }
134  --num_columns_;
135  PPL_ASSERT(OK());
136 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type num_columns_
The number of columns in this matrix.
Definition: Matrix_defs.hh:406
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Matrix< Row >::remove_rows ( iterator  first,
iterator  last 
)
inline

Definition at line 125 of file Matrix_inlines.hh.

125  {
126  rows.erase(first, last);
127 }
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
template<typename Row >
void Parma_Polyhedra_Library::Matrix< Row >::remove_trailing_columns ( dimension_type  n)
inline

Shrinks the matrix by removing its n trailing columns.

Parameters
nThe number of trailing columns that will be removed.

This operation invalidates existing iterators.

This method takes $O(\sum_{j=1}^r (k_j*\log n_j))$ amortized time, where r is the number of rows, $k_j$ is the number of elements that have to be removed from row j and $n_j$ is the total number of elements stored in row j. A weaker (but simpler) bound is $O(r*n*\log c)$, where r is the number of rows, c the number of columns and n the parameter passed to this method.

Definition at line 137 of file Matrix_inlines.hh.

137  {
138  PPL_ASSERT(n <= num_columns());
139  resize(num_rows(), num_columns() - n);
140 }
dimension_type num_columns() const
Returns the number of columns in the matrix.
void resize(dimension_type n)
Equivalent to resize(n, n).
dimension_type num_rows() const
Returns the number of rows in the matrix.
template<typename Row >
void Parma_Polyhedra_Library::Matrix< Row >::remove_trailing_rows ( dimension_type  n)
inline

Removes from the matrix the last n rows.

Parameters
nThe number of row that will be removed.

It is equivalent to num_rows() - n, num_columns()).

This method takes $O(n+k)$ amortized time, where k is the total number of elements stored in the removed rows and n is the number of removed rows.

Definition at line 119 of file Matrix_inlines.hh.

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

119  {
120  resize(num_rows() - n, num_columns());
121 }
dimension_type num_columns() const
Returns the number of columns in the matrix.
void resize(dimension_type n)
Equivalent to resize(n, n).
dimension_type num_rows() const
Returns the number of rows in the matrix.
template<typename Row >
void Parma_Polyhedra_Library::Matrix< Row >::reserve_rows ( dimension_type  n)
inline

Reserves space for at least n rows.

Definition at line 81 of file Matrix_inlines.hh.

81  {
82 
83  rows.reserve(requested_capacity);
84 }
void reserve(dimension_type new_capacity)
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
template<typename Row >
void Parma_Polyhedra_Library::Matrix< Row >::resize ( dimension_type  n)
inline

Equivalent to resize(n, n).

Definition at line 75 of file Matrix_inlines.hh.

75  {
76  resize(n, n);
77 }
void resize(dimension_type n)
Equivalent to resize(n, n).
template<typename Row >
void Parma_Polyhedra_Library::Matrix< Row >::resize ( dimension_type  num_rows,
dimension_type  num_columns 
)

Resizes this matrix to the specified dimensions.

Parameters
num_rowsThe desired numer of rows.
num_columnsThe desired numer of columns.

New rows and columns will contain non-stored zeroes.

This operation invalidates existing iterators.

Adding n rows takes $O(n)$ amortized time.

Adding n columns takes $O(r)$ time, where r is num_rows.

Removing n rows takes $O(n+k)$ amortized time, where k is the total number of elements stored in the removed rows.

Removing n columns takes $O(\sum_{j=1}^{r} (k_j*\log^2 n_j))$ time, where r is the number of rows, $k_j$ is the number of elements stored in the columns of the j-th row that must be removed and $n_j$ is the total number of elements stored in the j-th row. A weaker (but simpler) bound is $O(r+k*\log^2 c)$, where r is the number of rows, k is the number of elements that have to be removed and c is the number of columns.

Definition at line 49 of file Matrix_templates.hh.

49  {
50  const dimension_type old_num_rows = rows.size();
52  if (old_num_rows < num_rows) {
53  for (dimension_type i = old_num_rows; i < num_rows; ++i) {
55  }
56  if (num_columns_ != num_columns) {
58  for (dimension_type i = 0; i < old_num_rows; ++i) {
60  }
61  }
62  }
63  else
64  if (num_columns_ != num_columns) {
66  for (dimension_type i = 0; i < num_rows; ++i) {
68  }
69  }
70  PPL_ASSERT(OK());
71 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type num_columns() const
Returns the number of columns in the matrix.
dimension_type num_columns_
The number of columns in this matrix.
Definition: Matrix_defs.hh:406
Swapping_Vector< Row > rows
The vector that stores the matrix's elements.
Definition: Matrix_defs.hh:403
bool OK() const
Checks if all the invariants are satisfied.
dimension_type num_rows() const
Returns the number of rows in the matrix.
template<typename Row >
void Parma_Polyhedra_Library::Matrix< Row >::swap_columns ( dimension_type  i,
dimension_type  j 
)

Swaps the columns having indexes i and j.

Definition at line 112 of file Matrix_templates.hh.

112  {
113  for (dimension_type k = num_rows(); k-- > 0; ) {
114  (*this)[k].swap_coefficients(i, j);
115  }
116 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type num_rows() const
Returns the number of rows in the matrix.
template<typename Row >
memory_size_type Parma_Polyhedra_Library::Matrix< Row >::total_memory_in_bytes ( ) const
inline

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

This method is $O(r+k)$, where r is the number of rows and k is the number of elements stored in the matrix.

Definition at line 188 of file Matrix_inlines.hh.

References Parma_Polyhedra_Library::external_memory_in_bytes().

188  {
189  return sizeof(*this) + external_memory_in_bytes();
190 }
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 >
bool operator!= ( const Matrix< Row > &  x,
const Matrix< Row > &  y 
)
related

Definition at line 222 of file Matrix_templates.hh.

222  {
223  return !(x == y);
224 }
template<typename Row >
bool operator!= ( const Matrix< Row > &  x,
const Matrix< Row > &  y 
)
related

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

template<typename Row >
bool operator== ( const Matrix< Row > &  x,
const Matrix< Row > &  y 
)
related

Definition at line 204 of file Matrix_templates.hh.

References Parma_Polyhedra_Library::Matrix< Row >::num_columns(), and Parma_Polyhedra_Library::Matrix< Row >::num_rows().

204  {
205  if (x.num_rows() != y.num_rows()) {
206  return false;
207  }
208  if (x.num_columns() != y.num_columns()) {
209  return false;
210  }
211  for (dimension_type i = x.num_rows(); i-- > 0; ) {
212  if (x[i] != y[i]) {
213  return false;
214  }
215  }
216  return true;
217 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
template<typename Row >
bool operator== ( const Matrix< Row > &  x,
const Matrix< Row > &  y 
)
related

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

template<typename Row >
void swap ( Matrix< Row > &  x,
Matrix< Row > &  y 
)
related

Definition at line 194 of file Matrix_inlines.hh.

194  {
195  x.m_swap(y);
196 }

Member Data Documentation

template<typename Row>
dimension_type Parma_Polyhedra_Library::Matrix< Row >::num_columns_
private

The number of columns in this matrix.

Definition at line 406 of file Matrix_defs.hh.

Referenced by Parma_Polyhedra_Library::Matrix< Row >::m_swap(), and Parma_Polyhedra_Library::Matrix< Row >::Matrix().

template<typename Row>
Swapping_Vector<Row> Parma_Polyhedra_Library::Matrix< Row >::rows
private

The vector that stores the matrix's elements.

Definition at line 403 of file Matrix_defs.hh.

Referenced by Parma_Polyhedra_Library::Matrix< Row >::m_swap(), and Parma_Polyhedra_Library::Matrix< Row >::Matrix().


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