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 namespace Test { namespace Float {
00039
00040
00041
00042
00043
00044 inline
00045 Assignment::Assignment(int n0, const Gecode::FloatVal& d0)
00046 : n(n0), d(d0) {}
00047 inline int
00048 Assignment::size(void) const {
00049 return n;
00050 }
00051 inline
00052 Assignment::~Assignment(void) {}
00053
00054 inline
00055 CpltAssignment::CpltAssignment(int n, const Gecode::FloatVal& d, Gecode::FloatNum s)
00056 : Assignment(n,d),
00057 dsv(new Gecode::FloatVal[static_cast<unsigned int>(n)]),
00058 step(s) {
00059 using namespace Gecode;
00060 for (int i=n; i--; )
00061 dsv[i] = FloatVal(d.min(),nextafter(d.min(),d.max()));
00062 }
00063 inline bool
00064 CpltAssignment::operator()(void) const {
00065 return dsv[0].min() <= d.max();
00066 }
00067 inline Gecode::FloatVal
00068 CpltAssignment::operator[](int i) const {
00069 assert((i>=0) && (i<n));
00070 return dsv[i];
00071 }
00072 inline void
00073 CpltAssignment::set(int i, const Gecode::FloatVal& val) {
00074 assert((i>=0) && (i<n));
00075 dsv[i] = val;
00076 }
00077 inline
00078 CpltAssignment::~CpltAssignment(void) {
00079 delete [] dsv;
00080 }
00081
00082 inline
00083 ExtAssignment::ExtAssignment(int n, const Gecode::FloatVal& d, Gecode::FloatNum s, const Test * pb)
00084 : Assignment(n,d),curPb(pb),
00085 dsv(new Gecode::FloatVal[static_cast<unsigned int>(n)]),
00086 step(s) {
00087 using namespace Gecode;
00088 for (int i=n-1; i--; )
00089 dsv[i] = FloatVal(d.min(),nextafter(d.min(),d.max()));
00090 ++(*this);
00091 }
00092 inline bool
00093 ExtAssignment::operator()(void) const {
00094 return dsv[0].min() <= d.max();
00095 }
00096 inline Gecode::FloatVal
00097 ExtAssignment::operator[](int i) const {
00098 assert((i>=0) && (i<n));
00099 return dsv[i];
00100 }
00101 inline void
00102 ExtAssignment::set(int i, const Gecode::FloatVal& val) {
00103 assert((i>=0) && (i<n));
00104 dsv[i] = val;
00105 }
00106 inline
00107 ExtAssignment::~ExtAssignment(void) {
00108 delete [] dsv;
00109 }
00110
00111 forceinline Gecode::FloatNum
00112 RandomAssignment::randval(void) {
00113 using namespace Gecode;
00114 using namespace Gecode::Float;
00115 Rounding r;
00116 return
00117 r.add_down(
00118 d.min(),
00119 r.mul_down(
00120 r.div_down(
00121 Base::rand(static_cast<unsigned int>(Gecode::Int::Limits::max)),
00122 static_cast<FloatNum>(Gecode::Int::Limits::max)
00123 ),
00124 r.sub_down(d.max(),d.min())
00125 )
00126 );
00127 }
00128
00129 inline
00130 RandomAssignment::RandomAssignment(int n, const Gecode::FloatVal& d, int a0)
00131 : Assignment(n,d), vals(new Gecode::FloatVal[n]), a(a0) {
00132 for (int i=n; i--; )
00133 vals[i] = randval();
00134 }
00135
00136 inline bool
00137 RandomAssignment::operator()(void) const {
00138 return a>0;
00139 }
00140 inline Gecode::FloatVal
00141 RandomAssignment::operator[](int i) const {
00142 assert((i>=0) && (i<n));
00143 return vals[i];
00144 }
00145 inline void
00146 RandomAssignment::set(int i, const Gecode::FloatVal& val) {
00147 assert((i>=0) && (i<n));
00148 vals[i] = val;
00149 }
00150 inline
00151 RandomAssignment::~RandomAssignment(void) {
00152 delete [] vals;
00153 }
00154
00155
00156
00157
00158
00159 forceinline bool
00160 Test::eqv(void) const {
00161 return reified && ((rms & (1 << Gecode::RM_EQV)) != 0);
00162 }
00163 forceinline bool
00164 Test::imp(void) const {
00165 return reified && ((rms & (1 << Gecode::RM_IMP)) != 0);
00166 }
00167 forceinline bool
00168 Test::pmi(void) const {
00169 return reified && ((rms & (1 << Gecode::RM_PMI)) != 0);
00170 }
00171 inline
00172 Test::Test(const std::string& s, int a, const Gecode::FloatVal& d,
00173 Gecode::FloatNum st, AssignmentType at,
00174 bool r)
00175 : Base("Float::"+s), arity(a), dom(d), step(st), assigmentType(at),
00176 reified(r), rms((1 << Gecode::RM_EQV) |
00177 (1 << Gecode::RM_IMP) |
00178 (1 << Gecode::RM_PMI)),
00179 testsearch(true), testfix(true), testsubsumed(true) {}
00180
00181 inline
00182 Test::Test(const std::string& s, int a, Gecode::FloatNum min,
00183 Gecode::FloatNum max, Gecode::FloatNum st, AssignmentType at,
00184 bool r)
00185 : Base("Float::"+s), arity(a), dom(min,max), step(st),
00186 assigmentType(at), reified(r),
00187 rms((1 << Gecode::RM_EQV) |
00188 (1 << Gecode::RM_IMP) |
00189 (1 << Gecode::RM_PMI)),
00190 testsearch(true), testfix(true), testsubsumed(true) {}
00191
00192 inline
00193 std::string
00194 Test::str(Gecode::FloatRelType frt) {
00195 using namespace Gecode;
00196 switch (frt) {
00197 case FRT_EQ: return "Eq";
00198 case FRT_NQ: return "Nq";
00199 case FRT_LQ: return "Lq";
00200 case FRT_LE: return "Le";
00201 case FRT_GQ: return "Gq";
00202 case FRT_GR: return "Gr";
00203 default: ;
00204 }
00205 GECODE_NEVER;
00206 return "NONE";
00207 }
00208
00209 inline
00210 std::string
00211 Test::str(Gecode::FloatNum f) {
00212 std::stringstream s;
00213 s << f;
00214 return s.str();
00215 }
00216
00217 inline
00218 std::string
00219 Test::str(Gecode::FloatVal f) {
00220 std::stringstream s;
00221 s << "[" << f.min() << ":" << f.max() << "]";
00222 return s.str();
00223 }
00224
00225 inline
00226 std::string
00227 Test::str(const Gecode::FloatValArgs& x) {
00228 std::string s = "";
00229 for (int i=0; i<x.size()-1; i++)
00230 s += str(x[i]) + ",";
00231 return "[" + s + str(x[x.size()-1]) + "]";
00232 }
00233
00234 inline MaybeType
00235 Test::cmp(Gecode::FloatVal x, Gecode::FloatRelType r, Gecode::FloatVal y) {
00236 using namespace Gecode;
00237 switch (r) {
00238 case FRT_EQ:
00239 if (x == y) return MT_TRUE;
00240 if (x != y) return MT_FALSE;
00241 break;
00242 case FRT_NQ:
00243 if (x != y) return MT_TRUE;
00244 if (x == y) return MT_FALSE;
00245 break;
00246 case FRT_LQ:
00247 if (x <= y) return MT_TRUE;
00248 if (x > y) return MT_FALSE;
00249 break;
00250 case FRT_LE:
00251 if (x < y) return MT_TRUE;
00252 if (x >= y) return MT_FALSE;
00253 break;
00254 case FRT_GQ:
00255 if (x >= y) return MT_TRUE;
00256 if (x < y) return MT_FALSE;
00257 break;
00258 case FRT_GR:
00259 if (x > y) return MT_TRUE;
00260 if (x <= y) return MT_FALSE;
00261 break;
00262 default: ;
00263 }
00264 return MT_MAYBE;
00265 }
00266
00267 inline MaybeType
00268 Test::eq(Gecode::FloatVal x, Gecode::FloatVal y) {
00269 return cmp(x, Gecode::FRT_EQ, y);
00270 }
00271
00272 inline bool
00273 Test::flip(void) {
00274 return Base::rand(2U) == 0U;
00275 }
00276
00277 inline MaybeType
00278 operator &(MaybeType a, MaybeType b) {
00279 switch (a) {
00280 case MT_TRUE: return b;
00281 case MT_FALSE: return MT_FALSE;
00282 default: ;
00283 }
00284 return (b == MT_FALSE) ? MT_FALSE : MT_MAYBE;
00285 }
00286
00287
00288 inline
00289 FloatRelTypes::FloatRelTypes(void)
00290 : i(sizeof(frts)/sizeof(Gecode::FloatRelType)-1) {}
00291 inline void
00292 FloatRelTypes::reset(void) {
00293 i = sizeof(frts)/sizeof(Gecode::FloatRelType)-1;
00294 }
00295 inline bool
00296 FloatRelTypes::operator()(void) const {
00297 return i>=0;
00298 }
00299 inline void
00300 FloatRelTypes::operator++(void) {
00301 i--;
00302 }
00303 inline Gecode::FloatRelType
00304 FloatRelTypes::frt(void) const {
00305 return frts[i];
00306 }
00307
00308 }}
00309
00310
00311