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 template<class T>
00196 inline bool
00197 Test::cmp(T x, Gecode::IntRelType r, T y) {
00198 using namespace Gecode;
00199 switch (r) {
00200 case IRT_EQ: return x == y;
00201 case IRT_NQ: return x != y;
00202 case IRT_LQ: return x <= y;
00203 case IRT_LE: return x < y;
00204 case IRT_GR: return x > y;
00205 case IRT_GQ: return x >= y;
00206 default: ;
00207 }
00208 return false;
00209 }
00210
00211
00212 inline
00213 IntConLevels::IntConLevels(void)
00214 : i(sizeof(icls)/sizeof(Gecode::IntConLevel)-1) {}
00215 inline bool
00216 IntConLevels::operator()(void) const {
00217 return i>=0;
00218 }
00219 inline void
00220 IntConLevels::operator++(void) {
00221 i--;
00222 }
00223 inline Gecode::IntConLevel
00224 IntConLevels::icl(void) const {
00225 return icls[i];
00226 }
00227
00228
00229 inline
00230 IntRelTypes::IntRelTypes(void)
00231 : i(sizeof(irts)/sizeof(Gecode::IntRelType)-1) {}
00232 inline void
00233 IntRelTypes::reset(void) {
00234 i = sizeof(irts)/sizeof(Gecode::IntRelType)-1;
00235 }
00236 inline bool
00237 IntRelTypes::operator()(void) const {
00238 return i>=0;
00239 }
00240 inline void
00241 IntRelTypes::operator++(void) {
00242 i--;
00243 }
00244 inline Gecode::IntRelType
00245 IntRelTypes::irt(void) const {
00246 return irts[i];
00247 }
00248
00249 inline
00250 BoolOpTypes::BoolOpTypes(void)
00251 : i(sizeof(bots)/sizeof(Gecode::BoolOpType)-1) {}
00252 inline bool
00253 BoolOpTypes::operator()(void) const {
00254 return i>=0;
00255 }
00256 inline void
00257 BoolOpTypes::operator++(void) {
00258 i--;
00259 }
00260 inline Gecode::BoolOpType
00261 BoolOpTypes::bot(void) const {
00262 return bots[i];
00263 }
00264
00265 }}
00266
00267
00268