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
00043
00044 #include <iostream>
00045
00046 namespace Gecode { namespace Set {
00047
00048 class SetVarImp;
00049 class LUBndSet;
00050 class GLBndSet;
00051
00056 class SetDelta : public Delta {
00057 friend class SetVarImp;
00058 friend class LUBndSet;
00059 friend class GLBndSet;
00060 private:
00061 int _glbMin;
00062 int _glbMax;
00063 int _lubMin;
00064 int _lubMax;
00065 public:
00067 SetDelta(void);
00069 SetDelta(int glbMin, int glbMax, int lubMin, int lubMax);
00071 int glbMin(void) const;
00073 int glbMax(void) const;
00075 int lubMin(void) const;
00077 int lubMax(void) const;
00079 bool glbAny(void) const;
00081 bool lubAny(void) const;
00082 };
00083
00084 }}
00085
00086 #include "gecode/set/var-imp/delta.icc"
00087
00088 namespace Gecode { namespace Set {
00089
00094 class RangeList : public FreeList {
00095 protected:
00097 int _min;
00099 int _max;
00100 public:
00102
00103
00104 RangeList(void);
00106 RangeList(int min, int max, RangeList* n);
00108
00110
00111
00112 int min(void) const;
00114 int max(void) const;
00116 unsigned int width(void) const;
00117
00119 RangeList* next(void) const;
00121
00123
00124
00125 void min(int n);
00127 void max(int n);
00129 void next(RangeList* n);
00131
00133
00134
00137 void dispose(Space* home, RangeList* l);
00138
00140 static void* operator new(size_t s, Space* home);
00142 static void operator delete(void*);
00144 static void operator delete(void*, Space* home);
00146 };
00147
00148
00152 class BndSet {
00153 private:
00154 RangeList* first;
00155 RangeList* last;
00156 protected:
00158 unsigned int _size;
00160 void fst(RangeList* r);
00162 void lst(RangeList* r);
00163
00165 RangeList* fst(void) const;
00167 RangeList* lst(void) const;
00168
00169 public:
00171 static const int MAX_OF_EMPTY = Limits::min-1;
00173 static const int MIN_OF_EMPTY = Limits::max+1;
00174
00176
00177
00178 BndSet(void);
00180 BndSet(Space* home, int i, int j);
00182 BndSet(Space* home, const IntSet& s);
00184
00186
00187
00188 void dispose(Space* home);
00190
00192
00193
00194 int min(void) const;
00196 int max(void) const;
00198 int minN(unsigned int n) const;
00200 unsigned int size(void) const;
00202
00204
00205
00206 bool empty(void) const;
00208 bool in(int i) const;
00210
00212
00213
00214 void become(Space* home, const BndSet& s);
00216
00218
00219
00220 RangeList* ranges(void) const;
00222
00223 protected:
00225 template <class I> bool overwrite(Space* home,I& i);
00226
00227 public:
00229
00230
00231 void update(Space* home, BndSet& x);
00233
00235 GECODE_SET_EXPORT bool isConsistent(void) const;
00236 };
00237
00242 class BndSetRanges {
00243 private:
00245 const RangeList* c;
00246 public:
00248
00249
00250 BndSetRanges(void);
00252 BndSetRanges(const BndSet& s);
00254 void init(const BndSet& s);
00256
00258
00259
00260 bool operator()(void) const;
00262 void operator++(void);
00264
00266
00267
00268 int min(void) const;
00270 int max(void) const;
00272 unsigned int width(void) const;
00274 };
00275
00283 class GLBndSet : public BndSet {
00284 private:
00286 GECODE_SET_EXPORT bool include_full(Space* home,int,int,SetDelta&);
00287 public:
00289
00290
00291 GLBndSet(Space* =NULL);
00293 GLBndSet(Space* home, int i, int j);
00295 GLBndSet(Space* home, const IntSet& s);
00297 void init(Space* home);
00299
00301
00302
00303 bool include(Space* home,int i,int j,SetDelta& d);
00305 template <class I> bool includeI(Space* home,I& i);
00307 private:
00308 GLBndSet(const GLBndSet&);
00309 const GLBndSet& operator=(const GLBndSet&);
00310 };
00311
00319 class LUBndSet: public BndSet{
00320 private:
00321 GECODE_SET_EXPORT bool exclude_full(Space* home, int, int, SetDelta&);
00322 GECODE_SET_EXPORT bool intersect_full(Space* home, int i, int j);
00323 public:
00325
00326
00327 LUBndSet(void);
00329 LUBndSet(Space* home);
00331 LUBndSet(Space* home, int i, int j);
00333 LUBndSet(Space* home, const IntSet& s);
00335 void init(Space* home);
00337
00339
00340
00341 bool exclude(Space* home, int i, int j, SetDelta& d);
00343 bool intersect(Space* home, int i, int j);
00345 template <class I> bool intersectI(Space* home, I& i);
00347 template <class I> bool excludeI(Space* home, I& i);
00349 void excludeAll(Space* home);
00351 private:
00352 LUBndSet(const LUBndSet&);
00353 const LUBndSet& operator=(const LUBndSet&);
00354 };
00355
00356
00357
00358
00359
00360
00361
00367 template <class I>
00368 class RangesCompl :
00369 public Iter::Ranges::Compl<Limits::min, Limits::max, I> {
00370 public:
00372
00373
00374 RangesCompl(void);
00376 RangesCompl(I& i);
00378 void init(I& i);
00380 };
00381
00393 template <class T> class LubRanges {
00394 public:
00396
00397
00398 LubRanges(void);
00400 LubRanges(const T& x);
00402 void init(const T& x);
00404
00406
00407
00408 bool operator()(void) const;
00410 void operator++(void);
00412
00414
00415
00416 int min(void) const;
00418 int max(void) const;
00420 unsigned int width(void) const;
00422 };
00423
00435 template <class T> class GlbRanges {
00436 public:
00438
00439
00440 GlbRanges(void);
00442 GlbRanges(const T& x);
00444 void init(const T& x);
00446
00448
00449
00450 bool operator()(void) const;
00452 void operator++(void);
00454
00456
00457
00458 int min(void) const;
00460 int max(void) const;
00462 unsigned int width(void) const;
00464 };
00465
00477 template <class T>
00478 class UnknownRanges : public Iter::Ranges::Diff<LubRanges<T>, GlbRanges<T> >{
00479 private:
00480 LubRanges<T> i1;
00481 GlbRanges<T> i2;
00482 public:
00484
00485
00486 UnknownRanges(void);
00488 UnknownRanges(const T& x);
00490 void init(const T& x);
00492 };
00493
00494 }}
00495
00496 #include "gecode/set/var-imp/integerset.icc"
00497 #include "gecode/set/var-imp/iter.icc"
00498
00499 namespace Gecode { namespace Set {
00500
00506 class SetVarImp : public SetVarImpBase {
00507 friend class LubRanges<SetVarImp*>;
00508 friend class GlbRanges<SetVarImp*>;
00509 private:
00511 LUBndSet lub;
00513 GLBndSet glb;
00515 unsigned int _cardMin;
00517 unsigned int _cardMax;
00518
00519 protected:
00521 SetVarImp(Space* home, bool share, SetVarImp& x);
00522 public:
00524
00525
00526 SetVarImp(Space* home);
00535 SetVarImp(Space* home,int glbMin,int glbMax,int lubMin,int lubMax,
00536 unsigned int cardMin = 0,
00537 unsigned int cardMax = Limits::card);
00546 SetVarImp(Space* home,const IntSet& glbD,int lubMin,int lubMax,
00547 unsigned int cardMin,unsigned int cardMax);
00556 SetVarImp(Space* home,int glbMin,int glbMax,const IntSet& lubD,
00557 unsigned int cardMin,unsigned int cardMax);
00566 SetVarImp(Space* home,const IntSet& glbD,const IntSet& lubD,
00567 unsigned int cardMin,unsigned int cardMax);
00569
00571
00572
00573 unsigned int cardMin(void) const;
00575 unsigned int cardMax(void) const;
00577 int lubMin(void) const;
00579 int lubMax(void) const;
00581 int lubMinN(int n) const;
00583 int glbMin(void) const;
00585 int glbMax(void) const;
00587 unsigned int glbSize(void) const;
00589 unsigned int lubSize(void) const;
00591
00593
00594
00595 bool assigned(void) const;
00597 bool knownIn(int n) const;
00599 bool knownOut(int) const;
00601
00602 private:
00604
00605
00606 template <class I> ModEvent includeI_full(Space* home,int mi, int ma, I& i);
00608 template <class I> ModEvent excludeI_full(Space* home,int mi, int ma, I& i);
00610 template <class I> ModEvent intersectI_full(Space* home,int mi, int ma, I& i);
00612
00613 GECODE_SET_EXPORT ModEvent processLubChange(Space* home, SetDelta& d);
00614 GECODE_SET_EXPORT ModEvent processGlbChange(Space* home, SetDelta& d);
00615
00617
00618
00619 GECODE_SET_EXPORT ModEvent cardMin_full(Space* home);
00621 GECODE_SET_EXPORT ModEvent cardMax_full(Space* home);
00623
00624 public:
00625
00627
00628
00629 ModEvent include(Space* home,int n);
00631 ModEvent include(Space* home,int i,int j);
00633 ModEvent exclude(Space* home,int n);
00635 ModEvent exclude(Space* home,int i,int j);
00637 ModEvent intersect(Space* home,int n);
00639 ModEvent intersect(Space* home,int i,int j);
00641 ModEvent cardMin(Space* home,unsigned int n);
00643 ModEvent cardMax(Space* home,unsigned int n);
00645
00647
00648
00649 template <class I> ModEvent includeI(Space* home,I& i);
00651 template <class I> ModEvent excludeI(Space* home,I& i);
00653 template <class I> ModEvent intersectI(Space* home,I& i);
00655
00656 public:
00658
00659
00666 void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00668 void cancel(Space* home, Propagator* p, PropCond pc);
00670 void subscribe(Space* home, Advisor* a);
00672 void cancel(Space* home, Advisor* a);
00674
00675 private:
00677 GECODE_SET_EXPORT SetVarImp* perform_copy(Space* home, bool share);
00678
00679 public:
00681
00682
00683 SetVarImp* copy(Space* home, bool share);
00685
00687
00688
00689 GECODE_SET_EXPORT Reflection::Arg*
00690 spec(const Space* home, Reflection::VarMap& m) const;
00692 static GECODE_SET_EXPORT VarImpBase*
00693 create(Space* home, Reflection::VarSpec& spec);
00695 static GECODE_SET_EXPORT void
00696 constrain(Space* home, VarImpBase* v, Reflection::VarSpec& spec);
00698
00700
00701
00702 static ModEvent modevent(const Delta* d);
00704 int glbMin(const Delta* d) const;
00706 int glbMax(const Delta* d) const;
00708 bool glbAny(const Delta* d) const;
00710 int lubMin(const Delta* d) const;
00712 int lubMax(const Delta* d) const;
00714 bool lubAny(const Delta* d) const;
00716
00717 };
00718
00719 class SetView;
00720
00721 }}
00722
00723 #include "gecode/set/var-imp/set.icc"
00724
00725 namespace Gecode {
00726
00727 class SetVar;
00728
00730 template <>
00731 class VarImpVarTraits<Set::SetVarImp> {
00732 public:
00733 typedef SetVar Var;
00734 };
00735 }
00736
00737