Parma_Polyhedra_Library::Grid_Generator_System Class Reference
[C++ Language Interface]

A system of grid generators. More...

#include <Grid_Generator_System.defs.hh>

Inheritance diagram for Parma_Polyhedra_Library::Grid_Generator_System:
Inheritance graph
[legend]
Collaboration diagram for Parma_Polyhedra_Library::Grid_Generator_System:
Collaboration graph
[legend]

List of all members.

Classes

class  const_iterator
 An iterator over a system of grid generators. More...

Public Member Functions

 Grid_Generator_System ()
 Default constructor: builds an empty system of generators.
 Grid_Generator_System (const Grid_Generator &g)
 Builds the singleton system containing only generator g.
 Grid_Generator_System (dimension_type dim)
 Builds an empty system of generators of dimension dim.
 Grid_Generator_System (const Grid_Generator_System &gs)
 Ordinary copy constructor.
 ~Grid_Generator_System ()
 Destructor.
Grid_Generator_Systemoperator= (const Grid_Generator_System &y)
 Assignment operator.
dimension_type space_dimension () const
 Returns the dimension of the vector space enclosing *this.
void clear ()
 Removes all the generators from the generator system and sets its space dimension to 0.
void insert (const Grid_Generator &g)
 Inserts into *this a copy of the generator g, increasing the number of space dimensions if needed.
void recycling_insert (Grid_Generator &g)
 Inserts into *this the generator g, increasing the number of space dimensions if needed.
void recycling_insert (Grid_Generator_System &gs)
 Inserts into *this the generators in gs, increasing the number of space dimensions if needed.
bool empty () const
 Returns true if and only if *this has no generators.
const_iterator begin () const
 Returns the const_iterator pointing to the first generator, if this is not empty; otherwise, returns the past-the-end const_iterator.
const_iterator end () const
 Returns the past-the-end const_iterator.
dimension_type num_rows () const
 Returns the number of rows (generators) in the system.
dimension_type num_parameters () const
 Returns the number of parameters in the system.
dimension_type num_lines () const
 Returns the number of lines in the system.
bool has_points () const
 Returns true if and only if *this contains one or more points.
bool is_equal_to (const Grid_Generator_System &y) const
 Returns true if *this is identical to y.
bool OK () const
 Checks if all the invariants are satisfied.
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.
void swap (Grid_Generator_System &y)
 Swaps *this with y.

Static Public Member Functions

static dimension_type max_space_dimension ()
 Returns the maximum space dimension a Grid_Generator_System can handle.
static void initialize ()
 Initializes the class.
static void finalize ()
 Finalizes the class.
static const
Grid_Generator_System
zero_dim_univ ()
 Returns the singleton system containing only Grid_Generator::zero_dim_point().

Private Member Functions

void set_sorted (bool b)
 Sets the sortedness flag of the system to b.
void unset_pending_rows ()
 Sets the index to indicate that the system has no pending rows.
void set_index_first_pending_row (dimension_type i)
 Sets the index of the first pending row to i.
Grid_Generatoroperator[] (dimension_type k)
 Returns the k- th generator of the system.
const Grid_Generatoroperator[] (dimension_type k) const
 Returns a constant reference to the k- th generator of the system.
void affine_image (dimension_type v, const Linear_Expression &expr, Coefficient_traits::const_reference denominator)
 Assigns to a given variable an affine expression.
void add_universe_rows_and_columns (dimension_type dims)
 Adds dims rows and dims columns of zeroes to the matrix, initializing the added rows as in the universe system.
void remove_space_dimensions (const Variables_Set &vars)
 Removes all the specified dimensions from the generator system.
void remove_higher_space_dimensions (dimension_type new_dimension)
 Removes the higher dimensions of the system so that the resulting system will have dimension new_dimension.
void resize_no_copy (dimension_type new_num_rows, dimension_type new_num_columns)
 Resizes the system without worrying about the old contents.
dimension_type num_columns () const
 Returns the number of columns of the matrix (i.e., the size of the rows).
void erase_to_end (dimension_type first_to_erase)
 Erases from the matrix all the rows but those having an index less than first_to_erase.
void permute_columns (const std::vector< dimension_type > &cycles)
 Permutes the columns of the matrix.

Static Private Attributes

static const
Grid_Generator_System
zero_dim_univ_p = 0
 Holds (between class initialization and finalization) a pointer to the singleton system containing only Grid_Generator::zero_dim_point().

Friends

class Grid
bool operator== (const Grid_Generator_System &x, const Grid_Generator_System &y)
 Returns true if and only if x and y are identical.

Related Functions

(Note that these are not member functions.)



std::ostream & operator<< (std::ostream &s, const Grid_Generator_System &gs)
 Output operator.
void swap (Parma_Polyhedra_Library::Grid_Generator_System &x, Parma_Polyhedra_Library::Grid_Generator_System &y)
 Specializes std::swap.

Detailed Description

A system of grid generators.

