float.hpp /usr/include/gecode/float/var-imp.hpp Gecode Gecode::Float /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *FilipKonvicka<filip.konvicka@logis.cz> *LubomirMoric<lubomir.moric@logis.cz> *VincentBarichard<Vincent.Barichard@univ-angers.fr> * *Contributingauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *LOGIS,s.r.o.,2008 *ChristianSchulte,2010 *VincentBarichard,2012 * *Lastmodified: *$Date:2013-02-0417:54:05+0100(Mon,04Feb2013)$by$Author:schulte$ *$Revision:13260$ * *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{namespaceFloat{ /* *Creationofnewvariableimplementations * */ forceinline FloatVarImp::FloatVarImp(Space&home,constFloatVal&d) :FloatVarImpBase(home),dom(d){} forceinline FloatVarImp::FloatVarImp(Space&home,boolshare,FloatVarImp&x) :FloatVarImpBase(home,share,x),dom(x.dom){} /* *Operationsonfloatvariableimplementations * */ forceinlineFloatVal FloatVarImp::domain(void)const{ returndom; } forceinlineFloatNum FloatVarImp::min(void)const{ returndom.min(); } forceinlineFloatNum FloatVarImp::max(void)const{ returndom.max(); } forceinlineFloatVal FloatVarImp::val(void)const{ returndom; } forceinlineFloatNum FloatVarImp::med(void)const{ returndom.med(); } forceinlinebool FloatVarImp::assigned(void)const{ returndom.tight(); } forceinlineFloatNum FloatVarImp::size(void)const{ returndom.size(); } /* *Tests * */ forceinlinebool FloatVarImp::zero_in(void)const{ returndom.zero_in(); } forceinlinebool FloatVarImp::in(FloatNumn)const{ returndom.in(n); } forceinlinebool FloatVarImp::in(constFloatVal&n)const{ returnsubset(n,dom); } /* *Supportfordeltainformation * */ forceinlineFloatNum FloatVarImp::min(constDelta&d){ returnstatic_cast<constFloatDelta&>(d).min(); } forceinlineFloatNum FloatVarImp::max(constDelta&d){ returnstatic_cast<constFloatDelta&>(d).max(); } /* *Telloperations(tobeinlined:performingboundschecksfirst) * */ forceinlineModEvent FloatVarImp::gq(Space&home,FloatNumn){ if(n>dom.max())returnME_FLOAT_FAILED; if((n<=dom.min())||assigned())returnME_FLOAT_NONE; FloatDeltad(dom.min(),n); ModEventme=ME_FLOAT_BND; dom=intersect(dom,FloatVal(n,dom.max())); if(assigned())me=ME_FLOAT_VAL; GECODE_ASSUME((me==ME_FLOAT_VAL)| (me==ME_FLOAT_BND)); returnnotify(home,me,d); } forceinlineModEvent FloatVarImp::gq(Space&home,constFloatVal&n){ if(n.min()>dom.max())returnME_FLOAT_FAILED; if((n.min()<=dom.min())||assigned())returnME_FLOAT_NONE; FloatDeltad(dom.min(),n.min()); ModEventme=ME_FLOAT_BND; dom=intersect(dom,FloatVal(n.min(),dom.max())); if(assigned())me=ME_FLOAT_VAL; GECODE_ASSUME((me==ME_FLOAT_VAL)| (me==ME_FLOAT_BND)); returnnotify(home,me,d); } forceinlineModEvent FloatVarImp::lq(Space&home,FloatNumn){ if(n<dom.min())returnME_FLOAT_FAILED; if((n>=dom.max())||assigned())returnME_FLOAT_NONE; FloatDeltad(n,dom.max()); ModEventme=ME_FLOAT_BND; dom=intersect(dom,FloatVal(dom.min(),n)); if(assigned())me=ME_FLOAT_VAL; GECODE_ASSUME((me==ME_FLOAT_VAL)| (me==ME_FLOAT_BND)); returnnotify(home,me,d); } forceinlineModEvent FloatVarImp::lq(Space&home,constFloatVal&n){ if(n.max()<dom.min())returnME_FLOAT_FAILED; if((n.max()>=dom.max())||assigned())returnME_FLOAT_NONE; FloatDeltad(n.max(),dom.max()); ModEventme=ME_FLOAT_BND; dom=intersect(dom,FloatVal(dom.min(),n.max())); if(assigned())me=ME_FLOAT_VAL; GECODE_ASSUME((me==ME_FLOAT_VAL)| (me==ME_FLOAT_BND)); returnnotify(home,me,d); } forceinlineModEvent FloatVarImp::eq(Space&home,FloatNumn){ if(!dom.in(n)) returnME_FLOAT_FAILED; if(assigned()) returnME_FLOAT_NONE; FloatDeltad; dom=n; returnnotify(home,ME_FLOAT_VAL,d); } forceinlineModEvent FloatVarImp::eq(Space&home,constFloatVal&n){ if(!overlap(dom,n)) returnME_FLOAT_FAILED; if(assigned()||subset(dom,n)) returnME_FLOAT_NONE; FloatDeltad; ModEventme=ME_FLOAT_BND; dom=intersect(dom,n); if(assigned())me=ME_FLOAT_VAL; GECODE_ASSUME((me==ME_FLOAT_VAL)| (me==ME_FLOAT_BND)); returnnotify(home,me,d); } /* *Copyingavariable * */ forceinlineFloatVarImp* FloatVarImp::copy(Space&home,boolshare){ returncopied()?static_cast<FloatVarImp*>(forward()) :perform_copy(home,share); } forceinlineFloatVarImp* FloatVarImp::perform_copy(Space&home,boolshare){ returnnew(home)FloatVarImp(home,share,*this); } /* *Dependencies * */ forceinlinevoid FloatVarImp::subscribe(Space&home,Propagator&p,PropCondpc,boolschedule){ FloatVarImpBase::subscribe(home,p,pc,assigned(),schedule); } forceinlinevoid FloatVarImp::cancel(Space&home,Propagator&p,PropCondpc){ FloatVarImpBase::cancel(home,p,pc,assigned()); } forceinlinevoid FloatVarImp::subscribe(Space&home,Advisor&a){ FloatVarImpBase::subscribe(home,a,assigned()); } forceinlinevoid FloatVarImp::cancel(Space&home,Advisor&a){ FloatVarImpBase::cancel(home,a,assigned()); } forceinlineModEventDelta FloatVarImp::med(ModEventme){ returnFloatVarImpBase::med(me); } }} //STATISTICS:float-var