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 Linear_Expression& e1, const Linear_Expression& e2) {
00158 Linear_Expression diff = e1 - e2;
00159 Constraint c(diff, Constraint::NONSTRICT_INEQUALITY, NECESSARILY_CLOSED);
00160
00161 c.normalize();
00162 return c;
00163 }
00164
00166 inline Constraint
00167 operator>(const Linear_Expression& e1, const Linear_Expression& e2) {
00168 Linear_Expression diff;
00169
00170
00171 const dimension_type e1_dim = e1.space_dimension();
00172 const dimension_type e2_dim = e2.space_dimension();
00173 if (e1_dim > e2_dim)
00174 diff -= Variable(e1_dim);
00175 else
00176 diff -= Variable(e2_dim);
00177 diff += e1;
00178 diff -= e2;
00179
00180 Constraint c(diff, Constraint::STRICT_INEQUALITY, NOT_NECESSARILY_CLOSED);
00181 return c;
00182 }
00183
00185 inline Constraint
00186 operator==(Coefficient_traits::const_reference n, const Linear_Expression& e) {
00187 Linear_Expression diff = n - e;
00188 Constraint c(diff, Constraint::EQUALITY, NECESSARILY_CLOSED);
00189
00190 c.strong_normalize();
00191 return c;
00192 }
00193
00195 inline Constraint
00196 operator>=(Coefficient_traits::const_reference n, const Linear_Expression& e) {
00197 Linear_Expression diff = n - e;
00198 Constraint c(diff, Constraint::NONSTRICT_INEQUALITY, NECESSARILY_CLOSED);
00199
00200 c.normalize();
00201 return c;
00202 }
00203
00205 inline Constraint
00206 operator>(Coefficient_traits::const_reference n, const Linear_Expression& e) {
00207 Linear_Expression diff;
00208
00209
00210 diff -= Variable(e.space_dimension());
00211 diff += n;
00212 diff -= e;
00213
00214 Constraint c(diff, Constraint::STRICT_INEQUALITY, NOT_NECESSARILY_CLOSED);
00215 return c;
00216 }
00217
00219 inline Constraint
00220 operator==(const Linear_Expression& e, Coefficient_traits::const_reference n) {
00221 Linear_Expression diff = e - n;
00222 Constraint c(diff, Constraint::EQUALITY, NECESSARILY_CLOSED);
00223
00224 c.strong_normalize();
00225 return c;
00226 }
00227
00229 inline Constraint
00230 operator>=(const Linear_Expression& e, Coefficient_traits::const_reference n) {
00231 Linear_Expression diff = e - n;
00232 Constraint c(diff, Constraint::NONSTRICT_INEQUALITY, NECESSARILY_CLOSED);
00233
00234 c.normalize();
00235 return c;
00236 }
00237
00239 inline Constraint
00240 operator>(const Linear_Expression& e, Coefficient_traits::const_reference n) {
00241 Linear_Expression diff;
00242
00243
00244 diff -= Variable(e.space_dimension());
00245 diff += e;
00246 diff -= n;
00247
00248 Constraint c(diff, Constraint::STRICT_INEQUALITY, NOT_NECESSARILY_CLOSED);
00249 c.set_not_necessarily_closed();
00250 c.set_is_inequality();
00251 return c;
00252 }
00253
00255 inline Constraint
00256 operator<=(const Linear_Expression& e1, const Linear_Expression& e2) {
00257 return e2 >= e1;
00258 }
00259
00261 inline Constraint
00262 operator<=(Coefficient_traits::const_reference n, const Linear_Expression& e) {
00263 return e >= n;
00264 }
00265
00267 inline Constraint
00268 operator<=(const Linear_Expression& e, Coefficient_traits::const_reference n) {
00269 return n >= e;
00270 }
00271
00273 inline Constraint
00274 operator<(const Linear_Expression& e1, const Linear_Expression& e2) {
00275 return e2 > e1;
00276 }
00277
00279 inline Constraint
00280 operator<(Coefficient_traits::const_reference n, const Linear_Expression& e) {
00281 return e > n;
00282 }
00283
00285 inline Constraint
00286 operator<(const Linear_Expression& e, Coefficient_traits::const_reference n) {
00287 return n > e;
00288 }
00289
00290 inline const Constraint&
00291 Constraint::zero_dim_false() {
00292 static const Constraint zdf(Linear_Expression::zero() == Coefficient_one());
00293 return zdf;
00294 }
00295
00296 inline const Constraint&
00297 Constraint::zero_dim_positivity() {
00298 static const Constraint zdp(Linear_Expression::zero() <= Coefficient_one());
00299 return zdp;
00300 }
00301
00302 inline const Constraint&
00303 Constraint::epsilon_geq_zero() {
00304 static const Constraint eps_geq_zero = construct_epsilon_geq_zero();
00305 return eps_geq_zero;
00306 }
00307
00308 inline const Constraint&
00309 Constraint::epsilon_leq_one() {
00310 static const Constraint
00311 eps_leq_one(Linear_Expression::zero() < Coefficient_one());
00312 return eps_leq_one;
00313 }
00314
00315 inline void
00316 Constraint::ascii_dump(std::ostream& s) const {
00317 Linear_Row::ascii_dump(s);
00318 }
00319
00320 inline bool
00321 Constraint::ascii_load(std::istream& s) {
00322 return Linear_Row::ascii_load(s);
00323 }
00324
00325 inline void
00326 Constraint::swap(Constraint& y) {
00327 Linear_Row::swap(y);
00328 }
00329
00330 }
00331
00332 namespace std {
00333
00335 inline void
00336 swap(Parma_Polyhedra_Library::Constraint& x,
00337 Parma_Polyhedra_Library::Constraint& y) {
00338 x.swap(y);
00339 }
00340
00341 }
00342
00343 #endif // !defined(PPL_Constraint_inlines_hh)