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

A line, ray, point or closure point. More...

#include <Generator.defs.hh>

Inheritance diagram for Parma_Polyhedra_Library::Generator:

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

Collaboration graph
[legend]

List of all members.

Public Types

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

Public Member Functions

 Generator (const Generator &g)
 Ordinary copy-constructor.
 ~Generator ()
 Destructor.
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_ray () const
 Returns true if and only if *this is a ray.
bool is_line_or_ray () const
 Returns true if and only if *this is a line or a ray.
bool is_point () const
 Returns true if and only if *this is a point.
bool is_closure_point () const
 Returns true if and only if *this is a closure point.
Coefficient_traits::const_reference coefficient (Variable v) const
 Returns the coefficient of v in *this.
Coefficient_traits::const_reference divisor () const
 If *this is either a point or a closure point, returns its divisor.
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 Generator &y) const
 Returns true if and only if *this and y are equivalent generators.
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) and sets *this accordingly. Returns true if successful, false otherwise.
bool OK () const
 Checks if all the invariants are satisfied.
void swap (Generator &y)
 Swaps *this with y.

Static Public Member Functions

static Generator line (const Linear_Expression &e)
 Returns the line of direction e.
static Generator ray (const Linear_Expression &e)
 Returns the ray of direction e.
static Generator point (const Linear_Expression &e=Linear_Expression::zero(), Coefficient_traits::const_reference d=Coefficient_one())
 Returns the point at e / d.
static Generator closure_point (const Linear_Expression &e=Linear_Expression::zero(), Coefficient_traits::const_reference d=Coefficient_one())
 Returns the closure point at e / d.
static dimension_type max_space_dimension ()
 Returns the maximum space dimension a Generator can handle.
static const Generatorzero_dim_point ()
 Returns the origin of the zero-dimensional space $\Rset^0$.
static const Generatorzero_dim_closure_point ()
 Returns, as a closure point, the origin of the zero-dimensional space $\Rset^0$.

Private Member Functions

 Generator (Linear_Expression &e, Type type, Topology topology)
 Builds a generator of type type and topology topology, stealing the coefficients from e.
void throw_dimension_incompatible (const char *method, const char *name_var, Variable v) const
 Throw a std::invalid_argument exception containing the appropriate error message.
void throw_invalid_argument (const char *method, const char *reason) const
 Throw a std::invalid_argument exception containing the appropriate error message.
friend Parma_Polyhedra_Library::Linear_Expression::Linear_Expression (const Generator &g)
 Generator (const Generator &g, dimension_type dimension)
 Copy-constructor with given space dimension.
bool is_ray_or_point () const
 Returns true if and only if *this is not a line.
void set_is_line ()
 Sets the Linear_Row kind to LINE_OR_EQUALITY.
void set_is_ray_or_point ()
 Sets the Linear_Row kind to RAY_OR_POINT_OR_INEQUALITY.
bool is_matching_closure_point (const Generator &p) const
 Returns true if and only if the closure point *this has the same coordinates of the point p.
 Generator ()
 Default constructor: private and not implemented.

Friends

class Parma_Polyhedra_Library::Scalar_Products
class Parma_Polyhedra_Library::Topology_Adjusted_Scalar_Product_Sign
class Parma_Polyhedra_Library::Topology_Adjusted_Scalar_Product_Assign
class Parma_Polyhedra_Library::Generator_System
class Parma_Polyhedra_Library::Generator_System::const_iterator
class Parma_Polyhedra_Library::Polyhedron
class Parma_Polyhedra_Library::Grid_Generator
class Parma_Polyhedra_Library::Grid_Generator_System
std::ostream & operator<< (std::ostream &s, const Generator &g)
 Output operator.

Related Functions

(Note that these are not member functions.)

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


Detailed Description

A line, ray, point or closure point.

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

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

