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

A grid line, parameter or grid point. More...

#include <Grid_Generator.defs.hh>

Inheritance diagram for Parma_Polyhedra_Library::Grid_Generator:

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

Collaboration graph
[legend]

List of all members.

Public Types

enum  Type { LINE, PARAMETER, POINT }
 The generator type. More...

Public Member Functions

 Grid_Generator (const Grid_Generator &g)
 Ordinary copy-constructor.
 ~Grid_Generator ()
 Destructor.
Grid_Generatoroperator= (const Grid_Generator &g)
 Assignment operator.
Grid_Generatoroperator= (const Generator &g)
 Assignment operator.
dimension_type space_dimension () const
 Returns the dimension of the vector space enclosing *this.
Type type () const
 Returns the generator type of *this.
bool is_line () const
 Returns true if and only if *this is a line.
bool is_parameter () const
 Returns true if and only if *this is a parameter.
bool is_line_or_parameter () const
 Returns true if and only if *this is a line or a parameter.
bool is_point () const
 Returns true if and only if *this is a point.
bool is_parameter_or_point () const
 Returns true if and only if *this row represents a parameter or a point.
Coefficient_traits::const_reference coefficient (Variable v) const
 Returns the coefficient of v in *this.
Coefficient_traits::const_reference divisor () const
 Returns the divisor of *this.
memory_size_type total_memory_in_bytes () const
 Returns a lower bound to 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 is_equivalent_to (const Grid_Generator &y) const
 Returns true if and only if *this and y are equivalent generators.
bool is_equal_to (const Grid_Generator &y) const
 Returns true if *this is exactly equal to y.
bool is_equal_at_dimension (dimension_type dim, const Grid_Generator &gg) const
 Returns true if *this is equal to gg in dimension dim.
bool all_homogeneous_terms_are_zero () const
 Returns true if and only if all the homogeneous terms of *this are $0$.
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.
bool OK () const
 Checks if all the invariants are satisfied.
void swap (Grid_Generator &y)
 Swaps *this with y.
void coefficient_swap (Grid_Generator &y)
 Swaps *this with y, leaving *this with the original capacity.

Static Public Member Functions

static Grid_Generator grid_line (const Linear_Expression &e)
 Returns the line of direction e.
static Grid_Generator parameter (const Linear_Expression &e=Linear_Expression::zero(), Coefficient_traits::const_reference d=Coefficient_one())
 Returns the parameter of direction e and size e/d.
static Grid_Generator grid_point (const Linear_Expression &e=Linear_Expression::zero(), Coefficient_traits::const_reference d=Coefficient_one())
 Returns the point at e / d.
static dimension_type max_space_dimension ()
 Returns the maximum space dimension a Grid_Generator can handle.
static void initialize ()
 Initializes the class.
static void finalize ()
 Finalizes the class.
static const Grid_Generatorzero_dim_point ()
 Returns the origin of the zero-dimensional space $\Rset^0$.

Private Member Functions

void scale_to_divisor (Coefficient_traits::const_reference d)
 Scales *this to be represented with a divisor of d (if \*this is a parameter or point).
 Grid_Generator (Generator g)
 Constructs from polyhedron generator g, stealing the underlying data structures from g.
dimension_type size () const
 Returns the actual size of this.
void negate (dimension_type start, dimension_type end)
 Negates the elements from index start to index end.
void set_divisor (Coefficient_traits::const_reference d)
 Sets the divisor of *this to d.
void set_is_line ()
 Sets the Linear_Row kind to LINE_OR_EQUALITY.
void set_is_parameter_or_point ()
 Sets the Linear_Row kind to RAY_OR_POINT_OR_INEQUALITY.
void set_is_parameter ()
 Converts the Grid_Generator into a parameter.
void strong_normalize ()
 Strong normalization: ensures that different Grid_Generator objects represent different hyperplanes or hyperspaces.
Coefficientoperator[] (dimension_type k)
 Returns a reference to the element of the row indexed by k.
Coefficient_traits::const_reference operator[] (dimension_type k) const
 Returns a constant reference to the element of the row indexed by k.
void throw_invalid_argument (const char *method, const char *reason) const
 Throw a std::invalid_argument exception containing the appropriate error message.

Static Private Attributes

static const Grid_Generatorzero_dim_point_p = 0
 Holds (between class initialization and finalization) a pointer to the origin of the zero-dimensional space $\Rset^0$.

Friends

class Grid
class Parma_Polyhedra_Library::Box
class Grid_Generator_System
class Grid_Generator_System::const_iterator
class Congruence_System
class Scalar_Products
class Topology_Adjusted_Scalar_Product_Sign
class Linear_Expression
std::ostream & IO_Operators::operator<< (std::ostream &s, const Grid_Generator &g)

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &s, const Grid_Generator &g)
 Output operator.
