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 (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 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.
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 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.

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::LP_Problem
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- (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.
Congruence operator%= (const Linear_Expression &e1, const Linear_Expression &e2)
 Returns the congruence e1 = e2 {1}.
Congruence operator%= (const Linear_Expression &e, Coefficient_traits::const_reference n)
 Returns the congruence e = n {1}.

Related Functions

(Note that these are not member functions.)

 Linear_Expression (Variable v)
 Builds the linear expression corresponding to the variable v.
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, 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.
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 247 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 operator+(), operator-(), and zero().

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 61 of file Linear_Expression.inlines.hh.

00062   : Linear_Row(e) {
00063 }

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

Destructor.

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

00066                                       {
00067 }

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 76 of file Linear_Expression.inlines.hh.

00077   : Linear_Row(1, Linear_Row::Flags()) {
00078   (*this)[0] = n;
00079 }

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 34 of file Linear_Expression.cc.

References Parma_Polyhedra_Library::Row::size().

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

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 41 of file Linear_Expression.cc.

References Parma_Polyhedra_Library::Row::size().

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

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 49 of file Linear_Expression.cc.

References Parma_Polyhedra_Library::Row::size().

00050   : Linear_Row(cg.space_dimension() + 1, Linear_Row::Flags()) {
00051   Linear_Expression& e = *this;
00052   for (dimension_type i = size(); i-- > 0; )
00053     e[i] = cg[i];
00054 }

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 70 of file Linear_Expression.inlines.hh.

00072   : Linear_Row(e, sz, sz) {
00073 }

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 }


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().

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 82 of file Linear_Expression.inlines.hh.

References Parma_Polyhedra_Library::Row::size().

Referenced by Parma_Polyhedra_Library::Polyhedron::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::BD_Shape< T >::affine_image(), Parma_Polyhedra_Library::Polyhedron::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::BD_Shape< T >::affine_preimage(), Parma_Polyhedra_Library::Polyhedron::bounded_affine_image(), Parma_Polyhedra_Library::Polyhedron::bounded_affine_preimage(), Parma_Polyhedra_Library::Polyhedron::bounds(), Parma_Polyhedra_Library::Grid::bounds(), coefficient(), Parma_Polyhedra_Library::LP_Problem::evaluate_objective_function(), Parma_Polyhedra_Library::Polyhedron::generalized_affine_image(), Parma_Polyhedra_Library::Grid::generalized_affine_image(), Parma_Polyhedra_Library::BD_Shape< T >::generalized_affine_image(), Parma_Polyhedra_Library::Polyhedron::generalized_affine_preimage(), Parma_Polyhedra_Library::Grid::generalized_affine_preimage(), Parma_Polyhedra_Library::BD_Shape< T >::generalized_affine_preimage(), Parma_Polyhedra_Library::Grid_Generator::line(), Parma_Polyhedra_Library::Polyhedron::max_min(), Parma_Polyhedra_Library::LP_Problem::OK(), Parma_Polyhedra_Library::Grid_Generator::point(), Parma_Polyhedra_Library::LP_Problem::set_objective_function(), Parma_Polyhedra_Library::Polyhedron::throw_dimension_incompatible(), Parma_Polyhedra_Library::Grid::throw_dimension_incompatible(), and Parma_Polyhedra_Library::BD_Shape< T >::throw_dimension_incompatible().

00082                                          {
00083   return size() - 1;
00084 }

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

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

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

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 110 of file Linear_Expression.inlines.hh.

References Parma_Polyhedra_Library::Checked::total_memory_in_bytes().

00110                                                {
00111   return Linear_Row::total_memory_in_bytes();
00112 }

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 105 of file Linear_Expression.inlines.hh.

References Parma_Polyhedra_Library::Checked::external_memory_in_bytes().

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

00105                                                   {
00106   return Linear_Row::external_memory_in_bytes();
00107 }

bool Parma_Polyhedra_Library::Linear_Expression::OK (  )  const

Checks if all the invariants are satisfied.

Definition at line 239 of file Linear_Expression.cc.

References Parma_Polyhedra_Library::Linear_Row::OK(), and Parma_Polyhedra_Library::Row::size().

00239                                {
00240   dimension_type sz = size();
00241   return Linear_Row::OK(sz, sz);
00242 }

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

Swaps *this with y.

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

References Parma_Polyhedra_Library::Linear_Row::swap().

Referenced by swap().

00194                                             {
00195   Linear_Row::swap(y);
00196 }


Friends And Related Function Documentation

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

friend class Parma_Polyhedra_Library::Constraint [friend]

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

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

friend class Parma_Polyhedra_Library::Generator [friend]

Reimplemented from Parma_Polyhedra_Library::Linear_Row.

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

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

friend class Parma_Polyhedra_Library::Congruence [friend]

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

friend class Parma_Polyhedra_Library::Polyhedron [friend]

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

friend class Parma_Polyhedra_Library::Grid [friend]

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

friend class Parma_Polyhedra_Library::LP_Problem [friend]

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

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

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

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

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

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

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().

Referenced by build_linear_expression(), ppl_new_Linear_Expression(), ppl_new_Linear_Expression_from_Constraint(), ppl_new_Linear_Expression_from_Generator(), ppl_new_Linear_Expression_from_Linear_Expression(), and ppl_new_Linear_Expression_with_dimension().

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 }

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

