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 #include "test/set.hh"
00039
00040 using namespace Gecode;
00041
00042 namespace Test { namespace Set {
00043
00045 namespace Rel {
00046
00052
00053 static IntSet ds_33(-3,3);
00054
00056 class RelBin : public SetTest {
00057 private:
00058 Gecode::SetRelType srt;
00059 bool shared;
00060 public:
00062 RelBin(Gecode::SetRelType srt0, bool shared0)
00063 : SetTest("Rel::Bin::"+str(srt0)+"::S"+(shared0 ? "1":"0"),
00064 shared ? 1 : 2,ds_33,true)
00065 , srt(srt0), shared(shared0){}
00066 int minSymDiff(const SetAssignment& x) const {
00067 int x1 = shared ? x[0] : x[1];
00068 typedef Iter::Ranges::Diff<CountableSetRanges,CountableSetRanges> Diff;
00069 CountableSetRanges xr00(x.lub, x[0]);
00070 CountableSetRanges xr10(x.lub, x1);
00071 Diff a(xr00,xr10);
00072 CountableSetRanges xr01(x.lub, x[0]);
00073 CountableSetRanges xr11(x.lub, x1);
00074 Diff b(xr11,xr01);
00075 Iter::Ranges::Union<Diff,Diff> u(a,b);
00076 return u() ? u.min() : Gecode::Set::Limits::max+1;
00077 }
00078 bool in(int i, CountableSetRanges& c, bool eq=false) const {
00079 if (eq && i==Gecode::Set::Limits::max+1)
00080 return true;
00081 Iter::Ranges::Singleton s(i,i);
00082 return Iter::Ranges::subset(s,c);
00083 }
00085 bool solution(const SetAssignment& x) const {
00086 int x1 = shared ? x[0] : x[1];
00087 CountableSetRanges xr0(x.lub, x[0]);
00088 CountableSetRanges xr1(x.lub, x1);
00089 switch (srt) {
00090 case SRT_EQ: return Iter::Ranges::equal(xr0, xr1);
00091 case SRT_NQ: return !Iter::Ranges::equal(xr0, xr1);
00092
00093 case SRT_LQ: return (!xr0()) || in(minSymDiff(x),xr1,true);
00094 case SRT_LE: return xr0() ? in(minSymDiff(x),xr1) : xr1();
00095 case SRT_GQ: return (!xr1()) || in(minSymDiff(x),xr0,true);
00096 case SRT_GR: return xr1() ? in(minSymDiff(x),xr0) : xr0();
00097
00098 case SRT_SUB: return Iter::Ranges::subset(xr0, xr1);
00099 case SRT_SUP: return Iter::Ranges::subset(xr1, xr0);
00100 case SRT_DISJ:
00101 {
00102 Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
00103 inter(xr0,xr1);
00104 return !inter();
00105 }
00106 case SRT_CMPL:
00107 {
00108 Gecode::Set::RangesCompl<CountableSetRanges> rc(xr0);
00109 return Iter::Ranges::equal(rc,xr1);
00110 }
00111 default:
00112 GECODE_NEVER;
00113 }
00114 GECODE_NEVER;
00115 return false;
00116 }
00118 void post(Space& home, SetVarArray& x, IntVarArray&) {
00119 if (!shared)
00120 Gecode::rel(home, x[0], srt, x[1]);
00121 else
00122 Gecode::rel(home, x[0], srt, x[0]);
00123 }
00125 void post(Space& home, SetVarArray& x, IntVarArray&, BoolVar b) {
00126 if (!shared)
00127 Gecode::rel(home, x[0], srt, x[1], b);
00128 else
00129 Gecode::rel(home, x[0], srt, x[0], b);
00130 }
00131 };
00132 RelBin _relbin_eq(Gecode::SRT_EQ,false);
00133 RelBin _relbin_lq(Gecode::SRT_LQ,false);
00134 RelBin _relbin_le(Gecode::SRT_LE,false);
00135 RelBin _relbin_gq(Gecode::SRT_GQ,false);
00136 RelBin _relbin_gr(Gecode::SRT_GR,false);
00137 RelBin _relbin_nq(Gecode::SRT_NQ,false);
00138 RelBin _relbin_sub(Gecode::SRT_SUB,false);
00139 RelBin _relbin_sup(Gecode::SRT_SUP,false);
00140 RelBin _relbin_disj(Gecode::SRT_DISJ,false);
00141 RelBin _relbin_cmpl(Gecode::SRT_CMPL,false);
00142 RelBin _relbin_shared_eq(Gecode::SRT_EQ,true);
00143 RelBin _relbin_shared_lq(Gecode::SRT_LQ,true);
00144 RelBin _relbin_shared_le(Gecode::SRT_LE,true);
00145 RelBin _relbin_shared_gq(Gecode::SRT_GQ,true);
00146 RelBin _relbin_shared_gr(Gecode::SRT_GR,true);
00147 RelBin _relbin_shared_nq(Gecode::SRT_NQ,true);
00148 RelBin _relbin_shared_sub(Gecode::SRT_SUB,true);
00149 RelBin _relbin_shared_sup(Gecode::SRT_SUP,true);
00150 RelBin _relbin_shared_disj(Gecode::SRT_DISJ,true);
00151 RelBin _relbin_shared_cmpl(Gecode::SRT_CMPL,true);
00152
00154
00155 }}}
00156
00157