An object of the class Grid_Generator_System is a system of grid generators, i.e., a multiset of objects of the class Grid_Generator (lines, parameters and points). When inserting generators in a system, space dimensions are automatically adjusted so that all the generators in the system are defined on the same vector space. A system of grid generators which is meant to define a non-empty grid must include at least one point: the reason is that lines and parameters need a supporting point (lines only specify directions while parameters only specify direction and distance.

In all the examples it is assumed that variables x and y are defined as follows:
  Variable x(0);
  Variable y(1);
Example 1
The following code defines the line having the same direction as the $x$ axis (i.e., the first Cartesian axis) in $\Rset^2$:
  Grid_Generator_System gs;
  gs.insert(grid_line(x + 0*y));
As said above, this system of generators corresponds to an empty grid, because the line has no supporting point. To define a system of generators that does correspond to the $x$ axis, we can add the following code which inserts the origin of the space as a point:
  gs.insert(grid_point(0*x + 0*y));
Since space dimensions are automatically adjusted, the following code obtains the same effect:
  gs.insert(grid_point(0*x));
In contrast, if we had added the following code, we would have defined a line parallel to the $x$ axis through the point $(0, 1)^\transpose \in \Rset^2$.
  gs.insert(grid_point(0*x + 1*y));
Example 2
The following code builds a system of generators corresponding to the grid consisting of all the integral points on the $x$ axes; that is, all points satisfying the congruence relation

\[ \bigl\{\, (x, 0)^\transpose \in \Rset^2 \bigm| x \pmod{1}\ 0 \,\bigr\}, \]

  Grid_Generator_System gs;
  gs.insert(parameter(x + 0*y));
  gs.insert(grid_point(0*x + 0*y));
Example 3
The following code builds a system of generators having three points corresponding to a non-relational grid consisting of all points whose coordinates are integer multiple of 3.
  Grid_Generator_System gs;
  gs.insert(grid_point(0*x + 0*y));
  gs.insert(grid_point(0*x + 3*y));
  gs.insert(grid_point(3*x + 0*y));
Example 4
By using parameters instead of two of the points we can define the same grid as that defined in the previous example. Note that there has to be at least one point and, for this purpose, any point in the grid could be considered. Thus the following code builds two identical grids from the grid generator systems gs and gs1.
  Grid_Generator_System gs;
  gs.insert(grid_point(0*x + 0*y));
  gs.insert(parameter(0*x + 3*y));
  gs.insert(parameter(3*x + 0*y));
  Grid_Generator_System gs1;
  gs1.insert(grid_point(3*x + 3*y));
  gs1.insert(parameter(0*x + 3*y));
  gs1.insert(parameter(3*x + 0*y));
Example 5
The following code builds a system of generators having one point and a parameter corresponding to all the integral points that lie on $x + y = 2$ in $\Rset^2$
  Grid_Generator_System gs;
  gs.insert(grid_point(1*x + 1*y));
  gs.insert(parameter(1*x - 1*y));
Note:
After inserting a multiset of generators in a grid generator system, there are no guarantees that an exact copy of them can be retrieved: in general, only an equivalent grid generator system will be available, where original generators may have been reordered, removed (if they are duplicate or redundant), etc.

Definition at line 179 of file Grid_Generator_System.defs.hh.


Constructor & Destructor Documentation

Parma_Polyhedra_Library::Grid_Generator_System::Grid_Generator_System (  )  [inline]
Parma_Polyhedra_Library::Grid_Generator_System::Grid_Generator_System ( const Grid_Generator g  )  [inline, explicit]

Builds the singleton system containing only generator g.

Definition at line 95 of file Grid_Generator_System.inlines.hh.

References set_sorted().

00096   : Generator_System(g) {
00097   set_sorted(false);
00098 }

Parma_Polyhedra_Library::Grid_Generator_System::Grid_Generator_System ( dimension_type  dim  )  [inline, explicit]
Parma_Polyhedra_Library::Grid_Generator_System::Grid_Generator_System ( const Grid_Generator_System gs  )  [inline]

Ordinary copy constructor.

Definition at line 83 of file Grid_Generator_System.inlines.hh.

00084   : Generator_System(gs) {
00085 }

Parma_Polyhedra_Library::Grid_Generator_System::~Grid_Generator_System (  )  [inline]

Destructor.

Definition at line 101 of file Grid_Generator_System.inlines.hh.

00101                                               {
00102 }


Member Function Documentation

void Parma_Polyhedra_Library::Grid_Generator_System::add_universe_rows_and_columns ( dimension_type  dims  )  [private]

Adds dims rows and dims columns of zeroes to the matrix, initializing the added rows as in the universe system.

Parameters:
dims The number of rows and columns to be added: must be strictly positive.

Turns the $r \times c$ matrix $A$ into the $(r+dims) \times (c+dims)$ matrix $\bigl(\genfrac{}{}{0pt}{}{A}{0} \genfrac{}{}{0pt}{}{0}{B}\bigr)$ where $B$ is the $dims \times dims$ unit matrix of the form $\bigl(\genfrac{}{}{0pt}{}{1}{0} \genfrac{}{}{0pt}{}{0}{1}\bigr)$. The matrix is expanded avoiding reallocation whenever possible.

Definition at line 311 of file Grid_Generator_System.cc.

References Parma_Polyhedra_Library::Matrix::add_zero_rows_and_columns(), Parma_Polyhedra_Library::Linear_Row::LINE_OR_EQUALITY, Parma_Polyhedra_Library::NECESSARILY_CLOSED, num_columns(), num_rows(), Parma_Polyhedra_Library::Matrix::swap_columns(), and unset_pending_rows().

Referenced by Parma_Polyhedra_Library::Grid::add_space_dimensions(), and Parma_Polyhedra_Library::Grid::add_space_dimensions_and_embed().

00311                                                    {
00312   PPL_ASSERT(num_columns() > 0);
00313   dimension_type col = num_columns() - 1;
00314   add_zero_rows_and_columns(dims, dims,
00315                             Linear_Row::Flags(NECESSARILY_CLOSED,
00316                                               Linear_Row::LINE_OR_EQUALITY));
00317   unset_pending_rows();
00318   // Swap the parameter divisor column into the new last column.
00319   swap_columns(col, col + dims);
00320   // Set the diagonal element of each added rows.
00321   dimension_type num_rows = this->num_rows();
00322   for (dimension_type row = num_rows - dims; row < num_rows; ++row, ++col)
00323     const_cast<Coefficient&>(operator[](row)[col]) = 1;
00324 }

void Parma_Polyhedra_Library::Grid_Generator_System::affine_image ( dimension_type  v,
const Linear_Expression expr,
Coefficient_traits::const_reference  denominator 
) [private]

Assigns to a given variable an affine expression.

Parameters:
v Index of the column to which the affine transformation is assigned;
expr The numerator of the affine transformation: $\sum_{i = 0}^{n - 1} a_i x_i + b$;
denominator The denominator of the affine transformation;

We allow affine transformations (see the Section Operations on Rational Grids)to have rational coefficients. Since the coefficients of linear expressions are integers we also provide an integer denominator that will be used as denominator of the affine transformation. The denominator is required to be a positive integer and its default value is 1.

The affine transformation assigns to each element of v -th column the follow expression:

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

expr is a constant parameter and unaltered by this computation.

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 163 of file Grid_Generator_System.cc.

References Parma_Polyhedra_Library::Scalar_Products::assign(), num_columns(), num_rows(), PPL_DIRTY_TEMP_COEFFICIENT, Parma_Polyhedra_Library::Linear_Expression::space_dimension(), space_dimension(), and swap().

Referenced by Parma_Polyhedra_Library::Grid::affine_image(), and Parma_Polyhedra_Library::Grid::affine_preimage().

00165                                                               {
00166   // This is mostly a copy of Generator_System::affine_image.
00167 
00168   Grid_Generator_System& x = *this;
00169   // `v' is the index of a column corresponding to a "user" variable
00170   // (i.e., it cannot be the inhomogeneous term).
00171   PPL_ASSERT(v > 0 && v <= x.space_dimension());
00172   PPL_ASSERT(expr.space_dimension() <= x.space_dimension());
00173   PPL_ASSERT(denominator > 0);
00174 
00175   const dimension_type num_columns = x.num_columns();
00176   const dimension_type num_rows = x.num_rows();
00177 
00178   // Compute the numerator of the affine transformation and assign it
00179   // to the column of `*this' indexed by `v'.
00180   PPL_DIRTY_TEMP_COEFFICIENT(numerator);
00181   for (dimension_type i = num_rows; i-- > 0; ) {
00182     Grid_Generator& row = x[i];
00183     Scalar_Products::assign(numerator, expr, row);
00184     std::swap(numerator, row[v]);
00185   }
00186 
00187   if (denominator != 1)
00188     // Since we want integer elements in the matrix,
00189     // we multiply by `denominator' all the columns of `*this'
00190     // having an index different from `v'.
00191     for (dimension_type i = num_rows; i-- > 0; ) {
00192       Grid_Generator& row = x[i];
00193       for (dimension_type j = num_columns; j-- > 0; )
00194         if (j != v)
00195           row[j] *= denominator;
00196     }
00197 
00198   // If the mapping is not invertible we may have transformed valid
00199   // lines and rays into the origin of the space.
00200   const bool not_invertible = (v > expr.space_dimension() || expr[v] == 0);
00201   if (not_invertible)
00202     x.remove_invalid_lines_and_rays();
00203 }

void Parma_Polyhedra_Library::Grid_Generator_System::ascii_dump ( std::ostream &  s  )  const

Writes to s an ASCII representation of *this.

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 208 of file Grid_Generator_System.cc.

00208                                                         {
00209   const dimension_type num_rows = this->num_rows();
00210   s << num_rows << " x " << num_columns() << '\n';
00211   for (dimension_type i = 0; i < num_rows; ++i)
00212     operator[](i).ascii_dump(s);
00213 }

void Parma_Polyhedra_Library::Grid_Generator_System::ascii_dump (  )  const

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

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Referenced by Parma_Polyhedra_Library::Grid::ascii_dump(), and Parma_Polyhedra_Library::Grid::OK().

bool Parma_Polyhedra_Library::Grid_Generator_System::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.

Resizes the matrix of generators using the numbers of rows and columns read from s, then initializes the coordinates of each generator and its type reading the contents from s.

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 216 of file Grid_Generator_System.cc.

References num_columns(), num_rows(), OK(), resize_no_copy(), set_index_first_pending_row(), and set_sorted().

00216                                                   {
00217   dimension_type num_rows;
00218   dimension_type num_columns;
00219   if (!(s >> num_rows))
00220     return false;
00221   std::string str;
00222   if (!(s >> str) || str != "x")
00223     return false;
00224   if (!(s >> num_columns))
00225       return false;
00226   resize_no_copy(num_rows, num_columns);
00227 
00228   set_sorted(false);
00229   set_index_first_pending_row(num_rows);
00230 
00231   Grid_Generator_System& x = *this;
00232   for (dimension_type i = 0; i < num_rows; ++i)
00233     if (!x[i].ascii_load(s))
00234       return false;
00235 
00236   // Check invariants.
00237   PPL_ASSERT(OK());
00238 
00239   return true;
00240 }

Grid_Generator_System::const_iterator Parma_Polyhedra_Library::Grid_Generator_System::begin (  )  const [inline]

Returns the const_iterator pointing to the first generator, if this is not empty; otherwise, returns the past-the-end const_iterator.

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 238 of file Grid_Generator_System.inlines.hh.

Referenced by Parma_Polyhedra_Library::Grid::map_space_dimensions(), operator<<(), Parma_Polyhedra_Library::Grid::relation_with(), and Parma_Polyhedra_Library::Grid::simplify_using_context_assign().

00238                                    {
00239   return static_cast<Grid_Generator_System::const_iterator>
00240     (Generator_System::begin());
00241 }

void Parma_Polyhedra_Library::Grid_Generator_System::clear (  )  [inline]

Removes all the generators from the generator system and sets its space dimension to 0.

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 130 of file Grid_Generator_System.inlines.hh.

References Parma_Polyhedra_Library::Matrix::add_zero_columns(), set_sorted(), and unset_pending_rows().

Referenced by Parma_Polyhedra_Library::Grid::set_zero_dim_univ().

00130                              {
00131   Generator_System::clear();
00132   // For grid generators, two extra columns are needed.
00133   add_zero_columns(2);
00134   set_sorted(false);
00135   unset_pending_rows();
00136 }

bool Parma_Polyhedra_Library::Grid_Generator_System::empty (  )  const [inline]

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

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 227 of file Grid_Generator_System.inlines.hh.

Referenced by Parma_Polyhedra_Library::Box< ITV >::Box(), and Parma_Polyhedra_Library::Grid_Certificate::Grid_Certificate().

00227                                    {
00228   return Generator_System::empty();
00229 }

Grid_Generator_System::const_iterator Parma_Polyhedra_Library::Grid_Generator_System::end (  )  const [inline]
void Parma_Polyhedra_Library::Grid_Generator_System::erase_to_end ( dimension_type  first_to_erase  )  [inline, private]

Erases from the matrix all the rows but those having an index less than first_to_erase.

Reimplemented from Parma_Polyhedra_Library::Matrix.

Definition at line 59 of file Grid_Generator_System.inlines.hh.

Referenced by Parma_Polyhedra_Library::Grid::remove_higher_space_dimensions().

00059                                                                  {
00060   return Generator_System::erase_to_end(first_to_erase);
00061 }

memory_size_type Parma_Polyhedra_Library::Grid_Generator_System::external_memory_in_bytes (  )  const [inline]

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

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 144 of file Grid_Generator_System.inlines.hh.

Referenced by Parma_Polyhedra_Library::Grid::external_memory_in_bytes().

00144                                                       {
00145   return Generator_System::external_memory_in_bytes();
00146 }

void Parma_Polyhedra_Library::Grid_Generator_System::finalize (  )  [static]

Finalizes the class.

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 253 of file Grid_Generator_System.cc.

References zero_dim_univ_p.

00253                                    {
00254   PPL_ASSERT(zero_dim_univ_p != 0);
00255   delete zero_dim_univ_p;
00256   zero_dim_univ_p = 0;
00257 }

bool Parma_Polyhedra_Library::Grid_Generator_System::has_points (  )  const [inline]

Returns true if and only if *this contains one or more points.

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 250 of file Grid_Generator_System.inlines.hh.

Referenced by Parma_Polyhedra_Library::Grid::add_recycled_grid_generators(), Parma_Polyhedra_Library::Grid::construct(), and Parma_Polyhedra_Library::Grid::OK().

00250                                         {
00251   return Generator_System::has_points();
00252 }

void Parma_Polyhedra_Library::Grid_Generator_System::initialize (  )  [static]
void Parma_Polyhedra_Library::Grid_Generator_System::insert ( const Grid_Generator g  ) 

Inserts into *this a copy of the generator g, increasing the number of space dimensions if needed.

If g is an all-zero parameter then the only action is to ensure that the space dimension of *this is at least the space dimension of g.

Definition at line 85 of file Grid_Generator_System.cc.

References Parma_Polyhedra_Library::Linear_System::add_row(), Parma_Polyhedra_Library::Matrix::add_zero_columns(), Parma_Polyhedra_Library::Grid_Generator::all_homogeneous_terms_are_zero(), Parma_Polyhedra_Library::Linear_System::is_necessarily_closed(), Parma_Polyhedra_Library::Grid_Generator::is_parameter(), num_columns(), Parma_Polyhedra_Library::Linear_System::num_pending_rows(), num_rows(), OK(), Parma_Polyhedra_Library::Matrix::row_capacity, set_index_first_pending_row(), set_sorted(), Parma_Polyhedra_Library::Grid_Generator::size(), space_dimension(), Parma_Polyhedra_Library::Grid_Generator::space_dimension(), swap(), Parma_Polyhedra_Library::Matrix::swap_columns(), and Parma_Polyhedra_Library::Linear_System::topology().

Referenced by Parma_Polyhedra_Library::Grid::add_grid_generator(), Parma_Polyhedra_Library::Grid::add_recycled_grid_generators(), Parma_Polyhedra_Library::Grid::add_space_dimensions(), Parma_Polyhedra_Library::Grid::add_space_dimensions_and_project(), Parma_Polyhedra_Library::Grid::construct(), Parma_Polyhedra_Library::Grid::generalized_affine_image(), Parma_Polyhedra_Library::Grid::generalized_affine_preimage(), Parma_Polyhedra_Library::Grid::Grid(), Parma_Polyhedra_Library::Polyhedron::grid_generators(), Parma_Polyhedra_Library::Grid::map_space_dimensions(), Parma_Polyhedra_Library::Grid::select_wider_generators(), and Parma_Polyhedra_Library::Grid::set_zero_dim_univ().

00085                                                         {
00086   dimension_type g_space_dim = g.space_dimension();
00087 
00088   if (g.is_parameter())
00089     if (g.all_homogeneous_terms_are_zero()) {
00090       dimension_type initial_space_dim = space_dimension();
00091       if (initial_space_dim < g_space_dim) {
00092         // Adjust the space dimension.
00093         add_zero_columns(g_space_dim - initial_space_dim);
00094         // Swap the parameter divisor column into the new last column.
00095         swap_columns(g_space_dim + 1, initial_space_dim + 1);
00096         PPL_ASSERT(OK());
00097       }
00098       return;
00099     }
00100 
00101   {
00102     // This block is a substitute for Generator_System::insert, in
00103     // which the single call to Linear_System::insert has been
00104     // inlined.
00105 
00106     // We are sure that the matrix has no pending rows
00107     // and that the new row is not a pending generator.
00108     PPL_ASSERT(num_pending_rows() == 0);
00109 
00110     // TODO: Consider whether, if possible, it would be better to wrap
00111     //       an NNC Generator, storing the generator divisor in the
00112     //       epsilon column.
00113 
00114     // This is a modified copy of Linear_System::insert.  It is here
00115     // to force Grid_Generator::OK to be used (to work around the
00116     // normalization assertions in Linear_System::OK) and so that the
00117     // parameter divisor column can be moved during the insert.
00118 
00119     // The added row must be strongly normalized and have the same
00120     // topology as the system.
00121     PPL_ASSERT(topology() == g.topology());
00122     // This method is only used when the system has no pending rows.
00123     PPL_ASSERT(num_pending_rows() == 0);
00124 
00125     const dimension_type old_num_rows = num_rows();
00126     const dimension_type old_num_columns = num_columns();
00127     const dimension_type g_size = g.size();
00128 
00129     // Resize the system, if necessary.
00130     PPL_ASSERT(is_necessarily_closed());
00131     if (g_size > old_num_columns) {
00132       add_zero_columns(g_size - old_num_columns);
00133       if (old_num_rows > 0)
00134         // Swap the existing parameter divisor column into the new
00135         // last column.
00136         swap_columns(old_num_columns - 1, g_size - 1);
00137       Matrix::add_row(g);
00138     }
00139     else if (g_size < old_num_columns)
00140       if (old_num_rows == 0)
00141         Matrix::add_row(Linear_Row(g, old_num_columns, row_capacity));
00142       else {
00143         // Create a resized copy of the row (and move the parameter
00144         // divisor coefficient to its last position).
00145         Linear_Row tmp_row(g, old_num_columns, row_capacity);
00146         std::swap(tmp_row[g_size - 1], tmp_row[old_num_columns - 1]);
00147         Matrix::add_row(tmp_row);
00148       }
00149     else
00150       // Here r_size == old_num_columns.
00151       Matrix::add_row(g);
00152 
00153   } // Generator_System::insert(g) substitute.
00154 
00155   set_index_first_pending_row(num_rows());
00156   set_sorted(false);
00157 
00158   PPL_ASSERT(OK());
00159 }

bool Parma_Polyhedra_Library::Grid_Generator_System::is_equal_to ( const Grid_Generator_System y  )  const [inline]

Returns true if *this is identical to y.

Definition at line 70 of file Grid_Generator_System.inlines.hh.

References operator==.

00070                                                                        {
00071   return operator==(static_cast<const Generator_System&>(*this),
00072                     static_cast<const Generator_System&>(y));
00073 }

dimension_type Parma_Polyhedra_Library::Grid_Generator_System::max_space_dimension (  )  [inline, static]

Returns the maximum space dimension a Grid_Generator_System can handle.

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 111 of file Grid_Generator_System.inlines.hh.

Referenced by Parma_Polyhedra_Library::Grid::max_space_dimension().

00111                                            {
00112   // Grid generators use an extra column for the parameter divisor.
00113   return Generator_System::max_space_dimension() - 1;
00114 }

dimension_type Parma_Polyhedra_Library::Grid_Generator_System::num_columns (  )  const [inline, private]
dimension_type Parma_Polyhedra_Library::Grid_Generator_System::num_lines (  )  const [inline]

Returns the number of lines in the system.

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 164 of file Grid_Generator_System.inlines.hh.

Referenced by Parma_Polyhedra_Library::Grid::generator_widening_assign(), and Parma_Polyhedra_Library::Grid::quick_equivalence_test().

00164                                        {
00165   return Generator_System::num_lines();
00166 }

dimension_type Parma_Polyhedra_Library::Grid_Generator_System::num_parameters (  )  const [inline]
dimension_type Parma_Polyhedra_Library::Grid_Generator_System::num_rows (  )  const [inline]
bool Parma_Polyhedra_Library::Grid_Generator_System::OK (  )  const

Checks if all the invariants are satisfied.

Returns true if and only if *this is a valid Linear_System and each row in the system is a valid Grid_Generator.

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 260 of file Grid_Generator_System.cc.

References Parma_Polyhedra_Library::Linear_System::is_sorted(), Parma_Polyhedra_Library::NOT_NECESSARILY_CLOSED, num_rows(), Parma_Polyhedra_Library::Matrix::OK(), and Parma_Polyhedra_Library::Linear_System::topology().

Referenced by ascii_load(), insert(), Parma_Polyhedra_Library::Grid::OK(), remove_higher_space_dimensions(), and Parma_Polyhedra_Library::Grid::simplify().

00260                                    {
00261   if (topology() == NOT_NECESSARILY_CLOSED) {
00262 #ifndef NDEBUG
00263     std::cerr << "Grid_Generator_System is NOT_NECESSARILY_CLOSED"
00264               << std::endl;
00265 #endif
00266     return false;
00267   }
00268 
00269   if (is_sorted()) {
00270 #ifndef NDEBUG
00271     std::cerr << "Grid_Generator_System is marked as sorted."
00272               << std::endl;
00273 #endif
00274     return false;
00275   }
00276 
00277   // A Generator_System and hence a Grid_Generator_System must be a
00278   // valid Linear_System; do not check for strong normalization, since
00279   // this will be done when checking each individual generator.
00280   if (!Linear_System::OK(false))
00281     return false;
00282 
00283   // Checking each generator in the system.
00284   const Grid_Generator_System& x = *this;
00285   for (dimension_type i = num_rows(); i-- > 0; )
00286     if (!x[i].OK())
00287       return false;
00288 
00289   // All checks passed.
00290   return true;
00291 }

Grid_Generator_System & Parma_Polyhedra_Library::Grid_Generator_System::operator= ( const Grid_Generator_System y  )  [inline]

Assignment operator.

Definition at line 105 of file Grid_Generator_System.inlines.hh.

00105                                                                {
00106   Generator_System::operator=(y);
00107   return *this;
00108 }

const Grid_Generator & Parma_Polyhedra_Library::Grid_Generator_System::operator[] ( dimension_type  k  )  const [inline, private]

Returns a constant reference to the k- th generator of the system.

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 260 of file Grid_Generator_System.inlines.hh.

References operator[]().

00260                                                               {
00261   return static_cast<const Grid_Generator&>(Generator_System::operator[](k));
00262 }

Grid_Generator & Parma_Polyhedra_Library::Grid_Generator_System::operator[] ( dimension_type  k  )  [inline, private]

Returns the k- th generator of the system.

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 255 of file Grid_Generator_System.inlines.hh.

Referenced by operator[](), and recycling_insert().

00255                                                         {
00256   return static_cast<Grid_Generator&>(Generator_System::operator[](k));
00257 }

void Parma_Polyhedra_Library::Grid_Generator_System::permute_columns ( const std::vector< dimension_type > &  cycles  )  [inline, private]

Permutes the columns of the matrix.

Reimplemented from Parma_Polyhedra_Library::Linear_System.

Definition at line 65 of file Grid_Generator_System.inlines.hh.

References Parma_Polyhedra_Library::Linear_System::permute_columns().

Referenced by Parma_Polyhedra_Library::Grid::map_space_dimensions().

00065                                                          {
00066   return Generator_System::permute_columns(cycles);
00067 }

void Parma_Polyhedra_Library::Grid_Generator_System::print (  )  const

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

Reimplemented from Parma_Polyhedra_Library::Generator_System.

void Parma_Polyhedra_Library::Grid_Generator_System::recycling_insert ( Grid_Generator_System gs  ) 

Inserts into *this the generators in gs, increasing the number of space dimensions if needed.

Definition at line 35 of file Grid_Generator_System.cc.

References Parma_Polyhedra_Library::Matrix::add_zero_rows(), Parma_Polyhedra_Library::Matrix::add_zero_rows_and_columns(), Parma_Polyhedra_Library::NECESSARILY_CLOSED, num_columns(), num_rows(), Parma_Polyhedra_Library::Linear_Row::RAY_OR_POINT_OR_INEQUALITY, set_index_first_pending_row(), and Parma_Polyhedra_Library::Matrix::swap_columns().

00035                                                                     {
00036   const dimension_type old_num_rows = num_rows();
00037   const dimension_type gs_num_rows = gs.num_rows();
00038   const dimension_type old_num_columns = num_columns();
00039   const dimension_type gs_num_columns = gs.num_columns();
00040   if (old_num_columns >= gs_num_columns)
00041     add_zero_rows(gs_num_rows,
00042                   Linear_Row::Flags(NECESSARILY_CLOSED,
00043                                     Linear_Row::RAY_OR_POINT_OR_INEQUALITY));
00044   else {
00045     add_zero_rows_and_columns(gs_num_rows,
00046                               gs_num_columns - old_num_columns,
00047                               Linear_Row::Flags(NECESSARILY_CLOSED,
00048                                                 Linear_Row::RAY_OR_POINT_OR_INEQUALITY));
00049     // Swap the parameter divisor column into the new last column.
00050     swap_columns(old_num_columns - 1, num_columns() - 1);
00051   }
00052   set_index_first_pending_row(old_num_rows + gs_num_rows);
00053   // Swap one coefficient at a time into the newly added rows, instead
00054   // of swapping each entire row.  This ensures that the added rows
00055   // have the same capacities as the existing rows.
00056   for (dimension_type i = gs_num_rows; i-- > 0; )
00057     operator[](old_num_rows + i).coefficient_swap(gs[i]);
00058 }

void Parma_Polyhedra_Library::Grid_Generator_System::recycling_insert ( Grid_Generator g  ) 

Inserts into *this the generator g, increasing the number of space dimensions if needed.

Definition at line 61 of file Grid_Generator_System.cc.

References Parma_Polyhedra_Library::Matrix::add_zero_rows(), Parma_Polyhedra_Library::Matrix::add_zero_rows_and_columns(), Parma_Polyhedra_Library::Grid_Generator::coefficient_swap(), Parma_Polyhedra_Library::NECESSARILY_CLOSED, num_columns(), num_rows(), operator[](), Parma_Polyhedra_Library::Linear_Row::RAY_OR_POINT_OR_INEQUALITY, set_index_first_pending_row(), Parma_Polyhedra_Library::Grid_Generator::size(), and Parma_Polyhedra_Library::Matrix::swap_columns().

Referenced by Parma_Polyhedra_Library::Grid::add_recycled_grid_generators(), Parma_Polyhedra_Library::Grid::generalized_affine_image(), Parma_Polyhedra_Library::Grid::generalized_affine_preimage(), Parma_Polyhedra_Library::Grid::time_elapse_assign(), Parma_Polyhedra_Library::Grid::unconstrain(), and Parma_Polyhedra_Library::Grid::upper_bound_assign().

00061                                                             {
00062   dimension_type old_num_rows = num_rows();
00063   const dimension_type old_num_columns = num_columns();
00064   const dimension_type g_num_columns = g.size();
00065   if (old_num_columns >= g_num_columns)
00066     add_zero_rows(1,
00067                   Linear_Row::Flags(NECESSARILY_CLOSED,
00068                                     Linear_Row::RAY_OR_POINT_OR_INEQUALITY));
00069   else {
00070     add_zero_rows_and_columns(1,
00071                               g_num_columns - old_num_columns,
00072                               Linear_Row::Flags(NECESSARILY_CLOSED,
00073                                                 Linear_Row::RAY_OR_POINT_OR_INEQUALITY));
00074     // Swap the parameter divisor column into the new last column.
00075     swap_columns(old_num_columns - 1, num_columns() - 1);
00076   }
00077   set_index_first_pending_row(old_num_rows + 1);
00078   // Swap one coefficient at a time into the newly added rows, instead
00079   // of swapping each entire row.  This ensures that the added rows
00080   // have the same capacities as the existing rows.
00081   operator[](old_num_rows).coefficient_swap(g);
00082 }

void Parma_Polyhedra_Library::Grid_Generator_System::remove_higher_space_dimensions ( dimension_type  new_dimension  )  [private]

Removes the higher dimensions of the system so that the resulting system will have dimension new_dimension.

The value of new_dimension must be at most the space dimension of *this.

Definition at line 362 of file Grid_Generator_System.cc.

References OK(), Parma_Polyhedra_Library::Linear_System::remove_trailing_columns(), space_dimension(), and Parma_Polyhedra_Library::Matrix::swap_columns().

Referenced by Parma_Polyhedra_Library::Grid::remove_higher_space_dimensions().

00362                                                                    {
00363   dimension_type space_dim = space_dimension();
00364 
00365   PPL_ASSERT(new_dimension <= space_dim);
00366 
00367   // The removal of no dimensions from any system is a no-op.  Note
00368   // that this case also captures the only legal removal of dimensions
00369   // from a system in a 0-dim space.
00370   if (new_dimension == space_dim)
00371     return;
00372 
00373   // Swap the parameter divisor column into the column that will
00374   // become the last column.
00375   swap_columns(new_dimension + 1, space_dim + 1);
00376   Matrix::remove_trailing_columns(space_dim - new_dimension);
00377   PPL_ASSERT(OK());
00378 }

void Parma_Polyhedra_Library::Grid_Generator_System::remove_space_dimensions ( const Variables_Set vars  )  [private]

Removes all the specified dimensions from the generator system.

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

Definition at line 328 of file Grid_Generator_System.cc.

References num_columns(), Parma_Polyhedra_Library::Linear_System::remove_trailing_columns(), Parma_Polyhedra_Library::Variables_Set::space_dimension(), space_dimension(), and Parma_Polyhedra_Library::Matrix::swap_columns().

Referenced by Parma_Polyhedra_Library::Grid::remove_space_dimensions().

00328                                                    {
00329   // Dimension-compatibility assertion.
00330   PPL_ASSERT(space_dimension() >= vars.space_dimension());
00331 
00332   // The removal of no dimensions from any system is a no-op.  This
00333   // case also captures the only legal removal of dimensions from a
00334   // 0-dim system.
00335   if (vars.empty())
00336     return;
00337 
00338   // For each variable to be removed, replace the corresponding column
00339   // by shifting left the columns to the right that will be kept.
00340   Variables_Set::const_iterator vsi = vars.begin();
00341   Variables_Set::const_iterator vsi_end = vars.end();
00342   dimension_type dst_col = *vsi+1;
00343   dimension_type src_col = dst_col + 1;
00344   for (++vsi; vsi != vsi_end; ++vsi) {
00345     const dimension_type vsi_col = *vsi+1;
00346     // Move all columns in between to the left.
00347     while (src_col < vsi_col)
00348       Matrix::swap_columns(dst_col++, src_col++);
00349     ++src_col;
00350   }
00351   // Move any remaining columns.
00352   const dimension_type num_columns = this->num_columns();
00353   while (src_col < num_columns)
00354     Matrix::swap_columns(dst_col++, src_col++);
00355 
00356   // The number of remaining columns is `dst_col'.
00357   Matrix::remove_trailing_columns(num_columns - dst_col);
00358 }

void Parma_Polyhedra_Library::Grid_Generator_System::resize_no_copy ( dimension_type  new_num_rows,
dimension_type  new_num_columns 
) [inline, private]

Resizes the system without worrying about the old contents.

Parameters:
new_num_rows The number of rows of the resized system;
new_num_columns The number of columns of the resized system.

The system is expanded to the specified dimensions avoiding reallocation whenever possible. The contents of the original system is lost.

Reimplemented from Parma_Polyhedra_Library::Linear_System.

Definition at line 48 of file Grid_Generator_System.inlines.hh.

Referenced by ascii_load(), and Parma_Polyhedra_Library::Grid::conversion().

00049                                                                             {
00050   Generator_System::resize_no_copy(new_num_rows, new_num_columns);
00051 }

void Parma_Polyhedra_Library::Grid_Generator_System::set_index_first_pending_row ( dimension_type  i  )  [inline, private]

Sets the index of the first pending row to i.

Reimplemented from Parma_Polyhedra_Library::Linear_System.

Definition at line 43 of file Grid_Generator_System.inlines.hh.

Referenced by ascii_load(), Parma_Polyhedra_Library::Grid::conversion(), insert(), and recycling_insert().

void Parma_Polyhedra_Library::Grid_Generator_System::set_sorted ( bool  b  )  [inline, private]
dimension_type Parma_Polyhedra_Library::Grid_Generator_System::space_dimension (  )  const [inline]
void Parma_Polyhedra_Library::Grid_Generator_System::swap ( Grid_Generator_System y  )  [inline]
memory_size_type Parma_Polyhedra_Library::Grid_Generator_System::total_memory_in_bytes (  )  const [inline]

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

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 149 of file Grid_Generator_System.inlines.hh.

00149                                                    {
00150   return Generator_System::total_memory_in_bytes();
00151 }

void Parma_Polyhedra_Library::Grid_Generator_System::unset_pending_rows (  )  [inline, private]
const Grid_Generator_System & Parma_Polyhedra_Library::Grid_Generator_System::zero_dim_univ (  )  [inline, static]

Returns the singleton system containing only Grid_Generator::zero_dim_point().

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 124 of file Grid_Generator_System.inlines.hh.

References zero_dim_univ_p.

00124                                      {
00125   PPL_ASSERT(zero_dim_univ_p != 0);
00126   return *zero_dim_univ_p;
00127 }


Friends And Related Function Documentation

friend class Grid [friend]

Definition at line 385 of file Grid_Generator_System.defs.hh.

std::ostream & operator<< ( std::ostream &  s,
const Grid_Generator_System gs 
) [related]

Output operator.

Writes false if gs is empty. Otherwise, writes on s the generators of gs, all in one row and separated by ", ".

Definition at line 295 of file Grid_Generator_System.cc.

References begin(), and end().

00296                                                                {
00297   Grid_Generator_System::const_iterator i = gs.begin();
00298   const Grid_Generator_System::const_iterator gs_end = gs.end();
00299   if (i == gs_end)
00300     return s << "false";
00301   while (true) {
00302     s << *i++;
00303     if (i == gs_end)
00304       return s;
00305     s << ", ";
00306   }
00307 }

bool operator== ( const Grid_Generator_System x,
const Grid_Generator_System y 
) [friend]

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

Definition at line 266 of file Grid_Generator_System.inlines.hh.

Referenced by is_equal_to(), and Parma_Polyhedra_Library::Grid_Generator_System::const_iterator::operator==().

00267                                            {
00268   return x.is_equal_to(y);
00269 }

Specializes std::swap.

Definition at line 278 of file Grid_Generator_System.inlines.hh.

References swap().

00279                                                       {
00280   x.swap(y);
00281 }


Member Data Documentation

Holds (between class initialization and finalization) a pointer to the singleton system containing only Grid_Generator::zero_dim_point().

Reimplemented from Parma_Polyhedra_Library::Generator_System.

Definition at line 383 of file Grid_Generator_System.defs.hh.

Referenced by finalize(), initialize(), and zero_dim_univ().


The documentation for this class was generated from the following files:
Generated on Sun Feb 27 16:20:25 2011 for PPL by  doxygen 1.6.3