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>
00037 forceinline
00038 GqInt<VX,VY>::GqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c)
00039 : IntBase<VX,VY>(home,x,n_s,y,c) {}
00040
00041 template<class VX, class VY>
00042 ExecStatus
00043 GqInt<VX,VY>::post(Home home, ViewArray<VX>& x, VY y, int c) {
00044
00045 int n_x = x.size();
00046 for (int i=n_x; i--; )
00047 switch (holds(x[i],y)) {
00048 case RT_FALSE:
00049 x[i] = x[--n_x]; break;
00050 case RT_TRUE:
00051 x[i] = x[--n_x]; c--; break;
00052 case RT_MAYBE:
00053 break;
00054 default:
00055 GECODE_NEVER;
00056 }
00057 x.size(n_x);
00058
00059 if (n_x < c)
00060 return ES_FAILED;
00061
00062 if (c <= 0)
00063 return ES_OK;
00064
00065 if (c == n_x)
00066 return post_true(home,x,y);
00067 (void) new (home) GqInt<VX,VY>(home,x,c+1,y,c);
00068 return ES_OK;
00069 }
00070
00071 template<class VX, class VY>
00072 forceinline
00073 GqInt<VX,VY>::GqInt(Space& home, GqInt<VX,VY>& p)
00074 : IntBase<VX,VY>(home,p) {}
00075
00076 template<class VX, class VY>
00077 Actor*
00078 GqInt<VX,VY>::copy(Space& home) {
00079 return new (home) GqInt<VX,VY>(home,*this);
00080 }
00081
00082 template<class VX, class VY>
00083 ExecStatus
00084 GqInt<VX,VY>::propagate(Space& home, const ModEventDelta&) {
00085
00086 int n_x = x.size();
00087 for (int i=n_s; i--; )
00088 switch (holds(x[i],y)) {
00089 case RT_FALSE:
00090 x[i].cancel(home,*this,PC_INT_DOM);
00091 x[i]=x[--n_s]; x[n_s]=x[--n_x];
00092 break;
00093 case RT_TRUE:
00094 x[i].cancel(home,*this,PC_INT_DOM);
00095 x[i]=x[--n_s]; x[n_s]=x[--n_x]; c--;
00096 break;
00097 case RT_MAYBE:
00098 break;
00099 default:
00100 GECODE_NEVER;
00101 }
00102 x.size(n_x);
00103 if (n_x < c)
00104 return ES_FAILED;
00105 if (c <= 0)
00106 return home.ES_SUBSUMED(*this);
00107
00108 for (int i=n_x; i-- > n_s; )
00109 switch (holds(x[i],y)) {
00110 case RT_FALSE: x[i]=x[--n_x]; break;
00111 case RT_TRUE: x[i]=x[--n_x]; c--; break;
00112 case RT_MAYBE: break;
00113 default: GECODE_NEVER;
00114 }
00115 x.size(n_x);
00116 if (n_x < c)
00117 return ES_FAILED;
00118 if (c <= 0)
00119 return home.ES_SUBSUMED(*this);
00120 if (c == n_x) {
00121
00122 GECODE_ES_CHECK(post_true(home,x,y));
00123 return home.ES_SUBSUMED(*this);
00124 }
00125
00126 while (n_s <= c)
00127 x[n_s++].subscribe(home,*this,PC_INT_DOM,false);
00128 return ES_FIX;
00129 }
00130
00131 }}}
00132
00133