# HG changeset patch # User ladanyi # Date 1099575164 0 # Node ID 0ff924405d21a6b9fc1a36969c9116c3daa1cd87 # Parent 0a066f80e05fb539e5f6044ded58f7219e0611b8 Added the SimpleController class, and removed the first version of SimAnn in favour of the second. diff -r 0a066f80e05f -r 0ff924405d21 src/work/akos/simann.h --- a/src/work/akos/simann.h Tue Nov 02 06:28:38 2004 +0000 +++ b/src/work/akos/simann.h Thu Nov 04 13:32:44 2004 +0000 @@ -55,43 +55,6 @@ class SimAnn : public SimAnnBase { private: E *curr_ent; - E *prev_ent; - E *best_ent; - public: - SimAnn() : SimAnnBase() {} - void setEntity(E &Ent) { - curr_ent = new E(Ent); - prev_ent = new E(Ent); - best_ent = new E(Ent); - } - E getBestEntity() { return *best_ent; } - void mutate() { - *prev_ent = *curr_ent; - prev_cost = curr_cost; - curr_cost = curr_ent->mutate(); - } - void revert() { - E *tmp = curr_ent; - curr_ent = prev_ent; - prev_ent = tmp; - curr_cost = prev_cost; - } - void saveAsBest() { - *best_ent = *curr_ent; - best_cost = curr_cost; - } - }; - - class EntitySkeleton { - public: - // returns the new cost - double mutate() { return 0.0; } - }; - - template - class SimAnn2 : public SimAnnBase { - private: - E *curr_ent; E *best_ent; public: SimAnn2() : SimAnnBase() {} @@ -112,7 +75,7 @@ } }; - class EntitySkeleton2 { + class EntitySkeleton { public: // returns the new cost double mutate() { return 0.0; } @@ -121,6 +84,36 @@ void revert() {} }; + class SimpleController : public SimAnnBase::Controller { + public: + long iter, last_impr, max_iter, max_no_impr; + double temp, annealing_factor; + MyController() { + iter = last_impr = 0; + max_iter = 500000; + max_no_impr = 20000; + annealing_factor = 0.9999; + temp = 1000; + } + void acceptEvent() { + iter++; + } + void improveEvent() { + last_impr = iter; + } + void rejectEvent() { + iter++; + } + bool next() { + temp *= annealing_factor; + bool quit = (iter > max_iter) || (iter - last_impr > max_no_impr); + return !quit; + } + bool accept(double cost_diff) { + return (drand48() <= exp(cost_diff / temp)); + } + }; + } #endif