A note on terminology.
As observed in Section Representations of Convex Polyhedra, there are cases when, in order to represent a polyhedron $\cP$ using the generator system $\cG = (L, R, P, C)$, we need to include in the finite set $P$ even points of $\cP$ that are not vertices of $\cP$. This situation is even more frequent when working with NNC polyhedra and it is the reason why we prefer to use the word `point' where other libraries use the word `vertex'.
How to build a generator.
Each type of generator is built by applying the corresponding function (line, ray, point or closure_point) to a linear expression, representing a direction in the space; 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 points and closure points, 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 line with direction $x-y-z$ and having space dimension $3$:
  Generator l = line(x - y - z);
As mentioned above, the constant term of the linear expression is not relevant. Thus, the following code has the same effect:
  Generator l = line(x - y - z + 15);
By definition, the origin of the space is not a line, so that the following code throws an exception:
  Generator l = line(0*x);
Example 2
The following code builds a ray with the same direction as the line in Example 1:
  Generator r = ray(x - y - z);
As is the case for lines, when specifying a ray the constant term of the linear expression is not relevant; also, an exception is thrown when trying to build a ray from the origin of the space.
Example 3
The following code builds the point $\vect{p} = (1, 0, 2)^\transpose \in \Rset^3$:
  Generator p = point(1*x + 0*y + 2*z);
The same effect can be obtained by using the following code:
  Generator p = point(x + 2*z);
Similarly, the origin $\vect{0} \in \Rset^3$ can be defined using either one of the following lines of code:
  Generator origin3 = point(0*x + 0*y + 0*z);
  Generator origin3_alt = point(0*z);
Note however that the following code would have defined a different point, namely $\vect{0} \in \Rset^2$:
  Generator origin2 = point(0*y);
The following two lines of code both define the only 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.
  Generator origin0 = Generator::zero_dim_point();
  Generator origin0_alt = point();
Example 4
The 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 point (the divisor):
  Generator p = point(2*x + 0*y + 4*z, 2);
Obviously, the divisor can be usefully exploited to specify points having some non-integer (but rational) coordinates. For instance, the point $\vect{q} = (-1.5, 3.2, 2.1)^\transpose \in \Rset^3$ can be specified by the following code:
  Generator q = point(-15*x + 32*y + 21*z, 10);
If a zero divisor is provided, an exception is thrown.
Example 5
Closure points are specified in the same way we defined points, but invoking their specific constructor function. For instance, the closure point $\vect{c} = (1, 0, 2)^\transpose \in \Rset^3$ is defined by
  Generator c = closure_point(1*x + 0*y + 2*z);
For the particular case of the (only) closure point having space dimension zero, we can use any of the following:
  Generator closure_origin0 = Generator::zero_dim_closure_point();
  Generator closure_origin0_alt = closure_point();
How to inspect a generator
Several methods are provided to examine a generator and extract all the encoded information: its space dimension, its type and the value of its integer coefficients.
Example 6
The following code shows how it is possible to access each single coefficient of a generator. If g1 is a point having coordinates $(a_0, \ldots, a_{n-1})^\transpose$, we construct the closure point g2 having coordinates $(a_0, 2 a_1, \ldots, (i+1)a_i, \ldots, n a_{n-1})^\transpose$.
  if (g1.is_point()) {
    cout << "Point g1: " << g1 << endl;
    Linear_Expression e;
    for (int i = g1.space_dimension() - 1; i >= 0; i--)
      e += (i + 1) * g1.coefficient(Variable(i)) * Variable(i);
    Generator g2 = closure_point(e, g1.divisor());
    cout << "Closure point g2: " << g2 << endl;
  }
  else
    cout << "Generator g1 is not a point." << endl;
Therefore, for the point
  Generator g1 = point(2*x - y + 3*z, 2);
we would obtain the following output:
  Point g1: p((2*A - B + 3*C)/2)
  Closure point g2: cp((2*A - 2*B + 9*C)/2)
When working with (closure) points, be careful not to confuse the notion of coefficient with the notion of coordinate: these are equivalent only when the divisor of the (closure) point is 1.

Definition at line 241 of file Generator.defs.hh.


Member Enumeration Documentation

The generator type.

