offset.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.
*
*/
namespace Gecode { namespace Int {
/*
* Constructors and initialization
*
*/
forceinline
OffsetView::OffsetView(void) {}
forceinline
OffsetView::OffsetView(const IntView& y, int d)
: DerivedView<IntView>(y), c(d) {}
/*
* Value access
*
*/
forceinline int
OffsetView::offset(void) const {
return c;
}
forceinline void
OffsetView::offset(int n) {
c = n;
}
forceinline int
OffsetView::min(void) const {
return x.min()+c;
}
forceinline int
OffsetView::max(void) const {
return x.max()+c;
}
forceinline int
OffsetView::med(void) const {
return x.med()+c;
}
forceinline int
OffsetView::val(void) const {
return x.val()+c;
}
#ifdef GECODE_HAS_CBS
forceinline int
OffsetView::baseval(int val) const {
return val-c;
}
#endif
forceinline unsigned int
OffsetView::width(void) const {
return x.width();
}
forceinline unsigned int
OffsetView::size(void) const {
return x.size();
}
forceinline unsigned int
OffsetView::regret_min(void) const {
return x.regret_min();
}
forceinline unsigned int
OffsetView::regret_max(void) const {
return x.regret_max();
}
/*
* Domain tests
*
*/
forceinline bool
OffsetView::range(void) const {
return x.range();
}
forceinline bool
OffsetView::in(int n) const {
return x.in(n-c);
}
forceinline bool
OffsetView::in(long long int n) const {
return x.in(n-c);
}
/*
* Domain update by value
*
*/
forceinline ModEvent
OffsetView::lq(Space& home, int n) {
return x.lq(home,n-c);
}
forceinline ModEvent
OffsetView::lq(Space& home, long long int n) {
return x.lq(home,n-c);
}
forceinline ModEvent
OffsetView::le(Space& home, int n) {
return x.le(home,n-c);
}
forceinline ModEvent
OffsetView::le(Space& home, long long int n) {
return x.le(home,n-c);
}
forceinline ModEvent
OffsetView::gq(Space& home, int n) {
return x.gq(home,n-c);
}
forceinline ModEvent
OffsetView::gq(Space& home, long long int n) {
return x.gq(home,n-c);
}
forceinline ModEvent
OffsetView::gr(Space& home, int n) {
return x.gr(home,n-c);
}
forceinline ModEvent
OffsetView::gr(Space& home, long long int n) {
return x.gr(home,n-c);
}
forceinline ModEvent
OffsetView::nq(Space& home, int n) {
return x.nq(home,n-c);
}
forceinline ModEvent
OffsetView::nq(Space& home, long long int n) {
return x.nq(home,n-c);
}
forceinline ModEvent
OffsetView::eq(Space& home, int n) {
return x.eq(home,n-c);
}
forceinline ModEvent
OffsetView::eq(Space& home, long long int n) {
return x.eq(home,n-c);
}
/*
* Iterator-based domain update
*
*/
template<class I>
forceinline ModEvent
OffsetView::narrow_r(Space& home, I& i, bool depend) {
Iter::Ranges::Offset<I> oi(i,-c);
return x.narrow_r(home,oi,depend);
}
template<class I>
forceinline ModEvent
OffsetView::inter_r(Space& home, I& i, bool depend) {
Iter::Ranges::Offset<I> oi(i,-c);
return x.inter_r(home,oi,depend);
}
template<class I>
forceinline ModEvent
OffsetView::minus_r(Space& home, I& i, bool depend) {
Iter::Ranges::Offset<I> oi(i,-c);
return x.minus_r(home,oi,depend);
}
template<class I>
forceinline ModEvent
OffsetView::narrow_v(Space& home, I& i, bool depend) {
Iter::Values::Offset<I> oi(i,-c);
return x.narrow_v(home,oi,depend);
}
template<class I>
forceinline ModEvent
OffsetView::inter_v(Space& home, I& i, bool depend) {
Iter::Values::Offset<I> oi(i,-c);
return x.inter_v(home,oi,depend);
}
template<class I>
forceinline ModEvent
OffsetView::minus_v(Space& home, I& i, bool depend) {
Iter::Values::Offset<I> oi(i,-c);
return x.minus_v(home,oi,depend);
}
/*
* Propagator modification events
*
*/
forceinline ModEventDelta
OffsetView::med(ModEvent me) {
return IntView::med(me);
}
/*
* Delta information for advisors
*
*/
forceinline int
OffsetView::min(const Delta& d) const {
return x.min(d)+c;
}
forceinline int
OffsetView::max(const Delta& d) const {
return x.max(d)+c;
}
forceinline unsigned int
OffsetView::width(const Delta& d) const {
return x.width(d);
}
forceinline bool
OffsetView::any(const Delta& d) const {
return x.any(d);
}
/*
* Cloning
*
*/
forceinline void
OffsetView::update(Space& home, OffsetView& y) {
DerivedView<IntView>::update(home,y);
c=y.c;
}
/*
* Ordering
*
*/
forceinline bool
OffsetView::operator <(const OffsetView& y) const {
return ((base() < y.base())
|| ((base() == y.base()) && (offset() < y.offset())));
}
template<>
class ViewRanges<OffsetView>
: public Iter::Ranges::Offset<ViewRanges<IntView> > {
public:
ViewRanges(void);
ViewRanges(const OffsetView& x);
void init(const OffsetView& x);
};
forceinline
ViewRanges<OffsetView>::ViewRanges(void) {}
forceinline
ViewRanges<OffsetView>::ViewRanges(const OffsetView& x) {
ViewRanges<IntView> xi(x.base());
Iter::Ranges::Offset<ViewRanges<IntView> >::init(xi,x.offset());
}
forceinline void
ViewRanges<OffsetView>::init(const OffsetView& x) {
ViewRanges<IntView> xi(x.base());
Iter::Ranges::Offset<ViewRanges<IntView> >::init(xi,x.offset());
}
/*
* View comparison
*
*/
forceinline bool
operator ==(const OffsetView& x, const OffsetView& y) {
return (x.base() == y.base()) && (x.offset() == y.offset());
}
forceinline bool
operator !=(const OffsetView& x, const OffsetView& 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::OffsetView
Offset integer view.
Definition view.hpp:443
Gecode::Int::OffsetView::min
int min(void) const
Return minimum of domain.
Definition offset.hpp:64
Gecode::Int::OffsetView::gr
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition offset.hpp:154
Gecode::Int::OffsetView::lq
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition offset.hpp:127
Gecode::Int::OffsetView::val
int val(void) const
Return assigned value (only if assigned).
Definition offset.hpp:76
Gecode::Int::OffsetView::update
void update(Space &home, OffsetView &y)
Update this view to be a clone of view y.
Definition offset.hpp:262
Gecode::Int::OffsetView::inter_r
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition offset.hpp:193
Gecode::Int::OffsetView::c
int c
Offset.
Definition view.hpp:446
Gecode::Int::OffsetView::med
int med(void) const
Return median of domain (greatest element not greater than the median).
Definition offset.hpp:72
Gecode::Int::OffsetView::regret_min
unsigned int regret_min(void) const
Return regret of domain minimum (distance to next larger value).
Definition offset.hpp:95
Gecode::Int::OffsetView::narrow_v
ModEvent narrow_v(Space &home, I &i, bool depends=true)
Replace domain by values described by i.
Definition offset.hpp:205
Gecode::Int::OffsetView::size
unsigned int size(void) const
Return size (cardinality) of domain.
Definition offset.hpp:91
Gecode::Int::OffsetView::regret_max
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value).
Definition offset.hpp:99
Gecode::Int::OffsetView::minus_v
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
Definition offset.hpp:217
Gecode::Int::OffsetView::offset
int offset(void) const
Return offset.
Definition offset.hpp:56
Gecode::Int::OffsetView::max
int max(void) const
Return maximum of domain.
Definition offset.hpp:68
Gecode::Int::OffsetView::width
unsigned int width(void) const
Return width of domain (distance between maximum and minimum).
Definition offset.hpp:87
Gecode::Int::OffsetView::any
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition offset.hpp:251
Gecode::Int::OffsetView::OffsetView
OffsetView(void)
Default constructor.
Definition offset.hpp:45
Gecode::Int::OffsetView::in
bool in(int n) const
Test whether n is contained in domain.
Definition offset.hpp:112
Gecode::Int::OffsetView::operator<
bool operator<(const OffsetView &y) const
Whether this view comes before view y (arbitray order).
Definition offset.hpp:273
Gecode::Int::OffsetView::minus_r
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition offset.hpp:199
Gecode::Int::OffsetView::gq
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition offset.hpp:145
Gecode::Int::OffsetView::le
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition offset.hpp:136
Gecode::Int::OffsetView::inter_v
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
Definition offset.hpp:211
Gecode::Int::OffsetView::nq
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition offset.hpp:163
Gecode::Int::OffsetView::range
bool range(void) const
Test whether domain is a range.
Definition offset.hpp:108
Gecode::Int::OffsetView::eq
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition offset.hpp:172
Gecode::Int::OffsetView::narrow_r
ModEvent narrow_r(Space &home, I &i, bool depends=true)
Replace domain by ranges described by i.
Definition offset.hpp:187
Gecode::Int::ViewRanges< OffsetView >::ViewRanges
ViewRanges(void)
Default constructor.
Definition offset.hpp:299
Gecode::Int::ViewRanges< OffsetView >::init
void init(const OffsetView &x)
Initialize with ranges for view x.
Definition offset.hpp:308
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::Offset
Range iterator for pointwise offset (by some constant).
Definition ranges-offset.hpp:42
Gecode::Iter::Values::Offset
Value iterator for pointwise offset (by some constant).
Definition values-offset.hpp:42
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
Gecode::Int
Finite domain integers.
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
Gecode toplevel namespace
Gecode::ModEvent
int ModEvent
Type for modification events.
Definition core.hpp:62
forceinline
#define forceinline
Definition config.hpp:187