Returns the linear expression e1 + e2.

Definition at line 59 of file Linear_Expression.cc.

00059                                                                        {
00060   dimension_type e1_size = e1.size();
00061   dimension_type e2_size = e2.size();
00062   dimension_type min_size;
00063   dimension_type max_size;
00064   const Linear_Expression* p_e_max;
00065   if (e1_size > e2_size) {
00066     min_size = e2_size;
00067     max_size = e1_size;
00068     p_e_max = &e1;
00069   }
00070   else {
00071     min_size = e1_size;
00072     max_size = e2_size;
00073     p_e_max = &e2;
00074   }
00075 
00076   Linear_Expression r(max_size, false);
00077   dimension_type i = max_size;
00078   while (i > min_size) {
00079     --i;
00080     r[i] = (*p_e_max)[i];
00081   }
00082   while (i > 0) {
00083     --i;
00084     r[i] = e1[i] + e2[i];
00085   }
00086 
00087   return r;
00088 }

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

Returns the linear expression n + e.

Definition at line 92 of file Linear_Expression.cc.

00093                                            {
00094   Linear_Expression r(e);
00095   r[0] += n;
00096   return r;
00097 }

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

Returns the linear expression e + n.

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

00122                                                                            {
00123   return n + e;
00124 }

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

Returns the linear expression - e.

Definition at line 101 of file Linear_Expression.cc.

00101                                          {
00102   Linear_Expression r(e);
00103   for (dimension_type i = e.size(); i-- > 0; )
00104     neg_assign(r[i]);
00105   return r;
00106 }

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

Returns the linear expression e1 - e2.

Definition at line 110 of file Linear_Expression.cc.

00110                                                                        {
00111   dimension_type e1_size = e1.size();
00112   dimension_type e2_size = e2.size();
00113   if (e1_size > e2_size) {
00114     Linear_Expression r(e1_size, false);
00115     dimension_type i = e1_size;
00116     while (i > e2_size) {
00117       --i;
00118       r[i] = e1[i];
00119     }
00120     while (i > 0) {
00121       --i;
00122       r[i] = e1[i] - e2[i];
00123     }
00124     return r;
00125   }
00126   else {
00127     Linear_Expression r(e2_size, false);
00128     dimension_type i = e2_size;
00129     while (i > e1_size) {
00130       --i;
00131       r[i] = -e2[i];
00132     }
00133     while (i > 0) {
00134       --i;
00135       r[i] = e1[i] - e2[i];
00136     }
00137     return r;
00138   }
00139 }

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

Returns the linear expression n - e.

Definition at line 143 of file Linear_Expression.cc.

00144                                            {
00145   Linear_Expression r(e);
00146   for (dimension_type i = e.size(); i-- > 0; )
00147     neg_assign(r[i]);
00148   r[0] += n;
00149 
00150   return r;
00151 }

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

Returns the linear expression e - n.

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

00148                                                                            {
00149   return -n + e;
00150 }

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

Returns the linear expression n * e.

Definition at line 155 of file Linear_Expression.cc.

00156                                            {
00157   Linear_Expression r(e);
00158   for (dimension_type i = e.size(); i-- > 0; )
00159     r[i] *= n;
00160   return r;
00161 }

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

Returns the linear expression e * n.

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

00175                                                                            {
00176   return n * e;
00177 }

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 165 of file Linear_Expression.cc.

00165                                                                   {
00166   dimension_type e1_size = e1.size();
00167   dimension_type e2_size = e2.size();
00168   if (e1_size >= e2_size)
00169     for (dimension_type i = e2_size; i-- > 0; )
00170       e1[i] += e2[i];
00171   else {
00172     Linear_Expression e(e2);
00173     for (dimension_type i = e1_size; i-- > 0; )
00174       e[i] += e1[i];
00175     std::swap(e1, e);
00176   }
00177   return e1;
00178 }

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 182 of file Linear_Expression.cc.

00182                                                       {
00183   const dimension_type v_space_dim = v.space_dimension();
00184   if (v_space_dim > Linear_Expression::max_space_dimension())
00185     throw std::length_error("PPL::operator+=(e, v):\n"
00186                             "v exceeds the maximum allowed space dimension.");
00187   const dimension_type e_size = e.size();
00188   if (e_size <= v_space_dim) {
00189     Linear_Expression new_e(e, v_space_dim+1);
00190     std::swap(e, new_e);
00191   }
00192   ++e[v_space_dim];
00193   return e;
00194 }

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 181 of file Linear_Expression.inlines.hh.

00181                                                                       {
00182   e[0] += n;
00183   return e;
00184 }

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 198 of file Linear_Expression.cc.

