47#define GECODE_INT_RL2PD(r) reinterpret_cast<ptrdiff_t>(r)
48#define GECODE_INT_PD2RL(p) reinterpret_cast<RangeList*>(p)
50 forceinline
unsigned int
52 return static_cast<unsigned int>(
max) -
53 static_cast<unsigned int>(
min) + 1U;
113 forceinline
unsigned int
120 IntVarImp::RangeList::operator
delete(
void*) {}
123 IntVarImp::RangeList::operator
delete(
void*,
Space&) {
127 IntVarImp::RangeList::operator
delete(
void*,
void*) {
132 IntVarImp::RangeList::operator
new(size_t,
Space& home) {
133 return home.fl_alloc<
sizeof(
RangeList)>();
137 IntVarImp::RangeList::operator
new(size_t,
void* p) {
162#undef GECODE_INT_RL2PD
163#undef GECODE_INT_PD2RL
172 return dom.next(
nullptr);
177 dom.prevnext(
nullptr,f);
205 RangeList* r = home.alloc<RangeList>(n);
207 unsigned int h = range_width(d.min(),d.max());
209 r[0].min(d.min(0)); r[0].max(d.max(0));
210 r[0].prevnext(nullptr,&r[1]);
211 for (int i = 1; i < n-1; i++) {
213 r[i].min(d.min(i)); r[i].max(d.max(i));
214 r[i].prevnext(&r[i-1],&r[i+1]);
217 r[n-1].min(d.
min(n-1)); r[n-1].max(d.
max(n-1));
218 r[n-1].prevnext(&r[n-2],
nullptr);
221 fst(
nullptr); holes = 0;
241 assert(
dom.min() ==
dom.max());
247 return fst() ==
nullptr;
251 return dom.min() ==
dom.max();
255 forceinline
unsigned int
260 forceinline
unsigned int
265 forceinline
unsigned int
267 if (
fst() ==
nullptr) {
268 return (
dom.min() ==
dom.max()) ? 0U : 1U;
270 return static_cast<unsigned int>(
fst()->next(
nullptr)->min()) -
271 static_cast<unsigned int>(
dom.min());
276 forceinline
unsigned int
278 if (
fst() ==
nullptr) {
279 return (
dom.min() ==
dom.max()) ? 0U : 1U;
281 return static_cast<unsigned int>(
dom.max()) -
282 static_cast<unsigned int>(
lst()->prev(
nullptr)->max());
297 if ((n <
dom.min()) || (n >
dom.max()))
299 return (
fst() ==
nullptr) || in_full(n);
303 if ((n <
dom.min()) || (n >
dom.max()))
305 return (
fst() ==
nullptr) || in_full(
static_cast<int>(n));
316 return (
fst() ==
nullptr) ? &
dom :
fst();
321 return (
fst() ==
nullptr) ? &
dom :
lst();
338 forceinline
unsigned int
356 if (n >
dom.max())
return fail(home);
366 if (n >
dom.max())
return fail(home);
367 ModEvent me = gq_full(home,
static_cast<int>(n));
377 if (n <
dom.min())
return fail(home);
387 if (n <
dom.min())
return fail(home);
388 ModEvent me = lq_full(home,
static_cast<int>(n));
397 if ((n <
dom.min()) || (n >
dom.max()))
399 if ((n ==
dom.min()) && (n ==
dom.max()))
407 if ((m <
dom.min()) || (m >
dom.max()))
409 int n =
static_cast<int>(m);
410 if ((n ==
dom.min()) && (n ==
dom.max()))
419 if ((n <
dom.min()) || (n >
dom.max()))
421 return nq_full(home,n);
425 if ((d <
dom.min()) || (d >
dom.max()))
427 return nq_full(home,
static_cast<int>(d));
440 : p(nullptr), c(x->ranges_fwd()) {}
463 forceinline
unsigned int
478 : n(nullptr), c(x->ranges_bwd()) {}
501 forceinline
unsigned int
532 const int min1 =
dom.min();
dom.min(min0);
533 const int max1 =
dom.max();
dom.max(max0);
534 if ((min0 == min1) && (max0 == max1))
540 if (depends ||
range()) {
552 if (
fst() !=
nullptr)
560 const int min1 =
dom.min(); min0 = f->
min();
dom.min(min0);
561 const int max1 =
dom.max(); max0 = l->
max();
dom.max(max0);
581 assert((r != &f) && (r != &l));
582 if (r->
max() < min0) {
591 }
else if ((r->
min() == min0) && (r->
max() == max0)) {
598 min0=ri.
min(); max0=ri.max(); ++ri;
601 assert((r->
min() <= min0) && (max0 <= r->
max()));
605 r->
min(min0); r->
max(max0);
606 assert(h > r->
width());
614 min0=ri.min(); max0=ri.max(); ++ri;
639 assert((r == &l) && !ri());
654 fn->
prev(&f,
nullptr); ln->
next(&l,
nullptr);
656 unsigned int b = (
static_cast<unsigned int>(fn->
min()) -
657 static_cast<unsigned int>(
dom.min()) +
658 static_cast<unsigned int>(
dom.max()) -
659 static_cast<unsigned int>(ln->
max()));
664 assert((
dom.min() != fn->
min()) || (
dom.max() != ln->
max()));
671 assert((
dom.min() == fn->
min()) && (
dom.max() == ln->
max()));
699 while (i() && (i.max() <
dom.min()))
703 if (!i() || (i.min() >
dom.max()))
710 if ((i_min <=
dom.min()) && (i_max >=
dom.max()))
713 if ((i_min >
dom.min()) && (i_max >=
dom.max()))
714 return lq(home,i_min-1);
716 if ((i_min <=
dom.min()) && (i_max <
dom.max()) &&
717 (!i() || (i.min() >
dom.max())))
718 return gq(home,i_max+1);
741 assert((r != &f) && (r != &l));
742 if (i_min > r->
max()) {
746 }
else if (i_max < r->
min()) {
752 }
else if ((i_min <= r->
min()) && (r->
max() <= i_max)) {
761 }
else if ((i_min > r->
min()) && (i_max < r->
max())) {
773 }
else if (i_max < r->
max()) {
774 assert(i_min <= r->
min());
784 assert((i_max >= r->
max()) && (r->
min() < i_min));
812 fst(
nullptr);
lst(
nullptr);
821 fn->
prev(&f,
nullptr); ln->
next(&l,
nullptr);
823 b = (
static_cast<unsigned int>(fn->
min()) -
824 static_cast<unsigned int>(
dom.min()) +
825 static_cast<unsigned int>(
dom.max()) -
826 static_cast<unsigned int>(ln->
max()));
831 assert((
dom.min() != fn->
min()) || (
dom.max() != ln->
max()));
838 assert((
dom.min() == fn->
min()) && (
dom.max() == ln->
max()));
859 return inter_r(home,r,depends);
871 while (i() && (i.val() <
dom.min()))
875 if (!i() || (i.val() >
dom.max()))
882 }
while (i() && (i.val() == v));
885 if (!i() || (i.val() >
dom.max()))
886 return nq_full(home,v);
909 assert((r != &f) && (r != &l));
916 if ((v == r->
min()) && (v == r->
max())) {
925 }
else if (v == r->
min()) {
927 }
else if (v == r->
max()) {
932 }
else if (v > r->
min()) {
934 assert(v < r->
max());
947 assert((r == &l) || !i());
966 fst(
nullptr);
lst(
nullptr);
977 fn->
prev(&f,
nullptr); ln->
next(&l,
nullptr);
979 unsigned int b = (
static_cast<unsigned int>(fn->
min()) -
980 static_cast<unsigned int>(
dom.min()) +
981 static_cast<unsigned int>(
dom.max()) -
982 static_cast<unsigned int>(ln->
max()));
987 assert((
dom.min() != fn->
min()) || (
dom.max() != ln->
max()));
994 assert((
dom.min() == fn->
min()) && (
dom.max() == ln->
max()));
1010 : 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)
#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.
unsigned int range_width(int min, int max)
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
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
int ModEvent
Type for modification events.
#define GECODE_NEVER
Assert that this command is never executed.
#define GECODE_ASSUME(p)
Assert certain property.