ranges-scale.hpp cmath /usr/include/gecode/iter.hh Gecode::Iter::Ranges::ScaleUp Gecode::Iter::Ranges::ScaleDown Gecode Gecode::Iter Gecode::Iter::Ranges /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2005 * *Lastmodified: *$Date:2012-02-1702:33:03+0100(Fri,17Feb2012)$by$Author:tack$ *$Revision:12528$ * *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<cmath> namespaceGecode{namespaceIter{namespaceRanges{ template<classVal,classUnsVal,classI> classScaleUp{ protected: Ii; inta; Valcur; Valend; public: ScaleUp(void); ScaleUp(I&i,inta); voidinit(I&i,inta); booloperator ()(void)const; voidoperator ++(void); Valmin(void)const; Valmax(void)const; UnsValwidth(void)const; }; template<classI> classScaleDown:publicMinMax{ protected: Ii; inta; public: ScaleDown(void); ScaleDown(I&i,inta); voidinit(I&i,inta); voidoperator ++(void); }; template<classVal,classUnsVal,classI> forceinline ScaleUp<Val,UnsVal,I>::ScaleUp(void){} template<classVal,classUnsVal,classI> inlinevoid ScaleUp<Val,UnsVal,I>::init(I&i0,inta0){ i=i0;a=a0; if(i()){ cur=a*i.min(); end=a*i.max(); }else{ cur=1; end=0; } } template<classVal,classUnsVal,classI> inline ScaleUp<Val,UnsVal,I>::ScaleUp(I&i0,inta0):i(i0),a(a0){ if(i()){ cur=a*i.min(); end=a*i.max(); }else{ cur=1; end=0; } } template<classVal,classUnsVal,classI> forceinlinevoid ScaleUp<Val,UnsVal,I>::operator ++(void){ if(a==1){ ++i; }else{ cur+=a; if(cur>end){ ++i; if(i()){ cur=a*i.min(); end=a*i.max(); } } } } template<classVal,classUnsVal,classI> forceinlinebool ScaleUp<Val,UnsVal,I>::operator ()(void)const{ return(a==1)?i():(cur<=end); } template<classVal,classUnsVal,classI> forceinlineVal ScaleUp<Val,UnsVal,I>::min(void)const{ return(a==1)?static_cast<Val>(i.min()):cur; } template<classVal,classUnsVal,classI> forceinlineVal ScaleUp<Val,UnsVal,I>::max(void)const{ return(a==1)?static_cast<Val>(i.max()):cur; } template<classVal,classUnsVal,classI> forceinlineUnsVal ScaleUp<Val,UnsVal,I>::width(void)const{ return(a==1)? static_cast<UnsVal>(i.width()): static_cast<UnsVal>(1); } template<classI> forceinlinevoid ScaleDown<I>::operator ++(void){ finish(); while((mi>ma)&&i()){ mi=static_cast<int>(ceil(static_cast<double>(i.min())/a)); ma=static_cast<int>(floor(static_cast<double>(i.max())/a)); ++i; } while(i()){ intn_mi=static_cast<int>(ceil(static_cast<double>(i.min())/a)); if(n_mi-ma>1) break; intn_ma=static_cast<int>(floor(static_cast<double>(i.max())/a)); if(n_mi<=n_ma){ ma=n_ma; } ++i; } } template<classI> forceinline ScaleDown<I>::ScaleDown(void){} template<classI> inlinevoid ScaleDown<I>::init(I&i0,inta0){ i=i0;a=a0; operator++(); } template<classI> inline ScaleDown<I>::ScaleDown(I&i0,inta0):i(i0),a(a0){ i=i0;a=a0; operator ++(); } }}} //STATISTICS:iter-any