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
00035
00036
00037
00038 namespace Gecode { namespace Int { namespace Bool {
00039
00040 template<class BVA, class BVB, class BVC>
00041 forceinline
00042 Eqv<BVA,BVB,BVC>::Eqv(Home home, BVA b0, BVB b1, BVC b2)
00043 : BoolTernary<BVA,BVB,BVC>(home,b0,b1,b2) {}
00044
00045 template<class BVA, class BVB, class BVC>
00046 forceinline
00047 Eqv<BVA,BVB,BVC>::Eqv(Space& home, bool share, Eqv<BVA,BVB,BVC>& p)
00048 : BoolTernary<BVA,BVB,BVC>(home,share,p) {}
00049
00050 template<class BVA, class BVB, class BVC>
00051 inline ExecStatus
00052 Eqv<BVA,BVB,BVC>::post(Home home, BVA b0, BVB b1, BVC b2){
00053 switch (bool_test(b0,b1)) {
00054 case BT_SAME:
00055 GECODE_ME_CHECK(b2.one(home)); break;
00056 case BT_COMP:
00057 GECODE_ME_CHECK(b2.zero(home)); break;
00058 case BT_NONE:
00059 if (b2.one())
00060 return Eq<BVA,BVB>::post(home,b0,b1);
00061 if (b0.one()) {
00062 if (b1.one()) {
00063 GECODE_ME_CHECK(b2.one(home)); return ES_OK;
00064 } else if (b1.zero()) {
00065 GECODE_ME_CHECK(b2.zero(home)); return ES_OK;
00066 }
00067 }
00068 if (b0.zero()) {
00069 if (b1.one()) {
00070 GECODE_ME_CHECK(b2.zero(home)); return ES_OK;
00071 } else if (b1.zero()) {
00072 GECODE_ME_CHECK(b2.one(home)); return ES_OK;
00073 }
00074 }
00075 (void) new (home) Eqv(home,b0,b1,b2);
00076 break;
00077 default:
00078 GECODE_NEVER;
00079 }
00080 return ES_OK;
00081 }
00082
00083 template<class BVA, class BVB, class BVC>
00084 Actor*
00085 Eqv<BVA,BVB,BVC>::copy(Space& home, bool share) {
00086 return new (home) Eqv<BVA,BVB,BVC>(home,share,*this);
00087 }
00088
00089 template<class BVA, class BVB, class BVC>
00090 ExecStatus
00091 Eqv<BVA,BVB,BVC>::propagate(Space& home, const ModEventDelta&) {
00092 #define GECODE_INT_STATUS(S0,S1,S2) \
00093 ((BVA::S0<<(2*BVA::BITS))|(BVB::S1<<(1*BVB::BITS))|(BVC::S2<<(0*BVC::BITS)))
00094 switch ((x0.status() << (2*BVA::BITS)) | (x1.status() << (1*BVB::BITS)) |
00095 (x2.status() << (0*BVC::BITS))) {
00096 case GECODE_INT_STATUS(NONE,NONE,NONE):
00097 GECODE_NEVER;
00098 case GECODE_INT_STATUS(NONE,NONE,ZERO):
00099 case GECODE_INT_STATUS(NONE,NONE,ONE):
00100 case GECODE_INT_STATUS(NONE,ZERO,NONE):
00101 return ES_FIX;
00102 case GECODE_INT_STATUS(NONE,ZERO,ZERO):
00103 GECODE_ME_CHECK(x0.one_none(home)); break;
00104 case GECODE_INT_STATUS(NONE,ZERO,ONE):
00105 GECODE_ME_CHECK(x0.zero_none(home)); break;
00106 case GECODE_INT_STATUS(NONE,ONE,NONE):
00107 return ES_FIX;
00108 case GECODE_INT_STATUS(NONE,ONE,ZERO):
00109 GECODE_ME_CHECK(x0.zero_none(home)); break;
00110 case GECODE_INT_STATUS(NONE,ONE,ONE):
00111 GECODE_ME_CHECK(x0.one_none(home)); break;
00112 case GECODE_INT_STATUS(ZERO,NONE,NONE):
00113 return ES_FIX;
00114 case GECODE_INT_STATUS(ZERO,NONE,ZERO):
00115 GECODE_ME_CHECK(x1.one_none(home)); break;
00116 case GECODE_INT_STATUS(ZERO,NONE,ONE):
00117 GECODE_ME_CHECK(x1.zero_none(home)); break;
00118 case GECODE_INT_STATUS(ZERO,ZERO,NONE):
00119 GECODE_ME_CHECK(x2.one_none(home)); break;
00120 case GECODE_INT_STATUS(ZERO,ZERO,ZERO):
00121 return ES_FAILED;
00122 case GECODE_INT_STATUS(ZERO,ZERO,ONE):
00123 break;
00124 case GECODE_INT_STATUS(ZERO,ONE,NONE):
00125 GECODE_ME_CHECK(x2.zero_none(home)); break;
00126 case GECODE_INT_STATUS(ZERO,ONE,ZERO):
00127 break;
00128 case GECODE_INT_STATUS(ZERO,ONE,ONE):
00129 return ES_FAILED;
00130 case GECODE_INT_STATUS(ONE,NONE,NONE):
00131 return ES_FIX;
00132 case GECODE_INT_STATUS(ONE,NONE,ZERO):
00133 GECODE_ME_CHECK(x1.zero_none(home)); break;
00134 case GECODE_INT_STATUS(ONE,NONE,ONE):
00135 GECODE_ME_CHECK(x1.one_none(home)); break;
00136 case GECODE_INT_STATUS(ONE,ZERO,NONE):
00137 GECODE_ME_CHECK(x2.zero_none(home)); break;
00138 case GECODE_INT_STATUS(ONE,ZERO,ZERO):
00139 break;
00140 case GECODE_INT_STATUS(ONE,ZERO,ONE):
00141 return ES_FAILED;
00142 case GECODE_INT_STATUS(ONE,ONE,NONE):
00143 GECODE_ME_CHECK(x2.one_none(home)); break;
00144 case GECODE_INT_STATUS(ONE,ONE,ZERO):
00145 return ES_FAILED;
00146 case GECODE_INT_STATUS(ONE,ONE,ONE):
00147 break;
00148 default:
00149 GECODE_NEVER;
00150 }
00151 return home.ES_SUBSUMED(*this);
00152 #undef GECODE_INT_STATUS
00153 }
00154
00155
00156
00157
00158
00159
00160
00161 forceinline
00162 NaryEqv::NaryEqv(Home home, ViewArray<BoolView>& x0, int pm20)
00163 : BinaryPropagator<BoolView,PC_BOOL_VAL>(home,x0[0],x0[1]),
00164 x(x0), pm2(pm20) {
00165 assert(x.size() >= 2);
00166 x.drop_fst(2);
00167 }
00168
00169 forceinline
00170 NaryEqv::NaryEqv(Space& home, bool share, NaryEqv& p)
00171 : BinaryPropagator<BoolView,PC_BOOL_VAL>(home,share,p), pm2(p.pm2) {
00172 x.update(home,share,p.x);
00173 }
00174
00175 forceinline size_t
00176 NaryEqv::dispose(Space& home) {
00177 (void) BinaryPropagator<BoolView,PC_BOOL_VAL>::dispose(home);
00178 return sizeof(*this);
00179 }
00180
00181 forceinline void
00182 NaryEqv::resubscribe(Space& home, BoolView& x0) {
00183 if (x0.assigned()) {
00184 pm2 ^= x0.val();
00185 int n = x.size();
00186 for (int i=n; i--; )
00187 if (x[i].assigned()) {
00188 pm2 ^= x[i].val();
00189 x[i] = x[--n];
00190 } else {
00191
00192 x0=x[i]; x[i]=x[--n];
00193 x0.subscribe(home,*this,PC_BOOL_VAL,false);
00194 break;
00195 }
00196 x.size(n);
00197 }
00198 }
00199
00200 }}}
00201
00202