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 #include <iostream>
00039
00040 namespace Gecode { namespace CpltSet {
00041
00042 enum NodeStatus {
00043 INIT = -1,
00044 FIX_GLB = 1,
00045 FIX_NOT_LUB = 0,
00046 FIX_UNKNOWN = 2,
00047 UNDET = 5
00048 };
00049
00051 template <class T> class GlbValues {
00052 public:
00054
00055
00056 GlbValues(void);
00058 GlbValues(const T& x);
00060 void init(const T& x);
00062
00063
00064
00065 bool operator()(void) const;
00067 void operator++(void);
00069
00070
00071
00072 int val(void) const;
00074 };
00075
00077 template <class T> class LubValues {
00078 public:
00080
00081
00082 LubValues(void);
00084 LubValues(const T& x);
00086 void init(const T& x);
00088
00089
00090
00091 bool operator()(void) const;
00093 void operator++(void);
00095
00096
00097
00098 int min(void) const;
00100 int max(void) const;
00102 };
00103
00105 template <class T> class UnknownValues {
00106 public:
00108
00109
00110 UnknownValues(void);
00112 UnknownValues(const T& x);
00114 void init(const T& x);
00116
00117
00118
00119 bool operator()(void) const;
00121 void operator++(void);
00123
00124
00125
00126 int val(void) const;
00128 };
00129
00136 class CpltSetVarImp : public CpltSetVarImpBase {
00137 friend class BddIterator;
00138 friend class DomBddIterator;
00139
00140 friend class GlbValues<CpltSetVarImp*>;
00141 friend class LubValues<CpltSetVarImp*>;
00142 friend class UnknownValues<CpltSetVarImp*>;
00143
00144 public:
00146 static const int MAX_OF_EMPTY = Gecode::Set::Limits::min-1;
00148 static const int MIN_OF_EMPTY = Gecode::Set::Limits::max+1;
00149
00150 void printdom(void) const;
00151 private:
00153 bdd domain;
00155 int min;
00157 int max;
00161 unsigned int _offset;
00163 bool _assigned;
00164 protected:
00166 GECODE_CPLTSET_EXPORT
00167 CpltSetVarImp(Space* home, bool share, CpltSetVarImp& x);
00169 template <class I>
00170 bdd iterToBdd(I& i);
00171
00172 public:
00174 GECODE_CPLTSET_EXPORT
00175 CpltSetVarImp(Space* home, int glbMin, int glbMax, int lubMin, int lubMax,
00176 unsigned int cardMin, unsigned int cardMax);
00178 GECODE_CPLTSET_EXPORT
00179 CpltSetVarImp(Space* home, const IntSet& glbD, int lubMin, int lubMax,
00180 unsigned int cardMin, unsigned int cardMax);
00182 GECODE_CPLTSET_EXPORT
00183 CpltSetVarImp(Space* home, int glbMin, int glbMax, const IntSet& lubD,
00184 unsigned int cardMin, unsigned int cardMax);
00186 GECODE_CPLTSET_EXPORT
00187 CpltSetVarImp(Space* home, const IntSet& glbD,const IntSet& lubD,
00188 unsigned int cardMin, unsigned int cardMax);
00189
00190 GECODE_CPLTSET_EXPORT
00191 void dispose(Space* home);
00192 public:
00194
00195
00196 ModEvent exclude(Space* home, int v);
00198 GECODE_CPLTSET_EXPORT ModEvent exclude(Space* home, int a, int b);
00199
00201 ModEvent include(Space* home, int v);
00203 GECODE_CPLTSET_EXPORT ModEvent include(Space* home, int a, int b);
00204
00206 ModEvent intersect(Space* home, int i);
00208 GECODE_CPLTSET_EXPORT ModEvent intersect(Space* home, int a, int b);
00210
00212
00213
00214 template <class I> ModEvent intersectI(Space* home, I& i);
00216 template <class I> ModEvent excludeI(Space* home, I& i);
00218 template <class I> ModEvent includeI(Space* home, I& i);
00220
00222
00223
00224 GECODE_CPLTSET_EXPORT ModEvent cardinality(Space* home, int l, int u);
00226 ModEvent cardMin(Space* home,unsigned int n);
00228 ModEvent cardMax(Space* home,unsigned int n);
00230
00232
00233
00234 ModEvent nq(Space* home, int v);
00236 GECODE_CPLTSET_EXPORT ModEvent nq(Space* home, int a, int b);
00237
00239 ModEvent eq(Space* home, int v);
00241 GECODE_CPLTSET_EXPORT ModEvent eq(Space* home, int a, int b);
00243
00245
00246
00247 template <class I> ModEvent nqI(Space* home, I& i);
00249 template <class I> ModEvent eqI(Space* home, I& i);
00251
00253
00254
00255 GECODE_CPLTSET_EXPORT ModEvent intersect(Space* home, bdd& d);
00257
00259
00260
00262 unsigned int cardMin(void) const;
00264 unsigned int cardMax(void) const;
00265
00267 GECODE_CPLTSET_EXPORT int glbMin(void) const;
00269 GECODE_CPLTSET_EXPORT int glbMax(void) const;
00271 GECODE_CPLTSET_EXPORT unsigned int glbSize(void) const;
00273 GECODE_CPLTSET_EXPORT int lubMin(void) const;
00275 GECODE_CPLTSET_EXPORT int lubMax(void) const;
00277 GECODE_CPLTSET_EXPORT unsigned int lubSize(void) const;
00279 GECODE_CPLTSET_EXPORT int lubMinN(int n) const;
00281 GECODE_CPLTSET_EXPORT int lubMaxN(int n) const;
00282
00284 GECODE_CPLTSET_EXPORT int unknownMin(void) const;
00286 GECODE_CPLTSET_EXPORT int unknownMax(void) const;
00288 GECODE_CPLTSET_EXPORT unsigned int unknownSize(void) const;
00289
00291
00292
00294
00295
00296 int initialLubMin(void) const;
00298 int initialLubMax(void) const;
00301 unsigned int tableWidth(void) const;
00304 unsigned int offset(void) const;
00307 bdd element(int i) const;
00310 bdd elementNeg(int i) const;
00312 bdd dom(void) const;
00314
00316
00317
00318 GECODE_CPLTSET_EXPORT bool assigned(void) ;
00320 GECODE_CPLTSET_EXPORT bool knownIn(int i) const;
00322 GECODE_CPLTSET_EXPORT bool knownOut(int i) const;
00324 bool range(void) const;
00326
00328
00329
00330 void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00332 void cancel(Space* home, Propagator* p, PropCond pc);
00334
00335 private:
00337 GECODE_CPLTSET_EXPORT
00338 CpltSetVarImp* perform_copy(Space* home, bool share);
00339
00340 public:
00342
00343
00344 CpltSetVarImp* copy(Space* home, bool share);
00346
00348
00349 GECODE_CPLTSET_EXPORT Reflection::Arg*
00350 spec(const Space* home, Reflection::VarMap& m) const;
00352
00354
00355
00356 static ModEvent modevent(const Delta* d);
00358
00359 };
00360
00361
00369 class BddIterator {
00370 private:
00371
00372 bdd c;
00373
00374 bdd cur;
00375
00376 int markref;
00377
00378 int n;
00379
00380 int m;
00381
00382 NodeStatus flag;
00383 bool singleton;
00384
00385 SharedArray<bdd> nodes;
00386
00387 int l;
00388
00389 int r;
00390
00391 bool bypassed;
00392
00393
00394
00395 bool onlyleaves;
00396
00397 int _level;
00398
00399
00400 GECODE_CPLTSET_EXPORT void cache_mark(void);
00401
00402 GECODE_CPLTSET_EXPORT void cache_unmark(void);
00403 public:
00405
00406 BddIterator(void);
00407 BddIterator(const bdd&);
00408 GECODE_CPLTSET_EXPORT void init(const bdd&);
00410
00411
00412
00413 bool operator()(void) const;
00415 GECODE_CPLTSET_EXPORT void operator++(void);
00417
00418
00419
00420 NodeStatus status(void) const;
00422 int level(void) const;
00424 int label(void) const;
00426 bool empty(void) const;
00428 int size(void) const;
00430 };
00431
00432
00434 class DomBddIterator : public BddIterator {
00435 private:
00437 int vector_level;
00438 int mi;
00439 int ma;
00440 int off;
00442 int bdd_level;
00443 protected:
00445 bool same(void) const;
00446 public:
00448
00449 DomBddIterator(void);
00450 DomBddIterator(const CpltSetVarImp* x);
00451 DomBddIterator(const CpltSetVarImp* x, bdd& remain);
00452 void init(const CpltSetVarImp* x);
00453 void init(const CpltSetVarImp* x, bdd& remain);
00455
00456
00457
00458 bool operator()(void) const;
00460 void operator++(void);
00462
00463
00464
00465 NodeStatus status(void) const;
00467 int val(void) const;
00469 };
00470
00471 }}
00472
00473 #include "gecode/cpltset/var-imp/cpltset.icc"
00474
00475 namespace Gecode {
00476
00477 class CpltSetVar;
00478
00480 template <>
00481 class VarImpVarTraits<CpltSet::CpltSetVarImp> {
00482 public:
00483 typedef CpltSetVar Var;
00484 };
00485 }
00486
00487