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 #include <algorithm>
00039 #include <gecode/search.hh>
00040
00041 namespace Gecode { namespace Search {
00042
00043 unsigned long int
00044 CutoffConstant::operator ()(void) const {
00045 return c;
00046 }
00047 unsigned long int
00048 CutoffConstant::operator ++(void) {
00049 return c;
00050 }
00051
00052
00053 unsigned long int
00054 CutoffLinear::operator ()(void) const {
00055 return n;
00056 }
00057 unsigned long int
00058 CutoffLinear::operator ++(void) {
00059 n += scale;
00060 return n;
00061 }
00062
00063
00064 unsigned long int
00065 CutoffLuby::start[CutoffLuby::n_start] = {
00066 1,1,2,1,1,2,4,1,1,2,1,1,2,4,8,1,1,2,1,1,2,4,1,1,2,1,1,2,4,8,16,
00067 1,1,2,1,1,2,4,1,1,2,1,1,2,4,8,1,1,2,1,1,2,4,1,1,2,1,1,2,4,8,16,32
00068 };
00069 unsigned long int
00070 CutoffLuby::operator ()(void) const {
00071 return scale*luby(i);
00072 }
00073 unsigned long int
00074 CutoffLuby::operator ++(void) {
00075 return scale*luby(i++);
00076 }
00077
00078
00079 unsigned long int
00080 CutoffGeometric::operator ()(void) const {
00081 return static_cast<unsigned long int>(scale * n);
00082 }
00083 unsigned long int
00084 CutoffGeometric::operator ++(void) {
00085 n *= base;
00086 return static_cast<unsigned long int>(scale * n);
00087 }
00088
00089
00090 unsigned long int
00091 CutoffRandom::operator ++(void) {
00092 cur = min+step*rnd(n);
00093 return cur;
00094 }
00095 unsigned long int
00096 CutoffRandom::operator ()(void) const {
00097 return cur;
00098 }
00099
00100
00101 unsigned long int
00102 CutoffAppend::operator ()(void) const {
00103 if (n > 0) {
00104 return (*c1)();
00105 } else {
00106 return (*c2)();
00107 }
00108 }
00109 unsigned long int
00110 CutoffAppend::operator ++(void) {
00111 if (n > 0) {
00112 n--;
00113 return ++(*c1);
00114 } else {
00115 return ++(*c2);
00116 }
00117 }
00118
00119
00120 unsigned long int
00121 CutoffMerge::operator ()(void) const {
00122 return (*c1)();
00123 }
00124 unsigned long int
00125 CutoffMerge::operator ++(void) {
00126 (void) ++(*c1);
00127 std::swap(c1,c2);
00128 return (*c1)();
00129 }
00130
00131
00132 unsigned long int
00133 CutoffRepeat::operator ()(void) const {
00134 return cutoff;
00135 }
00136 unsigned long int
00137 CutoffRepeat::operator ++(void) {
00138 i++;
00139 if (i == n) {
00140 cutoff = (*c)();
00141 i = 0;
00142 }
00143 return cutoff;
00144 }
00145
00146
00147 Cutoff*
00148 Cutoff::constant(unsigned long int scale) {
00149 return new CutoffConstant(scale);
00150 }
00151 Cutoff*
00152 Cutoff::linear(unsigned long int scale) {
00153 return new CutoffLinear(scale);
00154 }
00155 Cutoff*
00156 Cutoff::luby(unsigned long int scale) {
00157 return new CutoffLuby(scale);
00158 }
00159 Cutoff*
00160 Cutoff::geometric(unsigned long int base, double scale) {
00161 return new CutoffGeometric(base,scale);
00162 }
00163 Cutoff*
00164 Cutoff::rnd(unsigned int seed,
00165 unsigned long int min,
00166 unsigned long int max,
00167 unsigned long int n) {
00168 return new CutoffRandom(seed,min,max,n);
00169 }
00170 Cutoff*
00171 Cutoff::append(Cutoff* c1, unsigned long int n, Cutoff* c2) {
00172 return new CutoffAppend(c1,n,c2);
00173 }
00174 Cutoff*
00175 Cutoff::merge(Cutoff* c1, Cutoff* c2) {
00176 return new CutoffMerge(c1,c2);
00177 }
00178 Cutoff*
00179 Cutoff::repeat(Cutoff* c, unsigned long int n) {
00180 return new CutoffRepeat(c,n);
00181 }
00182
00183 }}
00184
00185