void swap (Parma_Polyhedra_Library::Grid_Generator &x, Parma_Polyhedra_Library::Grid_Generator &y)
 Specializes std::swap.
bool operator== (const Grid_Generator &x, const Grid_Generator &y)
 Returns true if and only if x is equivalent to y.
bool operator!= (const Grid_Generator &x, const Grid_Generator &y)
 Returns true if and only if x is not equivalent to y.
std::ostream & operator<< (std::ostream &s, const Grid_Generator::Type &t)
 Output operator.


Detailed Description

A grid line, parameter or grid point.

An object of the class Grid_Generator is one of the following:

where $n$ is the dimension of the space and, for grid_points and parameters, $d > 0$ is the divisor.

How to build a grid generator.
Each type of generator is built by applying the corresponding function (grid_line, parameter or grid_point) to a linear expression; the space dimension of the generator is defined as the space dimension of the corresponding linear expression. Linear expressions used to define a generator should be homogeneous (any constant term will be simply ignored). When defining grid points and parameters, an optional Coefficient argument can be used as a common divisor for all the coefficients occurring in the provided linear expression; the default value for this argument is 1.
In all the following examples it is assumed that variables x, y and z are defined as follows:
  Variable x(0);
  Variable y(1);
  Variable z(2);
Example 1
The following code builds a grid line with direction $x-y-z$ and having space dimension $3$:
  Grid_Generator l = grid_line(x - y - z);
By definition, the origin of the space is not a line, so that the following code throws an exception:
Example 2
The following code builds the parameter as the vector $\vect{p} = (1, -1, -1)^\transpose \in \Rset^3$ which has the same direction as the line in Example 1:
  Grid_Generator q = parameter(x - y - z);
Note that, unlike lines, for parameters, the length as well as the direction of the vector represented by the code is significant. Thus q is not the same as the parameter q1 defined by
  Grid_Generator q1 = parameter(2x - 2y - 2z);
By definition, the origin of the space is not a parameter, so that the following code throws an exception:
Example 3
The following code builds the grid point $\vect{p} = (1, 0, 2)^\transpose \in \Rset^3$:
  Grid_Generator p = grid_point(1*x + 0*y + 2*z);
The same effect can be obtained by using the following code:
  Grid_Generator p = grid_point(x + 2*z);
Similarly, the origin $\vect{0} \in \Rset^3$ can be defined using either one of the following lines of code:
  Grid_Generator origin3 = grid_point(0*x + 0*y + 0*z);
  Grid_Generator origin3_alt = grid_point(0*z);
Note however that the following code would have defined a different point, namely $\vect{0} \in \Rset^2$:
  Grid_Generator origin2 = grid_point(0*y);
The following two lines of code both define the only grid point having space dimension zero, namely $\vect{0} \in \Rset^0$. In the second case we exploit the fact that the first argument of the function point is optional.
Example 4
The grid point $\vect{p}$ specified in Example 3 above can also be obtained with the following code, where we provide a non-default value for the second argument of the function grid_point (the divisor):
  Grid_Generator p = grid_point(2*x + 0*y + 4*z, 2);
Obviously, the divisor can be used to specify points having some non-integer (but rational) coordinates. For instance, the grid point $\vect{p1} = (-1.5, 3.2, 2.1)^\transpose \in \Rset^3$ can be specified by the following code:
  Grid_Generator p1 = grid_point(-15*x + 32*y + 21*z, 10);
If a zero divisor is provided, an exception is thrown.
Example 5
Parameters, like grid points can have a divisor. For instance, the parameter $\vect{q} = (1, 0, 2)^\transpose \in \Rset^3$ can be defined:
  Grid_Generator q = parameter(2*x + 0*y + 4*z, 2);
Also, the divisor can be used to specify parameters having some non-integer (but rational) coordinates. For instance, the parameter $\vect{q} = (-1.5, 3.2, 2.1)^\transpose \in \Rset^3$ can be defined:
  Grid_Generator q = parameter(-15*x + 32*y + 21*z, 10);
If a zero divisor is provided, an exception is thrown.
How to inspect a grid generator
Several methods are provided to examine a grid generator and extract all the encoded information: its space dimension, its type and the value of its integer coefficients and the value of the denominator.
Example 6
The following code shows how it is possible to access each single coefficient of a grid generator. If g1 is a grid point having coordinates $(a_0, \ldots, a_{n-1})^\transpose$, we construct the parameter g2 having coordinates $(a_0, 2 a_1, \ldots, (i+1)a_i, \ldots, n a_{n-1})^\transpose$.
  if (g1.is_point()) {
    cout << "Grid point g1: " << g1 << endl;
    Linear_Expression e;
    for (dimension_type i = g1.space_dimension(); i-- > 0; )
      e += (i + 1) * g1.coefficient(Variable(i)) * Variable(i);
    Grid_Generator g2 = parameter(e, g1.divisor());
    cout << "Parameter g2: " << g2 << endl;
  }
  else
    cout << "Grid Generator g1 is not a grid point." << endl;
