Index: src/work/akos/simann.h
===================================================================
--- src/work/akos/simann.h	(revision 1018)
+++ src/work/akos/simann.h	(revision 1023)
@@ -17,6 +17,7 @@
   protected:
     double curr_cost;
+    double best_cost;
     double prev_cost;
-    double best_cost;
+    double prev_prev_cost;
 
     virtual void mutate() = 0;
@@ -25,5 +26,5 @@
   public:
     SimAnnBase() {
-      curr_cost = prev_cost = best_cost = INFTY;
+      best_cost = prev_cost = prev_prev_cost = INFTY;
     }
     void setController(Controller &_controller) {
@@ -73,5 +74,4 @@
   };
 
-  /*! \todo atgondolni mi is ez a prev_cost */
   template <typename E>
   class SimAnn : public SimAnnBase {
@@ -84,13 +84,17 @@
       curr_ent = new E(ent);
       best_ent = new E(ent);
+      curr_cost = curr_ent->getCost();
     }
     E getBestEntity() { return *best_ent; }
     void mutate() {
+      prev_prev_cost = prev_cost;
       prev_cost = curr_cost;
-      curr_cost = curr_ent->mutate();
+      curr_ent->mutate();
+      curr_cost = curr_ent->getCost();
     }
     void revert() {
       curr_ent->revert();
       curr_cost = prev_cost;
+      prev_cost = prev_prev_cost;
     }
     void saveAsBest() {
@@ -102,8 +106,8 @@
   class EntitySkeleton {
   public:
-    /*! \brief Makes a minor change to the entity.
-     *  \return the new cost
-     */
-    double mutate() { return 0.0; }
+    /*! \return the cost of the entity */
+    double getCost() { return 0.0; }
+    /*! \brief Makes a minor change to the entity. */
+    void mutate() {}
     /*! \brief Restores the entity to its previous state i.e. reverts the
      *  effects of the last mutate.
@@ -175,5 +179,4 @@
     double temp, ann_fact;
     bool warmup;
-    long iter;
     /*! \param _end_time running time in seconds
      *  \param _alpha parameter used to calculate the running average
@@ -183,6 +186,5 @@
     AdvancedController(double _end_time, double _alpha = 0.2,
     double _beta = 0.9, double _gamma = 1.2) : alpha(_alpha), beta(_beta),
-    gamma(_gamma), end_time(_end_time), ann_fact(0.9999), warmup(true),
-    iter(0) {}
+    gamma(_gamma), end_time(_end_time), ann_fact(0.9999), warmup(true) {}
     void init() {
       avg_cost = base->getCurrCost();
@@ -190,28 +192,29 @@
     void acceptEvent() {
       avg_cost = alpha * base->getCurrCost() + (1.0 - alpha) * avg_cost;
-      iter++;
+      if (warmup) {
+        static double max_cost_diff = 0.0;
+        static int incr_cnt = 0;
+        double cost_diff = base->getCurrCost() - base->getPrevCost();
+        if (cost_diff > 0.0) {
+          incr_cnt++;
+          if (cost_diff > max_cost_diff) {
+            max_cost_diff = cost_diff;
+          }
+        }
+        if (incr_cnt >= 100) {
+          // calculate starting threshold and starting temperature
+          start_threshold = fabs(base->getBestCost() - avg_cost);
+          temp = max_cost_diff / log(0.5);
+          warmup = false;
+          timer.reset();
+        }
+      }
     }
     void improveEvent() {
     }
     void rejectEvent() {
-      iter++;
     }
     bool next() {
       if (warmup) {
-        static double max_cost_diff = 0.0;
-        double cost_diff = base->getCurrCost() - base->getPrevCost();
-        // jo ez igy egyaltalan? -> prev_cost
-        if ((cost_diff > 0.0) && (cost_diff > max_cost_diff)) {
-          max_cost_diff = cost_diff;
-        }
-        // How to set the starting temperature when all the 100 first
-        // iterations improve the solution?
-        if (iter > 100) {
-          // calculate starting threshold and starting temperature
-          start_threshold = fabs(base->getBestCost() - avg_cost);
-          temp = exp(max_cost_diff) / 0.5;
-          warmup = false;
-          timer.reset();
-        }
         return true;
       }
Index: src/work/akos/simann_demo.cc
===================================================================
--- src/work/akos/simann_demo.cc	(revision 999)
+++ src/work/akos/simann_demo.cc	(revision 1023)
@@ -5,5 +5,6 @@
 class MyEntity {
 public:
-  double mutate() { return 10.0; }
+  double getCost() { return 10.0; }
+  void mutate() {}
   void revert() {}
 };
