00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef PPL_Octagonal_Shape_defs_hh
00025 #define PPL_Octagonal_Shape_defs_hh 1
00026
00027 #include "Octagonal_Shape.types.hh"
00028 #include "globals.types.hh"
00029 #include "Constraint.types.hh"
00030 #include "Generator.types.hh"
00031 #include "Congruence.types.hh"
00032 #include "Linear_Expression.types.hh"
00033 #include "Constraint_System.types.hh"
00034 #include "Generator_System.types.hh"
00035 #include "Congruence_System.types.hh"
00036 #include "OR_Matrix.defs.hh"
00037 #include "Poly_Con_Relation.defs.hh"
00038 #include "Poly_Gen_Relation.defs.hh"
00039 #include "Polyhedron.types.hh"
00040 #include "Box.types.hh"
00041 #include "Grid.types.hh"
00042 #include "BD_Shape.types.hh"
00043 #include "Variable.defs.hh"
00044 #include "Variables_Set.types.hh"
00045 #include "Checked_Number.defs.hh"
00046 #include "WRD_coefficient_types.defs.hh"
00047 #include "Bit_Row.defs.hh"
00048 #include <vector>
00049 #include <cstddef>
00050 #include <climits>
00051 #include <iosfwd>
00052
00053 namespace Parma_Polyhedra_Library {
00054
00055 namespace IO_Operators {
00056
00058
00065 template <typename T>
00066 std::ostream&
00067 operator<<(std::ostream& s, const Octagonal_Shape<T>& oct);
00068
00069 }
00070
00078 template <typename T>
00079 bool operator==(const Octagonal_Shape<T>& x, const Octagonal_Shape<T>& y);
00080
00088 template <typename T>
00089 bool operator!=(const Octagonal_Shape<T>& x, const Octagonal_Shape<T>& y);
00090
00092
00102 template <typename To, typename T>
00103 bool rectilinear_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00104 const Octagonal_Shape<T>& x,
00105 const Octagonal_Shape<T>& y,
00106 Rounding_Dir dir);
00107
00109
00119 template <typename Temp, typename To, typename T>
00120 bool rectilinear_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00121 const Octagonal_Shape<T>& x,
00122 const Octagonal_Shape<T>& y,
00123 Rounding_Dir dir);
00124
00126
00136 template <typename Temp, typename To, typename T>
00137 bool rectilinear_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00138 const Octagonal_Shape<T>& x,
00139 const Octagonal_Shape<T>& y,
00140 Rounding_Dir dir,
00141 Temp& tmp0,
00142 Temp& tmp1,
00143 Temp& tmp2);
00144
00146
00156 template <typename To, typename T>
00157 bool euclidean_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00158 const Octagonal_Shape<T>& x,
00159 const Octagonal_Shape<T>& y,
00160 Rounding_Dir dir);
00161
00163
00173 template <typename Temp, typename To, typename T>
00174 bool euclidean_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00175 const Octagonal_Shape<T>& x,
00176 const Octagonal_Shape<T>& y,
00177 Rounding_Dir dir);
00178
00180
00190 template <typename Temp, typename To, typename T>
00191 bool euclidean_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00192 const Octagonal_Shape<T>& x,
00193 const Octagonal_Shape<T>& y,
00194 Rounding_Dir dir,
00195 Temp& tmp0,
00196 Temp& tmp1,
00197 Temp& tmp2);
00198
00200
00210 template <typename To, typename T>
00211 bool l_infinity_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00212 const Octagonal_Shape<T>& x,
00213 const Octagonal_Shape<T>& y,
00214 Rounding_Dir dir);
00215
00217
00227 template <typename Temp, typename To, typename T>
00228 bool l_infinity_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00229 const Octagonal_Shape<T>& x,
00230 const Octagonal_Shape<T>& y,
00231 Rounding_Dir dir);
00232
00234
00244 template <typename Temp, typename To, typename T>
00245 bool l_infinity_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00246 const Octagonal_Shape<T>& x,
00247 const Octagonal_Shape<T>& y,
00248 Rounding_Dir dir,
00249 Temp& tmp0,
00250 Temp& tmp1,
00251 Temp& tmp2);
00252
00253 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00254
00255
00292 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00293 bool extract_octagonal_difference(const Constraint& c,
00294 dimension_type c_space_dim,
00295 dimension_type& c_num_vars,
00296 dimension_type& c_first_var,
00297 dimension_type& c_second_var,
00298 Coefficient& c_coeff,
00299 Coefficient& c_term);
00300
00301 }
00302
00304
00407 template <typename T>
00408 class Parma_Polyhedra_Library::Octagonal_Shape {
00409 private:
00414 #ifndef NDEBUG
00415 typedef Checked_Number<T, Debug_WRD_Extended_Number_Policy> N;
00416 #else
00417 typedef Checked_Number<T, WRD_Extended_Number_Policy> N;
00418 #endif
00419
00420 public:
00421
00423 typedef T coefficient_type_base;
00424
00429 typedef N coefficient_type;
00430
00432 static dimension_type max_space_dimension();
00433
00437 static bool can_recycle_constraint_systems();
00438
00442 static bool can_recycle_congruence_systems();
00443
00445
00446
00448
00455 explicit Octagonal_Shape(dimension_type num_dimensions = 0,
00456 Degenerate_Element kind = UNIVERSE);
00457
00459
00462 Octagonal_Shape(const Octagonal_Shape& x,
00463 Complexity_Class complexity = ANY_COMPLEXITY);
00464
00466
00469 template <typename U>
00470 explicit Octagonal_Shape(const Octagonal_Shape<U>& y,
00471 Complexity_Class complexity = ANY_COMPLEXITY);
00472
00474
00484 explicit Octagonal_Shape(const Constraint_System& cs);
00485
00487
00497 explicit Octagonal_Shape(const Congruence_System& cgs);
00498
00500
00507 explicit Octagonal_Shape(const Generator_System& gs);
00508
00510
00516 explicit Octagonal_Shape(const Polyhedron& ph,
00517 Complexity_Class complexity = ANY_COMPLEXITY);
00518
00520
00535 template <typename Interval>
00536 explicit Octagonal_Shape(const Box<Interval>& box,
00537 Complexity_Class complexity = ANY_COMPLEXITY);
00538
00540
00555 explicit Octagonal_Shape(const Grid& grid,
00556 Complexity_Class complexity = ANY_COMPLEXITY);
00557
00559
00574 template <typename U>
00575 explicit Octagonal_Shape(const BD_Shape<U>& bd,
00576 Complexity_Class complexity = ANY_COMPLEXITY);
00577
00582 Octagonal_Shape& operator=(const Octagonal_Shape& y);
00583
00588 void swap(Octagonal_Shape& y);
00589
00591 ~Octagonal_Shape();
00592
00594
00596
00597
00599 dimension_type space_dimension() const;
00600
00606 dimension_type affine_dimension() const;
00607
00609 Constraint_System constraints() const;
00610
00612 Constraint_System minimized_constraints() const;
00613
00615 Congruence_System congruences() const;
00616
00621 Congruence_System minimized_congruences() const;
00622
00624
00628 bool contains(const Octagonal_Shape& y) const;
00629
00631
00635 bool strictly_contains(const Octagonal_Shape& y) const;
00636
00638
00643 bool is_disjoint_from(const Octagonal_Shape& y) const;
00644
00651 Poly_Con_Relation relation_with(const Constraint& c) const;
00652
00659 Poly_Con_Relation relation_with(const Congruence& cg) const;
00660
00667 Poly_Gen_Relation relation_with(const Generator& g) const;
00668
00670 bool is_empty() const;
00671
00673 bool is_universe() const;
00674
00676 bool is_discrete() const;
00677
00682 bool is_bounded() const;
00683
00688 bool is_topologically_closed() const;
00689
00694 bool contains_integer_point() const;
00695
00703 bool constrains(Variable var) const;
00704
00712 bool bounds_from_above(const Linear_Expression& expr) const;
00713
00721 bool bounds_from_below(const Linear_Expression& expr) const;
00722
00747 bool maximize(const Linear_Expression& expr,
00748 Coefficient& sup_n, Coefficient& sup_d, bool& maximum) const;
00749
00778 bool maximize(const Linear_Expression& expr,
00779 Coefficient& sup_n, Coefficient& sup_d, bool& maximum,
00780 Generator& g) const;
00781
00806 bool minimize(const Linear_Expression& expr,
00807 Coefficient& inf_n, Coefficient& inf_d, bool& minimum) const;
00808
00837 bool minimize(const Linear_Expression& expr,
00838 Coefficient& inf_n, Coefficient& inf_d, bool& minimum,
00839 Generator& g) const;
00840
00869 bool frequency(const Linear_Expression& expr,
00870 Coefficient& freq_n, Coefficient& freq_d,
00871 Coefficient& val_n, Coefficient& val_d) const;
00872
00874 bool OK() const;
00875
00877
00879
00880
00892 void add_constraint(const Constraint& c);
00893
00906 void add_constraints(const Constraint_System& cs);
00907
00925 void add_recycled_constraints(Constraint_System& cs);
00926
00937 void add_congruence(const Congruence& cg);
00938
00950 void add_congruences(const Congruence_System& cgs);
00951
00968 void add_recycled_congruences(Congruence_System& cgs);
00969
00980 void refine_with_constraint(const Constraint& c);
00981
00993 void refine_with_congruence(const Congruence& cg);
00994
01006 void refine_with_constraints(const Constraint_System& cs);
01007
01019 void refine_with_congruences(const Congruence_System& cgs);
01020
01031 void unconstrain(Variable var);
01032
01045 void unconstrain(const Variables_Set& vars);
01046
01048
01052 void intersection_assign(const Octagonal_Shape& y);
01053
01061 void upper_bound_assign(const Octagonal_Shape& y);
01062
01073 bool upper_bound_assign_if_exact(const Octagonal_Shape& y);
01074
01096 bool integer_upper_bound_assign_if_exact(const Octagonal_Shape& y);
01097
01105 void difference_assign(const Octagonal_Shape& y);
01106
01116 bool simplify_using_context_assign(const Octagonal_Shape& y);
01117
01136 void affine_image(Variable var,
01137 const Linear_Expression& expr,
01138 Coefficient_traits::const_reference denominator
01139 = Coefficient_one());
01140
01159 void affine_preimage(Variable var,
01160 const Linear_Expression& expr,
01161 Coefficient_traits::const_reference denominator
01162 = Coefficient_one());
01163
01188 void generalized_affine_image(Variable var,
01189 Relation_Symbol relsym,
01190 const Linear_Expression& expr,
01191 Coefficient_traits::const_reference denominator
01192 = Coefficient_one());
01193
01213 void generalized_affine_image(const Linear_Expression& lhs,
01214 Relation_Symbol relsym,
01215 const Linear_Expression& rhs);
01216
01243 void bounded_affine_image(Variable var,
01244 const Linear_Expression& lb_expr,
01245 const Linear_Expression& ub_expr,
01246 Coefficient_traits::const_reference denominator
01247 = Coefficient_one());
01248
01273 void generalized_affine_preimage(Variable var,
01274 Relation_Symbol relsym,
01275 const Linear_Expression& expr,
01276 Coefficient_traits::const_reference
01277 denominator = Coefficient_one());
01278
01298 void generalized_affine_preimage(const Linear_Expression& lhs,
01299 Relation_Symbol relsym,
01300 const Linear_Expression& rhs);
01301
01328 void bounded_affine_preimage(Variable var,
01329 const Linear_Expression& lb_expr,
01330 const Linear_Expression& ub_expr,
01331 Coefficient_traits::const_reference denominator
01332 = Coefficient_one());
01333
01341 void time_elapse_assign(const Octagonal_Shape& y);
01342
01389 void wrap_assign(const Variables_Set& vars,
01390 Bounded_Integer_Type_Width w,
01391 Bounded_Integer_Type_Representation r,
01392 Bounded_Integer_Type_Overflow o,
01393 const Constraint_System* pcs = 0,
01394 unsigned complexity_threshold = 16,
01395 bool wrap_individually = true);
01396
01408 void drop_some_non_integer_points(Complexity_Class complexity
01409 = ANY_COMPLEXITY);
01410
01426 void drop_some_non_integer_points(const Variables_Set& vars,
01427 Complexity_Class complexity
01428 = ANY_COMPLEXITY);
01429
01431 void topological_closure_assign();
01432
01448 void CC76_extrapolation_assign(const Octagonal_Shape& y, unsigned* tp = 0);
01449
01471 template <typename Iterator>
01472 void CC76_extrapolation_assign(const Octagonal_Shape& y,
01473 Iterator first, Iterator last,
01474 unsigned* tp = 0);
01475
01491 void BHMZ05_widening_assign(const Octagonal_Shape& y, unsigned* tp = 0);
01492
01494 void widening_assign(const Octagonal_Shape& y, unsigned* tp = 0);
01495
01516 void limited_BHMZ05_extrapolation_assign(const Octagonal_Shape& y,
01517 const Constraint_System& cs,
01518 unsigned* tp = 0);
01519
01530 void CC76_narrowing_assign(const Octagonal_Shape& y);
01531
01552 void limited_CC76_extrapolation_assign(const Octagonal_Shape& y,
01553 const Constraint_System& cs,
01554 unsigned* tp = 0);
01555
01557
01559
01560
01562
01579 void add_space_dimensions_and_embed(dimension_type m);
01580
01602 void add_space_dimensions_and_project(dimension_type m);
01603
01612 void concatenate_assign(const Octagonal_Shape& y);
01613
01615
01623 void remove_space_dimensions(const Variables_Set& vars);
01624
01633 void remove_higher_space_dimensions(dimension_type new_dimension);
01634
01671 template <typename Partial_Function>
01672 void map_space_dimensions(const Partial_Function& pfunc);
01673
01675
01695 void expand_space_dimension(Variable var, dimension_type m);
01696
01698
01720 void fold_space_dimensions(const Variables_Set& vars, Variable dest);
01721
01723
01727 template <typename Interval_Info>
01728 void refine_fp_interval_abstract_store(
01729 Box< Interval<T, Interval_Info> >& store) const;
01730
01732
01733 PPL_OUTPUT_DECLARATIONS
01734
01740 bool ascii_load(std::istream& s);
01741
01743 memory_size_type total_memory_in_bytes() const;
01744
01746 memory_size_type external_memory_in_bytes() const;
01747
01754 int32_t hash_code() const;
01755
01756 friend bool
01757 operator==<T>(const Octagonal_Shape<T>& x, const Octagonal_Shape<T>& y);
01758
01759 template <typename Temp, typename To, typename U>
01760 friend bool Parma_Polyhedra_Library::rectilinear_distance_assign
01761 (Checked_Number<To, Extended_Number_Policy>& r,
01762 const Octagonal_Shape<U>& x, const Octagonal_Shape<U>& y,
01763 const Rounding_Dir dir, Temp& tmp0, Temp& tmp1, Temp& tmp2);
01764 template <typename Temp, typename To, typename U>
01765 friend bool Parma_Polyhedra_Library::euclidean_distance_assign
01766 (Checked_Number<To, Extended_Number_Policy>& r,
01767 const Octagonal_Shape<U>& x, const Octagonal_Shape<U>& y,
01768 const Rounding_Dir dir, Temp& tmp0, Temp& tmp1, Temp& tmp2);
01769 template <typename Temp, typename To, typename U>
01770 friend bool Parma_Polyhedra_Library::l_infinity_distance_assign
01771 (Checked_Number<To, Extended_Number_Policy>& r,
01772 const Octagonal_Shape<U>& x, const Octagonal_Shape<U>& y,
01773 const Rounding_Dir dir, Temp& tmp0, Temp& tmp1, Temp& tmp2);
01774
01775 private:
01776 template <typename U> friend class Parma_Polyhedra_Library::Octagonal_Shape;
01777 template <typename Interval> friend class Parma_Polyhedra_Library::Box;
01778
01780 OR_Matrix<N> matrix;
01781
01783 dimension_type space_dim;
01784
01785
01786
01787
01788
01789
01790
01791 #define PPL_IN_Octagonal_Shape_CLASS
01792 #include "Og_Status.idefs.hh"
01793 #undef PPL_IN_Octagonal_Shape_CLASS
01794
01796 Status status;
01797
01799 bool marked_zero_dim_univ() const;
01800
01802
01806 bool marked_empty() const;
01807
01815 bool marked_strongly_closed() const;
01816
01818 void set_zero_dim_univ();
01819
01821 void set_empty();
01822
01824 void set_strongly_closed();
01825
01827 void reset_strongly_closed();
01828
01829 N& matrix_at(dimension_type i, dimension_type j);
01830 const N& matrix_at(dimension_type i, dimension_type j) const;
01831
01842 void refine_no_check(const Constraint& c);
01843
01856 void refine_no_check(const Congruence& cg);
01857
01859 void add_octagonal_constraint(dimension_type i,
01860 dimension_type j,
01861 const N& k);
01862
01864 void add_octagonal_constraint(dimension_type i,
01865 dimension_type j,
01866 Coefficient_traits::const_reference num,
01867 Coefficient_traits::const_reference den);
01868
01875 void refine(Variable var,
01876 Relation_Symbol relsym,
01877 const Linear_Expression& expr,
01878 Coefficient_traits::const_reference denominator
01879 = Coefficient_one());
01880
01882 void forget_all_octagonal_constraints(dimension_type v_id);
01883
01885 void forget_binary_octagonal_constraints(dimension_type v_id);
01886
01888
01914 void deduce_v_pm_u_bounds(dimension_type v_id,
01915 dimension_type last_id,
01916 const Linear_Expression& sc_expr,
01917 Coefficient_traits::const_reference sc_den,
01918 const N& ub_v);
01919
01921
01948 void deduce_minus_v_pm_u_bounds(dimension_type v,
01949 dimension_type last_v,
01950 const Linear_Expression& sc_expr,
01951 Coefficient_traits::const_reference sc_den,
01952 const N& minus_lb_v);
01953
01958 void get_limiting_octagon(const Constraint_System& cs,
01959 Octagonal_Shape& limiting_octagon) const;
01961
01964 void compute_successors(std::vector<dimension_type>& successor) const;
01965
01967
01970 void compute_leaders(std::vector<dimension_type>& successor,
01971 std::vector<dimension_type>& no_sing_leaders,
01972 bool& exist_sing_class,
01973 dimension_type& sing_leader) const;
01974
01976
01979 void compute_leaders(std::vector<dimension_type>& leaders) const;
01980
01988 void non_redundant_matrix_entries(std::vector<Bit_Row>& non_redundant) const;
01989
01991 void strong_reduction_assign() const;
01992
01997 bool is_strongly_reduced() const;
01998
02003 bool is_strong_coherent() const;
02004
02005 bool tight_coherence_would_make_empty() const;
02006
02008
02014 void strong_closure_assign() const;
02015
02017 void strong_coherence_assign();
02018
02020
02027 void tight_closure_assign();
02028
02040 void incremental_strong_closure_assign(Variable var) const;
02041
02043
02059 bool bounds(const Linear_Expression& expr, bool from_above) const;
02060
02062
02087 bool max_min(const Linear_Expression& expr,
02088 bool maximize,
02089 Coefficient& ext_n, Coefficient& ext_d, bool& included) const;
02090
02092
02122 bool max_min(const Linear_Expression& expr,
02123 bool maximize,
02124 Coefficient& ext_n, Coefficient& ext_d, bool& included,
02125 Generator& g) const;
02126
02127 void drop_some_non_integer_points_helper(N& elem);
02128
02129 friend std::ostream&
02130 Parma_Polyhedra_Library::IO_Operators
02131 ::operator<<<>(std::ostream& s, const Octagonal_Shape<T>& c);
02132
02134
02135 void throw_dimension_incompatible(const char* method,
02136 const Octagonal_Shape& x) const;
02137
02138 void throw_dimension_incompatible(const char* method,
02139 dimension_type required_dim) const;
02140
02141 void throw_dimension_incompatible(const char* method,
02142 const Constraint& c) const;
02143
02144 void throw_dimension_incompatible(const char* method,
02145 const Congruence& cg) const;
02146
02147 void throw_dimension_incompatible(const char* method,
02148 const Generator& g) const;
02149
02150 void throw_dimension_incompatible(const char* method,
02151 const char* name_row,
02152 const Linear_Expression& y) const;
02153
02154 void throw_constraint_incompatible(const char* method) const;
02155
02156 void throw_expression_too_complex(const char* method,
02157 const Linear_Expression& e) const;
02158
02159 void throw_generic(const char* method, const char* reason) const;
02161
02162 static T default_stop_points[];
02163 };
02164
02165 namespace std {
02166
02168
02169 template <typename T>
02170 void swap(Parma_Polyhedra_Library::Octagonal_Shape<T>& x,
02171 Parma_Polyhedra_Library::Octagonal_Shape<T>& y);
02172
02173 }
02174
02175 #include "Og_Status.inlines.hh"
02176 #include "Octagonal_Shape.inlines.hh"
02177 #include "Octagonal_Shape.templates.hh"
02178
02179 #endif // !defined(PPL_Octagonal_Shape_defs_hh)