3
* Guido Tack <tack@gecode.org>
5
* Contributing authors:
6
* Christian Schulte <schulte@gecode.org>
10
* Christian Schulte, 2004
13
* $Date: 2005-11-29 18:02:48 +0100 (Tue, 29 Nov 2005) $ by $Author: tack $
16
* This file is part of Gecode, the generic constraint
17
* development environment:
18
* http://www.gecode.org
20
* See the file "LICENSE" for information on usage and
21
* redistribution of this file, and for a
22
* DISCLAIMER OF ALL WARRANTIES.
31
SingletonView::SingletonView(void) {}
34
SingletonView::SingletonView(Gecode::Int::IntView& i0)
35
: DerivedViewBase<Gecode::Int::IntView>(i0) {}
38
SingletonView::pc_settoint(PropCond pc) {
43
return Gecode::Int::PC_INT_VAL;
45
return Gecode::Int::PC_INT_DOM;
50
SingletonView::me_inttoset(ModEvent me) {
52
case Gecode::Int::ME_INT_FAILED:
54
case Gecode::Int::ME_INT_NONE:
56
case Gecode::Int::ME_INT_VAL:
58
case Gecode::Int::ME_INT_DOM:
66
SingletonView::assigned(void) const { return view.assigned(); }
68
forceinline unsigned int
69
SingletonView::glbSize(void) const { return view.assigned() ? 1 : 0; }
71
forceinline unsigned int
72
SingletonView::lubSize(void) const { return view.size(); }
74
forceinline unsigned int
75
SingletonView::unknownSize(void) const {
76
return lubSize() - glbSize();
80
SingletonView::contains(int n) const { return view.assigned() ?
81
(view.val()==n) : false; }
84
SingletonView::notContains(int n) const { return !view.in(n); }
86
forceinline unsigned int
87
SingletonView::cardMin() const { return 1; }
89
forceinline unsigned int
90
SingletonView::cardMax() const { return 1; }
93
SingletonView::lubMin() const { return view.min(); }
96
SingletonView::lubMax() const { return view.max(); }
99
SingletonView::glbMin() const { return view.assigned() ?
100
view.val() : BndSet::MIN_OF_EMPTY; }
103
SingletonView::glbMax() const { return view.assigned() ?
104
view.val() : BndSet::MAX_OF_EMPTY; }
107
SingletonView::cardMin(Space* home,unsigned int c) {
108
return c<=1 ? ME_SET_NONE : ME_SET_FAILED;
112
SingletonView::cardMax(Space* home,unsigned int c) {
113
return c<1 ? ME_SET_FAILED : ME_SET_NONE;
117
SingletonView::include(Space* home,int c) {
118
return me_inttoset(view.eq(home,c));
122
SingletonView::intersect(Space* home,int c) {
123
return me_inttoset(view.eq(home,c));
127
SingletonView::intersect(Space* home,int i, int j) {
128
ModEvent me1 = me_inttoset(view.gq(home,i));
129
ModEvent me2 = me_inttoset(view.lq(home,j));
130
if (me_failed(me1) || me_failed(me2))
131
return ME_SET_FAILED;
145
SingletonView::exclude(Space* home,int c) {
146
return me_inttoset(view.nq(home,c));
150
SingletonView::include(Space* home, int j, int k) {
151
return j==k ? me_inttoset(view.eq(home,j)) : ME_SET_FAILED ;
155
SingletonView::exclude(Space* home, int j, int k) {
156
ModEvent me1 = me_inttoset(view.gr(home,j));
157
ModEvent me2 = me_inttoset(view.le(home,k));
158
if (me_failed(me1) || me_failed(me2))
159
return ME_SET_FAILED;
172
template <class I> ModEvent
173
SingletonView::excludeI(Space* home, I& iter) {
174
return me_inttoset(view.minus(home,iter));
177
template <class I> ModEvent
178
SingletonView::includeI(Space* home, I& iter) {
182
if (iter.min()!=iter.max())
183
return ME_SET_FAILED;
185
int val = iter.min();
188
return ME_SET_FAILED;
190
return me_inttoset(view.eq(home, val));
193
template <class I> ModEvent
194
SingletonView::intersectI(Space* home, I& iter) {
195
return me_inttoset(view.inter(home,iter));
199
SingletonView::subscribe(Space* home, Propagator* p, PropCond pc) {
200
view.subscribe(home,p,pc_settoint(pc));
203
SingletonView::cancel(Propagator* p, PropCond pc) {
204
view.cancel(p,pc_settoint(pc));
209
SingletonView::pme(const Propagator* p) {
210
return me_inttoset(Int::IntView::pme(p));
212
forceinline PropModEvent
213
SingletonView::pme(ModEvent me) {
215
return SetView::pme(me);
219
SingletonView::update(Space* home, bool share, SingletonView& y) {
220
view.update(home,share,y.view);
224
SingletonView::destruct(void) { return false; }
232
* \brief %Range iterator for least upper bound of singleton set view
233
* \ingroup TaskActorSetView
236
class LubRanges<SingletonView> : public Gecode::Int::IntVarImpFwd {
238
/// \name Constructors and initialization
240
/// Default constructor
242
/// Initialize with ranges for view \a x
243
LubRanges(const SingletonView& x);
244
/// Initialize with ranges for view \a x
245
void init(const SingletonView& x);
250
LubRanges<SingletonView>::LubRanges(void) {}
253
LubRanges<SingletonView>::LubRanges(const SingletonView& s) :
254
Gecode::Int::IntVarImpFwd(s.base().variable()) {}
257
LubRanges<SingletonView>::init(const SingletonView& s) {
258
Gecode::Int::IntVarImpFwd::init(s.base().variable());
262
* \brief %Range iterator for greatest lower bound of singleton set view
263
* \ingroup TaskActorSetView
266
class GlbRanges<SingletonView> {
271
/// \name Constructors and initialization
273
/// Default constructor
275
/// Initialize with ranges for view \a x
276
GlbRanges(const SingletonView& x);
277
/// Initialize with ranges for view \a x
278
void init(const SingletonView& x);
280
/// \name Iteration control
282
/// Test whether iterator is still at a range or done
283
bool operator()(void) const;
284
/// Move iterator to next range (if possible)
285
void operator++(void);
288
/// \name Range access
290
/// Return smallest value of range
292
/// Return largest value of range
294
/// Return width of ranges (distance between minimum and maximum)
295
unsigned int width(void) const;
300
GlbRanges<SingletonView>::GlbRanges(void) {}
303
GlbRanges<SingletonView>::init(const SingletonView& s) {
304
if (s.base().assigned()) {
305
val = s.base().val();
314
GlbRanges<SingletonView>::GlbRanges(const SingletonView& s) {
319
GlbRanges<SingletonView>::operator()(void) const { return flag; }
322
GlbRanges<SingletonView>::operator++(void) { flag=false; }
325
GlbRanges<SingletonView>::min(void) const { return val; }
327
GlbRanges<SingletonView>::max(void) const { return val; }
328
forceinline unsigned int
329
GlbRanges<SingletonView>::width(void) const { return 1; }
338
same(const Set::SingletonView& x, const Set::SingletonView& y) {
339
return same(x.base(),y.base());
342
before(const Set::SingletonView& x, const Set::SingletonView& y) {
343
return before(x.base(),y.base());
349
// STATISTICS: set-var