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>
*
* Contributing authors:
* Samuel Gagnon <samuel.gagnon92@gmail.com>
*
* Copyright:
* Christian Schulte, 2002
* Samuel Gagnon, 2018
*
* 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.
*
*/
#include <gecode/int/div.hh>
namespace Gecode { namespace Int {
/*
* Constructors and initialization
*
*/
template<class Val, class UnsVal>
forceinline
ScaleView<Val,UnsVal>::ScaleView(void) {}
template<class Val, class UnsVal>
forceinline
ScaleView<Val,UnsVal>::ScaleView(int b, const IntView& y)
: DerivedView<IntView>(y), a(b) {}
/*
* Value access
*
*/
template<class Val, class UnsVal>
forceinline int
ScaleView<Val,UnsVal>::scale(void) const {
return a;
}
template<class Val, class UnsVal>
forceinline Val
ScaleView<Val,UnsVal>::min(void) const {
return static_cast<Val>(x.min()) * a;
}
template<class Val, class UnsVal>
forceinline Val
ScaleView<Val,UnsVal>::max(void) const {
return static_cast<Val>(x.max()) * a;
}
template<class Val, class UnsVal>
forceinline Val
ScaleView<Val,UnsVal>::med(void) const {
return static_cast<Val>(x.med()) * a;
}
template<class Val, class UnsVal>
forceinline Val
ScaleView<Val,UnsVal>::val(void) const {
return static_cast<Val>(x.val()) * a;
}
#ifdef GECODE_HAS_CBS
template<class Val, class UnsVal>
forceinline Val
ScaleView<Val,UnsVal>::baseval(Val val) const {
return val / a;
}
#endif
template<class Val, class UnsVal>
forceinline UnsVal
ScaleView<Val,UnsVal>::size(void) const {
return static_cast<UnsVal>(x.size());
}
template<class Val, class UnsVal>
forceinline UnsVal
ScaleView<Val,UnsVal>::width(void) const {
return static_cast<UnsVal>(x.width()) * a;
}
template<class Val, class UnsVal>
forceinline UnsVal
ScaleView<Val,UnsVal>::regret_min(void) const {
return static_cast<UnsVal>(x.regret_min()) * a;
}
template<class Val, class UnsVal>
forceinline UnsVal
ScaleView<Val,UnsVal>::regret_max(void) const {
return static_cast<UnsVal>(x.regret_max()) * a;
}
/*
* Domain tests
*
*/
template<class Val, class UnsVal>
forceinline bool
ScaleView<Val,UnsVal>::range(void) const {
return x.range();
}
template<class Val, class UnsVal>
forceinline bool
ScaleView<Val,UnsVal>::in(Val n) const {
return ((n % a) == 0) && x.in(n / a);
}
/*
* Domain update by value
*
*/
template<class Val, class UnsVal>
forceinline ModEvent
ScaleView<Val,UnsVal>::lq(Space& home, Val n) {
return (n >= max()) ? ME_INT_NONE :
x.lq(home,floor_div_xp(n,static_cast<Val>(a)));
}
template<class Val, class UnsVal>
forceinline ModEvent
ScaleView<Val,UnsVal>::le(Space& home, Val n) {
return (n > max()) ? ME_INT_NONE :
x.le(home,floor_div_xp(n,static_cast<Val>(a)));
}
template<class Val, class UnsVal>
forceinline ModEvent
ScaleView<Val,UnsVal>::gq(Space& home, Val n) {
return (n <= min()) ? ME_INT_NONE :
x.gq(home,ceil_div_xp(n,static_cast<Val>(a)));
}
template<class Val, class UnsVal>
forceinline ModEvent
ScaleView<Val,UnsVal>::gr(Space& home, Val n) {
return (n < min()) ? ME_INT_NONE :
x.gr(home,ceil_div_xp(n,static_cast<Val>(a)));
}
template<class Val, class UnsVal>
forceinline ModEvent
ScaleView<Val,UnsVal>::nq(Space& home, Val n) {
return ((n % a) == 0) ? x.nq(home,n/a) : ME_INT_NONE;
}
template<class Val, class UnsVal>
forceinline ModEvent
ScaleView<Val,UnsVal>::eq(Space& home, Val n) {
return ((n % a) == 0) ? x.eq(home,n/a) : ME_INT_FAILED;
}
/*
* Propagator modification events
*
*/
template<class Val, class UnsVal>
forceinline ModEventDelta
ScaleView<Val,UnsVal>::med(ModEvent me) {
return IntView::med(me);
}
/*
* Delta information for advisors
*
*/
template<class Val, class UnsVal>
forceinline Val
ScaleView<Val,UnsVal>::min(const Delta& d) const {
return static_cast<Val>(x.min(d)) * a;
}
template<class Val, class UnsVal>
forceinline Val
ScaleView<Val,UnsVal>::max(const Delta& d) const {
return static_cast<Val>(x.max(d)) * a;
}
template<class Val, class UnsVal>
forceinline UnsVal
ScaleView<Val,UnsVal>::width(const Delta& d) const {
return static_cast<UnsVal>(x.width(d)) * a;
}
template<class Val, class UnsVal>
forceinline bool
ScaleView<Val,UnsVal>::any(const Delta& d) const {
return x.any(d);
}
/*
* Cloning
*
*/
template<class Val, class UnsVal>
forceinline void
ScaleView<Val,UnsVal>::update(Space& home, ScaleView<Val,UnsVal>& y) {
DerivedView<IntView>::update(home,y);
a=y.a;
}
/*
* Ordering
*
*/
template<class Val, class UnsVal>
forceinline bool
ScaleView<Val,UnsVal>::operator <(const ScaleView<Val,UnsVal>& y) const {
return ((base() < y.base())
|| ((base() == y.base()) && (scale() < y.scale())));
}
template<>
class ViewRanges<IntScaleView>
: public Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> > {
public:
ViewRanges(void);
ViewRanges(const IntScaleView& x);
void init(const IntScaleView& x);
};
forceinline
ViewRanges<IntScaleView>::ViewRanges(void) {}
forceinline
ViewRanges<IntScaleView>::ViewRanges(const IntScaleView& x) {
ViewRanges<IntView> xi(x.base());
Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> >::init
(xi,x.scale());
}
forceinline void
ViewRanges<IntScaleView>::init(const IntScaleView& x) {
ViewRanges<IntView> xi(x.base());
Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> >::init
(xi,x.scale());
}
template<>
class ViewRanges<LLongScaleView>
: public Iter::Ranges::ScaleUp<long long int,unsigned long long int,
ViewRanges<IntView> > {
public:
ViewRanges(void);
ViewRanges(const LLongScaleView& x);
void init(const LLongScaleView& x);
};
forceinline
ViewRanges<LLongScaleView>::ViewRanges(void) {}
forceinline
ViewRanges<LLongScaleView>::ViewRanges(const LLongScaleView& x) {
ViewRanges<IntView> xi(x.base());
Iter::Ranges::ScaleUp<long long int,unsigned long long int,
ViewRanges<IntView> >::init(xi,x.scale());
}
forceinline void
ViewRanges<LLongScaleView>::init(const LLongScaleView& x) {
ViewRanges<IntView> xi(x.base());
Iter::Ranges::ScaleUp<long long int,unsigned long long int,
ViewRanges<IntView> >::init(xi,x.scale());
}
/*
* View comparison
*
*/
template<class Val, class UnsVal>
forceinline bool
operator ==(const ScaleView<Val,UnsVal>& x, const ScaleView<Val,UnsVal>& y) {
return (x.base() == y.base()) && (x.scale() == y.scale());
}
template<class Val, class UnsVal>
forceinline bool
operator !=(const ScaleView<Val,UnsVal>& x, const ScaleView<Val,UnsVal>& y) {
return !(x == y);
}
}}
// STATISTICS: int-var
Gecode::Delta
Generic domain change information to be supplied to advisors.
Definition core.hpp:204
Gecode::DerivedView< IntView >::base
IntView base(void) const
Definition view.hpp:605
Gecode::DerivedView< IntView >::x
IntView x
Definition view.hpp:238
Gecode::DerivedView< IntView >::DerivedView
DerivedView(void)
Definition view.hpp:584
Gecode::DerivedView< IntView >::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::Int::IntView
Integer view for integer variables.
Definition view.hpp:129
Gecode::Int::IntView::med
int med(void) const
Return median of domain (greatest element not greater than the median).
Definition int.hpp:66
Gecode::Int::ScaleView
Scale integer view (template).
Definition view.hpp:704
Gecode::Int::ScaleView::val
Val val(void) const
Return assigned value (only if assigned).
Definition scale.hpp:85
Gecode::Int::ScaleView::gq
ModEvent gq(Space &home, Val n)
Restrict domain values to be greater or equal than n.
Definition scale.hpp:159
Gecode::Int::ScaleView::scale
int scale(void) const
Return scale factor of scale view.
Definition scale.hpp:62
Gecode::Int::ScaleView::in
bool in(Val n) const
Test whether n is contained in domain.
Definition scale.hpp:132
Gecode::Int::ScaleView::range
bool range(void) const
Test whether domain is a range.
Definition scale.hpp:127
Gecode::Int::ScaleView::update
void update(Space &home, ScaleView< Val, UnsVal > &y)
Update this view to be a clone of view y.
Definition scale.hpp:228
Gecode::Int::ScaleView::any
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition scale.hpp:216
Gecode::Int::ScaleView::le
ModEvent le(Space &home, Val n)
Restrict domain values to be less than n.
Definition scale.hpp:152
Gecode::Int::ScaleView::regret_max
UnsVal regret_max(void) const
Return regret of domain maximum (distance to next smaller value).
Definition scale.hpp:116
Gecode::Int::ScaleView::width
UnsVal width(void) const
Return width of domain (distance between maximum and minimum).
Definition scale.hpp:104
Gecode::Int::ScaleView::max
Val max(void) const
Return maximum of domain.
Definition scale.hpp:73
Gecode::Int::ScaleView::a
int a
Scale factor.
Definition view.hpp:708
Gecode::Int::ScaleView::med
Val med(void) const
Return median of domain (greatest element not greater than the median).
Definition scale.hpp:79
Gecode::Int::ScaleView::gr
ModEvent gr(Space &home, Val n)
Restrict domain values to be greater than n.
Definition scale.hpp:165
Gecode::Int::ScaleView::operator<
bool operator<(const ScaleView< Val, UnsVal > &y) const
Whether this view comes before view y (arbitray order).
Definition scale.hpp:240
Gecode::Int::ScaleView::min
Val min(void) const
Return minimum of domain.
Definition scale.hpp:67
Gecode::Int::ScaleView::eq
ModEvent eq(Space &home, Val n)
Restrict domain values to be equal to n.
Definition scale.hpp:178
Gecode::Int::ScaleView::nq
ModEvent nq(Space &home, Val n)
Restrict domain values to be different from n.
Definition scale.hpp:172
Gecode::Int::ScaleView::regret_min
UnsVal regret_min(void) const
Return regret of domain minimum (distance to next larger value).
Definition scale.hpp:110
Gecode::Int::ScaleView::lq
ModEvent lq(Space &home, Val n)
Restrict domain values to be less or equal than n.
Definition scale.hpp:145
Gecode::Int::ScaleView::size
UnsVal size(void) const
Return size (cardinality) of domain.
Definition scale.hpp:98
Gecode::Int::ScaleView::ScaleView
ScaleView(void)
Default constructor.
Definition scale.hpp:48
Gecode::Int::ViewRanges< IntScaleView >::ViewRanges
ViewRanges(void)
Default constructor.
Definition scale.hpp:268
Gecode::Int::ViewRanges< IntScaleView >::init
void init(const IntScaleView &x)
Initialize with ranges for view x.
Definition scale.hpp:276
Gecode::Int::ViewRanges< LLongScaleView >::ViewRanges
ViewRanges(void)
Default constructor.
Definition scale.hpp:304
Gecode::Int::ViewRanges< LLongScaleView >::init
void init(const LLongScaleView &x)
Initialize with ranges for view x.
Definition scale.hpp:312
Gecode::Int::ViewRanges::init
void init(const View &x)
Initialize with ranges for view x.
Gecode::Int::ViewRanges::ViewRanges
ViewRanges(void)
Default constructor.
Gecode::Iter::Ranges::ScaleUp
Range iterator for pointwise product with a positive integer.
Definition ranges-scale.hpp:49
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::Val
div.hh
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
Gecode::Int
Finite domain integers.
Gecode::Int::ceil_div_xp
IntType ceil_div_xp(IntType x, IntType y)
Compute where y is non-negative.
Definition div.hpp:69
Gecode::Int::ME_INT_FAILED
const Gecode::ModEvent ME_INT_FAILED
Domain operation has resulted in failure.
Definition var-type.hpp:52
Gecode::Int::floor_div_xp
IntType floor_div_xp(IntType x, IntType y)
Compute where y is non-negative.
Definition div.hpp:75
Gecode::Int::operator==
bool operator==(const CachedView< View > &x, const CachedView< View > &y)
Definition cached.hpp:401
Gecode::Int::operator!=
bool operator!=(const CachedView< View > &x, const CachedView< View > &y)
Definition cached.hpp:406
Gecode::Int::ME_INT_NONE
const Gecode::ModEvent ME_INT_NONE
Domain operation has not changed domain.
Definition var-type.hpp:54
Gecode
Gecode toplevel namespace
Gecode::min
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition arithmetic.cpp:67
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition arithmetic.cpp:49
Gecode::ModEvent
int ModEvent
Type for modification events.
Definition core.hpp:62
forceinline
#define forceinline
Definition config.hpp:187