1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 /* 3 * Main authors: 4 * Guido Tack <tack@gecode.org> 5 * Christian Schulte <schulte@gecode.org> 6 * 7 * Contributing authors: 8 * Gabor Szokoli <szokoli@gecode.org> 9 * 10 * Copyright: 11 * Guido Tack, 2004 12 * Christian Schulte, 2004 13 * Gabor Szokoli, 2004 14 * 15 * This file is part of Gecode, the generic constraint 16 * development environment: 17 * http://www.gecode.org 18 * 19 * Permission is hereby granted, free of charge, to any person obtaining 20 * a copy of this software and associated documentation files (the 21 * "Software"), to deal in the Software without restriction, including 22 * without limitation the rights to use, copy, modify, merge, publish, 23 * distribute, sublicense, and/or sell copies of the Software, and to 24 * permit persons to whom the Software is furnished to do so, subject to 25 * the following conditions: 26 * 27 * The above copyright notice and this permission notice shall be 28 * included in all copies or substantial portions of the Software. 29 * 30 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 31 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 33 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 34 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 35 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 36 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 37 * 38 */ 39 40 #ifndef GECODE_SET_HH 41 #define GECODE_SET_HH 42 43 #include <gecode/kernel.hh> 44 #include <gecode/int.hh> 45 #include <gecode/iter.hh> 46 47 #include <functional> 48 49 /* 50 * Configure linking 51 * 52 */ 53 #if !defined(GECODE_STATIC_LIBS) && \ 54 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER)) 55 56 #ifdef GECODE_BUILD_SET 57 #define GECODE_SET_EXPORT __declspec( dllexport ) 58 #else 59 #define GECODE_SET_EXPORT __declspec( dllimport ) 60 #endif 61 62 #else 63 64 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY 65 #define GECODE_SET_EXPORT __attribute__ ((visibility("default"))) 66 #else 67 #define GECODE_SET_EXPORT 68 #endif 69 70 #endif 71 72 // Configure auto-linking 73 #ifndef GECODE_BUILD_SET 74 #define GECODE_LIBRARY_NAME "Set" 75 #include <gecode/support/auto-link.hpp> 76 #endif 77 78 79 /** 80 * \namespace Gecode::Set 81 * \brief Finite integer sets 82 * 83 * The Gecode::Set namespace contains all functionality required 84 * to program propagators and branchers for finite integer sets. 85 * In addition, all propagators and branchers for finite integer 86 * sets provided by %Gecode are contained as nested namespaces. 87 * 88 */ 89 90 #include <gecode/set/exception.hpp> 91 92 namespace Gecode { namespace Set { 93 94 /// Numerical limits for set variables 95 namespace Limits { 96 /// Largest allowed integer in integer set 97 const int max = (Gecode::Int::Limits::max / 2) - 1; 98 /// Smallest allowed integer in integer set 99 const int min = -max; 100 /// Maximum cardinality of an integer set 101 const unsigned int card = max-min+1; 102 /// Check whether integer \a n is in range, otherwise throw overflow exception with information \a l 103 void check(int n, const char* l); 104 /// Check whether unsigned int \a n is in range for cardinality, otherwise throw overflow exception with information \a l 105 void check(unsigned int n, const char* l); 106 /// Check whether minimum and maximum of IntSet \a s is in range, otherwise throw overflow exception with information \a l 107 void check(const IntSet& s, const char* l); 108 } 109 110 }} 111 112 #include <gecode/set/limits.hpp> 113 114 #include <gecode/set/var-imp.hpp> 115 116 namespace Gecode { 117 118 namespace Set { 119 class SetView; 120 } 121 122 /** 123 * \brief %Set variables 124 * 125 * \ingroup TaskModelSetVars 126 */ 127 class SetVar : public VarImpVar<Set::SetVarImp> { 128 friend class SetVarArray; 129 friend class SetVarArgs; 130 using VarImpVar<Set::SetVarImp>::x; 131 public: 132 /// \name Constructors and initialization 133 //@{ 134 /// Default constructor 135 SetVar(void); 136 /// Initialize from set variable \a y 137 SetVar(const SetVar& y); 138 /// Initialize from set view \a y 139 SetVar(const Set::SetView& y); 140 141 /// Initialize variable with empty greatest lower and full least upper bound 142 GECODE_SET_EXPORT SetVar(Space& home); 143 144 /** 145 * \brief Initialize variable with given bounds and cardinality 146 * 147 * The variable is created with 148 * greatest lower bound \f$\{\mathit{glbMin},\dots,\mathit{glbMax}\}\f$, 149 * least upper bound \f$\{\mathit{lubMin},\dots,\mathit{lubMax}\}\f$, and 150 * cardinality minimum \a cardMin and maximum \a cardMax. 151 * The following exceptions might be thrown: 152 * - If the bounds are no legal set bounds (between Set::Limits::min 153 * and Set::Limits::max), an exception of type 154 * Gecode::Set::OutOfLimits is thrown. 155 * - If the cardinality is greater than Set::Limits::max_set_size, an 156 * exception of type Gecode::Set::OutOfLimits is 157 * thrown. 158 * - If \a cardMin > \a cardMax, an exception of type 159 * Gecode::Set::VariableEmptyDomain is thrown. 160 */ 161 GECODE_SET_EXPORT 162 SetVar(Space& home,int glbMin,int glbMax,int lubMin,int lubMax, 163 unsigned int cardMin = 0, 164 unsigned int cardMax = Set::Limits::card); 165 166 /** 167 * \brief Initialize variable with given bounds and cardinality 168 * 169 * The variable is created with greatest lower bound \a glbD, 170 * least upper bound \f$\{\mathit{lubMin},\dots,\mathit{lubMax}\}\f$, and 171 * cardinality minimum \a cardMin and maximum \a cardMax. 172 * The following exceptions might be thrown: 173 * - If the bounds are no legal set bounds (between Set::Limits::min 174 * and Set::Limits::max), an exception of type 175 * Gecode::Set::OutOfLimits is thrown. 176 * - If the cardinality is greater than Set::Limits::max_set_size, an 177 * exception of type Gecode::Set::OutOfLimits is 178 * thrown. 179 * - If \a cardMin > \a cardMax, an exception of type 180 * Gecode::Set::VariableEmptyDomain is thrown. 181 */ 182 GECODE_SET_EXPORT 183 SetVar(Space& home,const IntSet& glbD,int lubMin,int lubMax, 184 unsigned int cardMin = 0, 185 unsigned int cardMax = Set::Limits::card); 186 187 /** 188 * \brief Initialize variable with given bounds and cardinality 189 * 190 * The variable is created with 191 * greatest lower bound \f$\{\mathit{glbMin},\dots,\mathit{glbMax}\}\f$, 192 * least upper bound \a lubD, and 193 * cardinality minimum \a cardMin and maximum \a cardMax. 194 * The following exceptions might be thrown: 195 * - If the bounds are no legal set bounds (between Set::Limits::min 196 * and Set::Limits::max), an exception of type 197 * Gecode::Set::OutOfLimits is thrown. 198 * - If the cardinality is greater than Set::Limits::max_set_size, an 199 * exception of type Gecode::Set::OutOfLimits is 200 * thrown. 201 * - If \a minCard > \a maxCard, an exception of type 202 * Gecode::Set::VariableEmptyDomain is thrown. 203 */ 204 GECODE_SET_EXPORT 205 SetVar(Space& home,int glbMin,int glbMax,const IntSet& lubD, 206 unsigned int cardMin = 0, 207 unsigned int cardMax = Set::Limits::card); 208 209 /** 210 * \brief Initialize variable with given bounds and cardinality 211 * 212 * The variable is created with 213 * greatest lower bound \a glbD, 214 * least upper bound \a lubD, and 215 * cardinality minimum \a cardMin and maximum \a cardMax. 216 * The following exceptions might be thrown: 217 * - If the bounds are no legal set bounds (between Set::Limits::min 218 * and Set::Limits::max), an exception of type 219 * Gecode::Set::OutOfLimits is thrown. 220 * - If the cardinality is greater than Set::Limits::max_set_size, an 221 * exception of type Gecode::Set::OutOfLimits is 222 * thrown. 223 * - If \a minCard > \a maxCard, an exception of type 224 * Gecode::Set::VariableEmptyDomain is thrown. 225 */ 226 GECODE_SET_EXPORT 227 SetVar(Space& home,const IntSet& glbD,const IntSet& lubD, 228 unsigned int cardMin = 0, 229 unsigned int cardMax = Set::Limits::card); 230 //@} 231 232 /// \name Value access 233 //@{ 234 /// Return number of elements in the greatest lower bound 235 unsigned int glbSize(void) const; 236 /// Return number of elements in the least upper bound 237 unsigned int lubSize(void) const; 238 /// Return number of unknown elements (elements in lub but not in glb) 239 unsigned int unknownSize(void) const; 240 /// Return cardinality minimum 241 unsigned int cardMin(void) const; 242 /// Return cardinality maximum 243 unsigned int cardMax(void) const; 244 /// Return minimum element of least upper bound 245 int lubMin(void) const; 246 /// Return maximum element of least upper bound 247 int lubMax(void) const; 248 /// Return minimum element of greatest lower bound 249 int glbMin(void) const; 250 /// Return maximum of greatest lower bound 251 int glbMax(void) const; 252 //@} 253 254 /// \name Domain tests 255 //@{ 256 /// Test whether \a i is in greatest lower bound 257 bool contains(int i) const; 258 /// Test whether \a i is not in the least upper bound 259 bool notContains(int i) const; 260 //@} 261 }; 262 263 /** 264 * \defgroup TaskModelSetIter Range and value iterators for set variables 265 * \ingroup TaskModelSet 266 */ 267 //@{ 268 269 /// Iterator for the greatest lower bound ranges of a set variable 270 class SetVarGlbRanges { 271 private: 272 Set::GlbRanges<Set::SetVarImp*> iter; 273 public: 274 /// \name Constructors and initialization 275 //@{ 276 /// Default constructor 277 SetVarGlbRanges(void); 278 /// Initialize to iterate ranges of variable \a x 279 SetVarGlbRanges(const SetVar& x); 280 //@} 281 282 /// \name Iteration control 283 //@{ 284 /// Test whether iterator is still at a range or done 285 bool operator ()(void) const; 286 /// Move iterator to next range (if possible) 287 void operator ++(void); 288 //@} 289 290 /// \name Range access 291 //@{ 292 /// Return smallest value of range 293 int min(void) const; 294 /// Return largest value of range 295 int max(void) const; 296 /// Return width of range (distance between minimum and maximum) 297 unsigned int width(void) const; 298 //@} 299 }; 300 301 /// Iterator for the least upper bound ranges of a set variable 302 class SetVarLubRanges { 303 private: 304 Set::LubRanges<Set::SetVarImp*> iter; 305 public: 306 /// \name Constructors and initialization 307 //@{ 308 /// Default constructor 309 SetVarLubRanges(void); 310 /// Initialize to iterate ranges of variable \a x 311 SetVarLubRanges(const SetVar& x); 312 //@} 313 314 /// \name Iteration control 315 //@{ 316 /// Test whether iterator is still at a range or done 317 bool operator ()(void) const; 318 /// Move iterator to next range (if possible) 319 void operator ++(void); 320 //@} 321 322 /// \name Range access 323 //@{ 324 /// Return smallest value of range 325 int min(void) const; 326 /// Return largest value of range 327 int max(void) const; 328 /// Return width of range (distance between minimum and maximum) 329 unsigned int width(void) const; 330 //@} 331 }; 332 333 /// Iterator for the unknown ranges of a set variable 334 class SetVarUnknownRanges { 335 private: 336 Set::UnknownRanges<Set::SetVarImp*> iter; 337 public: 338 /// \name Constructors and initialization 339 //@{ 340 /// Default constructor 341 SetVarUnknownRanges(void); 342 /// Initialize to iterate ranges of variable \a x 343 SetVarUnknownRanges(const SetVar& x); 344 //@} 345 346 /// \name Iteration control 347 //@{ 348 /// Test whether iterator is still at a range or done 349 bool operator ()(void) const; 350 /// Move iterator to next range (if possible) 351 void operator ++(void); 352 //@} 353 354 /// \name Range access 355 //@{ 356 /// Return smallest value of range 357 int min(void) const; 358 /// Return largest value of range 359 int max(void) const; 360 /// Return width of range (distance between minimum and maximum) 361 unsigned int width(void) const; 362 //@} 363 }; 364 365 /// Iterator for the values in the greatest lower bound of a set variable 366 class SetVarGlbValues { 367 private: 368 Iter::Ranges::ToValues<SetVarGlbRanges> iter; 369 public: 370 /// \name Constructors and initialization 371 //@{ 372 /// Default constructor 373 SetVarGlbValues(void); 374 /// Initialize to iterate values of variable \a x 375 SetVarGlbValues(const SetVar& x); 376 //@} 377 378 /// \name Iteration control 379 //@{ 380 /// Test whether iterator is still at a value or done 381 bool operator ()(void) const; 382 /// Move iterator to next value (if possible) 383 void operator ++(void); 384 //@} 385 386 /// \name Value access 387 //@{ 388 /// Return current value 389 int val(void) const; 390 //@} 391 }; 392 393 /// Iterator for the values in the least upper bound of a set variable 394 class SetVarLubValues { 395 private: 396 Iter::Ranges::ToValues<SetVarLubRanges> iter; 397 public: 398 /// \name Constructors and initialization 399 //@{ 400 /// Default constructor 401 SetVarLubValues(void); 402 /// Initialize to iterate values of variable \a x 403 SetVarLubValues(const SetVar& x); 404 //@} 405 406 /// \name Iteration control 407 //@{ 408 /// Test whether iterator is still at a value or done 409 bool operator ()(void) const; 410 /// Move iterator to next value (if possible) 411 void operator ++(void); 412 //@} 413 414 /// \name Value access 415 //@{ 416 /// Return current value 417 int val(void) const; 418 //@} 419 }; 420 421 /// Iterator for the values in the unknown set of a set variable 422 class SetVarUnknownValues { 423 private: 424 Iter::Ranges::ToValues<SetVarUnknownRanges> iter; 425 public: 426 /// \name Constructors and initialization 427 //@{ 428 /// Default constructor 429 SetVarUnknownValues(void); 430 /// Initialize to iterate values of variable \a x 431 SetVarUnknownValues(const SetVar& x); 432 //@} 433 434 /// \name Iteration control 435 //@{ 436 /// Test whether iterator is still at a value or done 437 bool operator ()(void) const; 438 /// Move iterator to next value (if possible) 439 void operator ++(void); 440 //@} 441 442 /// \name Value access 443 //@{ 444 /// Return current value 445 int val(void) const; 446 //@} 447 }; 448 449 //@} 450 451 /** 452 * \brief Print set variable \a x 453 * \relates Gecode::SetVar 454 */ 455 template<class Char, class Traits> 456 std::basic_ostream<Char,Traits>& 457 operator <<(std::basic_ostream<Char,Traits>& os, const SetVar& x); 458 459 } 460 461 #include <gecode/set/view.hpp> 462 463 namespace Gecode { 464 /** 465 * \defgroup TaskModelSetArgs Argument arrays 466 * 467 * Argument arrays are just good enough for passing arguments 468 * with automatic memory management. 469 * \ingroup TaskModelSet 470 */ 471 472 //@{ 473 474 } 475 476 #include <gecode/set/array-traits.hpp> 477 478 namespace Gecode { 479 480 /** \brief Passing set variables 481 * 482 * We could have used a simple typedef instead, but doxygen cannot 483 * resolve some overloading then, leading to unusable documentation for 484 * important parts of the library. As long as there is no fix for this, 485 * we will keep this workaround. 486 * 487 */ 488 class SetVarArgs : public VarArgArray<SetVar> { 489 public: 490 /// \name Constructors and initialization 491 //@{ 492 /// Allocate empty array 493 SetVarArgs(void); 494 /// Allocate array with \a n elements 495 explicit SetVarArgs(int n); 496 /// Initialize from variable argument array \a a (copy elements) 497 SetVarArgs(const SetVarArgs& a); 498 /// Initialize from variable array \a a (copy elements) 499 SetVarArgs(const VarArray<SetVar>& a); 500 /// Initialize from vector \a a 501 SetVarArgs(const std::vector<SetVar>& a); 502 /// Initialize from list \a a 503 SetVarArgs(std::initializer_list<SetVar> a); 504 /// Initialize from InputIterator \a first and \a last 505 template<class InputIterator> 506 SetVarArgs(InputIterator first, InputIterator last); 507 /** 508 * \brief Create an array of size \a n. 509 * 510 * Each variable is initialized with the bounds and cardinality as 511 * given by the arguments. 512 */ 513 GECODE_SET_EXPORT 514 SetVarArgs(Space& home,int n,int glbMin,int glbMax, 515 int lubMin,int lubMax, 516 unsigned int minCard = 0, 517 unsigned int maxCard = Set::Limits::card); 518 /** 519 * \brief Create an array of size \a n. 520 * 521 * Each variable is initialized with the bounds and cardinality as 522 * given by the arguments. 523 */ 524 GECODE_SET_EXPORT 525 SetVarArgs(Space& home,int n,const IntSet& glb, 526 int lubMin, int lubMax, 527 unsigned int minCard = 0, 528 unsigned int maxCard = Set::Limits::card); 529 /** 530 * \brief Create an array of size \a n. 531 * 532 * Each variable is initialized with the bounds and cardinality as 533 * given by the arguments. 534 */ 535 GECODE_SET_EXPORT 536 SetVarArgs(Space& home,int n,int glbMin,int glbMax, 537 const IntSet& lub, 538 unsigned int minCard = 0, 539 unsigned int maxCard = Set::Limits::card); 540 /** 541 * \brief Create an array of size \a n. 542 * 543 * Each variable is initialized with the bounds and cardinality as 544 * given by the arguments. 545 */ 546 GECODE_SET_EXPORT 547 SetVarArgs(Space& home,int n, 548 const IntSet& glb,const IntSet& lub, 549 unsigned int minCard = 0, 550 unsigned int maxCard = Set::Limits::card); 551 //@} 552 }; 553 //@} 554 555 /** 556 * \defgroup TaskModelSetVarArrays Variable arrays 557 * 558 * Variable arrays can store variables. They are typically used 559 * for storing the variables being part of a solution. However, 560 * they can also be used for temporary purposes (even though 561 * memory is not reclaimed until the space it is created for 562 * is deleted). 563 * \ingroup TaskModelSet 564 */ 565 566 /** 567 * \brief %Set variable array 568 * \ingroup TaskModelSetVarArrays 569 */ 570 class SetVarArray : public VarArray<SetVar> { 571 public: 572 /// \name Creation and initialization 573 //@{ 574 /// Default constructor (array of size 0) 575 SetVarArray(void); 576 /// Initialize from set variable array \a a (share elements) 577 SetVarArray(const SetVarArray&); 578 /// Initialize from set variable argument array \a a (copy elements) 579 SetVarArray(Space& home, const SetVarArgs&); 580 /// Allocate array for \a n set variables (variables are uninitialized) 581 GECODE_SET_EXPORT SetVarArray(Space& home, int n); 582 /** 583 * \brief Create an array of size \a n. 584 * 585 * Each variable is initialized with the bounds and cardinality as 586 * given by the arguments. 587 */ 588 GECODE_SET_EXPORT 589 SetVarArray(Space& home,int n,int glbMin,int glbMax,int lubMin,int lubMax, 590 unsigned int minCard = 0, 591 unsigned int maxCard = Set::Limits::card); 592 /** 593 * \brief Create an array of size \a n. 594 * 595 * Each variable is initialized with the bounds and cardinality as 596 * given by the arguments. 597 */ 598 GECODE_SET_EXPORT 599 SetVarArray(Space& home,int n,const IntSet& glb, int lubMin, int lubMax, 600 unsigned int minCard = 0, 601 unsigned int maxCard = Set::Limits::card); 602 /** 603 * \brief Create an array of size \a n. 604 * 605 * Each variable is initialized with the bounds and cardinality as 606 * given by the arguments. 607 */ 608 GECODE_SET_EXPORT 609 SetVarArray(Space& home,int n,int glbMin,int glbMax,const IntSet& lub, 610 unsigned int minCard = 0, 611 unsigned int maxCard = Set::Limits::card); 612 /** 613 * \brief Create an array of size \a n. 614 * 615 * Each variable is initialized with the bounds and cardinality as 616 * given by the arguments. 617 */ 618 GECODE_SET_EXPORT 619 SetVarArray(Space& home,int n, 620 const IntSet& glb,const IntSet& lub, 621 unsigned int minCard = 0, 622 unsigned int maxCard = Set::Limits::card); 623 //@} 624 }; 625 626 } 627 628 #include <gecode/set/array.hpp> 629 630 namespace Gecode { 631 632 /** 633 * \brief Common relation types for sets 634 * 635 * The total order on sets is defined as the lexicographic 636 * order on their characteristic functions, e.g., 637 * \f$x\leq y\f$ means that either \f$x\f$ is empty or 638 * the minimal element of the symmetric difference 639 * \f$x\ominus y\f$ is in \f$y\f$. 640 * 641 * \ingroup TaskModelSet 642 */ 643 enum SetRelType { 644 SRT_EQ, ///< Equality (\f$=\f$) 645 SRT_NQ, ///< Disequality (\f$\neq\f$) 646 SRT_SUB, ///< Subset (\f$\subseteq\f$) 647 SRT_SUP, ///< Superset (\f$\supseteq\f$) 648 SRT_DISJ, ///< Disjoint (\f$\parallel\f$) 649 SRT_CMPL, ///< Complement 650 SRT_LQ, ///< Less or equal (\f$\leq\f$) 651 SRT_LE, ///< Less (\f$<\f$) 652 SRT_GQ, ///< Greater or equal (\f$\geq\f$) 653 SRT_GR ///< Greater (\f$>\f$) 654 }; 655 656 /** 657 * \brief Common operations for sets 658 * \ingroup TaskModelSet 659 */ 660 enum SetOpType { 661 SOT_UNION, ///< Union 662 SOT_DUNION, ///< Disjoint union 663 SOT_INTER, ///< %Intersection 664 SOT_MINUS ///< Difference 665 }; 666 667 /** 668 * \defgroup TaskModelSetDom Domain constraints 669 * \ingroup TaskModelSet 670 * 671 */ 672 //@{ 673 /// Propagates \f$ x \sim_r \{i\}\f$ 674 GECODE_SET_EXPORT void 675 dom(Home home, SetVar x, SetRelType r, int i); 676 /// Propagates \f$ x_i \sim_r \{i\}\f$ for all \f$0\leq i<|x|\f$ 677 GECODE_SET_EXPORT void 678 dom(Home home, const SetVarArgs& x, SetRelType r, int i); 679 /// Propagates \f$ x \sim_r \{i,\dots,j\}\f$ 680 GECODE_SET_EXPORT void 681 dom(Home home, SetVar x, SetRelType r, int i, int j); 682 /// Propagates \f$ x \sim_r \{i,\dots,j\}\f$ for all \f$0\leq i<|x|\f$ 683 GECODE_SET_EXPORT void 684 dom(Home home, const SetVarArgs& x, SetRelType r, int i, int j); 685 /// Propagates \f$ x \sim_r s\f$ 686 GECODE_SET_EXPORT void 687 dom(Home home, SetVar x, SetRelType r, const IntSet& s); 688 /// Propagates \f$ x \sim_r s\f$ for all \f$0\leq i<|x|\f$ 689 GECODE_SET_EXPORT void 690 dom(Home home, const SetVarArgs& x, SetRelType r, const IntSet& s); 691 /// Propagates \f$ i \leq |s| \leq j \f$ 692 GECODE_SET_EXPORT void 693 cardinality(Home home, SetVar x, unsigned int i, unsigned int j); 694 /// Propagates \f$ i \leq |s| \leq j \f$ for all \f$0\leq i<|x|\f$ 695 GECODE_SET_EXPORT void 696 cardinality(Home home, const SetVarArgs& x, unsigned int i, unsigned int j); 697 /// Post propagator for \f$ (x \sim_{rt} \{i\}) \equiv r \f$ 698 GECODE_SET_EXPORT void 699 dom(Home home, SetVar x, SetRelType rt, int i, Reify r); 700 /// Post propagator for \f$ (x \sim_{rt} \{i,\dots,j\}) \equiv r \f$ 701 GECODE_SET_EXPORT void 702 dom(Home home, SetVar x, SetRelType rt, int i, int j, Reify r); 703 /// Post propagator for \f$ (x \sim_{rt} s) \equiv r \f$ 704 GECODE_SET_EXPORT void 705 dom(Home home, SetVar x, SetRelType rt, const IntSet& s, Reify r); 706 /// Constrain domain of \a x according to domain of \a d 707 GECODE_SET_EXPORT void 708 dom(Home home, SetVar x, SetVar d); 709 /// Constrain domain of \f$ x_i \f$ according to domain of \f$ d_i \f$ for all \f$0\leq i<|x|\f$ 710 GECODE_SET_EXPORT void 711 dom(Home home, const SetVarArgs& x, const SetVarArgs& d); 712 //@} 713 714 715 /** 716 * \defgroup TaskModelSetRel Relation constraints 717 * \ingroup TaskModelSet 718 * 719 */ 720 //@{ 721 /// Post propagator for \f$ x \sim_r y\f$ 722 GECODE_SET_EXPORT void 723 rel(Home home, SetVar x, SetRelType r, SetVar y); 724 /// Post propagator for \f$ (x \sim_{rt} y) \equiv r\f$ 725 GECODE_SET_EXPORT void 726 rel(Home home, SetVar x, SetRelType rt, SetVar y, Reify r); 727 /// Post propagator for \f$ s \sim_r \{x\}\f$ 728 GECODE_SET_EXPORT void 729 rel(Home home, SetVar s, SetRelType r, IntVar x); 730 /// Post propagator for \f$ \{x\} \sim_r s\f$ 731 GECODE_SET_EXPORT void 732 rel(Home home, IntVar x, SetRelType r, SetVar s); 733 /// Post propagator for \f$ (s \sim_{rt} \{x\}) \equiv r\f$ 734 GECODE_SET_EXPORT void 735 rel(Home home, SetVar s, SetRelType rt, IntVar x, Reify r); 736 /// Post propagator for \f$ (\{x\} \sim_{rt} s) \equiv r \f$ 737 GECODE_SET_EXPORT void 738 rel(Home home, IntVar x, SetRelType rt, SetVar s, Reify r); 739 /// Post propagator for \f$|s|\geq 1 \land \forall i\in s:\ i \sim_{rt} x\f$ 740 GECODE_SET_EXPORT void 741 rel(Home home, SetVar s, IntRelType rt, IntVar x); 742 /// Post propagator for \f$|s|\geq 1 \land \forall i\in s:\ x \sim_{rt} i\f$ 743 void 744 rel(Home home, IntVar x, IntRelType rt, SetVar s); 745 /// Post reified propagator for \f$\left(|s|\geq 1 \land \forall i\in s:\ i \sim_{rt} x\right)\equiv r\f$ 746 GECODE_SET_EXPORT void 747 rel(Home home, SetVar s, IntRelType rt, IntVar x, Reify r); 748 /// Post reified propagator for \f$\left(|s|\geq 1 \land \forall i\in s:\ x \sim_{rt} i\right)\f\equiv r$ 749 void 750 rel(Home home, IntVar x, IntRelType rt, SetVar s, Reify r); 751 //@} 752 753 } 754 755 #include <gecode/set/int.hpp> 756 757 namespace Gecode { 758 759 /** 760 * \defgroup TaskModelSetRelOp Set operation/relation constraints 761 * \ingroup TaskModelSet 762 * 763 */ 764 //@{ 765 /// Post propagator for \f$ (x \diamond_{\mathit{op}} y) \sim_r z \f$ 766 GECODE_SET_EXPORT void 767 rel(Home home, SetVar x, SetOpType op, SetVar y, SetRelType r, SetVar z); 768 /// Post propagator for \f$ y = \diamond_{\mathit{op}} x\f$ 769 GECODE_SET_EXPORT void 770 rel(Home home, SetOpType op, const SetVarArgs& x, SetVar y); 771 /// Post propagator for \f$ y = \diamond_{\mathit{op}} x \diamond_{\mathit{op}} z\f$ 772 GECODE_SET_EXPORT void 773 rel(Home home, SetOpType op, const SetVarArgs& x, const IntSet& z, SetVar y); 774 /// Post propagator for \f$ y = \diamond_{\mathit{op}} x \diamond_{\mathit{op}} z\f$ 775 GECODE_SET_EXPORT void 776 rel(Home home, SetOpType op, const IntVarArgs& x, const IntSet& z, SetVar y); 777 /// Post propagator for \f$ y = \diamond_{\mathit{op}} x\f$ 778 GECODE_SET_EXPORT void 779 rel(Home home, SetOpType op, const IntVarArgs& x, SetVar y); 780 /// Post propagator for \f$ (x \diamond_{\mathit{op}} y) \sim_r z \f$ 781 GECODE_SET_EXPORT void 782 rel(Home home, const IntSet& x, SetOpType op, SetVar y, 783 SetRelType r, SetVar z); 784 /// Post propagator for \f$ (x \diamond_{\mathit{op}} y) \sim_r z \f$ 785 GECODE_SET_EXPORT void 786 rel(Home home, SetVar x, SetOpType op, const IntSet& y, 787 SetRelType r, SetVar z); 788 /// Post propagator for \f$ (x \diamond_{\mathit{op}} y) \sim_r z \f$ 789 GECODE_SET_EXPORT void 790 rel(Home home, SetVar x, SetOpType op, SetVar y, 791 SetRelType r, const IntSet& z); 792 /// Post propagator for \f$ (x \diamond_{\mathit{op}} y) \sim_r z \f$ 793 GECODE_SET_EXPORT void 794 rel(Home home, const IntSet& x, SetOpType op, SetVar y, SetRelType r, 795 const IntSet& z); 796 /// Post propagator for \f$ (x \diamond_{\mathit{op}} y) \sim_r z \f$ 797 GECODE_SET_EXPORT void 798 rel(Home home, SetVar x, SetOpType op, const IntSet& y, SetRelType r, 799 const IntSet& z); 800 /** \brief Post propagator for if-then-else constraint 801 * 802 * Posts propagator for \f$ z = b ? x : y \f$ 803 */ 804 GECODE_SET_EXPORT void 805 ite(Home home, BoolVar b, SetVar x, SetVar y, SetVar z); 806 //@} 807 808 809 /** 810 * \defgroup TaskModelSetConvex Convexity constraints 811 * \ingroup TaskModelSet 812 * 813 */ 814 //@{ 815 /// Post propagator that propagates that \a x is convex 816 GECODE_SET_EXPORT void 817 convex(Home home, SetVar x); 818 /// Post propagator that propagates that \a y is the convex hull of \a x 819 GECODE_SET_EXPORT void 820 convex(Home home, SetVar x, SetVar y); 821 //@} 822 823 824 /** 825 * \defgroup TaskModelSetSequence Sequence constraints 826 * \ingroup TaskModelSet 827 * 828 */ 829 //@{ 830 /// Post propagator for \f$\forall 0\leq i< |x|-1 : \max(x_i)<\min(x_{i+1})\f$ 831 GECODE_SET_EXPORT void 832 sequence(Home home, const SetVarArgs& x); 833 /// Post propagator for \f$\forall 0\leq i< |x|-1 : \max(x_i)<\min(x_{i+1})\f$ and \f$ x = \bigcup_{i\in\{0,\dots,n-1\}} y_i \f$ 834 GECODE_SET_EXPORT void 835 sequence(Home home, const SetVarArgs& y, SetVar x); 836 //@} 837 838 839 /** 840 * \defgroup TaskModelSetDistinct Distinctness constraints 841 * \ingroup TaskModelSet 842 * 843 */ 844 //@{ 845 /// Post propagator for \f$\forall 0\leq i\leq |x| : |x_i|=c\f$ and \f$\forall 0\leq i<j\leq |x| : |x_i\cap x_j|\leq 1\f$ 846 GECODE_SET_EXPORT void 847 atmostOne(Home home, const SetVarArgs& x, unsigned int c); 848 //@} 849 850 /** 851 * \defgroup TaskModelSetConnect Connection constraints to integer variables 852 * \ingroup TaskModelSet 853 * 854 */ 855 /** \brief Post propagator that \a x is the minimal element of \a s and that \a s is not empty 856 * \ingroup TaskModelSetConnect 857 */ 858 GECODE_SET_EXPORT void 859 min(Home home, SetVar s, IntVar x); 860 /** \brief Post propagator that \a x is not the minimal element of \a s 861 * \ingroup TaskModelSetConnect 862 */ 863 GECODE_SET_EXPORT void 864 notMin(Home home, SetVar s, IntVar x); 865 /** \brief Post reified propagator for \a b iff \a x is the minimal element of \a s 866 * \ingroup TaskModelSetConnect 867 */ 868 GECODE_SET_EXPORT void 869 min(Home home, SetVar s, IntVar x, Reify r); 870 /** \brief Post propagator that \a x is the maximal element of \a s and that \a s is not empty 871 * \ingroup TaskModelSetConnect 872 */ 873 GECODE_SET_EXPORT void 874 max(Home home, SetVar s, IntVar x); 875 /** \brief Post propagator that \a x is not the maximal element of \a s 876 * \ingroup TaskModelSetConnect 877 */ 878 GECODE_SET_EXPORT void 879 notMax(Home home, SetVar s, IntVar x); 880 /** \brief Post reified propagator for \a b iff \a x is the maximal element of \a s 881 * \ingroup TaskModelSetConnect 882 */ 883 GECODE_SET_EXPORT void 884 max(Home home, SetVar s, IntVar x, Reify r); 885 /** \brief Post propagator for \f$ |s|=x \f$ 886 * \ingroup TaskModelSetConnect 887 */ 888 GECODE_SET_EXPORT void 889 cardinality(Home home, SetVar s, IntVar x); 890 /** \brief Post reified propagator for \f$ |s|=x \equiv r\f$ 891 * \ingroup TaskModelSetConnect 892 */ 893 GECODE_SET_EXPORT void 894 cardinality(Home home, SetVar s, IntVar x, Reify r); 895 /** 896 * \brief Post propagator for \f$y = \mathrm{weight}(x)\f$ 897 * 898 * The weights are given as pairs of elements and their weight: 899 * \f$\mathrm{weight}(\mathrm{elements}_i) = \mathrm{weights}_i\f$ 900 * 901 * The upper bound of \a x is constrained to contain only elements from 902 * \a elements. The weight of a set is the sum of the weights of its 903 * elements. 904 * 905 * \ingroup TaskModelSetConnect 906 */ 907 GECODE_SET_EXPORT void 908 weights(Home home, IntSharedArray elements, IntSharedArray weights, 909 SetVar x, IntVar y); 910 911 912 /** 913 * \defgroup TaskModelSetChannel Channel constraints 914 * \ingroup TaskModelSet 915 * 916 */ 917 //@{ 918 /// Post propagator for \f$x_i=j \Leftrightarrow i\in y_j\f$ 919 GECODE_SET_EXPORT void 920 channel(Home home, const IntVarArgs& x,const SetVarArgs& y); 921 /// Post propagator for \f$\{x_0,\dots,x_{n-1}\}=y\f$ and \f$x_i<x_{i+1}\f$ 922 GECODE_SET_EXPORT void 923 channelSorted(Home home, const IntVarArgs& x, SetVar y); 924 /// Post propagator for \f$x_i=1 \Leftrightarrow i\in y\f$ 925 GECODE_SET_EXPORT void 926 channel(Home home, const BoolVarArgs& x, SetVar y); 927 /// Post propagator for \f$j\in x_i \Leftrightarrow i\in y_j\f$ 928 GECODE_SET_EXPORT void 929 channel(Home home, const SetVarArgs& x, const SetVarArgs& y); 930 //@} 931 932 933 /** 934 * \defgroup TaskModelSetPrecede Value precedence constraints over set variables 935 * \ingroup TaskModelSet 936 */ 937 /** \brief Post propagator that \a s precedes \a t in \a x 938 * 939 * This constraint enforces that if there exists \f$j\f$ such that 940 * \f$s\notin x_j\land t\in x_j\f$, then there exists \f$i<j\f$ such that 941 * \f$s\in x_i\land t\notin x_i\f$. 942 * \ingroup TaskModelSetPrecede 943 */ 944 GECODE_SET_EXPORT void 945 precede(Home home, const SetVarArgs& x, int s, int t); 946 /** \brief Post propagator that successive values in \a c precede each other in \a x 947 * \ingroup TaskModelSetPrecede 948 */ 949 GECODE_SET_EXPORT void 950 precede(Home home, const SetVarArgs& x, const IntArgs& c); 951 952 953 /** 954 * \defgroup TaskModelSetElement Element constraints 955 * \ingroup TaskModelSet 956 * 957 * An element constraint selects zero, one or more elements out of a 958 * sequence. We write \f$ \langle x_0,\dots, x_{n-1} \rangle \f$ for the 959 * sequence, and \f$ [y] \f$ for the index variable. 960 * 961 * Set element constraints are closely related to the ::element constraint 962 * on integer variables. 963 */ 964 //@{ 965 /** 966 * \brief Post propagator for \f$ z=\diamond_{\mathit{op}}\langle x_0,\dots,x_{n-1}\rangle[y] \f$ 967 * 968 * If \a y is the empty set, the usual conventions for set operations apply: 969 * an empty union is empty, while an empty intersection is the universe, 970 * which can be given as the optional parameter \a u. 971 * 972 * The indices for \a y start at 0. 973 */ 974 GECODE_SET_EXPORT void 975 element(Home home, SetOpType op, const SetVarArgs& x, SetVar y, SetVar z, 976 const IntSet& u = IntSet(Set::Limits::min,Set::Limits::max)); 977 /** 978 * \brief Post propagator for \f$ z=\diamond_{\mathit{op}}\langle \{x_0\},\dots,\{x_{n-1}\}\rangle[y] \f$ 979 * 980 * If \a y is the empty set, the usual conventions for set operations apply: 981 * an empty union is empty, while an empty intersection is the universe, 982 * which can be given as the optional parameter \a u. 983 * 984 * The indices for \a y start at 0. 985 */ 986 GECODE_SET_EXPORT void 987 element(Home home, SetOpType op, const IntVarArgs& x, SetVar y, SetVar z, 988 const IntSet& u = IntSet(Set::Limits::min,Set::Limits::max)); 989 /** 990 * \brief Post propagator for \f$ z=\diamond_{\mathit{op}}\langle x_0,\dots,x_{n-1}\rangle[y] \f$ 991 * 992 * If \a y is the empty set, the usual conventions for set operations apply: 993 * an empty union is empty, while an empty intersection is the universe, 994 * which can be given as the optional parameter \a u. 995 * 996 * The indices for \a y start at 0. 997 */ 998 GECODE_SET_EXPORT void 999 element(Home home, SetOpType op, const IntSetArgs& x, SetVar y, SetVar z, 1000 const IntSet& u = IntSet(Set::Limits::min,Set::Limits::max)); 1001 /** 1002 * \brief Post propagator for \f$ z=\diamond_{\mathit{op}}\langle \{x_0\},\dots,\{x_{n-1}\}\rangle[y] \f$ 1003 * 1004 * If \a y is the empty set, the usual conventions for set operations apply: 1005 * an empty union is empty, while an empty intersection is the universe, 1006 * which can be given as the optional parameter \a u. 1007 * 1008 * The indices for \a y start at 0. 1009 */ 1010 GECODE_SET_EXPORT void 1011 element(Home home, SetOpType op, const IntArgs& x, SetVar y, SetVar z, 1012 const IntSet& u = IntSet(Set::Limits::min,Set::Limits::max)); 1013 /** 1014 * \brief Post propagator for \f$ z=\langle x_0,\dots,x_{n-1}\rangle[y] \f$ 1015 * 1016 * The indices for \a y start at 0. 1017 */ 1018 GECODE_SET_EXPORT void 1019 element(Home home, const SetVarArgs& x, IntVar y, SetVar z); 1020 /** 1021 * \brief Post propagator for \f$ z=\langle s_0,\dots,s_{n-1}\rangle[y] \f$ 1022 * 1023 * The indices for \a y start at 0. 1024 */ 1025 GECODE_SET_EXPORT void 1026 element(Home home, const IntSetArgs& s, IntVar y, SetVar z); 1027 /** \brief Post propagator for \f$ a_{x+w\cdot y}=z\f$ 1028 * 1029 * Throws an exception of type Set::ArgumentSizeMismatch, if 1030 * \f$ w\cdot h\neq|a|\f$. 1031 */ 1032 GECODE_SET_EXPORT void 1033 element(Home home, const IntSetArgs& a, 1034 IntVar x, int w, IntVar y, int h, SetVar z); 1035 /** \brief Post propagator for \f$ a_{x+w\cdot y}=z\f$ 1036 * 1037 * Throws an exception of type Set::ArgumentSizeMismatch, if 1038 * \f$ w\cdot h\neq|a|\f$. 1039 */ 1040 GECODE_SET_EXPORT void 1041 element(Home home, const SetVarArgs& a, 1042 IntVar x, int w, IntVar y, int h, SetVar z); 1043 //@} 1044 1045 1046 /** 1047 * \defgroup TaskModelSetExec Synchronized execution 1048 * \ingroup TaskModelSet 1049 * 1050 * Synchronized execution executes a function or a static member function 1051 * when a certain event happends. 1052 * 1053 * \ingroup TaskModelSet 1054 */ 1055 //@{ 1056 /// Execute \a c when \a x becomes assigned 1057 GECODE_SET_EXPORT void 1058 wait(Home home, SetVar x, std::function<void(Space& home)> c); 1059 /// Execute \a c when all variables in \a x become assigned 1060 GECODE_SET_EXPORT void 1061 wait(Home home, const SetVarArgs& x, std::function<void(Space& home)> c); 1062 //@} 1063 1064 } 1065 1066 1067 namespace Gecode { 1068 1069 /** 1070 * \defgroup TaskModelSetBranch Branching 1071 * \ingroup TaskModelSet 1072 */ 1073 1074 /** 1075 * \brief Branch filter function type for set variables 1076 * 1077 * The variable \a x is considered for selection and \a i refers to the 1078 * variable's position in the original array passed to the brancher. 1079 * 1080 * \ingroup TaskModelSetBranch 1081 */ 1082 typedef std::function<bool(const Space& home, SetVar x, int i)> 1083 SetBranchFilter; 1084 /** 1085 * \brief Branch merit function type for set variables 1086 * 1087 * The function must return a merit value for the variable 1088 * \a x. 1089 * The value \a i refers to the variable's position in the original array 1090 * passed to the brancher. 1091 * 1092 * \ingroup TaskModelSetBranch 1093 */ 1094 typedef std::function<double(const Space& home, SetVar x, int i)> 1095 SetBranchMerit; 1096 1097 /** 1098 * \brief Branch value function type for set variables 1099 * 1100 * Returns a value for the variable \a x that is to be used in the 1101 * corresponding branch commit function. The integer \a i refers 1102 * to the variable's position in the original array passed to the 1103 * brancher. 1104 * 1105 * \ingroup TaskModelSetBranch 1106 */ 1107 typedef std::function<int(const Space& home, SetVar x, int i)> 1108 SetBranchVal; 1109 1110 /** 1111 * \brief Branch commit function type for set variables 1112 * 1113 * The function must post a constraint on the variable \a x which 1114 * corresponds to the alternative \a a. The integer \a i refers 1115 * to the variable's position in the original array passed to the 1116 * brancher. The value \a n is the value 1117 * computed by the corresponding branch value function. 1118 * 1119 * \ingroup TaskModelSetBranch 1120 */ 1121 typedef std::function<void(Space& home, unsigned int a, 1122 SetVar x, int i, int n)> 1123 SetBranchCommit; 1124 1125 } 1126 1127 #include <gecode/set/branch/traits.hpp> 1128 1129 namespace Gecode { 1130 1131 /** 1132 * \brief Recording AFC information for set variables 1133 * 1134 * \ingroup TaskModelSetBranch 1135 */ 1136 class SetAFC : public AFC { 1137 public: 1138 /** 1139 * \brief Construct as not yet initialized 1140 * 1141 * The only member functions that can be used on a constructed but not 1142 * yet initialized AFC storage is init or the assignment operator. 1143 * 1144 */ 1145 SetAFC(void); 1146 /// Copy constructor 1147 SetAFC(const SetAFC& a); 1148 /// Assignment operator 1149 SetAFC& operator =(const SetAFC& a); 1150 /** 1151 * \brief Initialize for set variables \a x and decay factor \a d 1152 * 1153 * If several AFC objects are created for a space or its clones, 1154 * the AFC values are shared between spaces. If the values should 1155 * not be shared, \a share should be false. 1156 */ 1157 SetAFC(Home home, const SetVarArgs& x, double d=1.0, bool share=true); 1158 /** 1159 * \brief Initialize for set variables \a x with decay factor \a d 1160 * 1161 * This member function can only be used once and only if the 1162 * AFC storage has been constructed with the default constructor. 1163 * 1164 * If several AFC objects are created for a space or its clones, 1165 * the AFC values are shared between spaces. If the values should 1166 * not be shared, \a share should be false. 1167 */ 1168 void init(Home home, const SetVarArgs& x, double d=1.0, bool share=true); 1169 }; 1170 1171 } 1172 1173 #include <gecode/set/branch/afc.hpp> 1174 1175 namespace Gecode { 1176 1177 1178 /** 1179 * \brief Recording actions for set variables 1180 * 1181 * \ingroup TaskModelSetBranch 1182 */ 1183 class SetAction : public Action { 1184 public: 1185 /** 1186 * \brief Construct as not yet initialized 1187 * 1188 * The only member functions that can be used on a constructed but not 1189 * yet initialized action storage is init or the assignment operator. 1190 * 1191 */ 1192 SetAction(void); 1193 /// Copy constructor 1194 SetAction(const SetAction& a); 1195 /// Assignment operator 1196 SetAction& operator =(const SetAction& a); 1197 /** 1198 * \brief Initialize for set variables \a x with decay factor \a d 1199 * 1200 * Counts propagation if \a p is true and failure if \a f is true. 1201 * 1202 * If the branch merit function \a bm is different from nullptr, the 1203 * action for each variable is initialized with the merit returned 1204 * by \a bm. 1205 * 1206 */ 1207 GECODE_SET_EXPORT 1208 SetAction(Home home, const SetVarArgs& x, double d=1.0, 1209 bool p=true, bool f=true, 1210 SetBranchMerit bm=nullptr); 1211 /** 1212 * \brief Initialize for set variables \a x with decay factor \a d 1213 * 1214 * Counts propagation if \a p is true and failure if \a f is true. 1215 * 1216 * If the branch merit function \a bm is different from nullptr, the 1217 * action for each variable is initialized with the merit returned 1218 * by \a bm. 1219 * 1220 * This member function can only be used once and only if the 1221 * action storage has been constructed with the default constructor. 1222 * 1223 */ 1224 GECODE_SET_EXPORT void 1225 init(Home home, const SetVarArgs& x, double d=1.0, 1226 bool p=true, bool f=true, 1227 SetBranchMerit bm=nullptr); 1228 }; 1229 1230 } 1231 1232 #include <gecode/set/branch/action.hpp> 1233 1234 namespace Gecode { 1235 1236 /** 1237 * \brief Recording CHB for set variables 1238 * 1239 * \ingroup TaskModelSetBranch 1240 */ 1241 class SetCHB : public CHB { 1242 public: 1243 /** 1244 * \brief Construct as not yet initialized 1245 * 1246 * The only member functions that can be used on a constructed but not 1247 * yet initialized CHB storage is init or the assignment operator. 1248 * 1249 */ 1250 SetCHB(void); 1251 /// Copy constructor 1252 SetCHB(const SetCHB& chb); 1253 /// Assignment operator 1254 SetCHB& operator =(const SetCHB& chb); 1255 /** 1256 * \brief Initialize for set variables \a x 1257 * 1258 * If the branch merit function \a bm is different from nullptr, the 1259 * action for each variable is initialized with the merit returned 1260 * by \a bm. 1261 * 1262 */ 1263 GECODE_SET_EXPORT 1264 SetCHB(Home home, const SetVarArgs& x, SetBranchMerit bm=nullptr); 1265 /** 1266 * \brief Initialize for set variables \a x 1267 * 1268 * If the branch merit function \a bm is different from nullptr, the 1269 * action for each variable is initialized with the merit returned 1270 * by \a bm. 1271 * 1272 * This member function can only be used once and only if the 1273 * action storage has been constructed with the default constructor. 1274 * 1275 */ 1276 GECODE_SET_EXPORT void 1277 init(Home home, const SetVarArgs& x, SetBranchMerit bm=nullptr); 1278 }; 1279 1280 } 1281 1282 #include <gecode/set/branch/chb.hpp> 1283 1284 namespace Gecode { 1285 1286 /// Function type for printing branching alternatives for set variables 1287 typedef std::function<void(const Space &home, const Brancher& b, 1288 unsigned int a, 1289 SetVar x, int i, const int& n, 1290 std::ostream& o)> 1291 SetVarValPrint; 1292 1293 } 1294 1295 namespace Gecode { 1296 1297 /** 1298 * \brief Which variable to select for branching 1299 * 1300 * \ingroup TaskModelSetBranch 1301 */ 1302 class SetVarBranch : public VarBranch<SetVar> { 1303 public: 1304 /// Which variable selection 1305 enum Select { 1306 SEL_NONE = 0, ///< First unassigned 1307 SEL_RND, ///< Random (uniform, for tie breaking) 1308 SEL_MERIT_MIN, ///< With least merit 1309 SEL_MERIT_MAX, ///< With highest merit 1310 SEL_DEGREE_MIN, ///< With smallest degree 1311 SEL_DEGREE_MAX, ///< With largest degree 1312 SEL_AFC_MIN, ///< With smallest accumulated failure count 1313 SEL_AFC_MAX, ///< With largest accumulated failure count 1314 SEL_ACTION_MIN, ///< With lowest action 1315 SEL_ACTION_MAX, ///< With highest action 1316 SEL_CHB_MIN, ///< With lowest CHB Q-score 1317 SEL_CHB_MAX, ///< With highest CHB Q-score 1318 SEL_MIN_MIN, ///< With smallest minimum unknown element 1319 SEL_MIN_MAX, ///< With largest minimum unknown element 1320 SEL_MAX_MIN, ///< With smallest maximum unknown element 1321 SEL_MAX_MAX, ///< With largest maximum unknown element 1322 SEL_SIZE_MIN, ///< With smallest unknown set 1323 SEL_SIZE_MAX, ///< With largest unknown set 1324 SEL_DEGREE_SIZE_MIN, ///< With smallest degree divided by domain size 1325 SEL_DEGREE_SIZE_MAX, ///< With largest degree divided by domain size 1326 SEL_AFC_SIZE_MIN, ///< With smallest accumulated failure count divided by domain size 1327 SEL_AFC_SIZE_MAX, ///< With largest accumulated failure count divided by domain size 1328 SEL_ACTION_SIZE_MIN, ///< With smallest action divided by domain size 1329 SEL_ACTION_SIZE_MAX, ///< With largest action divided by domain size 1330 SEL_CHB_SIZE_MIN, ///< With smallest CHB Q-score divided by domain size 1331 SEL_CHB_SIZE_MAX ///< With largest CHB Q-score divided by domain size 1332 }; 1333 protected: 1334 /// Which variable to select 1335 Select s; 1336 public: 1337 /// Initialize with strategy SEL_NONE 1338 SetVarBranch(void); 1339 /// Initialize with random number generator \a r 1340 SetVarBranch(Rnd r); 1341 /// Initialize with selection strategy \a s and tie-break limit function \a t 1342 SetVarBranch(Select s, BranchTbl t); 1343 /// Initialize with selection strategy \a s, decay factor \a d, and tie-break limit function \a t 1344 SetVarBranch(Select s, double d, BranchTbl t); 1345 /// Initialize with selection strategy \a s, afc \a a, and tie-break limit function \a t 1346 SetVarBranch(Select s, SetAFC a, BranchTbl t); 1347 /// Initialize with selection strategy \a s, action \a a, and tie-break limit function \a t 1348 SetVarBranch(Select s, SetAction a, BranchTbl t); 1349 /// Initialize with selection strategy \a s, CHB \a c, and tie-break limit function \a t 1350 SetVarBranch(Select s, SetCHB c, BranchTbl t); 1351 /// Initialize with selection strategy \a s, branch merit function \a mf, and tie-break limit function \a t 1352 SetVarBranch(Select s, SetBranchMerit mf, BranchTbl t); 1353 /// Return selection strategy 1354 Select select(void) const; 1355 /// Expand AFC, action, and CHB 1356 void expand(Home home, const SetVarArgs& x); 1357 }; 1358 1359 /** 1360 * \defgroup TaskModelSetBranchVar Selecting set variables 1361 * \ingroup TaskModelSetBranch 1362 */ 1363 //@{ 1364 /// Select first unassigned variable 1365 SetVarBranch SET_VAR_NONE(void); 1366 /// Select random variable (uniform distribution, for tie breaking) 1367 SetVarBranch SET_VAR_RND(Rnd r); 1368 /// Select variable with least merit according to branch merit function \a bm 1369 SetVarBranch SET_VAR_MERIT_MIN(SetBranchMerit bm, BranchTbl tbl=nullptr); 1370 /// Select variable with highest merit according to branch merit function \a bm 1371 SetVarBranch SET_VAR_MERIT_MAX(SetBranchMerit bm, BranchTbl tbl=nullptr); 1372 /// Select variable with smallest degree 1373 SetVarBranch SET_VAR_DEGREE_MIN(BranchTbl tbl=nullptr); 1374 /// Select variable with largest degree 1375 SetVarBranch SET_VAR_DEGREE_MAX(BranchTbl tbl=nullptr); 1376 /// Select variable with smallest accumulated failure count with decay factor \a d 1377 SetVarBranch SET_VAR_AFC_MIN(double d=1.0, BranchTbl tbl=nullptr); 1378 /// Select variable with smallest accumulated failure count 1379 SetVarBranch SET_VAR_AFC_MIN(SetAFC a, BranchTbl tbl=nullptr); 1380 /// Select variable with largest accumulated failure count with decay factor \a d 1381 SetVarBranch SET_VAR_AFC_MAX(double d=1.0, BranchTbl tbl=nullptr); 1382 /// Select variable with largest accumulated failure count 1383 SetVarBranch SET_VAR_AFC_MAX(SetAFC a, BranchTbl tbl=nullptr); 1384 /// Select variable with lowest action with decay factor \a d 1385 SetVarBranch SET_VAR_ACTION_MIN(double d=1.0, BranchTbl tbl=nullptr); 1386 /// Select variable with lowest action 1387 SetVarBranch SET_VAR_ACTION_MIN(SetAction a, BranchTbl tbl=nullptr); 1388 /// Select variable with highest action with decay factor \a d 1389 SetVarBranch SET_VAR_ACTION_MAX(double d=1.0, BranchTbl tbl=nullptr); 1390 /// Select variable with highest action 1391 SetVarBranch SET_VAR_ACTION_MAX(SetAction a, BranchTbl tbl=nullptr); 1392 /// Select variable with lowest CHB Q-score 1393 SetVarBranch SET_VAR_CHB_MIN(BranchTbl tbl=nullptr); 1394 /// Select variable with lowest CHB Q-score 1395 SetVarBranch SET_VAR_CHB_MIN(SetCHB c, BranchTbl tbl=nullptr); 1396 /// Select variable with highest CHB Q-score 1397 SetVarBranch SET_VAR_CHB_MAX(BranchTbl tbl=nullptr); 1398 /// Select variable with highest CHB Q-score 1399 SetVarBranch SET_VAR_CHB_MAX(SetCHB c, BranchTbl tbl=nullptr); 1400 /// Select variable with smallest minimum unknown element 1401 SetVarBranch SET_VAR_MIN_MIN(BranchTbl tbl=nullptr); 1402 /// Select variable with largest minimum unknown element 1403 SetVarBranch SET_VAR_MIN_MAX(BranchTbl tbl=nullptr); 1404 /// Select variable with smallest maximum unknown element 1405 SetVarBranch SET_VAR_MAX_MIN(BranchTbl tbl=nullptr); 1406 /// Select variable with largest maximum unknown element 1407 SetVarBranch SET_VAR_MAX_MAX(BranchTbl tbl=nullptr); 1408 /// Select variable with smallest unknown set 1409 SetVarBranch SET_VAR_SIZE_MIN(BranchTbl tbl=nullptr); 1410 /// Select variable with largest unknown set 1411 SetVarBranch SET_VAR_SIZE_MAX(BranchTbl tbl=nullptr); 1412 /// Select variable with smallest degree divided by domain size 1413 SetVarBranch SET_VAR_DEGREE_SIZE_MIN(BranchTbl tbl=nullptr); 1414 /// Select variable with largest degree divided by domain size 1415 SetVarBranch SET_VAR_DEGREE_SIZE_MAX(BranchTbl tbl=nullptr); 1416 /// Select variable with smallest accumulated failure count divided by domain size with decay factor \a d 1417 SetVarBranch SET_VAR_AFC_SIZE_MIN(double d=1.0, BranchTbl tbl=nullptr); 1418 /// Select variable with smallest accumulated failure count divided by domain size 1419 SetVarBranch SET_VAR_AFC_SIZE_MIN(SetAFC a, BranchTbl tbl=nullptr); 1420 /// Select variable with largest accumulated failure count divided by domain size with decay factor \a d 1421 SetVarBranch SET_VAR_AFC_SIZE_MAX(double d=1.0, BranchTbl tbl=nullptr); 1422 /// Select variable with largest accumulated failure count divided by domain size 1423 SetVarBranch SET_VAR_AFC_SIZE_MAX(SetAFC a, BranchTbl tbl=nullptr); 1424 /// Select variable with smallest action divided by domain size with decay factor \a d 1425 SetVarBranch SET_VAR_ACTION_SIZE_MIN(double d=1.0, BranchTbl tbl=nullptr); 1426 /// Select variable with smallest action divided by domain size 1427 SetVarBranch SET_VAR_ACTION_SIZE_MIN(SetAction a, BranchTbl tbl=nullptr); 1428 /// Select variable with largest action divided by domain size with decay factor \a d 1429 SetVarBranch SET_VAR_ACTION_SIZE_MAX(double d=1.0, BranchTbl tbl=nullptr); 1430 /// Select variable with largest action divided by domain size 1431 SetVarBranch SET_VAR_ACTION_SIZE_MAX(SetAction a, BranchTbl tbl=nullptr); 1432 /// Select variable with smallest CHB Q-score divided by domain size 1433 SetVarBranch SET_VAR_CHB_SIZE_MIN(BranchTbl tbl=nullptr); 1434 /// Select variable with smallest CHB Q-score divided by domain size 1435 SetVarBranch SET_VAR_CHB_SIZE_MIN(SetCHB c, BranchTbl tbl=nullptr); 1436 /// Select variable with largest CHB Q-score divided by domain size 1437 SetVarBranch SET_VAR_CHB_SIZE_MAX(BranchTbl tbl=nullptr); 1438 /// Select variable with largest CHB Q-score divided by domain size 1439 SetVarBranch SET_VAR_CHB_SIZE_MAX(SetCHB c, BranchTbl tbl=nullptr); 1440 //@} 1441 1442 } 1443 1444 #include <gecode/set/branch/var.hpp> 1445 1446 namespace Gecode { 1447 1448 /** 1449 * \brief Which values to select for branching first 1450 * 1451 * \ingroup TaskModelSetBranch 1452 */ 1453 class SetValBranch : public ValBranch<SetVar> { 1454 public: 1455 /// Which value selection 1456 enum Select { 1457 SEL_MIN_INC, ///< Include smallest element 1458 SEL_MIN_EXC, ///< Exclude smallest element 1459 SEL_MED_INC, ///< Include median element (rounding downwards) 1460 SEL_MED_EXC, ///< Exclude median element (rounding downwards) 1461 SEL_MAX_INC, ///< Include largest element 1462 SEL_MAX_EXC, ///< Exclude largest element 1463 SEL_RND_INC, ///< Include random element 1464 SEL_RND_EXC, ///< Exclude random element 1465 SEL_VAL_COMMIT ///< Select value according to user-defined functions 1466 }; 1467 protected: 1468 /// Which value to select 1469 Select s; 1470 public: 1471 /// Initialize with selection strategy \a s 1472 SetValBranch(Select s = SEL_MIN_INC); 1473 /// Initialize with random number generator \a r 1474 SetValBranch(Select s, Rnd r); 1475 /// Initialize with value function \a f and commit function \a c 1476 SetValBranch(SetBranchVal v, SetBranchCommit c); 1477 /// Return selection strategy 1478 Select select(void) const; 1479 }; 1480 1481 /** 1482 * \defgroup TaskModelSetBranchVal Value selection for set variables 1483 * \ingroup TaskModelSetBranch 1484 */ 1485 //@{ 1486 /// Include smallest element 1487 SetValBranch SET_VAL_MIN_INC(void); 1488 /// Exclude smallest element 1489 SetValBranch SET_VAL_MIN_EXC(void); 1490 /// Include median element (rounding downwards) 1491 SetValBranch SET_VAL_MED_INC(void); 1492 /// Exclude median element (rounding downwards) 1493 SetValBranch SET_VAL_MED_EXC(void); 1494 /// Include largest element 1495 SetValBranch SET_VAL_MAX_INC(void); 1496 /// Exclude largest element 1497 SetValBranch SET_VAL_MAX_EXC(void); 1498 /// Include random element 1499 SetValBranch SET_VAL_RND_INC(Rnd r); 1500 /// Exclude random element 1501 SetValBranch SET_VAL_RND_EXC(Rnd r); 1502 /** 1503 * \brief Select value as defined by the value function \a v and commit function \a c 1504 * 1505 * The default commit function posts the constraint that the value \a n 1506 * must be included in the set variable \a x for the first alternative, 1507 * and that \a n must be excluded from \a x otherwise. 1508 */ 1509 SetValBranch SET_VAL(SetBranchVal v, SetBranchCommit c=nullptr); 1510 //@} 1511 1512 } 1513 1514 #include <gecode/set/branch/val.hpp> 1515 1516 namespace Gecode { 1517 1518 /** 1519 * \brief Which value to select for assignment 1520 * 1521 * \ingroup TaskModelSetBranch 1522 */ 1523 class SetAssign : public ValBranch<SetVar> { 1524 public: 1525 /// Which value selection 1526 enum Select { 1527 SEL_MIN_INC, ///< Include smallest element 1528 SEL_MIN_EXC, ///< Exclude smallest element 1529 SEL_MED_INC, ///< Include median element (rounding downwards) 1530 SEL_MED_EXC, ///< Exclude median element (rounding downwards) 1531 SEL_MAX_INC, ///< Include largest element 1532 SEL_MAX_EXC, ///< Exclude largest element 1533 SEL_RND_INC, ///< Include random element 1534 SEL_RND_EXC, ///< Exclude random element 1535 SEL_VAL_COMMIT ///< Select value according to user-defined functions 1536 }; 1537 protected: 1538 /// Which value to select 1539 Select s; 1540 public: 1541 /// Initialize with selection strategy \a s 1542 SetAssign(Select s = SEL_MIN_INC); 1543 /// Initialize with random number generator \a r 1544 SetAssign(Select s, Rnd r); 1545 /// Initialize with value function \a f and commit function \a c 1546 SetAssign(SetBranchVal v, SetBranchCommit c); 1547 /// Return selection strategy 1548 Select select(void) const; 1549 }; 1550 1551 /** 1552 * \defgroup TaskModelSetBranchAssign Assigning set variables 1553 * \ingroup TaskModelSetBranch 1554 */ 1555 //@{ 1556 /// Include smallest element 1557 SetAssign SET_ASSIGN_MIN_INC(void); 1558 /// Exclude smallest element 1559 SetAssign SET_ASSIGN_MIN_EXC(void); 1560 /// Include median element (rounding downwards) 1561 SetAssign SET_ASSIGN_MED_INC(void); 1562 /// Exclude median element (rounding downwards) 1563 SetAssign SET_ASSIGN_MED_EXC(void); 1564 /// Include largest element 1565 SetAssign SET_ASSIGN_MAX_INC(void); 1566 /// Exclude largest element 1567 SetAssign SET_ASSIGN_MAX_EXC(void); 1568 /// Include random element 1569 SetAssign SET_ASSIGN_RND_INC(Rnd r); 1570 /// Exclude random element 1571 SetAssign SET_ASSIGN_RND_EXC(Rnd r); 1572 /** 1573 * \brief Select value as defined by the value function \a v and commit function \a c 1574 * 1575 * The default commit function posts the constraint that the value \a n 1576 * must be included in the set variable \a x. 1577 */ 1578 SetAssign SET_ASSIGN(SetBranchVal v, SetBranchCommit c=nullptr); 1579 //@} 1580 1581 } 1582 1583 #include <gecode/set/branch/assign.hpp> 1584 1585 namespace Gecode { 1586 1587 /** 1588 * \brief Branch over \a x with variable selection \a vars and value selection \a vals 1589 * 1590 * \ingroup TaskModelSetBranch 1591 */ 1592 GECODE_SET_EXPORT void 1593 branch(Home home, const SetVarArgs& x, 1594 SetVarBranch vars, SetValBranch vals, 1595 SetBranchFilter bf=nullptr, 1596 SetVarValPrint vvp=nullptr); 1597 /** 1598 * \brief Branch over \a x with tie-breaking variable selection \a vars and value selection \a vals 1599 * 1600 * \ingroup TaskModelSetBranch 1601 */ 1602 GECODE_SET_EXPORT void 1603 branch(Home home, const SetVarArgs& x, 1604 TieBreak<SetVarBranch> vars, SetValBranch vals, 1605 SetBranchFilter bf=nullptr, 1606 SetVarValPrint vvp=nullptr); 1607 /** 1608 * \brief Branch over \a x with value selection \a vals 1609 * 1610 * \ingroup TaskModelSetBranch 1611 */ 1612 GECODE_SET_EXPORT void 1613 branch(Home home, SetVar x, SetValBranch vals, 1614 SetVarValPrint vvp=nullptr); 1615 1616 /** 1617 * \brief Assign all \a x with variable selection \a vars and value selection \a vals 1618 * 1619 * \ingroup TaskModelSetBranch 1620 */ 1621 GECODE_SET_EXPORT void 1622 assign(Home home, const SetVarArgs& x, 1623 SetVarBranch vars, SetAssign vals, 1624 SetBranchFilter bf=nullptr, 1625 SetVarValPrint vvp=nullptr); 1626 /** 1627 * \brief Assign all \a x with tie-breaking variable selection \a vars and value selection \a vals 1628 * 1629 * \ingroup TaskModelSetBranch 1630 */ 1631 GECODE_SET_EXPORT void 1632 assign(Home home, const SetVarArgs& x, 1633 TieBreak<SetVarBranch> vars, SetAssign vals, 1634 SetBranchFilter bf=nullptr, 1635 SetVarValPrint vvp=nullptr); 1636 /** 1637 * \brief Assign \a x with value selection \a vals 1638 * 1639 * \ingroup TaskModelSetBranch 1640 */ 1641 GECODE_SET_EXPORT void 1642 assign(Home home, SetVar x, SetAssign vals, 1643 SetVarValPrint vvp=nullptr); 1644 1645 } 1646 1647 namespace Gecode { 1648 1649 /** 1650 * \brief Branch over \a x with value selection \a vals 1651 * 1652 * \ingroup TaskModelSetBranch 1653 */ 1654 void 1655 branch(Home home, const SetVarArgs& x, 1656 SetValBranch vals, 1657 SetBranchFilter bf=nullptr, 1658 SetVarValPrint vvp=nullptr); 1659 1660 /** 1661 * \brief Assign all \a x with value selection \a vals 1662 * 1663 * \ingroup TaskModelSetBranch 1664 */ 1665 void 1666 assign(Home home, const SetVarArgs& x, 1667 SetAssign vals, 1668 SetBranchFilter bf=nullptr, 1669 SetVarValPrint vvp=nullptr); 1670 1671 } 1672 1673 #include <gecode/set/branch.hpp> 1674 1675 // LDSB-related declarations. 1676 namespace Gecode { 1677 /// Variables in \a x are interchangeable 1678 GECODE_SET_EXPORT SymmetryHandle VariableSymmetry(const SetVarArgs& x); 1679 /** 1680 * \brief Variable sequences in \a x of size \a ss are interchangeable 1681 * 1682 * The size of \a x must be a multiple of \a ss. 1683 */ 1684 GECODE_SET_EXPORT 1685 SymmetryHandle VariableSequenceSymmetry(const SetVarArgs& x, int ss); 1686 /** 1687 * \brief Branch over \a x with variable selection \a vars and value 1688 * selection \a vals with symmetry breaking 1689 * 1690 * \ingroup TaskModelSetBranch 1691 */ 1692 GECODE_SET_EXPORT void 1693 branch(Home home, const SetVarArgs& x, 1694 SetVarBranch vars, SetValBranch vals, 1695 const Symmetries& syms, 1696 SetBranchFilter bf=nullptr, 1697 SetVarValPrint vvp=nullptr); 1698 /** 1699 * \brief Branch over \a x with tie-breaking variable selection \a 1700 * vars and value selection \a vals with symmetry breaking 1701 * 1702 * \ingroup TaskModelSetBranch 1703 */ 1704 GECODE_SET_EXPORT void 1705 branch(Home home, const SetVarArgs& x, 1706 TieBreak<SetVarBranch> vars, SetValBranch vals, 1707 const Symmetries& syms, 1708 SetBranchFilter bf=nullptr, 1709 SetVarValPrint vvp=nullptr); 1710 } 1711 1712 namespace Gecode { 1713 1714 /* 1715 * \brief Relaxed assignment of variables in \a x from values in \a sx 1716 * 1717 * The variables in \a x are assigned values from the assigned variables 1718 * in the solution \a sx with a relaxation probability \a p. That is, 1719 * if \f$p=0.1\f$ approximately 10% of the variables in \a x will be 1720 * assigned a value from \a sx. 1721 * 1722 * The random numbers are generated from the generator \a r. At least 1723 * one variable will not be assigned: in case the relaxation attempt 1724 * would suggest that all variables should be assigned, a single 1725 * variable will be selected randomly to remain unassigned. 1726 * 1727 * Throws an exception of type Set::ArgumentSizeMismatch, if \a x and 1728 * \a sx are of different size. 1729 * 1730 * Throws an exception of type Set::OutOfLimits, if \a p is not between 1731 * \a 0.0 and \a 1.0. 1732 * 1733 * \ingroup TaskModeSet 1734 */ 1735 GECODE_SET_EXPORT void 1736 relax(Home home, const SetVarArgs& x, const SetVarArgs& sx, 1737 Rnd r, double p); 1738 1739 } 1740 1741 #include <gecode/set/trace/trace-view.hpp> 1742 1743 namespace Gecode { 1744 1745 /** 1746 * \defgroup TaskSetTrace Tracing for set variables 1747 * \ingroup TaskTrace 1748 */ 1749 1750 /** 1751 * \brief Trace delta information for set variables 1752 * \ingroup TaskSetTrace 1753 */ 1754 class SetTraceDelta { 1755 protected: 1756 /// 1757 public: 1758 /// Delta for the greatest lower bound 1759 class Glb 1760 : public Iter::Ranges::Diff<Set::GlbRanges<Set::SetView>, 1761 Iter::Ranges::RangeList> { 1762 protected: 1763 /// Iterator over old glb 1764 Iter::Ranges::RangeList o; 1765 /// Iterator over new glb 1766 Set::GlbRanges<Set::SetView> n; 1767 public: 1768 /// \name Constructors and initialization 1769 //@{ 1770 /// Initialize with old glb and new glb 1771 Glb(RangeList* o, Set::SetView n); 1772 //@} 1773 }; 1774 Glb _glb; 1775 /// Delta for the least upper bound 1776 class Lub 1777 : public Iter::Ranges::Diff<Iter::Ranges::RangeList, 1778 Set::LubRanges<Set::SetView> > { 1779 protected: 1780 /// Iterator over old lub 1781 Iter::Ranges::RangeList o; 1782 /// Iterator over new lub 1783 Set::LubRanges<Set::SetView> n; 1784 public: 1785 /// \name Constructors and initialization 1786 //@{ 1787 /// Initialize with old lub \a o and new lub \a n 1788 Lub(RangeList* o, Set::SetView n); 1789 //@} 1790 }; 1791 Lub _lub; 1792 /// \name Constructor 1793 //@{ 1794 /// Initialize with old trace view \a o, new view \a n, and delta \a d 1795 SetTraceDelta(Set::SetTraceView o, Set::SetView n, const Delta& d); 1796 //@} 1797 /// \name Access to delta iterators 1798 //@{ 1799 /// Give access to iterator for delta in greatest lower bound (values that have been included) 1800 Glb& glb(void); 1801 /// Give access iterator for delta in leat bound (values that have been removed) 1802 Lub& lub(void); 1803 //@} 1804 }; 1805 1806 } 1807 1808 #include <gecode/set/trace/delta.hpp> 1809 1810 #include <gecode/set/trace/traits.hpp> 1811 1812 namespace Gecode { 1813 1814 /** 1815 * \brief Tracer for set variables 1816 * \ingroup TaskSetTrace 1817 */ 1818 typedef ViewTracer<Set::SetView> SetTracer; 1819 /** 1820 * \brief Trace recorder for set variables 1821 * \ingroup TaskSetTrace 1822 */ 1823 typedef ViewTraceRecorder<Set::SetView> SetTraceRecorder; 1824 1825 /** 1826 * \brief Standard set variable tracer 1827 * \ingroup TaskSetTrace 1828 */ 1829 class GECODE_SET_EXPORT StdSetTracer : public SetTracer { 1830 protected: 1831 /// Output stream to use 1832 std::ostream& os; 1833 public: 1834 /// Initialize with output stream \a os0 1835 StdSetTracer(std::ostream& os0 = std::cerr); 1836 /// Print init information 1837 virtual void init(const Space& home, const SetTraceRecorder& t); 1838 /// Print prune information 1839 virtual void prune(const Space& home, const SetTraceRecorder& t, 1840 const ViewTraceInfo& vti, int i, SetTraceDelta& d); 1841 /// Print fixpoint information 1842 virtual void fix(const Space& home, const SetTraceRecorder& t); 1843 /// Print failure information 1844 virtual void fail(const Space& home, const SetTraceRecorder& t); 1845 /// Print that trace recorder is done 1846 virtual void done(const Space& home, const SetTraceRecorder& t); 1847 /// Default tracer (printing to std::cerr) 1848 static StdSetTracer def; 1849 }; 1850 1851 1852 /** 1853 * \brief Create a tracer for set variables 1854 * \ingroup TaskSetTrace 1855 */ 1856 GECODE_SET_EXPORT void 1857 trace(Home home, const SetVarArgs& x, 1858 TraceFilter tf, 1859 int te = (TE_INIT | TE_PRUNE | TE_FIX | TE_FAIL | TE_DONE), 1860 SetTracer& t = StdSetTracer::def); 1861 /** 1862 * \brief Create a tracer for set variables 1863 * \ingroup TaskSetTrace 1864 */ 1865 void 1866 trace(Home home, const SetVarArgs& x, 1867 int te = (TE_INIT | TE_PRUNE | TE_FIX | TE_FAIL | TE_DONE), 1868 SetTracer& t = StdSetTracer::def); 1869 1870 } 1871 1872 #include <gecode/set/trace.hpp> 1873 1874 #endif 1875 1876 // IFDEF: GECODE_HAS_SET_VARS 1877 // STATISTICS: set-post 1878