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/int.hh"
00039
00040 #include "gecode/minimodel.hh"
00041
00042 namespace Test { namespace Int {
00043
00045 namespace Rel {
00046
00052
00053 class IntVarXY : public Test {
00054 protected:
00056 Gecode::IntRelType irt;
00057 public:
00059 IntVarXY(Gecode::IntRelType irt0, int n, Gecode::IntConLevel icl)
00060 : Test("Rel::Int::Var::XY::"+str(irt0)+"::"+str(icl)+"::"+str(n),
00061 n+1,-3,3,n==1,icl),
00062 irt(irt0) {}
00064 virtual bool solution(const Assignment& x) const {
00065 if (x.size() == 2) {
00066 return cmp(x[0],irt,x[1]);
00067 } else {
00068 return cmp(x[0],irt,x[2]) && cmp(x[1],irt,x[2]);
00069 }
00070 }
00072 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00073 using namespace Gecode;
00074 if (x.size() == 2) {
00075 rel(home, x[0], irt, x[1], icl);
00076 } else {
00077 IntVarArgs y(2);
00078 y[0]=x[0]; y[1]=x[1];
00079 rel(home, y, irt, x[2], icl);
00080 }
00081 }
00083 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x,
00084 Gecode::BoolVar b) {
00085 assert(x.size() == 2);
00086 Gecode::rel(home, x[0], irt, x[1], b, icl);
00087 }
00088 };
00089
00091 class IntVarXX : public Test {
00092 protected:
00094 Gecode::IntRelType irt;
00095 public:
00097 IntVarXX(Gecode::IntRelType irt0, Gecode::IntConLevel icl)
00098 : Test("Rel::Int::Var::XX::"+str(irt0)+"::"+str(icl),
00099 1,-3,3,true,icl),
00100 irt(irt0) {
00101 testdomcon = ((irt != Gecode::IRT_LE) &&
00102 (irt != Gecode::IRT_GR) &&
00103 (irt != Gecode::IRT_NQ));
00104 }
00106 virtual bool solution(const Assignment& x) const {
00107 return cmp(x[0],irt,x[0]);
00108 }
00110 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00111 Gecode::rel(home, x[0], irt, x[0], icl);
00112 }
00114 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x,
00115 Gecode::BoolVar b) {
00116 Gecode::rel(home, x[0], irt, x[0], b, icl);
00117 }
00118 };
00119
00121 class BoolVarXY : public Test {
00122 protected:
00124 Gecode::IntRelType irt;
00125 public:
00127 BoolVarXY(Gecode::IntRelType irt0, int n)
00128 : Test("Rel::Bool::Var::XY::"+str(irt0)+"::"+str(n),n+1,0,1),
00129 irt(irt0) {}
00131 virtual bool solution(const Assignment& x) const {
00132 if (x.size() == 2) {
00133 return cmp(x[0],irt,x[1]);
00134 } else {
00135 return cmp(x[0],irt,x[2]) && cmp(x[1],irt,x[2]);
00136 }
00137 }
00139 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00140 using namespace Gecode;
00141 if (x.size() == 2) {
00142 rel(home, channel(home,x[0]), irt, channel(home,x[1]));
00143 } else {
00144 BoolVarArgs y(2);
00145 y[0]=channel(home,x[0]); y[1]=channel(home,x[1]);
00146 rel(home, y, irt, channel(home,x[2]));
00147 }
00148 }
00149 };
00150
00152 class BoolVarXX : public Test {
00153 protected:
00155 Gecode::IntRelType irt;
00156 public:
00158 BoolVarXX(Gecode::IntRelType irt0)
00159 : Test("Rel::Bool::Var::XX::"+str(irt0),1,0,1),
00160 irt(irt0) {
00161 testdomcon = ((irt != Gecode::IRT_LE) &&
00162 (irt != Gecode::IRT_GR) &&
00163 (irt != Gecode::IRT_NQ));
00164 }
00166 virtual bool solution(const Assignment& x) const {
00167 return cmp(x[0],irt,x[0]);
00168 }
00170 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00171 Gecode::BoolVar b = Gecode::channel(home,x[0]);
00172 Gecode::rel(home, b, irt, b);
00173 }
00174 };
00175
00177 class IntInt : public Test {
00178 protected:
00180 Gecode::IntRelType irt;
00182 int c;
00183 public:
00185 IntInt(Gecode::IntRelType irt0, int n, int c0)
00186 : Test("Rel::Int::Int::"+str(irt0)+"::"+str(n)+"::"+str(c0),
00187 n,-3,3,n==1),
00188 irt(irt0), c(c0) {}
00190 virtual bool solution(const Assignment& x) const {
00191 if (x.size() == 1)
00192 return cmp(x[0],irt,c);
00193 else
00194 return cmp(x[0],irt,c) && cmp(x[1],irt,c);
00195 }
00197 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00198 using namespace Gecode;
00199 if (x.size() == 1)
00200 rel(home, x[0], irt, c);
00201 else
00202 rel(home, x, irt, c);
00203 }
00205 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x,
00206 Gecode::BoolVar b) {
00207 assert(x.size() == 1);
00208 Gecode::rel(home, x[0], irt, c, b);
00209 }
00210 };
00211
00213 class BoolInt : public Test {
00214 protected:
00216 Gecode::IntRelType irt;
00218 int c;
00219 public:
00221 BoolInt(Gecode::IntRelType irt0, int n, int c0)
00222 : Test("Rel::Bool::Int::"+str(irt0)+"::"+str(n)+"::"+str(c0),n,0,1),
00223 irt(irt0), c(c0) {}
00225 virtual bool solution(const Assignment& x) const {
00226 if (x.size() == 1)
00227 return cmp(x[0],irt,c);
00228 else
00229 return cmp(x[0],irt,c) && cmp(x[1],irt,c);
00230 }
00232 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00233 using namespace Gecode;
00234 if (x.size() == 1) {
00235 rel(home, channel(home,x[0]), irt, c);
00236 } else {
00237 BoolVarArgs y(2);
00238 y[0]=channel(home,x[0]); y[1]=channel(home,x[1]);
00239 rel(home, y, irt, c);
00240 }
00241 }
00242 };
00243
00245 class IntPairwise : public Test {
00246 protected:
00248 Gecode::IntRelType irt;
00249 public:
00251 IntPairwise(Gecode::IntRelType irt0, Gecode::IntConLevel icl)
00252 : Test("Rel::Int::Pairwise::"+str(irt0)+"::"+str(icl),
00253 4,-3,3,false,icl),
00254 irt(irt0) {}
00256 virtual bool solution(const Assignment& x) const {
00257 for (int i=0; i<x.size(); i++)
00258 for (int j=i+1; j<x.size(); j++)
00259 if (!cmp(x[i],irt,x[j]))
00260 return false;
00261 return true;
00262 }
00264 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00265 Gecode::rel(home, x, irt, icl);
00266 }
00267 };
00268
00270 class BoolPairwise : public Test {
00271 protected:
00273 Gecode::IntRelType irt;
00274 public:
00276 BoolPairwise(Gecode::IntRelType irt0)
00277 : Test("Rel::Bool::Pairwise::"+str(irt0),8,0,1),
00278 irt(irt0) {}
00280 virtual bool solution(const Assignment& x) const {
00281 for (int i=0; i<x.size(); i++)
00282 for (int j=i+1; j<x.size(); j++)
00283 if (!cmp(x[i],irt,x[j]))
00284 return false;
00285 return true;
00286 }
00288 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00289 using namespace Gecode;
00290 BoolVarArgs b(x.size());
00291 for (int i=x.size(); i--; )
00292 b[i]=channel(home,x[i]);
00293 rel(home, b, irt);
00294 }
00295 };
00296
00298 class IntArray : public Test {
00299 protected:
00301 Gecode::IntRelType irt;
00302 public:
00304 IntArray(Gecode::IntRelType irt0)
00305 : Test("Rel::Int::Array::"+str(irt0),6,-2,2), irt(irt0) {}
00307 virtual bool solution(const Assignment& x) const {
00308 int n=x.size() >> 1;
00309 for (int i=0; i<n; i++)
00310 if (x[i] != x[n+i])
00311 return cmp(x[i],irt,x[n+i]);
00312 return ((irt == Gecode::IRT_LQ) || (irt == Gecode::IRT_GQ) ||
00313 (irt == Gecode::IRT_EQ));
00314 GECODE_NEVER;
00315 return false;
00316 }
00318 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00319 using namespace Gecode;
00320 int n=x.size() >> 1;
00321 IntVarArgs y(n); IntVarArgs z(n);
00322 for (int i=0; i<n; i++) {
00323 y[i]=x[i]; z[i]=x[n+i];
00324 }
00325 rel(home, y, irt, z);
00326 }
00327 };
00328
00330 class BoolArray : public Test {
00331 protected:
00333 Gecode::IntRelType irt;
00334 public:
00336 BoolArray(Gecode::IntRelType irt0)
00337 : Test("Rel::Bool::Array::"+str(irt0),10,0,1), irt(irt0) {}
00339 virtual bool solution(const Assignment& x) const {
00340 int n=x.size() >> 1;
00341 for (int i=0; i<n; i++)
00342 if (x[i] != x[n+i])
00343 return cmp(x[i],irt,x[n+i]);
00344 return ((irt == Gecode::IRT_LQ) || (irt == Gecode::IRT_GQ) ||
00345 (irt == Gecode::IRT_EQ));
00346 GECODE_NEVER;
00347 return false;
00348 }
00350 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00351 using namespace Gecode;
00352 int n=x.size() >> 1;
00353 BoolVarArgs y(n); BoolVarArgs z(n);
00354 for (int i=0; i<n; i++) {
00355 y[i]=channel(home,x[i]); z[i]=channel(home,x[n+i]);
00356 }
00357 rel(home, y, irt, z);
00358 }
00359 };
00360
00362 class Create {
00363 public:
00365 Create(void) {
00366 using namespace Gecode;
00367 for (IntRelTypes irts; irts(); ++irts) {
00368 for (IntConLevels icls; icls(); ++icls) {
00369 (void) new IntVarXY(irts.irt(),1,icls.icl());
00370 (void) new IntVarXY(irts.irt(),2,icls.icl());
00371 (void) new IntVarXX(irts.irt(),icls.icl());
00372 (void) new IntPairwise(irts.irt(),icls.icl());
00373 }
00374 (void) new BoolVarXY(irts.irt(),1);
00375 (void) new BoolVarXY(irts.irt(),2);
00376 (void) new BoolVarXX(irts.irt());
00377 (void) new BoolPairwise(irts.irt());
00378 for (int c=-4; c<=4; c++) {
00379 (void) new IntInt(irts.irt(),1,c);
00380 (void) new IntInt(irts.irt(),2,c);
00381 }
00382 for (int c=0; c<=1; c++) {
00383 (void) new BoolInt(irts.irt(),1,c);
00384 (void) new BoolInt(irts.irt(),2,c);
00385 }
00386 (void) new IntArray(irts.irt());
00387 (void) new BoolArray(irts.irt());
00388 }
00389 }
00390 };
00391
00392 Create c;
00394
00395 }
00396 }}
00397
00398