36namespace Gecode {
namespace Int {
39 IntVarImp::closer_min(
int n)
const {
40 unsigned int l =
static_cast<unsigned int>(
n -
dom.min());
41 unsigned int r =
static_cast<unsigned int>(
dom.max() -
n);
46 IntVarImp::med(
void)
const {
49 return (
dom.min()+
dom.max())/2 - ((
dom.min()+
dom.max())%2 < 0 ? 1 : 0);
50 unsigned int i =
size() / 2;
53 const RangeList*
p = NULL;
54 const RangeList*
c = fst();
55 while (i >=
c->width()) {
57 const RangeList*
n=
c->next(
p);
p=
c;
c=
n;
59 return c->
min() +
static_cast<int>(
i);
63 IntVarImp::in_full(
int m)
const {
65 const RangeList*
p = NULL;
66 const RangeList*
c = fst();
67 while (m >
c->
max()) {
68 const RangeList*
n=
c->next(
p);
p=
c;
c=
n;
70 return (m >=
c->
min());
72 const RangeList*
n = NULL;
73 const RangeList*
c = lst();
74 while (m < c->
min()) {
75 const RangeList*
p=
c->prev(
n);
n=
c;
c=
p;
77 return (m <= c->
max());
87 IntVarImp::lq_full(Space& home,
int m) {
88 assert((m >=
dom.min()) && (m <=
dom.max()));
89 int old_max =
dom.max();
94 }
else if (m < fst()->next(NULL)->
min()) {
95 dom.max(std::min(m,fst()->
max()));
96 fst()->dispose(home,NULL,lst());
101 RangeList*
c = lst();
103 while (m < c->
min()) {
104 RangeList*
p =
c->prev(
n);
c->fix(
n);
109 int max_c = std::min(m,
c->
max());
112 n->dispose(home,lst());
113 c->next(
n,NULL); lst(c);
116 IntDelta
d(
dom.max()+1,old_max);
117 return notify(home,me,d);
121 IntVarImp::gq_full(Space& home,
int m) {
122 assert((m >=
dom.min()) && (m <=
dom.max()));
123 int old_min =
dom.min();
128 }
else if (m > lst()->prev(NULL)->
max()) {
129 dom.min(std::max(m,lst()->
min()));
130 fst()->dispose(home,NULL,lst());
131 fst(NULL); holes = 0;
135 RangeList*
c = fst();
137 while (m >
c->
max()) {
138 RangeList*
n =
c->next(
p);
c->fix(
n);
139 h += (
n->min() -
c->
max() - 1);
143 int min_c = std::max(m,
c->
min());
146 fst()->dispose(home,
p);
147 c->prev(
p,NULL); fst(c);
150 IntDelta
d(old_min,
dom.min()-1);
151 return notify(home,me,d);
155 IntVarImp::eq_full(Space& home,
int m) {
160 RangeList*
c = fst();
161 while (m >
c->
max()) {
162 RangeList*
n=
c->next(
p);
c->fix(
n);
p=
c;
c=
n;
167 RangeList*
n=
c->next(
p);
c->fix(
n);
p=
c;
c=
n;
170 fst()->dispose(home,
p);
171 fst(NULL); holes = 0;
180 IntVarImp::nq_full(Space& home,
int m) {
181 assert(!((m <
dom.min()) || (m >
dom.max())));
184 if ((m ==
dom.min()) && (m ==
dom.max()))
186 if (m ==
dom.min()) {
189 }
else if (m ==
dom.max()) {
193 RangeList*
f =
new (home) RangeList(
dom.min(),m-1);
194 RangeList*
l =
new (home) RangeList(m+1,
dom.max());
197 fst(f); lst(
l); holes = 1;
199 }
else if (m < fst()->next(NULL)->
min()) {
200 int f_max = fst()->max();
203 int f_min =
dom.min();
204 if ((m == f_min) && (m == f_max)) {
205 RangeList* f_next = fst()->next(NULL);
206 dom.min(f_next->min());
207 if (f_next == lst()) {
209 fst()->dispose(home,f_next);
210 fst(NULL); holes = 0;
213 f_next->prev(fst(),NULL);
214 fst()->dispose(home); fst(f_next);
215 holes -=
dom.min() - f_min - 1;
218 }
else if (m == f_min) {
219 dom.min(m+1); fst()->min(m+1);
221 }
else if (m == f_max) {
222 fst()->max(m-1); holes += 1;
225 RangeList*
f =
new (home) RangeList(f_min,m-1);
226 f->prevnext(NULL,fst());
227 fst()->min(m+1); fst()->prev(NULL,f);
230 }
else if (m > lst()->prev(NULL)->
max()) {
231 int l_min = lst()->min();
234 int l_max =
dom.max();
235 if ((m == l_min) && (m == l_max)) {
236 RangeList* l_prev = lst()->prev(NULL);
237 dom.max(l_prev->max());
238 if (l_prev == fst()) {
240 l_prev->dispose(home,lst());
241 fst(NULL); holes = 0;
244 l_prev->next(lst(),NULL);
245 lst()->dispose(home); lst(l_prev);
246 holes -= l_max -
dom.max() - 1;
249 }
else if (m == l_max) {
250 dom.max(m-1); lst()->max(m-1);
252 }
else if (m == l_min) {
253 lst()->min(m+1); holes += 1;
255 RangeList*
l =
new (home) RangeList(m+1,l_max);
256 l->prevnext(lst(),NULL);
257 lst()->max(m-1); lst()->next(NULL,
l);
265 assert(m > fst()->
max());
270 }
while (m >
c->
max());
275 assert(m < lst()->
min());
280 }
while (m < c->
min());
285 assert((fst() != c) && (lst() != c));
286 assert((m >=
c->
min()) && (m <= c->
max()));
288 int c_min =
c->
min();
289 int c_max =
c->
max();
290 if ((c_min == m) && (c_max == m)) {
292 p->next(c,
n);
n->prev(c,
p);
293 }
else if (c_min == m) {
298 RangeList*
l =
new (home) RangeList(m+1,c_max);
306 return notify(home,me,d);
317 IntVarImp::IntVarImp(Space& home, IntVarImp&
x)
324 RangeList* s_p =
x.fst();
325 RangeList* s_c = s_p->next(NULL);
328 RangeList* s_n = s_c->next(s_p); s_p=s_c; s_c=s_n;
329 }
while (s_c != NULL);
331 RangeList* d_c = home.alloc<RangeList>(m);
332 fst(d_c); lst(d_c+m-1);
333 d_c->min(
x.fst()->min());
334 d_c->max(
x.fst()->max());
335 d_c->prevnext(NULL,NULL);
336 RangeList* s_p =
x.fst();
337 RangeList* s_c = s_p->next(NULL);
339 RangeList* d_n = d_c + 1;
341 d_n->prevnext(d_c,NULL);
342 d_n->min(s_c->min()); d_n->max(s_c->max());
344 RangeList* s_n=s_c->next(s_p); s_p=s_c; s_c=s_n;
345 }
while (s_c != NULL);
346 d_c->next(NULL,NULL);
353 IntVarImp::perform_copy(Space& home) {
354 return new (home) IntVarImp(home,*
this);
362 IntVarImp::subscribe(Space& home, Propagator&
p, PropCond pc,
364 IntVarImpBase::subscribe(home,
p,pc,
dom.min()==
dom.max(),schedule);
368 IntVarImp::reschedule(Space& home, Propagator&
p, PropCond pc) {
369 IntVarImpBase::reschedule(home,
p,pc,
dom.min()==
dom.max());
373 IntVarImp::subscribe(Space& home, Advisor&
a,
bool fail) {
374 IntVarImpBase::subscribe(home,
a,
dom.min()==
dom.max(),fail);
int p
Number of positive literals for node type.
int n
Number of negative literals for node type.
struct Gecode::@603::NNF::@65::@67 a
For atomic nodes.
Node * x
Pointer to corresponding Boolean expression node.
friend FloatVal max(const FloatVal &x, const FloatVal &y)
friend FloatVal min(const FloatVal &x, const FloatVal &y)
bool assigned(View x, int v)
Whether x is assigned to value v.
const Gecode::ModEvent ME_INT_BND
Domain operation has changed the minimum or maximum of the domain.
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.
unsigned int size(I &i)
Size of all ranges of range iterator i.
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar SetRelType r
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
void range(Home home, const IntVarArgs &x, SetVar y, SetVar z)
Post constraint .
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Post propagator for SetVar x
int ModEvent
Type for modification events.
Gecode::FloatVal c(-8, 8)
Gecode::IntArgs i({1, 2, 3, 4})