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 #include "test/int.hh"
00035
00036 namespace Test { namespace Int {
00037
00039 namespace Count {
00040
00046
00047 class IntInt : public Test {
00048 protected:
00050 Gecode::IntRelType irt;
00051 public:
00053 IntInt(Gecode::IntRelType irt0)
00054 : Test("Count::Int::Int::"+str(irt0),4,-2,2), irt(irt0) {}
00056 virtual bool solution(const Assignment& x) const {
00057 int m = 0;
00058 for (int i=x.size(); i--; )
00059 if (x[i] == 0)
00060 m++;
00061 return cmp(m,irt,2);
00062 }
00064 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00065 Gecode::count(home, x, 0, irt, 2);
00066 }
00067 };
00068
00070 class SetInt : public Test {
00071 protected:
00073 Gecode::IntRelType irt;
00074 public:
00076 SetInt(Gecode::IntRelType irt0)
00077 : Test("Count::Set::Int::"+str(irt0),4,-2,2), irt(irt0) {}
00079 virtual bool solution(const Assignment& x) const {
00080 int m = 0;
00081 for (int i=x.size(); i--; )
00082 if ((x[i] >= -1) && (x[i] <= 1))
00083 m++;
00084 return cmp(m,irt,2);
00085 }
00087 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00088 Gecode::IntSet s(-1,1);
00089 Gecode::count(home, x, s, irt, 2);
00090 }
00091 };
00092
00094 class IntIntDup : public Test {
00095 protected:
00097 Gecode::IntRelType irt;
00098 public:
00100 IntIntDup(Gecode::IntRelType irt0)
00101 : Test("Count::Int::Int::Dup::"+str(irt0),4,-2,2), irt(irt0) {}
00103 virtual bool solution(const Assignment& x) const {
00104 int m = 0;
00105 for (int i=x.size(); i--; )
00106 if (x[i] == 0)
00107 m += 2;
00108 return cmp(m,irt,4);
00109 }
00111 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00112 Gecode::IntVarArgs y(8);
00113 for (int i=x.size(); i--; )
00114 y[i]=y[4+i]=x[i];
00115 Gecode::count(home, y, 0, irt, 4);
00116 }
00117 };
00118
00120 class IntVar : public Test {
00121 protected:
00123 Gecode::IntRelType irt;
00124 public:
00126 IntVar(Gecode::IntRelType irt0)
00127 : Test("Count::Int::Var::"+str(irt0),5,-2,2), irt(irt0) {}
00129 virtual bool solution(const Assignment& x) const {
00130 int m = 0;
00131 for (int i=0; i<4; i++)
00132 if (x[i] == 0)
00133 m++;
00134 return cmp(m,irt,x[4]);
00135 }
00137 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00138 Gecode::IntVarArgs y(4);
00139 for (int i=0; i<4; i++)
00140 y[i]=x[i];
00141 Gecode::count(home, y, 0, irt, x[4]);
00142 }
00143 };
00144
00146 class SetVar : public Test {
00147 protected:
00149 Gecode::IntRelType irt;
00150 public:
00152 SetVar(Gecode::IntRelType irt0)
00153 : Test("Count::Set::Var::"+str(irt0),5,-2,2), irt(irt0) {}
00155 virtual bool solution(const Assignment& x) const {
00156 int m = 0;
00157 for (int i=0; i<4; i++)
00158 if ((x[i] >= -1) && (x[i] <= 1))
00159 m++;
00160 return cmp(m,irt,x[4]);
00161 }
00163 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00164 Gecode::IntVarArgs y(4);
00165 for (int i=0; i<4; i++)
00166 y[i]=x[i];
00167 Gecode::IntSet s(-1,1);
00168 Gecode::count(home, y, s, irt, x[4]);
00169 }
00170 };
00171
00172 Gecode::IntArgs ints(4, 1,0,3,2);
00173
00175 class IntArrayInt : public Test {
00176 protected:
00178 Gecode::IntRelType irt;
00179 public:
00181 IntArrayInt(Gecode::IntRelType irt0)
00182 : Test("Count::IntArray::Int::"+str(irt0),5,-2,2), irt(irt0) {}
00184 virtual bool solution(const Assignment& x) const {
00185 int m = 0;
00186 for (int i=0; i<4; i++)
00187 if (x[i] == ints[i])
00188 m++;
00189 return cmp(m,irt,2);
00190 }
00192 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00193 Gecode::IntVarArgs y(4);
00194 for (int i=0; i<4; i++)
00195 y[i]=x[i];
00196 Gecode::count(home, y, ints, irt, 2);
00197 }
00198 };
00199
00201 class IntArrayVar : public Test {
00202 protected:
00204 Gecode::IntRelType irt;
00205 public:
00207 IntArrayVar(Gecode::IntRelType irt0)
00208 : Test("Count::IntArray::Var::"+str(irt0),5,-2,2), irt(irt0) {}
00210 virtual bool solution(const Assignment& x) const {
00211 int m = 0;
00212 for (int i=0; i<4; i++)
00213 if (x[i] == ints[i])
00214 m++;
00215 return cmp(m,irt,x[4]);
00216 }
00218 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00219 Gecode::IntVarArgs y(4);
00220 for (int i=0; i<4; i++)
00221 y[i]=x[i];
00222 Gecode::count(home, y, ints, irt, x[4]);
00223 }
00224 };
00225
00227 class IntVarShared : public Test {
00228 protected:
00230 Gecode::IntRelType irt;
00231 public:
00233 IntVarShared(Gecode::IntRelType irt0)
00234 : Test("Count::Int::Var::Shared::"+str(irt0),4,-2,2), irt(irt0) {}
00236 virtual bool solution(const Assignment& x) const {
00237 int m = 0;
00238 for (int i=0; i<4; i++)
00239 if (x[i] == 0)
00240 m++;
00241 return cmp(m,irt,x[2]);
00242 }
00244 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00245 Gecode::count(home, x, 0, irt, x[2]);
00246 }
00247 };
00248
00250 class VarVar : public Test {
00251 protected:
00253 Gecode::IntRelType irt;
00254 public:
00256 VarVar(Gecode::IntRelType irt0, Gecode::IntPropLevel ipl)
00257 : Test("Count::Var::Var::"+str(irt0)+"::"+str(ipl),5,-2,2,false,ipl),
00258 irt(irt0) {
00259 contest = CTL_NONE;
00260 }
00262 virtual bool solution(const Assignment& x) const {
00263 int m = 0;
00264 for (int i=0; i<3; i++)
00265 if (x[i] == x[3])
00266 m++;
00267 return cmp(m,irt,x[4]);
00268 }
00270 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00271 Gecode::IntVarArgs y(3);
00272 for (int i=0; i<3; i++)
00273 y[i]=x[i];
00274 Gecode::count(home, y, x[3], irt, x[4], ipl);
00275 }
00276 };
00277
00279 class VarInt : public Test {
00280 protected:
00282 Gecode::IntRelType irt;
00283 public:
00285 VarInt(Gecode::IntRelType irt0, Gecode::IntPropLevel ipl)
00286 : Test("Count::Var::Int::"+str(irt0)+"::"+str(ipl),4,-2,2,false,ipl),
00287 irt(irt0) {
00288 contest = CTL_NONE;
00289 }
00291 virtual bool solution(const Assignment& x) const {
00292 int m = 0;
00293 for (int i=0; i<3; i++)
00294 if (x[i] == x[3])
00295 m++;
00296 return cmp(m,irt,2);
00297 }
00299 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00300 Gecode::IntVarArgs y(3);
00301 for (int i=0; i<3; i++)
00302 y[i]=x[i];
00303 Gecode::count(home, y, x[3], irt, 2, ipl);
00304 }
00305 };
00306
00308 class VarVarSharedA : public Test {
00309 protected:
00311 Gecode::IntRelType irt;
00312 public:
00314 VarVarSharedA(Gecode::IntRelType irt0)
00315 : Test("Count::Var::Var::Shared::A::"+str(irt0),5,-2,2), irt(irt0) {}
00317 virtual bool solution(const Assignment& x) const {
00318 int m = 0;
00319 for (int i=0; i<4; i++)
00320 if (x[i] == x[1])
00321 m++;
00322 return cmp(m,irt,x[4]);
00323 }
00325 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00326 Gecode::IntVarArgs y(4);
00327 for (int i=0; i<4; i++)
00328 y[i]=x[i];
00329 Gecode::count(home, y, x[1], irt, x[4]);
00330 }
00331 };
00332
00334 class VarVarSharedB : public Test {
00335 protected:
00337 Gecode::IntRelType irt;
00338 public:
00340 VarVarSharedB(Gecode::IntRelType irt0)
00341 : Test("Count::Var::Var::Shared::B::"+str(irt0),5,-2,2), irt(irt0) {}
00343 virtual bool solution(const Assignment& x) const {
00344 int m = 0;
00345 for (int i=0; i<4; i++)
00346 if (x[i] == x[4])
00347 m++;
00348 return cmp(m,irt,x[3]);
00349 }
00351 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00352 Gecode::IntVarArgs y(4);
00353 for (int i=0; i<4; i++)
00354 y[i]=x[i];
00355 Gecode::count(home, y, x[4], irt, x[3]);
00356 }
00357 };
00358
00360 class VarVarSharedC : public Test {
00361 protected:
00363 Gecode::IntRelType irt;
00364 public:
00366 VarVarSharedC(Gecode::IntRelType irt0)
00367 : Test("Count::Var::Var::Shared::C::"+str(irt0),4,-2,2), irt(irt0) {}
00369 virtual bool solution(const Assignment& x) const {
00370 int m = 0;
00371 for (int i=0; i<4; i++)
00372 if (x[i] == x[1])
00373 m++;
00374 return cmp(m,irt,x[3]);
00375 }
00377 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00378 Gecode::count(home, x, x[1], irt, x[3]);
00379 }
00380 };
00381
00383 class Create {
00384 public:
00386 Create(void) {
00387 for (IntRelTypes irts; irts(); ++irts) {
00388 (void) new IntInt(irts.irt());
00389 (void) new SetInt(irts.irt());
00390 (void) new IntIntDup(irts.irt());
00391 (void) new IntVar(irts.irt());
00392 (void) new SetVar(irts.irt());
00393 (void) new IntArrayInt(irts.irt());
00394 (void) new IntArrayVar(irts.irt());
00395 (void) new IntVarShared(irts.irt());
00396 (void) new VarVar(irts.irt(), Gecode::IPL_BND);
00397 (void) new VarVar(irts.irt(), Gecode::IPL_DOM);
00398 (void) new VarInt(irts.irt(), Gecode::IPL_BND);
00399 (void) new VarInt(irts.irt(), Gecode::IPL_DOM);
00400 (void) new VarVarSharedA(irts.irt());
00401 (void) new VarVarSharedB(irts.irt());
00402 (void) new VarVarSharedC(irts.irt());
00403 }
00404 }
00405 };
00406
00407 Create c;
00409
00410 }
00411 }}
00412
00413
00414