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