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

A linear expression. More...

#include <Linear_Expression.defs.hh>

Inheritance diagram for Parma_Polyhedra_Library::Linear_Expression:

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

Collaboration graph
[legend]

List of all members.

Public Member Functions

 Linear_Expression ()
 Default constructor: returns a copy of Linear_Expression::zero().
 Linear_Expression (const Linear_Expression &e)
 Ordinary copy-constructor.
 ~Linear_Expression ()
 Destructor.
 Linear_Expression (Coefficient_traits::const_reference n)
 Builds the linear expression corresponding to the inhomogeneous term n.
 Linear_Expression (Variable v)
 Builds the linear expression corresponding to the variable v.
 Linear_Expression (const Constraint &c)
 Builds the linear expression corresponding to constraint c.
 Linear_Expression (const Generator &g)
 Builds the linear expression corresponding to generator g (for points and closure points, the divisor is not copied).
 Linear_Expression (const Grid_Generator &g)
 Builds the linear expression corresponding to grid generator g (for points, parameters and lines the divisor is not copied).
 Linear_Expression (const Congruence &cg)
 Builds the linear expression corresponding to congruence cg.
dimension_type space_dimension () const
 Returns the dimension of the vector space enclosing *this.
Coefficient_traits::const_reference coefficient (Variable v) const
 Returns the coefficient of v in *this.
Coefficient_traits::const_reference inhomogeneous_term () const
 Returns the inhomogeneous term 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.
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 (Linear_Expression &y)
 Swaps *this with y.

Static Public Member Functions

static dimension_type max_space_dimension ()
 Returns the maximum space dimension a Linear_Expression can handle.
static void initialize ()
 Initializes the class.
static void finalize ()
 Finalizes the class.
static const Linear_Expressionzero ()
 Returns the (zero-dimension space) constant 0.

Private Member Functions

 Linear_Expression (const Linear_Expression &e, dimension_type sz)
 Copy-constructor with a specified space dimension.
 Linear_Expression (dimension_type sz, bool)
 Implementation sizing constructor.
 Linear_Expression (Variable v, Variable w)
 Builds the linear expression corresponding to the difference of v and w.

Static Private Attributes

static const Linear_Expressionzero_p = 0
 Holds (between class initialization and finalization) a pointer to the (zero-dimension space) constant 0.

Friends

class Parma_Polyhedra_Library::Scalar_Products
class Parma_Polyhedra_Library::Constraint
class Parma_Polyhedra_Library::Generator
class Parma_Polyhedra_Library::Grid_Generator
class Parma_Polyhedra_Library::Congruence
class Parma_Polyhedra_Library::Polyhedron
class Parma_Polyhedra_Library::Grid
class Parma_Polyhedra_Library::Constraint_System
class Parma_Polyhedra_Library::Generator_System
class Parma_Polyhedra_Library::Congruence_System
class Parma_Polyhedra_Library::Grid_Generator_System
Linear_Expression operator+ (const Linear_Expression &e1, const Linear_Expression &e2)
 Returns the linear expression e1 + e2.
Linear_Expression operator+ (Coefficient_traits::const_reference n, const Linear_Expression &e)
 Returns the linear expression n + e.
Linear_Expression operator+ (const Linear_Expression &e, Coefficient_traits::const_reference n)
 Returns the linear expression e + n.
Linear_Expression operator- (const Linear_Expression &e)
 Returns the linear expression - e.
Linear_Expression operator- (const Linear_Expression &e1, const Linear_Expression &e2)
 Returns the linear expression e1 - e2.
Linear_Expression operator- (Variable v, Variable w)
 Returns the linear expression v - w.
Linear_Expression operator- (Coefficient_traits::const_reference n, const Linear_Expression &e)
 Returns the linear expression n - e.
Linear_Expression operator- (const Linear_Expression &e, Coefficient_traits::const_reference n)
 Returns the linear expression e - n.
Linear_Expression operator* (Coefficient_traits::const_reference n, const Linear_Expression &e)
 Returns the linear expression n * e.
Linear_Expression operator* (const Linear_Expression &e, Coefficient_traits::const_reference n)
 Returns the linear expression e * n.
Linear_Expressionoperator+= (Linear_Expression &e1, const Linear_Expression &e2)
 Returns the linear expression e1 + e2 and assigns it to e1.
Linear_Expressionoperator+= (Linear_Expression &e, Variable v)
 Returns the linear expression e + v and assigns it to e.
Linear_Expressionoperator+= (Linear_Expression &e, Coefficient_traits::const_reference n)
 Returns the linear expression e + n and assigns it to e.
Linear_Expressionoperator-= (Linear_Expression &e1, const Linear_Expression &e2)
 Returns the linear expression e1 - e2 and assigns it to e1.
Linear_Expressionoperator-= (Linear_Expression &e, Variable v)
 Returns the linear expression e - v and assigns it to e.
Linear_Expressionoperator-= (Linear_Expression &e, Coefficient_traits::const_reference n)
 Returns the linear expression e - n and assigns it to e.
Linear_Expressionoperator*= (Linear_Expression &e, Coefficient_traits::const_reference n)
 Returns the linear expression n * e and assigns it to e.
std::ostream & operator<< (std::ostream &s, const Linear_Expression &e)
 Output operator.

