range.hpp gecode/int/rel.hh /usr/include/gecode/int/dom.hh Gecode Gecode::Int Gecode::Int::Dom /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2004 * *Lastmodified: *$Date:2011-11-1816:02:48+0100(Fri,18Nov2011)$by$Author:schulte$ *$Revision:12472$ * *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{namespaceDom{ template<classView,ReifyModerm> forceinline ReRange<View,rm>::ReRange(Homehome,Viewx,intmin0,intmax0,BoolViewb) :ReUnaryPropagator<View,PC_INT_BND,BoolView>(home,x,b), min(min0),max(max0){} template<classView,ReifyModerm> ExecStatus ReRange<View,rm>::post(Homehome,Viewx,intmin,intmax,BoolViewb){ if(min==max){ returnRel::ReEqDomInt<View,BoolView,rm>::post(home,x,min,b); }elseif((min>max)||(max<x.min())||(min>x.max())){ if(rm==RM_PMI) returnES_OK; GECODE_ME_CHECK(b.zero(home)); }elseif((min<=x.min())&&(x.max()<=max)){ if(rm==RM_IMP) returnES_OK; GECODE_ME_CHECK(b.one(home)); }elseif(b.one()){ if(rm==RM_PMI) returnES_OK; GECODE_ME_CHECK(x.gq(home,min)); GECODE_ME_CHECK(x.lq(home,max)); }elseif(b.zero()){ if(rm==RM_IMP) returnES_OK; Iter::Ranges::Singletonr(min,max); GECODE_ME_CHECK(x.minus_r(home,r,false)); }else{ (void)new(home)ReRange<View,rm>(home,x,min,max,b); } returnES_OK; } template<classView,ReifyModerm> forceinline ReRange<View,rm>::ReRange(Space&home,boolshare,ReRange&p) :ReUnaryPropagator<View,PC_INT_BND,BoolView>(home,share,p), min(p.min),max(p.max){} template<classView,ReifyModerm> Actor* ReRange<View,rm>::copy(Space&home,boolshare){ returnnew(home)ReRange<View,rm>(home,share,*this); } template<classView,ReifyModerm> ExecStatus ReRange<View,rm>::propagate(Space&home,constModEventDelta&){ if(b.one()){ if(rm!=RM_PMI){ GECODE_ME_CHECK(x0.gq(home,min)); GECODE_ME_CHECK(x0.lq(home,max)); } }elseif(b.zero()){ if(rm!=RM_IMP){ Iter::Ranges::Singletonr(min,max); GECODE_ME_CHECK(x0.minus_r(home,r,false)); } }elseif((x0.max()<=max)&&(x0.min()>=min)){ if(rm!=RM_IMP) GECODE_ME_CHECK(b.one_none(home)); }elseif((x0.max()<min)||(x0.min()>max)){ if(rm!=RM_PMI) GECODE_ME_CHECK(b.zero_none(home)); }else{ returnES_FIX; } returnhome.ES_SUBSUMED(*this); } }}} //STATISTICS:int-prop