prop.hpp gecode/int/rel.hh /usr/include/gecode/int/member.hh Gecode Gecode::Int Gecode::Int::Member /*-*-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{namespaceMember{ template<classView> forceinline Prop<View>::Prop(Homehome,ValSet&vs0,ViewArray<View>&x,Viewy) :NaryOnePropagator<View,PC_INT_DOM>(home,x,y), vs(vs0){} template<classView> forceinlinevoid Prop<View>::add(Space&home,ValSet&vs,ViewArray<View>&x){ intn=x.size(); for(inti=n;i--;) if(x[i].assigned()){ vs.add(home,x[i].val()); x[i]=x[--n]; } x.size(n); } template<classView> forceinlinevoid Prop<View>::eliminate(Space&home){ intn=x.size(); for(inti=n;i--;) if((rtest_eq_dom(x[i],y)==RT_FALSE)||vs.subset(x[i])){ //x[i]isdifferentfromyorvaluesarecontainedinvs x[i].cancel(home,*this,PC_INT_DOM); x[i]=x[--n]; } x.size(n); } template<classView> inlineExecStatus Prop<View>::post(Homehome,ViewArray<View>&x,Viewy){ if(x.size()==0) returnES_FAILED; x.unique(home); if(x.size()==1) returnRel::EqDom<View,View>::post(home,x[0],y); if(x.same(home,y)) returnES_OK; //Eliminateassignedviewsandstorethemintothevalueset ValSetvs; add(home,vs,x); if(x.size()==0){ ValSet::Rangesvsr(vs); GECODE_ME_CHECK(y.inter_r(home,vsr,false)); returnES_OK; } (void)new(home)Prop<View>(home,vs,x,y); returnES_OK; } template<classView> forceinlineExecStatus Prop<View>::post(Homehome,ValSet&vs,ViewArray<View>&x,Viewy){ (void)new(home)Prop<View>(home,vs,x,y); returnES_OK; } template<classView> forceinline Prop<View>::Prop(Space&home,boolshare,Prop<View>&p) :NaryOnePropagator<View,PC_INT_DOM>(home,share,p){ vs.update(home,share,p.vs); } template<classView> Propagator* Prop<View>::copy(Space&home,boolshare){ returnnew(home)Prop<View>(home,share,*this); } template<classView> forceinlinesize_t Prop<View>::dispose(Space&home){ vs.dispose(home); (void)NaryOnePropagator<View,PC_INT_DOM>::dispose(home); returnsizeof(*this); } template<classView> PropCost Prop<View>::cost(constSpace&,constModEventDelta&)const{ returnPropCost::linear(PropCost::HI,x.size()+1); } template<classView> ExecStatus Prop<View>::propagate(Space&home,constModEventDelta&med){ //Addassignedviewstovalueset if(View::me(med)==ME_INT_VAL) add(home,vs,x); //Eliminateviewsfromx eliminate(home); if(x.size()==0){ //ymusthavevaluesinthevalueset ValSet::Rangesvsr(vs); GECODE_ME_CHECK(y.inter_r(home,vsr,false)); returnhome.ES_SUBSUMED(*this); } //Constrainytounionofxandvalueset Regionr(home); assert(x.size()>0); ValSet::Rangesvsr(vs); ViewRanges<View>xsr(x[x.size()-1]); Iter::Ranges::NaryUnionu(r,vsr,xsr); for(inti=x.size()-1;i--;){ ViewRanges<View>xir(x[i]); u|=xir; } GECODE_ME_CHECK(y.inter_r(home,u,false)); //Checkwhetherallvaluesinyarealreadyinthevalueset if(vs.subset(y)) returnhome.ES_SUBSUMED(*this); returnES_FIX; } }}} //STATISTICS:int-prop