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
00039
00040
00041
00042 #include "test/int.hh"
00043
00044 namespace Test { namespace Int {
00045
00047 namespace GCC {
00048
00054
00055 class IntAllMinMax : public Test {
00056 public:
00058 IntAllMinMax(Gecode::IntConLevel icl)
00059 : Test("GCC::Int::All::MinMax::"+str(icl),4,1,4,false,icl) {}
00061 virtual bool solution(const Assignment& x) const {
00062 int n[4];
00063 for (int i=4; i--; )
00064 n[i]=0;
00065 for (int i=x.size(); i--; )
00066 n[x[i]-1]++;
00067 if (n[2] > 0)
00068 return false;
00069 for (int i=4; i--;)
00070 if (n[i]>2)
00071 return false;
00072 return true;
00073 }
00075 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00076 using namespace Gecode;
00077 IntArgs values(4);
00078 IntSet fixed(0,2);
00079 IntSetArgs cards(4);
00080 for (int i=0; i<4; i++) {
00081 values[i] = i+1; cards[i] = fixed;
00082 }
00083 cards[2] = IntSet(0,0);
00084 count(home, x, cards, values, icl);
00085 }
00086 };
00087
00089 class IntAllMinMaxDef : public Test {
00090 public:
00092 IntAllMinMaxDef(Gecode::IntConLevel icl)
00093 : Test("GCC::Int::All::MinMaxDef::"+str(icl),4,0,3,false,icl) {}
00095 virtual bool solution(const Assignment& x) const {
00096 int n[4];
00097 for (int i=4; i--; )
00098 n[i]=0;
00099 for (int i=x.size(); i--; )
00100 n[x[i]]++;
00101 if (n[2] > 0)
00102 return false;
00103 for (int i=4; i--;)
00104 if (n[i]>2)
00105 return false;
00106 return true;
00107 }
00109 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00110 using namespace Gecode;
00111 IntSet fixed(0,2);
00112 IntSetArgs cards(4);
00113 for (int i=0; i<4; i++) {
00114 cards[i] = fixed;
00115 }
00116 cards[2] = IntSet(0,0);
00117 count(home, x, cards, icl);
00118 }
00119 };
00120
00122 class IntAllMax : public Test {
00123 public:
00125 IntAllMax(Gecode::IntConLevel icl)
00126 : Test("GCC::Int::All::Max::"+str(icl), 4, 1,2, false, icl) {}
00128 virtual bool solution(const Assignment& x) const {
00129 int n[2];
00130 for (int i=2; i--; )
00131 n[i] = 0;
00132 for (int i=x.size(); i--; )
00133 n[x[i] - 1]++;
00134 if (n[0] != 2 || n[1] != 2)
00135 return false;
00136 return true;
00137 }
00139 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00140 Gecode::IntArgs values(2, 1,2);
00141 Gecode::count(home, x, Gecode::IntSet(2,2), values, icl);
00142 }
00143 };
00144
00145
00147 template <bool hole>
00148 class IntSome : public Test {
00149 public:
00151 IntSome(Gecode::IntConLevel icl)
00152 : Test(std::string("GCC::Int::Some::")+
00153 (hole ? "::Hole" : "::Full")+str(icl),4,1,4,false,icl) {}
00155 virtual bool solution(const Assignment& x) const {
00156 int n[4];
00157 for (int i=4; i--; )
00158 n[i]=0;
00159 for (int i=x.size(); i--; )
00160 n[x[i]-1]++;
00161 if ((n[0] < 2) || (n[1] < 2) || (n[2] > 0) || (n[3] > 0))
00162 return false;
00163 return true;
00164 }
00166 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00167 using namespace Gecode;
00168 IntArgs values(2, 1,2);
00169 Gecode::IntSet fixed;
00170 if (!hole) {
00171 fixed = IntSet(0,2);
00172 } else {
00173 int ish[] = {0,2};
00174 fixed = IntSet(ish,2);
00175 }
00176 Gecode::IntSetArgs cards(2);
00177 cards[0]=fixed; cards[1]=fixed;
00178 count(home, x, cards, values, icl);
00179 }
00180 };
00181
00183 class VarAll : public Test {
00184 protected:
00186 static const int n = 4;
00187 public:
00189 VarAll(Gecode::IntConLevel icl)
00190 : Test("GCC::Var::All::"+str(icl),7,0,2,false,icl) {}
00192 virtual bool solution(const Assignment& x) const {
00193
00194 int m = x.size()-n;
00195 for (int i=0; i<n; i++)
00196 if ((x[i] < 0) || (x[i] > 2))
00197 return false;
00198 int* card = new int[m];
00199 for (int i=0; i<m; i++) {
00200 card[i] = 0;
00201 if ((x[n+i] < 0) || (x[n+i] > 2)) {
00202 delete [] card;
00203 return false;
00204 }
00205 }
00206 for (int i=0; i<n; i++)
00207 card[x[i]]++;
00208 for (int i=0; i<m; i++)
00209 if (card[i] != x[n+i]) {
00210 delete [] card;
00211 return false;
00212 }
00213 delete [] card;
00214 return true;
00215 }
00217 virtual void post(Gecode::Space& home, Gecode::IntVarArray& xy) {
00218 using namespace Gecode;
00219
00220 int m = xy.size()-n;
00221
00222 IntVarArgs x(n), y(m);
00223 for (int i=0; i<n; i++)
00224 x[i]=xy[i];
00225 for (int i=0; i<m; i++)
00226 y[i]=xy[n+i];
00227 count(home, x, y, icl);
00228 }
00229 };
00230
00232 class VarSome : public Test {
00233 protected:
00235 static const int n = 4;
00236 public:
00238 VarSome(Gecode::IntConLevel icl)
00239 : Test("GCC::Var::Some::"+str(icl),6,0,2,false,icl) {}
00241 virtual bool solution(const Assignment& x) const {
00242
00243 int m = x.size()-n;
00244 for (int i=0; i<n; i++)
00245 if ((x[i] < 0) || (x[i] > 1))
00246 return false;
00247 int* card = new int[m];
00248 for (int i=0; i<m; i++) {
00249 card[i] = 0;
00250 if ((x[n+i] < 0) || (x[n+i] > 2)) {
00251 delete [] card;
00252 return false;
00253 }
00254 }
00255 for (int i=0; i<n; i++)
00256 card[x[i]]++;
00257 for (int i=0; i<m; i++)
00258 if (card[i] != x[n+i]) {
00259 delete [] card;
00260 return false;
00261 }
00262 delete [] card;
00263 return true;
00264 }
00266 virtual void post(Gecode::Space& home, Gecode::IntVarArray& xy) {
00267 using namespace Gecode;
00268
00269 int m = xy.size()-n;
00270 IntVarArgs x(n), y(m);
00271 for (int i=0; i<n; i++)
00272 x[i]=xy[i];
00273 for (int i=0; i<m; i++)
00274 y[i]=xy[n+i];
00275 IntArgs values(2, 0,1);
00276 count(home,x,y,values,icl);
00277 }
00278 };
00279
00281 class Create {
00282 public:
00284 Create(void) {
00285 for (IntConLevels icls; icls(); ++icls) {
00286 (void) new IntAllMinMax(icls.icl());
00287 (void) new IntAllMinMaxDef(icls.icl());
00288 (void) new IntAllMax(icls.icl());
00289 (void) new IntSome<false>(icls.icl());
00290 (void) new IntSome<true>(icls.icl());
00291 (void) new VarAll(icls.icl());
00292 (void) new VarSome(icls.icl());
00293 }
00294 }
00295 };
00296
00297 Create c;
00299
00300 }
00301 }}
00302
00303