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 #include <gecode/int/rel.hh>
00039
00040 namespace Gecode { namespace Int { namespace Count {
00041
00042
00043
00044
00045
00046
00047 template<class VY>
00048 forceinline bool
00049 isintset(VY y) {
00050 (void) y;
00051 return false;
00052 }
00053 template<>
00054 forceinline bool
00055 isintset(IntSet y) {
00056 (void) y;
00057 return true;
00058 }
00059
00060
00061 template<class VY>
00062 forceinline bool
00063 isval(VY y) {
00064 return y.assigned();
00065 }
00066 template<>
00067 forceinline bool
00068 isval(IntSet y) {
00069 (void) y;
00070 return true;
00071 }
00072
00073
00074 forceinline void
00075 subscribe(Space& home, Propagator& p, IntSet& y) {
00076 (void) home; (void) p; (void) y;
00077 }
00078 template<class VY>
00079 forceinline void
00080 subscribe(Space& home, Propagator& p, VY y) {
00081 y.subscribe(home, p, PC_INT_DOM);
00082 }
00083
00084 forceinline void
00085 cancel(Space& home, Propagator& p, IntSet& y) {
00086 (void) home; (void) p;
00087 y.~IntSet();
00088 }
00089 template<class VY>
00090 forceinline void
00091 cancel(Space& home, Propagator& p, VY y) {
00092 y.cancel(home, p, PC_INT_DOM);
00093 }
00094
00095 forceinline void
00096 reschedule(Space& home, Propagator& p, IntSet& y) {
00097 (void) home; (void) p; (void) y;
00098 }
00099 template<class VY>
00100 forceinline void
00101 reschedule(Space& home, Propagator& p, VY y) {
00102 (void) y;
00103 y.schedule(home, p, PC_INT_DOM);
00104 }
00105
00106 template<class VX>
00107 forceinline RelTest
00108 holds(VX x, ConstIntView y) {
00109 return rtest_eq_dom(x,y.val());
00110 }
00111 template<class VX>
00112 forceinline RelTest
00113 holds(VX x, ZeroIntView) {
00114 return rtest_eq_dom(x,0);
00115 }
00116 template<class VX>
00117 forceinline RelTest
00118 holds(VX x, const IntSet& y) {
00119 if ((x.max() < y.min()) || (y.max() < x.min()))
00120 return RT_FALSE;
00121 ViewRanges<VX> rx(x);
00122 IntSetRanges ry(y);
00123 switch (Iter::Ranges::compare(rx,ry)) {
00124 case Iter::Ranges::CS_SUBSET:
00125 return RT_TRUE;
00126 case Iter::Ranges::CS_DISJOINT:
00127 return RT_FALSE;
00128 case Iter::Ranges::CS_NONE:
00129 return RT_MAYBE;
00130 default:
00131 GECODE_NEVER;
00132 }
00133 GECODE_NEVER;
00134 return RT_MAYBE;
00135 }
00136 template<class VX>
00137 forceinline RelTest
00138 holds(VX x, VX y) {
00139 return rtest_eq_dom(x,y);
00140 }
00141
00142 template<class VX>
00143 forceinline ExecStatus
00144 post_true(Home home, VX x, ConstIntView y) {
00145 GECODE_ME_CHECK(x.eq(home,y.val()));
00146 return ES_OK;
00147 }
00148 template<class VX>
00149 forceinline ExecStatus
00150 post_true(Home home, VX x, ZeroIntView) {
00151 GECODE_ME_CHECK(x.eq(home,0));
00152 return ES_OK;
00153 }
00154 template<class VX>
00155 forceinline ExecStatus
00156 post_true(Home home, VX x, const IntSet& y) {
00157 IntSetRanges ry(y);
00158 GECODE_ME_CHECK(x.inter_r(home,ry,false));
00159 return ES_OK;
00160 }
00161 template<class VX>
00162 forceinline ExecStatus
00163 post_true(Home home, ViewArray<VX>& x, ConstIntView y) {
00164 for (int i = x.size(); i--; )
00165 GECODE_ME_CHECK(x[i].eq(home,y.val()));
00166 return ES_OK;
00167 }
00168 template<class VX>
00169 forceinline ExecStatus
00170 post_true(Home home, ViewArray<VX>& x, ZeroIntView) {
00171 for (int i = x.size(); i--; )
00172 GECODE_ME_CHECK(x[i].eq(home,0));
00173 return ES_OK;
00174 }
00175 template<class VX>
00176 forceinline ExecStatus
00177 post_true(Home home, ViewArray<VX>& x, const IntSet& y) {
00178 for (int i = x.size(); i--; ) {
00179 IntSetRanges ry(y);
00180 GECODE_ME_CHECK(x[i].inter_r(home,ry,false));
00181 }
00182 return ES_OK;
00183 }
00184
00185 template<class VX>
00186 forceinline ExecStatus
00187 post_false(Home home, VX x, ConstIntView y) {
00188 GECODE_ME_CHECK(x.nq(home,y.val()));
00189 return ES_OK;
00190 }
00191 template<class VX>
00192 forceinline ExecStatus
00193 post_false(Home home, VX x, ZeroIntView) {
00194 GECODE_ME_CHECK(x.nq(home,0));
00195 return ES_OK;
00196 }
00197 template<class VX>
00198 forceinline ExecStatus
00199 post_false(Home home, VX x, const IntSet& y) {
00200 IntSetRanges ry(y);
00201 GECODE_ME_CHECK(x.minus_r(home,ry,false));
00202 return ES_OK;
00203 }
00204 template<class VX>
00205 forceinline ExecStatus
00206 post_false(Home home, ViewArray<VX>& x, ConstIntView y) {
00207 for (int i = x.size(); i--; )
00208 GECODE_ME_CHECK(x[i].nq(home,y.val()));
00209 return ES_OK;
00210 }
00211 template<class VX>
00212 forceinline ExecStatus
00213 post_false(Home home, ViewArray<VX>& x, ZeroIntView) {
00214 for (int i = x.size(); i--; )
00215 GECODE_ME_CHECK(x[i].nq(home,0));
00216 return ES_OK;
00217 }
00218 template<class VX>
00219 forceinline ExecStatus
00220 post_false(Home home, ViewArray<VX>& x, const IntSet& y) {
00221 for (int i = x.size(); i--; ) {
00222 IntSetRanges ry(y);
00223 GECODE_ME_CHECK(x[i].minus_r(home,ry,false));
00224 }
00225 return ES_OK;
00226 }
00227
00228 template<class VX>
00229 forceinline ExecStatus
00230 post_true(Home home, ViewArray<VX>& x, VX y) {
00231 ViewArray<VX> z(home,x.size()+1);
00232 z[x.size()] = y;
00233 for (int i = x.size(); i--; )
00234 z[i] = x[i];
00235 return Rel::NaryEqDom<VX>::post(home,z);
00236 }
00237 template<class VX>
00238 forceinline ExecStatus
00239 post_true(Home home, VX x, VX y) {
00240 return Rel::EqDom<VX,VX>::post(home,x,y);
00241 }
00242 template<class VX>
00243 forceinline ExecStatus
00244 post_false(Home home, ViewArray<VX>& x, VX y) {
00245 for (int i = x.size(); i--; )
00246 GECODE_ES_CHECK((Rel::Nq<VX,VX>::post(home,x[i],y)));
00247 return ES_OK;
00248 }
00249 template<class VX>
00250 forceinline ExecStatus
00251 post_false(Home home, VX x, VX y) {
00252 return Rel::Nq<VX,VX>::post(home,x,y);
00253 }
00254
00255 template<class VX>
00256 forceinline ExecStatus
00257 prune(Space& home, ViewArray<VX>& x, ConstIntView) {
00258 (void) home;
00259 (void) x;
00260 return ES_OK;
00261 }
00262 template<class VX>
00263 forceinline ExecStatus
00264 prune(Space& home, ViewArray<VX>& x, ZeroIntView) {
00265 (void) home;
00266 (void) x;
00267 return ES_OK;
00268 }
00269 template<class VX>
00270 forceinline ExecStatus
00271 prune(Space& home, ViewArray<VX>& x, const IntSet& y) {
00272 (void) home;
00273 (void) x;
00274 (void) y;
00275 return ES_OK;
00276 }
00277 template<class VX>
00278 forceinline ExecStatus
00279 prune(Space& home, ViewArray<VX>& x, VX y) {
00280 if (x.size() == 0)
00281 return ES_OK;
00282 Region r(home);
00283 ViewRanges<VX>* rx = r.alloc<ViewRanges<VX> >(x.size());
00284 for (int i=x.size(); i--; )
00285 rx[i] = ViewRanges<VX>(x[i]);
00286 Iter::Ranges::NaryUnion u(r, rx, x.size());
00287 GECODE_ME_CHECK(y.inter_r(home, u, false));
00288 return ES_OK;
00289 }
00290
00291 }}}
00292
00293