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 Distinct {
00046
00052
00053 static IntSet ds_33(-2,2);
00054 static IntSet ds_44(-4,4);
00055
00057 class AtmostOne : public SetTest {
00058 public:
00060 AtmostOne(const char* t)
00061 : SetTest(t,3,ds_33,false) {}
00063 virtual bool solution(const SetAssignment& x) const {
00064 {
00065 CountableSetRanges xr0(x.lub, x[0]);
00066 CountableSetRanges xr1(x.lub, x[1]);
00067 Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
00068 i(xr0,xr1);
00069 if (Iter::Ranges::size(i)>1)
00070 return false;
00071 }
00072 {
00073 CountableSetRanges xr0(x.lub, x[0]);
00074 CountableSetRanges xr2(x.lub, x[2]);
00075 Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
00076 i(xr0,xr2);
00077 if (Iter::Ranges::size(i)>1)
00078 return false;
00079 }
00080 {
00081 CountableSetRanges xr1(x.lub, x[1]);
00082 CountableSetRanges xr2(x.lub, x[2]);
00083 Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
00084 i(xr1,xr2);
00085 if (Iter::Ranges::size(i)>1)
00086 return false;
00087 }
00088 {
00089 CountableSetRanges xr0(x.lub, x[0]);
00090 CountableSetRanges xr1(x.lub, x[1]);
00091 CountableSetRanges xr2(x.lub, x[2]);
00092 if (Iter::Ranges::size(xr0)!=3 ||
00093 Iter::Ranges::size(xr1)!=3 ||
00094 Iter::Ranges::size(xr2)!=3)
00095 return false;
00096 }
00097 return true;
00098 }
00100 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
00101 SetVar s1(home, IntSet::empty, -2, 2, 0,1);
00102 Gecode::rel(home, x[0], SOT_INTER, x[1], SRT_EQ, s1);
00103 SetVar s2(home, IntSet::empty, -2, 2, 0,1);
00104 Gecode::rel(home, x[0], SOT_INTER, x[2], SRT_EQ, s2);
00105 SetVar s3(home, IntSet::empty, -2, 2, 0,1);
00106 Gecode::rel(home, x[1], SOT_INTER, x[2], SRT_EQ, s3);
00107 Gecode::atmostOne(home, x, 3);
00108 }
00109 };
00110 AtmostOne _atmostone("Distinct::AtmostOne");
00111
00113
00114 }}}
00115
00116