PPL  1.2
Constraint_defs.hh
Go to the documentation of this file.
1 /* Constraint 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_defs_hh
25 #define PPL_Constraint_defs_hh 1
26 
27 #include "Constraint_types.hh"
28 
29 #include "Congruence_types.hh"
30 #include "Variables_Set_types.hh"
31 #include "Polyhedron_types.hh"
32 #include "termination_types.hh"
33 #include "Octagonal_Shape_types.hh"
34 #include "Grid_types.hh"
35 
37 #include "Variable_defs.hh"
38 #include "Topology_types.hh"
40 
41 #include <iosfwd>
42 
43 namespace Parma_Polyhedra_Library {
44 
46 
47 Constraint
48 operator<(const Linear_Expression& e1, const Linear_Expression& e2);
49 
51 
52 Constraint
53 operator<(Variable v1, Variable v2);
54 
56 
57 Constraint
58 operator<(const Linear_Expression& e, Coefficient_traits::const_reference n);
59 
61 
62 Constraint
63 operator<(Coefficient_traits::const_reference n, const Linear_Expression& e);
64 
66 
67 Constraint
68 operator>(const Linear_Expression& e1, const Linear_Expression& e2);
69 
71 
72 Constraint
73 operator>(Variable v1, Variable v2);
74 
76 
77 Constraint
78 operator>(const Linear_Expression& e, Coefficient_traits::const_reference n);
79 
81 
82 Constraint
83 operator>(Coefficient_traits::const_reference n, const Linear_Expression& e);
84 
86 
87 Constraint
88 operator==(const Linear_Expression& e1, const Linear_Expression& e2);
89 
91 
92 Constraint
93 operator==(Variable v1, Variable v2);
94 
96 
97 Constraint
98 operator==(const Linear_Expression& e, Coefficient_traits::const_reference n);
99 
101 
102 Constraint
103 operator==(Coefficient_traits::const_reference n, const Linear_Expression& e);
104 
106 
107 Constraint
108 operator<=(const Linear_Expression& e1, const Linear_Expression& e2);
109 
111 
112 Constraint
113 operator<=(Variable v1, Variable v2);
114 
116 
117 Constraint
118 operator<=(const Linear_Expression& e, Coefficient_traits::const_reference n);
119 
121 
122 Constraint
123 operator<=(Coefficient_traits::const_reference n, const Linear_Expression& e);
124 
126 
127 Constraint
128 operator>=(const Linear_Expression& e1, const Linear_Expression& e2);
129 
131 
132 Constraint
133 operator>=(Variable v1, Variable v2);
134 
136 
137 Constraint
138 operator>=(const Linear_Expression& e, Coefficient_traits::const_reference n);
139 
141 
142 Constraint
143 operator>=(Coefficient_traits::const_reference n, const Linear_Expression& e);
144 
145 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
146 
181 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
182 int compare(const Constraint& x, const Constraint& y);
183 
184 }
185 
187 
285 public:
286 
288  enum Type {
295  };
296 
298 
304 
306  explicit Constraint(Representation r = default_representation);
307 
309 
313  Constraint(const Constraint& c);
314 
316 
320  Constraint(const Constraint& c, dimension_type space_dim);
321 
324 
326  Constraint(const Constraint& c, dimension_type space_dim,
327  Representation r);
328 
330 
334  explicit Constraint(const Congruence& cg,
335  Representation r = default_representation);
336 
338  ~Constraint();
339 
342 
345 
347  Constraint& operator=(const Constraint& c);
348 
351 
354 
357  void set_space_dimension(dimension_type space_dim);
358 
361 
363 
371  bool remove_space_dimensions(const Variables_Set& vars);
372 
374  /*
375  \param cycle
376  A vector representing a cycle of the permutation according to which the
377  space dimensions must be rearranged.
378 
379  The \p cycle vector represents a cycle of a permutation of space
380  dimensions.
381  For example, the permutation
382  \f$ \{ x_1 \mapsto x_2, x_2 \mapsto x_3, x_3 \mapsto x_1 \}\f$ can be
383  represented by the vector containing \f$ x_1, x_2, x_3 \f$.
384  */
385  void permute_space_dimensions(const std::vector<Variable>& cycle);
386 
390 
392  Type type() const;
393 
398  bool is_equality() const;
399 
404  bool is_inequality() const;
405 
410  bool is_nonstrict_inequality() const;
411 
416  bool is_strict_inequality() const;
417 
419 
423  Coefficient_traits::const_reference coefficient(Variable v) const;
424 
426  Coefficient_traits::const_reference inhomogeneous_term() const;
427 
429  static void initialize();
430 
432  static void finalize();
433 
435  static const Constraint& zero_dim_false();
436 
441  static const Constraint& zero_dim_positivity();
442 
448 
451 
463  bool is_tautological() const;
464 
477  bool is_inconsistent() const;
478 
487  bool is_equivalent_to(const Constraint& y) const;
488 
490 
494  bool is_equal_to(const Constraint& y) const;
495 
497  bool OK() const;
498 
500 
506  bool ascii_load(std::istream& s);
507 
509  void m_swap(Constraint& y);
510 
512  static const Constraint& epsilon_geq_zero();
513 
518  static const Constraint& epsilon_leq_one();
519 
523  expr_type expression() const;
524 
525 private:
526 
528  enum Kind {
531  };
532 
534 
536 
538 
544 
551 
557 
564 
567  Representation r = default_representation);
568 
576 
584 
589  bool is_line_or_equality() const;
590 
595  bool is_ray_or_point_or_inequality() const;
596 
599 
602 
604 
605  Topology topology() const;
607 
612  bool is_not_necessarily_closed() const;
613 
618  bool is_necessarily_closed() const;
620 
622 
623 
624  // TODO: Consider setting the epsilon dimension in this method.
626  void set_topology(Topology x);
627 
629  void set_necessarily_closed();
630 
634 
638 
643 
648  void
649  throw_invalid_argument(const char* method, const char* message) const;
650 
655  void
656  throw_dimension_incompatible(const char* method,
657  const char* name_var,
658  Variable v) const;
659 
661  Coefficient_traits::const_reference epsilon_coefficient() const;
662 
664  void set_epsilon_coefficient(Coefficient_traits::const_reference n);
665 
667 
672 
674 
679 
681  void set_is_equality();
682 
684 
689  void set_is_inequality();
690 
692 
703  void linear_combine(const Constraint& y, dimension_type i);
704 
709  void sign_normalize();
710 
717  void strong_normalize();
718 
723  bool check_strong_normalized() const;
724 
730 
731  friend int
732  compare(const Constraint& x, const Constraint& y);
733 
734  friend class Linear_System<Constraint>;
735  friend class Constraint_System;
736  friend class Polyhedron;
737  friend class Scalar_Products;
739  friend class Termination_Helpers;
740  friend class Grid;
741  template <typename T>
742  friend class Octagonal_Shape;
743 
744  friend Constraint
745  operator<(const Linear_Expression& e1, const Linear_Expression& e2);
746 
747  friend Constraint
748  operator<(Variable v1, Variable v2);
749 
750  friend Constraint
751  operator<(const Linear_Expression& e, Coefficient_traits::const_reference n);
752 
753  friend Constraint
754  operator<(Coefficient_traits::const_reference n, const Linear_Expression& e);
755 
756  friend Constraint
757  operator>(const Linear_Expression& e1, const Linear_Expression& e2);
758 
759  friend Constraint
760  operator>(Variable v1, Variable v2);
761 
762  friend Constraint
763  operator>(const Linear_Expression& e, Coefficient_traits::const_reference n);
764 
765  friend Constraint
766  operator>(Coefficient_traits::const_reference n, const Linear_Expression& e);
767 
768  friend Constraint
769  operator==(const Linear_Expression& e1, const Linear_Expression& e2);
770 
771  friend Constraint
772  operator==(Variable v1, Variable v2);
773 
774  friend Constraint
775  operator==(const Linear_Expression& e, Coefficient_traits::const_reference n);
776 
777  friend Constraint
778  operator==(Coefficient_traits::const_reference n, const Linear_Expression& e);
779 
780  friend Constraint
781  operator<=(const Linear_Expression& e1, const Linear_Expression& e2);
782 
783  friend Constraint
784  operator<=(Variable v1, Variable v2);
785 
786  friend Constraint
787  operator<=(const Linear_Expression& e, Coefficient_traits::const_reference n);
788 
789  friend Constraint
790  operator<=(Coefficient_traits::const_reference n, const Linear_Expression& e);
791 
792  friend Constraint
793  operator>=(const Linear_Expression& e1, const Linear_Expression& e2);
794 
795  friend Constraint
796  operator>=(Variable v1, Variable v2);
797 
798  friend Constraint
799  operator>=(const Linear_Expression& e, Coefficient_traits::const_reference n);
800 
801  friend Constraint
802  operator>=(Coefficient_traits::const_reference n, const Linear_Expression& e);
803 };
804 
805 namespace Parma_Polyhedra_Library {
806 
807 namespace IO_Operators {
808 
810 
811 std::ostream& operator<<(std::ostream& s, const Constraint& c);
812 
814 
815 std::ostream& operator<<(std::ostream& s, const Constraint::Type& t);
816 
817 } // namespace IO_Operators
818 
820 
821 bool
822 operator==(const Constraint& x, const Constraint& y);
823 
825 
826 bool
827 operator!=(const Constraint& x, const Constraint& y);
828 
830 void swap(Constraint& x, Constraint& y);
831 
832 } // namespace Parma_Polyhedra_Library
833 
834 #include "Constraint_inlines.hh"
835 
836 #endif // !defined(PPL_Constraint_defs_hh)
Expression_Hide_Last< Linear_Expression > expr_type
The type of the (adapted) internal expression.
memory_size_type total_memory_in_bytes() const
Returns a lower bound to the total size in bytes of the memory occupied by *this. ...
Scalar product sign function object depending on topology.
void shift_space_dimensions(Variable v, dimension_type n)
bool is_tautological() const
Returns true if and only if *this is a tautology (i.e., an always true constraint).
Definition: Constraint.cc:105
bool operator!=(const Box< ITV > &x, const Box< ITV > &y)
Definition: Box_inlines.hh:264
void throw_dimension_incompatible(const char *method, const char *name_var, Variable v) const
Throws a std::invalid_argument exception containing the appropriate error message.
Definition: Constraint.cc:47
bool operator>(const Ptr_Iterator< P > &x, const Ptr_Iterator< Q > &y)
A linear equality or inequality.
bool is_equality() const
Returns true if and only if *this is an equality constraint.
void swap(CO_Tree &x, CO_Tree &y)
void linear_combine(const Constraint &y, dimension_type i)
Linearly combines *this with y so that i-th coefficient is 0.
Definition: Constraint.cc:189
static const Constraint * zero_dim_false_p
Holds (between class initialization and finalization) a pointer to the unsatisfiable (zero-dimension ...
The base class for systems of constraints and generators.
void set_not_necessarily_closed()
Sets to NOT_NECESSARILY_CLOSED the topological kind of *this row.
Constraint(Representation r=default_representation)
Constructs the constraint.
void m_swap(Constraint &y)
Swaps *this with y.
size_t dimension_type
An unsigned integral type for representing space dimensions.
Type type() const
Returns the constraint type of *this.
static const Constraint * epsilon_geq_zero_p
Holds (between class initialization and finalization) a pointer to the zero-dimension space constrain...
bool check_strong_normalized() const
Returns true if and only if the coefficients are strongly normalized.
Definition: Constraint.cc:259
bool is_necessarily_closed() const
Returns true if and only if the topology of *this row is necessarily closed.
bool ascii_load(std::istream &s)
Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this ...
Definition: Constraint.cc:336
An std::set of variables' indexes.
void mark_as_necessarily_closed()
Marks the epsilon dimension as a standard dimension.
bool operator>=(const Ptr_Iterator< P > &x, const Ptr_Iterator< Q > &y)
std::ostream & operator<<(std::ostream &s, const Ask_Tell< D > &x)
static const Constraint & zero_dim_false()
The unsatisfiable (zero-dimension space) constraint .
Representation representation() const
Returns the current representation of *this.
friend int compare(const Constraint &x, const Constraint &y)
bool is_line_or_equality() const
Returns true if and only if *this row represents a line or an equality.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
void set_is_equality()
Sets the constraint type to EQUALITY.
Coefficient_traits::const_reference coefficient(Variable v) const
Returns the coefficient of v in *this.
friend Constraint operator<(const Linear_Expression &e1, const Linear_Expression &e2)
bool is_equivalent_to(const Constraint &y) const
Returns true if and only if *this and y are equivalent constraints.
Definition: Constraint.cc:208
A dimension of the vector space.
bool is_strict_inequality() const
Returns true if and only if *this is a strict inequality constraint.
The base class for convex polyhedra.
void set_space_dimension(dimension_type space_dim)
Constraint & operator=(const Constraint &c)
Assignment operator.
bool is_inequality() const
Returns true if and only if *this is an inequality constraint (either strict or non-strict).
#define PPL_OUTPUT_DECLARATIONS
void swap_space_dimensions(Variable v1, Variable v2)
Swaps the coefficients of the variables v1 and v2 .
Definition: Constraint.cc:80
friend Constraint operator<=(const Linear_Expression &e1, const Linear_Expression &e2)
void set_necessarily_closed()
Sets to NECESSARILY_CLOSED the topological kind of *this row.
static const Constraint & epsilon_geq_zero()
Returns the zero-dimension space constraint .
bool operator<(const Ptr_Iterator< P > &x, const Ptr_Iterator< Q > &y)
bool is_inconsistent() const
Returns true if and only if *this is inconsistent (i.e., an always false constraint).
Definition: Constraint.cc:148
void set_is_ray_or_point_or_inequality()
Sets to RAY_OR_POINT_OR_INEQUALITY the kind of *this row.
bool is_not_necessarily_closed() const
Returns true if and only if the topology of *this row is not necessarily closed.
static void finalize()
Finalizes the class.
Definition: Constraint.cc:290
int compare(const Linear_Expression &x, const Linear_Expression &y)
void set_representation(Representation r)
Converts *this to the specified representation.
static Constraint construct_epsilon_geq_zero()
Builds a new copy of the zero-dimension space constraint (used to implement NNC polyhedra).
Definition: Constraint.cc:58
void permute_space_dimensions(const std::vector< Variable > &cycle)
Permutes the space dimensions of the constraint.
Definition: Constraint.cc:91
void set_epsilon_coefficient(Coefficient_traits::const_reference n)
Sets the epsilon coefficient to n. The constraint must be NNC.
static const Constraint * zero_dim_positivity_p
Holds (between class initialization and finalization) a pointer to the true (zero-dimension space) co...
static const Representation default_representation
The representation used for new Constraints.
bool is_ray_or_point_or_inequality() const
Returns true if and only if *this row represents a ray, a point or an inequality. ...
The entire library is confined to this namespace.
Definition: version.hh:61
friend Constraint operator>(const Linear_Expression &e1, const Linear_Expression &e2)
void set_is_line_or_equality()
Sets to LINE_OR_EQUALITY the kind of *this row.
void set_is_inequality()
Sets the constraint to be an inequality.
static const Constraint & epsilon_leq_one()
The zero-dimension space constraint (used to implement NNC polyhedra).
Coefficient_traits::const_reference epsilon_coefficient() const
Returns the epsilon coefficient. The constraint must be NNC.
static const Constraint * epsilon_leq_one_p
Holds (between class initialization and finalization) a pointer to the zero-dimension space constrain...
void set_topology(Topology x)
Sets to x the topological kind of *this row.
static const Constraint & zero_dim_positivity()
The true (zero-dimension space) constraint , also known as positivity constraint. ...
bool operator<=(const Ptr_Iterator< P > &x, const Ptr_Iterator< Q > &y)
void strong_normalize()
Strong normalization: ensures that different Constraint objects represent different hyperplanes or hy...
bool is_equal_to(const Constraint &y) const
Returns true if *this is identical to y.
Definition: Constraint.cc:247
void throw_invalid_argument(const char *method, const char *message) const
Throws a std::invalid_argument exception containing error message message.
Definition: Constraint.cc:38
bool OK() const
Checks if all the invariants are satisfied.
Definition: Constraint.cc:467
void set_space_dimension_no_ok(dimension_type space_dim)
Sparse representation: only the nonzero coefficient are stored. If there are many nonzero coefficient...
bool operator==(const Box< ITV > &x, const Box< ITV > &y)
Kind
The possible kinds of Constraint objects.
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
bool is_nonstrict_inequality() const
Returns true if and only if *this is a non-strict inequality constraint.
Coefficient c
Definition: PIP_Tree.cc:64
Coefficient_traits::const_reference inhomogeneous_term() const
Returns the inhomogeneous term of *this.
static void initialize()
Initializes the class.
Definition: Constraint.cc:271
expr_type expression() const
Partial read access to the (adapted) internal expression.
static dimension_type max_space_dimension()
Returns the maximum space dimension a Constraint can handle.
friend Constraint operator>=(const Linear_Expression &e1, const Linear_Expression &e2)
bool remove_space_dimensions(const Variables_Set &vars)
Removes all the specified dimensions from the constraint.
Topology topology() const
Returns the topological kind of *this.
friend Constraint operator==(const Linear_Expression &e1, const Linear_Expression &e2)
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
void mark_as_not_necessarily_closed()
Marks the last dimension as the epsilon dimension.
void sign_normalize()
Normalizes the sign of the coefficients so that the first non-zero (homogeneous) coefficient of a lin...
Definition: Constraint.cc:252
An adapter for Linear_Expression that maybe hides the last coefficient.
Topology
Kinds of polyhedra domains.
A class implementing various scalar product functions.