equal
deleted
inserted
replaced
29 |
29 |
30 #include <cstdlib> |
30 #include <cstdlib> |
31 #include <cmath> |
31 #include <cmath> |
32 #include <limits> |
32 #include <limits> |
33 #include <lemon/time_measure.h> |
33 #include <lemon/time_measure.h> |
34 |
34 #include <lemon/random.h> |
35 #ifdef WIN32 |
|
36 #include <lemon/bits/mingw32_rand.h> |
|
37 #endif |
|
38 |
35 |
39 namespace lemon { |
36 namespace lemon { |
40 |
37 |
41 /// \addtogroup experimental |
38 /// \addtogroup experimental |
42 /// @{ |
39 /// @{ |
239 public: |
236 public: |
240 SimpleController(long _max_iter = 500000, long _max_no_impr = 20000, |
237 SimpleController(long _max_iter = 500000, long _max_no_impr = 20000, |
241 double _temp = 1000.0, double _ann_fact = 0.9999) : max_iter(_max_iter), |
238 double _temp = 1000.0, double _ann_fact = 0.9999) : max_iter(_max_iter), |
242 max_no_impr(_max_no_impr), temp(_temp), ann_fact(_ann_fact) |
239 max_no_impr(_max_no_impr), temp(_temp), ann_fact(_ann_fact) |
243 { |
240 { |
244 srand48(time(0)); |
|
245 } |
241 } |
246 /// \brief This is called when a neighbouring state gets accepted. |
242 /// \brief This is called when a neighbouring state gets accepted. |
247 void acceptEvent() {} |
243 void acceptEvent() {} |
248 /// \brief This is called when the accepted neighbouring state's cost is |
244 /// \brief This is called when the accepted neighbouring state's cost is |
249 /// less than the best found one's. |
245 /// less than the best found one's. |
259 return !quit; |
255 return !quit; |
260 } |
256 } |
261 /// \brief Decides whether to accept the current solution or not. |
257 /// \brief Decides whether to accept the current solution or not. |
262 bool accept() { |
258 bool accept() { |
263 double cost_diff = simann->getCurrCost() - simann->getPrevCost(); |
259 double cost_diff = simann->getCurrCost() - simann->getPrevCost(); |
264 return (drand48() <= exp(-(cost_diff / temp))); |
260 return (rnd.getReal() <= exp(-(cost_diff / temp))); |
265 } |
261 } |
266 /// \brief Destructor. |
262 /// \brief Destructor. |
267 virtual ~SimpleController() {} |
263 virtual ~SimpleController() {} |
268 }; |
264 }; |
269 |
265 |
319 AdvancedController(double _end_time, double _alpha = 0.2, |
315 AdvancedController(double _end_time, double _alpha = 0.2, |
320 double _beta = 0.9, double _gamma = 1.6, double _ann_fact = 0.9999) : |
316 double _beta = 0.9, double _gamma = 1.6, double _ann_fact = 0.9999) : |
321 alpha(_alpha), beta(_beta), gamma(_gamma), end_time(_end_time), |
317 alpha(_alpha), beta(_beta), gamma(_gamma), end_time(_end_time), |
322 ann_fact(_ann_fact), init_ann_fact(_ann_fact), start(false) |
318 ann_fact(_ann_fact), init_ann_fact(_ann_fact), start(false) |
323 { |
319 { |
324 srand48(time(0)); |
|
325 } |
320 } |
326 /// \brief Does initializations before each run. |
321 /// \brief Does initializations before each run. |
327 void init() { |
322 void init() { |
328 avg_cost = simann->getCurrCost(); |
323 avg_cost = simann->getCurrCost(); |
329 } |
324 } |
368 if (!start) { |
363 if (!start) { |
369 return true; |
364 return true; |
370 } |
365 } |
371 else { |
366 else { |
372 double cost_diff = simann->getCurrCost() - simann->getPrevCost(); |
367 double cost_diff = simann->getCurrCost() - simann->getPrevCost(); |
373 return (drand48() <= exp(-(cost_diff / temp))); |
368 return (rnd.getReal() <= exp(-(cost_diff / temp))); |
374 } |
369 } |
375 } |
370 } |
376 /// \brief Destructor. |
371 /// \brief Destructor. |
377 virtual ~AdvancedController() {} |
372 virtual ~AdvancedController() {} |
378 }; |
373 }; |