Changeset 1096:1cfb25ef14d2 in lemon0.x
 Timestamp:
 01/26/05 10:00:40 (18 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@1495
 Location:
 src/work/akos
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

src/work/akos/simann.h
r1023 r1096 99 99 } 100 100 void saveAsBest() { 101 *best_ent = *curr_ent; 101 delete(best_ent); 102 best_ent = new E(*curr_ent); 102 103 best_cost = curr_cost; 103 104 } … … 130 131 */ 131 132 SimpleController(long _max_iter = 500000, long _max_no_impr = 20000, 132 double _temp = 1000 , double _ann_fact = 0.9999) : iter(0), last_impr(0),133 double _temp = 1000.0, double _ann_fact = 0.9999) : iter(0), last_impr(0), 133 134 max_iter(_max_iter), max_no_impr(_max_no_impr), temp(_temp), 134 135 ann_fact(_ann_fact) {} … … 150 151 double cost_diff = base>getPrevCost()  base>getCurrCost(); 151 152 if (cost_diff < 0.0) { 152 return (drand48() <= exp(cost_diff / temp)); 153 bool ret = drand48() <= exp(cost_diff / temp); 154 return ret; 153 155 } 154 156 else { … … 167 169 /*! \param time the elapsed time in seconds */ 168 170 virtual double threshold(double time) { 169 // this is the function 1 / log(x) scaled and offset 171 // 1 / log(x) 172 /* 170 173 static double xm = 5.0 / end_time; 171 174 static double ym = start_threshold / (1 / log(1.2)  1 / log(5.0 + 1.2)); 172 175 return ym * (1 / log(xm * time + 1.2)  1 / log(5.0 + 1.2)); 176 */ 177 return (1.0) * start_threshold / end_time * time + start_threshold; 173 178 } 174 179 public: … … 185 190 */ 186 191 AdvancedController(double _end_time, double _alpha = 0.2, 187 double _beta = 0.9, double _gamma = 1. 2) : alpha(_alpha), beta(_beta),188 gamma(_gamma), end_time(_end_time), ann_fact(0.9999 ), warmup(true) {}192 double _beta = 0.9, double _gamma = 1.6) : alpha(_alpha), beta(_beta), 193 gamma(_gamma), end_time(_end_time), ann_fact(0.99999999), warmup(true) {} 189 194 void init() { 190 195 avg_cost = base>getCurrCost(); … … 193 198 avg_cost = alpha * base>getCurrCost() + (1.0  alpha) * avg_cost; 194 199 if (warmup) { 195 static double max_cost_diff = 0.0; 196 static int incr_cnt = 0; 197 double cost_diff = base>getCurrCost()  base>getPrevCost(); 198 if (cost_diff > 0.0) { 199 incr_cnt++; 200 if (cost_diff > max_cost_diff) { 201 max_cost_diff = cost_diff; 202 } 203 } 204 if (incr_cnt >= 100) { 200 static int cnt = 0; 201 cnt++; 202 if (cnt >= 100) { 205 203 // calculate starting threshold and starting temperature 206 start_threshold = fabs(base>getBestCost()  avg_cost); 207 temp = max_cost_diff / log(0.5); 204 start_threshold = 5.0 * fabs(base>getBestCost()  avg_cost); 205 //temp = max_cost_diff / log(0.5); 206 temp = 10000.0; 208 207 warmup = false; 209 208 timer.reset(); … … 228 227 // increase the temperature 229 228 temp *= gamma; 229 ann_fact = 0.99999999; 230 230 } 231 231 temp *= ann_fact; 
src/work/akos/simann_demo.cc
r1023 r1096 11 11 12 12 int main() { 13 /* 13 14 SimAnn<MyEntity> simann; 14 15 SimpleController ctrl; … … 17 18 simann.setEntity(ent); 18 19 simann.run(); 20 */ 19 21 20 22 SimAnn<MyEntity> simann2; 21 AdvancedController ctrl2( 20.0);23 AdvancedController ctrl2(10.0); 22 24 simann2.setController(ctrl2); 23 25 MyEntity ent2;
Note: See TracChangeset
for help on using the changeset viewer.