[Lemon-commits] [lemon_svn] ladanyi: r1340 - hugo/trunk/src/work/akos

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:44:42 CET 2006


Author: ladanyi
Date: Thu Nov  4 19:48:58 2004
New Revision: 1340

Modified:
   hugo/trunk/src/work/akos/simann.h

Log:
Now the controller asks SimAnnBase for the various costs.

Modified: hugo/trunk/src/work/akos/simann.h
==============================================================================
--- hugo/trunk/src/work/akos/simann.h	(original)
+++ hugo/trunk/src/work/akos/simann.h	Thu Nov  4 19:48:58 2004
@@ -22,12 +22,17 @@
     SimAnnBase() {
       curr_cost = prev_cost = best_cost = INFTY;
     }
-    void setController(Controller &_controller) { controller = &_controller; }
+    void setController(Controller &_controller) {
+      controller = &_controller;
+      controller->setBase(this);
+    }
+    double getCurrCost() { return curr_cost; }
+    double getPrevCost() { return prev_cost; }
     double getBestCost() { return best_cost; }
     void run() {
       while (controller->next()) {
         mutate();
-        if (controller->accept(prev_cost - curr_cost)) {
+        if (controller->accept()) {
           controller->acceptEvent();
           if (curr_cost < best_cost) {
             saveAsBest();
@@ -43,11 +48,13 @@
 
     class Controller {
     public:
+      SimAnnBase *base;
       virtual void acceptEvent() {}
       virtual void improveEvent() {}
       virtual void rejectEvent() {}
+      virtual void setBase(SimAnnBase *_base) { base = _base; }
       virtual bool next() = 0;
-      virtual bool accept(double cost_diff) = 0;
+      virtual bool accept() = 0;
     };
   };
 
@@ -57,10 +64,10 @@
     E *curr_ent;
     E *best_ent;
   public:
-    SimAnn2() : SimAnnBase() {}
-    void setEntity(E &Ent) {
-      curr_ent = new E(Ent);
-      best_ent = new E(Ent);
+    SimAnn() : SimAnnBase() {}
+    void setEntity(E &ent) {
+      curr_ent = new E(ent);
+      best_ent = new E(ent);
     }
     E getBestEntity() { return *best_ent; }
     void mutate() {
@@ -88,7 +95,7 @@
   public:
     long iter, last_impr, max_iter, max_no_impr;
     double temp, annealing_factor;
-    MyController() {
+    SimpleController() {
       iter = last_impr = 0;
       max_iter = 500000;
       max_no_impr = 20000;
@@ -109,8 +116,8 @@
       bool quit = (iter > max_iter) || (iter - last_impr > max_no_impr);
       return !quit;
     }
-    bool accept(double cost_diff) {
-      return (drand48() <= exp(cost_diff / temp));
+    bool accept() {
+      return (drand48() <= exp(base->getPrevCost() - base->getCurrCost() / temp));
     }
   };
 



More information about the Lemon-commits mailing list