scale.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
* Vincent Barichard <Vincent.Barichard@univ-angers.fr>
*
* Copyright:
* Christian Schulte, 2002
* 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 {
/*
* Constructors and initialization
*
*/
forceinline
ScaleView::ScaleView(void) {}
forceinline
ScaleView::ScaleView(FloatVal d, const FloatView& y)
: DerivedView<FloatView>(y), a(d) {}
/*
* Value access
*
*/
forceinline FloatVal
ScaleView::scale(void) const {
return a;
}
forceinline FloatVal
ScaleView::domain(void) const {
return x.domain()*a;
}
forceinline FloatNum
ScaleView::min(void) const {
FloatVal c = x.min(); c *= a; return c.min();
}
forceinline FloatNum
ScaleView::max(void) const {
FloatVal c = x.max(); c *= a; return c.max();
}
forceinline FloatNum
ScaleView::med(void) const {
FloatVal c = x.med(); c *= a; return (c.min()+c.max())/2;
}
forceinline FloatVal
ScaleView::val(void) const {
FloatVal c = x.val(); c *= a; return c;
}
forceinline FloatNum
ScaleView::size(void) const {
FloatVal c = x.size(); c *= a; return c.max();
}
/*
* Domain tests
*
*/
forceinline bool
ScaleView::zero_in(void) const {
return x.zero_in();
}
forceinline bool
ScaleView::in(FloatNum n) const {
return x.in(n/a);
}
forceinline bool
ScaleView::in(const FloatVal& n) const {
return x.in(n/a);
}
/*
* Domain update by value
*
*/
forceinline ModEvent
ScaleView::lq(Space& home, int n) {
FloatVal c = n; c /= a;
return x.lq(home,c.max());
}
forceinline ModEvent
ScaleView::lq(Space& home, FloatNum n) {
FloatVal c = n; c /= a;
return x.lq(home,c.max());
}
forceinline ModEvent
ScaleView::lq(Space& home, FloatVal n) {
FloatVal c = n; c /= a;
return x.lq(home,c.max());
}
forceinline ModEvent
ScaleView::gq(Space& home, int n) {
FloatVal c = n; c /= a;
return x.gq(home,c.min());
}
forceinline ModEvent
ScaleView::gq(Space& home, FloatNum n) {
FloatVal c = n; c /= a;
return x.gq(home,c.min());
}
forceinline ModEvent
ScaleView::gq(Space& home, FloatVal n) {
FloatVal c = n; c /= a;
return x.gq(home,c.min());
}
forceinline ModEvent
ScaleView::eq(Space& home, int n) {
FloatVal c = n; c /= a;
return x.eq(home,c);
}
forceinline ModEvent
ScaleView::eq(Space& home, FloatNum n) {
FloatVal c = n; c /= a;
return x.eq(home,c);
}
forceinline ModEvent
ScaleView::eq(Space& home, const FloatVal& n) {
FloatVal c = n; c /= a;
return x.eq(home,c);
}
/*
* Delta information for advisors
*
*/
forceinline FloatNum
ScaleView::min(const Delta& d) const {
FloatVal c = x.min(d); c *= a; return c.min();
}
forceinline FloatNum
ScaleView::max(const Delta& d) const {
FloatVal c = x.max(d); c *= a; return c.max();
}
forceinline ModEventDelta
ScaleView::med(ModEvent me) {
return VarImpView<FloatVar>::med(me);
}
/*
* Cloning
*
*/
forceinline void
ScaleView::update(Space& home, ScaleView& y) {
DerivedView<FloatView>::update(home,y);
a=y.a;
}
/*
* Ordering
*
*/
forceinline bool
ScaleView::operator <(const ScaleView& y) const {
return ((base() < y.base())
|| ((base() == y.base()) && (scale() < y.scale())));
}
/*
* View comparison
*
*/
forceinline bool
operator ==(const ScaleView& x, const ScaleView& y) {
return (x.base() == y.base()) && (x.scale() == y.scale());
}
forceinline bool
operator !=(const ScaleView& x, const ScaleView& y) {
return !(x == y);
}
}}
// STATISTICS: float-var
Gecode::Delta
Generic domain change information to be supplied to advisors.
Definition core.hpp:204
Gecode::DerivedView< FloatView >::base
FloatView base(void) const
Definition view.hpp:605
Gecode::DerivedView< FloatView >::x
FloatView x
Definition view.hpp:238
Gecode::DerivedView< FloatView >::DerivedView
DerivedView(void)
Definition view.hpp:584
Gecode::DerivedView< FloatView >::me
static ModEvent me(const ModEventDelta &med)
Definition view.hpp:639
Gecode::DerivedView::update
void update(Space &home, DerivedView< View > &y)
Update this view to be a clone of view y.
Definition view.hpp:681
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::FloatView
Float view for float variables.
Definition view.hpp:52
Gecode::Float::ScaleView::scale
FloatVal scale(void) const
Return scale factor of scale view.
Definition scale.hpp:54
Gecode::Float::ScaleView::update
void update(Space &home, ScaleView &y)
Definition scale.hpp:179
Gecode::Float::ScaleView::a
FloatVal a
Scale factor.
Definition view.hpp:399
Gecode::Float::ScaleView::zero_in
bool zero_in(void) const
Test whether 0 is contained in domain.
Definition scale.hpp:89
Gecode::Float::ScaleView::min
FloatNum min(void) const
Return minimum of domain.
Definition scale.hpp:62
Gecode::Float::ScaleView::lq
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition scale.hpp:107
Gecode::Float::ScaleView::operator<
bool operator<(const ScaleView &y) const
Whether this view comes before view y (arbitray order).
Definition scale.hpp:189
Gecode::Float::ScaleView::size
FloatNum size(void) const
Return size of domain (distance between maximum and minimum).
Definition scale.hpp:79
Gecode::Float::ScaleView::gq
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition scale.hpp:123
Gecode::Float::ScaleView::med
FloatNum med(void) const
Return median of domain (closest representation).
Definition scale.hpp:70
Gecode::Float::ScaleView::ScaleView
ScaleView(void)
Default constructor.
Definition scale.hpp:43
Gecode::Float::ScaleView::in
bool in(FloatNum n) const
Test whether n is contained in domain.
Definition scale.hpp:93
Gecode::Float::ScaleView::val
FloatVal val(void) const
Return assigned value.
Definition scale.hpp:74
Gecode::Float::ScaleView::domain
FloatVal domain(void) const
Return domain.
Definition scale.hpp:58
Gecode::Float::ScaleView::max
FloatNum max(void) const
Return maximum of domain.
Definition scale.hpp:66
Gecode::Float::ScaleView::eq
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition scale.hpp:139
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::VarImpView::med
static ModEventDelta med(ModEvent me)
Translate modification event me to modification event delta for view.
Definition view.hpp:557
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::operator!=
bool operator!=(const MinusView &x, const MinusView &y)
Definition minus.hpp:169
Gecode::Float::operator==
bool operator==(const MinusView &x, const MinusView &y)
Definition minus.hpp:165
Gecode
Gecode toplevel namespace
Gecode::ModEvent
int ModEvent
Type for modification events.
Definition core.hpp:62
forceinline
#define forceinline
Definition config.hpp:187