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_Polyhedron_defs_hh
00025 #define PPL_Polyhedron_defs_hh 1
00026
00027 #include "Polyhedron.types.hh"
00028 #include "globals.types.hh"
00029 #include "Variable.defs.hh"
00030 #include "Variables_Set.types.hh"
00031 #include "Linear_Expression.types.hh"
00032 #include "Constraint_System.defs.hh"
00033 #include "Constraint_System.inlines.hh"
00034 #include "Generator_System.defs.hh"
00035 #include "Generator_System.inlines.hh"
00036 #include "Congruence_System.defs.hh"
00037 #include "Congruence_System.inlines.hh"
00038 #include "Grid_Generator_System.defs.hh"
00039 #include "Grid_Generator_System.inlines.hh"
00040 #include "Bit_Matrix.defs.hh"
00041 #include "Constraint.types.hh"
00042 #include "Generator.types.hh"
00043 #include "Congruence.types.hh"
00044 #include "Poly_Con_Relation.defs.hh"
00045 #include "Poly_Gen_Relation.defs.hh"
00046 #include "BHRZ03_Certificate.types.hh"
00047 #include "H79_Certificate.types.hh"
00048 #include "Box.types.hh"
00049 #include "BD_Shape.types.hh"
00050 #include "Octagonal_Shape.types.hh"
00051 #include <vector>
00052 #include <iosfwd>
00053
00054 namespace Parma_Polyhedra_Library {
00055
00056 namespace IO_Operators {
00057
00059
00067 std::ostream&
00068 operator<<(std::ostream& s, const Polyhedron& ph);
00069
00070 }
00071
00080 bool operator==(const Polyhedron& x, const Polyhedron& y);
00081
00090 bool operator!=(const Polyhedron& x, const Polyhedron& y);
00091
00092 namespace Interfaces {
00093
00094 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00095
00099 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00100 bool is_necessarily_closed_for_interfaces(const Polyhedron& ph);
00101
00102 }
00103
00104 }
00105
00106
00108
00365 class Parma_Polyhedra_Library::Polyhedron {
00366 public:
00368 typedef Coefficient coefficient_type;
00369
00371 static dimension_type max_space_dimension();
00372
00377 static bool can_recycle_constraint_systems();
00378
00380 static void initialize();
00381
00383 static void finalize();
00384
00388 static bool can_recycle_congruence_systems();
00389
00390 protected:
00392
00402 Polyhedron(Topology topol,
00403 dimension_type num_dimensions,
00404 Degenerate_Element kind);
00405
00407
00410 Polyhedron(const Polyhedron& y,
00411 Complexity_Class complexity = ANY_COMPLEXITY);
00412
00414
00426 Polyhedron(Topology topol, const Constraint_System& cs);
00427
00429
00447 Polyhedron(Topology topol, Constraint_System& cs, Recycle_Input dummy);
00448
00450
00463 Polyhedron(Topology topol, const Generator_System& gs);
00464
00466
00485 Polyhedron(Topology topol, Generator_System& gs, Recycle_Input dummy);
00486
00488
00501 template <typename Interval>
00502 Polyhedron(Topology topol, const Box<Interval>& box,
00503 Complexity_Class complexity = ANY_COMPLEXITY);
00504
00509 Polyhedron& operator=(const Polyhedron& y);
00510
00511 public:
00513
00514
00516 dimension_type space_dimension() const;
00517
00523 dimension_type affine_dimension() const;
00524
00526 const Constraint_System& constraints() const;
00527
00529 const Constraint_System& minimized_constraints() const;
00530
00532 const Generator_System& generators() const;
00533
00535 const Generator_System& minimized_generators() const;
00536
00538 Congruence_System congruences() const;
00539
00545 Congruence_System minimized_congruences() const;
00546
00548 Grid_Generator_System grid_generators() const;
00549
00551 Grid_Generator_System minimized_grid_generators() const;
00552
00560 Poly_Con_Relation relation_with(const Constraint& c) const;
00561
00569 Poly_Gen_Relation relation_with(const Generator& g) const;
00570
00578 Poly_Con_Relation relation_with(const Congruence& cg) const;
00579
00584 bool is_empty() const;
00585
00590 bool is_universe() const;
00591
00596 bool is_topologically_closed() const;
00597
00599
00604 bool is_disjoint_from(const Polyhedron& y) const;
00605
00607 bool is_discrete() const;
00608
00613 bool is_bounded() const;
00614
00619 bool contains_integer_point() const;
00620
00628 bool constrains(Variable var) const;
00629
00637 bool bounds_from_above(const Linear_Expression& expr) const;
00638
00646 bool bounds_from_below(const Linear_Expression& expr) const;
00647
00672 bool maximize(const Linear_Expression& expr,
00673 Coefficient& sup_n, Coefficient& sup_d, bool& maximum) const;
00674
00703 bool maximize(const Linear_Expression& expr,
00704 Coefficient& sup_n, Coefficient& sup_d, bool& maximum,
00705 Generator& g) const;
00706
00731 bool minimize(const Linear_Expression& expr,
00732 Coefficient& inf_n, Coefficient& inf_d, bool& minimum) const;
00733
00762 bool minimize(const Linear_Expression& expr,
00763 Coefficient& inf_n, Coefficient& inf_d, bool& minimum,
00764 Generator& g) const;
00765
00794 bool frequency(const Linear_Expression& expr,
00795 Coefficient& freq_n, Coefficient& freq_d,
00796 Coefficient& val_n, Coefficient& val_d) const;
00797
00799
00804 bool contains(const Polyhedron& y) const;
00805
00807
00812 bool strictly_contains(const Polyhedron& y) const;
00813
00815
00831 bool OK(bool check_not_empty = false) const;
00832
00834
00836
00837
00850 void add_constraint(const Constraint& c);
00851
00861 void add_generator(const Generator& g);
00862
00872 void add_congruence(const Congruence& cg);
00873
00886 void add_constraints(const Constraint_System& cs);
00887
00904 void add_recycled_constraints(Constraint_System& cs);
00905
00919 void add_generators(const Generator_System& gs);
00920
00938 void add_recycled_generators(Generator_System& gs);
00939
00952 void add_congruences(const Congruence_System& cgs);
00953
00970 void add_recycled_congruences(Congruence_System& cgs);
00971
00978 void refine_with_constraint(const Constraint& c);
00979
00986 void refine_with_congruence(const Congruence& cg);
00987
00998 void refine_with_constraints(const Constraint_System& cs);
00999
01010 void refine_with_congruences(const Congruence_System& cgs);
01011
01022 void unconstrain(Variable var);
01023
01036 void unconstrain(const Variables_Set& vars);
01037
01045 void intersection_assign(const Polyhedron& y);
01046
01054 void poly_hull_assign(const Polyhedron& y);
01055
01057 void upper_bound_assign(const Polyhedron& y);
01058
01068 void poly_difference_assign(const Polyhedron& y);
01069
01071 void difference_assign(const Polyhedron& y);
01072
01082 bool simplify_using_context_assign(const Polyhedron& y);
01083
01173 void affine_image(Variable var,
01174 const Linear_Expression& expr,
01175 Coefficient_traits::const_reference denominator
01176 = Coefficient_one());
01177
01265 void affine_preimage(Variable var,
01266 const Linear_Expression& expr,
01267 Coefficient_traits::const_reference denominator
01268 = Coefficient_one());
01269
01296 void generalized_affine_image(Variable var,
01297 Relation_Symbol relsym,
01298 const Linear_Expression& expr,
01299 Coefficient_traits::const_reference denominator
01300 = Coefficient_one());
01301
01328 void
01329 generalized_affine_preimage(Variable var,
01330 Relation_Symbol relsym,
01331 const Linear_Expression& expr,
01332 Coefficient_traits::const_reference denominator
01333 = Coefficient_one());
01334
01355 void generalized_affine_image(const Linear_Expression& lhs,
01356 Relation_Symbol relsym,
01357 const Linear_Expression& rhs);
01358
01379 void generalized_affine_preimage(const Linear_Expression& lhs,
01380 Relation_Symbol relsym,
01381 const Linear_Expression& rhs);
01382
01409 void bounded_affine_image(Variable var,
01410 const Linear_Expression& lb_expr,
01411 const Linear_Expression& ub_expr,
01412 Coefficient_traits::const_reference denominator
01413 = Coefficient_one());
01414
01441 void bounded_affine_preimage(Variable var,
01442 const Linear_Expression& lb_expr,
01443 const Linear_Expression& ub_expr,
01444 Coefficient_traits::const_reference denominator
01445 = Coefficient_one());
01446
01455 void time_elapse_assign(const Polyhedron& y);
01456
01503 void wrap_assign(const Variables_Set& vars,
01504 Bounded_Integer_Type_Width w,
01505 Bounded_Integer_Type_Representation r,
01506 Bounded_Integer_Type_Overflow o,
01507 const Constraint_System* pcs = 0,
01508 unsigned complexity_threshold = 16,
01509 bool wrap_individually = true);
01510
01522 void drop_some_non_integer_points(Complexity_Class complexity
01523 = ANY_COMPLEXITY);
01524
01540 void drop_some_non_integer_points(const Variables_Set& vars,
01541 Complexity_Class complexity
01542 = ANY_COMPLEXITY);
01543
01545 void topological_closure_assign();
01546
01563 void BHRZ03_widening_assign(const Polyhedron& y, unsigned* tp = 0);
01564
01586 void limited_BHRZ03_extrapolation_assign(const Polyhedron& y,
01587 const Constraint_System& cs,
01588 unsigned* tp = 0);
01589
01611 void bounded_BHRZ03_extrapolation_assign(const Polyhedron& y,
01612 const Constraint_System& cs,
01613 unsigned* tp = 0);
01614
01631 void H79_widening_assign(const Polyhedron& y, unsigned* tp = 0);
01632
01634 void widening_assign(const Polyhedron& y, unsigned* tp = 0);
01635
01657 void limited_H79_extrapolation_assign(const Polyhedron& y,
01658 const Constraint_System& cs,
01659 unsigned* tp = 0);
01660
01682 void bounded_H79_extrapolation_assign(const Polyhedron& y,
01683 const Constraint_System& cs,
01684 unsigned* tp = 0);
01685
01687
01689
01690
01716 void add_space_dimensions_and_embed(dimension_type m);
01717
01743 void add_space_dimensions_and_project(dimension_type m);
01744
01756 void concatenate_assign(const Polyhedron& y);
01757
01759
01768 void remove_space_dimensions(const Variables_Set& vars);
01769
01778 void remove_higher_space_dimensions(dimension_type new_dimension);
01779
01820 template <typename Partial_Function>
01821 void map_space_dimensions(const Partial_Function& pfunc);
01822
01824
01844 void expand_space_dimension(Variable var, dimension_type m);
01845
01847
01869 void fold_space_dimensions(const Variables_Set& vars, Variable dest);
01870
01872
01873 friend bool operator==(const Polyhedron& x, const Polyhedron& y);
01874
01876
01877
01879 ~Polyhedron();
01880
01888 void swap(Polyhedron& y);
01889
01890 PPL_OUTPUT_DECLARATIONS
01891
01897 bool ascii_load(std::istream& s);
01898
01900 memory_size_type total_memory_in_bytes() const;
01901
01903 memory_size_type external_memory_in_bytes() const;
01904
01911 int32_t hash_code() const;
01912
01914
01915 private:
01917 Constraint_System con_sys;
01918
01920 Generator_System gen_sys;
01921
01923 Bit_Matrix sat_c;
01924
01926 Bit_Matrix sat_g;
01927
01928 #define PPL_IN_Polyhedron_CLASS
01929 #include "Ph_Status.idefs.hh"
01930 #undef PPL_IN_Polyhedron_CLASS
01931
01933 Status status;
01934
01936 dimension_type space_dim;
01937
01939 Topology topology() const;
01940
01945 bool is_necessarily_closed() const;
01946
01947 friend bool
01948 Parma_Polyhedra_Library::Interfaces
01949 ::is_necessarily_closed_for_interfaces(const Polyhedron&);
01950
01958 void refine_no_check(const Constraint& c);
01959
01961
01962
01964
01968 bool marked_empty() const;
01969
01971 bool constraints_are_up_to_date() const;
01972
01974 bool generators_are_up_to_date() const;
01975
01977
01981 bool constraints_are_minimized() const;
01982
01984
01988 bool generators_are_minimized() const;
01989
01991 bool has_pending_constraints() const;
01992
01994 bool has_pending_generators() const;
01995
02000 bool has_something_pending() const;
02001
02003 bool can_have_something_pending() const;
02004
02009 bool sat_c_is_up_to_date() const;
02010
02015 bool sat_g_is_up_to_date() const;
02016
02018
02020
02021
02026 void set_zero_dim_univ();
02027
02032 void set_empty();
02033
02035 void set_constraints_up_to_date();
02036
02038 void set_generators_up_to_date();
02039
02041 void set_constraints_minimized();
02042
02044 void set_generators_minimized();
02045
02047 void set_constraints_pending();
02048
02050 void set_generators_pending();
02051
02053 void set_sat_c_up_to_date();
02054
02056 void set_sat_g_up_to_date();
02057
02059
02061
02062
02064 void clear_empty();
02065
02067
02071 void clear_constraints_up_to_date();
02072
02074
02078 void clear_generators_up_to_date();
02079
02081 void clear_constraints_minimized();
02082
02084 void clear_generators_minimized();
02085
02087 void clear_pending_constraints();
02088
02090 void clear_pending_generators();
02091
02093 void clear_sat_c_up_to_date();
02094
02096 void clear_sat_g_up_to_date();
02097
02099
02101
02102
02114 bool process_pending() const;
02115
02117
02124 bool process_pending_constraints() const;
02125
02127
02130 void process_pending_generators() const;
02131
02139 void remove_pending_to_obtain_constraints() const;
02140
02152 bool remove_pending_to_obtain_generators() const;
02153
02155
02157
02158
02160
02165 void update_constraints() const;
02166
02168
02179 bool update_generators() const;
02180
02182
02196 void update_sat_c() const;
02197
02199
02213 void update_sat_g() const;
02214
02216
02225 void obtain_sorted_constraints() const;
02226
02228
02237 void obtain_sorted_generators() const;
02238
02240
02247 void obtain_sorted_constraints_with_sat_c() const;
02248
02250
02257 void obtain_sorted_generators_with_sat_g() const;
02258
02260
02262
02263
02265
02273 bool minimize() const;
02274
02276
02281 bool strongly_minimize_constraints() const;
02282
02284
02289 bool strongly_minimize_generators() const;
02290
02292 Constraint_System simplified_constraints() const;
02293
02295
02296 enum Three_Valued_Boolean {
02297 TVB_TRUE,
02298 TVB_FALSE,
02299 TVB_DONT_KNOW
02300 };
02301
02303 Three_Valued_Boolean quick_equivalence_test(const Polyhedron& y) const;
02304
02306 bool is_included_in(const Polyhedron& y) const;
02307
02309
02325 bool bounds(const Linear_Expression& expr, bool from_above) const;
02326
02328
02358 bool max_min(const Linear_Expression& expr,
02359 bool maximize,
02360 Coefficient& ext_n, Coefficient& ext_d, bool& included,
02361 Generator& g) const;
02362
02364
02365
02370 void select_CH78_constraints(const Polyhedron& y,
02371 Constraint_System& cs_selected) const;
02372
02378 void select_H79_constraints(const Polyhedron& y,
02379 Constraint_System& cs_selected,
02380 Constraint_System& cs_not_selected) const;
02381
02382 bool BHRZ03_combining_constraints(const Polyhedron& y,
02383 const BHRZ03_Certificate& y_cert,
02384 const Polyhedron& H79,
02385 const Constraint_System& x_minus_H79_con_sys);
02386
02387 bool BHRZ03_evolving_points(const Polyhedron& y,
02388 const BHRZ03_Certificate& y_cert,
02389 const Polyhedron& H79);
02390
02391 bool BHRZ03_evolving_rays(const Polyhedron& y,
02392 const BHRZ03_Certificate& y_cert,
02393 const Polyhedron& H79);
02394
02396
02398
02423 static void add_space_dimensions(Linear_System& mat1,
02424 Linear_System& mat2,
02425 Bit_Matrix& sat1,
02426 Bit_Matrix& sat2,
02427 dimension_type add_dim);
02428
02430
02431
02433
02434 static bool minimize(bool con_to_gen,
02435 Linear_System& source,
02436 Linear_System& dest,
02437 Bit_Matrix& sat);
02438
02443
02444 static bool add_and_minimize(bool con_to_gen,
02445 Linear_System& source1,
02446 Linear_System& dest,
02447 Bit_Matrix& sat,
02448 const Linear_System& source2);
02449
02454
02455 static bool add_and_minimize(bool con_to_gen,
02456 Linear_System& source,
02457 Linear_System& dest,
02458 Bit_Matrix& sat);
02459
02461
02462 static dimension_type conversion(Linear_System& source,
02463 dimension_type start,
02464 Linear_System& dest,
02465 Bit_Matrix& sat,
02466 dimension_type num_lines_or_equalities);
02467
02472
02473 static dimension_type simplify(Linear_System& mat, Bit_Matrix& sat);
02474
02476
02484 static dimension_type* simplify_num_saturators_p;
02485
02492 static size_t simplify_num_saturators_size;
02493
02494 template <typename Interval> friend class Parma_Polyhedra_Library::Box;
02495 template <typename T> friend class Parma_Polyhedra_Library::BD_Shape;
02496 template <typename T> friend class Parma_Polyhedra_Library::Octagonal_Shape;
02497 friend class Parma_Polyhedra_Library::Grid;
02498 friend class Parma_Polyhedra_Library::BHRZ03_Certificate;
02499 friend class Parma_Polyhedra_Library::H79_Certificate;
02500
02501 protected:
02502 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
02503
02517 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
02518 bool BFT00_poly_hull_assign_if_exact(const Polyhedron& y);
02519
02520 bool BHZ09_poly_hull_assign_if_exact(const Polyhedron& y);
02521 bool BHZ09_C_poly_hull_assign_if_exact(const Polyhedron& y);
02522 bool BHZ09_NNC_poly_hull_assign_if_exact(const Polyhedron& y);
02523
02524 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
02525
02526
02527 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
02528 protected:
02529 void throw_runtime_error(const char* method) const;
02530 void throw_invalid_argument(const char* method, const char* reason) const;
02531
02532 void throw_topology_incompatible(const char* method,
02533 const char* ph_name,
02534 const Polyhedron& ph) const;
02535 void throw_topology_incompatible(const char* method,
02536 const char* c_name,
02537 const Constraint& c) const;
02538 void throw_topology_incompatible(const char* method,
02539 const char* g_name,
02540 const Generator& g) const;
02541 void throw_topology_incompatible(const char* method,
02542 const char* cs_name,
02543 const Constraint_System& cs) const;
02544 void throw_topology_incompatible(const char* method,
02545 const char* gs_name,
02546 const Generator_System& gs) const;
02547
02548 void throw_dimension_incompatible(const char* method,
02549 const char* other_name,
02550 dimension_type other_dim) const;
02551 void throw_dimension_incompatible(const char* method,
02552 const char* ph_name,
02553 const Polyhedron& ph) const;
02554 void throw_dimension_incompatible(const char* method,
02555 const char* e_name,
02556 const Linear_Expression& e) const;
02557 void throw_dimension_incompatible(const char* method,
02558 const char* c_name,
02559 const Constraint& c) const;
02560 void throw_dimension_incompatible(const char* method,
02561 const char* g_name,
02562 const Generator& g) const;
02563 void throw_dimension_incompatible(const char* method,
02564 const char* cg_name,
02565 const Congruence& cg) const;
02566 void throw_dimension_incompatible(const char* method,
02567 const char* cs_name,
02568 const Constraint_System& cs) const;
02569 void throw_dimension_incompatible(const char* method,
02570 const char* gs_name,
02571 const Generator_System& gs) const;
02572 void throw_dimension_incompatible(const char* method,
02573 const char* cgs_name,
02574 const Congruence_System& cgs) const;
02575 void throw_dimension_incompatible(const char* method,
02576 const char* var_name,
02577 Variable var) const;
02578 void throw_dimension_incompatible(const char* method,
02579 dimension_type required_space_dim) const;
02580
02581
02582
02583 static void throw_space_dimension_overflow(Topology topol,
02584 const char* method,
02585 const char* reason);
02586
02587 void throw_invalid_generator(const char* method,
02588 const char* g_name) const;
02589 void throw_invalid_generators(const char* method,
02590 const char* gs_name) const;
02591 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
02592
02593 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
02594
02610 void drop_some_non_integer_points(const Variables_Set* pvars,
02611 Complexity_Class complexity);
02612
02613 };
02614
02615 namespace std {
02616
02618
02619 void swap(Parma_Polyhedra_Library::Polyhedron& x,
02620 Parma_Polyhedra_Library::Polyhedron& y);
02621
02622 }
02623
02624 #include "Ph_Status.inlines.hh"
02625 #include "Polyhedron.inlines.hh"
02626 #include "Polyhedron.templates.hh"
02627
02628 #endif // !defined(PPL_Polyhedron_defs_hh)