test/simann_test.cc
changeset 1936 0722ea2b0907
child 1956 a055123339d5
equal deleted inserted replaced
-1:000000000000 0:4969cf45ad68
       
     1 #include <lemon/simann.h>
       
     2 
       
     3 using namespace lemon;
       
     4 
       
     5 class MyEntity : public EntityBase {
       
     6 public:
       
     7   double d, prev_d;
       
     8   MyEntity() : d(100000.0) { srand48(time(0)); }
       
     9   double mutate() {
       
    10     prev_d = d;
       
    11     if (drand48() < 0.8) { d += 1.0; }
       
    12     else { d -= 1.0; }
       
    13     return d;
       
    14   }
       
    15   void revert() { d = prev_d; }
       
    16   MyEntity* clone() { return new MyEntity (*this); }
       
    17   void randomize() {}
       
    18 };
       
    19 
       
    20 int main() {
       
    21   SimAnn simann;
       
    22   SimpleController ctrl;
       
    23   simann.setController(ctrl);
       
    24   MyEntity ent;
       
    25   simann.setEntity(ent);
       
    26   simann.run();
       
    27 
       
    28   //MyEntity *best_ent = (MyEntity *) simann.getBestEntity();
       
    29   //std::cout << best_ent->d << std::endl;
       
    30 
       
    31   SimAnn simann2;
       
    32   AdvancedController ctrl2(2.0);
       
    33   simann2.setController(ctrl2);
       
    34   MyEntity ent2;
       
    35   simann2.setEntity(ent2);
       
    36   simann2.run();
       
    37 
       
    38   //MyEntity *best_ent2 = (MyEntity *) simann2.getBestEntity();
       
    39   //std::cout << best_ent2->d << std::endl;
       
    40 
       
    41   return 0;
       
    42 }