test/simann_test.cc
author deba
Fri, 03 Nov 2006 14:14:05 +0000
changeset 2289 03e4d2128efe
parent 1956 a055123339d5
child 2391 14a343be7a5a
permissions -rw-r--r--
Strict checking disabled
alpar@1956
     1
/* -*- C++ -*-
alpar@1956
     2
 *
alpar@1956
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1956
     4
 *
alpar@1956
     5
 * Copyright (C) 2003-2006
alpar@1956
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1956
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@1956
     8
 *
alpar@1956
     9
 * Permission to use, modify and distribute this software is granted
alpar@1956
    10
 * provided that this copyright notice appears in all copies. For
alpar@1956
    11
 * precise terms see the accompanying LICENSE file.
alpar@1956
    12
 *
alpar@1956
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@1956
    14
 * express or implied, and with no claim as to its suitability for any
alpar@1956
    15
 * purpose.
alpar@1956
    16
 *
alpar@1956
    17
 */
alpar@1956
    18
ladanyi@1921
    19
#include <lemon/simann.h>
ladanyi@1921
    20
ladanyi@1921
    21
using namespace lemon;
ladanyi@1921
    22
ladanyi@1921
    23
class MyEntity : public EntityBase {
ladanyi@1921
    24
public:
ladanyi@1921
    25
  double d, prev_d;
deba@2242
    26
  MyEntity() : d(100000.0) {}
ladanyi@1921
    27
  double mutate() {
ladanyi@1921
    28
    prev_d = d;
deba@2242
    29
    if (rnd.boolean(0.8)) { d += 1.0; }
ladanyi@1921
    30
    else { d -= 1.0; }
ladanyi@1921
    31
    return d;
ladanyi@1921
    32
  }
ladanyi@1921
    33
  void revert() { d = prev_d; }
ladanyi@1921
    34
  MyEntity* clone() { return new MyEntity (*this); }
ladanyi@1921
    35
  void randomize() {}
ladanyi@1921
    36
};
ladanyi@1921
    37
ladanyi@1921
    38
int main() {
ladanyi@1921
    39
  SimAnn simann;
ladanyi@1921
    40
  SimpleController ctrl;
ladanyi@1921
    41
  simann.setController(ctrl);
ladanyi@1921
    42
  MyEntity ent;
ladanyi@1921
    43
  simann.setEntity(ent);
ladanyi@1921
    44
  simann.run();
ladanyi@1921
    45
ladanyi@1921
    46
  //MyEntity *best_ent = (MyEntity *) simann.getBestEntity();
ladanyi@1921
    47
  //std::cout << best_ent->d << std::endl;
ladanyi@1921
    48
ladanyi@1921
    49
  SimAnn simann2;
ladanyi@1921
    50
  AdvancedController ctrl2(2.0);
ladanyi@1921
    51
  simann2.setController(ctrl2);
ladanyi@1921
    52
  MyEntity ent2;
ladanyi@1921
    53
  simann2.setEntity(ent2);
ladanyi@1921
    54
  simann2.run();
ladanyi@1921
    55
ladanyi@1921
    56
  //MyEntity *best_ent2 = (MyEntity *) simann2.getBestEntity();
ladanyi@1921
    57
  //std::cout << best_ent2->d << std::endl;
ladanyi@1921
    58
ladanyi@1921
    59
  return 0;
ladanyi@1921
    60
}