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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 namespace Gecode { namespace Set {
00039
00040 forceinline
00041 SingletonView::SingletonView(void) {}
00042
00043 forceinline
00044 SingletonView::SingletonView(Gecode::Int::IntView& y)
00045 : DerivedView<Gecode::Int::IntView>(y) {}
00046
00047 forceinline
00048 SingletonView::SingletonView(const Gecode::IntVar& y)
00049 : DerivedView<Gecode::Int::IntView>(y) {}
00050
00051 forceinline PropCond
00052 SingletonView::pc_settoint(PropCond pc) {
00053 switch(pc) {
00054 case PC_SET_VAL:
00055 case PC_SET_CGLB:
00056 case PC_SET_CARD:
00057 return Gecode::Int::PC_INT_VAL;
00058 default:
00059 return Gecode::Int::PC_INT_DOM;
00060 }
00061 }
00062
00063 forceinline ModEvent
00064 SingletonView::me_inttoset(ModEvent me) {
00065 switch(me) {
00066 case Gecode::Int::ME_INT_FAILED:
00067 return ME_SET_FAILED;
00068 case Gecode::Int::ME_INT_NONE:
00069 return ME_SET_NONE;
00070 case Gecode::Int::ME_INT_VAL:
00071 return ME_SET_VAL;
00072 case Gecode::Int::ME_INT_DOM:
00073 return ME_SET_LUB;
00074 default:
00075 return ME_SET_LUB;
00076 }
00077 }
00078
00079 forceinline ModEvent
00080 SingletonView::me_settoint(ModEvent me) {
00081 switch(me) {
00082 case ME_SET_FAILED:
00083 return Gecode::Int::ME_INT_FAILED;
00084 case ME_SET_NONE:
00085 return Gecode::Int::ME_INT_NONE;
00086 case ME_SET_VAL:
00087 return Gecode::Int::ME_INT_VAL;
00088 default:
00089 return Gecode::Int::ME_INT_DOM;
00090 }
00091 }
00092
00093 forceinline unsigned int
00094 SingletonView::glbSize(void) const {
00095 return x.assigned() ? 1U : 0U;
00096 }
00097
00098 forceinline unsigned int
00099 SingletonView::lubSize(void) const { return x.size(); }
00100
00101 forceinline unsigned int
00102 SingletonView::unknownSize(void) const {
00103 return lubSize() - glbSize();
00104 }
00105
00106 forceinline bool
00107 SingletonView::contains(int n) const { return x.assigned() ?
00108 (x.val()==n) : false; }
00109
00110 forceinline bool
00111 SingletonView::notContains(int n) const { return !x.in(n); }
00112
00113 forceinline unsigned int
00114 SingletonView::cardMin() const { return 1; }
00115
00116 forceinline unsigned int
00117 SingletonView::cardMax() const { return 1; }
00118
00119 forceinline int
00120 SingletonView::lubMin() const { return x.min(); }
00121
00122 forceinline int
00123 SingletonView::lubMax() const { return x.max(); }
00124
00125 forceinline int
00126 SingletonView::glbMin() const { return x.assigned() ?
00127 x.val() : BndSet::MIN_OF_EMPTY; }
00128
00129 forceinline int
00130 SingletonView::glbMax() const { return x.assigned() ?
00131 x.val() : BndSet::MAX_OF_EMPTY; }
00132
00133 forceinline ModEvent
00134 SingletonView::cardMin(Space&, unsigned int c) {
00135 return c<=1 ? ME_SET_NONE : ME_SET_FAILED;
00136 }
00137
00138 forceinline ModEvent
00139 SingletonView::cardMax(Space&, unsigned int c) {
00140 return c<1 ? ME_SET_FAILED : ME_SET_NONE;
00141 }
00142
00143 forceinline ModEvent
00144 SingletonView::include(Space& home,int c) {
00145 return me_inttoset(x.eq(home,c));
00146 }
00147
00148 forceinline ModEvent
00149 SingletonView::intersect(Space& home,int c) {
00150 return me_inttoset(x.eq(home,c));
00151 }
00152
00153 forceinline ModEvent
00154 SingletonView::intersect(Space& home,int i, int j) {
00155 ModEvent me1 = me_inttoset(x.gq(home,i));
00156 ModEvent me2 = me_inttoset(x.lq(home,j));
00157 if (me_failed(me1) || me_failed(me2))
00158 return ME_SET_FAILED;
00159 switch (me1) {
00160 case ME_SET_NONE:
00161 case ME_SET_LUB:
00162 return me2;
00163 case ME_SET_VAL:
00164 return ME_SET_VAL;
00165 default:
00166 GECODE_NEVER;
00167 return ME_SET_VAL;
00168 }
00169 }
00170
00171 forceinline ModEvent
00172 SingletonView::exclude(Space& home,int c) {
00173 return me_inttoset(x.nq(home,c));
00174 }
00175
00176 forceinline ModEvent
00177 SingletonView::include(Space& home, int j, int k) {
00178 return j==k ? me_inttoset(x.eq(home,j)) : ME_SET_FAILED ;
00179 }
00180
00181 forceinline ModEvent
00182 SingletonView::exclude(Space& home, int j, int k) {
00183 ModEvent me1 = me_inttoset(x.gr(home,j));
00184 ModEvent me2 = me_inttoset(x.le(home,k));
00185 if (me_failed(me1) || me_failed(me2))
00186 return ME_SET_FAILED;
00187 switch (me1) {
00188 case ME_SET_NONE:
00189 case ME_SET_LUB:
00190 return me2;
00191 case ME_SET_VAL:
00192 return ME_SET_VAL;
00193 default:
00194 GECODE_NEVER;
00195 return ME_SET_VAL;
00196 }
00197 }
00198
00199 template<class I> ModEvent
00200 SingletonView::excludeI(Space& home, I& iter) {
00201 return me_inttoset(x.minus_r(home,iter));
00202 }
00203
00204 template<class I> ModEvent
00205 SingletonView::includeI(Space& home, I& iter) {
00206 if (!iter())
00207 return ME_SET_NONE;
00208
00209 if (iter.min()!=iter.max())
00210 return ME_SET_FAILED;
00211
00212 int val = iter.min();
00213 ++iter;
00214 if ( iter() )
00215 return ME_SET_FAILED;
00216
00217 return me_inttoset(x.eq(home, val));
00218 }
00219
00220 template<class I> ModEvent
00221 SingletonView::intersectI(Space& home, I& iter) {
00222 return me_inttoset(x.inter_r(home,iter));
00223 }
00224
00225 forceinline void
00226 SingletonView::subscribe(Space& home, Propagator& p, PropCond pc,
00227 bool schedule) {
00228 x.subscribe(home,p,pc_settoint(pc),schedule);
00229 }
00230 forceinline void
00231 SingletonView::cancel(Space& home, Propagator& p, PropCond pc) {
00232 x.cancel(home,p,pc_settoint(pc));
00233 }
00234 forceinline void
00235 SingletonView::reschedule(Space& home, Propagator& p, PropCond pc) {
00236 x.reschedule(home,p,pc_settoint(pc));
00237 }
00238
00239 forceinline void
00240 SingletonView::subscribe(Space& home, Advisor& a) {
00241 x.subscribe(home,a);
00242 }
00243 forceinline void
00244 SingletonView::cancel(Space& home, Advisor& a) {
00245 x.cancel(home,a);
00246 }
00247
00248
00249 forceinline void
00250 SingletonView::schedule(Space& home, Propagator& p, ModEvent me) {
00251 return Gecode::Int::IntView::schedule(home,p,me_settoint(me));
00252 }
00253 forceinline ModEvent
00254 SingletonView::me(const ModEventDelta& med) {
00255 return me_inttoset(Int::IntView::me(med));
00256 }
00257 forceinline ModEventDelta
00258 SingletonView::med(ModEvent me) {
00259 return SetView::med(me_settoint(me));
00260 }
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 forceinline ModEvent
00272 SingletonView::modevent(const Delta& d) {
00273 return me_inttoset(Int::IntView::modevent(d));
00274 }
00275
00276 forceinline int
00277 SingletonView::glbMin(const Delta& d) const { return x.min(d); }
00278
00279 forceinline int
00280 SingletonView::glbMax(const Delta& d) const { return x.max(d); }
00281
00282 forceinline bool
00283 SingletonView::glbAny(const Delta& d) const { return x.any(d); }
00284
00285 forceinline int
00286 SingletonView::lubMin(const Delta& d) const { return x.min(d); }
00287
00288 forceinline int
00289 SingletonView::lubMax(const Delta& d) const { return x.max(d); }
00290
00291 forceinline bool
00292 SingletonView::lubAny(const Delta& d) const { return x.any(d); }
00293
00294 forceinline bool
00295 operator ==(const SingletonView& x, const SingletonView& y) {
00296 return x.base() == y.base();
00297 }
00298
00299 forceinline bool
00300 operator !=(const SingletonView& x, const SingletonView& y) {
00301 return x.base() != y.base();
00302 }
00303
00304
00305
00306
00307
00308
00309
00314 template<>
00315 class LubRanges<SingletonView> : public Gecode::Int::IntVarImpFwd {
00316 public:
00318
00319
00320 LubRanges(void);
00322 LubRanges(const SingletonView& x);
00324 void init(const SingletonView& x);
00326 };
00327
00328 forceinline
00329 LubRanges<SingletonView>::LubRanges(void) {}
00330
00331 forceinline
00332 LubRanges<SingletonView>::LubRanges(const SingletonView& s) :
00333 Gecode::Int::IntVarImpFwd(s.base().varimp()) {}
00334
00335 forceinline void
00336 LubRanges<SingletonView>::init(const SingletonView& s) {
00337 Gecode::Int::IntVarImpFwd::init(s.base().varimp());
00338 }
00339
00344 template<>
00345 class GlbRanges<SingletonView> {
00346 private:
00347 int val;
00348 bool flag;
00349 public:
00351
00352
00353 GlbRanges(void);
00355 GlbRanges(const SingletonView& x);
00357 void init(const SingletonView& x);
00358
00360
00361
00362 bool operator ()(void) const;
00364 void operator ++(void);
00366
00368
00369
00370 int min(void) const;
00372 int max(void) const;
00374 unsigned int width(void) const;
00376 };
00377
00378 forceinline
00379 GlbRanges<SingletonView>::GlbRanges(void) {}
00380
00381 forceinline void
00382 GlbRanges<SingletonView>::init(const SingletonView& s) {
00383 if (s.base().assigned()) {
00384 val = s.base().val();
00385 flag = true;
00386 } else {
00387 val = 0;
00388 flag = false;
00389 }
00390 }
00391
00392 forceinline
00393 GlbRanges<SingletonView>::GlbRanges(const SingletonView& s) {
00394 init(s);
00395 }
00396
00397 forceinline bool
00398 GlbRanges<SingletonView>::operator ()(void) const { return flag; }
00399
00400 forceinline void
00401 GlbRanges<SingletonView>::operator ++(void) { flag=false; }
00402
00403 forceinline int
00404 GlbRanges<SingletonView>::min(void) const { return val; }
00405 forceinline int
00406 GlbRanges<SingletonView>::max(void) const { return val; }
00407 forceinline unsigned int
00408 GlbRanges<SingletonView>::width(void) const { return 1; }
00409
00410 }}
00411
00412
00413