Related Functions

(Note that these are not member functions.)

Linear_Expression operator+ (Variable v, Variable w)
 Returns the linear expression v + w.
Linear_Expression operator+ (Variable v, const Linear_Expression &e)
 Returns the linear expression v + e.
Linear_Expression operator+ (const Linear_Expression &e, Variable v)
 Returns the linear expression e + v.
Linear_Expression operator+ (const Linear_Expression &e)
 Returns the linear expression e.
Linear_Expression operator- (Variable v, const Linear_Expression &e)
 Returns the linear expression v - e.
Linear_Expression operator- (const Linear_Expression &e, Variable v)
 Returns the linear expression e - v.
void swap (Parma_Polyhedra_Library::Linear_Expression &x, Parma_Polyhedra_Library::Linear_Expression &y)
 Specializes std::swap.


Detailed Description

A linear expression.

An object of the class Linear_Expression represents the linear expression

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

where $n$ is the dimension of the vector space, each $a_i$ is the integer coefficient of the $i$-th variable $x_i$ and $b$ is the integer for the inhomogeneous term.

How to build a linear expression.
Linear expressions are the basic blocks for defining both constraints (i.e., linear equalities or inequalities) and generators (i.e., lines, rays, points and closure points). A full set of functions is defined to provide a convenient interface for building complex linear expressions starting from simpler ones and from objects of the classes Variable and Coefficient: available operators include unary negation, binary addition and subtraction, as well as multiplication by a Coefficient. The space dimension of a linear expression is defined as the maximum space dimension of the arguments used to build it: in particular, the space dimension of a Variable x is defined as x.id()+1, whereas all the objects of the class Coefficient have space dimension zero.

Example
The following code builds the linear expression $4x - 2y - z + 14$, having space dimension $3$:
  Linear_Expression e = 4*x - 2*y - z + 14;
Another way to build the same linear expression is:
  Linear_Expression e1 = 4*x;
  Linear_Expression e2 = 2*y;
  Linear_Expression e3 = z;
  Linear_Expression e = Linear_Expression(14);
  e += e1 - e2 - e3;
Note that e1, e2 and e3 have space dimension 1, 2 and 3, respectively; also, in the fourth line of code, e is created with space dimension zero and then extended to space dimension 3 in the fifth line.

Definition at line 236 of file Linear_Expression.defs.hh.


Constructor & Destructor Documentation

Parma_Polyhedra_Library::Linear_Expression::Linear_Expression (  )  [inline]

Default constructor: returns a copy of Linear_Expression::zero().

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

Referenced by initialize(), operator+(), and operator-().

00039   : Linear_Row(1, Linear_Row::Flags()) {
00040 }

Parma_Polyhedra_Library::Linear_Expression::Linear_Expression ( const Linear_Expression e  )  [inline]

Ordinary copy-constructor.

Definition at line 79 of file Linear_Expression.inlines.hh.

00080   : Linear_Row(e) {
00081 }

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

Destructor.

Definition at line 84 of file Linear_Expression.inlines.hh.

00084                                       {
00085 }

Parma_Polyhedra_Library::Linear_Expression::Linear_Expression ( Coefficient_traits::const_reference  n  )  [inline, explicit]

Builds the linear expression corresponding to the inhomogeneous term n.

Definition at line 94 of file Linear_Expression.inlines.hh.

00095   : Linear_Row(1, Linear_Row::Flags()) {
00096   (*this)[0] = n;
00097 }

Parma_Polyhedra_Library::Linear_Expression::Linear_Expression ( Variable  v  )  [inline]

Builds the linear expression corresponding to the variable v.

Exceptions:
std::length_error Thrown if the space dimension of v exceeds Linear_Expression::max_space_dimension().

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

References Parma_Polyhedra_Library::Variable::id().

00049   : Linear_Row(v.space_dimension() <= max_space_dimension()
00050                ? v.id() + 2
00051                : (throw std::length_error("PPL::Linear_Expression::"
00052                                           "Linear_Expression(v):\n"
00053                                           "v exceeds the maximum allowed "
00054                                           "space dimension."),
00055                   v.id() + 2)
00056                , Linear_Row::Flags()) {
00057   (*this)[v.id() + 1] = 1;
00058 }

Parma_Polyhedra_Library::Linear_Expression::Linear_Expression ( const Constraint c  )  [explicit]

Builds the linear expression corresponding to constraint c.

Given the constraint $c = \bigl(\sum_{i=0}^{n-1} a_i x_i + b \relsym 0\bigr)$, where $\mathord{\relsym} \in \{ =, \geq, > \}$, this builds the linear expression $\sum_{i=0}^{n-1} a_i x_i + b$. If c is an inequality (resp., equality) constraint, then the built linear expression is unique up to a positive (resp., non-zero) factor.

Definition at line 35 of file Linear_Expression.cc.

References Parma_Polyhedra_Library::Row::size().

00036   : Linear_Row(c.space_dimension() + 1, Linear_Row::Flags()) {
00037   Linear_Expression& e = *this;
00038   for (dimension_type i = size(); i-- > 0; )
00039     e[i] = c[i];
00040 }

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

Builds the linear expression corresponding to generator g (for points and closure points, the divisor is not copied).

