1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
|
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
* Mikael Lagerkvist <lagerkvist@gecode.org>
* Vincent Barichard <Vincent.Barichard@univ-angers.fr>
*
* Copyright:
* Christian Schulte, 2005
* Mikael Lagerkvist, 2006
* Vincent Barichard, 2012
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
namespace Test { namespace Float {
/*
* Assignments
*
*/
inline
Assignment::Assignment(int n0, const Gecode::FloatVal& d0)
: n(n0), d(d0) {}
inline int
Assignment::size(void) const {
return n;
}
inline
Assignment::~Assignment(void) {}
inline
CpltAssignment::CpltAssignment(int n, const Gecode::FloatVal& d, Gecode::FloatNum s)
: Assignment(n,d),
dsv(new Gecode::FloatVal[static_cast<unsigned int>(n)]),
step(s) {
using namespace Gecode;
for (int i=n; i--; )
dsv[i] = FloatVal(d.min(),nextafter(d.min(),d.max()));
}
inline bool
CpltAssignment::has_more() const {
return dsv[0].min() <= d.max();
}
inline Gecode::FloatVal
CpltAssignment::operator[](int i) const {
assert((i>=0) && (i<n));
return dsv[i];
}
inline void
CpltAssignment::set(int i, const Gecode::FloatVal& val) {
assert((i>=0) && (i<n));
dsv[i] = val;
}
inline
CpltAssignment::~CpltAssignment(void) {
delete [] dsv;
}
inline
ExtAssignment::ExtAssignment(int n, const Gecode::FloatVal& d, Gecode::FloatNum s, const Test* pb,
Gecode::Support::RandomGenerator& rand)
: Assignment(n,d),curPb(pb),
dsv(new Gecode::FloatVal[static_cast<unsigned int>(n)]),
step(s) {
using namespace Gecode;
for (int i=n-1; i--; )
dsv[i] = FloatVal(d.min(),nextafter(d.min(),d.max()));
(*this).next(rand);
}
inline bool
ExtAssignment::has_more() const {
return dsv[0].min() <= d.max();
}
inline Gecode::FloatVal
ExtAssignment::operator[](int i) const {
assert((i>=0) && (i<n));
return dsv[i];
}
inline void
ExtAssignment::set(int i, const Gecode::FloatVal& val) {
assert((i>=0) && (i<n));
dsv[i] = val;
}
inline
ExtAssignment::~ExtAssignment(void) {
delete [] dsv;
}
forceinline Gecode::FloatNum
RandomAssignment::randval(Gecode::Support::RandomGenerator& rand) {
using namespace Gecode;
using namespace Gecode::Float;
Rounding r;
return
r.add_down(
d.min(),
r.mul_down(
r.div_down(
rand(static_cast<unsigned int>(Gecode::Int::Limits::max)),
static_cast<FloatNum>(Gecode::Int::Limits::max)
),
r.sub_down(d.max(),d.min())
)
);
}
inline
RandomAssignment::RandomAssignment(int n, const Gecode::FloatVal& d, int a0, Gecode::Support::RandomGenerator& rand)
: Assignment(n,d), vals(new Gecode::FloatVal[n]), a(a0) {
for (int i=n; i--; )
vals[i] = randval(rand);
}
inline bool
RandomAssignment::has_more() const {
return a>0;
}
inline Gecode::FloatVal
RandomAssignment::operator[](int i) const {
assert((i>=0) && (i<n));
return vals[i];
}
inline void
RandomAssignment::set(int i, const Gecode::FloatVal& val) {
assert((i>=0) && (i<n));
vals[i] = val;
}
inline
RandomAssignment::~RandomAssignment(void) {
delete [] vals;
}
/*
* Tests with float constraints
*
*/
forceinline bool
Test::eqv(void) const {
return reified && ((rms & (1 << Gecode::RM_EQV)) != 0);
}
forceinline bool
Test::imp(void) const {
return reified && ((rms & (1 << Gecode::RM_IMP)) != 0);
}
forceinline bool
Test::pmi(void) const {
return reified && ((rms & (1 << Gecode::RM_PMI)) != 0);
}
inline
Test::Test(const std::string& s, int a, const Gecode::FloatVal& d,
Gecode::FloatNum st, AssignmentType at,
bool r)
: Base("Float::"+s), arity(a), dom(d), step(st), assignmentType(at),
reified(r), rms((1 << Gecode::RM_EQV) |
(1 << Gecode::RM_IMP) |
(1 << Gecode::RM_PMI)),
testsearch(true), testfix(true), testsubsumed(true) {}
inline
Test::Test(const std::string& s, int a, Gecode::FloatNum min,
Gecode::FloatNum max, Gecode::FloatNum st, AssignmentType at,
bool r)
: Base("Float::"+s), arity(a), dom(min,max), step(st),
assignmentType(at), reified(r),
rms((1 << Gecode::RM_EQV) |
(1 << Gecode::RM_IMP) |
(1 << Gecode::RM_PMI)),
testsearch(true), testfix(true), testsubsumed(true) {}
inline
std::string
Test::str(Gecode::FloatRelType frt) {
using namespace Gecode;
switch (frt) {
case FRT_EQ: return "Eq";
case FRT_NQ: return "Nq";
case FRT_LQ: return "Lq";
case FRT_LE: return "Le";
case FRT_GQ: return "Gq";
case FRT_GR: return "Gr";
default: ;
}
GECODE_NEVER;
return "NONE";
}
inline
std::string
Test::str(Gecode::FloatNum f) {
std::stringstream s;
s << f;
return s.str();
}
inline
std::string
Test::str(Gecode::FloatVal f) {
std::stringstream s;
s << "[" << f.min() << ":" << f.max() << "]";
return s.str();
}
inline
std::string
Test::str(const Gecode::FloatValArgs& x) {
std::string s = "";
for (int i=0; i<x.size()-1; i++)
s += str(x[i]) + ",";
return "[" + s + str(x[x.size()-1]) + "]";
}
inline MaybeType
Test::cmp(Gecode::FloatVal x, Gecode::FloatRelType r, Gecode::FloatVal y) {
using namespace Gecode;
switch (r) {
case FRT_EQ:
if (x == y) return MT_TRUE;
if (x != y) return MT_FALSE;
break;
case FRT_NQ:
if (x != y) return MT_TRUE;
if (x == y) return MT_FALSE;
break;
case FRT_LQ:
if (x <= y) return MT_TRUE;
if (x > y) return MT_FALSE;
break;
case FRT_LE:
if (x < y) return MT_TRUE;
if (x >= y) return MT_FALSE;
break;
case FRT_GQ:
if (x >= y) return MT_TRUE;
if (x < y) return MT_FALSE;
break;
case FRT_GR:
if (x > y) return MT_TRUE;
if (x <= y) return MT_FALSE;
break;
default: ;
}
return MT_MAYBE;
}
inline MaybeType
Test::eq(Gecode::FloatVal x, Gecode::FloatVal y) {
return cmp(x, Gecode::FRT_EQ, y);
}
inline bool
Test::flip(void) {
return _rand(2U) == 0U;
}
inline MaybeType
operator &(MaybeType a, MaybeType b) {
switch (a) {
case MT_TRUE: return b;
case MT_FALSE: return MT_FALSE;
default: ;
}
return (b == MT_FALSE) ? MT_FALSE : MT_MAYBE;
}
inline
FloatRelTypes::FloatRelTypes(void)
: i(sizeof(frts)/sizeof(Gecode::FloatRelType)-1) {}
inline void
FloatRelTypes::reset(void) {
i = sizeof(frts)/sizeof(Gecode::FloatRelType)-1;
}
inline bool
FloatRelTypes::operator()(void) const {
return i>=0;
}
inline void
FloatRelTypes::operator++(void) {
i--;
}
inline Gecode::FloatRelType
FloatRelTypes::frt(void) const {
return frts[i];
}
}}
// STATISTICS: test-float
|