partition.hpp /usr/include/gecode/set/rel-op.hh Gecode Gecode::Set Gecode::Set::RelOp /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *GuidoTack<tack@gecode.org> *ChristianSchulte<schulte@gecode.org> * *Contributingauthors: *GaborSzokoli<szokoli@gecode.org> * *Copyright: *GuidoTack,2004 *ChristianSchulte,2004 *GaborSzokoli,2004 * *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. * */ namespaceGecode{namespaceSet{namespaceRelOp{ /* *"Narypartition"propagator * */ template<classView0,classView1> forceinline PartitionN<View0,View1>::PartitionN(Homehome,ViewArray<View0>&x,View1y) :MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home,x,y){ shared=x.shared(home)||viewarrayshared(home,x,y); } template<classView0,classView1> forceinline PartitionN<View0,View1>::PartitionN(Homehome,ViewArray<View0>&x, constIntSet&z,View1y) :MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home,x,y){ shared=x.shared(home)||viewarrayshared(home,x,y); IntSetRangesrz(z); unionOfDets.includeI(home,rz); } template<classView0,classView1> forceinline PartitionN<View0,View1>::PartitionN(Space&home,boolshare,PartitionN&p) :MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home,share,p), shared(p.shared){ unionOfDets.update(home,p.unionOfDets); } template<classView0,classView1> Actor* PartitionN<View0,View1>::copy(Space&home,boolshare){ returnnew(home)PartitionN(home,share,*this); } template<classView0,classView1> ExecStatusPartitionN<View0,View1>::post(Homehome,ViewArray<View0>&x, View1y){ switch(x.size()){ case0: GECODE_ME_CHECK(y.cardMax(home,0)); returnES_OK; case1: returnRel::Eq<View0,View1>::post(home,x[0],y); default: (void)new(home)PartitionN<View0,View1>(home,x,y); returnES_OK; } } template<classView0,classView1> ExecStatusPartitionN<View0,View1>::post(Homehome,ViewArray<View0>&x, constIntSet&z,View1y){ (void)new(home)PartitionN<View0,View1>(home,x,z,y); returnES_OK; } template<classView0,classView1> PropCostPartitionN<View0,View1>::cost(constSpace&,constModEventDelta&)const{ returnPropCost::quadratic(PropCost::LO,x.size()+1); } template<classView0,classView1> ExecStatus PartitionN<View0,View1>::propagate(Space&home,constModEventDelta&med){ ModEventme0=View0::me(med); ModEventme1=View1::me(med); boolubevent=Rel::testSetEventUB(me0,me1); boollbevent=Rel::testSetEventLB(me0,me1); boolanybevent=Rel::testSetEventAnyB(me0,me1); boolcardevent=Rel::testSetEventCard(me0,me1); boolmodified=false; boololdModified=false; do{ oldModified=modified; modified=false; if(oldModified||anybevent) GECODE_ES_CHECK(partitionNXiUB(home,modified,x,y,unionOfDets)); if(modified||oldModified||anybevent) GECODE_ES_CHECK(partitionNXiLB(home,modified,x,y,unionOfDets)); if(modified||oldModified||ubevent) GECODE_ES_CHECK(partitionNYUB(home,modified,x,y,unionOfDets)); if(modified||oldModified||lbevent) GECODE_ES_CHECK(partitionNYLB(home,modified,x,y,unionOfDets)); if(modified||oldModified||ubevent) GECODE_ES_CHECK(unionNXiUB(home,modified,x,y,unionOfDets)); if(modified||oldModified||cardevent) GECODE_ES_CHECK(partitionNCard(home,modified,x,y,unionOfDets)); }while(modified); //removingassignedsetsfromx,accumulatingthevalue: for(inti=0;i<x.size();i++){ //Donotreverse!Eatsawaytheendofthearray! while(i<x.size()&&x[i].assigned()){ GlbRanges<View0>det(x[i]); unionOfDets.includeI(home,det); x.move_lst(i); } } //Whenwerunoutofvariables,makeafinalcheckanddisolve: if(x.size()==0){ BndSetRangesall1(unionOfDets); GECODE_ME_CHECK(y.intersectI(home,all1)); BndSetRangesall2(unionOfDets); GECODE_ME_CHECK(y.includeI(home,all2)); unionOfDets.dispose(home); returnhome.ES_SUBSUMED(*this); } returnshared?ES_NOFIX:ES_FIX; } }}} //STATISTICS:set-prop