Therefore, for the grid point
  Grid_Generator g1 = grid_point(2*x - y + 3*z, 2);
we would obtain the following output:
  Grid point g1: p((2*A - B + 3*C)/2)
  Parameter g2: parameter((2*A - 2*B + 9*C)/2)
When working with grid points and parameters, be careful not to confuse the notion of coefficient with the notion of coordinate: these are equivalent only when the divisor is 1.

Definition at line 230 of file Grid_Generator.defs.hh.


Member Enumeration Documentation

The generator type.

Enumerator:
LINE  The generator is a grid line.
PARAMETER  The generator is a parameter.
POINT  The generator is a grid point.

Reimplemented from Parma_Polyhedra_Library::Generator.

Definition at line 285 of file Grid_Generator.defs.hh.

00285             {
00287     LINE,
00289     PARAMETER,
00291     POINT
00292   };


Constructor & Destructor Documentation

Parma_Polyhedra_Library::Grid_Generator::Grid_Generator ( const Grid_Generator g  )  [inline]

Ordinary copy-constructor.

Definition at line 29 of file Grid_Generator.inlines.hh.

Referenced by initialize().

00030   : Generator(g) {
00031 }

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

Destructor.

Definition at line 34 of file Grid_Generator.inlines.hh.

00034                                 {
00035 }

Parma_Polyhedra_Library::Grid_Generator::Grid_Generator ( Generator  g  )  [inline, explicit, private]

Constructs from polyhedron generator g, stealing the underlying data structures from g.

The last column in g becomes the parameter divisor column of the new Grid_Generator.

Definition at line 38 of file Grid_Generator.inlines.hh.

References Parma_Polyhedra_Library::swap().

00039   : Generator(Generator::point()) {
00040   Generator::swap(g);
00041 }


Member Function Documentation

PPL::Grid_Generator Parma_Polyhedra_Library::Grid_Generator::grid_line ( const Linear_Expression e  )  [inline, static]

Returns the line of direction e.

Shorthand for Grid_Generator Grid_Generator::grid_line(const Linear_Expression& e).

Exceptions:
std::invalid_argument Thrown if the homogeneous part of e represents the origin of the vector space.

Definition at line 209 of file Grid_Generator.inlines.hh.

00209                                       {
00210   return Grid_Generator::grid_line(e);
00211 }

PPL::Grid_Generator Parma_Polyhedra_Library::Grid_Generator::parameter ( const Linear_Expression e = Linear_Expression::zero(),
Coefficient_traits::const_reference  d = Coefficient_one() 
) [inline, static]

Returns the parameter of direction e and size e/d.

Shorthand for Grid_Generator Grid_Generator::parameter(const Linear_Expression& e, Coefficient_traits::const_reference d).

Both e and d are optional arguments, with default values Linear_Expression::zero() and Coefficient_one(), respectively.

Exceptions:
std::invalid_argument Thrown if d is zero.

Definition at line 215 of file Grid_Generator.inlines.hh.

00216                                                {
00217   return Grid_Generator::parameter(e, d);
00218 }

PPL::Grid_Generator Parma_Polyhedra_Library::Grid_Generator::grid_point ( const Linear_Expression e = Linear_Expression::zero(),
Coefficient_traits::const_reference  d = Coefficient_one() 
) [inline, static]

Returns the point at e / d.

Shorthand for Grid_Generator Grid_Generator::grid_point(const Linear_Expression& e, Coefficient_traits::const_reference d).

Both e and d are optional arguments, with default values Linear_Expression::zero() and Coefficient_one(), respectively.

Exceptions:
std::invalid_argument Thrown if d is zero.

Definition at line 222 of file Grid_Generator.inlines.hh.

Referenced by initialize().

00223                                                 {
00224   return Grid_Generator::grid_point(e, d);
00225 }

Grid_Generator & Parma_Polyhedra_Library::Grid_Generator::operator= ( const Grid_Generator g  )  [inline]

Assignment operator.

Definition at line 145 of file Grid_Generator.inlines.hh.

References Parma_Polyhedra_Library::Generator::operator=().

00145                                                  {
00146   Generator::operator=(g);
00147   return *this;
00148 }

Grid_Generator & Parma_Polyhedra_Library::Grid_Generator::operator= ( const Generator g  )  [inline]

Assignment operator.

Reimplemented from Parma_Polyhedra_Library::Generator.

Definition at line 151 of file Grid_Generator.inlines.hh.

References Parma_Polyhedra_Library::Generator::operator=().

00151                                             {
00152   Generator::operator=(g);
00153   return *this;
00154 }

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

Returns the maximum space dimension a Grid_Generator can handle.

Reimplemented from Parma_Polyhedra_Library::Generator.

Definition at line 49 of file Grid_Generator.inlines.hh.

