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