Changeset 957:4dd4eaee28e7 in lemon-0.x for src/work/akos
- Timestamp:
- 11/04/04 19:48:58 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1340
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/akos/simann.h
r956 r957 23 23 curr_cost = prev_cost = best_cost = INFTY; 24 24 } 25 void setController(Controller &_controller) { controller = &_controller; } 25 void setController(Controller &_controller) { 26 controller = &_controller; 27 controller->setBase(this); 28 } 29 double getCurrCost() { return curr_cost; } 30 double getPrevCost() { return prev_cost; } 26 31 double getBestCost() { return best_cost; } 27 32 void run() { 28 33 while (controller->next()) { 29 34 mutate(); 30 if (controller->accept( prev_cost - curr_cost)) {35 if (controller->accept()) { 31 36 controller->acceptEvent(); 32 37 if (curr_cost < best_cost) { … … 44 49 class Controller { 45 50 public: 51 SimAnnBase *base; 46 52 virtual void acceptEvent() {} 47 53 virtual void improveEvent() {} 48 54 virtual void rejectEvent() {} 55 virtual void setBase(SimAnnBase *_base) { base = _base; } 49 56 virtual bool next() = 0; 50 virtual bool accept( double cost_diff) = 0;57 virtual bool accept() = 0; 51 58 }; 52 59 }; … … 58 65 E *best_ent; 59 66 public: 60 SimAnn 2() : SimAnnBase() {}61 void setEntity(E & Ent) {62 curr_ent = new E( Ent);63 best_ent = new E( Ent);67 SimAnn() : SimAnnBase() {} 68 void setEntity(E &ent) { 69 curr_ent = new E(ent); 70 best_ent = new E(ent); 64 71 } 65 72 E getBestEntity() { return *best_ent; } … … 89 96 long iter, last_impr, max_iter, max_no_impr; 90 97 double temp, annealing_factor; 91 MyController() {98 SimpleController() { 92 99 iter = last_impr = 0; 93 100 max_iter = 500000; … … 110 117 return !quit; 111 118 } 112 bool accept( double cost_diff) {113 return (drand48() <= exp( cost_diff/ temp));119 bool accept() { 120 return (drand48() <= exp(base->getPrevCost() - base->getCurrCost() / temp)); 114 121 } 115 122 };
Note: See TracChangeset
for help on using the changeset viewer.