References Parma_Polyhedra_Library::Generator::max_space_dimension().

00049                                     {
00050   return Generator::max_space_dimension() - 1;
00051 }

dimension_type Parma_Polyhedra_Library::Grid_Generator::space_dimension (  )  const [inline]

Grid_Generator::Type Parma_Polyhedra_Library::Grid_Generator::type (  )  const [inline]

Returns the generator type of *this.

Reimplemented from Parma_Polyhedra_Library::Generator.

Definition at line 69 of file Grid_Generator.inlines.hh.

References Parma_Polyhedra_Library::Generator::CLOSURE_POINT, LINE, Parma_Polyhedra_Library::Generator::LINE, PARAMETER, POINT, Parma_Polyhedra_Library::Generator::POINT, Parma_Polyhedra_Library::Generator::RAY, and Parma_Polyhedra_Library::Generator::type().

Referenced by ascii_dump(), is_equal_to(), is_equivalent_to(), Parma_Polyhedra_Library::Grid::map_space_dimensions(), OK(), and operator<<().

00069                            {
00070   switch (Generator::type()) {
00071   case Generator::POINT:
00072     return POINT;
00073   case Generator::RAY:
00074     return PARAMETER;
00075   case Generator::LINE:
00076     return LINE;
00077   case Generator::CLOSURE_POINT:
00078   default:
00079     assert(false);
00080     return POINT;
00081   }
00082 }

bool Parma_Polyhedra_Library::Grid_Generator::is_line (  )  const [inline]

bool Parma_Polyhedra_Library::Grid_Generator::is_parameter (  )  const [inline]

Returns true if and only if *this is a parameter.

Definition at line 90 of file Grid_Generator.inlines.hh.

References Parma_Polyhedra_Library::Generator::is_ray().

Referenced by Parma_Polyhedra_Library::Grid::add_grid_generator(), Parma_Polyhedra_Library::Grid_Generator_System::insert(), and is_equal_to().

00090                                    {
00091   return is_ray();
00092 }

bool Parma_Polyhedra_Library::Grid_Generator::is_line_or_parameter (  )  const [inline]

bool Parma_Polyhedra_Library::Grid_Generator::is_point (  )  const [inline]

bool Parma_Polyhedra_Library::Grid_Generator::is_parameter_or_point (  )  const [inline]

Coefficient_traits::const_reference Parma_Polyhedra_Library::Grid_Generator::coefficient ( Variable  v  )  const [inline]

Coefficient_traits::const_reference Parma_Polyhedra_Library::Grid_Generator::divisor (  )  const [inline]

void Parma_Polyhedra_Library::Grid_Generator::initialize (  )  [static]

Initializes the class.

Reimplemented from Parma_Polyhedra_Library::Generator.

Definition at line 268 of file Grid_Generator.cc.

References Grid_Generator(), grid_point(), and zero_dim_point_p.

00268                               {
00269   assert(zero_dim_point_p == 0);
00270   zero_dim_point_p
00271     = new Grid_Generator(grid_point());
00272 }

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

Finalizes the class.

Reimplemented from Parma_Polyhedra_Library::Generator.

Definition at line 275 of file Grid_Generator.cc.

References zero_dim_point_p.

00275                             {
00276   assert(zero_dim_point_p != 0);
00277   delete zero_dim_point_p;
00278   zero_dim_point_p = 0;
00279 }

const Grid_Generator & Parma_Polyhedra_Library::Grid_Generator::zero_dim_point (  )  [inline, static]

Returns the origin of the zero-dimensional space $\Rset^0$.

Reimplemented from Parma_Polyhedra_Library::Generator.

Definition at line 180 of file Grid_Generator.inlines.hh.

References zero_dim_point_p.

Referenced by Parma_Polyhedra_Library::Grid_Generator_System::initialize().

00180                                {
00181   assert(zero_dim_point_p != 0);
00182   return *zero_dim_point_p;
00183 }

memory_size_type Parma_Polyhedra_Library::Grid_Generator::total_memory_in_bytes (  )  const [inline]

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

Reimplemented from Parma_Polyhedra_Library::Generator.

Definition at line 170 of file Grid_Generator.inlines.hh.

References Parma_Polyhedra_Library::total_memory_in_bytes().

00170                                             {
00171   return Generator::total_memory_in_bytes();
00172 }

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

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

Reimplemented from Parma_Polyhedra_Library::Generator.

Definition at line 175 of file Grid_Generator.inlines.hh.

References Parma_Polyhedra_Library::external_memory_in_bytes().

00175                                                {
00176   return Generator::external_memory_in_bytes();
00177 }

bool Parma_Polyhedra_Library::Grid_Generator::is_equivalent_to ( const Grid_Generator y  )  const

Returns true if and only if *this and y are equivalent generators.

Generators having different space dimensions are not equivalent.

Definition at line 200 of file Grid_Generator.cc.

