equal
deleted
inserted
replaced
|
1 #include "SimAnn.h" |
|
2 #include <cstdlib> |
|
3 #include <cmath> |
|
4 #include <iostream> |
|
5 |
|
6 class MyController : public SimAnnBase::Controller { |
|
7 public: |
|
8 long MaxIter, MaxNoImpr; |
|
9 double af; |
|
10 MyController() { |
|
11 MaxIter = 500000; |
|
12 MaxNoImpr = 20000; |
|
13 af = 0.9999; |
|
14 T = 1000; |
|
15 } |
|
16 bool next() { |
|
17 T *= af; |
|
18 std::cout << T << std::endl; |
|
19 return !((sab->getIter() > MaxIter) || (sab->getIter() - sab->getLastImpr() > MaxNoImpr)); |
|
20 } |
|
21 bool accept(double cost) { |
|
22 return (drand48() <= exp(cost / T)); |
|
23 } |
|
24 }; |
|
25 |
|
26 class MyEntity { |
|
27 public: |
|
28 void init() {} |
|
29 double mutate() { return 10.0; } |
|
30 }; |
|
31 |
|
32 int main() { |
|
33 SimAnn<MyEntity> sa; |
|
34 MyController c; |
|
35 sa.setController(c); |
|
36 MyEntity ent; |
|
37 sa.setEnt(ent); |
|
38 sa.run(); |
|
39 } |