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_Box_defs_hh
00025 #define PPL_Box_defs_hh 1
00026
00027 #include "Box.types.hh"
00028 #include "globals.types.hh"
00029 #include "Coefficient.defs.hh"
00030 #include "Variable.types.hh"
00031 #include "Variables_Set.types.hh"
00032 #include "Linear_Expression.types.hh"
00033 #include "Constraint.types.hh"
00034 #include "Constraint.defs.hh"
00035 #include "Constraint_System.types.hh"
00036 #include "Generator.types.hh"
00037 #include "Generator_System.types.hh"
00038 #include "Congruence.types.hh"
00039 #include "Congruence_System.types.hh"
00040 #include "BD_Shape.types.hh"
00041 #include "Octagonal_Shape.types.hh"
00042 #include "Poly_Con_Relation.types.hh"
00043 #include "Poly_Gen_Relation.types.hh"
00044 #include "Polyhedron.types.hh"
00045 #include "Grid.types.hh"
00046 #include "Partially_Reduced_Product.types.hh"
00047 #include "intervals.defs.hh"
00048 #include <vector>
00049 #include <iosfwd>
00050
00051 namespace Parma_Polyhedra_Library {
00052
00053 struct Interval_Base;
00054
00056
00060 template <typename ITV>
00061 bool operator==(const Box<ITV>& x, const Box<ITV>& y);
00062
00064
00068 template <typename ITV>
00069 bool operator!=(const Box<ITV>& x, const Box<ITV>& y);
00070
00071 namespace IO_Operators {
00072
00074
00075 template <typename ITV>
00076 std::ostream& operator<<(std::ostream& s, const Box<ITV>& box);
00077
00078 }
00079
00081
00091 template <typename To, typename ITV>
00092 bool
00093 rectilinear_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00094 const Box<ITV>& x,
00095 const Box<ITV>& y,
00096 Rounding_Dir dir);
00097
00099
00109 template <typename Temp, typename To, typename ITV>
00110 bool
00111 rectilinear_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00112 const Box<ITV>& x,
00113 const Box<ITV>& y,
00114 Rounding_Dir dir);
00115
00117
00127 template <typename Temp, typename To, typename ITV>
00128 bool
00129 rectilinear_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00130 const Box<ITV>& x,
00131 const Box<ITV>& y,
00132 Rounding_Dir dir,
00133 Temp& tmp0,
00134 Temp& tmp1,
00135 Temp& tmp2);
00136
00138
00148 template <typename To, typename ITV>
00149 bool
00150 euclidean_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00151 const Box<ITV>& x,
00152 const Box<ITV>& y,
00153 Rounding_Dir dir);
00154
00156
00166 template <typename Temp, typename To, typename ITV>
00167 bool
00168 euclidean_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00169 const Box<ITV>& x,
00170 const Box<ITV>& y,
00171 Rounding_Dir dir);
00172
00174
00184 template <typename Temp, typename To, typename ITV>
00185 bool
00186 euclidean_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00187 const Box<ITV>& x,
00188 const Box<ITV>& y,
00189 Rounding_Dir dir,
00190 Temp& tmp0,
00191 Temp& tmp1,
00192 Temp& tmp2);
00193
00195
00205 template <typename To, typename ITV>
00206 bool
00207 l_infinity_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00208 const Box<ITV>& x,
00209 const Box<ITV>& y,
00210 Rounding_Dir dir);
00211
00213
00223 template <typename Temp, typename To, typename ITV>
00224 bool
00225 l_infinity_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00226 const Box<ITV>& x,
00227 const Box<ITV>& y,
00228 Rounding_Dir dir);
00229
00231
00241 template <typename Temp, typename To, typename ITV>
00242 bool
00243 l_infinity_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00244 const Box<ITV>& x,
00245 const Box<ITV>& y,
00246 Rounding_Dir dir,
00247 Temp& tmp0,
00248 Temp& tmp1,
00249 Temp& tmp2);
00250
00251 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00252
00255 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00256 template <typename Specialization,
00257 typename Temp, typename To, typename ITV>
00258 bool
00259 l_m_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
00260 const Box<ITV>& x, const Box<ITV>& y,
00261 Rounding_Dir dir,
00262 Temp& tmp0, Temp& tmp1, Temp& tmp2);
00263
00264 }
00265
00267
00291 template <typename ITV>
00292 class Parma_Polyhedra_Library::Box {
00293 public:
00295 typedef ITV interval_type;
00296
00298 static dimension_type max_space_dimension();
00299
00303 static bool can_recycle_constraint_systems();
00304
00308 static bool can_recycle_congruence_systems();
00309
00311
00312
00314
00321 explicit Box(dimension_type num_dimensions = 0,
00322 Degenerate_Element kind = UNIVERSE);
00323
00325
00328 Box(const Box& y,
00329 Complexity_Class complexity = ANY_COMPLEXITY);
00330
00332
00335 template <typename Other_ITV>
00336 explicit Box(const Box<Other_ITV>& y,
00337 Complexity_Class complexity = ANY_COMPLEXITY);
00338
00340
00349 explicit Box(const Constraint_System& cs);
00350
00352
00365 Box(const Constraint_System& cs, Recycle_Input dummy);
00366
00368
00375 explicit Box(const Generator_System& gs);
00376
00378
00392 Box(const Generator_System& gs, Recycle_Input dummy);
00393
00404 explicit Box(const Congruence_System& cgs);
00405
00420 Box(const Congruence_System& cgs, Recycle_Input dummy);
00421
00423
00427 template <typename T>
00428 explicit Box(const BD_Shape<T>& bds,
00429 Complexity_Class complexity = POLYNOMIAL_COMPLEXITY);
00430
00432
00436 template <typename T>
00437 explicit Box(const Octagonal_Shape<T>& oct,
00438 Complexity_Class complexity = POLYNOMIAL_COMPLEXITY);
00439
00441
00447 explicit Box(const Polyhedron& ph,
00448 Complexity_Class complexity = ANY_COMPLEXITY);
00449
00451
00455 explicit Box(const Grid& ph,
00456 Complexity_Class complexity = POLYNOMIAL_COMPLEXITY);
00457
00459
00463 template <typename D1, typename D2, typename R>
00464 explicit Box(const Partially_Reduced_Product<D1, D2, R>& dp,
00465 Complexity_Class complexity = ANY_COMPLEXITY);
00466
00471 Box& operator=(const Box& y);
00472
00477 void swap(Box& y);
00478
00480
00482
00483
00485 dimension_type space_dimension() const;
00486
00492 dimension_type affine_dimension() const;
00493
00495 bool is_empty() const;
00496
00498 bool is_universe() const;
00499
00504 bool is_topologically_closed() const;
00505
00507 bool is_discrete() const;
00508
00510 bool is_bounded() const;
00511
00516 bool contains_integer_point() const;
00517
00525 bool constrains(Variable var) const;
00526
00528
00532 Poly_Con_Relation relation_with(const Constraint& c) const;
00533
00535
00539 Poly_Con_Relation relation_with(const Congruence& cg) const;
00540
00542
00546 Poly_Gen_Relation relation_with(const Generator& g) const;
00547
00555 bool bounds_from_above(const Linear_Expression& expr) const;
00556
00564 bool bounds_from_below(const Linear_Expression& expr) const;
00565
00590 bool maximize(const Linear_Expression& expr,
00591 Coefficient& sup_n, Coefficient& sup_d, bool& maximum) const;
00592
00621 bool maximize(const Linear_Expression& expr,
00622 Coefficient& sup_n, Coefficient& sup_d, bool& maximum,
00623 Generator& g) const;
00624
00649 bool minimize(const Linear_Expression& expr,
00650 Coefficient& inf_n, Coefficient& inf_d, bool& minimum) const;
00651
00680 bool minimize(const Linear_Expression& expr,
00681 Coefficient& inf_n, Coefficient& inf_d, bool& minimum,
00682 Generator& g) const;
00683
00712 bool frequency(const Linear_Expression& expr,
00713 Coefficient& freq_n, Coefficient& freq_d,
00714 Coefficient& val_n, Coefficient& val_d) const;
00715
00722 bool contains(const Box& y) const;
00723
00730 bool strictly_contains(const Box& y) const;
00731
00738 bool is_disjoint_from(const Box& y) const;
00739
00744 bool OK() const;
00745
00747
00749
00750
00762 void add_constraint(const Constraint& c);
00763
00776 void add_constraints(const Constraint_System& cs);
00777
00794 void add_recycled_constraints(Constraint_System& cs);
00795
00806 void add_congruence(const Congruence& cg);
00807
00819 void add_congruences(const Congruence_System& cgs);
00820
00837 void add_recycled_congruences(Congruence_System& cgs);
00838
00848 void refine_with_constraint(const Constraint& c);
00849
00869 void refine_with_constraints(const Constraint_System& cs);
00870
00880 void refine_with_congruence(const Congruence& cg);
00881
00891 void refine_with_congruences(const Congruence_System& cgs);
00892
00902 void propagate_constraint(const Constraint& c);
00903
00921 void propagate_constraints(const Constraint_System& cs,
00922 dimension_type max_iterations = 0);
00923
00934 void unconstrain(Variable var);
00935
00948 void unconstrain(const Variables_Set& vars);
00949
00951
00955 void intersection_assign(const Box& y);
00956
00964 void upper_bound_assign(const Box& y);
00965
00974 bool upper_bound_assign_if_exact(const Box& y);
00975
00982 void difference_assign(const Box& y);
00983
00992 bool simplify_using_context_assign(const Box& y);
00993
01015 void affine_image(Variable var,
01016 const Linear_Expression& expr,
01017 Coefficient_traits::const_reference denominator
01018 = Coefficient_one());
01019
01040 void affine_preimage(Variable var,
01041 const Linear_Expression& expr,
01042 Coefficient_traits::const_reference denominator
01043 = Coefficient_one());
01044
01069 void generalized_affine_image(Variable var,
01070 Relation_Symbol relsym,
01071 const Linear_Expression& expr,
01072 Coefficient_traits::const_reference denominator
01073 = Coefficient_one());
01074
01099 void
01100 generalized_affine_preimage(Variable var,
01101 Relation_Symbol relsym,
01102 const Linear_Expression& expr,
01103 Coefficient_traits::const_reference denominator
01104 = Coefficient_one());
01105
01124 void generalized_affine_image(const Linear_Expression& lhs,
01125 Relation_Symbol relsym,
01126 const Linear_Expression& rhs);
01127
01146 void generalized_affine_preimage(const Linear_Expression& lhs,
01147 Relation_Symbol relsym,
01148 const Linear_Expression& rhs);
01149
01175 void bounded_affine_image(Variable var,
01176 const Linear_Expression& lb_expr,
01177 const Linear_Expression& ub_expr,
01178 Coefficient_traits::const_reference denominator
01179 = Coefficient_one());
01180
01206 void bounded_affine_preimage(Variable var,
01207 const Linear_Expression& lb_expr,
01208 const Linear_Expression& ub_expr,
01209 Coefficient_traits::const_reference denominator
01210 = Coefficient_one());
01211
01219 void time_elapse_assign(const Box& y);
01220
01222 void topological_closure_assign();
01223
01264 void wrap_assign(const Variables_Set& vars,
01265 Bounded_Integer_Type_Width w,
01266 Bounded_Integer_Type_Representation r,
01267 Bounded_Integer_Type_Overflow o,
01268 const Constraint_System* pcs = 0,
01269 unsigned complexity_threshold = 16,
01270 bool wrap_individually = true);
01271
01283 void drop_some_non_integer_points(Complexity_Class complexity
01284 = ANY_COMPLEXITY);
01285
01301 void drop_some_non_integer_points(const Variables_Set& vars,
01302 Complexity_Class complexity
01303 = ANY_COMPLEXITY);
01304
01320 template <typename T>
01321 typename Enable_If<Is_Same<T, Box>::value
01322 && Is_Same_Or_Derived<Interval_Base, ITV>::value,
01323 void>::type
01324 CC76_widening_assign(const T& y, unsigned* tp = 0);
01325
01342 template <typename T, typename Iterator>
01343 typename Enable_If<Is_Same<T, Box>::value
01344 && Is_Same_Or_Derived<Interval_Base, ITV>::value,
01345 void>::type
01346 CC76_widening_assign(const T& y,
01347 Iterator first, Iterator last);
01348
01350 void widening_assign(const Box& y, unsigned* tp = 0);
01351
01372 void limited_CC76_extrapolation_assign(const Box& y,
01373 const Constraint_System& cs,
01374 unsigned* tp = 0);
01375
01395 template <typename T>
01396 typename Enable_If<Is_Same<T, Box>::value
01397 && Is_Same_Or_Derived<Interval_Base, ITV>::value,
01398 void>::type
01399 CC76_narrowing_assign(const T& y);
01400
01402
01404
01405
01407
01424 void add_space_dimensions_and_embed(dimension_type m);
01425
01447 void add_space_dimensions_and_project(dimension_type m);
01448
01472 void concatenate_assign(const Box& y);
01473
01475
01483 void remove_space_dimensions(const Variables_Set& vars);
01484
01493 void remove_higher_space_dimensions(dimension_type new_dimension);
01494
01532 template <typename Partial_Function>
01533 void map_space_dimensions(const Partial_Function& pfunc);
01534
01536
01556 void expand_space_dimension(Variable var, dimension_type m);
01557
01559
01581 void fold_space_dimensions(const Variables_Set& vars, Variable dest);
01582
01584
01591 const ITV& get_interval(Variable var) const;
01592
01599 void set_interval(Variable var, const ITV& i);
01600
01622 bool get_lower_bound(dimension_type k, bool& closed,
01623 Coefficient& n, Coefficient& d) const;
01624
01643 bool get_upper_bound(dimension_type k, bool& closed,
01644 Coefficient& n, Coefficient& d) const;
01645
01647 Constraint_System constraints() const;
01648
01650 Constraint_System minimized_constraints() const;
01651
01653 Congruence_System congruences() const;
01654
01656 Congruence_System minimized_congruences() const;
01657
01659 memory_size_type total_memory_in_bytes() const;
01660
01662 memory_size_type external_memory_in_bytes() const;
01663
01664 PPL_OUTPUT_DECLARATIONS
01665
01666 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
01667
01672 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
01673 bool ascii_load(std::istream& s);
01674
01675 private:
01676 template <typename Other_ITV>
01677 friend class Parma_Polyhedra_Library::Box;
01678
01679 friend bool
01680 operator==<ITV>(const Box<ITV>& x, const Box<ITV>& y);
01681
01682 friend std::ostream&
01683 Parma_Polyhedra_Library
01684 ::IO_Operators::operator<<<>(std::ostream& s, const Box<ITV>& box);
01685
01686 template <typename Specialization, typename Temp, typename To, typename I>
01687 friend bool Parma_Polyhedra_Library::l_m_distance_assign
01688 (Checked_Number<To, Extended_Number_Policy>& r,
01689 const Box<I>& x, const Box<I>& y, const Rounding_Dir dir,
01690 Temp& tmp0, Temp& tmp1, Temp& tmp2);
01691
01693 typedef std::vector<ITV> Sequence;
01694
01699 typedef ITV Tmp_Interval_Type;
01700
01702 Sequence seq;
01703
01704 #define PPL_IN_Box_CLASS
01705 #include "Box_Status.idefs.hh"
01706 #undef PPL_IN_Box_CLASS
01707
01709 Status status;
01710
01717 bool marked_empty() const;
01718
01719 public:
01721 void set_empty();
01722
01723 private:
01725 void set_nonempty();
01726
01728 void set_empty_up_to_date();
01729
01731 void reset_empty_up_to_date();
01732
01737 bool check_empty() const;
01738
01743 const ITV& operator[](dimension_type k) const;
01744
01748 static I_Result
01749 refine_interval_no_check(ITV& itv,
01750 Constraint::Type type,
01751 Coefficient_traits::const_reference num,
01752 Coefficient_traits::const_reference den);
01753
01757 void
01758 add_interval_constraint_no_check(dimension_type var_id,
01759 Constraint::Type type,
01760 Coefficient_traits::const_reference num,
01761 Coefficient_traits::const_reference den);
01762
01766 void add_constraint_no_check(const Constraint& c);
01767
01771 void add_constraints_no_check(const Constraint_System& cs);
01772
01776 void add_congruence_no_check(const Congruence& cg);
01777
01781 void add_congruences_no_check(const Congruence_System& cgs);
01782
01793 void refine_no_check(const Constraint& c);
01794
01807 void refine_no_check(const Constraint_System& cs);
01808
01820 void refine_no_check(const Congruence& cg);
01821
01833 void refine_no_check(const Congruence_System& cgs);
01834
01995 void propagate_constraint_no_check(const Constraint& c);
01996
02015 void propagate_constraints_no_check(const Constraint_System& cs,
02016 dimension_type max_iterations);
02017
02019
02035 bool bounds(const Linear_Expression& expr, bool from_above) const;
02036
02038
02067 bool max_min(const Linear_Expression& expr,
02068 bool maximize,
02069 Coefficient& ext_n, Coefficient& ext_d, bool& included,
02070 Generator& g) const;
02071
02073
02097 bool max_min(const Linear_Expression& expr,
02098 bool maximize,
02099 Coefficient& ext_n, Coefficient& ext_d, bool& included) const;
02100
02105 void get_limiting_box(const Constraint_System& cs,
02106 Box& limiting_box) const;
02107
02109
02110 void throw_dimension_incompatible(const char* method,
02111 const Box& x) const;
02112
02113 void throw_dimension_incompatible(const char* method,
02114 dimension_type required_dim) const;
02115
02116 void throw_dimension_incompatible(const char* method,
02117 const Constraint& c) const;
02118
02119 void throw_dimension_incompatible(const char* method,
02120 const Congruence& cg) const;
02121
02122 void throw_dimension_incompatible(const char* method,
02123 const Constraint_System& cs) const;
02124
02125 void throw_dimension_incompatible(const char* method,
02126 const Congruence_System& cgs) const;
02127
02128 void throw_dimension_incompatible(const char* method,
02129 const Generator& g) const;
02130
02131 void throw_dimension_incompatible(const char* method,
02132 const char* name_row,
02133 const Linear_Expression& y) const;
02134
02135 static void throw_space_dimension_overflow(const char* method,
02136 const char* reason);
02137
02138 static void throw_constraint_incompatible(const char* method);
02139
02140 static void throw_expression_too_complex(const char* method,
02141 const Linear_Expression& e);
02142
02143 static void throw_generic(const char* method, const char* reason);
02145 };
02146
02147 namespace Parma_Polyhedra_Library {
02148
02149 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
02150
02171 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
02172 template <typename ITV>
02173 Poly_Con_Relation
02174 interval_relation(const ITV& i,
02175 const Constraint::Type constraint_type,
02176 Coefficient_traits::const_reference num,
02177 Coefficient_traits::const_reference den = 1);
02178
02179 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
02180
02181
02204 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
02205 bool extract_interval_constraint(const Constraint& c,
02206 dimension_type c_space_dim,
02207 dimension_type& c_num_vars,
02208 dimension_type& c_only_var);
02209
02210 bool extract_interval_congruence(const Congruence& cg,
02211 dimension_type cg_space_dim,
02212 dimension_type& cg_num_vars,
02213 dimension_type& cg_only_var);
02214
02215 }
02216
02217 #include "Box_Status.inlines.hh"
02218 #include "Box.inlines.hh"
02219 #include "Box.templates.hh"
02220
02221 #endif // !defined(PPL_Box_defs_hh)