References LINE, POINT, space_dimension(), and type().

Referenced by operator==().

00200                                                                  {
00201   const Grid_Generator& x = *this;
00202   dimension_type x_space_dim = x.space_dimension();
00203   if (x_space_dim != y.space_dimension())
00204     return false;
00205 
00206   const Type x_type = x.type();
00207   if (x_type != y.type())
00208     return false;
00209 
00210   Grid_Generator tmp = *this;
00211   Grid_Generator tmp_y = y;
00212   dimension_type& last = x_space_dim;
00213   ++last;
00214   if (x_type == POINT || x_type == LINE) {
00215     tmp[last] = 0;
00216     tmp_y[last] = 0;
00217   }
00218   // Normalize the copies, including the divisor column.
00219   tmp.Row::normalize();
00220   tmp_y.Row::normalize();
00221   // Check for equality.
00222   while (last-- > 0)
00223     if (tmp[last] != tmp_y[last])
00224       return false;
00225   return true;
00226 }

bool Parma_Polyhedra_Library::Grid_Generator::is_equal_to ( const Grid_Generator y  )  const

Returns true if *this is exactly equal to y.

Definition at line 229 of file Grid_Generator.cc.

References is_parameter(), size(), and type().

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

00229                                                             {
00230   if (type() != y.type())
00231     return false;
00232   for (dimension_type col = (is_parameter() ? size() : size() - 1);
00233        col-- > 0; )
00234     if (Generator::operator[](col) != y.Generator::operator[](col))
00235       return false;
00236   return true;
00237 }

bool Parma_Polyhedra_Library::Grid_Generator::is_equal_at_dimension ( dimension_type  dim,
const Grid_Generator gg 
) const [inline]

Returns true if *this is equal to gg in dimension dim.

Definition at line 129 of file Grid_Generator.inlines.hh.

References divisor(), and operator[]().

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

00130                                                                       {
00131   return operator[](dim) * gg.divisor() == gg[dim] * divisor();
00132 }

bool Parma_Polyhedra_Library::Grid_Generator::all_homogeneous_terms_are_zero (  )  const

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

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

Definition at line 240 of file Grid_Generator.cc.

References size().

Referenced by Parma_Polyhedra_Library::Grid_Generator_System::insert().

00240                                                         {
00241   // Start at size() - 1 to avoid the extra grid generator column.
00242   for (dimension_type i = size() - 1; --i > 0; )
00243     if (operator[](i) != 0)
00244       return false;
00245   return true;
00246 }

void Parma_Polyhedra_Library::Grid_Generator::ascii_dump (  )  const

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

Reimplemented from Parma_Polyhedra_Library::Generator.

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

Writes to s an ASCII representation of *this.

Reimplemented from Parma_Polyhedra_Library::Generator.

Definition at line 132 of file Grid_Generator.cc.

References Parma_Polyhedra_Library::Generator::LINE, Parma_Polyhedra_Library::Generator::POINT, Parma_Polyhedra_Library::Generator::RAY, size(), and type().

00132                                                  {
00133   const Grid_Generator& x = *this;
00134   const dimension_type x_size = x.size();
00135   s << "size " << x_size << " ";
00136   for (dimension_type i = 0; i < x_size; ++i)
00137     s << x[i] << ' ';
00138   switch (x.type()) {
00139   case Generator::LINE:
00140     s << "L";
00141     break;
00142   case Generator::RAY:
00143     s << "Q";
00144     break;
00145   case Generator::POINT:
00146     s << "P";
00147     break;
00148   }
00149   s << "\n";
00150 }

void Parma_Polyhedra_Library::Grid_Generator::print (  )  const

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

Reimplemented from Parma_Polyhedra_Library::Generator.

bool Parma_Polyhedra_Library::Grid_Generator::ascii_load ( std::istream &  s  ) 

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

Reimplemented from Parma_Polyhedra_Library::Generator.

Definition at line 155 of file Grid_Generator.cc.

References set_is_line(), Parma_Polyhedra_Library::Generator::set_is_ray_or_point(), Parma_Polyhedra_Library::Row::shrink(), Parma_Polyhedra_Library::Row::size(), and Parma_Polyhedra_Library::Row::swap().

00155                                            {
00156   std::string str;
00157   if (!(s >> str) || str != "size")
00158     return false;
00159   dimension_type new_size;
00160   if (!(s >> new_size))
00161     return false;
00162 
00163   Row& x = *this;
00164   const dimension_type old_size = x.size();
00165   if (new_size < old_size)
00166     x.shrink(new_size);
00167   else if (new_size > old_size) {
00168     Row y(new_size, Row::Flags());
00169     x.swap(y);
00170   }
00171 
00172   for (dimension_type col = 0; col < new_size; ++col)
00173     if (!(s >> x[col]))
00174       return false;
00175 
00176   if (!(s >> str))
00177     return false;
00178   if (str == "L")
00179     set_is_line();
00180   else if (str == "P" || str == "Q")
00181     set_is_ray_or_point();
00182   else
00183     return false;
00184 
00185   return true;
00186 }

