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 #include <cmath>
00043
00044 namespace Gecode { namespace Int {
00045
00046 class IntVarImp;
00047 class BoolVarImp;
00048
00055 class IntDelta : public Delta {
00056 friend class IntVarImp;
00057 friend class BoolVarImp;
00058 private:
00059 int _min;
00060 int _max;
00061 public:
00063 IntDelta(void);
00065 IntDelta(int min, int max);
00067 IntDelta(int min);
00068 private:
00070 int min(void) const;
00072 int max(void) const;
00074 bool any(void) const;
00075 };
00076
00077 }}
00078
00079 #include <gecode/int/var-imp/delta.hpp>
00080
00081 namespace Gecode { namespace Int {
00082
00083 class IntVarImpFwd;
00084 class IntVarImpBwd;
00085
00091 class IntVarImp : public IntVarImpBase {
00092 friend class IntVarImpFwd;
00093 friend class IntVarImpBwd;
00094 protected:
00104 class RangeList : public FreeList {
00105 protected:
00107 int _min;
00109 int _max;
00110 public:
00112
00113
00114 RangeList(void);
00116 RangeList(int min, int max);
00118 RangeList(int min, int max, RangeList* p, RangeList* n);
00120
00122
00123
00124 int min(void) const;
00126 int max(void) const;
00128 unsigned int width(void) const;
00129
00131 RangeList* next(const RangeList* p) const;
00133 RangeList* prev(const RangeList* n) const;
00135
00137
00138
00139 void min(int n);
00141 void max(int n);
00142
00144 void prevnext(RangeList* p, RangeList* n);
00146 void next(RangeList* o, RangeList* n);
00148 void prev(RangeList* o, RangeList* n);
00150 void fix(RangeList* n);
00152
00154
00155
00160 void dispose(Space& home, RangeList* p, RangeList* l);
00166 void dispose(Space& home, RangeList* l);
00168 void dispose(Space& home);
00169
00171 static void* operator new(size_t s, Space& home);
00173 static void* operator new(size_t s, void* p);
00175 static void operator delete(void*);
00177 static void operator delete(void*, Space&);
00179 static void operator delete(void*, void*);
00181 };
00182
00190 RangeList dom;
00192 RangeList* _lst;
00194 RangeList* fst(void) const;
00196 void fst(RangeList* f);
00198 RangeList* lst(void) const;
00200 void lst(RangeList* l);
00202 unsigned int holes;
00203
00204 protected:
00206 IntVarImp(Space& home, bool share, IntVarImp& x);
00207 public:
00209 IntVarImp(Space& home, int min, int max);
00211 IntVarImp(Space& home, const IntSet& d);
00212
00214
00215
00216 int min(void) const;
00218 int max(void) const;
00220 int val(void) const;
00222 GECODE_INT_EXPORT int med(void) const;
00223
00225 unsigned int size(void) const;
00227 unsigned int width(void) const;
00229 unsigned int regret_min(void) const;
00231 unsigned int regret_max(void) const;
00233
00234 private:
00236 GECODE_INT_EXPORT bool in_full(int n) const;
00237
00238 public:
00240
00241
00242 bool range(void) const;
00244 bool assigned(void) const;
00245
00247 bool in(int n) const;
00249 bool in(long long int n) const;
00251
00252 protected:
00254
00255
00256 const RangeList* ranges_fwd(void) const;
00258 const RangeList* ranges_bwd(void) const;
00260
00261 private:
00263 bool closer_min(int b) const;
00265
00266
00267 GECODE_INT_EXPORT ModEvent lq_full(Space& home, int n);
00269 GECODE_INT_EXPORT ModEvent gq_full(Space& home, int n);
00271 GECODE_INT_EXPORT ModEvent eq_full(Space& home, int n);
00273 GECODE_INT_EXPORT ModEvent nq_full(Space& home, int n);
00275 public:
00277
00278
00279 ModEvent lq(Space& home, int n);
00281 ModEvent lq(Space& home, long long int n);
00282
00284 ModEvent gq(Space& home, int n);
00286 ModEvent gq(Space& home, long long int n);
00287
00289 ModEvent nq(Space& home, int n);
00291 ModEvent nq(Space& home, long long int n);
00292
00294 ModEvent eq(Space& home, int n);
00296 ModEvent eq(Space& home, long long int n);
00298
00315
00316 template<class I>
00317 ModEvent narrow_r(Space& home, I& i, bool depends=true);
00319 template<class I>
00320 ModEvent inter_r(Space& home, I& i, bool depends=true);
00322 template<class I>
00323 ModEvent minus_r(Space& home, I& i, bool depends=true);
00325 template<class I>
00326 ModEvent narrow_v(Space& home, I& i, bool depends=true);
00328 template<class I>
00329 ModEvent inter_v(Space& home, I& i, bool depends=true);
00331 template<class I>
00332 ModEvent minus_v(Space& home, I& i, bool depends=true);
00334
00336
00337
00345 GECODE_INT_EXPORT void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
00347 GECODE_INT_EXPORT void reschedule(Space& home, Propagator& p, PropCond pc);
00356 GECODE_INT_EXPORT void subscribe(Space& home, Advisor& a, bool fail);
00358
00360
00361
00362 static ModEventDelta med(ModEvent me);
00364
00365
00366 private:
00368 GECODE_INT_EXPORT IntVarImp* perform_copy(Space& home, bool share);
00369 public:
00371
00372
00373 IntVarImp* copy(Space& home, bool share);
00375
00377
00378
00379 static int min(const Delta& d);
00381 static int max(const Delta& d);
00383 static bool any(const Delta& d);
00385 };
00386
00387
00392 class IntVarImpFwd {
00393 private:
00395 const IntVarImp::RangeList* p;
00397 const IntVarImp::RangeList* c;
00398 public:
00400
00401
00402 IntVarImpFwd(void);
00404 IntVarImpFwd(const IntVarImp* x);
00406 void init(const IntVarImp* x);
00408
00410
00411
00412 bool operator ()(void) const;
00414 void operator ++(void);
00416
00418
00419
00420 int min(void) const;
00422 int max(void) const;
00424 unsigned int width(void) const;
00426 };
00427
00435 class IntVarImpBwd {
00436 private:
00438 const IntVarImp::RangeList* n;
00440 const IntVarImp::RangeList* c;
00441 public:
00443
00444
00445 IntVarImpBwd(void);
00447 IntVarImpBwd(const IntVarImp* x);
00449 void init(const IntVarImp* x);
00451
00453
00454
00455 bool operator ()(void) const;
00457 void operator ++(void);
00459
00461
00462
00463 int min(void) const;
00465 int max(void) const;
00467 unsigned int width(void) const;
00469 };
00470
00471 }}
00472
00473 #include <gecode/int/var-imp/int.hpp>
00474
00475 namespace Gecode {
00476
00477 class IntVar;
00478 class BoolVar;
00479 }
00480
00481 namespace Gecode { namespace Int {
00482
00484 typedef unsigned int BoolStatus;
00485
00491 class BoolVarImp : public BoolVarImpBase {
00492 friend class ::Gecode::BoolVar;
00493 private:
00505 GECODE_INT_EXPORT static BoolVarImp s_one;
00506 GECODE_INT_EXPORT static BoolVarImp s_zero;
00507
00509 BoolVarImp(Space& home, bool share, BoolVarImp& x);
00511 BoolVarImp(int n);
00512 public:
00514 BoolVarImp(Space& home, int min, int max);
00515
00517
00518
00519 static const int BITS = 2;
00521 static const BoolStatus ZERO = 0;
00523 static const BoolStatus ONE = 3;
00525 static const BoolStatus NONE = 2;
00527 BoolStatus status(void) const;
00529
00531
00532
00533 int min(void) const;
00535 int max(void) const;
00537 int val(void) const;
00539 int med(void) const;
00540
00542 unsigned int size(void) const;
00544 unsigned int width(void) const;
00546 unsigned int regret_min(void) const;
00548 unsigned int regret_max(void) const;
00550
00552
00553
00554 bool zero(void) const;
00556 bool one(void) const;
00558 bool none(void) const;
00560
00562
00563
00564 bool range(void) const;
00566 bool assigned(void) const;
00567
00569 bool in(int n) const;
00571 bool in(long long int n) const;
00573
00575
00576
00577 ModEvent lq(Space& home, int n);
00579 ModEvent lq(Space& home, long long int n);
00580
00582 ModEvent gq(Space& home, int n);
00584 ModEvent gq(Space& home, long long int n);
00585
00587 ModEvent nq(Space& home, int n);
00589 ModEvent nq(Space& home, long long int n);
00590
00592 ModEvent eq(Space& home, int n);
00594 ModEvent eq(Space& home, long long int n);
00596
00613
00614 template<class I>
00615 ModEvent narrow_r(Space& home, I& i, bool depends=true);
00617 template<class I>
00618 ModEvent inter_r(Space& home, I& i, bool depends=true);
00620 template<class I>
00621 ModEvent minus_r(Space& home, I& i, bool depends=true);
00623 template<class I>
00624 ModEvent narrow_v(Space& home, I& i, bool depends=true);
00626 template<class I>
00627 ModEvent inter_v(Space& home, I& i, bool depends=true);
00629 template<class I>
00630 ModEvent minus_v(Space& home, I& i, bool depends=true);
00632
00634
00635
00636 ModEvent zero(Space& home);
00638 ModEvent one(Space& home);
00640 GECODE_INT_EXPORT ModEvent zero_none(Space& home);
00642 GECODE_INT_EXPORT ModEvent one_none(Space& home);
00644
00645 public:
00647
00648
00658 GECODE_INT_EXPORT void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
00665 void cancel(Space& home, Propagator& p, PropCond pc);
00674 GECODE_INT_EXPORT void subscribe(Space& home, Advisor& a, bool fail);
00676 void cancel(Space& home, Advisor& a, bool fail);
00678
00680
00681
00688 static void schedule(Space& home, Propagator& p, ModEvent me);
00690 GECODE_INT_EXPORT void reschedule(Space& home, Propagator& p, PropCond pc);
00692 static ModEventDelta med(ModEvent me);
00694
00696
00697
00698 static ModEvent modevent(const Delta& d);
00700 static int min(const Delta& d);
00702 static int max(const Delta& d);
00704 static bool any(const Delta& d);
00706 static bool zero(const Delta& d);
00708 static bool one(const Delta& d);
00710
00712
00713
00714 BoolVarImp* copy(Space& home, bool share);
00716
00717 };
00718
00719 }}
00720
00721 #include <gecode/int/var-imp/bool.hpp>
00722
00723
00724