00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 namespace Gecode { namespace Int { namespace Rel {
00023
00024
00025
00026
00027
00028
00029 template <class View>
00030 forceinline
00031 Nq<View>::Nq(Space* home, View x0, View x1)
00032 : BinaryPropagator<View,PC_INT_VAL>(home,x0,x1) {}
00033
00034 template <class View>
00035 ExecStatus
00036 Nq<View>::post(Space* home, View x0, View x1){
00037 if (x0.assigned()) {
00038 GECODE_ME_CHECK(x1.nq(home,x0.val()));
00039 } else if (x1.assigned()) {
00040 GECODE_ME_CHECK(x0.nq(home,x1.val()));
00041 } else if (same(x0,x1)) {
00042 return ES_FAILED;
00043 } else {
00044 (void) new (home) Nq<View>(home,x0,x1);
00045 }
00046 return ES_OK;
00047 }
00048
00049 template <class View>
00050 forceinline
00051 Nq<View>::Nq(Space* home, bool share, Nq<View>& p)
00052 : BinaryPropagator<View,PC_INT_VAL>(home,share,p) {}
00053
00054 template <class View>
00055 Actor*
00056 Nq<View>::copy(Space* home, bool share) {
00057 return new (home) Nq<View>(home,share,*this);
00058 }
00059
00060 template <class View>
00061 PropCost
00062 Nq<View>::cost(void) const {
00063 return PC_UNARY_LO;
00064 }
00065
00066 template <class View>
00067 ExecStatus
00068 Nq<View>::propagate(Space* home) {
00069 if (x0.assigned()) {
00070 GECODE_ME_CHECK(x1.nq(home,x0.val()));
00071 } else {
00072 GECODE_ME_CHECK(x0.nq(home,x1.val()));
00073 }
00074 return ES_SUBSUMED;
00075 }
00076
00077
00078
00079
00080
00081 template<class View>
00082 forceinline
00083 NaryNq<View>::NaryNq(Space* home, ViewArray<ViewTuple<View,2> >& x0)
00084 : BinaryPropagator<ViewTuple<View,2>,PC_INT_DOM>(home,
00085 x0[x0.size()-2],
00086 x0[x0.size()-1]), x(x0) {
00087 assert(x.size() >= 2);
00088 x.size(x.size()-2);
00089 }
00090
00091 template<class View>
00092 forceinline
00093 NaryNq<View>::NaryNq(Space* home, bool share, NaryNq<View>& p)
00094 : BinaryPropagator<ViewTuple<View,2>,PC_INT_DOM>(home,share,p) {
00095 x.update(home,share,p.x);
00096 }
00097
00098 template<class View>
00099 forceinline ExecStatus
00100 NaryNq<View>::post(Space* home, ViewArray<ViewTuple<View,2> >& x) {
00101 int n = x.size();
00102 for (int i=n; i--; )
00103 switch (rtest_nq_dom(x[i][0],x[i][1])) {
00104 case RT_FALSE:
00105 x[i]=x[--n];
00106 break;
00107 case RT_TRUE:
00108 return ES_OK;
00109 case RT_MAYBE:
00110 break;
00111 default:
00112 GECODE_NEVER;
00113 }
00114 x.size(n);
00115 if (n == 0)
00116 return ES_FAILED;
00117 if (n == 1)
00118 return Nq<View>::post(home,x[0][0],x[0][1]);
00119 (void) new (home) NaryNq(home,x);
00120 return ES_OK;
00121 }
00122
00123 template<class View>
00124 Actor*
00125 NaryNq<View>::copy(Space* home, bool share) {
00126 return new (home) NaryNq<View>(home,share,*this);
00127 }
00128
00129 template<class View>
00130 ExecStatus
00131 NaryNq<View>::propagate(Space* home) {
00132
00133 int n = x.size();
00134 for (int i=n; i--; )
00135 switch (rtest_nq_dom(x[i][0],x[i][1])) {
00136 case RT_TRUE:
00137 return ES_SUBSUMED;
00138 case RT_FALSE:
00139 x[i].cancel(home,this,PC_INT_DOM);
00140 x[i]=x[--n];
00141 break;
00142 case RT_MAYBE:
00143 break;
00144 default:
00145 GECODE_NEVER;
00146 }
00147 switch (rtest_nq_dom(x0[0],x0[1])) {
00148 case RT_TRUE:
00149 return ES_SUBSUMED;
00150 case RT_FALSE:
00151 if (n == 0) {
00152 GECODE_ES_CHECK(Nq<View>::post(home,x1[0],x1[1]));
00153 return ES_SUBSUMED;
00154 }
00155 x0.cancel(home,this,PC_INT_DOM);
00156 x0=x[--n];
00157 x0.subscribe(home,this,PC_INT_DOM);
00158 break;
00159 case RT_MAYBE:
00160 break;
00161 default:
00162 GECODE_NEVER;
00163 }
00164 switch (rtest_nq_dom(x1[0],x1[1])) {
00165 case RT_TRUE:
00166 return ES_SUBSUMED;
00167 case RT_FALSE:
00168 if (n == 0) {
00169 GECODE_ES_CHECK(Nq<View>::post(home,x0[0],x0[1]));
00170 return ES_SUBSUMED;
00171 }
00172 x1.cancel(home,this,PC_INT_DOM);
00173 x1=x[--n];
00174 x1.subscribe(home,this,PC_INT_DOM);
00175 break;
00176 case RT_MAYBE:
00177 break;
00178 default:
00179 GECODE_NEVER;
00180 }
00181 x.size(n);
00182 return ES_FIX;
00183 }
00184
00185 }}}
00186
00187
00188