Generated on Fri Oct 19 11:25:02 2018 for Gecode by doxygen 1.6.3

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  *  This file is part of Gecode, the generic constraint
00012  *  development environment:
00013  *     http://www.gecode.org
00014  *
00015  *  Permission is hereby granted, free of charge, to any person obtaining
00016  *  a copy of this software and associated documentation files (the
00017  *  "Software"), to deal in the Software without restriction, including
00018  *  without limitation the rights to use, copy, modify, merge, publish,
00019  *  distribute, sublicense, and/or sell copies of the Software, and to
00020  *  permit persons to whom the Software is furnished to do so, subject to
00021  *  the following conditions:
00022  *
00023  *  The above copyright notice and this permission notice shall be
00024  *  included in all copies or substantial portions of the Software.
00025  *
00026  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00030  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00031  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00032  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00033  *
00034  */
00035 
00036 #ifndef __GECODE_INT_COUNT_HH__
00037 #define __GECODE_INT_COUNT_HH__
00038 
00039 #include <gecode/int.hh>
00040 
00046 namespace Gecode { namespace Int { namespace Count {
00047 
00053 
00054   template<class VY>
00055   bool isintset(VY y);
00057   template<class VY>
00058   bool isval(VY y);
00059 
00061   template<class VY>
00062   void subscribe(Space& home, Propagator& p, VY y);
00064   template<class VY>
00065   void cancel(Space& home, Propagator& p, VY y);
00067   template<class VY>
00068   void reschedule(Space& home, Propagator& p, VY y);
00070   template<class VY>
00071   void update(VY& y, Space& home, bool shared, VY py);
00072 
00074   template<class VX>
00075   RelTest holds(VX x, VX y);
00077   template<class VX>
00078   RelTest holds(VX x, ConstIntView y);
00080   template<class VX>
00081   RelTest holds(VX x, ZeroIntView y);
00083   template<class VX>
00084   RelTest holds(VX x, const IntSet& y);
00085 
00087   template<class VX>
00088   ExecStatus post_true(Home home, ViewArray<VX>& x, VX y);
00090   template<class VX>
00091   ExecStatus post_true(Home home, ViewArray<VX>& x, ConstIntView y);
00093   template<class VX>
00094   ExecStatus post_true(Home home, ViewArray<VX>& x, ZeroIntView y);
00096   template<class VX>
00097   ExecStatus post_true(Home home, ViewArray<VX>& x, const IntSet& y);
00098 
00100   template<class VX>
00101   ExecStatus post_false(Home home, ViewArray<VX>& x, VX y);
00103   template<class VX>
00104   ExecStatus post_false(Home home, ViewArray<VX>& x, ConstIntView y);
00106   template<class VX>
00107   ExecStatus post_false(Home home, ViewArray<VX>& x, ZeroIntView y);
00109   template<class VX>
00110   ExecStatus post_false(Home home, ViewArray<VX>& x, const IntSet& y);
00111 
00113   template<class VX>
00114   ExecStatus prune(Home home, ViewArray<VX>& x, VX y);
00116   template<class VX>
00117   ExecStatus prune(Home home, ViewArray<VX>& x, ConstIntView y);
00119   template<class VX>
00120   ExecStatus prune(Home home, ViewArray<VX>& x, ZeroIntView y);
00122   template<class VX>
00123   ExecStatus prune(Home home, ViewArray<VX>& x, const IntSet& y);
00125 
00126 }}}
00127 
00128 #include <gecode/int/count/rel.hpp>
00129 
00130 
00131 namespace Gecode { namespace Int { namespace Count {
00132 
00137   template<class VX, class VY>
00138   class IntBase : public Propagator {
00139   protected:
00141     ViewArray<VX> x;
00143     int n_s;
00145     VY y;
00147     int c;
00149     IntBase(Space& home, IntBase& p);
00151     IntBase(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
00152   public:
00154     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00156     virtual void reschedule(Space& home);
00158     virtual size_t dispose(Space& home);
00159   };
00160 
00171   template<class VX, class VY>
00172   class EqInt : public IntBase<VX,VY> {
00173   protected:
00174     using IntBase<VX,VY>::x;
00175     using IntBase<VX,VY>::n_s;
00176     using IntBase<VX,VY>::y;
00177     using IntBase<VX,VY>::c;
00179     EqInt(Space& home, EqInt& p);
00181     EqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
00182   public:
00184     virtual Actor* copy(Space& home);
00186     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00188     static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
00189   };
00190 
00201   template<class VX, class VY>
00202   class GqInt : public IntBase<VX,VY> {
00203   protected:
00204     using IntBase<VX,VY>::x;
00205     using IntBase<VX,VY>::n_s;
00206     using IntBase<VX,VY>::y;
00207     using IntBase<VX,VY>::c;
00209     GqInt(Space& home, GqInt& p);
00211     GqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
00212   public:
00214     virtual Actor* copy(Space& home);
00216     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00218     static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
00219   };
00220 
00231   template<class VX, class VY>
00232   class LqInt : public IntBase<VX,VY> {
00233   protected:
00234     using IntBase<VX,VY>::x;
00235     using IntBase<VX,VY>::n_s;
00236     using IntBase<VX,VY>::y;
00237     using IntBase<VX,VY>::c;
00239     LqInt(Space& home, LqInt& p);
00241     LqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
00242   public:
00244     virtual Actor* copy(Space& home);
00246     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00248     static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
00249   };
00250 
00251 }}}
00252 
00253 #include <gecode/int/count/int-base.hpp>
00254 #include <gecode/int/count/int-eq.hpp>
00255 #include <gecode/int/count/int-gq.hpp>
00256 #include <gecode/int/count/int-lq.hpp>
00257 
00258 
00259 namespace Gecode { namespace Int { namespace Count {
00260 
00265   template<class VX, class VY, class VZ>
00266   class ViewBase : public Propagator {
00267   protected:
00269     ViewArray<VX> x;
00271     VY y;
00273     VZ z;
00275     int   c;
00277     ViewBase(Space& home, ViewBase& p);
00279     ViewBase(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00280   public:
00282     virtual size_t dispose(Space& home);
00284     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00286     virtual void reschedule(Space& home);
00287   protected:
00289     void count(Space& home);
00291     int atleast(void) const;
00293     int atmost(void) const;
00295     static bool sharing(const ViewArray<VX>& x, const VY& y, const VZ& z);
00296   };
00297 
00308   template<class VX, class VY, class VZ, bool shr, bool dom>
00309   class EqView : public ViewBase<VX,VY,VZ> {
00310   protected:
00311     using ViewBase<VX,VY,VZ>::x;
00312     using ViewBase<VX,VY,VZ>::z;
00313     using ViewBase<VX,VY,VZ>::c;
00314     using ViewBase<VX,VY,VZ>::y;
00315     using ViewBase<VX,VY,VZ>::count;
00316     using ViewBase<VX,VY,VZ>::atleast;
00317     using ViewBase<VX,VY,VZ>::atmost;
00318     using ViewBase<VX,VY,VZ>::sharing;
00319 
00321     EqView(Space& home, EqView& p);
00322   public:
00324     EqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00326     virtual Actor* copy(Space& home);
00328     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00330     static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00331   };
00332 
00343   template<class VX, class VY, class VZ, bool shr>
00344   class LqView : public ViewBase<VX,VY,VZ> {
00345   protected:
00346     using ViewBase<VX,VY,VZ>::x;
00347     using ViewBase<VX,VY,VZ>::z;
00348     using ViewBase<VX,VY,VZ>::c;
00349     using ViewBase<VX,VY,VZ>::y;
00350     using ViewBase<VX,VY,VZ>::count;
00351     using ViewBase<VX,VY,VZ>::atleast;
00352     using ViewBase<VX,VY,VZ>::atmost;
00353     using ViewBase<VX,VY,VZ>::sharing;
00354 
00356     LqView(Space& home, LqView& p);
00357   public:
00359     LqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00361     virtual Actor* copy(Space& home);
00363     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00365     static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00366   };
00367 
00378   template<class VX, class VY, class VZ, bool shr, bool dom>
00379   class GqView : public ViewBase<VX,VY,VZ> {
00380   protected:
00381     using ViewBase<VX,VY,VZ>::x;
00382     using ViewBase<VX,VY,VZ>::z;
00383     using ViewBase<VX,VY,VZ>::c;
00384     using ViewBase<VX,VY,VZ>::y;
00385     using ViewBase<VX,VY,VZ>::count;
00386     using ViewBase<VX,VY,VZ>::atleast;
00387     using ViewBase<VX,VY,VZ>::atmost;
00388     using ViewBase<VX,VY,VZ>::sharing;
00389 
00391     GqView(Space& home, GqView& p);
00392   public:
00394     GqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00396     virtual Actor* copy(Space& home);
00398     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00400     static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00401   };
00402 
00403 }}}
00404 
00405 #include <gecode/int/count/view-base.hpp>
00406 #include <gecode/int/count/view-eq.hpp>
00407 #include <gecode/int/count/view-gq.hpp>
00408 #include <gecode/int/count/view-lq.hpp>
00409 
00410 #endif
00411 
00412 // STATISTICS: int-prop
00413