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