00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #ifndef __GECODE_SET_HH__
00045 #define __GECODE_SET_HH__
00046
00047 #include <gecode/kernel.hh>
00048 #include <gecode/int.hh>
00049 #include <gecode/iter.hh>
00050
00051
00052
00053
00054
00055 #if !defined(GECODE_STATIC_LIBS) && \
00056 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
00057
00058 #ifdef GECODE_BUILD_SET
00059 #define GECODE_SET_EXPORT __declspec( dllexport )
00060 #else
00061 #define GECODE_SET_EXPORT __declspec( dllimport )
00062 #endif
00063
00064 #else
00065
00066 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
00067 #define GECODE_SET_EXPORT __attribute__ ((visibility("default")))
00068 #else
00069 #define GECODE_SET_EXPORT
00070 #endif
00071
00072 #endif
00073
00074
00075 #ifndef GECODE_BUILD_SET
00076 #define GECODE_LIBRARY_NAME "Set"
00077 #include <gecode/support/auto-link.hpp>
00078 #endif
00079
00080
00092 #include <gecode/set/exception.hpp>
00093
00094 namespace Gecode { namespace Set {
00095
00097 namespace Limits {
00099 const int max = (Gecode::Int::Limits::max / 2) - 1;
00101 const int min = -max;
00103 const unsigned int card = max-min+1;
00105 void check(int n, const char* l);
00107 void check(unsigned int n, const char* l);
00109 void check(const IntSet& s, const char* l);
00110 }
00111
00112 }}
00113
00114 #include <gecode/set/limits.hpp>
00115
00116 #include <gecode/set/var-imp.hpp>
00117
00118 namespace Gecode {
00119
00120 namespace Set {
00121 class SetView;
00122 }
00123
00129 class SetVar : public VarBase<Set::SetVarImp> {
00130 friend class SetVarArray;
00131 private:
00132 using VarBase<Set::SetVarImp>::varimp;
00134 void init(Space& home);
00143 void init(Space& home,int glbMin,int glbMax,int lubMin,int lubMax,
00144 unsigned int cardMin = 0,
00145 unsigned int cardMax = Set::Limits::card);
00154 void init(Space& home,const IntSet& glbD,int lubMin,int lubMax,
00155 unsigned int cardMin = 0,
00156 unsigned int cardMax = Set::Limits::card);
00165 void init(Space& home,int glbMin,int glbMax,const IntSet& lubD,
00166 unsigned int cardMin = 0,
00167 unsigned int cardMax = Set::Limits::card);
00176 void init(Space& home,const IntSet& glbD,const IntSet& lubD,
00177 unsigned int cardMin = 0,
00178 unsigned int cardMax = Set::Limits::card);
00179 public:
00181
00182
00183 SetVar(void);
00185 SetVar(const SetVar& x0);
00187 SetVar(const Set::SetView& x0);
00188
00190 GECODE_SET_EXPORT SetVar(Space& home);
00191
00209 GECODE_SET_EXPORT
00210 SetVar(Space& home,int glbMin,int glbMax,int lubMin,int lubMax,
00211 unsigned int cardMin = 0,
00212 unsigned int cardMax = Set::Limits::card);
00213
00231 GECODE_SET_EXPORT
00232 SetVar(Space& home,const IntSet& glbD,int lubMin,int lubMax,
00233 unsigned int cardMin = 0,
00234 unsigned int cardMax = Set::Limits::card);
00235
00253 GECODE_SET_EXPORT
00254 SetVar(Space& home,int glbMin,int glbMax,const IntSet& lubD,
00255 unsigned int cardMin = 0,
00256 unsigned int cardMax = Set::Limits::card);
00257
00275 GECODE_SET_EXPORT
00276 SetVar(Space& home,const IntSet& glbD,const IntSet& lubD,
00277 unsigned int cardMin = 0,
00278 unsigned int cardMax = Set::Limits::card);
00280
00282
00283
00284 unsigned int glbSize(void) const;
00286 unsigned int lubSize(void) const;
00288 unsigned int unknownSize(void) const;
00290 unsigned int cardMin(void) const;
00292 unsigned int cardMax(void) const;
00294 int lubMin(void) const;
00296 int lubMax(void) const;
00298 int glbMin(void) const;
00300 int glbMax(void) const;
00302
00304
00305
00306 bool contains(int i) const;
00308 bool notContains(int i) const;
00310 bool assigned(void) const;
00311
00313
00314
00315 void update(Space& home, bool, SetVar& x);
00317 };
00318
00324
00326 class SetVarGlbRanges {
00327 private:
00328 Set::GlbRanges<Set::SetVarImp*> iter;
00329 public:
00331
00332
00333 SetVarGlbRanges(void);
00335 SetVarGlbRanges(const SetVar& x);
00337
00339
00340
00341 bool operator ()(void) const;
00343 void operator ++(void);
00345
00347
00348
00349 int min(void) const;
00351 int max(void) const;
00353 unsigned int width(void) const;
00355 };
00356
00358 class SetVarLubRanges {
00359 private:
00360 Set::LubRanges<Set::SetVarImp*> iter;
00361 public:
00363
00364
00365 SetVarLubRanges(void);
00367 SetVarLubRanges(const SetVar& x);
00369
00371
00372
00373 bool operator ()(void) const;
00375 void operator ++(void);
00377
00379
00380
00381 int min(void) const;
00383 int max(void) const;
00385 unsigned int width(void) const;
00387 };
00388
00390 class SetVarUnknownRanges {
00391 private:
00392 Set::UnknownRanges<Set::SetVarImp*> iter;
00393 public:
00395
00396
00397 SetVarUnknownRanges(void);
00399 SetVarUnknownRanges(const SetVar& x);
00401
00403
00404
00405 bool operator ()(void) const;
00407 void operator ++(void);
00409
00411
00412
00413 int min(void) const;
00415 int max(void) const;
00417 unsigned int width(void) const;
00419 };
00420
00422 class SetVarGlbValues {
00423 private:
00424 Iter::Ranges::ToValues<SetVarGlbRanges> iter;
00425 public:
00427
00428
00429 SetVarGlbValues(void);
00431 SetVarGlbValues(const SetVar& x);
00433
00435
00436
00437 bool operator ()(void) const;
00439 void operator ++(void);
00441
00443
00444
00445 int val(void) const;
00447 };
00448
00450 class SetVarLubValues {
00451 private:
00452 Iter::Ranges::ToValues<SetVarLubRanges> iter;
00453 public:
00455
00456
00457 SetVarLubValues(void);
00459 SetVarLubValues(const SetVar& x);
00461
00463
00464
00465 bool operator ()(void) const;
00467 void operator ++(void);
00469
00471
00472
00473 int val(void) const;
00475 };
00476
00478 class SetVarUnknownValues {
00479 private:
00480 Iter::Ranges::ToValues<SetVarUnknownRanges> iter;
00481 public:
00483
00484
00485 SetVarUnknownValues(void);
00487 SetVarUnknownValues(const SetVar& x);
00489
00491
00492
00493 bool operator ()(void) const;
00495 void operator ++(void);
00497
00499
00500
00501 int val(void) const;
00503 };
00504
00506
00511 template<class Char, class Traits>
00512 std::basic_ostream<Char,Traits>&
00513 operator <<(std::basic_ostream<Char,Traits>& os, const SetVar& x);
00514
00515 }
00516
00517 #include <gecode/set/view.hpp>
00518 #include <gecode/set/propagator.hpp>
00519
00520 namespace Gecode {
00530
00531 typedef VarArgArray<SetVar> SetVarArgs;
00533
00549 class SetVarArray : public VarArray<SetVar> {
00550 public:
00551 SetVarArray(void);
00552 SetVarArray(const SetVarArray&);
00554 GECODE_SET_EXPORT SetVarArray(Space& home,int n);
00561 GECODE_SET_EXPORT
00562 SetVarArray(Space& home,int n,int glbMin,int glbMax,int lubMin,int lubMax,
00563 unsigned int minCard = 0,
00564 unsigned int maxCard = Set::Limits::card);
00571 GECODE_SET_EXPORT
00572 SetVarArray(Space& home,int n,const IntSet& glb, int lubMin, int lubMax,
00573 unsigned int minCard = 0,
00574 unsigned int maxCard = Set::Limits::card);
00581 GECODE_SET_EXPORT
00582 SetVarArray(Space& home,int n,int glbMin,int glbMax,const IntSet& lub,
00583 unsigned int minCard = 0,
00584 unsigned int maxCard = Set::Limits::card);
00591 GECODE_SET_EXPORT
00592 SetVarArray(Space& home,int n,
00593 const IntSet& glb,const IntSet& lub,
00594 unsigned int minCard = 0,
00595 unsigned int maxCard = Set::Limits::card);
00596 };
00597
00598 }
00599
00600 #include <gecode/set/array.hpp>
00601
00602 namespace Gecode {
00603
00608 enum SetRelType {
00609 SRT_EQ,
00610 SRT_NQ,
00611 SRT_SUB,
00612 SRT_SUP,
00613 SRT_DISJ,
00614 SRT_CMPL
00615 };
00616
00621 enum SetOpType {
00622 SOT_UNION,
00623 SOT_DUNION,
00624 SOT_INTER,
00625 SOT_MINUS
00626 };
00627
00635
00637 GECODE_SET_EXPORT void
00638 dom(Space& home, SetVar x, SetRelType r, int i);
00639
00641 GECODE_SET_EXPORT void
00642 dom(Space& home, SetVar x, SetRelType r, int i, int j);
00643
00645 GECODE_SET_EXPORT void
00646 dom(Space& home, SetVar x, SetRelType r, const IntSet& s);
00647
00649 GECODE_SET_EXPORT void
00650 dom(Space& home, SetVar x, SetRelType r, int i, BoolVar b);
00651
00653 GECODE_SET_EXPORT void
00654 dom(Space& home, SetVar x, SetRelType r, int i, int j, BoolVar b);
00655
00657 GECODE_SET_EXPORT void
00658 dom(Space& home, SetVar x, SetRelType r, const IntSet& s, BoolVar b);
00659
00661 GECODE_SET_EXPORT void
00662 cardinality(Space& home, SetVar x, unsigned int i, unsigned int j);
00663
00665
00666
00674
00676 GECODE_SET_EXPORT void
00677 rel(Space& home, SetVar x, SetRelType r, SetVar y);
00678
00680 GECODE_SET_EXPORT void
00681 rel(Space& home, SetVar x, SetRelType r, SetVar y, BoolVar b);
00682
00684 GECODE_SET_EXPORT void
00685 rel(Space& home, SetVar s, SetRelType r, IntVar x);
00686
00688 GECODE_SET_EXPORT void
00689 rel(Space& home, IntVar x, SetRelType r, SetVar s);
00690
00692 GECODE_SET_EXPORT void
00693 rel(Space& home, SetVar s, SetRelType r, IntVar x, BoolVar b);
00694
00696 GECODE_SET_EXPORT void
00697 rel(Space& home, IntVar x, SetRelType r, SetVar s, BoolVar b);
00698
00700 GECODE_SET_EXPORT void
00701 rel(Space& home, SetVar s, IntRelType r, IntVar x);
00702
00704 GECODE_SET_EXPORT void
00705 rel(Space& home, IntVar x, IntRelType r, SetVar s);
00706
00708
00716
00718 GECODE_SET_EXPORT void
00719 rel(Space& home, SetVar x, SetOpType op, SetVar y, SetRelType r, SetVar z);
00720
00722 GECODE_SET_EXPORT void
00723 rel(Space& home, SetOpType op, const SetVarArgs& x, SetVar y);
00724
00726 GECODE_SET_EXPORT void
00727 rel(Space& home, SetOpType op, const SetVarArgs& x, const IntSet& z, SetVar y);
00728
00730 GECODE_SET_EXPORT void
00731 rel(Space& home, SetOpType op, const IntVarArgs& x, const IntSet& z, SetVar y);
00732
00734 GECODE_SET_EXPORT void
00735 rel(Space& home, SetOpType op, const IntVarArgs& x, SetVar y);
00736
00738 GECODE_SET_EXPORT void
00739 rel(Space& home, const IntSet& x, SetOpType op, SetVar y,
00740 SetRelType r, SetVar z);
00741
00743 GECODE_SET_EXPORT void
00744 rel(Space& home, SetVar x, SetOpType op, const IntSet& y,
00745 SetRelType r, SetVar z);
00746
00748 GECODE_SET_EXPORT void
00749 rel(Space& home, SetVar x, SetOpType op, SetVar y,
00750 SetRelType r, const IntSet& z);
00751
00753 GECODE_SET_EXPORT void
00754 rel(Space& home, const IntSet& x, SetOpType op, SetVar y, SetRelType r,
00755 const IntSet& z);
00756
00758 GECODE_SET_EXPORT void
00759 rel(Space& home, SetVar x, SetOpType op, const IntSet& y, SetRelType r,
00760 const IntSet& z);
00761
00763
00764
00771
00773 GECODE_SET_EXPORT void
00774 convex(Space& home, SetVar x);
00775
00777 GECODE_SET_EXPORT void
00778 convex(Space& home, SetVar x, SetVar y);
00779
00781
00788
00790 GECODE_SET_EXPORT void
00791 sequence(Space& home, const SetVarArgs& x);
00792
00794 GECODE_SET_EXPORT void
00795 sequence(Space& home, const SetVarArgs& y, SetVar x);
00796
00798
00805
00806
00808 GECODE_SET_EXPORT void
00809 atmostOne(Space& home, const SetVarArgs& x, unsigned int c);
00810
00812
00820
00823 GECODE_SET_EXPORT void
00824 min(Space& home, SetVar s, IntVar x);
00825
00828 GECODE_SET_EXPORT void
00829 notMin(Space& home, SetVar s, IntVar x);
00830
00833 GECODE_SET_EXPORT void
00834 min(Space& home, SetVar s, IntVar x, BoolVar b);
00835
00838 GECODE_SET_EXPORT void
00839 max(Space& home, SetVar s, IntVar x);
00840
00843 GECODE_SET_EXPORT void
00844 notMax(Space& home, SetVar s, IntVar x);
00845
00848 GECODE_SET_EXPORT void
00849 max(Space& home, SetVar s, IntVar x, BoolVar b);
00850
00852 GECODE_SET_EXPORT void
00853 channel(Space& home, const IntVarArgs& x, SetVar y);
00854
00856 GECODE_SET_EXPORT void
00857 channel(Space& home, const IntVarArgs& x,const SetVarArgs& y);
00858
00860 GECODE_SET_EXPORT void
00861 channel(Space& home, const BoolVarArgs& x, SetVar y);
00862
00864 GECODE_SET_EXPORT void
00865 cardinality(Space& home, SetVar s, IntVar x);
00866
00867
00878 GECODE_SET_EXPORT void
00879 weights(Space& home, const IntArgs& elements, const IntArgs& weights,
00880 SetVar x, IntVar y);
00881
00883
00897
00907 GECODE_SET_EXPORT void
00908 element(Space& home, SetOpType op, const SetVarArgs& x, SetVar y, SetVar z,
00909 const IntSet& u = IntSet(Set::Limits::min,Set::Limits::max));
00910
00920 GECODE_SET_EXPORT void
00921 element(Space& home, SetOpType op, const IntSetArgs& x, SetVar y, SetVar z,
00922 const IntSet& u = IntSet(Set::Limits::min,Set::Limits::max));
00923
00929 GECODE_SET_EXPORT void
00930 element(Space& home, const SetVarArgs& x, IntVar y, SetVar z);
00931
00937 GECODE_SET_EXPORT void
00938 element(Space& home, const IntSetArgs& s, IntVar y, SetVar z);
00939
00941
00952
00953 GECODE_SET_EXPORT void
00954 wait(Space& home, SetVar x, void (*c)(Space& home));
00956 GECODE_SET_EXPORT void
00957 wait(Space& home, const SetVarArgs& x, void (*c)(Space& home));
00959
00966
00967 enum SetVarBranch {
00968 SET_VAR_NONE = 0,
00969 SET_VAR_RND,
00970 SET_VAR_DEGREE_MIN,
00971 SET_VAR_DEGREE_MAX,
00972 SET_VAR_MIN_MIN,
00973 SET_VAR_MIN_MAX,
00974 SET_VAR_MAX_MIN,
00975 SET_VAR_MAX_MAX,
00976 SET_VAR_SIZE_MIN,
00977 SET_VAR_SIZE_MAX,
00978 SET_VAR_SIZE_DEGREE_MIN,
00979 SET_VAR_SIZE_DEGREE_MAX
00980 };
00981
00983 enum SetValBranch {
00984 SET_VAL_MIN_INC,
00985 SET_VAL_MIN_EXC,
00986 SET_VAL_MED_INC,
00987 SET_VAL_MED_EXC,
00988 SET_VAL_MAX_INC,
00989 SET_VAL_MAX_EXC,
00990 SET_VAL_RND_INC,
00991 SET_VAL_RND_EXC
00992 };
00993
00995 GECODE_SET_EXPORT void
00996 branch(Space& home, const SetVarArgs& x,
00997 SetVarBranch vars, SetValBranch vals,
00998 const VarBranchOptions& o_vars = VarBranchOptions::def,
00999 const ValBranchOptions& o_vals = ValBranchOptions::def);
01001 GECODE_SET_EXPORT void
01002 branch(Space& home, const SetVarArgs& x,
01003 const TieBreakVarBranch<SetVarBranch>& vars, SetValBranch vals,
01004 const TieBreakVarBranchOptions& o_vars = TieBreakVarBranchOptions::def,
01005 const ValBranchOptions& o_vals = ValBranchOptions::def);
01007
01013
01014 enum SetAssign {
01015 SET_ASSIGN_MIN_INC,
01016 SET_ASSIGN_MIN_EXC,
01017 SET_ASSIGN_MED_INC,
01018 SET_ASSIGN_MED_EXC,
01019 SET_ASSIGN_MAX_INC,
01020 SET_ASSIGN_MAX_EXC,
01021 SET_ASSIGN_RND_INC,
01022 SET_ASSIGN_RND_EXC
01023 };
01024
01026 GECODE_SET_EXPORT void
01027 assign(Space& home, const SetVarArgs& x, SetAssign vals,
01028 const ValBranchOptions& o_vals = ValBranchOptions::def);
01029
01031
01032 }
01033
01034 #endif
01035
01036
01037