cached.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Guido Tack, 2011
*
* 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 <sstream>
namespace Gecode { namespace Set {
template<class View>
forceinline
CachedView<View>::CachedView(void) {}
template<class View>
forceinline
CachedView<View>::CachedView(const View& y)
: DerivedView<View>(y) {}
template<class View>
forceinline unsigned int
CachedView<View>::glbSize(void) const {
return x.glbSize();
}
template<class View>
forceinline unsigned int
CachedView<View>::lubSize(void) const {
return x.lubSize();
}
template<class View>
forceinline unsigned int
CachedView<View>::unknownSize(void) const {
return x.unknownSize();
}
template<class View>
forceinline bool
CachedView<View>::contains(int n) const { return x.contains(n); }
template<class View>
forceinline bool
CachedView<View>::notContains(int n) const { return x.notContains(n); }
template<class View>
forceinline unsigned int
CachedView<View>::cardMin(void) const {
return x.cardMin();
}
template<class View>
forceinline unsigned int
CachedView<View>::cardMax(void) const {
return x.cardMax();
}
template<class View>
forceinline int
CachedView<View>::lubMin(void) const {
return x.lubMin();
}
template<class View>
forceinline int
CachedView<View>::lubMax(void) const {
return x.lubMax();
}
template<class View>
forceinline int
CachedView<View>::glbMin(void) const {
return x.glbMin();
}
template<class View>
forceinline int
CachedView<View>::glbMax(void) const {
return x.glbMax();
}
template<class View>
forceinline ModEvent
CachedView<View>::cardMin(Space& home, unsigned int m) {
return x.cardMin(home,m);
}
template<class View>
forceinline ModEvent
CachedView<View>::cardMax(Space& home, unsigned int m) {
return x.cardMax(home,m);
}
template<class View>
forceinline ModEvent
CachedView<View>::include(Space& home, int i) {
return x.include(home,i);
}
template<class View>
forceinline ModEvent
CachedView<View>::exclude(Space& home, int i) {
return x.exclude(home,i);
}
template<class View>
forceinline ModEvent
CachedView<View>::intersect(Space& home, int i) {
return x.intersect(home,i);
}
template<class View>
forceinline ModEvent
CachedView<View>::intersect(Space& home, int i, int j) {
return x.intersect(home,i,j);
}
template<class View>
forceinline ModEvent
CachedView<View>::include(Space& home, int i, int j) {
return x.include(home,i,j);
}
template<class View>
forceinline ModEvent
CachedView<View>::exclude(Space& home, int i, int j) {
return x.exclude(home,i,j);
}
template<class View>
template<class I> ModEvent
CachedView<View>::excludeI(Space& home,I& iter) {
return x.excludeI(home,iter);
}
template<class View>
template<class I> ModEvent
CachedView<View>::includeI(Space& home,I& iter) {
return x.includeI(home,iter);
}
template<class View>
template<class I> ModEvent
CachedView<View>::intersectI(Space& home,I& iter) {
return x.intersectI(home,iter);
}
template<class View>
forceinline void
CachedView<View>::subscribe(Space& home, Propagator& p, PropCond pc,
bool schedule) {
x.subscribe(home,p,pc,schedule);
}
template<class View>
forceinline void
CachedView<View>::cancel(Space& home, Propagator& p, PropCond pc) {
x.cancel(home,p,pc);
}
template<class View>
forceinline void
CachedView<View>::subscribe(Space& home, Advisor& a) {
x.subscribe(home,a);
}
template<class View>
forceinline void
CachedView<View>::cancel(Space& home, Advisor& a) {
x.cancel(home,a);
}
template<class View>
forceinline void
CachedView<View>::schedule(Space& home, Propagator& p, ModEvent me) {
return View::schedule(home,p,me);
}
template<class View>
forceinline ModEvent
CachedView<View>::me(const ModEventDelta& med) {
return View::me(med);
}
template<class View>
forceinline ModEventDelta
CachedView<View>::med(ModEvent me) {
return View::med(me);
}
/*
* Delta information for advisors
*
*/
template<class View>
forceinline ModEvent
CachedView<View>::modevent(const Delta& d) {
return View::modevent(d);
}
template<class View>
forceinline int
CachedView<View>::glbMin(const Delta& d) const {
return x.glbMin(d);
}
template<class View>
forceinline int
CachedView<View>::glbMax(const Delta& d) const {
return x.glbMax(d);
}
template<class View>
forceinline bool
CachedView<View>::glbAny(const Delta& d) const {
return x.glbAny(d);
}
template<class View>
forceinline int
CachedView<View>::lubMin(const Delta& d) const {
return x.lubMin(d);
}
template<class View>
forceinline int
CachedView<View>::lubMax(const Delta& d) const {
return x.lubMax(d);
}
template<class View>
forceinline bool
CachedView<View>::lubAny(const Delta& d) const {
return x.lubAny(d);
}
template<class View>
forceinline void
CachedView<View>::update(Space& home, CachedView<View>& y) {
lubCache.update(home,y.lubCache);
glbCache.update(home,y.glbCache);
DerivedView<View>::update(home,y);
}
/*
* Cache operations
*
*/
template<class View>
void
CachedView<View>::initCache(Space& home,
const IntSet& glb, const IntSet& lub) {
glbCache.init(home);
IntSetRanges gr(glb);
glbCache.includeI(home,gr);
lubCache.init(home);
IntSetRanges lr(lub);
lubCache.intersectI(home,lr);
}
template<class View>
forceinline void
CachedView<View>::cacheGlb(Space& home) {
GlbRanges<View> gr(DerivedView<View>::base());
glbCache.includeI(home,gr);
}
template<class View>
forceinline void
CachedView<View>::cacheLub(Space& home) {
LubRanges<View> lr(DerivedView<View>::base());
lubCache.intersectI(home,lr);
}
template<class View>
forceinline bool
CachedView<View>::glbModified(void) const {
return glbCache.size() != glbSize();
}
template<class View>
forceinline bool
CachedView<View>::lubModified(void) const {
return lubCache.size() != lubSize();
}
template<class View>
class LubRanges<CachedView<View> > : public LubRanges<View> {
public:
LubRanges(void) {}
LubRanges(const CachedView<View>& x);
void init(const CachedView<View>& x);
};
template<class View>
forceinline
LubRanges<CachedView<View> >::LubRanges(const CachedView<View>& s)
: LubRanges<View>(s.base()) {}
template<class View>
forceinline void
LubRanges<CachedView<View> >::init(const CachedView<View>& s) {
LubRanges<View>::init(s.base());
}
template<class View>
class GlbRanges<CachedView<View> > : public GlbRanges<View> {
public:
GlbRanges(void) {}
GlbRanges(const CachedView<View> & x);
void init(const CachedView<View> & x);
};
template<class View>
forceinline
GlbRanges<CachedView<View> >::GlbRanges(const CachedView<View> & s)
: GlbRanges<View>(s.base()) {}
template<class View>
forceinline void
GlbRanges<CachedView<View> >::init(const CachedView<View> & s) {
GlbRanges<View>::init(s.base());
}
template<class Char, class Traits, class View>
std::basic_ostream<Char,Traits>&
operator <<(std::basic_ostream<Char,Traits>& os,
const CachedView<View>& x) {
return os << x.base();
}
template<class View>
forceinline bool
operator ==(const CachedView<View>& x, const CachedView<View>& y) {
return x.base() == y.base();
}
template<class View>
forceinline bool
operator !=(const CachedView<View>& x, const CachedView<View>& y) {
return x.base() != y.base();
}
template<class View>
forceinline
GlbDiffRanges<View>::GlbDiffRanges(const CachedView<View>& x)
: gr(x.base()), cr(x.glbCache) {
Iter::Ranges::Diff<GlbRanges<View>,BndSetRanges>::init(gr,cr);
}
template<class View>
forceinline
LubDiffRanges<View>::LubDiffRanges(const CachedView<View>& x)
: cr(x.lubCache), lr(x.base()) {
Iter::Ranges::Diff<BndSetRanges,LubRanges<View> >::init(cr,lr);
}
}}
// STATISTICS: set-var
Gecode::Advisor
Base-class for advisors.
Definition core.hpp:1292
Gecode::Delta
Generic domain change information to be supplied to advisors.
Definition core.hpp:204
Gecode::DerivedView::base
View base(void) const
Return view from which this view is derived.
Definition view.hpp:605
Gecode::DerivedView::x
View x
View from which this view is derived.
Definition view.hpp:238
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::IntSetRanges
Range iterator for integer sets.
Definition int.hh:292
Gecode::IntSet
Integer sets.
Definition int.hh:174
Gecode::Int::CachedView
Cached integer view.
Definition view.hpp:1166
Gecode::Iter::Ranges::Diff
Range iterator for computing set difference.
Definition ranges-diff.hpp:43
Gecode::Iter::Ranges::Diff< GlbRanges< View >, BndSetRanges >::init
void init(GlbRanges< View > &i, BndSetRanges &j)
Definition ranges-diff.hpp:125
Gecode::Propagator
Base-class for propagators.
Definition core.hpp:1064
Gecode::Set::BndSetRanges
Range iterator for integer sets.
Definition var-imp.hpp:185
Gecode::Set::CachedView::intersect
ModEvent intersect(Space &home, int i, int j)
Update least upper bound to contain at most all elements between and including i and j.
Definition cached.hpp:141
Gecode::Set::CachedView::exclude
ModEvent exclude(Space &home, int i, int j)
Restrict least upper bound to not contain all elements between and including i and j.
Definition cached.hpp:153
Gecode::Set::CachedView::excludeI
ModEvent excludeI(Space &home, I &i)
Remove range sequence described by i from least upper bound.
Gecode::Set::CachedView::glbMax
int glbMax(void) const
Return maximum of the greatest lower bound.
Definition cached.hpp:105
Gecode::Set::CachedView::include
ModEvent include(Space &home, int i, int j)
Update greatest lower bound to include all elements between and including i and j.
Definition cached.hpp:147
Gecode::Set::CachedView::glbAny
bool glbAny(const Delta &d) const
Test whether arbitrary values got pruned from glb.
Definition cached.hpp:242
Gecode::Set::CachedView::glbModified
bool glbModified(void) const
Check whether greatest lower bound cache differs from current domain.
Definition cached.hpp:304
Gecode::Set::CachedView::lubAny
bool lubAny(const Delta &d) const
Test whether arbitrary values got pruned from lub.
Definition cached.hpp:260
Gecode::Set::CachedView::schedule
static void schedule(Space &home, Propagator &p, ModEvent me)
Schedule propagator p with modification event me.
Definition cached.hpp:202
Gecode::Set::CachedView::glbCache
GLBndSet glbCache
The cached greatest lower bound.
Definition view.hpp:957
Gecode::Set::CachedView::initCache
void initCache(Space &home, const IntSet &glb, const IntSet &lub)
Initialize cache to bounds glb and lub.
Definition cached.hpp:278
Gecode::Set::CachedView::glbSize
unsigned int glbSize(void) const
Return the number of elements in the greatest lower bound.
Definition cached.hpp:49
Gecode::Set::CachedView::lubCache
LUBndSet lubCache
The cached least upper bound.
Definition view.hpp:955
Gecode::Set::CachedView::lubMin
int lubMin(void) const
Return minimum of the least upper bound.
Definition cached.hpp:87
Gecode::Set::CachedView::cardMax
unsigned int cardMax(void) const
Return maximum cardinality.
Definition cached.hpp:81
Gecode::Set::CachedView::cancel
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition cached.hpp:184
Gecode::Set::CachedView::modevent
static ModEvent modevent(const Delta &d)
Return modification event.
Definition cached.hpp:224
Gecode::Set::CachedView::contains
bool contains(int i) const
Test whether i is in the greatest lower bound.
Definition cached.hpp:67
Gecode::Set::CachedView::cardMin
unsigned int cardMin(void) const
Return minimum cardinality.
Definition cached.hpp:75
Gecode::Set::CachedView::includeI
ModEvent includeI(Space &home, I &i)
Include range sequence described by i in greatest lower bound.
Gecode::Set::CachedView::cacheLub
void cacheLub(Space &home)
Update least upper bound cache to current domain.
Definition cached.hpp:297
Gecode::Set::CachedView::cacheGlb
void cacheGlb(Space &home)
Update greatest lower bound cache to current domain.
Definition cached.hpp:290
Gecode::Set::CachedView::med
static ModEventDelta med(ModEvent)
Translate modification event me to modification event delta for view.
Gecode::Set::CachedView::lubModified
bool lubModified(void) const
Check whether least upper bound cache differs from current domain.
Definition cached.hpp:310
Gecode::Set::CachedView::unknownSize
unsigned int unknownSize(void) const
Return the number of unknown elements.
Definition cached.hpp:61
Gecode::Set::CachedView::intersectI
ModEvent intersectI(Space &home, I &iter)
Intersect least upper bound with range sequence described by i.
Gecode::Set::CachedView::lubSize
unsigned int lubSize(void) const
Return the number of elements in the least upper bound.
Definition cached.hpp:55
Gecode::Set::CachedView::notContains
bool notContains(int i) const
Test whether i is not in the least upper bound.
Definition cached.hpp:71
Gecode::Set::CachedView::me
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition cached.hpp:207
Gecode::Set::CachedView::lubMax
int lubMax(void) const
Return maximum of the least upper bound.
Definition cached.hpp:93
Gecode::Set::CachedView::subscribe
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition cached.hpp:177
Gecode::Set::CachedView::glbMin
int glbMin(void) const
Return minimum of the greatest lower bound.
Definition cached.hpp:99
Gecode::Set::CachedView::update
void update(Space &home, CachedView< View > &y)
Update this view to be a clone of view y.
Gecode::Set::CachedView::CachedView
CachedView(void)
Default constructor.
Gecode::Set::GlbDiffRanges::gr
GlbRanges< View > gr
Lower bound iterator.
Definition view.hpp:1141
Gecode::Set::GlbDiffRanges::GlbDiffRanges
GlbDiffRanges(const CachedView< View > &x)
Constructor.
Definition cached.hpp:393
Gecode::Set::GlbDiffRanges::cr
BndSetRanges cr
Cached lower bound.
Definition view.hpp:1143
Gecode::Set::GlbRanges< CachedView< View > >::init
void init(const CachedView< View > &x)
Initialize with ranges for view x.
Definition cached.hpp:368
Gecode::Set::GlbRanges< CachedView< View > >::GlbRanges
GlbRanges(void)
Default constructor.
Definition cached.hpp:353
Gecode::Set::GlbRanges
Range iterator for the greatest lower bound.
Definition var-imp.hpp:359
Gecode::Set::GlbRanges::init
void init(const T &x)
Initialize with greatest lower bound ranges for set variable x.
Gecode::Set::GlbRanges::GlbRanges
GlbRanges(void)
Default constructor.
Gecode::Set::LubDiffRanges::lr
LubRanges< View > lr
Upper bound iterator.
Definition view.hpp:1160
Gecode::Set::LubDiffRanges::cr
BndSetRanges cr
Cached upper bound.
Definition view.hpp:1158
Gecode::Set::LubDiffRanges::LubDiffRanges
LubDiffRanges(const CachedView< View > &x)
Constructor.
Definition cached.hpp:400
Gecode::Set::LubRanges< CachedView< View > >::LubRanges
LubRanges(void)
Default constructor.
Definition cached.hpp:324
Gecode::Set::LubRanges< CachedView< View > >::init
void init(const CachedView< View > &x)
Initialize with ranges for view x.
Definition cached.hpp:339
Gecode::Set::LubRanges
Range iterator for the least upper bound.
Definition var-imp.hpp:317
Gecode::Set::LubRanges::init
void init(const T &x)
Initialize with least upper bound ranges for set variable x.
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::View
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
Gecode::Int::operator<<
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const IdxViewArray< View > &x)
Definition idx-view.hpp:167
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::Set
Finite integer sets.
Definition var-imp.hpp:137
Gecode
Gecode toplevel namespace
Gecode::PropCond
int PropCond
Type for propagation conditions.
Definition core.hpp:72
Gecode::ModEvent
int ModEvent
Type for modification events.
Definition core.hpp:62
forceinline
#define forceinline
Definition config.hpp:187