Generated on Tue Apr 18 10:21:34 2017 for Gecode by doxygen 1.6.3

pow-nroot.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00005  *
00006  *  Copyright:
00007  *     Vincent Barichard, 2012
00008  *
00009  *  Last modified:
00010  *     $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
00011  *     $Revision: 14967 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode { namespace Float { namespace Arithmetic {
00039 
00040 
00041   /*
00042    * Bounds consistent square operator
00043    *
00044    */
00045 
00046   template<class A, class B>
00047   forceinline
00048   Pow<A,B>::Pow(Home home, A x0, B x1, int n)
00049     : MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>(home,x0,x1), m_n(n) {}
00050 
00051   template<class A, class B>
00052   ExecStatus
00053   Pow<A,B>::post(Home home, A x0, B x1, int n) {
00054     if (n == 0) {
00055       if ((x0.min() == 0.0) && (x0.max() == 0.0)) return ES_FAILED;
00056       GECODE_ME_CHECK(x1.eq(home,1.0));
00057       return ES_OK;
00058     }
00059 
00060     GECODE_ME_CHECK(x1.eq(home,pow(x0.domain(),n)));
00061     if ((x1.min() == 0.0) && (x1.max() == 0.0)) {
00062       GECODE_ME_CHECK(x1.eq(home,0.0));
00063       return ES_OK;
00064     }
00065 
00066     if ((n % 2) == 0)
00067     {
00068       if (x0.min() >= 0)
00069         GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),n)));
00070       else if (x0.max() <= 0)
00071         GECODE_ME_CHECK(x0.eq(home,-nroot(x1.domain(),n)));
00072       else
00073         GECODE_ME_CHECK(x0.eq(home,
00074                               hull(
00075                                   nroot(x1.domain(),n),
00076                                   -nroot(x1.domain(),n)
00077                               )
00078                         ));
00079     } else
00080       GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),n)));
00081 
00082     if (!x0.assigned()) (void) new (home) Pow<A,B>(home,x0,x1,n);
00083     return ES_OK;
00084   }
00085 
00086   template<class A, class B>
00087   forceinline
00088   Pow<A,B>::Pow(Space& home, bool share, Pow<A,B>& p)
00089     : MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>(home,share,p), m_n(p.m_n) {}
00090 
00091   template<class A, class B>
00092   Actor*
00093   Pow<A,B>::copy(Space& home, bool share) {
00094     return new (home) Pow<A,B>(home,share,*this);
00095   }
00096 
00097   template<class A, class B>
00098   ExecStatus
00099   Pow<A,B>::propagate(Space& home, const ModEventDelta&) {
00100     if ((x0.min() == 0.0) && (x0.max() == 0.0)) return ES_FAILED;
00101     GECODE_ME_CHECK(x1.eq(home,pow(x0.domain(),m_n)));
00102 
00103     if ((x1.min() == 0.0) && (x1.max() == 0.0)) {
00104       GECODE_ME_CHECK(x1.eq(home,0.0));
00105       return home.ES_SUBSUMED(*this);
00106     }
00107 
00108     if ((m_n % 2) == 0)
00109     {
00110       if (x0.min() >= 0)
00111         GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),m_n)));
00112       else if (x0.max() <= 0)
00113         GECODE_ME_CHECK(x0.eq(home,-nroot(x1.domain(),m_n)));
00114       else
00115         GECODE_ME_CHECK(x0.eq(home,
00116                               hull(
00117                                   nroot(x1.domain(),m_n),
00118                                   -nroot(x1.domain(),m_n)
00119                               )
00120                         ));
00121     } else
00122       GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),m_n)));
00123     return x0.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX;
00124   }
00125 
00126   /*
00127    * Bounds consistent square root operator
00128    *
00129    */
00130 
00131   template<class A, class B>
00132   forceinline
00133   NthRoot<A,B>::NthRoot(Home home, A x0, B x1, int n)
00134     : MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>(home,x0,x1), m_n(n) {}
00135 
00136   template<class A, class B>
00137   ExecStatus
00138   NthRoot<A,B>::post(Home home, A x0, B x1, int n) {
00139     if (n == 0) return ES_FAILED;
00140     GECODE_ME_CHECK(x0.gq(home,0.0));
00141     (void) new (home) NthRoot<A,B>(home,x0,x1,n);
00142     return ES_OK;
00143   }
00144 
00145   template<class A, class B>
00146   forceinline
00147   NthRoot<A,B>::NthRoot(Space& home, bool share, NthRoot<A,B>& p)
00148     : MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>(home,share,p), m_n(p.m_n) {}
00149 
00150   template<class A, class B>
00151   Actor*
00152   NthRoot<A,B>::copy(Space& home, bool share) {
00153     return new (home) NthRoot<A,B>(home,share,*this);
00154   }
00155 
00156   template<class A, class B>
00157   ExecStatus
00158   NthRoot<A,B>::propagate(Space& home, const ModEventDelta&) {
00159     GECODE_ME_CHECK(x1.eq(home,nroot(x0.domain(),m_n)));
00160     GECODE_ME_CHECK(x0.eq(home,pow(x1.domain(),m_n)));
00161     return x0.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX;
00162   }
00163 
00164 
00165 }}}
00166 
00167 // STATISTICS: float-prop
00168