Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
15 kB · 412 lines
C++
at develop
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- *//* * Main authors: * Christian Schulte <schulte@gecode.org> * Guido Tack <tack@gecode.org> * Vincent Barichard <Vincent.Barichard@univ-angers.fr> * * Copyright: * Christian Schulte, 2002 * Guido Tack, 2004 * Vincent Barichard, 2012 * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */
#ifndef GECODE_FLOAT_ARITHMETIC_HH#define GECODE_FLOAT_ARITHMETIC_HH
#include <gecode/int.hh>#include <gecode/float.hh>#include <gecode/float/rel.hh>
/** * \namespace Gecode::Float::Arithmetic * \brief %Arithmetic propagators */
namespace Gecode { namespace Float { namespace Arithmetic {
/** * \brief Bounds consistent positive square propagator * * This propagator provides multiplication for positive views only. */ template<class VA, class VB> class SqrPlus : public MixBinaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND> { protected: using MixBinaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND>::x0; using MixBinaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND>::x1; /// Constructor for posting SqrPlus(Home home, VA x0, VB x1); /// Constructor for cloning \a p SqrPlus(Space& home, SqrPlus<VA,VB>& p); public: /// Post propagator \f$x_0\cdot x_0=x_1\f$ static ExecStatus post(Home home, VA x0, VB x1); /// Copy propagator during cloning virtual Actor* copy(Space& home); /// Perform propagation virtual ExecStatus propagate(Space& home, const ModEventDelta& med); };
/** * \brief %Propagator for bounds consistent square operator * * Requires \code #include <gecode/float/arithmetic.hh> \endcode * \ingroup FuncFloatProp */ template<class View> class Sqr : public BinaryPropagator<View,PC_FLOAT_BND> { protected: using BinaryPropagator<View,PC_FLOAT_BND>::x0; using BinaryPropagator<View,PC_FLOAT_BND>::x1;
/// Constructor for cloning \a p Sqr(Space& home, Sqr& p); /// Constructor for creation Sqr(Home home, View x0, View x1); public: /// Create copy during cloning virtual Actor* copy(Space& home); /// Perform propagation virtual ExecStatus propagate(Space& home, const ModEventDelta& med); /// Post propagator for \f$x_0^2 = x_1\f$ static ExecStatus post(Home home, View x0, View x1); };
/** * \brief %Propagator for bounds consistent square root operator * * The types \a A and \a B give the types of the views. * * Requires \code #include <gecode/float/arithmetic.hh> \endcode * \ingroup FuncFloatProp */ template<class A, class B> class Sqrt : public MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND> { protected: using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x0; using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x1;
/// Constructor for cloning \a p Sqrt(Space& home, Sqrt& p); /// Constructor for creation Sqrt(Home home, A x0, B x1); public: /// Create copy during cloning virtual Actor* copy(Space& home); /// Perform propagation virtual ExecStatus propagate(Space& home, const ModEventDelta& med); /// Post propagator for \f$x_0^2 = x_1\f$ static ExecStatus post(Home home, A x0, B x1); };
/** * \brief %Propagator for bounds consistent absolute operator * * The types \a A and \a B give the types of the views. * * Requires \code #include <gecode/float/arithmetic.hh> \endcode * \ingroup FuncFloatProp */ template<class A, class B> class Abs : public MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND> { protected: using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x0; using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x1;
/// Constructor for cloning \a p Abs(Space& home, Abs& p); /// Constructor for creation Abs(Home home, A x0, B x1); public: /// Constructor for rewriting \a p during cloning Abs(Space& home, Propagator& p, A x0, B x1); /// Create copy during cloning virtual Actor* copy(Space& home); /// Perform propagation virtual ExecStatus propagate(Space& home, const ModEventDelta& med); /// Post propagator for \f$ |x_0| = x_1\f$ static ExecStatus post(Home home, A x0, B x1); };
/** * \brief %Propagator for bounds consistent pow operator * * The types \a A and \a B give the types of the views. * * Requires \code #include <gecode/float/arithmetic.hh> \endcode * \ingroup FuncFloatProp */ template<class A, class B> class Pow : public MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND> { protected: using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x0; using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x1; int m_n;
/// Constructor for cloning \a p Pow(Space& home, Pow& p); /// Constructor for creation Pow(Home home, A x0, B x1, int n); public: /// Create copy during cloning virtual Actor* copy(Space& home); /// Perform propagation virtual ExecStatus propagate(Space& home, const ModEventDelta& med); /// Post propagator for \f$x_0^n = x_1\f$ static ExecStatus post(Home home, A x0, B x1, int n); };
/** * \brief %Propagator for bounds consistent nth root operator * * The types \a A and \a B give the types of the views. * * Requires \code #include <gecode/float/arithmetic.hh> \endcode * \ingroup FuncFloatProp */ template<class A, class B> class NthRoot : public MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND> { protected: using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x0; using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x1; int m_n;
/// Constructor for cloning \a p NthRoot(Space& home, NthRoot& p); /// Constructor for creation NthRoot(Home home, A x0, B x1, int n); public: /// Create copy during cloning virtual Actor* copy(Space& home); /// Perform propagation virtual ExecStatus propagate(Space& home, const ModEventDelta& med); /// Post propagator for \f$x_0^(1/n) = x_1\f$ static ExecStatus post(Home home, A x0, B x1, int n); };
/** * \brief Bounds or domain consistent propagator for \f$x_0\times x_1=x_0\f$ * * Requires \code #include <gecode/float/arithmetic.hh> \endcode * \ingroup FuncFloatProp */ template<class View> class MultZeroOne : public BinaryPropagator<View,PC_FLOAT_BND> { protected: using BinaryPropagator<View,PC_FLOAT_BND>::x0; using BinaryPropagator<View,PC_FLOAT_BND>::x1;
/// Constructor for cloning \a p MultZeroOne(Space& home, MultZeroOne<View>& p); /// Constructor for posting MultZeroOne(Home home, View x0, View x1); public: /// Copy propagator during cloning virtual Actor* copy(Space& home); /// Perform propagation virtual ExecStatus propagate(Space& home, const ModEventDelta& med); /// Post propagator \f$x_0\cdot x_1=x_0\f$ static ExecStatus post(Home home, View x0, View x1); };
/** * \brief Bounds consistent positive multiplication propagator * * This propagator provides multiplication for positive views only. */ template<class VA, class VB, class VC> class MultPlus : public MixTernaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND,VC,PC_FLOAT_BND> { protected: using MixTernaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND,VC,PC_FLOAT_BND>::x0; using MixTernaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND,VC,PC_FLOAT_BND>::x1; using MixTernaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND,VC,PC_FLOAT_BND>::x2; public: /// Constructor for posting MultPlus(Home home, VA x0, VB x1, VC x2); /// Constructor for cloning \a p MultPlus(Space& home, MultPlus<VA,VB,VC>& p); /// Post propagator \f$x_0\cdot x_1=x_2\f$ static ExecStatus post(Home home, VA x0, VB x1, VC x2); /// Copy propagator during cloning virtual Actor* copy(Space& home); /// Perform propagation virtual ExecStatus propagate(Space& home, const ModEventDelta& med); };
/** * \brief Bounds consistent multiplication propagator * * Requires \code #include <gecode/float/arithmetic.hh> \endcode * * \ingroup FuncFloatProp */ template<class View> class Mult : public TernaryPropagator<View,PC_FLOAT_BND> { protected: using TernaryPropagator<View,PC_FLOAT_BND>::x0; using TernaryPropagator<View,PC_FLOAT_BND>::x1; using TernaryPropagator<View,PC_FLOAT_BND>::x2;
/// Constructor for cloning \a p Mult(Space& home, Mult<View>& p); public: /// Constructor for posting Mult(Home home, View x0, View x1, View x2); /// Post propagator \f$x_0\cdot x_1=x_2\f$ static ExecStatus post(Home home, View x0, View x1, View x2); /// Copy propagator during cloning virtual Actor* copy(Space& home); /// Perform propagation virtual ExecStatus propagate(Space& home, const ModEventDelta& med); };
/** * \brief %Propagator for bounds division operator * * The types \a A, \a B and \a C give the types of the views. * * Requires \code #include <gecode/float/arithmetic.hh> \endcode * \ingroup FuncFloatProp */ template<class A, class B, class C> class Div : public MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND> { protected: using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x0; using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x1; using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x2; /// Constructor for cloning \a p Div(Space& home, Div& p); /// Constructor for creation Div(Home home, A x0, B x1, C x2); public: /// Create copy during cloning virtual Actor* copy(Space& home); /// Perform propagation virtual ExecStatus propagate(Space& home, const ModEventDelta& med); /// Post propagator for \f$ x_0 / x_1 = x_2\f$ static ExecStatus post(Home home, A x0, B x1, C x2); };
/** * \brief %Propagator for bounds consistent min operator * * The types \a A, \a B and \a C give the types of the views. * * Requires \code #include <gecode/float/arithmetic.hh> \endcode * \ingroup FuncFloatProp */ template<class A, class B, class C> class Min : public MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND> { protected: using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x0; using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x1; using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x2; /// Constructor for cloning \a p Min(Space& home, Min& p); /// Constructor for creation Min(Home home, A x0, B x1, C x2); public: /// Constructor for rewriting \a p during cloning Min(Space& home, Propagator& p, A x0, B x1, C x2); /// Create copy during cloning virtual Actor* copy(Space& home); /// Perform propagation virtual ExecStatus propagate(Space& home, const ModEventDelta& med); /// Post propagator for \f$ min(x_0, x_1) = x_2\f$ static ExecStatus post(Home home, A x0, B x1, C x2); };
/** * \brief %Propagator for bounds consistent max operator * * The types \a A, \a B and \a C give the types of the views. * * Requires \code #include <gecode/float/arithmetic.hh> \endcode * \ingroup FuncFloatProp */ template<class A, class B, class C> class Max : public MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND> { protected: using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x0; using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x1; using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x2; /// Constructor for cloning \a p Max(Space& home, Max& p); /// Constructor for creation Max(Home home, A x0, B x1, C x2); public: /// Constructor for rewriting \a p during cloning Max(Space& home, Propagator& p, A x0, B x1, C x2); /// Create copy during cloning virtual Actor* copy(Space& home); /// Perform propagation virtual ExecStatus propagate(Space& home, const ModEventDelta& med); /// Post propagator for \f$ max(x_0, x_1) = x_2\f$ static ExecStatus post(Home home, A x0, B x1, C x2); };
/** * \brief Bounds consistent n-ary maximum propagator * * Requires \code #include <gecode/float/arithmetic.hh> \endcode * \ingroup FuncFloatProp */ template<class View> class NaryMax : public NaryOnePropagator<View,PC_FLOAT_BND> { protected: using NaryOnePropagator<View,PC_FLOAT_BND>::x; using NaryOnePropagator<View,PC_FLOAT_BND>::y;
/// Constructor for cloning \a p NaryMax(Space& home, NaryMax& p); /// Constructor for posting NaryMax(Home home, ViewArray<View>& x, View y); public: /// Copy propagator during cloning virtual Actor* copy(Space& home); /// Perform propagation virtual ExecStatus propagate(Space& home, const ModEventDelta& med); /// Post propagator \f$ \max x=y\f$ static ExecStatus post(Home home, ViewArray<View>& x, View y); };
}}}
#include <gecode/float/arithmetic/sqr-sqrt.hpp>#include <gecode/float/arithmetic/abs.hpp>#include <gecode/float/arithmetic/pow-nroot.hpp>#include <gecode/float/arithmetic/mult.hpp>#include <gecode/float/arithmetic/div.hpp>#include <gecode/float/arithmetic/min-max.hpp>
#endif
// STATISTICS: float-prop