bool-lq.hpp gecode/int/bool.hh /usr/include/gecode/int/nvalues.hh Gecode Gecode::Int Gecode::Int::NValues /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2011 * *Lastmodified: *$Date:2012-09-0717:31:22+0200(Fri,07Sep2012)$by$Author:schulte$ *$Revision:13068$ * *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. * */ #include<gecode/int/bool.hh> namespaceGecode{namespaceInt{namespaceNValues{ template<classVY> forceinline LqBool<VY>::LqBool(Homehome,intstatus,ViewArray<BoolView>&x,VYy) :BoolBase<VY>(home,status,x,y){} template<classVY> forceinline LqBool<VY>::LqBool(Space&home,boolshare,LqBool<VY>&p) :BoolBase<VY>(home,share,p){} template<classVY> Actor* LqBool<VY>::copy(Space&home,boolshare){ returnnew(home)LqBool<VY>(home,share,*this); } template<classVY> inlineExecStatus LqBool<VY>::post(Homehome,ViewArray<BoolView>&x,VYy){ if(x.size()==0){ GECODE_ME_CHECK(y.gq(home,0)); returnES_OK; } x.unique(home); GECODE_ME_CHECK(y.gq(home,1)); if(x.size()==1) returnES_OK; if(y.max()==1){ assert(y.assigned()); ViewArray<BoolView>xc(home,x); returnBool::NaryEq<BoolView>::post(home,xc); } if(y.min()>=2) returnES_OK; intn=x.size(); intstatus=0; for(inti=n;i--;) if(x[i].zero()){ if(status&VS_ONE){ GECODE_ME_CHECK(y.gq(home,2)); returnES_OK; } x[i]=x[--n]; status|=VS_ZERO; }elseif(x[i].one()){ if(status&VS_ZERO){ GECODE_ME_CHECK(y.gq(home,2)); returnES_OK; } x[i]=x[--n]; status|=VS_ONE; } assert(status!=(VS_ZERO|VS_ONE)); if(n==0){ assert((status!=0)&&(y.min()>=1)); returnES_OK; } x.size(n); (void)new(home)LqBool<VY>(home,status,x,y); returnES_OK; } template<classVY> ExecStatus LqBool<VY>::propagate(Space&home,constModEventDelta&){ if(status==(VS_ZERO|VS_ONE)){ GECODE_ME_CHECK(y.gq(home,2)); returnhome.ES_SUBSUMED(*this); } if(c.empty()){ assert((status!=0)&&(y.min()>=1)); returnhome.ES_SUBSUMED(*this); } if(y.max()==1){ if(status==VS_ZERO){ //Markthateverythingisdone status=VS_ZERO|VS_ONE; for(Advisors<ViewAdvisor<BoolView>>as(c);as();++as) GECODE_ME_CHECK(as.advisor().view().zero(home)); returnhome.ES_SUBSUMED(*this); } if(status==VS_ONE){ //Markthateverythingisdone status=VS_ZERO|VS_ONE; for(Advisors<ViewAdvisor<BoolView>>as(c);as();++as) GECODE_ME_CHECK(as.advisor().view().one(home)); returnhome.ES_SUBSUMED(*this); } } if(y.min()==2) returnhome.ES_SUBSUMED(*this); returnES_FIX; } }}} //STATISTICS:int-prop