Generated on Mon Aug 25 11:35:35 2008 for Gecode by doxygen 1.5.6

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: 2008-07-11 10:52:51 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $
00013  *     $Revision: 7352 $
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(Space* home, View x0, View x1);
00071   public:
00072 
00074     virtual Actor* copy(Space* home, bool share);
00081     virtual PropCost cost(ModEventDelta med) const;
00083     virtual ExecStatus  propagate(Space* home, ModEventDelta med);
00085     static  ExecStatus  post(Space* home, View x0, View x1);
00087     static void post(Space* home, Reflection::VarMap& vars,
00088                      const Reflection::ActorSpec& spec);
00090     virtual Reflection::ActorSpec spec(const Space* home,
00091                                         Reflection::VarMap& m) const;
00093     static Support::Symbol ati(void);
00094   };
00095 
00102   template <class View>
00103   class AbsDom : public BinaryPropagator<View,PC_INT_DOM> {
00104   protected:
00105     using BinaryPropagator<View,PC_INT_DOM>::x0;
00106     using BinaryPropagator<View,PC_INT_DOM>::x1;
00107 
00109     AbsDom(Space* home, bool share, AbsDom& p);
00111     AbsDom(Space* home, View x0, View x1);
00112   public:
00114     virtual Actor* copy(Space* home, bool share);
00122     virtual PropCost cost(ModEventDelta med) const;
00124     virtual ExecStatus  propagate(Space* home, ModEventDelta med);
00126     static  ExecStatus  post(Space* home, View x0, View x1);
00128     static void post(Space* home, Reflection::VarMap& vars,
00129                      const Reflection::ActorSpec& spec);
00131     virtual Reflection::ActorSpec spec(const Space* home,
00132                                         Reflection::VarMap& m) const;
00134     static Support::Symbol ati(void);
00135   };
00136 
00137 
00138 
00145   template <class View>
00146   class MaxBnd : public TernaryPropagator<View,PC_INT_BND> {
00147   protected:
00148     using TernaryPropagator<View,PC_INT_BND>::x0;
00149     using TernaryPropagator<View,PC_INT_BND>::x1;
00150     using TernaryPropagator<View,PC_INT_BND>::x2;
00151 
00153     MaxBnd(Space* home, bool share, MaxBnd& p);
00155     MaxBnd(Space* home, View x0, View x1, View x2);
00156   public:
00158     MaxBnd(Space* home, bool share, Propagator& p, View x0, View x1, View x2);
00160     virtual Actor* copy(Space* home, bool share);
00162     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00164     static  ExecStatus post(Space* home, View x0, View x1, View x2);
00166     static void post(Space* home, Reflection::VarMap& vars,
00167                      const Reflection::ActorSpec& spec);
00169     virtual Reflection::ActorSpec spec(const Space* home,
00170                                        Reflection::VarMap& m) const;
00172     static Support::Symbol ati(void);
00173   };
00174 
00181   template <class View>
00182   class NaryMaxBnd : public NaryOnePropagator<View,PC_INT_BND> {
00183   protected:
00184     using NaryOnePropagator<View,PC_INT_BND>::x;
00185     using NaryOnePropagator<View,PC_INT_BND>::y;
00186 
00188     NaryMaxBnd(Space* home, bool share, NaryMaxBnd& p);
00190     NaryMaxBnd(Space* home, ViewArray<View>& x, View y);
00191   public:
00193     virtual Actor* copy(Space* home, bool share);
00195     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00197     static  ExecStatus post(Space* home, ViewArray<View>& x, View y);
00199     static void post(Space* home, Reflection::VarMap& vars,
00200                      const Reflection::ActorSpec& spec);
00202     virtual Reflection::ActorSpec spec(const Space* home,
00203                                        Reflection::VarMap& m) const;
00205     static Support::Symbol ati(void);
00206   };
00207 
00214   template <class View>
00215   class MaxDom : public 
00216   MixTernaryPropagator<View,PC_INT_DOM,View,PC_INT_DOM,View,PC_INT_BND> {
00217   protected:
00218     using MixTernaryPropagator<View,PC_INT_DOM,View,PC_INT_DOM,View,PC_INT_BND>::x0;
00219     using MixTernaryPropagator<View,PC_INT_DOM,View,PC_INT_DOM,View,PC_INT_BND>::x1;
00220     using MixTernaryPropagator<View,PC_INT_DOM,View,PC_INT_DOM,View,PC_INT_BND>::x2;
00221 
00223     MaxDom(Space* home, bool share, MaxDom& p);
00225     MaxDom(Space* home, View x0, View x1, View x2);
00226   public:
00228     MaxDom(Space* home, bool share, Propagator& p, View x0, View x1, View x2);
00230     virtual Actor* copy(Space* home, bool share);
00237     virtual PropCost cost(ModEventDelta med) const;
00239     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00241     static  ExecStatus post(Space* home, View x0, View x1, View x2);
00243     static void post(Space* home, Reflection::VarMap& vars,
00244                      const Reflection::ActorSpec& spec);
00246     virtual Reflection::ActorSpec spec(const Space* home,
00247                                        Reflection::VarMap& m) const;
00249     static Support::Symbol ati(void);
00250   };
00251 
00258   template <class View>
00259   class NaryMaxDom 
00260     : public MixNaryOnePropagator<View,PC_INT_DOM,View,PC_INT_BND> {
00261   protected:
00262     using MixNaryOnePropagator<View,PC_INT_DOM,View,PC_INT_BND>::x;
00263     using MixNaryOnePropagator<View,PC_INT_DOM,View,PC_INT_BND>::y;
00264 
00266     NaryMaxDom(Space* home, bool share, NaryMaxDom& p);
00268     NaryMaxDom(Space* home, ViewArray<View>& x, View y);
00269   public:
00271     virtual Actor* copy(Space* home, bool share);
00278     virtual PropCost cost(ModEventDelta med) const;
00280     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00282     static  ExecStatus post(Space* home, ViewArray<View>& x, View y);
00284     static void post(Space* home, Reflection::VarMap& vars,
00285                      const Reflection::ActorSpec& spec);
00287     virtual Reflection::ActorSpec spec(const Space* home,
00288                                        Reflection::VarMap& m) const;
00290     static Support::Symbol ati(void);
00291   };
00292 
00293 
00294 
00295 
00301   template <class VA, class VB>
00302   class SqrPlusBnd : public MixBinaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND> {
00303   protected:
00304     using MixBinaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND>::x0;
00305     using MixBinaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND>::x1;
00307     SqrPlusBnd(Space* home, VA x0, VB x1);
00309     SqrPlusBnd(Space* home, bool share, SqrPlusBnd<VA,VB>& p);
00310   public:
00312     static ExecStatus post(Space* home, VA x0, VB x1);
00314     static void post(Space* home, Reflection::VarMap& vars,
00315                      const Reflection::ActorSpec& spec);
00317     virtual Actor* copy(Space* home, bool share);
00319     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00321     virtual Reflection::ActorSpec spec(const Space* home,
00322                                        Reflection::VarMap& m) const;
00324     static Support::Symbol ati(void);
00325   };
00326 
00333   template <class View>
00334   class SqrBnd : public BinaryPropagator<View,PC_INT_BND> {
00335   protected:
00336     using BinaryPropagator<View,PC_INT_BND>::x0;
00337     using BinaryPropagator<View,PC_INT_BND>::x1;
00338 
00340     SqrBnd(Space* home, bool share, SqrBnd<View>& p);
00342     SqrBnd(Space* home, View x0, View x1);
00343   public:
00345     virtual Actor* copy(Space* home, bool share);
00347     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00349     static void post(Space* home, Reflection::VarMap& vars,
00350                      const Reflection::ActorSpec& spec);
00352     static ExecStatus post(Space* home, View x0, View x1);
00354     virtual Reflection::ActorSpec spec(const Space* home,
00355                                        Reflection::VarMap& m) const;
00357     static Support::Symbol ati(void);
00358   };
00359 
00360 
00361 
00367   template <class VA, class VB>
00368   class SqrPlusDom : public MixBinaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM> {
00369   protected:
00370     using MixBinaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM>::x0;
00371     using MixBinaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM>::x1;
00373     SqrPlusDom(Space* home, VA x0, VB x1);
00375     SqrPlusDom(Space* home, bool share, SqrPlusDom<VA,VB>& p);
00376   public:
00378     static ExecStatus post(Space* home, VA x0, VB x1);
00380     static void post(Space* home, Reflection::VarMap& vars,
00381                      const Reflection::ActorSpec& spec);
00383     virtual Actor* copy(Space* home, bool share);
00391     virtual PropCost cost(ModEventDelta med) const;
00393     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00395     virtual Reflection::ActorSpec spec(const Space* home,
00396                                        Reflection::VarMap& m) const;
00398     static Support::Symbol ati(void);
00399   };
00400 
00407   template <class View>
00408   class SqrDom : public BinaryPropagator<View,PC_INT_DOM> {
00409   protected:
00410     using BinaryPropagator<View,PC_INT_DOM>::x0;
00411     using BinaryPropagator<View,PC_INT_DOM>::x1;
00412 
00414     SqrDom(Space* home, bool share, SqrDom<View>& p);
00416     SqrDom(Space* home, View x0, View x1);
00417   public:
00419     virtual Actor* copy(Space* home, bool share);
00421     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00429     virtual PropCost cost(ModEventDelta med) const;
00431     static void post(Space* home, Reflection::VarMap& vars,
00432                      const Reflection::ActorSpec& spec);
00434     static ExecStatus post(Space* home, View x0, View x1);
00436     virtual Reflection::ActorSpec spec(const Space* home,
00437                                        Reflection::VarMap& m) const;
00439     static Support::Symbol ati(void);
00440   };
00441 
00442 
00443 
00450   template <class View>
00451   class SqrtBnd : public BinaryPropagator<View,PC_INT_BND> {
00452   protected:
00453     using BinaryPropagator<View,PC_INT_BND>::x0;
00454     using BinaryPropagator<View,PC_INT_BND>::x1;
00455 
00457     SqrtBnd(Space* home, bool share, SqrtBnd<View>& p);
00459     SqrtBnd(Space* home, View x0, View x1);
00460   public:
00462     virtual Actor* copy(Space* home, bool share);
00464     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00466     static void post(Space* home, Reflection::VarMap& vars,
00467                      const Reflection::ActorSpec& spec);
00469     static ExecStatus post(Space* home, View x0, View x1);
00471     virtual Reflection::ActorSpec spec(const Space* home,
00472                                        Reflection::VarMap& m) const;
00474     static Support::Symbol ati(void);
00475   };
00476 
00483   template <class View>
00484   class SqrtDom : public BinaryPropagator<View,PC_INT_DOM> {
00485   protected:
00486     using BinaryPropagator<View,PC_INT_DOM>::x0;
00487     using BinaryPropagator<View,PC_INT_DOM>::x1;
00488 
00490     SqrtDom(Space* home, bool share, SqrtDom<View>& p);
00492     SqrtDom(Space* home, View x0, View x1);
00493   public:
00495     virtual Actor* copy(Space* home, bool share);
00497     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00505     virtual PropCost cost(ModEventDelta med) const;
00507     static void post(Space* home, Reflection::VarMap& vars,
00508                      const Reflection::ActorSpec& spec);
00510     static ExecStatus post(Space* home, View x0, View x1);
00512     virtual Reflection::ActorSpec spec(const Space* home,
00513                                        Reflection::VarMap& m) const;
00515     static Support::Symbol ati(void);
00516   };
00517 
00518 
00519 
00526   template <class View, PropCond pc>
00527   class MultZeroOne : public BinaryPropagator<View,pc> {
00528   protected:
00529     using BinaryPropagator<View,pc>::x0;
00530     using BinaryPropagator<View,pc>::x1;
00531 
00533     MultZeroOne(Space* home, bool share, MultZeroOne<View,pc>& p);
00535     MultZeroOne(Space* home, View x0, View x1);
00537     static RelTest equal(View x, int n);
00538   public:
00540     virtual Actor* copy(Space* home, bool share);
00542     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00544     static void post(Space* home, Reflection::VarMap& vars,
00545                      const Reflection::ActorSpec& spec);
00547     static ExecStatus post(Space* home, View x0, View x1);
00549     virtual Reflection::ActorSpec spec(const Space* home,
00550                                        Reflection::VarMap& m) const;
00552     static Support::Symbol ati(void);
00553   };
00554 
00555 
00556 
00562   template <class Val, class VA, class VB, class VC>
00563   class MultPlusBnd : 
00564     public MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND> {
00565   protected:
00566     using MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND>::x0;
00567     using MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND>::x1;
00568     using MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND>::x2;
00569   public:
00571     MultPlusBnd(Space* home, VA x0, VB x1, VC x2);
00573     MultPlusBnd(Space* home, bool share, MultPlusBnd<Val,VA,VB,VC>& p);
00575     static ExecStatus post(Space* home, VA x0, VB x1, VC x2);
00577     static void post(Space* home, Reflection::VarMap& vars,
00578                      const Reflection::ActorSpec& spec);
00580     virtual Actor* copy(Space* home, bool share);
00582     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00584     virtual Reflection::ActorSpec spec(const Space* home,
00585                                        Reflection::VarMap& m) const;
00587     static Support::Symbol ati(void);
00588   };
00589 
00597   template <class View>
00598   class MultBnd : public TernaryPropagator<View,PC_INT_BND> {
00599   protected:
00600     using TernaryPropagator<View,PC_INT_BND>::x0;
00601     using TernaryPropagator<View,PC_INT_BND>::x1;
00602     using TernaryPropagator<View,PC_INT_BND>::x2;
00603 
00605     MultBnd(Space* home, bool share, MultBnd<View>& p);
00606   public:
00608     MultBnd(Space* home, View x0, View x1, View x2);
00610     static  ExecStatus post(Space* home, View x0, View x1, View x2);
00612     static void post(Space* home, Reflection::VarMap& vars,
00613                      const Reflection::ActorSpec& spec);
00615     virtual Actor* copy(Space* home, bool share);
00617     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00619     virtual Reflection::ActorSpec spec(const Space* home,
00620                                         Reflection::VarMap& m) const;
00622     static Support::Symbol ati(void);
00623   };
00624 
00625 
00626 
00632   template <class Val, class VA, class VB, class VC>
00633   class MultPlusDom : 
00634     public MixTernaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM,VC,PC_INT_DOM> {
00635   protected:
00636     using MixTernaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM,VC,PC_INT_DOM>::x0;
00637     using MixTernaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM,VC,PC_INT_DOM>::x1;
00638     using MixTernaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM,VC,PC_INT_DOM>::x2;
00639   public:
00641     MultPlusDom(Space* home, VA x0, VB x1, VC x2);
00643     MultPlusDom(Space* home, bool share, MultPlusDom<Val,VA,VB,VC>& p);
00645     static ExecStatus post(Space* home, VA x0, VB x1, VC x2);
00647     static void post(Space* home, Reflection::VarMap& vars,
00648                      const Reflection::ActorSpec& spec);
00650     virtual Actor* copy(Space* home, bool share);
00657     virtual PropCost cost(ModEventDelta med) const;
00659     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00661     virtual Reflection::ActorSpec spec(const Space* home,
00662                                        Reflection::VarMap& m) const;
00664     static Support::Symbol ati(void);
00665   };
00666 
00674   template <class View>
00675   class MultDom : public TernaryPropagator<View,PC_INT_DOM> {
00676   protected:
00677     using TernaryPropagator<View,PC_INT_DOM>::x0;
00678     using TernaryPropagator<View,PC_INT_DOM>::x1;
00679     using TernaryPropagator<View,PC_INT_DOM>::x2;
00680 
00682     MultDom(Space* home, bool share, MultDom<View>& p);
00683   public:
00685     MultDom(Space* home, View x0, View x1, View x2);
00687     static  ExecStatus post(Space* home, View x0, View x1, View x2);
00689     static void post(Space* home, Reflection::VarMap& vars,
00690                      const Reflection::ActorSpec& spec);
00692     virtual Actor* copy(Space* home, bool share);
00699     virtual PropCost cost(ModEventDelta med) const;
00701     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00703     virtual Reflection::ActorSpec spec(const Space* home,
00704                                         Reflection::VarMap& m) const;
00706     static Support::Symbol ati(void);
00707   };
00708 
00714   template <class Val, class VA, class VB, class VC, bool towardsMinInf=true>
00715   class DivPlusBnd : 
00716     public MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND> {
00717   protected:
00718     using MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND>::x0;
00719     using MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND>::x1;
00720     using MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND>::x2;
00721   public:
00723     DivPlusBnd(Space* home, VA x0, VB x1, VC x2);
00725     DivPlusBnd(Space* home, bool share,
00726                DivPlusBnd<Val,VA,VB,VC,towardsMinInf>& p);
00728     static ExecStatus post(Space* home, VA x0, VB x1, VC x2);
00730     static void post(Space* home, Reflection::VarMap& vars,
00731                      const Reflection::ActorSpec& spec);
00733     virtual Actor* copy(Space* home, bool share);
00735     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00737     virtual Reflection::ActorSpec spec(const Space* home,
00738                                        Reflection::VarMap& m) const;
00740     static Support::Symbol ati(void);
00741   };
00742 
00750   template <class View>
00751   class DivBnd : public TernaryPropagator<View,PC_INT_BND> {
00752   protected:
00753     using TernaryPropagator<View,PC_INT_BND>::x0;
00754     using TernaryPropagator<View,PC_INT_BND>::x1;
00755     using TernaryPropagator<View,PC_INT_BND>::x2;
00756 
00758     DivBnd(Space* home, bool share, DivBnd<View>& p);
00759   public:
00761     DivBnd(Space* home, View x0, View x1, View x2);
00763     static  ExecStatus post(Space* home, View x0, View x1, View x2);
00765     static void post(Space* home, Reflection::VarMap& vars,
00766                      const Reflection::ActorSpec& spec);
00768     virtual Actor* copy(Space* home, bool share);
00770     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00772     virtual Reflection::ActorSpec spec(const Space* home,
00773                                         Reflection::VarMap& m) const;
00775     static Support::Symbol ati(void);
00776   };
00777   
00788   template <class View>
00789   class DivMod : public BinaryPropagator<View,PC_INT_BND> {
00790   protected:
00791     using BinaryPropagator<View,PC_INT_BND>::x0;
00792     using BinaryPropagator<View,PC_INT_BND>::x1;
00793     
00795     DivMod(Space* home, bool share, DivMod<View>& p);
00796   public:
00798     DivMod(Space* home, View x0, View x1);
00800     static  ExecStatus post(Space* home, View x0, View x1);
00802     static void post(Space* home, Reflection::VarMap& vars,
00803                      const Reflection::ActorSpec& spec);
00805     virtual Actor* copy(Space* home, bool share);
00807     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00809     virtual Reflection::ActorSpec spec(const Space* home,
00810                                        Reflection::VarMap& m) const;
00812     static Support::Symbol ati(void);
00813   };
00814 
00815 }}}
00816 
00817 #include "gecode/int/arithmetic/abs.icc"
00818 #include "gecode/int/arithmetic/max.icc"
00819 #include "gecode/int/arithmetic/sqr.icc"
00820 #include "gecode/int/arithmetic/sqrt.icc"
00821 #include "gecode/int/arithmetic/mult.icc"
00822 #include "gecode/int/arithmetic/divmod.icc"
00823 
00824 #endif
00825 
00826 // STATISTICS: int-prop
00827