bool Parma_Polyhedra_Library::Grid_Generator::OK (  )  const

Checks if all the invariants are satisfied.

Reimplemented from Parma_Polyhedra_Library::Generator.

Definition at line 368 of file Grid_Generator.cc.

References divisor(), Parma_Polyhedra_Library::Linear_Row::is_necessarily_closed(), LINE, PARAMETER, POINT, size(), and type().

00368                             {
00369   if (!is_necessarily_closed()) {
00370 #ifndef NDEBUG
00371     std::cerr << "Grid_Generator should be necessarily closed."
00372               << std::endl;
00373 #endif
00374     return false;
00375   }
00376 
00377   // Topology consistency check.
00378   if (size() < 1) {
00379 #ifndef NDEBUG
00380     std::cerr << "Grid_Generator has fewer coefficients than the minimum "
00381               << "allowed:" << std::endl
00382               << "size is " << size() << ", minimum is 1." << std::endl;
00383 #endif
00384     return false;
00385   }
00386 
00387   switch (type()) {
00388   case Grid_Generator::LINE:
00389     if (operator[](0) != 0) {
00390 #ifndef NDEBUG
00391       std::cerr << "Inhomogeneous terms of lines must be zero!"
00392                 << std::endl;
00393 #endif
00394       return false;
00395     }
00396     break;
00397 
00398   case Grid_Generator::PARAMETER:
00399     if (operator[](0) != 0) {
00400 #ifndef NDEBUG
00401       std::cerr << "Inhomogeneous terms of parameters must be zero!"
00402                 << std::endl;
00403 #endif
00404       return false;
00405     }
00406     // Fall through.
00407 
00408   case Grid_Generator::POINT:
00409     if (divisor() <= 0) {
00410 #ifndef NDEBUG
00411       std::cerr << "Points and parameters must have positive divisors!"
00412                 << std::endl;
00413 #endif
00414       return false;
00415     }
00416     break;
00417 
00418   }
00419 
00420   // All tests passed.
00421   return true;
00422 }

void Parma_Polyhedra_Library::Grid_Generator::swap ( Grid_Generator y  )  [inline]

Swaps *this with y.

Definition at line 191 of file Grid_Generator.inlines.hh.

References Parma_Polyhedra_Library::swap().

Referenced by swap().

00191                                       {
00192   Generator::swap(y);
00193 }

void Parma_Polyhedra_Library::Grid_Generator::coefficient_swap ( Grid_Generator y  ) 

Swaps *this with y, leaving *this with the original capacity.

All elements up to and including the last element of the smaller of *this and y are swapped. The parameter divisor element of y is swapped with the divisor element of *this.

Definition at line 113 of file Grid_Generator.cc.

References is_line(), set_is_line(), Parma_Polyhedra_Library::Generator::set_is_ray_or_point(), size(), and Parma_Polyhedra_Library::swap().

Referenced by Parma_Polyhedra_Library::Grid_Generator_System::recycling_insert().

00113                                                      {
00114   // Swap one coefficient at a time into *this.  Doing this instead of
00115   // swapping the entire row ensures that the row keeps the same
00116   // capacity.
00117   if (y.is_line())
00118     set_is_line();
00119   else
00120     set_is_ray_or_point();
00121   assert(size() > 0);
00122   assert(y.size() > 0);
00123   dimension_type sz = size() - 1;
00124   dimension_type y_sz = y.size() - 1;
00125   // Swap parameter divisors.
00126   std::swap(operator[](sz), y[y_sz]);
00127   for (dimension_type j = (sz > y_sz ? y_sz : sz); j-- > 0; )
00128     std::swap(operator[](j), y[j]);
00129 }

void Parma_Polyhedra_Library::Grid_Generator::scale_to_divisor ( Coefficient_traits::const_reference  d  )  [private]

Scales *this to be represented with a divisor of d (if \*this is a parameter or point).

It is assumed that d is a multiple of the current divisor.

Exceptions:
std::invalid_argument Thrown if d is zero.

Definition at line 249 of file Grid_Generator.cc.

References divisor(), Parma_Polyhedra_Library::exact_div_assign(), is_parameter_or_point(), set_divisor(), size(), and TEMP_INTEGER.

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

00249                                                                        {
00250   if (is_parameter_or_point()) {
00251     if (d == 0)
00252       throw std::invalid_argument("PPL::Grid_Generator::scale_to_divisor(d):\n"
00253                                   "d == 0.");
00254 
00255     TEMP_INTEGER(factor);
00256     exact_div_assign(factor, d, divisor());
00257     set_divisor(d);
00258     assert(factor > 0);
00259     if (factor > 1)
00260       for (dimension_type col = size() - 2; col >= 1; --col)
00261         Generator::operator[](col) *= factor;
00262   }
00263 }

