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

arithmetic.hh

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *     Guido Tack <tack@gecode.org>
00006  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00007  *
00008  *  Copyright:
00009  *     Christian Schulte, 2002
00010  *     Guido Tack, 2004
00011  *     Vincent Barichard, 2012
00012  *
00013  *  Last modified:
00014  *     $Date: 2017-04-10 13:21:37 +0200 (Mon, 10 Apr 2017) $ by $Author: schulte $
00015  *     $Revision: 15631 $
00016  *
00017  *  This file is part of Gecode, the generic constraint
00018  *  development environment:
00019  *     http://www.gecode.org
00020  *
00021  *  Permission is hereby granted, free of charge, to any person obtaining
00022  *  a copy of this software and associated documentation files (the
00023  *  "Software"), to deal in the Software without restriction, including
00024  *  without limitation the rights to use, copy, modify, merge, publish,
00025  *  distribute, sublicense, and/or sell copies of the Software, and to
00026  *  permit persons to whom the Software is furnished to do so, subject to
00027  *  the following conditions:
00028  *
00029  *  The above copyright notice and this permission notice shall be
00030  *  included in all copies or substantial portions of the Software.
00031  *
00032  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00033  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00034  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00035  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00036  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00037  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00038  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00039  *
00040  */
00041 
00042 #ifndef __GECODE_FLOAT_ARITHMETIC_HH__
00043 #define __GECODE_FLOAT_ARITHMETIC_HH__
00044 
00045 #include <gecode/int.hh>
00046 #include <gecode/float.hh>
00047 #include <gecode/float/rel.hh>
00048 
00054 namespace Gecode { namespace Float { namespace Arithmetic {
00055 
00061   template<class VA, class VB>
00062   class SqrPlus : public MixBinaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND> {
00063   protected:
00064     using MixBinaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND>::x0;
00065     using MixBinaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND>::x1;
00067     SqrPlus(Home home, VA x0, VB x1);
00069     SqrPlus(Space& home, bool share, SqrPlus<VA,VB>& p);
00070   public:
00072     static ExecStatus post(Home home, VA x0, VB x1);
00074     virtual Actor* copy(Space& home, bool share);
00076     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00077   };
00078 
00085   template<class View>
00086   class Sqr : public BinaryPropagator<View,PC_FLOAT_BND> {
00087   protected:
00088     using BinaryPropagator<View,PC_FLOAT_BND>::x0;
00089     using BinaryPropagator<View,PC_FLOAT_BND>::x1;
00090 
00092     Sqr(Space& home, bool share, Sqr& p);
00094     Sqr(Home home, View x0, View x1);
00095   public:
00097     virtual Actor* copy(Space& home, bool share);
00099     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00101     static ExecStatus post(Home home, View x0, View x1);
00102   };
00103 
00112   template<class A, class B>
00113   class Sqrt : public MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND> {
00114   protected:
00115     using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x0;
00116     using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x1;
00117 
00119     Sqrt(Space& home, bool share, Sqrt& p);
00121     Sqrt(Home home, A x0, B x1);
00122   public:
00124     virtual Actor* copy(Space& home, bool share);
00126     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00128     static ExecStatus post(Home home, A x0, B x1);
00129   };
00130 
00139   template<class A, class B>
00140   class Abs : public MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND> {
00141   protected:
00142     using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x0;
00143     using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x1;
00144 
00146     Abs(Space& home, bool share, Abs& p);
00148     Abs(Home home, A x0, B x1);
00149   public:
00151     Abs(Space& home, bool share, Propagator& p, A x0, B x1);
00153     virtual Actor* copy(Space& home, bool share);
00155     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00157     static ExecStatus post(Home home, A x0, B x1);
00158   };
00159 
00168   template<class A, class B>
00169   class Pow : public MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND> {
00170   protected:
00171     using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x0;
00172     using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x1;
00173     int m_n;
00174 
00176     Pow(Space& home, bool share, Pow& p);
00178     Pow(Home home, A x0, B x1, int n);
00179   public:
00181     virtual Actor* copy(Space& home, bool share);
00183     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00185     static ExecStatus post(Home home, A x0, B x1, int n);
00186   };
00187 
00196   template<class A, class B>
00197   class NthRoot : public MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND> {
00198   protected:
00199     using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x0;
00200     using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x1;
00201     int m_n;
00202 
00204     NthRoot(Space& home, bool share, NthRoot& p);
00206     NthRoot(Home home, A x0, B x1, int n);
00207   public:
00209     virtual Actor* copy(Space& home, bool share);
00211     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00213     static ExecStatus post(Home home, A x0, B x1, int n);
00214   };
00215 
00222   template<class View>
00223   class MultZeroOne : public BinaryPropagator<View,PC_FLOAT_BND> {
00224   protected:
00225     using BinaryPropagator<View,PC_FLOAT_BND>::x0;
00226     using BinaryPropagator<View,PC_FLOAT_BND>::x1;
00227 
00229     MultZeroOne(Space& home, bool share, MultZeroOne<View>& p);
00231     MultZeroOne(Home home, View x0, View x1);
00232   public:
00234     virtual Actor* copy(Space& home, bool share);
00236     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00238     static ExecStatus post(Home home, View x0, View x1);
00239   };
00240 
00241 
00247   template<class VA, class VB, class VC>
00248   class MultPlus :
00249     public MixTernaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND,VC,PC_FLOAT_BND> {
00250   protected:
00251     using MixTernaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND,VC,PC_FLOAT_BND>::x0;
00252     using MixTernaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND,VC,PC_FLOAT_BND>::x1;
00253     using MixTernaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND,VC,PC_FLOAT_BND>::x2;
00254   public:
00256     MultPlus(Home home, VA x0, VB x1, VC x2);
00258     MultPlus(Space& home, bool share, MultPlus<VA,VB,VC>& p);
00260     static ExecStatus post(Home home, VA x0, VB x1, VC x2);
00262     virtual Actor* copy(Space& home, bool share);
00264     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00265   };
00266 
00274   template<class View>
00275   class Mult : public TernaryPropagator<View,PC_FLOAT_BND> {
00276   protected:
00277     using TernaryPropagator<View,PC_FLOAT_BND>::x0;
00278     using TernaryPropagator<View,PC_FLOAT_BND>::x1;
00279     using TernaryPropagator<View,PC_FLOAT_BND>::x2;
00280 
00282     Mult(Space& home, bool share, Mult<View>& p);
00283   public:
00285     Mult(Home home, View x0, View x1, View x2);
00287     static  ExecStatus post(Home home, View x0, View x1, View x2);
00289     virtual Actor* copy(Space& home, bool share);
00291     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00292   };
00293 
00294 
00303   template<class A, class B, class C>
00304   class Div : public MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND> {
00305   protected:
00306     using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x0;
00307     using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x1;
00308     using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x2;
00310     Div(Space& home, bool share, Div& p);
00312     Div(Home home, A x0, B x1, C x2);
00313   public:
00315     virtual Actor* copy(Space& home, bool share);
00317     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00319     static ExecStatus post(Home home, A x0, B x1, C x2);
00320   };
00321 
00330   template<class A, class B, class C>
00331   class Min : public MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND> {
00332   protected:
00333     using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x0;
00334     using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x1;
00335     using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x2;
00337     Min(Space& home, bool share, Min& p);
00339     Min(Home home, A x0, B x1, C x2);
00340   public:
00342     Min(Space& home, bool share, Propagator& p, A x0, B x1, C x2);
00344     virtual Actor* copy(Space& home, bool share);
00346     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00348     static ExecStatus post(Home home, A x0, B x1, C x2);
00349   };
00350 
00359   template<class A, class B, class C>
00360   class Max : public MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND> {
00361   protected:
00362     using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x0;
00363     using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x1;
00364     using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x2;
00366     Max(Space& home, bool share, Max& p);
00368     Max(Home home, A x0, B x1, C x2);
00369   public:
00371     Max(Space& home, bool share, Propagator& p, A x0, B x1, C x2);
00373     virtual Actor* copy(Space& home, bool share);
00375     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00377     static ExecStatus post(Home home, A x0, B x1, C x2);
00378   };
00379 
00386   template<class View>
00387   class NaryMax : public NaryOnePropagator<View,PC_FLOAT_BND> {
00388   protected:
00389     using NaryOnePropagator<View,PC_FLOAT_BND>::x;
00390     using NaryOnePropagator<View,PC_FLOAT_BND>::y;
00391 
00393     NaryMax(Space& home, bool share, NaryMax& p);
00395     NaryMax(Home home, ViewArray<View>& x, View y);
00396   public:
00398     virtual Actor* copy(Space& home, bool share);
00400     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00402     static  ExecStatus post(Home home, ViewArray<View>& x, View y);
00403   };
00404 
00405 }}}
00406 
00407 #include <gecode/float/arithmetic/sqr-sqrt.hpp>
00408 #include <gecode/float/arithmetic/abs.hpp>
00409 #include <gecode/float/arithmetic/pow-nroot.hpp>
00410 #include <gecode/float/arithmetic/mult.hpp>
00411 #include <gecode/float/arithmetic/div.hpp>
00412 #include <gecode/float/arithmetic/min-max.hpp>
00413 
00414 #endif
00415 
00416 // STATISTICS: float-prop