author | alpar |
Sat, 30 Oct 2004 18:30:29 +0000 | |
changeset 949 | b16a10926781 |
parent 918 | bb77eaa8fa0e |
child 958 | 75f749682240 |
permissions | -rw-r--r-- |
1 #include "simann.h"
2 #include <cstdlib>
3 #include <cmath>
4 #include <iostream>
6 using namespace lemon;
8 class MyController : public SimAnnBase::Controller {
9 public:
10 long iter, last_impr, max_iter, max_no_impr;
11 double temp, annealing_factor;
12 MyController() {
13 iter = last_impr = 0;
14 max_iter = 500000;
15 max_no_impr = 20000;
16 annealing_factor = 0.9999;
17 temp = 1000;
18 }
19 void acceptEvent() {
20 iter++;
21 }
22 void improveEvent() {
23 last_impr = iter;
24 }
25 void rejectEvent() {
26 iter++;
27 }
28 bool next() {
29 temp *= annealing_factor;
30 bool quit = (iter > max_iter) || (iter - last_impr > max_no_impr);
31 return !quit;
32 }
33 bool accept(double cost_diff) {
34 return (drand48() <= exp(cost_diff / temp));
35 }
36 };
38 class MyEntity {
39 public:
40 double mutate() { return 10.0; }
41 };
43 int main() {
44 SimAnn<MyEntity> simann;
45 MyController ctrl;
46 simann.setController(ctrl);
47 MyEntity ent;
48 simann.setEntity(ent);
49 simann.run();
50 }