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 #include "gecode/support/shared-array.hh"
00029
00030 #include <iostream>
00031
00032 #include "gecode/set/var/imp-hdr.icc"
00033 #include "gecode/iter.hh"
00034
00035 namespace Gecode { namespace Set {
00036
00041 class RangeList : public FreeList {
00042 protected:
00044 int _min;
00046 int _max;
00047 public:
00049
00050
00051 RangeList(void);
00053 RangeList(int min, int max, RangeList* p, RangeList* n);
00055
00057
00058
00059 int min(void) const;
00061 int max(void) const;
00063 unsigned int width(void) const;
00064
00066 RangeList* next(const RangeList* p) const;
00068 RangeList* prev(const RangeList* n) const;
00070
00072
00073
00074 void min(int n);
00076 void max(int n);
00077
00079 void prevnext(RangeList* p, RangeList* n);
00081 void next(RangeList* o, RangeList* n);
00083 void prev(RangeList* o, RangeList* n);
00085 void fix(RangeList* n);
00087
00089
00090
00095 void dispose(Space* home, RangeList* p, RangeList* l);
00096
00098 static void* operator new(size_t s, Space* home);
00100 static void operator delete(void*);
00102 static void operator delete(void*, Space* home);
00104 };
00105
00106
00110 class BndSet {
00111 private:
00112 RangeList* first;
00113 RangeList* last;
00114 protected:
00116 unsigned int _size;
00118 void fst(RangeList* r);
00120 void lst(RangeList* r);
00121
00123 RangeList* fst(void) const;
00125 RangeList* lst(void) const;
00126
00127 public:
00129 static const int MAX_OF_EMPTY = Limits::Set::int_min-1;
00131 static const int MIN_OF_EMPTY = Limits::Set::int_max+1;
00132
00134
00135
00136 BndSet(void);
00138 BndSet(Space* home, int i, int j);
00140 BndSet(Space* home, const IntSet& s);
00142
00144
00145
00146 void dispose(Space* home);
00148
00150
00151
00152 int min(void) const;
00154 int max(void) const;
00156 int minN(unsigned int n) const;
00158 int maxN(unsigned int n) const;
00160 unsigned int size(void) const;
00162
00164
00165
00166 bool empty(void) const;
00168 bool in(int i) const;
00170
00172
00173
00174 void linkTo(Space* home, const BndSet& s);
00176
00178
00179
00180 RangeList* ranges(void) const;
00182
00183 protected:
00185 template <class I> bool overwrite(Space* home,I& i);
00186
00187 public:
00189
00190
00191 void update(Space* home, BndSet& x);
00193
00195 GECODE_SET_EXPORT bool isConsistent(void) const;
00196 };
00197
00202 class BndSetRanges {
00203 private:
00205 const RangeList* p;
00207 const RangeList* c;
00208 public:
00210
00211
00212 BndSetRanges(void);
00214 BndSetRanges(const BndSet& s);
00216 void init(const BndSet& s);
00218
00220
00221
00222 bool operator()(void) const;
00224 void operator++(void);
00226
00228
00229
00230 int min(void) const;
00232 int max(void) const;
00234 unsigned int width(void) const;
00236 };
00237
00245 class GLBndSet : public BndSet {
00246 private:
00248 GECODE_SET_EXPORT bool include_full(Space* home,int,int);
00249 public:
00251
00252
00253 GLBndSet(Space* =NULL);
00255 GLBndSet(Space* home, int i, int j);
00257 GLBndSet(Space* home, const IntSet& s);
00259 void init(Space* home);
00261
00263
00264
00265 bool include(Space* home,int i,int j);
00267 template <class I> bool includeI(Space* home,I& i);
00269 private:
00270 GLBndSet(const GLBndSet&);
00271 const GLBndSet& operator=(const GLBndSet&);
00272 };
00273
00281 class LUBndSet: public BndSet{
00282 private:
00283 GECODE_SET_EXPORT bool exclude_full(Space* home, int, int);
00284 public:
00286
00287
00288 LUBndSet(void);
00290 LUBndSet(Space* home);
00292 LUBndSet(Space* home, int i, int j);
00294 LUBndSet(Space* home, const IntSet& s);
00296 void init(Space* home);
00298
00300
00301
00302 bool exclude(Space* home, int i, int j);
00304 template <class I> bool intersectI(Space* home, I& i);
00306 template <class I> bool excludeI(Space* home, I& i);
00308 private:
00309 LUBndSet(const LUBndSet&);
00310 const LUBndSet& operator=(const LUBndSet&);
00311 };
00312
00313
00314
00315
00316
00317
00318
00324 template <class I>
00325 class RangesCompl :
00326 public Iter::Ranges::Compl<Limits::Set::int_min, Limits::Set::int_max, I> {
00327 public:
00329
00330
00331 RangesCompl(void);
00333 RangesCompl(I& i);
00335 void init(I& i);
00337 };
00338
00350 template <class T> class LubRanges {
00351 public:
00353
00354
00355 LubRanges(void);
00357 LubRanges(const T& x);
00359 void init(const T& x);
00361
00363
00364
00365 bool operator()(void) const;
00367 void operator++(void);
00369
00371
00372
00373 int min(void) const;
00375 int max(void) const;
00377 unsigned int width(void) const;
00379 };
00380
00392 template <class T> class GlbRanges {
00393 public:
00395
00396
00397 GlbRanges(void);
00399 GlbRanges(const T& x);
00401 void init(const T& x);
00403
00405
00406
00407 bool operator()(void) const;
00409 void operator++(void);
00411
00413
00414
00415 int min(void) const;
00417 int max(void) const;
00419 unsigned int width(void) const;
00421 };
00422
00434 template <class T>
00435 class UnknownRanges : public Iter::Ranges::Diff<LubRanges<T>, GlbRanges<T> >{
00436 private:
00437 LubRanges<T> i1;
00438 GlbRanges<T> i2;
00439 public:
00441
00442
00443 UnknownRanges(void);
00445 UnknownRanges(const T& x);
00447 void init(const T& x);
00449 };
00450
00451 }}
00452
00453 #include "gecode/set/var/integerset.icc"
00454 #include "gecode/set/var/iter.icc"
00455
00456 namespace Gecode { namespace Set {
00457
00463 class SetVarImp : public SetVarImpBase {
00464 friend class LubRanges<SetVarImp*>;
00465 friend class GlbRanges<SetVarImp*>;
00466 private:
00468 LUBndSet lub;
00470 GLBndSet glb;
00472 unsigned int _cardMin;
00474 unsigned int _cardMax;
00475
00476 protected:
00478 SetVarImp(Space* home, bool share, SetVarImp& x);
00479 public:
00481
00482
00483 SetVarImp(Space* home);
00492 SetVarImp(Space* home,int glbMin,int glbMax,int lubMin,int lubMax,
00493 unsigned int cardMin = 0,
00494 unsigned int cardMax = Limits::Set::card_max);
00503 SetVarImp(Space* home,const IntSet& glbD,int lubMin,int lubMax,
00504 unsigned int cardMin,unsigned int cardMax);
00513 SetVarImp(Space* home,int glbMin,int glbMax,const IntSet& lubD,
00514 unsigned int cardMin,unsigned int cardMax);
00523 SetVarImp(Space* home,const IntSet& glbD,const IntSet& lubD,
00524 unsigned int cardMin,unsigned int cardMax);
00526
00528
00529
00530 unsigned int cardMin(void) const;
00532 unsigned int cardMax(void) const;
00534 int lubMin(void) const;
00536 int lubMax(void) const;
00538 int lubMinN(int n) const;
00540 int lubMaxN(int n) const;
00542 int glbMin(void) const;
00544 int glbMax(void) const;
00546 unsigned int glbSize(void) const;
00548 unsigned int lubSize(void) const;
00550
00552
00553
00554 bool assigned(void) const;
00556 bool knownIn(int n) const;
00558 bool knownOut(int) const;
00560
00561 private:
00563
00564
00565 GECODE_SET_EXPORT ModEvent processLubChange(Space* home);
00567 GECODE_SET_EXPORT ModEvent processGlbChange(Space* home);
00574 ModEvent checkLubCardAssigned(Space* home,ModEvent me);
00581 ModEvent checkGlbCardAssigned(Space* home,ModEvent me);
00583
00585
00586
00587 GECODE_SET_EXPORT ModEvent cardMin_full(Space* home,unsigned int n);
00589 GECODE_SET_EXPORT ModEvent cardMax_full(Space* home,unsigned int n);
00591
00593 bool boundsConsistent(void) const;
00594 public:
00595
00597
00598
00599 ModEvent include(Space* home,int n);
00601 ModEvent include(Space* home,int i,int j);
00603 ModEvent exclude(Space* home,int n);
00605 ModEvent exclude(Space* home,int i,int j);
00607 ModEvent intersect(Space* home,int n);
00609 ModEvent intersect(Space* home,int i,int j);
00611 ModEvent cardMin(Space* home,unsigned int n);
00613 ModEvent cardMax(Space* home,unsigned int n);
00615
00617
00618
00619 template <class I> ModEvent includeI(Space* home,I& i);
00621 template <class I> ModEvent excludeI(Space* home,I& i);
00623 template <class I> ModEvent intersectI(Space* home,I& i);
00625
00626 public:
00628
00629
00636 void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00638
00639 private:
00641 GECODE_SET_EXPORT SetVarImp* perform_copy(Space* home, bool share);
00642
00643 public:
00645
00646
00647 SetVarImp* copy(Space* home, bool share);
00649
00650 };
00651
00652 }}
00653
00654 #include "gecode/set/var/imp.icc"
00655
00656 namespace Gecode {
00657
00663 class SetVar {
00664 private:
00666 Set::SetVarImp* x;
00667 public:
00669
00670
00671 GECODE_SET_EXPORT SetVar(void);
00672
00674 GECODE_SET_EXPORT SetVar(Space* home);
00676 void init(Space* home);
00677
00695 GECODE_SET_EXPORT
00696 SetVar(Space* home,int glbMin,int glbMax,int lubMin,int lubMax,
00697 unsigned int cardMin = 0,
00698 unsigned int cardMax = Limits::Set::card_max);
00716 void init(Space* home,int glbMin,int glbMax,int lubMin,int lubMax,
00717 unsigned int cardMin = 0,
00718 unsigned int cardMax = Limits::Set::card_max);
00719
00737 GECODE_SET_EXPORT
00738 SetVar(Space* home,const IntSet& glbD,int lubMin,int lubMax,
00739 unsigned int cardMin = 0,
00740 unsigned int cardMax = Limits::Set::card_max);
00758 void init(Space* home,const IntSet& glbD,int lubMin,int lubMax,
00759 unsigned int cardMin = 0,
00760 unsigned int cardMax = Limits::Set::card_max);
00761
00779 GECODE_SET_EXPORT
00780 SetVar(Space* home,int glbMin,int glbMax,const IntSet& lubD,
00781 unsigned int cardMin = 0,
00782 unsigned int cardMax = Limits::Set::card_max);
00800 void init(Space* home,int glbMin,int glbMax,const IntSet& lubD,
00801 unsigned int cardMin = 0,
00802 unsigned int cardMax = Limits::Set::card_max);
00803
00821 GECODE_SET_EXPORT
00822 SetVar(Space* home,const IntSet& glbD,const IntSet& lubD,
00823 unsigned int cardMin = 0,
00824 unsigned int cardMax = Limits::Set::card_max);
00842 void init(Space* home,const IntSet& glbD,const IntSet& lubD,
00843 unsigned int cardMin = 0,
00844 unsigned int cardMax = Limits::Set::card_max);
00846
00848
00849
00850 Set::SetVarImp* variable(void) const;
00852
00854
00855
00856 unsigned int glbSize(void) const;
00858 unsigned int lubSize(void) const;
00860 unsigned int unknownSize(void) const;
00862 unsigned int cardMin(void) const;
00864 unsigned int cardMax(void) const;
00866 int lubMin(void) const;
00868 int lubMax(void) const;
00870 int glbMin(void) const;
00872 int glbMax(void) const;
00874
00876
00877
00878 bool contains(int i) const;
00880 bool notContains(int i) const;
00882 bool assigned(void) const;
00883
00885
00886
00887 void update(Space* home, bool, SetVar& x);
00889 };
00890
00896
00898 class SetVarGlbRanges {
00899 private:
00900 Set::GlbRanges<Set::SetVarImp*> iter;
00901 public:
00903
00904
00905 SetVarGlbRanges(void);
00907 SetVarGlbRanges(const SetVar& x);
00909
00911
00912
00913 bool operator()(void) const;
00915 void operator++(void);
00917
00919
00920
00921 int min(void) const;
00923 int max(void) const;
00925 unsigned int width(void) const;
00927 };
00928
00930 class SetVarLubRanges {
00931 private:
00932 Set::LubRanges<Set::SetVarImp*> iter;
00933 public:
00935
00936
00937 SetVarLubRanges(void);
00939 SetVarLubRanges(const SetVar& x);
00941
00943
00944
00945 bool operator()(void) const;
00947 void operator++(void);
00949
00951
00952
00953 int min(void) const;
00955 int max(void) const;
00957 unsigned int width(void) const;
00959 };
00960
00962 class SetVarUnknownRanges {
00963 private:
00964 Set::UnknownRanges<Set::SetVarImp*> iter;
00965 public:
00967
00968
00969 SetVarUnknownRanges(void);
00971 SetVarUnknownRanges(const SetVar& x);
00973
00975
00976
00977 bool operator()(void) const;
00979 void operator++(void);
00981
00983
00984
00985 int min(void) const;
00987 int max(void) const;
00989 unsigned int width(void) const;
00991 };
00992
00994 class SetVarGlbValues {
00995 private:
00996 Iter::Ranges::ToValues<SetVarGlbRanges> iter;
00997 public:
00999
01000
01001 SetVarGlbValues(void);
01003 SetVarGlbValues(const SetVar& x);
01005
01007
01008
01009 bool operator()(void) const;
01011 void operator++(void);
01013
01015
01016
01017 int val(void) const;
01019 };
01020
01022 class SetVarLubValues {
01023 private:
01024 Iter::Ranges::ToValues<SetVarLubRanges> iter;
01025 public:
01027
01028
01029 SetVarLubValues(void);
01031 SetVarLubValues(const SetVar& x);
01033
01035
01036
01037 bool operator()(void) const;
01039 void operator++(void);
01041
01043
01044
01045 int val(void) const;
01047 };
01048
01050 class SetVarUnknownValues {
01051 private:
01052 Iter::Ranges::ToValues<SetVarUnknownRanges> iter;
01053 public:
01055
01056
01057 SetVarUnknownValues(void);
01059 SetVarUnknownValues(const SetVar& x);
01061
01063
01064
01065 bool operator()(void) const;
01067 void operator++(void);
01069
01071
01072
01073 int val(void) const;
01075 };
01076
01078 }
01079
01080 #include "gecode/set/var/set.icc"
01081
01086 GECODE_SET_EXPORT std::ostream&
01087 operator<<(std::ostream&, const Gecode::SetVar& x);
01088
01089
01090