Generated on Wed Nov 5 2014 05:18:17 for Gecode by doxygen 1.7.6.1
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  *
00007  *  Copyright:
00008  *     Christian Schulte, 2002
00009  *     Guido Tack, 2004
00010  *
00011  *  Last modified:
00012  *     $Date: 2013-08-29 16:05:54 +0200 (Thu, 29 Aug 2013) $ by $Author: schulte $
00013  *     $Revision: 13993 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 #ifndef __GECODE_INT_ARITHMETIC_HH__
00041 #define __GECODE_INT_ARITHMETIC_HH__
00042 
00043 #include <gecode/int.hh>
00044 
00045 #include <gecode/int/rel.hh>
00046 #include <gecode/int/linear.hh>
00047 
00053 namespace Gecode { namespace Int { namespace Arithmetic {
00054 
00061   template<class View>
00062   class AbsBnd : public BinaryPropagator<View,PC_INT_BND> {
00063   protected:
00064     using BinaryPropagator<View,PC_INT_BND>::x0;
00065     using BinaryPropagator<View,PC_INT_BND>::x1;
00066 
00068     AbsBnd(Space& home, bool share, AbsBnd& p);
00070     AbsBnd(Home home, View x0, View x1);
00071   public:
00072 
00074     virtual Actor* copy(Space& home, bool share);
00081     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00083     virtual ExecStatus  propagate(Space& home, const ModEventDelta& med);
00085     static  ExecStatus  post(Home home, View x0, View x1);
00086   };
00087 
00094   template<class View>
00095   class AbsDom : public BinaryPropagator<View,PC_INT_DOM> {
00096   protected:
00097     using BinaryPropagator<View,PC_INT_DOM>::x0;
00098     using BinaryPropagator<View,PC_INT_DOM>::x1;
00099 
00101     AbsDom(Space& home, bool share, AbsDom& p);
00103     AbsDom(Home home, View x0, View x1);
00104   public:
00106     virtual Actor* copy(Space& home, bool share);
00114     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00116     virtual ExecStatus  propagate(Space& home, const ModEventDelta& med);
00118     static  ExecStatus  post(Home home, View x0, View x1);
00119   };
00120 
00121 }}}
00122 
00123 #include <gecode/int/arithmetic/abs.hpp>
00124 
00125 namespace Gecode { namespace Int { namespace Arithmetic {
00126 
00133   template<class View>
00134   class MaxBnd : public TernaryPropagator<View,PC_INT_BND> {
00135   protected:
00136     using TernaryPropagator<View,PC_INT_BND>::x0;
00137     using TernaryPropagator<View,PC_INT_BND>::x1;
00138     using TernaryPropagator<View,PC_INT_BND>::x2;
00139 
00141     MaxBnd(Space& home, bool share, MaxBnd& p);
00143     MaxBnd(Home home, View x0, View x1, View x2);
00144   public:
00146     MaxBnd(Space& home, bool share, Propagator& p, View x0, View x1, View x2);
00148     virtual Actor* copy(Space& home, bool share);
00150     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00152     static  ExecStatus post(Home home, View x0, View x1, View x2);
00153   };
00154 
00161   template<class View>
00162   class NaryMaxBnd : public NaryOnePropagator<View,PC_INT_BND> {
00163   protected:
00164     using NaryOnePropagator<View,PC_INT_BND>::x;
00165     using NaryOnePropagator<View,PC_INT_BND>::y;
00166 
00168     NaryMaxBnd(Space& home, bool share, NaryMaxBnd& p);
00170     NaryMaxBnd(Home home, ViewArray<View>& x, View y);
00171   public:
00173     virtual Actor* copy(Space& home, bool share);
00175     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00177     static  ExecStatus post(Home home, ViewArray<View>& x, View y);
00178   };
00179 
00186   template<class View>
00187   class MaxDom : public TernaryPropagator<View,PC_INT_DOM> {
00188   protected:
00189     using TernaryPropagator<View,PC_INT_DOM>::x0;
00190     using TernaryPropagator<View,PC_INT_DOM>::x1;
00191     using TernaryPropagator<View,PC_INT_DOM>::x2;
00192 
00194     MaxDom(Space& home, bool share, MaxDom& p);
00196     MaxDom(Home home, View x0, View x1, View x2);
00197   public:
00199     MaxDom(Space& home, bool share, Propagator& p, View x0, View x1, View x2);
00201     virtual Actor* copy(Space& home, bool share);
00208     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00210     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00212     static  ExecStatus post(Home home, View x0, View x1, View x2);
00213   };
00214 
00221   template<class View>
00222   class NaryMaxDom : public NaryOnePropagator<View,PC_INT_DOM> {
00223   protected:
00224     using NaryOnePropagator<View,PC_INT_DOM>::x;
00225     using NaryOnePropagator<View,PC_INT_DOM>::y;
00226 
00228     NaryMaxDom(Space& home, bool share, NaryMaxDom& p);
00230     NaryMaxDom(Home home, ViewArray<View>& x, View y);
00231   public:
00233     virtual Actor* copy(Space& home, bool share);
00240     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00242     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00244     static  ExecStatus post(Home home, ViewArray<View>& x, View y);
00245   };
00246 
00247 }}}
00248 
00249 #include <gecode/int/arithmetic/max.hpp>
00250 
00251 namespace Gecode { namespace Int { namespace Arithmetic {
00252 
00259   class SqrOps {
00260   public:
00262     bool even(void) const;
00264     int exp(void) const;
00266     void exp(int m);
00268     template<class IntType>
00269     IntType pow(IntType x) const;
00271     int tpow(int x) const;
00273     int fnroot(int x) const;
00275     int cnroot(int x) const;
00276   };
00277 
00284   class PowOps {
00285   protected:
00287     int n;
00289     static bool even(int m);
00291     bool powgr(long long int r, int x) const;
00293     bool powle(long long int r, int x) const;
00294   public:
00296     PowOps(int n);
00298     bool even(void) const;
00300     int exp(void) const;
00302     void exp(int m);
00304     template<class IntType>
00305     IntType pow(IntType x) const;
00307     int tpow(int x) const;
00309     int fnroot(int x) const;
00311     int cnroot(int x) const;
00312   };
00313 
00314 }}}
00315 
00316 #include <gecode/int/arithmetic/pow-ops.hpp>
00317 
00318 namespace Gecode { namespace Int { namespace Arithmetic {
00319 
00325   template<class VA, class VB, class Ops>
00326   class PowPlusBnd : public MixBinaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND> {
00327   protected:
00328     using MixBinaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND>::x0;
00329     using MixBinaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND>::x1;
00331     Ops ops;
00333     PowPlusBnd(Home home, VA x0, VB x1, const Ops& ops);
00335     PowPlusBnd(Space& home, bool share, PowPlusBnd<VA,VB,Ops>& p);
00336   public:
00338     virtual Actor* copy(Space& home, bool share);
00340     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00342     static ExecStatus post(Home home, VA x0, VB x1, Ops ops);
00343   };
00344 
00351   template<class Ops>
00352   class PowBnd : public BinaryPropagator<IntView,PC_INT_BND> {
00353   protected:
00354     using BinaryPropagator<IntView,PC_INT_BND>::x0;
00355     using BinaryPropagator<IntView,PC_INT_BND>::x1;
00357     Ops ops;
00359     PowBnd(Space& home, bool share, PowBnd& p);
00361     PowBnd(Home home, IntView x0, IntView x1, const Ops& ops);
00362   public:
00364     virtual Actor* copy(Space& home, bool share);
00366     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00368     static ExecStatus post(Home home, IntView x0, IntView x1, Ops ops);
00369   };
00370 
00376   template<class VA, class VB, class Ops>
00377   class PowPlusDom : public MixBinaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM> {
00378   protected:
00379     using MixBinaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM>::x0;
00380     using MixBinaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM>::x1;
00382     Ops ops;
00384     PowPlusDom(Home home, VA x0, VB x1, const Ops& ops);
00386     PowPlusDom(Space& home, bool share, PowPlusDom<VA,VB,Ops>& p);
00387   public:
00389     virtual Actor* copy(Space& home, bool share);
00397     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00399     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00401     static ExecStatus post(Home home, VA x0, VB x1, Ops ops);
00402   };
00403 
00410   template<class Ops>
00411   class PowDom : public BinaryPropagator<IntView,PC_INT_DOM> {
00412   protected:
00413     using BinaryPropagator<IntView,PC_INT_DOM>::x0;
00414     using BinaryPropagator<IntView,PC_INT_DOM>::x1;
00416     Ops ops;
00418     PowDom(Space& home, bool share, PowDom<Ops>& p);
00420     PowDom(Home home, IntView x0, IntView x1, const Ops& ops);
00421   public:
00423     virtual Actor* copy(Space& home, bool share);
00425     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00433     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00435     static ExecStatus post(Home home, IntView x0, IntView x1, Ops ops);
00436   };
00437 
00438 }}}
00439 
00440 #include <gecode/int/arithmetic/pow.hpp>
00441 
00442 namespace Gecode { namespace Int { namespace Arithmetic {
00443 
00450   template<class Ops, bool minus>
00451   class NrootPlusBnd : public BinaryPropagator<IntView,PC_INT_BND> {
00452   protected:
00453     using BinaryPropagator<IntView,PC_INT_BND>::x0;
00454     using BinaryPropagator<IntView,PC_INT_BND>::x1;
00456     Ops ops;
00458     NrootPlusBnd(Space& home, bool share, NrootPlusBnd<Ops,minus>& p);
00460     NrootPlusBnd(Home home, IntView x0, IntView x1, const Ops& ops);
00461   public:
00463     virtual Actor* copy(Space& home, bool share);
00465     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00467     static ExecStatus post(Home home, IntView x0, IntView x1, Ops ops);
00468   };
00469 
00476   template<class Ops>
00477   class NrootBnd : public BinaryPropagator<IntView,PC_INT_BND> {
00478   protected:
00479     using BinaryPropagator<IntView,PC_INT_BND>::x0;
00480     using BinaryPropagator<IntView,PC_INT_BND>::x1;
00482     Ops ops;
00484     NrootBnd(Space& home, bool share, NrootBnd<Ops>& p);
00486     NrootBnd(Home home, IntView x0, IntView x1, const Ops& ops);
00487   public:
00489     virtual Actor* copy(Space& home, bool share);
00491     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00493     static ExecStatus post(Home home, IntView x0, IntView x1, Ops ops);
00494   };
00495 
00502   template<class Ops, bool minus>
00503   class NrootPlusDom : public BinaryPropagator<IntView,PC_INT_DOM> {
00504   protected:
00505     using BinaryPropagator<IntView,PC_INT_DOM>::x0;
00506     using BinaryPropagator<IntView,PC_INT_DOM>::x1;
00508     Ops ops;
00510     NrootPlusDom(Space& home, bool share, NrootPlusDom<Ops,minus>& p);
00512     NrootPlusDom(Home home, IntView x0, IntView x1, const Ops& ops);
00513   public:
00515     virtual Actor* copy(Space& home, bool share);
00517     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00525     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00527     static ExecStatus post(Home home, IntView x0, IntView x1, Ops ops);
00528   };
00529 
00536   template<class Ops>
00537   class NrootDom : public BinaryPropagator<IntView,PC_INT_DOM> {
00538   protected:
00539     using BinaryPropagator<IntView,PC_INT_DOM>::x0;
00540     using BinaryPropagator<IntView,PC_INT_DOM>::x1;
00542     Ops ops;
00544     NrootDom(Space& home, bool share, NrootDom<Ops>& p);
00546     NrootDom(Home home, IntView x0, IntView x1, const Ops& ops);
00547   public:
00549     virtual Actor* copy(Space& home, bool share);
00551     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00559     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00561     static ExecStatus post(Home home, IntView x0, IntView x1, Ops ops);
00562   };
00563 
00564 }}}
00565 
00566 #include <gecode/int/arithmetic/nroot.hpp>
00567 
00568 namespace Gecode { namespace Int { namespace Arithmetic {
00569 
00576   template<class View, PropCond pc>
00577   class MultZeroOne : public BinaryPropagator<View,pc> {
00578   protected:
00579     using BinaryPropagator<View,pc>::x0;
00580     using BinaryPropagator<View,pc>::x1;
00581 
00583     MultZeroOne(Space& home, bool share, MultZeroOne<View,pc>& p);
00585     MultZeroOne(Home home, View x0, View x1);
00587     static RelTest equal(View x, int n);
00588   public:
00590     virtual Actor* copy(Space& home, bool share);
00592     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00594     static ExecStatus post(Home home, View x0, View x1);
00595   };
00596 
00597 
00598 
00604   template<class VA, class VB, class VC>
00605   class MultPlusBnd :
00606     public MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND> {
00607   protected:
00608     using MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND>::x0;
00609     using MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND>::x1;
00610     using MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND>::x2;
00611   public:
00613     MultPlusBnd(Home home, VA x0, VB x1, VC x2);
00615     MultPlusBnd(Space& home, bool share, MultPlusBnd<VA,VB,VC>& p);
00617     static ExecStatus post(Home home, VA x0, VB x1, VC x2);
00619     virtual Actor* copy(Space& home, bool share);
00621     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00622   };
00623 
00631   class MultBnd : public TernaryPropagator<IntView,PC_INT_BND> {
00632   protected:
00633     using TernaryPropagator<IntView,PC_INT_BND>::x0;
00634     using TernaryPropagator<IntView,PC_INT_BND>::x1;
00635     using TernaryPropagator<IntView,PC_INT_BND>::x2;
00637     MultBnd(Space& home, bool share, MultBnd& p);
00638   public:
00640     MultBnd(Home home, IntView x0, IntView x1, IntView x2);
00642     GECODE_INT_EXPORT
00643     static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2);
00645     GECODE_INT_EXPORT
00646     virtual Actor* copy(Space& home, bool share);
00648     GECODE_INT_EXPORT 
00649     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00650   };
00651 
00652 
00653 
00659   template<class VA, class VB, class VC>
00660   class MultPlusDom :
00661     public MixTernaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM,VC,PC_INT_DOM> {
00662   protected:
00663     using MixTernaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM,VC,PC_INT_DOM>::x0;
00664     using MixTernaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM,VC,PC_INT_DOM>::x1;
00665     using MixTernaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM,VC,PC_INT_DOM>::x2;
00666   public:
00668     MultPlusDom(Home home, VA x0, VB x1, VC x2);
00670     MultPlusDom(Space& home, bool share, MultPlusDom<VA,VB,VC>& p);
00672     static ExecStatus post(Home home, VA x0, VB x1, VC x2);
00674     virtual Actor* copy(Space& home, bool share);
00681     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00683     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00684   };
00685 
00693   class MultDom : public TernaryPropagator<IntView,PC_INT_DOM> {
00694   protected:
00695     using TernaryPropagator<IntView,PC_INT_DOM>::x0;
00696     using TernaryPropagator<IntView,PC_INT_DOM>::x1;
00697     using TernaryPropagator<IntView,PC_INT_DOM>::x2;
00699     MultDom(Space& home, bool share, MultDom& p);
00700   public:
00702     MultDom(Home home, IntView x0, IntView x1, IntView x2);
00704     GECODE_INT_EXPORT 
00705     static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2);
00707     GECODE_INT_EXPORT 
00708     virtual Actor* copy(Space& home, bool share);
00715     GECODE_INT_EXPORT 
00716     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00718     GECODE_INT_EXPORT 
00719     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00720   };
00721 
00722 }}}
00723 
00724 #include <gecode/int/arithmetic/mult.hpp>
00725 
00726 namespace Gecode { namespace Int { namespace Arithmetic {
00727 
00733   template<class VA, class VB, class VC>
00734   class DivPlusBnd :
00735     public MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND> {
00736   protected:
00737     using MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND>::x0;
00738     using MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND>::x1;
00739     using MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND>::x2;
00740   public:
00742     DivPlusBnd(Home home, VA x0, VB x1, VC x2);
00744     DivPlusBnd(Space& home, bool share, DivPlusBnd<VA,VB,VC>& p);
00746     static ExecStatus post(Home home, VA x0, VB x1, VC x2);
00748     virtual Actor* copy(Space& home, bool share);
00750     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00751   };
00752 
00760   template<class View>
00761   class DivBnd : public TernaryPropagator<View,PC_INT_BND> {
00762   protected:
00763     using TernaryPropagator<View,PC_INT_BND>::x0;
00764     using TernaryPropagator<View,PC_INT_BND>::x1;
00765     using TernaryPropagator<View,PC_INT_BND>::x2;
00766 
00768     DivBnd(Space& home, bool share, DivBnd<View>& p);
00769   public:
00771     DivBnd(Home home, View x0, View x1, View x2);
00773     static  ExecStatus post(Home home, View x0, View x1, View x2);
00775     virtual Actor* copy(Space& home, bool share);
00777     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00778   };
00779 
00790   template<class View>
00791   class DivMod : public TernaryPropagator<View,PC_INT_BND> {
00792   protected:
00793     using TernaryPropagator<View,PC_INT_BND>::x0;
00794     using TernaryPropagator<View,PC_INT_BND>::x1;
00795     using TernaryPropagator<View,PC_INT_BND>::x2;
00796 
00798     DivMod(Space& home, bool share, DivMod<View>& p);
00799   public:
00801     DivMod(Home home, View x0, View x1, View x2);
00803     static  ExecStatus post(Home home, View x0, View x1, View x2);
00805     virtual Actor* copy(Space& home, bool share);
00807     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00808   };
00809 
00810 }}}
00811 
00812 #include <gecode/int/arithmetic/divmod.hpp>
00813 
00814 #endif
00815 
00816 // STATISTICS: int-prop
00817