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_inlines_hh
00025 #define PPL_Polyhedron_inlines_hh 1
00026
00027 #include "Generator.defs.hh"
00028 #include "compiler.hh"
00029 #include <algorithm>
00030 #include <deque>
00031
00032 namespace Parma_Polyhedra_Library {
00033
00034 inline memory_size_type
00035 Polyhedron::total_memory_in_bytes() const {
00036 return sizeof(*this) + external_memory_in_bytes();
00037 }
00038
00039 inline dimension_type
00040 Polyhedron::space_dimension() const {
00041 return space_dim;
00042 }
00043
00044 inline int32_t
00045 Polyhedron::hash_code() const {
00046 return space_dimension() & 0x7fffffff;
00047 }
00048
00049 inline dimension_type
00050 Polyhedron::max_space_dimension() {
00051 using std::min;
00052
00053
00054 return min(std::numeric_limits<dimension_type>::max() - 1,
00055 min(Constraint_System::max_space_dimension(),
00056 Generator_System::max_space_dimension()
00057 )
00058 );
00059 }
00060
00061 inline Topology
00062 Polyhedron::topology() const {
00063
00064
00065 return con_sys.topology();
00066 }
00067
00068 inline bool
00069 Polyhedron::is_discrete() const {
00070 return affine_dimension() == 0;
00071 }
00072
00073 inline bool
00074 Polyhedron::is_necessarily_closed() const {
00075
00076
00077 return con_sys.is_necessarily_closed();
00078 }
00079
00080 inline void
00081 Polyhedron::upper_bound_assign(const Polyhedron& y) {
00082 poly_hull_assign(y);
00083 }
00084
00085 inline void
00086 Polyhedron::difference_assign(const Polyhedron& y) {
00087 poly_difference_assign(y);
00088 }
00089
00090 inline void
00091 Polyhedron::widening_assign(const Polyhedron& y, unsigned* tp) {
00092 H79_widening_assign(y, tp);
00093 }
00094
00095 inline
00096 Polyhedron::~Polyhedron() {
00097 }
00098
00099 inline void
00100 Polyhedron::swap(Polyhedron& y) {
00101 if (topology() != y.topology())
00102 throw_topology_incompatible("swap(y)", "y", y);
00103 std::swap(con_sys, y.con_sys);
00104 std::swap(gen_sys, y.gen_sys);
00105 std::swap(sat_c, y.sat_c);
00106 std::swap(sat_g, y.sat_g);
00107 std::swap(status, y.status);
00108 std::swap(space_dim, y.space_dim);
00109 }
00110
00111 inline bool
00112 Polyhedron::can_recycle_constraint_systems() {
00113 return true;
00114 }
00115
00116
00117 inline bool
00118 Polyhedron::can_recycle_congruence_systems() {
00119 return false;
00120 }
00121
00122 inline bool
00123 Polyhedron::marked_empty() const {
00124 return status.test_empty();
00125 }
00126
00127 inline bool
00128 Polyhedron::constraints_are_up_to_date() const {
00129 return status.test_c_up_to_date();
00130 }
00131
00132 inline bool
00133 Polyhedron::generators_are_up_to_date() const {
00134 return status.test_g_up_to_date();
00135 }
00136
00137 inline bool
00138 Polyhedron::constraints_are_minimized() const {
00139 return status.test_c_minimized();
00140 }
00141
00142 inline bool
00143 Polyhedron::generators_are_minimized() const {
00144 return status.test_g_minimized();
00145 }
00146
00147 inline bool
00148 Polyhedron::sat_c_is_up_to_date() const {
00149 return status.test_sat_c_up_to_date();
00150 }
00151
00152 inline bool
00153 Polyhedron::sat_g_is_up_to_date() const {
00154 return status.test_sat_g_up_to_date();
00155 }
00156
00157 inline bool
00158 Polyhedron::has_pending_constraints() const {
00159 return status.test_c_pending();
00160 }
00161
00162 inline bool
00163 Polyhedron::has_pending_generators() const {
00164 return status.test_g_pending();
00165 }
00166
00167 inline bool
00168 Polyhedron::has_something_pending() const {
00169 return status.test_c_pending() || status.test_g_pending();
00170 }
00171
00172 inline bool
00173 Polyhedron::can_have_something_pending() const {
00174 return constraints_are_minimized()
00175 && generators_are_minimized()
00176 && (sat_c_is_up_to_date() || sat_g_is_up_to_date());
00177 }
00178
00179 inline bool
00180 Polyhedron::is_empty() const {
00181 if (marked_empty())
00182 return true;
00183
00184
00185
00186 if (generators_are_up_to_date() && !has_pending_constraints())
00187 return false;
00188 return !minimize();
00189 }
00190
00191 inline void
00192 Polyhedron::set_constraints_up_to_date() {
00193 status.set_c_up_to_date();
00194 }
00195
00196 inline void
00197 Polyhedron::set_generators_up_to_date() {
00198 status.set_g_up_to_date();
00199 }
00200
00201 inline void
00202 Polyhedron::set_constraints_minimized() {
00203 set_constraints_up_to_date();
00204 status.set_c_minimized();
00205 }
00206
00207 inline void
00208 Polyhedron::set_generators_minimized() {
00209 set_generators_up_to_date();
00210 status.set_g_minimized();
00211 }
00212
00213 inline void
00214 Polyhedron::set_constraints_pending() {
00215 status.set_c_pending();
00216 }
00217
00218 inline void
00219 Polyhedron::set_generators_pending() {
00220 status.set_g_pending();
00221 }
00222
00223 inline void
00224 Polyhedron::set_sat_c_up_to_date() {
00225 status.set_sat_c_up_to_date();
00226 }
00227
00228 inline void
00229 Polyhedron::set_sat_g_up_to_date() {
00230 status.set_sat_g_up_to_date();
00231 }
00232
00233 inline void
00234 Polyhedron::clear_empty() {
00235 status.reset_empty();
00236 }
00237
00238 inline void
00239 Polyhedron::clear_constraints_minimized() {
00240 status.reset_c_minimized();
00241 }
00242
00243 inline void
00244 Polyhedron::clear_generators_minimized() {
00245 status.reset_g_minimized();
00246 }
00247
00248 inline void
00249 Polyhedron::clear_pending_constraints() {
00250 status.reset_c_pending();
00251 }
00252
00253 inline void
00254 Polyhedron::clear_pending_generators() {
00255 status.reset_g_pending();
00256 }
00257
00258 inline void
00259 Polyhedron::clear_sat_c_up_to_date() {
00260 status.reset_sat_c_up_to_date();
00261
00262 }
00263
00264 inline void
00265 Polyhedron::clear_sat_g_up_to_date() {
00266 status.reset_sat_g_up_to_date();
00267
00268 }
00269
00270 inline void
00271 Polyhedron::clear_constraints_up_to_date() {
00272 clear_pending_constraints();
00273 clear_constraints_minimized();
00274 clear_sat_c_up_to_date();
00275 clear_sat_g_up_to_date();
00276 status.reset_c_up_to_date();
00277
00278 }
00279
00280 inline void
00281 Polyhedron::clear_generators_up_to_date() {
00282 clear_pending_generators();
00283 clear_generators_minimized();
00284 clear_sat_c_up_to_date();
00285 clear_sat_g_up_to_date();
00286 status.reset_g_up_to_date();
00287
00288 }
00289
00290 inline bool
00291 Polyhedron::process_pending() const {
00292 PPL_ASSERT(space_dim > 0 && !marked_empty());
00293 PPL_ASSERT(has_something_pending());
00294
00295 Polyhedron& x = const_cast<Polyhedron&>(*this);
00296
00297 if (x.has_pending_constraints())
00298 return x.process_pending_constraints();
00299
00300 PPL_ASSERT(x.has_pending_generators());
00301 x.process_pending_generators();
00302 return true;
00303 }
00304
00305 inline bool
00306 Polyhedron::bounds_from_above(const Linear_Expression& expr) const {
00307 return bounds(expr, true);
00308 }
00309
00310 inline bool
00311 Polyhedron::bounds_from_below(const Linear_Expression& expr) const {
00312 return bounds(expr, false);
00313 }
00314
00315 inline bool
00316 Polyhedron::maximize(const Linear_Expression& expr,
00317 Coefficient& sup_n, Coefficient& sup_d,
00318 bool& maximum) const {
00319 Generator g(point());
00320 return max_min(expr, true, sup_n, sup_d, maximum, g);
00321 }
00322
00323 inline bool
00324 Polyhedron::maximize(const Linear_Expression& expr,
00325 Coefficient& sup_n, Coefficient& sup_d, bool& maximum,
00326 Generator& g) const {
00327 return max_min(expr, true, sup_n, sup_d, maximum, g);
00328 }
00329
00330 inline bool
00331 Polyhedron::minimize(const Linear_Expression& expr,
00332 Coefficient& inf_n, Coefficient& inf_d,
00333 bool& minimum) const {
00334 Generator g(point());
00335 return max_min(expr, false, inf_n, inf_d, minimum, g);
00336 }
00337
00338 inline bool
00339 Polyhedron::minimize(const Linear_Expression& expr,
00340 Coefficient& inf_n, Coefficient& inf_d, bool& minimum,
00341 Generator& g) const {
00342 return max_min(expr, false, inf_n, inf_d, minimum, g);
00343 }
00344
00345 inline Constraint_System
00346 Polyhedron::simplified_constraints() const {
00347 PPL_ASSERT(constraints_are_up_to_date());
00348 Constraint_System cs(con_sys);
00349 if (cs.num_pending_rows() > 0)
00350 cs.unset_pending_rows();
00351 if (has_pending_constraints() || !constraints_are_minimized())
00352 cs.simplify();
00353 return cs;
00354 }
00355
00356 inline Congruence_System
00357 Polyhedron::congruences() const {
00358 return Congruence_System(minimized_constraints());
00359 }
00360
00361 inline Congruence_System
00362 Polyhedron::minimized_congruences() const {
00363 return Congruence_System(minimized_constraints());
00364 }
00365
00366 inline Grid_Generator_System
00367 Polyhedron::minimized_grid_generators() const {
00368 return grid_generators();
00369 }
00370
00371 inline void
00372 Polyhedron::add_recycled_congruences(Congruence_System& cgs) {
00373 add_congruences(cgs);
00374 }
00375
00377 inline bool
00378 operator!=(const Polyhedron& x, const Polyhedron& y) {
00379 return !(x == y);
00380 }
00381
00382 inline bool
00383 Polyhedron::strictly_contains(const Polyhedron& y) const {
00384 const Polyhedron& x = *this;
00385 return x.contains(y) && !y.contains(x);
00386 }
00387
00388 inline void
00389 Polyhedron::drop_some_non_integer_points(Complexity_Class complexity) {
00390 const Variables_Set* p_vs = 0;
00391 drop_some_non_integer_points(p_vs, complexity);
00392 }
00393
00394 inline void
00395 Polyhedron::drop_some_non_integer_points(const Variables_Set& vars,
00396 Complexity_Class complexity) {
00397 drop_some_non_integer_points(&vars, complexity);
00398 }
00399
00400
00401 namespace Interfaces {
00402
00403 inline bool
00404 is_necessarily_closed_for_interfaces(const Polyhedron& ph) {
00405 return ph.is_necessarily_closed();
00406 }
00407
00408 }
00409
00410 }
00411
00412 namespace std {
00413
00415 inline void
00416 swap(Parma_Polyhedra_Library::Polyhedron& x,
00417 Parma_Polyhedra_Library::Polyhedron& y) {
00418 x.swap(y);
00419 }
00420
00421 }
00422
00423 #endif // !defined(PPL_Polyhedron_inlines_hh)