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