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 Element {
00046
00052
00053 class IntIntVar : public Test {
00054 protected:
00056 Gecode::IntArgs c;
00057 public:
00059 IntIntVar(const std::string& s, const Gecode::IntArgs& c0)
00060 : Test("Element::Int::Int::Var::"+s,2,-4,8), c(c0) {}
00062 virtual bool solution(const Assignment& x) const {
00063 return (x[0]>= 0) && (x[0]<c.size()) && c[x[0]]==x[1];
00064 }
00066 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00067 Gecode::element(home, c, x[0], x[1]);
00068 }
00069 };
00070
00072 class IntIntInt : public Test {
00073 protected:
00075 Gecode::IntArgs c;
00077 int r;
00078 public:
00080 IntIntInt(const std::string& s, const Gecode::IntArgs& c0, int r0)
00081 : Test("Element::Int::Int::Int::"+s+"::"+str(r0),1,-4,8),
00082 c(c0), r(r0) {}
00084 virtual bool solution(const Assignment& x) const {
00085 return (x[0]>= 0) && (x[0]<c.size()) && c[x[0]]==r;
00086 }
00088 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00089 Gecode::element(home, c, x[0], r);
00090 }
00091 };
00092
00094 class IntIntShared : public Test {
00095 protected:
00097 Gecode::IntArgs c;
00098 public:
00100 IntIntShared(const std::string& s, const Gecode::IntArgs& c0)
00101 : Test("Element::Int::Int::Shared::"+s,1,-4,8), c(c0) {}
00103 virtual bool solution(const Assignment& x) const {
00104 return (x[0]>= 0) && (x[0]<c.size()) && c[x[0]]==x[0];
00105 }
00107 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00108 Gecode::element(home, c, x[0], x[0]);
00109 }
00110 };
00111
00113 class IntBoolVar : public Test {
00114 protected:
00116 Gecode::IntArgs c;
00117 public:
00119 IntBoolVar(const std::string& s, const Gecode::IntArgs& c0)
00120 : Test("Element::Int::Bool::Var::"+s,2,-4,8), c(c0) {}
00122 virtual bool solution(const Assignment& x) const {
00123 return (x[0]>= 0) && (x[0]<c.size()) && c[x[0]]==x[1];
00124 }
00126 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00127 Gecode::element(home, c, x[0], Gecode::channel(home,x[1]));
00128 }
00129 };
00130
00132 class IntBoolInt : public Test {
00133 protected:
00135 Gecode::IntArgs c;
00137 int r;
00138 public:
00140 IntBoolInt(const std::string& s, const Gecode::IntArgs& c0, int r0)
00141 : Test("Element::Int::Bool::Int::"+s+"::"+str(r0),1,-4,8),
00142 c(c0), r(r0) {}
00144 virtual bool solution(const Assignment& x) const {
00145 return (x[0]>= 0) && (x[0]<c.size()) && c[x[0]]==r;
00146 }
00148 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00149 Gecode::element(home, c, x[0], r);
00150 }
00151 };
00152
00154 class VarIntVar : public Test {
00155 public:
00157 VarIntVar(Gecode::IntConLevel icl)
00158 : Test("Element::Var::Int::Var::"+str(icl),6,-1,3,false,icl) {}
00160 virtual bool solution(const Assignment& x) const {
00161 return (x[0]>= 0) && (x[0]<x.size()-2) && x[2+x[0]]==x[1];
00162 }
00164 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00165 Gecode::IntVarArgs c(x.size()-2);
00166 for (int i=0; i<x.size()-2; i++)
00167 c[i]=x[2+i];
00168 Gecode::element(home, c, x[0], x[1], icl);
00169 }
00170 };
00171
00173 class VarIntInt : public Test {
00174 protected:
00176 int r;
00177 public:
00179 VarIntInt(Gecode::IntConLevel icl, int r0)
00180 : Test("Element::Var::Int::Int::"+str(icl)+"::"+str(r0),
00181 5,-1,3,false,icl), r(r0) {
00182 testdomcon = false;
00183 }
00185 virtual bool solution(const Assignment& x) const {
00186 return (x[0]>= 0) && (x[0]<x.size()-1) && x[1+x[0]]==r;
00187 }
00189 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00190 Gecode::IntVarArgs c(x.size()-1);
00191 for (int i=0; i<x.size()-1; i++)
00192 c[i]=x[1+i];
00193 Gecode::element(home, c, x[0], r, icl);
00194 }
00195 };
00196
00198 class VarIntShared : public Test {
00199 public:
00201 VarIntShared(Gecode::IntConLevel icl)
00202 : Test("Element::Var::Int::Shared::"+str(icl),5,-1,3,false,icl) {}
00204 virtual bool solution(const Assignment& x) const {
00205 return (x[0]>= 0) && (x[0]<x.size()-1) && x[1+x[0]]==x[0];
00206 }
00208 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00209 Gecode::IntVarArgs c(x.size()-1);
00210 for (int i=0; i<x.size()-1; i++)
00211 c[i]=x[1+i];
00212 Gecode::element(home, c, x[0], x[0], icl);
00213 }
00214 };
00215
00217 class VarBoolVar : public Test {
00218 public:
00220 VarBoolVar(void) : Test("Element::Var::Bool::Var",6,-1,3,false) {}
00222 virtual bool solution(const Assignment& x) const {
00223 for (int i=0; i<x.size()-2; i++)
00224 if ((x[2+i] < 0) || (x[2+i]>1))
00225 return false;
00226 return ((x[0]>= 0) && (x[0]<x.size()-2) && x[2+x[0]]==x[1]
00227 && (x[1]>=0) && (x[1]<=1));
00228 }
00230 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00231 using namespace Gecode;
00232 BoolVarArgs c(x.size()-2);
00233 for (int i=0; i<x.size()-2; i++)
00234 c[i]=channel(home,x[2+i]);
00235 element(home, c, x[0], channel(home,x[1]));
00236 }
00237 };
00238
00240 class VarBoolInt : public Test {
00241 protected:
00243 int r;
00244 public:
00246 VarBoolInt(int r0)
00247 : Test("Element::Var::Bool::Int::"+str(r0),5,-1,3,false), r(r0) {}
00249 virtual bool solution(const Assignment& x) const {
00250 for (int i=0; i<x.size()-1; i++)
00251 if ((x[1+i] < 0) || (x[1+i]>1))
00252 return false;
00253 return ((x[0]>= 0) && (x[0]<x.size()-1) && x[1+x[0]]==r);
00254 }
00256 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00257 using namespace Gecode;
00258 BoolVarArgs c(x.size()-1);
00259 for (int i=0; i<x.size()-1; i++)
00260 c[i]=channel(home,x[1+i]);
00261 element(home, c, x[0], r);
00262 }
00263 };
00264
00266 class Create {
00267 public:
00269 Create(void) {
00270 using namespace Gecode;
00271 IntArgs ic1(5, -1,1,-3,3,-4);
00272 IntArgs ic2(8, -1,1,-1,1,-1,1,0,0);
00273 IntArgs ic3(1, -1);
00274 IntArgs ic4(7, 0,-1,2,-2,4,-3,6);
00275
00276 IntArgs bc1(5, 0,1,1,0,1);
00277 IntArgs bc2(8, 1,1,0,1,0,1,0,0);
00278 IntArgs bc3(1, 1);
00279
00280 (void) new IntIntVar("A",ic1);
00281 (void) new IntIntVar("B",ic2);
00282 (void) new IntIntVar("C",ic3);
00283 (void) new IntIntVar("D",ic4);
00284
00285 for (int i=-4; i<=4; i++) {
00286 (void) new IntIntInt("A",ic1,i);
00287 (void) new IntIntInt("B",ic2,i);
00288 (void) new IntIntInt("C",ic3,i);
00289 (void) new IntIntInt("D",ic4,i);
00290 }
00291
00292 (void) new IntIntShared("A",ic1);
00293 (void) new IntIntShared("B",ic2);
00294 (void) new IntIntShared("C",ic3);
00295 (void) new IntIntShared("D",ic4);
00296
00297 (void) new IntBoolVar("A",bc1);
00298 (void) new IntBoolVar("B",bc2);
00299 (void) new IntBoolVar("C",bc3);
00300
00301 for (int i=0; i<=1; i++) {
00302 (void) new IntBoolInt("A",bc1,i);
00303 (void) new IntBoolInt("B",bc2,i);
00304 (void) new IntBoolInt("C",bc3,i);
00305 }
00306
00307 (void) new VarIntVar(ICL_BND);
00308 (void) new VarIntVar(ICL_DOM);
00309
00310 for (int i=-4; i<=4; i++) {
00311 (void) new VarIntInt(ICL_BND,i);
00312 (void) new VarIntInt(ICL_DOM,i);
00313 }
00314
00315 (void) new VarIntShared(ICL_BND);
00316 (void) new VarIntShared(ICL_DOM);
00317
00318 (void) new VarBoolVar();
00319 (void) new VarBoolInt(0);
00320 (void) new VarBoolInt(1);
00321 }
00322 };
00323
00324 Create c;
00326
00327 }
00328 }}
00329
00330