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 enum ViewTypeDesc {
00059 VTD_CONSTVIEW,
00060 VTD_INTSET,
00061 VTD_VARVIEW
00062 };
00064 template<class VY>
00065 ViewTypeDesc vtd(VY y);
00066
00068 template<class VY>
00069 void subscribe(Space& home, Propagator& p, VY y);
00071 template<class VY>
00072 void cancel(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 size_t dispose(Space& home);
00158 };
00159
00170 template<class VX, class VY>
00171 class EqInt : public IntBase<VX,VY> {
00172 protected:
00173 using IntBase<VX,VY>::x;
00174 using IntBase<VX,VY>::n_s;
00175 using IntBase<VX,VY>::y;
00176 using IntBase<VX,VY>::c;
00178 EqInt(Space& home, bool share, EqInt& p);
00180 EqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
00181 public:
00183 virtual Actor* copy(Space& home, bool share);
00185 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00187 static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
00188 };
00189
00200 template<class VX, class VY>
00201 class GqInt : public IntBase<VX,VY> {
00202 protected:
00203 using IntBase<VX,VY>::x;
00204 using IntBase<VX,VY>::n_s;
00205 using IntBase<VX,VY>::y;
00206 using IntBase<VX,VY>::c;
00208 GqInt(Space& home, bool share, GqInt& p);
00210 GqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
00211 public:
00213 virtual Actor* copy(Space& home, bool share);
00215 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00217 static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
00218 };
00219
00230 template<class VX, class VY>
00231 class LqInt : public IntBase<VX,VY> {
00232 protected:
00233 using IntBase<VX,VY>::x;
00234 using IntBase<VX,VY>::n_s;
00235 using IntBase<VX,VY>::y;
00236 using IntBase<VX,VY>::c;
00238 LqInt(Space& home, bool share, LqInt& p);
00240 LqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
00241 public:
00243 virtual Actor* copy(Space& home, bool share);
00245 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00247 static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
00248 };
00249
00250 }}}
00251
00252 #include <gecode/int/count/int-base.hpp>
00253 #include <gecode/int/count/int-eq.hpp>
00254 #include <gecode/int/count/int-gq.hpp>
00255 #include <gecode/int/count/int-lq.hpp>
00256
00257
00258 namespace Gecode { namespace Int { namespace Count {
00259
00264 template<class VX, class VY, class VZ>
00265 class ViewBase : public Propagator {
00266 protected:
00268 ViewArray<VX> x;
00270 VY y;
00272 VZ z;
00274 int c;
00276 ViewBase(Space& home, bool share, ViewBase& p);
00278 ViewBase(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00279 public:
00281 virtual size_t dispose(Space& home);
00283 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00284 protected:
00286 void count(Space& home);
00288 int atleast(void) const;
00290 int atmost(void) const;
00292 static bool sharing(const ViewArray<VX>& x, const VY& y, const VZ& z);
00293 };
00294
00305 template<class VX, class VY, class VZ, bool shr, bool dom>
00306 class EqView : public ViewBase<VX,VY,VZ> {
00307 protected:
00308 using ViewBase<VX,VY,VZ>::x;
00309 using ViewBase<VX,VY,VZ>::z;
00310 using ViewBase<VX,VY,VZ>::c;
00311 using ViewBase<VX,VY,VZ>::y;
00312 using ViewBase<VX,VY,VZ>::count;
00313 using ViewBase<VX,VY,VZ>::atleast;
00314 using ViewBase<VX,VY,VZ>::atmost;
00315 using ViewBase<VX,VY,VZ>::sharing;
00316
00318 EqView(Space& home, bool share, EqView& p);
00319 public:
00321 EqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00323 virtual Actor* copy(Space& home, bool share);
00325 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00327 static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00328 };
00329
00340 template<class VX, class VY, class VZ, bool shr>
00341 class LqView : public ViewBase<VX,VY,VZ> {
00342 protected:
00343 using ViewBase<VX,VY,VZ>::x;
00344 using ViewBase<VX,VY,VZ>::z;
00345 using ViewBase<VX,VY,VZ>::c;
00346 using ViewBase<VX,VY,VZ>::y;
00347 using ViewBase<VX,VY,VZ>::count;
00348 using ViewBase<VX,VY,VZ>::atleast;
00349 using ViewBase<VX,VY,VZ>::atmost;
00350 using ViewBase<VX,VY,VZ>::sharing;
00351
00353 LqView(Space& home, bool share, LqView& p);
00354 public:
00356 LqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00358 virtual Actor* copy(Space& home, bool share);
00360 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00362 static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00363 };
00364
00375 template<class VX, class VY, class VZ, bool shr, bool dom>
00376 class GqView : public ViewBase<VX,VY,VZ> {
00377 protected:
00378 using ViewBase<VX,VY,VZ>::x;
00379 using ViewBase<VX,VY,VZ>::z;
00380 using ViewBase<VX,VY,VZ>::c;
00381 using ViewBase<VX,VY,VZ>::y;
00382 using ViewBase<VX,VY,VZ>::count;
00383 using ViewBase<VX,VY,VZ>::atleast;
00384 using ViewBase<VX,VY,VZ>::atmost;
00385 using ViewBase<VX,VY,VZ>::sharing;
00386
00388 GqView(Space& home, bool share, GqView& p);
00389 public:
00391 GqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00393 virtual Actor* copy(Space& home, bool share);
00395 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00397 static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
00398 };
00399
00400 }}}
00401
00402 #include <gecode/int/count/view-base.hpp>
00403 #include <gecode/int/count/view-eq.hpp>
00404 #include <gecode/int/count/view-gq.hpp>
00405 #include <gecode/int/count/view-lq.hpp>
00406
00407 #endif
00408
00409
00410