Given the generator $g = (\frac{a_0}{d}, \ldots, \frac{a_{n-1}}{d})^\transpose$ (where, for lines and rays, we have $d = 1$), this builds the linear expression $\sum_{i=0}^{n-1} a_i x_i$. The inhomogeneous term of the linear expression will always be 0. If g is a ray, point or closure point (resp., a line), then the linear expression is unique up to a positive (resp., non-zero) factor.

Definition at line 42 of file Linear_Expression.cc.

References Parma_Polyhedra_Library::Row::size().

00043   : Linear_Row(g.space_dimension() + 1, Linear_Row::Flags()) {
00044   Linear_Expression& e = *this;
00045   // Do not copy the divisor of `g'.
00046   for (dimension_type i = size(); --i > 0; )
00047     e[i] = g[i];
00048 }

Parma_Polyhedra_Library::Linear_Expression::Linear_Expression ( const Grid_Generator g  )  [explicit]

Builds the linear expression corresponding to grid generator g (for points, parameters and lines the divisor is not copied).

Given the grid generator $g = (\frac{a_0}{d}, \ldots, \frac{a_{n-1}}{d})^\transpose$ this builds the linear expression $\sum_{i=0}^{n-1} a_i x_i$. The inhomogeneous term of the linear expression is always 0.

Definition at line 50 of file Linear_Expression.cc.

References Parma_Polyhedra_Library::Row::size().

00051   : Linear_Row(g.space_dimension() + 1, Linear_Row::Flags()) {
00052   Linear_Expression& e = *this;
00053   // Do not copy the divisor of `g'.
00054   for (dimension_type i = size(); --i > 0; )
00055     e[i] = g[i];
00056 }

Parma_Polyhedra_Library::Linear_Expression::Linear_Expression ( const Congruence cg  )  [explicit]

Builds the linear expression corresponding to congruence cg.

Given the congruence $cg = \bigl(\sum_{i=0}^{n-1} a_i x_i + b = 0 \pmod{m}\bigr)$, this builds the linear expression $\sum_{i=0}^{n-1} a_i x_i + b$.

Definition at line 73 of file Linear_Expression.cc.

References Parma_Polyhedra_Library::Row::size().

00074   : Linear_Row(cg.space_dimension() + 1, Linear_Row::Flags()) {
00075   Linear_Expression& e = *this;
00076   for (dimension_type i = size(); i-- > 0; )
00077     e[i] = cg[i];
00078 }

Parma_Polyhedra_Library::Linear_Expression::Linear_Expression ( const Linear_Expression e,
dimension_type  sz 
) [inline, private]

Copy-constructor with a specified space dimension.

Definition at line 88 of file Linear_Expression.inlines.hh.

00090   : Linear_Row(e, sz, sz) {
00091 }

Parma_Polyhedra_Library::Linear_Expression::Linear_Expression ( dimension_type  sz,
bool   
) [inline, private]

Implementation sizing constructor.

The bool parameter is just to avoid problems with the constructor Linear_Expression(Coefficient_traits::const_reference n).

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

00044   : Linear_Row(sz, Linear_Row::Flags()) {
00045 }

Parma_Polyhedra_Library::Linear_Expression::Linear_Expression ( Variable  v,
Variable  w 
) [inline, private]

Builds the linear expression corresponding to the difference of v and w.

Exceptions:
std::length_error Thrown if the space dimension of v or the one of w exceed Linear_Expression::max_space_dimension().

Definition at line 61 of file Linear_Expression.inlines.hh.

References Parma_Polyhedra_Library::Linear_Row::construct(), max_space_dimension(), and Parma_Polyhedra_Library::Variable::space_dimension().

00062   : Linear_Row() {
00063   const dimension_type v_space_dim = v.space_dimension();
00064   const dimension_type w_space_dim = w.space_dimension();
00065   const dimension_type space_dim = std::max(v_space_dim, w_space_dim);
00066   if (space_dim > max_space_dimension())
00067     throw std::length_error("PPL::Linear_Expression::"
00068                             "Linear_Expression(v, w):\n"
00069                             "v or w exceed the maximum allowed "
00070                             "space dimension.");
00071   construct(space_dim+1, Linear_Row::Flags());
00072   if (v_space_dim != w_space_dim) {
00073     (*this)[v_space_dim] = 1;
00074     (*this)[w_space_dim] = -1;
00075   }
00076 }


Member Function Documentation

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

Returns the maximum space dimension a Linear_Expression can handle.

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

Definition at line 33 of file Linear_Expression.inlines.hh.

References Parma_Polyhedra_Library::Linear_Row::max_space_dimension().

Referenced by Linear_Expression().

00033                                        {
00034   return Linear_Row::max_space_dimension();
00035 }

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

Returns the dimension of the vector space enclosing *this.

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

Definition at line 100 of file Linear_Expression.inlines.hh.

References Parma_Polyhedra_Library::Row::size().

