set-op.hpp
Go to the documentation of this file.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 namespace Gecode { namespace Int { namespace Sequence {
00035
00037 enum TakesStatus {
00038 TS_NO,
00039 TS_YES,
00040 TS_MAYBE
00041 };
00042
00044 template<class View>
00045 forceinline TakesStatus
00046 takes(const View& x, int s) {
00047 if (x.in(s))
00048 return x.assigned() ? TS_YES : TS_MAYBE;
00049 else
00050 return TS_NO;
00051 }
00053 template<class View>
00054 forceinline TakesStatus
00055 takes(const View& x, const IntSet& s) {
00056 if ((x.max() < s.min()) || (x.min() > s.max()))
00057 return TS_NO;
00058 ViewRanges<View> ix(x);
00059 IntSetRanges is(s);
00060 switch (Iter::Ranges::compare(ix,is)) {
00061 case Iter::Ranges::CS_SUBSET: return TS_YES;
00062 case Iter::Ranges::CS_DISJOINT: return TS_NO;
00063 case Iter::Ranges::CS_NONE: return TS_MAYBE;
00064 default: GECODE_NEVER;
00065 }
00066 return TS_MAYBE;
00067 }
00068
00070 template<class View>
00071 forceinline bool
00072 includes(const View& x, int s) {
00073 return x.assigned() && x.in(s);
00074 }
00076 template<class View>
00077 forceinline bool
00078 includes(const View& x, const IntSet& s) {
00079 if ((x.max() < s.min()) || (x.min() > s.max()))
00080 return false;
00081 ViewRanges<View> ix(x);
00082 IntSetRanges is(s);
00083 return Iter::Ranges::subset(ix,is);
00084 }
00085
00087 template<class View>
00088 forceinline bool
00089 excludes(const View& x, int s) {
00090 return !x.in(s);
00091 }
00093 template<class View>
00094 forceinline bool
00095 excludes(const View& x, const IntSet& s) {
00096 if ((x.max() < s.min()) || (x.min() > s.max()))
00097 return true;
00098 ViewRanges<View> ix(x);
00099 IntSetRanges is(s);
00100 return Iter::Ranges::disjoint(ix,is);
00101 }
00102
00104 template<class View>
00105 forceinline bool
00106 undecided(const View& x, int s) {
00107 return !x.assigned() && x.in(s);
00108 }
00110 template<class View>
00111 forceinline bool
00112 undecided(const View& x, const IntSet& s) {
00113 if ((x.max() < s.min()) || (x.min() > s.max()))
00114 return false;
00115 ViewRanges<View> ix(x);
00116 IntSetRanges is(s);
00117 return Iter::Ranges::compare(ix,is) == Iter::Ranges::CS_NONE;
00118 }
00119
00121 template<class View>
00122 forceinline ModEvent
00123 include(Space& home, View& x, int s) {
00124 return x.eq(home,s);
00125 }
00127 template<class View>
00128 forceinline ModEvent
00129 include(Space& home, View& x, const IntSet& s) {
00130 IntSetRanges is(s);
00131 return x.inter_r(home,is,false);
00132 }
00133
00135 template<class View>
00136 forceinline ModEvent
00137 exclude(Space& home, View& x, int s) {
00138 return x.nq(home,s);
00139 }
00141 template<class View>
00142 forceinline ModEvent
00143 exclude(Space& home, View& x, const IntSet& s) {
00144 IntSetRanges is(s);
00145 return x.minus_r(home,is,false);
00146 }
00147
00148 }}}
00149
00150