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

count.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 09:28:48 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $
00013  *     $Revision: 7285 $
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_COUNT_HH__
00041 #define __GECODE_INT_COUNT_HH__
00042 
00043 #include "gecode/int.hh"
00044 
00050 namespace Gecode { namespace Int { namespace Count {
00051 
00057 
00058   template <class VX>
00059   RelTest holds(VX x, VX y);
00061   template <class VX>
00062   RelTest holds(VX x, ConstIntView y);
00064   template <class VX>
00065   bool post_true(Space* home, ViewArray<VX>& x, VX y);
00067   template <class VX>
00068   bool post_true(Space* home, ViewArray<VX>& x, ConstIntView y);
00070   template <class VX>
00071   bool post_false(Space* home, ViewArray<VX>& x, VX y);
00073   template <class VX>
00074   bool post_false(Space* home, ViewArray<VX>& x, ConstIntView y);
00076 
00077 }}}
00078 
00079 #include "gecode/int/count/rel.icc"
00080 
00081 
00082 namespace Gecode { namespace Int { namespace Count {
00083 
00088   template <class VX, class VY>
00089   class BaseInt : public Propagator {
00090   protected:
00092     ViewArray<VX> x;
00094     int n_s;
00096     VY y;
00098     int c;
00100     BaseInt(Space* home, bool share, BaseInt& p);
00102     BaseInt(Space* home, ViewArray<VX>& x, int n_s, VY y, int c);
00104     Reflection::ActorSpec spec(const Space* home, Reflection::VarMap& m,
00105                                 const Support::Symbol& name) const;
00106   public:
00108     virtual PropCost cost(ModEventDelta med) const;
00110     virtual size_t dispose(Space* home);
00111   };
00112 
00122   template <class VX, class VY>
00123   class EqInt : public BaseInt<VX,VY> {
00124   protected:
00125     using BaseInt<VX,VY>::x;
00126     using BaseInt<VX,VY>::n_s;
00127     using BaseInt<VX,VY>::y;
00128     using BaseInt<VX,VY>::c;
00130     EqInt(Space* home, bool share, EqInt& p);
00132     EqInt(Space* home, ViewArray<VX>& x, int n_s, VY y, int c);
00133   public:
00135     virtual Actor* copy(Space* home, bool share);
00137     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00139     static ExecStatus post(Space* home, ViewArray<VX>& x, VY y, int c);
00141     virtual Reflection::ActorSpec spec(const Space* home,
00142                                         Reflection::VarMap& m) const;
00144     static void post(Space* home, Reflection::VarMap& vars,
00145                      const Reflection::ActorSpec& spec);
00147     static Support::Symbol ati(void);
00148   };
00149 
00159   template <class VX, class VY>
00160   class GqInt : public BaseInt<VX,VY> {
00161   protected:
00162     using BaseInt<VX,VY>::x;
00163     using BaseInt<VX,VY>::n_s;
00164     using BaseInt<VX,VY>::y;
00165     using BaseInt<VX,VY>::c;
00167     GqInt(Space* home, bool share, GqInt& p);
00169     GqInt(Space* home, ViewArray<VX>& x, int n_s, VY y, int c);
00170   public:
00172     virtual Actor* copy(Space* home, bool share);
00174     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00176     virtual Reflection::ActorSpec spec(const Space* home,
00177                                         Reflection::VarMap& m) const;
00179     static Support::Symbol ati(void);
00181     static void post(Space* home, Reflection::VarMap& vars,
00182                      const Reflection::ActorSpec& spec);
00184     static ExecStatus post(Space* home, ViewArray<VX>& x, VY y, int c);
00185   };
00186 
00196   template <class VX, class VY>
00197   class LqInt : public BaseInt<VX,VY> {
00198   protected:
00199     using BaseInt<VX,VY>::x;
00200     using BaseInt<VX,VY>::n_s;
00201     using BaseInt<VX,VY>::y;
00202     using BaseInt<VX,VY>::c;
00204     LqInt(Space* home, bool share, LqInt& p);
00206     LqInt(Space* home, ViewArray<VX>& x, int n_s, VY y, int c);
00207   public:
00209     virtual Actor* copy(Space* home, bool share);
00211     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00213     virtual Reflection::ActorSpec spec(const Space* home,
00214                                         Reflection::VarMap& m) const;
00216     static Support::Symbol ati(void);
00218     static void post(Space* home, Reflection::VarMap& vars,
00219                      const Reflection::ActorSpec& spec);
00221     static ExecStatus post(Space* home, ViewArray<VX>& x, VY y, int c);
00222   };
00223 
00233   template<class VX, class VY>
00234   class NqInt : public BinaryPropagator<VX,PC_INT_DOM> {
00235   protected:
00236     using BinaryPropagator<VX,PC_INT_DOM>::x0;
00237     using BinaryPropagator<VX,PC_INT_DOM>::x1;
00239     ViewArray<VX> x;
00241     VY y;
00243     int c;
00245     bool resubscribe(Space* home, VX& z);
00247     NqInt(Space* home,  ViewArray<VX>& x, VY y, int c);
00249     NqInt(Space* home, bool share, NqInt& p);
00250   public:
00252     virtual Actor* copy(Space* home, bool share);
00254     virtual PropCost cost(ModEventDelta med) const;
00256     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00258     virtual Reflection::ActorSpec spec(const Space* home,
00259                                         Reflection::VarMap& m) const;
00261     static Support::Symbol ati(void);
00263     static void post(Space* home, Reflection::VarMap& vars,
00264                      const Reflection::ActorSpec& spec);
00266     static  ExecStatus post(Space* home, ViewArray<VX>& x, VY y, int c);
00268     virtual size_t dispose(Space* home);
00269   };
00270 
00271 }}}
00272 
00273 #include "gecode/int/count/int.icc"
00274 
00275 
00276 namespace Gecode { namespace Int { namespace Count {
00277 
00282   template <class VX, class VY, class VZ, bool shr>
00283   class BaseView : public Propagator {
00284   protected:
00286     ViewArray<VX> x;
00288     VY y;
00290     VZ z;
00292     int   c;
00294     BaseView(Space* home, bool shr, BaseView& p);
00296     BaseView(Space* home, ViewArray<VX>& x, VY y, VZ z, int c);
00298     Reflection::ActorSpec spec(const Space* home, Reflection::VarMap& m,
00299                                 const Support::Symbol& name) const;
00300   public:
00302     virtual size_t dispose(Space* home);
00304     virtual PropCost cost(ModEventDelta med) const;
00305   protected:
00307     void count(Space* home);
00309     int atleast(void) const;
00311     int atmost(void) const;
00313     static bool sharing(const ViewArray<VX>& x, const VY& y, const VZ& z);
00314   };
00315 
00325   template <class VX, class VY, class VZ, bool shr>
00326   class EqView : public BaseView<VX,VY,VZ,shr> {
00327   protected:
00328     using BaseView<VX,VY,VZ,shr>::x;
00329     using BaseView<VX,VY,VZ,shr>::z;
00330     using BaseView<VX,VY,VZ,shr>::c;
00331     using BaseView<VX,VY,VZ,shr>::y;
00332     using BaseView<VX,VY,VZ,shr>::count;
00333     using BaseView<VX,VY,VZ,shr>::atleast;
00334     using BaseView<VX,VY,VZ,shr>::atmost;
00335 
00337     EqView(Space* home, bool shr, EqView& p);
00338   public:
00340     EqView(Space* home, ViewArray<VX>& x, VY y, VZ z, int c);
00342     virtual Actor* copy(Space* home, bool shr);
00344     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00346     virtual Reflection::ActorSpec spec(const Space* home,
00347                                         Reflection::VarMap& m) const;
00349     static Support::Symbol ati(void);
00351     static void post(Space* home, Reflection::VarMap& vars,
00352                      const Reflection::ActorSpec& spec);
00354     static ExecStatus post(Space* home, ViewArray<VX>& x, VY y, VZ z, int c);
00355   };
00356 
00366   template <class VX, class VY, class VZ, bool shr>
00367   class NqView : public BaseView<VX,VY,VZ,shr> {
00368   protected:
00369     using BaseView<VX,VY,VZ,shr>::x;
00370     using BaseView<VX,VY,VZ,shr>::z;
00371     using BaseView<VX,VY,VZ,shr>::c;
00372     using BaseView<VX,VY,VZ,shr>::y;
00373     using BaseView<VX,VY,VZ,shr>::count;
00374     using BaseView<VX,VY,VZ,shr>::atleast;
00375     using BaseView<VX,VY,VZ,shr>::atmost;
00376 
00378     NqView(Space* home, bool shr, NqView& p);
00379   public:
00381     NqView(Space* home, ViewArray<VX>& x, VY y, VZ z, int c);
00383     virtual Actor* copy(Space* home, bool shr);
00385     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00387     virtual Reflection::ActorSpec spec(const Space* home,
00388                                         Reflection::VarMap& m) const;
00390     static void post(Space* home, Reflection::VarMap& vars,
00391                      const Reflection::ActorSpec& spec);
00393     static Support::Symbol ati(void);
00395     static ExecStatus post(Space* home, ViewArray<VX>& x, VY y, VZ z, int c);
00396   };
00397 
00407   template <class VX, class VY, class VZ, bool shr>
00408   class LqView : public BaseView<VX,VY,VZ,shr> {
00409   protected:
00410     using BaseView<VX,VY,VZ,shr>::x;
00411     using BaseView<VX,VY,VZ,shr>::z;
00412     using BaseView<VX,VY,VZ,shr>::c;
00413     using BaseView<VX,VY,VZ,shr>::y;
00414     using BaseView<VX,VY,VZ,shr>::count;
00415     using BaseView<VX,VY,VZ,shr>::atleast;
00416     using BaseView<VX,VY,VZ,shr>::atmost;
00417 
00419     LqView(Space* home, bool shr, LqView& p);
00420   public:
00422     LqView(Space* home, ViewArray<VX>& x, VY y, VZ z, int c);
00424     virtual Actor* copy(Space* home, bool shr);
00426     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00428     virtual Reflection::ActorSpec spec(const Space* home,
00429                                         Reflection::VarMap& m) const;
00431     static void post(Space* home, Reflection::VarMap& vars,
00432                      const Reflection::ActorSpec& spec);
00434     static Support::Symbol ati(void);
00436     static ExecStatus post(Space* home, ViewArray<VX>& x, VY y, VZ z, int c);
00437   };
00438 
00448   template <class VX, class VY, class VZ, bool shr>
00449   class GqView : public BaseView<VX,VY,VZ,shr> {
00450   protected:
00451     using BaseView<VX,VY,VZ,shr>::x;
00452     using BaseView<VX,VY,VZ,shr>::z;
00453     using BaseView<VX,VY,VZ,shr>::c;
00454     using BaseView<VX,VY,VZ,shr>::y;
00455     using BaseView<VX,VY,VZ,shr>::count;
00456     using BaseView<VX,VY,VZ,shr>::atleast;
00457     using BaseView<VX,VY,VZ,shr>::atmost;
00458 
00460     GqView(Space* home, bool shr, GqView& p);
00461   public:
00463     GqView(Space* home, ViewArray<VX>& x, VY y, VZ z, int c);
00465     virtual Actor* copy(Space* home, bool share);
00467     virtual ExecStatus propagate(Space* home, ModEventDelta med);
00469     virtual Reflection::ActorSpec spec(const Space* home,
00470                                         Reflection::VarMap& m) const;
00472     static void post(Space* home, Reflection::VarMap& vars,
00473                      const Reflection::ActorSpec& spec);
00475     static Support::Symbol ati(void);
00477     static ExecStatus post(Space* home, ViewArray<VX>& x, VY y, VZ z, int c);
00478   };
00479 
00480 }}}
00481 
00482 #include "gecode/int/count/view.icc"
00483 
00484 #endif
00485 
00486 // STATISTICS: int-prop
00487