/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * Mikael Lagerkvist * Vincent Barichard * * 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(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=0) && (i(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=0) && (i(Gecode::Int::Limits::max)), static_cast(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=0) && (i 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