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>
109 if (indices.valid(
l._variable)) {
110 indices.clear(
l._variable);
114 template <
class View>
126 template <
class View>
136 for (
unsigned int i = 1 ;
i <
n ;
i++) {
137 if (vs[
i] > maximum) maximum = vs[
i];
138 if (vs[
i] < minimum) minimum = vs[
i];
140 values.resize(home, maximum-minimum+1, minimum);
143 for (
unsigned int i = 0 ;
i <
n ;
i++) {
148 template <
class View>
153 template <
class View>
158 return sizeof(*this);
161 template <
class View>
169 template <
class View>
179 template <
class View>
186 template <
class View>
189 unsigned int seqsize)
190 : n_indices(
n), seq_size(seqsize), n_seqs(
n/seqsize) {
191 indices = home.
alloc<
unsigned int>(n_indices);
192 unsigned int max_index = _indices[0];
193 for (
unsigned int i = 0 ;
i < n_indices ;
i++) {
194 indices[
i] = _indices[
i];
195 if (indices[
i] > max_index)
196 max_index = indices[
i];
199 lookup_size = max_index+1;
200 lookup = home.
alloc<
int>(lookup_size);
201 for (
unsigned int i = 0 ;
i < lookup_size ;
i++)
203 for (
unsigned int i = 0 ;
i < n_indices ;
i++) {
204 if (lookup[indices[
i]] == -1)
205 lookup[indices[
i]] =
i;
209 template <
class View>
213 : n_indices(s.n_indices), seq_size(s.seq_size), n_seqs(s.n_seqs),
214 lookup_size(s.lookup_size) {
216 indices = home.
alloc<
unsigned int>(n_indices);
217 memcpy(indices, s.
indices, n_indices *
sizeof(
int));
218 lookup = home.
alloc<
int>(lookup_size);
219 memcpy(lookup, s.
lookup, lookup_size *
sizeof(
int));
222 template <
class View>
226 home.
free<
unsigned int>(indices, n_indices);
227 home.
free<
int>(lookup, lookup_size);
228 return sizeof(*this);
232 template <
class View>
237 if (
l._variable < (
int)lookup_size) {
238 int posIt = lookup[
l._variable];
242 unsigned int seqNum = posIt / seq_size;
243 unsigned int seqPos = posIt % seq_size;
244 for (
unsigned int seq = 0 ; seq < n_seqs ; seq++) {
252 const unsigned int *firstSeq = &indices[seqNum*seq_size];
253 const unsigned int *secondSeq = &indices[seq*seq_size];
254 for (
unsigned int i = 0 ;
i < seq_size ;
i++) {
255 const View& xv =
x[firstSeq[
i]];
256 const View& yv =
x[secondSeq[
i]];
257 if ((!xv.assigned() && !yv.assigned())
258 || (xv.assigned() && yv.assigned() && xv.val() == yv.val())) {
275 template <
class View>
283 template <
class View>
292 template <
class View>
299 template <
class View>
302 unsigned int seqsize)
303 : n_values(
n), seq_size(seqsize), n_seqs(
n/seqsize),
304 dead_sequences(home, n_seqs) {
306 for (
unsigned int i = 0 ;
i < n_values ;
i++)
310 template <
class View>
314 : n_values(vss.n_values),
315 seq_size(vss.seq_size),
317 dead_sequences(home, vss.dead_sequences) {
319 for (
unsigned int i = 0 ;
i < n_values ;
i++)
323 template <
class View>
328 return sizeof(*this);
331 template <
class View>
335 unsigned int seq = 0;
336 unsigned int pos = 0;
337 for (
unsigned int i = 0 ;
i < n_values ;
i++) {
339 dead_sequences.set(seq);
341 while (
pos < seq_size) {
347 if (
pos == seq_size) {
354 template <
class View>
SymmetryImp< View > * copy(Space &home, bool share) const
Copy function.
virtual size_t dispose(Space &home)
Disposal.
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.
SymmetryImp< View > * copy(Space &home, bool share) const
Copy function.
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.
SymmetryImp< View > * copy(Space &home, bool share) const
Copy function.
int * lookup
Map from variable's index to its sequence and position.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
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.)
SymmetryImp< View > * copy(Space &home, bool share) const
Copy function.
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.
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
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>
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.
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.