Generated on Sun Feb 17 15:24:07 2019 for Gecode by doxygen 1.6.3

val.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00005  *
00006  *  Contributing authors:
00007  *     Christian Schulte <schulte@gecode.org>
00008  *
00009  *  Copyright:
00010  *     Christian Schulte, 2012
00011  *     Vincent Barichard, 2012
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode {
00039 
00040   /*
00041    * Floating point value: member functions
00042    *
00043    */
00044   forceinline
00045   FloatVal::FloatVal(void) {}
00046   forceinline
00047   FloatVal::FloatVal(const FloatNum& n) : x(n) {}
00048   forceinline
00049   FloatVal::FloatVal(const FloatNum& l, const FloatNum& u) : x(l,u) {}
00050   forceinline
00051   FloatVal::FloatVal(const FloatValImpType& i) : x(i) {}
00052   forceinline
00053   FloatVal::FloatVal(const FloatVal& v) : x(v.x) {}
00054 
00055   forceinline FloatVal&
00056   FloatVal::operator =(const FloatNum& n) {
00057     x = n; return *this;
00058   }
00059   forceinline FloatVal&
00060   FloatVal::operator =(const FloatVal& v) {
00061     x = v.x; return *this;
00062   }
00063 
00064   forceinline void
00065   FloatVal::assign(FloatNum const &l, FloatNum const &u) {
00066     x.assign(l,u);
00067   }
00068 
00069   forceinline FloatNum
00070   FloatVal::min(void) const {
00071     return x.lower();
00072   }
00073   forceinline FloatNum
00074   FloatVal::max(void) const {
00075     return x.upper();
00076   }
00077   forceinline FloatNum
00078   FloatVal::size(void) const {
00079     return gecode_boost::numeric::width(x);
00080   }
00081   forceinline FloatNum
00082   FloatVal::med(void) const {
00083     return gecode_boost::numeric::median(x);
00084   }
00085 
00086   forceinline bool
00087   FloatVal::tight(void) const {
00088     return (gecode_boost::numeric::singleton(x) ||
00089             (nextafter(x.lower(),x.upper()) == x.upper()));
00090   }
00091   forceinline bool
00092   FloatVal::singleton(void) const {
00093     return gecode_boost::numeric::singleton(x);
00094   }
00095   forceinline bool
00096   FloatVal::in(FloatNum n) const {
00097     return gecode_boost::numeric::in(n,x);
00098   }
00099   forceinline bool
00100   FloatVal::zero_in(void) const {
00101     return gecode_boost::numeric::zero_in(x);
00102   }
00103 
00104   forceinline FloatVal
00105   FloatVal::hull(FloatNum x, FloatNum y) {
00106     FloatVal h(x,y); return h;
00107   }
00108   forceinline FloatVal
00109   FloatVal::pi_half(void) {
00110     FloatVal p(gecode_boost::numeric::interval_lib::pi_half<FloatValImpType>());
00111     return p;
00112   }
00113   forceinline FloatVal
00114   FloatVal::pi(void) {
00115     FloatVal p(gecode_boost::numeric::interval_lib::pi<FloatValImpType>());
00116     return p;
00117   }
00118   forceinline FloatVal
00119   FloatVal::pi_twice(void) {
00120     FloatVal p(gecode_boost::numeric::interval_lib::pi_twice<FloatValImpType>());
00121     return p;
00122   }
00123 
00124   forceinline FloatVal&
00125   FloatVal::operator +=(const FloatNum& n) {
00126     x += n; return *this;
00127   }
00128   forceinline FloatVal&
00129   FloatVal::operator -=(const FloatNum& n) {
00130     x -= n; return *this;
00131   }
00132   forceinline FloatVal&
00133   FloatVal::operator *=(const FloatNum& n) {
00134     x *= n; return *this;
00135   }
00136   forceinline FloatVal&
00137   FloatVal::operator /=(const FloatNum& n) {
00138     x /= n; return *this;
00139   }
00140 
00141   forceinline FloatVal&
00142   FloatVal::operator +=(const FloatVal& v) {
00143     x += v.x; return *this;
00144   }
00145   forceinline FloatVal&
00146   FloatVal::operator -=(const FloatVal& v) {
00147     x -= v.x; return *this;
00148   }
00149   forceinline FloatVal&
00150   FloatVal::operator *=(const FloatVal& v) {
00151     x *= v.x; return *this;
00152   }
00153   forceinline FloatVal&
00154   FloatVal::operator /=(const FloatVal& v) {
00155     x /= v.x; return *this;
00156   }
00157 
00158   /*
00159    * Operators and functions on float values
00160    *
00161    */
00162 
00163   forceinline FloatVal
00164   operator +(const FloatVal& x) {
00165     return FloatVal(+x.x);
00166   }
00167   forceinline FloatVal
00168   operator -(const FloatVal& x) {
00169     FloatNum mmi = (x.min() == 0.0) ? 0.0 : -x.min();
00170     FloatNum mma = (x.max() == 0.0) ? 0.0 :-x.max();
00171     return FloatVal(mma,mmi);
00172   }
00173   forceinline FloatVal
00174   operator +(const FloatVal& x, const FloatVal& y) {
00175     return FloatVal(x.x+y.x);
00176   }
00177   forceinline FloatVal
00178   operator +(const FloatVal& x, const FloatNum& y) {
00179     return FloatVal(x.x+y);
00180   }
00181   forceinline FloatVal
00182   operator +(const FloatNum& x, const FloatVal& y) {
00183     return FloatVal(x+y.x);
00184   }
00185 
00186   forceinline FloatVal
00187   operator -(const FloatVal& x, const FloatVal& y) {
00188     return FloatVal(x.x-y.x);
00189   }
00190   forceinline FloatVal
00191   operator -(const FloatVal& x, const FloatNum& y) {
00192     return FloatVal(x.x-y);
00193   }
00194   forceinline FloatVal
00195   operator -(const FloatNum& x, const FloatVal& y) {
00196     return FloatVal(x-y.x);
00197   }
00198 
00199   forceinline FloatVal
00200   operator *(const FloatVal& x, const FloatVal& y) {
00201     return FloatVal(x.x*y.x);
00202   }
00203   forceinline FloatVal
00204   operator *(const FloatVal& x, const FloatNum& y) {
00205     return FloatVal(x.x*y);
00206   }
00207   forceinline FloatVal
00208   operator *(const FloatNum& x, const FloatVal& y) {
00209     return FloatVal(x*y.x);
00210   }
00211 
00212   forceinline FloatVal
00213   operator /(const FloatVal& x, const FloatVal& y) {
00214     return FloatVal(x.x/y.x);
00215   }
00216   forceinline FloatVal
00217   operator /(const FloatVal& x, const FloatNum& y) {
00218     return FloatVal(x.x/y);
00219   }
00220   forceinline FloatVal
00221   operator /(const FloatNum& x, const FloatVal& y) {
00222     return FloatVal(x/y.x);
00223   }
00224 
00225   inline bool
00226   operator <(const FloatVal& x, const FloatVal& y) {
00227     try {
00228       return x.x < y.x;
00229     } catch (gecode_boost::numeric::interval_lib::comparison_error&) {
00230       return false;
00231     }
00232   }
00233   inline bool
00234   operator <(const FloatVal& x, const FloatNum& y) {
00235     try {
00236       return x.x < y;
00237     } catch (gecode_boost::numeric::interval_lib::comparison_error&) {
00238       return false;
00239     }
00240   }
00241 
00242   inline bool
00243   operator <=(const FloatVal& x, const FloatVal& y) {
00244     try {
00245       return x.x <= y.x;
00246     } catch (gecode_boost::numeric::interval_lib::comparison_error&) {
00247       return false;
00248     }
00249   }
00250   inline bool
00251   operator <=(const FloatVal& x, const FloatNum& y) {
00252     try {
00253       return x.x <= y;
00254     } catch (gecode_boost::numeric::interval_lib::comparison_error&) {
00255       return false;
00256     }
00257   }
00258 
00259   inline bool
00260   operator >(const FloatVal& x, const FloatVal& y) {
00261     try {
00262       return x.x > y.x;
00263     } catch (gecode_boost::numeric::interval_lib::comparison_error&) {
00264       return false;
00265     }
00266   }
00267   inline bool
00268   operator >(const FloatVal& x, const FloatNum& y) {
00269     try {
00270       return x.x > y;
00271     } catch (gecode_boost::numeric::interval_lib::comparison_error&) {
00272       return false;
00273     }
00274   }
00275 
00276   inline bool
00277   operator >=(const FloatVal& x, const FloatVal& y) {
00278     try {
00279       return x.x >= y.x;
00280     } catch (gecode_boost::numeric::interval_lib::comparison_error&) {
00281       return false;
00282     }
00283   }
00284   inline bool
00285   operator >=(const FloatVal& x, const FloatNum& y) {
00286     try {
00287       return x.x >= y;
00288     } catch (gecode_boost::numeric::interval_lib::comparison_error&) {
00289       return false;
00290     }
00291   }
00292 
00293   inline bool
00294   operator ==(const FloatVal& x, const FloatVal& y) {
00295     try {
00296       return x.x == y.x;
00297     } catch (gecode_boost::numeric::interval_lib::comparison_error&) {
00298       return false;
00299     }
00300   }
00301   inline bool
00302   operator ==(const FloatVal& x, const FloatNum& y) {
00303     if (!gecode_boost::numeric::interval_lib::checking_strict<FloatNum>
00304         ::is_empty(x.x.lower(), x.x.upper())) {
00305       if ((x.x.lower() == y) && (x.x.upper() == y))
00306         return true;
00307       }
00308     if (((x.x.lower() == y) &&
00309          (nextafter(x.x.lower(),x.x.upper()) == x.x.upper())) ||
00310         ((x.x.upper() == y) &&
00311          (nextafter(x.x.upper(),x.x.lower()) == x.x.lower())))
00312       return true;
00313     return false;
00314   }
00315 
00316   inline bool
00317   operator !=(const FloatVal& x, const FloatVal& y) {
00318     try {
00319       return x.x != y.x;
00320     } catch (gecode_boost::numeric::interval_lib::comparison_error&) {
00321       return false;
00322     }
00323   }
00324   inline bool
00325   operator !=(const FloatVal& x, const FloatNum& y) {
00326     try {
00327       return x.x != y;
00328     } catch (gecode_boost::numeric::interval_lib::comparison_error&) {
00329       return false;
00330     }
00331   }
00332 
00333   forceinline bool
00334   operator <(const FloatNum& x, const FloatVal& y) {
00335     return y > x;
00336   }
00337   forceinline bool
00338   operator <=(const FloatNum& x, const FloatVal& y) {
00339     return y >= x;
00340   }
00341   forceinline bool
00342   operator >(const FloatNum& x, const FloatVal& y) {
00343     return y < x;
00344   }
00345   forceinline bool
00346   operator >=(const FloatNum& x, const FloatVal& y) {
00347     return y <= x;
00348   }
00349   forceinline bool
00350   operator ==(const FloatNum& x, const FloatVal& y) {
00351     return y == x;
00352   }
00353   forceinline bool
00354   operator !=(const FloatNum& x, const FloatVal& y) {
00355     return y != x;
00356   }
00357 
00358   template<class Char, class Traits>
00359   std::basic_ostream<Char,Traits>&
00360   operator <<(std::basic_ostream<Char,Traits>& os, const FloatVal& x) {
00361     return os << '[' << x.min() << ".." << x.max() << ']';
00362   }
00363 
00364   forceinline FloatVal
00365   abs(const FloatVal& x) {
00366     return FloatVal(abs(x.x));
00367   }
00368   forceinline FloatVal
00369   sqrt(const FloatVal& x) {
00370     return FloatVal(sqrt(x.x));
00371   }
00372   forceinline FloatVal
00373   sqr(const FloatVal& x) {
00374     return FloatVal(square(x.x));
00375   }
00376   forceinline FloatVal
00377   pow(const FloatVal& x, int n) {
00378     return FloatVal(pow(x.x,n));
00379   }
00380   forceinline FloatVal
00381   nroot(const FloatVal& x, int n) {
00382     return FloatVal(nth_root(x.x,n));
00383   }
00384 
00385   forceinline FloatVal
00386   max(const FloatVal& x, const FloatVal& y) {
00387     return FloatVal(max(x.x,y.x));
00388   }
00389   forceinline FloatVal
00390   max(const FloatVal& x, const FloatNum& y) {
00391     return FloatVal(max(x.x,y));
00392   }
00393   forceinline FloatVal
00394   max(const FloatNum& x, const FloatVal& y) {
00395     return FloatVal(max(x,y.x));
00396   }
00397   forceinline FloatVal
00398   min(const FloatVal& x, const FloatVal& y) {
00399     return FloatVal(min(x.x,y.x));
00400   }
00401   forceinline FloatVal
00402   min(const FloatVal& x, const FloatNum& y) {
00403     return FloatVal(min(x.x,y));
00404   }
00405   forceinline FloatVal
00406   min(const FloatNum& x, const FloatVal& y) {
00407     return FloatVal(min(x,y.x));
00408   }
00409 
00410 #ifdef GECODE_HAS_MPFR
00411 
00412   forceinline FloatVal
00413   exp(const FloatVal& x) {
00414     return FloatVal(exp(x.x));
00415   }
00416   forceinline FloatVal
00417   log(const FloatVal& x) {
00418     return FloatVal(log(x.x));
00419   }
00420 
00421   forceinline FloatVal
00422   fmod(const FloatVal& x, const FloatVal& y) {
00423     return FloatVal(fmod(x.x,y.x));
00424   }
00425   forceinline FloatVal
00426   fmod(const FloatVal& x, const FloatNum& y) {
00427     return FloatVal(fmod(x.x,y));
00428   }
00429   forceinline FloatVal
00430   fmod(const FloatNum& x, const FloatVal& y) {
00431     return FloatVal(fmod(x,y.x));
00432   }
00433 
00434   forceinline FloatVal
00435   sin(const FloatVal& x) {
00436     return FloatVal(sin(x.x));
00437   }
00438   forceinline FloatVal
00439   cos(const FloatVal& x) {
00440     return FloatVal(cos(x.x));
00441   }
00442   forceinline FloatVal
00443   tan(const FloatVal& x) {
00444     return FloatVal(tan(x.x));
00445   }
00446   forceinline FloatVal
00447   asin(const FloatVal& x) {
00448     return FloatVal(asin(x.x));
00449   }
00450   forceinline FloatVal
00451   acos(const FloatVal& x) {
00452     return FloatVal(acos(x.x));
00453   }
00454   forceinline FloatVal
00455   atan(const FloatVal& x) {
00456     return FloatVal(atan(x.x));
00457   }
00458 
00459   forceinline FloatVal
00460   sinh(const FloatVal& x) {
00461     return FloatVal(sinh(x.x));
00462   }
00463   forceinline FloatVal
00464   cosh(const FloatVal& x) {
00465     return FloatVal(cosh(x.x));
00466   }
00467   forceinline FloatVal
00468   tanh(const FloatVal& x) {
00469     return FloatVal(tanh(x.x));
00470   }
00471   forceinline FloatVal
00472   asinh(const FloatVal& x) {
00473     return FloatVal(asinh(x.x));
00474   }
00475   forceinline FloatVal
00476   acosh(const FloatVal& x) {
00477     return FloatVal(acosh(x.x));
00478   }
00479   forceinline FloatVal
00480   atanh(const FloatVal& x) {
00481     return FloatVal(atanh(x.x));
00482   }
00483 
00484 #endif
00485 }
00486 
00487 namespace Gecode { namespace Float {
00488 
00489   forceinline bool
00490   subset(const FloatVal& x, const FloatVal& y) {
00491     return subset(x.x,y.x);
00492   }
00493   forceinline bool
00494   proper_subset(const FloatVal& x, const FloatVal& y) {
00495     return proper_subset(x.x,y.x);
00496   }
00497   forceinline bool
00498   overlap(const FloatVal& x, const FloatVal& y) {
00499     return overlap(x.x,y.x);
00500   }
00501 
00502   forceinline FloatVal
00503   intersect(const FloatVal& x, const FloatVal& y) {
00504     return FloatVal(intersect(x.x,y.x));
00505   }
00506   forceinline FloatVal
00507   hull(const FloatVal& x, const FloatVal& y) {
00508     return FloatVal(hull(x.x,y.x));
00509   }
00510   forceinline FloatVal
00511   hull(const FloatVal& x, const FloatNum& y) {
00512     return FloatVal(hull(x.x,y));
00513   }
00514   forceinline FloatVal
00515   hull(const FloatNum& x, const FloatVal& y) {
00516     return FloatVal(hull(x,y.x));
00517   }
00518   forceinline FloatVal
00519   hull(const FloatNum& x, const FloatNum& y) {
00520     return FloatVal(x,y);
00521   }
00522 
00523 }}
00524 
00525 // STATISTICS: float-var
00526