ite.hpp gecode/int/rel.hh algorithm /usr/include/gecode/int/bool.hh Gecode Gecode::Int Gecode::Int::Bool /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2013 * *Lastmodified: *$Date:2013-04-2920:52:35+0200(Mon,29Apr2013)$by$Author:schulte$ *$Revision:13590$ * *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> #include<algorithm> namespaceGecode{namespaceInt{namespaceBool{ template<classView,PropCondpc> forceinline IteBase<View,pc>::IteBase(Homehome,BoolViewb0,Viewy0,Viewy1,Viewy2) :Propagator(home),b(b0),x0(y0),x1(y1),x2(y2){ b.subscribe(home,*this,PC_BOOL_VAL); x0.subscribe(home,*this,pc); x1.subscribe(home,*this,pc); x2.subscribe(home,*this,pc); } template<classView,PropCondpc> forceinline IteBase<View,pc>::IteBase(Space&home,boolshare,IteBase<View,pc>&p) :Propagator(home,share,p){ b.update(home,share,p.b); x0.update(home,share,p.x0); x1.update(home,share,p.x1); x2.update(home,share,p.x2); } template<classView,PropCondpc> PropCost IteBase<View,pc>::cost(constSpace&,constModEventDelta&)const{ returnPropCost::ternary(PropCost::LO); } template<classView,PropCondpc> forceinlinesize_t IteBase<View,pc>::dispose(Space&home){ b.cancel(home,*this,PC_BOOL_VAL); x0.cancel(home,*this,pc); x1.cancel(home,*this,pc); x2.cancel(home,*this,pc); (void)Propagator::dispose(home); returnsizeof(*this); } template<classView> forceinline IteBnd<View>::IteBnd(Homehome,BoolViewb,Viewx0,Viewx1,Viewx2) :IteBase<View,PC_INT_BND>(home,b,x0,x1,x2){} template<classView> forceinline IteBnd<View>::IteBnd(Space&home,boolshare,IteBnd<View>&p) :IteBase<View,PC_INT_BND>(home,share,p){} template<classView> Actor* IteBnd<View>::copy(Space&home,boolshare){ returnnew(home)IteBnd<View>(home,share,*this); } template<classView> inlineExecStatus IteBnd<View>::post(Homehome,BoolViewb,Viewx0,Viewx1,Viewx2){ if(same(x0,x1)||b.one()) returnRel::EqBnd<View,View>::post(home,x2,x0); if(b.zero()) returnRel::EqBnd<View,View>::post(home,x2,x1); GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max()))); GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min()))); (void)new(home)IteBnd<View>(home,b,x0,x1,x2); returnES_OK; } template<classView> ExecStatus IteBnd<View>::propagate(Space&home,constModEventDelta&){ if(b.one()) GECODE_REWRITE(*this,(Rel::EqBnd<View,View>::post(home(*this),x2,x0))); if(b.zero()) GECODE_REWRITE(*this,(Rel::EqBnd<View,View>::post(home(*this),x2,x1))); GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max()))); GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min()))); RelTesteq20=rtest_eq_bnd(x2,x0); RelTesteq21=rtest_eq_bnd(x2,x1); if((eq20==RT_FALSE)&&(eq21==RT_FALSE)) returnES_FAILED; if(eq20==RT_FALSE){ GECODE_ME_CHECK(b.zero_none(home)); if(eq21==RT_TRUE) returnhome.ES_SUBSUMED(*this); else GECODE_REWRITE(*this,(Rel::EqBnd<View,View>::post(home(*this),x2,x1))); } if(eq21==RT_FALSE){ GECODE_ME_CHECK(b.one_none(home)); if(eq20==RT_TRUE) returnhome.ES_SUBSUMED(*this); else GECODE_REWRITE(*this,(Rel::EqBnd<View,View>::post(home(*this),x2,x0))); } if((eq20==RT_TRUE)&&(eq21==RT_TRUE)) returnhome.ES_SUBSUMED(*this); returnES_FIX; } template<classView> forceinline IteDom<View>::IteDom(Homehome,BoolViewb,Viewx0,Viewx1,Viewx2) :IteBase<View,PC_INT_DOM>(home,b,x0,x1,x2){} template<classView> forceinline IteDom<View>::IteDom(Space&home,boolshare,IteDom<View>&p) :IteBase<View,PC_INT_DOM>(home,share,p){} template<classView> Actor* IteDom<View>::copy(Space&home,boolshare){ returnnew(home)IteDom<View>(home,share,*this); } template<classView> inlineExecStatus IteDom<View>::post(Homehome,BoolViewb,Viewx0,Viewx1,Viewx2){ if(same(x0,x1)||b.one()) returnRel::EqDom<View,View>::post(home,x2,x0); if(b.zero()) returnRel::EqDom<View,View>::post(home,x2,x1); GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max()))); GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min()))); (void)new(home)IteDom<View>(home,b,x0,x1,x2); returnES_OK; } template<classView> PropCost IteDom<View>::cost(constSpace&,constModEventDelta&med)const{ if(View::me(med)==ME_INT_DOM) returnPropCost::ternary(PropCost::HI); else returnPropCost::ternary(PropCost::LO); } template<classView> ExecStatus IteDom<View>::propagate(Space&home,constModEventDelta&med){ if(b.one()) GECODE_REWRITE(*this,(Rel::EqDom<View,View>::post(home(*this),x2,x0))); if(b.zero()) GECODE_REWRITE(*this,(Rel::EqDom<View,View>::post(home(*this),x2,x1))); GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max()))); GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min()))); if(View::me(med)!=ME_INT_DOM){ RelTesteq20=rtest_eq_bnd(x2,x0); RelTesteq21=rtest_eq_bnd(x2,x1); if((eq20==RT_FALSE)&&(eq21==RT_FALSE)) returnES_FAILED; if(eq20==RT_FALSE){ GECODE_ME_CHECK(b.zero_none(home)); if(eq21==RT_TRUE) returnhome.ES_SUBSUMED(*this); else GECODE_REWRITE(*this, (Rel::EqDom<View,View>::post(home(*this),x2,x1))); } if(eq21==RT_FALSE){ GECODE_ME_CHECK(b.one_none(home)); if(eq20==RT_TRUE) returnhome.ES_SUBSUMED(*this); else GECODE_REWRITE(*this, (Rel::EqDom<View,View>::post(home(*this),x2,x0))); } if((eq20==RT_TRUE)&&(eq21==RT_TRUE)) returnhome.ES_SUBSUMED(*this); returnhome.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM)); } RelTesteq20=rtest_eq_dom(x2,x0); RelTesteq21=rtest_eq_dom(x2,x1); if((eq20==RT_FALSE)&&(eq21==RT_FALSE)) returnES_FAILED; if(eq20==RT_FALSE){ GECODE_ME_CHECK(b.zero_none(home)); if(eq21==RT_TRUE) returnhome.ES_SUBSUMED(*this); else GECODE_REWRITE(*this, (Rel::EqDom<View,View>::post(home(*this),x2,x1))); } if(eq21==RT_FALSE){ GECODE_ME_CHECK(b.one_none(home)); if(eq20==RT_TRUE) returnhome.ES_SUBSUMED(*this); else GECODE_REWRITE(*this, (Rel::EqDom<View,View>::post(home(*this),x2,x0))); } assert((eq20!=RT_TRUE)||(eq21!=RT_TRUE)); ViewRanges<View>r0(x0),r1(x1); Iter::Ranges::Union<ViewRanges<View>,ViewRanges<View>>u(r0,r1); if(!same(x0,x2)&&!same(x1,x2)) GECODE_ME_CHECK(x2.inter_r(home,u,false)); else GECODE_ME_CHECK(x2.inter_r(home,u,true)); returnES_FIX; } }}} //STATISTICS:int-prop