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 namespace Test { namespace Int {
00041
00042
00043
00044
00045
00046 inline
00047 Assignment::Assignment(int n0, const Gecode::IntSet& d0)
00048 : n(n0), d(d0) {}
00049 inline int
00050 Assignment::size(void) const {
00051 return n;
00052 }
00053 inline
00054 Assignment::~Assignment(void) {}
00055
00056
00057 inline
00058 CpltAssignment::CpltAssignment(int n, const Gecode::IntSet& d)
00059 : Assignment(n,d),
00060 dsv(new Gecode::IntSetValues[static_cast<unsigned int>(n)]) {
00061 for (int i=n; i--; )
00062 dsv[i].init(d);
00063 }
00064 inline bool
00065 CpltAssignment::operator()(void) const {
00066 return dsv[0]();
00067 }
00068 inline int
00069 CpltAssignment::operator[](int i) const {
00070 assert((i>=0) && (i<n));
00071 return dsv[i].val();
00072 }
00073 inline
00074 CpltAssignment::~CpltAssignment(void) {
00075 delete [] dsv;
00076 }
00077
00078
00079 forceinline int
00080 RandomAssignment::randval(void) {
00081 unsigned int skip = Base::rand(d.size());
00082 for (Gecode::IntSetRanges it(d); true; ++it) {
00083 if (it.width() > skip)
00084 return it.min() + static_cast<int>(skip);
00085 skip -= it.width();
00086 }
00087 GECODE_NEVER;
00088 return 0;
00089 }
00090
00091 inline
00092 RandomAssignment::RandomAssignment(int n, const Gecode::IntSet& d, int a0)
00093 : Assignment(n,d), vals(new int[n]), a(a0) {
00094 for (int i=n; i--; )
00095 vals[i] = randval();
00096 }
00097
00098 inline bool
00099 RandomAssignment::operator()(void) const {
00100 return a>0;
00101 }
00102 inline int
00103 RandomAssignment::operator[](int i) const {
00104 assert((i>=0) && (i<n));
00105 return vals[i];
00106 }
00107 inline
00108 RandomAssignment::~RandomAssignment(void) {
00109 delete [] vals;
00110 }
00111
00112 forceinline int
00113 RandomMixAssignment::randval(const Gecode::IntSet& d) {
00114 unsigned int skip = Base::rand(d.size());
00115 for (Gecode::IntSetRanges it(d); true; ++it) {
00116 if (it.width() > skip)
00117 return it.min() + static_cast<int>(skip);
00118 skip -= it.width();
00119 }
00120 GECODE_NEVER;
00121 return 0;
00122 }
00123
00124 inline
00125 RandomMixAssignment::RandomMixAssignment(int n0, const Gecode::IntSet& d0,
00126 int n1, const Gecode::IntSet& d1,
00127 int a0)
00128 : Assignment(n0+n1,d0),vals(new int[n0+n1]),a(a0),_n1(n1),_d1(d1) {
00129 for (int i=n0; i--; )
00130 vals[i] = randval(d);
00131 for (int i=n1; i--; )
00132 vals[n0+i] = randval(_d1);
00133 }
00134
00135 inline bool
00136 RandomMixAssignment::operator()(void) const {
00137 return a>0;
00138 }
00139
00140 inline int
00141 RandomMixAssignment::operator[](int i) const {
00142 assert((i>=0) && (i<n));
00143 return vals[i];
00144 }
00145
00146 inline
00147 RandomMixAssignment::~RandomMixAssignment(void) {
00148 delete [] vals;
00149 }
00150
00151
00152
00153
00154
00155 forceinline bool
00156 Test::eqv(void) const {
00157 return reified && ((rms & (1 << Gecode::RM_EQV)) != 0);
00158 }
00159 forceinline bool
00160 Test::imp(void) const {
00161 return reified && ((rms & (1 << Gecode::RM_IMP)) != 0);
00162 }
00163 forceinline bool
00164 Test::pmi(void) const {
00165 return reified && ((rms & (1 << Gecode::RM_PMI)) != 0);
00166 }
00167 inline
00168 Test::Test(const std::string& p, const std::string& s,
00169 int a, const Gecode::IntSet& d, bool r,
00170 Gecode::IntConLevel i)
00171 : Base(p+s), arity(a), dom(d),
00172 reified(r), rms((1 << Gecode::RM_EQV) ||
00173 (1 << Gecode::RM_IMP) ||
00174 (1 << Gecode::RM_PMI)),
00175 icl(i), contest(icl == Gecode::ICL_DOM ? CTL_DOMAIN : CTL_NONE),
00176 testsearch(true), testfix(true) {}
00177
00178 inline
00179 Test::Test(const std::string& s,
00180 int a, const Gecode::IntSet& d, bool r,
00181 Gecode::IntConLevel i)
00182 : Base("Int::"+s), arity(a), dom(d),
00183 reified(r), rms((1 << Gecode::RM_EQV) ||
00184 (1 << Gecode::RM_IMP) ||
00185 (1 << Gecode::RM_PMI)),
00186 icl(i), contest(icl == Gecode::ICL_DOM ? CTL_DOMAIN : CTL_NONE),
00187 testsearch(true), testfix(true) {}
00188
00189 inline
00190 Test::Test(const std::string& p, const std::string& s,
00191 int a, int min, int max, bool r,
00192 Gecode::IntConLevel i)
00193 : Base(p+s), arity(a), dom(min,max),
00194 reified(r), rms((1 << Gecode::RM_EQV) ||
00195 (1 << Gecode::RM_IMP) ||
00196 (1 << Gecode::RM_PMI)),
00197 icl(i), contest(icl == Gecode::ICL_DOM ? CTL_DOMAIN : CTL_NONE),
00198 testsearch(true), testfix(true) {}
00199
00200 inline
00201 Test::Test(const std::string& s,
00202 int a, int min, int max, bool r, Gecode::IntConLevel i)
00203 : Base("Int::"+s), arity(a), dom(min,max),
00204 reified(r), rms((1 << Gecode::RM_EQV) ||
00205 (1 << Gecode::RM_IMP) ||
00206 (1 << Gecode::RM_PMI)),
00207 icl(i), contest(icl == Gecode::ICL_DOM ? CTL_DOMAIN : CTL_NONE),
00208 testsearch(true), testfix(true) {}
00209
00210 inline
00211 std::string
00212 Test::str(Gecode::ExtensionalPropKind epk) {
00213 using namespace Gecode;
00214 switch (epk) {
00215 case EPK_MEMORY: return "Memory";
00216 case EPK_SPEED: return "Speed";
00217 default: return "Def";
00218 }
00219 }
00220
00221 inline
00222 std::string
00223 Test::str(Gecode::IntConLevel icl) {
00224 using namespace Gecode;
00225 switch (icl) {
00226 case ICL_VAL: return "Val";
00227 case ICL_BND: return "Bnd";
00228 case ICL_DOM: return "Dom";
00229 default: return "Def";
00230 }
00231 }
00232
00233 inline
00234 std::string
00235 Test::str(Gecode::IntRelType irt) {
00236 using namespace Gecode;
00237 switch (irt) {
00238 case IRT_LQ: return "Lq";
00239 case IRT_LE: return "Le";
00240 case IRT_GQ: return "Gq";
00241 case IRT_GR: return "Gr";
00242 case IRT_EQ: return "Eq";
00243 case IRT_NQ: return "Nq";
00244 default: ;
00245 }
00246 GECODE_NEVER;
00247 return "NONE";
00248 }
00249
00250 inline std::string
00251 Test::str(Gecode::BoolOpType bot) {
00252 using namespace Gecode;
00253 switch (bot) {
00254 case BOT_AND: return "And";
00255 case BOT_OR: return "Or";
00256 case BOT_IMP: return "Imp";
00257 case BOT_EQV: return "Eqv";
00258 case BOT_XOR: return "Xor";
00259 default: GECODE_NEVER;
00260 }
00261 GECODE_NEVER;
00262 return "NONE";
00263 }
00264
00265 inline
00266 std::string
00267 Test::str(int i) {
00268 std::stringstream s;
00269 s << i;
00270 return s.str();
00271 }
00272
00273 inline
00274 std::string
00275 Test::str(const Gecode::IntArgs& x) {
00276 std::string s = "";
00277 for (int i=0; i<x.size()-1; i++)
00278 s += str(x[i]) + ",";
00279 return "[" + s + str(x[x.size()-1]) + "]";
00280 }
00281
00282 template<class T>
00283 inline bool
00284 Test::cmp(T x, Gecode::IntRelType r, T y) {
00285 using namespace Gecode;
00286 switch (r) {
00287 case IRT_EQ: return x == y;
00288 case IRT_NQ: return x != y;
00289 case IRT_LQ: return x <= y;
00290 case IRT_LE: return x < y;
00291 case IRT_GR: return x > y;
00292 case IRT_GQ: return x >= y;
00293 default: ;
00294 }
00295 return false;
00296 }
00297
00298
00299
00300 inline
00301 IntConLevels::IntConLevels(void)
00302 : i(sizeof(icls)/sizeof(Gecode::IntConLevel)-1) {}
00303 inline bool
00304 IntConLevels::operator()(void) const {
00305 return i>=0;
00306 }
00307 inline void
00308 IntConLevels::operator++(void) {
00309 i--;
00310 }
00311 inline Gecode::IntConLevel
00312 IntConLevels::icl(void) const {
00313 return icls[i];
00314 }
00315
00316
00317 inline
00318 IntRelTypes::IntRelTypes(void)
00319 : i(sizeof(irts)/sizeof(Gecode::IntRelType)-1) {}
00320 inline void
00321 IntRelTypes::reset(void) {
00322 i = sizeof(irts)/sizeof(Gecode::IntRelType)-1;
00323 }
00324 inline bool
00325 IntRelTypes::operator()(void) const {
00326 return i>=0;
00327 }
00328 inline void
00329 IntRelTypes::operator++(void) {
00330 i--;
00331 }
00332 inline Gecode::IntRelType
00333 IntRelTypes::irt(void) const {
00334 return irts[i];
00335 }
00336
00337 inline
00338 BoolOpTypes::BoolOpTypes(void)
00339 : i(sizeof(bots)/sizeof(Gecode::BoolOpType)-1) {}
00340 inline bool
00341 BoolOpTypes::operator()(void) const {
00342 return i>=0;
00343 }
00344 inline void
00345 BoolOpTypes::operator++(void) {
00346 i--;
00347 }
00348 inline Gecode::BoolOpType
00349 BoolOpTypes::bot(void) const {
00350 return bots[i];
00351 }
00352
00353 }}
00354
00355
00356