Referenced by Parma_Polyhedra_Library::Polyhedron::affine_image(), Parma_Polyhedra_Library::Octagonal_Shape< T >::affine_image(), Parma_Polyhedra_Library::Grid::affine_image(), Parma_Polyhedra_Library::Grid_Generator_System::affine_image(), Parma_Polyhedra_Library::Generator_System::affine_image(), Parma_Polyhedra_Library::Box< ITV >::affine_image(), Parma_Polyhedra_Library::BD_Shape< T >::affine_image(), Parma_Polyhedra_Library::Polyhedron::affine_preimage(), Parma_Polyhedra_Library::Octagonal_Shape< T >::affine_preimage(), Parma_Polyhedra_Library::Grid::affine_preimage(), Parma_Polyhedra_Library::Constraint_System::affine_preimage(), Parma_Polyhedra_Library::Congruence_System::affine_preimage(), Parma_Polyhedra_Library::Box< ITV >::affine_preimage(), Parma_Polyhedra_Library::BD_Shape< T >::affine_preimage(), Parma_Polyhedra_Library::Polyhedron::bounded_affine_image(), Parma_Polyhedra_Library::Octagonal_Shape< T >::bounded_affine_image(), Parma_Polyhedra_Library::Grid::bounded_affine_image(), Parma_Polyhedra_Library::Box< ITV >::bounded_affine_image(), Parma_Polyhedra_Library::BD_Shape< T >::bounded_affine_image(), Parma_Polyhedra_Library::Polyhedron::bounded_affine_preimage(), Parma_Polyhedra_Library::Octagonal_Shape< T >::bounded_affine_preimage(), Parma_Polyhedra_Library::Grid::bounded_affine_preimage(), Parma_Polyhedra_Library::Box< ITV >::bounded_affine_preimage(), Parma_Polyhedra_Library::BD_Shape< T >::bounded_affine_preimage(), Parma_Polyhedra_Library::Polyhedron::bounds(), Parma_Polyhedra_Library::Octagonal_Shape< T >::bounds(), Parma_Polyhedra_Library::Grid::bounds(), Parma_Polyhedra_Library::Box< ITV >::bounds(), Parma_Polyhedra_Library::BD_Shape< T >::bounds(), coefficient(), Parma_Polyhedra_Library::Congruence::create(), Parma_Polyhedra_Library::MIP_Problem::evaluate_objective_function(), Parma_Polyhedra_Library::Polyhedron::generalized_affine_image(), Parma_Polyhedra_Library::Octagonal_Shape< T >::generalized_affine_image(), Parma_Polyhedra_Library::Grid::generalized_affine_image(), Parma_Polyhedra_Library::Box< ITV >::generalized_affine_image(), Parma_Polyhedra_Library::BD_Shape< T >::generalized_affine_image(), Parma_Polyhedra_Library::Polyhedron::generalized_affine_preimage(), Parma_Polyhedra_Library::Octagonal_Shape< T >::generalized_affine_preimage(), Parma_Polyhedra_Library::Grid::generalized_affine_preimage(), Parma_Polyhedra_Library::Box< ITV >::generalized_affine_preimage(), Parma_Polyhedra_Library::BD_Shape< T >::generalized_affine_preimage(), Parma_Polyhedra_Library::Polyhedron::max_min(), Parma_Polyhedra_Library::Octagonal_Shape< T >::max_min(), Parma_Polyhedra_Library::Box< ITV >::max_min(), Parma_Polyhedra_Library::BD_Shape< T >::max_min(), Parma_Polyhedra_Library::MIP_Problem::MIP_Problem(), Parma_Polyhedra_Library::MIP_Problem::OK(), Parma_Polyhedra_Library::MIP_Problem::process_pending_constraints(), Parma_Polyhedra_Library::Octagonal_Shape< T >::refine(), Parma_Polyhedra_Library::BD_Shape< T >::refine(), Parma_Polyhedra_Library::MIP_Problem::second_phase(), Parma_Polyhedra_Library::MIP_Problem::set_objective_function(), Parma_Polyhedra_Library::Polyhedron::throw_dimension_incompatible(), Parma_Polyhedra_Library::Octagonal_Shape< T >::throw_dimension_incompatible(), Parma_Polyhedra_Library::Grid::throw_dimension_incompatible(), Parma_Polyhedra_Library::Box< ITV >::throw_dimension_incompatible(), and Parma_Polyhedra_Library::BD_Shape< T >::throw_dimension_incompatible().

00100                                          {
00101   return size() - 1;
00102 }

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

Returns the coefficient of v in *this.

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

References Parma_Polyhedra_Library::Linear_Row::coefficient(), Parma_Polyhedra_Library::Coefficient_zero(), Parma_Polyhedra_Library::Variable::id(), space_dimension(), and Parma_Polyhedra_Library::Variable::space_dimension().

