38 namespace Gecode {
namespace Int {
namespace LDSB {
41 template <
class T,
class A>
57 return home.ralloc(s);
71 : indices(home, 0, 0) {
75 int maximum = _indices[0];
76 int minimum = _indices[0];
77 for (
unsigned int i = 1 ;
i <
n ;
i++) {
78 if (_indices[
i] > maximum) maximum = _indices[
i];
79 if (_indices[
i] < minimum) minimum = _indices[
i];
81 indices.resize(home, maximum-minimum+1, minimum);
84 for (
unsigned int i = 0 ;
i <
n ;
i++) {
85 indices.set(_indices[
i]);
95 indices(home, other.indices) {}
101 indices.dispose(home);
102 return sizeof(*this);
105 template <
class View>
114 template <
class View>
124 template <
class View>
134 for (
unsigned int i = 1 ;
i <
n ;
i++) {
135 if (vs[
i] > maximum) maximum = vs[
i];
136 if (vs[
i] < minimum) minimum = vs[
i];
138 values.resize(home, maximum-minimum+1, minimum);
141 for (
unsigned int i = 0 ;
i <
n ;
i++) {
146 template <
class View>
151 template <
class View>
156 return sizeof(*this);
159 template <
class View>
167 template <
class View>
175 template <
class View>
179 return indices[sequence*seq_size +
position];
182 template <
class View>
185 unsigned int seqsize)
186 : n_indices(n), seq_size(seqsize), n_seqs(n/seqsize) {
187 indices = home.
alloc<
unsigned int>(n_indices);
188 unsigned int max_index = _indices[0];
189 for (
unsigned int i = 0 ;
i < n_indices ;
i++) {
190 indices[
i] = _indices[
i];
191 if (indices[
i] > max_index)
192 max_index = indices[
i];
195 lookup_size = max_index+1;
196 lookup = home.
alloc<
int>(lookup_size);
197 for (
unsigned int i = 0 ;
i < lookup_size ;
i++)
199 for (
unsigned int i = 0 ;
i < n_indices ;
i++) {
200 if (lookup[indices[
i]] == -1)
201 lookup[indices[
i]] =
i;
205 template <
class View>
209 : n_indices(s.n_indices), seq_size(s.seq_size), n_seqs(s.n_seqs),
210 lookup_size(s.lookup_size) {
211 indices = home.
alloc<
unsigned int>(n_indices);
212 memcpy(indices, s.
indices, n_indices *
sizeof(
int));
213 lookup = home.
alloc<
int>(lookup_size);
214 memcpy(lookup, s.
lookup, lookup_size *
sizeof(
int));
217 template <
class View>
221 home.
free<
unsigned int>(indices, n_indices);
222 home.
free<
int>(lookup, lookup_size);
223 return sizeof(*this);
227 template <
class View>
237 unsigned int seqNum = posIt / seq_size;
238 unsigned int seqPos = posIt % seq_size;
239 for (
unsigned int seq = 0 ; seq < n_seqs ; seq++) {
243 if (x[getVal(seq, seqPos)].
assigned()) {
247 const unsigned int *firstSeq = &indices[seqNum*seq_size];
248 const unsigned int *secondSeq = &indices[seq*seq_size];
249 for (
unsigned int i = 0 ;
i < seq_size ;
i++) {
250 const View& xv = x[firstSeq[
i]];
251 const View& yv = x[secondSeq[
i]];
252 if ((!xv.assigned() && !yv.assigned())
253 || (xv.assigned() && yv.assigned() && xv.val() == yv.val())) {
270 template <
class View>
278 template <
class View>
287 template <
class View>
294 template <
class View>
297 unsigned int seqsize)
298 : n_values(n), seq_size(seqsize), n_seqs(n/seqsize),
299 dead_sequences(home, n_seqs) {
301 for (
unsigned int i = 0 ;
i < n_values ;
i++)
305 template <
class View>
309 : n_values(vss.n_values),
310 seq_size(vss.seq_size),
312 dead_sequences(home, vss.dead_sequences) {
314 for (
unsigned int i = 0 ;
i < n_values ;
i++)
318 template <
class View>
323 return sizeof(*this);
326 template <
class View>
330 unsigned int seq = 0;
331 unsigned int pos = 0;
332 for (
unsigned int i = 0 ;
i < n_values ;
i++) {
334 dead_sequences.set(seq);
336 while (pos < seq_size) {
342 if (pos == seq_size) {
349 template <
class View>
virtual size_t dispose(Space &home)
Disposal.
SymmetryImp< View > * copy(Space &home) const
Copy function.
void sequence(Home home, const IntVarArgs &x, const IntSet &s, int q, int l, int u, IntPropLevel)
Post propagator for .
A Literal is a pair of variable index and value.
ValueSymmetryImp(Space &home, int *vs, unsigned int n)
Constructor for creation.
virtual ~SymmetryImp(void)
Unused destructor.
VariableSymmetryImp(Space &home, int *vs, unsigned int n)
Constructor for creation.
bool pos(const View &x)
Test whether x is postive.
Implementation of a variable sequence symmetry.
int * lookup
Map from variable's index to its sequence and position.
int _value
The value of the literal. For int and bool variables, this is the value itself; for set variables...
int _variable
Variable index. The ViewArray that the index is meant for is assumed to be known by context...
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Argument array for non-primitive types.
virtual size_t dispose(Space &home)
Disposal.
unsigned int * indices
Array of variable indices.
Implementation of a value symmetry.
int getVal(unsigned int sequence, unsigned int position) const
Get the value in the specified sequence at the specified position. (Both are zero-based.)
virtual size_t dispose(Space &home)
Disposal.
void free(T *b, long unsigned int n)
Delete n objects allocated from space heap starting at b.
double position(const Space &home, IntVar x, int i)
Implementation of a single symmetry.
void update(Literal)
Left-branch update.
struct Gecode::@585::NNF::@62::@64 a
For atomic nodes.
Heap heap
The single global heap.
bool assigned(View x, int v)
Whether x is assigned to value v.
Implementation of a variable symmetry.
Stack with arbitrary number of elements.
void update(Literal)
Left-branch update.
Implementation of a value sequence symmetry.
virtual ArgArray< Literal > symmetric(Literal, const ViewArray< View > &) const
Compute symmetric literals.
void values(Home home, const IntVarArgs &x, IntSet y, IntPropLevel ipl=IPL_DEF)
Post constraint .
Post propagator for SetVar x
SymmetryImp< View > * copy(Space &home) const
Copy function.
void update(Literal)
Search left-branch update.
Gecode toplevel namespace
ArgArray< T > dynamicStackToArgArray(const Support::DynamicStack< T, A > &s)
Convert a DynamicStack<T,A> into an ArgArray<T>
SymmetryImp< View > * copy(Space &home) const
Copy function.
virtual size_t dispose(Space &home)
Disposal.
int getVal(unsigned int sequence, unsigned int position) const
Get the value in the specified sequence at the specified position. (Both are zero-based.)
int entries(void) const
Return number of entries currently on stack.
SymmetryImp< View > * copy(Space &home) const
Copy function.
void update(Literal)
Left-branch update.
void push(const T &x)
Push element x on top of stack.
VariableSequenceSymmetryImp(Space &home, int *_indices, unsigned int n, unsigned int seqsize)
Constructor for creation.
int * values
Set of sequences.