int.hpp
Go to the documentation of this file.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
00113
00114
00115
00116
00117
00118 inline
00119 Test::Test(const std::string& s, int a, const Gecode::IntSet& d,
00120 bool r, Gecode::IntConLevel i)
00121 : Base("Int::"+s), arity(a), dom(d), reified(r), icl(i),
00122 contest(icl == Gecode::ICL_DOM ? CTL_DOMAIN : CTL_NONE),
00123 testsearch(true) {}
00124
00125 inline
00126 Test::Test(const std::string& s, int a, int min, int max,
00127 bool r, Gecode::IntConLevel i)
00128 : Base("Int::"+s), arity(a), dom(min,max), reified(r), icl(i),
00129 contest(icl == Gecode::ICL_DOM ? CTL_DOMAIN : CTL_NONE),
00130 testsearch(true) {}
00131
00132 inline
00133 std::string
00134 Test::str(Gecode::ExtensionalPropKind epk) {
00135 using namespace Gecode;
00136 switch (epk) {
00137 case EPK_MEMORY: return "Memory";
00138 case EPK_SPEED: return "Speed";
00139 default: return "Def";
00140 }
00141 }
00142
00143 inline
00144 std::string
00145 Test::str(Gecode::IntConLevel icl) {
00146 using namespace Gecode;
00147 switch (icl) {
00148 case ICL_VAL: return "Val";
00149 case ICL_BND: return "Bnd";
00150 case ICL_DOM: return "Dom";
00151 default: return "Def";
00152 }
00153 }
00154
00155 inline
00156 std::string
00157 Test::str(Gecode::IntRelType irt) {
00158 using namespace Gecode;
00159 switch (irt) {
00160 case IRT_LQ: return "Lq";
00161 case IRT_LE: return "Le";
00162 case IRT_GQ: return "Gq";
00163 case IRT_GR: return "Gr";
00164 case IRT_EQ: return "Eq";
00165 case IRT_NQ: return "Nq";
00166 default: ;
00167 }
00168 GECODE_NEVER;
00169 return "NONE";
00170 }
00171
00172 inline std::string
00173 Test::str(Gecode::BoolOpType bot) {
00174 using namespace Gecode;
00175 switch (bot) {
00176 case BOT_AND: return "And";
00177 case BOT_OR: return "Or";
00178 case BOT_IMP: return "Imp";
00179 case BOT_EQV: return "Eqv";
00180 case BOT_XOR: return "Xor";
00181 default: GECODE_NEVER;
00182 }
00183 GECODE_NEVER;
00184 return "NONE";
00185 }
00186
00187 inline
00188 std::string
00189 Test::str(int i) {
00190 std::stringstream s;
00191 s << i;
00192 return s.str();
00193 }
00194
00195 inline
00196 std::string
00197 Test::str(const Gecode::IntArgs& x) {
00198 std::string s = "";
00199 for (int i=0; i<x.size()-1; i++)
00200 s += str(x[i]) + ",";
00201 return "[" + s + str(x[x.size()-1]) + "]";
00202 }
00203
00204 template<class T>
00205 inline bool
00206 Test::cmp(T x, Gecode::IntRelType r, T y) {
00207 using namespace Gecode;
00208 switch (r) {
00209 case IRT_EQ: return x == y;
00210 case IRT_NQ: return x != y;
00211 case IRT_LQ: return x <= y;
00212 case IRT_LE: return x < y;
00213 case IRT_GR: return x > y;
00214 case IRT_GQ: return x >= y;
00215 default: ;
00216 }
00217 return false;
00218 }
00219
00220
00221 inline
00222 IntConLevels::IntConLevels(void)
00223 : i(sizeof(icls)/sizeof(Gecode::IntConLevel)-1) {}
00224 inline bool
00225 IntConLevels::operator()(void) const {
00226 return i>=0;
00227 }
00228 inline void
00229 IntConLevels::operator++(void) {
00230 i--;
00231 }
00232 inline Gecode::IntConLevel
00233 IntConLevels::icl(void) const {
00234 return icls[i];
00235 }
00236
00237
00238 inline
00239 IntRelTypes::IntRelTypes(void)
00240 : i(sizeof(irts)/sizeof(Gecode::IntRelType)-1) {}
00241 inline void
00242 IntRelTypes::reset(void) {
00243 i = sizeof(irts)/sizeof(Gecode::IntRelType)-1;
00244 }
00245 inline bool
00246 IntRelTypes::operator()(void) const {
00247 return i>=0;
00248 }
00249 inline void
00250 IntRelTypes::operator++(void) {
00251 i--;
00252 }
00253 inline Gecode::IntRelType
00254 IntRelTypes::irt(void) const {
00255 return irts[i];
00256 }
00257
00258 inline
00259 BoolOpTypes::BoolOpTypes(void)
00260 : i(sizeof(bots)/sizeof(Gecode::BoolOpType)-1) {}
00261 inline bool
00262 BoolOpTypes::operator()(void) const {
00263 return i>=0;
00264 }
00265 inline void
00266 BoolOpTypes::operator++(void) {
00267 i--;
00268 }
00269 inline Gecode::BoolOpType
00270 BoolOpTypes::bot(void) const {
00271 return bots[i];
00272 }
00273
00274 }}
00275
00276
00277