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 Bool {
00046
00047 inline int
00048 check(int x0, Gecode::BoolOpType op, int x1) {
00049 switch (op) {
00050 case Gecode::BOT_AND: return x0 & x1;
00051 case Gecode::BOT_OR: return x0 | x1;
00052 case Gecode::BOT_IMP: return !x0 | x1;
00053 case Gecode::BOT_EQV: return x0 == x1;
00054 case Gecode::BOT_XOR: return x0 != x1;
00055 default: GECODE_NEVER;
00056 }
00057 GECODE_NEVER;
00058 return 0;
00059 }
00060
00066
00067 class BinXYZ : public Test {
00068 protected:
00070 Gecode::BoolOpType op;
00071 public:
00073 BinXYZ(Gecode::BoolOpType op0)
00074 : Test("Bool::Bin::XYZ::"+str(op0),3,0,1), op(op0) {}
00076 virtual bool solution(const Assignment& x) const {
00077 return check(x[0],op,x[1]) == x[2];
00078 }
00080 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00081 using namespace Gecode;
00082 rel(home,
00083 channel(home,x[0]), op, channel(home,x[1]),
00084 channel(home,x[2]));
00085 }
00086 };
00087
00089 class BinXXY : public Test {
00090 protected:
00092 Gecode::BoolOpType op;
00093 public:
00095 BinXXY(Gecode::BoolOpType op0)
00096 : Test("Bool::Bin::XXY::"+str(op0),2,0,1), op(op0) {}
00098 virtual bool solution(const Assignment& x) const {
00099 return check(x[0],op,x[0]) == x[1];
00100 }
00102 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00103 using namespace Gecode;
00104 BoolVar b = channel(home,x[0]);
00105 rel(home, b, op, b, channel(home,x[1]));
00106 }
00107 };
00108
00110 class BinXYX : public Test {
00111 protected:
00113 Gecode::BoolOpType op;
00114 public:
00116 BinXYX(Gecode::BoolOpType op0)
00117 : Test("Bool::Bin::XYX::"+str(op0),2,0,1), op(op0) {}
00119 virtual bool solution(const Assignment& x) const {
00120 return check(x[0],op,x[1]) == x[0];
00121 }
00123 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00124 using namespace Gecode;
00125 BoolVar b = channel(home,x[0]);
00126 rel(home, b, op, channel(home,x[1]), b);
00127 }
00128 };
00129
00131 class BinXYY : public Test {
00132 protected:
00134 Gecode::BoolOpType op;
00135 public:
00137 BinXYY(Gecode::BoolOpType op0)
00138 : Test("Bool::Bin::XYY::"+str(op0),2,0,1), op(op0) {}
00140 virtual bool solution(const Assignment& x) const {
00141 return check(x[0],op,x[1]) == x[1];
00142 }
00144 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00145 using namespace Gecode;
00146 BoolVar b = channel(home,x[1]);
00147 rel(home, channel(home,x[0]), op, b, b);
00148 }
00149 };
00150
00152 class BinXXX : public Test {
00153 protected:
00155 Gecode::BoolOpType op;
00156 public:
00158 BinXXX(Gecode::BoolOpType op0)
00159 : Test("Bool::Bin::XXX::"+str(op0),1,0,1), op(op0) {}
00161 virtual bool solution(const Assignment& x) const {
00162 return check(x[0],op,x[0]) == x[0];
00163 }
00165 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00166 using namespace Gecode;
00167 BoolVar b = channel(home,x[0]);
00168 rel(home, b, op, b, b);
00169 }
00170 };
00171
00173 class BinConstXY : public Test {
00174 protected:
00176 Gecode::BoolOpType op;
00178 int c;
00179 public:
00181 BinConstXY(Gecode::BoolOpType op0, int c0)
00182 : Test("Bool::Bin::XY::"+str(op0)+"::"+str(c0),2,0,1),
00183 op(op0), c(c0) {}
00185 virtual bool solution(const Assignment& x) const {
00186 return check(x[0],op,x[1]) == c;
00187 }
00189 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00190 using namespace Gecode;
00191 rel(home, channel(home,x[0]), op, channel(home,x[1]), c);
00192 }
00193 };
00194
00196 class BinConstXX : public Test {
00197 protected:
00199 Gecode::BoolOpType op;
00201 int c;
00202 public:
00204 BinConstXX(Gecode::BoolOpType op0, int c0)
00205 : Test("Bool::Bin::XX::"+str(op0)+"::"+str(c0),1,0,1),
00206 op(op0), c(c0) {}
00208 virtual bool solution(const Assignment& x) const {
00209 return check(x[0],op,x[0]) == c;
00210 }
00212 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00213 using namespace Gecode;
00214 BoolVar b = channel(home,x[0]);
00215 rel(home, b, op, b, c);
00216 }
00217 };
00218
00220 class Nary : public Test {
00221 protected:
00223 Gecode::BoolOpType op;
00224 public:
00226 Nary(Gecode::BoolOpType op0, int n)
00227 : Test("Bool::Nary::"+str(op0)+"::"+str(n),n+1,0,1), op(op0) {}
00229 virtual bool solution(const Assignment& x) const {
00230 int b = check(x[0],op,x[1]);
00231 for (int i=2; i<x.size()-1; i++)
00232 b = check(b,op,x[i]);
00233 return b == x[x.size()-1];
00234 }
00236 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00237 using namespace Gecode;
00238 BoolVarArgs b(x.size()-1);
00239 for (int i=x.size()-1; i--; )
00240 b[i]=channel(home,x[i]);
00241 rel(home, op, b, channel(home,x[x.size()-1]));
00242 }
00243 };
00244
00246 class NaryShared : public Test {
00247 protected:
00249 Gecode::BoolOpType op;
00250 public:
00252 NaryShared(Gecode::BoolOpType op0, int n)
00253 : Test("Bool::Nary::Shared::"+str(op0)+"::"+str(n),n,0,1),
00254 op(op0) {}
00256 virtual bool solution(const Assignment& x) const {
00257 int b = check(x[0],op,x[1]);
00258 for (int i=2; i<x.size(); i++)
00259 b = check(b,op,x[i]);
00260 return b == x[x.size()-1];
00261 }
00263 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00264 using namespace Gecode;
00265 BoolVarArgs b(x.size());
00266 for (int i=x.size(); i--; )
00267 b[i]=channel(home,x[i]);
00268 rel(home, op, b, b[x.size()-1]);
00269 }
00270 };
00271
00273 class NaryConst : public Test {
00274 protected:
00276 Gecode::BoolOpType op;
00278 int c;
00279 public:
00281 NaryConst(Gecode::BoolOpType op0, int n, int c0)
00282 : Test("Bool::Nary::"+str(op0)+"::"+str(n)+"::"+str(c0),n,0,1),
00283 op(op0), c(c0) {}
00285 virtual bool solution(const Assignment& x) const {
00286 int b = check(x[0],op,x[1]);
00287 for (int i=2; i<x.size(); i++)
00288 b = check(b,op,x[i]);
00289 return b == c;
00290 }
00292 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00293 using namespace Gecode;
00294 BoolVarArgs b(x.size());
00295 for (int i=x.size(); i--; )
00296 b[i]=channel(home,x[i]);
00297 rel(home, op, b, c);
00298 }
00299 };
00300
00302 class Create {
00303 public:
00305 Create(void) {
00306 using namespace Gecode;
00307 for (BoolOpTypes bots; bots(); ++bots) {
00308 (void) new BinXYZ(bots.bot());
00309 (void) new BinXXY(bots.bot());
00310 (void) new BinXYX(bots.bot());
00311 (void) new BinXYY(bots.bot());
00312 (void) new BinXXX(bots.bot());
00313 (void) new BinConstXY(bots.bot(),0);
00314 (void) new BinConstXY(bots.bot(),1);
00315 (void) new BinConstXX(bots.bot(),0);
00316 (void) new BinConstXX(bots.bot(),1);
00317 (void) new Nary(bots.bot(),2);
00318 (void) new Nary(bots.bot(),6);
00319 (void) new Nary(bots.bot(),10);
00320 (void) new NaryShared(bots.bot(),2);
00321 (void) new NaryShared(bots.bot(),6);
00322 (void) new NaryShared(bots.bot(),10);
00323 (void) new NaryConst(bots.bot(),2,0);
00324 (void) new NaryConst(bots.bot(),6,0);
00325 (void) new NaryConst(bots.bot(),10,0);
00326 (void) new NaryConst(bots.bot(),2,1);
00327 (void) new NaryConst(bots.bot(),6,1);
00328 (void) new NaryConst(bots.bot(),10,1);
00329 }
00330 }
00331 };
00332
00333 Create c;
00335
00336 }
00337 }}
00338
00339
00340