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 <gecode/minimodel.hh>
00039
00040 #include "test/set.hh"
00041
00042 using namespace Gecode;
00043
00044 namespace Test { namespace Set {
00045
00047 namespace Rel {
00048
00054
00055 static IntSet ds_33(-3,3);
00056 static IntSet ds_03(0,3);
00057
00059 class RelBin : public SetTest {
00060 private:
00061 Gecode::SetRelType srt;
00062 bool shared;
00063 public:
00065 RelBin(Gecode::SetRelType srt0, bool shared0)
00066 : SetTest("Rel::Bin::"+str(srt0)+"::S"+(shared0 ? "1":"0"),
00067 shared0 ? 1 : 2,ds_33,true)
00068 , srt(srt0), shared(shared0){}
00069 int minSymDiff(const SetAssignment& x) const {
00070 int x1 = shared ? x[0] : x[1];
00071 typedef Iter::Ranges::Diff<CountableSetRanges,CountableSetRanges> Diff;
00072 CountableSetRanges xr00(x.lub, x[0]);
00073 CountableSetRanges xr10(x.lub, x1);
00074 Diff a(xr00,xr10);
00075 CountableSetRanges xr01(x.lub, x[0]);
00076 CountableSetRanges xr11(x.lub, x1);
00077 Diff b(xr11,xr01);
00078 Iter::Ranges::Union<Diff,Diff> u(a,b);
00079 return u() ? u.min() : Gecode::Set::Limits::max+1;
00080 }
00081 bool in(int i, CountableSetRanges& c, bool eq=false) const {
00082 if (eq && i==Gecode::Set::Limits::max+1)
00083 return true;
00084 Iter::Ranges::Singleton s(i,i);
00085 return Iter::Ranges::subset(s,c);
00086 }
00088 bool solution(const SetAssignment& x) const {
00089 int x1 = shared ? x[0] : x[1];
00090 CountableSetRanges xr0(x.lub, x[0]);
00091 CountableSetRanges xr1(x.lub, x1);
00092 switch (srt) {
00093 case SRT_EQ: return Iter::Ranges::equal(xr0, xr1);
00094 case SRT_NQ: return !Iter::Ranges::equal(xr0, xr1);
00095
00096 case SRT_LQ: return (!xr0()) || in(minSymDiff(x),xr1,true);
00097 case SRT_LE: return xr0() ? in(minSymDiff(x),xr1) : xr1();
00098 case SRT_GQ: return (!xr1()) || in(minSymDiff(x),xr0,true);
00099 case SRT_GR: return xr1() ? in(minSymDiff(x),xr0) : xr0();
00100
00101 case SRT_SUB: return Iter::Ranges::subset(xr0, xr1);
00102 case SRT_SUP: return Iter::Ranges::subset(xr1, xr0);
00103 case SRT_DISJ:
00104 {
00105 Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
00106 inter(xr0,xr1);
00107 return !inter();
00108 }
00109 case SRT_CMPL:
00110 {
00111 Gecode::Set::RangesCompl<CountableSetRanges> rc(xr0);
00112 return Iter::Ranges::equal(rc,xr1);
00113 }
00114 default:
00115 GECODE_NEVER;
00116 }
00117 GECODE_NEVER;
00118 return false;
00119 }
00121 void post(Space& home, SetVarArray& x, IntVarArray&) {
00122 if (!shared)
00123 Gecode::rel(home, x[0], srt, x[1]);
00124 else
00125 Gecode::rel(home, x[0], srt, x[0]);
00126 }
00128 void post(Space& home, SetVarArray& x, IntVarArray&, Reify r) {
00129 if (!shared)
00130 Gecode::rel(home, x[0], srt, x[1], r);
00131 else
00132 Gecode::rel(home, x[0], srt, x[0], r);
00133 }
00134 };
00135
00137 class ITE : public SetTest {
00138 public:
00140 ITE(void)
00141 : SetTest("ITE",3,ds_03,false,1) {}
00143 virtual bool solution(const SetAssignment& x) const {
00144 if ((x.intval() < 0) || (x.intval() > 1))
00145 return false;
00146 if (x.intval() == 1) {
00147 CountableSetRanges xr0(x.lub, x[0]);
00148 CountableSetRanges xr2(x.lub, x[2]);
00149 return Iter::Ranges::equal(xr0,xr2);
00150 } else {
00151 CountableSetRanges xr1(x.lub, x[1]);
00152 CountableSetRanges xr2(x.lub, x[2]);
00153 return Iter::Ranges::equal(xr1,xr2);
00154 }
00155 }
00157 void post(Space& home, SetVarArray& x, IntVarArray& y) {
00158 Gecode::ite(home, Gecode::channel(home,y[0]), x[0], x[1], x[2]);
00159 }
00160 };
00161
00162 RelBin _relbin_eq(Gecode::SRT_EQ,false);
00163 RelBin _relbin_lq(Gecode::SRT_LQ,false);
00164 RelBin _relbin_le(Gecode::SRT_LE,false);
00165 RelBin _relbin_gq(Gecode::SRT_GQ,false);
00166 RelBin _relbin_gr(Gecode::SRT_GR,false);
00167 RelBin _relbin_nq(Gecode::SRT_NQ,false);
00168 RelBin _relbin_sub(Gecode::SRT_SUB,false);
00169 RelBin _relbin_sup(Gecode::SRT_SUP,false);
00170 RelBin _relbin_disj(Gecode::SRT_DISJ,false);
00171 RelBin _relbin_cmpl(Gecode::SRT_CMPL,false);
00172 RelBin _relbin_shared_eq(Gecode::SRT_EQ,true);
00173 RelBin _relbin_shared_lq(Gecode::SRT_LQ,true);
00174 RelBin _relbin_shared_le(Gecode::SRT_LE,true);
00175 RelBin _relbin_shared_gq(Gecode::SRT_GQ,true);
00176 RelBin _relbin_shared_gr(Gecode::SRT_GR,true);
00177 RelBin _relbin_shared_nq(Gecode::SRT_NQ,true);
00178 RelBin _relbin_shared_sub(Gecode::SRT_SUB,true);
00179 RelBin _relbin_shared_sup(Gecode::SRT_SUP,true);
00180 RelBin _relbin_shared_disj(Gecode::SRT_DISJ,true);
00181 RelBin _relbin_shared_cmpl(Gecode::SRT_CMPL,true);
00182
00183 ITE _ite;
00185
00186 }}}
00187
00188