PPL  1.2
Parma_Polyhedra_Library::Linear_System< Row > Class Template Reference

The base class for systems of constraints and generators. More...

#include <Linear_System_defs.hh>

Inheritance diagram for Parma_Polyhedra_Library::Linear_System< Row >:
Collaboration diagram for Parma_Polyhedra_Library::Linear_System< Row >:

Classes

struct  Row_Less_Than
 Ordering predicate (used when implementing the sort algorithm). More...
 
struct  Unique_Compare
 Comparison predicate (used when implementing the unique algorithm). More...
 
struct  With_Pending
 A tag class. More...
 

Public Types

typedef Swapping_Vector< Row >::const_iterator iterator
 
typedef Swapping_Vector< Row >::const_iterator const_iterator
 

Public Member Functions

 Linear_System (Topology topol, Representation r)
 Builds an empty linear system with specified topology. More...
 
 Linear_System (Topology topol, dimension_type space_dim, Representation r)
 Builds a system with specified topology and dimensions. More...
 
 Linear_System (const Linear_System &y)
 Copy constructor: pending rows are transformed into non-pending ones. More...
 
 Linear_System (const Linear_System &y, Representation r)
 
 Linear_System (const Linear_System &y, With_Pending)
 Full copy constructor: pending rows are copied as pending. More...
 
 Linear_System (const Linear_System &y, Representation r, With_Pending)
 Full copy constructor: pending rows are copied as pending. More...
 
Linear_Systemoperator= (const Linear_System &y)
 Assignment operator: pending rows are transformed into non-pending ones. More...
 
void assign_with_pending (const Linear_System &y)
 Full assignment operator: pending rows are copied as pending. More...
 
void m_swap (Linear_System &y)
 Swaps *this with y. More...
 
Representation representation () const
 Returns the current representation of *this. More...
 
void set_representation (Representation r)
 Converts *this to the specified representation. More...
 
dimension_type space_dimension () const
 Returns the space dimension of the rows in the system. More...
 
void set_space_dimension (dimension_type space_dim)
 Sets the space dimension of the rows in the system to space_dim . More...
 
void remove_trailing_rows (dimension_type n)
 Makes the system shrink by removing its n trailing rows. More...
 
void remove_row (dimension_type i, bool keep_sorted=false)
 Makes the system shrink by removing its i-th row. More...
 
void remove_rows (dimension_type first, dimension_type last, bool keep_sorted=false)
 Makes the system shrink by removing the rows in [first,last). More...
 
void remove_rows (const std::vector< dimension_type > &indexes)
 
void remove_space_dimensions (const Variables_Set &vars)
 Removes all the specified dimensions from the system. More...
 
void shift_space_dimensions (Variable v, dimension_type n)
 
void permute_space_dimensions (const std::vector< Variable > &cycle)
 Permutes the space dimensions of the matrix. More...
 
void swap_space_dimensions (Variable v1, Variable v2)
 Swaps the coefficients of the variables v1 and v2 . More...
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
bool has_no_rows () const
 
dimension_type num_rows () const
 
void strong_normalize ()
 Strongly normalizes the system. More...
 
void sign_normalize ()
 Sign-normalizes the system. More...
 
bool check_sorted () const
 Returns true if and only if *this is sorted, without checking for duplicates. More...
 
void set_topology (Topology t)
 Sets the system topology to t . More...
 
void set_necessarily_closed ()
 Sets the system topology to NECESSARILY_CLOSED. More...
 
void set_not_necessarily_closed ()
 Sets the system topology to NOT_NECESSARILY_CLOSED. More...
 
void mark_as_necessarily_closed ()
 Marks the epsilon dimension as a standard dimension. More...
 
void mark_as_not_necessarily_closed ()
 Marks the last dimension as the epsilon dimension. More...
 
void unset_pending_rows ()
 Sets the index to indicate that the system has no pending rows. More...
 
void set_index_first_pending_row (dimension_type i)
 Sets the index of the first pending row to i. More...
 
void set_sorted (bool b)
 Sets the sortedness flag of the system to b. More...
 
void add_universe_rows_and_space_dimensions (dimension_type n)
 Adds n rows and space dimensions to the system. More...
 
void insert (const Row &r)
 Adds a copy of r to the system, automatically resizing the system or the row's copy, if needed. More...
 
void insert_pending (const Row &r)
 Adds a copy of the given row to the pending part of the system, automatically resizing the system or the row, if needed. More...
 
void insert (Row &r, Recycle_Input)
 Adds r to the system, stealing its contents and automatically resizing the system or the row, if needed. More...
 
void insert_pending (Row &r, Recycle_Input)
 Adds the given row to the pending part of the system, stealing its contents and automatically resizing the system or the row, if needed. More...
 
void insert (const Linear_System &y)
 Adds to *this a copy of the rows of y. More...
 
void insert_pending (const Linear_System &r)
 Adds a copy of the rows of `y' to the pending part of `*this'. More...
 
void insert (Linear_System &r, Recycle_Input)
 Adds to *this a the rows of `y', stealing them from `y'. More...
 
void insert_pending (Linear_System &r, Recycle_Input)
 
void sort_rows ()
 Sorts the non-pending rows (in growing order) and eliminates duplicated ones. More...
 
void sort_rows (dimension_type first_row, dimension_type last_row)
 Sorts the rows (in growing order) form first_row to last_row and eliminates duplicated ones. More...
 
void merge_rows_assign (const Linear_System &y)
 Assigns to *this the result of merging its rows with those of y, obtaining a sorted system. More...
 
void sort_pending_and_remove_duplicates ()
 Sorts the pending rows and eliminates those that also occur in the non-pending part of the system. More...
 
void sort_and_remove_with_sat (Bit_Matrix &sat)
 Sorts the system, removing duplicates, keeping the saturation matrix consistent. More...
 
dimension_type gauss (dimension_type n_lines_or_equalities)
 Minimizes the subsystem of equations contained in *this. More...
 
void back_substitute (dimension_type n_lines_or_equalities)
 Back-substitutes the coefficients to reduce the complexity of the system. More...
 
void simplify ()
 Applies Gaussian elimination and back-substitution so as to simplify the linear system. More...
 
void clear ()
 Clears the system deallocating all its rows. More...
 
void ascii_dump () const
 Writes to std::cerr an ASCII representation of *this. More...
 
void ascii_dump (std::ostream &s) const
 Writes to s an ASCII representation of *this. More...
 
void print () const
 Prints *this to std::cerr using operator<<. More...
 
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. More...
 
memory_size_type total_memory_in_bytes () const
 Returns the total size in bytes of the memory occupied by *this. More...
 
memory_size_type external_memory_in_bytes () const
 Returns the size in bytes of the memory managed by *this. More...
 
bool OK () const
 Checks if all the invariants are satisfied. More...
 
Subscript operators
const Row & operator[] (dimension_type k) const
 Returns a const reference to the k-th row of the system. More...
 
Accessors
Topology topology () const
 Returns the system topology. More...
 
bool is_sorted () const
 Returns the value of the sortedness flag. More...
 
bool is_necessarily_closed () const
 Returns true if and only if the system topology is NECESSARILY_CLOSED. More...
 
dimension_type num_lines_or_equalities () const
 Returns the number of rows in the system that represent either lines or equalities. More...
 
dimension_type first_pending_row () const
 Returns the index of the first pending row. More...
 
dimension_type num_pending_rows () const
 Returns the number of rows that are in the pending part of the system. More...
 

Static Public Member Functions

static dimension_type max_space_dimension ()
 Returns the maximum space dimension a Linear_System can handle. More...
 

Public Attributes

Swapping_Vector< Row > rows
 The vector that contains the rows. More...
 

Private Member Functions

void remove_row_no_ok (dimension_type i, bool keep_sorted=false)
 Makes the system shrink by removing its i-th row. More...
 
void insert_pending_no_ok (Row &r, Recycle_Input)
 Adds r to the pending part of the system, stealing its contents and automatically resizing the system or the row, if needed. More...
 
void insert_no_ok (Row &r, Recycle_Input)
 Adds r to the system, stealing its contents and automatically resizing the system or the row, if needed. More...
 
void set_space_dimension_no_ok (dimension_type space_dim)
 Sets the space dimension of the rows in the system to space_dim . More...
 
void swap_row_intervals (dimension_type first, dimension_type last, dimension_type offset)
 

Private Attributes

dimension_type space_dimension_
 
Topology row_topology
 
dimension_type index_first_pending
 The index of the first pending row. More...
 
bool sorted
 true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted. More...
 
Representation representation_
 

Friends

class Polyhedron
 
class Generator_System
 

Related Functions

(Note that these are not member functions.)

