src/work/akos/simann_test.cc
author marci
Fri, 01 Oct 2004 11:31:03 +0000
changeset 933 1b7c88fbb950
child 942 75fdd0c6866d
permissions -rw-r--r--
NodeSubGraphWrapper, test, and ducumentation modifications.
     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 }