subofunion.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:2010-03-0317:32:21+0100(Wed,03Mar2010)$by$Author:schulte$ *$Revision:10364$ * *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{ template<classView0,classView1,classView2> Actor* SubOfUnion<View0,View1,View2>::copy(Space&home,boolshare){ returnnew(home)SubOfUnion(home,share,*this); } template<classView0,classView1,classView2> ExecStatus SubOfUnion<View0,View1,View2>::propagate(Space&home,constModEventDelta&med){ boolallassigned=x0.assigned()&&x1.assigned()&&x2.assigned(); ModEventme0=View0::me(med); ModEventme1=View1::me(med); ModEventme2=View2::me(med); boolmodified=false; do{ //lub(x2)<=lub(x0)ulub(x1) if(modified||Rel::testSetEventUB(me0,me1)) { LubRanges<View0>ub0(x0); LubRanges<View1>ub1(x1); Iter::Ranges::Union<LubRanges<View0>,LubRanges<View1>>u(ub0,ub1); GECODE_ME_CHECK(x2.intersectI(home,u)); } //x1<=glb(x2)-lub(x0) //x0<=glb(x2)-lub(x1) if(modified||Rel::testSetEventAnyB(me0,me1,me2)){ { modified=false; GlbRanges<View2>lb2(x2); LubRanges<View0>ub0(x0); Iter::Ranges::Diff<GlbRanges<View2>,LubRanges<View0>> diff(lb2,ub0); GECODE_ME_CHECK_MODIFIED(modified,x1.includeI(home,diff)); } { GlbRanges<View2>lb2(x2); LubRanges<View1>ub1(x1); Iter::Ranges::Diff<GlbRanges<View2>,LubRanges<View1>> diff(lb2,ub1); GECODE_ME_CHECK_MODIFIED(modified,x0.includeI(home,diff)); } }else{ modified=false; } //cardinalitypropagation if(modified|| Rel::testSetEventCard(me0,me1,me2)|| Rel::testSetEventLB(me0,me1) ){ GlbRanges<View0>lb0c(x0); GlbRanges<View1>lb1c(x1); Iter::Ranges::Inter<GlbRanges<View0>,GlbRanges<View1>> inter(lb0c,lb1c); unsignedintm=Iter::Ranges::size(inter); if(m<x0.cardMax()+x1.cardMax()){ GECODE_ME_CHECK_MODIFIED(modified, x2.cardMax(home, x0.cardMax()+x1.cardMax()-m)); } if(m+x2.cardMin()>x1.cardMax()){ GECODE_ME_CHECK_MODIFIED(modified, x0.cardMin(home, m+x2.cardMin()-x1.cardMax())); } if(m+x2.cardMin()>x0.cardMax()){ GECODE_ME_CHECK_MODIFIED(modified, x1.cardMin(home, m+x2.cardMin()-x0.cardMax())); } } }while(modified); if(shared(x0,x1,x2)){ if(allassigned){ returnhome.ES_SUBSUMED(*this); }else{ returnES_NOFIX; } }else{ if(x0.assigned()+x1.assigned()+x2.assigned()>=2){ returnhome.ES_SUBSUMED(*this); }else{ returnES_FIX; } } } template<classView0,classView1,classView2> forceinline SubOfUnion<View0,View1,View2>::SubOfUnion(Homehome,View0y0, View1y1,View2y2) :MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY, View2,PC_SET_ANY>(home,y0,y1,y2){} template<classView0,classView1,classView2> forceinline SubOfUnion<View0,View1,View2>::SubOfUnion (Space&home,boolshare,SubOfUnion<View0,View1,View2>&p) :MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY, View2,PC_SET_ANY>(home,share,p){} template<classView0,classView1,classView2> ExecStatusSubOfUnion<View0,View1,View2>::post (Homehome,View0x0,View1x1,View2x2){ (void)new(home)SubOfUnion<View0,View1,View2>(home,x0,x1,x2); returnES_OK; } }}} //STATISTICS:set-prop