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