Generated on Thu Apr 11 13:59:01 2019 for Gecode by doxygen 1.6.3

exp-log.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 Transcendental {
00035 
00036   /*
00037    * Bounds consistent exponential operator
00038    *
00039    */
00040 
00041   template<class A, class B>
00042   forceinline
00043   Exp<A,B>::Exp(Home home, A x0, B x1)
00044     : MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>(home,x0,x1) {}
00045 
00046   template<class A, class B>
00047   ExecStatus
00048   Exp<A,B>::post(Home home, A x0, B x1) {
00049     if (x0 == x1) {
00050       return ES_FAILED;
00051     } else {
00052       GECODE_ME_CHECK(x1.gq(home,0.0));
00053     }
00054     GECODE_ME_CHECK(x1.eq(home,exp(x0.domain())));
00055     if (x1.max() == 0.0)
00056       return ES_FAILED;
00057     GECODE_ME_CHECK(x0.eq(home,log(x1.domain())));
00058     (void) new (home) Exp<A,B>(home,x0,x1);
00059     return ES_OK;
00060   }
00061 
00062 
00063   template<class A, class B>
00064   forceinline
00065   Exp<A,B>::Exp(Space& home, Exp<A,B>& p)
00066     : MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>(home,p) {}
00067 
00068   template<class A, class B>
00069   Actor*
00070   Exp<A,B>::copy(Space& home) {
00071     return new (home) Exp<A,B>(home,*this);
00072   }
00073 
00074   template<class A, class B>
00075   ExecStatus
00076   Exp<A,B>::propagate(Space& home, const ModEventDelta&) {
00077     GECODE_ME_CHECK(x1.eq(home,exp(x0.domain())));
00078     if (x1.max() == 0.0)
00079       return ES_FAILED;
00080     GECODE_ME_CHECK(x0.eq(home,log(x1.domain())));
00081     return x0.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX;
00082   }
00083 
00084 
00085   /*
00086    * Bounds consistent logarithm operator with base
00087    *
00088    */
00089 
00090   template<class A, class B>
00091   forceinline
00092   Pow<A,B>::Pow(Home home, FloatNum base0, A x0, B x1)
00093     : MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>(home,x0,x1),
00094       base(base0) {}
00095 
00096   template<class A, class B>
00097   ExecStatus
00098   Pow<A,B>::post(Home home, FloatNum base, A x0, B x1) {
00099     if (base <= 0) return ES_FAILED;
00100     if (x0 == x1) {
00101       GECODE_ME_CHECK(x0.eq(home,0.0));
00102     } else {
00103       GECODE_ME_CHECK(x1.gq(home,0.0));
00104       if (x1.max() == 0.0)
00105         return ES_FAILED;
00106       GECODE_ME_CHECK(x0.eq(home,log(x1.domain())/log(base)));
00107       GECODE_ME_CHECK(x1.eq(home,exp(x0.domain()*log(base))));
00108       (void) new (home) Pow<A,B>(home,base,x0,x1);
00109     }
00110     return ES_OK;
00111   }
00112 
00113   template<class A, class B>
00114   forceinline
00115   Pow<A,B>::Pow(Space& home, Pow<A,B>& p)
00116     : MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>(home,p),
00117       base(p.base) {}
00118 
00119   template<class A, class B>
00120   Actor*
00121   Pow<A,B>::copy(Space& home) {
00122     return new (home) Pow<A,B>(home,*this);
00123   }
00124 
00125   template<class A, class B>
00126   ExecStatus
00127   Pow<A,B>::propagate(Space& home, const ModEventDelta&) {
00128     if (x1.max() == 0.0)
00129       return ES_FAILED;
00130     GECODE_ME_CHECK(x0.eq(home,log(x1.domain())/log(base)));
00131     GECODE_ME_CHECK(x1.eq(home,exp(x0.domain()*log(base))));
00132     return x0.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX;
00133   }
00134 
00135 }}}
00136 
00137 // STATISTICS: float-prop
00138