this repo has no description
at develop 3.4 kB view raw
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * Vincent Barichard <Vincent.Barichard@univ-angers.fr> 6 * 7 * Copyright: 8 * Christian Schulte, 2006 9 * Vincent Barichard, 2012 10 * 11 * This file is part of Gecode, the generic constraint 12 * development environment: 13 * http://www.gecode.org 14 * 15 * Permission is hereby granted, free of charge, to any person obtaining 16 * a copy of this software and associated documentation files (the 17 * "Software"), to deal in the Software without restriction, including 18 * without limitation the rights to use, copy, modify, merge, publish, 19 * distribute, sublicense, and/or sell copies of the Software, and to 20 * permit persons to whom the Software is furnished to do so, subject to 21 * the following conditions: 22 * 23 * The above copyright notice and this permission notice shall be 24 * included in all copies or substantial portions of the Software. 25 * 26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 * 34 */ 35 36#include "test/float.hh" 37 38#include <gecode/minimodel.hh> 39 40namespace Test { namespace Float { 41 42 /// %Tests for channel constraints 43 namespace Channel { 44 45 /// %Test channel between float and integer 46 class Int : public Test { 47 public: 48 /// Construct and register test 49 Int(Gecode::FloatNum st) 50 : Test("Channel::Int",2,-1,2,st,CPLT_ASSIGNMENT,false) {} 51 /// Check whether \a x is solution 52 virtual MaybeType solution(const Assignment& x) const { 53 Gecode::FloatNum tmp; 54 return (((modf(x[0].min(),&tmp)==0) || 55 (modf(x[0].max(),&tmp)==0)) 56 && (x[0]==x[1])) ? MT_TRUE : MT_FALSE; 57 } 58 /// Post constraint on \a x 59 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { 60 using namespace Gecode; 61 IntVar iv(home,-1000,1000); 62 channel(home, x[0], iv); 63 channel(home, iv, x[1]); 64 } 65 }; 66 67 /// %Test channel between float and Boolean 68 class Bool : public Test { 69 public: 70 /// Construct and register test 71 Bool(Gecode::FloatNum st) 72 : Test("Channel::Bool",2,0,1,st,CPLT_ASSIGNMENT,false) {} 73 /// Check whether \a x is solution 74 virtual MaybeType solution(const Assignment& x) const { 75 Gecode::FloatNum tmp; 76 return (((modf(x[0].min(),&tmp)==0) || 77 (modf(x[0].max(),&tmp)==0)) 78 && (x[0]==x[1])) ? MT_TRUE : MT_FALSE; 79 } 80 /// Post constraint on \a x 81 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { 82 using namespace Gecode; 83 BoolVar bv(home,0,1); 84 channel(home, x[0], bv); 85 channel(home, bv, x[1]); 86 } 87 }; 88 89 Gecode::FloatNum step1 = 0.7; 90 Gecode::FloatNum step2 = 0.1; 91 92 Int ci(step1); 93 Bool cb(step2); 94 //@} 95 96 } 97}} 98 99// STATISTICS: test-float 100