this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Vincent Barichard <Vincent.Barichard@univ-angers.fr> 5 * 6 * Copyright: 7 * Vincent Barichard, 2012 8 * 9 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files (the 15 * "Software"), to deal in the Software without restriction, including 16 * without limitation the rights to use, copy, modify, merge, publish, 17 * distribute, sublicense, and/or sell copies of the Software, and to 18 * permit persons to whom the Software is furnished to do so, subject to 19 * the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34namespace Gecode { namespace Float { namespace Arithmetic { 35 36 37 /* 38 * Bounds consistent square operator 39 * 40 */ 41 42 template<class A, class B> 43 forceinline 44 Pow<A,B>::Pow(Home home, A x0, B x1, int n) 45 : MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>(home,x0,x1), m_n(n) {} 46 47 template<class A, class B> 48 ExecStatus 49 Pow<A,B>::post(Home home, A x0, B x1, int n) { 50 if (n == 0) { 51 if ((x0.min() == 0.0) && (x0.max() == 0.0)) return ES_FAILED; 52 GECODE_ME_CHECK(x1.eq(home,1.0)); 53 return ES_OK; 54 } 55 56 GECODE_ME_CHECK(x1.eq(home,pow(x0.domain(),n))); 57 if ((x1.min() == 0.0) && (x1.max() == 0.0)) { 58 GECODE_ME_CHECK(x1.eq(home,0.0)); 59 return ES_OK; 60 } 61 62 if ((n % 2) == 0) { 63 if (x0.min() >= 0) 64 GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),n))); 65 else if (x0.max() <= 0) 66 GECODE_ME_CHECK(x0.eq(home,-nroot(x1.domain(),n))); 67 else 68 GECODE_ME_CHECK(x0.eq(home, 69 hull( 70 nroot(x1.domain(),n), 71 -nroot(x1.domain(),n) 72 ) 73 )); 74 } else { 75 GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),n))); 76 } 77 78 if (!x0.assigned()) (void) new (home) Pow<A,B>(home,x0,x1,n); 79 return ES_OK; 80 } 81 82 template<class A, class B> 83 forceinline 84 Pow<A,B>::Pow(Space& home, Pow<A,B>& p) 85 : MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>(home,p), m_n(p.m_n) {} 86 87 template<class A, class B> 88 Actor* 89 Pow<A,B>::copy(Space& home) { 90 return new (home) Pow<A,B>(home,*this); 91 } 92 93 template<class A, class B> 94 ExecStatus 95 Pow<A,B>::propagate(Space& home, const ModEventDelta&) { 96 if ((x0.min() == 0.0) && (x0.max() == 0.0)) return ES_FAILED; 97 GECODE_ME_CHECK(x1.eq(home,pow(x0.domain(),m_n))); 98 99 if ((x1.min() == 0.0) && (x1.max() == 0.0)) { 100 GECODE_ME_CHECK(x1.eq(home,0.0)); 101 return home.ES_SUBSUMED(*this); 102 } 103 104 if ((m_n % 2) == 0) { 105 if (x0.min() >= 0) 106 GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),m_n))); 107 else if (x0.max() <= 0) 108 GECODE_ME_CHECK(x0.eq(home,-nroot(x1.domain(),m_n))); 109 else 110 GECODE_ME_CHECK(x0.eq(home, 111 hull( 112 nroot(x1.domain(),m_n), 113 -nroot(x1.domain(),m_n) 114 ) 115 )); 116 } else { 117 GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),m_n))); 118 } 119 return x0.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX; 120 } 121 122 /* 123 * Bounds consistent square root operator 124 * 125 */ 126 127 template<class A, class B> 128 forceinline 129 NthRoot<A,B>::NthRoot(Home home, A x0, B x1, int n) 130 : MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>(home,x0,x1), m_n(n) {} 131 132 template<class A, class B> 133 ExecStatus 134 NthRoot<A,B>::post(Home home, A x0, B x1, int n) { 135 if (n == 0) return ES_FAILED; 136 GECODE_ME_CHECK(x0.gq(home,0.0)); 137 GECODE_ME_CHECK(x1.eq(home,nroot(x0.domain(),n))); 138 GECODE_ME_CHECK(x0.eq(home,pow(x1.domain(),n))); 139 (void) new (home) NthRoot<A,B>(home,x0,x1,n); 140 return ES_OK; 141 } 142 143 template<class A, class B> 144 forceinline 145 NthRoot<A,B>::NthRoot(Space& home, NthRoot<A,B>& p) 146 : MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>(home,p), m_n(p.m_n) {} 147 148 template<class A, class B> 149 Actor* 150 NthRoot<A,B>::copy(Space& home) { 151 return new (home) NthRoot<A,B>(home,*this); 152 } 153 154 template<class A, class B> 155 ExecStatus 156 NthRoot<A,B>::propagate(Space& home, const ModEventDelta&) { 157 GECODE_ME_CHECK(x1.eq(home,nroot(x0.domain(),m_n))); 158 GECODE_ME_CHECK(x0.eq(home,pow(x1.domain(),m_n))); 159 return x0.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX; 160 } 161 162 163}}} 164 165// STATISTICS: float-prop 166