00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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 VY>
00059 bool isintset(VY y);
00061 template<class VY>
00062 bool isval(VY y);
00063
00065 template<class VY>
00066 void subscribe(Space& home, Propagator& p, VY y);
00068 template<class VY>
00069 void cancel(Space& home, Propagator& p, VY y);
00071 template<class VY>
00072 void reschedule(Space& home, Propagator& p, VY y);
00073
00075 template<class VX>
00076 RelTest holds(VX x, VX y);
00078 template<class VX>
00079 RelTest holds(VX x, ConstIntView y);
00081 template<class VX>
00082 RelTest holds(VX x, ZeroIntView y);
00084 template<class VX>
00085 RelTest holds(VX x, const IntSet& y);
00086
00088 template<class VX>
00089 ExecStatus post_true(Home home, ViewArray<VX>& x, VX y);
00091 template<class VX>
00092 ExecStatus post_true(Home home, ViewArray<VX>& x, ConstIntView y);
00094 template<class VX>
00095 ExecStatus post_true(Home home, ViewArray<VX>& x, ZeroIntView y);
00097 template<class VX>
00098 ExecStatus post_true(Home home, ViewArray<VX>& x, const IntSet& y);
00099
00101 template<class VX>
00102 ExecStatus post_false(Home home, ViewArray<VX>& x, VX y);
00104 template<class VX>
00105 ExecStatus post_false(Home home, ViewArray<VX>& x, ConstIntView y);
00107 template<class VX>
00108 ExecStatus post_false(Home home, ViewArray<VX>& x, ZeroIntView y);
00110 template<class VX>
00111 ExecStatus post_false(Home home, ViewArray<VX>& x, const IntSet& y);
00112
00114 template<class VX>
00115 ExecStatus prune(Home home, ViewArray<VX>& x, VX y);
00117 template<class VX>
00118 ExecStatus prune(Home home, ViewArray<VX>& x, ConstIntView y);
00120 template<class VX>
00121 ExecStatus prune(Home home, ViewArray<VX>& x, ZeroIntView y);
00123 template<class VX>
00124 ExecStatus prune(Home home, ViewArray<VX>& x, const IntSet& y);
00126
00127 }}}
00128
00129 #include <gecode/int/count/rel.hpp>
00130
00131
00132 namespace Gecode { namespace Int { namespace Count {
00133
00138 template<class VX, class VY>
00139 class IntBase : public Propagator {
00140 protected:
00142 ViewArray<VX> x;
00144 int n_s;
00146 VY y;
00148 int c;
00150 IntBase(Space& home, bool share, IntBase& p);
00152 IntBase(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
00153 public:
00155 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00157 virtual void reschedule(Space& home);
00159 virtual size_t dispose(Space& home);
00160 };
00161
00172 template<class VX, class VY>
00173 class EqInt : public IntBase<VX,VY> {
00174 protected:
00175 using IntBase<VX,VY>::x;
00176 using IntBase<VX,VY>::n_s;
00177 using IntBase<VX,VY>::y;
00178 using IntBase<VX,VY>::c;
00180 EqInt(Space& home, bool share, EqInt& p);
00182 EqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
00183 public:
00185 virtual Actor* copy(Space& home, bool share);
00187 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00189 static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
00190 };
00191
00202 template<class VX, class VY>
00203 class GqInt : public IntBase<VX,VY> {
00204 protected:
00205 using IntBase<VX,VY>::x;
00206 using IntBase<VX,VY>::n_s;
00207 using IntBase<VX,VY>::y;
00208 using IntBase<VX,VY>::c;
00210 GqInt(Space& home, bool share, GqInt& p);
00212 GqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
00213 public:
00215 virtual Actor* copy(Space& home, bool share);
00217 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00219 static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
00220 };
00221
00232 template<class VX, class VY>
00233 class LqInt : public IntBase<VX,VY> {
00234 protected:
00235 using IntBase<VX,VY>::x;
00236 using IntBase<VX,VY>::n_s;
00237 using IntBase<VX,VY>::y;
00238 using IntBase<VX,VY>::c;
00240 LqInt(Space& home, bool share, LqInt& p);
00242 LqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
00243 public:
00245 virtual Actor* copy(Space& home, bool share);
00247 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00249 static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
00250 };
00251
00252 }}}
00253
00254 #include <gecode/int/count/int-base.hpp>
00255 #include <gecode/int/count/int-eq.hpp>
00256 #include <gecode/int/count/int-gq.hpp>
00257 #include <gecode/int/count/int-lq.hpp>
00258
00259
00260 namespace Gecode { namespace Int { namespace Count {
00261
00266 template<class VX, class VY, class VZ>
00267 class ViewBase : public Propagator {
00268 protected:
00270 ViewArray<VX> x;
00272 VY y;
00274 VZ z;
00276 int c;
00278 ViewBase(Space& home, bool share, ViewBase& p);
00280 ViewBase(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00281 public:
00283 virtual size_t dispose(Space& home);
00285 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00287 virtual void reschedule(Space& home);
00288 protected:
00290 void count(Space& home);
00292 int atleast(void) const;
00294 int atmost(void) const;
00296 static bool sharing(const ViewArray<VX>& x, const VY& y, const VZ& z);
00297 };
00298
00309 template<class VX, class VY, class VZ, bool shr, bool dom>
00310 class EqView : public ViewBase<VX,VY,VZ> {
00311 protected:
00312 using ViewBase<VX,VY,VZ>::x;
00313 using ViewBase<VX,VY,VZ>::z;
00314 using ViewBase<VX,VY,VZ>::c;
00315 using ViewBase<VX,VY,VZ>::y;
00316 using ViewBase<VX,VY,VZ>::count;
00317 using ViewBase<VX,VY,VZ>::atleast;
00318 using ViewBase<VX,VY,VZ>::atmost;
00319 using ViewBase<VX,VY,VZ>::sharing;
00320
00322 EqView(Space& home, bool share, EqView& p);
00323 public:
00325 EqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00327 virtual Actor* copy(Space& home, bool share);
00329 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00331 static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00332 };
00333
00344 template<class VX, class VY, class VZ, bool shr>
00345 class LqView : public ViewBase<VX,VY,VZ> {
00346 protected:
00347 using ViewBase<VX,VY,VZ>::x;
00348 using ViewBase<VX,VY,VZ>::z;
00349 using ViewBase<VX,VY,VZ>::c;
00350 using ViewBase<VX,VY,VZ>::y;
00351 using ViewBase<VX,VY,VZ>::count;
00352 using ViewBase<VX,VY,VZ>::atleast;
00353 using ViewBase<VX,VY,VZ>::atmost;
00354 using ViewBase<VX,VY,VZ>::sharing;
00355
00357 LqView(Space& home, bool share, LqView& p);
00358 public:
00360 LqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00362 virtual Actor* copy(Space& home, bool share);
00364 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00366 static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00367 };
00368
00379 template<class VX, class VY, class VZ, bool shr, bool dom>
00380 class GqView : public ViewBase<VX,VY,VZ> {
00381 protected:
00382 using ViewBase<VX,VY,VZ>::x;
00383 using ViewBase<VX,VY,VZ>::z;
00384 using ViewBase<VX,VY,VZ>::c;
00385 using ViewBase<VX,VY,VZ>::y;
00386 using ViewBase<VX,VY,VZ>::count;
00387 using ViewBase<VX,VY,VZ>::atleast;
00388 using ViewBase<VX,VY,VZ>::atmost;
00389 using ViewBase<VX,VY,VZ>::sharing;
00390
00392 GqView(Space& home, bool share, GqView& p);
00393 public:
00395 GqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00397 virtual Actor* copy(Space& home, bool share);
00399 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00401 static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00402 };
00403
00404 }}}
00405
00406 #include <gecode/int/count/view-base.hpp>
00407 #include <gecode/int/count/view-eq.hpp>
00408 #include <gecode/int/count/view-gq.hpp>
00409 #include <gecode/int/count/view-lq.hpp>
00410
00411 #endif
00412
00413
00414