COIN-OR::LEMON - Graph Library

Changeset 942:75fdd0c6866d in lemon-0.x for src/work/akos/simann_test.cc


Ignore:
Timestamp:
10/11/04 20:02:48 (20 years ago)
Author:
Akos Ladanyi
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1285
Message:

Naming and coding style fixes and various other changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/work/akos/simann_test.cc

    r918 r942  
    1 #include "SimAnn.h"
     1#include "simann.h"
    22#include <cstdlib>
    33#include <cmath>
    44#include <iostream>
    55
     6using namespace lemon;
     7
    68class MyController : public SimAnnBase::Controller {
    79public:
    8   long MaxIter, MaxNoImpr;
    9   double af;
     10  long iter, last_impr, max_iter, max_no_impr;
     11  double temp, annealing_factor;
    1012  MyController() {
    11     MaxIter = 500000;
    12     MaxNoImpr = 20000;
    13     af = 0.9999;
    14     T = 1000;
     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++;
    1527  }
    1628  bool next() {
    17     T *= af;
    18     std::cout << T << std::endl;
    19     return !((sab->getIter() > MaxIter) || (sab->getIter() - sab->getLastImpr() > MaxNoImpr));
     29    temp *= annealing_factor;
     30    bool quit = (iter > max_iter) || (iter - last_impr > max_no_impr);
     31    return !quit;
    2032  }
    21   bool accept(double cost) {
    22     return (drand48() <= exp(cost / T));
     33  bool accept(double cost_diff) {
     34    return (drand48() <= exp(cost_diff / temp));
    2335  }
    2436};
     
    2638class MyEntity {
    2739public:
    28   void init() {}
    2940  double mutate() { return 10.0; }
    3041};
    3142
    3243int main() {
    33   SimAnn<MyEntity> sa;
    34   MyController c;
    35   sa.setController(c);
     44  SimAnn<MyEntity> simann;
     45  MyController ctrl;
     46  simann.setController(ctrl);
    3647  MyEntity ent;
    37   sa.setEnt(ent);
    38   sa.run();
     48  simann.setEntity(ent);
     49  simann.run();
    3950}
Note: See TracChangeset for help on using the changeset viewer.