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 MiniModelCount {
00046
00048 std::string expand(Gecode::IntRelType irt) {
00049 switch (irt) {
00050 case Gecode::IRT_EQ: return "Exactly";
00051 case Gecode::IRT_LQ: return "AtMost";
00052 case Gecode::IRT_GQ: return "AtLeast";
00053 default: GECODE_NEVER;
00054 }
00055 GECODE_NEVER;
00056 return "";
00057 }
00058
00064
00065 class IntInt : public Test {
00066 protected:
00068 Gecode::IntRelType irt;
00069 public:
00071 IntInt(Gecode::IntRelType irt0)
00072 : Test("MiniModel::"+expand(irt0)+"::Int::Int",4,-2,2), irt(irt0) {}
00074 virtual bool solution(const Assignment& x) const {
00075 int m = 0;
00076 for (int i=x.size(); i--; )
00077 if (x[i] == 0)
00078 m++;
00079 return cmp(m,irt,2);
00080 }
00082 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00083 switch (irt) {
00084 case Gecode::IRT_EQ:
00085 Gecode::exactly(home,x,0,2); break;
00086 case Gecode::IRT_LQ:
00087 Gecode::atmost(home,x,0,2); break;
00088 case Gecode::IRT_GQ:
00089 Gecode::atleast(home,x,0,2); break;
00090 default: GECODE_NEVER;
00091 }
00092 }
00093 };
00094
00096 class IntVar : public Test {
00097 protected:
00099 Gecode::IntRelType irt;
00100 public:
00102 IntVar(Gecode::IntRelType irt0)
00103 : Test("MiniModel::"+expand(irt0)+"::Int::Var",5,-2,2), irt(irt0) {}
00105 virtual bool solution(const Assignment& x) const {
00106 int m = 0;
00107 for (int i=0; i<4; i++)
00108 if (x[i] == 0)
00109 m++;
00110 return cmp(m,irt,x[4]);
00111 }
00113 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00114 Gecode::IntVarArgs y(4);
00115 for (int i=0; i<4; i++)
00116 y[i]=x[i];
00117 switch (irt) {
00118 case Gecode::IRT_EQ:
00119 Gecode::exactly(home,y,0,x[4]); break;
00120 case Gecode::IRT_LQ:
00121 Gecode::atmost(home,y,0,x[4]); break;
00122 case Gecode::IRT_GQ:
00123 Gecode::atleast(home,y,0,x[4]); break;
00124 default: GECODE_NEVER;
00125 }
00126 }
00127 };
00128
00130 class VarVar : public Test {
00131 protected:
00133 Gecode::IntRelType irt;
00134 public:
00136 VarVar(Gecode::IntRelType irt0)
00137 : Test("MiniModel::"+expand(irt0)+"::Var::Var",5,-2,2), irt(irt0) {}
00139 virtual bool solution(const Assignment& x) const {
00140 int m = 0;
00141 for (int i=0; i<3; i++)
00142 if (x[i] == x[3])
00143 m++;
00144 return cmp(m,irt,x[4]);
00145 }
00147 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00148 Gecode::IntVarArgs y(3);
00149 for (int i=0; i<3; i++)
00150 y[i]=x[i];
00151 switch (irt) {
00152 case Gecode::IRT_EQ:
00153 Gecode::exactly(home,y,x[3],x[4]); break;
00154 case Gecode::IRT_LQ:
00155 Gecode::atmost(home,y,x[3],x[4]); break;
00156 case Gecode::IRT_GQ:
00157 Gecode::atleast(home,y,x[3],x[4]); break;
00158 default: GECODE_NEVER;
00159 }
00160 }
00161 };
00162
00164 class VarInt : public Test {
00165 protected:
00167 Gecode::IntRelType irt;
00168 public:
00170 VarInt(Gecode::IntRelType irt0)
00171 : Test("MiniModel::"+expand(irt0)+"::Var::Int",4,-2,2), irt(irt0) {}
00173 virtual bool solution(const Assignment& x) const {
00174 int m = 0;
00175 for (int i=0; i<3; i++)
00176 if (x[i] == x[3])
00177 m++;
00178 return cmp(m,irt,2);
00179 }
00181 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00182 Gecode::IntVarArgs y(3);
00183 for (int i=0; i<3; i++)
00184 y[i]=x[i];
00185 switch (irt) {
00186 case Gecode::IRT_EQ:
00187 Gecode::exactly(home,y,x[3],2); break;
00188 case Gecode::IRT_LQ:
00189 Gecode::atmost(home,y,x[3],2); break;
00190 case Gecode::IRT_GQ:
00191 Gecode::atleast(home,y,x[3],2); break;
00192 default: GECODE_NEVER;
00193 }
00194 }
00195 };
00196
00197 Gecode::IntArgs ints(4, 1,0,3,2);
00198
00200 class IntArrayInt : public Test {
00201 protected:
00203 Gecode::IntRelType irt;
00204 public:
00206 IntArrayInt(Gecode::IntRelType irt0)
00207 : Test("MiniModel::"+expand(irt0)+"::IntArray::Int",5,-2,2),
00208 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,2);
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 switch (irt) {
00223 case Gecode::IRT_EQ:
00224 Gecode::exactly(home,y,ints,2); break;
00225 case Gecode::IRT_LQ:
00226 Gecode::atmost(home,y,ints,2); break;
00227 case Gecode::IRT_GQ:
00228 Gecode::atleast(home,y,ints,2); break;
00229 default: GECODE_NEVER;
00230 }
00231 }
00232 };
00233
00235 class IntArrayVar : public Test {
00236 protected:
00238 Gecode::IntRelType irt;
00239 public:
00241 IntArrayVar(Gecode::IntRelType irt0)
00242 : Test("MiniModel::"+expand(irt0)+"::IntArray::Var",5,-2,2),
00243 irt(irt0) {}
00245 virtual bool solution(const Assignment& x) const {
00246 int m = 0;
00247 for (int i=0; i<4; i++)
00248 if (x[i] == ints[i])
00249 m++;
00250 return cmp(m,irt,x[4]);
00251 }
00253 virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00254 Gecode::IntVarArgs y(4);
00255 for (int i=0; i<4; i++)
00256 y[i]=x[i];
00257 switch (irt) {
00258 case Gecode::IRT_EQ:
00259 Gecode::exactly(home,y,ints,x[4]); break;
00260 case Gecode::IRT_LQ:
00261 Gecode::atmost(home,y,ints,x[4]); break;
00262 case Gecode::IRT_GQ:
00263 Gecode::atleast(home,y,ints,x[4]); break;
00264 default: GECODE_NEVER;
00265 }
00266 }
00267 };
00268
00270 class Create {
00271 public:
00273 Create(void) {
00274 for (IntRelTypes irts; irts(); ++irts)
00275 if ((irts.irt() == Gecode::IRT_EQ) ||
00276 (irts.irt() == Gecode::IRT_LQ) ||
00277 (irts.irt() == Gecode::IRT_GQ)) {
00278 (void) new IntInt(irts.irt());
00279 (void) new IntVar(irts.irt());
00280 (void) new VarVar(irts.irt());
00281 (void) new VarInt(irts.irt());
00282 (void) new IntArrayInt(irts.irt());
00283 (void) new IntArrayVar(irts.irt());
00284 }
00285 }
00286 };
00287
00288 Create c;
00290
00291 }
00292
00293 }}
00294
00295