Referenced by Parma_Polyhedra_Library::Polyhedron::affine_image(), Parma_Polyhedra_Library::Octagonal_Shape< T >::affine_image(), Parma_Polyhedra_Library::Box< ITV >::affine_image(), Parma_Polyhedra_Library::BD_Shape< T >::affine_image(), Parma_Polyhedra_Library::Polyhedron::affine_preimage(), Parma_Polyhedra_Library::Octagonal_Shape< T >::affine_preimage(), Parma_Polyhedra_Library::Box< ITV >::affine_preimage(), Parma_Polyhedra_Library::BD_Shape< T >::affine_preimage(), Parma_Polyhedra_Library::Polyhedron::bounded_affine_image(), Parma_Polyhedra_Library::Octagonal_Shape< T >::bounded_affine_image(), Parma_Polyhedra_Library::Box< ITV >::bounded_affine_image(), Parma_Polyhedra_Library::BD_Shape< T >::bounded_affine_image(), Parma_Polyhedra_Library::Polyhedron::bounded_affine_preimage(), Parma_Polyhedra_Library::Octagonal_Shape< T >::bounded_affine_preimage(), Parma_Polyhedra_Library::Box< ITV >::bounded_affine_preimage(), Parma_Polyhedra_Library::BD_Shape< T >::bounded_affine_preimage(), Parma_Polyhedra_Library::Box< ITV >::bounds(), Parma_Polyhedra_Library::Octagonal_Shape< T >::deduce_minus_v_pm_u_bounds(), Parma_Polyhedra_Library::BD_Shape< T >::deduce_u_minus_v_bounds(), Parma_Polyhedra_Library::BD_Shape< T >::deduce_v_minus_u_bounds(), Parma_Polyhedra_Library::Octagonal_Shape< T >::deduce_v_pm_u_bounds(), Parma_Polyhedra_Library::MIP_Problem::evaluate_objective_function(), Parma_Polyhedra_Library::Polyhedron::generalized_affine_image(), Parma_Polyhedra_Library::Octagonal_Shape< T >::generalized_affine_image(), Parma_Polyhedra_Library::Grid::generalized_affine_image(), Parma_Polyhedra_Library::Box< ITV >::generalized_affine_image(), Parma_Polyhedra_Library::BD_Shape< T >::generalized_affine_image(), Parma_Polyhedra_Library::Polyhedron::generalized_affine_preimage(), Parma_Polyhedra_Library::Octagonal_Shape< T >::generalized_affine_preimage(), Parma_Polyhedra_Library::Grid::generalized_affine_preimage(), Parma_Polyhedra_Library::Box< ITV >::generalized_affine_preimage(), Parma_Polyhedra_Library::BD_Shape< T >::generalized_affine_preimage(), Parma_Polyhedra_Library::Grid::Grid(), Parma_Polyhedra_Library::Octagonal_Shape< T >::max_min(), Parma_Polyhedra_Library::Box< ITV >::max_min(), Parma_Polyhedra_Library::BD_Shape< T >::max_min(), Parma_Polyhedra_Library::MIP_Problem::process_pending_constraints(), Parma_Polyhedra_Library::Octagonal_Shape< T >::refine(), Parma_Polyhedra_Library::BD_Shape< T >::refine(), and Parma_Polyhedra_Library::MIP_Problem::second_phase().

00105                                                {
00106   if (v.space_dimension() > space_dimension())
00107     return Coefficient_zero();
00108   return Linear_Row::coefficient(v.id());
00109 }

Coefficient_traits::const_reference Parma_Polyhedra_Library::Linear_Expression::inhomogeneous_term (  )  const [inline]

Returns the inhomogeneous term of *this.

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

Definition at line 112 of file Linear_Expression.inlines.hh.

References Parma_Polyhedra_Library::Linear_Row::inhomogeneous_term().

Referenced by Parma_Polyhedra_Library::Octagonal_Shape< T >::affine_image(), Parma_Polyhedra_Library::Box< ITV >::affine_image(), Parma_Polyhedra_Library::BD_Shape< T >::affine_image(), Parma_Polyhedra_Library::Octagonal_Shape< T >::affine_preimage(), Parma_Polyhedra_Library::Box< ITV >::affine_preimage(), Parma_Polyhedra_Library::BD_Shape< T >::affine_preimage(), Parma_Polyhedra_Library::Octagonal_Shape< T >::bounded_affine_image(), Parma_Polyhedra_Library::BD_Shape< T >::bounded_affine_image(), Parma_Polyhedra_Library::MIP_Problem::evaluate_objective_function(), Parma_Polyhedra_Library::Octagonal_Shape< T >::generalized_affine_image(), Parma_Polyhedra_Library::Box< ITV >::generalized_affine_image(), Parma_Polyhedra_Library::BD_Shape< T >::generalized_affine_image(), Parma_Polyhedra_Library::Octagonal_Shape< T >::generalized_affine_preimage(), Parma_Polyhedra_Library::BD_Shape< T >::generalized_affine_preimage(), Parma_Polyhedra_Library::Polyhedron::max_min(), Parma_Polyhedra_Library::Octagonal_Shape< T >::max_min(), Parma_Polyhedra_Library::Grid::max_min(), Parma_Polyhedra_Library::Box< ITV >::max_min(), Parma_Polyhedra_Library::BD_Shape< T >::max_min(), Parma_Polyhedra_Library::Octagonal_Shape< T >::refine(), Parma_Polyhedra_Library::BD_Shape< T >::refine(), and Parma_Polyhedra_Library::MIP_Problem::second_phase().

00112                                             {
00113   return Linear_Row::inhomogeneous_term();
00114 }

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

Initializes the class.

Definition at line 61 of file Linear_Expression.cc.

References Parma_Polyhedra_Library::Coefficient_zero(), Linear_Expression(), and zero_p.

00061                                  {
00062   assert(zero_p == 0);
00063   zero_p = new Linear_Expression(Coefficient_zero());
00064 }

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

Finalizes the class.

Definition at line 67 of file Linear_Expression.cc.

