test for simann
authorladanyi
Sun, 29 Jan 2006 22:10:06 +0000
changeset 1921fb4a2a84d363
parent 1920 e9e27c5a53bf
child 1922 1ee37068316b
test for simann
test/Makefile.am
test/simann_test.cc
     1.1 --- a/test/Makefile.am	Sun Jan 29 22:07:52 2006 +0000
     1.2 +++ b/test/Makefile.am	Sun Jan 29 22:10:06 2006 +0000
     1.3 @@ -35,7 +35,8 @@
     1.4  	unionfind_test \
     1.5  	ugraph_test \
     1.6  	xy_test \
     1.7 -	heap_test
     1.8 +	heap_test \
     1.9 +	simann_test
    1.10  
    1.11  if HAVE_GLPK
    1.12  check_PROGRAMS += lp_test
    1.13 @@ -72,6 +73,7 @@
    1.14  xy_test_SOURCES = xy_test.cc
    1.15  ugraph_test_SOURCES = ugraph_test.cc
    1.16  heap_test_SOURCES = heap_test.cc
    1.17 +simann_test_SOURCES = simann_test.cc
    1.18  
    1.19  lp_test_SOURCES = lp_test.cc
    1.20  lp_test_CXXFLAGS = $(GLPK_CFLAGS) $(CPLEX_CFLAGS)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/simann_test.cc	Sun Jan 29 22:10:06 2006 +0000
     2.3 @@ -0,0 +1,42 @@
     2.4 +#include <lemon/simann.h>
     2.5 +
     2.6 +using namespace lemon;
     2.7 +
     2.8 +class MyEntity : public EntityBase {
     2.9 +public:
    2.10 +  double d, prev_d;
    2.11 +  MyEntity() : d(100000.0) { srand48(time(0)); }
    2.12 +  double mutate() {
    2.13 +    prev_d = d;
    2.14 +    if (drand48() < 0.8) { d += 1.0; }
    2.15 +    else { d -= 1.0; }
    2.16 +    return d;
    2.17 +  }
    2.18 +  void revert() { d = prev_d; }
    2.19 +  MyEntity* clone() { return new MyEntity (*this); }
    2.20 +  void randomize() {}
    2.21 +};
    2.22 +
    2.23 +int main() {
    2.24 +  SimAnn simann;
    2.25 +  SimpleController ctrl;
    2.26 +  simann.setController(ctrl);
    2.27 +  MyEntity ent;
    2.28 +  simann.setEntity(ent);
    2.29 +  simann.run();
    2.30 +
    2.31 +  //MyEntity *best_ent = (MyEntity *) simann.getBestEntity();
    2.32 +  //std::cout << best_ent->d << std::endl;
    2.33 +
    2.34 +  SimAnn simann2;
    2.35 +  AdvancedController ctrl2(2.0);
    2.36 +  simann2.setController(ctrl2);
    2.37 +  MyEntity ent2;
    2.38 +  simann2.setEntity(ent2);
    2.39 +  simann2.run();
    2.40 +
    2.41 +  //MyEntity *best_ent2 = (MyEntity *) simann2.getBestEntity();
    2.42 +  //std::cout << best_ent2->d << std::endl;
    2.43 +
    2.44 +  return 0;
    2.45 +}