[Lemon-commits] [lemon_svn] ladanyi: r1336 - hugo/trunk/src/work/akos
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:44:41 CET 2006
Author: ladanyi
Date: Thu Nov 4 14:32:44 2004
New Revision: 1336
Modified:
hugo/trunk/src/work/akos/simann.h
Log:
Added the SimpleController class, and removed the first version of SimAnn in favour of the second.
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 14:32:44 2004
@@ -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 <typename E>
- 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
More information about the Lemon-commits
mailing list