int.hh
Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 00002 /* 00003 * Main authors: 00004 * Christian Schulte <schulte@gecode.org> 00005 * Guido Tack <tack@gecode.org> 00006 * 00007 * Contributing authors: 00008 * Mikael Lagerkvist <lagerkvist@gecode.org> 00009 * David Rijsman <David.Rijsman@quintiq.com> 00010 * 00011 * Copyright: 00012 * David Rijsman, 2009 00013 * Mikael Lagerkvist, 2006 00014 * Christian Schulte, 2002 00015 * Guido Tack, 2004 00016 * 00017 * Last modified: 00018 * $Date: 2010-10-06 23:20:35 +0200 (Wed, 06 Oct 2010) $ by $Author: schulte $ 00019 * $Revision: 11468 $ 00020 * 00021 * This file is part of Gecode, the generic constraint 00022 * development environment: 00023 * http://www.gecode.org 00024 * 00025 * Permission is hereby granted, free of charge, to any person obtaining 00026 * a copy of this software and associated documentation files (the 00027 * "Software"), to deal in the Software without restriction, including 00028 * without limitation the rights to use, copy, modify, merge, publish, 00029 * distribute, sublicense, and/or sell copies of the Software, and to 00030 * permit persons to whom the Software is furnished to do so, subject to 00031 * the following conditions: 00032 * 00033 * The above copyright notice and this permission notice shall be 00034 * included in all copies or substantial portions of the Software. 00035 * 00036 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00037 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00038 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00039 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00040 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00041 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00042 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00043 * 00044 */ 00045 00046 #ifndef __GECODE_INT_HH__ 00047 #define __GECODE_INT_HH__ 00048 00049 #include <climits> 00050 #include <cfloat> 00051 #include <iostream> 00052 00053 #include <vector> 00054 00055 #include <gecode/kernel.hh> 00056 #include <gecode/iter.hh> 00057 00058 /* 00059 * Configure linking 00060 * 00061 */ 00062 #if !defined(GECODE_STATIC_LIBS) && \ 00063 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER)) 00064 00065 #ifdef GECODE_BUILD_INT 00066 #define GECODE_INT_EXPORT __declspec( dllexport ) 00067 #else 00068 #define GECODE_INT_EXPORT __declspec( dllimport ) 00069 #endif 00070 00071 #else 00072 00073 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY 00074 #define GECODE_INT_EXPORT __attribute__ ((visibility("default"))) 00075 #else 00076 #define GECODE_INT_EXPORT 00077 #endif 00078 00079 #endif 00080 00081 // Configure auto-linking 00082 #ifndef GECODE_BUILD_INT 00083 #define GECODE_LIBRARY_NAME "Int" 00084 #include <gecode/support/auto-link.hpp> 00085 #endif 00086 00098 #include <gecode/int/exception.hpp> 00099 00100 namespace Gecode { namespace Int { 00101 00109 namespace Limits { 00111 const int max = INT_MAX - 1; 00113 const int min = -max; 00115 const int infinity = max + 1; 00117 bool valid(int n); 00119 bool valid(double n); 00121 void check(int n, const char* l); 00123 void check(double n, const char* l); 00125 void positive(int n, const char* l); 00127 void positive(double n, const char* l); 00129 void nonnegative(int n, const char* l); 00131 void nonnegative(double n, const char* l); 00133 const double double_max = 9007199254740991.0; 00135 const double double_min = -9007199254740991.0; 00137 void double_check(double n, const char* l); 00139 const double double_infinity = DBL_MAX; 00140 } 00141 00142 }} 00143 00144 #include <gecode/int/limits.hpp> 00145 00146 namespace Gecode { 00147 00148 class IntSetRanges; 00149 00157 class IntSet : public SharedHandle { 00158 friend class IntSetRanges; 00159 private: 00161 class Range { 00162 public: 00163 int min, max; 00164 }; 00165 class IntSetObject : public SharedHandle::Object { 00166 public: 00168 unsigned int size; 00170 int n; 00172 Range* r; 00174 GECODE_INT_EXPORT static IntSetObject* allocate(int m); 00176 GECODE_INT_EXPORT SharedHandle::Object* copy(void) const; 00178 GECODE_INT_EXPORT bool in(int n) const; 00180 GECODE_INT_EXPORT virtual ~IntSetObject(void); 00181 }; 00183 class MinInc; 00185 GECODE_INT_EXPORT void normalize(Range* r, int n); 00187 GECODE_INT_EXPORT void init(int n, int m); 00189 GECODE_INT_EXPORT void init(const int r[], int n); 00191 GECODE_INT_EXPORT void init(const int r[][2], int n); 00192 public: 00194 00195 00196 IntSet(void); 00201 IntSet(int n, int m); 00203 IntSet(const int r[], int n); 00209 IntSet(const int r[][2], int n); 00211 template<class I> 00212 explicit IntSet(I& i); 00213 #ifdef __INTEL_COMPILER 00214 00215 IntSet(const IntSet& s); 00217 IntSet(IntSet& s); 00219 IntSet(const PrimArgArray<int>& i); 00221 IntSet(PrimArgArray<int>& i); 00222 #endif 00223 00224 00226 00227 00228 int ranges(void) const; 00230 int min(int i) const; 00232 int max(int i) const; 00234 unsigned int width(int i) const; 00236 00238 00239 00240 bool in(int n) const; 00242 unsigned int size(void) const; 00244 unsigned int width(void) const; 00246 int min(void) const; 00248 int max(void) const; 00250 00252 00253 00254 GECODE_INT_EXPORT static const IntSet empty; 00256 }; 00257 00263 class IntSetRanges { 00264 private: 00266 const IntSet::Range* i; 00268 const IntSet::Range* e; 00269 public: 00271 00272 00273 IntSetRanges(void); 00275 IntSetRanges(const IntSet& s); 00277 void init(const IntSet& s); 00279 00281 00282 00283 bool operator ()(void) const; 00285 void operator ++(void); 00287 00289 00290 00291 int min(void) const; 00293 int max(void) const; 00295 unsigned int width(void) const; 00297 }; 00298 00304 class IntSetValues : public Iter::Ranges::ToValues<IntSetRanges> { 00305 public: 00307 00308 00309 IntSetValues(void); 00311 IntSetValues(const IntSet& s); 00313 void init(const IntSet& s); 00315 }; 00316 00321 template<class Char, class Traits> 00322 std::basic_ostream<Char,Traits>& 00323 operator <<(std::basic_ostream<Char,Traits>& os, const IntSet& s); 00324 00325 } 00326 00327 #include <gecode/int/int-set-1.hpp> 00328 00329 #include <gecode/int/var-imp.hpp> 00330 00331 namespace Gecode { 00332 00333 namespace Int { 00334 class IntView; 00335 } 00336 00342 class IntVar : public VarImpVar<Int::IntVarImp> { 00343 friend class IntVarArray; 00344 friend class IntVarArgs; 00345 private: 00346 using VarImpVar<Int::IntVarImp>::x; 00353 void _init(Space& home, int min, int max); 00360 void _init(Space& home, const IntSet& d); 00361 public: 00363 00364 00365 IntVar(void); 00367 IntVar(const IntVar& y); 00369 IntVar(const Int::IntView& y); 00381 GECODE_INT_EXPORT IntVar(Space& home, int min, int max); 00393 GECODE_INT_EXPORT IntVar(Space& home, const IntSet& d); 00395 00397 00398 00399 int min(void) const; 00401 int max(void) const; 00403 int med(void) const; 00411 int val(void) const; 00412 00414 unsigned int size(void) const; 00416 unsigned int width(void) const; 00418 unsigned int regret_min(void) const; 00420 unsigned int regret_max(void) const; 00422 00424 00425 00426 bool range(void) const; 00428 bool in(int n) const; 00430 }; 00431 00436 template<class Char, class Traits> 00437 std::basic_ostream<Char,Traits>& 00438 operator <<(std::basic_ostream<Char,Traits>& os, const IntVar& x); 00439 00444 class IntVarRanges : public Int::IntVarImpFwd { 00445 public: 00447 00448 00449 IntVarRanges(void); 00451 IntVarRanges(const IntVar& x); 00453 void init(const IntVar& x); 00455 }; 00456 00461 class IntVarValues : public Iter::Ranges::ToValues<IntVarRanges> { 00462 public: 00464 00465 00466 IntVarValues(void); 00468 IntVarValues(const IntVar& x); 00470 void init(const IntVar& x); 00472 }; 00473 00474 namespace Int { 00475 class BoolView; 00476 } 00477 00483 class BoolVar : public VarImpVar<Int::BoolVarImp> { 00484 friend class BoolVarArray; 00485 friend class BoolVarArgs; 00486 private: 00487 using VarImpVar<Int::BoolVarImp>::x; 00494 void _init(Space& home, int min, int max); 00495 public: 00497 00498 00499 BoolVar(void); 00501 BoolVar(const BoolVar& y); 00503 BoolVar(const Int::BoolView& y); 00515 GECODE_INT_EXPORT BoolVar(Space& home, int min, int max); 00517 00519 00520 00521 int min(void) const; 00523 int max(void) const; 00525 int med(void) const; 00533 int val(void) const; 00534 00536 unsigned int size(void) const; 00538 unsigned int width(void) const; 00540 unsigned int regret_min(void) const; 00542 unsigned int regret_max(void) const; 00544 00546 00547 00548 bool range(void) const; 00550 bool in(int n) const; 00552 00554 00555 00556 bool zero(void) const; 00558 bool one(void) const; 00560 bool none(void) const; 00562 }; 00563 00568 template<class Char, class Traits> 00569 std::basic_ostream<Char,Traits>& 00570 operator <<(std::basic_ostream<Char,Traits>& os, const BoolVar& x); 00571 00572 } 00573 00574 00575 #include <gecode/int/view.hpp> 00576 #include <gecode/int/propagator.hpp> 00577 00578 namespace Gecode { 00579 00589 00590 typedef ArgArray<IntSet> IntSetArgs; 00591 00592 } 00593 00594 #include <gecode/int/array-traits.hpp> 00595 00596 namespace Gecode { 00597 00599 class IntArgs : public PrimArgArray<int> { 00600 public: 00602 00603 00604 IntArgs(void); 00606 explicit IntArgs(int n); 00608 IntArgs(const SharedArray<int>& x); 00610 IntArgs(const std::vector<int>& x); 00612 GECODE_INT_EXPORT 00613 IntArgs(int n, int e0, ...); 00615 IntArgs(int n, const int* e); 00617 IntArgs(const PrimArgArray<int>& a); 00618 00620 static IntArgs create(int n, int start, int inc=1); 00622 }; 00623 00625 class IntVarArgs : public VarArgArray<IntVar> { 00626 public: 00628 00629 00630 IntVarArgs(void) {} 00632 explicit IntVarArgs(int n) : VarArgArray<IntVar>(n) {} 00634 IntVarArgs(const IntVarArgs& a) : VarArgArray<IntVar>(a) {} 00636 IntVarArgs(const VarArray<IntVar>& a) : VarArgArray<IntVar>(a) {} 00648 GECODE_INT_EXPORT 00649 IntVarArgs(Space& home, int n, int min, int max); 00661 GECODE_INT_EXPORT 00662 IntVarArgs(Space& home, int n, const IntSet& s); 00664 }; 00673 class BoolVarArgs : public VarArgArray<BoolVar> { 00674 public: 00676 00677 00678 BoolVarArgs(void) {} 00680 explicit BoolVarArgs(int n) : VarArgArray<BoolVar>(n) {} 00682 BoolVarArgs(const BoolVarArgs& a) : VarArgArray<BoolVar>(a) {} 00684 BoolVarArgs(const VarArray<BoolVar>& a) 00685 : VarArgArray<BoolVar>(a) {} 00697 GECODE_INT_EXPORT 00698 BoolVarArgs(Space& home, int n, int min, int max); 00700 }; 00702 00718 class IntVarArray : public VarArray<IntVar> { 00719 public: 00721 00722 00723 IntVarArray(void); 00725 IntVarArray(Space& home, int n); 00727 IntVarArray(const IntVarArray& a); 00729 IntVarArray(Space& home, const IntVarArgs& a); 00741 GECODE_INT_EXPORT 00742 IntVarArray(Space& home, int n, int min, int max); 00754 GECODE_INT_EXPORT 00755 IntVarArray(Space& home, int n, const IntSet& s); 00757 }; 00758 00763 class BoolVarArray : public VarArray<BoolVar> { 00764 public: 00766 00767 00768 BoolVarArray(void); 00770 BoolVarArray(Space& home, int n); 00772 BoolVarArray(const BoolVarArray& a); 00774 BoolVarArray(Space& home, const BoolVarArgs& a); 00786 GECODE_INT_EXPORT 00787 BoolVarArray(Space& home, int n, int min, int max); 00789 }; 00790 00791 } 00792 00793 #include <gecode/int/int-set-2.hpp> 00794 00795 #include <gecode/int/array.hpp> 00796 00797 namespace Gecode { 00798 00803 enum IntRelType { 00804 IRT_EQ, 00805 IRT_NQ, 00806 IRT_LQ, 00807 IRT_LE, 00808 IRT_GQ, 00809 IRT_GR 00810 }; 00811 00816 enum BoolOpType { 00817 BOT_AND, 00818 BOT_OR, 00819 BOT_IMP, 00820 BOT_EQV, 00821 BOT_XOR 00822 }; 00823 00837 enum IntConLevel { 00838 ICL_VAL, 00839 ICL_BND, 00840 ICL_DOM, 00841 ICL_DEF 00842 }; 00843 00844 00852 00853 GECODE_INT_EXPORT void 00854 dom(Home home, IntVar x, int n, 00855 IntConLevel icl=ICL_DEF); 00857 GECODE_INT_EXPORT void 00858 dom(Home home, const IntVarArgs& x, int n, 00859 IntConLevel icl=ICL_DEF); 00860 00862 GECODE_INT_EXPORT void 00863 dom(Home home, IntVar x, int l, int m, 00864 IntConLevel icl=ICL_DEF); 00866 GECODE_INT_EXPORT void 00867 dom(Home home, const IntVarArgs& x, int l, int m, 00868 IntConLevel icl=ICL_DEF); 00869 00871 GECODE_INT_EXPORT void 00872 dom(Home home, IntVar x, const IntSet& s, 00873 IntConLevel icl=ICL_DEF); 00875 GECODE_INT_EXPORT void 00876 dom(Home home, const IntVarArgs& x, const IntSet& s, 00877 IntConLevel icl=ICL_DEF); 00878 00880 GECODE_INT_EXPORT void 00881 dom(Home home, IntVar x, int n, BoolVar b, 00882 IntConLevel icl=ICL_DEF); 00884 GECODE_INT_EXPORT void 00885 dom(Home home, IntVar x, int l, int m, BoolVar b, 00886 IntConLevel icl=ICL_DEF); 00888 GECODE_INT_EXPORT void 00889 dom(Home home, IntVar x, const IntSet& s, BoolVar b, 00890 IntConLevel icl=ICL_DEF); 00892 00893 00904 GECODE_INT_EXPORT void 00905 rel(Home home, IntVar x0, IntRelType r, IntVar x1, 00906 IntConLevel icl=ICL_DEF); 00913 GECODE_INT_EXPORT void 00914 rel(Home home, const IntVarArgs& x, IntRelType r, IntVar y, 00915 IntConLevel icl=ICL_DEF); 00919 GECODE_INT_EXPORT void 00920 rel(Home home, IntVar x, IntRelType r, int c, 00921 IntConLevel icl=ICL_DEF); 00925 GECODE_INT_EXPORT void 00926 rel(Home home, const IntVarArgs& x, IntRelType r, int c, 00927 IntConLevel icl=ICL_DEF); 00934 GECODE_INT_EXPORT void 00935 rel(Home home, IntVar x0, IntRelType r, IntVar x1, BoolVar b, 00936 IntConLevel icl=ICL_DEF); 00943 GECODE_INT_EXPORT void 00944 rel(Home home, IntVar x, IntRelType r, int c, BoolVar b, 00945 IntConLevel icl=ICL_DEF); 00964 GECODE_INT_EXPORT void 00965 rel(Home home, const IntVarArgs& x, IntRelType r, 00966 IntConLevel icl=ICL_DEF); 00979 GECODE_INT_EXPORT void 00980 rel(Home home, const IntVarArgs& x, IntRelType r, const IntVarArgs& y, 00981 IntConLevel icl=ICL_DEF); 00982 00990 GECODE_INT_EXPORT void 00991 rel(Home home, BoolVar x0, IntRelType r, BoolVar x1, 00992 IntConLevel icl=ICL_DEF); 00996 GECODE_INT_EXPORT void 00997 rel(Home home, BoolVar x0, IntRelType r, BoolVar x1, BoolVar b, 00998 IntConLevel icl=ICL_DEF); 01002 GECODE_INT_EXPORT void 01003 rel(Home home, const BoolVarArgs& x, IntRelType r, BoolVar y, 01004 IntConLevel icl=ICL_DEF); 01012 GECODE_INT_EXPORT void 01013 rel(Home home, BoolVar x, IntRelType r, int n, 01014 IntConLevel icl=ICL_DEF); 01022 GECODE_INT_EXPORT void 01023 rel(Home home, BoolVar x, IntRelType r, int n, BoolVar b, 01024 IntConLevel icl=ICL_DEF); 01032 GECODE_INT_EXPORT void 01033 rel(Home home, const BoolVarArgs& x, IntRelType r, int n, 01034 IntConLevel icl=ICL_DEF); 01044 GECODE_INT_EXPORT void 01045 rel(Home home, const BoolVarArgs& x, IntRelType r, const BoolVarArgs& y, 01046 IntConLevel icl=ICL_DEF); 01058 GECODE_INT_EXPORT void 01059 rel(Home home, const BoolVarArgs& x, IntRelType r, 01060 IntConLevel icl=ICL_DEF); 01066 GECODE_INT_EXPORT void 01067 rel(Home home, BoolVar x0, BoolOpType o, BoolVar x1, BoolVar x2, 01068 IntConLevel icl=ICL_DEF); 01077 GECODE_INT_EXPORT void 01078 rel(Home home, BoolVar x0, BoolOpType o, BoolVar x1, int n, 01079 IntConLevel icl=ICL_DEF); 01089 GECODE_INT_EXPORT void 01090 rel(Home home, BoolOpType o, const BoolVarArgs& x, BoolVar y, 01091 IntConLevel icl=ICL_DEF); 01104 GECODE_INT_EXPORT void 01105 rel(Home home, BoolOpType o, const BoolVarArgs& x, int n, 01106 IntConLevel icl=ICL_DEF); 01117 GECODE_INT_EXPORT void 01118 clause(Home home, BoolOpType o, const BoolVarArgs& x, const BoolVarArgs& y, 01119 BoolVar z, IntConLevel icl=ICL_DEF); 01133 GECODE_INT_EXPORT void 01134 clause(Home home, BoolOpType o, const BoolVarArgs& x, const BoolVarArgs& y, 01135 int n, IntConLevel icl=ICL_DEF); 01136 01137 01144 01145 typedef SharedArray<int> IntSharedArray; 01151 GECODE_INT_EXPORT void 01152 element(Home home, IntSharedArray n, IntVar x0, IntVar x1, 01153 IntConLevel icl=ICL_DEF); 01159 GECODE_INT_EXPORT void 01160 element(Home home, IntSharedArray n, IntVar x0, BoolVar x1, 01161 IntConLevel icl=ICL_DEF); 01167 GECODE_INT_EXPORT void 01168 element(Home home, IntSharedArray n, IntVar x0, int x1, 01169 IntConLevel icl=ICL_DEF); 01175 GECODE_INT_EXPORT void 01176 element(Home home, const IntVarArgs& x, IntVar y0, IntVar y1, 01177 IntConLevel icl=ICL_DEF); 01183 GECODE_INT_EXPORT void 01184 element(Home home, const IntVarArgs& x, IntVar y0, int y1, 01185 IntConLevel icl=ICL_DEF); 01187 GECODE_INT_EXPORT void 01188 element(Home home, const BoolVarArgs& x, IntVar y0, BoolVar y1, 01189 IntConLevel icl=ICL_DEF); 01191 GECODE_INT_EXPORT void 01192 element(Home home, const BoolVarArgs& x, IntVar y0, int y1, 01193 IntConLevel icl=ICL_DEF); 01194 01207 GECODE_INT_EXPORT void 01208 element(Home home, IntSharedArray a, 01209 IntVar x, int w, IntVar y, int h, IntVar z, 01210 IntConLevel icl=ICL_DEF); 01223 GECODE_INT_EXPORT void 01224 element(Home home, IntSharedArray a, 01225 IntVar x, int w, IntVar y, int h, BoolVar z, 01226 IntConLevel icl=ICL_DEF); 01242 GECODE_INT_EXPORT void 01243 element(Home home, const IntVarArgs& a, 01244 IntVar x, int w, IntVar y, int h, IntVar z, 01245 IntConLevel icl=ICL_DEF); 01258 GECODE_INT_EXPORT void 01259 element(Home home, const BoolVarArgs& a, 01260 IntVar x, int w, IntVar y, int h, BoolVar z, 01261 IntConLevel icl=ICL_DEF); 01263 01264 01279 GECODE_INT_EXPORT void 01280 distinct(Home home, const IntVarArgs& x, 01281 IntConLevel icl=ICL_DEF); 01294 GECODE_INT_EXPORT void 01295 distinct(Home home, const IntArgs& n, const IntVarArgs& x, 01296 IntConLevel icl=ICL_DEF); 01298 01299 01317 GECODE_INT_EXPORT void 01318 channel(Home home, const IntVarArgs& x, const IntVarArgs& y, 01319 IntConLevel icl=ICL_DEF); 01320 01334 GECODE_INT_EXPORT void 01335 channel(Home home, const IntVarArgs& x, int xoff, 01336 const IntVarArgs& y, int yoff, 01337 IntConLevel icl=ICL_DEF); 01338 01340 GECODE_INT_EXPORT void 01341 channel(Home home, BoolVar x0, IntVar x1, 01342 IntConLevel icl=ICL_DEF); 01344 forceinline void 01345 channel(Home home, IntVar x0, BoolVar x1, 01346 IntConLevel icl=ICL_DEF) { 01347 channel(home,x1,x0,icl); 01348 } 01354 GECODE_INT_EXPORT void 01355 channel(Home home, const BoolVarArgs& x, IntVar y, int o=0, 01356 IntConLevel icl=ICL_DEF); 01358 01359 01376 GECODE_INT_EXPORT void 01377 sorted(Home home, const IntVarArgs& x, const IntVarArgs& y, 01378 IntConLevel icl=ICL_DEF); 01379 01391 GECODE_INT_EXPORT void 01392 sorted(Home home, const IntVarArgs& x, const IntVarArgs& y, 01393 const IntVarArgs& z, 01394 IntConLevel icl=ICL_DEF); 01396 01397 01416 GECODE_INT_EXPORT void 01417 count(Home home, const IntVarArgs& x, int n, IntRelType r, int m, 01418 IntConLevel icl=ICL_DEF); 01423 GECODE_INT_EXPORT void 01424 count(Home home, const IntVarArgs& x, IntVar y, IntRelType r, int m, 01425 IntConLevel icl=ICL_DEF); 01433 GECODE_INT_EXPORT void 01434 count(Home home, const IntVarArgs& x, const IntArgs& y, IntRelType r, int m, 01435 IntConLevel icl=ICL_DEF); 01440 GECODE_INT_EXPORT void 01441 count(Home home, const IntVarArgs& x, int n, IntRelType r, IntVar z, 01442 IntConLevel icl=ICL_DEF); 01447 GECODE_INT_EXPORT void 01448 count(Home home, const IntVarArgs& x, IntVar y, IntRelType r, IntVar z, 01449 IntConLevel icl=ICL_DEF); 01457 GECODE_INT_EXPORT void 01458 count(Home home, const IntVarArgs& x, const IntArgs& y, IntRelType r, IntVar z, 01459 IntConLevel icl=ICL_DEF); 01460 01474 GECODE_INT_EXPORT void 01475 count(Home home, const IntVarArgs& x, const IntVarArgs& c, 01476 IntConLevel icl=ICL_DEF); 01477 01491 GECODE_INT_EXPORT void 01492 count(Home home, const IntVarArgs& x, const IntSetArgs& c, 01493 IntConLevel icl=ICL_DEF); 01494 01511 GECODE_INT_EXPORT void 01512 count(Home home, const IntVarArgs& x, 01513 const IntVarArgs& c, const IntArgs& v, 01514 IntConLevel icl=ICL_DEF); 01515 01532 GECODE_INT_EXPORT void 01533 count(Home home, const IntVarArgs& x, 01534 const IntSetArgs& c, const IntArgs& v, 01535 IntConLevel icl=ICL_DEF); 01536 01553 GECODE_INT_EXPORT void 01554 count(Home home, const IntVarArgs& x, 01555 const IntSet& c, const IntArgs& v, 01556 IntConLevel icl=ICL_DEF); 01557 01559 01580 GECODE_INT_EXPORT void 01581 sequence(Home home, const IntVarArgs& x, const IntSet& s, 01582 int q, int l, int u, IntConLevel icl=ICL_DEF); 01583 01598 GECODE_INT_EXPORT void 01599 sequence(Home home, const BoolVarArgs& x, const IntSet& s, 01600 int q, int l, int u, IntConLevel icl=ICL_DEF); 01601 01603 01616 01624 class DFA : public SharedHandle { 01625 private: 01627 class DFAI; 01628 public: 01630 class Transition { 01631 public: 01632 int i_state; 01633 int symbol; 01634 int o_state; 01635 }; 01637 class Transitions { 01638 private: 01640 const Transition* c_trans; 01642 const Transition* e_trans; 01643 public: 01645 Transitions(const DFA& d); 01647 Transitions(const DFA& d, int n); 01649 bool operator ()(void) const; 01651 void operator ++(void); 01653 int i_state(void) const; 01655 int symbol(void) const; 01657 int o_state(void) const; 01658 }; 01660 class Symbols { 01661 private: 01663 const Transition* c_trans; 01665 const Transition* e_trans; 01666 public: 01668 Symbols(const DFA& d); 01670 bool operator ()(void) const; 01672 void operator ++(void); 01674 int val(void) const; 01675 }; 01676 public: 01677 friend class Transitions; 01679 DFA(void); 01691 GECODE_INT_EXPORT 01692 DFA(int s, Transition t[], int f[], bool minimize=true); 01694 DFA(const DFA& d); 01696 int n_states(void) const; 01698 int n_transitions(void) const; 01700 unsigned int n_symbols(void) const; 01702 unsigned int max_degree(void) const; 01704 int final_fst(void) const; 01706 int final_lst(void) const; 01708 int symbol_min(void) const; 01710 int symbol_max(void) const; 01711 }; 01712 01713 01721 enum ExtensionalPropKind { 01722 EPK_DEF, 01723 EPK_SPEED, 01724 EPK_MEMORY 01725 }; 01726 01737 GECODE_INT_EXPORT void 01738 extensional(Home home, const IntVarArgs& x, DFA d, 01739 IntConLevel icl=ICL_DEF); 01740 01751 GECODE_INT_EXPORT void 01752 extensional(Home home, const BoolVarArgs& x, DFA d, 01753 IntConLevel icl=ICL_DEF); 01754 01761 class TupleSet : public SharedHandle { 01762 public: 01767 typedef int* Tuple; 01768 01773 class GECODE_VTABLE_EXPORT TupleSetI 01774 : public SharedHandle::Object { 01775 public: 01777 int arity; 01779 int size; 01781 Tuple** tuples; 01783 Tuple* tuple_data; 01785 int* data; 01787 int excess; 01789 int min, max; 01791 unsigned int domsize; 01793 Tuple** last; 01795 Tuple* nullpointer; 01796 01798 template<class T> 01799 void add(T t); 01801 GECODE_INT_EXPORT void finalize(void); 01803 GECODE_INT_EXPORT void resize(void); 01805 bool finalized(void) const; 01807 TupleSetI(void); 01809 GECODE_INT_EXPORT virtual ~TupleSetI(void); 01811 GECODE_INT_EXPORT virtual SharedHandle::Object* copy(void) const; 01812 }; 01813 01815 TupleSetI* implementation(void); 01816 01818 TupleSet(void); 01820 TupleSet(const TupleSet& d); 01821 01823 void add(const IntArgs& tuple); 01825 void finalize(void); 01827 bool finalized(void) const; 01829 int arity(void) const; 01831 int tuples(void) const; 01833 Tuple operator [](int i) const; 01835 int min(void) const; 01837 int max(void) const; 01838 }; 01839 01858 GECODE_INT_EXPORT void 01859 extensional(Home home, const IntVarArgs& x, const TupleSet& t, 01860 ExtensionalPropKind epk=EPK_DEF, IntConLevel icl=ICL_DEF); 01861 01872 GECODE_INT_EXPORT void 01873 extensional(Home home, const BoolVarArgs& x, const TupleSet& t, 01874 ExtensionalPropKind epk=EPK_DEF, IntConLevel icl=ICL_DEF); 01876 01877 } 01878 01879 #include <gecode/int/extensional/dfa.hpp> 01880 #include <gecode/int/extensional/tuple-set.hpp> 01881 01882 namespace Gecode { 01883 01895 GECODE_INT_EXPORT void 01896 min(Home home, IntVar x0, IntVar x1, IntVar x2, 01897 IntConLevel icl=ICL_DEF); 01905 GECODE_INT_EXPORT void 01906 min(Home home, const IntVarArgs& x, IntVar y, 01907 IntConLevel icl=ICL_DEF); 01913 GECODE_INT_EXPORT void 01914 max(Home home, IntVar x0, IntVar x1, IntVar x2, 01915 IntConLevel icl=ICL_DEF); 01923 GECODE_INT_EXPORT void 01924 max(Home home, const IntVarArgs& x, IntVar y, 01925 IntConLevel icl=ICL_DEF); 01926 01932 GECODE_INT_EXPORT void 01933 abs(Home home, IntVar x0, IntVar x1, 01934 IntConLevel icl=ICL_DEF); 01935 01941 GECODE_INT_EXPORT void 01942 mult(Home home, IntVar x0, IntVar x1, IntVar x2, 01943 IntConLevel icl=ICL_DEF); 01944 01950 GECODE_INT_EXPORT void 01951 sqr(Home home, IntVar x0, IntVar x1, 01952 IntConLevel icl=ICL_DEF); 01953 01959 GECODE_INT_EXPORT void 01960 sqrt(Home home, IntVar x0, IntVar x1, 01961 IntConLevel icl=ICL_DEF); 01962 01967 GECODE_INT_EXPORT void 01968 divmod(Home home, IntVar x0, IntVar x1, IntVar x2, IntVar x3, 01969 IntConLevel icl=ICL_DEF); 01970 01975 GECODE_INT_EXPORT void 01976 div(Home home, IntVar x0, IntVar x1, IntVar x2, 01977 IntConLevel icl=ICL_DEF); 01978 01983 GECODE_INT_EXPORT void 01984 mod(Home home, IntVar x0, IntVar x1, IntVar x2, 01985 IntConLevel icl=ICL_DEF); 01987 02019 GECODE_INT_EXPORT void 02020 linear(Home home, const IntVarArgs& x, 02021 IntRelType r, int c, 02022 IntConLevel icl=ICL_DEF); 02026 GECODE_INT_EXPORT void 02027 linear(Home home, const IntVarArgs& x, 02028 IntRelType r, IntVar y, 02029 IntConLevel icl=ICL_DEF); 02033 GECODE_INT_EXPORT void 02034 linear(Home home, const IntVarArgs& x, 02035 IntRelType r, int c, BoolVar b, 02036 IntConLevel icl=ICL_DEF); 02040 GECODE_INT_EXPORT void 02041 linear(Home home, const IntVarArgs& x, 02042 IntRelType r, IntVar y, BoolVar b, 02043 IntConLevel icl=ICL_DEF); 02050 GECODE_INT_EXPORT void 02051 linear(Home home, const IntArgs& a, const IntVarArgs& x, 02052 IntRelType r, int c, 02053 IntConLevel icl=ICL_DEF); 02060 GECODE_INT_EXPORT void 02061 linear(Home home, const IntArgs& a, const IntVarArgs& x, 02062 IntRelType r, IntVar y, 02063 IntConLevel icl=ICL_DEF); 02070 GECODE_INT_EXPORT void 02071 linear(Home home, const IntArgs& a, const IntVarArgs& x, 02072 IntRelType r, int c, BoolVar b, 02073 IntConLevel icl=ICL_DEF); 02080 GECODE_INT_EXPORT void 02081 linear(Home home, const IntArgs& a, const IntVarArgs& x, 02082 IntRelType r, IntVar y, BoolVar b, 02083 IntConLevel icl=ICL_DEF); 02084 02085 02113 GECODE_INT_EXPORT void 02114 linear(Home home, const BoolVarArgs& x, 02115 IntRelType r, int c, 02116 IntConLevel icl=ICL_DEF); 02120 GECODE_INT_EXPORT void 02121 linear(Home home, const BoolVarArgs& x, 02122 IntRelType r, int c, BoolVar b, 02123 IntConLevel icl=ICL_DEF); 02127 GECODE_INT_EXPORT void 02128 linear(Home home, const BoolVarArgs& x, 02129 IntRelType r, IntVar y, 02130 IntConLevel icl=ICL_DEF); 02134 GECODE_INT_EXPORT void 02135 linear(Home home, const BoolVarArgs& x, 02136 IntRelType r, IntVar y, BoolVar b, 02137 IntConLevel icl=ICL_DEF); 02144 GECODE_INT_EXPORT void 02145 linear(Home home, const IntArgs& a, const BoolVarArgs& x, 02146 IntRelType r, int c, 02147 IntConLevel icl=ICL_DEF); 02154 GECODE_INT_EXPORT void 02155 linear(Home home, const IntArgs& a, const BoolVarArgs& x, 02156 IntRelType r, int c, BoolVar b, 02157 IntConLevel icl=ICL_DEF); 02164 GECODE_INT_EXPORT void 02165 linear(Home home, const IntArgs& a, const BoolVarArgs& x, 02166 IntRelType r, IntVar y, 02167 IntConLevel icl=ICL_DEF); 02174 GECODE_INT_EXPORT void 02175 linear(Home home, const IntArgs& a, const BoolVarArgs& x, 02176 IntRelType r, IntVar y, BoolVar b, 02177 IntConLevel icl=ICL_DEF); 02178 02179 02205 GECODE_INT_EXPORT void 02206 binpacking(Home home, 02207 const IntVarArgs& l, 02208 const IntVarArgs& b, const IntArgs& s, 02209 IntConLevel icl=ICL_DEF); 02210 02211 02220 02221 GECODE_INT_EXPORT void 02222 wait(Home home, IntVar x, void (*c)(Space& home), 02223 IntConLevel icl=ICL_DEF); 02225 GECODE_INT_EXPORT void 02226 wait(Home home, BoolVar x, void (*c)(Space& home), 02227 IntConLevel icl=ICL_DEF); 02229 GECODE_INT_EXPORT void 02230 wait(Home home, const IntVarArgs& x, void (*c)(Space& home), 02231 IntConLevel icl=ICL_DEF); 02233 GECODE_INT_EXPORT void 02234 wait(Home home, const BoolVarArgs& x, void (*c)(Space& home), 02235 IntConLevel icl=ICL_DEF); 02237 GECODE_INT_EXPORT void 02238 when(Home home, BoolVar x, 02239 void (*t)(Space& home), void (*e)(Space& home)= NULL, 02240 IntConLevel icl=ICL_DEF); 02242 02243 02268 GECODE_INT_EXPORT void 02269 unshare(Home home, IntVarArgs& x, 02270 IntConLevel icl=ICL_DEF); 02272 GECODE_INT_EXPORT void 02273 unshare(Home home, BoolVarArgs& x, 02274 IntConLevel icl=ICL_DEF); 02276 02277 02283 02284 enum IntVarBranch { 02285 INT_VAR_NONE = 0, 02286 INT_VAR_RND, 02287 INT_VAR_DEGREE_MIN, 02288 INT_VAR_DEGREE_MAX, 02289 INT_VAR_AFC_MIN, 02290 INT_VAR_AFC_MAX, 02291 INT_VAR_MIN_MIN, 02292 INT_VAR_MIN_MAX, 02293 INT_VAR_MAX_MIN, 02294 INT_VAR_MAX_MAX, 02295 INT_VAR_SIZE_MIN, 02296 INT_VAR_SIZE_MAX, 02297 INT_VAR_SIZE_DEGREE_MIN, 02298 INT_VAR_SIZE_DEGREE_MAX, 02299 INT_VAR_SIZE_AFC_MIN, 02300 INT_VAR_SIZE_AFC_MAX, 02301 02306 INT_VAR_REGRET_MIN_MIN, 02312 INT_VAR_REGRET_MIN_MAX, 02318 INT_VAR_REGRET_MAX_MIN, 02324 INT_VAR_REGRET_MAX_MAX 02325 }; 02326 02328 enum IntValBranch { 02329 INT_VAL_MIN, 02330 INT_VAL_MED, 02331 INT_VAL_MAX, 02332 INT_VAL_RND, 02333 INT_VAL_SPLIT_MIN, 02334 INT_VAL_SPLIT_MAX, 02335 INT_VAL_RANGE_MIN, 02336 INT_VAL_RANGE_MAX, 02337 INT_VALUES_MIN, 02338 INT_VALUES_MAX 02339 }; 02340 02342 GECODE_INT_EXPORT void 02343 branch(Home home, const IntVarArgs& x, 02344 IntVarBranch vars, IntValBranch vals, 02345 const VarBranchOptions& o_vars = VarBranchOptions::def, 02346 const ValBranchOptions& o_vals = ValBranchOptions::def); 02348 GECODE_INT_EXPORT void 02349 branch(Home home, const IntVarArgs& x, 02350 const TieBreakVarBranch<IntVarBranch>& vars, IntValBranch vals, 02351 const TieBreakVarBranchOptions& o_vars = TieBreakVarBranchOptions::def, 02352 const ValBranchOptions& o_vals = ValBranchOptions::def); 02354 GECODE_INT_EXPORT void 02355 branch(Home home, IntVar x, IntValBranch vals, 02356 const ValBranchOptions& o_vals = ValBranchOptions::def); 02358 GECODE_INT_EXPORT void 02359 branch(Home home, const BoolVarArgs& x, 02360 IntVarBranch vars, IntValBranch vals, 02361 const VarBranchOptions& o_vars = VarBranchOptions::def, 02362 const ValBranchOptions& o_vals = ValBranchOptions::def); 02364 GECODE_INT_EXPORT void 02365 branch(Home home, const BoolVarArgs& x, 02366 const TieBreakVarBranch<IntVarBranch>& vars, IntValBranch vals, 02367 const TieBreakVarBranchOptions& o_vars = TieBreakVarBranchOptions::def, 02368 const ValBranchOptions& o_vals = ValBranchOptions::def); 02370 GECODE_INT_EXPORT void 02371 branch(Home home, BoolVar x, IntValBranch vals, 02372 const ValBranchOptions& o_vals = ValBranchOptions::def); 02373 02375 02381 02382 enum IntAssign { 02383 INT_ASSIGN_MIN, 02384 INT_ASSIGN_MED, 02385 INT_ASSIGN_MAX, 02386 INT_ASSIGN_RND 02387 }; 02388 02390 GECODE_INT_EXPORT void 02391 assign(Home home, const IntVarArgs& x, IntAssign vals, 02392 const ValBranchOptions& o_vals = ValBranchOptions::def); 02394 GECODE_INT_EXPORT void 02395 assign(Home home, IntVar x, IntAssign vals, 02396 const ValBranchOptions& o_vals = ValBranchOptions::def); 02398 GECODE_INT_EXPORT void 02399 assign(Home home, const BoolVarArgs& x, IntAssign vals, 02400 const ValBranchOptions& o_vals = ValBranchOptions::def); 02402 GECODE_INT_EXPORT void 02403 assign(Home home, BoolVar x, IntAssign vals, 02404 const ValBranchOptions& o_vals = ValBranchOptions::def); 02405 02407 02411 template<class Char, class Traits> 02412 std::basic_ostream<Char,Traits>& 02413 operator <<(std::basic_ostream<Char,Traits>& os, const DFA& d); 02414 02418 template<class Char, class Traits> 02419 std::basic_ostream<Char,Traits>& 02420 operator <<(std::basic_ostream<Char,Traits>& os, const TupleSet& ts); 02421 02422 } 02423 02424 #endif 02425 02426 // IFDEF: GECODE_HAS_INT_VARS 02427 // STATISTICS: int-post 02428