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_inlines_hh
00025 #define PPL_Grid_inlines_hh 1
00026
00027 #include "Grid_Generator.defs.hh"
00028 #include "Grid_Generator_System.defs.hh"
00029 #include "Grid_Generator_System.inlines.hh"
00030 #include <algorithm>
00031
00032 namespace Parma_Polyhedra_Library {
00033
00034 inline bool
00035 Grid::marked_empty() const {
00036 return status.test_empty();
00037 }
00038
00039 inline bool
00040 Grid::congruences_are_up_to_date() const {
00041 return status.test_c_up_to_date();
00042 }
00043
00044 inline bool
00045 Grid::generators_are_up_to_date() const {
00046 return status.test_g_up_to_date();
00047 }
00048
00049 inline bool
00050 Grid::congruences_are_minimized() const {
00051 return status.test_c_minimized();
00052 }
00053
00054 inline bool
00055 Grid::generators_are_minimized() const {
00056 return status.test_g_minimized();
00057 }
00058
00059 inline void
00060 Grid::set_generators_up_to_date() {
00061 status.set_g_up_to_date();
00062 }
00063
00064 inline void
00065 Grid::set_congruences_up_to_date() {
00066 status.set_c_up_to_date();
00067 }
00068
00069 inline void
00070 Grid::set_congruences_minimized() {
00071 set_congruences_up_to_date();
00072 status.set_c_minimized();
00073 }
00074
00075 inline void
00076 Grid::set_generators_minimized() {
00077 set_generators_up_to_date();
00078 status.set_g_minimized();
00079 }
00080
00081 inline void
00082 Grid::clear_empty() {
00083 status.reset_empty();
00084 }
00085
00086 inline void
00087 Grid::clear_congruences_minimized() {
00088 status.reset_c_minimized();
00089 }
00090
00091 inline void
00092 Grid::clear_generators_minimized() {
00093 status.reset_g_minimized();
00094 }
00095
00096 inline void
00097 Grid::clear_congruences_up_to_date() {
00098 clear_congruences_minimized();
00099 status.reset_c_up_to_date();
00100
00101 }
00102
00103 inline void
00104 Grid::clear_generators_up_to_date() {
00105 clear_generators_minimized();
00106 status.reset_g_up_to_date();
00107
00108 }
00109
00110 inline dimension_type
00111 Grid::max_space_dimension() {
00112
00113
00114 return std::min(std::numeric_limits<dimension_type>::max() - 1,
00115 std::min(Congruence_System::max_space_dimension(),
00116 Grid_Generator_System::max_space_dimension()
00117 )
00118 );
00119 }
00120
00121 inline
00122 Grid::Grid(dimension_type num_dimensions,
00123 const Degenerate_Element kind)
00124 : con_sys(),
00125 gen_sys(num_dimensions > max_space_dimension()
00126 ? (throw_space_dimension_overflow("Grid(n, k)",
00127 "n exceeds the maximum "
00128 "allowed space dimension"),
00129 0)
00130 : num_dimensions) {
00131 construct(num_dimensions, kind);
00132 PPL_ASSERT(OK());
00133 }
00134
00135 inline
00136 Grid::Grid(const Congruence_System& cgs)
00137 : con_sys(cgs.space_dimension() > max_space_dimension()
00138 ? throw_space_dimension_overflow("Grid(cgs)",
00139 "the space dimension of cgs "
00140 "exceeds the maximum allowed "
00141 "space dimension"), 0
00142 : cgs.space_dimension()),
00143 gen_sys(cgs.space_dimension()) {
00144 Congruence_System cgs_copy(cgs);
00145 construct(cgs_copy);
00146 }
00147
00148 inline
00149 Grid::Grid(Congruence_System& cgs, Recycle_Input)
00150 : con_sys(cgs.space_dimension() > max_space_dimension()
00151 ? throw_space_dimension_overflow("Grid(cgs, recycle)",
00152 "the space dimension of cgs "
00153 "exceeds the maximum allowed "
00154 "space dimension"), 0
00155 : cgs.space_dimension()),
00156 gen_sys(cgs.space_dimension()) {
00157 construct(cgs);
00158 }
00159
00160 inline
00161 Grid::Grid(const Grid_Generator_System& ggs)
00162 : con_sys(ggs.space_dimension() > max_space_dimension()
00163 ? throw_space_dimension_overflow("Grid(ggs)",
00164 "the space dimension of ggs "
00165 "exceeds the maximum allowed "
00166 "space dimension"), 0
00167 : ggs.space_dimension()),
00168 gen_sys(ggs.space_dimension()) {
00169 Grid_Generator_System ggs_copy(ggs);
00170 construct(ggs_copy);
00171 }
00172
00173 inline
00174 Grid::Grid(Grid_Generator_System& ggs, Recycle_Input)
00175 : con_sys(ggs.space_dimension() > max_space_dimension()
00176 ? throw_space_dimension_overflow("Grid(ggs, recycle)",
00177 "the space dimension of ggs "
00178 "exceeds the maximum allowed "
00179 "space dimension"), 0
00180 : ggs.space_dimension()),
00181 gen_sys(ggs.space_dimension()) {
00182 construct(ggs);
00183 }
00184
00185 template <typename U>
00186 inline
00187 Grid::Grid(const BD_Shape<U>& bd,
00188 Complexity_Class)
00189 : con_sys(bd.space_dimension() > max_space_dimension()
00190 ? throw_space_dimension_overflow("Grid(bd)",
00191 "the space dimension of bd "
00192 "exceeds the maximum allowed "
00193 "space dimension"), 0
00194 : bd.space_dimension()),
00195 gen_sys(bd.space_dimension()) {
00196 Congruence_System cgs = bd.congruences();
00197 construct(cgs);
00198 }
00199
00200 template <typename U>
00201 inline
00202 Grid::Grid(const Octagonal_Shape<U>& os,
00203 Complexity_Class)
00204 : con_sys(os.space_dimension() > max_space_dimension()
00205 ? throw_space_dimension_overflow("Grid(os)",
00206 "the space dimension of os "
00207 "exceeds the maximum allowed "
00208 "space dimension"), 0
00209 : os.space_dimension()),
00210 gen_sys(os.space_dimension()) {
00211 Congruence_System cgs = os.congruences();
00212 construct(cgs);
00213 }
00214
00215 inline
00216 Grid::~Grid() {
00217 }
00218
00219 inline dimension_type
00220 Grid::space_dimension() const {
00221 return space_dim;
00222 }
00223
00224 inline memory_size_type
00225 Grid::total_memory_in_bytes() const {
00226 return sizeof(*this) + external_memory_in_bytes();
00227 }
00228
00229 inline int32_t
00230 Grid::hash_code() const {
00231 return space_dimension() & 0x7fffffff;
00232 }
00233
00234 inline Constraint_System
00235 Grid::constraints() const {
00236 return Constraint_System(congruences());;
00237 }
00238
00239 inline Constraint_System
00240 Grid::minimized_constraints() const {
00241 return Constraint_System(minimized_congruences());;
00242 }
00243
00244 inline void
00245 Grid::swap(Grid& y) {
00246 std::swap(con_sys, y.con_sys);
00247 std::swap(gen_sys, y.gen_sys);
00248 std::swap(status, y.status);
00249 std::swap(space_dim, y.space_dim);
00250 std::swap(dim_kinds, y.dim_kinds);
00251 }
00252
00253 inline void
00254 Grid::add_congruence(const Congruence& cg) {
00255
00256 if (space_dim < cg.space_dimension())
00257 throw_dimension_incompatible("add_congruence(cg)", "cg", cg);
00258
00259 if (!marked_empty())
00260 add_congruence_no_check(cg);
00261 }
00262
00263 inline void
00264 Grid::add_congruences(const Congruence_System& cgs) {
00265
00266
00267 if (space_dim < cgs.space_dimension())
00268 throw_dimension_incompatible("add_congruences(cgs)", "cgs", cgs);
00269
00270 if (!marked_empty()) {
00271 Congruence_System cgs_copy = cgs;
00272 add_recycled_congruences(cgs_copy);
00273 }
00274 }
00275
00276 inline void
00277 Grid::refine_with_congruence(const Congruence& cg) {
00278 add_congruence(cg);
00279 }
00280
00281 inline void
00282 Grid::refine_with_congruences(const Congruence_System& cgs) {
00283 add_congruences(cgs);
00284 }
00285
00286 inline bool
00287 Grid::can_recycle_constraint_systems() {
00288 return true;
00289 }
00290
00291 inline bool
00292 Grid::can_recycle_congruence_systems() {
00293 return true;
00294 }
00295
00296 inline void
00297 Grid::add_constraint(const Constraint& c) {
00298
00299 if (space_dim < c.space_dimension())
00300 throw_dimension_incompatible("add_constraint(c)", "c", c);
00301 if (!marked_empty())
00302 add_constraint_no_check(c);
00303 }
00304
00305 inline void
00306 Grid::add_recycled_constraints(Constraint_System& cs) {
00307
00308 add_constraints(cs);
00309 }
00310
00311 inline bool
00312 Grid::bounds_from_above(const Linear_Expression& expr) const {
00313 return bounds(expr, "bounds_from_above(e)");
00314 }
00315
00316 inline bool
00317 Grid::bounds_from_below(const Linear_Expression& expr) const {
00318 return bounds(expr, "bounds_from_below(e)");
00319 }
00320
00321 inline bool
00322 Grid::maximize(const Linear_Expression& expr,
00323 Coefficient& sup_n, Coefficient& sup_d, bool& maximum) const {
00324 return max_min(expr, "maximize(e, ...)", sup_n, sup_d, maximum);
00325 }
00326
00327 inline bool
00328 Grid::maximize(const Linear_Expression& expr,
00329 Coefficient& sup_n, Coefficient& sup_d, bool& maximum,
00330 Generator& point) const {
00331 return max_min(expr, "maximize(e, ...)", sup_n, sup_d, maximum, &point);
00332 }
00333
00334 inline bool
00335 Grid::minimize(const Linear_Expression& expr,
00336 Coefficient& inf_n, Coefficient& inf_d, bool& minimum) const {
00337 return max_min(expr, "minimize(e, ...)", inf_n, inf_d, minimum);
00338 }
00339
00340 inline bool
00341 Grid::minimize(const Linear_Expression& expr,
00342 Coefficient& inf_n, Coefficient& inf_d, bool& minimum,
00343 Generator& point) const {
00344 return max_min(expr, "minimize(e, ...)", inf_n, inf_d, minimum, &point);
00345 }
00346
00347 inline void
00348 Grid::normalize_divisors(Grid_Generator_System& sys) {
00349 PPL_DIRTY_TEMP_COEFFICIENT(divisor);
00350 divisor = 1;
00351 normalize_divisors(sys, divisor);
00352 }
00353
00355 inline bool
00356 operator!=(const Grid& x, const Grid& y) {
00357 return !(x == y);
00358 }
00359
00360 inline bool
00361 Grid::strictly_contains(const Grid& y) const {
00362 const Grid& x = *this;
00363 return x.contains(y) && !y.contains(x);
00364 }
00365
00366 inline void
00367 Grid::topological_closure_assign() {
00368 }
00369
00370 }
00371
00372 namespace std {
00373
00375 inline void
00376 swap(Parma_Polyhedra_Library::Grid& x,
00377 Parma_Polyhedra_Library::Grid& y) {
00378 x.swap(y);
00379 }
00380
00381 }
00382
00383 #endif // !defined(PPL_Grid_inlines_hh)