Enumerator:
LINE  The generator is a line.
RAY  The generator is a ray.
POINT  The generator is a point.
CLOSURE_POINT  The generator is a closure point.

Reimplemented in Parma_Polyhedra_Library::Grid_Generator.

Definition at line 300 of file Generator.defs.hh.

00300             {
00302     LINE,
00304     RAY,
00306     POINT,
00308     CLOSURE_POINT
00309   };


Constructor & Destructor Documentation

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

Ordinary copy-constructor.

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

00039   : Linear_Row(g) {
00040 }

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

Destructor.

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

00048                       {
00049 }

Parma_Polyhedra_Library::Generator::Generator ( Linear_Expression e,
Type  type,
Topology  topology 
) [inline, private]

Parma_Polyhedra_Library::Generator::Generator ( const Generator g,
dimension_type  dimension 
) [inline, private]

Copy-constructor with given space dimension.

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

00044   : Linear_Row(g, dimension, dimension) {
00045 }

Parma_Polyhedra_Library::Generator::Generator (  )  [private]

Default constructor: private and not implemented.


Member Function Documentation

PPL::Generator Parma_Polyhedra_Library::Generator::line ( const Linear_Expression e  )  [inline, static]

Returns the line of direction e.

Shorthand for Generator Generator::line(const Linear_Expression& e).

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

Reimplemented in Parma_Polyhedra_Library::Grid_Generator.

Definition at line 162 of file Generator.inlines.hh.

Referenced by Parma_Polyhedra_Library::Polyhedron::add_generator().

00162                                  {
00163   return Generator::line(e);
00164 }

PPL::Generator Parma_Polyhedra_Library::Generator::ray ( const Linear_Expression e  )  [inline, static]

Returns the ray of direction e.