template<typename Row >
void swap (Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
 Swaps x with y. More...
 
template<typename Row >
bool operator== (const Linear_System< Row > &x, const Linear_System< Row > &y)
 Returns true if and only if x and y are identical. More...
 
template<typename Row >
bool operator!= (const Linear_System< Row > &x, const Linear_System< Row > &y)
 Returns true if and only if x and y are different. More...
 
template<typename Row >
bool operator!= (const Linear_System< Row > &x, const Linear_System< Row > &y)
 
template<typename Row >
void swap (Linear_System< Row > &x, Linear_System< Row > &y)
 
template<typename Row >
bool operator== (const Linear_System< Row > &x, const Linear_System< Row > &y)
 

Detailed Description

template<typename Row>
class Parma_Polyhedra_Library::Linear_System< Row >

The base class for systems of constraints and generators.

An object of this class represents either a constraint system or a generator system. Each Linear_System object can be viewed as a finite sequence of strong-normalized Row objects, where each Row implements a constraint or a generator. Linear systems are characterized by the matrix of coefficients, also encoding the number, size and capacity of Row objects, as well as a few additional information, including:

  • the topological kind of (all) the rows;
  • an indication of whether or not some of the rows in the Linear_System are pending, meaning that they still have to undergo an (unspecified) elaboration; if there are pending rows, then these form a proper suffix of the overall sequence of rows;
  • a Boolean flag that, when true, ensures that the non-pending prefix of the sequence of rows is sorted.

Definition at line 61 of file Linear_System_defs.hh.

Member Typedef Documentation

Definition at line 66 of file Linear_System_defs.hh.

template<typename Row>
typedef Swapping_Vector<Row>::const_iterator Parma_Polyhedra_Library::Linear_System< Row >::iterator

Definition at line 65 of file Linear_System_defs.hh.

Constructor & Destructor Documentation

template<typename Row >
Parma_Polyhedra_Library::Linear_System< Row >::Linear_System ( Topology  topol,
Representation  r 
)
inline

Builds an empty linear system with specified topology.

Rows size and capacity are initialized to $0$.

Definition at line 66 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::Linear_System< Row >::OK().

67  : rows(),
69  row_topology(topol),
71  sorted(true),
72  representation_(r) {
73 
74  PPL_ASSERT(OK());
75 }
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
bool OK() const
Checks if all the invariants are satisfied.
dimension_type index_first_pending
The index of the first pending row.
template<typename Row >
Parma_Polyhedra_Library::Linear_System< Row >::Linear_System ( Topology  topol,
dimension_type  space_dim,
Representation  r 
)
inline

Builds a system with specified topology and dimensions.

Parameters
topolThe topology of the system that will be created;
space_dimThe number of space dimensions of the system that will be created.
rThe representation for system's rows.

Creates a n_rows $\times$ space_dim system whose coefficients are all zero and with the given topology.

Definition at line 79 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::Linear_System< Row >::OK(), and Parma_Polyhedra_Library::Linear_System< Row >::set_space_dimension().

82  : rows(),
84  row_topology(topol),
86  sorted(true),
87  representation_(r) {
88  set_space_dimension(space_dim);
89  PPL_ASSERT(OK());
90 }
void set_space_dimension(dimension_type space_dim)
Sets the space dimension of the rows in the system to space_dim .
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
bool OK() const
Checks if all the invariants are satisfied.
dimension_type index_first_pending
The index of the first pending row.
template<typename Row >
Parma_Polyhedra_Library::Linear_System< Row >::Linear_System ( const Linear_System< Row > &  y)
inline

Copy constructor: pending rows are transformed into non-pending ones.

Definition at line 121 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::Linear_System< Row >::num_pending_rows(), Parma_Polyhedra_Library::Linear_System< Row >::OK(), Parma_Polyhedra_Library::Linear_System< Row >::sorted, and Parma_Polyhedra_Library::Linear_System< Row >::unset_pending_rows().

122  : rows(y.rows),
123  space_dimension_(y.space_dimension_),
124  row_topology(y.row_topology),
125  representation_(y.representation_) {
126  // Previously pending rows may violate sortedness.
127  sorted = (y.num_pending_rows() > 0) ? false : y.sorted;
129  PPL_ASSERT(OK());
130 }
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
void unset_pending_rows()
Sets the index to indicate that the system has no pending rows.
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
Parma_Polyhedra_Library::Linear_System< Row >::Linear_System ( const Linear_System< Row > &  y,
Representation  r 
)
inline

Copy constructor with specified representation. Pending rows are transformed into non-pending ones.

Definition at line 134 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::Linear_System< Row >::num_pending_rows(), Parma_Polyhedra_Library::Linear_System< Row >::num_rows(), Parma_Polyhedra_Library::Linear_System< Row >::OK(), Parma_Polyhedra_Library::Swapping_Vector< T >::resize(), Parma_Polyhedra_Library::Linear_System< Row >::rows, Parma_Polyhedra_Library::Linear_System< Row >::sorted, Parma_Polyhedra_Library::Linear_System< Row >::swap(), and Parma_Polyhedra_Library::Linear_System< Row >::unset_pending_rows().

135  : rows(),
136  space_dimension_(y.space_dimension_),
137  row_topology(y.row_topology),
138  representation_(r) {
139  rows.resize(y.num_rows());
140  for (dimension_type i = 0; i < y.num_rows(); ++i) {
141  // Create the copies with the right representation.
142  Row row(y.rows[i], r);
143  swap(rows[i], row);
144  }
145  // Previously pending rows may violate sortedness.
146  sorted = (y.num_pending_rows() > 0) ? false : y.sorted;
148  PPL_ASSERT(OK());
149 }
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
size_t dimension_type
An unsigned integral type for representing space dimensions.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
void unset_pending_rows()
Sets the index to indicate that the system has no pending rows.
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
Parma_Polyhedra_Library::Linear_System< Row >::Linear_System ( const Linear_System< Row > &  y,
With_Pending   
)
inline

Full copy constructor: pending rows are copied as pending.

Definition at line 153 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::Linear_System< Row >::OK().

154  : rows(y.rows),
155  space_dimension_(y.space_dimension_),
156  row_topology(y.row_topology),
157  index_first_pending(y.index_first_pending),
158  sorted(y.sorted),
159  representation_(y.representation_) {
160  PPL_ASSERT(OK());
161 }
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
bool OK() const
Checks if all the invariants are satisfied.
dimension_type index_first_pending
The index of the first pending row.
template<typename Row >
Parma_Polyhedra_Library::Linear_System< Row >::Linear_System ( const Linear_System< Row > &  y,
Representation  r,
With_Pending   
)
inline

Full copy constructor: pending rows are copied as pending.

Definition at line 165 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::Linear_System< Row >::num_rows(), Parma_Polyhedra_Library::Linear_System< Row >::OK(), Parma_Polyhedra_Library::Swapping_Vector< T >::resize(), Parma_Polyhedra_Library::Linear_System< Row >::rows, and Parma_Polyhedra_Library::Linear_System< Row >::swap().

167  : rows(),
168  space_dimension_(y.space_dimension_),
169  row_topology(y.row_topology),
170  index_first_pending(y.index_first_pending),
171  sorted(y.sorted),
172  representation_(r) {
173  rows.resize(y.num_rows());
174  for (dimension_type i = 0; i < y.num_rows(); ++i) {
175  // Create the copies with the right representation.
176  Row row(y.rows[i], r);
177  swap(rows[i], row);
178  }
179  PPL_ASSERT(OK());
180 }
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
size_t dimension_type
An unsigned integral type for representing space dimensions.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
bool OK() const
Checks if all the invariants are satisfied.
dimension_type index_first_pending
The index of the first pending row.

Member Function Documentation

template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::add_universe_rows_and_space_dimensions ( dimension_type  n)

Adds n rows and space dimensions to the system.

Parameters
nThe number of rows and space dimensions to be added: must be strictly positive.

Turns the system $M \in \Rset^r \times \Rset^c$ into the system $N \in \Rset^{r+n} \times \Rset^{c+n}$ such that $N = \bigl(\genfrac{}{}{0pt}{}{0}{M}\genfrac{}{}{0pt}{}{J}{o}\bigr)$, where $J$ is the specular image of the $n \times n$ identity matrix.

Definition at line 779 of file Linear_System_templates.hh.

References c, Parma_Polyhedra_Library::compare(), Parma_Polyhedra_Library::Boundary_NS::le(), Parma_Polyhedra_Library::NECESSARILY_CLOSED, Parma_Polyhedra_Library::NOT_NECESSARILY_CLOSED, Parma_Polyhedra_Library::Linear_Expression::set_space_dimension(), and Parma_Polyhedra_Library::swap().

779  {
780  PPL_ASSERT(n > 0);
781  const bool was_sorted = is_sorted();
782  const dimension_type old_n_rows = num_rows();
783  const dimension_type old_space_dim
786  rows.resize(rows.size() + n);
787  // The old system is moved to the bottom.
788  for (dimension_type i = old_n_rows; i-- > 0; ) {
789  swap(rows[i], rows[i + n]);
790  }
791  for (dimension_type i = n, c = old_space_dim; i-- > 0; ) {
792  // The top right-hand sub-system (i.e., the system made of new
793  // rows and columns) is set to the specular image of the identity
794  // matrix.
795  if (Variable(c).space_dimension() <= space_dimension()) {
796  // Variable(c) is a user variable.
797  Linear_Expression le(representation());
798  le.set_space_dimension(space_dimension());
799  le += Variable(c);
800  Row r(le, Row::LINE_OR_EQUALITY, row_topology);
801  swap(r, rows[i]);
802  }
803  else {
804  // Variable(c) is the epsilon dimension.
805  PPL_ASSERT(row_topology == NOT_NECESSARILY_CLOSED);
806  Linear_Expression le(Variable(c), representation());
807  Row r(le, Row::LINE_OR_EQUALITY, NECESSARILY_CLOSED);
808  r.mark_as_not_necessarily_closed();
809  swap(r, rows[i]);
810  // Note: `r' is strongly normalized.
811  }
812  ++c;
813  }
814  // If the old system was empty, the last row added is either
815  // a positivity constraint or a point.
816  if (was_sorted) {
817  sorted = (compare(rows[n-1], rows[n]) <= 0);
818  }
819 
820  // If the system is not necessarily closed, move the epsilon coefficients to
821  // the last column.
822  if (!is_necessarily_closed()) {
823  // Try to preserve sortedness of `gen_sys'.
824  PPL_ASSERT(old_space_dim != 0);
825  if (!is_sorted()) {
826  for (dimension_type i = n; i-- > 0; ) {
827  rows[i].expr.swap_space_dimensions(Variable(old_space_dim - 1),
828  Variable(old_space_dim - 1 + n));
829  PPL_ASSERT(rows[i].OK());
830  }
831  }
832  else {
833  dimension_type old_eps_index = old_space_dim - 1;
834  // The upper-right corner of `rows' contains the J matrix:
835  // swap coefficients to preserve sortedness.
836  for (dimension_type i = n; i-- > 0; ++old_eps_index) {
837  rows[i].expr.swap_space_dimensions(Variable(old_eps_index),
838  Variable(old_eps_index + 1));
839  PPL_ASSERT(rows[i].OK());
840  }
841 
842  sorted = true;
843  }
844  }
845  // NOTE: this already checks for OK().
847 }
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
Representation representation() const
Returns the current representation of *this.
size_t dimension_type
An unsigned integral type for representing space dimensions.
void set_index_first_pending_row(dimension_type i)
Sets the index of the first pending row to i.
bool is_necessarily_closed() const
Returns true if and only if the system topology is NECESSARILY_CLOSED.
void set_space_dimension(dimension_type space_dim)
Sets the space dimension of the rows in the system to space_dim .
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
bool is_sorted() const
Returns the value of the sortedness flag.
int compare(const Linear_Expression &x, const Linear_Expression &y)
dimension_type space_dimension() const
Returns the space dimension of the rows in the system.
Coefficient c
Definition: PIP_Tree.cc:64
bool OK() const
Checks if all the invariants are satisfied.
bool le(Boundary_Type type1, const T1 &x1, const Info1 &info1, Boundary_Type type2, const T2 &x2, const Info2 &info2)
dimension_type index_first_pending
The index of the first pending row.
template<typename Row>
void Parma_Polyhedra_Library::Linear_System< Row >::ascii_dump ( ) const

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

template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::ascii_dump ( std::ostream &  s) const

Writes to s an ASCII representation of *this.

Definition at line 119 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::ascii_dump().

119  {
120  // Prints the topology, the number of rows, the number of columns
121  // and the sorted flag. The specialized methods provided by
122  // Constraint_System and Generator_System take care of properly
123  // printing the contents of the system.
124  s << "topology " << (is_necessarily_closed()
125  ? "NECESSARILY_CLOSED"
126  : "NOT_NECESSARILY_CLOSED")
127  << "\n"
128  << num_rows() << " x " << space_dimension() << " ";
130  s << " " << (sorted ? "(sorted)" : "(not_sorted)")
131  << "\n"
132  << "index_first_pending " << first_pending_row()
133  << "\n";
134  for (dimension_type i = 0; i < rows.size(); ++i) {
135  rows[i].ascii_dump(s);
136  }
137 }
Representation representation() const
Returns the current representation of *this.
size_t dimension_type
An unsigned integral type for representing space dimensions.
Enable_If< Is_Native_Or_Checked< T >::value, void >::type ascii_dump(std::ostream &s, const T &t)
bool is_necessarily_closed() const
Returns true if and only if the system topology is NECESSARILY_CLOSED.
dimension_type first_pending_row() const
Returns the index of the first pending row.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
dimension_type space_dimension() const
Returns the space dimension of the rows in the system.
template<typename Row >
bool Parma_Polyhedra_Library::Linear_System< Row >::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.

Reads into a Linear_System object the information produced by the output of ascii_dump(std::ostream&) const. The specialized methods provided by Constraint_System and Generator_System take care of properly reading the contents of the system.

Definition at line 143 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::ascii_load(), Parma_Polyhedra_Library::NECESSARILY_CLOSED, and Parma_Polyhedra_Library::NOT_NECESSARILY_CLOSED.

143  {
144  std::string str;
145  if (!(s >> str) || str != "topology") {
146  return false;
147  }
148  if (!(s >> str)) {
149  return false;
150  }
151 
152  clear();
153 
154  Topology t;
155  if (str == "NECESSARILY_CLOSED") {
156  t = NECESSARILY_CLOSED;
157  }
158  else {
159  if (str != "NOT_NECESSARILY_CLOSED") {
160  return false;
161  }
163  }
164 
165  set_topology(t);
166 
167  dimension_type nrows;
168  dimension_type space_dims;
169  if (!(s >> nrows)) {
170  return false;
171  }
172  if (!(s >> str) || str != "x") {
173  return false;
174  }
175  if (!(s >> space_dims)) {
176  return false;
177  }
178 
179  space_dimension_ = space_dims;
180 
182  return false;
183  }
184 
185  if (!(s >> str) || (str != "(sorted)" && str != "(not_sorted)")) {
186  return false;
187  }
188  const bool sortedness = (str == "(sorted)");
189  dimension_type index;
190  if (!(s >> str) || str != "index_first_pending") {
191  return false;
192  }
193  if (!(s >> index)) {
194  return false;
195  }
196 
197  Row row;
198  for (dimension_type i = 0; i < nrows; ++i) {
199  if (!row.ascii_load(s)) {
200  return false;
201  }
202  insert(row, Recycle_Input());
203  }
204  index_first_pending = index;
205  sorted = sortedness;
206 
207  // Check invariants.
208  PPL_ASSERT(OK());
209  return true;
210 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
void clear()
Clears the system deallocating all its rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
Enable_If< Is_Native_Or_Checked< T >::value, bool >::type ascii_load(std::istream &s, T &t)
void insert(const Row &r)
Adds a copy of r to the system, automatically resizing the system or the row's copy, if needed.
bool OK() const
Checks if all the invariants are satisfied.
void set_topology(Topology t)
Sets the system topology to t .
Topology
Kinds of polyhedra domains.
dimension_type index_first_pending
The index of the first pending row.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::assign_with_pending ( const Linear_System< Row > &  y)
inline

Full assignment operator: pending rows are copied as pending.

Definition at line 193 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::swap().

193  {
194  Linear_System<Row> tmp(y, With_Pending());
195  swap(*this, tmp);
196 }
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::back_substitute ( dimension_type  n_lines_or_equalities)

Back-substitutes the coefficients to reduce the complexity of the system.

Takes an upper triangular system having n_lines_or_equalities rows. For each row, starting from the one having the minimum number of coefficients different from zero, computes the expression of an element as a function of the remaining ones and then substitutes this expression in all the other rows.

Definition at line 628 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::compare(), and Parma_Polyhedra_Library::neg_assign().

628  {
629  // This method is only applied to a system having no pending rows and
630  // exactly `n_lines_or_equalities' lines or equalities, all of which occur
631  // before the first ray or point or inequality.
632  PPL_ASSERT(num_pending_rows() == 0);
633  PPL_ASSERT(n_lines_or_equalities <= num_lines_or_equalities());
634 #ifndef NDEBUG
635  for (dimension_type i = n_lines_or_equalities; i-- > 0; ) {
636  PPL_ASSERT((*this)[i].is_line_or_equality());
637  }
638 #endif
639 
640  const dimension_type nrows = num_rows();
641  // Trying to keep sortedness.
642  bool still_sorted = is_sorted();
643  // This deque of Booleans will be used to flag those rows that,
644  // before exiting, need to be re-checked for sortedness.
645  std::deque<bool> check_for_sortedness;
646  if (still_sorted) {
647  check_for_sortedness.insert(check_for_sortedness.end(), nrows, false);
648  }
649 
650  for (dimension_type k = n_lines_or_equalities; k-- > 0; ) {
651  // For each line or equality, starting from the last one,
652  // looks for the last non-zero element.
653  // `j' will be the index of such a element.
654  Row& row_k = rows[k];
655  const dimension_type j = row_k.expr.last_nonzero();
656  // TODO: Check this.
657  PPL_ASSERT(j != 0);
658 
659  // Go through the equalities above `row_k'.
660  for (dimension_type i = k; i-- > 0; ) {
661  Row& row_i = rows[i];
662  if (row_i.expr.get(Variable(j - 1)) != 0) {
663  // Combine linearly `row_i' with `row_k'
664  // so that `row_i[j]' becomes zero.
665  row_i.linear_combine(row_k, j);
666  if (still_sorted) {
667  // Trying to keep sortedness: remember which rows
668  // have to be re-checked for sortedness at the end.
669  if (i > 0) {
670  check_for_sortedness[i-1] = true;
671  }
672  check_for_sortedness[i] = true;
673  }
674  }
675  }
676 
677  // Due to strong normalization during previous iterations,
678  // the pivot coefficient `row_k[j]' may now be negative.
679  // Since an inequality (or ray or point) cannot be multiplied
680  // by a negative factor, the coefficient of the pivot must be
681  // forced to be positive.
682  const bool have_to_negate = (row_k.expr.get(Variable(j - 1)) < 0);
683  if (have_to_negate) {
684  neg_assign(row_k.expr);
685  }
686 
687  // NOTE: Here row_k will *not* be ok if we have negated it.
688 
689  // Note: we do not mark index `k' in `check_for_sortedness',
690  // because we will later negate back the row.
691 
692  // Go through all the other rows of the system.
693  for (dimension_type i = n_lines_or_equalities; i < nrows; ++i) {
694  Row& row_i = rows[i];
695  if (row_i.expr.get(Variable(j - 1)) != 0) {
696  // Combine linearly the `row_i' with `row_k'
697  // so that `row_i[j]' becomes zero.
698  row_i.linear_combine(row_k, j);
699  if (still_sorted) {
700  // Trying to keep sortedness: remember which rows
701  // have to be re-checked for sortedness at the end.
702  if (i > n_lines_or_equalities) {
703  check_for_sortedness[i-1] = true;
704  }
705  check_for_sortedness[i] = true;
706  }
707  }
708  }
709  if (have_to_negate) {
710  // Negate `row_k' to restore strong-normalization.
711  neg_assign(row_k.expr);
712  }
713 
714  PPL_ASSERT(row_k.OK());
715  }
716 
717  // Trying to keep sortedness.
718  for (dimension_type i = 0; still_sorted && i+1 < nrows; ++i) {
719  if (check_for_sortedness[i]) {
720  // Have to check sortedness of `(*this)[i]' with respect to `(*this)[i+1]'.
721  still_sorted = (compare((*this)[i], (*this)[i+1]) <= 0);
722  }
723  }
724 
725  // Set the sortedness flag.
726  sorted = still_sorted;
727 
728  PPL_ASSERT(OK());
729 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type num_lines_or_equalities() const
Returns the number of rows in the system that represent either lines or equalities.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
bool is_sorted() const
Returns the value of the sortedness flag.
int compare(const Linear_Expression &x, const Linear_Expression &y)
void neg_assign(GMP_Integer &x)
bool OK() const
Checks if all the invariants are satisfied.
dimension_type num_pending_rows() const
Returns the number of rows that are in the pending part of the system.
template<typename Row >
Linear_System< Row >::iterator Parma_Polyhedra_Library::Linear_System< Row >::begin ( )
inline

Definition at line 286 of file Linear_System_inlines.hh.

286  {
287  return rows.begin();
288 }
Swapping_Vector< Row > rows
The vector that contains the rows.
template<typename Row >
Linear_System< Row >::const_iterator Parma_Polyhedra_Library::Linear_System< Row >::begin ( ) const
inline

Definition at line 298 of file Linear_System_inlines.hh.

298  {
299  return rows.begin();
300 }
Swapping_Vector< Row > rows
The vector that contains the rows.
template<typename Row >
bool Parma_Polyhedra_Library::Linear_System< Row >::check_sorted ( ) const

Returns true if and only if *this is sorted, without checking for duplicates.

Definition at line 912 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::compare().

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::merge_rows_assign().

912  {
913  for (dimension_type i = first_pending_row(); i-- > 1; ) {
914  if (compare(rows[i], rows[i-1]) < 0) {
915  return false;
916  }
917  }
918  return true;
919 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type first_pending_row() const
Returns the index of the first pending row.
Swapping_Vector< Row > rows
The vector that contains the rows.
int compare(const Linear_Expression &x, const Linear_Expression &y)
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::clear ( )
inline

Clears the system deallocating all its rows.

Definition at line 214 of file Linear_System_inlines.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::insert_pending().

214  {
215  // Note: do NOT modify the value of `row_topology' and `representation'.
216  rows.clear();
218  sorted = true;
219  space_dimension_ = 0;
220 
221  PPL_ASSERT(OK());
222 }
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
bool OK() const
Checks if all the invariants are satisfied.
dimension_type index_first_pending
The index of the first pending row.
template<typename Row >
Linear_System< Row >::iterator Parma_Polyhedra_Library::Linear_System< Row >::end ( )
inline

Definition at line 292 of file Linear_System_inlines.hh.

292  {
293  return rows.end();
294 }
Swapping_Vector< Row > rows
The vector that contains the rows.
template<typename Row >
Linear_System< Row >::const_iterator Parma_Polyhedra_Library::Linear_System< Row >::end ( ) const
inline

Definition at line 304 of file Linear_System_inlines.hh.

304  {
305  return rows.end();
306 }
Swapping_Vector< Row > rows
The vector that contains the rows.
template<typename Row >
memory_size_type Parma_Polyhedra_Library::Linear_System< Row >::external_memory_in_bytes ( ) const
inline

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

Definition at line 36 of file Linear_System_inlines.hh.

36  {
38 }
Swapping_Vector< Row > rows
The vector that contains the rows.
template<typename Row >
dimension_type Parma_Polyhedra_Library::Linear_System< Row >::first_pending_row ( ) const
inline

Returns the index of the first pending row.

Definition at line 94 of file Linear_System_inlines.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::operator==().

94  {
95  return index_first_pending;
96 }
dimension_type index_first_pending
The index of the first pending row.
template<typename Row >
dimension_type Parma_Polyhedra_Library::Linear_System< Row >::gauss ( dimension_type  n_lines_or_equalities)

Minimizes the subsystem of equations contained in *this.

This method works only on the equalities of the system: the system is required to be partially sorted, so that all the equalities are grouped at its top; it is assumed that the number of equalities is exactly n_lines_or_equalities. The method finds a minimal system for the equalities and returns its rank, i.e., the number of linearly independent equalities. The result is an upper triangular subsystem of equalities: for each equality, the pivot is chosen starting from the right-most space dimensions.

Definition at line 567 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::swap().

567  {
568  // This method is only applied to a linear system having no pending rows and
569  // exactly `n_lines_or_equalities' lines or equalities, all of which occur
570  // before the rays or points or inequalities.
571  PPL_ASSERT(num_pending_rows() == 0);
572  PPL_ASSERT(n_lines_or_equalities == num_lines_or_equalities());
573 #ifndef NDEBUG
574  for (dimension_type i = n_lines_or_equalities; i-- > 0; ) {
575  PPL_ASSERT((*this)[i].is_line_or_equality());
576  }
577 #endif
578 
579  dimension_type rank = 0;
580  // Will keep track of the variations on the system of equalities.
581  bool changed = false;
582  // TODO: Don't use the number of columns.
583  const dimension_type num_cols
585  // TODO: Consider exploiting the row (possible) sparseness of rows in the
586  // following loop, if needed. It would probably make it more cache-efficient
587  // for dense rows, too.
588  for (dimension_type j = num_cols; j-- > 0; ) {
589  for (dimension_type i = rank; i < n_lines_or_equalities; ++i) {
590  // Search for the first row having a non-zero coefficient
591  // (the pivot) in the j-th column.
592  if ((*this)[i].expr.get(j) == 0) {
593  continue;
594  }
595  // Pivot found: if needed, swap rows so that this one becomes
596  // the rank-th row in the linear system.
597  if (i > rank) {
598  swap(rows[i], rows[rank]);
599  // After swapping the system is no longer sorted.
600  changed = true;
601  }
602  // Combine the row containing the pivot with all the lines or
603  // equalities following it, so that all the elements on the j-th
604  // column in these rows become 0.
605  for (dimension_type k = i + 1; k < n_lines_or_equalities; ++k) {
606  if (rows[k].expr.get(Variable(j - 1)) != 0) {
607  rows[k].linear_combine(rows[rank], j);
608  changed = true;
609  }
610  }
611  // Already dealt with the rank-th row.
612  ++rank;
613  // Consider another column index `j'.
614  break;
615  }
616  }
617  if (changed) {
618  sorted = false;
619  }
620 
621  PPL_ASSERT(OK());
622  return rank;
623 }
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type num_lines_or_equalities() const
Returns the number of rows in the system that represent either lines or equalities.
bool is_necessarily_closed() const
Returns true if and only if the system topology is NECESSARILY_CLOSED.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
dimension_type space_dimension() const
Returns the space dimension of the rows in the system.
bool OK() const
Checks if all the invariants are satisfied.
dimension_type num_pending_rows() const
Returns the number of rows that are in the pending part of the system.
template<typename Row >
bool Parma_Polyhedra_Library::Linear_System< Row >::has_no_rows ( ) const
inline

Definition at line 310 of file Linear_System_inlines.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::insert().

310  {
311  return rows.empty();
312 }
Swapping_Vector< Row > rows
The vector that contains the rows.
template<typename Row>
void Parma_Polyhedra_Library::Linear_System< Row >::insert ( const Row &  r)

Adds a copy of r to the system, automatically resizing the system or the row's copy, if needed.

Definition at line 214 of file Linear_System_templates.hh.

214  {
215  Row tmp(r, representation());
216  insert(tmp, Recycle_Input());
217 }
Representation representation() const
Returns the current representation of *this.
void insert(const Row &r)
Adds a copy of r to the system, automatically resizing the system or the row's copy, if needed.
template<typename Row>
void Parma_Polyhedra_Library::Linear_System< Row >::insert ( Row &  r,
Recycle_Input   
)

Adds r to the system, stealing its contents and automatically resizing the system or the row, if needed.

Definition at line 221 of file Linear_System_templates.hh.

221  {
222  insert_no_ok(r, Recycle_Input());
223  PPL_ASSERT(OK());
224 }
bool OK() const
Checks if all the invariants are satisfied.
void insert_no_ok(Row &r, Recycle_Input)
Adds r to the system, stealing its contents and automatically resizing the system or the row...
template<typename Row>
void Parma_Polyhedra_Library::Linear_System< Row >::insert ( const Linear_System< Row > &  y)

Adds to *this a copy of the rows of y.

It is assumed that *this has no pending rows.

Definition at line 323 of file Linear_System_templates.hh.

323  {
324  Linear_System tmp(y, representation(), With_Pending());
325  insert(tmp, Recycle_Input());
326 }
Representation representation() const
Returns the current representation of *this.
void insert(const Row &r)
Adds a copy of r to the system, automatically resizing the system or the row's copy, if needed.
Linear_System(Topology topol, Representation r)
Builds an empty linear system with specified topology.
template<typename Row>
void Parma_Polyhedra_Library::Linear_System< Row >::insert ( Linear_System< Row > &  r,
Recycle_Input   
)

Adds to *this a the rows of `y', stealing them from `y'.

It is assumed that *this has no pending rows.

Definition at line 330 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::compare(), Parma_Polyhedra_Library::Linear_System< Row >::has_no_rows(), Parma_Polyhedra_Library::Linear_System< Row >::is_sorted(), and Parma_Polyhedra_Library::Linear_System< Row >::num_pending_rows().

330  {
331  PPL_ASSERT(num_pending_rows() == 0);
332 
333  // Adding no rows is a no-op.
334  if (y.has_no_rows()) {
335  return;
336  }
337 
338  // Check if sortedness is preserved.
339  if (is_sorted()) {
340  if (!y.is_sorted() || y.num_pending_rows() > 0) {
341  sorted = false;
342  }
343  else {
344  // `y' is sorted and has no pending rows.
345  const dimension_type n_rows = num_rows();
346  if (n_rows > 0) {
347  sorted = (compare(rows[n_rows-1], y[0]) <= 0);
348  }
349  }
350  }
351 
352  // Add the rows of `y' as if they were pending.
353  insert_pending(y, Recycle_Input());
354 
355  // TODO: May y have pending rows? Should they remain pending?
356 
357  // There are no pending_rows.
359 
360  PPL_ASSERT(OK());
361 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
void insert_pending(const Row &r)
Adds a copy of the given row to the pending part of the system, automatically resizing the system or ...
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
void unset_pending_rows()
Sets the index to indicate that the system has no pending rows.
bool is_sorted() const
Returns the value of the sortedness flag.
int compare(const Linear_Expression &x, const Linear_Expression &y)
bool OK() const
Checks if all the invariants are satisfied.
dimension_type num_pending_rows() const
Returns the number of rows that are in the pending part of the system.
template<typename Row>
void Parma_Polyhedra_Library::Linear_System< Row >::insert_no_ok ( Row &  r,
Recycle_Input   
)
private

Adds r to the system, stealing its contents and automatically resizing the system or the row, if needed.

This method is for internal use, it does *not* assert OK() at the end, so it can be used for invalid systems.

Definition at line 228 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::compare().

228  {
229  PPL_ASSERT(topology() == r.topology());
230  // This method is only used when the system has no pending rows.
231  PPL_ASSERT(num_pending_rows() == 0);
232 
233  const bool was_sorted = is_sorted();
234 
235  insert_pending_no_ok(r, Recycle_Input());
236 
237  if (was_sorted) {
238  const dimension_type nrows = num_rows();
239  // The added row may have caused the system to be not sorted anymore.
240  if (nrows > 1) {
241  // If the system is not empty and the inserted row is the
242  // greatest one, the system is set to be sorted.
243  // If it is not the greatest one then the system is no longer sorted.
244  sorted = (compare(rows[nrows-2], rows[nrows-1]) <= 0);
245  }
246  else {
247  // A system having only one row is sorted.
248  sorted = true;
249  }
250  }
251 
253 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Topology topology() const
Returns the system topology.
Swapping_Vector< Row > rows
The vector that contains the rows.
void insert_pending_no_ok(Row &r, Recycle_Input)
Adds r to the pending part of the system, stealing its contents and automatically resizing the system...
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
void unset_pending_rows()
Sets the index to indicate that the system has no pending rows.
bool is_sorted() const
Returns the value of the sortedness flag.
int compare(const Linear_Expression &x, const Linear_Expression &y)
dimension_type num_pending_rows() const
Returns the number of rows that are in the pending part of the system.
template<typename Row>
void Parma_Polyhedra_Library::Linear_System< Row >::insert_pending ( const Row &  r)

Adds a copy of the given row to the pending part of the system, automatically resizing the system or the row, if needed.

Definition at line 284 of file Linear_System_templates.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::insert_pending().

284  {
285  Row tmp(r, representation());
286  insert_pending(tmp, Recycle_Input());
287 }
Representation representation() const
Returns the current representation of *this.
void insert_pending(const Row &r)
Adds a copy of the given row to the pending part of the system, automatically resizing the system or ...
template<typename Row>
void Parma_Polyhedra_Library::Linear_System< Row >::insert_pending ( Row &  r,
Recycle_Input   
)

Adds the given row to the pending part of the system, stealing its contents and automatically resizing the system or the row, if needed.

Definition at line 291 of file Linear_System_templates.hh.

291  {
292  insert_pending_no_ok(r, Recycle_Input());
293  PPL_ASSERT(OK());
294 }
void insert_pending_no_ok(Row &r, Recycle_Input)
Adds r to the pending part of the system, stealing its contents and automatically resizing the system...
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row>
void Parma_Polyhedra_Library::Linear_System< Row >::insert_pending ( const Linear_System< Row > &  r)

Adds a copy of the rows of `y' to the pending part of `*this'.

Definition at line 298 of file Linear_System_templates.hh.

298  {
299  Linear_System tmp(y, representation(), With_Pending());
300  insert_pending(tmp, Recycle_Input());
301 }
Representation representation() const
Returns the current representation of *this.
void insert_pending(const Row &r)
Adds a copy of the given row to the pending part of the system, automatically resizing the system or ...
Linear_System(Topology topol, Representation r)
Builds an empty linear system with specified topology.
template<typename Row>
void Parma_Polyhedra_Library::Linear_System< Row >::insert_pending ( Linear_System< Row > &  r,
Recycle_Input   
)

Adds the rows of `y' to the pending part of `*this', stealing them from `y'.

Definition at line 305 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::Linear_System< Row >::clear(), Parma_Polyhedra_Library::Linear_System< Row >::insert_pending(), Parma_Polyhedra_Library::Linear_System< Row >::num_rows(), Parma_Polyhedra_Library::Linear_System< Row >::OK(), Parma_Polyhedra_Library::Linear_System< Row >::rows, and Parma_Polyhedra_Library::Linear_System< Row >::space_dimension().

305  {
306  Linear_System& x = *this;
307  PPL_ASSERT(x.space_dimension() == y.space_dimension());
308 
309  // Steal the rows of `y'.
310  // This loop must use an increasing index (instead of a decreasing one) to
311  // preserve the row ordering.
312  for (dimension_type i = 0; i < y.num_rows(); ++i) {
313  x.insert_pending(y.rows[i], Recycle_Input());
314  }
315 
316  y.clear();
317 
318  PPL_ASSERT(x.OK());
319 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Linear_System(Topology topol, Representation r)
Builds an empty linear system with specified topology.
template<typename Row>
void Parma_Polyhedra_Library::Linear_System< Row >::insert_pending_no_ok ( Row &  r,
Recycle_Input   
)
private

Adds r to the pending part of the system, stealing its contents and automatically resizing the system or the row, if needed.

This method is for internal use, it does *not* assert OK() at the end, so it can be used for invalid systems.

Definition at line 257 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::swap().

257  {
258  // TODO: A Grid_Generator_System may contain non-normalized lines that
259  // represent parameters, so this check is disabled. Consider re-enabling it
260  // when it's possibile.
261 #if 0
262  // The added row must be strongly normalized and have the same
263  // number of elements as the existing rows of the system.
264  PPL_ASSERT(r.check_strong_normalized());
265 #endif
266 
267  PPL_ASSERT(r.topology() == topology());
268 
269  r.set_representation(representation());
270 
271  if (space_dimension() < r.space_dimension()) {
272  set_space_dimension_no_ok(r.space_dimension());
273  }
274  else {
275  r.set_space_dimension_no_ok(space_dimension());
276  }
277 
278  rows.resize(rows.size() + 1);
279  swap(rows.back(), r);
280 }
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
Representation representation() const
Returns the current representation of *this.
Topology topology() const
Returns the system topology.
Swapping_Vector< Row > rows
The vector that contains the rows.
void set_space_dimension_no_ok(dimension_type space_dim)
Sets the space dimension of the rows in the system to space_dim .
dimension_type space_dimension() const
Returns the space dimension of the rows in the system.
template<typename Row >
bool Parma_Polyhedra_Library::Linear_System< Row >::is_necessarily_closed ( ) const
inline

Returns true if and only if the system topology is NECESSARILY_CLOSED.

Definition at line 274 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::NECESSARILY_CLOSED.

template<typename Row >
bool Parma_Polyhedra_Library::Linear_System< Row >::is_sorted ( ) const
inline

Returns the value of the sortedness flag.

Definition at line 48 of file Linear_System_inlines.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::insert().

48  {
49  // The flag `sorted' does not really reflect the sortedness status
50  // of a system (if `sorted' evaluates to `false' nothing is known).
51  // This assertion is used to ensure that the system
52  // is actually sorted when `sorted' value is 'true'.
53  PPL_ASSERT(!sorted || check_sorted());
54  return sorted;
55 }
bool check_sorted() const
Returns true if and only if *this is sorted, without checking for duplicates.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::m_swap ( Linear_System< Row > &  y)
inline

Swaps *this with y.

Definition at line 200 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::Linear_System< Row >::index_first_pending, Parma_Polyhedra_Library::Linear_System< Row >::OK(), Parma_Polyhedra_Library::Linear_System< Row >::representation_, Parma_Polyhedra_Library::Linear_System< Row >::row_topology, Parma_Polyhedra_Library::Linear_System< Row >::rows, Parma_Polyhedra_Library::Linear_System< Row >::sorted, Parma_Polyhedra_Library::Linear_System< Row >::space_dimension_, and Parma_Polyhedra_Library::swap().

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::swap().

200  {
201  using std::swap;
202  swap(rows, y.rows);
203  swap(space_dimension_, y.space_dimension_);
204  swap(row_topology, y.row_topology);
205  swap(index_first_pending, y.index_first_pending);
206  swap(sorted, y.sorted);
207  swap(representation_, y.representation_);
208  PPL_ASSERT(OK());
209  PPL_ASSERT(y.OK());
210 }
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
void swap(CO_Tree &x, CO_Tree &y)
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
bool OK() const
Checks if all the invariants are satisfied.
dimension_type index_first_pending
The index of the first pending row.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::mark_as_necessarily_closed ( )
inline

Marks the epsilon dimension as a standard dimension.

The system topology is changed to NOT_NECESSARILY_CLOSED, and the number of space dimensions is increased by 1.

Definition at line 226 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::NECESSARILY_CLOSED, and Parma_Polyhedra_Library::NOT_NECESSARILY_CLOSED.

226  {
227  PPL_ASSERT(topology() == NOT_NECESSARILY_CLOSED);
230  for (dimension_type i = num_rows(); i-- > 0; ) {
231  rows[i].mark_as_necessarily_closed();
232  }
233 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Topology topology() const
Returns the system topology.
Swapping_Vector< Row > rows
The vector that contains the rows.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::mark_as_not_necessarily_closed ( )
inline

Marks the last dimension as the epsilon dimension.

The system topology is changed to NECESSARILY_CLOSED, and the number of space dimensions is decreased by 1.

Definition at line 237 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::NECESSARILY_CLOSED, and Parma_Polyhedra_Library::NOT_NECESSARILY_CLOSED.

237  {
238  PPL_ASSERT(topology() == NECESSARILY_CLOSED);
239  PPL_ASSERT(space_dimension() > 0);
242  for (dimension_type i = num_rows(); i-- > 0; ) {
243  rows[i].mark_as_not_necessarily_closed();
244  }
245 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Topology topology() const
Returns the system topology.
Swapping_Vector< Row > rows
The vector that contains the rows.
dimension_type space_dimension() const
Returns the space dimension of the rows in the system.
template<typename Row >
dimension_type Parma_Polyhedra_Library::Linear_System< Row >::max_space_dimension ( )
inlinestatic

Returns the maximum space dimension a Linear_System can handle.

Definition at line 344 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::max_space_dimension().

Referenced by Parma_Polyhedra_Library::Constraint_System::max_space_dimension(), Parma_Polyhedra_Library::Grid_Generator_System::max_space_dimension(), and Parma_Polyhedra_Library::Generator_System::max_space_dimension().

344  {
345  return Row::max_space_dimension();
346 }
dimension_type max_space_dimension()
Returns the maximum space dimension this library can handle.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::merge_rows_assign ( const Linear_System< Row > &  y)

Assigns to *this the result of merging its rows with those of y, obtaining a sorted system.

Duplicated rows will occur only once in the result. On entry, both systems are assumed to be sorted and have no pending rows.

Definition at line 55 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::Swapping_Vector< T >::back(), Parma_Polyhedra_Library::Linear_System< Row >::check_sorted(), Parma_Polyhedra_Library::compare(), Parma_Polyhedra_Library::compute_capacity(), Parma_Polyhedra_Library::Swapping_Vector< T >::max_num_rows(), Parma_Polyhedra_Library::Linear_System< Row >::num_pending_rows(), Parma_Polyhedra_Library::Linear_System< Row >::num_rows(), Parma_Polyhedra_Library::Swapping_Vector< T >::reserve(), Parma_Polyhedra_Library::Swapping_Vector< T >::resize(), Parma_Polyhedra_Library::Linear_System< Row >::rows, Parma_Polyhedra_Library::Swapping_Vector< T >::size(), Parma_Polyhedra_Library::Linear_System< Row >::space_dimension(), and Parma_Polyhedra_Library::swap().

55  {
56  PPL_ASSERT(space_dimension() >= y.space_dimension());
57  // Both systems have to be sorted and have no pending rows.
58  PPL_ASSERT(check_sorted() && y.check_sorted());
59  PPL_ASSERT(num_pending_rows() == 0 && y.num_pending_rows() == 0);
60 
61  Linear_System& x = *this;
62 
63  // A temporary vector...
64  Swapping_Vector<Row> tmp;
65  // ... with enough capacity not to require any reallocations.
66  tmp.reserve(compute_capacity(x.rows.size() + y.rows.size(),
67  tmp.max_num_rows()));
68 
69  dimension_type xi = 0;
70  const dimension_type x_num_rows = x.num_rows();
71  dimension_type yi = 0;
72  const dimension_type y_num_rows = y.num_rows();
73 
74  while (xi < x_num_rows && yi < y_num_rows) {
75  const int comp = compare(x[xi], y[yi]);
76  if (comp <= 0) {
77  // Elements that can be taken from `x' are actually _stolen_ from `x'
78  tmp.resize(tmp.size() + 1);
79  swap(tmp.back(), x.rows[xi++]);
80  tmp.back().set_representation(representation());
81  if (comp == 0) {
82  // A duplicate element.
83  ++yi;
84  }
85  }
86  else {
87  // (comp > 0)
88  tmp.resize(tmp.size() + 1);
89  Row copy(y[yi++], space_dimension(), representation());
90  swap(tmp.back(), copy);
91  }
92  }
93  // Insert what is left.
94  if (xi < x_num_rows) {
95  while (xi < x_num_rows) {
96  tmp.resize(tmp.size() + 1);
97  swap(tmp.back(), x.rows[xi++]);
98  tmp.back().set_representation(representation());
99  }
100  }
101  else {
102  while (yi < y_num_rows) {
103  tmp.resize(tmp.size() + 1);
104  Row copy(y[yi++], space_dimension(), representation());
105  swap(tmp.back(), copy);
106  }
107  }
108 
109  // We get the result matrix and let the old one be destroyed.
110  swap(tmp, rows);
111  // There are no pending rows.
113  PPL_ASSERT(check_sorted());
114  PPL_ASSERT(OK());
115 }
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
Representation representation() const
Returns the current representation of *this.
size_t dimension_type
An unsigned integral type for representing space dimensions.
bool check_sorted() const
Returns true if and only if *this is sorted, without checking for duplicates.
Swapping_Vector< Row > rows
The vector that contains the rows.
void unset_pending_rows()
Sets the index to indicate that the system has no pending rows.
dimension_type compute_capacity(dimension_type requested_size, dimension_type maximum_size)
Speculative allocation function.
int compare(const Linear_Expression &x, const Linear_Expression &y)
Linear_System(Topology topol, Representation r)
Builds an empty linear system with specified topology.
dimension_type space_dimension() const
Returns the space dimension of the rows in the system.
bool OK() const
Checks if all the invariants are satisfied.
dimension_type num_pending_rows() const
Returns the number of rows that are in the pending part of the system.
template<typename Row >
dimension_type Parma_Polyhedra_Library::Linear_System< Row >::num_lines_or_equalities ( ) const

Returns the number of rows in the system that represent either lines or equalities.

Definition at line 41 of file Linear_System_templates.hh.

41  {
42  PPL_ASSERT(num_pending_rows() == 0);
43  const Linear_System& x = *this;
44  dimension_type n = 0;
45  for (dimension_type i = num_rows(); i-- > 0; ) {
46  if (x[i].is_line_or_equality()) {
47  ++n;
48  }
49  }
50  return n;
51 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Linear_System(Topology topol, Representation r)
Builds an empty linear system with specified topology.
dimension_type num_pending_rows() const
Returns the number of rows that are in the pending part of the system.
template<typename Row >
dimension_type Parma_Polyhedra_Library::Linear_System< Row >::num_pending_rows ( ) const
inline

Returns the number of rows that are in the pending part of the system.

Definition at line 100 of file Linear_System_inlines.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::insert(), Parma_Polyhedra_Library::Linear_System< Row >::Linear_System(), and Parma_Polyhedra_Library::Linear_System< Row >::merge_rows_assign().

100  {
101  PPL_ASSERT(num_rows() >= first_pending_row());
102  return num_rows() - first_pending_row();
103 }
dimension_type first_pending_row() const
Returns the index of the first pending row.
template<typename Row >
bool Parma_Polyhedra_Library::Linear_System< Row >::OK ( ) const

Checks if all the invariants are satisfied.

Definition at line 923 of file Linear_System_templates.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::insert_pending(), Parma_Polyhedra_Library::Linear_System< Row >::Linear_System(), and Parma_Polyhedra_Library::Linear_System< Row >::m_swap().

923  {
924 #ifndef NDEBUG
925  using std::endl;
926  using std::cerr;
927 #endif
928 
929  for (dimension_type i = rows.size(); i-- > 0; ) {
930  if (rows[i].representation() != representation()) {
931 #ifndef NDEBUG
932  cerr << "Linear_System has a row with the wrong representation!"
933  << endl;
934 #endif
935  return false;
936  }
937  if (rows[i].space_dimension() != space_dimension()) {
938 #ifndef NDEBUG
939  cerr << "Linear_System has a row with the wrong number of space dimensions!"
940  << endl;
941 #endif
942  return false;
943  }
944  }
945 
946  for (dimension_type i = rows.size(); i-- > 0; ) {
947  if (rows[i].topology() != topology()) {
948 #ifndef NDEBUG
949  cerr << "Linear_System has a row with the wrong topology!"
950  << endl;
951 #endif
952  return false;
953  }
954 
955  }
956  // `index_first_pending' must be less than or equal to `num_rows()'.
957  if (first_pending_row() > num_rows()) {
958 #ifndef NDEBUG
959  cerr << "Linear_System has a negative number of pending rows!"
960  << endl;
961 #endif
962  return false;
963  }
964 
965  // Check for topology mismatches.
966  const dimension_type n_rows = num_rows();
967  for (dimension_type i = 0; i < n_rows; ++i) {
968  if (topology() != rows[i].topology()) {
969 #ifndef NDEBUG
970  cerr << "Topology mismatch between the system "
971  << "and one of its rows!"
972  << endl;
973 #endif
974  return false;
975  }
976 
977  }
978  if (sorted && !check_sorted()) {
979 #ifndef NDEBUG
980  cerr << "The system declares itself to be sorted but it is not!"
981  << endl;
982 #endif
983  return false;
984  }
985 
986  // All checks passed.
987  return true;
988 }
Representation representation() const
Returns the current representation of *this.
size_t dimension_type
An unsigned integral type for representing space dimensions.
Topology topology() const
Returns the system topology.
bool check_sorted() const
Returns true if and only if *this is sorted, without checking for duplicates.
dimension_type first_pending_row() const
Returns the index of the first pending row.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
dimension_type space_dimension() const
Returns the space dimension of the rows in the system.
template<typename Row >
Linear_System< Row > & Parma_Polyhedra_Library::Linear_System< Row >::operator= ( const Linear_System< Row > &  y)
inline

Assignment operator: pending rows are transformed into non-pending ones.

Definition at line 184 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::swap().

184  {
185  // NOTE: Pending rows are transformed into non-pending ones.
186  Linear_System<Row> tmp = y;
187  swap(*this, tmp);
188  return *this;
189 }
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
template<typename Row >
const Row & Parma_Polyhedra_Library::Linear_System< Row >::operator[] ( dimension_type  k) const
inline

Returns a const reference to the k-th row of the system.

Definition at line 280 of file Linear_System_inlines.hh.

280  {
281  return rows[k];
282 }
Swapping_Vector< Row > rows
The vector that contains the rows.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::permute_space_dimensions ( const std::vector< Variable > &  cycle)
inline

Permutes the space dimensions of the matrix.

Definition at line 659 of file Linear_System_inlines.hh.

659  {
660  for (dimension_type i = num_rows(); i-- > 0; ) {
661  rows[i].permute_space_dimensions(cycle);
662  }
663  sorted = false;
664  PPL_ASSERT(OK());
665 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row>
void Parma_Polyhedra_Library::Linear_System< Row >::print ( ) const

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

template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::remove_row ( dimension_type  i,
bool  keep_sorted = false 
)
inline

Makes the system shrink by removing its i-th row.

When keep_sorted is true and the system is sorted, sortedness will be preserved, but this method costs O(n).

Otherwise, this method just swaps the i-th row with the last and then removes it, so it costs O(1).

Definition at line 414 of file Linear_System_inlines.hh.

414  {
415  remove_row_no_ok(i, keep_sorted);
416  PPL_ASSERT(OK());
417 }
void remove_row_no_ok(dimension_type i, bool keep_sorted=false)
Makes the system shrink by removing its i-th row.
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::remove_row_no_ok ( dimension_type  i,
bool  keep_sorted = false 
)
inlineprivate

Makes the system shrink by removing its i-th row.

When keep_sorted is true and the system is sorted, sortedness will be preserved, but this method costs O(n).

Otherwise, this method just swaps the i-th row with the last and then removes it, so it costs O(1).

This method is for internal use, it does *not* assert OK() at the end, so it can be used for invalid systems.

Definition at line 372 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::swap().

373  {
374  PPL_ASSERT(i < num_rows());
375  const bool was_pending = (i >= index_first_pending);
376 
377  if (sorted && keep_sorted && !was_pending) {
378  for (dimension_type j = i + 1; j < rows.size(); ++j) {
379  swap(rows[j], rows[j-1]);
380  }
381  rows.pop_back();
382  }
383  else {
384  if (!was_pending) {
385  sorted = false;
386  }
387  const bool last_row_is_pending = (num_rows() - 1 >= index_first_pending);
388  if (was_pending == last_row_is_pending) {
389  // Either both rows are pending or both rows are not pending.
390  swap(rows[i], rows.back());
391  }
392  else {
393  // Pending rows are stored after the non-pending ones.
394  PPL_ASSERT(!was_pending);
395  PPL_ASSERT(last_row_is_pending);
396 
397  // Swap the row with the last non-pending row.
398  swap(rows[i], rows[index_first_pending - 1]);
399 
400  // Now the (non-pending) row that has to be deleted is between the
401  // non-pending and the pending rows.
402  swap(rows[i], rows.back());
403  }
404  rows.pop_back();
405  }
406  if (!was_pending) {
407  // A non-pending row has been removed.
409  }
410 }
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
size_t dimension_type
An unsigned integral type for representing space dimensions.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
dimension_type index_first_pending
The index of the first pending row.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::remove_rows ( dimension_type  first,
dimension_type  last,
bool  keep_sorted = false 
)
inline

Makes the system shrink by removing the rows in [first,last).

When keep_sorted is true and the system is sorted, sortedness will be preserved, but this method costs O(num_rows()).

Otherwise, this method just swaps the rows with the last ones and then removes them, so it costs O(last - first).

Definition at line 422 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::swap().

424  {
425  PPL_ASSERT(first <= last);
426  PPL_ASSERT(last <= num_rows());
427  const dimension_type n = last - first;
428 
429  if (n == 0) {
430  return;
431  }
432 
433  // All the rows that have to be removed must have the same (pending or
434  // non-pending) status.
435  PPL_ASSERT(first >= index_first_pending || last <= index_first_pending);
436 
437  const bool were_pending = (first >= index_first_pending);
438 
439  // Move the rows in [first,last) at the end of the system.
440  if (sorted && keep_sorted && !were_pending) {
441  // Preserve the row ordering.
442  for (dimension_type i = last; i < rows.size(); ++i) {
443  swap(rows[i], rows[i - n]);
444  }
445 
446  rows.resize(rows.size() - n);
447 
448  // `n' non-pending rows have been removed.
449  index_first_pending -= n;
450 
451  PPL_ASSERT(OK());
452  return;
453  }
454 
455  // We can ignore the row ordering, but we must not mix pending and
456  // non-pending rows.
457 
458  const dimension_type offset = rows.size() - n - first;
459  // We want to swap the rows in [first, last) and
460  // [first + offset, last + offset) (note that these intervals may not be
461  // disjunct).
462 
463  if (index_first_pending == num_rows()) {
464  // There are no pending rows.
465  PPL_ASSERT(!were_pending);
466 
467  swap_row_intervals(first, last, offset);
468 
469  rows.resize(rows.size() - n);
470 
471  // `n' non-pending rows have been removed.
472  index_first_pending -= n;
473  }
474  else {
475  // There are some pending rows in [first + offset, last + offset).
476  if (were_pending) {
477  // Both intervals contain only pending rows, because the second
478  // interval is after the first.
479 
480  swap_row_intervals(first, last, offset);
481 
482  rows.resize(rows.size() - n);
483 
484  // `n' non-pending rows have been removed.
485  index_first_pending -= n;
486  }
487  else {
488  PPL_ASSERT(rows.size() - n < index_first_pending);
489  PPL_ASSERT(rows.size() > index_first_pending);
490  PPL_ASSERT(!were_pending);
491  // In the [size() - n, size()) interval there are some non-pending
492  // rows and some pending ones. Be careful not to mix them.
493 
494  PPL_ASSERT(index_first_pending >= last);
495  swap_row_intervals(first, last, index_first_pending - last);
496 
497  // Mark the rows that must be deleted as pending.
498  index_first_pending -= n;
499  first = index_first_pending;
500  last = first + n;
501 
502  // Move them at the end of the system.
503  swap_row_intervals(first, last, num_rows() - last);
504 
505  // Actually remove the rows.
506  rows.resize(rows.size() - n);
507  }
508  }
509 
510  PPL_ASSERT(OK());
511 }
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
size_t dimension_type
An unsigned integral type for representing space dimensions.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
void swap_row_intervals(dimension_type first, dimension_type last, dimension_type offset)
bool OK() const
Checks if all the invariants are satisfied.
dimension_type index_first_pending
The index of the first pending row.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::remove_rows ( const std::vector< dimension_type > &  indexes)
inline

Removes the specified rows. The row ordering of remaining rows is preserved.

Parameters
indexesspecifies a list of row indexes. It must be sorted.

Definition at line 560 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::swap().

560  {
561 #ifndef NDEBUG
562  {
563  // Check that `indexes' is sorted.
564  std::vector<dimension_type> sorted_indexes = indexes;
565  std::sort(sorted_indexes.begin(), sorted_indexes.end());
566  PPL_ASSERT(indexes == sorted_indexes);
567 
568  // Check that the last index (if any) is lower than num_rows().
569  // This guarantees that all indexes are in [0, num_rows()).
570  if (!indexes.empty()) {
571  PPL_ASSERT(indexes.back() < num_rows());
572  }
573  }
574 #endif
575 
576  if (indexes.empty()) {
577  return;
578  }
579 
580  const dimension_type rows_size = rows.size();
581  typedef std::vector<dimension_type>::const_iterator itr_t;
582 
583  // `i' and last_unused_row' start with the value `indexes[0]' instead
584  // of `0', because the loop would just increment `last_unused_row' in the
585  // preceding iterations.
586  dimension_type last_unused_row = indexes[0];
587  dimension_type i = indexes[0];
588  itr_t itr = indexes.begin();
589  itr_t itr_end = indexes.end();
590  while (itr != itr_end) {
591  // i <= *itr < rows_size
592  PPL_ASSERT(i < rows_size);
593  if (*itr == i) {
594  // The current row has to be removed, don't increment last_unused_row.
595  ++itr;
596  }
597  else {
598  // The current row must not be removed, swap it after the last used row.
599  swap(rows[last_unused_row], rows[i]);
600  ++last_unused_row;
601  }
602  ++i;
603  }
604 
605  // Move up the remaining rows, if any.
606  for ( ; i < rows_size; ++i) {
607  swap(rows[last_unused_row], rows[i]);
608  ++last_unused_row;
609  }
610 
611  PPL_ASSERT(last_unused_row == num_rows() - indexes.size());
612 
613  // The rows that have to be removed are now at the end of the system, just
614  // remove them.
615  rows.resize(last_unused_row);
616 
617  // Adjust index_first_pending.
618  if (indexes[0] >= index_first_pending) {
619  // Removing pending rows only.
620  }
621  else {
622  if (indexes.back() < index_first_pending) {
623  // Removing non-pending rows only.
624  index_first_pending -= indexes.size();
625  }
626  else {
627  // Removing some pending and some non-pending rows, count the
628  // non-pending rows that must be removed.
629  // This exploits the fact that `indexes' is sorted by using binary
630  // search.
631  itr_t j = std::lower_bound(indexes.begin(), indexes.end(),
633  std::iterator_traits<itr_t>::difference_type
634  non_pending = j - indexes.begin();
635  index_first_pending -= static_cast<dimension_type>(non_pending);
636  }
637  }
638 
639  // NOTE: This method does *not* call set_sorted(false), because it preserves
640  // the relative row ordering.
641 
642  PPL_ASSERT(OK());
643 }
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
size_t dimension_type
An unsigned integral type for representing space dimensions.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool OK() const
Checks if all the invariants are satisfied.
dimension_type index_first_pending
The index of the first pending row.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::remove_space_dimensions ( const Variables_Set vars)

Removes all the specified dimensions from the system.

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

Definition at line 365 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::Variables_Set::space_dimension().

365  {
366  // Dimension-compatibility assertion.
367  PPL_ASSERT(space_dimension() >= vars.space_dimension());
368 
369  // The removal of no dimensions from any system is a no-op. This
370  // case also captures the only legal removal of dimensions from a
371  // 0-dim system.
372  if (vars.empty()) {
373  return;
374  }
375 
376  // NOTE: num_rows() is *not* constant, because it may be decreased by
377  // remove_row_no_ok().
378  for (dimension_type i = 0; i < num_rows(); ) {
379  const bool valid = rows[i].remove_space_dimensions(vars);
380  if (!valid) {
381  // Remove the current row.
382  // We can't call remove_row(i) here, because the system is not OK as
383  // some rows already have the new space dimension and others still have
384  // the old one.
385  remove_row_no_ok(i, false);
386  }
387  else {
388  ++i;
389  }
390  }
391 
392  space_dimension_ -= vars.size();
393 
394  PPL_ASSERT(OK());
395 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Swapping_Vector< Row > rows
The vector that contains the rows.
void remove_row_no_ok(dimension_type i, bool keep_sorted=false)
Makes the system shrink by removing its i-th row.
dimension_type space_dimension() const
Returns the space dimension of the rows in the system.
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::remove_trailing_rows ( dimension_type  n)
inline

Makes the system shrink by removing its n trailing rows.

Definition at line 647 of file Linear_System_inlines.hh.

647  {
648  PPL_ASSERT(rows.size() >= n);
649  rows.resize(rows.size() - n);
650  if (first_pending_row() > rows.size()) {
652  }
653  PPL_ASSERT(OK());
654 }
dimension_type first_pending_row() const
Returns the index of the first pending row.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool OK() const
Checks if all the invariants are satisfied.
dimension_type index_first_pending
The index of the first pending row.
template<typename Row >
Representation Parma_Polyhedra_Library::Linear_System< Row >::representation ( ) const
inline

Returns the current representation of *this.

Definition at line 328 of file Linear_System_inlines.hh.

328  {
329  return representation_;
330 }
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::set_index_first_pending_row ( dimension_type  i)
inline

Sets the index of the first pending row to i.

Definition at line 114 of file Linear_System_inlines.hh.

114  {
116  PPL_ASSERT(OK());
117 }
bool OK() const
Checks if all the invariants are satisfied.
dimension_type index_first_pending
The index of the first pending row.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::set_necessarily_closed ( )
inline

Sets the system topology to NECESSARILY_CLOSED.

Definition at line 262 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::NECESSARILY_CLOSED.

template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::set_not_necessarily_closed ( )
inline

Sets the system topology to NOT_NECESSARILY_CLOSED.

Definition at line 268 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::NOT_NECESSARILY_CLOSED.

template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::set_representation ( Representation  r)
inline

Converts *this to the specified representation.

Definition at line 334 of file Linear_System_inlines.hh.

334  {
335  representation_ = r;
336  for (dimension_type i = 0; i < rows.size(); ++i) {
337  rows[i].set_representation(r);
338  }
339  PPL_ASSERT(OK());
340 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::set_sorted ( bool  b)
inline

Sets the sortedness flag of the system to b.

Definition at line 59 of file Linear_System_inlines.hh.

59  {
60  sorted = b;
61  PPL_ASSERT(OK());
62 }
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::set_space_dimension ( dimension_type  space_dim)
inline

Sets the space dimension of the rows in the system to space_dim .

Definition at line 365 of file Linear_System_inlines.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::Linear_System().

365  {
366  set_space_dimension_no_ok(space_dim);
367  PPL_ASSERT(OK());
368 }
void set_space_dimension_no_ok(dimension_type space_dim)
Sets the space dimension of the rows in the system to space_dim .
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::set_space_dimension_no_ok ( dimension_type  space_dim)
inlineprivate

Sets the space dimension of the rows in the system to space_dim .

This method is for internal use, it does *not* assert OK() at the end, so it can be used for invalid systems.

Definition at line 356 of file Linear_System_inlines.hh.

356  {
357  for (dimension_type i = rows.size(); i-- > 0; ) {
358  rows[i].set_space_dimension_no_ok(space_dim);
359  }
360  space_dimension_ = space_dim;
361 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Swapping_Vector< Row > rows
The vector that contains the rows.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::set_topology ( Topology  t)
inline

Sets the system topology to t .

Definition at line 249 of file Linear_System_inlines.hh.

249  {
250  if (topology() == t) {
251  return;
252  }
253  for (dimension_type i = num_rows(); i-- > 0; ) {
254  rows[i].set_topology(t);
255  }
256  row_topology = t;
257  PPL_ASSERT(OK());
258 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Topology topology() const
Returns the system topology.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::shift_space_dimensions ( Variable  v,
dimension_type  n 
)

Shift by n positions the coefficients of variables, starting from the coefficient of v. This increases the space dimension by n.

Definition at line 399 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::Variable::id().

399  {
400  // NOTE: v.id() may be equal to the space dimension of the system
401  // (when no space dimension need to be shifted).
402  PPL_ASSERT(v.id() <= space_dimension());
403  for (dimension_type i = rows.size(); i-- > 0; ) {
404  rows[i].shift_space_dimensions(v, n);
405  }
406  space_dimension_ += n;
407  PPL_ASSERT(OK());
408 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Swapping_Vector< Row > rows
The vector that contains the rows.
dimension_type space_dimension() const
Returns the space dimension of the rows in the system.
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::sign_normalize ( )

Sign-normalizes the system.

Definition at line 481 of file Linear_System_templates.hh.

481  {
482  const dimension_type nrows = rows.size();
483  // We sign-normalize also the pending rows.
484  for (dimension_type i = nrows; i-- > 0; ) {
485  rows[i].sign_normalize();
486  }
487  sorted = (nrows <= 1);
488  PPL_ASSERT(OK());
489 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::simplify ( )

Applies Gaussian elimination and back-substitution so as to simplify the linear system.

Definition at line 733 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::swap().

733  {
734  // This method is only applied to a system having no pending rows.
735  PPL_ASSERT(num_pending_rows() == 0);
736 
737  // Partially sort the linear system so that all lines/equalities come first.
738  const dimension_type old_nrows = num_rows();
739  dimension_type nrows = old_nrows;
740  dimension_type n_lines_or_equalities = 0;
741  for (dimension_type i = 0; i < nrows; ++i) {
742  if ((*this)[i].is_line_or_equality()) {
743  if (n_lines_or_equalities < i) {
744  swap(rows[i], rows[n_lines_or_equalities]);
745  // The system was not sorted.
746  PPL_ASSERT(!sorted);
747  }
748  ++n_lines_or_equalities;
749  }
750  }
751  // Apply Gaussian elimination to the subsystem of lines/equalities.
752  const dimension_type rank = gauss(n_lines_or_equalities);
753  // Eliminate any redundant line/equality that has been detected.
754  if (rank < n_lines_or_equalities) {
755  const dimension_type
756  n_rays_or_points_or_inequalities = nrows - n_lines_or_equalities;
757  const dimension_type
758  num_swaps = std::min(n_lines_or_equalities - rank,
759  n_rays_or_points_or_inequalities);
760  for (dimension_type i = num_swaps; i-- > 0; ) {
761  swap(rows[--nrows], rows[rank + i]);
762  }
763  remove_trailing_rows(old_nrows - nrows);
764  if (n_rays_or_points_or_inequalities > num_swaps) {
765  set_sorted(false);
766  }
768  n_lines_or_equalities = rank;
769  }
770  // Apply back-substitution to the system of rays/points/inequalities.
771  back_substitute(n_lines_or_equalities);
772 
773  PPL_ASSERT(OK());
774 }
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
size_t dimension_type
An unsigned integral type for representing space dimensions.
void back_substitute(dimension_type n_lines_or_equalities)
Back-substitutes the coefficients to reduce the complexity of the system.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
void unset_pending_rows()
Sets the index to indicate that the system has no pending rows.
void remove_trailing_rows(dimension_type n)
Makes the system shrink by removing its n trailing rows.
dimension_type gauss(dimension_type n_lines_or_equalities)
Minimizes the subsystem of equations contained in *this.
void set_sorted(bool b)
Sets the sortedness flag of the system to b.
bool OK() const
Checks if all the invariants are satisfied.
dimension_type num_pending_rows() const
Returns the number of rows that are in the pending part of the system.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::sort_and_remove_with_sat ( Bit_Matrix sat)

Sorts the system, removing duplicates, keeping the saturation matrix consistent.

Parameters
satBit matrix with rows corresponding to the rows of *this.

Definition at line 521 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::Implementation::indirect_sort_and_unique(), Parma_Polyhedra_Library::Bit_Matrix::num_rows(), Parma_Polyhedra_Library::Bit_Matrix::remove_trailing_rows(), and Parma_Polyhedra_Library::swap().

521  {
522  // We can only sort the non-pending part of the system.
523  PPL_ASSERT(first_pending_row() == sat.num_rows());
524  if (first_pending_row() <= 1) {
525  set_sorted(true);
526  return;
527  }
528 
529  const dimension_type num_elems = sat.num_rows();
530  // Build the function objects implementing indirect sort comparison,
531  // indirect unique comparison and indirect swap operation.
532  typedef Swapping_Vector<Row> Cont;
533  const Implementation::Indirect_Sort_Compare<Cont, Row_Less_Than>
534  sort_cmp(rows);
535  const Unique_Compare unique_cmp(rows);
536  const Implementation::Indirect_Swapper2<Cont, Bit_Matrix> swapper(rows, sat);
537 
538  const dimension_type num_duplicates
539  = Implementation::indirect_sort_and_unique(num_elems, sort_cmp,
540  unique_cmp, swapper);
541 
542  const dimension_type new_first_pending_row
543  = first_pending_row() - num_duplicates;
544 
545  if (num_pending_rows() > 0) {
546  // In this case, we must put the duplicates after the pending rows.
547  const dimension_type n_rows = num_rows() - 1;
548  for (dimension_type i = 0; i < num_duplicates; ++i) {
549  swap(rows[new_first_pending_row + i], rows[n_rows - i]);
550  }
551  }
552 
553  // Erasing the duplicated rows...
554  rows.resize(rows.size() - num_duplicates);
555  index_first_pending = new_first_pending_row;
556  // ... and the corresponding rows of the saturation matrix.
557  sat.remove_trailing_rows(num_duplicates);
558 
559  // Now the system is sorted.
560  sorted = true;
561 
562  PPL_ASSERT(OK());
563 }
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type first_pending_row() const
Returns the index of the first pending row.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
Sort_Comparer::size_type indirect_sort_and_unique(typename Sort_Comparer::size_type num_elems, Sort_Comparer sort_cmp, Unique_Comparer unique_cmp, Swapper indirect_swap)
void set_sorted(bool b)
Sets the sortedness flag of the system to b.
bool OK() const
Checks if all the invariants are satisfied.
dimension_type num_pending_rows() const
Returns the number of rows that are in the pending part of the system.
dimension_type index_first_pending
The index of the first pending row.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::sort_pending_and_remove_duplicates ( )

Sorts the pending rows and eliminates those that also occur in the non-pending part of the system.

Definition at line 851 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::cmp(), Parma_Polyhedra_Library::compare(), and Parma_Polyhedra_Library::swap().

851  {
852  PPL_ASSERT(num_pending_rows() > 0);
853  PPL_ASSERT(is_sorted());
854 
855  // The non-pending part of the system is already sorted.
856  // Now sorting the pending part..
857  const dimension_type first_pending = first_pending_row();
858  sort_rows(first_pending, num_rows());
859  // Recompute the number of rows, because we may have removed
860  // some rows occurring more than once in the pending part.
861  const dimension_type old_num_rows = num_rows();
862  dimension_type num_rows = old_num_rows;
863 
864  dimension_type k1 = 0;
865  dimension_type k2 = first_pending;
866  dimension_type num_duplicates = 0;
867  // In order to erase them, put at the end of the system
868  // those pending rows that also occur in the non-pending part.
869  while (k1 < first_pending && k2 < num_rows) {
870  const int cmp = compare(rows[k1], rows[k2]);
871  if (cmp == 0) {
872  // We found the same row.
873  ++num_duplicates;
874  --num_rows;
875  // By initial sortedness, we can increment index `k1'.
876  ++k1;
877  // Do not increment `k2'; instead, swap there the next pending row.
878  if (k2 < num_rows) {
879  swap(rows[k2], rows[k2 + num_duplicates]);
880  }
881  }
882  else if (cmp < 0) {
883  // By initial sortedness, we can increment `k1'.
884  ++k1;
885  }
886  else {
887  // Here `cmp > 0'.
888  // Increment `k2' and, if we already found any duplicate,
889  // swap the next pending row in position `k2'.
890  ++k2;
891  if (num_duplicates > 0 && k2 < num_rows) {
892  swap(rows[k2], rows[k2 + num_duplicates]);
893  }
894  }
895  }
896  // If needed, swap any duplicates found past the pending rows
897  // that has not been considered yet; then erase the duplicates.
898  if (num_duplicates > 0) {
899  if (k2 < num_rows) {
900  for (++k2; k2 < num_rows; ++k2) {
901  swap(rows[k2], rows[k2 + num_duplicates]);
902  }
903  }
904  rows.resize(num_rows);
905  }
906  sorted = true;
907  PPL_ASSERT(OK());
908 }
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type first_pending_row() const
Returns the index of the first pending row.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
bool is_sorted() const
Returns the value of the sortedness flag.
int compare(const Linear_Expression &x, const Linear_Expression &y)
int cmp(const GMP_Integer &x, const GMP_Integer &y)
void sort_rows()
Sorts the non-pending rows (in growing order) and eliminates duplicated ones.
bool OK() const
Checks if all the invariants are satisfied.
dimension_type num_pending_rows() const
Returns the number of rows that are in the pending part of the system.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::sort_rows ( )

Sorts the non-pending rows (in growing order) and eliminates duplicated ones.

Definition at line 412 of file Linear_System_templates.hh.

412  {
413  // We sort the non-pending rows only.
415  sorted = true;
416  PPL_ASSERT(OK());
417 }
dimension_type first_pending_row() const
Returns the index of the first pending row.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
void sort_rows()
Sorts the non-pending rows (in growing order) and eliminates duplicated ones.
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::sort_rows ( dimension_type  first_row,
dimension_type  last_row 
)

Sorts the rows (in growing order) form first_row to last_row and eliminates duplicated ones.

Definition at line 421 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::Implementation::indirect_sort_and_unique().

422  {
423  PPL_ASSERT(first_row <= last_row && last_row <= num_rows());
424  // We cannot mix pending and non-pending rows.
425  PPL_ASSERT(first_row >= first_pending_row()
426  || last_row <= first_pending_row());
427 
428  const bool sorting_pending = (first_row >= first_pending_row());
429  const dimension_type old_num_pending = num_pending_rows();
430 
431  const dimension_type num_elems = last_row - first_row;
432  if (num_elems < 2) {
433  return;
434  }
435 
436  // Build the function objects implementing indirect sort comparison,
437  // indirect unique comparison and indirect swap operation.
438  using namespace Implementation;
439  typedef Swapping_Vector<Row> Cont;
440  typedef Indirect_Sort_Compare<Cont, Row_Less_Than> Sort_Compare;
441  typedef Indirect_Swapper<Cont> Swapper;
442  const dimension_type num_duplicates
443  = indirect_sort_and_unique(num_elems,
444  Sort_Compare(rows, first_row),
445  Unique_Compare(rows, first_row),
446  Swapper(rows, first_row));
447 
448  if (num_duplicates > 0) {
449  typedef typename Cont::iterator Iter;
450  typedef typename std::iterator_traits<Iter>::difference_type diff_t;
451  Iter last = rows.begin() + static_cast<diff_t>(last_row);
452  Iter first = last - + static_cast<diff_t>(num_duplicates);
453  rows.erase(first, last);
454  }
455 
456  if (sorting_pending) {
457  PPL_ASSERT(old_num_pending >= num_duplicates);
458  index_first_pending = num_rows() - (old_num_pending - num_duplicates);
459  }
460  else {
461  index_first_pending = num_rows() - old_num_pending;
462  }
463 
464  PPL_ASSERT(OK());
465 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type first_pending_row() const
Returns the index of the first pending row.
Swapping_Vector< Row > rows
The vector that contains the rows.
Sort_Comparer::size_type indirect_sort_and_unique(typename Sort_Comparer::size_type num_elems, Sort_Comparer sort_cmp, Unique_Comparer unique_cmp, Swapper indirect_swap)
bool OK() const
Checks if all the invariants are satisfied.
dimension_type num_pending_rows() const
Returns the number of rows that are in the pending part of the system.
dimension_type index_first_pending
The index of the first pending row.
template<typename Row >
dimension_type Parma_Polyhedra_Library::Linear_System< Row >::space_dimension ( ) const
inline

Returns the space dimension of the rows in the system.

The computation of the space dimension correctly ignores the column encoding the inhomogeneous terms of constraint (resp., the divisors of generators); if the system topology is NOT_NECESSARILY_CLOSED, also the column of the $\epsilon$-dimension coefficients will be ignored.

Definition at line 350 of file Linear_System_inlines.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::insert_pending(), Parma_Polyhedra_Library::Linear_System< Row >::merge_rows_assign(), and Parma_Polyhedra_Library::Linear_System< Row >::operator==().

350  {
351  return space_dimension_;
352 }
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::strong_normalize ( )

Strongly normalizes the system.

Definition at line 469 of file Linear_System_templates.hh.

469  {
470  const dimension_type nrows = rows.size();
471  // We strongly normalize also the pending rows.
472  for (dimension_type i = nrows; i-- > 0; ) {
473  rows[i].strong_normalize();
474  }
475  sorted = (nrows <= 1);
476  PPL_ASSERT(OK());
477 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::swap_row_intervals ( dimension_type  first,
dimension_type  last,
dimension_type  offset 
)
inlineprivate

Swaps the [first,last) row interval with the [first + offset, last + offset) interval.

These intervals may not be disjunct.

Sorting of these intervals is *not* preserved.

Either both intervals contain only not-pending rows, or they both contain pending rows.

Definition at line 515 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::swap().

517  {
518  PPL_ASSERT(first <= last);
519  PPL_ASSERT(last + offset <= num_rows());
520 #ifndef NDEBUG
521  if (first < last) {
522  bool first_interval_has_pending_rows = (last > index_first_pending);
523  bool second_interval_has_pending_rows = (last + offset > index_first_pending);
524  bool first_interval_has_not_pending_rows = (first < index_first_pending);
525  bool second_interval_has_not_pending_rows = (first + offset < index_first_pending);
526  PPL_ASSERT(first_interval_has_not_pending_rows
527  == !first_interval_has_pending_rows);
528  PPL_ASSERT(second_interval_has_not_pending_rows
529  == !second_interval_has_pending_rows);
530  PPL_ASSERT(first_interval_has_pending_rows
531  == second_interval_has_pending_rows);
532  }
533 #endif
534  if (first + offset < last) {
535  // The intervals are not disjunct, make them so.
536  const dimension_type k = last - first - offset;
537  last -= k;
538  offset += k;
539  }
540 
541  if (first == last) {
542  // Nothing to do.
543  return;
544  }
545 
546  for (dimension_type i = first; i < last; ++i) {
547  swap(rows[i], rows[i + offset]);
548  }
549 
550  if (first < index_first_pending) {
551  // The swaps involved not pending rows, so they may not be sorted anymore.
552  set_sorted(false);
553  }
554 
555  PPL_ASSERT(OK());
556 }
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
size_t dimension_type
An unsigned integral type for representing space dimensions.
Swapping_Vector< Row > rows
The vector that contains the rows.
void set_sorted(bool b)
Sets the sortedness flag of the system to b.
bool OK() const
Checks if all the invariants are satisfied.
dimension_type index_first_pending
The index of the first pending row.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::swap_space_dimensions ( Variable  v1,
Variable  v2 
)
inline

Swaps the coefficients of the variables v1 and v2 .

Definition at line 670 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::Variable::space_dimension().

670  {
671  PPL_ASSERT(v1.space_dimension() <= space_dimension());
672  PPL_ASSERT(v2.space_dimension() <= space_dimension());
673  for (dimension_type k = num_rows(); k-- > 0; ) {
674  rows[k].swap_space_dimensions(v1, v2);
675  }
676  sorted = false;
677  PPL_ASSERT(OK());
678 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Swapping_Vector< Row > rows
The vector that contains the rows.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
dimension_type space_dimension() const
Returns the space dimension of the rows in the system.
bool OK() const
Checks if all the invariants are satisfied.
template<typename Row >
Topology Parma_Polyhedra_Library::Linear_System< Row >::topology ( ) const
inline

Returns the system topology.

Definition at line 322 of file Linear_System_inlines.hh.

322  {
323  return row_topology;
324 }
template<typename Row >
memory_size_type Parma_Polyhedra_Library::Linear_System< Row >::total_memory_in_bytes ( ) const
inline

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

Definition at line 42 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::external_memory_in_bytes().

42  {
43  return sizeof(*this) + external_memory_in_bytes();
44 }
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
template<typename Row >
void Parma_Polyhedra_Library::Linear_System< Row >::unset_pending_rows ( )
inline

Sets the index to indicate that the system has no pending rows.

Definition at line 107 of file Linear_System_inlines.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::Linear_System().

107  {
109  PPL_ASSERT(OK());
110 }
bool OK() const
Checks if all the invariants are satisfied.
dimension_type index_first_pending
The index of the first pending row.

Friends And Related Function Documentation

template<typename Row>
friend class Generator_System
friend

Definition at line 546 of file Linear_System_defs.hh.

template<typename Row >
bool operator!= ( const Linear_System< Row > &  x,
const Linear_System< Row > &  y 
)
related

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

template<typename Row >
bool operator!= ( const Linear_System< Row > &  x,
const Linear_System< Row > &  y 
)
related

Definition at line 683 of file Linear_System_inlines.hh.

683  {
684  return !(x == y);
685 }
template<typename Row >
bool operator== ( const Linear_System< Row > &  x,
const Linear_System< Row > &  y 
)
related

Definition at line 494 of file Linear_System_templates.hh.

References Parma_Polyhedra_Library::Linear_System< Row >::first_pending_row(), Parma_Polyhedra_Library::Linear_System< Row >::num_rows(), and Parma_Polyhedra_Library::Linear_System< Row >::space_dimension().

494  {
495  if (x.space_dimension() != y.space_dimension()) {
496  return false;
497  }
498  const dimension_type x_num_rows = x.num_rows();
499  const dimension_type y_num_rows = y.num_rows();
500  if (x_num_rows != y_num_rows) {
501  return false;
502  }
503  if (x.first_pending_row() != y.first_pending_row()) {
504  return false;
505  }
506  // TODO: Check if the following comment is up to date.
507  // Notice that calling operator==(const Swapping_Vector<Row>&,
508  // const Swapping_Vector<Row>&)
509  // would be wrong here, as equality of the type fields would
510  // not be checked.
511  for (dimension_type i = x_num_rows; i-- > 0; ) {
512  if (x[i] != y[i]) {
513  return false;
514  }
515  }
516  return true;
517 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
template<typename Row >
bool operator== ( const Linear_System< Row > &  x,
const Linear_System< Row > &  y 
)
related

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

template<typename Row>
friend class Polyhedron
friend

Definition at line 545 of file Linear_System_defs.hh.

template<typename Row >
void swap ( Parma_Polyhedra_Library::Linear_System< Row > &  x,
Parma_Polyhedra_Library::Linear_System< Row > &  y 
)
related
template<typename Row >
void swap ( Linear_System< Row > &  x,
Linear_System< Row > &  y 
)
related

Definition at line 712 of file Linear_System_inlines.hh.

References Parma_Polyhedra_Library::Linear_System< Row >::m_swap().

712  {
713  x.m_swap(y);
714 }

Member Data Documentation

template<typename Row>
dimension_type Parma_Polyhedra_Library::Linear_System< Row >::index_first_pending
private

The index of the first pending row.

Definition at line 518 of file Linear_System_defs.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::m_swap().

template<typename Row>
Representation Parma_Polyhedra_Library::Linear_System< Row >::representation_
private
template<typename Row>
Topology Parma_Polyhedra_Library::Linear_System< Row >::row_topology
private

The topological kind of the rows in the system. All rows must have this topology.

Definition at line 515 of file Linear_System_defs.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::m_swap().

template<typename Row>
Swapping_Vector<Row> Parma_Polyhedra_Library::Linear_System< Row >::rows

The vector that contains the rows.

Note
This is public for convenience. Clients that modify if must preserve the class invariant.

Definition at line 452 of file Linear_System_defs.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::insert_pending(), Parma_Polyhedra_Library::Linear_System< Row >::Linear_System(), Parma_Polyhedra_Library::Linear_System< Row >::m_swap(), and Parma_Polyhedra_Library::Linear_System< Row >::merge_rows_assign().

template<typename Row>
bool Parma_Polyhedra_Library::Linear_System< Row >::sorted
private

true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.

Definition at line 525 of file Linear_System_defs.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::Linear_System(), and Parma_Polyhedra_Library::Linear_System< Row >::m_swap().

template<typename Row>
dimension_type Parma_Polyhedra_Library::Linear_System< Row >::space_dimension_
private

The space dimension of each row. All rows must have this number of space dimensions.

Definition at line 511 of file Linear_System_defs.hh.

Referenced by Parma_Polyhedra_Library::Linear_System< Row >::m_swap().


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