eqv.cpp
Go to the documentation of this file.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 #include <gecode/int/bool.hh>
00035
00036 namespace Gecode { namespace Int { namespace Bool {
00037
00038
00039
00040
00041
00042
00043 PropCost
00044 NaryEqv::cost(const Space&, const ModEventDelta&) const {
00045 return PropCost::binary(PropCost::LO);
00046 }
00047
00048 Actor*
00049 NaryEqv::copy(Space& home) {
00050 return new (home) NaryEqv(home,*this);
00051 }
00052
00053 ExecStatus
00054 NaryEqv::post(Home home, ViewArray<BoolView>& x, int pm2) {
00055 int n = x.size();
00056 for (int i=n; i--; )
00057 if (x[i].assigned()) {
00058 pm2 ^= x[i].val();
00059 x[i] = x[--n];
00060 }
00061 if (n == 0)
00062 return (pm2 == 1) ? ES_OK : ES_FAILED;
00063 if (n == 1) {
00064 GECODE_ME_CHECK(x[0].eq(home,1^pm2));
00065 return ES_OK;
00066 }
00067 if (n == 2) {
00068 if (pm2 == 1) {
00069 return Bool::Eq<BoolView,BoolView>::post(home,x[0],x[1]);
00070 } else {
00071 NegBoolView nx(x[1]);
00072 return Bool::Eq<BoolView,NegBoolView>::post(home,x[0],nx);
00073 }
00074 }
00075 x.size(n);
00076 (void) new (home) NaryEqv(home,x,pm2);
00077 return ES_OK;
00078 }
00079
00080 ExecStatus
00081 NaryEqv::propagate(Space& home, const ModEventDelta&) {
00082 resubscribe(home,x0);
00083 resubscribe(home,x1);
00084 if (x.size() == 0) {
00085 if (x0.assigned() && x1.assigned()) {
00086 return (pm2 == 1) ? home.ES_SUBSUMED(*this) : ES_FAILED;
00087 } else if (x0.assigned()) {
00088 GECODE_ME_CHECK(x1.eq(home,1^pm2));
00089 return home.ES_SUBSUMED(*this);
00090 } else if (x1.assigned()) {
00091 GECODE_ME_CHECK(x0.eq(home,1^pm2));
00092 return home.ES_SUBSUMED(*this);
00093 }
00094 }
00095 return ES_FIX;
00096 }
00097
00098 }}}
00099
00100