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