PPL  1.2
Constraint_System_defs.hh
Go to the documentation of this file.
1 /* Constraint_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_Constraint_System_defs_hh
25 #define PPL_Constraint_System_defs_hh 1
26 
28 
29 #include "Linear_System_defs.hh"
30 #include "Constraint_defs.hh"
31 
33 #include "Generator_types.hh"
34 #include "Constraint_types.hh"
36 #include "Polyhedron_types.hh"
37 #include "termination_types.hh"
38 #include <iterator>
39 #include <iosfwd>
40 #include <cstddef>
41 
42 namespace Parma_Polyhedra_Library {
43 
44 namespace IO_Operators {
45 
47 
52 std::ostream& operator<<(std::ostream& s, const Constraint_System& cs);
53 
54 } // namespace IO_Operators
55 
56 // TODO: Consider removing this.
57 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
58 
60 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
61 bool operator==(const Constraint_System& x, const Constraint_System& y);
62 
63 // TODO: Consider removing this.
64 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
65 
67 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
68 bool operator!=(const Constraint_System& x, const Constraint_System& y);
69 
71 void
72 swap(Constraint_System& x, Constraint_System& y);
73 
74 } // namespace Parma_Polyhedra_Library
75 
77 
138 public:
140 
142 
144  explicit Constraint_System(Representation r = default_representation);
145 
147  explicit Constraint_System(const Constraint& c,
148  Representation r = default_representation);
149 
151  explicit Constraint_System(const Congruence_System& cgs,
152  Representation r = default_representation);
153 
155 
160 
163 
166 
169 
172 
175 
178 
181 
183  void set_space_dimension(dimension_type space_dim);
184 
189  bool has_equalities() const;
190 
195  bool has_strict_inequalities() const;
196 
201  void insert(const Constraint& c);
202 
204  static void initialize();
205 
207  static void finalize();
208 
212  static const Constraint_System& zero_dim_empty();
213 
215 
217  bool empty() const;
218 
223  void clear();
224 
230  const_iterator begin() const;
231 
233  const_iterator end() const;
234 
236  bool OK() const;
237 
239 
245  bool ascii_load(std::istream& s);
246 
249 
252 
254  void m_swap(Constraint_System& y);
255 
256 private:
258 
264 
266 
267  friend bool operator==(const Constraint_System& x,
268  const Constraint_System& y);
269 
271  explicit Constraint_System(Topology topol,
272  Representation r = default_representation);
273 
279  Constraint_System(Topology topol, dimension_type space_dim,
280  Representation r = default_representation);
281 
284 
287 
294  void simplify();
295 
304  dimension_type new_space_dim);
305 
307  const Constraint& operator[](dimension_type k) const;
308 
310  bool satisfies_all_constraints(const Generator& g) const;
311 
313 
347  void affine_preimage(Variable v,
348  const Linear_Expression& expr,
349  Coefficient_traits::const_reference denominator);
350 
356  void insert_pending(const Constraint& c);
357 
360 
362  Topology topology() const;
363 
364  dimension_type num_rows() const;
365 
370  bool is_necessarily_closed() const;
371 
374 
377 
379  bool is_sorted() const;
380 
382  void unset_pending_rows();
383 
386 
388  void set_sorted(bool b);
389 
391 
398  void remove_row(dimension_type i, bool keep_sorted = false);
399 
402 
406  void remove_rows(const std::vector<dimension_type>& indexes);
407 
409 
416  void remove_rows(dimension_type first, dimension_type last,
417  bool keep_sorted = false);
418 
421 
423 
428  void remove_space_dimensions(const Variables_Set& vars);
429 
433 
435  /*
436  \param cycle
437  A vector representing a cycle of the permutation according to which the
438  columns must be rearranged.
439 
440  The \p cycle vector represents a cycle of a permutation of space
441  dimensions.
442  For example, the permutation
443  \f$ \{ x_1 \mapsto x_2, x_2 \mapsto x_3, x_3 \mapsto x_1 \}\f$ can be
444  represented by the vector containing \f$ x_1, x_2, x_3 \f$.
445  */
446  void permute_space_dimensions(const std::vector<Variable>& cycle);
447 
450 
451  bool has_no_rows() const;
452 
454  void strong_normalize();
455 
460  void sort_rows();
461 
467 
471 
476  void insert(Constraint& r, Recycle_Input);
477 
479 
483 
485  void insert_pending(const Constraint_System& r);
486 
495  void merge_rows_assign(const Constraint_System& y);
496 
498 
501  void insert(const Constraint_System& y);
502 
504 
509 
511 
516 
518 
529  dimension_type gauss(dimension_type n_lines_or_equalities);
530 
541  void back_substitute(dimension_type n_lines_or_equalities);
542 
544  void assign_with_pending(const Constraint_System& y);
545 
551 
560 
565  bool check_sorted() const;
566 
572 
574 
587 
588  friend class Polyhedron;
589  friend class Termination_Helpers;
590 };
591 
593 
607 // NOTE: This is not an inner class of Constraint_System, so Constraint can
608 // declare that this class is his friend without including this file
609 // (the .types.hh file suffices).
611  : public std::iterator<std::forward_iterator_tag,
612  Constraint,
613  std::ptrdiff_t,
614  const Constraint*,
615  const Constraint&> {
616 public:
619 
622 
625 
629 
631  const Constraint& operator*() const;
632 
634  const Constraint* operator->() const;
635 
638 
641 
646  bool operator==(const Constraint_System_const_iterator& y) const;
647 
652  bool operator!=(const Constraint_System_const_iterator& y) const;
653 
654 private:
655  friend class Constraint_System;
656 
659 
662 
665  ::const_iterator& iter,
666  const Constraint_System& cs);
667 
669  void skip_forward();
670 };
671 
672 namespace Parma_Polyhedra_Library {
673 
674 namespace Implementation {
675 
676 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
677 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
681 
682 } // namespace Implementation
683 
684 } // namespace Parma_Polyhedra_Library
685 
686 // Constraint_System_inlines.hh is not included here on purpose.
687 
688 #endif // !defined(PPL_Constraint_System_defs_hh)
void m_swap(Constraint_System &y)
Swaps *this with y.
bool operator!=(const Box< ITV > &x, const Box< ITV > &y)
Definition: Box_inlines.hh:264
void shift_space_dimensions(Variable v, dimension_type n)
A linear equality or inequality.
memory_size_type total_memory_in_bytes() const
Returns the total size in bytes of the memory occupied by *this.
void swap(CO_Tree &x, CO_Tree &y)
void insert_pending(const Constraint &c)
Inserts in *this a copy of the constraint c, increasing the number of space dimensions if needed...
void set_representation(Representation r)
Converts *this to the specified representation.
The base class for systems of constraints and generators.
bool check_sorted() const
Returns true if and only if *this is sorted, without checking for duplicates.
size_t dimension_type
An unsigned integral type for representing space dimensions.
void set_space_dimension(dimension_type space_dim)
Sets the space dimension of the rows in the system to space_dim .
An std::set of variables' indexes.
bool operator!=(const Constraint_System_const_iterator &y) const
Returns true if and only if *this and y are different.
A line, ray, point or closure point.
void simplify()
Applies Gaussian elimination and back-substitution so as to provide a partial simplification of the s...
bool is_necessarily_closed() const
Returns true if and only if the system topology is NECESSARILY_CLOSED.
void merge_rows_assign(const Constraint_System &y)
Assigns to *this the result of merging its rows with those of y, obtaining a sorted system...
void assign_with_pending(const Constraint_System &y)
Full assignment operator: pending rows are copied as pending.
const Constraint * operator->() const
Indirect member selector.
dimension_type first_pending_row() const
Returns the index of the first pending row.
std::ostream & operator<<(std::ostream &s, const Ask_Tell< D > &x)
static const Constraint_System & zero_dim_empty()
Returns the singleton system containing only Constraint::zero_dim_false().
void insert(const Constraint &c)
Inserts in *this a copy of the constraint c, increasing the number of space dimensions if needed...
dimension_type num_constraints(const Constraint_System &cs)
Helper returning number of constraints in system.
Linear_System< Constraint >::const_iterator i
The const iterator over the matrix of constraints.
void add_universe_rows_and_space_dimensions(dimension_type n)
Adds n rows and space dimensions to the system.
dimension_type num_pending_rows() const
Returns the number of rows that are in the pending part of the system.
bool is_sorted() const
Returns the value of the sortedness flag.
Representation representation() const
Returns the current representation of *this.
Topology topology() const
Returns the system topology.
void clear()
Removes all the constraints from the constraint system and sets its space dimension to 0...
const_iterator begin() const
Returns the const_iterator pointing to the first constraint, if *this is not empty; otherwise...
const Linear_System< Constraint > * csp
A const pointer to the matrix of constraints.
void mark_as_not_necessarily_closed()
Marks the last dimension as the epsilon dimension.
bool operator==(const Constraint_System_const_iterator &y) const
Returns true if and only if *this and y are identical.
A dimension of the vector space.
Constraint_System_const_iterator & operator=(const Constraint_System_const_iterator &y)
Assignment operator.
The base class for convex polyhedra.
void remove_row(dimension_type i, bool keep_sorted=false)
Makes the system shrink by removing its i-th row.
#define PPL_OUTPUT_DECLARATIONS
void skip_forward()
*this skips to the next non-trivial constraint.
void permute_space_dimensions(const std::vector< Variable > &cycle)
Permutes the space dimensions of the matrix.
dimension_type num_equalities() const
Returns the number of equality constraints.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
bool ascii_load(std::istream &s)
Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this ...
bool empty() const
Returns true if and only if *this has no constraints.
bool OK() const
Checks if all the invariants are satisfied.
const_iterator end() const
Returns the past-the-end const_iterator.
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
dimension_type num_lines_or_equalities() const
Returns the number of rows in the system that represent either lines or equalities.
void sort_and_remove_with_sat(Bit_Matrix &sat)
Sorts the system, removing duplicates, keeping the saturation matrix consistent.
static const Constraint_System * zero_dim_empty_p
Holds (between class initialization and finalization) a pointer to the singleton system containing on...
const Constraint & operator[](dimension_type k) const
Returns a constant reference to the k- th constraint of the system.
Swapping_Vector< Row >::const_iterator const_iterator
bool has_equalities() const
Returns true if and only if *this contains one or more equality constraints.
void sort_rows()
Sorts the non-pending rows (in growing order) and eliminates duplicated ones.
Constraint_System_const_iterator & operator++()
Prefix increment operator.
static dimension_type max_space_dimension()
Returns the maximum space dimension a Constraint_System can handle.
void remove_rows(const std::vector< dimension_type > &indexes)
The entire library is confined to this namespace.
Definition: version.hh:61
void remove_trailing_rows(dimension_type n)
Makes the system shrink by removing its n trailing rows.
void remove_space_dimensions(const Variables_Set &vars)
Removes all the specified dimensions from the constraint system.
void strong_normalize()
Strongly normalizes the system.
Constraint_System(Representation r=default_representation)
Default constructor: builds an empty system of constraints.
void unset_pending_rows()
Sets the index to indicate that the system has no pending rows.
void affine_preimage(Variable v, const Linear_Expression &expr, Coefficient_traits::const_reference denominator)
Substitutes a given column of coefficients by a given affine expression.
void add_low_level_constraints()
Adds low-level constraints to the constraint system.
Sparse representation: only the nonzero coefficient are stored. If there are many nonzero coefficient...
static void finalize()
Finalizes the class.
bool operator==(const Box< ITV > &x, const Box< ITV > &y)
dimension_type num_inequalities() const
Returns the number of inequality constraints.
const Constraint & operator*() const
Dereference operator.
void set_sorted(bool b)
Sets the sortedness flag of the system to b.
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
Coefficient c
Definition: PIP_Tree.cc:64
Constraint_System & operator=(const Constraint_System &y)
Assignment operator.
void sort_pending_and_remove_duplicates()
Sorts the pending rows and eliminates those that also occur in the non-pending part of the system...
friend bool operator==(const Constraint_System &x, const Constraint_System &y)
void back_substitute(dimension_type n_lines_or_equalities)
Back-substitutes the coefficients to reduce the complexity of the system.
static void initialize()
Initializes the class.
void set_index_first_pending_row(dimension_type i)
Sets the index of the first pending row to i.
void swap_space_dimensions(Variable v1, Variable v2)
Swaps the coefficients of the variables v1 and v2 .
bool adjust_topology_and_space_dimension(Topology new_topology, dimension_type new_space_dim)
Adjusts *this so that it matches new_topology and new_space_dim (adding or removing columns if needed...
void mark_as_necessarily_closed()
Marks the epsilon dimension as a standard dimension.
dimension_type gauss(dimension_type n_lines_or_equalities)
Minimizes the subsystem of equations contained in *this.
Topology
Kinds of polyhedra domains.
Constraint_System_const_iterator const_iterator
bool satisfies_all_constraints(const Generator &g) const
Returns true if g satisfies all the constraints.
bool has_strict_inequalities() const
Returns true if and only if *this contains one or more strict inequality constraints.