COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/akos/simann_test.cc @ 942:75fdd0c6866d

Last change on this file since 942:75fdd0c6866d was 942:75fdd0c6866d, checked in by Akos Ladanyi, 20 years ago

Naming and coding style fixes and various other changes.

File size: 959 bytes
RevLine 
[942]1#include "simann.h"
[918]2#include <cstdlib>
3#include <cmath>
4#include <iostream>
5
[942]6using namespace lemon;
7
[918]8class MyController : public SimAnnBase::Controller {
9public:
[942]10  long iter, last_impr, max_iter, max_no_impr;
11  double temp, annealing_factor;
[918]12  MyController() {
[942]13    iter = last_impr = 0;
14    max_iter = 500000;
15    max_no_impr = 20000;
16    annealing_factor = 0.9999;
17    temp = 1000;
18  }
19  void acceptEvent() {
20    iter++;
21  }
22  void improveEvent() {
23    last_impr = iter;
24  }
25  void rejectEvent() {
26    iter++;
[918]27  }
28  bool next() {
[942]29    temp *= annealing_factor;
30    bool quit = (iter > max_iter) || (iter - last_impr > max_no_impr);
31    return !quit;
[918]32  }
[942]33  bool accept(double cost_diff) {
34    return (drand48() <= exp(cost_diff / temp));
[918]35  }
36};
37
38class MyEntity {
39public:
40  double mutate() { return 10.0; }
41};
42
43int main() {
[942]44  SimAnn<MyEntity> simann;
45  MyController ctrl;
46  simann.setController(ctrl);
[918]47  MyEntity ent;
[942]48  simann.setEntity(ent);
49  simann.run();
[918]50}
Note: See TracBrowser for help on using the repository browser.