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/cpltset.hh"
00039
00040 using namespace Gecode;
00041 using namespace Test::Set;
00042
00043 namespace Test { namespace CpltSet {
00044
00046 namespace Partition {
00047
00053
00054 static const int d1r[2][2] = {
00055 {-4,-4},{3,5}
00056 };
00057 static IntSet d1(d1r,2);
00058
00059 static IntSet ds_33(-3,3);
00060 static IntSet ds_4(4,4);
00061 static IntSet ds_13(1,3);
00062
00064 class CpltSetPartition : public CpltSetTest {
00065 public:
00067 CpltSetPartition(const char* t) : CpltSetTest(t,2,ds_13,false) {}
00069 virtual bool solution(const SetAssignment& x) const {
00070 CountableSetRanges xr1(x.lub, x[0]);
00071 CountableSetRanges xr2(x.lub, x[1]);
00072
00073 Iter::Ranges::Inter<CountableSetRanges, CountableSetRanges>
00074 d(xr1, xr2);
00075 Iter::Ranges::Union<CountableSetRanges, CountableSetRanges>
00076 u(xr1, xr2);
00077 IntSetRanges ir(ds_13);
00078
00079 bool empty = !d();
00080 bool same = Iter::Ranges::equal(u, ir);
00081
00082 return empty && same;
00083 }
00084
00086 virtual void post(Space* home, CpltSetVarArray& x, IntVarArray&) {
00087
00088 Gecode::partition(home, x);
00089 }
00090 };
00091 CpltSetPartition _cpltsetpartition("Partition");
00092
00094 class CpltSetPartitionLex : public CpltSetTest {
00095 public:
00097 CpltSetPartitionLex(const char* t) : CpltSetTest(t,2,ds_13,false) {}
00099 virtual bool solution(const SetAssignment& x) const {
00100 CountableSetRanges xr1(x.lub, x[0]);
00101 CountableSetRanges xr2(x.lub, x[1]);
00102
00103 Iter::Ranges::Inter<CountableSetRanges, CountableSetRanges>
00104 d(xr1, xr2);
00105 Iter::Ranges::Union<CountableSetRanges, CountableSetRanges>
00106 u(xr1, xr2);
00107 IntSetRanges ir(ds_13);
00108
00109 bool empty = !d();
00110 bool same = Iter::Ranges::equal(u, ir);
00111
00112 CountableSetValues xv1(x.lub, x[0]);
00113 CountableSetValues xv2(x.lub, x[1]);
00114 int a = iter2int(xv1, 3);
00115 int b = iter2int(xv2, 3);
00116
00117 return empty && same && (a < b);
00118 }
00119
00121 virtual void post(Space* home, CpltSetVarArray& x, IntVarArray&) {
00122 Gecode::partitionLex(home, x, SRT_LE);
00123 }
00124 };
00125 CpltSetPartitionLex _cpltsetpartitionlex("Partition::Lex");
00126
00128 class CpltSetPartitionNaryOne : public CpltSetTest {
00129 public:
00131 CpltSetPartitionNaryOne(const char* t)
00132 : CpltSetTest(t,3,ds_13,false, 0, 200, 10) {}
00134 virtual bool solution(const SetAssignment& x) const {
00135 CountableSetRanges xr1(x.lub, x[0]);
00136 CountableSetRanges xr2(x.lub, x[1]);
00137 CountableSetRanges xr3(x.lub, x[2]);
00138
00139 Iter::Ranges::Inter<CountableSetRanges, CountableSetRanges>
00140 d(xr1, xr2);
00141 Iter::Ranges::Union<CountableSetRanges, CountableSetRanges>
00142 u(xr1, xr2);
00143
00144 bool empty = !d();
00145 bool same = Iter::Ranges::equal(u, xr3);
00146
00147 return empty && same;
00148 }
00149
00151 virtual void post(Space* home, CpltSetVarArray& x, IntVarArray&) {
00152
00153 int n = x.size() - 1;
00154 CpltSetVarArgs z(n);
00155 for (int i = 0; i < n; i++)
00156 z[i] = x[i];
00157 CpltSetVar y = x[n];
00158 partition(home, z, y);
00159 }
00160 };
00161 CpltSetPartitionNaryOne _cpltsetpartitionnaryone("Partition::NaryOne");
00162
00164 class CpltSetPartitionNaryOneBigger : public CpltSetTest {
00165 public:
00167 CpltSetPartitionNaryOneBigger(const char* t)
00168 : CpltSetTest(t,3,d1,false, 0, 200, 80) {}
00170 virtual bool solution(const SetAssignment& x) const {
00171 CountableSetRanges xr1(x.lub, x[0]);
00172 CountableSetRanges xr2(x.lub, x[1]);
00173 CountableSetRanges xr3(x.lub, x[2]);
00174 Iter::Ranges::Cache<CountableSetRanges> cxr3(xr3);
00175
00176 Iter::Ranges::Inter<CountableSetRanges, CountableSetRanges>
00177 d(xr1, xr2);
00178 Iter::Ranges::Union<CountableSetRanges, CountableSetRanges>
00179 u(xr1, xr2);
00180
00181 bool empty = !d();
00182 bool same = Iter::Ranges::equal(u, cxr3);
00183
00184 cxr3.reset();
00185 Iter::Ranges::Singleton m(3,5);
00186
00187 bool fixed = Iter::Ranges::equal(m, cxr3);
00188
00189 return empty && same && fixed;
00190 }
00191
00193 virtual void post(Space* home, CpltSetVarArray& x, IntVarArray&) {
00194 int n = x.size() - 1;
00195 CpltSetVarArgs z(n);
00196 for (int i = 0; i < n; i++)
00197 z[i] = x[i];
00198 CpltSetVar y = x[n];
00199 partition(home, z, y);
00200 dom(home, y, SRT_EQ, 3, 5);
00201 }
00202 };
00203 CpltSetPartitionNaryOneBigger
00204 _cpltsetpartitionnaryonebigger("Partition::NaryOne::Bigger");
00205
00207
00208 }}}
00209
00210