val.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Vincent Barichard <Vincent.Barichard@univ-angers.fr>
*
* Contributing authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2012
* Vincent Barichard, 2012
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
namespace Gecode {
/*
* Floating point value: member functions
*
*/
forceinline
FloatVal::FloatVal(void) {}
forceinline
FloatVal::FloatVal(const FloatNum& n) : x(n) {}
forceinline
FloatVal::FloatVal(const FloatNum& l, const FloatNum& u) : x(l,u) {}
forceinline
FloatVal::FloatVal(const FloatValImpType& i) : x(i) {}
forceinline
FloatVal::FloatVal(const FloatVal& v) : x(v.x) {}
forceinline FloatVal&
FloatVal::operator =(const FloatNum& n) {
x = n; return *this;
}
forceinline FloatVal&
FloatVal::operator =(const FloatVal& v) {
x = v.x; return *this;
}
forceinline void
FloatVal::assign(FloatNum const &l, FloatNum const &u) {
x.assign(l,u);
}
forceinline FloatNum
FloatVal::min(void) const {
return x.lower();
}
forceinline FloatNum
FloatVal::max(void) const {
return x.upper();
}
forceinline FloatNum
FloatVal::size(void) const {
return boost::numeric::width(x);
}
forceinline FloatNum
FloatVal::med(void) const {
return boost::numeric::median(x);
}
forceinline bool
FloatVal::tight(void) const {
return (boost::numeric::singleton(x) ||
(nextafter(x.lower(),x.upper()) == x.upper()));
}
forceinline bool
FloatVal::singleton(void) const {
return boost::numeric::singleton(x);
}
forceinline bool
FloatVal::in(FloatNum n) const {
return boost::numeric::in(n,x);
}
forceinline bool
FloatVal::zero_in(void) const {
return boost::numeric::zero_in(x);
}
forceinline FloatVal
FloatVal::hull(FloatNum x, FloatNum y) {
FloatVal h(x,y); return h;
}
forceinline FloatVal
FloatVal::pi_half(void) {
FloatVal p(boost::numeric::interval_lib::pi_half<FloatValImpType>());
return p;
}
forceinline FloatVal
FloatVal::pi(void) {
FloatVal p(boost::numeric::interval_lib::pi<FloatValImpType>());
return p;
}
forceinline FloatVal
FloatVal::pi_twice(void) {
FloatVal p(boost::numeric::interval_lib::pi_twice<FloatValImpType>());
return p;
}
forceinline FloatVal&
FloatVal::operator +=(const FloatNum& n) {
x += n; return *this;
}
forceinline FloatVal&
FloatVal::operator -=(const FloatNum& n) {
x -= n; return *this;
}
forceinline FloatVal&
FloatVal::operator *=(const FloatNum& n) {
x *= n; return *this;
}
forceinline FloatVal&
FloatVal::operator /=(const FloatNum& n) {
x /= n; return *this;
}
forceinline FloatVal&
FloatVal::operator +=(const FloatVal& v) {
x += v.x; return *this;
}
forceinline FloatVal&
FloatVal::operator -=(const FloatVal& v) {
x -= v.x; return *this;
}
forceinline FloatVal&
FloatVal::operator *=(const FloatVal& v) {
x *= v.x; return *this;
}
forceinline FloatVal&
FloatVal::operator /=(const FloatVal& v) {
x /= v.x; return *this;
}
/*
* Operators and functions on float values
*
*/
forceinline FloatVal
operator +(const FloatVal& x) {
return FloatVal(+x.x);
}
forceinline FloatVal
operator -(const FloatVal& x) {
FloatNum mmi = (x.min() == 0.0) ? 0.0 : -x.min();
FloatNum mma = (x.max() == 0.0) ? 0.0 :-x.max();
return FloatVal(mma,mmi);
}
forceinline FloatVal
operator +(const FloatVal& x, const FloatVal& y) {
return FloatVal(x.x+y.x);
}
forceinline FloatVal
operator +(const FloatVal& x, const FloatNum& y) {
return FloatVal(x.x+y);
}
forceinline FloatVal
operator +(const FloatNum& x, const FloatVal& y) {
return FloatVal(x+y.x);
}
forceinline FloatVal
operator -(const FloatVal& x, const FloatVal& y) {
return FloatVal(x.x-y.x);
}
forceinline FloatVal
operator -(const FloatVal& x, const FloatNum& y) {
return FloatVal(x.x-y);
}
forceinline FloatVal
operator -(const FloatNum& x, const FloatVal& y) {
return FloatVal(x-y.x);
}
forceinline FloatVal
operator *(const FloatVal& x, const FloatVal& y) {
return FloatVal(x.x*y.x);
}
forceinline FloatVal
operator *(const FloatVal& x, const FloatNum& y) {
return FloatVal(x.x*y);
}
forceinline FloatVal
operator *(const FloatNum& x, const FloatVal& y) {
return FloatVal(x*y.x);
}
forceinline FloatVal
operator /(const FloatVal& x, const FloatVal& y) {
return FloatVal(x.x/y.x);
}
forceinline FloatVal
operator /(const FloatVal& x, const FloatNum& y) {
return FloatVal(x.x/y);
}
forceinline FloatVal
operator /(const FloatNum& x, const FloatVal& y) {
return FloatVal(x/y.x);
}
inline bool
operator <(const FloatVal& x, const FloatVal& y) {
try {
return x.x < y.x;
} catch (boost::numeric::interval_lib::comparison_error&) {
return false;
}
}
inline bool
operator <(const FloatVal& x, const FloatNum& y) {
try {
return x.x < y;
} catch (boost::numeric::interval_lib::comparison_error&) {
return false;
}
}
inline bool
operator <=(const FloatVal& x, const FloatVal& y) {
try {
return x.x <= y.x;
} catch (boost::numeric::interval_lib::comparison_error&) {
return false;
}
}
inline bool
operator <=(const FloatVal& x, const FloatNum& y) {
try {
return x.x <= y;
} catch (boost::numeric::interval_lib::comparison_error&) {
return false;
}
}
inline bool
operator >(const FloatVal& x, const FloatVal& y) {
try {
return x.x > y.x;
} catch (boost::numeric::interval_lib::comparison_error&) {
return false;
}
}
inline bool
operator >(const FloatVal& x, const FloatNum& y) {
try {
return x.x > y;
} catch (boost::numeric::interval_lib::comparison_error&) {
return false;
}
}
inline bool
operator >=(const FloatVal& x, const FloatVal& y) {
try {
return x.x >= y.x;
} catch (boost::numeric::interval_lib::comparison_error&) {
return false;
}
}
inline bool
operator >=(const FloatVal& x, const FloatNum& y) {
try {
return x.x >= y;
} catch (boost::numeric::interval_lib::comparison_error&) {
return false;
}
}
inline bool
operator ==(const FloatVal& x, const FloatVal& y) {
try {
return x.x == y.x;
} catch (boost::numeric::interval_lib::comparison_error&) {
return false;
}
}
inline bool
operator ==(const FloatVal& x, const FloatNum& y) {
if (!boost::numeric::interval_lib::checking_strict<FloatNum>
::is_empty(x.x.lower(), x.x.upper())) {
if ((x.x.lower() == y) && (x.x.upper() == y))
return true;
}
if (((x.x.lower() == y) &&
(nextafter(x.x.lower(),x.x.upper()) == x.x.upper())) ||
((x.x.upper() == y) &&
(nextafter(x.x.upper(),x.x.lower()) == x.x.lower())))
return true;
return false;
}
inline bool
operator !=(const FloatVal& x, const FloatVal& y) {
try {
return x.x != y.x;
} catch (boost::numeric::interval_lib::comparison_error&) {
return false;
}
}
inline bool
operator !=(const FloatVal& x, const FloatNum& y) {
try {
return x.x != y;
} catch (boost::numeric::interval_lib::comparison_error&) {
return false;
}
}
forceinline bool
operator <(const FloatNum& x, const FloatVal& y) {
return y > x;
}
forceinline bool
operator <=(const FloatNum& x, const FloatVal& y) {
return y >= x;
}
forceinline bool
operator >(const FloatNum& x, const FloatVal& y) {
return y < x;
}
forceinline bool
operator >=(const FloatNum& x, const FloatVal& y) {
return y <= x;
}
forceinline bool
operator ==(const FloatNum& x, const FloatVal& y) {
return y == x;
}
forceinline bool
operator !=(const FloatNum& x, const FloatVal& y) {
return y != x;
}
template<class Char, class Traits>
std::basic_ostream<Char,Traits>&
operator <<(std::basic_ostream<Char,Traits>& os, const FloatVal& x) {
return os << '[' << x.min() << ".." << x.max() << ']';
}
forceinline FloatVal
abs(const FloatVal& x) {
return FloatVal(abs(x.x));
}
forceinline FloatVal
sqrt(const FloatVal& x) {
return FloatVal(sqrt(x.x));
}
forceinline FloatVal
sqr(const FloatVal& x) {
return FloatVal(square(x.x));
}
forceinline FloatVal
pow(const FloatVal& x, int n) {
return FloatVal(pow(x.x,n));
}
forceinline FloatVal
nroot(const FloatVal& x, int n) {
return FloatVal(nth_root(x.x,n));
}
forceinline FloatVal
max(const FloatVal& x, const FloatVal& y) {
return FloatVal(max(x.x,y.x));
}
forceinline FloatVal
max(const FloatVal& x, const FloatNum& y) {
return FloatVal(max(x.x,y));
}
forceinline FloatVal
max(const FloatNum& x, const FloatVal& y) {
return FloatVal(max(x,y.x));
}
forceinline FloatVal
min(const FloatVal& x, const FloatVal& y) {
return FloatVal(min(x.x,y.x));
}
forceinline FloatVal
min(const FloatVal& x, const FloatNum& y) {
return FloatVal(min(x.x,y));
}
forceinline FloatVal
min(const FloatNum& x, const FloatVal& y) {
return FloatVal(min(x,y.x));
}
#ifdef GECODE_HAS_MPFR
forceinline FloatVal
exp(const FloatVal& x) {
return FloatVal(exp(x.x));
}
forceinline FloatVal
log(const FloatVal& x) {
return FloatVal(log(x.x));
}
forceinline FloatVal
fmod(const FloatVal& x, const FloatVal& y) {
return FloatVal(fmod(x.x,y.x));
}
forceinline FloatVal
fmod(const FloatVal& x, const FloatNum& y) {
return FloatVal(fmod(x.x,y));
}
forceinline FloatVal
fmod(const FloatNum& x, const FloatVal& y) {
return FloatVal(fmod(x,y.x));
}
forceinline FloatVal
sin(const FloatVal& x) {
return FloatVal(sin(x.x));
}
forceinline FloatVal
cos(const FloatVal& x) {
return FloatVal(cos(x.x));
}
forceinline FloatVal
tan(const FloatVal& x) {
return FloatVal(tan(x.x));
}
forceinline FloatVal
asin(const FloatVal& x) {
return FloatVal(asin(x.x));
}
forceinline FloatVal
acos(const FloatVal& x) {
return FloatVal(acos(x.x));
}
forceinline FloatVal
atan(const FloatVal& x) {
return FloatVal(atan(x.x));
}
forceinline FloatVal
sinh(const FloatVal& x) {
return FloatVal(sinh(x.x));
}
forceinline FloatVal
cosh(const FloatVal& x) {
return FloatVal(cosh(x.x));
}
forceinline FloatVal
tanh(const FloatVal& x) {
return FloatVal(tanh(x.x));
}
forceinline FloatVal
asinh(const FloatVal& x) {
return FloatVal(asinh(x.x));
}
forceinline FloatVal
acosh(const FloatVal& x) {
return FloatVal(acosh(x.x));
}
forceinline FloatVal
atanh(const FloatVal& x) {
return FloatVal(atanh(x.x));
}
#endif
}
namespace Gecode { namespace Float {
forceinline bool
subset(const FloatVal& x, const FloatVal& y) {
return subset(x.x,y.x);
}
forceinline bool
proper_subset(const FloatVal& x, const FloatVal& y) {
return proper_subset(x.x,y.x);
}
forceinline bool
overlap(const FloatVal& x, const FloatVal& y) {
return overlap(x.x,y.x);
}
forceinline FloatVal
intersect(const FloatVal& x, const FloatVal& y) {
return FloatVal(intersect(x.x,y.x));
}
forceinline FloatVal
hull(const FloatVal& x, const FloatVal& y) {
return FloatVal(hull(x.x,y.x));
}
forceinline FloatVal
hull(const FloatVal& x, const FloatNum& y) {
return FloatVal(hull(x.x,y));
}
forceinline FloatVal
hull(const FloatNum& x, const FloatVal& y) {
return FloatVal(hull(x,y.x));
}
forceinline FloatVal
hull(const FloatNum& x, const FloatNum& y) {
return FloatVal(x,y);
}
}}
// STATISTICS: float-var
Gecode::FloatVal
Float value type.
Definition float.hh:334
Gecode::FloatVal::singleton
bool singleton(void) const
Test whether float is a singleton.
Definition val.hpp:92
Gecode::FloatVal::hull
friend FloatVal Float::hull(const FloatVal &x, const FloatVal &y)
Gecode::FloatVal::operator/=
FloatVal & operator/=(const FloatNum &n)
Divide by n.
Definition val.hpp:137
Gecode::FloatVal::pi
static FloatVal pi(void)
Return lower bound of .
Definition val.hpp:114
Gecode::FloatVal::FloatValImpType
boost::numeric::interval< FloatNum, boost::numeric::interval_lib::policies< R, P > > FloatValImpType
Implementation type for float value.
Definition float.hh:423
Gecode::FloatVal::pi_twice
static FloatVal pi_twice(void)
Return .
Definition val.hpp:119
Gecode::FloatVal::x
FloatValImpType x
Implementation of float value.
Definition float.hh:425
Gecode::FloatVal::zero_in
bool zero_in(void) const
Test whether zero is included.
Definition val.hpp:100
Gecode::FloatVal::operator-=
FloatVal & operator-=(const FloatNum &n)
Subtract by n.
Definition val.hpp:129
Gecode::FloatVal::in
bool in(FloatNum n) const
Test whether n is included.
Definition val.hpp:96
Gecode::FloatVal::operator*=
FloatVal & operator*=(const FloatNum &n)
Multiply by n.
Definition val.hpp:133
Gecode::FloatVal::max
FloatNum max(void) const
Return upper bound.
Definition val.hpp:74
Gecode::FloatVal::assign
void assign(FloatNum const &l, FloatNum const &u)
Assign lower bound l and upper bound u.
Definition val.hpp:65
Gecode::FloatVal::operator+=
FloatVal & operator+=(const FloatNum &n)
Increment by n.
Definition val.hpp:125
Gecode::FloatVal::med
FloatNum med(void) const
Return median of float value.
Definition val.hpp:82
Gecode::FloatVal::operator=
FloatVal & operator=(const FloatNum &n)
Assignment operator.
Definition val.hpp:56
Gecode::FloatVal::max
friend FloatVal max(const FloatVal &x, const FloatVal &y)
Definition val.hpp:386
Gecode::FloatVal::min
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Definition val.hpp:398
Gecode::FloatVal::tight
bool tight(void) const
Test whether float is tight.
Definition val.hpp:87
Gecode::FloatVal::size
FloatNum size(void) const
Return size of float value (distance between maximum and minimum).
Definition val.hpp:78
Gecode::FloatVal::pi_half
static FloatVal pi_half(void)
Return .
Definition val.hpp:109
Gecode::FloatVal::FloatVal
FloatVal(const FloatValImpType &i)
Initialize from implementation i.
Definition val.hpp:51
Gecode::FloatVal::FloatVal
FloatVal(void)
Default constructor.
Definition val.hpp:45
Gecode::FloatVal::min
FloatNum min(void) const
Return lower bound.
Definition val.hpp:70
Gecode::FloatNum
double FloatNum
Floating point number base type.
Definition float.hh:106
Gecode::Float::subset
bool subset(const FloatVal &x, const FloatVal &y)
Definition val.hpp:490
Gecode::Float::proper_subset
bool proper_subset(const FloatVal &x, const FloatVal &y)
Definition val.hpp:494
Gecode::Float::hull
FloatVal hull(const FloatVal &x, const FloatVal &y)
Definition val.hpp:507
Gecode::Float::overlap
bool overlap(const FloatVal &x, const FloatVal &y)
Definition val.hpp:498
Gecode::Float::intersect
FloatVal intersect(const FloatVal &x, const FloatVal &y)
Definition val.hpp:503
Gecode
Gecode toplevel namespace
Gecode::operator/
FloatVal operator/(const FloatVal &x, const FloatVal &y)
Definition val.hpp:213
Gecode::operator-
FloatVal operator-(const FloatVal &x)
Definition val.hpp:168
Gecode::asinh
FloatVal asinh(const FloatVal &x)
Definition val.hpp:472
Gecode::operator<=
bool operator<=(const FloatVal &x, const FloatVal &y)
Definition val.hpp:243
Gecode::sin
void sin(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition trigonometric.cpp:52
Gecode::operator+
FloatVal operator+(const FloatVal &x)
Definition val.hpp:164
Gecode::sqr
void sqr(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition arithmetic.cpp:95
Gecode::operator<<
Archive & operator<<(Archive &e, FloatNumBranch nl)
Definition val-sel.hpp:39
Gecode::cos
void cos(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition trigonometric.cpp:66
Gecode::min
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition arithmetic.cpp:67
Gecode::abs
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition arithmetic.cpp:41
Gecode::operator<
bool operator<(const FloatVal &x, const FloatVal &y)
Definition val.hpp:226
Gecode::sqrt
void sqrt(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition arithmetic.cpp:102
Gecode::acos
void acos(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition trigonometric.cpp:59
Gecode::operator>
bool operator>(const FloatVal &x, const FloatVal &y)
Definition val.hpp:260
Gecode::log
void log(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition transcendental.cpp:53
Gecode::operator>=
bool operator>=(const FloatVal &x, const FloatVal &y)
Definition val.hpp:277
Gecode::exp
void exp(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition transcendental.cpp:45
Gecode::atan
void atan(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition trigonometric.cpp:73
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition arithmetic.cpp:49
Gecode::fmod
FloatVal fmod(const FloatVal &x, const FloatVal &y)
Definition val.hpp:422
Gecode::sinh
FloatVal sinh(const FloatVal &x)
Definition val.hpp:460
Gecode::acosh
FloatVal acosh(const FloatVal &x)
Definition val.hpp:476
Gecode::tanh
FloatVal tanh(const FloatVal &x)
Definition val.hpp:468
Gecode::asin
void asin(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition trigonometric.cpp:45
Gecode::pow
void pow(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n\geq 0$.
Definition arithmetic.cpp:109
Gecode::atanh
FloatVal atanh(const FloatVal &x)
Definition val.hpp:480
Gecode::operator*
FloatVal operator*(const FloatVal &x, const FloatVal &y)
Definition val.hpp:200
Gecode::cosh
FloatVal cosh(const FloatVal &x)
Definition val.hpp:464
Gecode::nroot
void nroot(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n\geq 0$.
Definition arithmetic.cpp:118
Gecode::operator==
bool operator==(const FloatVal &x, const FloatVal &y)
Definition val.hpp:294
Gecode::operator!=
bool operator!=(const FloatVal &x, const FloatVal &y)
Definition val.hpp:317
Gecode::tan
void tan(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition trigonometric.cpp:80
forceinline
#define forceinline
Definition config.hpp:187