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_Grid_defs_hh
00025 #define PPL_Grid_defs_hh 1
00026
00027 #include "Grid.types.hh"
00028 #include "globals.defs.hh"
00029 #include "Variable.defs.hh"
00030 #include "Variables_Set.types.hh"
00031 #include "Linear_Expression.defs.hh"
00032 #include "Constraint.types.hh"
00033 #include "Constraint_System.defs.hh"
00034 #include "Constraint_System.inlines.hh"
00035 #include "Congruence_System.defs.hh"
00036 #include "Congruence_System.inlines.hh"
00037 #include "Grid_Generator_System.defs.hh"
00038 #include "Grid_Generator_System.inlines.hh"
00039 #include "Grid_Generator.types.hh"
00040 #include "Poly_Con_Relation.defs.hh"
00041 #include "Poly_Gen_Relation.defs.hh"
00042 #include "Grid_Certificate.types.hh"
00043 #include "Box.types.hh"
00044 #include "Polyhedron.types.hh"
00045 #include "BD_Shape.types.hh"
00046 #include "Octagonal_Shape.types.hh"
00047 #include <vector>
00048 #include <iosfwd>
00049
00050 namespace Parma_Polyhedra_Library {
00051
00052 namespace IO_Operators {
00053
00055
00063 std::ostream&
00064 operator<<(std::ostream& s, const Grid& gr);
00065
00066 }
00067
00076 bool operator==(const Grid& x, const Grid& y);
00077
00086 bool operator!=(const Grid& x, const Grid& y);
00087
00088 }
00089
00090
00092
00359 class Parma_Polyhedra_Library::Grid {
00360 public:
00362 typedef Coefficient coefficient_type;
00363
00365 static dimension_type max_space_dimension();
00366
00371 static bool can_recycle_congruence_systems();
00372
00377 static bool can_recycle_constraint_systems();
00378
00380
00391 explicit Grid(dimension_type num_dimensions = 0,
00392 Degenerate_Element kind = UNIVERSE);
00393
00395
00405 explicit Grid(const Congruence_System& cgs);
00406
00408
00423 Grid(Congruence_System& cgs, Recycle_Input dummy);
00424
00426
00439 explicit Grid(const Constraint_System& cs);
00440
00442
00460 Grid(Constraint_System& cs, Recycle_Input dummy);
00461
00463
00476 explicit Grid(const Grid_Generator_System& const_gs);
00477
00479
00496 Grid(Grid_Generator_System& gs, Recycle_Input dummy);
00497
00499
00514 template <typename Interval>
00515 explicit Grid(const Box<Interval>& box,
00516 Complexity_Class complexity = ANY_COMPLEXITY);
00517
00519
00534 template <typename U>
00535 explicit Grid(const BD_Shape<U>& bd,
00536 Complexity_Class complexity = ANY_COMPLEXITY);
00537
00539
00554 template <typename U>
00555 explicit Grid(const Octagonal_Shape<U>& os,
00556 Complexity_Class complexity = ANY_COMPLEXITY);
00557
00576 explicit Grid(const Polyhedron& ph,
00577 Complexity_Class complexity = ANY_COMPLEXITY);
00578
00580
00583 Grid(const Grid& y,
00584 Complexity_Class complexity = ANY_COMPLEXITY);
00585
00590 Grid& operator=(const Grid& y);
00591
00593
00594
00596 dimension_type space_dimension() const;
00597
00602 dimension_type affine_dimension() const;
00603
00608 Constraint_System constraints() const;
00609
00614 Constraint_System minimized_constraints() const;
00615
00617 const Congruence_System& congruences() const;
00618
00620 const Congruence_System& minimized_congruences() const;
00621
00623 const Grid_Generator_System& grid_generators() const;
00624
00626 const Grid_Generator_System& minimized_grid_generators() const;
00627
00629
00630
00631
00632
00633
00634
00635
00636 Poly_Con_Relation relation_with(const Congruence& cg) const;
00637
00639
00640
00641
00642
00643
00644 Poly_Gen_Relation
00645 relation_with(const Grid_Generator& g) const;
00646
00648
00649
00650
00651
00652
00653 Poly_Gen_Relation
00654 relation_with(const Generator& g) const;
00655
00657
00658
00659
00660
00661
00662
00663
00664 Poly_Con_Relation relation_with(const Constraint& c) const;
00665
00667 bool is_empty() const;
00668
00670 bool is_universe() const;
00671
00678 bool is_topologically_closed() const;
00679
00687 bool is_disjoint_from(const Grid& y) const;
00688
00690
00695 bool is_discrete() const;
00696
00698 bool is_bounded() const;
00699
00704 bool contains_integer_point() const;
00705
00713 bool constrains(Variable var) const;
00714
00716
00722 bool bounds_from_above(const Linear_Expression& expr) const;
00723
00725
00731 bool bounds_from_below(const Linear_Expression& expr) const;
00732
00760 bool maximize(const Linear_Expression& expr,
00761 Coefficient& sup_n, Coefficient& sup_d, bool& maximum) const;
00762
00794 bool maximize(const Linear_Expression& expr,
00795 Coefficient& sup_n, Coefficient& sup_d, bool& maximum,
00796 Generator& point) const;
00797
00825 bool minimize(const Linear_Expression& expr,
00826 Coefficient& inf_n, Coefficient& inf_d, bool& minimum) const;
00827
00859 bool minimize(const Linear_Expression& expr,
00860 Coefficient& inf_n, Coefficient& inf_d, bool& minimum,
00861 Generator& point) const;
00862
00893 bool frequency(const Linear_Expression& expr,
00894 Coefficient& freq_n, Coefficient& freq_d,
00895 Coefficient& val_n, Coefficient& val_d) const;
00896
00898
00902 bool contains(const Grid& y) const;
00903
00911 bool strictly_contains(const Grid& y) const;
00912
00914
00930 bool OK(bool check_not_empty = false) const;
00931
00933
00935
00936
00938
00943 void add_congruence(const Congruence& cg);
00944
00953 void add_grid_generator(const Grid_Generator& g);
00954
00956
00964 void add_congruences(const Congruence_System& cgs);
00965
00967
00979 void add_recycled_congruences(Congruence_System& cgs);
00980
00991 void add_constraint(const Constraint& c);
00992
01004 void add_constraints(const Constraint_System& cs);
01005
01021 void add_recycled_constraints(Constraint_System& cs);
01022
01024
01031 void refine_with_congruence(const Congruence& cg);
01032
01034
01041 void refine_with_congruences(const Congruence_System& cgs);
01042
01044
01052 void refine_with_constraint(const Constraint& c);
01053
01055
01062 void refine_with_constraints(const Constraint_System& cs);
01063
01077 void add_grid_generators(const Grid_Generator_System& gs);
01078
01094 void add_recycled_grid_generators(Grid_Generator_System& gs);
01095
01106 void unconstrain(Variable var);
01107
01120 void unconstrain(const Variables_Set& vars);
01121
01128 void intersection_assign(const Grid& y);
01129
01136 void upper_bound_assign(const Grid& y);
01137
01146 bool upper_bound_assign_if_exact(const Grid& y);
01147
01158 void difference_assign(const Grid& y);
01159
01169 bool simplify_using_context_assign(const Grid& y);
01170
01232 void affine_image(Variable var,
01233 const Linear_Expression& expr,
01234 Coefficient_traits::const_reference denominator
01235 = Coefficient_one());
01236
01296 void affine_preimage(Variable var,
01297 const Linear_Expression& expr,
01298 Coefficient_traits::const_reference denominator
01299 = Coefficient_one());
01300
01331 void
01332 generalized_affine_image(Variable var,
01333 Relation_Symbol relsym,
01334 const Linear_Expression& expr,
01335 Coefficient_traits::const_reference denominator
01336 = Coefficient_one(),
01337 Coefficient_traits::const_reference modulus
01338 = Coefficient_zero());
01339
01370 void
01371 generalized_affine_preimage(Variable var,
01372 Relation_Symbol relsym,
01373 const Linear_Expression& expr,
01374 Coefficient_traits::const_reference denominator
01375 = Coefficient_one(),
01376 Coefficient_traits::const_reference modulus
01377 = Coefficient_zero());
01378
01403 void
01404 generalized_affine_image(const Linear_Expression& lhs,
01405 Relation_Symbol relsym,
01406 const Linear_Expression& rhs,
01407 Coefficient_traits::const_reference modulus
01408 = Coefficient_zero());
01409
01434 void
01435 generalized_affine_preimage(const Linear_Expression& lhs,
01436 Relation_Symbol relsym,
01437 const Linear_Expression& rhs,
01438 Coefficient_traits::const_reference modulus
01439 = Coefficient_zero());
01440
01467 void bounded_affine_image(Variable var,
01468 const Linear_Expression& lb_expr,
01469 const Linear_Expression& ub_expr,
01470 Coefficient_traits::const_reference denominator
01471 = Coefficient_one());
01472
01499 void bounded_affine_preimage(Variable var,
01500 const Linear_Expression& lb_expr,
01501 const Linear_Expression& ub_expr,
01502 Coefficient_traits::const_reference denominator
01503 = Coefficient_one());
01504
01512 void time_elapse_assign(const Grid& y);
01513
01559 void wrap_assign(const Variables_Set& vars,
01560 Bounded_Integer_Type_Width w,
01561 Bounded_Integer_Type_Representation r,
01562 Bounded_Integer_Type_Overflow o,
01563 const Constraint_System* pcs = 0,
01564 unsigned complexity_threshold = 16,
01565 bool wrap_individually = true);
01566
01575 void drop_some_non_integer_points(Complexity_Class complexity
01576 = ANY_COMPLEXITY);
01577
01590 void drop_some_non_integer_points(const Variables_Set& vars,
01591 Complexity_Class complexity
01592 = ANY_COMPLEXITY);
01593
01595 void topological_closure_assign();
01596
01612 void congruence_widening_assign(const Grid& y, unsigned* tp = NULL);
01613
01629 void generator_widening_assign(const Grid& y, unsigned* tp = NULL);
01630
01650 void widening_assign(const Grid& y, unsigned* tp = NULL);
01651
01672 void limited_congruence_extrapolation_assign(const Grid& y,
01673 const Congruence_System& cgs,
01674 unsigned* tp = NULL);
01675
01696 void limited_generator_extrapolation_assign(const Grid& y,
01697 const Congruence_System& cgs,
01698 unsigned* tp = NULL);
01699
01719 void limited_extrapolation_assign(const Grid& y,
01720 const Congruence_System& cgs,
01721 unsigned* tp = NULL);
01722
01724
01726
01727
01754 void add_space_dimensions_and_embed(dimension_type m);
01755
01782 void add_space_dimensions_and_project(dimension_type m);
01783
01792 void concatenate_assign(const Grid& y);
01793
01795
01804 void remove_space_dimensions(const Variables_Set& vars);
01805
01815 void remove_higher_space_dimensions(dimension_type new_dimension);
01816
01864 template <typename Partial_Function>
01865 void map_space_dimensions(const Partial_Function& pfunc);
01866
01868
01890 void expand_space_dimension(Variable var, dimension_type m);
01891
01893
01916 void fold_space_dimensions(const Variables_Set& vars, Variable dest);
01917
01919
01920 friend bool operator==(const Grid& x, const Grid& y);
01921
01922 friend class Parma_Polyhedra_Library::Grid_Certificate;
01923
01924 template <typename Interval> friend class Parma_Polyhedra_Library::Box;
01925
01927
01928
01930 ~Grid();
01931
01936 void swap(Grid& y);
01937
01938 PPL_OUTPUT_DECLARATIONS
01939
01945 bool ascii_load(std::istream& s);
01946
01948 memory_size_type total_memory_in_bytes() const;
01949
01951 memory_size_type external_memory_in_bytes() const;
01952
01959 int32_t hash_code() const;
01960
01962
01963 private:
01964
01966 Congruence_System con_sys;
01967
01969 Grid_Generator_System gen_sys;
01970
01971 #define PPL_IN_Grid_CLASS
01972 #include "Grid_Status.idefs.hh"
01973 #undef PPL_IN_Grid_CLASS
01974
01976 Status status;
01977
01979 dimension_type space_dim;
01980
01981 enum Dimension_Kind {
01982 PARAMETER,
01983 LINE,
01984 GEN_VIRTUAL,
01985 PROPER_CONGRUENCE = PARAMETER,
01986 CON_VIRTUAL = LINE,
01987 EQUALITY = GEN_VIRTUAL
01988 };
01989
01990 typedef std::vector<Dimension_Kind> Dimension_Kinds;
01991
01992
01993
01994
01995
01996
01997
01998 Dimension_Kinds dim_kinds;
01999
02001
02008 void construct(dimension_type num_dimensions, Degenerate_Element kind);
02009
02011
02018 void construct(Congruence_System& cgs);
02019
02021
02028 void construct(Grid_Generator_System& ggs);
02029
02031
02032
02034
02038 bool marked_empty() const;
02039
02041 bool congruences_are_up_to_date() const;
02042
02044 bool generators_are_up_to_date() const;
02045
02047 bool congruences_are_minimized() const;
02048
02050 bool generators_are_minimized() const;
02051
02053
02055
02056
02061 void set_zero_dim_univ();
02062
02067 void set_empty();
02068
02070 void set_congruences_up_to_date();
02071
02073 void set_generators_up_to_date();
02074
02076 void set_congruences_minimized();
02077
02079 void set_generators_minimized();
02080
02082
02084
02085
02087 void clear_empty();
02088
02090 void clear_congruences_up_to_date();
02091
02093 void clear_generators_up_to_date();
02094
02096 void clear_congruences_minimized();
02097
02099 void clear_generators_minimized();
02100
02102
02104
02105
02107 void update_congruences() const;
02108
02110
02118 bool update_generators() const;
02119
02121
02123
02124
02126
02134 bool minimize() const;
02135
02137
02138 enum Three_Valued_Boolean {
02139 TVB_TRUE,
02140 TVB_FALSE,
02141 TVB_DONT_KNOW
02142 };
02143
02145 Three_Valued_Boolean quick_equivalence_test(const Grid& y) const;
02146
02148 bool is_included_in(const Grid& y) const;
02149
02151
02168 bool bounds(const Linear_Expression& expr, const char* method_call) const;
02169
02171
02202 bool max_min(const Linear_Expression& expr,
02203 const char* method_call,
02204 Coefficient& ext_n, Coefficient& ext_d, bool& included,
02205 Generator* point = NULL) const;
02206
02239 bool frequency_no_check(const Linear_Expression& expr,
02240 Coefficient& freq_n, Coefficient& freq_d,
02241 Coefficient& val_n, Coefficient& val_d) const;
02242
02244
02253 bool bounds_no_check(const Linear_Expression& expr) const;
02254
02263 void add_congruence_no_check(const Congruence& cg);
02264
02278 void add_constraint_no_check(const Constraint& c);
02279
02291 void refine_no_check(const Constraint& c);
02292
02294
02295
02297 void select_wider_congruences(const Grid& y,
02298 Congruence_System& selected_cgs) const;
02299
02301 void select_wider_generators(const Grid& y,
02302 Grid_Generator_System& widened_ggs) const;
02303
02305
02307
02320 void add_space_dimensions(Congruence_System& cgs,
02321 Grid_Generator_System& gs,
02322 dimension_type dims);
02323
02325
02338 void add_space_dimensions(Grid_Generator_System& gs,
02339 Congruence_System& cgs,
02340 dimension_type dims);
02341
02343
02344
02346
02363 static void
02364 normalize_divisors(Grid_Generator_System& sys,
02365 Coefficient& divisor,
02366 const Grid_Generator* first_point = NULL);
02367
02369
02377 static void
02378 normalize_divisors(Grid_Generator_System& sys);
02379
02381
02397 static void normalize_divisors(Grid_Generator_System& sys,
02398 Grid_Generator_System& gen_sys);
02399
02404 static void conversion(Congruence_System& source,
02405 Grid_Generator_System& dest,
02406 Dimension_Kinds& dim_kinds);
02407
02412 static void conversion(Grid_Generator_System& source,
02413 Congruence_System& dest,
02414 Dimension_Kinds& dim_kinds);
02415
02417
02421 static bool simplify(Congruence_System& cgs,
02422 Dimension_Kinds& dim_kinds);
02423
02425
02428 static void simplify(Grid_Generator_System& gs,
02429 Dimension_Kinds& dim_kinds);
02430
02432
02436
02437 static void reduce_line_with_line(Grid_Generator& row,
02438 Grid_Generator& pivot,
02439 dimension_type col);
02440
02442
02447
02448 static void reduce_equality_with_equality(Congruence& row,
02449 const Congruence& pivot,
02450 dimension_type col);
02451
02453
02460
02461 template <typename R>
02462 static void reduce_pc_with_pc(R& row,
02463 R& pivot,
02464 dimension_type col,
02465 dimension_type start,
02466 dimension_type end);
02467
02469
02474
02475 static void reduce_parameter_with_line(Grid_Generator& row,
02476 const Grid_Generator& pivot,
02477 dimension_type col,
02478 Grid_Generator_System& sys);
02479
02481
02486
02487 static void reduce_congruence_with_equality(Congruence& row,
02488 const Congruence& pivot,
02489 dimension_type col,
02490 Congruence_System& sys);
02491
02493
02508 template <typename M, typename R>
02509 static void reduce_reduced(M& sys, dimension_type dim,
02510 dimension_type pivot_index,
02511 dimension_type start, dimension_type end,
02512 const Dimension_Kinds& dim_kinds,
02513 bool generators = true);
02514
02516
02517 static void multiply_grid(const Coefficient& multiplier,
02518 Congruence& cg, Congruence_System& dest,
02519 dimension_type num_rows,
02520 dimension_type num_dims);
02521
02523
02524 static void multiply_grid(const Coefficient& multiplier,
02525 Grid_Generator& gen,
02526 Grid_Generator_System& dest,
02527 dimension_type num_rows,
02528 dimension_type num_dims);
02529
02534 static bool lower_triangular(const Congruence_System& sys,
02535 const Dimension_Kinds& dim_kinds);
02536
02541 static bool upper_triangular(const Grid_Generator_System& sys,
02542 const Dimension_Kinds& dim_kinds);
02543
02544 #ifndef NDEBUG
02545
02546
02554 template <typename M, typename R>
02555 static bool rows_are_zero(M& system,
02556 dimension_type first,
02557 dimension_type last,
02558 dimension_type row_size);
02559 #endif
02560
02562
02563 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
02564
02565
02566 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
02567 protected:
02568 void throw_runtime_error(const char* method) const;
02569 void throw_invalid_argument(const char* method, const char* reason) const;
02570
02571 void throw_dimension_incompatible(const char* method,
02572 const char* other_name,
02573 dimension_type other_dim) const;
02574 void throw_dimension_incompatible(const char* method,
02575 const char* gr_name,
02576 const Grid& gr) const;
02577 void throw_dimension_incompatible(const char* method,
02578 const char* e_name,
02579 const Linear_Expression& e) const;
02580 void throw_dimension_incompatible(const char* method,
02581 const char* cg_name,
02582 const Congruence& cg) const;
02583 void throw_dimension_incompatible(const char* method,
02584 const char* c_name,
02585 const Constraint& c) const;
02586 void throw_dimension_incompatible(const char* method,
02587 const char* g_name,
02588 const Grid_Generator& g) const;
02589 void throw_dimension_incompatible(const char* method,
02590 const char* g_name,
02591 const Generator& g) const;
02592 void throw_dimension_incompatible(const char* method,
02593 const char* cgs_name,
02594 const Congruence_System& cgs) const;
02595 void throw_dimension_incompatible(const char* method,
02596 const char* cs_name,
02597 const Constraint_System& cs) const;
02598 void throw_dimension_incompatible(const char* method,
02599 const char* gs_name,
02600 const Grid_Generator_System& gs) const;
02601 void throw_dimension_incompatible(const char* method,
02602 const char* var_name,
02603 Variable var) const;
02604 void throw_dimension_incompatible(const char* method,
02605 dimension_type required_space_dim) const;
02606
02607
02608
02609 static void throw_space_dimension_overflow(const char* method,
02610 const char* reason);
02611
02612 void throw_invalid_constraint(const char* method,
02613 const char* c_name) const;
02614 void throw_invalid_constraints(const char* method,
02615 const char* cs_name) const;
02616 void throw_invalid_generator(const char* method,
02617 const char* g_name) const;
02618 void throw_invalid_generators(const char* method,
02619 const char* gs_name) const;
02620 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
02621
02622 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
02623
02624 };
02625
02626
02627 namespace std {
02628
02630
02631 void swap(Parma_Polyhedra_Library::Grid& x,
02632 Parma_Polyhedra_Library::Grid& y);
02633
02634 }
02635
02636 #include "Grid_Status.inlines.hh"
02637 #include "Grid.inlines.hh"
02638 #include "Grid.templates.hh"
02639
02640 #endif // !defined(PPL_Grid_defs_hh)