PPL  1.2
Linear_System_defs.hh
Go to the documentation of this file.
1 /* Linear_System class declaration.
2  Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3  Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_Linear_System_defs_hh
25 #define PPL_Linear_System_defs_hh 1
26 
27 #include "Linear_System_types.hh"
28 
29 #include "Swapping_Vector_defs.hh"
30 #include "globals_defs.hh"
31 #include "Variable_defs.hh"
32 #include "Variables_Set_defs.hh"
33 
34 #include "Polyhedron_types.hh"
35 #include "Bit_Row_types.hh"
36 #include "Bit_Matrix_types.hh"
38 #include "Topology_types.hh"
39 
40 // TODO: Check how much of this description is still true.
41 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
42 
59 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
60 template <typename Row>
62 public:
63 
64  // NOTE: `iterator' is actually a const_iterator.
67 
69 
73 
75 
89 
90 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
91 
97 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
98  struct With_Pending {
99  };
100 
102  Linear_System(const Linear_System& y);
103 
107 
110 
113 
116 
118  void assign_with_pending(const Linear_System& y);
119 
121  void m_swap(Linear_System& y);
122 
125 
128 
131 
133 
142 
144  void set_space_dimension(dimension_type space_dim);
145 
148 
150 
157  void remove_row(dimension_type i, bool keep_sorted = false);
158 
160 
167  void remove_rows(dimension_type first, dimension_type last,
168  bool keep_sorted = false);
169 
170  // TODO: Consider removing this.
173 
177  void remove_rows(const std::vector<dimension_type>& indexes);
178 
179  // TODO: Consider making this private.
181 
186  void remove_space_dimensions(const Variables_Set& vars);
187 
191 
192  // TODO: Consider making this private.
194  /*
195  \param cycle
196  A vector representing a cycle of the permutation according to which the
197  space dimensions must be rearranged.
198 
199  The \p cycle vector represents a cycle of a permutation of space
200  dimensions.
201  For example, the permutation
202  \f$ \{ x_1 \mapsto x_2, x_2 \mapsto x_3, x_3 \mapsto x_1 \}\f$ can be
203  represented by the vector containing \f$ x_1, x_2, x_3 \f$.
204  */
205  void permute_space_dimensions(const std::vector<Variable>& cycle);
206 
209 
211 
212  const Row& operator[](dimension_type k) const;
215 
216  iterator begin();
217  iterator end();
218  const_iterator begin() const;
219  const_iterator end() const;
220 
221  bool has_no_rows() const;
222  dimension_type num_rows() const;
223 
225  void strong_normalize();
226 
228  void sign_normalize();
229 
231 
232  Topology topology() const;
234 
236  bool is_sorted() const;
237 
242  bool is_necessarily_closed() const;
243 
249 
252 
256 
261  bool check_sorted() const;
262 
264  void set_topology(Topology t);
265 
267  void set_necessarily_closed();
268 
271 
272  // TODO: Consider removing this, or making it private.
274 
279 
280  // TODO: Consider removing this, or making it private.
282 
287 
289  void unset_pending_rows();
290 
293 
295  void set_sorted(bool b);
296 
298 
311 
316  void insert(const Row& r);
317 
322  void insert_pending(const Row& r);
323 
328  void insert(Row& r, Recycle_Input);
329 
334  void insert_pending(Row& r, Recycle_Input);
335 
337 
340  void insert(const Linear_System& y);
341 
343  void insert_pending(const Linear_System& r);
344 
346 
350 
354 
359  void sort_rows();
360 
365  void sort_rows(dimension_type first_row, dimension_type last_row);
366 
375  void merge_rows_assign(const Linear_System& y);
376 
382 
391 
393 
404  dimension_type gauss(dimension_type n_lines_or_equalities);
405 
416  void back_substitute(dimension_type n_lines_or_equalities);
417 
422  void simplify();
423 
425  void clear();
426 
428 
439  bool ascii_load(std::istream& s);
440 
443 
446 
448 
453 
455  bool OK() const;
456 
457 private:
459 
469  void remove_row_no_ok(dimension_type i, bool keep_sorted = false);
470 
478  void insert_pending_no_ok(Row& r, Recycle_Input);
479 
487  void insert_no_ok(Row& r, Recycle_Input);
488 
490 
495 
498 
507  dimension_type offset);
508 
512 
516 
519 
525  bool sorted;
526 
528 
530  struct Row_Less_Than {
531  bool operator()(const Row& x, const Row& y) const;
532  };
533 
535  struct Unique_Compare {
537  dimension_type base = 0);
538 
539  bool operator()(dimension_type i, dimension_type j) const;
540 
543  };
544 
545  friend class Polyhedron;
546  friend class Generator_System;
547 };
548 
549 namespace Parma_Polyhedra_Library {
550 
551 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
552 
554 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
555 template <typename Row>
558 
559 } // namespace std
560 
561 namespace Parma_Polyhedra_Library {
562 
563 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
564 
566 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
567 template <typename Row>
568 bool operator==(const Linear_System<Row>& x, const Linear_System<Row>& y);
569 
570 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
571 
573 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
574 template <typename Row>
575 bool operator!=(const Linear_System<Row>& x, const Linear_System<Row>& y);
576 
577 } // namespace Parma_Polyhedra_Library
578 
579 #include "Linear_System_inlines.hh"
581 
582 #endif // !defined(PPL_Linear_System_defs_hh)
Comparison predicate (used when implementing the unique algorithm).
bool operator!=(const Box< ITV > &x, const Box< ITV > &y)
Definition: Box_inlines.hh:264
void swap(CO_Tree &x, CO_Tree &y)
The base class for systems of constraints and generators.
Representation representation() const
Returns the current representation of *this.
size_t dimension_type
An unsigned integral type for representing space dimensions.
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...
An std::set of variables' indexes.
void set_index_first_pending_row(dimension_type i)
Sets the index of the first pending row to i.
void sort_pending_and_remove_duplicates()
Sorts the pending rows and eliminates those that also occur in the non-pending part of the system...
bool ascii_load(std::istream &s)
Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this ...
void set_not_necessarily_closed()
Sets the system topology to NOT_NECESSARILY_CLOSED.
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 ...
Topology topology() const
Returns the system topology.
dimension_type num_lines_or_equalities() const
Returns the number of rows in the system that represent either lines or equalities.
void strong_normalize()
Strongly normalizes the system.
memory_size_type total_memory_in_bytes() const
Returns the total size in bytes of the memory occupied by *this.
bool is_necessarily_closed() const
Returns true if and only if the system topology is NECESSARILY_CLOSED.
void mark_as_not_necessarily_closed()
Marks the last dimension as the epsilon dimension.
void set_space_dimension(dimension_type space_dim)
Sets the space dimension of the rows in the system to space_dim .
const Row & operator[](dimension_type k) const
Returns a const reference to the k-th row of the system.
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.
void sort_and_remove_with_sat(Bit_Matrix &sat)
Sorts the system, removing duplicates, keeping the saturation matrix consistent.
void back_substitute(dimension_type n_lines_or_equalities)
Back-substitutes the coefficients to reduce the complexity of the system.
Linear_System & operator=(const Linear_System &y)
Assignment operator: pending rows are transformed into non-pending ones.
void clear()
Clears the system deallocating all its rows.
Swapping_Vector< Row > rows
The vector that contains the rows.
void permute_space_dimensions(const std::vector< Variable > &cycle)
Permutes the space dimensions of the matrix.
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...
void remove_row(dimension_type i, bool keep_sorted=false)
Makes the system shrink by removing its i-th row.
void mark_as_necessarily_closed()
Marks the epsilon dimension as a standard dimension.
void set_necessarily_closed()
Sets the system topology to NECESSARILY_CLOSED.
A dimension of the vector space.
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.
The base class for convex polyhedra.
void unset_pending_rows()
Sets the index to indicate that the system has no pending rows.
#define PPL_OUTPUT_DECLARATIONS
Swapping_Vector< Row >::const_iterator iterator
void m_swap(Linear_System &y)
Swaps *this with y.
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
void add_universe_rows_and_space_dimensions(dimension_type n)
Adds n rows and space dimensions to the system.
void set_space_dimension_no_ok(dimension_type space_dim)
Sets the space dimension of the rows in the system to space_dim .
bool is_sorted() const
Returns the value of the sortedness flag.
Swapping_Vector< Row >::const_iterator const_iterator
void simplify()
Applies Gaussian elimination and back-substitution so as to simplify the linear system.
void remove_row_no_ok(dimension_type i, bool keep_sorted=false)
Makes the system shrink by removing its i-th row.
void shift_space_dimensions(Variable v, dimension_type n)
void remove_rows(dimension_type first, dimension_type last, bool keep_sorted=false)
Makes the system shrink by removing the rows in [first,last).
void insert(const Row &r)
Adds a copy of r to the system, automatically resizing the system or the row's copy, if needed.
The entire library is confined to this namespace.
Definition: version.hh:61
void sign_normalize()
Sign-normalizes the system.
void assign_with_pending(const Linear_System &y)
Full assignment operator: pending rows are copied as pending.
void swap_space_dimensions(Variable v1, Variable v2)
Swaps the coefficients of the variables v1 and v2 .
void swap_row_intervals(dimension_type first, dimension_type last, dimension_type offset)
Linear_System(Topology topol, Representation r)
Builds an empty linear system with specified topology.
static dimension_type max_space_dimension()
Returns the maximum space dimension a Linear_System can handle.
void remove_trailing_rows(dimension_type n)
Makes the system shrink by removing its n trailing rows.
bool operator==(const Box< ITV > &x, const Box< ITV > &y)
dimension_type gauss(dimension_type n_lines_or_equalities)
Minimizes the subsystem of equations contained in *this.
void set_representation(Representation r)
Converts *this to the specified representation.
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
dimension_type space_dimension() const
Returns the space dimension of the rows in the system.
void sort_rows()
Sorts the non-pending rows (in growing order) and eliminates duplicated ones.
bool operator()(dimension_type i, dimension_type j) const
void set_sorted(bool b)
Sets the sortedness flag of the system to b.
bool OK() const
Checks if all the invariants are satisfied.
void remove_space_dimensions(const Variables_Set &vars)
Removes all the specified dimensions from the system.
void insert_no_ok(Row &r, Recycle_Input)
Adds r to the system, stealing its contents and automatically resizing the system or the row...
Ordering predicate (used when implementing the sort algorithm).
void set_topology(Topology t)
Sets the system topology to t .
dimension_type num_pending_rows() const
Returns the number of rows that are in the pending part of the system.
bool operator()(const Row &x, const Row &y) const
Unique_Compare(const Swapping_Vector< Row > &cont, dimension_type base=0)
Topology
Kinds of polyhedra domains.
dimension_type index_first_pending
The index of the first pending row.