dimension_type Parma_Polyhedra_Library::Grid_Generator::size (  )  const [inline, private]

void Parma_Polyhedra_Library::Grid_Generator::negate ( dimension_type  start,
dimension_type  end 
) [inline, private]

Negates the elements from index start to index end.

Definition at line 157 of file Grid_Generator.inlines.hh.

References Parma_Polyhedra_Library::neg_assign().

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

00157                                                                {
00158   while (start <= end)
00159     neg_assign(operator[](start++));
00160 }

void Parma_Polyhedra_Library::Grid_Generator::set_divisor ( Coefficient_traits::const_reference  d  )  [inline, private]

Sets the divisor of *this to d.

Exceptions:
std::invalid_argument Thrown if *this is a line.

Definition at line 110 of file Grid_Generator.inlines.hh.

References is_line(), is_line_or_parameter(), Parma_Polyhedra_Library::Row::operator[](), and size().

Referenced by Parma_Polyhedra_Library::Box< ITV >::Box(), Parma_Polyhedra_Library::Grid::get_covering_box(), and scale_to_divisor().

00110                                                                {
00111   assert(!is_line());
00112   if (is_line_or_parameter())
00113     Generator::operator[](size() - 1) = d;
00114   else
00115     Generator::operator[](0) = d;
00116 }

void Parma_Polyhedra_Library::Grid_Generator::set_is_line (  )  [inline, private]

Sets the Linear_Row kind to LINE_OR_EQUALITY.

Reimplemented from Parma_Polyhedra_Library::Generator.

Definition at line 135 of file Grid_Generator.inlines.hh.

References Parma_Polyhedra_Library::Generator::set_is_line().

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

00135                             {
00136   Generator::set_is_line();
00137 }

void Parma_Polyhedra_Library::Grid_Generator::set_is_parameter_or_point (  )  [inline, private]

Sets the Linear_Row kind to RAY_OR_POINT_OR_INEQUALITY.

Definition at line 140 of file Grid_Generator.inlines.hh.

References Parma_Polyhedra_Library::Generator::set_is_ray_or_point().

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

00140                                           {
00141   Generator::set_is_ray_or_point();
00142 }

void Parma_Polyhedra_Library::Grid_Generator::set_is_parameter (  )  [private]

Converts the Grid_Generator into a parameter.

Definition at line 189 of file Grid_Generator.cc.

References is_line(), is_line_or_parameter(), Parma_Polyhedra_Library::Row::operator[](), set_is_parameter_or_point(), and size().

Referenced by Parma_Polyhedra_Library::Grid::relation_with(), and Parma_Polyhedra_Library::Grid::time_elapse_assign().

00189                                     {
00190   if (is_line())
00191     set_is_parameter_or_point();
00192   else if (!is_line_or_parameter()) {
00193     // The generator is a point.
00194     Generator::operator[](size() - 1) = Generator::operator[](0);
00195     Generator::operator[](0) = 0;
00196   }
00197 }

void Parma_Polyhedra_Library::Grid_Generator::strong_normalize (  )  [inline, private]

Strong normalization: ensures that different Grid_Generator objects represent different hyperplanes or hyperspaces.

Applies both Linear_Row::normalize() and Linear_Row::sign_normalize().

This is simply a wrapper around the Generator::strong_normalize, which means applying it to a parameter may change the parameter.

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

Definition at line 186 of file Grid_Generator.inlines.hh.

References Parma_Polyhedra_Library::Linear_Row::strong_normalize().

00186                                  {
00187   Generator::strong_normalize();
00188 }

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

Returns a reference to the element of the row indexed by k.

Reimplemented from Parma_Polyhedra_Library::Row.

Definition at line 54 of file Grid_Generator.inlines.hh.

References Parma_Polyhedra_Library::Row::operator[]().

Referenced by is_equal_at_dimension().

00054                                            {
00055   return Generator::operator[](k);
00056 }

Coefficient_traits::const_reference Parma_Polyhedra_Library::Grid_Generator::operator[] ( dimension_type  k  )  const [inline, private]

Returns a constant reference to the element of the row indexed by k.

Reimplemented from Parma_Polyhedra_Library::Row.

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

References Parma_Polyhedra_Library::Row::operator[]().

00059                                                  {
00060   return Generator::operator[](k);
00061 }

void Parma_Polyhedra_Library::Grid_Generator::throw_invalid_argument ( const char *  method,
const char *  reason 
) const [private]

Throw a std::invalid_argument exception containing the appropriate error message.

Reimplemented from Parma_Polyhedra_Library::Generator.

Definition at line 32 of file Grid_Generator.cc.

Referenced by divisor().

