Last change
on this file since 197 was 44, checked in by Rick van der Zwet, 15 years ago |
Make it cute
|
-
Property svn:keywords
set to
Id
|
File size:
1.0 KB
|
Line | |
---|
1 | % Simulated Annealing low-autocorrelation program
|
---|
2 | % BSDLicence
|
---|
3 | % Rick van der Zwet - 0433373 - <hvdzwet@liacs.nl>
|
---|
4 | % $Id: sa.m 44 2009-12-17 22:23:16Z rick $
|
---|
5 |
|
---|
6 | function [iteration_history,fitness_history] = sa(seq, stopLimit)
|
---|
7 | fitness = 0;
|
---|
8 | temperature = stopLimit;
|
---|
9 |
|
---|
10 | iteration_history = [];
|
---|
11 | fitness_history = [];
|
---|
12 |
|
---|
13 | for iteration = 1:stopLimit
|
---|
14 | % Generate new mutation
|
---|
15 | newseq = mutation(seq);
|
---|
16 |
|
---|
17 | new_fitness = autocorrelation(newseq);
|
---|
18 |
|
---|
19 | % Better is always accept
|
---|
20 | if (new_fitness > fitness)
|
---|
21 | fitness = new_fitness;
|
---|
22 | % disp(rot90(newseq,-1));
|
---|
23 | temperature = temperature - 10;
|
---|
24 | else
|
---|
25 | % Make the next 'move' less atractive
|
---|
26 | temperature = temperature + 1;
|
---|
27 |
|
---|
28 | % Accept on an certain probability
|
---|
29 | if (temperature < 1)
|
---|
30 | break;
|
---|
31 | else
|
---|
32 | % XXX: Some more cleaver cooling would be great
|
---|
33 | if( exp(1)^((fitness - new_fitness) / temperature) > rand())
|
---|
34 | seq = newseq;
|
---|
35 | end
|
---|
36 | end
|
---|
37 | end
|
---|
38 | iteration_history = [ iteration_history, iteration ];
|
---|
39 | fitness_history = [ fitness_history, fitness ];
|
---|
40 | end
|
---|
41 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.