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