/usr/include/gecode/int/ldsb/sym-imp.hpp is in libgecode-dev 4.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christopher Mears <chris.mears@monash.edu>
*
* Copyright:
* Christopher Mears, 2012
*
* Last modified:
* $Date: 2013-03-07 02:18:29 +0100 (Thu, 07 Mar 2013) $ by $Author: mears $
* $Revision: 13455 $
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
namespace Gecode { namespace Int { namespace LDSB {
/// Convert a \a DynamicStack<T,A> into an \a ArgArray<T>
template <class T, class A>
ArgArray<T>
dynamicStackToArgArray(const Support::DynamicStack<T,A>& s) {
ArgArray<T> a(s.entries());
for (int i = 0 ; i < s.entries() ; ++i) {
a[i] = s[i];
}
return a;
}
template<class View>
void*
SymmetryImp<View>::operator new(size_t s, Space& home) {
return home.ralloc(s);
}
template<class View>
void
SymmetryImp<View>::operator delete(void*,Space&) {}
template<class View>
void
SymmetryImp<View>::operator delete(void*) {}
template <class View>
VariableSymmetryImp<View>
::VariableSymmetryImp(Space& home, int* _indices, unsigned int n)
: indices(home, 0, 0) {
// Find minimum and maximum value in _indices: the minimum is the
// offset, and the maximum dictates how large the bitset needs to
// be.
int maximum = _indices[0];
int minimum = _indices[0];
for (unsigned int i = 1 ; i < n ; i++) {
if (_indices[i] > maximum) maximum = _indices[i];
if (_indices[i] < minimum) minimum = _indices[i];
}
indices.resize(home, maximum-minimum+1, minimum);
// Set the bits for the included indices.
for (unsigned int i = 0 ; i < n ; i++) {
indices.set(_indices[i]);
}
}
template <class View>
inline
VariableSymmetryImp<View>
::VariableSymmetryImp(Space& home, const VariableSymmetryImp& other) :
indices(home, other.indices) {}
template <class View>
size_t
VariableSymmetryImp<View>
::dispose(Space& home) {
indices.dispose(home);
return sizeof(*this);
}
template <class View>
void
VariableSymmetryImp<View>
::update(Literal l) {
if (indices.valid(l._variable)) {
indices.clear(l._variable);
}
}
template <class View>
SymmetryImp<View>*
VariableSymmetryImp<View>
::copy(Space& home, bool share) const {
(void) share;
return new (home) VariableSymmetryImp<View>(home, *this);
}
// The minimum value in vs is the bitset's offset, and the maximum
// dictates how large the bitset needs to be.
template <class View>
ValueSymmetryImp<View>
::ValueSymmetryImp(Space& home, int* vs, unsigned int n)
: values(home, 0, 0) {
// Find minimum and maximum value in vs: the minimum is the
// offset, and the maximum dictates how large the bitset needs to
// be.
assert(n > 0);
int maximum = vs[0];
int minimum = vs[0];
for (unsigned int i = 1 ; i < n ; i++) {
if (vs[i] > maximum) maximum = vs[i];
if (vs[i] < minimum) minimum = vs[i];
}
values.resize(home, maximum-minimum+1, minimum);
// Set the bits for the included values.
for (unsigned int i = 0 ; i < n ; i++) {
values.set(vs[i]);
}
}
template <class View>
ValueSymmetryImp<View>
::ValueSymmetryImp(Space& home, const ValueSymmetryImp<View>& other)
: values(home, other.values) { }
template <class View>
size_t
ValueSymmetryImp<View>
::dispose(Space& home) {
values.dispose(home);
return sizeof(*this);
}
template <class View>
void
ValueSymmetryImp<View>
::update(Literal l) {
if (values.valid(l._value))
values.clear(l._value);
}
template <class View>
SymmetryImp<View>*
ValueSymmetryImp<View>
::copy(Space& home, bool share) const {
(void) share;
return new (home) ValueSymmetryImp(home, *this);
}
template <class View>
int
VariableSequenceSymmetryImp<View>
::getVal(unsigned int sequence, unsigned int position) const {
return indices[sequence*seq_size + position];
}
template <class View>
VariableSequenceSymmetryImp<View>
::VariableSequenceSymmetryImp(Space& home, int* _indices, unsigned int n,
unsigned int seqsize)
: n_indices(n), seq_size(seqsize), n_seqs(n/seqsize) {
indices = home.alloc<unsigned int>(n_indices);
unsigned int max_index = _indices[0];
for (unsigned int i = 0 ; i < n_indices ; i++) {
indices[i] = _indices[i];
if (indices[i] > max_index)
max_index = indices[i];
}
lookup_size = max_index+1;
lookup = home.alloc<int>(lookup_size);
for (unsigned int i = 0 ; i < lookup_size ; i++)
lookup[i] = -1;
for (unsigned int i = 0 ; i < n_indices ; i++) {
if (lookup[indices[i]] == -1)
lookup[indices[i]] = i;
}
}
template <class View>
VariableSequenceSymmetryImp<View>
::VariableSequenceSymmetryImp(Space& home, bool share,
const VariableSequenceSymmetryImp& s)
: n_indices(s.n_indices), seq_size(s.seq_size), n_seqs(s.n_seqs),
lookup_size(s.lookup_size) {
(void) share;
indices = home.alloc<unsigned int>(n_indices);
memcpy(indices, s.indices, n_indices * sizeof(int));
lookup = home.alloc<int>(lookup_size);
memcpy(lookup, s.lookup, lookup_size * sizeof(int));
}
template <class View>
size_t
VariableSequenceSymmetryImp<View>
::dispose(Space& home) {
home.free<unsigned int>(indices, n_indices);
home.free<int>(lookup, lookup_size);
return sizeof(*this);
}
/// Compute symmetric literals
template <class View>
ArgArray<Literal>
VariableSequenceSymmetryImp<View>
::symmetric(Literal l, const ViewArray<View>& x) const {
Support::DynamicStack<Literal, Heap> s(heap);
if (l._variable < (int)lookup_size) {
int posIt = lookup[l._variable];
if (posIt == -1) {
return dynamicStackToArgArray(s);
}
unsigned int seqNum = posIt / seq_size;
unsigned int seqPos = posIt % seq_size;
for (unsigned int seq = 0 ; seq < n_seqs ; seq++) {
if (seq == seqNum) {
continue;
}
if (x[getVal(seq, seqPos)].assigned()) {
continue;
}
bool active = true;
const unsigned int *firstSeq = &indices[seqNum*seq_size];
const unsigned int *secondSeq = &indices[seq*seq_size];
for (unsigned int i = 0 ; i < seq_size ; i++) {
const View& xv = x[firstSeq[i]];
const View& yv = x[secondSeq[i]];
if ((!xv.assigned() && !yv.assigned())
|| (xv.assigned() && yv.assigned() && xv.val() == yv.val())) {
continue;
} else {
active = false;
break;
}
}
if (active) {
s.push(Literal(secondSeq[seqPos], l._value));
}
}
}
return dynamicStackToArgArray(s);
}
template <class View>
void
VariableSequenceSymmetryImp<View>
::update(Literal l) {
// Do nothing.
(void) l;
}
template <class View>
SymmetryImp<View>*
VariableSequenceSymmetryImp<View>
::copy(Space& home, bool share) const {
return new (home) VariableSequenceSymmetryImp<View>(home, share, *this);
}
template <class View>
int
ValueSequenceSymmetryImp<View>
::getVal(unsigned int sequence, unsigned int position) const {
return values[sequence*seq_size + position];
}
template <class View>
ValueSequenceSymmetryImp<View>
::ValueSequenceSymmetryImp(Space& home, int* _values, unsigned int n,
unsigned int seqsize)
: n_values(n), seq_size(seqsize), n_seqs(n/seqsize),
dead_sequences(home, n_seqs) {
values = home.alloc<int>(n_values);
for (unsigned int i = 0 ; i < n_values ; i++)
values[i] = _values[i];
}
template <class View>
ValueSequenceSymmetryImp<View>
::ValueSequenceSymmetryImp(Space& home,
const ValueSequenceSymmetryImp<View>& vss)
: n_values(vss.n_values),
seq_size(vss.seq_size),
n_seqs(vss.n_seqs),
dead_sequences(home, vss.dead_sequences) {
values = home.alloc<int>(n_values);
for (unsigned int i = 0 ; i < n_values ; i++)
values[i] = vss.values[i];
}
template <class View>
size_t
ValueSequenceSymmetryImp<View>
::dispose(Space& home) {
home.free(values, n_values);
return sizeof(*this);
}
template <class View>
void
ValueSequenceSymmetryImp<View>
::update(Literal l) {
unsigned int seq = 0;
unsigned int pos = 0;
for (unsigned int i = 0 ; i < n_values ; i++) {
if (values[i] == l._value) {
dead_sequences.set(seq);
// TODO: This can be slightly optimised.
while (pos < seq_size) {
i++;
pos++;
}
}
pos++;
if (pos == seq_size) {
pos = 0;
seq++;
}
}
}
template <class View>
SymmetryImp<View>*
ValueSequenceSymmetryImp<View>
::copy(Space& home, bool share) const {
(void) share;
return new (home) ValueSequenceSymmetryImp<View>(home, *this);
}
}}}
// STATISTICS: int-branch
|