bool-gq.hpp gecode/int/rel.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/rel.hh> namespaceGecode{namespaceInt{namespaceNValues{ template<classVY> forceinline GqBool<VY>::GqBool(Homehome,intstatus,ViewArray<BoolView>&x,VYy) :BoolBase<VY>(home,status,x,y){} template<classVY> forceinline GqBool<VY>::GqBool(Space&home,boolshare,GqBool<VY>&p) :BoolBase<VY>(home,share,p){} template<classVY> Actor* GqBool<VY>::copy(Space&home,boolshare){ returnnew(home)GqBool<VY>(home,share,*this); } template<classVY> inlineExecStatus GqBool<VY>::post(Homehome,ViewArray<BoolView>&x,VYy){ if(x.size()==0){ GECODE_ME_CHECK(y.lq(home,0)); returnES_OK; } x.unique(home); if(x.size()==1){ GECODE_ME_CHECK(y.lq(home,1)); returnES_OK; } GECODE_ME_CHECK(y.lq(home,2)); if(y.max()<=1) returnES_OK; if(y.min()==2){ assert(y.assigned()); ViewArray<BoolView>xc(home,x); returnRel::NaryNq<BoolView>::post(home,xc); } intn=x.size(); intstatus=0; for(inti=n;i--;) if(x[i].zero()){ if(status&VS_ONE) returnES_OK; x[i]=x[--n]; status|=VS_ZERO; }elseif(x[i].one()){ if(status&VS_ZERO) returnES_OK; x[i]=x[--n]; status|=VS_ONE; } assert(status!=(VS_ZERO|VS_ONE)); if(n==0){ assert(status!=0); GECODE_ME_CHECK(y.lq(home,1)); returnES_OK; } x.size(n); (void)new(home)GqBool<VY>(home,status,x,y); returnES_OK; } template<classVY> ExecStatus GqBool<VY>::propagate(Space&home,constModEventDelta&){ if(status==(VS_ZERO|VS_ONE)) returnhome.ES_SUBSUMED(*this); if(c.empty()){ assert(status!=0); GECODE_ME_CHECK(y.lq(home,1)); returnhome.ES_SUBSUMED(*this); } if(y.max()<=1) returnhome.ES_SUBSUMED(*this); if(y.min()==2){ Advisors<ViewAdvisor<BoolView>>as(c); assert(as()); ViewAdvisor<BoolView>&a(as.advisor()); ++as; if(!as()){ //Onlyasingleviewisleft if(status==VS_ZERO){ GECODE_ME_CHECK(a.view().one(home)); }elseif(status==VS_ONE){ GECODE_ME_CHECK(a.view().zero(home)); }else{ returnES_FAILED; } returnhome.ES_SUBSUMED(*this); } } returnES_FIX; } }}} //STATISTICS:int-prop