cutoff.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 namespace Gecode { namespace Search {
00039
00040 forceinline
00041 Cutoff::Cutoff(void) {}
00042 forceinline
00043 Cutoff::~Cutoff(void) {}
00044
00045
00046 forceinline
00047 CutoffConstant::CutoffConstant(unsigned long int c0)
00048 : c(c0) {}
00049
00050
00051 forceinline
00052 CutoffLinear::CutoffLinear(unsigned long int s)
00053 : scale(s), n(0) {}
00054
00055
00056 forceinline
00057 CutoffLuby::CutoffLuby(unsigned long int scale0)
00058 : i(1U), scale(scale0) {}
00059 forceinline unsigned long int
00060 CutoffLuby::log(unsigned long int i) {
00061 if (i == 1U)
00062 return 0U;
00063 unsigned long int exp = 0U;
00064 while ( (i >> (++exp)) > 1U ) {}
00065 return exp;
00066 }
00067 forceinline unsigned long int
00068 CutoffLuby::luby(unsigned long int i) {
00069 while (true) {
00070 if (i <= n_start)
00071 return start[i-1];
00072 unsigned long int l = log(i);
00073 if (i == (1U<<(l+1))-1)
00074 return 1UL<<l;
00075 i=i-(1U<<l)+1;
00076 }
00077 GECODE_NEVER;
00078 return 0;
00079 }
00080
00081
00082 forceinline
00083 CutoffGeometric::CutoffGeometric(unsigned long int scale0, double base0)
00084 : n(1.0), scale(static_cast<double>(scale0)), base(base0) {}
00085
00086
00087 forceinline
00088 CutoffRandom::CutoffRandom(unsigned int seed,
00089 unsigned long int min0,
00090 unsigned long int max0,
00091 unsigned long int n0)
00092 : rnd(seed), min(min0), n(n0 == 0 ? (max0-min+1U) : n0),
00093 step(std::max(1UL,
00094 static_cast<unsigned long int>((max0-min0+1U)/n))) {
00095 cur = ++(*this);
00096 }
00097
00098
00099 forceinline
00100 CutoffAppend::CutoffAppend(Cutoff* d1, unsigned long int n0, Cutoff* d2)
00101 : c1(d1), c2(d2), n(n0) {}
00102 forceinline
00103 CutoffAppend::~CutoffAppend(void) {
00104 delete c1; delete c2;
00105 }
00106
00107
00108 forceinline
00109 CutoffMerge::CutoffMerge(Cutoff* d1, Cutoff* d2)
00110 : c1(d1), c2(d2) {}
00111 forceinline
00112 CutoffMerge::~CutoffMerge(void) {
00113 delete c1; delete c2;
00114 }
00115
00116
00117 forceinline
00118 CutoffRepeat::CutoffRepeat(Cutoff* c1, unsigned long int n0)
00119 : c(c1), i(0), n(n0) {
00120 cutoff = (*c)();
00121 }
00122 forceinline
00123 CutoffRepeat::~CutoffRepeat(void) {
00124 delete c;
00125 }
00126
00127 }}
00128
00129