Shorthand for Generator Generator::ray(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 168 of file Generator.inlines.hh.

Referenced by Parma_Polyhedra_Library::Polyhedron::add_generator().

00168                                 {
00169   return Generator::ray(e);
00170 }

PPL::Generator Parma_Polyhedra_Library::Generator::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 Generator Generator::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.

Reimplemented in Parma_Polyhedra_Library::Grid_Generator.

Definition at line 174 of file Generator.inlines.hh.

Referenced by Parma_Polyhedra_Library::Polyhedron::add_generator(), and zero_dim_point().

00174                                                                        {
00175   return Generator::point(e, d);
00176 }

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

Returns the closure point at e / d.

Shorthand for Generator Generator::closure_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 180 of file Generator.inlines.hh.

Referenced by zero_dim_closure_point().

00181                                                    {
00182   return Generator::closure_point(e, d);
00183 }

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

Assignment operator.

Reimplemented in Parma_Polyhedra_Library::Grid_Generator.

Definition at line 52 of file Generator.inlines.hh.

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

Referenced by Parma_Polyhedra_Library::Grid_Generator::operator=().

00052                                        {
00053   Linear_Row::operator=(g);
00054   return *this;
00055 }

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

Returns the maximum space dimension a Generator can handle.

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

Definition at line 58 of file Generator.inlines.hh.

References Parma_Polyhedra_Library::Linear_Row::max_space_dimension().

00058                                {
00059   return Linear_Row::max_space_dimension();
00060 }

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

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

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

bool Parma_Polyhedra_Library::Generator::is_ray (  )  const [inline]

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

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

References is_line_or_ray(), and is_ray_or_point().

Referenced by Parma_Polyhedra_Library::Polyhedron::BHRZ03_evolving_rays(), and Parma_Polyhedra_Library::Grid_Generator::is_parameter().

00083                         {
00084   return is_ray_or_point() && is_line_or_ray();
00085 }

bool Parma_Polyhedra_Library::Generator::is_line_or_ray (  )  const [inline]

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

bool Parma_Polyhedra_Library::Generator::is_closure_point (  )  const [inline]

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

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

If *this is either a point or a closure point, returns its divisor.

Exceptions:
std::invalid_argument Thrown if *this is neither a point nor a closure point.

Reimplemented in Parma_Polyhedra_Library::Grid_Generator.

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

References Parma_Polyhedra_Library::Linear_Row::inhomogeneous_term(), is_ray_or_point(), and throw_invalid_argument().

Referenced by Parma_Polyhedra_Library::Polyhedron::add_generator(), Parma_Polyhedra_Library::BD_Shape< T >::BD_Shape(), Parma_Polyhedra_Library::LP_Problem::evaluate_objective_function(), generator_term(), Parma_Polyhedra_Library::Polyhedron::map_space_dimensions(), ppl_Generator_divisor(), and Parma_Polyhedra_Library::Polyhedron::shrink_bounding_box().

00130                          {
00131   Coefficient_traits::const_reference d = Linear_Row::inhomogeneous_term();
00132   if (!is_ray_or_point() || d == 0)
00133     throw_invalid_argument("divisor()",
00134                            "*this is neither a point nor a closure point");
00135   return d;
00136 }

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

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

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

References point().

Referenced by Parma_Polyhedra_Library::Polyhedron::add_space_dimensions_and_project(), and Parma_Polyhedra_Library::Generator_System::zero_dim_univ().

00149                           {
00150   static const Generator zdp = point();
00151   return zdp;
00152 }

const Generator & Parma_Polyhedra_Library::Generator::zero_dim_closure_point (  )  [inline, static]

Returns, as a closure point, the origin of the zero-dimensional space $\Rset^0$.

Definition at line 155 of file Generator.inlines.hh.

References closure_point().

Referenced by Parma_Polyhedra_Library::Polyhedron::add_space_dimensions_and_project().

00155                                   {
00156   static const Generator zdcp = closure_point();
00157   return zdcp;
00158 }

memory_size_type Parma_Polyhedra_Library::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::Row.

Reimplemented in Parma_Polyhedra_Library::Grid_Generator.

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

References Parma_Polyhedra_Library::Checked::total_memory_in_bytes().

00144                                        {
00145   return Linear_Row::total_memory_in_bytes();
00146 }

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

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

Reimplemented from Parma_Polyhedra_Library::Row.

Reimplemented in Parma_Polyhedra_Library::Grid_Generator.

Definition at line 139 of file Generator.inlines.hh.

References Parma_Polyhedra_Library::Checked::external_memory_in_bytes().

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

00139                                           {
00140   return Linear_Row::external_memory_in_bytes();
00141 }

bool Parma_Polyhedra_Library::Generator::is_equivalent_to ( const 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 125 of file Generator.cc.

References Parma_Polyhedra_Library::Linear_Row::is_necessarily_closed(), Parma_Polyhedra_Library::Row::normalize(), POINT, space_dimension(), and type().

Referenced by operator!=(), and operator==().

00125                                                        {
00126   const Generator& x = *this;
00127   const dimension_type x_space_dim = x.space_dimension();
00128   if (x_space_dim != y.space_dimension())
00129     return false;
00130 
00131   const Type x_type = x.type();
00132   if (x_type != y.type())
00133     return false;
00134 
00135   if (x_type == POINT
00136       && !(x.is_necessarily_closed() && y.is_necessarily_closed())) {
00137     // Due to the presence of epsilon-coefficients, syntactically
00138     // different points may actually encode the same generator.
00139     // First, drop the epsilon-coefficient ...
00140     Linear_Expression x_expr(x);
00141     Linear_Expression y_expr(y);
00142     // ... second, re-normalize ...
00143     x_expr.normalize();
00144     y_expr.normalize();
00145     // ... and finally check for syntactic equality.
00146     for (dimension_type i = x_space_dim + 1; i-- > 0; )
00147       if (x_expr[i] != y_expr[i])
00148         return false;
00149     return true;
00150   }
00151 
00152   // Here the epsilon-coefficient, if present, is zero.
00153   // It is sufficient to check for syntactic equality.
00154   for (dimension_type i = x_space_dim + 1; i-- > 0; )
00155     if (x[i] != y[i])
00156       return false;
00157   return true;
00158 }

void Parma_Polyhedra_Library::Generator::ascii_dump (  )  const

void Parma_Polyhedra_Library::Generator::ascii_dump ( std::ostream &  s  )  const [inline]

Writes to s an ASCII representation of *this.

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

Reimplemented in Parma_Polyhedra_Library::Grid_Generator.

Definition at line 198 of file Generator.inlines.hh.

References Parma_Polyhedra_Library::Linear_Row::ascii_dump().

00198                                          {
00199   Linear_Row::ascii_dump(s);
00200 }

void Parma_Polyhedra_Library::Generator::print (  )  const

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

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

Reimplemented in Parma_Polyhedra_Library::Grid_Generator.

bool Parma_Polyhedra_Library::Generator::ascii_load ( std::istream &  s  )  [inline]

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

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

Reimplemented in Parma_Polyhedra_Library::Grid_Generator.

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

References Parma_Polyhedra_Library::Linear_Row::ascii_load().

Referenced by Parma_Polyhedra_Library::Grid_Generator::ascii_load().

00203                                    {
00204   return Linear_Row::ascii_load(s);
00205 }

bool Parma_Polyhedra_Library::Generator::OK (  )  const

Checks if all the invariants are satisfied.

Reimplemented in Parma_Polyhedra_Library::Grid_Generator.

Definition at line 292 of file Generator.cc.

References Parma_Polyhedra_Library::Linear_Row::all_homogeneous_terms_are_zero(), CLOSURE_POINT, Parma_Polyhedra_Library::Linear_Row::is_necessarily_closed(), LINE, POINT, RAY, Parma_Polyhedra_Library::Row::size(), Parma_Polyhedra_Library::Linear_Row::strong_normalize(), and type().

00292                        {
00293   const Generator& g = *this;
00294 
00295   // Topology consistency check.
00296   const dimension_type min_size = is_necessarily_closed() ? 1 : 2;
00297   if (size() < min_size) {
00298 #ifndef NDEBUG
00299     std::cerr << "Generator has fewer coefficients than the minimum "
00300               << "allowed by its topology:"
00301               << std::endl
00302               << "size is " << size()
00303               << ", minimum is " << min_size << "."
00304               << std::endl;
00305 #endif
00306     return false;
00307   }
00308 
00309   // Normalization check.
00310   Generator tmp = g;
00311   tmp.strong_normalize();
00312   if (tmp != g) {
00313 #ifndef NDEBUG
00314     std::cerr << "Generators should be strongly normalized!"
00315               << std::endl;
00316 #endif
00317     return false;
00318   }
00319 
00320   switch (g.type()) {
00321   case LINE:
00322     // Intentionally fall through.
00323   case RAY:
00324     if (g[0] != 0) {
00325 #ifndef NDEBUG
00326       std::cerr << "Lines must have a zero inhomogeneous term!"
00327                 << std::endl;
00328 #endif
00329       return false;
00330     }
00331     if (!g.is_necessarily_closed() && g[size() - 1] != 0) {
00332 #ifndef NDEBUG
00333       std::cerr << "Lines and rays must have a zero coefficient "
00334                 << "for the epsilon dimension!"
00335                 << std::endl;
00336 #endif
00337       return false;
00338     }
00339     // The following test is correct, since we already checked
00340     // that the epsilon coordinate is zero.
00341     if (g.all_homogeneous_terms_are_zero()) {
00342 #ifndef NDEBUG
00343       std::cerr << "The origin of the vector space cannot be a line or a ray!"
00344                 << std::endl;
00345 #endif
00346       return false;
00347     }
00348     break;
00349 
00350   case POINT:
00351     if (g[0] <= 0) {
00352 #ifndef NDEBUG
00353       std::cerr << "Points must have a positive divisor!"
00354                 << std::endl;
00355 #endif
00356       return false;
00357     }
00358     if (!g.is_necessarily_closed())
00359       if (g[size() - 1] <= 0) {
00360 #ifndef NDEBUG
00361         std::cerr << "In the NNC topology, points must have epsilon > 0"
00362                   << std::endl;
00363 #endif
00364         return false;
00365       }
00366     break;
00367 
00368   case CLOSURE_POINT:
00369     if (g[0] <= 0) {
00370 #ifndef NDEBUG
00371       std::cerr << "Closure points must have a positive divisor!"
00372                 << std::endl;
00373 #endif
00374       return false;
00375     }
00376     break;
00377   }
00378 
00379   // All tests passed.
00380   return true;
00381 }

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

void Parma_Polyhedra_Library::Generator::throw_dimension_incompatible ( const char *  method,
const char *  name_var,
Variable  v 
) const [private]

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

Definition at line 35 of file Generator.cc.

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

Referenced by coefficient().

00037                                                                      {
00038   std::ostringstream s;
00039   s << "PPL::Generator::" << method << ":" << std::endl
00040     << "this->space_dimension() == " << space_dimension() << ", "
00041     << name_var << ".space_dimension() == " << v.space_dimension() << ".";
00042   throw std::invalid_argument(s.str());
00043 }

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

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

Reimplemented in Parma_Polyhedra_Library::Grid_Generator.

Definition at line 46 of file Generator.cc.

Referenced by divisor().

00047                                                                  {
00048   std::ostringstream s;
00049   s << "PPL::Generator::" << method << ":" << std::endl
00050     << reason << ".";
00051   throw std::invalid_argument(s.str());
00052 }

Parma_Polyhedra_Library::Generator::Parma_Polyhedra_Library::Linear_Expression::Linear_Expression ( const Generator g  )  [private]

bool Parma_Polyhedra_Library::Generator::is_ray_or_point (  )  const [inline, private]

Returns true if and only if *this is not a line.

Definition at line 73 of file Generator.inlines.hh.

References Parma_Polyhedra_Library::Linear_Row::is_ray_or_point_or_inequality().

Referenced by divisor(), and is_ray().

00073                                  {
00074   return is_ray_or_point_or_inequality();
00075 }

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

void Parma_Polyhedra_Library::Generator::set_is_ray_or_point (  )  [inline, private]

bool Parma_Polyhedra_Library::Generator::is_matching_closure_point ( const Generator p  )  const [private]

Returns true if and only if the closure point *this has the same coordinates of the point p.

It is assumed that *this is a closure point, p is a point and both topologies and space dimensions agree.

Definition at line 249 of file Generator.cc.

References CLOSURE_POINT, Parma_Polyhedra_Library::exact_div_assign(), Parma_Polyhedra_Library::gcd_assign(), POINT, space_dimension(), TEMP_INTEGER, Parma_Polyhedra_Library::Linear_Row::topology(), and type().

Referenced by Parma_Polyhedra_Library::Polyhedron::is_topologically_closed(), and Parma_Polyhedra_Library::Generator_System::const_iterator::skip_forward().

00249                                                                 {
00250   assert(topology() == p.topology()
00251          && space_dimension() == p.space_dimension()
00252          && type() == CLOSURE_POINT
00253          && p.type() == POINT);
00254   const Generator& cp = *this;
00255   if (cp[0] == p[0]) {
00256     // Divisors are equal: we can simply compare coefficients
00257     // (disregarding the epsilon coefficient).
00258     for (dimension_type i = cp.size() - 2; i > 0; --i)
00259       if (cp[i] != p[i])
00260         return false;
00261     return true;
00262   }
00263   else {
00264     // Divisors are different: divide them by their GCD
00265     // to simplify the following computation.
00266     TEMP_INTEGER(gcd);
00267     gcd_assign(gcd, cp[0], p[0]);
00268     const bool rel_prime = (gcd == 1);
00269     TEMP_INTEGER(cp_0_scaled);
00270     TEMP_INTEGER(p_0_scaled);
00271     if (!rel_prime) {
00272       exact_div_assign(cp_0_scaled, cp[0], gcd);
00273       exact_div_assign(p_0_scaled, p[0], gcd);
00274     }
00275     const Coefficient& cp_div = rel_prime ? cp[0] : cp_0_scaled;
00276     const Coefficient& p_div = rel_prime ? p[0] : p_0_scaled;
00277     TEMP_INTEGER(prod1);
00278     TEMP_INTEGER(prod2);
00279     for (dimension_type i = cp.size() - 2; i > 0; --i) {
00280       prod1 = cp[i] * p_div;
00281       prod2 = p[i] * cp_div;
00282       if (prod1 != prod2)
00283         return false;
00284     }
00285     return true;
00286   }
00287 }


Friends And Related Function Documentation

Definition at line 412 of file Generator.defs.hh.

Definition at line 413 of file Generator.defs.hh.

friend class Parma_Polyhedra_Library::Topology_Adjusted_Scalar_Product_Assign [friend]

Definition at line 414 of file Generator.defs.hh.

Definition at line 415 of file Generator.defs.hh.

Definition at line 416 of file Generator.defs.hh.

friend class Parma_Polyhedra_Library::Polyhedron [friend]

Definition at line 418 of file Generator.defs.hh.

Definition at line 419 of file Generator.defs.hh.

Definition at line 421 of file Generator.defs.hh.

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

Output operator.

Definition at line 162 of file Generator.cc.

00162                                                              {
00163   bool needed_divisor = false;
00164   bool extra_parentheses = false;
00165   const int num_variables = g.space_dimension();
00166   Generator::Type t = g.type();
00167   switch (t) {
00168   case Generator::LINE:
00169     s << "l(";
00170     break;
00171   case Generator::RAY:
00172     s << "r(";
00173     break;
00174   case Generator::POINT:
00175     s << "p(";
00176     goto any_point;
00177   case Generator::CLOSURE_POINT:
00178     s << "c(";
00179   any_point:
00180     if (g[0] != 1) {
00181       needed_divisor = true;
00182       int num_non_zero_coefficients = 0;
00183       for (int v = 0; v < num_variables; ++v)
00184         if (g[v+1] != 0)
00185           if (++num_non_zero_coefficients > 1) {
00186             extra_parentheses = true;
00187             s << "(";
00188             break;
00189           }
00190     }
00191     break;
00192   }
00193 
00194   bool first = true;
00195   for (int v = 0; v < num_variables; ++v) {
00196     Coefficient gv = g[v+1];
00197     if (gv != 0) {
00198       if (!first) {
00199         if (gv > 0)
00200           s << " + ";
00201         else {
00202           s << " - ";
00203           neg_assign(gv);
00204         }
00205       }
00206       else
00207         first = false;
00208       if (gv == -1)
00209         s << "-";
00210       else if (gv != 1)
00211         s << gv << "*";
00212       s << PPL::Variable(v);
00213     }
00214   }
00215   if (first)
00216     // A point or closure point in the origin.
00217     s << 0;
00218   if (extra_parentheses)
00219     s << ")";
00220   if (needed_divisor)
00221     s << "/" << g[0];
00222   s << ")";
00223   return s;
00224 }

Specializes std::swap.

Definition at line 218 of file Generator.inlines.hh.

References swap().

00219                                           {
00220   x.swap(y);
00221 }

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

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

Definition at line 187 of file Generator.inlines.hh.

References is_equivalent_to().

00187                                                    {
00188   return x.is_equivalent_to(y);
00189 }

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

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

Definition at line 193 of file Generator.inlines.hh.

References is_equivalent_to().

00193                                                    {
00194   return !x.is_equivalent_to(y);
00195 }

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

Output operator.

Definition at line 228 of file Generator.cc.

References CLOSURE_POINT, LINE, POINT, and RAY.

00228                                                                  {
00229   const char* n = 0;
00230   switch (t) {
00231   case Generator::LINE:
00232     n = "LINE";
00233     break;
00234   case Generator::RAY:
00235     n = "RAY";
00236     break;
00237   case Generator::POINT:
00238     n = "POINT";
00239     break;
00240   case Generator::CLOSURE_POINT:
00241     n = "CLOSURE_POINT";
00242     break;
00243   }
00244   s << n;
00245   return s;
00246 }


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

Generated on Wed Jul 16 22:55:47 2008 for PPL by  doxygen 1.5.6