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 #include <cmath>
00027
00028 namespace Gecode { namespace Int {
00029
00036
00037 const ModEvent ME_INT_FAILED = ME_GEN_FAILED;
00039 const ModEvent ME_INT_NONE = ME_GEN_NONE;
00041 const ModEvent ME_INT_VAL = ME_GEN_ASSIGNED;
00047 const ModEvent ME_INT_BND = ME_INT_VAL + 1;
00054 const ModEvent ME_INT_DOM = ME_INT_BND + 1;
00055
00063 const PropCond PC_INT_VAL = PC_GEN_ASSIGNED;
00072 const PropCond PC_INT_BND = PC_INT_VAL + 1;
00081 const PropCond PC_INT_DOM = PC_INT_BND + 1;
00082
00084
00085 class IntVarImpFwd;
00086 class IntVarImpBwd;
00087
00093 class IntVarImp : public Variable<VTI_INT,PC_INT_DOM> {
00094 friend class IntVarImpFwd;
00095 friend class IntVarImpBwd;
00096 protected:
00106 class RangeList : public FreeList {
00107 protected:
00109 int _min;
00111 int _max;
00112 public:
00114
00115
00116 RangeList(void);
00118 RangeList(int min, int max);
00120 RangeList(int min, int max, RangeList* p, RangeList* n);
00122
00124
00125
00126 int min(void) const;
00128 int max(void) const;
00130 unsigned int width(void) const;
00131
00133 RangeList* next(const RangeList* p) const;
00135 RangeList* prev(const RangeList* n) const;
00137
00139
00140
00141 void min(int n);
00143 void max(int n);
00144
00146 void prevnext(RangeList* p, RangeList* n);
00148 void next(RangeList* o, RangeList* n);
00150 void prev(RangeList* o, RangeList* n);
00152 void fix(RangeList* n);
00154
00156
00157
00162 void dispose(Space* home, RangeList* p, RangeList* l);
00168 void dispose(Space* home, RangeList* l);
00170 void dispose(Space* home);
00171
00173 static void* operator new(size_t s, Space* home);
00175 static void operator delete(void*);
00177 static void operator delete(void*, Space*);
00179 };
00180
00188 RangeList dom;
00190 RangeList* _lst;
00192 RangeList* fst(void) const;
00194 void fst(RangeList* f);
00196 RangeList* lst(void) const;
00198 void lst(RangeList* l);
00200 unsigned int holes;
00201
00203 class Processor : public VarTypeProcessor<VTI_INT,PC_INT_DOM> {
00204 public:
00206 Processor(void);
00207 };
00209 GECODE_INT_EXPORT static Processor ivp;
00210
00211 protected:
00213 IntVarImp(Space* home, bool share, IntVarImp& x);
00214 public:
00216 IntVarImp(Space* home, int min, int max);
00218 IntVarImp(Space* home, const IntSet& d);
00219
00221
00222
00223 int min(void) const;
00225 int max(void) const;
00227 int val(void) const;
00229 GECODE_INT_EXPORT int med(void) const;
00230
00232 unsigned int size(void) const;
00234 unsigned int width(void) const;
00236 unsigned int regret_min(void) const;
00238 unsigned int regret_max(void) const;
00240
00241 private:
00243 GECODE_INT_EXPORT bool in_full(int n) const;
00244
00245 public:
00247
00248
00249 bool range(void) const;
00251 bool assigned(void) const;
00252
00254 bool in(int n) const;
00256 bool in(double n) const;
00258
00259 protected:
00261
00262
00263 const RangeList* ranges_fwd(void) const;
00265 const RangeList* ranges_bwd(void) const;
00267
00268 private:
00270 bool closer_min(int b) const;
00272
00273
00274 GECODE_INT_EXPORT void lq_full(Space* home, int n);
00276 GECODE_INT_EXPORT void gq_full(Space* home, int n);
00278 GECODE_INT_EXPORT void eq_full(Space* home, int n);
00280 GECODE_INT_EXPORT ModEvent nq_full(Space* home, int n);
00282 public:
00284
00285
00286 ModEvent lq(Space* home, int n);
00288 ModEvent lq(Space* home, double n);
00289
00291 ModEvent gq(Space* home, int n);
00293 ModEvent gq(Space* home, double n);
00294
00296 ModEvent nq(Space* home, int n);
00298 ModEvent nq(Space* home, double n);
00299
00301 ModEvent eq(Space* home, int n);
00303 ModEvent eq(Space* home, double n);
00305
00307
00308
00309 template <class I> ModEvent narrow(Space* home, I& i);
00311 template <class I> ModEvent inter(Space* home, I& i);
00313 template <class I> ModEvent minus(Space* home, I& i);
00315
00317
00318
00319 void t_zero_none(Space* home);
00321 void t_one_none(Space* home);
00323
00324 public:
00326
00327
00328 GECODE_INT_EXPORT void subscribe(Space* home, Propagator* p, PropCond pc);
00330
00331 private:
00333 GECODE_INT_EXPORT IntVarImp* perform_copy(Space* home, bool share);
00334 public:
00336
00337
00338 IntVarImp* copy(Space* home, bool share);
00340 };
00341
00342
00347 class IntVarImpFwd {
00348 private:
00350 const IntVarImp::RangeList* p;
00352 const IntVarImp::RangeList* c;
00353 public:
00355
00356
00357 IntVarImpFwd(void);
00359 IntVarImpFwd(const IntVarImp* x);
00361 void init(const IntVarImp* x);
00363
00365
00366
00367 bool operator()(void) const;
00369 void operator++(void);
00371
00373
00374
00375 int min(void) const;
00377 int max(void) const;
00379 unsigned int width(void) const;
00381 };
00382
00390 class IntVarImpBwd {
00391 private:
00393 const IntVarImp::RangeList* n;
00395 const IntVarImp::RangeList* c;
00396 public:
00398
00399
00400 IntVarImpBwd(void);
00402 IntVarImpBwd(const IntVarImp* x);
00404 void init(const IntVarImp* x);
00406
00408
00409
00410 bool operator()(void) const;
00412 void operator++(void);
00414
00416
00417
00418 int min(void) const;
00420 int max(void) const;
00422 unsigned int width(void) const;
00424 };
00425
00426
00427 class IntView;
00428 class BoolView;
00429
00430 }}
00431
00432 #include "gecode/int/var/imp.icc"
00433
00434
00435 namespace Gecode {
00436
00442 class IntVar {
00443 protected:
00445 Int::IntVarImp* var;
00446 public:
00448
00449
00450 IntVar(void);
00452 IntVar(const IntVar& x);
00454 IntVar(const Int::IntView& x);
00466 GECODE_INT_EXPORT IntVar(Space* home, int min ,int max);
00478 GECODE_INT_EXPORT IntVar(Space* home, const IntSet& d);
00490 void init(Space* home, int min, int max);
00502 void init(Space* home, const IntSet& d);
00504
00506
00507
00508 Int::IntVarImp* variable(void) const;
00510
00512
00513
00514 int min(void) const;
00516 int max(void) const;
00518 int med(void) const;
00520 int val(void) const;
00521
00523 unsigned int size(void) const;
00525 unsigned int width(void) const;
00527 unsigned int degree(void) const;
00529
00531
00532
00533 bool range(void) const;
00535 bool assigned(void) const;
00536
00538 bool in(int n) const;
00540
00542
00543
00544 void update(Space* home, bool share, IntVar& x);
00546 };
00547
00548
00553 class IntVarRanges : public Int::IntVarImpFwd {
00554 public:
00556
00557
00558 IntVarRanges(void);
00560 IntVarRanges(const IntVar& x);
00562 void init(const IntVar& x);
00564 };
00565
00570 class IntVarValues
00571 : public Iter::Ranges::ToValues<IntVarRanges> {
00572 public:
00574
00575
00576 IntVarValues(void);
00578 IntVarValues(const IntVar& x);
00580 void init(const IntVar& x);
00582 };
00583
00589 class BoolVar : public IntVar {
00590 public:
00592
00593
00594 BoolVar(void);
00596 BoolVar(const Int::BoolView& x);
00608 BoolVar(Space* home, int min, int max);
00615 explicit BoolVar(const IntVar& x);
00617
00619
00620
00621 void update(Space* home, bool share, BoolVar& x);
00623 };
00624
00625 }
00626
00631 std::ostream&
00632 operator<<(std::ostream&, const Gecode::IntVar& x);
00633
00634
00635
00636
00637
00638
00639
00640
00641