References zero_p.

00067                                {
00068   assert(zero_p != 0);
00069   delete zero_p;
00070   zero_p = 0;
00071 }

const Linear_Expression & Parma_Polyhedra_Library::Linear_Expression::zero (  )  [inline, static]

Returns the (zero-dimension space) constant 0.

Definition at line 117 of file Linear_Expression.inlines.hh.

References zero_p.

Referenced by Parma_Polyhedra_Library::Constraint::initialize(), and Parma_Polyhedra_Library::Congruence::initialize().

00117                         {
00118   assert(zero_p != 0);
00119   return *zero_p;
00120 }

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

Definition at line 128 of file Linear_Expression.inlines.hh.

References Parma_Polyhedra_Library::total_memory_in_bytes().

00128                                                {
00129   return Linear_Row::total_memory_in_bytes();
00130 }

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

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

Reimplemented from Parma_Polyhedra_Library::Row.

Definition at line 123 of file Linear_Expression.inlines.hh.

References Parma_Polyhedra_Library::external_memory_in_bytes().

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

00123                                                   {
00124   return Linear_Row::external_memory_in_bytes();
00125 }

void Parma_Polyhedra_Library::Linear_Expression::ascii_dump (  )  const

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

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

Referenced by Parma_Polyhedra_Library::MIP_Problem::ascii_dump().

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

Writes to s an ASCII representation of *this.

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

Definition at line 216 of file Linear_Expression.inlines.hh.

References Parma_Polyhedra_Library::ascii_dump().

00216                                                  {
00217   Linear_Row::ascii_dump(s);
00218 }

void Parma_Polyhedra_Library::Linear_Expression::print (  )  const

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

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

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

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

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

Definition at line 221 of file Linear_Expression.inlines.hh.

References Parma_Polyhedra_Library::ascii_load().

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

00221                                            {
00222   return Linear_Row::ascii_load(s);
00223 }

bool Parma_Polyhedra_Library::Linear_Expression::OK (  )  const

Checks if all the invariants are satisfied.

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

Definition at line 262 of file Linear_Expression.cc.

References Parma_Polyhedra_Library::Linear_Row::OK().

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

00262                                {
00263   return Linear_Row::OK();
00264 }

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

Swaps *this with y.

Definition at line 211 of file Linear_Expression.inlines.hh.

References Parma_Polyhedra_Library::swap().

Referenced by swap().

00211                                             {
00212   Linear_Row::swap(y);
00213 }


Friends And Related Function Documentation

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

friend class Parma_Polyhedra_Library::Constraint [friend]

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

Definition at line 362 of file Linear_Expression.defs.hh.

friend class Parma_Polyhedra_Library::Generator [friend]

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

Definition at line 363 of file Linear_Expression.defs.hh.

Definition at line 365 of file Linear_Expression.defs.hh.

friend class Parma_Polyhedra_Library::Congruence [friend]

Definition at line 366 of file Linear_Expression.defs.hh.

friend class Parma_Polyhedra_Library::Polyhedron [friend]

Definition at line 368 of file Linear_Expression.defs.hh.

friend class Parma_Polyhedra_Library::Grid [friend]

Definition at line 369 of file Linear_Expression.defs.hh.

Definition at line 373 of file Linear_Expression.defs.hh.

Definition at line 377 of file Linear_Expression.defs.hh.

Definition at line 381 of file Linear_Expression.defs.hh.

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

PPL::Linear_Expression operator+ ( const Linear_Expression e1,
const Linear_Expression e2 
) [friend]

Returns the linear expression e1 + e2.

Definition at line 82 of file Linear_Expression.cc.

00082                                                                        {
00083   dimension_type e1_size = e1.size();
00084   dimension_type e2_size = e2.size();
00085   dimension_type min_size;
00086   dimension_type max_size;
00087   const Linear_Expression* p_e_max;
00088   if (e1_size > e2_size) {
00089     min_size = e2_size;
00090     max_size = e1_size;
00091     p_e_max = &e1;
00092   }
00093   else {
00094     min_size = e1_size;
00095     max_size = e2_size;
00096     p_e_max = &e2;
00097   }
00098 
00099   Linear_Expression r(max_size, false);
00100   dimension_type i = max_size;
00101   while (i > min_size) {
00102     --i;
00103     r[i] = (*p_e_max)[i];
00104   }
00105   while (i > 0) {
00106     --i;
00107     r[i] = e1[i] + e2[i];
00108   }
00109 
00110   return r;
00111 }

PPL::Linear_Expression operator+ ( Coefficient_traits::const_reference  n,
const Linear_Expression e 
) [friend]

Returns the linear expression n + e.

Definition at line 115 of file Linear_Expression.cc.

00116                                            {
00117   Linear_Expression r(e);
00118   r[0] += n;
00119   return r;
00120 }

Linear_Expression operator+ ( const Linear_Expression e,
Coefficient_traits::const_reference  n 
) [friend]

Returns the linear expression e + n.

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

00140                                                                            {
00141   return n + e;
00142 }

PPL::Linear_Expression operator- ( const Linear_Expression e  )  [friend]

Returns the linear expression - e.

Definition at line 124 of file Linear_Expression.cc.

