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>
00037 forceinline
00038 ViewBase<VX,VY,VZ>::ViewBase(Home home,
00039 ViewArray<VX>& x0, VY y0, VZ z0, int c0)
00040 : Propagator(home), x(x0), y(y0), z(z0), c(c0) {
00041 if (isintset(y))
00042 home.notice(*this,AP_DISPOSE);
00043 x.subscribe(home,*this,PC_INT_DOM);
00044 subscribe(home,*this,y);
00045 z.subscribe(home,*this,PC_INT_BND);
00046 }
00047
00048 template<class VX, class VY, class VZ>
00049 forceinline
00050 ViewBase<VX,VY,VZ>::ViewBase(Space& home, ViewBase<VX,VY,VZ>& p)
00051 : Propagator(home,p), c(p.c) {
00052 x.update(home,p.x);
00053 update(y,home,p.y);
00054 z.update(home,p.z);
00055 }
00056
00057 template<class VX, class VY, class VZ>
00058 PropCost
00059 ViewBase<VX,VY,VZ>::cost(const Space&, const ModEventDelta&) const {
00060 return PropCost::linear(PropCost::LO,x.size()+1);
00061 }
00062
00063 template<class VX, class VY, class VZ>
00064 void
00065 ViewBase<VX,VY,VZ>::reschedule(Space& home) {
00066 x.reschedule(home,*this,PC_INT_DOM);
00067 Gecode::Int::Count::reschedule(home,*this,y);
00068 z.reschedule(home,*this,PC_INT_BND);
00069 }
00070
00071 template<class VX, class VY, class VZ>
00072 forceinline size_t
00073 ViewBase<VX,VY,VZ>::dispose(Space& home) {
00074 if (isintset(y))
00075 home.ignore(*this,AP_DISPOSE);
00076 x.cancel(home,*this,PC_INT_DOM);
00077 cancel(home,*this,y);
00078 z.cancel(home,*this,PC_INT_BND);
00079 (void) Propagator::dispose(home);
00080 return sizeof(*this);
00081 }
00082
00083 template<class VX, class VY, class VZ>
00084 forceinline void
00085 ViewBase<VX,VY,VZ>::count(Space& home) {
00086 int n = x.size();
00087 for (int i=n; i--; )
00088 switch (holds(x[i],y)) {
00089 case RT_FALSE:
00090 x[i].cancel(home,*this,PC_INT_DOM); x[i]=x[--n];
00091 break;
00092 case RT_TRUE:
00093 x[i].cancel(home,*this,PC_INT_DOM); x[i]=x[--n];
00094 c--;
00095 break;
00096 case RT_MAYBE:
00097 break;
00098 default:
00099 GECODE_NEVER;
00100 }
00101 x.size(n);
00102 }
00103
00104 template<class VX, class VY, class VZ>
00105 forceinline int
00106 ViewBase<VX,VY,VZ>::atleast(void) const {
00107 return -c;
00108 }
00109
00110 template<class VX, class VY, class VZ>
00111 forceinline int
00112 ViewBase<VX,VY,VZ>::atmost(void) const {
00113 return x.size()-c;
00114 }
00115
00116 template<class VX>
00117 forceinline bool
00118 shared(const IntSet&, VX) {
00119 return false;
00120 }
00121 template<class VX, class VY, class VZ>
00122 forceinline bool
00123 ViewBase<VX,VY,VZ>::sharing(const ViewArray<VX>& x,
00124 const VY& y, const VZ& z) {
00125 if (shared(y,z))
00126 return true;
00127 for (int i=0; i<x.size(); i++)
00128 if (shared(x[i],z))
00129 return true;
00130 return false;
00131 }
00132
00133 }}}
00134
00135