45#define GECODE_INT_RL2PD(r) reinterpret_cast<ptrdiff_t>(r)
46#define GECODE_INT_PD2RL(p) reinterpret_cast<RangeList*>(p)
107 return static_cast<unsigned int>(
_max -
_min) + 1;
112 IntVarImp::RangeList::operator
delete(
void*) {}
115 IntVarImp::RangeList::operator
delete(
void*,
Space&) {
119 IntVarImp::RangeList::operator
delete(
void*,
void*) {
124 IntVarImp::RangeList::operator
new(size_t,
Space& home) {
125 return home.fl_alloc<
sizeof(
RangeList)>();
129 IntVarImp::RangeList::operator
new(size_t,
void* p) {
154#undef GECODE_INT_RL2PD
155#undef GECODE_INT_PD2RL
164 return dom.next(NULL);
169 dom.prevnext(NULL,f);
197 RangeList* r = home.alloc<RangeList>(n);
199 unsigned int h = static_cast<unsigned int>(d.max()-d.min())+1;
201 r[0].min(d.min(0)); r[0].max(d.max(0));
202 r[0].prevnext(NULL,&r[1]);
203 for (int i = 1; i < n-1; i++) {
205 r[i].min(d.min(i)); r[i].max(d.max(i));
206 r[i].prevnext(&r[i-1],&r[i+1]);
209 r[n-1].min(d.
min(n-1));
r[n-1].max(d.
max(n-1));
210 r[n-1].prevnext(&
r[n-2],NULL);
213 fst(NULL); holes = 0;
233 assert(
dom.min() ==
dom.max());
239 return fst() == NULL;
243 return dom.min() ==
dom.max();
260 return (
dom.min() ==
dom.max()) ? 0U : 1U;
262 return static_cast<unsigned int>(
fst()->
next(NULL)->
min()-
dom.min());
270 return (
dom.min() ==
dom.max()) ? 0U : 1U;
272 return static_cast<unsigned int>(
dom.max()-
lst()->prev(NULL)->
max());
287 if ((n <
dom.min()) || (n >
dom.max()))
289 return (
fst() == NULL) || in_full(n);
293 if ((n <
dom.min()) || (n >
dom.max()))
295 return (
fst() == NULL) || in_full(
static_cast<int>(n));
346 if (n >
dom.max())
return fail(home);
356 if (n >
dom.max())
return fail(home);
357 ModEvent me = gq_full(home,
static_cast<int>(n));
367 if (n <
dom.min())
return fail(home);
377 if (n <
dom.min())
return fail(home);
378 ModEvent me = lq_full(home,
static_cast<int>(n));
387 if ((n <
dom.min()) || (n >
dom.max()))
389 if ((n ==
dom.min()) && (n ==
dom.max()))
397 if ((m <
dom.min()) || (m >
dom.max()))
399 int n =
static_cast<int>(m);
400 if ((n ==
dom.min()) && (n ==
dom.max()))
409 if ((n <
dom.min()) || (n >
dom.max()))
411 return nq_full(home,n);
415 if ((d <
dom.min()) || (d >
dom.max()))
417 return nq_full(home,
static_cast<int>(d));
430 : p(NULL), c(
x->ranges_fwd()) {}
433 p=NULL; c=
x->ranges_fwd();
468 : n(NULL), c(
x->ranges_bwd()) {}
471 n=NULL; c=
x->ranges_bwd();
522 const int min1 =
dom.min();
dom.min(min0);
523 const int max1 =
dom.max();
dom.max(max0);
524 if ((min0 == min1) && (max0 == max1))
530 if (depends ||
range()) {
534 unsigned int s =
static_cast<unsigned int>(max0-min0+1);
550 const int min1 =
dom.min(); min0 = f->min();
dom.min(min0);
551 const int max1 =
dom.max(); max0 = l->
max();
dom.max(max0);
571 assert((
r != &f) && (
r != &l));
572 if (
r->max() < min0) {
581 }
else if ((
r->min() == min0) && (
r->max() == max0)) {
588 min0=ri.
min(); max0=ri.max(); ++ri;
591 assert((
r->min() <= min0) && (max0 <= r->
max()));
595 r->min(min0);
r->max(max0);
596 assert(h >
r->width());
604 min0=ri.min(); max0=ri.max(); ++ri;
607 assert(h >
static_cast<unsigned int>(max0-min0+1));
610 p->
next(
r,n);
r->prev(p,n);
628 assert((
r == &l) && !ri());
643 fn->
prev(&f,NULL); ln->
next(&l,NULL);
645 unsigned int b = (
static_cast<unsigned int>(fn->
min()-
dom.min()) +
646 static_cast<unsigned int>(
dom.max()-ln->
max()));
651 assert((
dom.min() != fn->
min()) || (
dom.max() != ln->
max()));
658 assert((
dom.min() == fn->
min()) && (
dom.max() == ln->
max()));
686 while (i() && (i.max() <
dom.min()))
690 if (!i() || (i.min() >
dom.max()))
697 if ((i_min <=
dom.min()) && (i_max >=
dom.max()))
700 if ((i_min >
dom.min()) && (i_max >=
dom.max()))
701 return lq(home,i_min-1);
703 if ((i_min <=
dom.min()) && (i_max <
dom.max()) &&
704 (!i() || (i.min() >
dom.max())))
705 return gq(home,i_max+1);
713 f.prevnext(NULL,n); l.
prevnext(n,NULL);
728 assert((
r != &f) && (
r != &l));
729 if (i_min >
r->max()) {
733 }
else if (i_max < r->
min()) {
739 }
else if ((i_min <= r->
min()) && (
r->max() <= i_max)) {
748 }
else if ((i_min >
r->min()) && (i_max < r->
max())) {
750 h +=
static_cast<unsigned int>(i_max - i_min) + 1;
753 p->
next(
r,n);
r->prev(p,n);
760 }
else if (i_max < r->
max()) {
761 assert(i_min <= r->
min());
763 h += i_max-
r->min()+1;
771 assert((i_max >=
r->max()) && (
r->min() < i_min));
773 h +=
r->max()-i_min+1;
808 fn->
prev(&f,NULL); ln->
next(&l,NULL);
810 b = (
static_cast<unsigned int>(fn->
min()-
dom.min()) +
811 static_cast<unsigned int>(
dom.max()-ln->
max()));
816 assert((
dom.min() != fn->
min()) || (
dom.max() != ln->
max()));
823 assert((
dom.min() == fn->
min()) && (
dom.max() == ln->
max()));
856 while (i() && (i.val() <
dom.min()))
860 if (!i() || (i.val() >
dom.max()))
867 }
while (i() && (i.val() == v));
870 if (!i() || (i.val() >
dom.max()))
871 return nq_full(home,v);
879 f.prevnext(NULL,n); l.
prevnext(n,NULL);
894 assert((
r != &f) && (
r != &l));
901 if ((v ==
r->min()) && (v ==
r->max())) {
910 }
else if (v ==
r->min()) {
912 }
else if (v ==
r->max()) {
917 }
else if (v >
r->min()) {
919 assert(v < r->
max());
923 p->
next(
r,n);
r->prev(p,n);
932 assert((
r == &l) || !i());
962 fn->
prev(&f,NULL); ln->
next(&l,NULL);
964 unsigned int b = (
static_cast<unsigned int>(fn->
min()-
dom.min()) +
965 static_cast<unsigned int>(
dom.max()-ln->
max()));
970 assert((
dom.min() != fn->
min()) || (
dom.max() != ln->
max()));
977 assert((
dom.min() == fn->
min()) && (
dom.max() == ln->
max()));
993 : perform_copy(home);
Generic domain change information to be supplied to advisors.
FreeList * next(void) const
Return next freelist object.
FreeList * _next
Pointer to next freelist object.
int min(int i) const
Return minimum of range at position i.
int max(int i) const
Return maximum of range at position i.
int ranges(void) const
Return number of ranges of the specification.
unsigned int width(int i) const
Return width of range at position i.
Integer delta information for advisors.
IntVarImpBase(Gecode::Space &home, IntVarImpBase &x)
Constructor for cloning x.
Gecode::ModEvent notify(Gecode::Space &home, Gecode::ModEvent me, Gecode::Delta &d)
Notify that variable implementation has been modified with modification event me and delta informatio...
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
void operator++(void)
Move iterator to previous range (if possible)
int max(void) const
Return largest value of range.
bool operator()(void) const
Test whether iterator is still at a range or done.
int min(void) const
Return smallest value of range.
void init(const IntVarImp *x)
Initialize with ranges from variable implementation x.
IntVarImpBwd(void)
Default constructor.
void init(const IntVarImp *x)
Initialize with ranges from variable implementation x.
IntVarImpFwd(void)
Default constructor.
bool operator()(void) const
Test whether iterator is still at a range or done.
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
int min(void) const
Return smallest value of range.
void operator++(void)
Move iterator to next range (if possible)
int max(void) const
Return largest value of range.
Lists of ranges (intervals)
unsigned int width(void) const
Return width (distance between maximum and minimum)
void fix(RangeList *n)
Restore simple link to next element (so that it becomes a true free list)
int _max
Maximum of range.
int _min
Minimum of range.
RangeList(void)
Default constructor (noop)
int min(void) const
Return minimum.
void prevnext(RangeList *p, RangeList *n)
Set previous element to p and next element to n.
RangeList * prev(const RangeList *n) const
Return previous element (from next n)
RangeList * next(const RangeList *p) const
Return next element (from previous p)
int max(void) const
Return maximum.
void dispose(Space &home, RangeList *p, RangeList *l)
Free memory for all elements between this and l (inclusive)
Integer variable implementation.
const RangeList * ranges_bwd(void) const
Return range list for backward iteration.
RangeList * _lst
Link the last element.
RangeList * lst(void) const
Return last element of rangelist.
unsigned int width(void) const
Return width of domain (distance between maximum and minimum)
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
int med(void) const
Return median of domain (greatest element not greater than the median)
ModEvent narrow_v(Space &home, I &i, bool depends=true)
Replace domain by values described by i.
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
bool in(int n) const
Test whether n is contained in domain.
IntVarImp * copy(Space &home)
Return copy of this variable.
bool assigned(void) const
Test whether variable is assigned.
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
int max(void) const
Return maximum of domain.
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
int val(void) const
Return assigned value (only if assigned)
RangeList * fst(void) const
Return first element of rangelist.
unsigned int size(void) const
Return size (cardinality) of domain.
int min(void) const
Return minimum of domain.
unsigned int regret_min(void) const
Return regret of domain minimum (distance to next larger value)
RangeList dom
Domain information.
unsigned int holes
Size of holes in the domain.
bool range(void) const
Test whether domain is a range.
ModEvent narrow_r(Space &home, I &i, bool depends=true)
Replace domain by ranges described by i.
IntVarImp(Space &home, IntVarImp &x)
Constructor for cloning x.
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
friend class IntVarImpFwd
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
const RangeList * ranges_fwd(void) const
Return range list for forward iteration.
static bool any(const Delta &d)
Test whether arbitrary values got pruned.
Range iterator for computing set difference.
Range iterator for computing intersection (binary)
Range iterator from value iterator.
void fl_dispose(FreeList *f, FreeList *l)
Return freelist-managed memory to freelist.
ModEvent fail(Space &home)
VarImp * forward(void) const
static ModEvent me(const ModEventDelta &med)
static ModEventDelta med(ModEvent me)
Base * next(void) const
Return next test.
#define GECODE_INT_RL2PD(r)
#define GECODE_INT_PD2RL(p)
int ModEventDelta
Modification event deltas.
const Gecode::ModEvent ME_INT_BND
Domain operation has changed the minimum or maximum of the domain.
const Gecode::ModEvent ME_INT_FAILED
Domain operation has resulted in failure.
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable)
const Gecode::ModEvent ME_INT_DOM
Domain operation has changed the domain.
const Gecode::ModEvent ME_INT_NONE
Domain operation has not changed domain.
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar SetRelType r
Post propagator for SetVar x
int ModEvent
Type for modification events.
#define GECODE_NEVER
Assert that this command is never executed.
#define GECODE_ASSUME(p)
Assert certain property.