Changeset 942:75fdd0c6866d in lemon-0.x for src/work/akos/simann_test.cc
- Timestamp:
- 10/11/04 20:02:48 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1285
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/akos/simann_test.cc
r918 r942 1 #include " SimAnn.h"1 #include "simann.h" 2 2 #include <cstdlib> 3 3 #include <cmath> 4 4 #include <iostream> 5 5 6 using namespace lemon; 7 6 8 class MyController : public SimAnnBase::Controller { 7 9 public: 8 long MaxIter, MaxNoImpr;9 double af;10 long iter, last_impr, max_iter, max_no_impr; 11 double temp, annealing_factor; 10 12 MyController() { 11 MaxIter = 500000; 12 MaxNoImpr = 20000; 13 af = 0.9999; 14 T = 1000; 13 iter = last_impr = 0; 14 max_iter = 500000; 15 max_no_impr = 20000; 16 annealing_factor = 0.9999; 17 temp = 1000; 18 } 19 void acceptEvent() { 20 iter++; 21 } 22 void improveEvent() { 23 last_impr = iter; 24 } 25 void rejectEvent() { 26 iter++; 15 27 } 16 28 bool next() { 17 T *= af;18 std::cout << T << std::endl;19 return ! ((sab->getIter() > MaxIter) || (sab->getIter() - sab->getLastImpr() > MaxNoImpr));29 temp *= annealing_factor; 30 bool quit = (iter > max_iter) || (iter - last_impr > max_no_impr); 31 return !quit; 20 32 } 21 bool accept(double cost ) {22 return (drand48() <= exp(cost / T));33 bool accept(double cost_diff) { 34 return (drand48() <= exp(cost_diff / temp)); 23 35 } 24 36 }; … … 26 38 class MyEntity { 27 39 public: 28 void init() {}29 40 double mutate() { return 10.0; } 30 41 }; 31 42 32 43 int main() { 33 SimAnn<MyEntity> s a;34 MyController c ;35 s a.setController(c);44 SimAnn<MyEntity> simann; 45 MyController ctrl; 46 simann.setController(ctrl); 36 47 MyEntity ent; 37 s a.setEnt(ent);38 s a.run();48 simann.setEntity(ent); 49 simann.run(); 39 50 }
Note: See TracChangeset
for help on using the changeset viewer.