00033                                                                       {
00034   std::ostringstream s;
00035   s << "PPL::Grid_Generator::" << method << ":" << std::endl
00036     << reason << ".";
00037   throw std::invalid_argument(s.str());
00038 }


Friends And Related Function Documentation

friend class Grid [friend]

Definition at line 480 of file Grid_Generator.defs.hh.

friend class Parma_Polyhedra_Library::Box [friend]

Definition at line 487 of file Grid_Generator.defs.hh.

friend class Grid_Generator_System [friend]

Definition at line 489 of file Grid_Generator.defs.hh.

Definition at line 490 of file Grid_Generator.defs.hh.

friend class Congruence_System [friend]

Definition at line 491 of file Grid_Generator.defs.hh.

friend class Scalar_Products [friend]

Definition at line 492 of file Grid_Generator.defs.hh.

Definition at line 493 of file Grid_Generator.defs.hh.

friend class Linear_Expression [friend]

Definition at line 494 of file Grid_Generator.defs.hh.

std::ostream& IO_Operators::operator<< ( std::ostream &  s,
const Grid_Generator g 
) [friend]

std::ostream & operator<< ( std::ostream &  s,
const Grid_Generator g 
) [related]

Output operator.

Definition at line 283 of file Grid_Generator.cc.

References divisor(), LINE, Parma_Polyhedra_Library::neg_assign(), PARAMETER, POINT, space_dimension(), TEMP_INTEGER, and type().

00283                                                                   {
00284   bool need_divisor = false;
00285   bool extra_parentheses = false;
00286   const dimension_type num_variables = g.space_dimension();
00287   Grid_Generator::Type t = g.type();
00288   switch (t) {
00289   case Grid_Generator::LINE:
00290     s << "l(";
00291     break;
00292   case Grid_Generator::PARAMETER:
00293     s << "q(";
00294     if (g[num_variables + 1] == 1)
00295       break;
00296     goto any_point;
00297   case Grid_Generator::POINT:
00298     s << "p(";
00299     if (g[0] > 1) {
00300     any_point:
00301       need_divisor = true;
00302       dimension_type num_non_zero_coefficients = 0;
00303       for (dimension_type v = 0; v < num_variables; ++v)
00304         if (g[v+1] != 0)
00305           if (++num_non_zero_coefficients > 1) {
00306             extra_parentheses = true;
00307             s << "(";
00308             break;
00309           }
00310     }
00311     break;
00312   }
00313 
00314   TEMP_INTEGER(gv);
00315   bool first = true;
00316   for (dimension_type v = 0; v < num_variables; ++v) {
00317     gv = g[v+1];
00318     if (gv != 0) {
00319       if (!first) {
00320         if (gv > 0)
00321           s << " + ";
00322         else {
00323           s << " - ";
00324           neg_assign(gv);
00325         }
00326       }
00327       else
00328         first = false;
00329       if (gv == -1)
00330         s << "-";
00331       else if (gv != 1)
00332         s << gv << "*";
00333       s << PPL::Variable(v);
00334     }
00335   }
00336   if (first)
00337     // A generator in the origin.
00338     s << 0;
00339   if (extra_parentheses)
00340     s << ")";
00341   if (need_divisor)
00342     s << "/" << g.divisor();
00343   s << ")";
00344   return s;
00345 }

Specializes std::swap.

Definition at line 233 of file Grid_Generator.inlines.hh.

References swap().

00234                                                {
00235   x.swap(y);
00236 }

bool operator== ( const Grid_Generator x,
const Grid_Generator y 
) [related]

Returns true if and only if x is equivalent to y.

Definition at line 197 of file Grid_Generator.inlines.hh.

References is_equivalent_to().

00197                                                              {
00198   return x.is_equivalent_to(y);
00199 }

bool operator!= ( const Grid_Generator x,
const Grid_Generator y 
) [related]

Returns true if and only if x is not equivalent to y.

Definition at line 203 of file Grid_Generator.inlines.hh.

00203                                                              {
00204   return !(x == y);
00205 }

std::ostream & operator<< ( std::ostream &  s,
const Grid_Generator::Type t 
) [related]

Output operator.

Definition at line 349 of file Grid_Generator.cc.

References LINE, PARAMETER, and Parma_Polyhedra_Library::Generator::POINT.

00350                                                            {
00351   const char* n = 0;
00352   switch (t) {
00353   case Grid_Generator::LINE:
00354     n = "LINE";
00355     break;
00356   case Grid_Generator::PARAMETER:
00357     n = "PARAMETER";
00358     break;
00359   case Generator::POINT:
00360     n = "POINT";
00361     break;
00362   }
00363   s << n;
00364   return s;
00365 }


Member Data Documentation

Holds (between class initialization and finalization) a pointer to the origin of the zero-dimensional space $\Rset^0$.

Reimplemented from Parma_Polyhedra_Library::Generator.

Definition at line 407 of file Grid_Generator.defs.hh.

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


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

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