25 #include "ppl-config.h"
30 #include "assertions.hh"
36 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
46 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
109 PPL_ASSERT(con_sys.has_no_rows());
110 PPL_ASSERT(gen_sys.has_no_rows());
118 con_sys.normalize_moduli();
119 set_congruences_up_to_date();
125 if (cgs[i].is_inconsistent()) {
147 PPL_ASSERT(con_sys.has_no_rows());
148 PPL_ASSERT(gen_sys.has_no_rows());
164 throw_invalid_generators(
"Grid(ggs)",
"ggs");
167 if (space_dim == 0) {
173 normalize_divisors(gen_sys);
175 set_generators_up_to_date();
185 PPL_ASSERT(!marked_empty() && !y.
marked_empty() && space_dim > 0);
187 const Grid& x = *
this;
189 bool css_normalized =
false;
198 const dimension_type x_num_equalities = x.con_sys.num_equalities();
204 css_normalized = (x_num_equalities == 0);
219 if (x_num_lines == 0) {
234 if (css_normalized) {
250 PPL_ASSERT(!marked_empty() && !y.
marked_empty() && space_dim > 0);
252 const Grid& x = *
this;
255 if (!x.generators_are_up_to_date() && !x.update_generators()) {
263 if (!x.generators_are_minimized() && !x.minimize()) {
290 const char* method_call)
const {
293 throw_dimension_incompatible(method_call,
"e", expr);
298 || (!generators_are_up_to_date() && !update_generators())) {
301 if (!generators_are_minimized() && !minimize()) {
306 return bounds_no_check(expr);
313 PPL_ASSERT(generators_are_minimized() && !marked_empty());
338 PPL_ASSERT(generators_are_minimized() && !marked_empty());
344 if (bounds_no_check(expr)) {
414 const char* method_call,
417 if (bounds(expr, method_call)) {
418 if (marked_empty()) {
421 if (space_dim == 0) {
431 if (!generators_are_minimized()) {
433 Grid& gr =
const_cast<Grid&
>(*this);
460 status.set_zero_dim_univ();
464 gen_sys.insert(grid_point());
485 PPL_ASSERT(space_dim > 0);
486 PPL_ASSERT(!marked_empty());
487 PPL_ASSERT(!gen_sys.has_no_rows());
488 PPL_ASSERT(gen_sys.space_dimension() > 0);
490 Grid& gr =
const_cast<Grid&
>(*this);
492 if (!generators_are_minimized()) {
493 gr.
simplify(gr.gen_sys, gr.dim_kinds);
498 PPL_ASSERT(!gen_sys.has_no_rows());
502 gr.conversion(gr.gen_sys, gr.con_sys, gr.dim_kinds);
505 gr.set_congruences_minimized();
506 gr.set_generators_minimized();
511 PPL_ASSERT(space_dim > 0);
512 PPL_ASSERT(!marked_empty());
513 PPL_ASSERT(congruences_are_up_to_date());
517 if (!congruences_are_minimized()) {
538 if (marked_empty()) {
541 if (space_dim == 0) {
545 if (congruences_are_minimized() && generators_are_minimized()) {
550 if (congruences_are_up_to_date()) {
551 if (generators_are_up_to_date()) {
552 Grid& gr =
const_cast<Grid&
>(*this);
554 if (congruences_are_minimized()) {
569 if (!generators_are_minimized()) {
578 const bool ret = update_generators();
584 PPL_ASSERT(generators_are_up_to_date());
585 update_congruences();
597 PPL_ASSERT(num_rows > 0);
601 while (gen_sys[row].is_line_or_parameter()) {
604 PPL_ASSERT(row < num_rows);
614 PPL_ASSERT(gen_sys_divisor == g.
divisor());
617 #endif // !defined(NDEBUG)
620 divisor = gen_sys_divisor;
622 normalize_divisors(sys, divisor);
623 if (divisor != gen_sys_divisor) {
629 normalize_divisors(gen_sys, divisor, &first_point);
637 PPL_ASSERT(divisor >= 0);
641 if (first_point != 0) {
642 lcm_assign(divisor, divisor, (*first_point).divisor());
645 PPL_ASSERT(num_rows > 0);
648 while (sys[row].is_line()) {
649 if (++row == num_rows) {
657 while (row < num_rows) {
669 sys.
sys.rows[i].scale_to_divisor(divisor);
673 PPL_ASSERT(sys.
sys.OK());
679 PPL_ASSERT(!marked_empty());
683 if (space_dim == 0) {
690 if (!congruences_are_up_to_date()) {
691 update_congruences();
696 clear_congruences_minimized();
697 set_congruences_up_to_date();
698 clear_generators_up_to_date();
707 PPL_ASSERT(!marked_empty());
720 throw_invalid_constraint(
"add_constraint(c)",
"c");
725 add_congruence_no_check(cg);
730 PPL_ASSERT(!marked_empty());
735 add_congruence_no_check(cg);
744 std::ostringstream s;
745 s <<
"PPL::Grid::" << method <<
":" << std::endl
747 throw std::invalid_argument(s.str());
752 const char* other_name,
754 std::ostringstream s;
755 s <<
"PPL::Grid::" << method <<
":\n"
756 <<
"this->space_dimension() == " << space_dimension() <<
", "
757 << other_name <<
".space_dimension() == " << other_dim <<
".";
758 throw std::invalid_argument(s.str());
764 const Grid& gr)
const {
805 const char* cgs_name,
826 const char* var_name,
828 std::ostringstream s;
829 s <<
"PPL::Grid::" << method <<
":" << std::endl
830 <<
"this->space_dimension() == " << space_dimension() <<
", "
831 << var_name <<
".space_dimension() == " << var.
space_dimension() <<
".";
832 throw std::invalid_argument(s.str());
839 std::ostringstream s;
840 s <<
"PPL::Grid::" << method <<
":" << std::endl
841 <<
"this->space_dimension() == " << space_dimension()
842 <<
", required space dimension == " << required_space_dim <<
".";
843 throw std::invalid_argument(s.str());
848 const char* c_name) {
849 std::ostringstream s;
850 s <<
"PPL::Grid::" << method <<
":" << std::endl
851 << c_name <<
" is not an equality constraint.";
852 throw std::invalid_argument(s.str());
857 const char* cs_name) {
858 std::ostringstream s;
859 s <<
"PPL::Grid::" << method <<
":" << std::endl
860 <<
"the constraint system " << cs_name
861 <<
" contains inequalities.";
862 throw std::invalid_argument(s.str());
867 const char* g_name) {
868 std::ostringstream s;
869 s <<
"PPL::Grid::" << method <<
":" << std::endl
870 <<
"*this is an empty grid and "
871 << g_name <<
" is not a point.";
872 throw std::invalid_argument(s.str());
877 const char* gs_name) {
878 std::ostringstream s;
879 s <<
"PPL::Grid::" << method <<
":" << std::endl
880 <<
"*this is an empty grid and" << std::endl
881 <<
"the non-empty generator system " << gs_name <<
" contains no points.";
882 throw std::invalid_argument(s.str());
bool is_parameter_or_point() const
Returns true if and only if *this row represents a parameter or a point.
Grid_Generator_System gen_sys
The system of generators.
static int homogeneous_sign(const Linear_Expression &x, const Linear_Expression &y)
Returns the sign of the homogeneous scalar product of x and y, where the inhomogeneous terms are igno...
bool is_tautological() const
Returns true if and only if *this is a tautology (i.e., an always true constraint).
The empty element, i.e., the empty set.
dimension_type max_space_dimension()
Returns the maximum space dimension this library can handle.
Status status
The status flags to keep track of the grid's internal state.
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)
bool is_included_in(const Grid &y) const
Returns true if and only if *this is included in y.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
void set_empty()
Sets status to express that the grid is empty, clearing all corresponding matrices.
size_t dimension_type
An unsigned integral type for representing space dimensions.
static void throw_invalid_generator(const char *method, const char *g_name)
Linear_System< Grid_Generator > sys
Congruence_System con_sys
The system of congruences.
bool is_line() const
Returns true if and only if *this is a line.
A line, ray, point or closure point.
void add_congruence_no_check(const Congruence &cg)
Adds the congruence cg to *this.
Coefficient_traits::const_reference inhomogeneous_term() const
Returns the inhomogeneous term of *this.
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
Declare a local variable named id, of type Coefficient, and containing an unknown initial value...
bool is_inconsistent() const
Returns true if and only if *this is inconsistent (i.e., an always false congruence).
bool set_space_dimension(dimension_type new_space_dim)
Sets the number of space dimensions to new_space_dim.
bool has_points() const
Returns true if and only if *this contains one or more points.
void add_constraint_no_check(const Constraint &c)
Uses the constraint c to refine *this.
dimension_type num_lines() const
Returns the number of lines in the system.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
void lcm_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
dimension_type num_equalities() const
Returns the number of equalities.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
void exact_div_assign(Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y, const Checked_Number< T, Policy > &z)
static bool simplify(Congruence_System &cgs, Dimension_Kinds &dim_kinds)
Converts cgs to upper triangular (i.e. minimized) form.
void set_space_dimension(dimension_type space_dim)
Resizes the system to the specified space dimension.
bool congruences_are_up_to_date() const
Returns true if the system of congruences is up-to-date.
expr_type expression() const
Partial read access to the (adapted) internal expression.
static void normalize_divisors(Grid_Generator_System &sys, Coefficient &divisor, const Grid_Generator *first_point=NULL)
Normalizes the divisors in sys.
void set_generators_minimized()
Sets status to express that generators are minimized.
void throw_dimension_incompatible(const char *method, const char *other_name, dimension_type other_dim) const
static const Congruence & zero_dim_false()
Returns a reference to the false (zero-dimension space) congruence .
A dimension of the vector space.
bool satisfies_all_congruences(const Grid_Generator &g) const
Returns true if g satisfies all the congruences.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
static const Congruence & zero_dim_integrality()
Returns a reference to the true (zero-dimension space) congruence , also known as the integrality con...
Three_Valued_Boolean quick_equivalence_test(const Grid &y) const
Polynomial but incomplete equivalence test between grids.
bool is_inequality() const
Returns true if and only if *this is an inequality constraint (either strict or non-strict).
Swapping_Vector< Congruence > rows
bool max_min(const Linear_Expression &expr, const char *method_call, Coefficient &ext_n, Coefficient &ext_d, bool &included, Generator *point=NULL) const
Maximizes or minimizes expr subject to *this.
bool OK(bool check_not_empty=false) const
Checks if all the invariants are satisfied.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
Coefficient_traits::const_reference divisor() const
Returns the divisor of *this.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
bool bounds(const Linear_Expression &expr, const char *method_call) const
Checks if and how expr is bounded in *this.
Degenerate_Element
Kinds of degenerate abstract elements.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
bool is_line_or_parameter() const
Returns true if and only if *this is a line or a parameter.
bool is_inconsistent() const
Returns true if and only if *this is inconsistent (i.e., an always false constraint).
bool OK() const
Checks if all the invariants are satisfied.
bool is_point() const
Returns true if and only if *this is a point.
void refine_no_check(const Constraint &c)
Uses the constraint c to refine *this.
void swap(Grid &x, Grid &y)
Swaps x with y.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
bool frequency_no_check(const Linear_Expression &expr, Coefficient &freq_n, Coefficient &freq_d, Coefficient &val_n, Coefficient &val_d) const
Returns true if and only if *this is not empty and frequency for *this with respect to expr is define...
bool minimize(const Linear_Expression &expr, Coefficient &inf_n, Coefficient &inf_d, bool &minimum) const
Returns true if and only if *this is not empty and expr is bounded from below in *this, in which case the infimum value is computed.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
void set_zero_dim_univ()
Sets status to express that the grid is the universe 0-dimension vector space, clearing all correspon...
static Generator point(const Linear_Expression &e=Linear_Expression::zero(), Coefficient_traits::const_reference d=Coefficient_one(), Representation r=default_representation)
Returns the point at e / d.
dimension_type space_dim
The number of dimensions of the enclosing vector space.
The entire library is confined to this namespace.
dimension_type num_rows() const
Returns the number of rows in the system.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
static void throw_invalid_generators(const char *method, const char *gs_name)
bool marked_empty() const
Returns true if the grid is known to be empty.
dimension_type num_rows() const
Returns the number of rows (generators) in the system.
bool congruences_are_minimized() const
Returns true if the system of congruences is minimized.
static void throw_invalid_constraints(const char *method, const char *cs_name)
static void throw_invalid_argument(const char *method, const char *reason)
Dimension_Kinds dim_kinds
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
void gcd_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
int sgn(Boundary_Type type, const T &x, const Info &info)
static void homogeneous_assign(Coefficient &z, const Linear_Expression &x, const Linear_Expression &y)
Computes the homogeneous scalar product of x and y, where the inhomogeneous terms are ignored...
void update_congruences() const
Updates and minimizes the congruences from the generators.
bool is_parameter() const
Returns true if and only if *this is a parameter.
Coefficient_traits::const_reference Coefficient_one()
Returns a const reference to a Coefficient with value 1.
bool generators_are_minimized() const
Returns true if the system of generators is minimized.
bool bounds_no_check(const Linear_Expression &expr) const
Checks if and how expr is bounded in *this.
static void throw_invalid_constraint(const char *method, const char *c_name)
void construct(dimension_type num_dimensions, Degenerate_Element kind)
Builds a grid universe or empty grid.
void insert(const Grid_Generator &g)
Inserts into *this a copy of the generator g, increasing the number of space dimensions if needed...
bool le(Boundary_Type type1, const T1 &x1, const Info1 &info1, Boundary_Type type2, const T2 &x2, const Info2 &info2)
bool update_generators() const
Updates and minimizes the generators from the congruences.
A grid line, parameter or grid point.
void set_congruences_minimized()
Sets status to express that congruences are minimized.
A system of grid generators.
bool minimize() const
Minimizes both the congruences and the generators.