singleton.icc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 namespace Gecode {
00027
00028 namespace Set {
00029
00030 forceinline
00031 SingletonView::SingletonView(void) {}
00032
00033 forceinline
00034 SingletonView::SingletonView(Gecode::Int::IntView& i0)
00035 : DerivedViewBase<Gecode::Int::IntView>(i0) {}
00036
00037 forceinline PropCond
00038 SingletonView::pc_settoint(PropCond pc) {
00039 switch(pc) {
00040 case PC_SET_VAL:
00041 case PC_SET_CGLB:
00042 case PC_SET_CARD:
00043 return Gecode::Int::PC_INT_VAL;
00044 default:
00045 return Gecode::Int::PC_INT_DOM;
00046 }
00047 }
00048
00049 forceinline ModEvent
00050 SingletonView::me_inttoset(ModEvent me) {
00051 switch(me) {
00052 case Gecode::Int::ME_INT_FAILED:
00053 return ME_SET_FAILED;
00054 case Gecode::Int::ME_INT_NONE:
00055 return ME_SET_NONE;
00056 case Gecode::Int::ME_INT_VAL:
00057 return ME_SET_VAL;
00058 case Gecode::Int::ME_INT_DOM:
00059 return ME_SET_LUB;
00060 default:
00061 return ME_SET_LUB;
00062 }
00063 }
00064
00065 forceinline bool
00066 SingletonView::assigned(void) const { return view.assigned(); }
00067
00068 forceinline unsigned int
00069 SingletonView::glbSize(void) const { return view.assigned() ? 1 : 0; }
00070
00071 forceinline unsigned int
00072 SingletonView::lubSize(void) const { return view.size(); }
00073
00074 forceinline unsigned int
00075 SingletonView::unknownSize(void) const {
00076 return lubSize() - glbSize();
00077 }
00078
00079 forceinline bool
00080 SingletonView::contains(int n) const { return view.assigned() ?
00081 (view.val()==n) : false; }
00082
00083 forceinline bool
00084 SingletonView::notContains(int n) const { return !view.in(n); }
00085
00086 forceinline unsigned int
00087 SingletonView::cardMin() const { return 1; }
00088
00089 forceinline unsigned int
00090 SingletonView::cardMax() const { return 1; }
00091
00092 forceinline int
00093 SingletonView::lubMin() const { return view.min(); }
00094
00095 forceinline int
00096 SingletonView::lubMax() const { return view.max(); }
00097
00098 forceinline int
00099 SingletonView::glbMin() const { return view.assigned() ?
00100 view.val() : BndSet::MIN_OF_EMPTY; }
00101
00102 forceinline int
00103 SingletonView::glbMax() const { return view.assigned() ?
00104 view.val() : BndSet::MAX_OF_EMPTY; }
00105
00106 forceinline ModEvent
00107 SingletonView::cardMin(Space* home,unsigned int c) {
00108 return c<=1 ? ME_SET_NONE : ME_SET_FAILED;
00109 }
00110
00111 forceinline ModEvent
00112 SingletonView::cardMax(Space* home,unsigned int c) {
00113 return c<1 ? ME_SET_FAILED : ME_SET_NONE;
00114 }
00115
00116 forceinline ModEvent
00117 SingletonView::include(Space* home,int c) {
00118 return me_inttoset(view.eq(home,c));
00119 }
00120
00121 forceinline ModEvent
00122 SingletonView::intersect(Space* home,int c) {
00123 return me_inttoset(view.eq(home,c));
00124 }
00125
00126 forceinline ModEvent
00127 SingletonView::intersect(Space* home,int i, int j) {
00128 ModEvent me1 = me_inttoset(view.gq(home,i));
00129 ModEvent me2 = me_inttoset(view.lq(home,j));
00130 if (me_failed(me1) || me_failed(me2))
00131 return ME_SET_FAILED;
00132 switch (me1) {
00133 case ME_SET_NONE:
00134 case ME_SET_LUB:
00135 return me2;
00136 case ME_SET_VAL:
00137 return ME_SET_VAL;
00138 default:
00139 assert(false);
00140 return ME_SET_VAL;
00141 }
00142 }
00143
00144 forceinline ModEvent
00145 SingletonView::exclude(Space* home,int c) {
00146 return me_inttoset(view.nq(home,c));
00147 }
00148
00149 forceinline ModEvent
00150 SingletonView::include(Space* home, int j, int k) {
00151 return j==k ? me_inttoset(view.eq(home,j)) : ME_SET_FAILED ;
00152 }
00153
00154 forceinline ModEvent
00155 SingletonView::exclude(Space* home, int j, int k) {
00156 ModEvent me1 = me_inttoset(view.gr(home,j));
00157 ModEvent me2 = me_inttoset(view.le(home,k));
00158 if (me_failed(me1) || me_failed(me2))
00159 return ME_SET_FAILED;
00160 switch (me1) {
00161 case ME_SET_NONE:
00162 case ME_SET_LUB:
00163 return me2;
00164 case ME_SET_VAL:
00165 return ME_SET_VAL;
00166 default:
00167 assert(false);
00168 return ME_SET_VAL;
00169 }
00170 }
00171
00172 template <class I> ModEvent
00173 SingletonView::excludeI(Space* home, I& iter) {
00174 return me_inttoset(view.minus(home,iter));
00175 }
00176
00177 template <class I> ModEvent
00178 SingletonView::includeI(Space* home, I& iter) {
00179 if (!iter())
00180 return ME_SET_NONE;
00181
00182 if (iter.min()!=iter.max())
00183 return ME_SET_FAILED;
00184
00185 int val = iter.min();
00186 ++iter;
00187 if ( iter() )
00188 return ME_SET_FAILED;
00189
00190 return me_inttoset(view.eq(home, val));
00191 }
00192
00193 template <class I> ModEvent
00194 SingletonView::intersectI(Space* home, I& iter) {
00195 return me_inttoset(view.inter(home,iter));
00196 }
00197
00198 forceinline void
00199 SingletonView::subscribe(Space* home, Propagator* p, PropCond pc) {
00200 view.subscribe(home,p,pc_settoint(pc));
00201 }
00202 forceinline void
00203 SingletonView::cancel(Propagator* p, PropCond pc) {
00204 view.cancel(p,pc_settoint(pc));
00205 }
00206
00207
00208 forceinline ModEvent
00209 SingletonView::pme(const Propagator* p) {
00210 return me_inttoset(Int::IntView::pme(p));
00211 }
00212 forceinline PropModEvent
00213 SingletonView::pme(ModEvent me) {
00214
00215 return SetView::pme(me);
00216 }
00217
00218 forceinline void
00219 SingletonView::update(Space* home, bool share, SingletonView& y) {
00220 view.update(home,share,y.view);
00221 }
00222
00223 forceinline bool
00224 SingletonView::destruct(void) { return false; }
00225
00226
00227
00228
00229
00230
00235 template <>
00236 class LubRanges<SingletonView> : public Gecode::Int::IntVarImpFwd {
00237 public:
00239
00240
00241 LubRanges(void);
00243 LubRanges(const SingletonView& x);
00245 void init(const SingletonView& x);
00247 };
00248
00249 forceinline
00250 LubRanges<SingletonView>::LubRanges(void) {}
00251
00252 forceinline
00253 LubRanges<SingletonView>::LubRanges(const SingletonView& s) :
00254 Gecode::Int::IntVarImpFwd(s.base().variable()) {}
00255
00256 forceinline void
00257 LubRanges<SingletonView>::init(const SingletonView& s) {
00258 Gecode::Int::IntVarImpFwd::init(s.base().variable());
00259 }
00260
00265 template <>
00266 class GlbRanges<SingletonView> {
00267 private:
00268 int val;
00269 bool flag;
00270 public:
00272
00273
00274 GlbRanges(void);
00276 GlbRanges(const SingletonView& x);
00278 void init(const SingletonView& x);
00279
00281
00282
00283 bool operator()(void) const;
00285 void operator++(void);
00287
00289
00290
00291 int min(void) const;
00293 int max(void) const;
00295 unsigned int width(void) const;
00297 };
00298
00299 forceinline
00300 GlbRanges<SingletonView>::GlbRanges(void) {}
00301
00302 forceinline void
00303 GlbRanges<SingletonView>::init(const SingletonView& s) {
00304 if (s.base().assigned()) {
00305 val = s.base().val();
00306 flag = true;
00307 } else {
00308 val = 0;
00309 flag = false;
00310 }
00311 }
00312
00313 forceinline
00314 GlbRanges<SingletonView>::GlbRanges(const SingletonView& s) {
00315 init(s);
00316 }
00317
00318 forceinline bool
00319 GlbRanges<SingletonView>::operator()(void) const { return flag; }
00320
00321 forceinline void
00322 GlbRanges<SingletonView>::operator++(void) { flag=false; }
00323
00324 forceinline int
00325 GlbRanges<SingletonView>::min(void) const { return val; }
00326 forceinline int
00327 GlbRanges<SingletonView>::max(void) const { return val; }
00328 forceinline unsigned int
00329 GlbRanges<SingletonView>::width(void) const { return 1; }
00330
00331 }
00332
00333
00334
00335
00336
00337 forceinline bool
00338 same(const Set::SingletonView& x, const Set::SingletonView& y) {
00339 return same(x.base(),y.base());
00340 }
00341 forceinline bool
00342 before(const Set::SingletonView& x, const Set::SingletonView& y) {
00343 return before(x.base(),y.base());
00344 }
00345
00346
00347 }
00348
00349
00350