24 #include "ppl-config.h"
39 const char* message)
const {
41 s <<
"PPL::Constraint::" << method <<
":" << std::endl
43 throw std::invalid_argument(s.str());
51 s <<
"PPL::Constraint::" << method <<
":" << std::endl
52 <<
"this->space_dimension() == " << space_dimension() <<
", "
54 throw std::invalid_argument(s.str());
67 : expr(cg.expression(), r),
68 kind_(LINE_OR_EQUALITY),
72 "congruence cg must be an equality.");
83 expr.swap_space_dimensions(v1, v2);
92 if (cycle.size() < 2) {
97 expr.permute_space_dimensions(cycle);
106 if (expr.all_homogeneous_terms_are_zero()) {
108 return expr.inhomogeneous_term() == 0;
112 return expr.inhomogeneous_term() >= 0;
117 if (is_necessarily_closed()) {
122 const int eps_sign =
sgn(epsilon_coefficient());
133 if (expr.inhomogeneous_term() <= 0) {
141 return expression().all_homogeneous_terms_are_zero();
149 if (expr.all_homogeneous_terms_are_zero()) {
152 return expr.inhomogeneous_term() != 0;
156 return expr.inhomogeneous_term() < 0;
161 if (is_necessarily_closed()) {
166 if (epsilon_coefficient() >= 0) {
174 if (expr.inhomogeneous_term() > 0) {
182 return expression().all_homogeneous_terms_are_zero();
190 expr.linear_combine(y.
expr, i);
199 if (x_is_line_or_equality != y_is_line_or_equality) {
201 return y_is_line_or_equality ? 2 : -2;
216 if (x_type != y.
type()) {
226 if (x_type == STRICT_INEQUALITY) {
237 return x_expr.is_equal_to(y_expr);
248 return expr.is_equal_to(y.
expr) && kind_ == y.
kind_ && topology() == y.
topology();
253 if (is_line_or_equality()) {
254 expr.sign_normalize();
262 return compare(*
this, tmp) == 0;
272 PPL_ASSERT(zero_dim_false_p == 0);
276 PPL_ASSERT(zero_dim_positivity_p == 0);
277 zero_dim_positivity_p
280 PPL_ASSERT(epsilon_geq_zero_p == 0);
282 =
new Constraint(construct_epsilon_geq_zero());
284 PPL_ASSERT(epsilon_leq_one_p == 0);
291 PPL_ASSERT(zero_dim_false_p != 0);
292 delete zero_dim_false_p;
293 zero_dim_false_p = 0;
295 PPL_ASSERT(zero_dim_positivity_p != 0);
296 delete zero_dim_positivity_p;
297 zero_dim_positivity_p = 0;
299 PPL_ASSERT(epsilon_geq_zero_p != 0);
300 delete epsilon_geq_zero_p;
301 epsilon_geq_zero_p = 0;
303 PPL_ASSERT(epsilon_leq_one_p != 0);
304 delete epsilon_leq_one_p;
305 epsilon_leq_one_p = 0;
348 else if (str ==
">=" || str ==
">") {
358 if (str2 ==
"(NNC)") {
361 mark_as_not_necessarily_closed();
368 mark_as_necessarily_closed();
383 case NONSTRICT_INEQUALITY:
388 case STRICT_INEQUALITY:
429 const char* relation_symbol = 0;
432 relation_symbol =
" = ";
435 relation_symbol =
" >= ";
438 relation_symbol =
" > ";
454 n =
"NONSTRICT_INEQUALITY";
457 n =
"STRICT_INEQUALITY";
469 if (is_not_necessarily_closed() && expr.space_dimension() == 0) {
471 std::cerr <<
"Constraint has fewer coefficients than the minimum "
472 <<
"allowed by its topology."
478 if (is_equality() && is_not_necessarily_closed()
479 && epsilon_coefficient() != 0) {
481 std::cerr <<
"Illegal constraint: an equality cannot be strict."
492 std::cerr <<
"Constraint is not strongly normalized as it should be."
void ascii_dump() const
Writes to std::cerr an ASCII representation of *this.
bool is_tautological() const
Returns true if and only if *this is a tautology (i.e., an always true constraint).
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.
A linear equality or inequality.
void linear_combine(const Constraint &y, dimension_type i)
Linearly combines *this with y so that i-th coefficient is 0.
static const Constraint * zero_dim_false_p
Holds (between class initialization and finalization) a pointer to the unsatisfiable (zero-dimension ...
Constraint(Representation r=default_representation)
Constructs the constraint.
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.
bool ascii_load(std::istream &s)
Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this ...
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
Declare a local variable named id, of type Coefficient, and containing an unknown initial value...
std::ostream & operator<<(std::ostream &s, const Ask_Tell< D > &x)
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.
bool is_equivalent_to(const Constraint &y) const
Returns true if and only if *this and y are equivalent constraints.
bool is_equal_to(const Linear_Expression &x) const
A dimension of the vector space.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
void swap_space_dimensions(Variable v1, Variable v2)
Swaps the coefficients of the variables v1 and v2 .
bool is_equality() const
Returns true if *this is an equality.
const_iterator end() const
Iterator pointing after the last nonzero variable coefficient.
bool is_inconsistent() const
Returns true if and only if *this is inconsistent (i.e., an always false constraint).
static void finalize()
Finalizes the class.
int compare(const Linear_Expression &x, const Linear_Expression &y)
static Constraint construct_epsilon_geq_zero()
Builds a new copy of the zero-dimension space constraint (used to implement NNC polyhedra).
void permute_space_dimensions(const std::vector< Variable > &cycle)
Permutes the space dimensions of the constraint.
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...
void neg_assign(GMP_Integer &x)
Coefficient_traits::const_reference Coefficient_zero()
Returns a const reference to a Coefficient with value 0.
#define PPL_OUTPUT_DEFINITIONS(class_name)
The entire library is confined to this namespace.
static const Constraint * epsilon_leq_one_p
Holds (between class initialization and finalization) a pointer to the zero-dimension space constrain...
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.
void throw_invalid_argument(const char *method, const char *message) const
Throws a std::invalid_argument exception containing error message message.
base_type::const_iterator const_iterator
The type of const iterators on coefficients.
bool OK() const
Checks if all the invariants are satisfied.
int sgn(Boundary_Type type, const T &x, const Info &info)
static const Linear_Expression & zero()
Returns the (zero-dimension space) constant 0.
Coefficient_traits::const_reference inhomogeneous_term() const
Returns the inhomogeneous term of *this.
static void initialize()
Initializes the class.
Coefficient_traits::const_reference Coefficient_one()
Returns a const reference to a Coefficient with value 1.
expr_type expression() const
Partial read access to the (adapted) internal expression.
const_iterator begin() const
Iterator pointing to the first nonzero variable coefficient.
Topology topology() const
Returns the topological kind of *this.
void sign_normalize()
Normalizes the sign of the coefficients so that the first non-zero (homogeneous) coefficient of a lin...