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 #include <iostream>
00027 #include "gecode/iter.hh"
00028
00029 namespace Gecode {
00030
00031 namespace Set {
00032
00047 class SetView : public VariableViewBase<SetVarImp> {
00048 protected:
00049 using VariableViewBase<SetVarImp>::var;
00050 public:
00052
00053
00054 SetView(void);
00056 SetView(const SetVar& x);
00058
00060
00061
00063 unsigned int cardMin(void) const;
00065 unsigned int cardMax(void) const;
00067 int lubMin(void) const;
00069 int lubMax(void) const;
00071 int lubMinN(int n) const;
00073 int lubMaxN(int n) const;
00075 int glbMin(void) const;
00077 int glbMax(void) const;
00078
00080 unsigned int glbSize(void) const;
00082 unsigned int lubSize(void) const;
00084 unsigned int unknownSize(void) const;
00086
00088
00089
00090 bool assigned(void) const;
00092 bool contains(int i) const;
00094 bool notContains(int i) const;
00096
00097
00099
00100
00101 ModEvent cardMin(Space* home, unsigned int m);
00103 ModEvent cardMax(Space* home, unsigned int m);
00108 ModEvent include(Space* home,int i,int j);
00113 ModEvent exclude(Space* home,int i,int j);
00115 ModEvent include(Space* home,int i);
00117 ModEvent exclude(Space* home,int i);
00122 ModEvent intersect(Space* home,int i,int j);
00124 ModEvent intersect(Space* home,int i);
00126
00128
00129
00131 template <class I> ModEvent excludeI(Space* home, I& i);
00133 template <class I> ModEvent includeI(Space* home, I& i);
00135 template <class I> ModEvent intersectI(Space* home, I& iter);
00137
00139
00140
00141 void update(Space* home, bool share, SetView& x);
00143 };
00144
00145 }
00146
00153 template<>
00154 class ViewVarTraits<Set::SetView> {
00155 public:
00157 typedef Set::SetVarImp Var;
00158 };
00159
00160
00161 namespace Set { class ConstantView; }
00162 bool same(const Set::ConstantView&, const Set::ConstantView&);
00163 bool before(const Set::ConstantView&, const Set::ConstantView&);
00164
00165 namespace Set {
00166
00174 class ConstantView : public ConstantViewBase {
00175 friend class LubRanges<ConstantView>;
00176 friend class GlbRanges<ConstantView>;
00177 friend bool Gecode::same(const Gecode::Set::ConstantView&,
00178 const Gecode::Set::ConstantView&);
00179 friend bool Gecode::before(const Gecode::Set::ConstantView&,
00180 const Gecode::Set::ConstantView&);
00181 private:
00182 int *ranges;
00183 unsigned int size;
00184 unsigned int domSize;
00185 public:
00187
00188
00189 ConstantView(void);
00191 ConstantView(Space* home, const IntSet& s);
00193
00195
00196
00197 unsigned int cardMin(void) const;
00199 unsigned int cardMax(void) const;
00201 int lubMin(void) const;
00203 int lubMax(void) const;
00205 int lubMinN(int n) const;
00207 int lubMaxN(int n) const;
00209 int glbMin(void) const;
00211 int glbMax(void) const;
00212
00214 unsigned int glbSize(void) const;
00216 unsigned int lubSize(void) const;
00218 unsigned int unknownSize(void) const;
00220
00222
00223
00224 bool assigned(void) const;
00226 bool contains(int i) const;
00228 bool notContains(int i) const;
00230
00231
00233
00234
00235 ModEvent cardMin(Space* home, unsigned int m);
00237 ModEvent cardMax(Space* home, unsigned int m);
00242 ModEvent include(Space* home,int i,int j);
00247 ModEvent exclude(Space* home,int i,int j);
00249 ModEvent include(Space* home,int i);
00251 ModEvent exclude(Space* home,int i);
00256 ModEvent intersect(Space* home,int i,int j);
00258 ModEvent intersect(Space* home,int i);
00260
00262
00263
00265 template <class I> ModEvent excludeI(Space* home, I& i);
00267 template <class I> ModEvent includeI(Space* home, I& i);
00269 template <class I> ModEvent intersectI(Space* home, I& iter);
00271
00273
00274
00275 static ModEvent pme(const Propagator* p);
00277 static PropModEvent pme(ModEvent);
00279
00281
00282
00283 void subscribe(Space* home, Propagator* p, PropCond pc);
00285 void cancel(Space* home, Propagator* p, PropCond pc);
00287
00289
00290
00291 void update(Space* home, bool share, ConstantView& x);
00293 };
00294
00295 }
00296
00301
00302 bool same(const Set::ConstantView& x, const Set::ConstantView& y);
00304 bool before(const Set::ConstantView& x, const Set::ConstantView& y);
00306
00313 template<>
00314 class ViewVarTraits<Set::ConstantView> {
00315 public:
00317 typedef VarBase Var;
00318 };
00319
00320 namespace Set {
00321
00330 class EmptyView : public ConstantViewBase {
00331 public:
00333
00334
00335 EmptyView(void);
00337
00339
00340
00342 unsigned int cardMin(void) const;
00344 unsigned int cardMax(void) const;
00346 int lubMin(void) const;
00348 int lubMax(void) const;
00350 int lubMinN(int n) const;
00352 int lubMaxN(int n) const;
00354 int glbMin(void) const;
00356 int glbMax(void) const;
00357
00359 unsigned int glbSize(void) const;
00361 unsigned int lubSize(void) const;
00363 unsigned int unknownSize(void) const;
00365
00367
00368
00369 bool assigned(void) const;
00371 bool contains(int i) const;
00373 bool notContains(int i) const;
00375
00376
00378
00379
00380 ModEvent cardMin(Space* home, unsigned int m);
00382 ModEvent cardMax(Space* home, unsigned int m);
00387 ModEvent include(Space* home,int i,int j);
00392 ModEvent exclude(Space* home,int i,int j);
00394 ModEvent include(Space* home,int i);
00396 ModEvent exclude(Space* home,int i);
00401 ModEvent intersect(Space* home,int i,int j);
00403 ModEvent intersect(Space* home,int i);
00405
00407
00408
00410 template <class I> ModEvent excludeI(Space* home, I& i);
00412 template <class I> ModEvent includeI(Space* home, I& i);
00414 template <class I> ModEvent intersectI(Space* home, I& iter);
00416
00418
00419
00420 static ModEvent pme(const Propagator* p);
00422 static PropModEvent pme(ModEvent);
00424
00426
00427
00428 void subscribe(Space* home, Propagator* p, PropCond pc);
00430 void cancel(Space* home, Propagator* p, PropCond pc);
00432
00434
00435
00436 void update(Space* home, bool share, EmptyView& x);
00438 };
00439
00440 }
00441
00446
00447 bool same(const Set::EmptyView& x, const Set::EmptyView& y);
00449 bool before(const Set::EmptyView& x, const Set::EmptyView& y);
00451
00458 template<>
00459 class ViewVarTraits<Set::EmptyView> {
00460 public:
00462 typedef VarBase Var;
00463 };
00464
00465 namespace Set {
00466
00467
00476 class UniverseView : public ConstantViewBase {
00477 public:
00479
00480
00481 UniverseView(void);
00483
00485
00486
00488 unsigned int cardMin(void) const;
00490 unsigned int cardMax(void) const;
00492 int lubMin(void) const;
00494 int lubMax(void) const;
00496 int lubMinN(int n) const;
00498 int lubMaxN(int n) const;
00500 int glbMin(void) const;
00502 int glbMax(void) const;
00503
00505 unsigned int glbSize(void) const;
00507 unsigned int lubSize(void) const;
00509 unsigned int unknownSize(void) const;
00511
00513
00514
00515 bool assigned(void) const;
00517 bool contains(int i) const;
00519 bool notContains(int i) const;
00521
00522
00524
00525
00526 ModEvent cardMin(Space* home, unsigned int m);
00528 ModEvent cardMax(Space* home, unsigned int m);
00533 ModEvent include(Space* home,int i,int j);
00538 ModEvent exclude(Space* home,int i,int j);
00540 ModEvent include(Space* home,int i);
00542 ModEvent exclude(Space* home,int i);
00547 ModEvent intersect(Space* home,int i,int j);
00549 ModEvent intersect(Space* home,int i);
00551
00553
00554
00556 template <class I> ModEvent excludeI(Space* home, I& i);
00558 template <class I> ModEvent includeI(Space* home, I& i);
00560 template <class I> ModEvent intersectI(Space* home, I& iter);
00562
00564
00565
00566 static ModEvent pme(const Propagator* p);
00568 static PropModEvent pme(ModEvent);
00570
00572
00573
00574 void subscribe(Space* home, Propagator* p, PropCond pc);
00576 void cancel(Space* home, Propagator* p, PropCond pc);
00578
00580
00581
00582 void update(Space* home, bool share, UniverseView& x);
00584 };
00585
00586 }
00587
00592
00593 bool same(const Set::UniverseView& x, const Set::UniverseView& y);
00595 bool before(const Set::UniverseView& x, const Set::UniverseView& y);
00597
00604 template<>
00605 class ViewVarTraits<Set::UniverseView> {
00606 public:
00608 typedef VarBase Var;
00609 };
00610
00611 namespace Set {
00612
00613
00614
00623 class SingletonView :
00624 public DerivedViewBase<Gecode::Int::IntView> {
00625 protected:
00626 using DerivedViewBase<Gecode::Int::IntView>::view;;
00627
00629 static PropCond pc_settoint(PropCond pc);
00631 static ModEvent me_inttoset(ModEvent me);
00632
00633 public:
00635
00636
00637 SingletonView(void);
00639 SingletonView(Gecode::Int::IntView& x);
00641
00643
00644
00646 unsigned int cardMin(void) const;
00648 unsigned int cardMax(void) const;
00650 int lubMin(void) const;
00652 int lubMax(void) const;
00654 int lubMinN(int n) const;
00656 int lubMaxN(int n) const;
00658 int glbMin(void) const;
00660 int glbMax(void) const;
00661
00663 unsigned int glbSize(void) const;
00665 unsigned int lubSize(void) const;
00667 unsigned int unknownSize(void) const;
00669
00671
00672
00673 bool assigned(void) const;
00675 bool contains(int i) const;
00677 bool notContains(int i) const;
00679
00680
00682
00683
00684 ModEvent cardMin(Space* home, unsigned int m);
00686 ModEvent cardMax(Space* home, unsigned int m);
00691 ModEvent include(Space* home,int i,int j);
00696 ModEvent exclude(Space* home,int i,int j);
00698 ModEvent include(Space* home,int i);
00700 ModEvent exclude(Space* home,int i);
00705 ModEvent intersect(Space* home,int i,int j);
00707 ModEvent intersect(Space* home,int i);
00709
00711
00712
00714 template <class I> ModEvent excludeI(Space* home, I& i);
00716 template <class I> ModEvent includeI(Space* home, I& i);
00718 template <class I> ModEvent intersectI(Space* home, I& iter);
00720
00722
00723
00724 static ModEvent pme(const Propagator* p);
00726 static PropModEvent pme(ModEvent);
00728
00730
00731
00732 void subscribe(Space* home, Propagator* p, PropCond pc);
00734 void cancel(Space* home, Propagator* p, PropCond pc);
00736
00737
00739
00740
00741 void update(Space* home, bool share, SingletonView& x);
00743 };
00744
00745 }
00746
00751
00752 bool same(const Set::SingletonView& x, const Set::SingletonView& y);
00754 bool before(const Set::SingletonView& x, const Set::SingletonView& y);
00756
00763 template<>
00764 class ViewVarTraits<Set::SingletonView> {
00765 public:
00767 typedef Int::IntVarImp Var;
00768 };
00769
00770 namespace Set {
00771
00772
00782 template <class View>
00783 class ComplementView
00784 : public DerivedViewBase<View> {
00785 protected:
00786 using DerivedViewBase<View>::view;
00787
00789 static PropCond pc_negateset(PropCond pc);
00791 static ModEvent me_negateset(ModEvent me);
00792
00793 public:
00795
00796
00797 ComplementView(void);
00799 ComplementView(View& x);
00801
00803
00804
00806 unsigned int cardMin(void) const;
00808 unsigned int cardMax(void) const;
00810 int lubMin(void) const;
00812 int lubMax(void) const;
00814 int lubMinN(int n) const;
00816 int lubMaxN(int n) const;
00818 int glbMin(void) const;
00820 int glbMax(void) const;
00821
00823 unsigned int glbSize(void) const;
00825 unsigned int lubSize(void) const;
00827 unsigned int unknownSize(void) const;
00829
00831
00832
00833 bool assigned(void) const;
00835 bool contains(int i) const;
00837 bool notContains(int i) const;
00839
00840
00842
00843
00844 ModEvent cardMin(Space* home, unsigned int m);
00846 ModEvent cardMax(Space* home, unsigned int m);
00851 ModEvent include(Space* home,int i,int j);
00856 ModEvent exclude(Space* home,int i,int j);
00858 ModEvent include(Space* home,int i);
00860 ModEvent exclude(Space* home,int i);
00865 ModEvent intersect(Space* home,int i,int j);
00867 ModEvent intersect(Space* home,int i);
00869
00871
00872
00874 template <class I> ModEvent excludeI(Space* home, I& i);
00876 template <class I> ModEvent includeI(Space* home, I& i);
00878 template <class I> ModEvent intersectI(Space* home, I& iter);
00880
00882
00883
00884 static ModEvent pme(const Propagator* p);
00886 static PropModEvent pme(ModEvent);
00888
00890
00891
00892 void subscribe(Space* home, Propagator* p, PropCond pc);
00894 void cancel(Space* home, Propagator* p, PropCond pc);
00896
00897
00899
00900
00901 void update(Space* home, bool share, ComplementView& x);
00903 };
00904
00905 }
00906
00911
00912 template <class View>
00913 bool same(const Set::ComplementView<View>& x,
00914 const Set::ComplementView<View>& y);
00916 template <class View>
00917 bool before(const Set::ComplementView<View>& x,
00918 const Set::ComplementView<View>& y);
00920
00921
00928 template <class View>
00929 class ViewVarTraits<Set::ComplementView<View> > {
00930 public:
00932 typedef typename ViewVarTraits<View>::Var Var;
00933 };
00934
00935 namespace Set {
00936
00945 template <class View>
00946 class ComplementView<ComplementView<View> > : public View {
00947 public:
00949
00950
00951 ComplementView(void);
00953 ComplementView(ComplementView<View>& x);
00955 };
00956
00957 }
00958
00963
00964 template <class View>
00965 bool same(const Set::ComplementView<Set::ComplementView<View> >& x,
00966 const Set::ComplementView<Set::ComplementView<View> >& y);
00968 template <class View>
00969 bool before(const Set::ComplementView<Set::ComplementView<View> >& x,
00970 const Set::ComplementView<Set::ComplementView<View> >& y);
00972
00973
00981 template <class View>
00982 class ViewVarTraits<Set::ComplementView<Set::ComplementView<View> > > {
00983 public:
00985 typedef typename ViewVarTraits<View>::Var Var;
00986 };
00987
00988 }
00989
00990 #include "gecode/set/view/set.icc"
00991 #include "gecode/set/view/const.icc"
00992 #include "gecode/set/view/singleton.icc"
00993 #include "gecode/set/view/complement.icc"
00994
00999 GECODE_SET_EXPORT std::ostream&
01000 operator<<(std::ostream&, const Gecode::Set::SetView&);
01001
01002
01007 GECODE_SET_EXPORT std::ostream&
01008 operator<<(std::ostream&, const Gecode::Set::EmptyView&);
01009
01014 GECODE_SET_EXPORT std::ostream&
01015 operator<<(std::ostream&, const Gecode::Set::UniverseView&);
01016
01021 GECODE_SET_EXPORT std::ostream&
01022 operator<<(std::ostream&, const Gecode::Set::ConstantView&);
01023
01028 GECODE_SET_EXPORT std::ostream&
01029 operator<<(std::ostream&, const Gecode::Set::SingletonView&);
01030
01035 template <class View>
01036 std::ostream&
01037 operator<<(std::ostream&, const Gecode::Set::ComplementView<View>&);
01038
01039 inline std::ostream&
01040 operator<<(std::ostream& os, const Gecode::SetVar& x) {
01041 Gecode::Set::SetView vx(x);
01042 return os << vx;
01043 }
01044
01045