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(Space* home, Propagator* p, PropCond pc) {
00204 view.cancel(home,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
00224
00225
00226
00227
00232 template <>
00233 class LubRanges<SingletonView> : public Gecode::Int::IntVarImpFwd {
00234 public:
00236
00237
00238 LubRanges(void);
00240 LubRanges(const SingletonView& x);
00242 void init(const SingletonView& x);
00244 };
00245
00246 forceinline
00247 LubRanges<SingletonView>::LubRanges(void) {}
00248
00249 forceinline
00250 LubRanges<SingletonView>::LubRanges(const SingletonView& s) :
00251 Gecode::Int::IntVarImpFwd(s.base().variable()) {}
00252
00253 forceinline void
00254 LubRanges<SingletonView>::init(const SingletonView& s) {
00255 Gecode::Int::IntVarImpFwd::init(s.base().variable());
00256 }
00257
00262 template <>
00263 class GlbRanges<SingletonView> {
00264 private:
00265 int val;
00266 bool flag;
00267 public:
00269
00270
00271 GlbRanges(void);
00273 GlbRanges(const SingletonView& x);
00275 void init(const SingletonView& x);
00276
00278
00279
00280 bool operator()(void) const;
00282 void operator++(void);
00284
00286
00287
00288 int min(void) const;
00290 int max(void) const;
00292 unsigned int width(void) const;
00294 };
00295
00296 forceinline
00297 GlbRanges<SingletonView>::GlbRanges(void) {}
00298
00299 forceinline void
00300 GlbRanges<SingletonView>::init(const SingletonView& s) {
00301 if (s.base().assigned()) {
00302 val = s.base().val();
00303 flag = true;
00304 } else {
00305 val = 0;
00306 flag = false;
00307 }
00308 }
00309
00310 forceinline
00311 GlbRanges<SingletonView>::GlbRanges(const SingletonView& s) {
00312 init(s);
00313 }
00314
00315 forceinline bool
00316 GlbRanges<SingletonView>::operator()(void) const { return flag; }
00317
00318 forceinline void
00319 GlbRanges<SingletonView>::operator++(void) { flag=false; }
00320
00321 forceinline int
00322 GlbRanges<SingletonView>::min(void) const { return val; }
00323 forceinline int
00324 GlbRanges<SingletonView>::max(void) const { return val; }
00325 forceinline unsigned int
00326 GlbRanges<SingletonView>::width(void) const { return 1; }
00327
00328 }
00329
00330
00331
00332
00333
00334 forceinline bool
00335 same(const Set::SingletonView& x, const Set::SingletonView& y) {
00336 return same(x.base(),y.base());
00337 }
00338 forceinline bool
00339 before(const Set::SingletonView& x, const Set::SingletonView& y) {
00340 return before(x.base(),y.base());
00341 }
00342
00343
00344 }
00345
00346
00347