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_Constraint_inlines_hh
00025 #define PPL_Constraint_inlines_hh 1
00026
00027 #include "Linear_Expression.defs.hh"
00028
00029 namespace Parma_Polyhedra_Library {
00030
00031 inline
00032 Constraint::Constraint(Linear_Expression& e, Type type, Topology topology) {
00033 PPL_ASSERT(type != STRICT_INEQUALITY || topology == NOT_NECESSARILY_CLOSED);
00034 Linear_Row::swap(e);
00035 flags() = Flags(topology, (type == EQUALITY
00036 ? LINE_OR_EQUALITY
00037 : RAY_OR_POINT_OR_INEQUALITY));
00038 }
00039
00040 inline
00041 Constraint::Constraint(const Constraint& c)
00042 : Linear_Row(c) {
00043 }
00044
00045 inline
00046 Constraint::Constraint(const Constraint& c, const dimension_type sz)
00047 : Linear_Row(c, sz, sz) {
00048 }
00049
00050 inline
00051 Constraint::~Constraint() {
00052 }
00053
00054 inline Constraint&
00055 Constraint::operator=(const Constraint& c) {
00056 Linear_Row::operator=(c);
00057 return *this;
00058 }
00059
00060 inline dimension_type
00061 Constraint::max_space_dimension() {
00062 return Linear_Row::max_space_dimension();
00063 }
00064
00065 inline dimension_type
00066 Constraint::space_dimension() const {
00067 return Linear_Row::space_dimension();
00068 }
00069
00070 inline bool
00071 Constraint::is_equality() const {
00072 return is_line_or_equality();
00073 }
00074
00075 inline bool
00076 Constraint::is_inequality() const {
00077 return is_ray_or_point_or_inequality();
00078 }
00079
00080 inline Constraint::Type
00081 Constraint::type() const {
00082 if (is_equality())
00083 return EQUALITY;
00084 if (is_necessarily_closed())
00085 return NONSTRICT_INEQUALITY;
00086 else
00087 return ((*this)[size() - 1] < 0)
00088 ? STRICT_INEQUALITY
00089 : NONSTRICT_INEQUALITY;
00090 }
00091
00092 inline bool
00093 Constraint::is_nonstrict_inequality() const {
00094 return type() == NONSTRICT_INEQUALITY;
00095 }
00096
00097 inline bool
00098 Constraint::is_strict_inequality() const {
00099 return type() == STRICT_INEQUALITY;
00100 }
00101
00102 inline void
00103 Constraint::set_is_equality() {
00104 set_is_line_or_equality();
00105 }
00106
00107 inline void
00108 Constraint::set_is_inequality() {
00109 set_is_ray_or_point_or_inequality();
00110 }
00111
00112 inline Coefficient_traits::const_reference
00113 Constraint::coefficient(const Variable v) const {
00114 if (v.space_dimension() > space_dimension())
00115 throw_dimension_incompatible("coefficient(v)", "v", v);
00116 return Linear_Row::coefficient(v.id());
00117 }
00118
00119 inline Coefficient_traits::const_reference
00120 Constraint::inhomogeneous_term() const {
00121 return Linear_Row::inhomogeneous_term();
00122 }
00123
00124 inline memory_size_type
00125 Constraint::external_memory_in_bytes() const {
00126 return Linear_Row::external_memory_in_bytes();
00127 }
00128
00129 inline memory_size_type
00130 Constraint::total_memory_in_bytes() const {
00131 return Linear_Row::total_memory_in_bytes();
00132 }
00133
00135 inline bool
00136 operator==(const Constraint& x, const Constraint& y) {
00137 return x.is_equivalent_to(y);
00138 }
00139
00141 inline bool
00142 operator!=(const Constraint& x, const Constraint& y) {
00143 return !x.is_equivalent_to(y);
00144 }
00145
00147 inline Constraint
00148 operator==(const Linear_Expression& e1, const Linear_Expression& e2) {
00149 Linear_Expression diff = e1 - e2;
00150 Constraint c(diff, Constraint::EQUALITY, NECESSARILY_CLOSED);
00151
00152 c.strong_normalize();
00153 return c;
00154 }
00155
00157 inline Constraint
00158 operator==(const Variable v1, const Variable v2) {
00159 Linear_Expression diff
00160 = (v1.space_dimension() < v2.space_dimension()) ? v1-v2 : v2-v1;
00161 return Constraint(diff, Constraint::EQUALITY, NECESSARILY_CLOSED);
00162 }
00163
00165 inline Constraint
00166 operator>=(const Linear_Expression& e1, const Linear_Expression& e2) {
00167 Linear_Expression diff = e1 - e2;
00168 Constraint c(diff, Constraint::NONSTRICT_INEQUALITY, NECESSARILY_CLOSED);
00169
00170 c.normalize();
00171 return c;
00172 }
00173
00175 inline Constraint
00176 operator>=(const Variable v1, const Variable v2) {
00177 Linear_Expression diff = v1-v2;
00178 return Constraint(diff, Constraint::NONSTRICT_INEQUALITY, NECESSARILY_CLOSED);
00179 }
00180
00182 inline Constraint
00183 operator>(const Linear_Expression& e1, const Linear_Expression& e2) {
00184 Linear_Expression diff;
00185
00186
00187 const dimension_type e1_dim = e1.space_dimension();
00188 const dimension_type e2_dim = e2.space_dimension();
00189 if (e1_dim > e2_dim)
00190 diff -= Variable(e1_dim);
00191 else
00192 diff -= Variable(e2_dim);
00193 diff += e1;
00194 diff -= e2;
00195
00196 Constraint c(diff, Constraint::STRICT_INEQUALITY, NOT_NECESSARILY_CLOSED);
00197 return c;
00198 }
00199
00201 inline Constraint
00202 operator>(const Variable v1, const Variable v2) {
00203 Linear_Expression diff = v1-v2;
00204 diff -= Variable(std::max(v1.space_dimension(), v2.space_dimension()));
00205 return Constraint(diff,
00206 Constraint::STRICT_INEQUALITY,
00207 NOT_NECESSARILY_CLOSED);
00208 }
00209
00211 inline Constraint
00212 operator==(Coefficient_traits::const_reference n, const Linear_Expression& e) {
00213 Linear_Expression diff = n - e;
00214 Constraint c(diff, Constraint::EQUALITY, NECESSARILY_CLOSED);
00215
00216 c.strong_normalize();
00217 return c;
00218 }
00219
00221 inline Constraint
00222 operator>=(Coefficient_traits::const_reference n, const Linear_Expression& e) {
00223 Linear_Expression diff = n - e;
00224 Constraint c(diff, Constraint::NONSTRICT_INEQUALITY, NECESSARILY_CLOSED);
00225
00226 c.normalize();
00227 return c;
00228 }
00229
00231 inline Constraint
00232 operator>(Coefficient_traits::const_reference n, const Linear_Expression& e) {
00233 Linear_Expression diff;
00234
00235
00236 diff -= Variable(e.space_dimension());
00237 diff += n;
00238 diff -= e;
00239
00240 Constraint c(diff, Constraint::STRICT_INEQUALITY, NOT_NECESSARILY_CLOSED);
00241 return c;
00242 }
00243
00245 inline Constraint
00246 operator==(const Linear_Expression& e, Coefficient_traits::const_reference n) {
00247 Linear_Expression diff = e - n;
00248 Constraint c(diff, Constraint::EQUALITY, NECESSARILY_CLOSED);
00249
00250 c.strong_normalize();
00251 return c;
00252 }
00253
00255 inline Constraint
00256 operator>=(const Linear_Expression& e, Coefficient_traits::const_reference n) {
00257 Linear_Expression diff = e - n;
00258 Constraint c(diff, Constraint::NONSTRICT_INEQUALITY, NECESSARILY_CLOSED);
00259
00260 c.normalize();
00261 return c;
00262 }
00263
00265 inline Constraint
00266 operator>(const Linear_Expression& e, Coefficient_traits::const_reference n) {
00267 Linear_Expression diff;
00268
00269
00270 diff -= Variable(e.space_dimension());
00271 diff += e;
00272 diff -= n;
00273
00274 Constraint c(diff, Constraint::STRICT_INEQUALITY, NOT_NECESSARILY_CLOSED);
00275 c.set_not_necessarily_closed();
00276 c.set_is_inequality();
00277 return c;
00278 }
00279
00281 inline Constraint
00282 operator<=(const Linear_Expression& e1, const Linear_Expression& e2) {
00283 return e2 >= e1;
00284 }
00285
00287 inline Constraint
00288 operator<=(const Variable v1, const Variable v2) {
00289 return v2 >= v1;
00290 }
00291
00293 inline Constraint
00294 operator<=(Coefficient_traits::const_reference n, const Linear_Expression& e) {
00295 return e >= n;
00296 }
00297
00299 inline Constraint
00300 operator<=(const Linear_Expression& e, Coefficient_traits::const_reference n) {
00301 return n >= e;
00302 }
00303
00305 inline Constraint
00306 operator<(const Linear_Expression& e1, const Linear_Expression& e2) {
00307 return e2 > e1;
00308 }
00309
00311 inline Constraint
00312 operator<(const Variable v1, const Variable v2) {
00313 return v2 > v1;
00314 }
00315
00317 inline Constraint
00318 operator<(Coefficient_traits::const_reference n, const Linear_Expression& e) {
00319 return e > n;
00320 }
00321
00323 inline Constraint
00324 operator<(const Linear_Expression& e, Coefficient_traits::const_reference n) {
00325 return n > e;
00326 }
00327
00328 inline const Constraint&
00329 Constraint::zero_dim_false() {
00330 PPL_ASSERT(zero_dim_false_p != 0);
00331 return *zero_dim_false_p;
00332 }
00333
00334 inline const Constraint&
00335 Constraint::zero_dim_positivity() {
00336 PPL_ASSERT(zero_dim_positivity_p != 0);
00337 return *zero_dim_positivity_p;
00338 }
00339
00340 inline const Constraint&
00341 Constraint::epsilon_geq_zero() {
00342 PPL_ASSERT(epsilon_geq_zero_p != 0);
00343 return *epsilon_geq_zero_p;
00344 }
00345
00346 inline const Constraint&
00347 Constraint::epsilon_leq_one() {
00348 PPL_ASSERT(epsilon_leq_one_p != 0);
00349 return *epsilon_leq_one_p;
00350 }
00351
00352 inline void
00353 Constraint::ascii_dump(std::ostream& s) const {
00354 Linear_Row::ascii_dump(s);
00355 }
00356
00357 inline bool
00358 Constraint::ascii_load(std::istream& s) {
00359 return Linear_Row::ascii_load(s);
00360 }
00361
00362 inline void
00363 Constraint::swap(Constraint& y) {
00364 Linear_Row::swap(y);
00365 }
00366
00367 }
00368
00369 namespace std {
00370
00372 inline void
00373 swap(Parma_Polyhedra_Library::Constraint& x,
00374 Parma_Polyhedra_Library::Constraint& y) {
00375 x.swap(y);
00376 }
00377
00378 }
00379
00380 #endif // !defined(PPL_Constraint_inlines_hh)