42 namespace Gecode {
namespace Int {
49 #define GECODE_INT_RL2PD(r) reinterpret_cast<ptrdiff_t>(r) 50 #define GECODE_INT_PD2RL(p) reinterpret_cast<RangeList*>(p) 111 return static_cast<unsigned int>(
_max -
_min) + 1;
116 IntVarImp::RangeList::operator
delete(
void*) {}
119 IntVarImp::RangeList::operator
delete(
void*,
Space&) {
123 IntVarImp::RangeList::operator
delete(
void*,
void*) {
128 IntVarImp::RangeList::operator
new(size_t,
Space& home) {
129 return home.fl_alloc<
sizeof(
RangeList)>();
133 IntVarImp::RangeList::operator
new(size_t,
void*
p) {
158 #undef GECODE_INT_RL2PD 159 #undef GECODE_INT_PD2RL 203 unsigned int h =
static_cast<unsigned int>(d.
max()-d.
min())+1;
207 for (
int i = 1;
i < n-1;
i++) {
243 return fst() == NULL;
293 return (
fst() == NULL) || in_full(n);
299 return (
fst() == NULL) || in_full(static_cast<int>(n));
357 ModEvent me = gq_full(home,static_cast<int>(n));
378 ModEvent me = lq_full(home,static_cast<int>(n));
399 int n =
static_cast<int>(m);
411 return nq_full(home,n);
417 return nq_full(home,static_cast<int>(d));
468 :
n(NULL), c(x->ranges_bwd()) {}
519 fst()->dispose(home,NULL,lst());
520 fst(NULL); holes = 0;
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);
543 fst()->dispose(home,NULL,lst());
550 const int min1 =
dom.min(); min0 = f->
min();
dom.min(min0);
551 const int max1 =
dom.max(); max0 = l->
max();
dom.max(max0);
561 fst()->prev(NULL,&f); lst()->next(NULL,&l);
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));
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()));
665 return notify(home,me,d);
673 return narrow_r(home,ij,
true);
682 return narrow_r(home,ij,
true);
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);
717 fst()->prev(NULL,&f); lst()->next(NULL,&l);
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;
787 fst(NULL); lst(NULL); holes=0;
799 fst(NULL); lst(NULL);
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()));
830 return notify(home,me,d);
837 return narrow_r(home,r,depends);
844 return inter_r(home,r,depends);
852 return minus_r(home, r,
true);
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);
883 fst()->prev(NULL,&f); lst()->next(NULL,&l);
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());
940 fst(NULL); lst(NULL); holes=0;
951 fst(NULL); lst(NULL);
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()));
992 return copied() ?
static_cast<IntVarImp*
>(forward())
993 : perform_copy(home,share);
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
unsigned int size(void) const
Return size (cardinality) of domain.
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc.
void dispose(Space &home, RangeList *p, RangeList *l)
Free memory for all elements between this and l (inclusive)
#define GECODE_ASSUME(p)
Assert certain property.
void fix(RangeList *n)
Restore simple link to next element (so that it becomes a true free list)
int min(void) const
Return minimum.
int min(void) const
Return smallest value of range.
RangeList * _lst
Link the last element.
bool operator()(void) const
Test whether iterator is still at a range or done.
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to variable.
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
int ModEvent
Type for modification events.
Base-class for propagators.
bool operator()(void) const
Test whether iterator is still at a range or done.
FreeList * next(void) const
Return next freelist object.
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
IntVarImpFwd(void)
Default constructor.
static ModEventDelta med(ModEvent me)
Translate modification event me into modification event delta.
Base-class for Int-variable implementations.
RangeList * lst(void) const
Return last element of rangelist.
void init(const IntVarImp *x)
Initialize with ranges from variable implementation x.
void cancel(Space &home)
Cancel all subscriptions when variable implementation is assigned.
RangeList(void)
Default constructor (noop)
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
int val(void) const
Return assigned value (only if assigned)
const Gecode::ModEvent ME_INT_FAILED
Domain operation has resulted in failure.
IntVarImpBwd(void)
Default constructor.
Gecode::FloatVal c(-8, 8)
int _max
Maximum of range.
int p
Number of positive literals for node type.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
bool assigned(void) const
Test whether variable is assigned.
int max(void) const
Return largest value of range.
static ModEvent me(const ModEventDelta &med)
Project modification event for this variable type from med.
Range iterator for computing intersection (binary)
void operator++(void)
Move iterator to previous range (if possible)
int ranges(void) const
Return number of ranges of the specification.
bool range(void) const
Test whether domain is a range.
int PropCond
Type for propagation conditions.
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable)
int max(void) const
Return maximum.
Range iterator from value iterator.
unsigned int size(I &i)
Size of all ranges of range iterator i.
void range(Home home, const IntVarArgs &x, SetVar y, SetVar z)
Post constraint .
unsigned int width(int i) const
Return width of range at position i.
Range iterator for ranges of integer variable implementation.
int min(void) const
Return smallest value of range.
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
const Gecode::ModEvent ME_INT_BND
Domain operation has changed the minimum or maximum of the domain.
FreeList * _next
Pointer to next freelist object.
struct Gecode::@519::NNF::@60::@62 a
For atomic nodes.
RangeList * prev(const RangeList *n) const
Return previous element (from next n)
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
IntVarImp * copy(Space &home, bool share)
Return copy of this variable.
#define GECODE_INT_PD2RL(p)
unsigned int holes
Size of holes in the domain.
const RangeList * ranges_bwd(void) const
Return range list for backward iteration.
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
ModEvent narrow_v(Space &home, I &i, bool depends=true)
Replace domain by values described by i.
Integer delta information for advisors.
struct Gecode::@519::NNF::@60::@61 b
For binary nodes (and, or, eqv)
Integer variable implementation.
RangeList dom
Domain information.
IntVarImp(Space &home, bool share, IntVarImp &x)
Constructor for cloning x.
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
Node * x
Pointer to corresponding Boolean expression node.
Generic domain change information to be supplied to advisors.
Lists of ranges (intervals)
int max(void) const
Return maximum of domain.
const Gecode::ModEvent ME_INT_DOM
Domain operation has changed the domain.
void operator++(void)
Move iterator to next range (if possible)
unsigned int width(void) const
Return width (distance between maximum and minimum)
bool assigned(View x, int v)
Whether x is assigned to value v.
void prevnext(RangeList *p, RangeList *n)
Set previous element to p and next element to n.
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
void fl_dispose(FreeList *f, FreeList *l)
Return freelist-managed memory to freelist.
bool in(int n) const
Test whether n is contained in domain.
RangeList * next(const RangeList *p) const
Return next element (from previous p)
int med(void) const
Return median of domain (greatest element not greater than the median)
static bool any(const Delta &d)
Test whether arbitrary values got pruned.
Gecode toplevel namespace
const RangeList * ranges_fwd(void) const
Return range list for forward iteration.
Range iterator for computing set difference.
int _min
Minimum of range.
int max(void) const
Return largest value of range.
void init(const IntVarImp *x)
Initialize with ranges from variable implementation x.
int ModEventDelta
Modification event deltas.
ModEvent narrow_r(Space &home, I &i, bool depends=true)
Replace domain by ranges described by i.
int min(void) const
Return minimum of domain.
#define GECODE_NEVER
Assert that this command is never executed.
const Gecode::ModEvent ME_INT_NONE
Domain operation has not changed domain.
RangeList * fst(void) const
Return first element of rangelist.
unsigned int regret_min(void) const
Return regret of domain minimum (distance to next larger value)
unsigned int width(void) const
Return width of domain (distance between maximum and minimum)
int max(int i) const
Return maximum of range at position i.
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
#define GECODE_INT_RL2PD(r)
int min(int i) const
Return minimum of range at position i.
void subscribe(Gecode::Space &home, Gecode::Propagator &p, Gecode::PropCond pc, bool assigned, bool schedule)
Subscribe propagator p with propagation condition pc.