singleton.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>
*
* Contributing authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Guido Tack, 2004
* Christian Schulte, 2004
*
* 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 Set {
forceinline
SingletonView::SingletonView(void) {}
forceinline
SingletonView::SingletonView(Gecode::Int::IntView& y)
: DerivedView<Gecode::Int::IntView>(y) {}
forceinline
SingletonView::SingletonView(const Gecode::IntVar& y)
: DerivedView<Gecode::Int::IntView>(y) {}
forceinline PropCond
SingletonView::pc_settoint(PropCond pc) {
switch(pc) {
case PC_SET_VAL:
case PC_SET_CGLB:
case PC_SET_CARD:
return Gecode::Int::PC_INT_VAL;
default:
return Gecode::Int::PC_INT_DOM;
}
}
forceinline ModEvent
SingletonView::me_inttoset(ModEvent me) {
switch(me) {
case Gecode::Int::ME_INT_FAILED:
return ME_SET_FAILED;
case Gecode::Int::ME_INT_NONE:
return ME_SET_NONE;
case Gecode::Int::ME_INT_VAL:
return ME_SET_VAL;
case Gecode::Int::ME_INT_DOM:
return ME_SET_LUB;
default:
return ME_SET_LUB;
}
}
forceinline ModEvent
SingletonView::me_settoint(ModEvent me) {
switch(me) {
case ME_SET_FAILED:
return Gecode::Int::ME_INT_FAILED;
case ME_SET_NONE:
return Gecode::Int::ME_INT_NONE;
case ME_SET_VAL:
return Gecode::Int::ME_INT_VAL;
default:
return Gecode::Int::ME_INT_DOM;
}
}
forceinline unsigned int
SingletonView::glbSize(void) const {
return x.assigned() ? 1U : 0U;
}
forceinline unsigned int
SingletonView::lubSize(void) const { return x.size(); }
forceinline unsigned int
SingletonView::unknownSize(void) const {
return lubSize() - glbSize();
}
forceinline bool
SingletonView::contains(int n) const { return x.assigned() ?
(x.val()==n) : false; }
forceinline bool
SingletonView::notContains(int n) const { return !x.in(n); }
forceinline unsigned int
SingletonView::cardMin() const { return 1; }
forceinline unsigned int
SingletonView::cardMax() const { return 1; }
forceinline int
SingletonView::lubMin() const { return x.min(); }
forceinline int
SingletonView::lubMax() const { return x.max(); }
forceinline int
SingletonView::glbMin() const { return x.assigned() ?
x.val() : BndSet::MIN_OF_EMPTY; }
forceinline int
SingletonView::glbMax() const { return x.assigned() ?
x.val() : BndSet::MAX_OF_EMPTY; }
forceinline ModEvent
SingletonView::cardMin(Space&, unsigned int c) {
return c<=1 ? ME_SET_NONE : ME_SET_FAILED;
}
forceinline ModEvent
SingletonView::cardMax(Space&, unsigned int c) {
return c<1 ? ME_SET_FAILED : ME_SET_NONE;
}
forceinline ModEvent
SingletonView::include(Space& home,int c) {
return me_inttoset(x.eq(home,c));
}
forceinline ModEvent
SingletonView::intersect(Space& home,int c) {
return me_inttoset(x.eq(home,c));
}
forceinline ModEvent
SingletonView::intersect(Space& home,int i, int j) {
ModEvent me1 = me_inttoset(x.gq(home,i));
ModEvent me2 = me_inttoset(x.lq(home,j));
if (me_failed(me1) || me_failed(me2))
return ME_SET_FAILED;
switch (me1) {
case ME_SET_NONE:
case ME_SET_LUB:
return me2;
case ME_SET_VAL:
return ME_SET_VAL;
default:
GECODE_NEVER;
return ME_SET_VAL;
}
}
forceinline ModEvent
SingletonView::exclude(Space& home,int c) {
return me_inttoset(x.nq(home,c));
}
forceinline ModEvent
SingletonView::include(Space& home, int j, int k) {
return j==k ? me_inttoset(x.eq(home,j)) : ME_SET_FAILED ;
}
forceinline ModEvent
SingletonView::exclude(Space& home, int j, int k) {
ModEvent me1 = me_inttoset(x.gr(home,j));
ModEvent me2 = me_inttoset(x.le(home,k));
if (me_failed(me1) || me_failed(me2))
return ME_SET_FAILED;
switch (me1) {
case ME_SET_NONE:
case ME_SET_LUB:
return me2;
case ME_SET_VAL:
return ME_SET_VAL;
default:
GECODE_NEVER;
return ME_SET_VAL;
}
}
template<class I> ModEvent
SingletonView::excludeI(Space& home, I& iter) {
return me_inttoset(x.minus_r(home,iter));
}
template<class I> ModEvent
SingletonView::includeI(Space& home, I& iter) {
if (!iter())
return ME_SET_NONE;
if (iter.min()!=iter.max())
return ME_SET_FAILED;
int val = iter.min();
++iter;
if ( iter() )
return ME_SET_FAILED;
return me_inttoset(x.eq(home, val));
}
template<class I> ModEvent
SingletonView::intersectI(Space& home, I& iter) {
return me_inttoset(x.inter_r(home,iter));
}
forceinline void
SingletonView::subscribe(Space& home, Propagator& p, PropCond pc,
bool schedule) {
x.subscribe(home,p,pc_settoint(pc),schedule);
}
forceinline void
SingletonView::cancel(Space& home, Propagator& p, PropCond pc) {
x.cancel(home,p,pc_settoint(pc));
}
forceinline void
SingletonView::reschedule(Space& home, Propagator& p, PropCond pc) {
x.reschedule(home,p,pc_settoint(pc));
}
forceinline void
SingletonView::subscribe(Space& home, Advisor& a) {
x.subscribe(home,a);
}
forceinline void
SingletonView::cancel(Space& home, Advisor& a) {
x.cancel(home,a);
}
forceinline void
SingletonView::schedule(Space& home, Propagator& p, ModEvent me) {
return Gecode::Int::IntView::schedule(home,p,me_settoint(me));
}
forceinline ModEvent
SingletonView::me(const ModEventDelta& med) {
return me_inttoset(Int::IntView::me(med));
}
forceinline ModEventDelta
SingletonView::med(ModEvent me) {
return SetView::med(me_settoint(me));
}
/*
* Delta information for advisors
*
* For SingletonViews, a glb change means that the view is assigned.
* Thus, the delta for the glb is always equal to the delta for the lub.
*
*/
forceinline ModEvent
SingletonView::modevent(const Delta& d) {
return me_inttoset(Int::IntView::modevent(d));
}
forceinline int
SingletonView::glbMin(const Delta& d) const { return x.min(d); }
forceinline int
SingletonView::glbMax(const Delta& d) const { return x.max(d); }
forceinline bool
SingletonView::glbAny(const Delta& d) const { return x.any(d); }
forceinline int
SingletonView::lubMin(const Delta& d) const { return x.min(d); }
forceinline int
SingletonView::lubMax(const Delta& d) const { return x.max(d); }
forceinline bool
SingletonView::lubAny(const Delta& d) const { return x.any(d); }
forceinline bool
operator ==(const SingletonView& x, const SingletonView& y) {
return x.base() == y.base();
}
forceinline bool
operator !=(const SingletonView& x, const SingletonView& y) {
return x.base() != y.base();
}
/*
* Iterators
*
*/
template<>
class LubRanges<SingletonView> : public Gecode::Int::IntVarImpFwd {
public:
LubRanges(void);
LubRanges(const SingletonView& x);
void init(const SingletonView& x);
};
forceinline
LubRanges<SingletonView>::LubRanges(void) {}
forceinline
LubRanges<SingletonView>::LubRanges(const SingletonView& s) :
Gecode::Int::IntVarImpFwd(s.base().varimp()) {}
forceinline void
LubRanges<SingletonView>::init(const SingletonView& s) {
Gecode::Int::IntVarImpFwd::init(s.base().varimp());
}
template<>
class GlbRanges<SingletonView> {
private:
int val;
bool flag;
public:
GlbRanges(void);
GlbRanges(const SingletonView& x);
void init(const SingletonView& x);
bool operator ()(void) const;
void operator ++(void);
int min(void) const;
int max(void) const;
unsigned int width(void) const;
};
forceinline
GlbRanges<SingletonView>::GlbRanges(void) {}
forceinline void
GlbRanges<SingletonView>::init(const SingletonView& s) {
if (s.base().assigned()) {
val = s.base().val();
flag = true;
} else {
val = 0;
flag = false;
}
}
forceinline
GlbRanges<SingletonView>::GlbRanges(const SingletonView& s) {
init(s);
}
forceinline bool
GlbRanges<SingletonView>::operator ()(void) const { return flag; }
forceinline void
GlbRanges<SingletonView>::operator ++(void) { flag=false; }
forceinline int
GlbRanges<SingletonView>::min(void) const { return val; }
forceinline int
GlbRanges<SingletonView>::max(void) const { return val; }
forceinline unsigned int
GlbRanges<SingletonView>::width(void) const { return 1; }
}}
// 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< Gecode::Int::IntView >::x
Gecode::Int::IntView x
Definition view.hpp:238
Gecode::DerivedView< Gecode::Int::IntView >::DerivedView
DerivedView(void)
Definition view.hpp:584
Gecode::IntVar
Integer variables.
Definition int.hh:371
Gecode::Int::IntVarImpFwd
Range iterator for ranges of integer variable implementation.
Definition var-imp.hpp:392
Gecode::Int::IntVarImpFwd::init
void init(const IntVarImp *x)
Initialize with ranges from variable implementation x.
Definition int.hpp:432
Gecode::Int::IntVarImpFwd::IntVarImpFwd
IntVarImpFwd(void)
Default constructor.
Definition int.hpp:427
Gecode::Int::IntView
Integer view for integer variables.
Definition view.hpp:129
Gecode::Int::IntView::val
int val(void) const
Return assigned value (only if assigned).
Definition int.hpp:70
Gecode::Propagator
Base-class for propagators.
Definition core.hpp:1064
Gecode::Set::BndSet::MAX_OF_EMPTY
static const int MAX_OF_EMPTY
Returned by empty sets when asked for their maximum element.
Definition var-imp.hpp:110
Gecode::Set::BndSet::MIN_OF_EMPTY
static const int MIN_OF_EMPTY
Returned by empty sets when asked for their minimum element.
Definition var-imp.hpp:112
Gecode::Set::GlbRanges< SingletonView >::GlbRanges
GlbRanges(void)
Default constructor.
Definition singleton.hpp:379
Gecode::Set::GlbRanges< SingletonView >::init
void init(const SingletonView &x)
Initialize with ranges for view x.
Definition singleton.hpp:382
Gecode::Set::GlbRanges::operator()
bool operator()(void) const
Test whether iterator is still at a range or done.
Gecode::Set::GlbRanges::init
void init(const T &x)
Initialize with greatest lower bound ranges for set variable x.
Gecode::Set::GlbRanges::min
int min(void) const
Return smallest value of range.
Gecode::Set::GlbRanges::max
int max(void) const
Return largest value of range.
Gecode::Set::GlbRanges::width
unsigned int width(void) const
Return width of range (distance between minimum and maximum).
Gecode::Set::GlbRanges::operator++
void operator++(void)
Move iterator to next range (if possible).
Gecode::Set::GlbRanges::GlbRanges
GlbRanges(void)
Default constructor.
Gecode::Set::LubRanges< SingletonView >::LubRanges
LubRanges(void)
Default constructor.
Definition singleton.hpp:329
Gecode::Set::LubRanges::LubRanges
LubRanges(void)
Default constructor.
Gecode::Set::LubRanges::init
void init(const T &x)
Initialize with least upper bound ranges for set variable x.
Gecode::Set::SingletonView
Singleton set view.
Definition view.hpp:594
Gecode::Set::SingletonView::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 singleton.hpp:182
Gecode::Set::SingletonView::lubAny
bool lubAny(const Delta &d) const
Test whether arbitrary values got pruned from lub.
Definition singleton.hpp:292
Gecode::Set::SingletonView::contains
bool contains(int i) const
Test whether i is in the greatest lower bound.
Definition singleton.hpp:107
Gecode::Set::SingletonView::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 singleton.hpp:154
Gecode::Set::SingletonView::cardMin
unsigned int cardMin(void) const
Return minimum cardinality.
Definition singleton.hpp:114
Gecode::Set::SingletonView::reschedule
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition singleton.hpp:235
Gecode::Set::SingletonView::lubSize
unsigned int lubSize(void) const
Return the number of elements in the least upper bound.
Definition singleton.hpp:99
Gecode::Set::SingletonView::lubMax
int lubMax(void) const
Return maximum of the least upper bound.
Definition singleton.hpp:123
Gecode::Set::SingletonView::glbMax
int glbMax(void) const
Return maximum of the greatest lower bound.
Definition singleton.hpp:130
Gecode::Set::SingletonView::me
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition singleton.hpp:254
Gecode::Set::SingletonView::intersectI
ModEvent intersectI(Space &home, I &iter)
Intersect least upper bound with range sequence described by i.
Definition singleton.hpp:221
Gecode::Set::SingletonView::cardMax
unsigned int cardMax(void) const
Return maximum cardinality.
Definition singleton.hpp:117
Gecode::Set::SingletonView::glbAny
bool glbAny(const Delta &d) const
Test whether arbitrary values got pruned from glb.
Definition singleton.hpp:283
Gecode::Set::SingletonView::glbSize
unsigned int glbSize(void) const
Return the number of elements in the greatest lower bound.
Definition singleton.hpp:94
Gecode::Set::SingletonView::includeI
ModEvent includeI(Space &home, I &i)
Include range sequence described by i in greatest lower bound.
Definition singleton.hpp:205
Gecode::Set::SingletonView::glbMin
int glbMin(void) const
Return minimum of the greatest lower bound.
Definition singleton.hpp:126
Gecode::Set::SingletonView::cancel
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition singleton.hpp:231
Gecode::Set::SingletonView::unknownSize
unsigned int unknownSize(void) const
Return the number of unknown elements.
Definition singleton.hpp:102
Gecode::Set::SingletonView::subscribe
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition singleton.hpp:226
Gecode::Set::SingletonView::notContains
bool notContains(int i) const
Test whether i is not in the least upper bound.
Definition singleton.hpp:111
Gecode::Set::SingletonView::SingletonView
SingletonView(void)
Default constructor.
Definition singleton.hpp:41
Gecode::Set::SingletonView::pc_settoint
static PropCond pc_settoint(PropCond pc)
Convert set variable PropCond pc to a PropCond for integer variables.
Definition singleton.hpp:52
Gecode::Set::SingletonView::include
ModEvent include(Space &home, int i, int j)
Update greatest lower bound to include all elements between and including i and j.
Definition singleton.hpp:177
Gecode::Set::SingletonView::excludeI
ModEvent excludeI(Space &home, I &i)
Remove range sequence described by i from least upper bound.
Definition singleton.hpp:200
Gecode::Set::SingletonView::me_inttoset
static ModEvent me_inttoset(ModEvent me)
Convert integer variable ModEvent me to a ModEvent for set variables.
Definition singleton.hpp:64
Gecode::Set::SingletonView::me_settoint
static ModEvent me_settoint(ModEvent me)
Convert set variable ModEvent me to a ModEvent for integer variables.
Definition singleton.hpp:80
Gecode::Set::SingletonView::lubMin
int lubMin(void) const
Return minimum of the least upper bound.
Definition singleton.hpp:120
Gecode::Set::SingletonView::schedule
static void schedule(Space &home, Propagator &p, ModEvent me)
Schedule propagator p with modification event me.
Definition singleton.hpp:250
Gecode::Set::SingletonView::modevent
static ModEvent modevent(const Delta &d)
Return modification event.
Definition singleton.hpp:272
Gecode::Set::SingletonView::med
static ModEventDelta med(ModEvent)
Translate modification event me to modification event delta for view.
Definition singleton.hpp:258
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::VarImpView< SetVar >::med
static ModEventDelta med(ModEvent me)
Definition view.hpp:557
Gecode::VarImpView< IntVar >::me
static ModEvent me(const ModEventDelta &med)
Definition view.hpp:552
Gecode::VarImpView< IntVar >::schedule
static void schedule(Space &home, Propagator &p, ModEvent me)
Definition view.hpp:547
Gecode::VarImpView< IntVar >::modevent
static ModEvent modevent(const Delta &d)
Definition view.hpp:562
Gecode::VarImpView::assigned
bool assigned(void) const
Test whether view is assigned.
Definition view.hpp:516
Gecode::VarImpView::varimp
void varimp(VarImpType *y)
Set variable implementation to y.
Definition view.hpp:484
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
Gecode::me_failed
bool me_failed(ModEvent me)
Check whether modification event me is failed.
Definition modevent.hpp:54
Gecode::Int::PC_INT_VAL
const Gecode::PropCond PC_INT_VAL
Propagate when a view becomes assigned (single value).
Definition var-type.hpp:82
Gecode::Int::ME_INT_FAILED
const Gecode::ModEvent ME_INT_FAILED
Domain operation has resulted in failure.
Definition var-type.hpp:52
Gecode::Int::PC_INT_DOM
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition var-type.hpp:100
Gecode::Int::ME_INT_VAL
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable).
Definition var-type.hpp:56
Gecode::Int::operator==
bool operator==(const CachedView< View > &x, const CachedView< View > &y)
Definition cached.hpp:401
Gecode::Int::ME_INT_DOM
const Gecode::ModEvent ME_INT_DOM
Domain operation has changed the domain.
Definition var-type.hpp:72
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::Set::Int
Propagators connecting set and int variables.
Definition int.cpp:105
Gecode::Set
Finite integer sets.
Definition var-imp.hpp:137
Gecode::Set::ME_SET_NONE
const Gecode::ModEvent ME_SET_NONE
Domain operation has not changed domain.
Definition var-type.hpp:140
Gecode::Set::ME_SET_VAL
const Gecode::ModEvent ME_SET_VAL
Domain operation has resulted in a value (assigned variable).
Definition var-type.hpp:142
Gecode::Set::PC_SET_CARD
const Gecode::PropCond PC_SET_CARD
Propagate when the cardinality of a view changes.
Definition var-type.hpp:216
Gecode::Set::PC_SET_VAL
const Gecode::PropCond PC_SET_VAL
Propagate when a view becomes assigned (single value).
Definition var-type.hpp:207
Gecode::Set::ME_SET_LUB
const Gecode::ModEvent ME_SET_LUB
Domain operation has changed the least upper bound.
Definition var-type.hpp:156
Gecode::Set::ME_SET_FAILED
const Gecode::ModEvent ME_SET_FAILED
Domain operation has resulted in failure.
Definition var-type.hpp:138
Gecode::Set::PC_SET_CGLB
const Gecode::PropCond PC_SET_CGLB
Propagate when the cardinality or the greatest lower bound of a view changes.
Definition var-type.hpp:238
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
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56