author | klao |
Thu, 02 Feb 2006 17:09:09 +0000 | |
changeset 1945 | e5c0c5cc477f |
child 1956 | a055123339d5 |
permissions | -rw-r--r-- |
ladanyi@1921 | 1 |
#include <lemon/simann.h> |
ladanyi@1921 | 2 |
|
ladanyi@1921 | 3 |
using namespace lemon; |
ladanyi@1921 | 4 |
|
ladanyi@1921 | 5 |
class MyEntity : public EntityBase { |
ladanyi@1921 | 6 |
public: |
ladanyi@1921 | 7 |
double d, prev_d; |
ladanyi@1921 | 8 |
MyEntity() : d(100000.0) { srand48(time(0)); } |
ladanyi@1921 | 9 |
double mutate() { |
ladanyi@1921 | 10 |
prev_d = d; |
ladanyi@1921 | 11 |
if (drand48() < 0.8) { d += 1.0; } |
ladanyi@1921 | 12 |
else { d -= 1.0; } |
ladanyi@1921 | 13 |
return d; |
ladanyi@1921 | 14 |
} |
ladanyi@1921 | 15 |
void revert() { d = prev_d; } |
ladanyi@1921 | 16 |
MyEntity* clone() { return new MyEntity (*this); } |
ladanyi@1921 | 17 |
void randomize() {} |
ladanyi@1921 | 18 |
}; |
ladanyi@1921 | 19 |
|
ladanyi@1921 | 20 |
int main() { |
ladanyi@1921 | 21 |
SimAnn simann; |
ladanyi@1921 | 22 |
SimpleController ctrl; |
ladanyi@1921 | 23 |
simann.setController(ctrl); |
ladanyi@1921 | 24 |
MyEntity ent; |
ladanyi@1921 | 25 |
simann.setEntity(ent); |
ladanyi@1921 | 26 |
simann.run(); |
ladanyi@1921 | 27 |
|
ladanyi@1921 | 28 |
//MyEntity *best_ent = (MyEntity *) simann.getBestEntity(); |
ladanyi@1921 | 29 |
//std::cout << best_ent->d << std::endl; |
ladanyi@1921 | 30 |
|
ladanyi@1921 | 31 |
SimAnn simann2; |
ladanyi@1921 | 32 |
AdvancedController ctrl2(2.0); |
ladanyi@1921 | 33 |
simann2.setController(ctrl2); |
ladanyi@1921 | 34 |
MyEntity ent2; |
ladanyi@1921 | 35 |
simann2.setEntity(ent2); |
ladanyi@1921 | 36 |
simann2.run(); |
ladanyi@1921 | 37 |
|
ladanyi@1921 | 38 |
//MyEntity *best_ent2 = (MyEntity *) simann2.getBestEntity(); |
ladanyi@1921 | 39 |
//std::cout << best_ent2->d << std::endl; |
ladanyi@1921 | 40 |
|
ladanyi@1921 | 41 |
return 0; |
ladanyi@1921 | 42 |
} |