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_BD_Shape_defs_hh
00025 #define PPL_BD_Shape_defs_hh 1
00026
00027 #include "BD_Shape.types.hh"
00028 #include "globals.defs.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 "Poly_Con_Relation.types.hh"
00037 #include "Poly_Gen_Relation.types.hh"
00038 #include "Polyhedron.types.hh"
00039 #include "Box.types.hh"
00040 #include "Grid.types.hh"
00041 #include "Octagonal_Shape.types.hh"
00042 #include "Variable.defs.hh"
00043 #include "Variables_Set.types.hh"
00044 #include "DB_Matrix.defs.hh"
00045 #include "DB_Row.defs.hh"
00046 #include "Checked_Number.defs.hh"
00047 #include "WRD_coefficient_types.defs.hh"
00048 #include "Bit_Matrix.defs.hh"
00049 #include <cstddef>
00050 #include <iosfwd>
00051 #include <vector>
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 BD_Shape<T>& bds);
00068
00069 }
00070
00072
00076 template <typename T>
00077 bool operator==(const BD_Shape<T>& x, const BD_Shape<T>& y);
00078
00080
00084 template <typename T>
00085 bool operator!=(const BD_Shape<T>& x, const BD_Shape<T>& y);
00086
00088
00098 template <typename To, typename T>
00099 bool rectilinear_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00100 const BD_Shape<T>& x,
00101 const BD_Shape<T>& y,
00102 Rounding_Dir dir);
00103
00105
00115 template <typename Temp, typename To, typename T>
00116 bool rectilinear_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00117 const BD_Shape<T>& x,
00118 const BD_Shape<T>& y,
00119 Rounding_Dir dir);
00120
00122
00132 template <typename Temp, typename To, typename T>
00133 bool rectilinear_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00134 const BD_Shape<T>& x,
00135 const BD_Shape<T>& y,
00136 Rounding_Dir dir,
00137 Temp& tmp0,
00138 Temp& tmp1,
00139 Temp& tmp2);
00140
00142
00152 template <typename To, typename T>
00153 bool euclidean_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00154 const BD_Shape<T>& x,
00155 const BD_Shape<T>& y,
00156 Rounding_Dir dir);
00157
00159
00169 template <typename Temp, typename To, typename T>
00170 bool euclidean_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00171 const BD_Shape<T>& x,
00172 const BD_Shape<T>& y,
00173 Rounding_Dir dir);
00174
00176
00186 template <typename Temp, typename To, typename T>
00187 bool euclidean_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00188 const BD_Shape<T>& x,
00189 const BD_Shape<T>& y,
00190 Rounding_Dir dir,
00191 Temp& tmp0,
00192 Temp& tmp1,
00193 Temp& tmp2);
00194
00196
00206 template <typename To, typename T>
00207 bool l_infinity_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00208 const BD_Shape<T>& x,
00209 const BD_Shape<T>& y,
00210 Rounding_Dir dir);
00211
00213
00223 template <typename Temp, typename To, typename T>
00224 bool l_infinity_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00225 const BD_Shape<T>& x,
00226 const BD_Shape<T>& y,
00227 Rounding_Dir dir);
00228
00230
00240 template <typename Temp, typename To, typename T>
00241 bool l_infinity_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00242 const BD_Shape<T>& x,
00243 const BD_Shape<T>& y,
00244 Rounding_Dir dir,
00245 Temp& tmp0,
00246 Temp& tmp1,
00247 Temp& tmp2);
00248
00249 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00250
00251
00284 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00285 bool extract_bounded_difference(const Constraint& c,
00286 dimension_type c_space_dim,
00287 dimension_type& c_num_vars,
00288 dimension_type& c_first_var,
00289 dimension_type& c_second_var,
00290 Coefficient& c_coeff);
00291
00292 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00293
00294
00295 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00296 void compute_leader_indices(const std::vector<dimension_type>& predecessor,
00297 std::vector<dimension_type>& indices);
00298
00299 }
00300
00302
00402 template <typename T>
00403 class Parma_Polyhedra_Library::BD_Shape {
00404 private:
00409 #ifndef NDEBUG
00410 typedef Checked_Number<T, Debug_WRD_Extended_Number_Policy> N;
00411 #else
00412 typedef Checked_Number<T, WRD_Extended_Number_Policy> N;
00413 #endif
00414
00415 public:
00417 typedef T coefficient_type_base;
00418
00423 typedef N coefficient_type;
00424
00426 static dimension_type max_space_dimension();
00427
00431 static bool can_recycle_constraint_systems();
00432
00436 static bool can_recycle_congruence_systems();
00437
00439
00440
00442
00449 explicit BD_Shape(dimension_type num_dimensions = 0,
00450 Degenerate_Element kind = UNIVERSE);
00451
00453
00456 BD_Shape(const BD_Shape& y,
00457 Complexity_Class complexity = ANY_COMPLEXITY);
00458
00460
00463 template <typename U>
00464 explicit BD_Shape(const BD_Shape<U>& y,
00465 Complexity_Class complexity = ANY_COMPLEXITY);
00466
00468
00478 explicit BD_Shape(const Constraint_System& cs);
00479
00481
00491 explicit BD_Shape(const Congruence_System& cgs);
00492
00494
00501 explicit BD_Shape(const Generator_System& gs);
00502
00504
00510 explicit BD_Shape(const Polyhedron& ph,
00511 Complexity_Class complexity = ANY_COMPLEXITY);
00512
00514
00529 template <typename Interval>
00530 explicit BD_Shape(const Box<Interval>& box,
00531 Complexity_Class complexity = ANY_COMPLEXITY);
00532
00534
00549 explicit BD_Shape(const Grid& grid,
00550 Complexity_Class complexity = ANY_COMPLEXITY);
00551
00553
00568 template <typename U>
00569 explicit BD_Shape(const Octagonal_Shape<U>& os,
00570 Complexity_Class complexity = ANY_COMPLEXITY);
00571
00576 BD_Shape& operator=(const BD_Shape& y);
00577
00582 void swap(BD_Shape& y);
00583
00585 ~BD_Shape();
00586
00588
00590
00591
00593 dimension_type space_dimension() const;
00594
00600 dimension_type affine_dimension() const;
00601
00603 Constraint_System constraints() const;
00604
00606 Constraint_System minimized_constraints() const;
00607
00609 Congruence_System congruences() const;
00610
00615 Congruence_System minimized_congruences() const;
00616
00624 bool bounds_from_above(const Linear_Expression& expr) const;
00625
00633 bool bounds_from_below(const Linear_Expression& expr) const;
00634
00659 bool maximize(const Linear_Expression& expr,
00660 Coefficient& sup_n, Coefficient& sup_d, bool& maximum) const;
00661
00690 bool maximize(const Linear_Expression& expr,
00691 Coefficient& sup_n, Coefficient& sup_d, bool& maximum,
00692 Generator& g) const;
00693
00718 bool minimize(const Linear_Expression& expr,
00719 Coefficient& inf_n, Coefficient& inf_d, bool& minimum) const;
00720
00749 bool minimize(const Linear_Expression& expr,
00750 Coefficient& inf_n, Coefficient& inf_d, bool& minimum,
00751 Generator& g) const;
00752
00781 bool frequency(const Linear_Expression& expr,
00782 Coefficient& freq_n, Coefficient& freq_d,
00783 Coefficient& val_n, Coefficient& val_d) const;
00784
00786
00790 bool contains(const BD_Shape& y) const;
00791
00793
00797 bool strictly_contains(const BD_Shape& y) const;
00798
00800
00805 bool is_disjoint_from(const BD_Shape& y) const;
00806
00808
00812 Poly_Con_Relation relation_with(const Constraint& c) const;
00813
00815
00819 Poly_Con_Relation relation_with(const Congruence& cg) const;
00820
00822
00826 Poly_Gen_Relation relation_with(const Generator& g) const;
00827
00829 bool is_empty() const;
00830
00832 bool is_universe() const;
00833
00835 bool is_discrete() const;
00836
00841 bool is_topologically_closed() const;
00842
00844 bool is_bounded() const;
00845
00850 bool contains_integer_point() const;
00851
00859 bool constrains(Variable var) const;
00860
00865 bool OK() const;
00866
00868
00870
00871
00883 void add_constraint(const Constraint& c);
00884
00895 void add_congruence(const Congruence& cg);
00896
00909 void add_constraints(const Constraint_System& cs);
00910
00928 void add_recycled_constraints(Constraint_System& cs);
00929
00942 void add_congruences(const Congruence_System& cgs);
00943
00960 void add_recycled_congruences(Congruence_System& cgs);
00961
00972 void refine_with_constraint(const Constraint& c);
00973
00985 void refine_with_congruence(const Congruence& cg);
00986
00998 void refine_with_constraints(const Constraint_System& cs);
00999
01011 void refine_with_congruences(const Congruence_System& cgs);
01012
01023 void unconstrain(Variable var);
01024
01037 void unconstrain(const Variables_Set& vars);
01038
01040
01044 void intersection_assign(const BD_Shape& y);
01045
01053 void upper_bound_assign(const BD_Shape& y);
01054
01063 bool upper_bound_assign_if_exact(const BD_Shape& y);
01064
01079 bool integer_upper_bound_assign_if_exact(const BD_Shape& y);
01080
01088 void difference_assign(const BD_Shape& y);
01089
01099 bool simplify_using_context_assign(const BD_Shape& y);
01100
01120 void affine_image(Variable var,
01121 const Linear_Expression& expr,
01122 Coefficient_traits::const_reference denominator
01123 = Coefficient_one());
01124
01144 void affine_preimage(Variable var,
01145 const Linear_Expression& expr,
01146 Coefficient_traits::const_reference denominator
01147 = Coefficient_one());
01148
01173 void generalized_affine_image(Variable var,
01174 Relation_Symbol relsym,
01175 const Linear_Expression& expr,
01176 Coefficient_traits::const_reference denominator
01177 = Coefficient_one());
01178
01198 void generalized_affine_image(const Linear_Expression& lhs,
01199 Relation_Symbol relsym,
01200 const Linear_Expression& rhs);
01201
01226 void generalized_affine_preimage(Variable var,
01227 Relation_Symbol relsym,
01228 const Linear_Expression& expr,
01229 Coefficient_traits::const_reference
01230 denominator = Coefficient_one());
01231
01251 void generalized_affine_preimage(const Linear_Expression& lhs,
01252 Relation_Symbol relsym,
01253 const Linear_Expression& rhs);
01254
01281 void bounded_affine_image(Variable var,
01282 const Linear_Expression& lb_expr,
01283 const Linear_Expression& ub_expr,
01284 Coefficient_traits::const_reference denominator
01285 = Coefficient_one());
01286
01313 void bounded_affine_preimage(Variable var,
01314 const Linear_Expression& lb_expr,
01315 const Linear_Expression& ub_expr,
01316 Coefficient_traits::const_reference denominator
01317 = Coefficient_one());
01325 void time_elapse_assign(const BD_Shape& y);
01326
01373 void wrap_assign(const Variables_Set& vars,
01374 Bounded_Integer_Type_Width w,
01375 Bounded_Integer_Type_Representation r,
01376 Bounded_Integer_Type_Overflow o,
01377 const Constraint_System* pcs = 0,
01378 unsigned complexity_threshold = 16,
01379 bool wrap_individually = true);
01380
01392 void drop_some_non_integer_points(Complexity_Class complexity
01393 = ANY_COMPLEXITY);
01394
01410 void drop_some_non_integer_points(const Variables_Set& vars,
01411 Complexity_Class complexity
01412 = ANY_COMPLEXITY);
01413
01415 void topological_closure_assign();
01416
01432 void CC76_extrapolation_assign(const BD_Shape& y, unsigned* tp = 0);
01433
01455 template <typename Iterator>
01456 void CC76_extrapolation_assign(const BD_Shape& y,
01457 Iterator first, Iterator last,
01458 unsigned* tp = 0);
01459
01475 void BHMZ05_widening_assign(const BD_Shape& y, unsigned* tp = 0);
01476
01497 void limited_BHMZ05_extrapolation_assign(const BD_Shape& y,
01498 const Constraint_System& cs,
01499 unsigned* tp = 0);
01500
01520 void CC76_narrowing_assign(const BD_Shape& y);
01521
01542 void limited_CC76_extrapolation_assign(const BD_Shape& y,
01543 const Constraint_System& cs,
01544 unsigned* tp = 0);
01545
01561 void H79_widening_assign(const BD_Shape& y, unsigned* tp = 0);
01562
01564 void widening_assign(const BD_Shape& y, unsigned* tp = 0);
01565
01585 void limited_H79_extrapolation_assign(const BD_Shape& y,
01586 const Constraint_System& cs,
01587 unsigned* tp = 0);
01588
01590
01592
01593
01595
01612 void add_space_dimensions_and_embed(dimension_type m);
01613
01635 void add_space_dimensions_and_project(dimension_type m);
01636
01645 void concatenate_assign(const BD_Shape& y);
01646
01648
01656 void remove_space_dimensions(const Variables_Set& vars);
01657
01666 void remove_higher_space_dimensions(dimension_type new_dimension);
01667
01705 template <typename Partial_Function>
01706 void map_space_dimensions(const Partial_Function& pfunc);
01707
01709
01729 void expand_space_dimension(Variable var, dimension_type m);
01730
01732
01754 void fold_space_dimensions(const Variables_Set& vars, Variable dest);
01755
01757
01758 PPL_OUTPUT_DECLARATIONS
01759
01765 bool ascii_load(std::istream& s);
01766
01768 memory_size_type total_memory_in_bytes() const;
01769
01771 memory_size_type external_memory_in_bytes() const;
01772
01779 int32_t hash_code() const;
01780
01781 friend bool operator==<T>(const BD_Shape<T>& x, const BD_Shape<T>& y);
01782
01783 template <typename Temp, typename To, typename U>
01784 friend bool Parma_Polyhedra_Library::rectilinear_distance_assign
01785 (Checked_Number<To, Extended_Number_Policy>& r,
01786 const BD_Shape<U>& x, const BD_Shape<U>& y, const Rounding_Dir dir,
01787 Temp& tmp0, Temp& tmp1, Temp& tmp2);
01788 template <typename Temp, typename To, typename U>
01789 friend bool Parma_Polyhedra_Library::euclidean_distance_assign
01790 (Checked_Number<To, Extended_Number_Policy>& r,
01791 const BD_Shape<U>& x, const BD_Shape<U>& y, const Rounding_Dir dir,
01792 Temp& tmp0, Temp& tmp1, Temp& tmp2);
01793 template <typename Temp, typename To, typename U>
01794 friend bool Parma_Polyhedra_Library::l_infinity_distance_assign
01795 (Checked_Number<To, Extended_Number_Policy>& r,
01796 const BD_Shape<U>& x, const BD_Shape<U>& y, const Rounding_Dir dir,
01797 Temp& tmp0, Temp& tmp1, Temp& tmp2);
01798
01799 private:
01800 template <typename U> friend class Parma_Polyhedra_Library::BD_Shape;
01801 template <typename Interval> friend class Parma_Polyhedra_Library::Box;
01802
01804 DB_Matrix<N> dbm;
01805
01806 #define PPL_IN_BD_Shape_CLASS
01807 #include "BDS_Status.idefs.hh"
01808 #undef PPL_IN_BD_Shape_CLASS
01809
01811 Status status;
01812
01814 Bit_Matrix redundancy_dbm;
01815
01817 bool marked_zero_dim_univ() const;
01818
01825 bool marked_empty() const;
01826
01834 bool marked_shortest_path_closed() const;
01835
01843 bool marked_shortest_path_reduced() const;
01844
01846 void set_empty();
01847
01849 void set_zero_dim_univ();
01850
01852 void set_shortest_path_closed();
01853
01855 void set_shortest_path_reduced();
01856
01858 void reset_shortest_path_closed();
01859
01861 void reset_shortest_path_reduced();
01862
01864 void shortest_path_closure_assign() const;
01865
01871 void shortest_path_reduction_assign() const;
01872
01878 bool is_shortest_path_reduced() const;
01879
01891 void incremental_shortest_path_closure_assign(Variable var) const;
01892
01894
01910 bool bounds(const Linear_Expression& expr, bool from_above) const;
01911
01913
01943 bool max_min(const Linear_Expression& expr,
01944 bool maximize,
01945 Coefficient& ext_n, Coefficient& ext_d, bool& included,
01946 Generator& g) const;
01947
01949
01974 bool max_min(const Linear_Expression& expr,
01975 bool maximize,
01976 Coefficient& ext_n, Coefficient& ext_d, bool& included) const;
01977
01992 bool BFT00_upper_bound_assign_if_exact(const BD_Shape& y);
01993
02010 template <bool integer_upper_bound>
02011 bool BHZ09_upper_bound_assign_if_exact(const BD_Shape& y);
02012
02023 void refine_no_check(const Constraint& c);
02024
02037 void refine_no_check(const Congruence& cg);
02038
02040 void add_dbm_constraint(dimension_type i, dimension_type j, const N& k);
02041
02043 void add_dbm_constraint(dimension_type i, dimension_type j,
02044 Coefficient_traits::const_reference num,
02045 Coefficient_traits::const_reference den);
02046
02053 void refine(Variable var, Relation_Symbol relsym,
02054 const Linear_Expression& expr,
02055 Coefficient_traits::const_reference denominator
02056 = Coefficient_one());
02057
02059 void forget_all_dbm_constraints(dimension_type v);
02061 void forget_binary_dbm_constraints(dimension_type v);
02062
02064
02078 void deduce_v_minus_u_bounds(dimension_type v,
02079 dimension_type last_v,
02080 const Linear_Expression& sc_expr,
02081 Coefficient_traits::const_reference sc_den,
02082 const N& ub_v);
02083
02085
02100 void deduce_u_minus_v_bounds(dimension_type v,
02101 dimension_type last_v,
02102 const Linear_Expression& sc_expr,
02103 Coefficient_traits::const_reference sc_den,
02104 const N& minus_lb_v);
02105
02110 void get_limiting_shape(const Constraint_System& cs,
02111 BD_Shape& limiting_shape) const;
02112
02114
02117 void compute_predecessors(std::vector<dimension_type>& predecessor) const;
02118
02120
02123 void compute_leaders(std::vector<dimension_type>& leaders) const;
02124
02125 void drop_some_non_integer_points_helper(N& elem);
02126
02127 friend std::ostream&
02128 Parma_Polyhedra_Library::IO_Operators
02129 ::operator<<<>(std::ostream& s, const BD_Shape<T>& c);
02130
02132
02133 void throw_dimension_incompatible(const char* method,
02134 const BD_Shape& x) const;
02135
02136 void throw_dimension_incompatible(const char* method,
02137 dimension_type required_dim) const;
02138
02139 void throw_dimension_incompatible(const char* method,
02140 const Constraint& c) const;
02141
02142 void throw_dimension_incompatible(const char* method,
02143 const Congruence& cg) const;
02144
02145 void throw_dimension_incompatible(const char* method,
02146 const Generator& g) const;
02147
02148 void throw_dimension_incompatible(const char* method,
02149 const char* name_row,
02150 const Linear_Expression& y) const;
02151
02152 static void throw_expression_too_complex(const char* method,
02153 const Linear_Expression& e);
02154
02155 static void throw_generic(const char* method, const char* reason);
02157 };
02158
02159
02160 namespace std {
02161
02163
02164 template <typename T>
02165 void swap(Parma_Polyhedra_Library::BD_Shape<T>& x,
02166 Parma_Polyhedra_Library::BD_Shape<T>& y);
02167
02168 }
02169
02170 #include "BDS_Status.inlines.hh"
02171 #include "BD_Shape.inlines.hh"
02172 #include "BD_Shape.templates.hh"
02173
02174 #endif // !defined(PPL_BD_Shape_defs_hh)