/usr/include/gecode/int/var-imp.hpp is in libgecode-dev 5.1.0-2build1.
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 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 | /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Contributing authors:
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Christian Schulte, 2002
* Guido Tack, 2004
*
* Last modified:
* $Date: 2017-03-09 09:51:58 +0100 (Thu, 09 Mar 2017) $ by $Author: schulte $
* $Revision: 15565 $
*
* 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.
*
*/
#include <cmath>
namespace Gecode { namespace Int {
class IntVarImp;
class BoolVarImp;
/**
* \brief Integer delta information for advisors
*
* Note that the same delta information is used for both
* integer and Boolean variables and views.
*/
class IntDelta : public Delta {
friend class IntVarImp;
friend class BoolVarImp;
private:
int _min; ///< Minimum value just pruned
int _max; ///< Largest value just pruned
public:
/// Create integer delta as providing no information
IntDelta(void);
/// Create integer delta with \a min and \a max
IntDelta(int min, int max);
/// Create integer delta with \a min
IntDelta(int min);
private:
/// Return minimum
int min(void) const;
/// Return maximum
int max(void) const;
/// Test whether any domain change has happened
bool any(void) const;
};
}}
#include <gecode/int/var-imp/delta.hpp>
namespace Gecode { namespace Int {
class IntVarImpFwd;
class IntVarImpBwd;
/**
* \brief Integer variable implementation
*
* \ingroup Other
*/
class IntVarImp : public IntVarImpBase {
friend class IntVarImpFwd;
friend class IntVarImpBwd;
protected:
/**
* \brief Lists of ranges (intervals)
*
* Range lists are doubly-linked storing the pointer to both
* the next and the previous element in a single pointer.
* That means that the next element is only available when
* the previous element is supplied as additional information.
* The same holds true for access to the previous element.
*/
class RangeList : public FreeList {
protected:
/// Minimum of range
int _min;
/// Maximum of range
int _max;
public:
/// \name Constructors
//@{
/// Default constructor (noop)
RangeList(void);
/// Initialize with minimum \a min and maximum \a max
RangeList(int min, int max);
/// Initialize with minimum \a min and maximum \a max and predecessor \a p and successor \a n
RangeList(int min, int max, RangeList* p, RangeList* n);
//@}
/// \name Access
//@{
/// Return minimum
int min(void) const;
/// Return maximum
int max(void) const;
/// Return width (distance between maximum and minimum)
unsigned int width(void) const;
/// Return next element (from previous \a p)
RangeList* next(const RangeList* p) const;
/// Return previous element (from next \a n)
RangeList* prev(const RangeList* n) const;
//@}
/// \name Update
//@{
/// Set minimum to \a n
void min(int n);
/// Set maximum to \a n
void max(int n);
/// Set previous element to \a p and next element to \a n
void prevnext(RangeList* p, RangeList* n);
/// Set next element from \a o to \a n
void next(RangeList* o, RangeList* n);
/// Set previous element from \a o to \a n
void prev(RangeList* o, RangeList* n);
/// Restore simple link to next element (so that it becomes a true free list)
void fix(RangeList* n);
//@}
/// \name Memory management
//@{
/**
* \brief Free memory for all elements between this and \a l (inclusive)
*
* \a p must be the pointer to the previous element of \c this.
*/
void dispose(Space& home, RangeList* p, RangeList* l);
/**
* \brief Free memory for all elements between this and \a l (inclusive)
*
* This routine assumes that the list has already been fixed.
*/
void dispose(Space& home, RangeList* l);
/// Free memory for this element
void dispose(Space& home);
/// Allocate memory from space
static void* operator new(size_t s, Space& home);
/// Placement new
static void* operator new(size_t s, void* p);
/// No-op (for exceptions)
static void operator delete(void*);
/// No-op (use dispose instead)
static void operator delete(void*, Space&);
/// No-op (use dispose instead)
static void operator delete(void*, void*);
//@}
};
/**
* \brief Domain information
*
* Provides fast access to minimum and maximum of the
* entire domain and links to the first element
* of a RangeList defining the domain.
*/
RangeList dom;
/// Link the last element
RangeList* _lst;
/// Return first element of rangelist
RangeList* fst(void) const;
/// Set first element of rangelist
void fst(RangeList* f);
/// Return last element of rangelist
RangeList* lst(void) const;
/// Set last element of rangelist
void lst(RangeList* l);
/// Size of holes in the domain
unsigned int holes;
protected:
/// Constructor for cloning \a x
IntVarImp(Space& home, bool share, IntVarImp& x);
public:
/// Initialize with range domain
IntVarImp(Space& home, int min, int max);
/// Initialize with domain specified by \a d
IntVarImp(Space& home, const IntSet& d);
/// \name Value access
//@{
/// Return minimum of domain
int min(void) const;
/// Return maximum of domain
int max(void) const;
/// Return assigned value (only if assigned)
int val(void) const;
/// Return median of domain (greatest element not greater than the median)
GECODE_INT_EXPORT int med(void) const;
/// Return size (cardinality) of domain
unsigned int size(void) const;
/// Return width of domain (distance between maximum and minimum)
unsigned int width(void) const;
/// Return regret of domain minimum (distance to next larger value)
unsigned int regret_min(void) const;
/// Return regret of domain maximum (distance to next smaller value)
unsigned int regret_max(void) const;
//@}
private:
/// Test whether \a n is contained in domain (full domain)
GECODE_INT_EXPORT bool in_full(int n) const;
public:
/// \name Domain tests
//@{
/// Test whether domain is a range
bool range(void) const;
/// Test whether variable is assigned
bool assigned(void) const;
/// Test whether \a n is contained in domain
bool in(int n) const;
/// Test whether \a n is contained in domain
bool in(long long int n) const;
//@}
protected:
/// \name Range list access for iteration
//@{
/// Return range list for forward iteration
const RangeList* ranges_fwd(void) const;
/// Return range list for backward iteration
const RangeList* ranges_bwd(void) const;
//@}
private:
/// Test whether \a n is closer to the minimum or maximum
bool closer_min(int b) const;
/// \name Domain update by value (full domain)
//@{
/// Restrict domain values to be less or equal than \a n
GECODE_INT_EXPORT ModEvent lq_full(Space& home, int n);
/// Restrict domain values to be greater or equal than \a n
GECODE_INT_EXPORT ModEvent gq_full(Space& home, int n);
/// Restrict domain values to be equal to current minimum of domain
GECODE_INT_EXPORT ModEvent eq_full(Space& home, int n);
/// Restrict domain values to be different from \a n
GECODE_INT_EXPORT ModEvent nq_full(Space& home, int n);
//@}
public:
/// \name Domain update by value
//@{
/// Restrict domain values to be less or equal than \a n
ModEvent lq(Space& home, int n);
/// Restrict domain values to be less or equal than \a n
ModEvent lq(Space& home, long long int n);
/// Restrict domain values to be greater or equal than \a n
ModEvent gq(Space& home, int n);
/// Restrict domain values to be greater or equal than \a n
ModEvent gq(Space& home, long long int n);
/// Restrict domain values to be different from \a n
ModEvent nq(Space& home, int n);
/// Restrict domain values to be different from \a n
ModEvent nq(Space& home, long long int n);
/// Restrict domain values to be equal to \a n
ModEvent eq(Space& home, int n);
/// Restrict domain values to be equal to \a n
ModEvent eq(Space& home, long long int n);
//@}
/**
* \name Domain update by iterator
*
* Variable domains can be both updated by range and value iterators.
* Value iterators do not need to be strict in that the same value
* is allowed to occur more than once in the iterated sequence.
*
* The argument \a depends must be true, if the iterator
* passed as argument depends on the variable implementation
* on which the operation is invoked. In this case, the variable
* implementation is only updated after the iterator has been
* consumed. Otherwise, the domain might be updated concurrently
* while following the iterator.
*
*/
//@{
/// Replace domain by ranges described by \a i
template<class I>
ModEvent narrow_r(Space& home, I& i, bool depends=true);
/// Intersect domain with ranges described by \a i
template<class I>
ModEvent inter_r(Space& home, I& i, bool depends=true);
/// Remove from domain the ranges described by \a i
template<class I>
ModEvent minus_r(Space& home, I& i, bool depends=true);
/// Replace domain by values described by \a i
template<class I>
ModEvent narrow_v(Space& home, I& i, bool depends=true);
/// Intersect domain with values described by \a i
template<class I>
ModEvent inter_v(Space& home, I& i, bool depends=true);
/// Remove from domain the values described by \a i
template<class I>
ModEvent minus_v(Space& home, I& i, bool depends=true);
//@}
/// \name Dependencies
//@{
/**
* \brief Subscribe propagator \a p with propagation condition \a pc to variable
*
* In case \a schedule is false, the propagator is just subscribed but
* not scheduled for execution (this must be used when creating
* subscriptions during propagation).
*
*/
GECODE_INT_EXPORT void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
/// Re-schedule propagator \a p
GECODE_INT_EXPORT void reschedule(Space& home, Propagator& p, PropCond pc);
/** \brief Subscribe advisor \a a to variable
*
* The advisor \a a is only subscribed if \a assigned is false.
*
* If \a fail is true, the advisor \a a is also run when a variable
* operation triggers failure. This feature is undocumented.
*
*/
GECODE_INT_EXPORT void subscribe(Space& home, Advisor& a, bool fail);
//@}
/// \name Variable implementation-dependent propagator support
//@{
/// Translate modification event \a me to modification event delta for view
static ModEventDelta med(ModEvent me);
//@}
private:
/// Return copy of not-yet copied variable
GECODE_INT_EXPORT IntVarImp* perform_copy(Space& home, bool share);
public:
/// \name Cloning
//@{
/// Return copy of this variable
IntVarImp* copy(Space& home, bool share);
//@}
/// \name Delta information for advisors
//@{
/// Return minimum value just pruned
static int min(const Delta& d);
/// Return maximum value just pruned
static int max(const Delta& d);
/// Test whether arbitrary values got pruned
static bool any(const Delta& d);
//@}
};
/**
* \brief Range iterator for ranges of integer variable implementation
*
*/
class IntVarImpFwd {
private:
/// Previous range
const IntVarImp::RangeList* p;
/// Current range
const IntVarImp::RangeList* c;
public:
/// \name Constructors and initialization
//@{
/// Default constructor
IntVarImpFwd(void);
/// Initialize with ranges from variable implementation \a x
IntVarImpFwd(const IntVarImp* x);
/// Initialize with ranges from variable implementation \a x
void init(const IntVarImp* x);
//@}
/// \name Iteration control
//@{
/// Test whether iterator is still at a range or done
bool operator ()(void) const;
/// Move iterator to next range (if possible)
void operator ++(void);
//@}
/// \name Range access
//@{
/// Return smallest value of range
int min(void) const;
/// Return largest value of range
int max(void) const;
/// Return width of range (distance between minimum and maximum)
unsigned int width(void) const;
//@}
};
/**
* \brief Backward iterator for ranges of integer variable implementations
*
* Note that this iterator is not a range iterator as the ranges
* are not iterated in increasing but in decreasing order.
*
*/
class IntVarImpBwd {
private:
/// Next range
const IntVarImp::RangeList* n;
/// Current range
const IntVarImp::RangeList* c;
public:
/// \name Constructors and initialization
//@{
/// Default constructor
IntVarImpBwd(void);
/// Initialize with ranges from variable implementation \a x
IntVarImpBwd(const IntVarImp* x);
/// Initialize with ranges from variable implementation \a x
void init(const IntVarImp* x);
//@}
/// \name Iteration control
//@{
/// Test whether iterator is still at a range or done
bool operator ()(void) const;
/// Move iterator to previous range (if possible)
void operator ++(void);
//@}
/// \name Range access
//@{
/// Return smallest value of range
int min(void) const;
/// Return largest value of range
int max(void) const;
/// Return width of range (distance between minimum and maximum)
unsigned int width(void) const;
//@}
};
}}
#include <gecode/int/var-imp/int.hpp>
namespace Gecode {
class IntVar;
class BoolVar;
}
namespace Gecode { namespace Int {
/// Type for status of a Boolean variable
typedef unsigned int BoolStatus;
/**
* \brief Boolean variable implementation
*
* \ingroup Other
*/
class BoolVarImp : public BoolVarImpBase {
friend class ::Gecode::BoolVar;
private:
/**
* \brief Domain information
*
* - The bit at position 0 corresponds to the minimum
* - The bit at position 1 corresponds to the maximum
* - Interpreted as an unsigned, that is: 0 represents
* a variable assigned to 0, 3 represents a variable
* assigned to 1, and 2 represents an unassigned variable.
* - No other values are possible.
*/
GECODE_INT_EXPORT static BoolVarImp s_one;
GECODE_INT_EXPORT static BoolVarImp s_zero;
/// Constructor for cloning \a x
BoolVarImp(Space& home, bool share, BoolVarImp& x);
/// Initialize static instance assigned to \a n
BoolVarImp(int n);
public:
/// Initialize with range domain
BoolVarImp(Space& home, int min, int max);
/// \name Domain status access
//@{
/// How many bits does the status have
static const int BITS = 2;
/// Status of domain assigned to zero
static const BoolStatus ZERO = 0;
/// Status of domain assigned to one
static const BoolStatus ONE = 3;
/// Status of domain not yet assigned
static const BoolStatus NONE = 2;
/// Return current domain status
BoolStatus status(void) const;
//@}
/// \name Value access
//@{
/// Return minimum of domain
int min(void) const;
/// Return maximum of domain
int max(void) const;
/// Return assigned value (only if assigned)
int val(void) const;
/// Return median of domain (greatest element not greater than the median)
int med(void) const;
/// Return size (cardinality) of domain
unsigned int size(void) const;
/// Return width of domain (distance between maximum and minimum)
unsigned int width(void) const;
/// Return regret of domain minimum (distance to next larger value)
unsigned int regret_min(void) const;
/// Return regret of domain maximum (distance to next smaller value)
unsigned int regret_max(void) const;
//@}
/// \name Boolean domain tests
//@{
/// Test whether variable is assigned to zero
bool zero(void) const;
/// Test whether variable is assigned to one
bool one(void) const;
/// Test whether variable is not yet assigned
bool none(void) const;
//@}
/// \name Domain tests
//@{
/// Test whether domain is a range
bool range(void) const;
/// Test whether variable is assigned
bool assigned(void) const;
/// Test whether \a n is contained in domain
bool in(int n) const;
/// Test whether \a n is contained in domain
bool in(long long int n) const;
//@}
/// \name Domain update by value
//@{
/// Restrict domain values to be less or equal than \a n
ModEvent lq(Space& home, int n);
/// Restrict domain values to be less or equal than \a n
ModEvent lq(Space& home, long long int n);
/// Restrict domain values to be greater or equal than \a n
ModEvent gq(Space& home, int n);
/// Restrict domain values to be greater or equal than \a n
ModEvent gq(Space& home, long long int n);
/// Restrict domain values to be different from \a n
ModEvent nq(Space& home, int n);
/// Restrict domain values to be different from \a n
ModEvent nq(Space& home, long long int n);
/// Restrict domain values to be equal to \a n
ModEvent eq(Space& home, int n);
/// Restrict domain values to be equal to \a n
ModEvent eq(Space& home, long long int n);
//@}
/**
* \name Domain update by iterator
*
* Variable domains can be both updated by range and value iterators.
* Value iterators do not need to be strict in that the same value
* is allowed to occur more than once in the iterated sequence.
*
* The argument \a depends must be true, if the iterator
* passed as argument depends on the variable implementation
* on which the operation is invoked. In this case, the variable
* implementation is only updated after the iterator has been
* consumed. Otherwise, the domain might be updated concurrently
* while following the iterator.
*
*/
//@{
/// Replace domain by ranges described by \a i
template<class I>
ModEvent narrow_r(Space& home, I& i, bool depends=true);
/// Intersect domain with ranges described by \a i
template<class I>
ModEvent inter_r(Space& home, I& i, bool depends=true);
/// Remove from domain the ranges described by \a i
template<class I>
ModEvent minus_r(Space& home, I& i, bool depends=true);
/// Replace domain by values described by \a i
template<class I>
ModEvent narrow_v(Space& home, I& i, bool depends=true);
/// Intersect domain with values described by \a i
template<class I>
ModEvent inter_v(Space& home, I& i, bool depends=true);
/// Remove from domain the values described by \a i
template<class I>
ModEvent minus_v(Space& home, I& i, bool depends=true);
//@}
/// \name Boolean update operations
//@{
/// Assign variable to zero
ModEvent zero(Space& home);
/// Assign variable to one
ModEvent one(Space& home);
/// Assign unassigned variable to zero
GECODE_INT_EXPORT ModEvent zero_none(Space& home);
/// Assign unassigned variable to one
GECODE_INT_EXPORT ModEvent one_none(Space& home);
//@}
public:
/// \name Dependencies
//@{
/**
* \brief Subscribe propagator \a p to variable with propagation condition \a pc
*
* In case \a schedule is false, the propagator is just subscribed but
* not scheduled for execution (this must be used when creating
* subscriptions during propagation).
*
* The propagation condition \a pc can be a propagation condition
* for integer variables, which will be mapped to PC_BOOL_VAL.
*/
GECODE_INT_EXPORT void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
/**
* \brief Cancel subscription of propagator \a p with propagation condition \a pc
*
* The propagation condition \a pc can be a propagation condition
* for integer variables, which will be mapped to PC_BOOL_VAL.
*/
void cancel(Space& home, Propagator& p, PropCond pc);
/** \brief Subscribe advisor \a a to variable
*
* The advisor \a a is only subscribed if \a assigned is false.
*
* If \a fail is true, the advisor \a a is also run when a variable
* operation triggers failure. This feature is undocumented.
*
*/
GECODE_INT_EXPORT void subscribe(Space& home, Advisor& a, bool fail);
/// Cancel subscription of advisor \a a
void cancel(Space& home, Advisor& a, bool fail);
//@}
/// \name Variable implementation-dependent propagator support
//@{
/**
* \brief Schedule propagator \a p with modification event \a me
*
* The modfication event \a me can be a modification event for
* integer variables, however \a me will be ignored if it is not
* ME_INT_VAL (or ME_BOOL_VAL).
*/
static void schedule(Space& home, Propagator& p, ModEvent me);
/// Re-schedule propagator \a p
GECODE_INT_EXPORT void reschedule(Space& home, Propagator& p, PropCond pc);
/// Translate modification event \a me to modification event delta for view
static ModEventDelta med(ModEvent me);
//@}
/// \name Support for delta information for advisors
//@{
/// Return modification event
static ModEvent modevent(const Delta& d);
/// Return minimum value just pruned
static int min(const Delta& d);
/// Return maximum value just pruned
static int max(const Delta& d);
/// Test whether arbitrary values got pruned
static bool any(const Delta& d);
/// Test whether a variable has been assigned to zero
static bool zero(const Delta& d);
/// Test whether a variable has been assigned to one
static bool one(const Delta& d);
//@}
/// \name Cloning
//@{
/// Return copy of this variable
BoolVarImp* copy(Space& home, bool share);
//@}
};
}}
#include <gecode/int/var-imp/bool.hpp>
// STATISTICS: int-var
|