float.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Filip Konvicka <filip.konvicka@logis.cz>
* Lubomir Moric <lubomir.moric@logis.cz>
* Vincent Barichard <Vincent.Barichard@univ-angers.fr>
*
* Contributing authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* LOGIS, s.r.o., 2008
* Christian Schulte, 2010
* 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 { namespace Float {
/*
* Creation of new variable implementations
*
*/
forceinline
FloatVarImp::FloatVarImp(Space& home, const FloatVal& d)
: FloatVarImpBase(home), dom(d) {}
forceinline
FloatVarImp::FloatVarImp(Space& home, FloatVarImp& x)
: FloatVarImpBase(home, x), dom(x.dom) {}
/*
* Operations on float variable implementations
*
*/
forceinline FloatVal
FloatVarImp::domain(void) const {
return dom;
}
forceinline FloatNum
FloatVarImp::min(void) const {
return dom.min();
}
forceinline FloatNum
FloatVarImp::max(void) const {
return dom.max();
}
forceinline FloatVal
FloatVarImp::val(void) const {
return dom;
}
forceinline FloatNum
FloatVarImp::med(void) const {
return dom.med();
}
forceinline bool
FloatVarImp::assigned(void) const {
return dom.tight();
}
forceinline FloatNum
FloatVarImp::size(void) const {
return dom.size();
}
/*
* Tests
*
*/
forceinline bool
FloatVarImp::zero_in(void) const {
return dom.zero_in();
}
forceinline bool
FloatVarImp::in(FloatNum n) const {
return dom.in(n);
}
forceinline bool
FloatVarImp::in(const FloatVal& n) const {
return subset(n,dom);
}
/*
* Support for delta information
*
*/
forceinline FloatNum
FloatVarImp::min(const Delta& d) {
return static_cast<const FloatDelta&>(d).min();
}
forceinline FloatNum
FloatVarImp::max(const Delta& d) {
return static_cast<const FloatDelta&>(d).max();
}
/*
* Tell operations (to be inlined: performing bounds checks first)
*
*/
forceinline ModEvent
FloatVarImp::gq(Space& home, FloatNum n) {
if (n > dom.max()) return fail(home);
if ((n <= dom.min()) || assigned()) return ME_FLOAT_NONE;
FloatDelta d(dom.min(),n);
ModEvent me = ME_FLOAT_BND;
dom = intersect(dom,FloatVal(n,dom.max()));
if (assigned()) me = ME_FLOAT_VAL;
GECODE_ASSUME((me == ME_FLOAT_VAL) |
(me == ME_FLOAT_BND));
return notify(home,me,d);
}
forceinline ModEvent
FloatVarImp::gq(Space& home, const FloatVal& n) {
if (n.min() > dom.max()) return fail(home);
if ((n.min() <= dom.min()) || assigned()) return ME_FLOAT_NONE;
FloatDelta d(dom.min(),n.min());
ModEvent me = ME_FLOAT_BND;
dom = intersect(dom,FloatVal(n.min(),dom.max()));
if (assigned()) me = ME_FLOAT_VAL;
GECODE_ASSUME((me == ME_FLOAT_VAL) |
(me == ME_FLOAT_BND));
return notify(home,me,d);
}
forceinline ModEvent
FloatVarImp::lq(Space& home, FloatNum n) {
if (n < dom.min()) return fail(home);
if ((n >= dom.max()) || assigned()) return ME_FLOAT_NONE;
FloatDelta d(n,dom.max());
ModEvent me = ME_FLOAT_BND;
dom = intersect(dom,FloatVal(dom.min(),n));
if (assigned()) me = ME_FLOAT_VAL;
GECODE_ASSUME((me == ME_FLOAT_VAL) |
(me == ME_FLOAT_BND));
return notify(home,me,d);
}
forceinline ModEvent
FloatVarImp::lq(Space& home, const FloatVal& n) {
if (n.max() < dom.min()) return fail(home);
if ((n.max() >= dom.max()) || assigned()) return ME_FLOAT_NONE;
FloatDelta d(n.max(),dom.max());
ModEvent me = ME_FLOAT_BND;
dom = intersect(dom,FloatVal(dom.min(),n.max()));
if (assigned()) me = ME_FLOAT_VAL;
GECODE_ASSUME((me == ME_FLOAT_VAL) |
(me == ME_FLOAT_BND));
return notify(home,me,d);
}
forceinline ModEvent
FloatVarImp::eq(Space& home, FloatNum n) {
if (!dom.in(n))
return fail(home);
if (assigned())
return ME_FLOAT_NONE;
FloatDelta d;
dom = n;
return notify(home,ME_FLOAT_VAL,d);
}
forceinline ModEvent
FloatVarImp::eq(Space& home, const FloatVal& n) {
if (!overlap(dom,n))
return fail(home);
if (assigned() || subset(dom,n))
return ME_FLOAT_NONE;
FloatDelta d;
ModEvent me = ME_FLOAT_BND;
dom = intersect(dom,n);
if (assigned()) me = ME_FLOAT_VAL;
GECODE_ASSUME((me == ME_FLOAT_VAL) |
(me == ME_FLOAT_BND));
return notify(home,me,d);
}
/*
* Copying a variable
*
*/
forceinline FloatVarImp*
FloatVarImp::copy(Space& home) {
return copied() ? static_cast<FloatVarImp*>(forward())
: perform_copy(home);
}
forceinline FloatVarImp*
FloatVarImp::perform_copy(Space& home) {
return new (home) FloatVarImp(home, *this);
}
forceinline ModEventDelta
FloatVarImp::med(ModEvent me) {
return FloatVarImpBase::med(me);
}
}}
// STATISTICS: float-var
Gecode::Delta
Generic domain change information to be supplied to advisors.
Definition core.hpp:204
Gecode::FloatVal
Float value type.
Definition float.hh:334
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::Float::FloatDelta
Float delta information for advisors.
Definition var-imp.hpp:48
Gecode::Float::FloatVarImpBase::FloatVarImpBase
FloatVarImpBase(Gecode::Space &home, FloatVarImpBase &x)
Constructor for cloning x.
Definition var-imp.hpp:435
Gecode::Float::FloatVarImpBase::notify
Gecode::ModEvent notify(Gecode::Space &home, Gecode::ModEvent me, Gecode::Delta &d)
Notify that variable implementation has been modified with modification event me and delta informatio...
Definition var-imp.hpp:457
Gecode::Float::FloatVarImp
Float variable implementation.
Definition var-imp.hpp:76
Gecode::Float::FloatVarImp::zero_in
bool zero_in(void) const
Test whether 0 is contained in domain.
Definition float.hpp:100
Gecode::Float::FloatVarImp::min
FloatNum min(void) const
Return minimum of domain.
Definition float.hpp:67
Gecode::Float::FloatVarImp::FloatVarImp
FloatVarImp(Space &home, FloatVarImp &x)
Constructor for cloning x.
Definition float.hpp:53
Gecode::Float::FloatVarImp::eq
ModEvent eq(Space &home, FloatNum n)
Restrict domain values to be equal to n.
Definition float.hpp:185
Gecode::Float::FloatVarImp::max
FloatNum max(void) const
Return maximum of domain.
Definition float.hpp:71
Gecode::Float::FloatVarImp::val
FloatVal val(void) const
Return value of domain (only if assigned).
Definition float.hpp:75
Gecode::Float::FloatVarImp::dom
FloatVal dom
Domain information.
Definition var-imp.hpp:79
Gecode::Float::FloatVarImp::in
bool in(FloatNum n) const
Test whether n is contained in domain.
Definition float.hpp:104
Gecode::Float::FloatVarImp::copy
FloatVarImp * copy(Space &home)
Return copy of this variable.
Definition float.hpp:216
Gecode::Float::FloatVarImp::size
FloatNum size(void) const
Return width of domain (distance between maximum and minimum).
Definition float.hpp:89
Gecode::Float::FloatVarImp::med
FloatNum med(void) const
Return median of domain (closest representation).
Definition float.hpp:79
Gecode::Float::FloatVarImp::lq
ModEvent lq(Space &home, FloatNum n)
Restrict domain values to be less or equal than n.
Definition float.hpp:159
Gecode::Float::FloatVarImp::gq
ModEvent gq(Space &home, FloatNum n)
Restrict domain values to be greater or equal than n.
Definition float.hpp:133
Gecode::Float::FloatVarImp::assigned
bool assigned(void) const
Test whether variable is assigned.
Definition float.hpp:84
Gecode::Float::FloatVarImp::domain
FloatVal domain(void) const
Return domain.
Definition float.hpp:63
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::VarImp< Gecode::Float::FloatVarImpConf >::fail
ModEvent fail(Space &home)
Definition core.hpp:4570
Gecode::VarImp< Gecode::Float::FloatVarImpConf >::copied
bool copied(void) const
Definition core.hpp:4222
Gecode::VarImp< Gecode::Float::FloatVarImpConf >::forward
VarImp * forward(void) const
Definition core.hpp:4228
Gecode::VarImp< Gecode::Float::FloatVarImpConf >::me
static ModEvent me(const ModEventDelta &med)
Definition core.hpp:4270
Gecode::VarImp< Gecode::Float::FloatVarImpConf >::med
static ModEventDelta med(ModEvent me)
Definition core.hpp:4276
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
Gecode::FloatNum
double FloatNum
Floating point number base type.
Definition float.hh:106
Gecode::Float
Floating point numbers.
Gecode::Float::subset
bool subset(const FloatVal &x, const FloatVal &y)
Definition val.hpp:490
Gecode::Float::ME_FLOAT_VAL
const Gecode::ModEvent ME_FLOAT_VAL
Domain operation has resulted in a value (assigned variable).
Definition var-type.hpp:264
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::Float::ME_FLOAT_BND
const Gecode::ModEvent ME_FLOAT_BND
Domain operation has changed the minimum or maximum of the domain.
Definition var-type.hpp:273
Gecode::Float::ME_FLOAT_NONE
const Gecode::ModEvent ME_FLOAT_NONE
Domain operation has not changed domain.
Definition var-type.hpp:262
Gecode
Gecode toplevel namespace
Gecode::ModEvent
int ModEvent
Type for modification events.
Definition core.hpp:62
forceinline
#define forceinline
Definition config.hpp:187
GECODE_ASSUME
#define GECODE_ASSUME(p)
Assert certain property.
Definition macros.hpp:114