00124                                          {
00125   Linear_Expression r(e);
00126   for (dimension_type i = e.size(); i-- > 0; )
00127     neg_assign(r[i]);
00128   return r;
00129 }

PPL::Linear_Expression operator- ( const Linear_Expression e1,
const Linear_Expression e2 
) [friend]

Returns the linear expression e1 - e2.

Definition at line 133 of file Linear_Expression.cc.

00133                                                                        {
00134   dimension_type e1_size = e1.size();
00135   dimension_type e2_size = e2.size();
00136   if (e1_size > e2_size) {
00137     Linear_Expression r(e1_size, false);
00138     dimension_type i = e1_size;
00139     while (i > e2_size) {
00140       --i;
00141       r[i] = e1[i];
00142     }
00143     while (i > 0) {
00144       --i;
00145       r[i] = e1[i] - e2[i];
00146     }
00147     return r;
00148   }
00149   else {
00150     Linear_Expression r(e2_size, false);
00151     dimension_type i = e2_size;
00152     while (i > e1_size) {
00153       --i;
00154       r[i] = -e2[i];
00155     }
00156     while (i > 0) {
00157       --i;
00158       r[i] = e1[i] - e2[i];
00159     }
00160     return r;
00161   }
00162 }

Linear_Expression operator- ( Variable  v,
Variable  w 
) [friend]

Returns the linear expression v - w.

Definition at line 172 of file Linear_Expression.inlines.hh.

00172                                               {
00173   return Linear_Expression(v, w);
00174 }

PPL::Linear_Expression operator- ( Coefficient_traits::const_reference  n,
const Linear_Expression e 
) [friend]

Returns the linear expression n - e.

Definition at line 166 of file Linear_Expression.cc.

00167                                            {
00168   Linear_Expression r(e);
00169   for (dimension_type i = e.size(); i-- > 0; )
00170     neg_assign(r[i]);
00171   r[0] += n;
00172 
00173   return r;
00174 }

Linear_Expression operator- ( const Linear_Expression e,
Coefficient_traits::const_reference  n 
) [friend]

Returns the linear expression e - n.

Definition at line 166 of file Linear_Expression.inlines.hh.

00166                                                                            {
00167   return -n + e;
00168 }

PPL::Linear_Expression operator* ( Coefficient_traits::const_reference  n,
const Linear_Expression e 
) [friend]

Returns the linear expression n * e.

Definition at line 178 of file Linear_Expression.cc.

00179                                            {
00180   Linear_Expression r(e);
00181   for (dimension_type i = e.size(); i-- > 0; )
00182     r[i] *= n;
00183   return r;
00184 }

Linear_Expression operator* ( const Linear_Expression e,
Coefficient_traits::const_reference  n 
) [friend]

Returns the linear expression e * n.

Definition at line 192 of file Linear_Expression.inlines.hh.

00192                                                                            {
00193   return n * e;
00194 }

PPL::Linear_Expression & operator+= ( Linear_Expression e1,
const Linear_Expression e2 
) [friend]

Returns the linear expression e1 + e2 and assigns it to e1.

Definition at line 188 of file Linear_Expression.cc.

00188                                                                   {
00189   dimension_type e1_size = e1.size();
00190   dimension_type e2_size = e2.size();
00191   if (e1_size >= e2_size)
00192     for (dimension_type i = e2_size; i-- > 0; )
00193       e1[i] += e2[i];
00194   else {
00195     Linear_Expression e(e2);
00196     for (dimension_type i = e1_size; i-- > 0; )
00197       e[i] += e1[i];
00198     std::swap(e1, e);
00199   }
00200   return e1;
00201 }

PPL::Linear_Expression & operator+= ( Linear_Expression e,
Variable  v 
) [friend]

Returns the linear expression e + v and assigns it to e.

Exceptions:
std::length_error Thrown if the space dimension of v exceeds Linear_Expression::max_space_dimension().

Definition at line 205 of file Linear_Expression.cc.

00205                                                       {
00206   const dimension_type v_space_dim = v.space_dimension();
00207   if (v_space_dim > Linear_Expression::max_space_dimension())
00208     throw std::length_error("PPL::operator+=(e, v):\n"
00209                             "v exceeds the maximum allowed space dimension.");
00210   const dimension_type e_size = e.size();
00211   if (e_size <= v_space_dim) {
00212     Linear_Expression new_e(e, v_space_dim+1);
00213     std::swap(e, new_e);
00214   }
00215   ++e[v_space_dim];
00216   return e;
00217 }

Linear_Expression & operator+= ( Linear_Expression e,
Coefficient_traits::const_reference  n 
) [friend]

Returns the linear expression e + n and assigns it to e.

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

00198                                                                       {
00199   e[0] += n;
00200   return e;
00201 }

PPL::Linear_Expression & operator-= ( Linear_Expression e1,
const Linear_Expression e2 
) [friend]

Returns the linear expression e1 - e2 and assigns it to e1.

Definition at line 221 of file Linear_Expression.cc.

00221                                                                   {
00222   dimension_type e1_size = e1.size();
00223   dimension_type e2_size = e2.size();
00224   if (e1_size >= e2_size)
00225     for (dimension_type i = e2_size; i-- > 0; )
00226       e1[i] -= e2[i];
00227   else {
00228     Linear_Expression e(e1, e2_size);
00229     for (dimension_type i = e2_size; i-- > 0; )
00230       e[i] -= e2[i];
00231     std::swap(e1, e);
00232   }
00233   return e1;
00234 }

