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 namespace Gecode { namespace Int { namespace Count {
00035
00036 template<class VX, class VY, class VZ, bool shr, bool dom>
00037 forceinline
00038 EqView<VX,VY,VZ,shr,dom>::EqView(Home home,
00039 ViewArray<VX>& x, VY y, VZ z, int c)
00040 : ViewBase<VX,VY,VZ>(home,x,y,z,c) {}
00041
00042 template<class VX, class VY, class VZ, bool shr, bool dom>
00043 ExecStatus
00044 EqView<VX,VY,VZ,shr,dom>::post(Home home,
00045 ViewArray<VX>& x, VY y, VZ z, int c) {
00046 GECODE_ME_CHECK(z.gq(home,-c));
00047 GECODE_ME_CHECK(z.lq(home,x.size()-c));
00048 if (isval(y) && z.assigned())
00049 return EqInt<VX,VY>::post(home,x,y,z.val()+c);
00050 if (sharing(x,y,z))
00051 (void) new (home) EqView<VX,VY,VZ,true,dom>(home,x,y,z,c);
00052 else
00053 (void) new (home) EqView<VX,VY,VZ,false,dom>(home,x,y,z,c);
00054 return ES_OK;
00055 }
00056
00057 template<class VX, class VY, class VZ, bool shr, bool dom>
00058 forceinline
00059 EqView<VX,VY,VZ,shr,dom>::EqView(Space& home, EqView<VX,VY,VZ,shr,dom>& p)
00060 : ViewBase<VX,VY,VZ>(home,p) {}
00061
00062 template<class VX, class VY, class VZ, bool shr, bool dom>
00063 Actor*
00064 EqView<VX,VY,VZ,shr,dom>::copy(Space& home) {
00065 return new (home) EqView<VX,VY,VZ,shr,dom>(home,*this);
00066 }
00067
00068 template<class VX, class VY, class VZ, bool shr, bool dom>
00069 ExecStatus
00070 EqView<VX,VY,VZ,shr,dom>::propagate(Space& home, const ModEventDelta&) {
00071 count(home);
00072
00073 GECODE_ME_CHECK(z.gq(home,atleast()));
00074 GECODE_ME_CHECK(z.lq(home,atmost()));
00075
00076 if (z.assigned()) {
00077 if (z.val() == atleast()) {
00078 GECODE_ES_CHECK(post_false(home,x,y));
00079 return home.ES_SUBSUMED(*this);
00080 }
00081 if (z.val() == atmost()) {
00082 GECODE_ES_CHECK(post_true(home,x,y));
00083 return home.ES_SUBSUMED(*this);
00084 }
00085 if (!dom || isval(y)) {
00086 VY yc(y);
00087 GECODE_REWRITE(*this,(EqInt<VX,VY>
00088 ::post(home(*this),x,yc,z.val()+c)));
00089 }
00090 }
00091
00092
00093 if (dom && !isval(y) && (z.min() > 0)) {
00094
00095
00096
00097
00098
00099 if (shr && (VX::me(Propagator::modeventdelta()) != ME_INT_NONE))
00100 return ES_NOFIX;
00101
00102 GECODE_ES_CHECK(prune(home,x,y));
00103
00104 return ES_NOFIX;
00105 }
00106
00107 return shr ? ES_NOFIX : ES_FIX;
00108 }
00109
00110 }}}
00111
00112