00198                                                                   {
00199   dimension_type e1_size = e1.size();
00200   dimension_type e2_size = e2.size();
00201   if (e1_size >= e2_size)
00202     for (dimension_type i = e2_size; i-- > 0; )
00203       e1[i] -= e2[i];
00204   else {
00205     Linear_Expression e(e1, e2_size);
00206     for (dimension_type i = e2_size; i-- > 0; )
00207       e[i] -= e2[i];
00208     std::swap(e1, e);
00209   }
00210   return e1;
00211 }

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 215 of file Linear_Expression.cc.

00215                                                       {
00216   const dimension_type v_space_dim = v.space_dimension();
00217   if (v_space_dim > Linear_Expression::max_space_dimension())
00218     throw std::length_error("PPL::operator-=(e, v):\n"
00219                             "v exceeds the maximum allowed space dimension.");
00220   const dimension_type e_size = e.size();
00221   if (e_size <= v_space_dim) {
00222     Linear_Expression new_e(e, v_space_dim+1);
00223     std::swap(e, new_e);
00224   }
00225   --e[v_space_dim];
00226   return e;
00227 }

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 188 of file Linear_Expression.inlines.hh.

00188                                                                       {
00189   e[0] -= n;
00190   return e;
00191 }

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 231 of file Linear_Expression.cc.

00231                                                                          {
00232   dimension_type e_size = e.size();
00233   for (dimension_type i = e_size; i-- > 0; )
00234     e[i] *= n;
00235   return e;
00236 }

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

Output operator.

Definition at line 246 of file Linear_Expression.cc.

00246                                                                      {
00247   const int num_variables = e.space_dimension();
00248   bool first = true;
00249   for (int v = 0; v < num_variables; ++v) {
00250     Coefficient ev = e[v+1];
00251     if (ev != 0) {
00252       if (!first) {
00253         if (ev > 0)
00254           s << " + ";
00255         else {
00256           s << " - ";
00257           neg_assign(ev);
00258         }
00259       }
00260       else
00261         first = false;
00262       if (ev == -1)
00263         s << "-";
00264       else if (ev != 1)
00265         s << ev << "*";
00266       s << PPL::Variable(v);
00267     }
00268   }
00269   // Inhomogeneous term.
00270   Coefficient it = e[0];
00271   if (it != 0) {
00272     if (!first) {
00273       if (it > 0)
00274         s << " + ";
00275       else {
00276         s << " - ";
00277         neg_assign(it);
00278       }
00279     }
00280     else
00281       first = false;
00282     s << it;
00283   }
00284 
00285   if (first)
00286     // The null linear expression.
00287     s << Coefficient_zero();
00288   return s;
00289 }

PPL::Congruence operator%= ( const Linear_Expression e1,
const Linear_Expression e2 
) [friend]

Returns the congruence e1 = e2 {1}.

Returns the congruence $e1 = e2 \pmod{1}$.

Definition at line 112 of file Congruence.cc.

00112                                                                         {
00113   // Ensure that diff is created with capacity for the modulus.
00114   dimension_type dim, e1_dim, e2_dim;
00115   e1_dim = e1.space_dimension();
00116   e2_dim = e2.space_dimension();
00117   if (e1_dim > e2_dim)
00118     dim = e1_dim;
00119   else
00120     dim = e2_dim;
00121   Linear_Expression diff(e1_dim > e2_dim ? e1 : e2,
00122                          dim + 2);
00123   diff -= (e1_dim > e2_dim ? e2 : e1);
00124   Congruence cg(diff, 1, false);
00125   return cg;
00126 }

Congruence operator%= ( const Linear_Expression e,
Coefficient_traits::const_reference  n 
) [friend]

Returns the congruence e = n {1}.

Returns the congruence $e = n \pmod{1}$.

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

00080                                                       {
00081   // Ensure that diff has capacity for the modulus.
00082   Linear_Expression diff(e, e.space_dimension() + 2);
00083   diff -= n;
00084   Congruence cg(diff, 1, false);
00085   return cg;
00086 }

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

Returns the linear expression v + w.

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

References Linear_Expression().

00128                                               {
00129   // FIXME: provide a better implementation.
00130   return Linear_Expression(v) + Linear_Expression(w);
00131 }

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

Returns the linear expression v + e.

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

References Linear_Expression().

00135                                                         {
00136   // FIXME: provide a better implementation.
00137   return e + Linear_Expression(v);
00138 }

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

Returns the linear expression e + v.

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

00142                                                         {
00143   return v + e;
00144 }

Linear_Expression operator+ ( const Linear_Expression e  )  [related]

Returns the linear expression e.

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

00116                                       {
00117   return e;
00118 }

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

Returns the linear expression v - w.

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

References Linear_Expression().

00154                                               {
00155   // FIXME: provide a better implementation.
00156   return Linear_Expression(v) - Linear_Expression(w);
00157 }

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

Returns the linear expression v - e.

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

References Linear_Expression().

00161                                                         {
00162   // FIXME: provide a better implementation.
00163   return Linear_Expression(v) - e;
00164 }

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

Returns the linear expression e - v.

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

References Linear_Expression().

00168                                                         {
00169   // FIXME: provide a better implementation.
00170   return e - Linear_Expression(v);
00171 }

Specializes std::swap.

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

References swap().

00206                                                   {
00207   x.swap(y);
00208 }


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

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