PPL::Linear_Expression & operator-= ( Linear_Expression e,
Variable  v 
) [friend]

Returns the linear expression e - v and assigns it to e.

Exceptions:
std::length_error Thrown if the space dimension of v exceeds Linear_Expression::max_space_dimension().

Definition at line 238 of file Linear_Expression.cc.

00238                                                       {
00239   const dimension_type v_space_dim = v.space_dimension();
00240   if (v_space_dim > Linear_Expression::max_space_dimension())
00241     throw std::length_error("PPL::operator-=(e, v):\n"
00242                             "v exceeds the maximum allowed space dimension.");
00243   const dimension_type e_size = e.size();
00244   if (e_size <= v_space_dim) {
00245     Linear_Expression new_e(e, v_space_dim+1);
00246     std::swap(e, new_e);
00247   }
00248   --e[v_space_dim];
00249   return e;
00250 }

Linear_Expression & operator-= ( Linear_Expression e,
Coefficient_traits::const_reference  n 
) [friend]

Returns the linear expression e - n and assigns it to e.

Definition at line 205 of file Linear_Expression.inlines.hh.

00205                                                                       {
00206   e[0] -= n;
00207   return e;
00208 }

PPL::Linear_Expression & operator*= ( Linear_Expression e,
Coefficient_traits::const_reference  n 
) [friend]

Returns the linear expression n * e and assigns it to e.

Definition at line 254 of file Linear_Expression.cc.

00254                                                                          {
00255   dimension_type e_size = e.size();
00256   for (dimension_type i = e_size; i-- > 0; )
00257     e[i] *= n;
00258   return e;
00259 }

std::ostream & operator<< ( std::ostream &  s,
const Linear_Expression e 
) [friend]

Output operator.

Definition at line 268 of file Linear_Expression.cc.

00268                                                                      {
00269   const dimension_type num_variables = e.space_dimension();
00270   TEMP_INTEGER(ev);
00271   bool first = true;
00272   for (dimension_type v = 0; v < num_variables; ++v) {
00273     ev = e[v+1];
00274     if (ev != 0) {
00275       if (!first) {
00276         if (ev > 0)
00277           s << " + ";
00278         else {
00279           s << " - ";
00280           neg_assign(ev);
00281         }
00282       }
00283       else
00284         first = false;
00285       if (ev == -1)
00286         s << "-";
00287       else if (ev != 1)
00288         s << ev << "*";
00289       s << PPL::Variable(v);
00290     }
00291   }
00292   // Inhomogeneous term.
00293   TEMP_INTEGER(it);
00294   it = e[0];
00295   if (it != 0) {
00296     if (!first) {
00297       if (it > 0)
00298         s << " + ";
00299       else {
00300         s << " - ";
00301         neg_assign(it);
00302       }
00303     }
00304     else
00305       first = false;
00306     s << it;
00307   }
00308 
00309   if (first)
00310     // The null linear expression.
00311     s << Coefficient_zero();
00312   return s;
00313 }

Linear_Expression operator+ ( Variable  v,
Variable  w 
) [related]

Returns the linear expression v + w.

Definition at line 146 of file Linear_Expression.inlines.hh.

References Linear_Expression().

00146                                               {
00147   // FIXME: provide a better implementation.
00148   return Linear_Expression(v) + Linear_Expression(w);
00149 }

Linear_Expression operator+ ( Variable  v,
const Linear_Expression e 
) [related]

Returns the linear expression v + e.

Definition at line 153 of file Linear_Expression.inlines.hh.

References Linear_Expression().

00153                                                         {
00154   // FIXME: provide a better implementation.
00155   return e + Linear_Expression(v);
00156 }

Linear_Expression operator+ ( const Linear_Expression e,
Variable  v 
) [related]

Returns the linear expression e + v.

Definition at line 160 of file Linear_Expression.inlines.hh.

00160                                                         {
00161   return v + e;
00162 }

Linear_Expression operator+ ( const Linear_Expression e  )  [related]

Returns the linear expression e.

Definition at line 134 of file Linear_Expression.inlines.hh.

00134                                       {
00135   return e;
00136 }

Linear_Expression operator- ( Variable  v,
const Linear_Expression e 
) [related]

Returns the linear expression v - e.

Definition at line 178 of file Linear_Expression.inlines.hh.

References Linear_Expression().

00178                                                         {
00179   // FIXME: provide a better implementation.
00180   return Linear_Expression(v) - e;
00181 }

Linear_Expression operator- ( const Linear_Expression e,
Variable  v 
) [related]

Returns the linear expression e - v.

Definition at line 185 of file Linear_Expression.inlines.hh.

References Linear_Expression().

00185                                                         {
00186   // FIXME: provide a better implementation.
00187   return e - Linear_Expression(v);
00188 }

Specializes std::swap.

Definition at line 232 of file Linear_Expression.inlines.hh.

References swap().

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


Member Data Documentation

Holds (between class initialization and finalization) a pointer to the (zero-dimension space) constant 0.

Definition at line 359 of file Linear_Expression.defs.hh.

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


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

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