Changeset 956:0ff924405d21 in lemon-0.x
- Timestamp:
- 11/04/04 14:32:44 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1336
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/akos/simann.h
r942 r956 56 56 private: 57 57 E *curr_ent; 58 E *prev_ent;59 E *best_ent;60 public:61 SimAnn() : SimAnnBase() {}62 void setEntity(E &Ent) {63 curr_ent = new E(Ent);64 prev_ent = new E(Ent);65 best_ent = new E(Ent);66 }67 E getBestEntity() { return *best_ent; }68 void mutate() {69 *prev_ent = *curr_ent;70 prev_cost = curr_cost;71 curr_cost = curr_ent->mutate();72 }73 void revert() {74 E *tmp = curr_ent;75 curr_ent = prev_ent;76 prev_ent = tmp;77 curr_cost = prev_cost;78 }79 void saveAsBest() {80 *best_ent = *curr_ent;81 best_cost = curr_cost;82 }83 };84 85 class EntitySkeleton {86 public:87 // returns the new cost88 double mutate() { return 0.0; }89 };90 91 template <typename E>92 class SimAnn2 : public SimAnnBase {93 private:94 E *curr_ent;95 58 E *best_ent; 96 59 public: … … 113 76 }; 114 77 115 class EntitySkeleton 2{78 class EntitySkeleton { 116 79 public: 117 80 // returns the new cost … … 122 85 }; 123 86 87 class SimpleController : public SimAnnBase::Controller { 88 public: 89 long iter, last_impr, max_iter, max_no_impr; 90 double temp, annealing_factor; 91 MyController() { 92 iter = last_impr = 0; 93 max_iter = 500000; 94 max_no_impr = 20000; 95 annealing_factor = 0.9999; 96 temp = 1000; 97 } 98 void acceptEvent() { 99 iter++; 100 } 101 void improveEvent() { 102 last_impr = iter; 103 } 104 void rejectEvent() { 105 iter++; 106 } 107 bool next() { 108 temp *= annealing_factor; 109 bool quit = (iter > max_iter) || (iter - last_impr > max_no_impr); 110 return !quit; 111 } 112 bool accept(double cost_diff) { 113 return (drand48() <= exp(cost_diff / temp)); 114 } 115 }; 116 124 117 } 125 118
Note: See TracChangeset
for help on using the changeset viewer.