34 namespace Gecode {
namespace Int {
namespace Element {
38 template<
class V0,
class V1,
class Idx,
class Val>
43 template<
class V0,
class V1,
class Idx,
class Val>
51 template<
class V0,
class V1,
class Idx,
class Val>
57 while ((i != 0) && iv[i].
marked())
61 template<
class V0,
class V1,
class Idx,
class Val>
66 template<
class V0,
class V1,
class Idx,
class Val>
75 template<
class V0,
class V1,
class Idx,
class Val>
84 template<
class V0,
class V1,
class Idx,
class Val>
87 :
iv(iv0),
i(
iv[0].val_next) {}
88 template<
class V0,
class V1,
class Idx,
class Val>
93 template<
class V0,
class V1,
class Idx,
class Val>
98 template<
class V0,
class V1,
class Idx,
class Val>
107 template<
class V0,
class V1,
class Idx,
class Val>
113 while ((i != 0) && iv[i].
marked())
117 template<
class V0,
class V1,
class Idx,
class Val>
122 template<
class V0,
class V1,
class Idx,
class Val>
131 template<
class V0,
class V1,
class Idx,
class Val>
141 template<
class V0,
class V1,
class Idx,
class Val>
145 template<
class V0,
class V1,
class Idx,
class Val>
156 template<
class V0,
class V1,
class Idx,
class Val>
165 template<
class V0,
class V1,
class Idx,
class Val>
173 return sizeof(*this);
176 template<
class V0,
class V1,
class Idx,
class Val>
181 }
else if (x1.assigned()) {
189 template<
class V0,
class V1,
class Idx,
class Val>
193 x0.update(home,
p.x0);
194 x1.update(home,
p.x1);
197 template<
class V0,
class V1,
class Idx,
class Val>
203 template<
class V0,
class V1,
class Idx,
class Val>
213 template<
class V0,
class V1,
class Idx,
class Val>
220 template<
class V0,
class V1,
class Idx,
class Val>
224 Idx
i = iv[
p].idx_next;
226 while (
v() && (
i != 0)) {
228 if (iv[
i].idx <
v.min()) {
229 iv[
i].mark();
i=iv[
i].idx_next; iv[
p].idx_next=
i;
230 }
else if (iv[
i].idx >
v.max()) {
233 p=
i;
i=iv[
i].idx_next;
238 iv[
i].mark();
i=iv[
i].idx_next;
242 template<
class V0,
class V1,
class Idx,
class Val>
246 Idx
i = iv[
p].val_next;
248 while (
v() && (
i != 0)) {
250 i=iv[
i].val_next; iv[
p].val_next=
i;
251 }
else if (iv[
i].val <
v.min()) {
252 iv[
i].mark();
i=iv[
i].val_next; iv[
p].val_next=
i;
253 }
else if (iv[
i].val >
v.max()) {
256 p=
i;
i=iv[
i].val_next;
261 iv[
i].mark();
i=iv[
i].val_next;
265 template<
class V0,
class V1,
class Idx,
class Val>
270 int*
v =
r.alloc<
int>(x0.size());
273 if (
c[
i.val()] != x1.val())
280 template<
class V0,
class V1,
class Idx,
class Val>
288 if (x1.assigned() && (iv == NULL)) {
293 if ((
static_cast<ValSize>(x1.size()) == s1) &&
294 (
static_cast<IdxSize>(x0.size()) != s0)) {
303 s1=
static_cast<ValSize>(x1.size());
305 assert(!x0.assigned());
309 if ((
static_cast<IdxSize>(x0.size()) == s0) &&
310 (
static_cast<ValSize>(x1.size()) != s1)) {
319 s0=
static_cast<IdxSize>(x0.size());
321 return (x0.assigned() || x1.assigned()) ?
325 bool assigned = x0.assigned() && x1.assigned();
335 if ((x1.min() <=
c[
v.val()]) && (x1.max() >=
c[
v.val()])) {
336 by_idx[
size].idx =
static_cast<Idx
>(
v.val());
337 by_idx[
size].val =
static_cast<Val
>(
c[
v.val()]);
344 Idx* by_val =
r.alloc<Idx>(
size);
345 if (x1.width() <= 128) {
346 int n_buckets =
static_cast<int>(x1.width());
347 int*
pos =
r.alloc<
int>(n_buckets);
348 int* buckets =
pos - x1.min();
349 for (
int i=0;
i<n_buckets;
i++)
352 buckets[by_idx[
i].val]++;
354 for (
int i=0;
i<n_buckets;
i++) {
359 by_val[buckets[by_idx[
i].val]++] =
i+1;
364 Support::quicksort<Idx>(by_val,
size,less);
368 by_idx[
i].idx_next =
i+2;
369 iv[by_val[
i]].val_next = by_val[
i+1];
371 by_idx[
size-1].idx_next = 0;
372 iv[by_val[
size-1]].val_next = 0;
375 iv[0].val_next = by_val[0];
390 s0=
static_cast<IdxSize>(x0.size());
391 s1=
static_cast<ValSize>(x1.size());
395 s0=
static_cast<IdxSize>(x0.size());
396 s1=
static_cast<ValSize>(x1.size());
397 return (x0.assigned() || x1.assigned()) ?
403 template<
class V0,
class V1>
406 assert(
c.
size() > 0);
int p
Number of positive literals for node type.
int n
Number of negative literals for node type.
Base-class for both propagators and branchers.
virtual size_t dispose(Space &home)
Delete actor and return its size.
FloatNum size(void) const
Return size of float value (distance between maximum and minimum)
Home class for posting propagators
void notice(Actor &a, ActorProperty p, bool duplicate=false)
Notice actor property.
Sorting pointers to (index,value) pairs in value order.
bool operator()(Idx &i, Idx &j)
Compare pairs at positions i and j.
ByVal(const IdxVal *iv)
Initialize with index value pairs.
Linked index-value pairs.
Idx val_next
The position of the next pair in value order.
Val val
The value Mark that this pair should be removed.
bool marked(void) const
Return whether this pair is marked for removal.
Idx idx_next
The position of the next pair in index order.
Value iterator for indices in index-value map.
Idx val(void) const
Return index of current index value pair.
void operator++(void)
Move to next index value pair (next index)
IterIdxUnmark(IdxVal *iv)
Initialize with start.
bool operator()(void) const
Test whether more pairs to be iterated.
Value iterator for values in index-value map.
void operator++(void)
Move to next index value pair (next value)
bool operator()(void) const
Test whether more pairs to be iterated.
Val val(void) const
Return value of current index value pair.
IterValUnmark(IdxVal *iv)
Initialize with start.
Value iterator for values in index-value map.
bool operator()(void) const
Test whether more pairs to be iterated.
IterVal(IdxVal *iv)
Initialize with start.
Val val(void) const
Return value of current index value pair.
void operator++(void)
Move to next index value pair (next value)
Element propagator for array of integers
Int(Space &home, Int &p)
Constructor for cloning p.
ValSize s1
Size of x1 at last execution.
void prune_val(void)
Prune values according to x1.
IntSharedArray c
Shared array of integer values.
static ExecStatus post(Home home, IntSharedArray &i, V0 x0, V1 x1)
Post propagator for .
virtual Actor * copy(Space &home)
Perform copying during cloning.
virtual void reschedule(Space &home)
Schedule function.
static ExecStatus assigned_val(Space &home, IntSharedArray &c, V0 x0, V1 x1)
Prune when x1 is assigned.
IdxSize s0
Size of x0 at last execution.
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
IdxVal * iv
The index-value data structure.
Gecode::Support::IntTypeTraits< Idx >::utype IdxSize
Type for index size.
Gecode::Support::IntTypeTraits< Val >::utype ValSize
Type for value size.
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as high binary)
void prune_idx(void)
Prune index according to x0.
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Range iterator for integer views.
Value iterator for integer views.
Value iterator for array of integers
static PropCost unary(PropCost::Mod m)
Single variable for modifier pcm.
static PropCost binary(PropCost::Mod m)
Two variables for modifier pcm.
Base-class for propagators.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
@ ES_OK
Execution is okay.
@ ES_FIX
Propagation has computed fixpoint.
@ ES_FAILED
Execution has resulted in failure.
@ ES_NOFIX
Propagation has not computed fixpoint.
ExecStatus ES_SUBSUMED(Propagator &p)
void ignore(Actor &a, ActorProperty p, bool duplicate=false)
Ignore actor property.
int ModEventDelta
Modification event deltas.
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
@ AP_DISPOSE
Actor must always be disposed.
bool pos(const View &x)
Test whether x is postive.
const FloatNum max
Largest allowed float value.
const FloatNum min
Smallest allowed float value.
bool shared(const IntSet &, VX)
ExecStatus post_int(Home home, IntSharedArray &c, V0 x0, V1 x1)
Post propagator with apropriate index and value types.
bool assigned(View x, int v)
Whether x is assigned to value v.
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable)
unsigned int size(I &i)
Size of all ranges of range iterator i.
IntType s_type(signed int n)
Return type required to represent n.
IntType
Description of integer types.
@ IT_CHAR
char integer type
@ IT_SHRT
short integer type
bool marked(void *p)
Check whether p is marked.
Gecode::FloatVal c(-8, 8)
Gecode::IntArgs i({1, 2, 3, 4})