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