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