eqv.hpp /usr/include/gecode/int/bool.hh Gecode Gecode::Int Gecode::Int::Bool GECODE_INT_STATUS S0 S1 S2 ((BVA::S0<<(2*BVA::BITS))|(BVB::S1<<(1*BVB::BITS))|(BVC::S2<<(0*BVC::BITS))) /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2004 * *Lastmodified: *$Date:2011-10-0711:28:27+0200(Fri,07Oct2011)$by$Author:schulte$ *$Revision:12427$ * *ThisfileispartofGecode,thegenericconstraint *developmentenvironment: *http://www.gecode.org * *Permissionisherebygranted,freeofcharge,toanypersonobtaining *acopyofthissoftwareandassociateddocumentationfiles(the *"Software"),todealintheSoftwarewithoutrestriction,including *withoutlimitationtherightstouse,copy,modify,merge,publish, *distribute,sublicense,and/orsellcopiesoftheSoftware,andto *permitpersonstowhomtheSoftwareisfurnishedtodoso,subjectto *thefollowingconditions: * *Theabovecopyrightnoticeandthispermissionnoticeshallbe *includedinallcopiesorsubstantialportionsoftheSoftware. * *THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND, *EXPRESSORIMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOF *MERCHANTABILITY,FITNESSFORAPARTICULARPURPOSEAND *NONINFRINGEMENT.INNOEVENTSHALLTHEAUTHORSORCOPYRIGHTHOLDERSBE *LIABLEFORANYCLAIM,DAMAGESOROTHERLIABILITY,WHETHERINANACTION *OFCONTRACT,TORTOROTHERWISE,ARISINGFROM,OUTOFORINCONNECTION *WITHTHESOFTWAREORTHEUSEOROTHERDEALINGSINTHESOFTWARE. * */ namespaceGecode{namespaceInt{namespaceBool{ template<classBVA,classBVB,classBVC> forceinline Eqv<BVA,BVB,BVC>::Eqv(Homehome,BVAb0,BVBb1,BVCb2) :BoolTernary<BVA,BVB,BVC>(home,b0,b1,b2){} template<classBVA,classBVB,classBVC> forceinline Eqv<BVA,BVB,BVC>::Eqv(Space&home,boolshare,Eqv<BVA,BVB,BVC>&p) :BoolTernary<BVA,BVB,BVC>(home,share,p){} template<classBVA,classBVB,classBVC> inlineExecStatus Eqv<BVA,BVB,BVC>::post(Homehome,BVAb0,BVBb1,BVCb2){ switch(bool_test(b0,b1)){ caseBT_SAME: GECODE_ME_CHECK(b2.one(home));break; caseBT_COMP: GECODE_ME_CHECK(b2.zero(home));break; caseBT_NONE: if(b2.one()) returnEq<BVA,BVB>::post(home,b0,b1); if(b0.one()){ if(b1.one()){ GECODE_ME_CHECK(b2.one(home));returnES_OK; }elseif(b1.zero()){ GECODE_ME_CHECK(b2.zero(home));returnES_OK; } } if(b0.zero()){ if(b1.one()){ GECODE_ME_CHECK(b2.zero(home));returnES_OK; }elseif(b1.zero()){ GECODE_ME_CHECK(b2.one(home));returnES_OK; } } (void)new(home)Eqv(home,b0,b1,b2); break; default: GECODE_NEVER; } returnES_OK; } template<classBVA,classBVB,classBVC> Actor* Eqv<BVA,BVB,BVC>::copy(Space&home,boolshare){ returnnew(home)Eqv<BVA,BVB,BVC>(home,share,*this); } template<classBVA,classBVB,classBVC> ExecStatus Eqv<BVA,BVB,BVC>::propagate(Space&home,constModEventDelta&){ #defineGECODE_INT_STATUS(S0,S1,S2)\ ((BVA::S0<<(2*BVA::BITS))|(BVB::S1<<(1*BVB::BITS))|(BVC::S2<<(0*BVC::BITS))) switch((x0.status()<<(2*BVA::BITS))|(x1.status()<<(1*BVB::BITS))| (x2.status()<<(0*BVC::BITS))){ caseGECODE_INT_STATUS(NONE,NONE,NONE): GECODE_NEVER; caseGECODE_INT_STATUS(NONE,NONE,ZERO): caseGECODE_INT_STATUS(NONE,NONE,ONE): caseGECODE_INT_STATUS(NONE,ZERO,NONE): returnES_FIX; caseGECODE_INT_STATUS(NONE,ZERO,ZERO): GECODE_ME_CHECK(x0.one_none(home));break; caseGECODE_INT_STATUS(NONE,ZERO,ONE): GECODE_ME_CHECK(x0.zero_none(home));break; caseGECODE_INT_STATUS(NONE,ONE,NONE): returnES_FIX; caseGECODE_INT_STATUS(NONE,ONE,ZERO): GECODE_ME_CHECK(x0.zero_none(home));break; caseGECODE_INT_STATUS(NONE,ONE,ONE): GECODE_ME_CHECK(x0.one_none(home));break; caseGECODE_INT_STATUS(ZERO,NONE,NONE): returnES_FIX; caseGECODE_INT_STATUS(ZERO,NONE,ZERO): GECODE_ME_CHECK(x1.one_none(home));break; caseGECODE_INT_STATUS(ZERO,NONE,ONE): GECODE_ME_CHECK(x1.zero_none(home));break; caseGECODE_INT_STATUS(ZERO,ZERO,NONE): GECODE_ME_CHECK(x2.one_none(home));break; caseGECODE_INT_STATUS(ZERO,ZERO,ZERO): returnES_FAILED; caseGECODE_INT_STATUS(ZERO,ZERO,ONE): break; caseGECODE_INT_STATUS(ZERO,ONE,NONE): GECODE_ME_CHECK(x2.zero_none(home));break; caseGECODE_INT_STATUS(ZERO,ONE,ZERO): break; caseGECODE_INT_STATUS(ZERO,ONE,ONE): returnES_FAILED; caseGECODE_INT_STATUS(ONE,NONE,NONE): returnES_FIX; caseGECODE_INT_STATUS(ONE,NONE,ZERO): GECODE_ME_CHECK(x1.zero_none(home));break; caseGECODE_INT_STATUS(ONE,NONE,ONE): GECODE_ME_CHECK(x1.one_none(home));break; caseGECODE_INT_STATUS(ONE,ZERO,NONE): GECODE_ME_CHECK(x2.zero_none(home));break; caseGECODE_INT_STATUS(ONE,ZERO,ZERO): break; caseGECODE_INT_STATUS(ONE,ZERO,ONE): returnES_FAILED; caseGECODE_INT_STATUS(ONE,ONE,NONE): GECODE_ME_CHECK(x2.one_none(home));break; caseGECODE_INT_STATUS(ONE,ONE,ZERO): returnES_FAILED; caseGECODE_INT_STATUS(ONE,ONE,ONE): break; default: GECODE_NEVER; } returnhome.ES_SUBSUMED(*this); #undefGECODE_INT_STATUS } /* *N-aryBooleanequivalencepropagator * */ forceinline NaryEqv::NaryEqv(Homehome,ViewArray<BoolView>&x0,intpm20) :BinaryPropagator<BoolView,PC_BOOL_VAL>(home,x0[0],x0[1]), x(x0),pm2(pm20){ assert(x.size()>=2); x.drop_fst(2); } forceinline NaryEqv::NaryEqv(Space&home,boolshare,NaryEqv&p) :BinaryPropagator<BoolView,PC_BOOL_VAL>(home,share,p),pm2(p.pm2){ x.update(home,share,p.x); } forceinlinesize_t NaryEqv::dispose(Space&home){ (void)BinaryPropagator<BoolView,PC_BOOL_VAL>::dispose(home); returnsizeof(*this); } forceinlinevoid NaryEqv::resubscribe(Space&home,BoolView&x0){ if(x0.assigned()){ pm2^=x0.val(); intn=x.size(); for(inti=n;i--;) if(x[i].assigned()){ pm2^=x[i].val(); x[i]=x[--n]; }else{ //Movetox0andsubscribe x0=x[i];x[i]=x[--n]; x0.subscribe(home,*this,PC_BOOL_VAL,false); break; } x.size(n); } } }}} //STATISTICS:int-prop