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