/usr/include/gecode/int/var-imp/bool.hpp is in libgecode-dev 4.4.0-3.
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 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2006
*
* Last modified:
* $Date: 2013-02-14 16:29:11 +0100 (Thu, 14 Feb 2013) $ by $Author: schulte $
* $Revision: 13292 $
*
* 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 {
/*
* Creation of new variable implementations
*
*/
forceinline
BoolVarImp::BoolVarImp(int n) {
assert(bits() == 0);
bits() |= (n << 1) | n;
}
forceinline
BoolVarImp::BoolVarImp(Space& home, int min, int max)
: BoolVarImpBase(home) {
assert(bits() == 0);
bits() |= (max << 1) | min;
}
/*
* Operations on Boolean variable implementations
*
*/
forceinline BoolStatus
BoolVarImp::status(void) const {
return bits() & 3;
}
forceinline int
BoolVarImp::min(void) const {
return static_cast<int>(bits() & 1);
}
forceinline int
BoolVarImp::max(void) const {
return static_cast<int>((bits() & 2) >> 1);
}
forceinline int
BoolVarImp::med(void) const {
return min();
}
forceinline int
BoolVarImp::val(void) const {
assert(status() != NONE);
return min();
}
forceinline bool
BoolVarImp::range(void) const {
return true;
}
forceinline bool
BoolVarImp::assigned(void) const {
return status() != NONE;
}
forceinline unsigned int
BoolVarImp::width(void) const {
return assigned() ? 1U : 2U;
}
forceinline unsigned int
BoolVarImp::size(void) const {
return assigned() ? 1U : 2U;
}
forceinline unsigned int
BoolVarImp::regret_min(void) const {
return assigned() ? 1U : 0U;
}
forceinline unsigned int
BoolVarImp::regret_max(void) const {
return assigned() ? 1U : 0U;
}
/*
* Tests
*
*/
forceinline bool
BoolVarImp::in(int n) const {
return (n >= min()) && (n <= max());
}
forceinline bool
BoolVarImp::in(long long int n) const {
return (n >= min()) && (n <= max());
}
/*
* Boolean domain tests
*
*/
forceinline bool
BoolVarImp::zero(void) const {
return status() < NONE;
}
forceinline bool
BoolVarImp::one(void) const {
return status() > NONE;
}
forceinline bool
BoolVarImp::none(void) const {
return status() == NONE;
}
/*
* Support for delta information
*
*/
forceinline ModEvent
BoolVarImp::modevent(const Delta&) {
return ME_BOOL_VAL;
}
forceinline int
BoolVarImp::min(const Delta& d) {
return static_cast<const IntDelta&>(d).min();
}
forceinline int
BoolVarImp::max(const Delta& d) {
return static_cast<const IntDelta&>(d).min();
}
forceinline bool
BoolVarImp::any(const Delta&) {
return false;
}
forceinline bool
BoolVarImp::zero(const Delta& d) {
return static_cast<const IntDelta&>(d).min() != 0;
}
forceinline bool
BoolVarImp::one(const Delta& d) {
return static_cast<const IntDelta&>(d).min() == 0;
}
/*
* Boolean tell operations
*
*/
forceinline ModEvent
BoolVarImp::zero(Space& home) {
if (one()) return ME_BOOL_FAILED;
if (zero()) return ME_BOOL_NONE;
return zero_none(home);
}
forceinline ModEvent
BoolVarImp::one(Space& home) {
if (one()) return ME_BOOL_NONE;
if (zero()) return ME_BOOL_FAILED;
return one_none(home);
}
/*
* Tell operations
*
*/
forceinline ModEvent
BoolVarImp::gq(Space& home, int n) {
if (n <= 0) return ME_INT_NONE;
if (n > 1) return ME_INT_FAILED;
return one(home);
}
forceinline ModEvent
BoolVarImp::gq(Space& home, long long int n) {
if (n <= 0) return ME_INT_NONE;
if (n > 1) return ME_INT_FAILED;
return one(home);
}
forceinline ModEvent
BoolVarImp::lq(Space& home, int n) {
if (n < 0) return ME_INT_FAILED;
if (n >= 1) return ME_INT_NONE;
return zero(home);
}
forceinline ModEvent
BoolVarImp::lq(Space& home, long long int n) {
if (n < 0) return ME_INT_FAILED;
if (n >= 1) return ME_INT_NONE;
return zero(home);
}
forceinline ModEvent
BoolVarImp::eq(Space& home, int n) {
if ((n < 0) || (n > 1)) return ME_INT_FAILED;
return (n == 0) ? zero(home): one(home);
}
forceinline ModEvent
BoolVarImp::eq(Space& home, long long int n) {
if ((n < 0) || (n > 1)) return ME_INT_FAILED;
return (n == 0) ? zero(home): one(home);
}
forceinline ModEvent
BoolVarImp::nq(Space& home, int n) {
if ((n < 0) || (n > 1)) return ME_INT_NONE;
return (n == 0) ? one(home): zero(home);
}
forceinline ModEvent
BoolVarImp::nq(Space& home, long long int n) {
if ((n < 0) || (n > 1)) return ME_INT_NONE;
return (n == 0) ? one(home): zero(home);
}
/*
* Copying a variable
*
*/
forceinline
BoolVarImp::BoolVarImp(Space& home, bool share, BoolVarImp& x)
: BoolVarImpBase(home,share,x) {}
forceinline BoolVarImp*
BoolVarImp::copy(Space& home, bool share) {
if (copied())
return static_cast<BoolVarImp*>(forward());
else if (zero())
return &s_zero;
else if (one())
return &s_one;
else
return new (home) BoolVarImp(home,share,*this);
}
/*
* Iterator-based domain operations
*
*/
template<class I>
forceinline ModEvent
BoolVarImp::narrow_r(Space& home, I& i, bool) {
// Is new domain empty?
if (!i())
return ME_INT_FAILED;
assert((i.min() == 0) || (i.min() == 1));
assert((i.max() == 0) || (i.max() == 1));
if (i.max() == 0) {
assert(!one());
// Assign domain to be zero (domain cannot be one)
return zero(home);
}
if (i.min() == 1) {
// Assign domain to be one (domain cannot be zero)
assert(!zero());
return one(home);
}
assert(none());
return ME_INT_NONE;
}
template<class I>
forceinline ModEvent
BoolVarImp::inter_r(Space& home, I& i, bool) {
// Skip all ranges that are too small
while (i() && (i.max() < 0))
++i;
// Is new domain empty?
if (!i() || (i.min() > 1))
return ME_INT_FAILED;
assert(i.min() <= 1);
if (i.min() == 1)
return one(home);
if (i.max() == 0)
return zero(home);
assert((i.min() <= 0) && (i.max() >= 1));
return ME_INT_NONE;
}
template<class I>
forceinline ModEvent
BoolVarImp::minus_r(Space& home, I& i, bool) {
// Skip all ranges that are too small
while (i() && (i.max() < 0))
++i;
// Is new domain empty?
if (!i() || (i.min() > 1))
return ME_INT_NONE;
assert(i.min() <= 1);
if (i.min() == 1)
return zero(home);
if (i.max() == 0)
return one(home);
assert((i.min() <= 0) && (i.max() >= 1));
return ME_INT_FAILED;
}
template<class I>
forceinline ModEvent
BoolVarImp::narrow_v(Space& home, I& i, bool) {
if (!i())
return ME_INT_FAILED;
if (!none())
return ME_INT_NONE;
if (i.val() == 0) {
do {
++i;
} while (i() && (i.val() == 0));
if (!i())
return zero_none(home);
return ME_INT_NONE;
} else {
assert(i.val() == 1);
return one_none(home);
}
}
template<class I>
forceinline ModEvent
BoolVarImp::inter_v(Space& home, I& i, bool) {
while (i() && (i.val() < 0))
++i;
if (!i() || (i.val() > 1))
return ME_INT_FAILED;
if (i.val() == 0) {
do {
++i;
} while (i() && (i.val() == 0));
if (!i() || (i.val() > 1))
return zero(home);
return ME_INT_NONE;
} else {
assert(i.val() == 1);
return one(home);
}
}
template<class I>
forceinline ModEvent
BoolVarImp::minus_v(Space& home, I& i, bool) {
while (i() && (i.val() < 0))
++i;
if (!i() || (i.val() > 1))
return ME_INT_NONE;
if (i.val() == 0) {
do {
++i;
} while (i() && (i.val() == 0));
if (!i() || (i.val() > 1))
return one(home);
return ME_INT_FAILED;
} else {
assert(i.val() == 1);
return zero(home);
}
}
/*
* Dependencies
*
*/
forceinline void
BoolVarImp::subscribe(Space& home, Propagator& p, PropCond,
bool schedule) {
// Subscription can be used with integer propagation conditions,
// which must be remapped to the single Boolean propagation condition.
BoolVarImpBase::subscribe(home,p,PC_BOOL_VAL,assigned(),schedule);
}
forceinline void
BoolVarImp::cancel(Space& home, Propagator& p, PropCond) {
BoolVarImpBase::cancel(home,p,PC_BOOL_VAL,assigned());
}
forceinline void
BoolVarImp::subscribe(Space& home, Advisor& a) {
BoolVarImpBase::subscribe(home,a,assigned());
}
forceinline void
BoolVarImp::cancel(Space& home, Advisor& a) {
BoolVarImpBase::cancel(home,a,assigned());
}
forceinline void
BoolVarImp::schedule(Space& home, Propagator& p, ModEvent me) {
if (me == ME_GEN_ASSIGNED)
BoolVarImpBase::schedule(home,p,me);
}
forceinline ModEventDelta
BoolVarImp::med(ModEvent me) {
return BoolVarImpBase::med(me);
}
}}
// STATISTICS: int-var
|